From ae496bb66ec698a639856cbc4b3821ae1fa8b425 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Sat, 2 Mar 2024 18:22:08 +0300 Subject: [PATCH 1/3] Fix crashes caused by createBuilding with engineRequestModel --- Client/game_sa/CPoolsSA.cpp | 9 ++++++ Client/game_sa/CPtrNodeSingleListSA.h | 45 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Client/game_sa/CPtrNodeSingleListSA.h diff --git a/Client/game_sa/CPoolsSA.cpp b/Client/game_sa/CPoolsSA.cpp index 6680e82194..32891fed71 100644 --- a/Client/game_sa/CPoolsSA.cpp +++ b/Client/game_sa/CPoolsSA.cpp @@ -26,6 +26,7 @@ #include "CWorldSA.h" #include "CKeyGenSA.h" #include "CFileLoaderSA.h" +#include "CPtrNodeSingleListSA.h" extern CGameSA* pGame; @@ -410,6 +411,14 @@ void CPoolsSA::RemoveBuilding(CBuilding* pBuilding) // Remove building from world pGame->GetWorld()->Remove(pInterface, CBuildingPool_Destructor); + // Remove building from cover list + CPtrNodeSingleListSAInterface* coverList = reinterpret_cast*>(0xC1A2B8); + coverList->RemoveItem(pInterface); + + // Remove plant + typedef CEntitySAInterface*(__cdecl * CPlantColEntEntry_Remove)(CEntitySAInterface * item); + ((CPlantColEntEntry_Remove)0x5DBEF0)(pInterface); + // Remove col reference auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex()); modelInfo->RemoveColRef(); diff --git a/Client/game_sa/CPtrNodeSingleListSA.h b/Client/game_sa/CPtrNodeSingleListSA.h new file mode 100644 index 0000000000..67dfe72669 --- /dev/null +++ b/Client/game_sa/CPtrNodeSingleListSA.h @@ -0,0 +1,45 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto v1.0 + * LICENSE: See LICENSE in the top level directory + * FILE: game_sa/CPtrNodeSingleListSA.cpp + * + * Multi Theft Auto is available from http://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +template +struct CPtrNodeSingleLink +{ + T* pItem; + CPtrNodeSingleLink* pNext; +}; + +template +class CPtrNodeSingleListSAInterface +{ +public: + void RemoveItem(T* item); + void RemoveAllItems(); + +private: + CPtrNodeSingleLink* m_pList; +}; + +template +void CPtrNodeSingleListSAInterface::RemoveItem(T* item) +{ + typedef void(__thiscall * CPtrNodeSingleList_RemoveItem_t)(CPtrNodeSingleListSAInterface * pLinkList, void* item); + ((CPtrNodeSingleList_RemoveItem_t)0x533610)(this, item); +} + +template +void CPtrNodeSingleListSAInterface::RemoveAllItems() +{ + while (m_pList) + { + RemoveItem(m_pList->pItem); + } +} From 1d9d4161466b9210763297d15d08d795b9c3cc73 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Sun, 3 Mar 2024 20:07:35 +0300 Subject: [PATCH 2/3] Use using --- Client/game_sa/CPoolsSA.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/game_sa/CPoolsSA.cpp b/Client/game_sa/CPoolsSA.cpp index 32891fed71..e3810ec443 100644 --- a/Client/game_sa/CPoolsSA.cpp +++ b/Client/game_sa/CPoolsSA.cpp @@ -416,8 +416,8 @@ void CPoolsSA::RemoveBuilding(CBuilding* pBuilding) coverList->RemoveItem(pInterface); // Remove plant - typedef CEntitySAInterface*(__cdecl * CPlantColEntEntry_Remove)(CEntitySAInterface * item); - ((CPlantColEntEntry_Remove)0x5DBEF0)(pInterface); + using CPlantColEntry_Remove = CEntitySAInterface* (*)(CEntitySAInterface*); + ((CPlantColEntry_Remove)0x5DBEF0)(pInterface); // Remove col reference auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex()); From 276658b7dec1956f98815676f93e2fc792d4f886 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Mon, 4 Mar 2024 18:22:30 +0300 Subject: [PATCH 3/3] using + clangformat --- Client/game_sa/CPtrNodeSingleListSA.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/game_sa/CPtrNodeSingleListSA.h b/Client/game_sa/CPtrNodeSingleListSA.h index 67dfe72669..06df6a2575 100644 --- a/Client/game_sa/CPtrNodeSingleListSA.h +++ b/Client/game_sa/CPtrNodeSingleListSA.h @@ -10,14 +10,14 @@ #pragma once -template +template struct CPtrNodeSingleLink { T* pItem; CPtrNodeSingleLink* pNext; }; -template +template class CPtrNodeSingleListSAInterface { public: @@ -31,7 +31,7 @@ class CPtrNodeSingleListSAInterface template void CPtrNodeSingleListSAInterface::RemoveItem(T* item) { - typedef void(__thiscall * CPtrNodeSingleList_RemoveItem_t)(CPtrNodeSingleListSAInterface * pLinkList, void* item); + using CPtrNodeSingleList_RemoveItem_t = void(__thiscall*)(CPtrNodeSingleListSAInterface * pLinkList, void* item); ((CPtrNodeSingleList_RemoveItem_t)0x533610)(this, item); }