From ccf61157fb8f832de8e71ba590ec59d0962ffbea Mon Sep 17 00:00:00 2001 From: Silent Date: Fri, 17 May 2024 19:34:38 +0200 Subject: [PATCH] III/VC: Corrected randomness of CPed::Chat Makes pedestrians less likely to initiate a chat, matching the PS2 odds (they were too chatty on PC). --- SilentPatch/Common.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp index 0dc0307..ee0cd1c 100644 --- a/SilentPatch/Common.cpp +++ b/SilentPatch/Common.cpp @@ -163,7 +163,8 @@ namespace Rand16bit return bottomBits | topBit; } - HOOK_EACH_FUNC(Rand, orgRand, rand16bit); + HOOK_EACH_FUNC_CTR(Rand_Script, 0, orgRand, rand16bit); + HOOK_EACH_FUNC_CTR(Rand_PedChat, 1, orgRand, rand16bit); } @@ -329,19 +330,35 @@ namespace Common { TXN_CATCH(); - // Make script randomness 16-bit, like on PS2 - try + // Fix various randomness factors expecting 16-bit rand() { + // Treat each instance separately using namespace Rand16bit; - std::array rands = { - get_pattern("E8 ? ? ? ? 0F B7 C0 89 06"), - get_pattern("E8 ? ? ? ? 25 FF FF 00 00 89 84 24 ? ? ? ? 30 C0"), - }; + // Script randomness + try + { + std::array rands = { + get_pattern("E8 ? ? ? ? 0F B7 C0 89 06"), + get_pattern("E8 ? ? ? ? 25 FF FF 00 00 89 84 24 ? ? ? ? 30 C0"), + }; - HookEach_Rand(rands, InterceptCall); + HookEach_Rand_Script(rands, InterceptCall); + } + TXN_CATCH(); + + // CPed::Chat + try + { + std::array rands = { + get_pattern("E8 ? ? ? ? 66 3D 00 02"), + get_pattern("E8 ? ? ? ? 66 83 F8 14"), + }; + + HookEach_Rand_PedChat(rands, InterceptCall); + } + TXN_CATCH(); } - TXN_CATCH(); } void III_VC_SetDelayedPatchesFunc( void(*func)() )