From fb00aa5c3719b57b299f535f5d024493fcb6e071 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:56:56 +0100 Subject: [PATCH] Force 'CMaterialSystem::IsMaterialInternal' no inline This seems to work a lot better for our crash handler. 'CMaterialSystem::IsMaterialInternal' still needs to be removed entirely in the future! --- r5dev/bsplib/bsplib.cpp | 2 +- r5dev/materialsystem/cmaterialsystem.cpp | 4 ++-- r5dev/materialsystem/cmaterialsystem.h | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/r5dev/bsplib/bsplib.cpp b/r5dev/bsplib/bsplib.cpp index 926da8c6..81310b33 100644 --- a/r5dev/bsplib/bsplib.cpp +++ b/r5dev/bsplib/bsplib.cpp @@ -400,7 +400,7 @@ void* __fastcall BuildPropStaticFrustumCullMap(int64_t a1, int64_t a2, unsigned if (reinterpret_cast(v68) < g_GameDll.m_RunTimeData.m_pSectionBase || // Check bounds (data is mostly within the '.data' segment. reinterpret_cast(v68) > g_GameDll.m_ExceptionTable.m_pSectionBase || error) { - if (!IsMaterialInternal(reinterpret_cast(v68))) // Last chance. + if (!CMaterialSystem::IsMaterialInternal(reinterpret_cast(v68))) // Last chance. { error = true; continue; diff --git a/r5dev/materialsystem/cmaterialsystem.cpp b/r5dev/materialsystem/cmaterialsystem.cpp index b124beea..d1a9144e 100644 --- a/r5dev/materialsystem/cmaterialsystem.cpp +++ b/r5dev/materialsystem/cmaterialsystem.cpp @@ -68,7 +68,7 @@ void* __fastcall DispatchDrawCall(int64_t a1, uint64_t a2, int a3, int a4, int64 // Input : **pCandidate - // Output : true if valid and material, false otherwise //----------------------------------------------------------------------------- -__declspec(noinline) bool IsMaterialInternal(void** pCandidate) +FORCENOINLINE bool CMaterialSystem::IsMaterialInternal(void** pCandidate) { // NOTE: this is a dirty fix, but for running technically broken BSP's, this is the only fix // besides going bare metal inline assembly (which on its own isn't directly the problem, but @@ -134,7 +134,7 @@ void VMaterialSystem::Attach() const { // TODO: This has to be removed!!! #ifndef _DEBUG - vector find_IMI_ref = CMemory(IsMaterialInternal).FindAllCallReferences(reinterpret_cast(BuildPropStaticFrustumCullMap), 1000); + vector find_IMI_ref = CMemory(CMaterialSystem::IsMaterialInternal).FindAllCallReferences(reinterpret_cast(BuildPropStaticFrustumCullMap), 1000); if (!find_IMI_ref.empty()) { void* imiRetAddr = find_IMI_ref.at(0).Offset(0x5).RCast(); diff --git a/r5dev/materialsystem/cmaterialsystem.h b/r5dev/materialsystem/cmaterialsystem.h index e57aff4f..efd37a17 100644 --- a/r5dev/materialsystem/cmaterialsystem.h +++ b/r5dev/materialsystem/cmaterialsystem.h @@ -7,6 +7,7 @@ class CMaterialSystem { public: + FORCENOINLINE static bool IsMaterialInternal(void** pCandidate); #ifndef DEDICATED static CMaterialGlue* FindMaterialEx(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain); static Vector2D GetScreenSize(CMaterialSystem* pMatSys = nullptr); @@ -43,8 +44,6 @@ inline int* g_nUnfreeStreamingTextureMemory = nullptr; inline int* g_nUnusableStreamingTextureMemory = nullptr; #endif // !DEDICATED -__declspec(noinline) bool IsMaterialInternal(void** pCandidate); - /////////////////////////////////////////////////////////////////////////////// class VMaterialSystem : public IDetour {