Skip to content

Commit

Permalink
Fix cover crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Apr 28, 2024
1 parent 5d366b9 commit 4569a72
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 7 deletions.
26 changes: 23 additions & 3 deletions Client/game_sa/CCoverManagerSA.cpp
Original file line number Diff line number Diff line change
@@ -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<CPtrNodeSingleListSAInterface<CEntitySAInterface>*>(0xC1A2B8);
m_pCoverList = reinterpret_cast<CPtrNodeDoubleListSAInterface<CEntitySAInterface>*>(0xC1A2B8);
}

void CCoverManagerSA::RemoveAllCovers()
{
CPtrNodeDoubleLink<CEntitySAInterface>* 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);
}
17 changes: 15 additions & 2 deletions Client/game_sa/CCoverManagerSA.h
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -13,5 +23,8 @@ class CCoverManagerSA
void RemoveCover(CEntitySAInterface* entity);

private:
CPtrNodeSingleListSAInterface<CEntitySAInterface>* m_pCoverList;
void RemoveCoverFromArray(CEntitySAInterface* entity);

private:
CPtrNodeDoubleListSAInterface<CEntitySAInterface>* m_pCoverList;
};
3 changes: 2 additions & 1 deletion Client/game_sa/CPhysicalSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <game/CPhysical.h>
#include "CEntitySA.h"
#include <CVector.h>
#include "CPtrNodeDoubleListSA.h"

#define FUNC_GetMoveSpeed 0x404460
#define FUNC_GetTurnSpeed 0x470030
Expand Down Expand Up @@ -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<void>* m_pControlCodeNodeLink; // 296
float m_fLighting; // 300
float m_fLighting2; // 304
class CShadowDataSA* m_pShadowData; // 308
Expand Down
41 changes: 41 additions & 0 deletions Client/game_sa/CPtrNodeDoubleListSA.h
Original file line number Diff line number Diff line change
@@ -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 T>
class CPtrNodeDoubleLink
{
public:
T* pItem;
CPtrNodeDoubleLink<T>* pNext;
CPtrNodeDoubleLink<T>* pPrev;
};

template <class T>
class CPtrNodeDoubleListSAInterface
{
public:
CPtrNodeDoubleLink<T>* m_pNode;

void RemoveItem(T* pItem)
{
using CPtrListDoubleLinkSAInterface_RemoveItem = void(__thiscall*)(CPtrNodeDoubleListSAInterface<T> * pLinkList, void* item);
((CPtrListDoubleLinkSAInterface_RemoveItem)0x5336B0)(this, pItem);
};

void RemoveAllItems()
{
while (m_pNode)
{
RemoveItem(m_pNode->pItem);
}
};
};
2 changes: 1 addition & 1 deletion Client/game_sa/CPtrNodeSingleListSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*
Expand Down

0 comments on commit 4569a72

Please sign in to comment.