1
0
Fork 0
mirror of https://git.rip/DMCA_FUCKER/re3.git synced 2024-12-23 13:20:00 +00:00

More save/load alignment fixes

This commit is contained in:
Sergeanur 2020-05-13 16:24:00 +03:00
parent 509d57edcb
commit 3f1001b86b
3 changed files with 49 additions and 36 deletions

View file

@ -17738,23 +17738,25 @@ CPed::SetExitBoat(CVehicle *boat)
} }
#ifdef COMPATIBLE_SAVES #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 void
CPed::Save(uint8*& buf) CPed::Save(uint8*& buf)
{ {
SkipSaveBuf(buf, 52); SkipSaveBuf(buf, 52);
WriteSaveBuf<float>(buf, GetPosition().x); CopyToBuf(buf, GetPosition().x);
WriteSaveBuf<float>(buf, GetPosition().y); CopyToBuf(buf, GetPosition().y);
WriteSaveBuf<float>(buf, GetPosition().z); CopyToBuf(buf, GetPosition().z);
SkipSaveBuf(buf, 288); SkipSaveBuf(buf, 288);
WriteSaveBuf<uint8>(buf, CharCreatedBy); CopyToBuf(buf, CharCreatedBy);
SkipSaveBuf(buf, 351); SkipSaveBuf(buf, 351);
WriteSaveBuf<float>(buf, m_fHealth); CopyToBuf(buf, m_fHealth);
WriteSaveBuf<float>(buf, m_fArmour); CopyToBuf(buf, m_fArmour);
SkipSaveBuf(buf, 148); SkipSaveBuf(buf, 148);
for (int i = 0; i < 13; i++) // has to be hardcoded for (int i = 0; i < 13; i++) // has to be hardcoded
m_weapons[i].Save(buf); m_weapons[i].Save(buf);
SkipSaveBuf(buf, 5); SkipSaveBuf(buf, 5);
WriteSaveBuf<uint8>(buf, m_maxWeaponTypeAllowed); CopyToBuf(buf, m_maxWeaponTypeAllowed);
SkipSaveBuf(buf, 162); SkipSaveBuf(buf, 162);
} }
@ -17762,19 +17764,21 @@ void
CPed::Load(uint8*& buf) CPed::Load(uint8*& buf)
{ {
SkipSaveBuf(buf, 52); SkipSaveBuf(buf, 52);
GetMatrix().GetPosition().x = ReadSaveBuf<float>(buf); CopyFromBuf(buf, GetMatrix().GetPosition().x);
GetMatrix().GetPosition().y = ReadSaveBuf<float>(buf); CopyFromBuf(buf, GetMatrix().GetPosition().y);
GetMatrix().GetPosition().z = ReadSaveBuf<float>(buf); CopyFromBuf(buf, GetMatrix().GetPosition().z);
SkipSaveBuf(buf, 288); SkipSaveBuf(buf, 288);
CharCreatedBy = ReadSaveBuf<uint8>(buf); CopyFromBuf(buf, CharCreatedBy);
SkipSaveBuf(buf, 351); SkipSaveBuf(buf, 351);
m_fHealth = ReadSaveBuf<float>(buf); CopyFromBuf(buf, m_fHealth);
m_fArmour = ReadSaveBuf<float>(buf); CopyFromBuf(buf, m_fArmour);
SkipSaveBuf(buf, 148); SkipSaveBuf(buf, 148);
for (int i = 0; i < 13; i++) // has to be hardcoded for (int i = 0; i < 13; i++) // has to be hardcoded
m_weapons[i].Load(buf); m_weapons[i].Load(buf);
SkipSaveBuf(buf, 5); SkipSaveBuf(buf, 5);
m_maxWeaponTypeAllowed = ReadSaveBuf<uint8>(buf); CopyFromBuf(buf, m_maxWeaponTypeAllowed);
SkipSaveBuf(buf, 162); SkipSaveBuf(buf, 162);
} }
#undef CopyFromBuf
#undef CopyToBuf
#endif #endif

