#ifndef MATERIALSYSTEM_H #define MATERIALSYSTEM_H #include "cmaterialglue.h" #define STREAM_DB_EXT "stbsp" class CMaterialSystem { public: #ifndef DEDICATED static CMaterialGlue* FindMaterialEx(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain); static Vector2D GetScreenSize(CMaterialSystem* pMatSys = nullptr); #endif // !DEDICATED }; /* ==== MATERIALSYSTEM ================================================================================================================================================== */ inline CMemory p_CMaterialSystem__Init; inline auto CMaterialSystem__Init = p_CMaterialSystem__Init.RCast(); inline void* g_pMaterialSystem = nullptr; inline void* g_pMaterialVFTable = nullptr; #ifndef DEDICATED inline CMemory p_CMaterialSystem__FindMaterialEx; inline auto CMaterialSystem__FindMaterialEx = p_CMaterialSystem__FindMaterialEx.RCast(); inline CMemory p_CMaterialSystem_GetScreenSize; inline auto CMaterialSystem_GetScreenSize = p_CMaterialSystem_GetScreenSize.RCast(); #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) inline CMemory p_DispatchDrawCall; inline auto v_DispatchDrawCall = p_DispatchDrawCall.RCast(); #elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) inline CMemory p_DispatchDrawCall; inline auto v_DispatchDrawCall = p_DispatchDrawCall.RCast(); #endif inline CMemory p_DrawStreamOverlay; inline auto v_DrawStreamOverlay = p_DrawStreamOverlay.RCast(); inline CMemory s_pRenderContext; inline int* g_nTotalStreamingTextureMemory = nullptr; inline int* g_nUnfreeStreamingTextureMemory = nullptr; inline int* g_nUnusableStreamingTextureMemory = nullptr; #endif // !DEDICATED bool IsMaterialInternal(void** pCandidate); void CMaterialSystem_Attach(); void CMaterialSystem_Detach(); /////////////////////////////////////////////////////////////////////////////// class VMaterialSystem : public IDetour { virtual void GetAdr(void) const { spdlog::debug("| FUN: CMaterialSystem::Init : {:#18x} |\n", p_CMaterialSystem__Init.GetPtr()); #ifndef DEDICATED spdlog::debug("| FUN: CMaterialSystem::DispatchDrawCall : {:#18x} |\n", p_DispatchDrawCall.GetPtr()); spdlog::debug("| FUN: CMaterialSystem::DrawStreamOverlay : {:#18x} |\n", p_DrawStreamOverlay.GetPtr()); spdlog::debug("| VAR: g_nTotalStreamingTextureMemory : {:#18x} |\n", reinterpret_cast(g_nTotalStreamingTextureMemory)); spdlog::debug("| VAR: g_nUnfreeStreamingTextureMemory : {:#18x} |\n", reinterpret_cast(g_nUnfreeStreamingTextureMemory)); spdlog::debug("| VAR: g_nUnusableStreamingTextureMemory : {:#18x} |\n", reinterpret_cast(g_nUnusableStreamingTextureMemory)); spdlog::debug("| VAR: s_pRenderContext : {:#18x} |\n", s_pRenderContext.GetPtr()); #endif // !DEDICATED spdlog::debug("| VAR: g_pMaterialSystem : {:#18x} |\n", reinterpret_cast(g_pMaterialSystem)); spdlog::debug("| CON: g_pMaterialVFTable : {:#18x} |\n", reinterpret_cast(g_pMaterialVFTable)); spdlog::debug("+----------------------------------------------------------------+\n"); } virtual void GetFun(void) const { p_CMaterialSystem__Init = g_GameDll.FindPatternSIMD(reinterpret_cast("\x48\x89\x5C\x24\x00\x55\x56\x57\x41\x54\x41\x55\x41\x56\x41\x57\x48\x83\xEC\x70\x48\x83\x3D\x00\x00\x00\x00\x00"), "xxxx?xxxxxxxxxxxxxxxxxx?????"); CMaterialSystem__Init = p_CMaterialSystem__Init.RCast(); /*48 89 5C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 48 83 EC 70 48 83 3D ?? ?? ?? ?? ??*/ #ifndef DEDICATED p_CMaterialSystem__FindMaterialEx = g_GameDll.FindPatternSIMD(reinterpret_cast("\x44\x89\x4C\x24\x00\x44\x88\x44\x24\x00\x48\x89\x4C\x24\x00"), "xxxx?xxxx?xxxx?"); CMaterialSystem__FindMaterialEx = p_CMaterialSystem__FindMaterialEx.RCast(); /*44 89 4C 24 ?? 44 88 44 24 ?? 48 89 4C 24 ??*/ p_CMaterialSystem_GetScreenSize = g_GameDll.FindPatternSIMD(reinterpret_cast("\x8B\x05\x00\x00\x00\x00\x89\x02\x8B\x05\x00\x00\x00\x00\x41\x89\x00\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x8B\x05\x00\x00\x00\x00"), "xx????xxxx????xxxxxxxxxxxxxxxxxxxx????"); CMaterialSystem_GetScreenSize = p_CMaterialSystem_GetScreenSize.RCast(); /*8B 05 ? ? ? ? 89 02 8B 05 ? ? ? ? 41 89 00 C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 8B 05 ? ? ? ?*/ #if defined (GAMEDLL_S0) || defined (GAMEDLL_S1) p_DispatchDrawCall = g_GameDll.FindPatternSIMD(reinterpret_cast("\x44\x89\x4C\x24\x00\x44\x89\x44\x24\x00\x48\x89\x4C\x24\x00\x55\x53"), "xxxx?xxxx?xxxx?xx"); v_DispatchDrawCall = p_DispatchDrawCall.RCast(); #elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3) p_DispatchDrawCall = g_GameDll.FindPatternSIMD(reinterpret_cast("\x44\x89\x4C\x24\x00\x44\x89\x44\x24\x00\x48\x89\x4C\x24\x00\x55\x53\x56"), "xxxx?xxxx?xxxx?xxx"); v_DispatchDrawCall = p_DispatchDrawCall.RCast(); #endif p_DrawStreamOverlay = g_GameDll.FindPatternSIMD(reinterpret_cast("\x41\x56\xB8\x00\x00\x00\x00\xE8\x00\x00\x00\x00\x48\x2B\xE0\xC6\x02\x00"), "xxx????x????xxxxxx"); v_DrawStreamOverlay = p_DrawStreamOverlay.RCast(); // 41 56 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 C6 02 00 // #endif // !DEDICATED } virtual void GetVar(void) const { #ifndef DEDICATED g_nTotalStreamingTextureMemory = p_DrawStreamOverlay.Offset(0x0).FindPatternSelf("48 8B 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); g_nUnfreeStreamingTextureMemory = p_DrawStreamOverlay.Offset(0x20).FindPatternSelf("48 8B 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); g_nUnusableStreamingTextureMemory = p_DrawStreamOverlay.Offset(0x50).FindPatternSelf("48 8B 05", CMemory::Direction::DOWN).ResolveRelativeAddressSelf(0x3, 0x7).RCast(); s_pRenderContext = p_DispatchDrawCall.FindPattern("48 8B ?? ?? ?? ?? 01").ResolveRelativeAddressSelf(0x3, 0x7); #endif // !DEDICATED g_pMaterialSystem = g_GameDll.FindPatternSIMD(reinterpret_cast( "\x48\x8B\x0D\x00\x00\x00\x00\x48\x85\xC9\x74\x11\x48\x8B\x01\x48\x8D\x15\x00\x00\x00\x00"), "xxx????xxxxxxxxxxx????").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); } virtual void GetCon(void) const { g_pMaterialVFTable = g_GameDll.GetVirtualMethodTable(".?AVCMaterial@@").RCast(); } virtual void Attach(void) const { } virtual void Detach(void) const { } }; /////////////////////////////////////////////////////////////////////////////// REGISTER(VMaterialSystem); #endif // MATERIALSYSTEM_H