Skip to content

Fix crashes caused by createBuilding with engineRequestModel #3330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Client/game_sa/CPoolsSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "CWorldSA.h"
#include "CKeyGenSA.h"
#include "CFileLoaderSA.h"
#include "CPtrNodeSingleListSA.h"

extern CGameSA* pGame;

Expand Down Expand Up @@ -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<CBuildingSAInterface>* coverList = reinterpret_cast<CPtrNodeSingleListSAInterface<CBuildingSAInterface>*>(0xC1A2B8);
coverList->RemoveItem(pInterface);

// Remove plant
using CPlantColEntry_Remove = CEntitySAInterface* (*)(CEntitySAInterface*);
((CPlantColEntry_Remove)0x5DBEF0)(pInterface);

// Remove col reference
auto modelInfo = pGame->GetModelInfo(pBuilding->GetModelIndex());
modelInfo->RemoveColRef();
Expand Down
45 changes: 45 additions & 0 deletions Client/game_sa/CPtrNodeSingleListSA.h
Original file line number Diff line number Diff line change
@@ -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<class T>
struct CPtrNodeSingleLink
{
T* pItem;
CPtrNodeSingleLink* pNext;
};

template<class T>
class CPtrNodeSingleListSAInterface
{
public:
void RemoveItem(T* item);
void RemoveAllItems();

private:
CPtrNodeSingleLink<T>* m_pList;
};

template <class T>
void CPtrNodeSingleListSAInterface<T>::RemoveItem(T* item)
{
typedef void(__thiscall * CPtrNodeSingleList_RemoveItem_t)(CPtrNodeSingleListSAInterface<T> * pLinkList, void* item);
((CPtrNodeSingleList_RemoveItem_t)0x533610)(this, item);
}

template <class T>
void CPtrNodeSingleListSAInterface<T>::RemoveAllItems()
{
while (m_pList)
{
RemoveItem(m_pList->pItem);
}
}