Skip to content

Commit 6b17138

Browse files
authored
Merge branch 'master' into 230924_Add_C++20_Deathmatch
2 parents 7a6e88f + 73a09d6 commit 6b17138

File tree

24 files changed

+172
-61
lines changed

24 files changed

+172
-61
lines changed

Client/game_sa/CBuildingsPoolSA.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ void CBuildingsPoolSA::RemoveAllBuildings()
151151

152152
RemoveBuildingFromWorld(building);
153153

154+
if (building->HasMatrix())
155+
building->RemoveMatrix();
156+
154157
pBuildsingsPool->Release(i);
155158

156159
(*m_pOriginalBuildingsBackup)[i].first = true;

Client/game_sa/CCameraSA.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,8 @@ void CCameraSA::ResetShakeCamera() noexcept
458458
{
459459
GetInterface()->m_fCamShakeForce = 0.0f;
460460
}
461+
462+
std::uint8_t CCameraSA::GetTransitionState()
463+
{
464+
return GetInterface()->m_uiTransitionState;
465+
}

Client/game_sa/CCameraSA.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class CCameraSAInterface
8282
public:
8383
// CPlaceable
8484
CPlaceableSAInterface Placeable;
85+
std::uint8_t specialPadding[4]; // Temporary padding due to incorrect CPlaceableSAInterface class
8586
// End CPlaceable
8687

8788
// move these out the class, have decided to set up a mirrored enumerated type thingy at the top
@@ -131,16 +132,6 @@ class CCameraSAInterface
131132
bool m_bCooperativeCamMode;
132133
bool m_bAllowShootingWith2PlayersInCar;
133134
bool m_bDisableFirstPersonInCar;
134-
static bool m_bUseMouse3rdPerson;
135-
#ifndef FINALBUILD
136-
bool bStaticFrustum;
137-
#endif
138-
139-
// for debug keyboard stuff
140-
#ifndef MASTER
141-
unsigned char display_kbd_debug;
142-
float kbd_fov_value;
143-
#endif // MASTER
144135

145136
// The following fields allow the level designers to specify the camera for 2 player games.
146137
short m_ModeForTwoPlayersSeparateCars;
@@ -430,4 +421,6 @@ class CCameraSA : public CCamera
430421

431422
void ShakeCamera(float radius, float x, float y, float z) noexcept override;
432423
void ResetShakeCamera() noexcept override;
424+
425+
std::uint8_t GetTransitionState();
433426
};

Client/game_sa/CEntitySA.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class CPlaceableSAInterface // 20 bytes
123123
class CEntitySAInterface
124124
{
125125
public:
126-
CEntitySAInterfaceVTBL* vtbl; // the virtual table
126+
CEntitySAInterfaceVTBL* vtbl; // the virtual table it should be in the CPlaceableSAInterface
127127

128128
CPlaceableSAInterface Placeable; // 4
129129

@@ -242,6 +242,10 @@ class CEntitySAInterface
242242
using vtbl_DeleteRwObject = void(__thiscall*)(CEntitySAInterface * pEntity);
243243
((vtbl_DeleteRwObject)this->vtbl->DeleteRwObject)(this);
244244
};
245+
246+
bool HasMatrix() const noexcept { return Placeable.matrix != nullptr; }
247+
248+
void RemoveMatrix() { ((void(__thiscall*)(void*))0x54F3B0)(this); }
245249
};
246250
static_assert(sizeof(CEntitySAInterface) == 0x38, "Invalid size for CEntitySAInterface");
247251

Client/game_sa/CHudSA.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
#include "StdInc.h"
1313
#include "CHudSA.h"
14+
#include "CGameSA.h"
15+
#include "CCameraSA.h"
16+
#include "CPlayerInfoSA.h"
17+
#include "TaskAttackSA.h"
18+
19+
extern CGameSA* pGame;
1420

