Skip to content

Commit 1377cb9

Browse files
authored
Merge branch 'master' into TheNormalnij/create_building_server
2 parents 326bfa5 + e9ec7f1 commit 1377cb9

File tree

364 files changed

+24291
-31710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

364 files changed

+24291
-31710
lines changed

Client/game_sa/CBuildingsPoolSA.cpp

+5-15
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,11 @@ void CBuildingsPoolSA::RemoveBuilding(CBuilding* pBuilding)
138138
--m_buildingPool.count;
139139
}
140140

141-
void CBuildingsPoolSA::RemoveAllBuildings()
141+
void CBuildingsPoolSA::RemoveAllWithBackup()
142142
{
143143
if (m_pOriginalBuildingsBackup)
144144
return;
145145

146-
pGame->GetCoverManager()->RemoveAllCovers();
147-
pGame->GetPlantManager()->RemoveAllPlants();
148-
149-
// Remove all shadows
150-
using CStencilShadowObjects_dtorAll = void* (*)();
151-
((CStencilShadowObjects_dtorAll)0x711390)();
152-
153146
m_pOriginalBuildingsBackup = std::make_unique<std::array<std::pair<bool, CBuildingSAInterface>, MAX_BUILDINGS>>();
154147

155148
auto pBuildsingsPool = (*m_ppBuildingPoolInterface);
@@ -176,7 +169,7 @@ void CBuildingsPoolSA::RemoveAllBuildings()
176169
}
177170
}
178171

179-
void CBuildingsPoolSA::RestoreAllBuildings()
172+
void CBuildingsPoolSA::RestoreBackup()
180173
{
181174
if (!m_pOriginalBuildingsBackup)
182175
return;
@@ -202,10 +195,7 @@ void CBuildingsPoolSA::RemoveBuildingFromWorld(CBuildingSAInterface* pBuilding)
202195
{
203196
// Remove building from world
204197
pGame->GetWorld()->Remove(pBuilding, CBuildingPool_Destructor);
205-
206-
pBuilding->DeleteRwObject();
207-
pBuilding->ResolveReferences();
208-
pBuilding->RemoveShadows();
198+
pBuilding->RemoveRWObjectWithReferencesCleanup();
209199
}
210200

211201
bool CBuildingsPoolSA::Resize(int size)
@@ -254,7 +244,7 @@ bool CBuildingsPoolSA::Resize(int size)
254244
newBytemap[i].bEmpty = true;
255245
}
256246

257-
const uint32_t offset = (uint32_t)newObjects - (uint32_t)oldPool;
247+
const std::uint32_t offset = (std::uint32_t)newObjects - (std::uint32_t)oldPool;
258248
if (oldPool != nullptr)
259249
{
260250
UpdateIplEntrysPointers(offset);
@@ -265,7 +255,7 @@ bool CBuildingsPoolSA::Resize(int size)
265255
UpdateBackupLodPointers(offset);
266256
}
267257

268-
pGame->GetPools()->GetDummyPool().UpdateBuildingLods(oldPool, newObjects);
258+
pGame->GetPools()->GetDummyPool().UpdateBuildingLods(offset);
269259

270260
RemoveVehicleDamageLinks();
271261
RemovePedsContactEnityLinks();

Client/game_sa/CBuildingsPoolSA.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class CBuildingsPoolSA : public CBuildingsPool
2626
void RemoveBuilding(CBuilding* pBuilding);
2727
bool HasFreeBuildingSlot();
2828

29-
void RemoveAllBuildings() override;
30-
void RestoreAllBuildings() override;
29+
void RemoveAllWithBackup() override;
30+
void RestoreBackup() override;
3131
bool Resize(int size) override;
3232
int GetSize() const override { return (*m_ppBuildingPoolInterface)->m_nSize; };
3333

@@ -40,8 +40,8 @@ class CBuildingsPoolSA : public CBuildingsPool
4040
void RemovePedsContactEnityLinks();
4141

4242
private:
43-
SVectorPoolData<CBuildingSA> m_buildingPool{MAX_BUILDINGS};
44-
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;
43+
SVectorPoolData<CBuildingSA> m_buildingPool{MAX_BUILDINGS};
44+
CPoolSAInterface<CBuildingSAInterface>** m_ppBuildingPoolInterface;
4545

4646
std::unique_ptr<std::array<std::pair<bool, CBuildingSAInterface>, MAX_BUILDINGS>> m_pOriginalBuildingsBackup;
4747
};

