Skip to content

Commit 0f75a96

Browse files
committed
Yourself!Fitness: Made the fix calculate aspect ratio and FOV automatically from the in-game resolution
1 parent 74cd1c8 commit 0f75a96

2 files changed

Lines changed: 88 additions & 74 deletions

File tree

project/Yourself!FitnessFOVFix.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<LanguageStandard>stdcpplatest</LanguageStandard>
109109
<LanguageStandard_C>stdclatest</LanguageStandard_C>
110110
<DebugInformationFormat>None</DebugInformationFormat>
111-
<Optimization>Disabled</Optimization>
111+
<Optimization>MaxSpeed</Optimization>
112112
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
113113
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
114114
</ClCompile>

source/fixes/Yourself!FitnessFOVFix/dllmain.cpp

Lines changed: 87 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ HMODULE thisModule;
2626

2727
// Fix details
2828
std::string sFixName = "Yourself!FitnessFOVFix";
29-
std::string sFixVersion = "1.2";
29+
std::string sFixVersion = "1.3";
3030
std::filesystem::path sFixPath;
3131

3232
// Ini
@@ -44,17 +44,15 @@ constexpr float fOldAspectRatio = 4.0f / 3.0f;
4444

4545
// Ini variables
4646
bool bFixActive;
47-
int iCurrentResX;
48-
int iCurrentResY;
4947
double dFOVFactor;
5048

5149
// Variables
5250
float fNewAspectRatio;
5351
float fAspectRatioScale;
5452
float fNewAspectRatio2;
5553
double dNewCameraFOV;
56-
uint8_t* CameraFOV1Address;
57-
uint8_t* CameraFOV2Address;
54+
uintptr_t CameraFOV1Address;
55+
uintptr_t CameraFOV2Address;
5856

5957
// Game detection
6058
enum class Game
@@ -63,12 +61,18 @@ enum class Game
6361
Unknown
6462
};
6563

64+
enum ResolutionInstructionsIndices
65+
{
66+
Res1,
67+
Res2
68+
};
69+
6670
enum CameraFOVInstructionsIndices
6771
{
68-
FOV1Scan,
69-
FOV2Scan,
70-
FOV3Scan,
71-
FOV4Scan
72+
FOV1,
73+
FOV2,
74+
FOV3,
75+
FOV4
7276
};
7377

7478
struct GameInfo
@@ -158,25 +162,9 @@ void Configuration()
158162
spdlog_confparse(bFixActive);
159163

160164
// Load resolution from ini
161-
inipp::get_value(ini.sections["Settings"], "Width", iCurrentResX);
162-
inipp::get_value(ini.sections["Settings"], "Height", iCurrentResY);
163165
inipp::get_value(ini.sections["Settings"], "FOVFactor", dFOVFactor);
164-
spdlog_confparse(iCurrentResX);
165-
spdlog_confparse(iCurrentResY);
166166
spdlog_confparse(dFOVFactor);
167167

168-
// If resolution not specified, use desktop resolution
169-
if (iCurrentResX <= 0 || iCurrentResY <= 0)
170-
{
171-
spdlog::info("Resolution not specified in ini file. Using desktop resolution.");
172-
// Implement Util::GetPhysicalDesktopDimensions() accordingly
173-
auto desktopDimensions = Util::GetPhysicalDesktopDimensions();
174-
iCurrentResX = desktopDimensions.first;
175-
iCurrentResY = desktopDimensions.second;
176-
spdlog_confparse(iCurrentResX);
177-
spdlog_confparse(iCurrentResY);
178-
}
179-
180168
spdlog::info("----------");
181169
}
182170

@@ -198,13 +186,14 @@ bool DetectGame()
198186
return false;
199187
}
200188

201-
static SafetyHookMid AspectRatioInstructionHook{};
189+
static SafetyHookMid ResolutionInstructions1Hook{};
190+
static SafetyHookMid ResolutionInstructions2Hook{};
202191
static SafetyHookMid CameraFOVInstruction1Hook{};
203192
static SafetyHookMid CameraFOVInstruction2Hook{};
204193
static SafetyHookMid CameraFOVInstruction3Hook{};
205194
static SafetyHookMid CameraFOVInstruction4Hook{};
206195

207-
void CameraFOVInstructionsMidHook(uint8_t* FOVAddress, double fovFactor = 1.0)
196+
void CameraFOVInstructionsMidHook(uintptr_t FOVAddress, double fovFactor = 1.0)
208197
{
209198
double& dCurrentCameraFOV = Memory::ReadMem(FOVAddress);
210199

@@ -213,77 +202,102 @@ void CameraFOVInstructionsMidHook(uint8_t* FOVAddress, double fovFactor = 1.0)
213202
FPU::FLD(dNewCameraFOV);
214203
}
215204