1521
char szVehicleName[50] = {'\0'};
1622
char szZoneName[50] = {'\0'};
@@ -171,3 +177,54 @@ void CHudSA::ResetComponentAdjustment()
171177
MemPut<float>(m_pfCameraCrosshairScale, 192.0f);
172178
m_fSniperCrosshairScale = 210.0f;
173179
}
180+
181+
bool CHudSA::IsCrosshairVisible()
182+
{
183+
bool specialAiming = false;
184+
bool simpleAiming = false;
185+
186+
// Get camera view mode
187+
CCamera* camera = pGame->GetCamera();
188+
eCamMode cameraViewMode = static_cast<eCamMode>(camera->GetCam(camera->GetActiveCam())->GetMode());
189+
190+
// Get player
191+
CPed* playerPed = pGame->GetPedContext();
192+
CWeapon* weapon = nullptr;
193+
eWeaponType weaponType;
194+
195+
// Get player current weapon
196+
if (playerPed)
197+
{
198+
weapon = playerPed->GetWeapon(playerPed->GetCurrentWeaponSlot());
199+
if (weapon)
200+
weaponType = weapon->GetType();
201+
}
202+
203+
// Special aiming
204+
if (cameraViewMode == MODE_SNIPER || cameraViewMode == MODE_1STPERSON || cameraViewMode == MODE_ROCKETLAUNCHER || cameraViewMode == MODE_ROCKETLAUNCHER_HS || cameraViewMode == MODE_M16_1STPERSON || cameraViewMode == MODE_HELICANNON_1STPERSON || cameraViewMode == MODE_CAMERA)
205+
{
206+
if (weapon && cameraViewMode != MODE_1STPERSON && pGame->GetWeaponInfo(weaponType, WEAPONSKILL_STD)->GetFireType() != FIRETYPE_MELEE)
207+
specialAiming = true;
208+
}
209+
210+
// Simple aiming
211+
if (cameraViewMode == MODE_M16_1STPERSON_RUNABOUT || cameraViewMode == MODE_ROCKETLAUNCHER_RUNABOUT || cameraViewMode == MODE_ROCKETLAUNCHER_RUNABOUT_HS || cameraViewMode == MODE_SNIPER_RUNABOUT)
212+
simpleAiming = true;
213+
214+
if ((playerPed && weapon) && !playerPed->GetTargetedObject() && playerPed->GetPedInterface()->pPlayerData->m_bFreeAiming)
215+
{
216+
CTaskSimpleUseGun* taskUseGun = playerPed->GetPedIntelligence()->GetTaskUseGun();
217+
if ((!taskUseGun || !taskUseGun->GetSkipAim()) && (cameraViewMode == MODE_AIMWEAPON || cameraViewMode == MODE_AIMWEAPON_FROMCAR || cameraViewMode == MODE_AIMWEAPON_ATTACHED))
218+
{
219+
if (playerPed->GetPedState() != PED_ENTER_CAR && playerPed->GetPedState() != PED_CARJACK)
220+
{
221+
if ((weaponType >= WEAPONTYPE_PISTOL && weaponType <= WEAPONTYPE_M4) || weaponType == WEAPONTYPE_TEC9 || weaponType == WEAPONTYPE_COUNTRYRIFLE || weaponType == WEAPONTYPE_MINIGUN || weaponType == WEAPONTYPE_FLAMETHROWER)
222+
simpleAiming = cameraViewMode != MODE_AIMWEAPON || camera->GetTransitionState() == 0;
223+
}
224+
}
225+
}
226+
227+
// Check CTheScripts::bDrawCrossHair
228+
std::uint8_t crossHairType = *reinterpret_cast<std::uint8_t*>(VAR_CTheScripts_bDrawCrossHair);
229+
return specialAiming || simpleAiming || crossHairType > 0;
230+
}

Client/game_sa/CHudSA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#define CODE_ShowMoney 0x58F47D
4040

