Make script randomness 16-bit, like on PS2

This commit is contained in:
Silent 2024-03-17 20:52:52 +01:00
parent d72a0cb7a0
commit b3131a41b4
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1
8 changed files with 82 additions and 35 deletions

View file

@ -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 <array>
#include <rwcore.h>
RwCamera*& Camera = **hook::get_pattern<RwCamera**>( "A1 ? ? ? ? D8 88 ? ? ? ?", 1 );
@ -130,6 +133,25 @@ namespace ExtraCompSpecularity
}
}
// ============= Make script randomness 16-bit, like on PS2 =============
namespace Rand16bit
{
template<std::size_t Index>
static int (*orgRand)();
template<std::size_t Index>
static int rand16bit()
{
const int bottomBits = orgRand<Index>();
const int topBit = (orgRand<Index>() & 1) << 15;
return bottomBits | topBit;
}
HOOK_EACH_FUNC(Rand, orgRand, rand16bit);
}
// ============= Delayed patches =============
namespace DelayedPatches
{
@ -280,6 +302,19 @@ namespace Common {
Patch<const void*>(match.get<void>(2), &LightStatusRandomnessThreshold);
});
}
// Make script randomness 16-bit, like on PS2
{
using namespace Rand16bit;
std::array<void*, 2> 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)() )

View file

@ -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<std::size_t Ctr, typename Tuple, std::size_t... I, typename Func> \
static void _HookEachImpl_##name(Tuple&& tuple, std::index_sequence<I...>, Func&& f) \
{ \
(f(std::get<I>(tuple), origFunc<Ctr << 16 | I>, hook<Ctr << 16 | I>), ...); \
} \
\
template<std::size_t Ctr = ctr, typename Vars, typename Func> \
static void HookEach_##name(Vars&& vars, Func&& f) \
{ \
auto tuple = std::tuple_cat(std::forward<Vars>(vars)); \
_HookEachImpl_##name<Ctr>(std::move(tuple), std::make_index_sequence<std::tuple_size_v<decltype(tuple)>>{}, std::forward<Func>(f)); \
}
#define HOOK_EACH_FUNC(name, orig, hook) HOOK_EACH_FUNC_CTR(name, 0, orig, hook)
#define DISABLE_FLA_DONATION_WINDOW 0

@ -1 +1 @@
Subproject commit 945c81964c4a94b6ef5164d4318798a891676e13
Subproject commit f69eb3956d9349ea820120b218676d74589ea0a2

View file

@ -15,6 +15,7 @@
#include "Utils/ModuleList.hpp"
#include "Utils/Patterns.h"
#include "Utils/ScopedUnprotect.hpp"
#include "Utils/HookEach.hpp"
#include "debugmenu_public.h"

View file

@ -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<std::size_t Index>
static int (*orgRand)();
template<std::size_t Index>
static int rand16bit()
{
const int bottomBits = orgRand<Index>();
const int topBit = (orgRand<Index>() & 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<uintptr_t, 2> rands = { 0x4674FE, 0x467533 };
HookEach_Rand(rands, InterceptCall);
}
#if FULL_PRECISION_D3D
// Test - full precision D3D device
Patch<uint8_t>( 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<void*, 2> rands = {
get_pattern("E8 ? ? ? ? 89 45 08 DB 45 08 32 C0"),
get_pattern("E8 ? ? ? ? 89 06 32 C0"),
};
HookEach_Rand(rands, InterceptCall);
}
}

View file

@ -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<std::size_t Ctr, typename Tuple, std::size_t... I, typename Func> \
static void _HookEachImpl_##name(Tuple&& tuple, std::index_sequence<I...>, Func&& f) \
{ \
(f(std::get<I>(tuple), origFunc<Ctr << 16 | I>, hook<Ctr << 16 | I>), ...); \
} \
\
template<std::size_t Ctr = ctr, typename Vars, typename Func> \
static void HookEach_##name(Vars&& vars, Func&& f) \
{ \
auto tuple = std::tuple_cat(std::forward<Vars>(vars)); \
_HookEachImpl_##name<Ctr>(std::move(tuple), std::make_index_sequence<std::tuple_size_v<decltype(tuple)>>{}, std::forward<Func>(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*);

View file

@ -5,6 +5,8 @@
#include "ModelInfoSA.h"
#include "PedSA.h"
#include "Utils/HookEach.hpp"
enum eVehicleType
{
VEHICLE_AUTOMOBILE,

View file

@ -17,6 +17,7 @@
#include "Utils/ModuleList.hpp"
#include "Utils/Patterns.h"
#include "Utils/ScopedUnprotect.hpp"
#include "Utils/HookEach.hpp"
#include "debugmenu_public.h"