mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Originally, we store the search results in a CMemory instance which we then assign to the actual function pointer. CMemory is just a pointer class; we can assign the results directly to the actual function pointer. This commit reduces a lot of code verbosity, and also reduced roughly 2KiB worth of static pointers in the resulting executable. This commit also officially deprecates the support for any GameDLL's below S3 (Season 3), since it makes more sense to port the assets from earlier/later games back to the version this SDK supports.
109 lines
2.8 KiB
C++
109 lines
2.8 KiB
C++
#pragma once
|
|
#include "mathlib/color.h"
|
|
#include "tier0/tslist.h"
|
|
#include "tier1/utlbuffer.h"
|
|
#include "public/ifilesystem.h"
|
|
#include "filesystem/filesystem.h"
|
|
|
|
class RSON
|
|
{
|
|
public:
|
|
enum eFieldType
|
|
{
|
|
RSON_NULL = 0x1,
|
|
RSON_STRING = 0x2,
|
|
RSON_VALUE = 0x4,
|
|
RSON_OBJECT = 0x8,
|
|
RSON_BOOLEAN = 0x10,
|
|
RSON_INTEGER = 0x20,
|
|
RSON_SIGNED_INTEGER = 0x40,
|
|
RSON_UNSIGNED_INTEGER = 0x80,
|
|
RSON_DOUBLE = 0x100,
|
|
RSON_ARRAY = 0x1000,
|
|
};
|
|
|
|
struct Field_t;
|
|
|
|
union Value_t
|
|
{
|
|
Field_t* pSubKey;
|
|
char* pszString;
|
|
__int64 integerValue;
|
|
};
|
|
|
|
// used for the root node of rson tree
|
|
struct Node_t
|
|
{
|
|
eFieldType m_Type;
|
|
int m_nValueCount;
|
|
Value_t m_Value;
|
|
|
|
Field_t* GetFirstSubKey()
|
|
{
|
|
if (m_Type & eFieldType::RSON_OBJECT)
|
|
return m_Value.pSubKey;
|
|
return NULL;
|
|
};
|
|
|
|
// does not support finding a key in a different level of the tree
|
|
Field_t* FindKey(const char* pszKeyName)
|
|
{
|
|
if ((m_Type & eFieldType::RSON_OBJECT) == 0)
|
|
return NULL;
|
|
|
|
for (Field_t* pKey = GetFirstSubKey(); pKey != nullptr; pKey = pKey->GetNextKey())
|
|
{
|
|
if (!_stricmp(pKey->m_pszName, pszKeyName))
|
|
return pKey;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
};
|
|
|
|
// used for every other field of the rson tree
|
|
struct Field_t
|
|
{
|
|
char* m_pszName;
|
|
Node_t m_Node;
|
|
Field_t* m_pNext;
|
|
Field_t* m_pPrev;
|
|
|
|
Field_t* GetNextKey() { return m_pNext; };
|
|
Field_t* GetLastKey() { return m_pPrev; };
|
|
|
|
Field_t* GetFirstSubKey() { return m_Node.GetFirstSubKey(); };
|
|
|
|
Field_t* FindKey(const char* pszKeyName) { return m_Node.FindKey(pszKeyName); };
|
|
|
|
const char* GetString() { return (m_Node.m_Type == RSON_STRING) ? m_Node.m_Value.pszString : NULL; };
|
|
};
|
|
|
|
public:
|
|
static Node_t* LoadFromBuffer(const char* pszBufferName, char* pBuffer, eFieldType rootType);
|
|
static Node_t* LoadFromFile(const char* pszFilePath, const char* pPathID = nullptr);
|
|
};
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
inline RSON::Node_t* (*RSON_LoadFromBuffer)(const char* bufName, char* buf, RSON::eFieldType rootType, __int64 a4, void* a5);
|
|
inline void (*RSON_Free)(RSON::Node_t* rson, CAlignedMemAlloc* allocator);
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
class VRSON : public IDetour
|
|
{
|
|
virtual void GetAdr(void) const
|
|
{
|
|
LogFunAdr("RSON_LoadFromBuffer", RSON_LoadFromBuffer);
|
|
LogFunAdr("RSON_Free", RSON_Free);
|
|
}
|
|
virtual void GetFun(void) const
|
|
{
|
|
g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 48 89 45 60 48 8B D8").FollowNearCallSelf().GetPtr(RSON_LoadFromBuffer);
|
|
g_GameDll.FindPatternSIMD("E8 ?? ?? ?? ?? 48 83 EF 01 75 E7").FollowNearCallSelf().GetPtr(RSON_Free);
|
|
}
|
|
virtual void GetVar(void) const { }
|
|
virtual void GetCon(void) const { }
|
|
virtual void Detour(const bool bAttach) const { }
|
|
};
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|