Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions Client/game_sa/CBuildingsPoolSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ void CBuildingsPoolSA::RemoveAllWithBackup()
RemoveBuildingFromWorld(building);

if (building->HasMatrix())
{
// Keep original matrix
m_buildingMatrix[building] = *building->matrix;

building->RemoveMatrix();
}

pBuildsingsPool->Release(i);

Expand Down Expand Up @@ -231,6 +236,21 @@ void CBuildingsPoolSA::RestoreBackup()
auto* pBuilding = pBuildsingsPool->AllocateAtNoInit(i);
std::memcpy(pBuilding, &originalData[i].second, sizeof(CBuildingSAInterface));

// Restore matrix if it was removed
auto it = m_buildingMatrix.find(pBuilding);
if (it != m_buildingMatrix.end())
{
if (!pBuilding->HasMatrix())
pBuilding->AllocateMatrix();

pBuilding->matrix->vRight = it->second.vRight;
pBuilding->matrix->vFront = it->second.vFront;
pBuilding->matrix->vUp = it->second.vUp;
pBuilding->matrix->vPos = it->second.vPos;

m_buildingMatrix.erase(it);
}

worldSA->Add(pBuilding, CBuildingPool_Constructor);
buildingRemovealSA->AddDataBuilding(pBuilding);
}
Expand Down
2 changes: 2 additions & 0 deletions Client/game_sa/CBuildingsPoolSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class CBuildingsPoolSA : public CBuildingsPool

std::unique_ptr<backup_container_t> m_pOriginalBuildingsBackup;

std::unordered_map<CBuildingSAInterface*, CMatrix_Padded> m_buildingMatrix{};

// Set by RemoveAllWithBackup after sweeping stale entity links (vehicle damage,
// ped contact, object entity refs). Cleared by Resize to skip a redundant pass
// when SetBuildingPoolSize calls both in the same remove/resize cycle.
Expand Down
1 change: 1 addition & 0 deletions Client/game_sa/CPlaceableSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CPlaceableSAInterface
bool IsPlaceableVTBL() const { return GetVTBL() == (void*)0x863C40; }

bool HasMatrix() const noexcept { return matrix != nullptr; }
void AllocateMatrix() { ((void(__thiscall*)(void*))0x54F560)(this); }
void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); }

void SetOrientation(float x, float y, float z) { ((void(__thiscall*)(CPlaceableSAInterface * pEntity, float, float, float))0x439A80)(this, x, y, z); }
Expand Down
Loading