From 3f1001b86bffe6c5de8b7c6ce047d0f2bc3472b4 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 13 May 2020 16:24:00 +0300 Subject: More save/load alignment fixes --- src/peds/Ped.cpp | 32 ++++++++++++++++++-------------- src/peds/PlayerPed.cpp | 24 ++++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) (limited to 'src/peds') diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index f4e99d4d..d261385a 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -17738,23 +17738,25 @@ CPed::SetExitBoat(CVehicle *boat) } #ifdef COMPATIBLE_SAVES +#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data)); +#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data)); void CPed::Save(uint8*& buf) { SkipSaveBuf(buf, 52); - WriteSaveBuf(buf, GetPosition().x); - WriteSaveBuf(buf, GetPosition().y); - WriteSaveBuf(buf, GetPosition().z); + CopyToBuf(buf, GetPosition().x); + CopyToBuf(buf, GetPosition().y); + CopyToBuf(buf, GetPosition().z); SkipSaveBuf(buf, 288); - WriteSaveBuf(buf, CharCreatedBy); + CopyToBuf(buf, CharCreatedBy); SkipSaveBuf(buf, 351); - WriteSaveBuf(buf, m_fHealth); - WriteSaveBuf(buf, m_fArmour); + CopyToBuf(buf, m_fHealth); + CopyToBuf(buf, m_fArmour); SkipSaveBuf(buf, 148); for (int i = 0; i < 13; i++) // has to be hardcoded m_weapons[i].Save(buf); SkipSaveBuf(buf, 5); - WriteSaveBuf(buf, m_maxWeaponTypeAllowed); + CopyToBuf(buf, m_maxWeaponTypeAllowed); SkipSaveBuf(buf, 162); } @@ -17762,19 +17764,21 @@ void CPed::Load(uint8*& buf) { SkipSaveBuf(buf, 52); - GetMatrix().GetPosition().x = ReadSaveBuf(buf); - GetMatrix().GetPosition().y = ReadSaveBuf(buf); - GetMatrix().GetPosition().z = ReadSaveBuf(buf); + CopyFromBuf(buf, GetMatrix().GetPosition().x); + CopyFromBuf(buf, GetMatrix().GetPosition().y); + CopyFromBuf(buf, GetMatrix().GetPosition().z); SkipSaveBuf(buf, 288); - CharCreatedBy = ReadSaveBuf(buf); + CopyFromBuf(buf, CharCreatedBy); SkipSaveBuf(buf, 351); - m_fHealth = ReadSaveBuf(buf); - m_fArmour = ReadSaveBuf(buf); + CopyFromBuf(buf, m_fHealth); + CopyFromBuf(buf, m_fArmour); SkipSaveBuf(buf, 148); for (int i = 0; i < 13; i++) // has to be hardcoded m_weapons[i].Load(buf); SkipSaveBuf(buf, 5); - m_maxWeaponTypeAllowed = ReadSaveBuf(buf); + CopyFromBuf(buf, m_maxWeaponTypeAllowed); SkipSaveBuf(buf, 162); } +#undef CopyFromBuf +#undef CopyToBuf #endif diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index 92e3d358..3c6fad57 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -1513,17 +1513,19 @@ CPlayerPed::ProcessControl(void) } #ifdef COMPATIBLE_SAVES +#define CopyFromBuf(buf, data) memcpy(&data, buf, sizeof(data)); SkipSaveBuf(buf, sizeof(data)); +#define CopyToBuf(buf, data) memcpy(buf, &data, sizeof(data)); SkipSaveBuf(buf, sizeof(data)); void CPlayerPed::Save(uint8*& buf) { CPed::Save(buf); SkipSaveBuf(buf, 16); - WriteSaveBuf(buf, m_fMaxStamina); + CopyToBuf(buf, m_fMaxStamina); SkipSaveBuf(buf, 28); - WriteSaveBuf(buf, m_nTargettableObjects[0]); - WriteSaveBuf(buf, m_nTargettableObjects[1]); - WriteSaveBuf(buf, m_nTargettableObjects[2]); - WriteSaveBuf(buf, m_nTargettableObjects[3]); + CopyToBuf(buf, m_nTargettableObjects[0]); + CopyToBuf(buf, m_nTargettableObjects[1]); + CopyToBuf(buf, m_nTargettableObjects[2]); + CopyToBuf(buf, m_nTargettableObjects[3]); SkipSaveBuf(buf, 116); } @@ -1532,12 +1534,14 @@ CPlayerPed::Load(uint8*& buf) { CPed::Load(buf); SkipSaveBuf(buf, 16); - m_fMaxStamina = ReadSaveBuf(buf); + CopyFromBuf(buf, m_fMaxStamina); SkipSaveBuf(buf, 28); - m_nTargettableObjects[0] = ReadSaveBuf(buf); - m_nTargettableObjects[1] = ReadSaveBuf(buf); - m_nTargettableObjects[2] = ReadSaveBuf(buf); - m_nTargettableObjects[3] = ReadSaveBuf(buf); + CopyFromBuf(buf, m_nTargettableObjects[0]); + CopyFromBuf(buf, m_nTargettableObjects[1]); + CopyFromBuf(buf, m_nTargettableObjects[2]); + CopyFromBuf(buf, m_nTargettableObjects[3]); SkipSaveBuf(buf, 116); } +#undef CopyFromBuf +#undef CopyToBuf #endif -- cgit v1.2.3 From 9d4d83db0d9b9bd2921972a030a0c53566688fbb Mon Sep 17 00:00:00 2001 From: Nikolay Korolev Date: Thu, 14 May 2020 14:01:24 +0300 Subject: some fixes --- src/peds/Ped.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/peds') diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index d261385a..fd8fd540 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -16166,7 +16166,11 @@ CPed::SeekCar(void) } if (dest.x == 0.0f && dest.y == 0.0f) { +#ifdef FIX_BUGS + if ((!IsPlayer() && CharCreatedBy != MISSION_CHAR) || vehToSeek->VehicleCreatedBy != MISSION_VEHICLE || vehToSeek->pDriver || !vehToSeek->CanPedOpenLocks(this)) { +#else if ((!IsPlayer() && CharCreatedBy != MISSION_CHAR) || vehToSeek->VehicleCreatedBy != MISSION_VEHICLE || vehToSeek->pDriver) { +#endif RestorePreviousState(); if (IsPlayer()) { ClearObjective(); -- cgit v1.2.3 From c21061a1998772ed9cde2e5f473966c5efd46cf4 Mon Sep 17 00:00:00 2001 From: aap Date: Thu, 14 May 2020 14:29:26 +0200 Subject: fixed RotateTorso --- src/peds/PedIK.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/peds') diff --git a/src/peds/PedIK.cpp b/src/peds/PedIK.cpp index c9428cb3..ae9a85b4 100644 --- a/src/peds/PedIK.cpp +++ b/src/peds/PedIK.cpp @@ -64,8 +64,8 @@ CPedIK::RotateTorso(AnimBlendFrameData *node, LimbOrientation *limb, bool change // We can't get the parent matrix of an hanim frame but // this function is always called with PED_MID, so we know the parent frame. // Trouble is that PED_MID is "Smid" on PS2/PC but BONE_torso on mobile/xbox... - // so this doesn't exactly do what we'd like anyway - RwMatrix *mat = GetComponentMatrix(m_ped, PED_MID); + // Assuming BONE_torso, the parent is BONE_mid, so let's use that: + RwMatrix *mat = GetBoneMatrix(m_ped, BONE_mid); RwV3d vec1, vec2; vec1.x = mat->right.z; -- cgit v1.2.3