Skip to content

Commit 5f21c32

Browse files
authored
Fix #3760 isPlayerCrosshairVisible returns true at the start of aiming (#3762)
1 parent 550a152 commit 5f21c32

File tree

12 files changed

+87
-39
lines changed

12 files changed

+87
-39
lines changed

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: 1 addition & 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

Client/game_sa/CHudSA.cpp

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "CHudSA.h"
1414
#include "CGameSA.h"
1515
#include "CCameraSA.h"
16+
#include "CPlayerInfoSA.h"
17+
#include "TaskAttackSA.h"
1618

1719
extern CGameSA* pGame;
1820

@@ -178,35 +180,51 @@ void CHudSA::ResetComponentAdjustment()
178180

179181
bool CHudSA::IsCrosshairVisible()
180182
{
181-
if (!IsComponentVisible(HUD_CROSSHAIR))
182-
return false;
183+
bool specialAiming = false;
184+
bool simpleAiming = false;
183185

186+
// Get camera view mode
184187
CCamera* camera = pGame->GetCamera();
185188
eCamMode cameraViewMode = static_cast<eCamMode>(camera->GetCam(camera->GetActiveCam())->GetMode());
186189

187-
switch (cameraViewMode)
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)
188215
{
189-
case MODE_SNIPER_RUNABOUT:
190-
case MODE_ROCKETLAUNCHER_RUNABOUT:
191-
case MODE_ROCKETLAUNCHER_RUNABOUT_HS:
192-
case MODE_M16_1STPERSON_RUNABOUT:
193-
case MODE_1STPERSON_RUNABOUT:
194-
case MODE_AIMWEAPON:
195-
case MODE_AIMWEAPON_ATTACHED:
196-
case MODE_AIMWEAPON_FROMCAR:
197-
case MODE_M16_1STPERSON:
198-
case MODE_HELICANNON_1STPERSON:
199-
case MODE_SNIPER:
200-
case MODE_ROCKETLAUNCHER:
201-
case MODE_ROCKETLAUNCHER_HS:
202-
case MODE_AIMING:
203-
case MODE_CAMERA:
204-
return true;
205-
default:
206-
break;
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+
}
207225
}
208226

209227
// Check CTheScripts::bDrawCrossHair
210228
std::uint8_t crossHairType = *reinterpret_cast<std::uint8_t*>(VAR_CTheScripts_bDrawCrossHair);
211-
return crossHairType > 0;
229+
return specialAiming || simpleAiming || crossHairType > 0;
212230
}

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: 11 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,8 @@ 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;
262268
BYTE bFightingStyle; // 1837
263269
BYTE bFightingStyleExtra;
264270
BYTE bPad7[1];
@@ -408,5 +414,8 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
408414
std::unique_ptr<CPedIK> GetPedIK() { return std::make_unique<CPedIKSA>(GetPedIKInterface()); }
409415
static void StaticSetHooks();
410416

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

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

Client/sdk/game/CCamera.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,6 @@ class CCamera
146146

147147
virtual void ShakeCamera(float radius, float x, float y, float z) noexcept = 0;
148148
virtual void ResetShakeCamera() noexcept = 0;
149+
150+
virtual std::uint8_t GetTransitionState() = 0;
149151
};

Client/sdk/game/CPed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,8 @@ class CPed : public virtual CPhysical
285285
virtual void* GetPedNodeInterface(std::int32_t nodeId) = 0;
286286
virtual std::unique_ptr<CPedIK> GetPedIK() = 0;
287287

288+
virtual CEntitySAInterface* GetTargetedObject() = 0;
289+
virtual ePedState GetPedState() = 0;
290+
288291
virtual void GetAttachedSatchels(std::vector<SSatchelsData> &satchelsList) const = 0;
289292
};

Client/sdk/game/CPedIntelligence.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
class CPed;
1515
class CTaskSAInterface;
1616
class CTaskManager;
17+
class CTaskSimpleUseGun;
1718

1819
class CPedIntelligence
1920
{
2021
public:
2122
virtual CTaskManager* GetTaskManager() = 0;
2223
virtual bool TestForStealthKill(CPed* pPed, bool bUnk) = 0;
2324
virtual CTaskSAInterface* SetTaskDuckSecondary(unsigned short nLengthOfDuck) = 0;
25+
virtual CTaskSimpleUseGun* GetTaskUseGun() = 0;
2426
};

Client/sdk/game/TaskAttack.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class CTaskSimpleUseGun : public virtual CTaskSimple
4444
virtual bool ControlGun(CPed* pPed, CEntity* pTargetEntity, char nCommand) = 0;
4545
virtual bool ControlGunMove(CVector2D* pMoveVec) = 0;
4646
virtual void Reset(CPed* pPed, CEntity* pTargetEntity, CVector vecTarget, char nCommand, short nBurstLength = 1) = 0;
47+
48+
virtual bool GetSkipAim() = 0;
4749
};
4850

4951
class CTaskSimpleFight : public virtual CTaskSimple

0 commit comments

Comments
 (0)