init
This commit is contained in:
88
TempleWare-CS2/source/templeware/utils/schema/schema.cpp
Normal file
88
TempleWare-CS2/source/templeware/utils/schema/schema.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "schema.h"
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <Shlobj.h>
|
||||
#include <shlobj_core.h>
|
||||
|
||||
|
||||
#include "../fnv1a/fnv1a.h"
|
||||
|
||||
#include "../math/utlstring/utlstring.h"
|
||||
#include "../memory/Interface/Interface.h"
|
||||
|
||||
struct SchemaDumpedData_t
|
||||
{
|
||||
uint32_t hashedName = 0x0ULL;
|
||||
std::uint32_t uOffset = 0x0U;
|
||||
};
|
||||
|
||||
static std::vector<SchemaDumpedData_t> dumped_data;
|
||||
|
||||
bool Schema::init(const char* ModuleName, int module_type)
|
||||
{
|
||||
|
||||
schema_system = I::Get<ISchemaSystem>("schemasystem.dll", "SchemaSystem_00");
|
||||
if (!schema_system)
|
||||
return false;
|
||||
|
||||
CSchemaSystemTypeScope* pTypeScope = schema_system->FindTypeScopeForModule(ModuleName);
|
||||
if (pTypeScope == nullptr)
|
||||
return false;
|
||||
|
||||
const int nTableSize = pTypeScope->hashClasses.Count();
|
||||
|
||||
UtlTSHashHandle_t* pElements = new UtlTSHashHandle_t[nTableSize + 1U];
|
||||
const auto nElements = pTypeScope->hashClasses.GetElements(0, nTableSize, pElements);
|
||||
|
||||
for (int i = 0; i < nElements; i++)
|
||||
{
|
||||
const UtlTSHashHandle_t hElement = pElements[i];
|
||||
|
||||
if (hElement == 0)
|
||||
continue;
|
||||
|
||||
CSchemaClassBinding* pClassBinding = pTypeScope->hashClasses[hElement];
|
||||
if (pClassBinding == nullptr)
|
||||
continue;
|
||||
|
||||
SchemaClassInfoData_t* pDeclaredClassInfo;
|
||||
pTypeScope->FindDeclaredClass(&pDeclaredClassInfo, pClassBinding->szBinaryName);
|
||||
|
||||
if (pDeclaredClassInfo == nullptr)
|
||||
continue;
|
||||
|
||||
if (pDeclaredClassInfo->nFieldSize == 0)
|
||||
continue;
|
||||
|
||||
for (auto j = 0; j < pDeclaredClassInfo->nFieldSize; j++)
|
||||
{
|
||||
SchemaClassFieldData_t* pFields = pDeclaredClassInfo->pFields;
|
||||
std::string szFieldClassBuffer = std::string(pDeclaredClassInfo->szName) + "->" + std::string(pFields[j].szName);
|
||||
|
||||
dumped_data.emplace_back(hash_32_fnv1a_const(szFieldClassBuffer.c_str()), pFields[j].nSingleInheritanceOffset);
|
||||
}
|
||||
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY);
|
||||
printf("[Schema] ");
|
||||
|
||||
SetConsoleTextAttribute(hConsole, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
printf("Dumped Class: %s fields: %i \n", pDeclaredClassInfo->szName, pDeclaredClassInfo->nFieldSize);
|
||||
}
|
||||
|
||||
delete[] pElements;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::uint32_t SchemaFinder::Get(const uint32_t hashedName)
|
||||
{
|
||||
if (const auto it = std::ranges::find_if(dumped_data, [hashedName](const SchemaDumpedData_t& data)
|
||||
{ return data.hashedName == hashedName; });
|
||||
it != dumped_data.end())
|
||||
return it->uOffset;
|
||||
|
||||
return 0U;
|
||||
}
|
||||
|
||||
41
TempleWare-CS2/source/templeware/utils/schema/schema.h
Normal file
41
TempleWare-CS2/source/templeware/utils/schema/schema.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include "..\fnv1a\fnv1a.h"
|
||||
#include "..\memory\vfunc\vfunc.h"
|
||||
#include "..\math\utlmemory\utlmemory.h"
|
||||
#include "..\math\utlvector\utlvector.h"
|
||||
#include "..\..\..\cs2\datatypes\schema\ISchemaClass\ISchemaClass.h"
|
||||
|
||||
#define SCHEMA_ADD_OFFSET(TYPE, NAME, OFFSET) \
|
||||
[[nodiscard]] inline std::add_lvalue_reference_t<TYPE> NAME() \
|
||||
{ \
|
||||
static const std::uint32_t uOffset = OFFSET; \
|
||||
return *reinterpret_cast<std::add_pointer_t<TYPE>>(reinterpret_cast<std::uint8_t*>(this) + (uOffset)); \
|
||||
}
|
||||
|
||||
#define SCHEMA_ADD_POFFSET(TYPE, NAME, OFFSET) \
|
||||
[[nodiscard]] inline std::add_pointer_t<TYPE> NAME() \
|
||||
{ \
|
||||
const static std::uint32_t uOffset = OFFSET; \
|
||||
return reinterpret_cast<std::add_pointer_t<TYPE>>(reinterpret_cast<std::uint8_t*>(this) + (uOffset)); \
|
||||
}
|
||||
|
||||
|
||||
#define schema(TYPE, NAME, FIELD) SCHEMA_ADD_OFFSET(TYPE, NAME, SchemaFinder::Get(hash_32_fnv1a_const(FIELD)) + 0u)
|
||||
|
||||
#define schema_pfield(TYPE, NAME, FIELD, ADDITIONAL) SCHEMA_ADD_POFFSET(TYPE, NAME, SchemaFinder::Get(hash_32_fnv1a_const(FIELD)) + ADDITIONAL)
|
||||
|
||||
class Schema {
|
||||
public:
|
||||
bool init( const char* module_name, int module_type);
|
||||
|
||||
ISchemaSystem* schema_system = nullptr;
|
||||
|
||||
};
|
||||
|
||||
namespace SchemaFinder {
|
||||
|
||||
[[nodiscard]] std::uint32_t Get(const uint32_t hashed);
|
||||
[[nodiscard]] std::uint32_t GetExternal(const char* moduleName, const uint32_t HashedClass, const uint32_t HashedFieldName);
|
||||
}
|
||||
Reference in New Issue
Block a user