diff options
Diffstat (limited to 'src/entities')
-rw-r--r-- | src/entities/Ped.cpp | 242 | ||||
-rw-r--r-- | src/entities/Ped.h | 92 | ||||
-rw-r--r-- | src/entities/PedIK.cpp | 7 | ||||
-rw-r--r-- | src/entities/PedIK.h | 33 | ||||
-rw-r--r-- | src/entities/PlayerInfo.cpp | 3 | ||||
-rw-r--r-- | src/entities/PlayerInfo.h | 74 | ||||
-rw-r--r-- | src/entities/PlayerPed.h | 36 | ||||
-rw-r--r-- | src/entities/Vehicle.cpp | 10 | ||||
-rw-r--r-- | src/entities/Vehicle.h | 10 |
9 files changed, 479 insertions, 28 deletions
diff --git a/src/entities/Ped.cpp b/src/entities/Ped.cpp index 55e33a2d..ccb07d46 100644 --- a/src/entities/Ped.cpp +++ b/src/entities/Ped.cpp @@ -1,16 +1,24 @@ #include "common.h" #include "patcher.h" -#include "Ped.h" #include "Pools.h" +#include "Particle.h" +#include "Stats.h" +#include "World.h" +#include "PedStat.h" +#include "DMaudio.h" +#include "Ped.h" + +bool &CPed::bNastyLimbsCheat = *(bool*)0x95CD44; +bool &CPed::bPedCheat2 = *(bool*)0x95CD5A; +bool &CPed::bPedCheat3 = *(bool*)0x95CD59; -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::SetDie(AnimationId anim, float arg1, float arg2) { EAXJMP(0x4D37D0); } +WRAPPER void CPed::SpawnFlyingComponent(int, int8) { EAXJMP(0x4EB060); } static char ObjectiveText[34][28] = { "No Obj", @@ -175,3 +183,227 @@ 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, GetNodeFrame(PED_HANDR)); + RpClumpAddAtomic((RpClump*)m_rwObject, atm); + m_wepModelID = id; + } +} + +void +CPed::AimGun() +{ + RwV3d pos; + CVector vector; + + 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->GetPosition()); + } + CPed::Say(SOUND_PED_ATTACK); + + m_ped_flagB2 = m_pedIK.PointGunAtPosition(&vector); + if (m_pPedFight != m_pSeekTarget) { + CPed::SetLookFlag(m_pSeekTarget, 1); + } + + } else { + if (CPed::IsPlayer()) { + m_ped_flagB2 = m_pedIK.PointGunInDirection(m_fLookDirection, ((CPlayerPed*)this)->m_fFPSMoveHeading); + } else { + m_ped_flagB2 = m_pedIK.PointGunInDirection(m_fLookDirection, 0.0f); + } + } +} + + +// 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.1f + ); + + if (!CPed::IsPlayer() || evenOnPlayer) { + ++CStats::HeadShots; + + // BUG: This condition will always return true. + if (m_nPedState != PED_PASSENGER || m_nPedState != PED_TAXI_PASSENGER) { + CPed::SetDie(ANIM_KO_SHOT_FRONT1, 4.0f, 0.0f); + } + + m_ped_flagC20 = 1; + m_nPedStateTimer = CTimer::GetTimeInMilliseconds() + 150; + + CParticle::AddParticle(PARTICLE_TEST, pos2, + CVector(0.0f, 0.0f, 0.0f), nil, 0.2f, 0, 0, 0, 0); + + if (CEntity::GetIsOnScreen()) { + for(int i=0; i < 32; i++) { + CParticle::AddParticle(PARTICLE_BLOOD_SMALL, + pos2, CVector(0.0f, 0.0f, 0.03f), + nil, 0.0f, 0, 0, 0, 0); + } + + for (int i = 0; i < 16; i++) { + CParticle::AddParticle(PARTICLE_DEBRIS2, + pos2, + CVector(0.0f, 0.0f, 0.01f), + nil, 0.0f, 0, 0, 0, 0); + } + } + } +} + +void +CPed::RemoveBodyPart(PedNode nodeId, int8 unk) +{ + RwFrame *frame; + RwFrame *fp; + RwV3d zero; + + frame = GetNodeFrame(nodeId); + if (frame) { + if (CGame::nastyGame) { + if (nodeId != PED_HEAD) + CPed::SpawnFlyingComponent(nodeId, unk); + + RecurseFrameChildrenVisibilityCB(frame, 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()) { + CParticle::AddParticle(PARTICLE_TEST, zero, + CVector(0.0f, 0.0f, 0.0f), + nil, 0.2f, 0, 0, 0, 0); + + for (int i = 0; i < 16; i++) { + CParticle::AddParticle(PARTICLE_BLOOD_SMALL, + zero, + CVector(0.0f, 0.0f, 0.03f), + nil, 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) +{ + if (data == 0) + RpAtomicSetFlags(object, 0); + return object; +} + +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.0f; + m_lookTimer = 0; + m_ped_flagA20_look = set; + if (m_nPedState != PED_DRIVING) { + m_pedIK.m_flags &= ~CPedIK::FLAG_4; + } + } +} + +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) { + m_pedIK.m_flags &= ~CPedIK::FLAG_4; + } + } +} + +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); +} + +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); + InjectHook(0x4D12E0, &CPed::SetLookTimer, PATCH_JUMP); + InjectHook(0x4C5700, &CPed::OurPedCanSeeThisOne, PATCH_JUMP); +ENDPATCHES diff --git a/src/entities/Ped.h b/src/entities/Ped.h index adf24c88..0b0a5562 100644 --- a/src/entities/Ped.h +++ b/src/entities/Ped.h @@ -2,6 +2,12 @@ #include "Physical.h" #include "Weapon.h" +#include "PedIK.h" +#include "AnimManager.h" +#include "AnimBlendClumpData.h" + +struct PedStat; +struct CPathNode; enum { PED_MAX_WEAPONS = 13 @@ -92,7 +98,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; @@ -159,39 +165,99 @@ public: uint8 m_ped_flagI20 : 1; uint8 m_ped_flagI40 : 1; uint8 m_ped_flagI80 : 1; - uint8 stuff1[199]; + uint8 stuff10[15]; + int32 m_field_16C; + uint8 stuff12[44]; + int32 m_pEventEntity; + 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[8]; + uint32 m_nPedStateTimer; int32 m_nPedState; int32 m_nLastPedState; int32 m_nMoveState; - uint8 stuff2[188]; + int32 m_nStoredActionState; + int32 m_nPrevActionState; + int32 m_nWaitState; + int32 m_nWaitTimer; +private: + uint32 stuff0[28]; +public: + uint16 m_nPathNodes; + uint8 m_nCurPathNode; + int8 m_nPathState; +private: + int8 _pad2B5[3]; +public: + CPathNode *m_pNextPathNode; + CPathNode *m_pLastPathNode; + float m_fHealth; + float m_fArmour; + uint8 stuff2[34]; 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]; int32 m_nPedType; - - uint8 stuff5[28]; + PedStat *m_pedStats; + uint8 stuff5[24]; CEntity *m_pCollidingEntity; uint8 stuff6[12]; 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; + uint32 m_leaveCarTimer; + uint32 m_getUpTimer; + uint32 m_lookTimer; + uint8 stuff9[34]; + uint8 m_bodyPartBleeding; + uint8 m_field_4F3; + CPed *m_nearPeds[10]; + uint8 stuff11[32]; static void *operator new(size_t); static void operator delete(void*, size_t); + // TODO: enum! 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(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, int8 unknown); + void SpawnFlyingComponent(int, int8 unknown); + 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]; } - - static Bool &bNastyLimbsCheat; - static Bool &bPedCheat2; - static Bool &bPedCheat3; + RwFrame *GetNodeFrame(int nodeId) { return m_pFrames[nodeId]->frame; } + + static bool &bNastyLimbsCheat; + static bool &bPedCheat2; + static bool &bPedCheat3; }; static_assert(offsetof(CPed, m_nPedState) == 0x224, "CPed: error"); static_assert(offsetof(CPed, m_pCurSurface) == 0x2FC, "CPed: error"); @@ -200,4 +266,8 @@ 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(offsetof(CPed, m_field_16C) == 0x16C, "CPed: error"); +static_assert(offsetof(CPed, m_pEventEntity) == 0x19C, "CPed: error"); static_assert(sizeof(CPed) == 0x53C, "CPed: error"); 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..67aaa469 --- /dev/null +++ b/src/entities/PedIK.h @@ -0,0 +1,33 @@ +#pragma once +#include "common.h" + +struct LimbOrientation +{ + float phi; + float theta; +}; + +class CPed; + +class CPedIK +{ +public: + // TODO + enum { + FLAG_1, + FLAG_2, + FLAG_4, + }; + + 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"); diff --git a/src/entities/PlayerInfo.cpp b/src/entities/PlayerInfo.cpp new file mode 100644 index 00000000..796481a4 --- /dev/null +++ b/src/entities/PlayerInfo.cpp @@ -0,0 +1,3 @@ +#include "common.h" +#include "patcher.h" +#include "PlayerInfo.h" diff --git a/src/entities/PlayerInfo.h b/src/entities/PlayerInfo.h new file mode 100644 index 00000000..abda1b23 --- /dev/null +++ b/src/entities/PlayerInfo.h @@ -0,0 +1,74 @@ +#pragma once +#include "Automobile.h" +#include "PlayerPed.h" + +enum eWastedBustedState +{ + WBSTATE_PLAYING, + WBSTATE_WASTED, + WBSTATE_BUSTED, + WBSTATE_FAILED_CRITICAL_MISSION, +}; + +struct CCivilianPed +{ + +}; + +class CPlayerInfo +{ +public: + CPlayerPed *m_pPed; + CVehicle *m_pRemoteVehicle; + CColModel m_ColModel; + CVehicle *m_pVehicleEx; + char m_aszPlayerName[70]; +private: + int8 _pad0[2]; +public: + int32 m_nMoney; + int32 m_nVisibleMoney; + int32 m_nCollectedPackages; + int32 m_nTotalPackages; + int32 field_188; + int32 m_nSwitchTaxiTime; + bool m_bSwitchTaxi; + int8 field_197; + int8 field_198; + int8 field_199; + int32 m_nNextSexFrequencyUpdateTime; + int32 m_nNextSexMoneyUpdateTime; + int32 m_nSexFrequency; + CCivilianPed *m_pHooker; + int8 m_bWBState; // eWastedBustedState + int8 field_217; + int8 field_218; + int8 field_219; + int32 m_nWBTime; + bool m_bInRemoteMode; + int8 field_225; + int8 field_226; + int8 field_227; + int32 m_nTimeLostRemoteCar; + int32 m_nTimeLastHealthLoss; + int32 m_nTimeLastArmourLoss; + int32 field_240; + int32 m_nUpsideDownCounter; + int32 field_248; + int16 m_nTrafficMultiplier; + int8 field_254; + int8 field_255; + float m_fRoadDensity; + int32 m_nPreviousTimeRewardedForExplosion; + int32 m_nExplosionsSinceLastReward; + int32 field_268; + int32 field_272; + bool m_bInfiniteSprint; + bool m_bFastReload; + bool m_bGetOutOfJailFree; + bool m_bGetOutOfHospitalFree; + uint8 m_aSkinName[32]; + RwTexture *m_pSkinTexture; +}; + +static_assert(sizeof(CPlayerInfo) == 0x13C, "CPlayerPed: error"); diff --git a/src/entities/PlayerPed.h b/src/entities/PlayerPed.h index 35128f46..a41135e9 100644 --- a/src/entities/PlayerPed.h +++ b/src/entities/PlayerPed.h @@ -1,11 +1,43 @@ #pragma once #include "Ped.h" +#include "Wanted.h" class CPlayerPed : public CPed { public: - // 0x53C - uint8 stuff[180]; + CWanted *m_pWanted; + CCopPed *m_pArrestingCop; + float m_fMoveSpeed; + float m_fCurrentStamina; + float m_fMaxStamina; + float m_fStaminaProgress; + bool m_bWeaponSlot; + bool m_bSpeedTimerFlag; + bool m_bShouldEvade; + int8 field_1367; + int32 m_nSpeedTimer; + int32 m_nShotDelay; + float field_1376; + int8 field_1380; + int8 field_1381; + int8 field_1382; + int8 field_1383; + CEntity *m_pEvadingFrom; + int32 m_nTargettableObjects[4]; + bool m_bAdrenalineActive; + bool m_bHasLockOnTarget; + int8 field_1406; + int8 field_1407; + bool m_bAdrenalineTime; + bool m_bCanBeDamaged; + int8 field_1413; + int8 field_1414; + int8 field_1415; + CVector field_1416[6]; + int32 field_1488[6]; + float field_1512; + float m_fFPSMoveHeading; }; + static_assert(sizeof(CPlayerPed) == 0x5F0, "CPlayerPed: error"); diff --git a/src/entities/Vehicle.cpp b/src/entities/Vehicle.cpp index ebd7ae68..bac05f7b 100644 --- a/src/entities/Vehicle.cpp +++ b/src/entities/Vehicle.cpp @@ -3,11 +3,11 @@ #include "Vehicle.h" #include "Pools.h" -Bool &CVehicle::bWheelsOnlyCheat = *(Bool *)0x95CD78; -Bool &CVehicle::bAllDodosCheat = *(Bool *)0x95CD75; -Bool &CVehicle::bCheat3 = *(Bool *)0x95CD66; -Bool &CVehicle::bCheat4 = *(Bool *)0x95CD65; -Bool &CVehicle::bCheat5 = *(Bool *)0x95CD64; +bool &CVehicle::bWheelsOnlyCheat = *(bool *)0x95CD78; +bool &CVehicle::bAllDodosCheat = *(bool *)0x95CD75; +bool &CVehicle::bCheat3 = *(bool *)0x95CD66; +bool &CVehicle::bCheat4 = *(bool *)0x95CD65; +bool &CVehicle::bCheat5 = *(bool *)0x95CD64; void *CVehicle::operator new(size_t sz) { return CPools::GetVehiclePool()->New(); } void CVehicle::operator delete(void *p, size_t sz) { CPools::GetVehiclePool()->Delete((CVehicle*)p); } diff --git a/src/entities/Vehicle.h b/src/entities/Vehicle.h index 00126c31..e5d1cfb3 100644 --- a/src/entities/Vehicle.h +++ b/src/entities/Vehicle.h @@ -63,11 +63,11 @@ uint8 m_extra2; bool IsHeli(void) { return m_vehType == VEHICLE_TYPE_HELI; } bool IsPlane(void) { return m_vehType == VEHICLE_TYPE_PLANE; } - static Bool &bWheelsOnlyCheat; - static Bool &bAllDodosCheat; - static Bool &bCheat3; - static Bool &bCheat4; - static Bool &bCheat5; + static bool &bWheelsOnlyCheat; + static bool &bAllDodosCheat; + static bool &bCheat3; + static bool &bCheat4; + static bool &bCheat5; }; static_assert(sizeof(CVehicle) == 0x288, "CVehicle: error"); static_assert(offsetof(CVehicle, m_pCurSurface) == 0x1E0, "CVehicle: error"); |