Skip to content

Commit 8344069

Browse files
committed
modified: source/fixes/TheWatchmakerWidescreenFix/dllmain.cpp
modified: source/fixes/TonkaSpaceStationWidescreenFix/dllmain.cpp
1 parent 43409b6 commit 8344069

2 files changed

Lines changed: 14 additions & 39 deletions

File tree

source/fixes/TheWatchmakerWidescreenFix/dllmain.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,7 @@ bool DetectGame()
220220
return false;
221221
}
222222

223-
while ((dllModule2 = GetModuleHandleA("render.dll")) == nullptr)
224-
{
225-
spdlog::warn("render.dll not loaded yet. Waiting...");
226-
}
227-
228-
spdlog::info("Successfully obtained handle for render.dll: 0x{:X}", reinterpret_cast<uintptr_t>(dllModule2));
223+
dllModule2 = Memory::GetHandle("render.dll");
229224

230225
return true;
231226
}
@@ -253,7 +248,7 @@ void WidescreenFix()
253248
fAspectRatioScale = fNewAspectRatio / fOldAspectRatio;
254249

255250
std::vector<std::uint8_t*> ResolutionInstructionsScansResult = Memory::PatternScan(exeModule, "89 0D 18 B2 62 00 89 15 1C B2 62 00 BF 01 00 00 00 BE C4 F4 55 00", "8B 0D 40 55 AE 00 8B 15 90 55 AE 00 56 57", "68 ?? ?? ?? ?? 68 ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 68",
256-
dllModule2, "A1 ?? ?? ?? ?? 8B 0D ?? ?? ?? ?? 89 35", "89 0D ?? ?? ?? ?? 89 15 ?? ?? ?? ?? 5E", "89 35 ?? ?? ?? ?? 89 35 ?? ?? ?? ?? 89 35 ?? ?? ?? ?? 89 35", "A3 ?? ?? ?? ?? 8B 44 24 ?? 6A 00 6A 00 68 ?? ?? ?? ?? 50 89 7C 24 ?? FF D6 85 C0 0F 85 ?? ?? ?? ?? 8B 44 24 ?? 85 C0 0F 84 ?? ?? ?? ?? 8B 4C 24 ?? 8D 54 24 ?? 8D 44 24 ?? 52 50 89 0D ?? ?? ?? ??");
251+
dllModule2, "A1 ?? ?? ?? ?? 8B 0D ?? ?? ?? ?? 89 35", "89 0D ?? ?? ?? ?? 89 15 ?? ?? ?? ?? 5E", "89 35 ?? ?? ?? ?? 89 35 ?? ?? ?? ?? 89 35 ?? ?? ?? ?? 89 35", "A3 ?? ?? ?? ?? 8B 44 24 ?? 6A 00 6A 00 68 ?? ?? ?? ?? 50 89 7C 24 ?? FF D6 85 C0 0F 85 ?? ?? ?? ?? 8B 44 24 ?? 85 C0 0F 84 ?? ?? ?? ?? 8B 4C 24 ?? 8D 54 24 ?? 8D 44 24 ?? 52 50 89 0D ?? ?? ?? ??");
257252
if (Memory::AreAllSignaturesValid(ResolutionInstructionsScansResult) == true)
258253
{
259254
spdlog::info("Resolution Instructions 1 Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScansResult[Resolution1Scan] - (std::uint8_t*)exeModule);
@@ -286,7 +281,7 @@ void WidescreenFix()
286281

287282
ResolutionHeight7Address = Memory::GetPointerFromAddress<uint32_t>(ResolutionInstructionsScansResult[Resolution7Scan] + 61, Memory::PointerMode::Absolute);
288283

289-
Memory::PatchBytes(ResolutionInstructionsScansResult[Resolution1Scan], "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", 12);
284+
Memory::WriteNOPs(ResolutionInstructionsScansResult[Resolution1Scan], 12);
290285

291286
static SafetyHookMid ResolutionInstructions1MidHook{};
292287

@@ -312,7 +307,7 @@ void WidescreenFix()
312307
Memory::Write(ResolutionInstructionsScansResult[Resolution3Scan] + 1, iCurrentResY);
313308
*/
314309

315-
Memory::PatchBytes(ResolutionInstructionsScansResult[Resolution4Scan], "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", 11);
310+
Memory::WriteNOPs(ResolutionInstructionsScansResult[Resolution4Scan], 11);
316311

317312
static SafetyHookMid ResolutionInstructions4MidHook{};
318313

@@ -323,7 +318,7 @@ void WidescreenFix()
323318
ctx.ecx = std::bit_cast<uintptr_t>(iCurrentResY);
324319
});
325320

326-
Memory::PatchBytes(ResolutionInstructionsScansResult[Resolution5Scan], "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", 12);
321+
Memory::WriteNOPs(ResolutionInstructionsScansResult[Resolution5Scan], 12);
327322

328323
static SafetyHookMid ResolutionInstructions5MidHook{};
329324

@@ -334,7 +329,7 @@ void WidescreenFix()
334329
*reinterpret_cast<int*>(ResolutionHeight5Address) = iCurrentResY;
335330
});
336331

337-
Memory::PatchBytes(ResolutionInstructionsScansResult[Resolution6Scan], "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90", 12);
332+
Memory::WriteNOPs(ResolutionInstructionsScansResult[Resolution6Scan], 12);
338333

339334
static SafetyHookMid ResolutionInstructions6MidHook{};
340335