41+
#define VAR_CTheScripts_bDrawCrossHair 0xA44490
42+
4143
struct SHudComponent
4244
{
4345
bool bIsPartOfAll;
@@ -59,6 +61,7 @@ class CHudSA : public CHud
5961
bool IsComponentVisible(eHudComponent component);
6062
void AdjustComponents(float fAspectRatio);
6163
void ResetComponentAdjustment();
64+
bool IsCrosshairVisible();
6265

6366
protected:
6467
void InitComponentList();

Client/game_sa/CPedIntelligenceSA.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CPedSA.h"
1515
#include "CTaskManagementSystemSA.h"
1616
#include "CTaskManagerSA.h"
17+
#include "TaskAttackSA.h"
1718

1819
CPedIntelligenceSA::CPedIntelligenceSA(CPedIntelligenceSAInterface* pedIntelligenceSAInterface, CPed* ped)
1920
{
@@ -55,3 +56,16 @@ CTaskSAInterface* CPedIntelligenceSA::SetTaskDuckSecondary(unsigned short nLengt
5556
auto SetTaskDuckSecondary = (CTaskSAInterface * (__thiscall*)(CPedIntelligenceSAInterface*, unsigned short))0x601230;
5657
return SetTaskDuckSecondary(internalInterface, nLengthOfDuck);
5758
}
59+
60+
CTaskSimpleUseGun* CPedIntelligenceSA::GetTaskUseGun()
61+
{
62+
CTaskManager* taskMgr = GetTaskManager();
63+
if (!taskMgr)
64+
return nullptr;
65+
66+
CTask* secondaryTask = taskMgr->GetTaskSecondary(TASK_SECONDARY_ATTACK);
67+
if (secondaryTask && secondaryTask->GetTaskType() == TASK_SIMPLE_USE_GUN)
68+
return dynamic_cast<CTaskSimpleUseGun*>(secondaryTask);
69+
70+
return nullptr;
71+
}

Client/game_sa/CPedIntelligenceSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ class CPedIntelligenceSA : public CPedIntelligence
5454
CTaskManager* GetTaskManager();
5555
bool TestForStealthKill(CPed* pPed, bool bUnk);
5656
CTaskSAInterface* SetTaskDuckSecondary(unsigned short nLengthOfDuck);
57+
CTaskSimpleUseGun* GetTaskUseGun();
5758
};

Client/game_sa/CPedSA.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,12 @@ class CPedSAInterface : public CPhysicalSAInterface // +1420 = curre
230230
int iMoveAnimGroup; // 1236
231231
BYTE bPad4b[52];
232232
CPedIKSAInterface pedIK; // 1292 (length 32 bytes)
233-
int bPad5[5];
233+
234+
std::uint32_t field_52C;
235+
ePedState pedState;
236+
eMoveState moveState;
237+
eMoveState swimmingMoveState;
238+
std::uint32_t field_53C;
234239

235240
float fHealth;
236241
int iUnknown121;
@@ -258,7 +263,9 @@ class CPedSAInterface : public CPhysicalSAInterface // +1420 = curre
258263
// weapons at +1440 ends at +1804
259264
BYTE bPad4[12];
260265
BYTE bCurrentWeaponSlot; // is actually here
261-
BYTE bPad6[20];
266+
BYTE bPad6[3];
267+
CEntitySAInterface* pTargetedObject;
268+
BYTE tempPad[13];
262269
BYTE bFightingStyle; // 1837
263270
BYTE bFightingStyleExtra;
264271
BYTE bPad7[1];
@@ -408,5 +415,8 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
408415
std::unique_ptr<CPedIK> GetPedIK() { return std::make_unique<CPedIKSA>(GetPedIKInterface()); }
409416
static void StaticSetHooks();
410417

418+
CEntitySAInterface* GetTargetedObject() { return GetPedInterface()->pTargetedObject; }
419+
ePedState GetPedState() { return GetPedInterface()->pedState; }
420+
411421
void GetAttachedSatchels(std::vector<SSatchelsData> &satchelsList) const override;
412422
};

Client/game_sa/CPlayerInfoSA.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class CPlayerPedDataSAInterface
4141

4242
CVector2D m_vecFightMovement; // 12
4343
float m_moveBlendRatio; // 20
44-
float m_fSprintEnergy; // 24
45-
// FLOAT m_fSprintControlCounter; // Removed arbitatrily to aligned next byte, should be here really
44+
float m_fTimeCanRun;
45+
float m_fSprintEnergy;
46+
4647
BYTE m_nChosenWeapon; // 28
4748
BYTE m_nCarDangerCounter; // 29
4849
BYTE m_pad0; // 30
@@ -68,8 +69,6 @@ class CPlayerPedDataSAInterface
6869
DWORD m_bInVehicleDontAllowWeaponChange : 1; // stop weapon change once driveby weapon has been given
6970
DWORD m_bRenderWeapon : 1; // set to false during cutscenes so that knuckledusters are not rendered
7071

71-
DWORD m_pad2; // 56
72-
7372
long m_PlayerGroup; // 60
7473

7574
DWORD m_AdrenalineEndTime; // 64

0 commit comments

Comments
 (0)