From 7dd107916c80e9fcba413ca806c9880ef46e5b89 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 30 Apr 2022 18:59:55 +0200 Subject: [PATCH] Fix rare crash Rare crash when the sqvm tries to look for an animation sequence on a missing prop_dynamic model (mdl/error.rmdl doesn't support animations), its purely to indicate there is a problem). --- r5dev/core/init.cpp | 3 +++ r5dev/game/shared/animation.cpp | 30 ++++++++++++++++++++++++++++ r5dev/game/shared/animation.h | 31 +++++++++++++++++++++++++++++ r5dev/public/include/studio.h | 11 ++++++++++ r5dev/vproj/gamesdk.vcxproj | 2 ++ r5dev/vproj/gamesdk.vcxproj.filters | 9 +++++++++ 6 files changed, 86 insertions(+) create mode 100644 r5dev/game/shared/animation.cpp create mode 100644 r5dev/game/shared/animation.h diff --git a/r5dev/core/init.cpp b/r5dev/core/init.cpp index cc613700..36559b2a 100644 --- a/r5dev/core/init.cpp +++ b/r5dev/core/init.cpp @@ -86,6 +86,7 @@ #include "engine/gl_rsurf.h" #include "engine/debugoverlay.h" #endif // !DEDICATED +#include "game/shared/animation.h" #ifndef CLIENT_DLL #include "game/server/ai_node.h" #include "game/server/ai_network.h" @@ -201,6 +202,7 @@ void Systems_Init() RSurf_Attach(); #endif // !DEDICATED + Animation_Attach(); #ifndef CLIENT_DLL CAI_Utility_Attach(); CAI_Network_Attach(); @@ -311,6 +313,7 @@ void Systems_Shutdown() RSurf_Detach(); #endif // !DEDICATED + Animation_Detach(); #ifndef CLIENT_DLL CAI_Utility_Detach(); CAI_Network_Detach(); diff --git a/r5dev/game/shared/animation.cpp b/r5dev/game/shared/animation.cpp new file mode 100644 index 00000000..6dcca68e --- /dev/null +++ b/r5dev/game/shared/animation.cpp @@ -0,0 +1,30 @@ +//=============================================================================// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#include "core/stdafx.h" +#include "public/include/studio.h" +#include "game/shared/animation.h" + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +int CStudioHdr::LookupSequence(CStudioHdr* pStudio, const char* pszName) +{ + if (!pStudio->m_pMdlCacheVTable) + return -1; // animations are unavailable for missing dynamic props! (mdl/error.rmdl). + + return v_CStudioHdr__LookupSequence(pStudio, pszName); +} + +void Animation_Attach() +{ + DetourAttach((LPVOID*)&v_CStudioHdr__LookupSequence, &CStudioHdr::LookupSequence); +} + +void Animation_Detach() +{ + DetourDetach((LPVOID*)&v_CStudioHdr__LookupSequence, &CStudioHdr::LookupSequence); +} diff --git a/r5dev/game/shared/animation.h b/r5dev/game/shared/animation.h new file mode 100644 index 00000000..c462d717 --- /dev/null +++ b/r5dev/game/shared/animation.h @@ -0,0 +1,31 @@ +#ifndef ANIMATION_H +#define ANIMATION_H + +inline CMemory p_CStudioHdr__LookupSequence; +inline auto v_CStudioHdr__LookupSequence = p_CStudioHdr__LookupSequence.RCast(); + +void Animation_Attach(); +void Animation_Detach(); +/////////////////////////////////////////////////////////////////////////////// +class HAnimation : public IDetour +{ + virtual void GetAdr(void) const + { + std::cout << "| FUN: CStudioHdr::LookupSequence : 0x" << std::hex << std::uppercase << p_CStudioHdr__LookupSequence.GetPtr() << std::setw(nPad) << " |" << std::endl; + std::cout << "+----------------------------------------------------------------+" << std::endl; + } + virtual void GetFun(void) const + { + p_CStudioHdr__LookupSequence = g_mGameDll.FindPatternSIMD(reinterpret_cast("\x40\x53\x48\x83\xEC\x20\x48\x8B\xD9\x4C\x8B\xC2\x48\x8B\x89\x00\x00\x00\x00"), "xxxxxxxxxxxxxxx????"); + v_CStudioHdr__LookupSequence = p_CStudioHdr__LookupSequence.RCast(); /*40 53 48 83 EC 20 48 8B D9 4C 8B C2 48 8B 89 ?? ?? ?? ??*/ + } + virtual void GetVar(void) const { } + virtual void GetCon(void) const { } + virtual void Attach(void) const { } + virtual void Detach(void) const { } +}; +/////////////////////////////////////////////////////////////////////////////// + +REGISTER(HAnimation); + +#endif // ANIMATION_H diff --git a/r5dev/public/include/studio.h b/r5dev/public/include/studio.h index 709419e0..3308fd38 100644 --- a/r5dev/public/include/studio.h +++ b/r5dev/public/include/studio.h @@ -67,4 +67,15 @@ struct studiohdr_t }; #pragma pack(pop) +class CStudioHdr +{ +public: + static int LookupSequence(CStudioHdr* pStudio, const char* pszName); + + int64_t m_nUnk0; + studiohdr_t* m_pStudioHdr; + uint8_t m_Pad[0x85A]; // Compatible between S0 - S3. + void* m_pMdlCacheVTable; +}; + #endif // STUDIO_H diff --git a/r5dev/vproj/gamesdk.vcxproj b/r5dev/vproj/gamesdk.vcxproj index b0e8f7f4..65e67dbb 100644 --- a/r5dev/vproj/gamesdk.vcxproj +++ b/r5dev/vproj/gamesdk.vcxproj @@ -54,6 +54,7 @@ + @@ -180,6 +181,7 @@ + diff --git a/r5dev/vproj/gamesdk.vcxproj.filters b/r5dev/vproj/gamesdk.vcxproj.filters index 29339a14..cbe86f10 100644 --- a/r5dev/vproj/gamesdk.vcxproj.filters +++ b/r5dev/vproj/gamesdk.vcxproj.filters @@ -181,6 +181,9 @@ {67444ecb-b115-4231-a33b-aab424f785fc} + + {bb7fbc8a-906a-4322-b8d6-04a495e69a12} + @@ -474,6 +477,9 @@ sdk\engine + + sdk\game\shared + @@ -1328,6 +1334,9 @@ sdk\tier0 + + sdk\game\shared +