From 396f013961ad75cceff82ed3daf25d7ee5a00ced Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 27 Apr 2017 02:19:27 +0200 Subject: [PATCH] MountainCloudBoysFix using patternies instead of a hardcoded offset --- SilentPatchSA/SilentPatchSA.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index be911d1..c94be7f 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -632,20 +632,15 @@ static void SweetsGirlFix() static void MountainCloudBoysFix() { - static const uint8_t bOldCode[22] = { - 0xD6, 0x00, 0x04, 0x00, 0x39, 0x00, 0x03, 0xEF, 0x00, 0x04, 0x02, 0x4D, - 0x00, 0x01, 0x90, 0xF2, 0xFF, 0xFF, 0xD6, 0x00, 0x04, 0x01 - }; - - // Faulty code lies under offset 3367 - replace it if it matches - if ( memcmp( ScriptSpace+ScriptFileSize+3367, bOldCode, sizeof(bOldCode) ) == 0 ) + auto pattern = hook::range_pattern( uintptr_t(ScriptSpace+ScriptFileSize), uintptr_t(ScriptSpace+ScriptFileSize+ScriptMissionSize), + "D6 00 04 00 39 00 03 EF 00 04 02 4D 00 01 90 F2 FF FF D6 00 04 01" ).count_hint(1); + if ( pattern.size() == 1 ) // Faulty code lies under offset 3367 - replace it if it matches { const uint8_t bNewCode[22] = { 0x00, 0x00, 0x00, 0x00, 0xD6, 0x00, 0x04, 0x03, 0x39, 0x00, 0x03, 0x2B, 0x00, 0x04, 0x0B, 0x39, 0x00, 0x03, 0xEF, 0x00, 0x04, 0x02 }; - - memcpy( ScriptSpace+ScriptFileSize+3367, bNewCode, sizeof(bNewCode) ); + memcpy( pattern.get(0).get(), bNewCode, sizeof(bNewCode) ); } }