Client/game_sa/CDummyPoolSA.cpp

+63-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: game_sa/CDummyPoolSA.cpp
66
* PURPOSE: Dummy pool class
@@ -13,64 +13,96 @@
1313

1414
#include "StdInc.h"
1515
#include "CDummyPoolSA.h"
16+
#include "CGameSA.h"
17+
#include <game/CWorld.h>
18+
19+
extern CGameSA* pGame;
1620

1721
CDummyPoolSA::CDummyPoolSA()
1822
{
1923
m_ppDummyPoolInterface = (CPoolSAInterface<CEntitySAInterface>**)0xB744A0;
2024
}
2125

22-
void CDummyPoolSA::RemoveAllBuildingLods()
26+
void CDummyPoolSA::RemoveAllWithBackup()
2327
{
24-
if (m_pLodBackup)
28+
if (m_pOriginalElementsBackup)
2529
return;
2630

27-
m_pLodBackup = std::make_unique<std::array<CEntitySAInterface*, MAX_DUMMIES>>();
31+
m_pOriginalElementsBackup = std::make_unique<pool_backup_t>();
2832

29-
for (int i = 0; i < MAX_DUMMIES; i++)
33+
auto pDummyPool = (*m_ppDummyPoolInterface);
34+
for (auto i = 0; i < MAX_DUMMIES_DEFAULT; i++)
3035
{
31-
CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i);
32-
(*m_pLodBackup)[i] = object->m_pLod;
33-
object->m_pLod = nullptr;
36+
if (pDummyPool->IsContains(i))
37+
{
38+
CEntitySAInterface* building = pDummyPool->GetObject(i);
39+
40+
pGame->GetWorld()->Remove(building, CDummyPool_Destructor);
41+
building->RemoveRWObjectWithReferencesCleanup();
42+
43+
pDummyPool->Release(i);
44+
45+
(*m_pOriginalElementsBackup)[i].first = true;
46+
(*m_pOriginalElementsBackup)[i].second = *building;
47+
}
48+
else
49+
{
50+
(*m_pOriginalElementsBackup)[i].first = false;
51+
}
3452
}
3553
}
3654

37-
void CDummyPoolSA::RestoreAllBuildingsLods()
55+
void CDummyPoolSA::RestoreBackup()
3856
{
39-
if (!m_pLodBackup)
57+
if (!m_pOriginalElementsBackup)
4058
return;
4159

42-
for (int i = 0; i < MAX_DUMMIES; i++)
60+
auto& originalData = *m_pOriginalElementsBackup;
61+
auto pDummyPool = (*m_ppDummyPoolInterface);
62+
for (auto i = 0; i < MAX_DUMMIES_DEFAULT; i++)
4363
{
44-
CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i);
45-
object->m_pLod = (*m_pLodBackup)[i];
64+
if (originalData[i].first)
65+
{
66+
pDummyPool->AllocateAt(i);
67+
auto pDummy = pDummyPool->GetObject(i);
68+
*pDummy = originalData[i].second;
69+
70+
pGame->GetWorld()->Add(pDummy, CDummyPool_Constructor);
71+
}
4672
}
4773

48-
m_pLodBackup.release();
74+
m_pOriginalElementsBackup = nullptr;
4975
}
5076

51-
void CDummyPoolSA::UpdateBuildingLods(void* oldPool, void* newPool)
77+
void CDummyPoolSA::UpdateBuildingLods(const std::uint32_t offset)
5278
{
53-
const uint32_t offset = (uint32_t)newPool - (uint32_t)oldPool;
79+
if (m_pOriginalElementsBackup)
80+
UpdateBackupLodOffset(offset);
81+
else
82+
UpdateLodsOffestInPool(offset);
83+
}
5484

