Revert "Redo ReadSaveBuf + common.h cleanup"

This reverts commit 2b67aba94c.
This commit is contained in:
erorcun 2021-06-26 00:25:59 +03:00
parent 4bab6d5356
commit af7573ddbe
26 changed files with 337 additions and 398 deletions

View File

@ -3,7 +3,6 @@
#include "AudioScriptObject.h" #include "AudioScriptObject.h"
#include "Pools.h" #include "Pools.h"
#include "DMAudio.h" #include "DMAudio.h"
#include "SaveBuf.h"
cAudioScriptObject::cAudioScriptObject() cAudioScriptObject::cAudioScriptObject()
{ {
@ -54,14 +53,12 @@ cAudioScriptObject::LoadAllAudioScriptObjects(uint8 *buf, uint32 size)
CheckSaveHeader(buf, 'A', 'U', 'D', '\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buf, 'A', 'U', 'D', '\0', size - SAVE_HEADER_SIZE);
int32 pool_size; int32 pool_size = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&pool_size, buf);
for (int32 i = 0; i < pool_size; i++) { for (int32 i = 0; i < pool_size; i++) {
int32 handle; int handle = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&handle, buf);
cAudioScriptObject *p = new(handle) cAudioScriptObject; cAudioScriptObject *p = new(handle) cAudioScriptObject;
assert(p != nil); assert(p != nil);
ReadSaveBuf(p, buf); *p = ReadSaveBuf<cAudioScriptObject>(buf);
p->AudioEntity = DMAudio.CreateLoopingScriptObject(p); p->AudioEntity = DMAudio.CreateLoopingScriptObject(p);
} }

View File

@ -5,7 +5,6 @@
#include "CarCtrl.h" #include "CarCtrl.h"
#include "Curves.h" #include "Curves.h"
#include "PathFind.h" #include "PathFind.h"
#include "SaveBuf.h"
void CAutoPilot::ModifySpeed(float speed) void CAutoPilot::ModifySpeed(float speed)
{ {
@ -89,40 +88,39 @@ void CAutoPilot::Save(uint8*& buf)
void CAutoPilot::Load(uint8*& buf) void CAutoPilot::Load(uint8*& buf)
{ {
ReadSaveBuf(&m_nCurrentRouteNode, buf); m_nCurrentRouteNode = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&m_nNextRouteNode, buf); m_nNextRouteNode = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&m_nPrevRouteNode, buf); m_nPrevRouteNode = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&m_nTimeEnteredCurve, buf); m_nTimeEnteredCurve = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&m_nTimeToSpendOnCurrentCurve, buf); m_nTimeToSpendOnCurrentCurve = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&m_nCurrentPathNodeInfo, buf); m_nCurrentPathNodeInfo = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nNextPathNodeInfo, buf); m_nNextPathNodeInfo = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nPreviousPathNodeInfo, buf); m_nPreviousPathNodeInfo = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nAntiReverseTimer, buf); m_nAntiReverseTimer = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nTimeToStartMission, buf); m_nTimeToStartMission = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nPreviousDirection, buf); m_nPreviousDirection = ReadSaveBuf<int8>(buf);
ReadSaveBuf(&m_nCurrentDirection, buf); m_nCurrentDirection = ReadSaveBuf<int8>(buf);
ReadSaveBuf(&m_nNextDirection, buf); m_nNextDirection = ReadSaveBuf<int8>(buf);
ReadSaveBuf(&m_nCurrentLane, buf); m_nCurrentLane = ReadSaveBuf<int8>(buf);
ReadSaveBuf(&m_nNextLane, buf); m_nNextLane = ReadSaveBuf<int8>(buf);
ReadSaveBuf(&m_nDrivingStyle, buf); m_nDrivingStyle = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&m_nCarMission, buf); m_nCarMission = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&m_nTempAction, buf); m_nTempAction = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&m_nTimeTempAction, buf); m_nTimeTempAction = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_fMaxTrafficSpeed, buf); m_fMaxTrafficSpeed = ReadSaveBuf<float>(buf);
ReadSaveBuf(&m_nCruiseSpeed, buf); m_nCruiseSpeed = ReadSaveBuf<uint8>(buf);
uint8 flags; uint8 flags = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&flags, buf);
m_bSlowedDownBecauseOfCars = !!(flags & BIT(0)); m_bSlowedDownBecauseOfCars = !!(flags & BIT(0));
m_bSlowedDownBecauseOfPeds = !!(flags & BIT(1)); m_bSlowedDownBecauseOfPeds = !!(flags & BIT(1));
m_bStayInCurrentLevel = !!(flags & BIT(2)); m_bStayInCurrentLevel = !!(flags & BIT(2));
m_bStayInFastLane = !!(flags & BIT(3)); m_bStayInFastLane = !!(flags & BIT(3));
m_bIgnorePathfinding = !!(flags & BIT(4)); m_bIgnorePathfinding = !!(flags & BIT(4));
SkipSaveBuf(buf, 2); SkipSaveBuf(buf, 2);
ReadSaveBuf(&m_vecDestinationCoors.x, buf); m_vecDestinationCoors.x = ReadSaveBuf<float>(buf);
ReadSaveBuf(&m_vecDestinationCoors.y, buf); m_vecDestinationCoors.y = ReadSaveBuf<float>(buf);
ReadSaveBuf(&m_vecDestinationCoors.z, buf); m_vecDestinationCoors.z = ReadSaveBuf<float>(buf);
SkipSaveBuf(buf, 32); SkipSaveBuf(buf, 32);
ReadSaveBuf(&m_nPathFindNodesCount, buf); m_nPathFindNodesCount = ReadSaveBuf<int16>(buf);
SkipSaveBuf(buf, 6); SkipSaveBuf(buf, 6);
} }
#endif #endif

View File

