-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
331 lines (281 loc) · 6.92 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
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.Collections.Generic;
namespace FovChanger
{
public partial class Form1 : Form
{
public enum Version
{
Steam,
French_1_0
}
public class CurrentPointer
{
public const int ModuleSize_French = 24276992;
public int AspectAdress { get; private set; }
public int FovAddress { get; private set; }
public int[] Offsets { get; private set; }
public int FovInstructionAddress { get; private set; }
public CurrentPointer(Version ver)
{
switch (ver)
{
case Version.French_1_0:
AspectAdress = 0x7AD358;
FovAddress = 0x597080;
Offsets = new int[] { 0x64c };
FovInstructionAddress = 0x0;
break;
default:
AspectAdress = 0x7AC188;
FovAddress = 0x211C98;
Offsets = new int[] { 0x64c };
FovInstructionAddress = 0x00086F76;
break;
}
}
}
// Base address value for pointers.
int baseAddress = 0x0000000;
// Other variables.
Process[] myProcess;
readonly string processName = "rf2";
float fov = 90;
float fovPlus = 120;
static float writeAspect = 1.0f;
int ResX = 1280;
int ResY = 720;
float desiredAspect = 1.7777777f;
float readAspect = 1.777777f;
float readFov = 0;
float readPrevFOV = 0;
float displayedFOV = 0;
CurrentPointer currentPointer;
Keys Key = Keys.Tab;
bool settingInputKey;
bool overwriteInstruction = false;
string labelUrl = "http://www.pcgamingwiki.com";
/*------------------
-- INITIALIZATION --
------------------*/
public Form1()
{
InitializeComponent();
RecalculateValues();
FOVtoFOVWithAspect();
}
bool foundProcess = false;
private void Timer_Tick(object sender, EventArgs e)
{
try
{
myProcess = Process.GetProcessesByName(processName);
if (myProcess.Length > 0)
{
if (foundProcess == false)
{
System.Threading.Thread.Sleep(100);
IntPtr startOffset = myProcess[0].MainModule.BaseAddress;
baseAddress = startOffset.ToInt32();
switch (myProcess[0].MainModule.ModuleMemorySize)
{
case CurrentPointer.ModuleSize_French:
currentPointer = new CurrentPointer(Version.French_1_0);
break;
default:
currentPointer = new CurrentPointer(Version.Steam);
break;
}
}
foundProcess = true;
}
else
foundProcess = false;
if (foundProcess)
{
// The game is running, ready for memory reading.
LB_Running.Text = "RED FACTION 2 IS RUNNING";
LB_Running.ForeColor = Color.Green;
readAspect = Trainer.ReadFloat(myProcess, baseAddress + currentPointer.AspectAdress);
if (readAspect != desiredAspect)
ChangeAspect();
readFov = Trainer.ReadPointerFloat(myProcess, baseAddress + currentPointer.FovAddress, currentPointer.Offsets);
if (readFov != readPrevFOV)
readFOVToDisplayedFOV();
readPrevFOV = readFov;
}
else
{
// The game process has not been found, reseting values.
LB_Running.Text = "RED FACTION 2 IS NOT RUNNING";
LB_Running.ForeColor = Color.Red;
ResetValues();
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
}
}
private void ChangeAspect()
{
if (foundProcess)
{
Trainer.WriteFloat(myProcess, baseAddress + currentPointer.AspectAdress, writeAspect);
}
}
// 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)
{
Timer.Start();
}
public void InitHotkey()
{
if (!KeyGrabber.Hooked)
{
KeyGrabber.keyPressEvent += KeyGrabber_KeyPress;
KeyGrabber.key.Clear();
if (Key != Keys.None)
KeyGrabber.key.Add(Key);
KeyGrabber.SetHook();
}
else
{
if (Key != Keys.None)
{
KeyGrabber.key.Clear();
KeyGrabber.key.Add(Key);
}
}
}
private void RecalculateValues()
{
desiredAspect = ResX * 1.0f / ResY * 1.0f;
}
public void UnHook()
{
KeyGrabber.UnHook();
}
private void KeyGrabber_KeyPress(object sender, EventArgs e)
{
ChangeFov();
if (overwriteInstruction)
ChangeInstruction();
}
void ChangeFov()
{
if (foundProcess && readFov != fovPlus)
Trainer.WritePointerFloat(myProcess, baseAddress + currentPointer.FovAddress, currentPointer.Offsets, fovPlus);
}
void ChangeInstruction()
{
if (foundProcess && currentPointer.FovInstructionAddress != 0)
Trainer.WriteFloat(myProcess, baseAddress + currentPointer.FovInstructionAddress, fovPlus);
}
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 = "";
C_KeyMode.Checked = true;
}
else
{
settingInputKey = false;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
UnHook();
}
private void C_KeyMode_CheckedChanged(object sender, EventArgs e)
{
if (C_KeyMode.Checked)
{
B_Key.Enabled = true;
InitHotkey();
}
else
{
UnHook();
}
}
private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(labelUrl);
}
private void T_Input_TextChanged(object sender, EventArgs e)
{
float temp;
if (float.TryParse(T_Input.Text, out temp))
{
fov = temp;
RecalculateValues();
FOVtoFOVWithAspect();
}
}
private void TB_ResX_TextChanged(object sender, EventArgs e)
{
int temp;
if (int.TryParse(TB_ResX.Text, out temp))
{
ResX = temp;
RecalculateValues();
FOVtoFOVWithAspect();
}
}
private void TB_ResY_TextChanged(object sender, EventArgs e)
{
int temp;
if (int.TryParse(TB_ResY.Text, out temp))
{
ResY = temp;
RecalculateValues();
FOVtoFOVWithAspect();
}
}
///////////////////////////////
///CALCULATOR FUNCTIONS////////
///////////////////////////////
private void FOVtoFOVWithAspect()
{
fovPlus = (fov * desiredAspect) / 1.333333333f;
}
private void readFOVToDisplayedFOV()
{
displayedFOV = readFov * 1.33333333f / desiredAspect;
L_fov.Text = displayedFOV.ToString();
}
private void C_OverwriteInstructions_CheckedChanged(object sender, EventArgs e)
{
if (C_OverwriteInstructions.Checked)
{
MessageBox.Show("This option can crash a game, but it should prevent from FOV reseting to default value after cutscenes. If you're having problems with the game's stability, disable this option.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
overwriteInstruction = true;
}
else
overwriteInstruction = false;
}
}
}