View file

@ -1513,17 +1513,19 @@ CPlayerPed::ProcessControl(void)
} }
#ifdef COMPATIBLE_SAVES #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 void
CPlayerPed::Save(uint8*& buf) CPlayerPed::Save(uint8*& buf)
{ {
CPed::Save(buf); CPed::Save(buf);
SkipSaveBuf(buf, 16); SkipSaveBuf(buf, 16);
WriteSaveBuf<float>(buf, m_fMaxStamina); CopyToBuf(buf, m_fMaxStamina);
SkipSaveBuf(buf, 28); SkipSaveBuf(buf, 28);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[0]); CopyToBuf(buf, m_nTargettableObjects[0]);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[1]); CopyToBuf(buf, m_nTargettableObjects[1]);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[2]); CopyToBuf(buf, m_nTargettableObjects[2]);
WriteSaveBuf<int32>(buf, m_nTargettableObjects[3]); CopyToBuf(buf, m_nTargettableObjects[3]);
SkipSaveBuf(buf, 116); SkipSaveBuf(buf, 116);
} }
@ -1532,12 +1534,14 @@ CPlayerPed::Load(uint8*& buf)
{ {
CPed::Load(buf); CPed::Load(buf);
SkipSaveBuf(buf, 16); SkipSaveBuf(buf, 16);
m_fMaxStamina = ReadSaveBuf<float>(buf); CopyFromBuf(buf, m_fMaxStamina);
SkipSaveBuf(buf, 28); SkipSaveBuf(buf, 28);
m_nTargettableObjects[0] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[0]);
m_nTargettableObjects[1] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[1]);
m_nTargettableObjects[2] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[2]);
m_nTargettableObjects[3] = ReadSaveBuf<int32>(buf); CopyFromBuf(buf, m_nTargettableObjects[3]);
SkipSaveBuf(buf, 116); SkipSaveBuf(buf, 116);
} }
#undef CopyFromBuf
#undef CopyToBuf
#endif #endif

View file

@ -2284,27 +2284,32 @@ CWeapon::ProcessLineOfSight(CVector const &point1, CVector const &point2, CColPo
} }
#ifdef COMPATIBLE_SAVES #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 void
CWeapon::Save(uint8*& buf) CWeapon::Save(uint8*& buf)
{ {
WriteSaveBuf<uint32>(buf, m_eWeaponType); CopyToBuf(buf, m_eWeaponType);
WriteSaveBuf<uint32>(buf, m_eWeaponState); CopyToBuf(buf, m_eWeaponState);
WriteSaveBuf<uint32>(buf, m_nAmmoInClip); CopyToBuf(buf, m_nAmmoInClip);
WriteSaveBuf<uint32>(buf, m_nAmmoTotal); CopyToBuf(buf, m_nAmmoTotal);
WriteSaveBuf<uint32>(buf, m_nTimer); CopyToBuf(buf, m_nTimer);
WriteSaveBuf<bool>(buf, m_bAddRotOffset); CopyToBuf(buf, m_bAddRotOffset);
SkipSaveBuf(buf, 3); SkipSaveBuf(buf, 3);
} }
void void
CWeapon::Load(uint8*& buf) CWeapon::Load(uint8*& buf)
{ {
m_eWeaponType = (eWeaponType)ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_eWeaponType);
m_eWeaponState = (eWeaponState)ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_eWeaponState);
m_nAmmoInClip = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_nAmmoInClip);
m_nAmmoTotal = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_nAmmoTotal);
m_nTimer = ReadSaveBuf<uint32>(buf); CopyFromBuf(buf, m_nTimer);
m_bAddRotOffset = ReadSaveBuf<bool>(buf); CopyFromBuf(buf, m_bAddRotOffset);
SkipSaveBuf(buf, 3); SkipSaveBuf(buf, 3);
} }
#undef CopyFromBuf
#undef CopyToBuf
#endif #endif