Skip to content

Commit dcf4406

Browse files
authored
Fix stealth kill #4092 (#4093)
1 parent f495899 commit dcf4406

File tree

7 files changed

+29
-24
lines changed

7 files changed

+29
-24
lines changed

Client/game_sa/CBuildingsPoolSA.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "MemSA.h"
2020
#include "CVehicleSA.h"
2121
#include "CBuildingRemovalSA.h"
22+
#include "CPlayerPedSA.h"
2223

2324
extern CGameSA* pGame;
2425

@@ -372,7 +373,8 @@ void CBuildingsPoolSA::RemovePedsContactEnityLinks()
372373
ped->pLastContactedEntity[2] = nullptr;
373374
ped->pLastContactedEntity[3] = nullptr;
374375
ped->m_ucCollisionState = 0;
375-
ped->pTargetedEntity = nullptr;
376+
377+
reinterpret_cast<CPlayerPedSA*>(pedLinks->pEntity)->SetTargetedEntity(nullptr);
376378
}
377379
}
378380
}

Client/game_sa/CPedSA.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -380,20 +380,6 @@ CEntity* CPedSA::GetContactEntity() const
380380
return pGame->GetPools()->GetEntity(reinterpret_cast<DWORD*>(contactInterface));
381381
}
382382

383-
CEntity* CPedSA::GetTargetedEntity() const
384-
{
385-
CEntitySAInterface* targetInterface = GetPedInterface()->pTargetedEntity;
386-
if (!targetInterface)
387-
return nullptr;
388-
389-
return pGame->GetPools()->GetEntity(reinterpret_cast<DWORD*>(targetInterface));
390-
}
391-
392-
void CPedSA::SetTargetedEntity(CEntity* targetEntity)
393-
{
394-
GetPedInterface()->pTargetedEntity = targetEntity ? targetEntity->GetInterface() : nullptr;
395-
}
396-
397383
void CPedSA::RemoveBodyPart(std::uint8_t boneID, std::uint8_t direction)
398384
{
399385
// char __thiscall CPed::RemoveBodyPart(CPed *this, int boneID, int localDir)

Client/game_sa/CPedSA.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class CPedSAInterface : public CPhysicalSAInterface
324324
int unk_75C;
325325
std::uint8_t lastWeaponDamage;
326326
std::uint8_t unk_761[3];
327-
CEntitySAInterface* pTargetedEntity;
327+
CEntitySAInterface* lastDamagedEntity;
328328
std::int16_t unk_768;
329329

330330
CVector vecTurretOffset;
@@ -424,9 +424,6 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
424424

425425
int GetRunState() const override { return GetPedInterface()->moveState; }
426426

427-
CEntity* GetTargetedEntity() const override;
428-
void SetTargetedEntity(CEntity* targetEntity) override;
429-
430427
bool GetCanBeShotInVehicle() const override{ return GetPedInterface()->pedFlags.bCanBeShotInVehicle; }
431428
bool GetTestForShotInVehicle() const override { return GetPedInterface()->pedFlags.bTestForShotInVehicle; }
432429

Client/game_sa/CPlayerPedSA.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,20 @@ void CPlayerPedSA::SetMoveAnim(eMoveAnim iAnimGroup)
300300
}
301301
}
302302

303+
CEntity* CPlayerPedSA::GetTargetedEntity() const
304+
{
305+
CEntitySAInterface* targetInterface = GetPlayerPedInterface()->mouseTargetEntity;
306+
if (!targetInterface)
307+
return nullptr;
308+
309+
return pGame->GetPools()->GetEntity(reinterpret_cast<DWORD*>(targetInterface));
310+
}
311+
312+
void CPlayerPedSA::SetTargetedEntity(CEntity* targetEntity)
313+
{
314+
GetPlayerPedInterface()->mouseTargetEntity = targetEntity ? targetEntity->GetInterface() : nullptr;
315+
}
316+
303317
////////////////////////////////////////////////////////////////
304318
//
305319
// Hooks for CPlayerPedSA

Client/game_sa/CPlayerPedSA.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828

2929
#define SIZEOF_CPLAYERPED 1956
3030

31-
class CPlayerPedSAInterface : public CPedSAInterface // CPlayerPed 1956 bytes in SA
31+
class CPlayerPedSAInterface : public CPedSAInterface
3232
{
3333
public:
34+
CEntitySAInterface* mouseTargetEntity;
35+
std::uint8_t field_7A0[4];
3436
};
37+
static_assert(sizeof(CPlayerPedSAInterface) == 0x7A4, "Invalid size for CPlayerPedSAInterface");
3538

3639
class CPlayerPedSA : public virtual CPlayerPed, public virtual CPedSA
3740
{
@@ -52,7 +55,10 @@ class CPlayerPedSA : public virtual CPlayerPed, public virtual CPedSA
5255
eMoveAnim GetMoveAnim();
5356
void SetMoveAnim(eMoveAnim iAnimGroup);
5457

55-
CPlayerPedSAInterface* GetPlayerPedInterface() { return static_cast<CPlayerPedSAInterface*>(m_pInterface); };
58+
CEntity* GetTargetedEntity() const override;
59+
void SetTargetedEntity(CEntity* targetEntity) override;
60+
61+
CPlayerPedSAInterface* GetPlayerPedInterface() const noexcept { return static_cast<CPlayerPedSAInterface*>(m_pInterface); };
5662

5763
static void StaticSetHooks();
5864
};

Client/sdk/game/CPed.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ class CPed : public virtual CPhysical
255255

256256
virtual int GetRunState() const = 0;
257257

258-
virtual CEntity* GetTargetedEntity() const = 0;
259-
virtual void SetTargetedEntity(CEntity* targetEntity) = 0;
260-
261258
virtual bool GetCanBeShotInVehicle() const = 0;
262259
virtual bool GetTestForShotInVehicle() const = 0;
263260

Client/sdk/game/CPlayerPed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ class CPlayerPed : public virtual CPed
2626

2727
virtual eMoveAnim GetMoveAnim() = 0;
2828
virtual void SetMoveAnim(eMoveAnim iAnimGroup) = 0;
29+
30+
virtual CEntity* GetTargetedEntity() const = 0;
31+
virtual void SetTargetedEntity(CEntity* entity) = 0;
2932
};

0 commit comments

Comments
 (0)