diff --git a/r5dev/datacache/mdlcache.cpp b/r5dev/datacache/mdlcache.cpp index 032e33af..9b32d850 100644 --- a/r5dev/datacache/mdlcache.cpp +++ b/r5dev/datacache/mdlcache.cpp @@ -190,6 +190,11 @@ studiohdr_t* CMDLCache::FindUncachedMDL(CMDLCache* const cache, const MDLHandle_ return studioHdr; } +//----------------------------------------------------------------------------- +// Purpose: gets the model cache by handle +// Input : handle - +// Output : a pointer to the studiomodelcache_t object +//----------------------------------------------------------------------------- studiomodelcache_t* CMDLCache::GetModelCache(const MDLHandle_t handle) { if (handle == MDLHANDLE_INVALID) @@ -318,11 +323,6 @@ studiohwdata_t* CMDLCache::GetHardwareData(CMDLCache* const cache, const MDLHand //----------------------------------------------------------------------------- studiohdr_t* CMDLCache::GetErrorModel(void) { - // NOTE: must enable the old gather props logic for fallback models to draw !!! - // The new one won't call GetHardwareData on bad model handles. - // TODO[ AMOS ]: move this elsewhere; correct place is GatherStaticPropsSecondPass(). - g_StudioMdlFallbackHandler.EnableLegacyGatherProps(); - return g_StudioMdlFallbackHandler.GetFallbackModelHeader(); } const char* CMDLCache::GetErrorModelName(void) diff --git a/r5dev/engine/staticpropmgr.cpp b/r5dev/engine/staticpropmgr.cpp index 4be31af0..fe58e1a2 100644 --- a/r5dev/engine/staticpropmgr.cpp +++ b/r5dev/engine/staticpropmgr.cpp @@ -22,9 +22,32 @@ void* CStaticProp::Init(CStaticProp* thisptr, int64_t a2, unsigned int idx, unsi return CStaticProp__Init(thisptr, a2, idx, a4, lump, a6, a7); } +//----------------------------------------------------------------------------- +// NOTE: the following gather props functions have been hooked as we must +// enable the old gather props logic for fall back models to draw !!! The +// new solution won't call CMDLCache::GetHardwareData() on bad model handles. +//----------------------------------------------------------------------------- +void* GatherStaticPropsSecondPass_PreInit(GatherProps_t* gather) +{ + if (g_StudioMdlFallbackHandler.HasInvalidModelHandles()) + g_StudioMdlFallbackHandler.EnableLegacyGatherProps(); + + return v_GatherStaticPropsSecondPass_PreInit(gather); +} +void* GatherStaticPropsSecondPass_PostInit(GatherProps_t* gather) +{ + if (g_StudioMdlFallbackHandler.HasInvalidModelHandles()) + g_StudioMdlFallbackHandler.EnableLegacyGatherProps(); + + return v_GatherStaticPropsSecondPass_PostInit(gather); +} + void VStaticPropMgr::Detour(const bool bAttach) const { #ifndef DEDICATED DetourSetup(&CStaticProp__Init, &CStaticProp::Init, bAttach); #endif // !DEDICATED + + DetourSetup(&v_GatherStaticPropsSecondPass_PreInit, &GatherStaticPropsSecondPass_PreInit, bAttach); + DetourSetup(&v_GatherStaticPropsSecondPass_PostInit, &GatherStaticPropsSecondPass_PostInit, bAttach); } diff --git a/r5dev/engine/staticpropmgr.h b/r5dev/engine/staticpropmgr.h index 2ee7277d..b7ee2ab8 100644 --- a/r5dev/engine/staticpropmgr.h +++ b/r5dev/engine/staticpropmgr.h @@ -1,6 +1,25 @@ #pragma once #include "public/gamebspfile.h" +struct GatherProps_t +{ + // TODO: reverse structure. + int field_0; + int field_4; + int field_8; + int field_C; + _BYTE gap10[8]; + int field_18; + int field_1C; + int field_20; + int field_24; + int field_28; + __int64 field_30; + int field_38; + int field_3C; + __int64 field_40; +}; + class CStaticProp { public: @@ -10,6 +29,8 @@ private: // TODO: reverse structure. }; inline void*(*CStaticProp__Init)(CStaticProp* thisptr, int64_t a2, unsigned int idx, unsigned int a4, StaticPropLump_t* lump, int64_t a6, int64_t a7); +inline void*(*v_GatherStaticPropsSecondPass_PreInit)(GatherProps_t* gather); +inline void* (*v_GatherStaticPropsSecondPass_PostInit)(GatherProps_t* gather); /////////////////////////////////////////////////////////////////////////////// class VStaticPropMgr : public IDetour @@ -22,6 +43,8 @@ class VStaticPropMgr : public IDetour virtual void GetFun(void) const { g_GameDll.FindPatternSIMD("48 8B C4 44 89 40 18 48 89 50 10 55").GetPtr(CStaticProp__Init); + g_GameDll.FindPatternSIMD("48 89 4C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8D 6C 24 ?? 48 8B 05 ?? ?? ?? ?? 4C 8B F9").GetPtr(v_GatherStaticPropsSecondPass_PreInit); + g_GameDll.FindPatternSIMD("48 89 4C 24 ?? 55 56 57 41 54 41 55 41 56 41 57 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8D 6C 24 ?? 48 8B 05 ?? ?? ?? ?? 4C 8B F1").GetPtr(v_GatherStaticPropsSecondPass_PostInit); } virtual void GetVar(void) const {