From 011aafa0435d2c60dc4e0769ed4c93ed1761e3f6 Mon Sep 17 00:00:00 2001 From: withmorten Date: Mon, 5 Jul 2021 18:07:26 +0200 Subject: finish COMPATIBLE_SAVES and FIX_INCOMPATIBLE_SAVES --- src/core/Pools.cpp | 10 +++---- src/core/Zones.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/core/config.h | 4 ++- 3 files changed, 84 insertions(+), 8 deletions(-) (limited to 'src/core') diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index 5cffe9e4..b0248664 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -281,9 +281,9 @@ INITSAVEBUF #else if ((pVehicle->IsCar() || pVehicle->IsBoat()) && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) { #endif - WriteSaveBuf(buf, pVehicle->m_vehType); - WriteSaveBuf(buf, pVehicle->GetModelIndex()); - WriteSaveBuf(buf, GetVehicleRef(pVehicle)); + WriteSaveBuf(buf, pVehicle->m_vehType); + WriteSaveBuf(buf, pVehicle->GetModelIndex()); + WriteSaveBuf(buf, GetVehicleRef(pVehicle)); pVehicle->Save(buf); } #else @@ -292,7 +292,7 @@ INITSAVEBUF #else if (pVehicle->IsCar() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) { #endif - WriteSaveBuf(buf, (uint32)pVehicle->m_vehType); + WriteSaveBuf(buf, pVehicle->m_vehType); WriteSaveBuf(buf, pVehicle->GetModelIndex()); WriteSaveBuf(buf, GetVehicleRef(pVehicle)); memcpy(buf, pVehicle, sizeof(CAutomobile)); @@ -303,7 +303,7 @@ INITSAVEBUF #else if (pVehicle->IsBoat() && pVehicle->VehicleCreatedBy == MISSION_VEHICLE) { #endif - WriteSaveBuf(buf, (uint32)pVehicle->m_vehType); + WriteSaveBuf(buf, pVehicle->m_vehType); WriteSaveBuf(buf, pVehicle->GetModelIndex()); WriteSaveBuf(buf, GetVehicleRef(pVehicle)); memcpy(buf, pVehicle, sizeof(CBoat)); diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 107b1db8..82fbc047 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -10,6 +10,14 @@ #include "Timer.h" #include "SaveBuf.h" +#ifdef COMPATIBLE_SAVES +#define ZONEARRAY_SAVE_SIZE 0xAF0 +#define MAPZONEARRAY_SAVE_SIZE 0x578 +#else +#define ZONEARRAY_SAVE_SIZE sizeof(ZoneArray) +#define MAPZONEARRAY_SAVE_SIZE sizeof(MapZoneArray) +#endif + eLevelName CTheZones::m_CurrLevel; CZone *CTheZones::m_pPlayersZone; int16 CTheZones::FindIndex; @@ -633,6 +641,28 @@ CTheZones::InitialiseAudioZoneArray(void) } } +#ifdef COMPATIBLE_SAVES +static inline void +SaveOneZone(CZone &zone, uint8 *&buffer) +{ + memcpy(buffer, zone.name, sizeof(zone.name)); + SkipSaveBuf(buffer, sizeof(zone.name)); + WriteSaveBuf(buffer, zone.minx); + WriteSaveBuf(buffer, zone.miny); + WriteSaveBuf(buffer, zone.minz); + WriteSaveBuf(buffer, zone.maxx); + WriteSaveBuf(buffer, zone.maxy); + WriteSaveBuf(buffer, zone.maxz); + WriteSaveBuf(buffer, zone.type); + WriteSaveBuf(buffer, zone.level); + WriteSaveBuf(buffer, zone.zoneinfoDay); + WriteSaveBuf(buffer, zone.zoneinfoNight); + WriteSaveBuf(buffer, (int32)CTheZones::GetIndexForZonePointer(zone.child)); + WriteSaveBuf(buffer, (int32)CTheZones::GetIndexForZonePointer(zone.parent)); + WriteSaveBuf(buffer, (int32)CTheZones::GetIndexForZonePointer(zone.next)); +} +#endif + void CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) { @@ -643,9 +673,9 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) + sizeof(int32) // GetIndexForZonePointer + sizeof(m_CurrLevel) + sizeof(FindIndex) + sizeof(int16) // padding - + sizeof(ZoneArray) + sizeof(ZoneInfoArray) + + ZONEARRAY_SAVE_SIZE + sizeof(ZoneInfoArray) + sizeof(TotalNumberOfZones) + sizeof(TotalNumberOfZoneInfos) - + sizeof(MapZoneArray) + sizeof(AudioZoneArray) + + MAPZONEARRAY_SAVE_SIZE + sizeof(AudioZoneArray) + sizeof(TotalNumberOfMapZones) + sizeof(NumberOfAudioZones); WriteSaveHeader(buffer, 'Z', 'N', 'S', '\0', *size - SAVE_HEADER_SIZE); @@ -656,10 +686,14 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) WriteSaveBuf(buffer, (int16)0); // padding for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ +#ifdef COMPATIBLE_SAVES + SaveOneZone(ZoneArray[i], buffer); +#else CZone *zone = WriteSaveBuf(buffer, ZoneArray[i]); zone->child = (CZone*)GetIndexForZonePointer(ZoneArray[i].child); zone->parent = (CZone*)GetIndexForZonePointer(ZoneArray[i].parent); zone->next = (CZone*)GetIndexForZonePointer(ZoneArray[i].next); +#endif } for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) @@ -669,7 +703,9 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) WriteSaveBuf(buffer, TotalNumberOfZoneInfos); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) { +#ifndef COMPATIBLE_SAVES CZone* zone = WriteSaveBuf(buffer, MapZoneArray[i]); +#endif /* The call of GetIndexForZonePointer is wrong, as it is @@ -679,9 +715,13 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) assert(MapZoneArray[i].child == nil); assert(MapZoneArray[i].parent == nil); assert(MapZoneArray[i].next == nil); +#ifndef COMPATIBLE_SAVES zone->child = (CZone*)GetIndexForZonePointer(MapZoneArray[i].child); zone->parent = (CZone*)GetIndexForZonePointer(MapZoneArray[i].parent); zone->next = (CZone*)GetIndexForZonePointer(MapZoneArray[i].next); +#else + SaveOneZone(MapZoneArray[i], buffer); +#endif } for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++) @@ -693,6 +733,32 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) VALIDATESAVEBUF(*size) } +#ifdef COMPATIBLE_SAVES +static inline void +LoadOneZone(CZone &zone, uint8 *&buffer) +{ + memcpy(zone.name, buffer, sizeof(zone.name)); + SkipSaveBuf(buffer, sizeof(zone.name)); + ReadSaveBuf(&zone.minx, buffer); + ReadSaveBuf(&zone.miny, buffer); + ReadSaveBuf(&zone.minz, buffer); + ReadSaveBuf(&zone.maxx, buffer); + ReadSaveBuf(&zone.maxy, buffer); + ReadSaveBuf(&zone.maxz, buffer); + ReadSaveBuf(&zone.type, buffer); + ReadSaveBuf(&zone.level, buffer); + ReadSaveBuf(&zone.zoneinfoDay, buffer); + ReadSaveBuf(&zone.zoneinfoNight, buffer); + int32 tmp; + ReadSaveBuf(&tmp, buffer); + zone.child = CTheZones::GetPointerForZoneIndex(tmp); + ReadSaveBuf(&tmp, buffer); + zone.parent = CTheZones::GetPointerForZoneIndex(tmp); + ReadSaveBuf(&tmp, buffer); + zone.next = CTheZones::GetPointerForZoneIndex(tmp); +} +#endif + void CTheZones::LoadAllZones(uint8 *buffer, uint32 size) { @@ -708,11 +774,15 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) SkipSaveBuf(buffer, 2); for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ +#ifdef COMPATIBLE_SAVES + LoadOneZone(ZoneArray[i], buffer); +#else ReadSaveBuf(&ZoneArray[i], buffer); ZoneArray[i].child = GetPointerForZoneIndex((uintptr)ZoneArray[i].child); ZoneArray[i].parent = GetPointerForZoneIndex((uintptr)ZoneArray[i].parent); ZoneArray[i].next = GetPointerForZoneIndex((uintptr)ZoneArray[i].next); +#endif } for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) @@ -722,6 +792,9 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) ReadSaveBuf(&TotalNumberOfZoneInfos, buffer); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){ +#ifdef COMPATIBLE_SAVES + LoadOneZone(MapZoneArray[i], buffer); +#else ReadSaveBuf(&MapZoneArray[i], buffer); /* @@ -732,6 +805,7 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) MapZoneArray[i].child = GetPointerForZoneIndex((uintptr)MapZoneArray[i].child); MapZoneArray[i].parent = GetPointerForZoneIndex((uintptr)MapZoneArray[i].parent); MapZoneArray[i].next = GetPointerForZoneIndex((uintptr)MapZoneArray[i].next); +#endif assert(MapZoneArray[i].child == nil); assert(MapZoneArray[i].parent == nil); assert(MapZoneArray[i].next == nil); diff --git a/src/core/config.h b/src/core/config.h index c9339b74..00d7a938 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -237,7 +237,8 @@ enum Config { #define FIX_BUGS // fixes bugs that we've came across during reversing. You can undefine this only on release builds. #define MORE_LANGUAGES // Add more translations to the game -#define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible +#define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible, and keeps saves compatible between platforms +#define FIX_INCOMPATIBLE_SAVES // try to fix incompatible saves, requires COMPATIBLE_SAVES #define LOAD_INI_SETTINGS // as the name suggests. fundamental for CUSTOM_FRONTEND_OPTIONS #define NO_MOVIES // add option to disable intro videos @@ -464,6 +465,7 @@ enum Config { #define THIS_IS_STUPID #undef MORE_LANGUAGES #undef COMPATIBLE_SAVES +#undef FIX_INCOMPATIBLE_SAVES #undef LOAD_INI_SETTINGS #undef ASPECT_RATIO_SCALE -- cgit v1.2.3