@ -24,7 +24,6 @@
#include "Vehicle.h" #include "Vehicle.h"
#include "Wanted.h" #include "Wanted.h"
#include "World.h" #include "World.h"
#include "SaveBuf.h"
#define CRUSHER_GARAGE_X1 (1135.5f) #define CRUSHER_GARAGE_X1 (1135.5f)
#define CRUSHER_GARAGE_Y1 (57.0f) #define CRUSHER_GARAGE_Y1 (57.0f)
@ -2362,25 +2361,22 @@ void CGarages::Load(uint8* buf, uint32 size)
assert(size == 5484); assert(size == 5484);
#endif #endif
CloseHideOutGaragesBeforeSave(); CloseHideOutGaragesBeforeSave();
ReadSaveBuf(&NumGarages, buf); NumGarages = ReadSaveBuf<uint32>(buf);
int32 tempInt; BombsAreFree = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&tempInt, buf); RespraysAreFree = ReadSaveBuf<uint32>(buf);
BombsAreFree = tempInt ? true : false; CarsCollected = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&tempInt, buf); BankVansCollected = ReadSaveBuf<int32>(buf);
RespraysAreFree = tempInt ? true : false; PoliceCarsCollected = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&CarsCollected, buf);
ReadSaveBuf(&BankVansCollected, buf);
ReadSaveBuf(&PoliceCarsCollected, buf);
for (int i = 0; i < TOTAL_COLLECTCARS_GARAGES; i++) for (int i = 0; i < TOTAL_COLLECTCARS_GARAGES; i++)
ReadSaveBuf(&CarTypesCollected[i], buf); CarTypesCollected[i] = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&LastTimeHelpMessage, buf); LastTimeHelpMessage = ReadSaveBuf<uint32>(buf);
for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++) { for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++) {
ReadSaveBuf(&aCarsInSafeHouse1[i], buf); aCarsInSafeHouse1[i] = ReadSaveBuf<CStoredCar>(buf);
ReadSaveBuf(&aCarsInSafeHouse2[i], buf); aCarsInSafeHouse2[i] = ReadSaveBuf<CStoredCar>(buf);
ReadSaveBuf(&aCarsInSafeHouse3[i], buf); aCarsInSafeHouse3[i] = ReadSaveBuf<CStoredCar>(buf);
} }
for (int i = 0; i < NUM_GARAGES; i++) { for (int i = 0; i < NUM_GARAGES; i++) {
ReadSaveBuf(&aGarages[i], buf); aGarages[i] = ReadSaveBuf<CGarage>(buf);
aGarages[i].m_pDoor1 = nil; aGarages[i].m_pDoor1 = nil;
aGarages[i].m_pDoor2 = nil; aGarages[i].m_pDoor2 = nil;
aGarages[i].m_pTarget = nil; aGarages[i].m_pTarget = nil;

View File

@ -13,7 +13,6 @@
#include "RpAnimBlend.h" #include "RpAnimBlend.h"
#include "AnimBlendAssociation.h" #include "AnimBlendAssociation.h"
#include "soundlist.h" #include "soundlist.h"
#include "SaveBuf.h"
#ifdef FIX_BUGS #ifdef FIX_BUGS
#include "Replay.h" #include "Replay.h"
#endif #endif
@ -213,9 +212,8 @@ void
CPhoneInfo::Load(uint8 *buf, uint32 size) CPhoneInfo::Load(uint8 *buf, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
int32 max, scriptPhonesMax; int max = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&max, buf); int scriptPhonesMax = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&scriptPhonesMax, buf);
#ifdef PEDS_REPORT_CRIMES_ON_PHONE #ifdef PEDS_REPORT_CRIMES_ON_PHONE
m_nMax = Min(NUMPHONES, max); m_nMax = Min(NUMPHONES, max);
@ -225,8 +223,7 @@ INITSAVEBUF
// We can do it without touching saves. We'll only load script phones, others are already loaded in Initialise // We can do it without touching saves. We'll only load script phones, others are already loaded in Initialise
for (int i = 0; i < 50; i++) { for (int i = 0; i < 50; i++) {
CPhone phoneToLoad; CPhone phoneToLoad = ReadSaveBuf<CPhone>(buf);
ReadSaveBuf(&phoneToLoad, buf);
if (ignoreOtherPhones) if (ignoreOtherPhones)
continue; continue;
@ -252,7 +249,7 @@ INITSAVEBUF
m_nScriptPhonesMax = scriptPhonesMax; m_nScriptPhonesMax = scriptPhonesMax;
for (int i = 0; i < NUMPHONES; i++) { for (int i = 0; i < NUMPHONES; i++) {
ReadSaveBuf(&m_aPhones[i], buf); m_aPhones[i] = ReadSaveBuf<CPhone>(buf);
// It's saved as building pool index in save file, convert it to true entity // It's saved as building pool index in save file, convert it to true entity
if (m_aPhones[i].m_pEntity) { if (m_aPhones[i].m_pEntity) {
m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1); m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1);

View File

@ -23,7 +23,6 @@
#ifdef FIX_BUGS #ifdef FIX_BUGS
#include "Replay.h" #include "Replay.h"
#endif #endif
#include "SaveBuf.h"
#include "Script.h" #include "Script.h"
#include "Shadows.h" #include "Shadows.h"
#include "SpecialFX.h" #include "SpecialFX.h"
@ -1000,18 +999,18 @@ CPickups::Load(uint8 *buf, uint32 size)
INITSAVEBUF INITSAVEBUF
for (int32 i = 0; i < NUMPICKUPS; i++) { for (int32 i = 0; i < NUMPICKUPS; i++) {
ReadSaveBuf(&aPickUps[i], buf); aPickUps[i] = ReadSaveBuf<CPickup>(buf);
if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].m_pObject != nil) if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].m_pObject != nil)
aPickUps[i].m_pObject = CPools::GetObjectPool()->GetSlot((uintptr)aPickUps[i].m_pObject - 1); aPickUps[i].m_pObject = CPools::GetObjectPool()->GetSlot((uintptr)aPickUps[i].m_pObject - 1);
} }
ReadSaveBuf(&CollectedPickUpIndex, buf); CollectedPickUpIndex = ReadSaveBuf<uint16>(buf);
SkipSaveBuf(buf, 2); ReadSaveBuf<uint16>(buf);
NumMessages = 0; NumMessages = 0;
for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++) for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++)
ReadSaveBuf(&aPickUpsCollected[i], buf); aPickUpsCollected[i] = ReadSaveBuf<int32>(buf);
VALIDATESAVEBUF(size) VALIDATESAVEBUF(size)
} }

View File

@ -1,7 +1,6 @@
#include "common.h" #include "common.h"
#include "Restart.h" #include "Restart.h"
#include "SaveBuf.h"
#include "Zones.h" #include "Zones.h"
#include "PathFind.h" #include "PathFind.h"
@ -174,28 +173,29 @@ INITSAVEBUF
CheckSaveHeader(buf, 'R','S','T','\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buf, 'R','S','T','\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUM_RESTART_POINTS; i++) { for (int i = 0; i < NUM_RESTART_POINTS; i++) {
ReadSaveBuf(&HospitalRestartPoints[i], buf); HospitalRestartPoints[i] = ReadSaveBuf<CVector>(buf);
ReadSaveBuf(&HospitalRestartHeadings[i], buf); HospitalRestartHeadings[i] = ReadSaveBuf<float>(buf);
} }
for (int i = 0; i < NUM_RESTART_POINTS; i++) { for (int i = 0; i < NUM_RESTART_POINTS; i++) {
ReadSaveBuf(&PoliceRestartPoints[i], buf); PoliceRestartPoints[i] = ReadSaveBuf<CVector>(buf);
ReadSaveBuf(&PoliceRestartHeadings[i], buf); PoliceRestartHeadings[i] = ReadSaveBuf<float>(buf);
} }
ReadSaveBuf(&NumberOfHospitalRestarts, buf); NumberOfHospitalRestarts = ReadSaveBuf<uint16>(buf);
ReadSaveBuf(&NumberOfPoliceRestarts, buf); NumberOfPoliceRestarts = ReadSaveBuf<uint16>(buf);
ReadSaveBuf(&bOverrideRestart, buf); bOverrideRestart = ReadSaveBuf<bool>(buf);
// skip something unused // skip something unused
SkipSaveBuf(buf, 3); ReadSaveBuf<uint8>(buf);
ReadSaveBuf<uint16>(buf);
ReadSaveBuf(&OverridePosition, buf); OverridePosition = ReadSaveBuf<CVector>(buf);
ReadSaveBuf(&OverrideHeading, buf); OverrideHeading = ReadSaveBuf<float>(buf);
ReadSaveBuf(&bFadeInAfterNextDeath, buf); bFadeInAfterNextDeath = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&bFadeInAfterNextArrest, buf); bFadeInAfterNextArrest = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&OverrideHospitalLevel, buf); OverrideHospitalLevel = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&OverridePoliceStationLevel, buf); OverridePoliceStationLevel = ReadSaveBuf<uint8>(buf);
VALIDATESAVEBUF(size); VALIDATESAVEBUF(size);
} }

