From 1d2f0014f165497a66f0eb73a9d923ed5d726bbc Mon Sep 17 00:00:00 2001 From: Silent Date: Tue, 27 Feb 2024 22:27:51 +0100 Subject: [PATCH] Fix the random chance of cars not turning lights on when it's foggy or rainy On PC, they would always eventually turn the lights on due to a different range of randomness. Fixes #2 --- SilentPatch/Common.cpp | 19 +++++++++++++++++++ SilentPatchSA/SilentPatchSA.cpp | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp index 205ef66..1fa0d61 100644 --- a/SilentPatch/Common.cpp +++ b/SilentPatch/Common.cpp @@ -235,6 +235,25 @@ namespace Common { InjectHook( resetComps.get( -14 ), ResetCompsForNoExtras, HookType::Call ); Nop( resetComps.get( -9 ), 9 ); } + + + // Rescale light switching randomness in CAutomobile::PreRender/CBike::PreRender for PC the randomness range + // The original randomness was 50000 out of 65535, which is impossible to hit with PC's 32767 range + { + // GTA III expects 2 matches, VC expects 4 due to the addition of CBike::PreRender +#if _GTA_III + constexpr uint32_t expected = 2; +#else + constexpr uint32_t expected = 4; +#endif + auto matches = pattern("D8 0D ? ? ? ? D8 1D ? ? ? ? DF E0 80 E4 05 80 FC 01").count(expected); + + matches.for_each_result([](pattern_match match) + { + static const float LightStatusRandomnessThreshold = 1.0f / 25000.0f; + Patch(match.get(2), &LightStatusRandomnessThreshold); + }); + } } void III_VC_SetDelayedPatchesFunc( void(*func)() ) diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index 86d5f67..8844092 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -5198,6 +5198,14 @@ void Patch_SA_10(HINSTANCE hInstance) InjectHook(0x6CD545, CheckIfInPlayerGroupAndOnAMission, HookType::Jump); } + + // Rescale light switching randomness in CVehicle::GetVehicleLightsStatus for PC the randomness range + // The original randomness was 50000 out of 65535, which is impossible to hit with PC's 32767 range + { + static const float LightStatusRandomnessThreshold = 1.0f / 25000.0f; + Patch(0x6D5612 + 2, &LightStatusRandomnessThreshold); + } + #if FULL_PRECISION_D3D // Test - full precision D3D device Patch( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE ); @@ -6882,6 +6890,16 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) SkipTargetting = skipTargetting; InjectHook(targettingCheck.get(), CheckIfInPlayerGroupAndOnAMission_Steam, HookType::Jump); } + + + // Rescale light switching randomness in CVehicle::GetVehicleLightsStatus for PC the randomness range + // The original randomness was 50000 out of 65535, which is impossible to hit with PC's 32767 range + { + auto getVehicleLightsStatus = get_pattern("DC 35 ? ? ? ? D9 05 ? ? ? ? D8 D9", 2); + + static const double LightStatusRandomnessThreshold = 25000.0; + Patch(getVehicleLightsStatus, &LightStatusRandomnessThreshold); + } }