216-
void FOVFix()
205+
void SetARAndFOV()
217206
{
218-
if (eGameType == Game::YF && bFixActive == true)
207+
std::uint8_t* AspectRatioInstructionScanResult = Memory::PatternScan(exeModule, "D8 0D ?? ?? ?? ?? 8B 54 24 ?? 89 0C");
208+
if (AspectRatioInstructionScanResult)
219209
{
220-
fNewAspectRatio = static_cast<float>(iCurrentResX) / static_cast<float>(iCurrentResY);
210+
spdlog::info("Aspect Ratio Instruction: Address is {:s}+{:x}", sExeName.c_str(), AspectRatioInstructionScanResult - (std::uint8_t*)exeModule);
221211

222-
fAspectRatioScale = fNewAspectRatio / fOldAspectRatio;
212+
Memory::Write(AspectRatioInstructionScanResult + 2, &fNewAspectRatio2);
213+
}
214+
else
215+
{
216+
spdlog::error("Failed to locate aspect ratio instruction memory address.");
217+
return;
218+
}
223219

224-
std::uint8_t* AspectRatioInstructionScanResult = Memory::PatternScan(exeModule, "D8 0D ?? ?? ?? ?? 8B 54 24 ?? 89 0C");
225-
if (AspectRatioInstructionScanResult)
226-
{
227-
spdlog::info("Aspect Ratio Instruction: Address is {:s}+{:x}", sExeName.c_str(), AspectRatioInstructionScanResult - (std::uint8_t*)exeModule);
220+
std::vector<std::uint8_t*> CameraFOVInstructionsScansResult = Memory::PatternScan(exeModule, "DD 05 ?? ?? ?? ?? 53", "DD 05 ?? ?? ?? ?? D9 F2",
221+
"DD 05 ?? ?? ?? ?? 8B 0D", "DD 05 ?? ?? ?? ?? A1");
222+
if (Memory::AreAllSignaturesValid(CameraFOVInstructionsScansResult) == true)
223+
{
224+
spdlog::info("Camera FOV Instruction 1: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV1] - (std::uint8_t*)exeModule);
228225

229-
fNewAspectRatio2 = 0.75f / fAspectRatioScale;
226+
spdlog::info("Camera FOV Instruction 2: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV2] - (std::uint8_t*)exeModule);
230227

231-
Memory::WriteNOPs(AspectRatioInstructionScanResult, 6);
228+
spdlog::info("Camera FOV Instruction 3: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV3] - (std::uint8_t*)exeModule);
232229

233-
AspectRatioInstructionHook = safetyhook::create_mid(AspectRatioInstructionScanResult, [](SafetyHookContext& ctx)
234-
{
235-
FPU::FMUL(fNewAspectRatio2);
236-
});
237-
}
238-
else
230+
spdlog::info("Camera FOV Instruction 4: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV4] - (std::uint8_t*)exeModule);
231+
232+
CameraFOV1Address = Memory::GetPointerFromAddress(CameraFOVInstructionsScansResult[FOV1] + 2, Memory::PointerMode::Absolute);
233+
234+
CameraFOV2Address = Memory::GetPointerFromAddress(CameraFOVInstructionsScansResult[FOV3] + 2, Memory::PointerMode::Absolute);
235+
236+
Memory::WriteNOPs(CameraFOVInstructionsScansResult, FOV1, FOV4, 0, 6);
237+
238+
CameraFOVInstruction1Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV1], [](SafetyHookContext& ctx)
239239
{
240-
spdlog::error("Failed to locate aspect ratio instruction memory address.");
241-
return;
242-
}
240+
CameraFOVInstructionsMidHook(CameraFOV1Address);
241+
});
242+
243+
CameraFOVInstruction2Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV2], [](SafetyHookContext& ctx)
244+
{
245+
CameraFOVInstructionsMidHook(CameraFOV1Address);
246+
});
243247

244-
std::vector<std::uint8_t*> CameraFOVInstructionsScansResult = Memory::PatternScan(exeModule, "DD 05 ?? ?? ?? ?? 53", "DD 05 ?? ?? ?? ?? D9 F2", "DD 05 ?? ?? ?? ?? 8B 0D", "DD 05 ?? ?? ?? ?? A1");
245-
if (Memory::AreAllSignaturesValid(CameraFOVInstructionsScansResult) == true)
248+
CameraFOVInstruction3Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV3], [](SafetyHookContext& ctx)
246249
{
247-
spdlog::info("Camera FOV Instruction 1: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV1Scan] - (std::uint8_t*)exeModule);
250+
CameraFOVInstructionsMidHook(CameraFOV2Address);
251+
});
248252

