From 6ba07a9264869c2cc56a5060171fe519921411f8 Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 12 Mar 2025 03:35:01 +0100 Subject: [PATCH 1/2] Fix bug --- Client/game_sa/CBuildingsPoolSA.cpp | 4 +++- Client/game_sa/CPedSA.cpp | 14 -------------- Client/game_sa/CPedSA.h | 6 ++---- Client/game_sa/CPlayerPedSA.cpp | 14 ++++++++++++++ Client/game_sa/CPlayerPedSA.h | 10 ++++++++-- Client/sdk/game/CPed.h | 3 --- Client/sdk/game/CPlayerPed.h | 3 +++ 7 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Client/game_sa/CBuildingsPoolSA.cpp b/Client/game_sa/CBuildingsPoolSA.cpp index ae51fa06734..1deba03a6d4 100644 --- a/Client/game_sa/CBuildingsPoolSA.cpp +++ b/Client/game_sa/CBuildingsPoolSA.cpp @@ -19,6 +19,7 @@ #include "MemSA.h" #include "CVehicleSA.h" #include "CBuildingRemovalSA.h" +#include "CPlayerPedSA.h" extern CGameSA* pGame; @@ -372,7 +373,8 @@ void CBuildingsPoolSA::RemovePedsContactEnityLinks() ped->pLastContactedEntity[2] = nullptr; ped->pLastContactedEntity[3] = nullptr; ped->m_ucCollisionState = 0; - ped->pTargetedEntity = nullptr; + + reinterpret_cast(pedLinks->pEntity)->SetTargetedEntity(nullptr); } } } diff --git a/Client/game_sa/CPedSA.cpp b/Client/game_sa/CPedSA.cpp index 0601cabcf71..ef718d32d1e 100644 --- a/Client/game_sa/CPedSA.cpp +++ b/Client/game_sa/CPedSA.cpp @@ -380,20 +380,6 @@ CEntity* CPedSA::GetContactEntity() const return pGame->GetPools()->GetEntity(reinterpret_cast(contactInterface)); } -CEntity* CPedSA::GetTargetedEntity() const -{ - CEntitySAInterface* targetInterface = GetPedInterface()->pTargetedEntity; - if (!targetInterface) - return nullptr; - - return pGame->GetPools()->GetEntity(reinterpret_cast(targetInterface)); -} - -void CPedSA::SetTargetedEntity(CEntity* targetEntity) -{ - GetPedInterface()->pTargetedEntity = targetEntity ? targetEntity->GetInterface() : nullptr; -} - void CPedSA::RemoveBodyPart(std::uint8_t boneID, std::uint8_t direction) { // char __thiscall CPed::RemoveBodyPart(CPed *this, int boneID, int localDir) diff --git a/Client/game_sa/CPedSA.h b/Client/game_sa/CPedSA.h index df9abc476de..883de1797ad 100644 --- a/Client/game_sa/CPedSA.h +++ b/Client/game_sa/CPedSA.h @@ -324,7 +324,7 @@ class CPedSAInterface : public CPhysicalSAInterface int unk_75C; std::uint8_t lastWeaponDamage; std::uint8_t unk_761[3]; - CEntitySAInterface* pTargetedEntity; + CEntitySAInterface* lastDamagedEntity; std::int16_t unk_768; CVector vecTurretOffset; @@ -343,6 +343,7 @@ class CPedSAInterface : public CPhysicalSAInterface }; static_assert(sizeof(CPedSAInterface) == 0x79C, "Invalid size for CPedSAInterface"); + class CPedSA : public virtual CPed, public virtual CPhysicalSA { friend class CPoolsSA; @@ -424,9 +425,6 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA int GetRunState() const override { return GetPedInterface()->moveState; } - CEntity* GetTargetedEntity() const override; - void SetTargetedEntity(CEntity* targetEntity) override; - bool GetCanBeShotInVehicle() const override{ return GetPedInterface()->pedFlags.bCanBeShotInVehicle; } bool GetTestForShotInVehicle() const override { return GetPedInterface()->pedFlags.bTestForShotInVehicle; } diff --git a/Client/game_sa/CPlayerPedSA.cpp b/Client/game_sa/CPlayerPedSA.cpp index 17c10e9d640..a365cba6f98 100644 --- a/Client/game_sa/CPlayerPedSA.cpp +++ b/Client/game_sa/CPlayerPedSA.cpp @@ -300,6 +300,20 @@ void CPlayerPedSA::SetMoveAnim(eMoveAnim iAnimGroup) } } +CEntity* CPlayerPedSA::GetTargetedEntity() const +{ + CEntitySAInterface* targetInterface = GetPlayerPedInterface()->mouseTargetEntity; + if (!targetInterface) + return nullptr; + + return pGame->GetPools()->GetEntity(reinterpret_cast(targetInterface)); +} + +void CPlayerPedSA::SetTargetedEntity(CEntity* targetEntity) +{ + GetPlayerPedInterface()->mouseTargetEntity = targetEntity ? targetEntity->GetInterface() : nullptr; +} + //////////////////////////////////////////////////////////////// // // Hooks for CPlayerPedSA diff --git a/Client/game_sa/CPlayerPedSA.h b/Client/game_sa/CPlayerPedSA.h index 53c7b7b357c..7932f294973 100644 --- a/Client/game_sa/CPlayerPedSA.h +++ b/Client/game_sa/CPlayerPedSA.h @@ -28,10 +28,13 @@ #define SIZEOF_CPLAYERPED 1956 -class CPlayerPedSAInterface : public CPedSAInterface // CPlayerPed 1956 bytes in SA +class CPlayerPedSAInterface : public CPedSAInterface { public: + CEntitySAInterface* mouseTargetEntity; + std::uint8_t field_7A0[4]; }; +static_assert(sizeof(CPlayerPedSAInterface) == 0x7A4, "Invalid size for CPlayerPedSAInterface"); class CPlayerPedSA : public virtual CPlayerPed, public virtual CPedSA { @@ -52,7 +55,10 @@ class CPlayerPedSA : public virtual CPlayerPed, public virtual CPedSA eMoveAnim GetMoveAnim(); void SetMoveAnim(eMoveAnim iAnimGroup); - CPlayerPedSAInterface* GetPlayerPedInterface() { return static_cast(m_pInterface); }; + CEntity* GetTargetedEntity() const override; + void SetTargetedEntity(CEntity* targetEntity) override; + + CPlayerPedSAInterface* GetPlayerPedInterface() const noexcept { return static_cast(m_pInterface); }; static void StaticSetHooks(); }; diff --git a/Client/sdk/game/CPed.h b/Client/sdk/game/CPed.h index 3c3c8459660..99133873bc9 100644 --- a/Client/sdk/game/CPed.h +++ b/Client/sdk/game/CPed.h @@ -255,9 +255,6 @@ class CPed : public virtual CPhysical virtual int GetRunState() const = 0; - virtual CEntity* GetTargetedEntity() const = 0; - virtual void SetTargetedEntity(CEntity* targetEntity) = 0; - virtual bool GetCanBeShotInVehicle() const = 0; virtual bool GetTestForShotInVehicle() const = 0; diff --git a/Client/sdk/game/CPlayerPed.h b/Client/sdk/game/CPlayerPed.h index e651be48e37..5ab18448759 100644 --- a/Client/sdk/game/CPlayerPed.h +++ b/Client/sdk/game/CPlayerPed.h @@ -26,4 +26,7 @@ class CPlayerPed : public virtual CPed virtual eMoveAnim GetMoveAnim() = 0; virtual void SetMoveAnim(eMoveAnim iAnimGroup) = 0; + + virtual CEntity* GetTargetedEntity() const = 0; + virtual void SetTargetedEntity(CEntity* entity) = 0; }; From f9f83f50307e8033452605956c20721913b01b43 Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 12 Mar 2025 03:37:44 +0100 Subject: [PATCH 2/2] Remove line --- Client/game_sa/CPedSA.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/game_sa/CPedSA.h b/Client/game_sa/CPedSA.h index 883de1797ad..ef92e058c16 100644 --- a/Client/game_sa/CPedSA.h +++ b/Client/game_sa/CPedSA.h @@ -343,7 +343,6 @@ class CPedSAInterface : public CPhysicalSAInterface }; static_assert(sizeof(CPedSAInterface) == 0x79C, "Invalid size for CPedSAInterface"); - class CPedSA : public virtual CPed, public virtual CPhysicalSA { friend class CPoolsSA;