Skip to content

Commit 0936201

Browse files
authored
Merge branch 'master' into attach
2 parents cfdede2 + e09b85f commit 0936201

File tree

77 files changed

+2846
-2321
lines changed

Some content is hidden

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

77 files changed

+2846
-2321
lines changed

Client/core/CVersionUpdater.Util.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
class CVersionUpdater;
1313

1414
// Update master info
15-
#define UPDATER_MASTER_URL1 "http://updatesa.mtasa.com/sa/master/?v=%VERSION%&id=%ID%"
16-
#define UPDATER_MASTER_URL2 "http://updatesa.multitheftauto.com/sa/master/?v=%VERSION%&id=%ID%"
15+
#define UPDATER_MASTER_URL1 "https://updatesa.mtasa.com/sa/master/?v=%VERSION%&id=%ID%"
16+
#define UPDATER_MASTER_URL2 "https://updatesa.multitheftauto.com/sa/master/?v=%VERSION%&id=%ID%"
1717

1818
/*
1919

Client/game_sa/CAnimManagerSA.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,10 @@ static const char* const kGateWayAnimationName = "run_wuzi";
3232

3333
CAnimManagerSA::CAnimManagerSA()
3434
{
35-
MemSetFast(m_pAnimAssocGroups, 0, sizeof(m_pAnimAssocGroups));
36-
MemSetFast(m_pAnimBlocks, 0, sizeof(m_pAnimBlocks));
3735
}
3836

3937
CAnimManagerSA::~CAnimManagerSA()
4038
{
41-
for (unsigned int i = 0; i < MAX_ANIM_GROUPS; i++)
42-
if (m_pAnimAssocGroups[i])
43-
delete m_pAnimAssocGroups[i];
44-
for (unsigned int i = 0; i < MAX_ANIM_BLOCKS; i++)
45-
if (m_pAnimBlocks[i])
46-
delete m_pAnimBlocks[i];
4739
}
4840

4941
void CAnimManagerSA::Initialize()

Client/game_sa/CAnimManagerSA.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,4 @@ class CAnimManagerSA : public CAnimManager
165165

166166
bool IsValidGroup(std::uint32_t uiAnimGroup) const;
167167
bool IsValidAnim(std::uint32_t uiAnimGroup, std::uint32_t uiAnimID) const;
168-
private:
169-
CAnimBlendAssocGroup* m_pAnimAssocGroups[MAX_ANIM_GROUPS];
170-
CAnimBlock* m_pAnimBlocks[MAX_ANIM_BLOCKS];
171168
};

Client/game_sa/CBuildingsPoolSA.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "CPtrNodeSingleListSA.h"
1919
#include "MemSA.h"
2020
#include "CVehicleSA.h"
21+
#include "CBuildingRemovalSA.h"
2122

2223
extern CGameSA* pGame;
2324

@@ -48,6 +49,16 @@ inline bool CBuildingsPoolSA::AddBuildingToPool(CClientBuilding* pClientBuilding
4849
return true;
4950
}
5051

52+
CClientEntity* CBuildingsPoolSA::GetClientBuilding(CBuildingSAInterface* pGameInterface) const noexcept
53+
{
54+
std::uint32_t poolIndex = (*m_ppBuildingPoolInterface)->GetObjectIndexSafe(pGameInterface);
55+
56+
if (poolIndex == static_cast<std::uint32_t>(-1))
57+
return nullptr;
58+
59+
return m_buildingPool.entities[poolIndex].pClientEntity;
60+
}
61+
5162
CBuilding* CBuildingsPoolSA::AddBuilding(CClientBuilding* pClientBuilding, uint16_t modelId, CVector* vPos, CVector4D* vRot, uint8_t interior)
5263
{
5364
if (!HasFreeBuildingSlot())
@@ -174,6 +185,9 @@ void CBuildingsPoolSA::RestoreBackup()
174185
if (!m_pOriginalBuildingsBackup)
175186
return;
176187

188+
auto* worldSA = pGame->GetWorld();
189+
auto* buildingRemovealSA = static_cast<CBuildingRemovalSA*>(pGame->GetBuildingRemoval());
190+
177191
auto& originalData = *m_pOriginalBuildingsBackup;
178192
auto pBuildsingsPool = (*m_ppBuildingPoolInterface);
179193
for (size_t i = 0; i < MAX_BUILDINGS; i++)
@@ -184,7 +198,8 @@ void CBuildingsPoolSA::RestoreBackup()
184198
auto pBuilding = pBuildsingsPool->GetObject(i);
185199
*pBuilding = originalData[i].second;
186200

187-
pGame->GetWorld()->Add(pBuilding, CBuildingPool_Constructor);
201+
worldSA->Add(pBuilding, CBuildingPool_Constructor);
202+
buildingRemovealSA->AddDataBuilding(pBuilding);
188203
}
189204
}
190205

Client/game_sa/CBuildingsPoolSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class CBuildingsPoolSA : public CBuildingsPool
3030
void RestoreBackup() override;
3131
bool Resize(int size) override;
3232
int GetSize() const override { return (*m_ppBuildingPoolInterface)->m_nSize; };
33+
CClientEntity* GetClientBuilding(CBuildingSAInterface* pGameInterface) const noexcept;
3334

3435
private:
3536
void RemoveBuildingFromWorld(CBuildingSAInterface* pBuilding);

Client/game_sa/CDynamicPool.h

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CDynamicPool.h
6+
* PURPOSE: Custom implementation for SA pools
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
14+
#include <vector>
15+
#include <array>
16+
#include <memory>
17+
18+
template <typename PoolObjT>
19+
class CDynamicPoolPart
20+
{
21+
public:
22+
explicit CDynamicPoolPart(std::size_t size) : m_size{size}
23+
{
24+
m_items = std::make_unique<PoolObjT[]>(size);
25+
m_unusedIndices.reserve(size);
26+
for (std::size_t i = 0; i < size; i++)
27+
m_unusedIndices.push_back(i);
28+
}
29+
30+
PoolObjT* AllocateItem()
31+
{
32+
std::size_t index = m_unusedIndices.back();
33+
m_unusedIndices.pop_back();
34+
return &m_items[index];
35+
}
36+
37+
void RemoveItem(PoolObjT* item)
38+
{
39+
auto pos = item - m_items.get();
40+
m_unusedIndices.push_back(pos);
41+
}
42+
43+
bool OwnsItem(PoolObjT* item) const noexcept { return item >= m_items.get() && item < m_items.get() + m_size; }
44+
bool HasFreeSize() const noexcept { return m_unusedIndices.size() != 0; }
45+
std::size_t GetCapacity() const noexcept { return m_size; }
46+
std::size_t GetUsedSize() const noexcept { return m_size - m_unusedIndices.size(); }
47+
48+
private:
49+
std::unique_ptr<PoolObjT[]> m_items;
50+
std::vector<std::size_t> m_unusedIndices;
51+
const std::size_t m_size;
52+
};
53+
54+
template <std::size_t InitialSize, std::size_t AddSize>
55+
struct PoolGrowAddStrategy
56+
{
57+
static constexpr std::size_t GetInitialSize() { return InitialSize; }
58+
static constexpr std::size_t GetNextSize(std::size_t index) { return AddSize; }
59+
};
60+
61+
template <typename PoolObjT, typename GrowStrategy>
62+
class CDynamicPool
63+
{
64+
public:
65+
CDynamicPool()
66+
{
67+
constexpr size_t initialSize = GrowStrategy::GetInitialSize();
68+
m_poolParts.emplace_back(initialSize);
69+
}
70+
71+
PoolObjT* AllocateItem()
72+
{
73+
for (auto& pool : m_poolParts)
74+
{
75+
if (pool.HasFreeSize())
76+
return pool.AllocateItem();
77+
}
78+
79+
try
80+
{
81+
return AllocateNewPart().AllocateItem();
82+
}
83+
catch (const std::bad_alloc&)
84+
{
85+
assert(false && "Could not allocate a memory for CDynamicPoolPart");
86+
}
87+
}
88+
89+
void RemoveItem(PoolObjT* item)
90+
{
91+
for (auto& pool : m_poolParts)
92+
{
93+
if (pool.OwnsItem(item))
94+
{
95+
pool.RemoveItem(item);
96+
return;
97+
}
98+
}
99+
100+
assert(false && "Invalid item for CDynamicPool::RemoveItem");
101+
}
102+
103+
std::size_t GetCapacity() const noexcept
104+
{
105+
std::size_t size = 0;
106+
for (auto& pool : m_poolParts)
107+
size += pool.GetCapacity();
108+
109+
return size;
110+
}
111+
112+
std::size_t GetUsedSize() const noexcept
113+
{
114+
std::size_t size = 0;
115+
for (auto& pool : m_poolParts)
116+
size += pool.GetUsedSize();
117+
118+
return size;
119+
}
120+
121+
bool SetCapacity(std::size_t newSize) {
122+
if (newSize == 0)
123+
return false;
124+
125+
std::size_t currentSize = GetCapacity();
126+
127+
if (currentSize == newSize)
128+
return false;
129+
else if (currentSize < newSize)
130+
{
131+
// Grow
132+
while (currentSize < newSize)
133+
{
134+
try
135+
{
136+
auto& nextPart = AllocateNewPart();
137+
currentSize += nextPart.GetCapacity();
138+
}
139+
catch (const std::bad_alloc&)
140+
{
141+
return false;
142+
}
143+
}
144+
}
145+
else
146+
{
147+
// Shrink
148+
while (true)
149+
{
150+
auto& part = m_poolParts.back();
151+
if (part.GetUsedSize() != 0)
152+
return false;
153+
154+
currentSize -= part.GetCapacity();
155+
if (currentSize < newSize)
156+
return false;
157+
158+
m_poolParts.pop_back();
159+
160+
if (currentSize == newSize)
161+
return true;
162+
}
163+
}
164+
165+
return true;
166+
}
167+
168+
private:
169+
CDynamicPoolPart<PoolObjT>& AllocateNewPart()
170+
{
171+
const std::size_t nextSize = GrowStrategy::GetNextSize(m_poolParts.size());
172+
m_poolParts.emplace_back(nextSize);
173+
return m_poolParts.back();
174+
}
175+
176+
private:
177+
std::list<CDynamicPoolPart<PoolObjT>> m_poolParts;
178+
};

Client/game_sa/CFireSA.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "CFireSA.h"
1515
#include "CGameSA.h"
1616
#include "CPoolsSA.h"
17+
#include <game/CTaskManager.h>
18+
#include <game/TaskTypes.h>
1719

1820
extern CGameSA* pGame;
1921

@@ -209,3 +211,49 @@ void CFireSA::SetNumGenerationsAllowed(char generations)
209211
{
210212
internalInterface->nNumGenerationsAllowed = generations;
211213
}
214+
215+
////////////////////////////////////////////////////////////////////////
216+
// CFire::Extinguish
217+
//
218+
// Fix GH #3249 (PLAYER_ON_FIRE task is not aborted after the fire is extinguished)
219+
////////////////////////////////////////////////////////////////////////
220+
static void AbortFireTask(CEntitySAInterface* entityOnFire, DWORD returnAddress)
221+
{
222+
// We can't and shouldn't remove the task if we're in CTaskSimplePlayerOnFire::ProcessPed. Otherwise we will crash.
223+
if (returnAddress == 0x633783)
224+
return;
225+
226+
auto ped = pGame->GetPools()->GetPed(reinterpret_cast<DWORD*>(entityOnFire));
227+
if (!ped || !ped->pEntity)
228+
return;
229+
230+
CTaskManager* taskManager = ped->pEntity->GetPedIntelligence()->GetTaskManager();
231+
if (!taskManager)
232+
return;
233+
234+
taskManager->RemoveTaskSecondary(TASK_SECONDARY_PARTIAL_ANIM, TASK_SIMPLE_PLAYER_ON_FIRE);
235+
}
236+
237+
#define HOOKPOS_CFire_Extinguish 0x539429
238+
#define HOOKSIZE_CFire_Extinguish 6
239+
static constexpr std::uintptr_t CONTINUE_CFire_Extinguish = 0x53942F;
240+
static void _declspec(naked) HOOK_CFire_Extinguish()
241+
{
242+
_asm
243+
{
244+
mov [eax+730h], edi
245+
mov ebx, [esp+8]
246+
247+
push ebx
248+
push eax
249+
call AbortFireTask
250+
add esp, 8
251+
252+
jmp CONTINUE_CFire_Extinguish
253+
}
254+
}
255+
256+
void CFireSA::StaticSetHooks()
257+
{
258+
EZHookInstall(CFire_Extinguish);
259+
}

Client/game_sa/CFireSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ class CFireSA : public CFire
6464
void SetStrength(float fStrength);
6565
void SetNumGenerationsAllowed(char generations);
6666
CFireSAInterface* GetInterface() { return internalInterface; }
67+
68+
static void StaticSetHooks();
6769
};

Client/game_sa/CGameSA.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "CIplStoreSA.h"
6060
#include "CBuildingRemovalSA.h"
6161
#include "CCheckpointSA.h"
62+
#include "CPtrNodeSingleLinkPoolSA.h"
6263

6364
extern CGameSA* pGame;
6465

@@ -245,6 +246,8 @@ CGameSA::CGameSA()
245246
CVehicleSA::StaticSetHooks();
246247
CCheckpointSA::StaticSetHooks();
247248
CHudSA::StaticSetHooks();
249+
CFireSA::StaticSetHooks();
250+
CPtrNodeSingleLinkPoolSA::StaticSetHooks();
248251
}
249252
catch (const std::bad_alloc& e)
250253
{

Client/game_sa/CHudSA.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ void __fastcall CHudSA::RenderWeaponIcon_Sprite(void* sprite, void*, CRect* rect
837837
color->a = properties.fillColorSecondary.a;
838838

839839
// Call CSprite2d::Draw
840-
((void(__thiscall*)(void*, CRect*, RwColor*))FUNC_CSprie2d_Draw)(sprite, rect, color);
840+
((void(__thiscall*)(void*, CRect*, RwColor*))FUNC_CSprite2d_Draw)(sprite, rect, color);
841841
}
842842

843843
void CHudSA::RenderWeaponIcon_XLU(CVector pos, CVector2D halfSize, std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint16_t intensity, float rhw, std::uint8_t a, std::uint8_t uDir, std::uint8_t vDir)

0 commit comments

Comments
 (0)