View File

@ -12,7 +12,6 @@
#include "Pools.h" #include "Pools.h"
#include "Population.h" #include "Population.h"
#include "RpAnimBlend.h" #include "RpAnimBlend.h"
#include "SaveBuf.h"
#include "Shadows.h" #include "Shadows.h"
#include "SpecialFX.h" #include "SpecialFX.h"
#include "World.h" #include "World.h"
@ -2003,25 +2002,21 @@ void CTheScripts::LoadAllScripts(uint8* buf, uint32 size)
Init(); Init();
INITSAVEBUF INITSAVEBUF
CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE);
uint32 varSpace, type, handle; uint32 varSpace = ReadSaveBuf<uint32>(buf);
uint32 tmp;
ReadSaveBuf(&varSpace, buf);
for (uint32 i = 0; i < varSpace; i++) for (uint32 i = 0; i < varSpace; i++)
ReadSaveBuf(&ScriptSpace[i], buf); ScriptSpace[i] = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&tmp, buf); script_assert(ReadSaveBuf<uint32>(buf) == SCRIPT_DATA_SIZE);
script_assert(tmp == SCRIPT_DATA_SIZE); OnAMissionFlag = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&OnAMissionFlag, buf);
for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) { for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) {
ReadSaveBuf(&OnAMissionForContactFlag[i], buf); OnAMissionForContactFlag[i] = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&BaseBriefIdForContact[i], buf); BaseBriefIdForContact[i] = ReadSaveBuf<uint32>(buf);
} }
for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++) for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++)
ReadSaveBuf(&CollectiveArray[i], buf); CollectiveArray[i] = ReadSaveBuf<tCollectiveData>(buf);
ReadSaveBuf(&NextFreeCollectiveIndex, buf); NextFreeCollectiveIndex = ReadSaveBuf<uint32>(buf);
for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) { for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) {
ReadSaveBuf(&type, buf); uint32 type = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&handle, buf); uint32 handle = ReadSaveBuf<uint32>(buf);
switch (type) { switch (type) {
case 0: case 0:
BuildingSwapArray[i].m_pBuilding = nil; BuildingSwapArray[i].m_pBuilding = nil;
@ -2035,14 +2030,14 @@ INITSAVEBUF
default: default:
script_assert(false); script_assert(false);
} }
ReadSaveBuf(&BuildingSwapArray[i].m_nNewModel, buf); BuildingSwapArray[i].m_nNewModel = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&BuildingSwapArray[i].m_nOldModel, buf); BuildingSwapArray[i].m_nOldModel = ReadSaveBuf<uint32>(buf);
if (BuildingSwapArray[i].m_pBuilding) if (BuildingSwapArray[i].m_pBuilding)
BuildingSwapArray[i].m_pBuilding->ReplaceWithNewModel(BuildingSwapArray[i].m_nNewModel); BuildingSwapArray[i].m_pBuilding->ReplaceWithNewModel(BuildingSwapArray[i].m_nNewModel);
} }
for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) { for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) {
ReadSaveBuf(&type, buf); uint32 type = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&handle, buf); uint32 handle = ReadSaveBuf<uint32>(buf);
switch (type) { switch (type) {
case 0: case 0:
InvisibilitySettingArray[i] = nil; InvisibilitySettingArray[i] = nil;
@ -2065,20 +2060,14 @@ INITSAVEBUF
if (InvisibilitySettingArray[i]) if (InvisibilitySettingArray[i])
InvisibilitySettingArray[i]->bIsVisible = false; InvisibilitySettingArray[i]->bIsVisible = false;
} }
bool tmpBool; script_assert(ReadSaveBuf<bool>(buf) == bUsingAMultiScriptFile);
ReadSaveBuf(&tmpBool, buf); ReadSaveBuf<uint8>(buf);
script_assert(tmpBool == bUsingAMultiScriptFile); ReadSaveBuf<uint16>(buf);
SkipSaveBuf(buf, 3); script_assert(ReadSaveBuf<uint32>(buf) == MainScriptSize);
ReadSaveBuf(&tmp, buf); script_assert(ReadSaveBuf<uint32>(buf) == LargestMissionScriptSize);
script_assert(tmp == MainScriptSize); script_assert(ReadSaveBuf<uint16>(buf) == NumberOfMissionScripts);
ReadSaveBuf(&tmp, buf); ReadSaveBuf<uint16>(buf);
script_assert(tmp == LargestMissionScriptSize); uint32 runningScripts = ReadSaveBuf<uint32>(buf);
uint16 tmp16;
ReadSaveBuf(&tmp16, buf);
script_assert(tmp16 == NumberOfMissionScripts);
SkipSaveBuf(buf, 2);
uint32 runningScripts;
ReadSaveBuf(&runningScripts, buf);
for (uint32 i = 0; i < runningScripts; i++) for (uint32 i = 0; i < runningScripts; i++)
StartNewScript(0)->Load(buf); StartNewScript(0)->Load(buf);
VALIDATESAVEBUF(size) VALIDATESAVEBUF(size)
@ -2126,35 +2115,35 @@ void CRunningScript::Load(uint8*& buf)
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
SkipSaveBuf(buf, 8); SkipSaveBuf(buf, 8);
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
ReadSaveBuf(&m_abScriptName[i], buf); m_abScriptName[i] = ReadSaveBuf<char>(buf);
ReadSaveBuf(&m_nIp, buf); m_nIp = ReadSaveBuf<uint32>(buf);
#ifdef CHECK_STRUCT_SIZES #ifdef CHECK_STRUCT_SIZES
static_assert(MAX_STACK_DEPTH == 6, "Compatibility loss: MAX_STACK_DEPTH != 6"); static_assert(MAX_STACK_DEPTH == 6, "Compatibility loss: MAX_STACK_DEPTH != 6");
#endif #endif
for (int i = 0; i < MAX_STACK_DEPTH; i++) for (int i = 0; i < MAX_STACK_DEPTH; i++)
ReadSaveBuf(&m_anStack[i], buf); m_anStack[i] = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nStackPointer, buf); m_nStackPointer = ReadSaveBuf<uint16>(buf);
SkipSaveBuf(buf, 2); SkipSaveBuf(buf, 2);
#ifdef CHECK_STRUCT_SIZES #ifdef CHECK_STRUCT_SIZES
static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18"); static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18");
#endif #endif
for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++) for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++)
ReadSaveBuf(&m_anLocalVariables[i], buf); m_anLocalVariables[i] = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&m_bCondResult, buf); m_bCondResult = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&m_bIsMissionScript, buf); m_bIsMissionScript = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&m_bSkipWakeTime, buf); m_bSkipWakeTime = ReadSaveBuf<bool>(buf);
SkipSaveBuf(buf, 1); SkipSaveBuf(buf, 1);
ReadSaveBuf(&m_nWakeTime, buf); m_nWakeTime = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&m_nAndOrState, buf); m_nAndOrState = ReadSaveBuf<uint16>(buf);
ReadSaveBuf(&m_bNotFlag, buf); m_bNotFlag = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&m_bDeatharrestEnabled, buf); m_bDeatharrestEnabled = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&m_bDeatharrestExecuted, buf); m_bDeatharrestExecuted = ReadSaveBuf<bool>(buf);
ReadSaveBuf(&m_bMissionFlag, buf); m_bMissionFlag = ReadSaveBuf<bool>(buf);
SkipSaveBuf(buf, 2); SkipSaveBuf(buf, 2);
#else #else
CRunningScript* n = next; CRunningScript* n = next;
CRunningScript* p = prev; CRunningScript* p = prev;
ReadSaveBuf(this, buf); *this = ReadSaveBuf<CRunningScript>(buf);
next = n; next = n;
prev = p; prev = p;
#endif #endif

