Skip to content

Commit

Permalink
Fix engineSetPoolCapacity crash (#3413)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Jun 2, 2024
1 parent b6216ca commit 6702200
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
22 changes: 22 additions & 0 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ bool CBuildingsPoolSA::Resize(int size)
pGame->GetPools()->GetDummyPool().UpdateBuildingLods(oldPool, newObjects);

RemoveVehicleDamageLinks();
RemovePedsContactEnityLinks();

return true;
}
Expand Down Expand Up @@ -310,6 +311,27 @@ void CBuildingsPoolSA::RemoveVehicleDamageLinks()
}
}

void CBuildingsPoolSA::RemovePedsContactEnityLinks()
{
const int count = pGame->GetPools()->GetPedCount();
for (int i = 0; i < count; i++)
{
auto* pedLinks = pGame->GetPools()->GetPed(i);
if (pedLinks->pEntity)
{
CPedSAInterface* ped = pedLinks->pEntity->GetPedInterface();
ped->m_pCollidedEntity = nullptr;
ped->pContactEntity = nullptr;
ped->pLastContactedEntity[0] = nullptr;
ped->pLastContactedEntity[1] = nullptr;
ped->pLastContactedEntity[2] = nullptr;
ped->pLastContactedEntity[3] = nullptr;
ped->m_ucCollisionState = 0;
ped->pTargetedEntity = nullptr;
}
}
}

bool CBuildingsPoolSA::HasFreeBuildingSlot()
{
return (*m_ppBuildingPoolInterface)->GetFreeSlot() != -1;
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CBuildingsPoolSA : public CBuildingsPool
void UpdateIplEntrysPointers(uint32_t offset);
void UpdateBackupLodPointers(uint32_t offset);
void RemoveVehicleDamageLinks();
void RemovePedsContactEnityLinks();

private:
SPoolData<CBuildingSA, CBuildingSAInterface, MAX_BUILDINGS> m_buildingPool;
Expand Down
2 changes: 1 addition & 1 deletion Client/game_sa/CPedSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ CVehicle* CPedSA::GetVehicle()
{
if (((CPedSAInterface*)GetInterface())->pedFlags.bInVehicle)
{
CVehicleSAInterface* vehicle = (CVehicleSAInterface*)(((CPedSAInterface*)GetInterface())->CurrentObjective);
CVehicleSAInterface* vehicle = (CVehicleSAInterface*)(((CPedSAInterface*)GetInterface())->pVehicle);
if (vehicle)
{
SClientEntity<CVehicleSA>* pVehicleClientEntity = pGame->GetPools()->GetVehicle((DWORD*)vehicle);
Expand Down
18 changes: 13 additions & 5 deletions Client/game_sa/CPedSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class CPedWeaponAudioEntitySAInterface
public:
};

class CVehicleSAInterface;

class CPedSAInterface : public CPhysicalSAInterface // +1420 = current vehicle 312 first byte
{
public:
Expand Down Expand Up @@ -239,11 +241,17 @@ class CPedSAInterface : public CPhysicalSAInterface // +1420 = curre
float fCurrentRotation;
float fTargetRotation;
float fRotationSpeed;
BYTE bPad8[4];
CEntitySAInterface* pContactEntity;
BYTE bPad3[32];
CEntitySAInterface* CurrentObjective; // current vehicle 1420
BYTE bPad2[8]; // 1424
float fMoveAnim;
CPedSAInterface* unkPed;
CVector unk_56C;
CVector unk_578;

CEntitySAInterface* pContactEntity;
CVehicleSAInterface* pLastVehicle;
CVehicleSAInterface* pVehicle;

int unk_590;
int unk_594;
BYTE bPedType; // ped type? 0 = player, >1 = ped? // 1432
BYTE bPad9[7];
CWeaponSAInterface Weapons[WEAPONSLOT_MAX];
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CPoolsSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class CPoolsSA : public CPools
public:
void RemovePed(CPed* ped, bool bDelete = true);
SClientEntity<CPedSA>* GetPed(DWORD* pGameInterface);
SClientEntity<CPedSA>* GetPed(size_t pos) { return &m_pedPool.arrayOfClientEntities[pos]; };
CPed* GetPedFromRef(DWORD dwGameRef);
CPedSAInterface* GetPedInterface(DWORD dwGameRef); // game_sa specific
unsigned long GetPedCount() { return m_pedPool.ulCount; }
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 @@ -86,6 +86,7 @@ class CPools
virtual void RemovePed(CPed* pPed, bool bDelete = true) = 0;

virtual SClientEntity<CPedSA>* GetPed(DWORD* pGameInterface) = 0; // not sure we really want this here
virtual SClientEntity<CPedSA>* GetPed(size_t pos) = 0;
virtual CPed* GetPedFromRef(DWORD dwGameRef) = 0;
virtual unsigned long GetPedCount() = 0;

Expand Down

0 comments on commit 6702200

Please sign in to comment.