-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEliteForcesWW2IwoJimaFOVFix.cpp
269 lines (217 loc) · 10.1 KB
/
EliteForcesWW2IwoJimaFOVFix.cpp
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdint> // For uint32_t variable type
#include <windows.h>
#include <cmath>
#include <limits>
#include <conio.h> // For getch() function [get character]
#include <string>
#include <algorithm>
using namespace std;
// Constants
const double kPi = 3.14159265358979323846;
const double kTolerance = 0.01;
const double kDefaultCameraVerticalFOVInRadians = 1.1780972480773926;
const streampos kCameraHorizontalFOVOffset = 0x00099601;
const streampos kCameraVerticalFOVOffset = 0x000995FC;
// Variables
int choice1, choice2, tempChoice;
uint32_t newWidth, newHeight;
bool fileNotFound, validKeyPressed;
double currentCameraHorizontalFOVInRadians, currentCameraVerticalFOVInRadians, newCameraHorizontalFOVInRadians, newCameraVerticalFOVInRadians, currentCameraHorizontalFOVInDegrees, currentCameraVerticalFOVInDegrees, newCameraHorizontalFOVInDegrees, newCameraHorizontalFOVInDegreesValue, newCameraVerticalFOVInDegrees, oldWidth = 4.0, oldHeight = 3.0, oldCameraHorizontalFOV = 90.0, oldAspectRatio = oldWidth / oldHeight, newAspectRatio;
string descriptor, input;
fstream file;
char ch;
// Function to convert degrees to radians
double DegToRad(double degrees)
{
return degrees * (kPi / 180.0);
}
// Function to convert radians to degrees
double RadToDeg(double radians)
{
return radians * (180.0 / kPi);
}
// Function to handle user input in choices
void HandleChoiceInput(int &choice)
{
tempChoice = -1; // Temporary variable to store the input
validKeyPressed = false; // Flag to track if a valid key was pressed
while (true)
{
ch = _getch(); // Waits for user to press a key
// Checks if the key is '1' or '2'
if ((ch == '1' || ch == '2') && !validKeyPressed)
{
tempChoice = ch - '0'; // Converts char to int and stores the input temporarily
cout << ch; // Echoes the valid input
validKeyPressed = true; // Sets the flag as a valid key has been pressed
}
else if (ch == '\b' || ch == 127) // Handles backspace or delete keys
{
if (tempChoice != -1) // Checks if there is something to delete
{
tempChoice = -1; // Resets the temporary choice
cout << "\b \b"; // Erases the last character from the console
validKeyPressed = false; // Resets the flag as the input has been deleted
}
}
// If 'Enter' is pressed and a valid key has been pressed prior
else if (ch == '\r' && validKeyPressed)
{
choice = tempChoice; // Assigns the temporary input to the choice variable
cout << endl; // Moves to a new line
break; // Exits the loop since we have a confirmed input
}
}
}
void HandleFOVInput(double &newCustomFOVInDegrees)
{
do
{
// Reads the input as a string
cin >> input;
// Replaces all commas with dots
replace(input.begin(), input.end(), ',', '.');
// Parses the string to a double
newCustomFOVInDegrees = stod(input);
if (cin.fail())
{
cin.clear(); // Clears error flags
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Ignores invalid input
cout << "Invalid input. Please enter a numeric value." << endl;
}
else if (newCustomFOVInDegrees <= 0 || newCustomFOVInDegrees >= 180)
{
cout << "Please enter a valid number for the FOV (greater than 0 and less than 180)." << endl;
}
} while (newCustomFOVInDegrees <= 0 || newCustomFOVInDegrees >= 180);
}
void HandleResolutionInput(uint32_t &newCustomResolutionValue)
{
do
{
cin >> newCustomResolutionValue;
cin.clear(); // Clears error flags
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Ignores invalid input
if (cin.fail())
{
cin.clear(); // Clears error flags
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Ignores invalid input
cout << "Invalid input. Please enter a numeric value." << endl;
}
else if (newCustomResolutionValue <= 0 || newCustomResolutionValue >= 65535)
{
cout << "Please enter a valid number." << endl;
}
} while (newCustomResolutionValue <= 0 || newCustomResolutionValue > 65535);
}
// Function to open the file
void OpenFile(fstream &file, const string &filename)
{
fileNotFound = false;
file.open(filename, ios::in | ios::out | ios::binary);
// If the file is not open, sets fileNotFound to true
if (!file.is_open())
{
fileNotFound = true;
}
// Loops until the file is found and opened
while (fileNotFound)
{
// Tries to open the file again
file.open(filename, ios::in | ios::out | ios::binary);
if (!file.is_open())
{
cout << "\nFailed to open " << filename << ", check if the DLL file has special permissions allowed that prevent the fixer from opening it (e.g: read-only mode), it's not present in the same directory as the fixer, or if the DLL is currently being used. Press Enter when all the mentioned problems are solved." << endl;
do
{
ch = _getch(); // Wait for user to press a key
} while (ch != '\r'); // Keep waiting if the key is not Enter ('\r' is the Enter key in ASCII)
}
else
{
cout << "\n" << filename << " opened successfully!" << endl;
fileNotFound = false; // Sets fileNotFound to false as the file is found and opened
}
}
}
double NewHorizontalCameraFOVInDegreesCalculation(uint32_t &newWidthValue, uint32_t &newHeightValue)
{
newCameraHorizontalFOVInDegreesValue = 2.0 * RadToDeg(atan((static_cast<double>(newWidthValue) / static_cast<double>(newHeightValue)) / oldAspectRatio) * tan(DegToRad(oldCameraHorizontalFOV / 2.0)));
return newCameraHorizontalFOVInDegreesValue;
}
int main()
{
SetConsoleOutputCP(CP_UTF8);
cout << "Elite Forces: WWII Iwo Jima (2001) FOV Fixer v1.4 by AlphaYellow, 2024\n\n----------------\n";
do
{
OpenFile(file, "client.exe");
file.seekg(kCameraHorizontalFOVOffset);
file.read(reinterpret_cast<char *>(¤tCameraHorizontalFOVInRadians), sizeof(currentCameraHorizontalFOVInRadians));
file.seekg(kCameraVerticalFOVOffset);
file.read(reinterpret_cast<char *>(¤tCameraVerticalFOVInRadians), sizeof(currentCameraVerticalFOVInRadians));
file.close();
// Converts the FOV values from radians to degrees
currentCameraHorizontalFOVInDegrees = RadToDeg(currentCameraHorizontalFOVInRadians);
currentCameraVerticalFOVInDegrees = RadToDeg(currentCameraVerticalFOVInRadians);
cout << "\nCurrent FOV: " << currentCameraHorizontalFOVInDegrees << "\u00B0 (Horizontal); " << currentCameraVerticalFOVInDegrees << "\u00B0 (Vertical)\n";
cout << "\n- Do you want to set FOV automatically based on the desired resolution (1) or set custom horizontal and vertical FOV values (2)?: ";
HandleChoiceInput(choice1);
switch (choice1)
{
case 1:
cout << "\n- Enter the desired width: ";
HandleResolutionInput(newWidth);
cout << "\n- Enter the desired height: ";
HandleResolutionInput(newHeight);
newCameraHorizontalFOVInDegrees = NewHorizontalCameraFOVInDegreesCalculation(newWidth, newHeight);
newCameraHorizontalFOVInRadians = DegToRad(newCameraHorizontalFOVInDegrees); // Converts degrees to radians
newCameraVerticalFOVInRadians = kDefaultCameraVerticalFOVInRadians;
newCameraVerticalFOVInDegrees = RadToDeg(newCameraVerticalFOVInRadians);
descriptor = "automatically";
break;
case 2:
cout << "\n- Enter the desired horizontal FOV (in degrees, default for 4:3 is 90\u00B0): ";
HandleFOVInput(newCameraHorizontalFOVInDegrees);
cout << "\n- Enter the desired vertical FOV (in degrees, default for 4:3 is 67.5\u00B0): ";
HandleFOVInput(newCameraVerticalFOVInDegrees);
newCameraHorizontalFOVInRadians = DegToRad(newCameraHorizontalFOVInDegrees); // Converts degrees to radians
newCameraVerticalFOVInRadians = DegToRad(newCameraVerticalFOVInDegrees); // Converts degrees to radians
descriptor = "manually";
break;
}
OpenFile(file, "client.exe");
file.seekp(kCameraHorizontalFOVOffset);
file.write(reinterpret_cast<const char *>(&newCameraHorizontalFOVInRadians), sizeof(newCameraHorizontalFOVInRadians));
file.seekp(kCameraVerticalFOVOffset);
file.write(reinterpret_cast<const char *>(&newCameraVerticalFOVInRadians), sizeof(newCameraVerticalFOVInRadians));
// Checks if any errors occurred during the file operations
if (file.good())
{
// Confirmation message
cout << "\nSuccessfully changed " << descriptor << " the horizontal FOV to " << newCameraHorizontalFOVInDegrees << "\u00B0 and vertical FOV to " << newCameraVerticalFOVInDegrees << "\u00B0."
<< endl;
}
else
{
cout << "\nError(s) occurred during the file operations." << endl;
}
// Closes the file
file.close();
cout << "\n- Do you want to exit the program (1) or try another value (2)?: ";
HandleChoiceInput(choice2);
if (choice2 == 1)
{
cout << "\nPress enter to exit the program...";
do
{
ch = _getch(); // Wait for user to press a key
} while (ch != '\r'); // Keep waiting if the key is not Enter ('\r' is the Enter key in ASCII)
return 0;
}
cout << "\n-----------------------------------------\n";
} while (choice2 == 2); // Checks the flag in the loop condition
}