@@ -345,7 +340,7 @@ void WidescreenFix()
345340
*reinterpret_cast<int*>(ResolutionHeight6Address) = iCurrentResY;
346341
});
347342

348-
Memory::PatchBytes(ResolutionInstructionsScansResult[Resolution7Scan], "\x90\x90\x90\x90\x90", 5);
343+
Memory::WriteNOPs(ResolutionInstructionsScansResult[Resolution7Scan], 5);
349344

350345
static SafetyHookMid ResolutionWidthInstruction7MidHook{};
351346

@@ -354,7 +349,7 @@ void WidescreenFix()
354349
*reinterpret_cast<int*>(ResolutionWidth7Address) = iCurrentResX;
355350
});
356351

357-
Memory::PatchBytes(ResolutionInstructionsScansResult[Resolution7Scan] + 59, "\x90\x90\x90\x90\x90\x90", 6);
352+
Memory::WriteNOPs(ResolutionInstructionsScansResult[Resolution7Scan] + 59, 6);
358353

359354
static SafetyHookMid ResolutionHeightInstruction7MidHook{};
360355

@@ -369,7 +364,7 @@ void WidescreenFix()
369364
{
370365
spdlog::info("Camera FOV Instruction: Address is render.dll+{:x}", CameraFOVInstructionScanResult - (std::uint8_t*)dllModule2);
371366

372-
Memory::PatchBytes(CameraFOVInstructionScanResult, "\x90\x90\x90\x90", 4);
367+
Memory::WriteNOPs(CameraFOVInstructionScanResult, 4);
373368

374369
CameraFOVInstructionHook = safetyhook::create_mid(CameraFOVInstructionScanResult, CameraFOVInstructionMidHook);
375370
}

source/fixes/TonkaSpaceStationWidescreenFix/dllmain.cpp

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void WidescreenFix()
200200

201201
fAspectRatioScale = fNewAspectRatio / fOldAspectRatio;
202202

203-
std::uint8_t* ResolutionInstructionsScanResult = Memory::PatternScan(exeModule, "C7 05 BC 7E 47 00 80 02 00 00 39 1D C0 7E 47 00 75 0A C7 05 C0 7E 47 00 E0 01 00 00");
203+
std::uint8_t* ResolutionInstructionsScanResult = Memory::PatternScan(exeModule, "C7 05 ?? ?? ?? ?? ?? ?? ?? ?? 39 1D ?? ?? ?? ?? 75 ?? C7 05 ?? ?? ?? ?? ?? ?? ?? ?? 39 1D");
204204
if (ResolutionInstructionsScanResult)
205205
{
206206
spdlog::info("Resolution Instructions Scan: Address is {:s}+{:x}", sExeName.c_str(), ResolutionInstructionsScanResult - (std::uint8_t*)exeModule);
@@ -215,36 +215,16 @@ void WidescreenFix()
215215
return;
216216
}
217217

218-
std::uint8_t* AspectRatioInstructionScanResult = Memory::PatternScan(exeModule, "D8 4A ?? D9 42");
219-
if (AspectRatioInstructionScanResult)
220-
{
221-
spdlog::info("Aspect Ratio Instruction: Address is {:s}+{:x}", sExeName.c_str(), AspectRatioInstructionScanResult - (std::uint8_t*)exeModule);
222-
223-
Memory::PatchBytes(AspectRatioInstructionScanResult, "\x90\x90\x90", 3);
224-
225-
fNewAspectRatio2 = 1.0f / fNewAspectRatio;
226-
227-
AspectRatioInstructionHook = safetyhook::create_mid(AspectRatioInstructionScanResult, [](SafetyHookContext& ctx)
228-
{
229-
FPU::FMUL(fNewAspectRatio2);
230-
});
231-
}
232-
else
233-
{
234-
spdlog::error("Failed to locate aspect ratio instruction memory address.");
235-
return;
236-
}
237-
238-
std::uint8_t* CameraFOVInstructionScanResult = Memory::PatternScan(exeModule, "D9 F2 DD D8 D8 3D ?? ?? ?? ?? D9 C0");
218+
std::uint8_t* CameraFOVInstructionScanResult = Memory::PatternScan(exeModule, "D8 3D ?? ?? ?? ?? D9 C0 D8 4A");
239219
if (CameraFOVInstructionScanResult)
240220
{
241-
spdlog::info("Camera FOV Instruction: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionScanResult + 4 - (std::uint8_t*)exeModule);
221+
spdlog::info("Camera FOV Instruction: Address is {:s}+{:x}", sExeName.c_str(), CameraFOVInstructionScanResult - (std::uint8_t*)exeModule);
242222

243-
Memory::PatchBytes(CameraFOVInstructionScanResult + 4, "\x90\x90\x90\x90\x90\x90", 6);
223+
Memory::WriteNOPs(CameraFOVInstructionScanResult, 6);
244224

245225
fNewCameraFOV = fOriginalCameraFOV / fFOVFactor;
246226

247-
CameraFOVInstructionHook = safetyhook::create_mid(CameraFOVInstructionScanResult + 4, [](SafetyHookContext& ctx)
227+
CameraFOVInstructionHook = safetyhook::create_mid(CameraFOVInstructionScanResult, [](SafetyHookContext& ctx)
248228
{
249229
FPU::FDIVR(fNewCameraFOV);
250230
});

0 commit comments

Comments
 (0)