Skip to content

Commit 7399bf6

Browse files
author
saml1er
authored
Merge pull request #1442 from Zangomangu/driveby-pitch-fix
Fix #1440 Driveby aiming is inverted in some cases
2 parents c99423b + 525c920 commit 7399bf6

File tree

16 files changed

+82
-35
lines changed

16 files changed

+82
-35
lines changed

Client/game_sa/CPedSA.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,18 @@ int CPedSA::GetCustomMoveAnim()
10271027
return m_iCustomMoveAnim;
10281028
}
10291029

1030+
bool CPedSA::IsDoingGangDriveby()
1031+
{
1032+
auto pTaskManager = m_pPedIntelligence->GetTaskManager();
1033+
CTask* pTask = pTaskManager->GetTask(TASK_PRIORITY_PRIMARY);
1034+
if (pTask && pTask->GetTaskType() == TASK_SIMPLE_GANG_DRIVEBY)
1035+
{
1036+
return true;
1037+
}
1038+
1039+
return false;
1040+
}
1041+
10301042
/*
10311043
bool CPedSA::CanPedReturnToState ( )
10321044
{

Client/game_sa/CPedSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
447447
void AddWeaponAudioEvent(EPedWeaponAudioEventType audioEventType);
448448

449449
virtual int GetCustomMoveAnim();
450+
bool IsDoingGangDriveby();
450451

451452
static void StaticSetHooks();
452453
};

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ void CClientGame::DrawPlayerDetails(CClientPlayer* pPlayer)
30533053
pPlayer->GetAim(fAimX, fAimY);
30543054
const CVector& vecAimSource = pPlayer->GetAimSource();
30553055
const CVector& vecAimTarget = pPlayer->GetAimTarget();
3056-
unsigned char ucDrivebyAim = pPlayer->GetVehicleAimAnim();
3056+
eVehicleAimDirection ucDrivebyAim = pPlayer->GetVehicleAimAnim();
30573057

30583058
g_pCore->GetGraphics()->DrawLine3DQueued(vecAimSource, vecAimTarget, 1.0f, 0x10DE1212, true);
30593059
g_pCore->GetGraphics()->DrawLine3DQueued(vecAimSource, vecAimTarget, 1.0f, 0x90DE1212, false);
@@ -3222,7 +3222,7 @@ void CClientGame::UpdateMimics()
32223222
m_pLocalPlayer->GetShotData(&vecOrigin, &vecTarget);
32233223
float fAimX = pShotSync->m_fArmDirectionX;
32243224
float fAimY = pShotSync->m_fArmDirectionY;
3225-
char cVehicleAimDirection = pShotSync->m_cInVehicleAimDirection;
3225+
eVehicleAimDirection cVehicleAimDirection = pShotSync->m_cInVehicleAimDirection;
32263226
bool bAkimboUp = g_pMultiplayer->GetAkimboTargetUp();
32273227

32283228
/*

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ CVector CClientPed::GetAim() const
25562556
return CVector();
25572557
}
25582558

2559-
void CClientPed::SetAim(float fArmDirectionX, float fArmDirectionY, unsigned char cInVehicleAimAnim)
2559+
void CClientPed::SetAim(float fArmDirectionX, float fArmDirectionY, eVehicleAimDirection cInVehicleAimAnim)
25602560
{
25612561
if (!m_bIsLocalPlayer)
25622562
{
@@ -2568,7 +2568,7 @@ void CClientPed::SetAim(float fArmDirectionX, float fArmDirectionY, unsigned cha
25682568
}
25692569
}
25702570

2571-
void CClientPed::SetAimInterpolated(unsigned long ulDelay, float fArmDirectionX, float fArmDirectionY, bool bAkimboAimUp, unsigned char cInVehicleAimAnim)
2571+
void CClientPed::SetAimInterpolated(unsigned long ulDelay, float fArmDirectionX, float fArmDirectionY, bool bAkimboAimUp, eVehicleAimDirection cInVehicleAimAnim)
25722572
{
25732573
if (!m_bIsLocalPlayer)
25742574
{
@@ -2587,7 +2587,7 @@ void CClientPed::SetAimInterpolated(unsigned long ulDelay, float fArmDirectionX,
25872587
}
25882588
}
25892589

2590-
void CClientPed::SetAimingData(unsigned long ulDelay, const CVector& vecTargetPosition, float fArmDirectionX, float fArmDirectionY, char cInVehicleAimAnim,
2590+
void CClientPed::SetAimingData(unsigned long ulDelay, const CVector& vecTargetPosition, float fArmDirectionX, float fArmDirectionY, eVehicleAimDirection cInVehicleAimAnim,
25912591
CVector* pSource, bool bInterpolateAim)
25922592
{
25932593
if (!m_bIsLocalPlayer)

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
321321
CVector GetAim() const;
322322
const CVector& GetAimSource() { return m_shotSyncData->m_vecShotOrigin; };
323323
const CVector& GetAimTarget() { return m_shotSyncData->m_vecShotTarget; };
324-
unsigned char GetVehicleAimAnim() { return m_shotSyncData->m_cInVehicleAimDirection; };
325-
void SetAim(float fArmDirectionX, float fArmDirectionY, unsigned char cInVehicleAimAnim);
326-
void SetAimInterpolated(unsigned long ulDelay, float fArmDirectionX, float fArmDirectionY, bool bAkimboAimUp, unsigned char cInVehicleAimAnim);
327-
void SetAimingData(unsigned long ulDelay, const CVector& vecTargetPosition, float fArmDirectionX, float fArmDirectionY, char cInVehicleAimAnim,
324+
eVehicleAimDirection GetVehicleAimAnim() { return m_shotSyncData->m_cInVehicleAimDirection; };
325+
void SetAim(float fArmDirectionX, float fArmDirectionY, eVehicleAimDirection cInVehicleAimAnim);
326+
void SetAimInterpolated(unsigned long ulDelay, float fArmDirectionX, float fArmDirectionY, bool bAkimboAimUp, eVehicleAimDirection cInVehicleAimAnim);
327+
void SetAimingData(unsigned long ulDelay, const CVector& vecTargetPosition, float fArmDirectionX, float fArmDirectionY, eVehicleAimDirection cInVehicleAimAnim,
328328
CVector* pSource, bool bInterpolateAim);
329329

330330
unsigned long GetMemoryValue(unsigned long ulOffset) { return (m_pPlayerPed) ? *m_pPlayerPed->GetMemoryValue(ulOffset) : 0; };

Client/mods/deathmatch/logic/CNetAPI.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ void CNetAPI::ReadKeysync(CClientPlayer* pPlayer, NetBitStreamInterface& BitStre
625625
BitStream.Read(&aim);
626626

627627
// Read out the driveby direction
628-
unsigned char ucDriveByAim;
629-
BitStream.Read(ucDriveByAim);
628+
eVehicleAimDirection ucDriveByAim;
629+
BitStream.Read(*reinterpret_cast<char*>(&ucDriveByAim));
630630

631631
// Set the aim data (immediately if in vehicle, otherwize delayed/interpolated)
632632
if (pVehicle)
@@ -763,7 +763,7 @@ void CNetAPI::WriteKeysync(CClientPed* pPlayerModel, NetBitStreamInterface& BitS
763763

764764
// Write the driveby direction
765765
CShotSyncData* pShotsyncData = g_pMultiplayer->GetLocalShotSyncData();
766-
BitStream.Write(pShotsyncData->m_cInVehicleAimDirection);
766+
BitStream.Write(static_cast<char>(pShotsyncData->m_cInVehicleAimDirection));
767767
}
768768
}
769769
else
@@ -928,7 +928,7 @@ void CNetAPI::ReadPlayerPuresync(CClientPlayer* pPlayer, NetBitStreamInterface&
928928
BitStream.Read(&aim);
929929

930930
// Interpolate the aiming
931-
pPlayer->SetAimInterpolated(TICK_RATE_AIM, rotation.data.fRotation, aim.data.fArm, flags.data.bAkimboTargetUp, 0);
931+
pPlayer->SetAimInterpolated(TICK_RATE_AIM, rotation.data.fRotation, aim.data.fArm, flags.data.bAkimboTargetUp, eVehicleAimDirection::FORWARDS);
932932

933933
// Read the aim data only if he's shooting or aiming
934934
if (aim.isFull())
@@ -1484,9 +1484,10 @@ void CNetAPI::ReadVehiclePuresync(CClientPlayer* pPlayer, CClientVehicle* pVehic
14841484
// Read out the driveby direction
14851485
SDrivebyDirectionSync driveby;
14861486
BitStream.Read(&driveby);
1487+
eVehicleAimDirection ucDirection = static_cast<eVehicleAimDirection>(driveby.data.ucDirection);
14871488

14881489
// Set the aiming
1489-
pPlayer->SetAimingData(TICK_RATE, aim.data.vecTarget, aim.data.fArm, 0.0f, driveby.data.ucDirection, &aim.data.vecOrigin, false);
1490+
pPlayer->SetAimingData(TICK_RATE, aim.data.vecTarget, aim.data.fArm, 0.0f, ucDirection, &aim.data.vecOrigin, false);
14901491
}
14911492
else
14921493
{
@@ -1727,7 +1728,7 @@ void CNetAPI::WriteVehiclePuresync(CClientPed* pPlayerModel, CClientVehicle* pVe
17271728
// Sync driveby direction
17281729
CShotSyncData* pShotsyncData = g_pMultiplayer->GetLocalShotSyncData();
17291730
SDrivebyDirectionSync driveby;
1730-
driveby.data.ucDirection = static_cast<unsigned char>(pShotsyncData->m_cInVehicleAimDirection);
1731+
driveby.data.ucDirection = pShotsyncData->m_cInVehicleAimDirection;
17311732
BitStream.Write(&driveby);
17321733
}
17331734
}

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,8 +2415,7 @@ bool CStaticFunctionDefinitions::SetPedAimTarget(CClientEntity& Entity, CVector&
24152415
if (Ped.IsInVehicle())
24162416
{
24172417
// Driveby aim animation
2418-
// 0 = forwards, 1 = left, 2 = back, 3 = right
2419-
unsigned char cInVehicleAimAnim = 0;
2418+
eVehicleAimDirection cInVehicleAimAnim = eVehicleAimDirection::FORWARDS;
24202419

24212420
// Ped rotation
24222421
CVector vecRot;
@@ -2439,21 +2438,21 @@ bool CStaticFunctionDefinitions::SetPedAimTarget(CClientEntity& Entity, CVector&
24392438
if (fRotDiff > PI * 0.25 && fRotDiff < PI * 0.75)
24402439
{
24412440
// Facing left
2442-
cInVehicleAimAnim = 1;
2441+
cInVehicleAimAnim = eVehicleAimDirection::LEFT;
24432442
fArmX = fArmX - PI / 2;
24442443
fArmY = -fArmY;
24452444
}
24462445
else if (fRotDiff > PI * 0.75 || fRotDiff < -PI * 0.75)
24472446
{
24482447
// Facing backwards
2449-
cInVehicleAimAnim = 2;
2448+
cInVehicleAimAnim = eVehicleAimDirection::BACKWARDS;
24502449
fArmX = fArmX + PI;
24512450
fArmY = -fArmY;
24522451
}
24532452
else if (fRotDiff < -PI * 0.25 && fRotDiff > -PI * 0.75)
24542453
{
24552454
// Facing right
2456-
cInVehicleAimAnim = 3;
2455+
cInVehicleAimAnim = eVehicleAimDirection::RIGHT;
24572456
fArmX = fArmX + PI / 2;
24582457
}
24592458
else
@@ -2468,7 +2467,7 @@ bool CStaticFunctionDefinitions::SetPedAimTarget(CClientEntity& Entity, CVector&
24682467
else
24692468
{
24702469
Ped.SetTargetTarget(TICK_RATE, vecOrigin, vecTarget);
2471-
Ped.SetAim(fArmX, fArmY, 0);
2470+
Ped.SetAim(fArmX, fArmY, eVehicleAimDirection::FORWARDS);
24722471
}
24732472

24742473
return true;

Client/multiplayer_sa/multiplayer_shotsync.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../game_sa/CPedSA.h"
1616
#include "../game_sa/CEventDamageSA.h"
1717
#include "../game_sa/CColPointSA.h"
18+
#include <net/SyncStructures.h>
1819

1920
extern CMultiplayerSA* pMultiplayer;
2021

@@ -49,7 +50,7 @@ CVector vecLastOrigin;
4950
CVector vecLastLocalPlayerBulletStart;
5051
CVector vecLastLocalPlayerBulletEnd;
5152

52-
char cTempGunDirection;
53+
eVehicleAimDirection cTempGunDirection;
5354

5455
DWORD vecTargetPosition;
5556
DWORD vecAltPos;
@@ -138,9 +139,15 @@ bool IsLocalPlayer(CPedSAInterface* pPedInterface)
138139
return false;
139140
}
140141

141-
VOID WriteGunDirectionDataForPed(CPedSAInterface* pPedInterface, float* fGunDirectionX, float* fGunDirectionY, char* cGunDirection)
142+
VOID WriteGunDirectionDataForPed(CPedSAInterface* pPedInterface, float* fGunDirectionX, float* fGunDirectionY, eVehicleAimDirection* cGunDirection)
142143
{
143-
if (!IsLocalPlayer(pPedInterface))
144+
SClientEntity<CPedSA>* pPedClientEntity = m_pools->GetPed((DWORD*)pPedInterface);
145+
CPed* pAimingPed = pPedClientEntity ? pPedClientEntity->pEntity : nullptr;
146+
147+
if (!pAimingPed)
148+
return;
149+
150+
if (!IsLocalPlayer(pAimingPed))
144151
{
145152
CRemoteDataStorageSA* data = CRemoteDataSA::GetRemoteDataStorage(pPedInterface);
146153
if (data)
@@ -168,6 +175,18 @@ VOID WriteGunDirectionDataForPed(CPedSAInterface* pPedInterface, float* fGunDire
168175
// Make sure our pitch is updated (fixes first-person weapons not moving)
169176
*fGunDirectionY = pGameInterface->GetCamera()->Find3rdPersonQuickAimPitch();
170177

178+
if (pAimingPed->IsDoingGangDriveby())
179+
{
180+
// Fix pitch in driveby when facing left or backwards
181+
switch (LocalShotSyncData.m_cInVehicleAimDirection)
182+
{
183+
case eVehicleAimDirection::LEFT:
184+
case eVehicleAimDirection::BACKWARDS:
185+
*fGunDirectionY = -*fGunDirectionY;
186+
break;
187+
}
188+
}
189+
171190
LocalShotSyncData.m_fArmDirectionX = *fGunDirectionX;
172191
LocalShotSyncData.m_fArmDirectionY = *fGunDirectionY;
173192
}

Client/multiplayer_sa/multiplayer_shotsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// our stuff
4444
VOID InitShotsyncHooks();
4545
CShotSyncData* GetLocalPedShotSyncData();
46-
VOID WriteGunDirectionDataForPed(class CPedSAInterface* pPedInterface, float* fGunDirectionX, float* fGunDirectionY, char* cGunDirection);
46+
VOID WriteGunDirectionDataForPed(class CPedSAInterface* pPedInterface, float* fGunDirectionX, float* fGunDirectionY, eVehicleAimDirection* cGunDirection);
4747
bool IsLocalPlayer(CPedSAInterface* pPedInterface);
4848

4949
// hooks

Client/sdk/game/CPed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,5 @@ class CPed : public virtual CPhysical
269269
virtual void AddWeaponAudioEvent(EPedWeaponAudioEventType audioEventType) = 0;
270270

271271
virtual int GetCustomMoveAnim() = 0;
272+
virtual bool IsDoingGangDriveby() = 0;
272273
};

Client/sdk/multiplayer/CMultiplayer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ typedef void(PedStepHandler)(CPedSAInterface* pPed, bool bFoot);
123123

124124
using VehicleWeaponHitHandler = void(SVehicleWeaponHitEvent& event);
125125

126+
enum class eVehicleAimDirection : unsigned char;
127+
126128
/**
127129
* This class contains information used for shot syncing, one exists per player.
128130
*/
@@ -135,7 +137,7 @@ class CShotSyncData
135137
float m_fArmDirectionX;
136138
float m_fArmDirectionY;
137139
// only for in-vehicle shooting
138-
char m_cInVehicleAimDirection; // 0 = forwards, 1 = left, 2 = back, 3 = right
140+
eVehicleAimDirection m_cInVehicleAimDirection;
139141
// use origin
140142
bool m_bUseOrigin;
141143

