From e797ec4f3a4d70e14d8808da64ab4e0801eedbe5 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 28 Dec 2019 00:13:27 +0100 Subject: [PATCH] SA: Ported new fixes to Steam/RGL: - Reset bPenaltyForDeathApplies and bPenaltyForArrestApplies on new game - Fix lightless taxis - Allow extra6 to be picked with component rule 4 (any) - Disallow moving cam up/down with mouse when looking back/left/right in vehicle --- SilentPatchSA/ModelInfoSA.cpp | 4 +-- SilentPatchSA/SilentPatchSA.cpp | 60 +++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/SilentPatchSA/ModelInfoSA.cpp b/SilentPatchSA/ModelInfoSA.cpp index 9a6e30c..3fed5e4 100644 --- a/SilentPatchSA/ModelInfoSA.cpp +++ b/SilentPatchSA/ModelInfoSA.cpp @@ -17,8 +17,8 @@ bool (*CCustomCarPlateMgr::GeneratePlateText)(char* pBuf, int nLen); // Read fro CBaseModelInfo** const ms_modelInfoPtrs = *AddressByVersion(0x509CB1, 0x4C0C96, 0x403DB7); -int8_t* CVehicleModelInfo::ms_compsUsed = *AddressByVersion( 0x4C973B + 2, 0, 0 ); -int8_t* CVehicleModelInfo::ms_compsToUse = *AddressByVersion( 0x4C8057 + 2, 0, 0 ); +int8_t* CVehicleModelInfo::ms_compsUsed = *AddressByVersion( 0x4C973B + 2, Memory::PatternAndOffset("8B CE A2 ? ? ? ? E8", 2 + 1) ); +int8_t* CVehicleModelInfo::ms_compsToUse = *AddressByVersion( 0x4C8057 + 2, Memory::PatternAndOffset("0F BE C0 C6 05 ? ? ? ? FE 5E", 3 + 2) ); static RwTexture** const ms_aDirtTextures = *AddressByVersion( 0x5D5DCC + 3, 0, 0x5F259C + 3 ); diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 5057d22..c05fe6d 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -1672,7 +1672,7 @@ namespace MoonphasesFix // ============= Disallow moving cam up/down with mouse when looking back/left/right in vehicle ============= namespace FollowCarMouseCamFix { - static uint32_t& camLookDirection = **AddressByVersion( 0x525526 + 2, 0, 0 ); + static uint32_t& camLookDirection = **AddressByVersion( 0x525526 + 2, Memory::PatternAndOffset("83 3D ? ? ? ? 03 74 06", 2) ); static void* (*orgGetPad)(int); static bool* orgUseMouse3rdPerson; @@ -5454,15 +5454,30 @@ void Patch_SA_NewBinaries_Common() } - // Reinit CCarCtrl fields (firetruck and ambulance generation) + // Reset variables on New Game { using namespace VariableResets; - auto timers_init = pattern( "89 45 FC DB 45 FC C6 05 ? ? ? ? 01" ).get_one(); + { + auto reinit1 = get_pattern( "E8 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? E8 ? ? ? ? 38 1D" ); + auto reinit2 = get_pattern( "E8 ? ? ? ? 89 1D ? ? ? ? E8 ? ? ? ? 5E" ); - GameVariablesToReset.emplace_back( *timers_init.get(-17 + 2) ); - GameVariablesToReset.emplace_back( *timers_init.get(-11 + 2) ); - GameVariablesToReset.emplace_back( *timers_init.get*>(0x41 + 2) ); + ReadCall( reinit1, orgReInitGameObjectVariables ); + InjectHook( reinit1, ReInitGameObjectVariables ); + InjectHook( reinit2, ReInitGameObjectVariables ); + } + + // Variables to reset + { + auto timers_init = pattern( "89 45 FC DB 45 FC C6 05 ? ? ? ? 01" ).get_one(); + + GameVariablesToReset.emplace_back( *timers_init.get(-17 + 2) ); + GameVariablesToReset.emplace_back( *timers_init.get(-11 + 2) ); + GameVariablesToReset.emplace_back( *timers_init.get*>(0x41 + 2) ); + } + + GameVariablesToReset.emplace_back( *get_pattern( "A2 ? ? ? ? E9 ? ? ? ? 6A 01 8B CE", 1 ) ); // CGameLogic::bPenaltyForDeathApplies + GameVariablesToReset.emplace_back( *get_pattern( "88 0D ? ? ? ? E9 ? ? ? ? 6A 05", 2 ) ); // CGameLogic::bPenaltyForArrestApplies } // FuckCarCompletely not fixing panels @@ -5715,6 +5730,39 @@ void Patch_SA_NewBinaries_Common() ReadCall( getPipeID.get( 0x1A ), orgGetExtraVertColourPtr ); InjectHook( getPipeID.get( 0x1A ), GetExtraVertColourPtr_SkinCheck ); } + + + // Reset requested extras if created vehicle has no extras + // Fixes eg. lightless taxis + { + auto resetComps = pattern( "6A 00 68 ? ? ? ? 57 E8 ? ? ? ? 83 C4 0C 8B C7" ).get_one(); + + InjectHook( resetComps.get( -9 ), CVehicleModelInfo::ResetCompsForNoExtras, PATCH_CALL ); + Nop( resetComps.get( -9 + 5 ), 4 ); + } + + + // Allow extra6 to be picked with component rule 4 (any) + { + void* extra6 = get_pattern( "6A 00 E8 ? ? ? ? 83 C4 08 5E", -2 + 1 ); + + Patch( extra6, 6 ); + } + + + // Disallow moving cam up/down with mouse when looking back/left/right in vehicle + { + using namespace FollowCarMouseCamFix; + + bool** useMouse3rdPerson = get_pattern( "80 3D ? ? ? ? 00 C6 45 1B 00", 2 ); + auto getPad = get_pattern( "89 45 B8 E8 ? ? ? ? 89 45 FC", 3 ); + + orgUseMouse3rdPerson = *useMouse3rdPerson; + Patch( useMouse3rdPerson, &useMouseAndLooksForwards ); + + ReadCall( getPad, orgGetPad ); + InjectHook( getPad, getPadAndSetFlag ); + } }