From ed69be36cc30609100f0c75ac18aa5b4c15b22b4 Mon Sep 17 00:00:00 2001 From: erorcun Date: Fri, 14 Jun 2019 15:33:08 +0300 Subject: Some CPed functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: eray orçunus --- src/entities/Ped.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/entities/Ped.h | 47 ++++++++++++++++++++++++++++++++++++++---- src/entities/PedIK.cpp | 7 +++++++ src/entities/PedIK.h | 26 ++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 src/entities/PedIK.cpp create mode 100644 src/entities/PedIK.h (limited to 'src/entities') diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp index 55e33a2d..b4b980e5 100644 --- a/src/entities/Ped.cpp +++ b/src/entities/Ped.cpp @@ -11,6 +11,8 @@ void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); } void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } WRAPPER void CPed::KillPedWithCar(CVehicle *veh, float impulse) { EAXJMP(0x4EC430); } +WRAPPER void CPed::Say(uint16 audio) { EAXJMP(0x4E5A10); } +WRAPPER void CPed::SetLookFlag(CEntity* to, bool set) { EAXJMP(0x4C6460); } static char ObjectiveText[34][28] = { "No Obj", @@ -175,3 +177,56 @@ CPed::UseGroundColModel(void) m_nPedState == PED_DIE || m_nPedState == PED_DEAD; } + +void +CPed::AddWeaponModel(int id) +{ + RpAtomic* atm; + + if (id != -1) { + atm = (RpAtomic*)CModelInfo::GetModelInfo(id)->CreateInstance(); + RwFrameDestroy(RpAtomicGetFrame(atm)); + RpAtomicSetFrame(atm, m_pFrames[PED_HANDR]->frame); + RpClumpAddAtomic((RpClump*)m_rwObject, atm); + m_wepModelID = id; + } +} + +void +CPed::AimGun() +{ + RwV3d pos; + CVector vector; + uint8 newFlag; + + if (m_pSeekTarget) { + if (m_pSeekTarget->m_status == STATUS_PHYSICS) { + m_pSeekTarget->m_pedIK.GetComponentPosition(&pos, 1); + vector.x = pos.x; + vector.y = pos.y; + vector.z = pos.z; + } else { + vector = *(m_pSeekTarget->GetMatrix().GetPosition()); + } + CPed::Say(0x74); + + m_ped_flagB40 = m_pedIK.PointGunAtPosition(&vector); + if (m_pPedFight != m_pSeekTarget) { + CPed::SetLookFlag(m_pSeekTarget, 1); + } + + } else { + if (CPed::IsPlayer()) { + newFlag = m_pedIK.PointGunInDirection(m_fLookDirection, m_vecMoveSpeedAvg.y); + } else { + newFlag = m_pedIK.PointGunInDirection(m_fLookDirection, 0.0); + } + + m_ped_flagB40 = newFlag; + } +} + +STARTPATCHES + InjectHook(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP); + InjectHook(0x4C6AA0, &CPed::AimGun, PATCH_JUMP); +ENDPATCHES \ No newline at end of file diff --git a/src/entities/Ped.h b/src/entities/Ped.h index adf24c88..4a616e22 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -2,6 +2,8 @@ #include "Physical.h" #include "Weapon.h" +#include "PedIK.h" +#include enum { PED_MAX_WEAPONS = 13 @@ -79,6 +81,22 @@ enum { PEDMOVE_SPRINT, }; +enum PedNode { + PED_WAIST = 0, + PED_TORSO, // Smid on PS2/PC, Storso on mobile/xbox. We follow mobile/xbox (makes kicking on ground look better) + PED_HEAD, + PED_UPPERARML, + PED_UPPERARMR, + PED_HANDL, + PED_HANDR, + PED_UPPERLEGL, + PED_UPPERLEGR, + PED_FOOTL, + PED_FOOTR, + PED_NODE_11, + PED_NODE_MAX +}; + class CVehicle; class CPed : public CPhysical @@ -159,7 +177,16 @@ public: uint8 m_ped_flagI20 : 1; uint8 m_ped_flagI40 : 1; uint8 m_ped_flagI80 : 1; - uint8 stuff1[199]; + uint8 stuff10[60]; + int32 m_pEventEntity; + int32 m_fAngleToEvent; + AnimBlendFrameData *m_pFrames[PED_FRAME_MAX]; + int32 m_animGroup; + int32 m_pVehicleAnim; + CVector2D m_vecAnimMoveDelta; + CVector m_vecOffsetSeek; + CPedIK m_pedIK; + uint8 stuff1[12]; int32 m_nPedState; int32 m_nLastPedState; int32 m_nMoveState; @@ -167,7 +194,8 @@ public: CEntity *m_pCurrentPhysSurface; CVector m_vecOffsetFromPhysSurface; CEntity *m_pCurSurface; - uint8 stuff3[16]; + uint8 stuff3[12]; + CPed* m_pSeekTarget; CVehicle *m_pMyVehicle; bool bInVehicle; uint8 stuff4[23]; @@ -179,14 +207,25 @@ public: CWeapon m_weapons[PED_MAX_WEAPONS]; int32 stuff7; uint8 m_currentWeapon; - uint8 stuff[163]; + uint8 stuff[3]; + int32 m_pPointGunAt; + CVector m_vecHitLastPos; + uint8 stuff8[12]; + CPed *m_pPedFight; + float m_fLookDirection; + int32 m_wepModelID; + uint8 stuff9[120]; static void *operator new(size_t); static void operator delete(void*, size_t); bool IsPlayer(void) { return m_nPedType == 0 || m_nPedType== 1 || m_nPedType == 2 || m_nPedType == 3; } bool UseGroundColModel(void); + void AddWeaponModel(int id); + void AimGun(); void KillPedWithCar(CVehicle *veh, float impulse); + void Say(uint16 audio); + void SetLookFlag(CEntity *to, bool set); CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } static Bool &bNastyLimbsCheat; @@ -200,4 +239,4 @@ static_assert(offsetof(CPed, m_nPedType) == 0x32C, "CPed: error"); static_assert(offsetof(CPed, m_pCollidingEntity) == 0x34C, "CPed: error"); static_assert(offsetof(CPed, m_weapons) == 0x35C, "CPed: error"); static_assert(offsetof(CPed, m_currentWeapon) == 0x498, "CPed: error"); -static_assert(sizeof(CPed) == 0x53C, "CPed: error"); +static_assert(sizeof(CPed) == 0x53C, "CPed: error"); \ No newline at end of file diff --git a/src/entities/PedIK.cpp b/src/entities/PedIK.cpp new file mode 100644 index 00000000..f262fab5 --- /dev/null +++ b/src/entities/PedIK.cpp @@ -0,0 +1,7 @@ +#include "common.h" +#include "patcher.h" +#include "Ped.h" + +WRAPPER void CPedIK::GetComponentPosition(RwV3d* pos, int id) { EAXJMP(0x4ED0F0); } +WRAPPER bool CPedIK::PointGunInDirection(float phi, float theta) { EAXJMP(0x4ED9B0); } +WRAPPER bool CPedIK::PointGunAtPosition(CVector* position) { EAXJMP(0x4ED920); } \ No newline at end of file diff --git a/src/entities/PedIK.h b/src/entities/PedIK.h new file mode 100644 index 00000000..5e873bf5 --- /dev/null +++ b/src/entities/PedIK.h @@ -0,0 +1,26 @@ +#pragma once +#include + +struct LimbOrientation +{ + float phi; + float theta; +}; + +class CPed; + +class CPedIK +{ +public: + CPed* m_ped; + LimbOrientation m_headOrient; + LimbOrientation m_torsoOrient; + LimbOrientation m_upperArmOrient; + LimbOrientation m_lowerArmOrient; + int32 m_flags; + + void GetComponentPosition(RwV3d* pos, int id); + bool PointGunInDirection(float phi, float theta); + bool PointGunAtPosition(CVector* position); +}; +static_assert(sizeof(CPedIK) == 0x28, "CPedIK: error"); -- cgit v1.2.3 From 8db50cea6c5e7d93d7e7fe102ca465a615ab86de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Fri, 14 Jun 2019 17:14:22 +0300 Subject: Fix duplicate code for PedNode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: eray orçunus --- src/entities/Ped.h | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'src/entities') diff --git a/src/entities/Ped.h b/src/entities/Ped.h index 4a616e22..b7db77dc 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -81,22 +81,6 @@ enum { PEDMOVE_SPRINT, }; -enum PedNode { - PED_WAIST = 0, - PED_TORSO, // Smid on PS2/PC, Storso on mobile/xbox. We follow mobile/xbox (makes kicking on ground look better) - PED_HEAD, - PED_UPPERARML, - PED_UPPERARMR, - PED_HANDL, - PED_HANDR, - PED_UPPERLEGL, - PED_UPPERLEGR, - PED_FOOTL, - PED_FOOTR, - PED_NODE_11, - PED_NODE_MAX -}; - class CVehicle; class CPed : public CPhysical @@ -180,7 +164,7 @@ public: uint8 stuff10[60]; int32 m_pEventEntity; int32 m_fAngleToEvent; - AnimBlendFrameData *m_pFrames[PED_FRAME_MAX]; + AnimBlendFrameData *m_pFrames[PED_NODE_MAX]; int32 m_animGroup; int32 m_pVehicleAnim; CVector2D m_vecAnimMoveDelta; -- cgit v1.2.3 From 2f4fc5aaf07aedecf3796bae5a63734f133e19a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sat, 15 Jun 2019 18:53:25 +0300 Subject: More CPed functions and minor fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: eray orçunus --- src/entities/Ped.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++++++++-- src/entities/Ped.h | 28 ++++++-- 2 files changed, 198 insertions(+), 10 deletions(-) (limited to 'src/entities') diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp index b4b980e5..00e7ecb7 100644 --- a/src/entities/Ped.cpp +++ b/src/entities/Ped.cpp @@ -2,17 +2,21 @@ #include "patcher.h" #include "Ped.h" #include "Pools.h" +#include +#include +#include Bool &CPed::bNastyLimbsCheat = *(Bool*)0x95CD44; Bool &CPed::bPedCheat2 = *(Bool*)0x95CD5A; Bool &CPed::bPedCheat3 = *(Bool*)0x95CD59; - + void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); } void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } WRAPPER void CPed::KillPedWithCar(CVehicle *veh, float impulse) { EAXJMP(0x4EC430); } WRAPPER void CPed::Say(uint16 audio) { EAXJMP(0x4E5A10); } -WRAPPER void CPed::SetLookFlag(CEntity* to, bool set) { EAXJMP(0x4C6460); } +WRAPPER void CPed::SetDie(AnimationId anim, float arg1, float arg2) { EAXJMP(0x4D37D0); } +WRAPPER void CPed::SpawnFlyingComponent(int, signed char) { EAXJMP(0x4EB060); } static char ObjectiveText[34][28] = { "No Obj", @@ -186,7 +190,7 @@ CPed::AddWeaponModel(int id) if (id != -1) { atm = (RpAtomic*)CModelInfo::GetModelInfo(id)->CreateInstance(); RwFrameDestroy(RpAtomicGetFrame(atm)); - RpAtomicSetFrame(atm, m_pFrames[PED_HANDR]->frame); + RpAtomicSetFrame(atm, GetNodeFrame(PED_HANDR)); RpClumpAddAtomic((RpClump*)m_rwObject, atm); m_wepModelID = id; } @@ -210,7 +214,7 @@ CPed::AimGun() } CPed::Say(0x74); - m_ped_flagB40 = m_pedIK.PointGunAtPosition(&vector); + m_ped_flagB2 = m_pedIK.PointGunAtPosition(&vector); if (m_pPedFight != m_pSeekTarget) { CPed::SetLookFlag(m_pSeekTarget, 1); } @@ -222,11 +226,177 @@ CPed::AimGun() newFlag = m_pedIK.PointGunInDirection(m_fLookDirection, 0.0); } - m_ped_flagB40 = newFlag; + m_ped_flagB2 = newFlag; + } +} + + +// After I finished this I realized it's only for SCM opcode... +void +CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer) +{ + CVector pos2 = CVector( + pos.x, + pos.y, + pos.z + 0.1 + ); + + if (!CPed::IsPlayer() || evenOnPlayer) + { + ++CStats::HeadShots; + + // yes. decompiled by hand. + if (m_nPedState != PED_PASSENGER || m_nPedState != PED_TAXI_PASSENGER) { + CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0, 0.0); + } + + m_ped_flagC20 = 1; + m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 150; + + CParticle::AddParticle(PARTICLE_TEST, pos2, + CVector( + 0.0, + 0.0, + 0.0 + ), NULL, 0.2f, 0, 0, 0, 0); + + if (CEntity::GetIsOnScreen()) + { + for(int i=0; i<0x20; i++) { + CParticle::AddParticle(PARTICLE_BLOOD_SMALL, + pos2, + CVector( + 0.0, + 0.0, + 0.03 + ), NULL, 0.0f, 0, 0, 0, 0); + } + + for (int i = 0; i < 0x10; i++) { + CParticle::AddParticle(PARTICLE_DEBRIS2, + pos2, + CVector( + 0.0, + 0.0, + 0.0099999998 + ), NULL, 0.0f, 0, 0, 0, 0); + } + } + } +} + +void +CPed::RemoveBodyPart(PedNode nodeId, char arg4) +{ + RwFrame *frame; + RwFrame *fp; + RwV3d zero; + + frame = GetNodeFrame(nodeId); + if (frame) + { + if (CGame::nastyGame) + { + if (nodeId != PED_HEAD) + CPed::SpawnFlyingComponent(nodeId, arg4); + + RecurseFrameChildrenVisibilityCB(frame, 0); + zero.x = 0.0; + zero.z = 0.0; + zero.y = 0.0; + for (fp = RwFrameGetParent(frame); fp; fp = RwFrameGetParent(frame)) + RwV3dTransformPoints(&zero, &zero, 1, &fp->modelling); + + if (CEntity::GetIsOnScreen()) + { + CParticle::AddParticle(PARTICLE_TEST, zero, + CVector( + 0.0, + 0.0, + 0.0 + ), NULL, 0.2f, 0, 0, 0, 0); + + for (int i = 0; i < 0x10; i++) { + CParticle::AddParticle(PARTICLE_BLOOD_SMALL, + zero, + CVector( + 0.0, + 0.0, + 0.03 + ), NULL, 0.0f, 0, 0, 0, 0); + } + } + m_ped_flagC20 = 1; + m_bodyPartBleeding = nodeId; + } + } + else + { + printf("Trying to remove ped component"); + } +} + +RwObject* +CPed::SetPedAtomicVisibilityCB(RwObject *object, void *data) +{ + RwObject *result = object; + if (!data) + object->flags = 0; + + return result; +} + +RwFrame* +CPed::RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data) +{ + RwFrameForAllObjects(frame, SetPedAtomicVisibilityCB, data); + RwFrameForAllChildren(frame, RecurseFrameChildrenVisibilityCB, 0); + return frame; +} + +void +CPed::SetLookFlag(CPed *to, bool set) +{ + if (m_lookTimer < CTimer::GetTimeInMilliseconds()) + { + m_ped_flagA10 = 1; + m_ped_flagA40 = 0; + m_pPedFight = to; + m_pPedFight->RegisterReference((CEntity**)&m_pPedFight); + m_fLookDirection = 999999; + m_lookTimer = 0; + m_ped_flagA20_look = set; + if (m_nPedState != PED_DRIVING) { + // Resets second right most bit + m_pedIK.m_flags &= 0xFFFFFFFD; + } } } +void +CPed::SetLookFlag(float angle, bool set) +{ + if (m_lookTimer < CTimer::GetTimeInMilliseconds()) + { + m_ped_flagA10 = 1; + m_ped_flagA40 = 0; + m_pPedFight = 0; + m_fLookDirection = angle; + m_lookTimer = 0; + m_ped_flagA20_look = set; + if (m_nPedState != PED_DRIVING) { + // Resets second right most bit + m_pedIK.m_flags &= 0xFFFFFFFD; + } + } +} + + STARTPATCHES InjectHook(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP); InjectHook(0x4C6AA0, &CPed::AimGun, PATCH_JUMP); + InjectHook(0x4EB470, &CPed::ApplyHeadShot, PATCH_JUMP); + InjectHook(0x4EAEE0, &CPed::RemoveBodyPart, PATCH_JUMP); + InjectHook(0x4C6460, (void (CPed::*)(CPed*, bool)) &CPed::SetLookFlag, PATCH_JUMP); + InjectHook(0x4C63E0, (void (CPed::*)(float, bool)) &CPed::SetLookFlag, PATCH_JUMP); ENDPATCHES \ No newline at end of file diff --git a/src/entities/Ped.h b/src/entities/Ped.h index b7db77dc..2f0f67f0 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -3,6 +3,7 @@ #include "Physical.h" #include "Weapon.h" #include "PedIK.h" +#include #include enum { @@ -94,7 +95,7 @@ public: uint8 m_ped_flagA4 : 1; uint8 m_ped_flagA8 : 1; uint8 m_ped_flagA10 : 1; - uint8 m_ped_flagA20 : 1; + uint8 m_ped_flagA20_look : 1; uint8 m_ped_flagA40 : 1; uint8 m_ped_flagA80 : 1; uint8 m_ped_flagB1 : 1; @@ -163,14 +164,15 @@ public: uint8 m_ped_flagI80 : 1; uint8 stuff10[60]; int32 m_pEventEntity; - int32 m_fAngleToEvent; + float m_fAngleToEvent; AnimBlendFrameData *m_pFrames[PED_NODE_MAX]; int32 m_animGroup; int32 m_pVehicleAnim; CVector2D m_vecAnimMoveDelta; CVector m_vecOffsetSeek; CPedIK m_pedIK; - uint8 stuff1[12]; + uint8 stuff1[8]; + int32 m_nPedStateTimer; int32 m_nPedState; int32 m_nLastPedState; int32 m_nMoveState; @@ -198,7 +200,12 @@ public: CPed *m_pPedFight; float m_fLookDirection; int32 m_wepModelID; - uint8 stuff9[120]; + uint32 m_leaveCarTimer; + uint32 m_getUpTimer; + uint32 m_lookTimer; + uint8 stuff9[34]; + uint8 m_bodyPartBleeding; + uint8 stuff11[73]; static void *operator new(size_t); static void operator delete(void*, size_t); @@ -209,8 +216,17 @@ public: void AimGun(); void KillPedWithCar(CVehicle *veh, float impulse); void Say(uint16 audio); - void SetLookFlag(CEntity *to, bool set); + void SetLookFlag(CPed *to, bool set); + void SetLookFlag(float angle, bool set); + void SetDie(AnimationId anim, float arg1, float arg2); + void ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer); + void RemoveBodyPart(PedNode nodeId, char arg4); + void SpawnFlyingComponent(int, signed char); + static RwObject *SetPedAtomicVisibilityCB(RwObject *object, void *data); + static RwFrame *RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data); + CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } + RwFrame* GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; } static Bool &bNastyLimbsCheat; static Bool &bPedCheat2; @@ -223,4 +239,6 @@ static_assert(offsetof(CPed, m_nPedType) == 0x32C, "CPed: error"); static_assert(offsetof(CPed, m_pCollidingEntity) == 0x34C, "CPed: error"); static_assert(offsetof(CPed, m_weapons) == 0x35C, "CPed: error"); static_assert(offsetof(CPed, m_currentWeapon) == 0x498, "CPed: error"); +static_assert(offsetof(CPed, m_lookTimer) == 0x4CC, "CPed: error"); +static_assert(offsetof(CPed, m_bodyPartBleeding) == 0x4F2, "CPed: error"); static_assert(sizeof(CPed) == 0x53C, "CPed: error"); \ No newline at end of file -- cgit v1.2.3 From c1bd90c7ddcb28c0ba5ebe66ab90319ffeee6d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sun, 16 Jun 2019 21:39:48 +0300 Subject: CPed fixes and needed functions for further commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: eray orçunus --- src/entities/Ped.cpp | 140 +++++++++++++++++++++++++++-------------------- src/entities/Ped.h | 29 +++++++--- src/entities/PedIK.h | 2 +- src/entities/PlayerPed.h | 34 +++++++++++- 4 files changed, 136 insertions(+), 69 deletions(-) (limited to 'src/entities') diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp index 00e7ecb7..cb7d7923 100644 --- a/src/entities/Ped.cpp +++ b/src/entities/Ped.cpp @@ -2,9 +2,9 @@ #include "patcher.h" #include "Ped.h" #include "Pools.h" -#include -#include -#include +#include "Particle.h" +#include "Stats.h" +#include "World.h" Bool &CPed::bNastyLimbsCheat = *(Bool*)0x95CD44; Bool &CPed::bPedCheat2 = *(Bool*)0x95CD5A; @@ -14,7 +14,7 @@ void *CPed::operator new(size_t sz) { return CPools::GetPedPool()->New(); } void CPed::operator delete(void *p, size_t sz) { CPools::GetPedPool()->Delete((CPed*)p); } WRAPPER void CPed::KillPedWithCar(CVehicle *veh, float impulse) { EAXJMP(0x4EC430); } -WRAPPER void CPed::Say(uint16 audio) { EAXJMP(0x4E5A10); } +WRAPPER void CPed::Say(eSound audio) { EAXJMP(0x4E5A10); } WRAPPER void CPed::SetDie(AnimationId anim, float arg1, float arg2) { EAXJMP(0x4D37D0); } WRAPPER void CPed::SpawnFlyingComponent(int, signed char) { EAXJMP(0x4EB060); } @@ -201,7 +201,6 @@ CPed::AimGun() { RwV3d pos; CVector vector; - uint8 newFlag; if (m_pSeekTarget) { if (m_pSeekTarget->m_status == STATUS_PHYSICS) { @@ -210,9 +209,9 @@ CPed::AimGun() vector.y = pos.y; vector.z = pos.z; } else { - vector = *(m_pSeekTarget->GetMatrix().GetPosition()); + vector = *(m_pSeekTarget->GetPosition()); } - CPed::Say(0x74); + CPed::Say(SOUND_PED_ATTACK); m_ped_flagB2 = m_pedIK.PointGunAtPosition(&vector); if (m_pPedFight != m_pSeekTarget) { @@ -221,12 +220,10 @@ CPed::AimGun() } else { if (CPed::IsPlayer()) { - newFlag = m_pedIK.PointGunInDirection(m_fLookDirection, m_vecMoveSpeedAvg.y); + m_ped_flagB2 = m_pedIK.PointGunInDirection(m_fLookDirection, ((CPlayerPed*)this)->m_fFPSMoveHeading); } else { - newFlag = m_pedIK.PointGunInDirection(m_fLookDirection, 0.0); + m_ped_flagB2 = m_pedIK.PointGunInDirection(m_fLookDirection, 0.0f); } - - m_ped_flagB2 = newFlag; } } @@ -238,16 +235,15 @@ CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer) CVector pos2 = CVector( pos.x, pos.y, - pos.z + 0.1 + pos.z + 0.1f ); - if (!CPed::IsPlayer() || evenOnPlayer) - { + if (!CPed::IsPlayer() || evenOnPlayer) { ++CStats::HeadShots; - // yes. decompiled by hand. + // BUG: This condition will always return true. if (m_nPedState != PED_PASSENGER || m_nPedState != PED_TAXI_PASSENGER) { - CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0, 0.0); + CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); } m_ped_flagC20 = 1; @@ -255,30 +251,29 @@ CPed::ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer) CParticle::AddParticle(PARTICLE_TEST, pos2, CVector( - 0.0, - 0.0, - 0.0 + 0.0f, + 0.0f, + 0.0f ), NULL, 0.2f, 0, 0, 0, 0); - if (CEntity::GetIsOnScreen()) - { - for(int i=0; i<0x20; i++) { + if (CEntity::GetIsOnScreen()) { + for(int i=0; i < 32; i++) { CParticle::AddParticle(PARTICLE_BLOOD_SMALL, pos2, CVector( - 0.0, - 0.0, - 0.03 + 0.0f, + 0.0f, + 0.03f ), NULL, 0.0f, 0, 0, 0, 0); } - for (int i = 0; i < 0x10; i++) { + for (int i = 0; i < 16; i++) { CParticle::AddParticle(PARTICLE_DEBRIS2, pos2, CVector( - 0.0, - 0.0, - 0.0099999998 + 0.0f, + 0.0f, + 0.01f ), NULL, 0.0f, 0, 0, 0, 0); } } @@ -293,45 +288,40 @@ CPed::RemoveBodyPart(PedNode nodeId, char arg4) RwV3d zero; frame = GetNodeFrame(nodeId); - if (frame) - { - if (CGame::nastyGame) - { + if (frame) { + if (CGame::nastyGame) { if (nodeId != PED_HEAD) CPed::SpawnFlyingComponent(nodeId, arg4); RecurseFrameChildrenVisibilityCB(frame, 0); - zero.x = 0.0; - zero.z = 0.0; - zero.y = 0.0; + zero.x = 0.0f; + zero.z = 0.0f; + zero.y = 0.0f; for (fp = RwFrameGetParent(frame); fp; fp = RwFrameGetParent(frame)) RwV3dTransformPoints(&zero, &zero, 1, &fp->modelling); - if (CEntity::GetIsOnScreen()) - { + if (CEntity::GetIsOnScreen()) { CParticle::AddParticle(PARTICLE_TEST, zero, CVector( - 0.0, - 0.0, - 0.0 + 0.0f, + 0.0f, + 0.0f ), NULL, 0.2f, 0, 0, 0, 0); - for (int i = 0; i < 0x10; i++) { + for (int i = 0; i < 16; i++) { CParticle::AddParticle(PARTICLE_BLOOD_SMALL, zero, CVector( - 0.0, - 0.0, - 0.03 + 0.0f, + 0.0f, + 0.03f ), NULL, 0.0f, 0, 0, 0, 0); } } m_ped_flagC20 = 1; m_bodyPartBleeding = nodeId; } - } - else - { + } else { printf("Trying to remove ped component"); } } @@ -341,7 +331,7 @@ CPed::SetPedAtomicVisibilityCB(RwObject *object, void *data) { RwObject *result = object; if (!data) - object->flags = 0; + RpAtomicSetFlags(object, 0); return result; } @@ -357,18 +347,16 @@ CPed::RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data) void CPed::SetLookFlag(CPed *to, bool set) { - if (m_lookTimer < CTimer::GetTimeInMilliseconds()) - { + if (m_lookTimer < CTimer::GetTimeInMilliseconds()) { m_ped_flagA10 = 1; m_ped_flagA40 = 0; m_pPedFight = to; m_pPedFight->RegisterReference((CEntity**)&m_pPedFight); - m_fLookDirection = 999999; + m_fLookDirection = 999999.0f; m_lookTimer = 0; m_ped_flagA20_look = set; if (m_nPedState != PED_DRIVING) { - // Resets second right most bit - m_pedIK.m_flags &= 0xFFFFFFFD; + m_pedIK.m_flags &= ~(1 << 2); } } } @@ -376,8 +364,7 @@ CPed::SetLookFlag(CPed *to, bool set) void CPed::SetLookFlag(float angle, bool set) { - if (m_lookTimer < CTimer::GetTimeInMilliseconds()) - { + if (m_lookTimer < CTimer::GetTimeInMilliseconds()) { m_ped_flagA10 = 1; m_ped_flagA40 = 0; m_pPedFight = 0; @@ -385,12 +372,47 @@ CPed::SetLookFlag(float angle, bool set) m_lookTimer = 0; m_ped_flagA20_look = set; if (m_nPedState != PED_DRIVING) { - // Resets second right most bit - m_pedIK.m_flags &= 0xFFFFFFFD; + m_pedIK.m_flags &= ~(1 << 2); } } } +void +CPed::SetLookTimer(int time) +{ + if (CTimer::GetTimeInMilliseconds() > m_lookTimer) { + m_lookTimer = CTimer::GetTimeInMilliseconds() + time; + } +} + +bool +CPed::OurPedCanSeeThisOne(CEntity* who) +{ + float xDiff; + float yDiff; + float distance; + CColPoint colpoint; + CEntity* ent; + CVector ourPos; + CVector itsPos; + + ourPos = this->GetPosition(); + itsPos = who->GetPosition(); + + xDiff = itsPos.x - ourPos.x; + yDiff = itsPos.y - ourPos.y; + + if ((yDiff * this->GetUp().y) + (xDiff * this->GetUp().x) < 0.0f) + return 0; + + distance = sqrt(yDiff * yDiff + xDiff * xDiff); + + if (distance < 40.0f) + return 0; + + ourPos.z += 1.0f; + return CWorld::ProcessLineOfSight(ourPos, itsPos, colpoint, ent, 1, 0, 0, 0, 0, 0, 0) == 0; +} STARTPATCHES InjectHook(0x4CF8F0, &CPed::AddWeaponModel, PATCH_JUMP); @@ -399,4 +421,6 @@ STARTPATCHES InjectHook(0x4EAEE0, &CPed::RemoveBodyPart, PATCH_JUMP); InjectHook(0x4C6460, (void (CPed::*)(CPed*, bool)) &CPed::SetLookFlag, PATCH_JUMP); InjectHook(0x4C63E0, (void (CPed::*)(float, bool)) &CPed::SetLookFlag, PATCH_JUMP); + InjectHook(0x4D12E0, &CPed::SetLookTimer, PATCH_JUMP); + InjectHook(0x4C5700, &CPed::OurPedCanSeeThisOne, PATCH_JUMP); ENDPATCHES \ No newline at end of file diff --git a/src/entities/Ped.h b/src/entities/Ped.h index 2f0f67f0..dfefeddf 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -2,9 +2,12 @@ #include "Physical.h" #include "Weapon.h" +#include "PathFind.h" #include "PedIK.h" -#include -#include +#include "AnimManager.h" +#include "AnimBlendClumpData.h" +#include "PedStat.h" +#include "Sounds.h" enum { PED_MAX_WEAPONS = 13 @@ -162,7 +165,9 @@ public: uint8 m_ped_flagI20 : 1; uint8 m_ped_flagI40 : 1; uint8 m_ped_flagI80 : 1; - uint8 stuff10[60]; + uint8 stuff10[15]; + int32 m_field_16C; + uint8 stuff12[44]; int32 m_pEventEntity; float m_fAngleToEvent; AnimBlendFrameData *m_pFrames[PED_NODE_MAX]; @@ -172,7 +177,7 @@ public: CVector m_vecOffsetSeek; CPedIK m_pedIK; uint8 stuff1[8]; - int32 m_nPedStateTimer; + uint32 m_nPedStateTimer; int32 m_nPedState; int32 m_nLastPedState; int32 m_nMoveState; @@ -186,8 +191,8 @@ public: bool bInVehicle; uint8 stuff4[23]; int32 m_nPedType; - - uint8 stuff5[28]; + PedStat *m_pedStats; + uint8 stuff5[24]; CEntity *m_pCollidingEntity; uint8 stuff6[12]; CWeapon m_weapons[PED_MAX_WEAPONS]; @@ -205,7 +210,9 @@ public: uint32 m_lookTimer; uint8 stuff9[34]; uint8 m_bodyPartBleeding; - uint8 stuff11[73]; + uint8 m_field_4F3; + CPed *m_nearPeds[10]; + uint8 stuff11[32]; static void *operator new(size_t); static void operator delete(void*, size_t); @@ -215,19 +222,21 @@ public: void AddWeaponModel(int id); void AimGun(); void KillPedWithCar(CVehicle *veh, float impulse); - void Say(uint16 audio); + void Say(eSound audio); void SetLookFlag(CPed *to, bool set); void SetLookFlag(float angle, bool set); + void SetLookTimer(int time); void SetDie(AnimationId anim, float arg1, float arg2); void ApplyHeadShot(eWeaponType weaponType, CVector pos, bool evenOnPlayer); void RemoveBodyPart(PedNode nodeId, char arg4); void SpawnFlyingComponent(int, signed char); + bool OurPedCanSeeThisOne(CEntity* who); static RwObject *SetPedAtomicVisibilityCB(RwObject *object, void *data); static RwFrame *RecurseFrameChildrenVisibilityCB(RwFrame *frame, void *data); CWeapon *GetWeapon(void) { return &m_weapons[m_currentWeapon]; } RwFrame* GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; } - + static Bool &bNastyLimbsCheat; static Bool &bPedCheat2; static Bool &bPedCheat3; @@ -241,4 +250,6 @@ static_assert(offsetof(CPed, m_weapons) == 0x35C, "CPed: error"); static_assert(offsetof(CPed, m_currentWeapon) == 0x498, "CPed: error"); static_assert(offsetof(CPed, m_lookTimer) == 0x4CC, "CPed: error"); static_assert(offsetof(CPed, m_bodyPartBleeding) == 0x4F2, "CPed: error"); +static_assert(offsetof(CPed, m_field_16C) == 0x16C, "CPed: error"); +static_assert(offsetof(CPed, m_pEventEntity) == 0x19C, "CPed: error"); static_assert(sizeof(CPed) == 0x53C, "CPed: error"); \ No newline at end of file diff --git a/src/entities/PedIK.h b/src/entities/PedIK.h index 5e873bf5..ecb17777 100644 --- a/src/entities/PedIK.h +++ b/src/entities/PedIK.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common.h" struct LimbOrientation { diff --git a/src/entities/PlayerPed.h b/src/entities/PlayerPed.h index 35128f46..08892277 100644 --- a/src/entities/PlayerPed.h +++ b/src/entities/PlayerPed.h @@ -5,7 +5,39 @@ class CPlayerPed : public CPed { public: + // All credits goes to DK22Pac // 0x53C - uint8 stuff[180]; + int *m_pWanted; // CWanted * + int *m_pArrestingCop; // CCopPed *m_pArrestingCop; + float m_fMoveSpeed; + float m_fCurrentStamina; + float m_fMaxStamina; + float m_fStaminaProgress; + char m_bWeaponSlot; + uint8 m_bSpeedTimerFlag; + bool m_bShouldEvade; + char field_1367; + uint32 m_nSpeedTimer; + uint32 m_nShotDelay; + float field_1376; + char field_1380; + char field_1381; + char field_1382; + char field_1383; + CEntity *m_pEvadingFrom; + int m_nTargettableObjects[4]; + bool m_bAdrenalineActive; + bool m_bHasLockOnTarget; + char field_1406; + char field_1407; + uint32 m_bAdrenalineTime; + bool m_bCanBeDamaged; + char field_1413; + char field_1414; + char field_1415; + CVector field_1416[6]; + int field_1488[6]; + float field_1512; + float m_fFPSMoveHeading; }; static_assert(sizeof(CPlayerPed) == 0x5F0, "CPlayerPed: error"); -- cgit v1.2.3 From 18cdf53723a4455c292bb32a34a52a03f26ff675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?eray=20or=C3=A7unus?= Date: Sun, 16 Jun 2019 23:26:39 +0300 Subject: Delete duplicate enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: eray orçunus --- src/entities/Ped.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/entities') diff --git a/src/entities/Ped.h b/src/entities/Ped.h index a1f14afb..2143fa93 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -7,7 +7,7 @@ #include "AnimManager.h" #include "AnimBlendClumpData.h" #include "PedStat.h" -#include "Sounds.h" +#include "DMAudio.h" enum { PED_MAX_WEAPONS = 13 -- cgit v1.2.3