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
This commit is contained in:
Silent 2024-02-27 22:27:51 +01:00
parent 03fb49689d
commit 1d2f0014f1
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 37 additions and 0 deletions

View File

@ -235,6 +235,25 @@ namespace Common {
InjectHook( resetComps.get<void>( -14 ), ResetCompsForNoExtras, HookType::Call );
Nop( resetComps.get<void>( -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<const void*>(match.get<void>(2), &LightStatusRandomnessThreshold);
});
}
}
void III_VC_SetDelayedPatchesFunc( void(*func)() )

View File

@ -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<const void*>(0x6D5612 + 2, &LightStatusRandomnessThreshold);
}
#if FULL_PRECISION_D3D
// Test - full precision D3D device
Patch<uint8_t>( 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<void>(), 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<const void*>(getVehicleLightsStatus, &LightStatusRandomnessThreshold);
}
}