From 83b95d23c9194bc90cc57cdc851d22fcccd69500 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Mon, 25 Dec 2023 18:47:05 +0100 Subject: [PATCH] MaterialSystem: Expose the proper pointer The first pointer was a pointing to a pointer to g_MaterialSystem. The new pointer points directly to g_MaterialSystem. Also added CMaterialSystem::GetCurrentFrameCount() for g_FrameNum. --- r5dev/materialsystem/cmaterialsystem.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/r5dev/materialsystem/cmaterialsystem.h b/r5dev/materialsystem/cmaterialsystem.h index 1058ca96..59b94aef 100644 --- a/r5dev/materialsystem/cmaterialsystem.h +++ b/r5dev/materialsystem/cmaterialsystem.h @@ -14,6 +14,13 @@ public: static CMaterialGlue* FindMaterialEx(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain); static Vector2D GetScreenSize(CMaterialSystem* pMatSys = nullptr); #endif // !MATERIALSYSTEM_NODX + + // TODO: reverse the vftable! + inline int GetCurrentFrameCount() + { + const static int index = 74; + return CallVFunc(index, this); + } }; #ifndef MATERIALSYSTEM_NODX @@ -91,6 +98,13 @@ inline int* g_nUnfreeStreamingTextureMemory = nullptr; inline int* g_nUnusableStreamingTextureMemory = nullptr; #endif // !MATERIALSYSTEM_NODX +// TODO: move to materialsystem_global.h! +// TODO: reverse the vftable! +inline CMaterialSystem* MaterialSystem() +{ + return g_pMaterialSystem; +} + /////////////////////////////////////////////////////////////////////////////// class VMaterialSystem : public IDetour { @@ -158,7 +172,7 @@ class VMaterialSystem : public IDetour s_pRenderContext = p_DispatchDrawCall.FindPattern("48 8B ?? ?? ?? ?? 01").ResolveRelativeAddressSelf(0x3, 0x7); g_pMaterialAdapterMgr = p_CMaterialSystem__Disconnect.FindPattern("48 8D").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); #endif // !MATERIALSYSTEM_NODX - g_pMaterialSystem = g_GameDll.FindPatternSIMD("48 8B 0D ?? ?? ?? ?? 48 85 C9 74 11 48 8B 01 48 8D 15 ?? ?? ?? ??").ResolveRelativeAddressSelf(0x3, 0x7).RCast(); + g_pMaterialSystem = g_GameDll.FindPatternSIMD("8B 41 28 85 C0 7F 18").FindPatternSelf("48 8D 0D").ResolveRelativeAddressSelf(3, 7).RCast(); } virtual void GetCon(void) const {