-
Notifications
You must be signed in to change notification settings - Fork 0
/
MadeManConfessionsOfTheFamilyBloodWidescreenFix.cpp
247 lines (202 loc) · 8.56 KB
/
MadeManConfessionsOfTheFamilyBloodWidescreenFix.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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <conio.h> // For getch() function [get character]
#include <cstdint> // For uint32_t variable type
#include <limits>
#include <string>
#include <algorithm>
using namespace std;
// Constants
const streampos kAspectRatioOffset = 0x00237BE8;
const streampos kCameraFOVOffset = 0x001FCB31;
const streampos kResolutionWidth1Offset = 0x001FCB71;
const streampos kResolutionHeight1Offset = 0x001FCB61;
const streampos kResolutionWidth2Offset = 0x001FCB3C;
const streampos kResolutionHeight2Offset = 0x001FCB4C;
// Variables
uint32_t currentWidth, currentHeight, newWidth, newHeight;
fstream file;
string input, descriptor;
int choice1, choice2, tempChoice;
bool fileNotFound, validKeyPressed;
double newAspectRatio, newCameraFOV, newCameraFOVValue;
char ch;
// 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 &customFOVMultiplier)
{
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
customFOVMultiplier = 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 (customFOVMultiplier <= 0)
{
cout << "Please enter a number greater than 0 for the FOV." << endl;
}
} while (customFOVMultiplier <= 0);
}
// Function to handle user input in resolution
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 executable 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 it's currently running. Press Enter when all the mentioned problems are solved." << endl;
do
{
ch = _getch(); // Waits for user to press a key
} while (ch != '\r'); // Keeps 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 NewCameraFOVCalculation(uint32_t &newWidthValue, uint32_t &newHeightValue)
{
newCameraFOVValue = (4.0 / 3.0) / (static_cast<double>(newWidthValue) / static_cast<double>(newHeightValue));
return newCameraFOVValue;
}
int main()
{
cout << "Made Man: Confessions of the Family Blood (2006) Widescreen Fixer v1.0 by AlphaYellow, 2024\n\n----------------\n";
do
{
OpenFile(file, "IMM.exe");
file.seekg(kResolutionWidth1Offset);
file.read(reinterpret_cast<char *>(¤tWidth), sizeof(currentWidth));
file.seekg(kResolutionHeight1Offset);
file.read(reinterpret_cast<char *>(¤tHeight), sizeof(currentHeight));
cout << "\nCurrent resolution is " << currentWidth << "x" << currentHeight << "." << endl;
cout << "\n- Enter the desired width: ";
HandleResolutionInput(newWidth);
cout << "\n- Enter the desired height: ";
HandleResolutionInput(newHeight);
newAspectRatio = static_cast<double>(newWidth) / static_cast<double>(newHeight);
file.seekp(kResolutionWidth1Offset);
file.write(reinterpret_cast<const char *>(&newWidth), sizeof(newWidth));
file.seekp(kResolutionHeight1Offset);
file.write(reinterpret_cast<const char *>(&newHeight), sizeof(newHeight));
file.seekp(kResolutionWidth2Offset);
file.write(reinterpret_cast<const char *>(&newWidth), sizeof(newWidth));
file.seekp(kResolutionHeight2Offset);
file.write(reinterpret_cast<const char *>(&newHeight), sizeof(newHeight));
file.seekp(kAspectRatioOffset);
file.write(reinterpret_cast<const char *>(&newAspectRatio), sizeof(newAspectRatio));
cout << "\n- Do you want to fix the FOV automatically based on the resolution typed above (1) or set a custom FOV multiplier value (2)?: ";
HandleChoiceInput(choice1);
switch (choice1)
{
case 1:
newCameraFOV = NewCameraFOVCalculation(newWidth, newHeight);
descriptor = "";
break;
case 2:
cout << "\n- Enter a custom FOV multiplier value (default value for 4:3 aspect ratio is 1.0, a lower value increases FOV and a higher one decreases it): ";
HandleFOVInput(newCameraFOV);
descriptor = "changed the ";
break;
}
file.seekp(kCameraFOVOffset);
file.write(reinterpret_cast<const char *>(&newCameraFOV), sizeof(newCameraFOV));
// Checks if any errors occurred during the file operations
if (file.good())
{
// Confirmation message
cout << "\nSuccessfully fixed the resolution, aspect ratio and " << descriptor << "field of view." << 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(); // Waits for user to press a key
} while (ch != '\r'); // Keeps 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
}