From 4569a7200cea94a4965e5ed221f5f4b65d67b0c4 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Sun, 28 Apr 2024 22:25:26 +0300 Subject: [PATCH] Fix cover crashes --- Client/game_sa/CCoverManagerSA.cpp | 26 +++++++++++++++-- Client/game_sa/CCoverManagerSA.h | 17 +++++++++-- Client/game_sa/CPhysicalSA.h | 3 +- Client/game_sa/CPtrNodeDoubleListSA.h | 41 +++++++++++++++++++++++++++ Client/game_sa/CPtrNodeSingleListSA.h | 2 +- 5 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 Client/game_sa/CPtrNodeDoubleListSA.h diff --git a/Client/game_sa/CCoverManagerSA.cpp b/Client/game_sa/CCoverManagerSA.cpp index 5e625cdad6..dee7782ffb 100644 --- a/Client/game_sa/CCoverManagerSA.cpp +++ b/Client/game_sa/CCoverManagerSA.cpp @@ -1,21 +1,41 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto v1.0 + * LICENSE: See LICENSE in the top level directory + * FILE: game_sa/CCoverManagerSA.cpp + * + * Multi Theft Auto is available from http://www.multitheftauto.com/ + * + *****************************************************************************/ #include "StdInc.h" #include "CCoverManagerSA.h" CCoverManagerSA::CCoverManagerSA() { - m_pCoverList = reinterpret_cast*>(0xC1A2B8); + m_pCoverList = reinterpret_cast*>(0xC1A2B8); } void CCoverManagerSA::RemoveAllCovers() { + CPtrNodeDoubleLink* pNode = m_pCoverList->m_pNode; + while (pNode) + { + RemoveCoverFromArray(pNode->pItem); + pNode = pNode->pNext; + } m_pCoverList->RemoveAllItems(); } void CCoverManagerSA::RemoveCover(CEntitySAInterface* entity) { + RemoveCoverFromArray(entity); + m_pCoverList->RemoveItem(entity); +} - //using CCover_RemoveCoverPointsForThisEntity = char (__cdecl*)(CEntitySAInterface*); - //((CCover_RemoveCoverPointsForThisEntity)0x698740)(entity); +void CCoverManagerSA::RemoveCoverFromArray(CEntitySAInterface* entity) +{ + using CCover_RemoveCoverPointsForThisEntity = char(__cdecl*)(CEntitySAInterface*); + ((CCover_RemoveCoverPointsForThisEntity)0x698740)(entity); } diff --git a/Client/game_sa/CCoverManagerSA.h b/Client/game_sa/CCoverManagerSA.h index 209cfb44c8..6944b43604 100644 --- a/Client/game_sa/CCoverManagerSA.h +++ b/Client/game_sa/CCoverManagerSA.h @@ -1,7 +1,17 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto v1.0 + * LICENSE: See LICENSE in the top level directory + * FILE: game_sa/CCoverManagerSA.h + * + * Multi Theft Auto is available from http://www.multitheftauto.com/ + * + *****************************************************************************/ + #pragma once #include "CEntitySA.h" -#include "CPtrNodeSingleListSA.h" +#include "CPtrNodeDoubleListSA.h" class CCoverManagerSA { @@ -13,5 +23,8 @@ class CCoverManagerSA void RemoveCover(CEntitySAInterface* entity); private: - CPtrNodeSingleListSAInterface* m_pCoverList; + void RemoveCoverFromArray(CEntitySAInterface* entity); + +private: + CPtrNodeDoubleListSAInterface* m_pCoverList; }; diff --git a/Client/game_sa/CPhysicalSA.h b/Client/game_sa/CPhysicalSA.h index 7ac72168f1..2b1234150c 100644 --- a/Client/game_sa/CPhysicalSA.h +++ b/Client/game_sa/CPhysicalSA.h @@ -14,6 +14,7 @@ #include #include "CEntitySA.h" #include +#include "CPtrNodeDoubleListSA.h" #define FUNC_GetMoveSpeed 0x404460 #define FUNC_GetTurnSpeed 0x470030 @@ -102,7 +103,7 @@ class CPhysicalSAInterface : public CEntitySAInterface CVector m_vecAttachedRotation; // 268 CVector m_vecUnk; // 280 uint32 m_pad4; // 292 - class CPtrNodeDoubleLink* m_pControlCodeNodeLink; // 296 + CPtrNodeDoubleLink* m_pControlCodeNodeLink; // 296 float m_fLighting; // 300 float m_fLighting2; // 304 class CShadowDataSA* m_pShadowData; // 308 diff --git a/Client/game_sa/CPtrNodeDoubleListSA.h b/Client/game_sa/CPtrNodeDoubleListSA.h new file mode 100644 index 0000000000..fb6f6c9978 --- /dev/null +++ b/Client/game_sa/CPtrNodeDoubleListSA.h @@ -0,0 +1,41 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto v1.0 + * LICENSE: See LICENSE in the top level directory + * FILE: game_sa/CPtrNodeDoubleListSA.h + * + * Multi Theft Auto is available from http://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +template +class CPtrNodeDoubleLink +{ +public: + T* pItem; + CPtrNodeDoubleLink* pNext; + CPtrNodeDoubleLink* pPrev; +}; + +template +class CPtrNodeDoubleListSAInterface +{ +public: + CPtrNodeDoubleLink* m_pNode; + + void RemoveItem(T* pItem) + { + using CPtrListDoubleLinkSAInterface_RemoveItem = void(__thiscall*)(CPtrNodeDoubleListSAInterface * pLinkList, void* item); + ((CPtrListDoubleLinkSAInterface_RemoveItem)0x5336B0)(this, pItem); + }; + + void RemoveAllItems() + { + while (m_pNode) + { + RemoveItem(m_pNode->pItem); + } + }; +}; diff --git a/Client/game_sa/CPtrNodeSingleListSA.h b/Client/game_sa/CPtrNodeSingleListSA.h index 06df6a2575..f083614421 100644 --- a/Client/game_sa/CPtrNodeSingleListSA.h +++ b/Client/game_sa/CPtrNodeSingleListSA.h @@ -2,7 +2,7 @@ * * PROJECT: Multi Theft Auto v1.0 * LICENSE: See LICENSE in the top level directory - * FILE: game_sa/CPtrNodeSingleListSA.cpp + * FILE: game_sa/CPtrNodeSingleListSA.h * * Multi Theft Auto is available from http://www.multitheftauto.com/ *