-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm1.cs
398 lines (342 loc) · 15.6 KB
/
Form1.cs
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.Collections.Generic;
namespace FovChanger
{
public partial class Form1 : Form
{
// Base address value for pointers.
int baseAddress = 0x00400000;
// Other variables.
System.Text.Encoding enc = System.Text.Encoding.UTF8;
Process[] myProcess;
string processNameDX9, processNameDX11;
bool isDX11 = false;
int useAlternativePointer = 0;
float fov=1.3f;
float readFov = 0;
float readCurrentDisplayedFOV = 0;
int fovAddress = 0x0082E128;
int[] offsetCurrentFOV = new int[] { 0x200, 0x0, 0x28, 0x80 };
int[] offsetCurrentDisplayedFOV = new int[] { 0x200, 0x0, 0x28, 0xC };
int[] offsetCurrentFOVAlternative = new int[] { 0x200, 0x4, 0x0, 0x28, 0x80 }; //Alternative pointers DX9
int[] offsetCurrentDisplayedFOVAlternative = new int[] { 0x200, 0x4, 0x0, 0x28, 0xC };
int fovAddressAlternative2 = 0x00823F00;
int[] offsetCurrentFOVAlternative2 = new int[] { 0x158, 0xCC, 0x64, 0x28, 0x80 };
int[] offsetCurrentDisplayedFOVAlternative2 = new int[] { 0x158, 0xCC, 0x64, 0x28, 0xC };
int fovAddressDX11 = 0x0066DA28;
int[] offsetCurrentFOVDX11 = new int[] { 0x200, 0x0, 0x28, 0x80 };
int[] offsetCurrentDisplayFOVDX11 = new int[] { 0x200, 0x0, 0x28, 0xC };
int[] offsetCurrentFOVDX11Alternative = new int[] { 0x200, 0x4, 0x0, 0x28, 0x80 }; //Alternative pointers DX11
int[] offsetCurrentDisplayFOVDX11Alternative = new int[] { 0x200, 0x4, 0x0, 0x28, 0xC };
int fovAddressDX11Alternative2 = 0x005EA2F0;
int[] offsetCurrentFOVDX11Alternative2 = new int[] { 0x30, 0x0, 0x10, 0x28, 0x80 };
int[] offsetCurrentDisplayFOVDX11Alternative2= new int[] { 0x30, 0x0, 0x10, 0x28, 0xC };
Keys Key = Keys.F2;
bool autoMode;
bool settingInputKey;
string PCGWUrl = "http://www.pcgamingwiki.com";
/*------------------
-- INITIALIZATION --
------------------*/
public Form1()
{
InitializeComponent();
processNameDX9 = "AvP";
processNameDX11 = "AvP_DX11";
}
bool foundProcess = false;
private void Timer_Tick(object sender, EventArgs e)
{
try
{
if (isDX11 == false)
myProcess = Process.GetProcessesByName(processNameDX9);
else
myProcess = Process.GetProcessesByName(processNameDX11);
if (myProcess.Length > 0)
{
if (foundProcess == false)
System.Threading.Thread.Sleep(100);
foundProcess = true;
}
else
foundProcess = false;
if (foundProcess)
{
// The game is running, ready for memory reading.
LB_Running.Text = "AvP is running";
LB_Running.ForeColor = Color.Green;
if (isDX11 == false)
{
readFov = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentFOV);
readCurrentDisplayedFOV = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentDisplayedFOV);
useAlternativePointer = 0;
if ((Single.IsNaN(readFov) || readFov < 0.013 || readFov > 2.99) && useAlternativePointer == 0) //if FOV is NaN / lower than 1 / higher than 170 -> use alternative pointer
{
useAlternativePointer = 1;
readFov = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentFOVAlternative);
readCurrentDisplayedFOV = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentDisplayedFOVAlternative);
}
if ((Single.IsNaN(readFov) || readFov < 0.013 || readFov > 2.99) && useAlternativePointer == 1)
{
useAlternativePointer = 2;
readFov = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddressAlternative2, offsetCurrentFOVAlternative2);
readCurrentDisplayedFOV = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddressAlternative2, offsetCurrentDisplayedFOVAlternative2);
}
if ((Single.IsNaN(readFov) || readFov < 0.013 || readFov > 2.99) && useAlternativePointer == 2)
{
useAlternativePointer = 99;
}
}
else
{
readFov = Trainer.ReadPointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentFOVDX11);
readCurrentDisplayedFOV = Trainer.ReadPointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentDisplayFOVDX11);
useAlternativePointer = 0;
if ((Single.IsNaN(readFov) || readFov < 0.013 || readFov > 2.99) && useAlternativePointer == 0) //Yes, I know, this is a terrible way of doing it :|
{
useAlternativePointer = 1;
readFov = Trainer.ReadPointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentFOVDX11Alternative);
readCurrentDisplayedFOV = Trainer.ReadPointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentDisplayFOVDX11Alternative);
}
if ((Single.IsNaN(readFov) || readFov < 0.013 || readFov > 2.99) && useAlternativePointer == 1)
{
useAlternativePointer = 2;
readFov = Trainer.ReadPointerFloat(processNameDX11, baseAddress + fovAddressDX11Alternative2, offsetCurrentFOVDX11Alternative2);
readCurrentDisplayedFOV = Trainer.ReadPointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentFOVAlternative2);
}
if ((Single.IsNaN(readFov) || readFov < 0.013 || readFov > 2.99) && useAlternativePointer == 2)
{
useAlternativePointer = 99;
}
}
L_fov.Text = VerticalRadiansToHorizontalFOV(readFov).ToString();
if (autoMode)
{
ChangeFov();
}
}
else
{
// The game process has not been found, reseting values.
LB_Running.Text = "AvP is not running";
LB_Running.ForeColor = Color.Red;
ResetValues();
}
}
catch(Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
// Called when the game is not running or no mission is active.
// Used to reset all the values.
private void ResetValues()
{
L_fov.Text = "0";
}
private void Form1_Load(object sender, EventArgs e)
{
InitHotkey();
Timer.Start();
}
public void InitHotkey()
{
if (!KeyGrabber.Hooked)
{
KeyGrabber.key.Clear();
KeyGrabber.keyPressEvent += KeyGrabber_KeyPress;
if (Key != Keys.None)
KeyGrabber.key.Add(Key);
KeyGrabber.SetHook();
}
else
{
if (Key != Keys.None)
KeyGrabber.key.Add(Key);
}
}
public void UnHook()
{
KeyGrabber.UnHook();
}
private void KeyGrabber_KeyPress(object sender, EventArgs e)
{
ChangeDisplayedFOV();
}
void ChangeFov()
{
if ((fovAddress != 0x0000000 || fovAddressDX11 != 0x0000000) && foundProcess)
{
if(isDX11==false)
{
if (readFov != fov && useAlternativePointer < 99)
{
if (useAlternativePointer == 1)
Trainer.WritePointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentFOVAlternative, fov);
else if (useAlternativePointer == 2)
Trainer.WritePointerFloat(processNameDX9, baseAddress + fovAddressAlternative2, offsetCurrentFOVAlternative2, fov);
else if(useAlternativePointer == 0)
Trainer.WritePointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentFOV, fov);
L_fov.Text = VerticalRadiansToHorizontalFOV(fov).ToString();
}
}
else
{
if (readFov != fov && useAlternativePointer < 99)
{
if (useAlternativePointer == 1)
Trainer.WritePointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentFOVDX11Alternative, fov);
else if (useAlternativePointer == 2)
Trainer.WritePointerFloat(processNameDX11, baseAddress + fovAddressDX11Alternative2, offsetCurrentFOVDX11Alternative2, fov);
else if (useAlternativePointer == 0)
Trainer.WritePointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentFOVDX11, fov);
L_fov.Text = VerticalRadiansToHorizontalFOV(fov).ToString();
}
}
}
}
void ChangeDisplayedFOV()
{
if ((fovAddress != 0x0000000 || fovAddressDX11 != 0x0000000) && foundProcess)
{
if(isDX11==false)
{
if (readCurrentDisplayedFOV != fov && useAlternativePointer < 99)
{
if (useAlternativePointer == 1)
Trainer.WritePointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentDisplayedFOVAlternative, fov);
else if (useAlternativePointer == 2)
Trainer.WritePointerFloat(processNameDX9, baseAddress + fovAddressAlternative2, offsetCurrentDisplayedFOVAlternative2, fov);
else
Trainer.WritePointerFloat(processNameDX9, baseAddress + fovAddress, offsetCurrentDisplayedFOV, fov);
}
}
else
{
if (readCurrentDisplayedFOV != fov && useAlternativePointer < 99)
{
if (useAlternativePointer == 1)
Trainer.WritePointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentDisplayFOVDX11Alternative, fov);
else if (useAlternativePointer == 2)
Trainer.WritePointerFloat(processNameDX11, baseAddress + fovAddressDX11Alternative2, offsetCurrentDisplayFOVDX11Alternative2, fov);
else
Trainer.WritePointerFloat(processNameDX11, baseAddress + fovAddressDX11, offsetCurrentDisplayFOVDX11, fov);
}
}
}
}
//////////////////////////
// Calculator functions //
//////////////////////////
public double ConvertToDegrees(double angle)
{
return angle * (180.0 / Math.PI);
}
public double ConvertToRadians(double angle)
{
return Math.PI * angle / 180.0;
}
public float VerticalRadiansToHorizontalFOV(float angle)
{
double dHorizontalRadians, dHorizontalFOV;
dHorizontalRadians = 2 * Math.Atan(Math.Tan(Convert.ToDouble(angle) / 2) * (4 * 1.0 / 3 * 1.0));
dHorizontalFOV = ConvertToDegrees(dHorizontalRadians);
return Convert.ToSingle(Math.Round(dHorizontalFOV, 3));
}
public float HorizontalFOVToVerticalRadians(float angle)
{
double dHorizontalRadians, dVertialRadians;
dHorizontalRadians = ConvertToRadians(Convert.ToDouble(angle));
dVertialRadians = 2 * Math.Atan(Math.Tan(dHorizontalRadians / 2) * (3 * 1.0 / 4 * 1.0));
return Convert.ToSingle(Math.Round(dVertialRadians, 3));
}
/////////////////////////////////
// End of calculator functions //
/////////////////////////////////
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (settingInputKey)
{
Key = keyData;
B_Key.Text = Key.ToString();
B_Key.Checked = false;
InitHotkey();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
private void B_Key_CheckedChanged(object sender, EventArgs e)
{
if (B_Key.Checked)
{
settingInputKey = true;
B_Key.Text = "";
}
else
{
settingInputKey = false;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
UnHook();
}
// Lazy way to do it i know, it would be better with events
private void C_AutoMode_CheckedChanged(object sender, EventArgs e)
{
if (C_AutoMode.Checked)
{
autoMode = true;
B_Key.Enabled = true;
InitHotkey();
}
else
{
autoMode = false;
UnHook();
}
}
private void B_set_Click(object sender, EventArgs e)
{
var res = 0f;
if (float.TryParse(T_Input.Text, out res))
{
if(res<1)
{
res = 1;
T_Input.Text = "1";
}
if(res>170)
{
res = 170;
T_Input.Text = "170";
}
fov = HorizontalFOVToVerticalRadians(res);
}
}
private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(PCGWUrl);
}
private void RButton_DX9_CheckedChanged(object sender, EventArgs e)
{
if (RButton_DX9.Checked)
{
RButton_DX11.Checked = false;
isDX11 = false;
}
}
private void RButton_DX11_CheckedChanged(object sender, EventArgs e)
{
if (RButton_DX11.Checked)
{
RButton_DX9.Checked = false;
isDX11 = true;
}
}
}
}