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
};

0 commit comments

Comments
 (0)