Skip to content

Commit

Permalink
Fix vehicle crash
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Apr 14, 2024
1 parent 083b448 commit a192fe3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
15 changes: 15 additions & 0 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "CGameSA.h"
#include "CPtrNodeSingleListSA.h"
#include "MemSA.h"
#include "CVehicleSA.h"

extern CGameSA* pGame;

Expand Down Expand Up @@ -263,6 +264,8 @@ bool CBuildingsPoolSA::SetSize(int size)

pGame->GetPools()->GetDummyPool().UpdateBuildingLods(oldPool, newObjects);

RemoveVehicleDamageLinks();

return true;
}

Expand Down Expand Up @@ -307,6 +310,18 @@ void CBuildingsPoolSA::UpdateBackupLodPointers(uint32_t offset)
}
}

void CBuildingsPoolSA::RemoveVehicleDamageLinks()
{
const int count = pGame->GetPools()->GetVehicleCount();
for (int i = 0; i < count; i++)
{
auto* vehicle = pGame->GetPools()->GetVehicle(i);
{
vehicle->pEntity->GetVehicleInterface()->m_pCollidedEntity = nullptr;
}
}
}

bool CBuildingsPoolSA::HasFreeBuildingSlot()
{
return (*m_ppBuildingPoolInterface)->GetFreeSlot() != -1;
Expand Down
3 changes: 3 additions & 0 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*
*****************************************************************************/

#pragma once

#include <game/CBuildingsPool.h>
#include <CVector.h>
#include "CPoolSAInterface.h"
Expand All @@ -34,6 +36,7 @@ class CBuildingsPoolSA : public CBuildingsPool
bool AddBuildingToPool(CClientBuilding* pClientBuilding, CBuildingSA* pBuilding);
void UpdateIplEntrysPointers(uint32_t offset);
void UpdateBackupLodPointers(uint32_t offset);
void RemoveVehicleDamageLinks();

private:
SPoolData<CBuildingSA, CBuildingSAInterface, MAX_BUILDINGS> m_buildingPool;
Expand Down
7 changes: 2 additions & 5 deletions Client/game_sa/CPoolsSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ class CPoolsSA : public CPools
public:
void RemoveVehicle(CVehicle* pVehicle, bool bDelete = true);
SClientEntity<CVehicleSA>* GetVehicle(DWORD* pGameInterface);
unsigned long GetVehicleCount()
{
return m_vehiclePool.ulCount;
;
}
SClientEntity<CVehicleSA>* GetVehicle(size_t pos) { return &m_vehiclePool.arrayOfClientEntities[pos]; };
unsigned long GetVehicleCount() { return m_vehiclePool.ulCount; };
void DeleteAllVehicles();

// Objects pool
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/game/CPools.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class CPools
virtual void RemoveVehicle(CVehicle* pVehicle, bool bDelete = true) = 0;

virtual SClientEntity<CVehicleSA>* GetVehicle(DWORD* pGameInterface) = 0;
virtual SClientEntity<CVehicleSA>* GetVehicle(size_t pos) = 0;
virtual unsigned long GetVehicleCount() = 0;

// Objects pool
Expand Down

0 comments on commit a192fe3

Please sign in to comment.