From 8414ed4208f01645739b67eb871a265ccee83d6d Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 18 Mar 2024 23:47:51 +0100 Subject: [PATCH] Null terminate read lines in CPlane::LoadPath and CTrain::ReadAndInterpretTrackFile --- SilentPatchIII/SilentPatchIII.cpp | 62 +++++++++++++++++++++++++++++++ SilentPatchVC/SilentPatchVC.cpp | 26 +++++++++++++ 2 files changed, 88 insertions(+) diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index 9483816..abbcb6a 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -574,6 +574,48 @@ namespace EvasiveDiveFix } +// ============= Null terminate read lines in CPlane::LoadPath and CTrain::ReadAndInterpretTrackFile ============= +namespace NullTerminatedLines +{ + static char* gString; + + static void* orgSscanf_LoadPath; + __declspec(naked) static void sscanf1_LoadPath_Terminate() + { + _asm + { + mov eax, [esp+4] + mov byte ptr [eax+ecx], 0 + jmp [orgSscanf_LoadPath] + } + } + + static void* orgSscanf1; + __declspec(naked) static void sscanf1_Terminate() + { + _asm + { + mov eax, [esp+4] + mov byte ptr [eax+ecx], 0 + jmp [orgSscanf1] + } + } + + __declspec(naked) static void ReadTrackFile_Terminate() + { + _asm + { + mov ecx, [gString] + mov byte ptr [ecx+edx], 0 + mov ecx, [esi] + inc ebp + add ecx, [esp+0ACh-98h] + retn + } + } +} + + void InjectDelayedPatches_III_Common( bool bHasDebugMenu, const wchar_t* wcModulePath ) { using namespace Memory; @@ -1404,6 +1446,26 @@ void Patch_III_Common() Patch(probability_do_nothing, 35000u * 32767u / 100000u); Patch(probability_flee, 75000u * 32767u / 100000u); } + + + // Null terminate read lines in CPlane::LoadPath and CTrain::ReadAndInterpretTrackFile + { + using namespace NullTerminatedLines; + + auto loadPath = get_pattern("DD D8 45 E8", 3); + auto readTrackFile1 = pattern("E8 ? ? ? ? 0F BF 07").get_one(); + auto readTrackFile2 = pattern(" 8B 0E 45 03 4C 24 10").get_one(); + + gString = *readTrackFile1.get(-5 + 1); + + InterceptCall(loadPath, orgSscanf_LoadPath, sscanf1_LoadPath_Terminate); + + Patch(readTrackFile1.get(-10 + 1), "%hd"); + InterceptCall(readTrackFile1.get(), orgSscanf1, sscanf1_Terminate); + + Nop(readTrackFile2.get(), 2); + InjectHook(readTrackFile2.get(2), ReadTrackFile_Terminate, HookType::Call); + } } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 8dc8eb8..ea5909b 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -536,6 +536,22 @@ namespace EnvMapsOnExtras } +// ============= Null terminate read lines in CPlane::LoadPath ============= +namespace NullTerminatedLines +{ + static void* orgSscanf_LoadPath; + __declspec(naked) static void sscanf1_LoadPath_Terminate() + { + _asm + { + mov eax, [esp+4] + mov byte ptr [eax+ecx], 0 + jmp [orgSscanf_LoadPath] + } + } +} + + void InjectDelayedPatches_VC_Common( bool bHasDebugMenu, const wchar_t* wcModulePath ) { using namespace Memory; @@ -1298,6 +1314,16 @@ void Patch_VC_Common() Patch(probability, 35000u / 2u); } + + + // Null terminate read lines in CPlane::LoadPath + { + using namespace NullTerminatedLines; + + auto loadPath = get_pattern("DD D8 45 E8", 3); + + InterceptCall(loadPath, orgSscanf_LoadPath, sscanf1_LoadPath_Terminate); + } } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)