Server/mods/deathmatch/logic/CPlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CPlayer::CPlayer(CPlayerManager* pPlayerManager, class CScriptDebugging* pScript
3939

4040
m_fRotation = 0.0f;
4141
m_fAimDirection = 0.0f;
42-
m_ucDriveByDirection = 0;
42+
m_ucDriveByDirection = eVehicleAimDirection::FORWARDS;
4343
m_bAkimboArmUp = false;
4444

4545
m_VoiceState = VOICESTATE_IDLE;

Server/mods/deathmatch/logic/CPlayer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CPlayer;
2525
#include "packets/CPlayerStatsPacket.h"
2626
class CKeyBinds;
2727
class CPlayerCamera;
28+
enum class eVehicleAimDirection : unsigned char;
2829

2930
enum eVoiceState
3031
{
@@ -121,8 +122,8 @@ class CPlayer : public CPed, public CClient
121122
void SetTargettingVector(const CVector& vecTarget) { m_vecTargetting = vecTarget; };
122123
float GetAimDirection() { return m_fAimDirection; };
123124
void SetAimDirection(float fDirection) { m_fAimDirection = fDirection; };
124-
unsigned char GetDriveByDirection() { return m_ucDriveByDirection; };
125-
void SetDriveByDirection(unsigned char ucDirection) { m_ucDriveByDirection = ucDirection; };
125+
eVehicleAimDirection GetDriveByDirection() { return m_ucDriveByDirection; };
126+
void SetDriveByDirection(eVehicleAimDirection ucDirection) { m_ucDriveByDirection = ucDirection; };
126127
bool IsAkimboArmUp() { return m_bAkimboArmUp; };
127128
void SetAkimboArmUp(bool bUp) { m_bAkimboArmUp = bUp; };
128129

@@ -372,7 +373,7 @@ class CPlayer : public CPed, public CClient
372373
CVector m_vecSniperSource;
373374
CVector m_vecTargetting;
374375
float m_fAimDirection;
375-
unsigned char m_ucDriveByDirection;
376+
eVehicleAimDirection m_ucDriveByDirection;
376377

377378
bool m_bAkimboArmUp;
378379

Server/mods/deathmatch/logic/net/CSimVehiclePuresyncPacket.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ struct STrailerInfo
1414
CVector m_TrailerRotationDeg;
1515
};
1616

17+
enum class eVehicleAimDirection : unsigned char;
18+
1719
class CSimVehiclePuresyncPacket : public CSimPacket
1820
{
1921
public:
@@ -85,7 +87,7 @@ class CSimVehiclePuresyncPacket : public CSimPacket
8587
CVector vecSniperSource;
8688
CVector vecTargetting;
8789

88-
uchar ucDriveByDirection;
90+
eVehicleAimDirection ucDriveByDirection;
8991

9092
float fTurretX;
9193
float fTurretY;

Server/mods/deathmatch/logic/packets/CKeysyncPacket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ bool CKeysyncPacket::Read(NetBitStreamInterface& BitStream)
108108
}
109109

110110
// Read out the driveby direction
111-
unsigned char ucDriveByDirection;
112-
if (!BitStream.Read(ucDriveByDirection))
111+
eVehicleAimDirection ucDriveByDirection;
112+
if (!BitStream.Read(*reinterpret_cast<underlying_type_t<eVehicleAimDirection>*>(&ucDriveByDirection)))
113113
return false;
114114
pSourcePlayer->SetDriveByDirection(ucDriveByDirection);
115115
}
@@ -216,7 +216,7 @@ bool CKeysyncPacket::Write(NetBitStreamInterface& BitStream) const
216216
BitStream.Write(&aim);
217217

218218
// Write the driveby aim directoin
219-
BitStream.Write(pSourcePlayer->GetDriveByDirection());
219+
BitStream.Write(static_cast<underlying_type_t<eVehicleAimDirection>>(pSourcePlayer->GetDriveByDirection()));
220220
}
221221
else
222222
{

Shared/sdk/net/SyncStructures.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,15 @@ struct SVehiclePuresyncFlags : public ISyncStructure
678678
} data;
679679
};
680680

681+
682+
enum class eVehicleAimDirection : unsigned char
683+
{
684+
FORWARDS = 0,
685+
LEFT,
686+
BACKWARDS,
687+
RIGHT,
688+
};
689+
681690
struct SDrivebyDirectionSync : public ISyncStructure
682691
{
683692
enum
@@ -690,7 +699,7 @@ struct SDrivebyDirectionSync : public ISyncStructure
690699

691700
struct
692701
{
693-
unsigned char ucDirection : 2;
702+
eVehicleAimDirection ucDirection : 2;
694703
} data;
695704
};
696705

0 commit comments

Comments
 (0)