View File

@ -9,7 +9,6 @@
#endif #endif
#include "Population.h" #include "Population.h"
#include "ProjectileInfo.h" #include "ProjectileInfo.h"
#include "SaveBuf.h"
#include "Streaming.h" #include "Streaming.h"
#include "Wanted.h" #include "Wanted.h"
#include "World.h" #include "World.h"
@ -131,19 +130,14 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot)
void CPools::LoadVehiclePool(uint8* buf, uint32 size) void CPools::LoadVehiclePool(uint8* buf, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
int nNumCars, nNumBoats; int nNumCars = ReadSaveBuf<int>(buf);
ReadSaveBuf(&nNumCars, buf); int nNumBoats = ReadSaveBuf<int>(buf);
ReadSaveBuf(&nNumBoats, buf);
for (int i = 0; i < nNumCars + nNumBoats; i++) { for (int i = 0; i < nNumCars + nNumBoats; i++) {
uint32 type; uint32 type = ReadSaveBuf<uint32>(buf);
int16 model; int16 model = ReadSaveBuf<int16>(buf);
int32 slot;
ReadSaveBuf(&type, buf);
ReadSaveBuf(&model, buf);
CStreaming::RequestModel(model, STREAMFLAGS_DEPENDENCY); CStreaming::RequestModel(model, STREAMFLAGS_DEPENDENCY);
CStreaming::LoadAllRequestedModels(false); CStreaming::LoadAllRequestedModels(false);
ReadSaveBuf(&slot, buf); int32 slot = ReadSaveBuf<int32>(buf);
CVehicle* pVehicle; CVehicle* pVehicle;
#ifdef COMPATIBLE_SAVES #ifdef COMPATIBLE_SAVES
if (type == VEHICLE_TYPE_BOAT) if (type == VEHICLE_TYPE_BOAT)

View File

@ -16,7 +16,6 @@
#include "Script.h" #include "Script.h"
#include "TxdStore.h" #include "TxdStore.h"
#include "World.h" #include "World.h"
#include "SaveBuf.h"
#include "Streaming.h" #include "Streaming.h"
#include "SpecialFX.h" #include "SpecialFX.h"
@ -1056,7 +1055,7 @@ INITSAVEBUF
CheckSaveHeader(buf, 'R', 'D', 'R', '\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buf, 'R', 'D', 'R', '\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUMRADARBLIPS; i++) for (int i = 0; i < NUMRADARBLIPS; i++)
ReadSaveBuf(&ms_RadarTrace[i], buf); ms_RadarTrace[i] = ReadSaveBuf<sRadarTrace>(buf);
VALIDATESAVEBUF(size); VALIDATESAVEBUF(size);
} }

View File

@ -8,7 +8,6 @@
#include "Text.h" #include "Text.h"
#include "World.h" #include "World.h"
#include "Timer.h" #include "Timer.h"
#include "SaveBuf.h"
eLevelName CTheZones::m_CurrLevel; eLevelName CTheZones::m_CurrLevel;
CZone *CTheZones::m_pPlayersZone; CZone *CTheZones::m_pPlayersZone;
@ -697,18 +696,17 @@ void
CTheZones::LoadAllZones(uint8 *buffer, uint32 size) CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
int32 i; int i;
CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE);
ReadSaveBuf(&i, buffer); m_pPlayersZone = GetPointerForZoneIndex(ReadSaveBuf<int32>(buffer));
m_pPlayersZone = GetPointerForZoneIndex(i); m_CurrLevel = ReadSaveBuf<eLevelName>(buffer);
ReadSaveBuf(&m_CurrLevel, buffer); FindIndex = ReadSaveBuf<int16>(buffer);
ReadSaveBuf(&FindIndex, buffer); ReadSaveBuf<int16>(buffer);
SkipSaveBuf(buffer, 2);
for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){
ReadSaveBuf(&ZoneArray[i], buffer); ZoneArray[i] = ReadSaveBuf<CZone>(buffer);
ZoneArray[i].child = GetPointerForZoneIndex((uintptr)ZoneArray[i].child); ZoneArray[i].child = GetPointerForZoneIndex((uintptr)ZoneArray[i].child);
ZoneArray[i].parent = GetPointerForZoneIndex((uintptr)ZoneArray[i].parent); ZoneArray[i].parent = GetPointerForZoneIndex((uintptr)ZoneArray[i].parent);
@ -716,13 +714,13 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
} }
for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++)
ReadSaveBuf(&ZoneInfoArray[i], buffer); ZoneInfoArray[i] = ReadSaveBuf<CZoneInfo>(buffer);
ReadSaveBuf(&TotalNumberOfZones, buffer); TotalNumberOfZones = ReadSaveBuf<int16>(buffer);
ReadSaveBuf(&TotalNumberOfZoneInfos, buffer); TotalNumberOfZoneInfos = ReadSaveBuf<int16>(buffer);
for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){ for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){
ReadSaveBuf(&MapZoneArray[i], buffer); MapZoneArray[i] = ReadSaveBuf<CZone>(buffer);
/* /*
The call of GetPointerForZoneIndex is wrong, as it is The call of GetPointerForZoneIndex is wrong, as it is
@ -738,10 +736,10 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
} }
for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++) for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++)
ReadSaveBuf(&AudioZoneArray[i], buffer); AudioZoneArray[i] = ReadSaveBuf<int16>(buffer);
ReadSaveBuf(&TotalNumberOfMapZones, buffer); TotalNumberOfMapZones = ReadSaveBuf<uint16>(buffer);
ReadSaveBuf(&NumberOfAudioZones, buffer); NumberOfAudioZones = ReadSaveBuf<uint16>(buffer);
VALIDATESAVEBUF(size) VALIDATESAVEBUF(size)
} }

View File

@ -393,3 +393,173 @@ template<int s, int t> struct check_size {
#define STR(x) STRINGIFY(x) #define STR(x) STRINGIFY(x)
#define CONCAT_(x,y) x##y #define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y) #define CONCAT(x,y) CONCAT_(x,y)
#ifdef DEBUGMENU
// Tweaking stuff for debugmenu
#define TWEAKPATH ___tw___TWEAKPATH
#define SETTWEAKPATH(path) static const char *___tw___TWEAKPATH = path;
#define TWEAKFUNC(v) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH);
#define TWEAKFUNCN(v, name) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH);
#define TWEAKBOOL(v) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH);
#define TWEAKBOOLN(v, name) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH);
#define TWEAKINT32(v, lower, upper, step) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKINT32N(v, lower, upper, step, name) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKUINT32(v, lower, upper, step) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKUINT32N(v, lower, upper, step, name) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKINT16(v, lower, upper, step) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKINT16N(v, lower, upper, step, name) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKUINT16(v, lower, upper, step) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKUINT16N(v, lower, upper, step, name) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKINT8(v, lower, upper, step) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKINT8N(v, lower, upper, step, name) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKUINT8(v, lower, upper, step) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKUINT8N(v, lower, upper, step, name) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKFLOAT(v, lower, upper, step) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKFLOATN(v, lower, upper, step, name) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKSWITCH(v, lower, upper, str, f) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, str, f, TWEAKPATH);
#define TWEAKSWITCHN(v, lower, upper, str, f, name) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, str, f, TWEAKPATH);
// interface
class CTweakVar
{
public:
virtual void AddDBG(const char *path) = 0;
};
class CTweakVars
{
public:
static void Add(CTweakVar *var);
static void AddDBG(const char *path);
};
class CTweakFunc : public CTweakVar
{
const char *m_pPath, *m_pVarName;
void (*m_pFunc)();
public:
CTweakFunc(void (*pFunc)(), const char *strName, const char *strPath) :
m_pPath(strPath), m_pVarName(strName), m_pFunc(pFunc)
{
CTweakVars::Add(this);
}
void AddDBG(const char *path);
};
class CTweakBool : public CTweakVar
{
const char *m_pPath, *m_pVarName;
bool *m_pBoolVar;
public:
CTweakBool(bool *pBool, const char *strName, const char *strPath) :
m_pPath(strPath), m_pVarName(strName), m_pBoolVar(pBool)
{
CTweakVars::Add(this);
}
void AddDBG(const char *path);
};
class CTweakSwitch : public CTweakVar
{
const char *m_pPath, *m_pVarName;
void *m_pIntVar;
int32 m_nMin, m_nMax;
const char **m_aStr;
void (*m_pFunc)();
public:
CTweakSwitch(void *pInt, const char *strName, int32 nMin, int32 nMax, const char **aStr,
void (*pFunc)(), const char *strPath)
: m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), m_nMin(nMin), m_nMax(nMax),
m_aStr(aStr)
{
CTweakVars::Add(this);
}
void AddDBG(const char *path);
};
#define _TWEEKCLASS(name, type) \
class name : public CTweakVar \
{ \
public: \
const char *m_pPath, *m_pVarName; \
type *m_pIntVar, m_nLoawerBound, m_nUpperBound, m_nStep; \
\
name(type *pInt, const char *strName, type nLower, type nUpper, type nStep, \
const char *strPath) \
: m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), \
m_nLoawerBound(nLower), m_nUpperBound(nUpper), m_nStep(nStep) \
\
{ \
CTweakVars::Add(this); \
} \
\
void AddDBG(const char *path); \
};
_TWEEKCLASS(CTweakInt8, int8);
_TWEEKCLASS(CTweakUInt8, uint8);
_TWEEKCLASS(CTweakInt16, int16);
_TWEEKCLASS(CTweakUInt16, uint16);
_TWEEKCLASS(CTweakInt32, int32);
_TWEEKCLASS(CTweakUInt32, uint32);
_TWEEKCLASS(CTweakFloat, float);
#undef _TWEEKCLASS
#endif
#ifdef VALIDATE_SAVE_SIZE
extern int32 _saveBufCount;
#define INITSAVEBUF _saveBufCount = 0;
#define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
#else
#define INITSAVEBUF
#define VALIDATESAVEBUF(b)
#endif
inline void SkipSaveBuf(uint8 *&buf, int32 skip)
{
buf += skip;
#ifdef VALIDATE_SAVE_SIZE
_saveBufCount += skip;
#endif
}
template<typename T>
inline const T ReadSaveBuf(uint8 *&buf)
{
T &value = *(T*)buf;
SkipSaveBuf(buf, sizeof(T));
return value;
}
template<typename T>
inline T *WriteSaveBuf(uint8 *&buf, const T &value)
{
T *p = (T*)buf;
*p = value;
SkipSaveBuf(buf, sizeof(T));
return p;
}
#define SAVE_HEADER_SIZE (4*sizeof(char)+sizeof(uint32))
#define WriteSaveHeader(buf,a,b,c,d,size) \
WriteSaveBuf(buf, a);\
WriteSaveBuf(buf, b);\
WriteSaveBuf(buf, c);\
WriteSaveBuf(buf, d);\
WriteSaveBuf<uint32>(buf, size);
#define CheckSaveHeader(buf,a,b,c,d,size)\
assert(ReadSaveBuf<char>(buf) == a);\
assert(ReadSaveBuf<char>(buf) == b);\
assert(ReadSaveBuf<char>(buf) == c);\
assert(ReadSaveBuf<char>(buf) == d);\
assert(ReadSaveBuf<uint32>(buf) == size);
void cprintf(char*, ...);

View File

@ -22,7 +22,6 @@
#include "MemoryHeap.h" #include "MemoryHeap.h"
#include "Bones.h" #include "Bones.h"
#include "Debug.h" #include "Debug.h"
#include "SaveBuf.h"
int gBuildings; int gBuildings;
@ -754,8 +753,7 @@ CEntity::SaveEntityFlags(uint8*& buf)
void void
CEntity::LoadEntityFlags(uint8*& buf) CEntity::LoadEntityFlags(uint8*& buf)
{ {
uint32 tmp; uint32 tmp = ReadSaveBuf<uint32>(buf);
ReadSaveBuf(&tmp, buf);
m_type = (tmp & ((BIT(3) - 1))); m_type = (tmp & ((BIT(3) - 1)));
m_status = ((tmp >> 3) & (BIT(5) - 1)); m_status = ((tmp >> 3) & (BIT(5) - 1));
@ -786,7 +784,7 @@ CEntity::LoadEntityFlags(uint8*& buf)
bZoneCulled = !!(tmp & BIT(30)); bZoneCulled = !!(tmp & BIT(30));
bZoneCulled2 = !!(tmp & BIT(31)); bZoneCulled2 = !!(tmp & BIT(31));
ReadSaveBuf(&tmp, buf); tmp = ReadSaveBuf<uint32>(buf);
bRemoveFromWorld = !!(tmp & BIT(0)); bRemoveFromWorld = !!(tmp & BIT(0));
bHasHitWall = !!(tmp & BIT(1)); bHasHitWall = !!(tmp & BIT(1));

View File

@ -2,120 +2,6 @@
#ifdef DEBUGMENU #ifdef DEBUGMENU
// Tweaking stuff for debugmenu
#define TWEAKPATH ___tw___TWEAKPATH
#define SETTWEAKPATH(path) static const char *___tw___TWEAKPATH = path;
#define TWEAKFUNC(v) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH);
#define TWEAKFUNCN(v, name) static CTweakFunc CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH);
#define TWEAKBOOL(v) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), TWEAKPATH);
#define TWEAKBOOLN(v, name) static CTweakBool CONCAT(___tw___tweak, __COUNTER__)(&v, name, TWEAKPATH);
#define TWEAKINT32(v, lower, upper, step) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKINT32N(v, lower, upper, step, name) static CTweakInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKUINT32(v, lower, upper, step) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKUINT32N(v, lower, upper, step, name) static CTweakUInt32 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKINT16(v, lower, upper, step) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKINT16N(v, lower, upper, step, name) static CTweakInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKUINT16(v, lower, upper, step) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKUINT16N(v, lower, upper, step, name) static CTweakUInt16 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKINT8(v, lower, upper, step) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKINT8N(v, lower, upper, step, name) static CTweakInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKUINT8(v, lower, upper, step) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKUINT8N(v, lower, upper, step, name) static CTweakUInt8 CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKFLOAT(v, lower, upper, step) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, step, TWEAKPATH);
#define TWEAKFLOATN(v, lower, upper, step, name) static CTweakFloat CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, step, TWEAKPATH);
#define TWEAKSWITCH(v, lower, upper, str, f) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, STR(v), lower, upper, str, f, TWEAKPATH);
#define TWEAKSWITCHN(v, lower, upper, str, f, name) static CTweakSwitch CONCAT(___tw___tweak, __COUNTER__)(&v, name, lower, upper, str, f, TWEAKPATH);
// interface
class CTweakVar
{
public:
virtual void AddDBG(const char* path) = 0;
};
class CTweakVars
{
public:
static void Add(CTweakVar* var);
static void AddDBG(const char* path);
};
class CTweakFunc : public CTweakVar
{
const char* m_pPath, * m_pVarName;
void (*m_pFunc)();
public:
CTweakFunc(void (*pFunc)(), const char* strName, const char* strPath) :
m_pPath(strPath), m_pVarName(strName), m_pFunc(pFunc)
{
CTweakVars::Add(this);
}
void AddDBG(const char* path);
};
class CTweakBool : public CTweakVar
{
const char* m_pPath, * m_pVarName;
bool* m_pBoolVar;
public:
CTweakBool(bool* pBool, const char* strName, const char* strPath) :
m_pPath(strPath), m_pVarName(strName), m_pBoolVar(pBool)
{
CTweakVars::Add(this);
}
void AddDBG(const char* path);
};
class CTweakSwitch : public CTweakVar
{
const char* m_pPath, * m_pVarName;
void* m_pIntVar;
int32 m_nMin, m_nMax;
const char** m_aStr;
void (*m_pFunc)();
public:
CTweakSwitch(void* pInt, const char* strName, int32 nMin, int32 nMax, const char** aStr,
void (*pFunc)(), const char* strPath)
: m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), m_nMin(nMin), m_nMax(nMax),
m_aStr(aStr)
{
CTweakVars::Add(this);
}
void AddDBG(const char* path);
};
#define _TWEEKCLASS(name, type) \
class name : public CTweakVar \
{ \
public: \
const char *m_pPath, *m_pVarName; \
type *m_pIntVar, m_nLoawerBound, m_nUpperBound, m_nStep; \
\
name(type *pInt, const char *strName, type nLower, type nUpper, type nStep, \
const char *strPath) \
: m_pPath(strPath), m_pVarName(strName), m_pIntVar(pInt), \
m_nLoawerBound(nLower), m_nUpperBound(nUpper), m_nStep(nStep) \
\
{ \
CTweakVars::Add(this); \
} \
\
void AddDBG(const char *path); \
};
_TWEEKCLASS(CTweakInt8, int8);
_TWEEKCLASS(CTweakUInt8, uint8);
_TWEEKCLASS(CTweakInt16, int16);
_TWEEKCLASS(CTweakUInt16, uint16);
_TWEEKCLASS(CTweakInt32, int32);
_TWEEKCLASS(CTweakUInt32, uint32);
_TWEEKCLASS(CTweakFloat, float);
#undef _TWEEKCLASS
typedef void (*TriggerFunc)(void); typedef void (*TriggerFunc)(void);
struct Menu; struct Menu;

View File

@ -3,7 +3,6 @@
#include "ModelIndices.h" #include "ModelIndices.h"
#include "Gangs.h" #include "Gangs.h"
#include "Weapon.h" #include "Weapon.h"
#include "SaveBuf.h"
CGangInfo CGangs::Gang[NUM_GANGS]; CGangInfo CGangs::Gang[NUM_GANGS];
@ -73,6 +72,6 @@ INITSAVEBUF
CheckSaveHeader(buf, 'G','N','G','\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buf, 'G','N','G','\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUM_GANGS; i++) for (int i = 0; i < NUM_GANGS; i++)
ReadSaveBuf(&Gang[i], buf); Gang[i] = ReadSaveBuf<CGangInfo>(buf);
VALIDATESAVEBUF(size); VALIDATESAVEBUF(size);
} }

View File

@ -32,7 +32,6 @@
#include "Floater.h" #include "Floater.h"
#include "Range2D.h" #include "Range2D.h"
#include "Wanted.h" #include "Wanted.h"
#include "SaveBuf.h"
CPed *gapTempPedList[50]; CPed *gapTempPedList[50];
uint16 gnNumTempPedList; uint16 gnNumTempPedList;

View File

@ -3,7 +3,6 @@
#include "General.h" #include "General.h"
#include "FileMgr.h" #include "FileMgr.h"
#include "PedType.h" #include "PedType.h"
#include "SaveBuf.h"
CPedType *CPedType::ms_apPedType[NUM_PEDTYPES]; CPedType *CPedType::ms_apPedType[NUM_PEDTYPES];
CPedStats *CPedStats::ms_apPedStats[NUM_PEDSTATS]; CPedStats *CPedStats::ms_apPedStats[NUM_PEDSTATS];
@ -202,7 +201,7 @@ INITSAVEBUF
CheckSaveHeader(buf, 'P', 'T', 'P', '\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buf, 'P', 'T', 'P', '\0', size - SAVE_HEADER_SIZE);
for(int i = 0; i < NUM_PEDTYPES; i++) for(int i = 0; i < NUM_PEDTYPES; i++)
ReadSaveBuf(ms_apPedType[i], buf); *ms_apPedType[i] = ReadSaveBuf<CPedType>(buf);
VALIDATESAVEBUF(size) VALIDATESAVEBUF(size)
} }

View File

@ -16,7 +16,6 @@
#include "Pools.h" #include "Pools.h"
#include "Darkel.h" #include "Darkel.h"
#include "CarCtrl.h" #include "CarCtrl.h"
#include "SaveBuf.h"
#define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f #define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f

View File

@ -23,5 +23,3 @@ public:
}; };
extern CConsole TheConsole; extern CConsole TheConsole;
void cprintf(char*, ...);

View File

@ -14,7 +14,6 @@
#include "ParticleObject.h" #include "ParticleObject.h"
#include "Particle.h" #include "Particle.h"
#include "soundlist.h" #include "soundlist.h"
#include "debugmenu.h"
#define MAX_PARTICLES_ON_SCREEN (1000) #define MAX_PARTICLES_ON_SCREEN (1000)

View File

@ -1,64 +0,0 @@
#pragma once
#ifdef VALIDATE_SAVE_SIZE
extern int32 _saveBufCount;
#define INITSAVEBUF _saveBufCount = 0;
#define VALIDATESAVEBUF(b) assert(_saveBufCount == b);
#else
#define INITSAVEBUF
#define VALIDATESAVEBUF(b)
#endif
inline void
SkipSaveBuf(uint8 *&buf, int32 skip)
{
buf += skip;
#ifdef VALIDATE_SAVE_SIZE
_saveBufCount += skip;
#endif
}
template <typename T>
inline void
ReadSaveBuf(T* out, uint8 *&buf)
{
*out = *(T *)buf;
SkipSaveBuf(buf, sizeof(T));
}
template <typename T>
inline T *
WriteSaveBuf(uint8 *&buf, const T &value)
{
T *p = (T *)buf;
*p = value;
SkipSaveBuf(buf, sizeof(T));
return p;
}
#define SAVE_HEADER_SIZE (4 * sizeof(char) + sizeof(uint32))
#define WriteSaveHeader(buf, a, b, c, d, size) \
WriteSaveBuf(buf, a); \
WriteSaveBuf(buf, b); \
WriteSaveBuf(buf, c); \
WriteSaveBuf(buf, d); \
WriteSaveBuf(buf, (uint32)size);
#ifdef VALIDATE_SAVE_SIZE
#define CheckSaveHeader(buf, a, b, c, d, size) { \
char _C; uint32 _size;\
ReadSaveBuf(&_C, buf);\
assert(_C == a);\
ReadSaveBuf(&_C, buf);\
assert(_C == b);\
ReadSaveBuf(&_C, buf);\
assert(_C == c);\
ReadSaveBuf(&_C, buf);\
assert(_C == d);\
ReadSaveBuf(&_size, buf);\
assert(_size == size);\
}
#else
#define CheckSaveHeader(buf, a, b, c, d, size) SkipSaveBuf(buf, 8);
#endif

View File

@ -45,7 +45,6 @@
#include "Object.h" #include "Object.h"
#include "Automobile.h" #include "Automobile.h"
#include "Wanted.h" #include "Wanted.h"
#include "SaveBuf.h"
bool bAllCarCheat; // unused bool bAllCarCheat; // unused
@ -4725,7 +4724,7 @@ void
CAutomobile::Load(uint8*& buf) CAutomobile::Load(uint8*& buf)
{ {
CVehicle::Load(buf); CVehicle::Load(buf);
ReadSaveBuf(&Damage, buf); Damage = ReadSaveBuf<CDamageManager>(buf);
SkipSaveBuf(buf, 800 - sizeof(CDamageManager)); SkipSaveBuf(buf, 800 - sizeof(CDamageManager));
SetupDamageAfterLoad(); SetupDamageAfterLoad();
} }

View File

@ -19,7 +19,6 @@
#include "Pools.h" #include "Pools.h"
#include "Pad.h" #include "Pad.h"
#include "Boat.h" #include "Boat.h"
#include "SaveBuf.h"
#define INVALID_ORIENTATION (-9999.99f) #define INVALID_ORIENTATION (-9999.99f)

View File

@ -13,7 +13,6 @@
#include "Timer.h" #include "Timer.h"
#include "Vehicle.h" #include "Vehicle.h"
#include "World.h" #include "World.h"
#include "SaveBuf.h"
uint8 CTheCarGenerators::ProcessCounter; uint8 CTheCarGenerators::ProcessCounter;
uint32 CTheCarGenerators::NumOfCarGenerators; uint32 CTheCarGenerators::NumOfCarGenerators;
@ -255,17 +254,14 @@ void CTheCarGenerators::LoadAllCarGenerators(uint8* buffer, uint32 size)
Init(); Init();
INITSAVEBUF INITSAVEBUF
CheckSaveHeader(buffer, 'C','G','N','\0', size - SAVE_HEADER_SIZE); CheckSaveHeader(buffer, 'C','G','N','\0', size - SAVE_HEADER_SIZE);
uint32 tmp; assert(ReadSaveBuf<uint32>(buffer) == nGeneralDataSize);
ReadSaveBuf(&tmp, buffer); NumOfCarGenerators = ReadSaveBuf<uint32>(buffer);
assert(tmp == nGeneralDataSize); CurrentActiveCount = ReadSaveBuf<uint32>(buffer);
ReadSaveBuf(&NumOfCarGenerators, buffer); ProcessCounter = ReadSaveBuf<uint8>(buffer);
ReadSaveBuf(&CurrentActiveCount, buffer); GenerateEvenIfPlayerIsCloseCounter = ReadSaveBuf<uint8>(buffer);
ReadSaveBuf(&ProcessCounter, buffer); ReadSaveBuf<int16>(buffer); // alignment
ReadSaveBuf(&GenerateEvenIfPlayerIsCloseCounter, buffer); assert(ReadSaveBuf<uint32>(buffer) == sizeof(CarGeneratorArray));
SkipSaveBuf(buffer, 2);
ReadSaveBuf(&tmp, buffer);
assert(tmp == sizeof(CarGeneratorArray));
for (int i = 0; i < NUM_CARGENS; i++) for (int i = 0; i < NUM_CARGENS; i++)
ReadSaveBuf(&CarGeneratorArray[i], buffer); CarGeneratorArray[i] = ReadSaveBuf<CCarGenerator>(buffer);
VALIDATESAVEBUF(size) VALIDATESAVEBUF(size)
} }

View File

@ -11,7 +11,6 @@
#include "Replay.h" #include "Replay.h"
#include "Object.h" #include "Object.h"
#include "World.h" #include "World.h"
#include "SaveBuf.h"
#define MAX_DISTANCE_TO_FIND_CRANE (10.0f) #define MAX_DISTANCE_TO_FIND_CRANE (10.0f)
#define CRANE_UPDATE_RADIUS (300.0f) #define CRANE_UPDATE_RADIUS (300.0f)
@ -654,10 +653,10 @@ void CCranes::Load(uint8* buf, uint32 size)
{ {
INITSAVEBUF INITSAVEBUF
ReadSaveBuf(&NumCranes, buf); NumCranes = ReadSaveBuf<int32>(buf);
ReadSaveBuf(&CarsCollectedMilitaryCrane, buf); CarsCollectedMilitaryCrane = ReadSaveBuf<uint32>(buf);
for (int i = 0; i < NUM_CRANES; i++) for (int i = 0; i < NUM_CRANES; i++)
ReadSaveBuf(&aCranes[i], buf); aCranes[i] = ReadSaveBuf<CCrane>(buf);
for (int i = 0; i < NUM_CRANES; i++) { for (int i = 0; i < NUM_CRANES; i++) {
CCrane *pCrane = &aCranes[i]; CCrane *pCrane = &aCranes[i];
if (pCrane->m_pCraneEntity != nil) if (pCrane->m_pCraneEntity != nil)

View File

@ -18,7 +18,6 @@
#include "Radar.h" #include "Radar.h"
#include "Fire.h" #include "Fire.h"
#include "Darkel.h" #include "Darkel.h"
#include "SaveBuf.h"
bool CVehicle::bWheelsOnlyCheat; bool CVehicle::bWheelsOnlyCheat;
bool CVehicle::bAllDodosCheat; bool CVehicle::bAllDodosCheat;
@ -1324,44 +1323,43 @@ CVehicle::Load(uint8*& buf)
{ {
CMatrix tmp; CMatrix tmp;
SkipSaveBuf(buf, 4); SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetRight().x, buf); tmp.GetRight().x = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetRight().y, buf); tmp.GetRight().y = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetRight().z, buf); tmp.GetRight().z = ReadSaveBuf<float>(buf);
SkipSaveBuf(buf, 4); SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetForward().x, buf); tmp.GetForward().x = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetForward().y, buf); tmp.GetForward().y = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetForward().z, buf); tmp.GetForward().z = ReadSaveBuf<float>(buf);
SkipSaveBuf(buf, 4); SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetUp().x, buf); tmp.GetUp().x = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetUp().y, buf); tmp.GetUp().y = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetUp().z, buf); tmp.GetUp().z = ReadSaveBuf<float>(buf);
SkipSaveBuf(buf, 4); SkipSaveBuf(buf, 4);
ReadSaveBuf(&tmp.GetPosition().x, buf); tmp.GetPosition().x = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetPosition().y, buf); tmp.GetPosition().y = ReadSaveBuf<float>(buf);
ReadSaveBuf(&tmp.GetPosition().z, buf); tmp.GetPosition().z = ReadSaveBuf<float>(buf);
m_matrix = tmp; m_matrix = tmp;
SkipSaveBuf(buf, 16); SkipSaveBuf(buf, 16);
LoadEntityFlags(buf); LoadEntityFlags(buf);
SkipSaveBuf(buf, 212); SkipSaveBuf(buf, 212);
AutoPilot.Load(buf); AutoPilot.Load(buf);
ReadSaveBuf(&m_currentColour1, buf); m_currentColour1 = ReadSaveBuf<int8>(buf);
ReadSaveBuf(&m_currentColour2, buf); m_currentColour2 = ReadSaveBuf<int8>(buf);
SkipSaveBuf(buf, 2); SkipSaveBuf(buf, 2);
ReadSaveBuf(&m_nAlarmState, buf); m_nAlarmState = ReadSaveBuf<int16>(buf);
SkipSaveBuf(buf, 43); SkipSaveBuf(buf, 43);
ReadSaveBuf(&m_nNumMaxPassengers, buf); m_nNumMaxPassengers = ReadSaveBuf<int8>(buf);
SkipSaveBuf(buf, 2); SkipSaveBuf(buf, 2);
ReadSaveBuf(&field_1D0[0], buf); field_1D0[0] = ReadSaveBuf<float>(buf);
ReadSaveBuf(&field_1D0[1], buf); field_1D0[1] = ReadSaveBuf<float>(buf);
ReadSaveBuf(&field_1D0[2], buf); field_1D0[2] = ReadSaveBuf<float>(buf);
ReadSaveBuf(&field_1D0[3], buf); field_1D0[3] = ReadSaveBuf<float>(buf);
SkipSaveBuf(buf, 8); SkipSaveBuf(buf, 8);
ReadSaveBuf(&m_fSteerAngle, buf); m_fSteerAngle = ReadSaveBuf<float>(buf);
ReadSaveBuf(&m_fGasPedal, buf); m_fGasPedal = ReadSaveBuf<float>(buf);
ReadSaveBuf(&m_fBrakePedal, buf); m_fBrakePedal = ReadSaveBuf<float>(buf);
ReadSaveBuf(&VehicleCreatedBy, buf); VehicleCreatedBy = ReadSaveBuf<uint8>(buf);
uint8 flags; uint8 flags = ReadSaveBuf<uint8>(buf);
ReadSaveBuf(&flags, buf);
bIsLawEnforcer = !!(flags & BIT(0)); bIsLawEnforcer = !!(flags & BIT(0));
bIsLocked = !!(flags & BIT(3)); bIsLocked = !!(flags & BIT(3));
bEngineOn = !!(flags & BIT(4)); bEngineOn = !!(flags & BIT(4));
@ -1369,17 +1367,16 @@ CVehicle::Load(uint8*& buf)
bLightsOn = !!(flags & BIT(6)); bLightsOn = !!(flags & BIT(6));
bFreebies = !!(flags & BIT(7)); bFreebies = !!(flags & BIT(7));
SkipSaveBuf(buf, 10); SkipSaveBuf(buf, 10);
ReadSaveBuf(&m_fHealth, buf); m_fHealth = ReadSaveBuf<float>(buf);
ReadSaveBuf(&m_nCurrentGear, buf); m_nCurrentGear = ReadSaveBuf<uint8>(buf);
SkipSaveBuf(buf, 3); SkipSaveBuf(buf, 3);
ReadSaveBuf(&m_fChangeGearTime, buf); m_fChangeGearTime = ReadSaveBuf<float>(buf);
SkipSaveBuf(buf, 4); SkipSaveBuf(buf, 4);
ReadSaveBuf(&m_nTimeOfDeath, buf); m_nTimeOfDeath = ReadSaveBuf<uint32>(buf);
SkipSaveBuf(buf, 2); SkipSaveBuf(buf, 2);
ReadSaveBuf(&m_nBombTimer, buf); m_nBombTimer = ReadSaveBuf<int16>(buf);
SkipSaveBuf(buf, 12); SkipSaveBuf(buf, 12);
ReadSaveBuf(&flags, buf); m_nDoorLock = (eCarLock)ReadSaveBuf<int8>(buf);
m_nDoorLock = (eCarLock)flags;
SkipSaveBuf(buf, 99); SkipSaveBuf(buf, 99);
} }
#endif #endif

View File

@ -30,7 +30,6 @@
#include "WaterLevel.h" #include "WaterLevel.h"
#include "WeaponInfo.h" #include "WeaponInfo.h"
#include "World.h" #include "World.h"
#include "SaveBuf.h"
uint16 gReloadSampleTime[WEAPONTYPE_LAST_WEAPONTYPE] = uint16 gReloadSampleTime[WEAPONTYPE_LAST_WEAPONTYPE] =
{ {