55-
if (m_pLodBackup)
85+
void CDummyPoolSA::UpdateBackupLodOffset(const std::uint32_t offset)
86+
{
87+
for (auto& it : *m_pOriginalElementsBackup)
5688
{
57-
for (int i = 0; i < MAX_DUMMIES; i++)
89+
if (it.first)
5890
{
59-
if ((*m_pLodBackup)[i] != nullptr)
60-
{
61-
(*m_pLodBackup)[i] = (CEntitySAInterface*)((uint32_t)(*m_pLodBackup)[i] + offset);
62-
}
91+
CEntitySAInterface* object = &it.second;
92+
CEntitySAInterface* lod = object->GetLod();
93+
if (lod)
94+
object->SetLod((CEntitySAInterface*)((std::uint32_t)lod + offset));
6395
}
6496
}
65-
else
97+
}
98+
99+
void CDummyPoolSA::UpdateLodsOffestInPool(const std::uint32_t offset)
100+
{
101+
for (auto i = 0; i < (*m_ppDummyPoolInterface)->Size(); i++)
66102
{
67-
for (int i = 0; i < MAX_DUMMIES; i++)
68-
{
69-
CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i);
70-
if (object->m_pLod)
71-
{
72-
object->m_pLod = (CEntitySAInterface*)((uint32_t)object->m_pLod + offset);
73-
}
74-
}
103+
CEntitySAInterface* object = (*m_ppDummyPoolInterface)->GetObject(i);
104+
CEntitySAInterface* lod = object->GetLod();
105+
if (lod)
106+
object->SetLod((CEntitySAInterface*)((std::uint32_t)lod + offset));
75107
}
76108
}

Client/game_sa/CDummyPoolSA.h

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
*
3-
* PROJECT: Multi Theft Auto v1.0
3+
* PROJECT: Multi Theft Auto
44
* LICENSE: See LICENSE in the top level directory
55
* FILE: game_sa/CDummyPoolSA.h
66
* PURPOSE: Dummy pool class
@@ -16,18 +16,25 @@
1616
#include "CPoolSAInterface.h"
1717
#include <memory>
1818

19-
class CDummyPoolSA : public CDummyPool
19+
constexpr std::size_t MAX_DUMMIES_DEFAULT = 2500;
20+
21+
class CDummyPoolSA final : public CDummyPool
2022
{
2123
public:
2224
CDummyPoolSA();
2325
~CDummyPoolSA() = default;
2426

25-
void RemoveAllBuildingLods();
26-
void RestoreAllBuildingsLods();
27-
void UpdateBuildingLods(void* oldPool, void* newPool);
27+
void RemoveAllWithBackup() override;
28+
void RestoreBackup() override;
29+
void UpdateBuildingLods(const std::uint32_t offset);
30+
31+
private:
32+
void UpdateBackupLodOffset(const std::uint32_t offest);
33+
void UpdateLodsOffestInPool(const std::uint32_t offset);
2834

2935
private:
3036
CPoolSAInterface<CEntitySAInterface>** m_ppDummyPoolInterface;
3137

32-
std::unique_ptr<std::array<CEntitySAInterface*, MAX_DUMMIES>> m_pLodBackup;
38+
using pool_backup_t = std::array<std::pair<bool, CEntitySAInterface>, MAX_DUMMIES_DEFAULT>;
39+
std::unique_ptr<pool_backup_t> m_pOriginalElementsBackup;
3340
};

Client/game_sa/CEntitySA.h

+10
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ class CEntitySAInterface
202202
// Functions to hide member variable misuse
203203
//
204204

205+
void SetLod(CEntitySAInterface* pLod) noexcept { m_pLod = pLod; };
206+
CEntitySAInterface* GetLod() const noexcept { return m_pLod; };
207+
205208
// Sets
206209
void SetIsLowLodEntity() { numLodChildrenRendered = 0x40; }
207210

@@ -243,9 +246,16 @@ class CEntitySAInterface
243246
((vtbl_DeleteRwObject)this->vtbl->DeleteRwObject)(this);
244247
};
245248

249+
void RemoveRWObjectWithReferencesCleanup() {
250+
DeleteRwObject();
251+
ResolveReferences();
252+
RemoveShadows();
253+
}
254+
246255
bool HasMatrix() const noexcept { return Placeable.matrix != nullptr; }
247256

248257
void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); }
258+
249259
};
250260
static_assert(sizeof(CEntitySAInterface) == 0x38, "Invalid size for CEntitySAInterface");
251261

Client/game_sa/CGameSA.cpp

+21-22
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ void CGameSA::Reset()
465465
CModelInfoSA::StaticResetTextureDictionaries();
466466

467467
// Restore default world state
468-
RestoreGameBuildings();
468+
RestoreGameWorld();
469469
}
470470
}
471471

@@ -1059,46 +1059,45 @@ void CGameSA::GetShaderReplacementStats(SShaderReplacementStats& outStats)
10591059
m_pRenderWare->GetShaderReplacementStats(outStats);
10601060
}
10611061

