r5sdk/r5dev/vstdlib/keyvaluessystem.h
Kawe Mazidjatari a618990937 Detour code refactor
This change was planned for a long time. This moves all REGISTER calls to a single translation unit, this is required as we currently added a very dirty workaround for not registering duplicates by checking if VFTable pointer was already present in the vector... Registering from single translation unit prevents duplicate instances that gets created if header is included by more cpp files.
Reworking this reduced 100kb+ of compiled code. This commit also reworked the way functions/variables/constant gets logged with their addresses; the new code formats them on the fly, and allows for resize at any time. Formatting is no longer required by programmer.

TODO: currently there are some compile errors for dedicated and client dll's. These will be resolved very soon as they need to be properly worked out still (server & client only stuff needs to be properly split). Use the 'main' (stable) branch for the time being if you need to compile these dll's.
2023-01-25 02:26:52 +01:00

62 lines
2.6 KiB
C++

#pragma once
#include "public/ikeyvaluessystem.h"
class CKeyValuesSystem : public IKeyValuesSystem// VTABLE @ 0x1413AA1E8 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
{
public:
void RegisterSizeofKeyValues(int64_t size);
void* AllocKeyValuesMemory(int64_t size);
void FreeKeyValuesMemory(void* pMem);
HKeySymbol GetSymbolForString(const char* name, bool bCreate = false);
const char* GetStringForSymbol(HKeySymbol symbol);
void* GetMemPool(void); // GetMemPool returns a global variable called m_pMemPool, it gets modified by AllocKeyValuesMemory and with FreeKeyValuesMemory you can see where to find it in FreeKeyValuesMemory.
void SetKeyValuesExpressionSymbol(const char* name, bool bValue);
bool GetKeyValuesExpressionSymbol(const char* name);
HKeySymbol GetSymbolForStringCaseSensitive(HKeySymbol& hCaseInsensitiveSymbol, const char* name, bool bCreate = false);
// Datatypes aren't accurate. But full fill the actual byte distance.
public:
int64_t m_iMaxKeyValuesSize; // 0x0008
private:
char gap10[240]; // 0x0010
public:
int m_KvConditionalSymbolTable; // 0x0100
private:
char gap104[4]; // 0x0104
public:
int64_t field_108; // 0x0108
private:
char gap110[32]; // 0x0110
public:
int m_mutex; // 0x0130
};
CKeyValuesSystem* KeyValuesSystem();
/* ==== KEYVALUESSYSTEM ================================================================================================================================================= */
inline void* g_pKeyValuesMemPool = nullptr;
inline CKeyValuesSystem* g_pKeyValuesSystem = nullptr;
///////////////////////////////////////////////////////////////////////////////
class HKeyValuesSystem : public IDetour
{
virtual void GetAdr(void) const
{
LogVarAdr("g_pKeyValuesMemPool", reinterpret_cast<uintptr_t>(g_pKeyValuesMemPool));
LogVarAdr("g_pKeyValuesSystem", reinterpret_cast<uintptr_t>(g_pKeyValuesSystem));
}
virtual void GetFun(void) const { }
virtual void GetVar(void) const
{
g_pKeyValuesSystem = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 6C 24 ?? 56 57 41 56 48 83 EC 40 48 8B F1")
.FindPatternSelf("48 8D 0D ?? ?? ?? 01", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CKeyValuesSystem*>();
g_pKeyValuesMemPool = g_GameDll.FindPatternSIMD("48 8B 05 ?? ?? ?? ?? C3 CC CC CC CC CC CC CC CC 48 85 D2").ResolveRelativeAddressSelf(0x3, 0x7).RCast<void*>();
}
virtual void GetCon(void) const { }
virtual void Attach(void) const { }
virtual void Detach(void) const { }
};
///////////////////////////////////////////////////////////////////////////////