-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathForm1.cs
More file actions
279 lines (244 loc) · 8.12 KB
/
Copy pathForm1.cs
File metadata and controls
279 lines (244 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace StuntGP_widescreen
{
public struct sequence
{
public byte[] byteSequence;
public int offset;
public sequence(byte[] byteSequence, int offset)
{
this.byteSequence = byteSequence;
this.offset = offset;
}
}
public partial class Form1 : Form
{
static string _GamesExecutable = "StuntGP_D3D.exe";
static string _GamesExecutableBackup = "StuntGP_D3D.bak";
static string PCGW_URL = "http://pcgamingwiki.com/";
static string donationURL = "https://www.twitchalerts.com/donate/suicidemachine";
int width = 1280;
int height = 720;
float aspectRatio = 1.7777777f;
List<sequence> sequences = new List<sequence>()
{
new sequence(new byte[] { 0x80, 0xDC, 0x00, 0x00, 0x00, 0xBE, 0x9F, 0xAA, 0x3F, 0xC7, 0x80, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F }, 5),
new sequence(new byte[] { 0x80, 0xBC, 0x00, 0x00, 0x00, 0xBE, 0x9F, 0xAA, 0x3F, 0xC7, 0x80, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3F }, 5)
};
byte[] AspectAsArray = new byte[4];
byte[] data;
int adress = 0;
bool autoCalculate = true;
public Form1()
{
InitializeComponent();
if(!File.Exists(_GamesExecutable))
{
MessageBox.Show("No executable found. Please place the file in a folder with a game.");
Close();
}
else
{
data = GetBytesFromAFile(_GamesExecutable);
string s = BitConverter.ToString(data);
for(int i=0; i<sequences.Count; i++)
{
adress = findSequence(data, sequences[i]);
if (adress != -1)
break;
}
if (adress == -1)
{
MessageBox.Show("Nothing found in the file. Sorry.");
Close();
}
else
{
Trace.WriteLine("Found address: 0x" + adress.ToString("X4"));
aspectRatio = BitConverter.ToSingle(data, adress);
TB_AspectRatio.Text = aspectRatio.ToString();
}
}
}
#region FindAdress
private int findSequence(byte[] source, sequence _sequence)
{
for (int tempAdress = 0; tempAdress < source.Length; tempAdress++)
{
if(compareByteArrays(_sequence, source, tempAdress))
{
return tempAdress + _sequence.offset;
}
}
return -1;
}
private bool compareByteArrays(sequence _sequence, byte[] dataArray, int dataOffset)
{
byte[] sequenceArray = _sequence.byteSequence;
int offset = _sequence.offset;
if (dataArray.Length-dataOffset > sequenceArray.Length)
{
for (int i = 0; i<sequenceArray.Length; i++)
{
if (i == offset)
{
i += 3;
continue;
}
if(sequenceArray[i]!=dataArray[dataOffset+i])
{
return false;
}
}
return true;
}
return false;
}
#endregion
#region Buttons_Lables_and_Stuff
private void TB_ResX_TextChanged(object sender, EventArgs e)
{
var temp = 1280;
if (int.TryParse(TB_ResX.Text, out temp))
{
width = temp;
}
else
width = 1280;
if (autoCalculate)
{
aspectRatio = CalculateAspect(width, height);
TB_AspectRatio.Text = aspectRatio.ToString();
}
}
private void TB_ResY_TextChanged(object sender, EventArgs e)
{
var temp = 720;
if (int.TryParse(TB_ResY.Text, out temp))
{
height = temp;
}
else
height = 720;
if (autoCalculate)
{
aspectRatio = CalculateAspect(width, height);
TB_AspectRatio.Text = aspectRatio.ToString();
}
}
float CalculateAspect(int X, int Y)
{
float outputValue = X*1.0f / Y*1.0f;
return outputValue;
}
private void C_AutomaticAspect_CheckedChanged(object sender, EventArgs e)
{
if (C_AutomaticAspect.Checked)
{
autoCalculate = true;
TB_AspectRatio.Enabled = false;
aspectRatio = CalculateAspect(width, height);
TB_AspectRatio.Text = aspectRatio.ToString();
}
else
{
autoCalculate = false;
TB_AspectRatio.Enabled = true;
}
}
private void getArray()
{
AspectAsArray = BitConverter.GetBytes(aspectRatio);
L_Byte0.Text = AspectAsArray[0].ToString("X2");
L_Byte1.Text = AspectAsArray[1].ToString("X2");
L_Byte2.Text = AspectAsArray[2].ToString("X2");
L_Byte3.Text = AspectAsArray[3].ToString("X2");
}
private void TB_AspectRatio_TextChanged(object sender, EventArgs e)
{
if(!autoCalculate)
{
var temp = 1.333f;
if(float.TryParse(TB_AspectRatio.Text, out temp))
{
aspectRatio = temp;
}
}
getArray();
}
#endregion
#region Load_Save
private byte[] GetBytesFromAFile(string filename)
{
FileStream fs = null;
try
{
fs = File.OpenRead(filename);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
return bytes;
}
finally
{
if (fs != null)
{
fs.Close();
fs.Dispose();
}
}
}
private bool WriteBytesToAFile(string filename, byte[] usedData)
{
try
{
File.WriteAllBytes(filename, usedData);
return true;
}
catch (Exception ex)
{
Trace.WriteLine(ex.ToString());
return false;
}
}
private void B_WriteToAFile_Click(object sender, EventArgs e)
{
//Replacing bytes
data[adress + 0] = AspectAsArray[0];
data[adress + 1] = AspectAsArray[1];
data[adress + 2] = AspectAsArray[2];
data[adress + 3] = AspectAsArray[3];
//Backup
if (!File.Exists(_GamesExecutableBackup))
{
File.Copy(_GamesExecutable, _GamesExecutableBackup);
}
bool success = true;
success = WriteBytesToAFile(_GamesExecutable, data);
if (!success)
MessageBox.Show("There was an error writting to a file!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
MessageBox.Show("Successfully made the changes!", "Note", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
#endregion
private void LL_PCGW_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(PCGW_URL);
}
private void donateLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(donationURL);
}
}
}