1062-
void CGameSA::RemoveAllBuildings()
1062+
void CGameSA::RemoveGameWorld()
10631063
{
10641064
m_pIplStore->SetDynamicIplStreamingEnabled(false);
10651065

1066-
m_Pools->GetDummyPool().RemoveAllBuildingLods();
1067-
m_Pools->GetBuildingsPool().RemoveAllBuildings();
1066+
m_pCoverManager->RemoveAllCovers();
1067+
m_pPlantManager->RemoveAllPlants();
10681068

1069-
auto pBuildingRemoval = static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval);
1070-
pBuildingRemoval->DropCaches();
1069+
// Remove all shadows in CStencilShadowObjects::dtorAll
1070+
((void* (*)())0x711390)();
10711071

1072-
m_isBuildingsRemoved = true;
1072+
m_Pools->GetDummyPool().RemoveAllWithBackup();
1073+
m_Pools->GetBuildingsPool().RemoveAllWithBackup();
1074+
1075+
static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval)->DropCaches();
1076+
1077+
m_isGameWorldRemoved = true;
10731078
}
10741079

1075-
void CGameSA::RestoreGameBuildings()
1080+
void CGameSA::RestoreGameWorld()
10761081
{
1077-
m_Pools->GetBuildingsPool().RestoreAllBuildings();
1078-
m_Pools->GetDummyPool().RestoreAllBuildingsLods();
1082+
m_Pools->GetBuildingsPool().RestoreBackup();
1083+
m_Pools->GetDummyPool().RestoreBackup();
10791084

10801085
m_pIplStore->SetDynamicIplStreamingEnabled(true, [](CIplSAInterface* ipl) { return memcmp("barriers", ipl->name, 8) != 0; });
1081-
m_isBuildingsRemoved = false;
1086+
m_isGameWorldRemoved = false;
10821087
}
10831088

10841089
bool CGameSA::SetBuildingPoolSize(size_t size)
10851090
{
1086-
const bool shouldRemoveBuilding = !m_isBuildingsRemoved;
1087-
if (shouldRemoveBuilding)
1088-
{
1089-
RemoveAllBuildings();
1090-
}
1091+
const bool shouldRemoveWorld = !m_isGameWorldRemoved;
1092+
if (shouldRemoveWorld)
1093+
RemoveGameWorld();
10911094
else
1092-
{
10931095
static_cast<CBuildingRemovalSA*>(m_pBuildingRemoval)->DropCaches();
1094-
}
10951096

10961097
bool status = m_Pools->GetBuildingsPool().Resize(size);
10971098

1098-
if (shouldRemoveBuilding)
1099-
{
1100-
RestoreGameBuildings();
1101-
}
1099+
if (shouldRemoveWorld)
1100+
RestoreGameWorld();
11021101

11031102
return status;
11041103
}

Client/game_sa/CGameSA.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ class CGameSA : public CGame
310310
PostWeaponFireHandler* m_pPostWeaponFireHandler;
311311
TaskSimpleBeHitHandler* m_pTaskSimpleBeHitHandler;
312312

313-
void RemoveAllBuildings();
314-
void RestoreGameBuildings();
313+
void RemoveGameWorld();
314+
void RestoreGameWorld();
315315

316316
bool SetBuildingPoolSize(size_t size);
317317

@@ -381,7 +381,7 @@ class CGameSA : public CGame
381381
bool m_isBurnFlippedCarsEnabled{true};
382382
bool m_isFireballDestructEnabled{true};
383383
bool m_isRoadSignsTextEnabled{true};
384-
bool m_isBuildingsRemoved{false};
384+
bool m_isGameWorldRemoved{false};
385385
bool m_isExtendedWaterCannonsEnabled{false};
386386
bool m_isIgnoreFireStateEnabled{false};
387387

Client/game_sa/CPoolSAInterface.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ class CPoolSAInterface
114114

115115
void Delete(uint index) { Release(index); }
116116

117-
bool IsEmpty(std::int32_t objectIndex) { return m_byteMap[objectIndex].bEmpty; }
118-
bool IsContains(uint index)
117+
std::int32_t Size() const noexcept { return m_nSize; };
118+
bool IsEmpty(std::int32_t objectIndex) const { return m_byteMap[objectIndex].bEmpty; }
119+
bool IsContains(uint index) const
119120
{
120121
if (m_nSize <= index)
121122
return false;

Client/game_sa/CPoolsSA.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define INVALID_POOL_ARRAY_ID 0xFFFFFFFF
2323

2424
class CClientEntity;
25+
class CClientVehicle;
26+
class CClientObject;
2527

2628
class CPoolsSA : public CPools
2729
{

0 commit comments

Comments
 (0)