From e4a3d81e817f2585ea5ee6d6c186a7172c5706e2 Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 12 Sep 2017 16:14:07 +0200 Subject: [PATCH] Only hook DOUBLE_RHWEELS exception list if there are any entries listed in INI --- SilentPatchSA/SilentPatchSA.cpp | 35 ++++++++++++++++++++------------- SilentPatchSA/VehicleSA.cpp | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 9f8bff5..8aec917 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1074,9 +1074,11 @@ void DrawScriptSpritesAndRectangles( uint8_t arg ) } std::vector< std::pair > doubleRearWheelsList; -void ReadDoubleRearWheels(const wchar_t* pPath) +bool ReadDoubleRearWheels(const wchar_t* pPath) { - const size_t SCRATCH_PAD_SIZE = 32767; + bool listedAny = false; + + constexpr size_t SCRATCH_PAD_SIZE = 32767; WideDelimStringReader reader( SCRATCH_PAD_SIZE ); GetPrivateProfileSectionW( L"DoubleRearWheels", reader.GetBuffer(), reader.GetSize(), pPath ); @@ -1100,8 +1102,10 @@ void ReadDoubleRearWheels(const wchar_t* pPath) if ( begin != end ) { doubleRearWheelsList.emplace_back( toList, value ); + listedAny = true; } } + return listedAny; } bool __stdcall CheckDoubleRWheelsList( void* modelInfo, uint8_t* handlingData ) @@ -2294,7 +2298,7 @@ BOOL InjectDelayedPatches_10() bool bSARender = GetASIModuleHandleW(L"SARender") != nullptr; ReadRotorFixExceptions(wcModulePath); - ReadDoubleRearWheels(wcModulePath); + bool bHookDoubleRwheels = ReadDoubleRearWheels(wcModulePath); if ( GetPrivateProfileIntW(L"SilentPatch", L"SunSizeHack", -1, wcModulePath) == TRUE ) { @@ -2492,6 +2496,20 @@ BOOL InjectDelayedPatches_10() // to work fine with Deji's Custom Plate Format ReadCall( 0x4C9484, CCustomCarPlateMgr::GeneratePlateText ); + + if ( bHookDoubleRwheels ) + { + // Double rwheels whitelist + // push ecx + // push edi + // call CheckDoubleRWheelsWhitelist + // test al, al + Patch( 0x4C9239, 0x5751 ); + InjectHook( 0x4C9239+2, CheckDoubleRWheelsList, PATCH_CALL ); + Patch( 0x4C9239+7, 0xC084 ); + Nop( 0x4C9239+9, 1 ); + } + // Adblocker #if DISABLE_FLA_DONATION_WINDOW if ( GetASIModuleHandleW(L"$fastman92limitAdjuster") != nullptr ) @@ -3431,17 +3449,6 @@ void Patch_SA_10() InjectHook( 0x58C092, DrawScriptSpritesAndRectangles ); - // Double rwheels whitelist - // push ecx - // push edi - // call CheckDoubleRWheelsWhitelist - // test al, al - Patch( 0x4C9239, 0x5751 ); - InjectHook( 0x4C9239+2, CheckDoubleRWheelsList, PATCH_CALL ); - Patch( 0x4C9239+7, 0xC084 ); - Nop( 0x4C9239+9, 1 ); - - // Properly initialize all CVehicleModelInfo fields ReadCall( 0x4C75E4, orgVehicleModelInfoCtor ); InjectHook( 0x4C75E4, VehicleModelInfoCtor ); diff --git a/SilentPatchSA/VehicleSA.cpp b/SilentPatchSA/VehicleSA.cpp index 6f7082e..66fa3b9 100644 --- a/SilentPatchSA/VehicleSA.cpp +++ b/SilentPatchSA/VehicleSA.cpp @@ -84,7 +84,7 @@ static RwFrame* GetFrameFromName( RwFrame* topFrame, const char* name ) void ReadRotorFixExceptions(const wchar_t* pPath) { - const size_t SCRATCH_PAD_SIZE = 32767; + constexpr size_t SCRATCH_PAD_SIZE = 32767; WideDelimStringReader reader( SCRATCH_PAD_SIZE ); GetPrivateProfileSectionW( L"RotorFixExceptions", reader.GetBuffer(), reader.GetSize(), pPath );