Skip to content

Commit 6245a68

Browse files
authored
Fix crashes caused by createBuilding with engineRequestModel (#3330)
Bugs fixed: 1) Crash occurs when a resource that uses createBuilding with engineRequestModel is stopped 2) Destroyed building leaves grass
1 parent 229389a commit 6245a68

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

Client/game_sa/CPoolsSA.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "CWorldSA.h"
2727
#include "CKeyGenSA.h"
2828
#include "CFileLoaderSA.h"
29+
#include "CPtrNodeSingleListSA.h"
2930

3031
extern CGameSA* pGame;
3132

@@ -410,6 +411,14 @@ void CPoolsSA::RemoveBuilding(CBuilding* pBuilding)
410411
// Remove building from world
411412
pGame->GetWorld()->Remove(pInterface, CBuildingPool_Destructor);
412413

414+
// Remove building from cover list
415+
CPtrNodeSingleListSAInterface<CBuildingSAInterface>* coverList = reinterpret_cast<CPtrNodeSingleListSAInterface<CBuildingSAInterface>*>(0xC1A2B8);
416+
coverList->RemoveItem(pInterface);
417+
418+
// Remove plant
419+
using CPlantColEntry_Remove = CEntitySAInterface* (*)(CEntitySAInterface*);
420+
((CPlantColEntry_Remove)0x5DBEF0)(pInterface);
421+
413422
// Remove col reference
414423
auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex());
415424
modelInfo->RemoveColRef();

Client/game_sa/CPtrNodeSingleListSA.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CPtrNodeSingleListSA.cpp
6+
*
7+
* Multi Theft Auto is available from http://www.multitheftauto.com/
8+
*
9+
*****************************************************************************/
10+
11+
#pragma once
12+
13+
template <class T>
14+
struct CPtrNodeSingleLink
15+
{
16+
T* pItem;
17+
CPtrNodeSingleLink* pNext;
18+
};
19+
20+
template <class T>
21+
class CPtrNodeSingleListSAInterface
22+
{
23+
public:
24+
void RemoveItem(T* item);
25+
void RemoveAllItems();
26+
27+
private:
28+
CPtrNodeSingleLink<T>* m_pList;
29+
};
30+
31+
template <class T>
32+
void CPtrNodeSingleListSAInterface<T>::RemoveItem(T* item)
33+
{
34+
using CPtrNodeSingleList_RemoveItem_t = void(__thiscall*)(CPtrNodeSingleListSAInterface<T> * pLinkList, void* item);
35+
((CPtrNodeSingleList_RemoveItem_t)0x533610)(this, item);
36+
}
37+
38+
template <class T>
39+
void CPtrNodeSingleListSAInterface<T>::RemoveAllItems()
40+
{
41+
while (m_pList)
42+
{
43+
RemoveItem(m_pList->pItem);
44+
}
45+
}

0 commit comments

Comments
 (0)