diff --git a/base/pgBase.hpp b/base/pgBase.hpp index f539d9e..37d7bc6 100644 --- a/base/pgBase.hpp +++ b/base/pgBase.hpp @@ -1,37 +1,129 @@ #pragma once #include -namespace rage -{ +namespace rage { -class pgBase -{ +class pgBase { public: - virtual ~pgBase() = default; - virtual int ReturnZero() = 0; - virtual void Error() = 0; + virtual void ShutdownClass() = 0; + virtual void SetHandleIndex(uint32_t index) = 0; + virtual void Validate(uint32_t arg) = 0; + virtual void InitClass(int arg) = 0; + virtual uint32_t GetHandleIndex() const { return 0; } - void *unk_0000; // 0x0000 -}; // Size: 0x0008 -static_assert(sizeof(pgBase) == 0x10); + uintptr_t LookupMetaData(uint32_t index) const { + uintptr_t current = reinterpret_cast(this); -class pgBaseMetaDataType -{ + uintptr_t nextPage = *reinterpret_cast(current + 8); + if (nextPage == 0) + return 0; + + uint8_t pageStatus = *reinterpret_cast(nextPage + 11); + if (pageStatus == 0) + return 0; + + uintptr_t* metadataStart = reinterpret_cast(nextPage + 16); + uintptr_t metadataCount = *reinterpret_cast(nextPage + 24); + + for (uintptr_t i = 0; i < metadataCount; ++i) { + uintptr_t currentMeta = *(metadataStart + i); + + uint32_t metaIndex = *reinterpret_cast(currentMeta + 8); + if (metaIndex == index) { + return currentMeta; + } + } + + return 0; + } + + bool HasPageMap() const { + uintptr_t nextPage = *reinterpret_cast(reinterpret_cast(this) + 8); + if (nextPage == 0) + return false; + + uint8_t pageStatus = *reinterpret_cast(nextPage + 11); + if (pageStatus == 0) + return false; + + nextPage = 0; + bool hasPageMap = (nextPage != 0); + + return hasPageMap; + } + + bool MapContainsPointer(void* ptr) const { + uintptr_t basePage = reinterpret_cast(this); + uintptr_t nextPage = *reinterpret_cast(basePage + 8); + if (nextPage == 0) + return false; + + uint8_t pageStatus = *reinterpret_cast(nextPage + 11); + if (pageStatus == 0) + return false; + + uintptr_t* data = reinterpret_cast(nextPage + 16); + uintptr_t count = *reinterpret_cast(nextPage + 8); + + for (uintptr_t i = 0; i < count; ++i) { + uintptr_t elementPage = *(data + i); + if (elementPage >= reinterpret_cast(ptr) && elementPage < reinterpret_cast(ptr) + 24) { + return true; + } + } + + return false; + } + +private: + uint32_t m_map_size; +}; + +class pgBaseRefCounted : public pgBase { public: - virtual ~pgBaseMetaDataType() = default; - virtual void Lookup(uint32_t hash) = 0; -}; // Size: 0x0008 + virtual ~pgBaseRefCounted() = default; +}; -class pgBaseMetaDataDebugNameType : public pgBaseMetaDataType -{ +class pgBaseMetaDataType { public: - virtual ~pgBaseMetaDataDebugNameType() = default; - char pad_0000[64]; -}; // Size: 0x0072 + static pgBaseMetaDataType* m_first; + + pgBaseMetaDataType(uint32_t id, uintptr_t value) + : m_id(id), m_value(value), m_next(nullptr) { + if (!m_first) { + m_first = this; + } + } + + ~pgBaseMetaDataType() { + if (m_first == this) { + m_first = m_next; + } else { + pgBaseMetaDataType* current = m_first; + while (current && current->m_next != this) { + current = current->m_next; + } + if (current) { + current->m_next = m_next; + } + } + } + + static pgBaseMetaDataType* Lookup(uint32_t id) { + pgBaseMetaDataType* current = m_first; + while (current != nullptr) { + if (current->m_id == id) { + return current; + } + current = current->m_next; + } + return nullptr; + } + +private: + uint32_t m_id; + uintptr_t m_value; + pgBaseMetaDataType* m_next; +}; -class pgBaseRefCounted : public pgBase -{ -public: - virtual ~pgBaseRefCounted() = default; -}; // Size: 0x0008 } \ No newline at end of file