2022-04-09 16:16:40 +02:00
# pragma once
2022-11-27 21:53:54 +01:00
# include "public/ikeyvaluessystem.h"
2023-07-02 02:51:12 +02:00
# include "tier1/memstack.h"
# include "tier1/mempool.h"
# include "tier1/utlvector.h"
# include "tier1/utlmap.h"
2022-04-09 16:16:40 +02:00
2022-11-27 21:53:54 +01:00
class CKeyValuesSystem : public IKeyValuesSystem // VTABLE @ 0x1413AA1E8 in R5pc_r5launch_N1094_CL456479_2019_10_30_05_20_PM
2022-04-09 16:16:40 +02:00
{
public :
2023-03-25 17:26:42 +01:00
void RegisterSizeofKeyValues ( int64_t nSize ) ;
void * AllocKeyValuesMemory ( int64_t nSize ) ;
2022-04-09 16:16:40 +02:00
void FreeKeyValuesMemory ( void * pMem ) ;
2023-03-25 17:31:41 +01:00
HKeySymbol GetSymbolForString ( const char * szName , bool bCreate = true ) ;
2022-04-09 16:16:40 +02:00
const char * GetStringForSymbol ( HKeySymbol symbol ) ;
2022-05-28 02:24:57 +02:00
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.
2023-03-25 17:26:42 +01:00
void SetKeyValuesExpressionSymbol ( const char * szName , bool bValue ) ;
bool GetKeyValuesExpressionSymbol ( const char * szName ) ;
2023-03-25 17:31:41 +01:00
HKeySymbol GetSymbolForStringCaseSensitive ( HKeySymbol & hCaseInsensitiveSymbol , const char * szName , bool bCreate = true ) ;
2022-04-09 16:16:40 +02:00
private :
2023-07-02 02:51:12 +02:00
int64 m_iMaxKeyValuesSize ;
CMemoryStack m_Strings ;
struct hash_item_t
{
int stringIndex ;
hash_item_t * next ;
} ;
CUtlMemoryPool m_HashItemMemPool ;
CUtlVector < hash_item_t > m_HashTable ;
struct MemoryLeakTracker_t
{
int nameIndex ;
void * pMem ;
} ;
// Unknown less func.
void * m_pCompareFunc ;
CUtlRBTree < MemoryLeakTracker_t , int > m_KeyValuesTrackingList ;
CUtlMap < HKeySymbol , bool > m_KvConditionalSymbolTable ;
CThreadFastMutex m_Mutex ;
2022-04-09 16:16:40 +02:00
} ;
/* ==== KEYVALUESSYSTEM ================================================================================================================================================= */
2022-05-13 14:53:25 +02:00
inline void * g_pKeyValuesMemPool = nullptr ;
2022-04-18 03:35:08 +02:00
inline CKeyValuesSystem * g_pKeyValuesSystem = nullptr ;
2022-04-09 16:16:40 +02:00
2023-07-02 02:51:12 +02:00
//-----------------------------------------------------------------------------
// Instance singleton and expose interface to rest of code
//-----------------------------------------------------------------------------
FORCEINLINE CKeyValuesSystem * KeyValuesSystem ( )
{
return g_pKeyValuesSystem ;
}
2022-04-09 16:16:40 +02:00
///////////////////////////////////////////////////////////////////////////////
class HKeyValuesSystem : public IDetour
{
2022-04-11 01:44:30 +02:00
virtual void GetAdr ( void ) const
2022-04-09 16:16:40 +02:00
{
2023-01-25 02:26:52 +01:00
LogVarAdr ( " g_pKeyValuesMemPool " , reinterpret_cast < uintptr_t > ( g_pKeyValuesMemPool ) ) ;
LogVarAdr ( " g_pKeyValuesSystem " , reinterpret_cast < uintptr_t > ( g_pKeyValuesSystem ) ) ;
2022-04-09 16:16:40 +02:00
}
2022-04-11 01:44:30 +02:00
virtual void GetFun ( void ) const { }
2022-04-18 03:35:08 +02:00
virtual void GetVar ( void ) const
{
2022-12-01 22:44:55 +01:00
g_pKeyValuesSystem = g_GameDll . FindPatternSIMD ( " 48 89 5C 24 ?? 48 89 6C 24 ?? 56 57 41 56 48 83 EC 40 48 8B F1 " )
2022-04-19 00:00:45 +02:00
. FindPatternSelf ( " 48 8D 0D ?? ?? ?? 01 " , CMemory : : Direction : : DOWN ) . ResolveRelativeAddressSelf ( 0x3 , 0x7 ) . RCast < CKeyValuesSystem * > ( ) ;
2022-04-18 03:35:08 +02:00
2022-12-01 22:44:55 +01:00
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 * > ( ) ;
2022-04-18 03:35:08 +02:00
}
2022-04-11 01:44:30 +02:00
virtual void GetCon ( void ) const { }
virtual void Attach ( void ) const { }
virtual void Detach ( void ) const { }
2022-04-09 16:16:40 +02:00
} ;
///////////////////////////////////////////////////////////////////////////////