diff --git a/SilentPatch/Common.cpp b/SilentPatch/Common.cpp index e38f94d..f1f1d95 100644 --- a/SilentPatch/Common.cpp +++ b/SilentPatch/Common.cpp @@ -2,11 +2,14 @@ #include "Utils/MemoryMgr.h" #include "Utils/Patterns.h" +#include "Utils/HookEach.hpp" #include "StoredCar.h" #include "SVF.h" #include "Utils/DelimStringReader.h" +#include + #include RwCamera*& Camera = **hook::get_pattern( "A1 ? ? ? ? D8 88 ? ? ? ?", 1 ); @@ -130,6 +133,25 @@ namespace ExtraCompSpecularity } } + +// ============= Make script randomness 16-bit, like on PS2 ============= +namespace Rand16bit +{ + template + static int (*orgRand)(); + + template + static int rand16bit() + { + const int bottomBits = orgRand(); + const int topBit = (orgRand() & 1) << 15; + return bottomBits | topBit; + } + + HOOK_EACH_FUNC(Rand, orgRand, rand16bit); +} + + // ============= Delayed patches ============= namespace DelayedPatches { @@ -280,6 +302,19 @@ namespace Common { Patch(match.get(2), &LightStatusRandomnessThreshold); }); } + + + // Make script randomness 16-bit, like on PS2 + { + 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"), + }; + + HookEach_Rand(rands, InterceptCall); + } } void III_VC_SetDelayedPatchesFunc( void(*func)() ) diff --git a/SilentPatch/StdAfx.h b/SilentPatch/StdAfx.h index f28019e..2ca801a 100644 --- a/SilentPatch/StdAfx.h +++ b/SilentPatch/StdAfx.h @@ -12,21 +12,4 @@ #include "Utils/MemoryMgr.GTA.h" #include "Utils/Patterns.h" -// Move this to ModUtils when it matures a bit more -#define HOOK_EACH_FUNC_CTR(name, ctr, origFunc, hook) \ - template \ - static void _HookEachImpl_##name(Tuple&& tuple, std::index_sequence, Func&& f) \ - { \ - (f(std::get(tuple), origFunc, hook), ...); \ - } \ - \ - template \ - static void HookEach_##name(Vars&& vars, Func&& f) \ - { \ - auto tuple = std::tuple_cat(std::forward(vars)); \ - _HookEachImpl_##name(std::move(tuple), std::make_index_sequence>{}, std::forward(f)); \ - } - -#define HOOK_EACH_FUNC(name, orig, hook) HOOK_EACH_FUNC_CTR(name, 0, orig, hook) - #define DISABLE_FLA_DONATION_WINDOW 0 diff --git a/SilentPatch/Utils b/SilentPatch/Utils index 945c819..f69eb39 160000 --- a/SilentPatch/Utils +++ b/SilentPatch/Utils @@ -1 +1 @@ -Subproject commit 945c81964c4a94b6ef5164d4318798a891676e13 +Subproject commit f69eb3956d9349ea820120b218676d74589ea0a2 diff --git a/SilentPatchIII/SilentPatchIII.cpp b/SilentPatchIII/SilentPatchIII.cpp index e3b40ba..9483816 100644 --- a/SilentPatchIII/SilentPatchIII.cpp +++ b/SilentPatchIII/SilentPatchIII.cpp @@ -15,6 +15,7 @@ #include "Utils/ModuleList.hpp" #include "Utils/Patterns.h" #include "Utils/ScopedUnprotect.hpp" +#include "Utils/HookEach.hpp" #include "debugmenu_public.h" diff --git a/SilentPatchSA/SilentPatchSA.cpp b/SilentPatchSA/SilentPatchSA.cpp index ba2b3ec..2dcd8b1 100644 --- a/SilentPatchSA/SilentPatchSA.cpp +++ b/SilentPatchSA/SilentPatchSA.cpp @@ -26,6 +26,7 @@ #include "Utils/DelimStringReader.h" #include "Utils/ModuleList.hpp" #include "Utils/ScopedUnprotect.hpp" +#include "Utils/HookEach.hpp" #include "Desktop.h" @@ -2514,6 +2515,24 @@ namespace LitFlyingComponents } +// ============= Make script randomness 16-bit, like on PS2 ============= +namespace Rand16bit +{ + template + static int (*orgRand)(); + + template + static int rand16bit() + { + const int bottomBits = orgRand(); + const int topBit = (orgRand() & 1) << 15; + return bottomBits | topBit; + } + + HOOK_EACH_FUNC(Rand, orgRand, rand16bit); +} + + // ============= LS-RP Mode stuff ============= namespace LSRPMode { @@ -5314,6 +5333,17 @@ void Patch_SA_10(HINSTANCE hInstance) Patch(0x6C25F5 + 2, &fRandomness); } + + // Make script randomness 16-bit, like on PS2 + { + using namespace Rand16bit; + + std::array rands = { 0x4674FE, 0x467533 }; + + HookEach_Rand(rands, InterceptCall); + } + + #if FULL_PRECISION_D3D // Test - full precision D3D device Patch( 0x7F672B+1, *(uint8_t*)(0x7F672B+1) | D3DCREATE_FPU_PRESERVE ); @@ -7078,6 +7108,18 @@ void Patch_SA_NewBinaries_Common(HINSTANCE hInstance) Patch(wheelDetachRandomness, &fRandomness); } + + // Make script randomness 16-bit, like on PS2 + { + using namespace Rand16bit; + + std::array rands = { + get_pattern("E8 ? ? ? ? 89 45 08 DB 45 08 32 C0"), + get_pattern("E8 ? ? ? ? 89 06 32 C0"), + }; + + HookEach_Rand(rands, InterceptCall); + } } diff --git a/SilentPatchSA/StdAfxSA.h b/SilentPatchSA/StdAfxSA.h index da59f67..e15ad29 100644 --- a/SilentPatchSA/StdAfxSA.h +++ b/SilentPatchSA/StdAfxSA.h @@ -24,23 +24,6 @@ #include "TheFLAUtils.h" -// Move this to ModUtils when it matures a bit more -#define HOOK_EACH_FUNC_CTR(name, ctr, origFunc, hook) \ - template \ - static void _HookEachImpl_##name(Tuple&& tuple, std::index_sequence, Func&& f) \ - { \ - (f(std::get(tuple), origFunc, hook), ...); \ - } \ - \ - template \ - static void HookEach_##name(Vars&& vars, Func&& f) \ - { \ - auto tuple = std::tuple_cat(std::forward(vars)); \ - _HookEachImpl_##name(std::move(tuple), std::make_index_sequence>{}, std::forward(f)); \ - } - -#define HOOK_EACH_FUNC(name, orig, hook) HOOK_EACH_FUNC_CTR(name, 0, orig, hook) - // SA operator delete extern void (*GTAdelete)(void* data); extern const char* (*GetFrameNodeName)(RwFrame*); diff --git a/SilentPatchSA/VehicleSA.h b/SilentPatchSA/VehicleSA.h index 0fc8bb7..dfff1fe 100644 --- a/SilentPatchSA/VehicleSA.h +++ b/SilentPatchSA/VehicleSA.h @@ -5,6 +5,8 @@ #include "ModelInfoSA.h" #include "PedSA.h" +#include "Utils/HookEach.hpp" + enum eVehicleType { VEHICLE_AUTOMOBILE, diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index 6d0a1ea..8dc8eb8 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -17,6 +17,7 @@ #include "Utils/ModuleList.hpp" #include "Utils/Patterns.h" #include "Utils/ScopedUnprotect.hpp" +#include "Utils/HookEach.hpp" #include "debugmenu_public.h"