249-
spdlog::info("Camera FOV Instruction 2: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV2Scan] - (std::uint8_t*)exeModule);
253+
CameraFOVInstruction4Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV4], [](SafetyHookContext& ctx)
254+
{
255+
CameraFOVInstructionsMidHook(CameraFOV1Address, dFOVFactor);
256+
});
257+
}
258+
}
250259

251-
spdlog::info("Camera FOV Instruction 3: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV3Scan] - (std::uint8_t*)exeModule);
260+
void FOVFix()
261+
{
262+
if (eGameType == Game::YF && bFixActive == true)
263+
{
264+
std::vector<std::uint8_t*> ResolutionInstructionsScansResult = Memory::PatternScan(exeModule, "8B 41 ?? 57 8D 79", "8B 44 24 ?? 8B 54 24 ?? 89 41 ?? 89 51");
265+
if (Memory::AreAllSignaturesValid(ResolutionInstructionsScansResult) == true)
266+
{
267+
spdlog::info("Resolution Instructions 1 Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScansResult[Res1] - (std::uint8_t*)exeModule);
252268

253-
spdlog::info("Camera FOV Instruction 4: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionsScansResult[FOV4Scan] - (std::uint8_t*)exeModule);
269+
spdlog::info("Resolution Instructions 2 Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScansResult[Res2] - (std::uint8_t*)exeModule);
254270

255-
CameraFOV1Address = Memory::GetPointerFromAddress(CameraFOVInstructionsScansResult[FOV1Scan] + 2, Memory::PointerMode::Absolute);
271+
ResolutionInstructions1Hook = safetyhook::create_mid(ResolutionInstructionsScansResult[Res1], [](SafetyHookContext& ctx)
272+
{
273+
int& iCurrentWidth = Memory::ReadMem(0x0056E004);
256274

257-
CameraFOV2Address = Memory::GetPointerFromAddress(CameraFOVInstructionsScansResult[FOV3Scan] + 2, Memory::PointerMode::Absolute);
275+
int& iCurrentHeight = Memory::ReadMem(0x0056E008);
258276

259-
Memory::WriteNOPs(CameraFOVInstructionsScansResult[FOV1Scan], 6);
277+
fNewAspectRatio = static_cast<float>(iCurrentWidth) / static_cast<float>(iCurrentHeight);
260278

261-
Memory::WriteNOPs(CameraFOVInstructionsScansResult[FOV2Scan], 6);
279+
fAspectRatioScale = fNewAspectRatio / fOldAspectRatio;
262280

263-
Memory::WriteNOPs(CameraFOVInstructionsScansResult[FOV3Scan], 6);
281+
fNewAspectRatio2 = 0.75f / fAspectRatioScale;
264282

265-
Memory::WriteNOPs(CameraFOVInstructionsScansResult[FOV4Scan], 6);
283+
SetARAndFOV();
266284

267-
CameraFOVInstruction1Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV1Scan], [](SafetyHookContext& ctx)
268-
{
269-
CameraFOVInstructionsMidHook(CameraFOV1Address);
270-
});
271-
272-
CameraFOVInstruction2Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV2Scan], [](SafetyHookContext& ctx)
273-
{
274-
CameraFOVInstructionsMidHook(CameraFOV1Address);
285+
ResolutionInstructions1Hook.disable();
275286
});
276287

277-
CameraFOVInstruction3Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV3Scan], [](SafetyHookContext& ctx)
288+
ResolutionInstructions2Hook = safetyhook::create_mid(ResolutionInstructionsScansResult[Res2], [](SafetyHookContext& ctx)
278289
{
279-
CameraFOVInstructionsMidHook(CameraFOV2Address);
280-
});
290+
int& iCurrentWidth = Memory::ReadMem(ctx.esp + 0x4);
281291

282-
CameraFOVInstruction4Hook = safetyhook::create_mid(CameraFOVInstructionsScansResult[FOV4Scan], [](SafetyHookContext& ctx)
283-
{
284-
CameraFOVInstructionsMidHook(CameraFOV1Address, dFOVFactor);
292+
int& iCurrentHeight = Memory::ReadMem(ctx.esp + 0x8);
293+
294+
fNewAspectRatio = static_cast<float>(iCurrentWidth) / static_cast<float>(iCurrentHeight);
295+
296+
fAspectRatioScale = fNewAspectRatio / fOldAspectRatio;
297+
298+
fNewAspectRatio2 = 0.75f / fAspectRatioScale;
285299
});
286-
}
300+
}
287301
}
288302
}
289303

0 commit comments

Comments
 (0)