summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwithmorten <morten.with@gmail.com>2021-06-26 19:14:46 +0200
committerwithmorten <morten.with@gmail.com>2021-06-26 19:14:46 +0200
commitf3a931e1c99372ae4bc224ef482d4052a09580cb (patch)
tree13992380234e68b8f1a32030b4df6aa3d6ebbaca /src
parentMerge pull request #1155 from leanndroguedes/master (diff)
downloadre3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar
re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.gz
re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.bz2
re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.lz
re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.xz
re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.tar.zst
re3-f3a931e1c99372ae4bc224ef482d4052a09580cb.zip
Diffstat (limited to '')
-rw-r--r--src/audio/AudioScriptObject.cpp9
-rw-r--r--src/control/AutoPilot.cpp54
-rw-r--r--src/control/Garages.cpp28
-rw-r--r--src/control/Phones.cpp11
-rw-r--r--src/control/Pickups.cpp9
-rw-r--r--src/control/Restart.cpp32
-rw-r--r--src/control/Script5.cpp85
-rw-r--r--src/core/Pools.cpp16
-rw-r--r--src/core/Radar.cpp3
-rw-r--r--src/core/Zones.cpp28
-rw-r--r--src/core/common.h170
-rw-r--r--src/entities/Entity.cpp6
-rw-r--r--src/extras/debugmenu.h114
-rw-r--r--src/peds/Gangs.cpp3
-rw-r--r--src/peds/Ped.cpp1
-rw-r--r--src/peds/PedType.cpp3
-rw-r--r--src/peds/PlayerPed.cpp1
-rw-r--r--src/render/Console.h2
-rw-r--r--src/render/Particle.cpp1
-rw-r--r--src/save/SaveBuf.h64
-rw-r--r--src/vehicles/Automobile.cpp3
-rw-r--r--src/vehicles/Boat.cpp1
-rw-r--r--src/vehicles/CarGen.cpp20
-rw-r--r--src/vehicles/Cranes.cpp7
-rw-r--r--src/vehicles/Vehicle.cpp65
-rw-r--r--src/weapons/Weapon.cpp1
26 files changed, 399 insertions, 338 deletions
diff --git a/src/audio/AudioScriptObject.cpp b/src/audio/AudioScriptObject.cpp
index c74feb92..03efdea9 100644
--- a/src/audio/AudioScriptObject.cpp
+++ b/src/audio/AudioScriptObject.cpp
@@ -3,6 +3,7 @@
#include "AudioScriptObject.h"
#include "Pools.h"
#include "DMAudio.h"
+#include "SaveBuf.h"
cAudioScriptObject::cAudioScriptObject()
{
@@ -53,12 +54,14 @@ cAudioScriptObject::LoadAllAudioScriptObjects(uint8 *buf, uint32 size)
CheckSaveHeader(buf, 'A', 'U', 'D', '\0', size - SAVE_HEADER_SIZE);
- int32 pool_size = ReadSaveBuf<int32>(buf);
+ int32 pool_size;
+ ReadSaveBuf(&pool_size, buf);
for (int32 i = 0; i < pool_size; i++) {
- int handle = ReadSaveBuf<int32>(buf);
+ int32 handle;
+ ReadSaveBuf(&handle, buf);
cAudioScriptObject *p = new(handle) cAudioScriptObject;
assert(p != nil);
- *p = ReadSaveBuf<cAudioScriptObject>(buf);
+ ReadSaveBuf(p, buf);
p->AudioEntity = DMAudio.CreateLoopingScriptObject(p);
}
diff --git a/src/control/AutoPilot.cpp b/src/control/AutoPilot.cpp
index 77cbd0b4..22a73179 100644
--- a/src/control/AutoPilot.cpp
+++ b/src/control/AutoPilot.cpp
@@ -5,6 +5,7 @@
#include "CarCtrl.h"
#include "Curves.h"
#include "PathFind.h"
+#include "SaveBuf.h"
void CAutoPilot::ModifySpeed(float speed)
{
@@ -88,39 +89,40 @@ void CAutoPilot::Save(uint8*& buf)
void CAutoPilot::Load(uint8*& buf)
{
- m_nCurrentRouteNode = ReadSaveBuf<int32>(buf);
- m_nNextRouteNode = ReadSaveBuf<int32>(buf);
- m_nPrevRouteNode = ReadSaveBuf<int32>(buf);
- m_nTimeEnteredCurve = ReadSaveBuf<int32>(buf);
- m_nTimeToSpendOnCurrentCurve = ReadSaveBuf<int32>(buf);
- m_nCurrentPathNodeInfo = ReadSaveBuf<uint32>(buf);
- m_nNextPathNodeInfo = ReadSaveBuf<uint32>(buf);
- m_nPreviousPathNodeInfo = ReadSaveBuf<uint32>(buf);
- m_nAntiReverseTimer = ReadSaveBuf<uint32>(buf);
- m_nTimeToStartMission = ReadSaveBuf<uint32>(buf);
- m_nPreviousDirection = ReadSaveBuf<int8>(buf);
- m_nCurrentDirection = ReadSaveBuf<int8>(buf);
- m_nNextDirection = ReadSaveBuf<int8>(buf);
- m_nCurrentLane = ReadSaveBuf<int8>(buf);
- m_nNextLane = ReadSaveBuf<int8>(buf);
- m_nDrivingStyle = ReadSaveBuf<uint8>(buf);
- m_nCarMission = ReadSaveBuf<uint8>(buf);
- m_nTempAction = ReadSaveBuf<uint8>(buf);
- m_nTimeTempAction = ReadSaveBuf<uint32>(buf);
- m_fMaxTrafficSpeed = ReadSaveBuf<float>(buf);
- m_nCruiseSpeed = ReadSaveBuf<uint8>(buf);
- uint8 flags = ReadSaveBuf<uint8>(buf);
+ ReadSaveBuf(&m_nCurrentRouteNode, buf);
+ ReadSaveBuf(&m_nNextRouteNode, buf);
+ ReadSaveBuf(&m_nPrevRouteNode, buf);
+ ReadSaveBuf(&m_nTimeEnteredCurve, buf);
+ ReadSaveBuf(&m_nTimeToSpendOnCurrentCurve, buf);
+ ReadSaveBuf(&m_nCurrentPathNodeInfo, buf);
+ ReadSaveBuf(&m_nNextPathNodeInfo, buf);
+ ReadSaveBuf(&m_nPreviousPathNodeInfo, buf);
+ ReadSaveBuf(&m_nAntiReverseTimer, buf);
+ ReadSaveBuf(&m_nTimeToStartMission, buf);
+ ReadSaveBuf(&m_nPreviousDirection, buf);
+ ReadSaveBuf(&m_nCurrentDirection, buf);
+ ReadSaveBuf(&m_nNextDirection, buf);
+ ReadSaveBuf(&m_nCurrentLane, buf);
+ ReadSaveBuf(&m_nNextLane, buf);
+ ReadSaveBuf(&m_nDrivingStyle, buf);
+ ReadSaveBuf(&m_nCarMission, buf);
+ ReadSaveBuf(&m_nTempAction, buf);
+ ReadSaveBuf(&m_nTimeTempAction, buf);
+ ReadSaveBuf(&m_fMaxTrafficSpeed, buf);
+ ReadSaveBuf(&m_nCruiseSpeed, buf);
+ uint8 flags;
+ ReadSaveBuf(&flags, buf);
m_bSlowedDownBecauseOfCars = !!(flags & BIT(0));
m_bSlowedDownBecauseOfPeds = !!(flags & BIT(1));
m_bStayInCurrentLevel = !!(flags & BIT(2));
m_bStayInFastLane = !!(flags & BIT(3));
m_bIgnorePathfinding = !!(flags & BIT(4));
SkipSaveBuf(buf, 2);
- m_vecDestinationCoors.x = ReadSaveBuf<float>(buf);
- m_vecDestinationCoors.y = ReadSaveBuf<float>(buf);
- m_vecDestinationCoors.z = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&m_vecDestinationCoors.x, buf);
+ ReadSaveBuf(&m_vecDestinationCoors.y, buf);
+ ReadSaveBuf(&m_vecDestinationCoors.z, buf);
SkipSaveBuf(buf, 32);
- m_nPathFindNodesCount = ReadSaveBuf<int16>(buf);
+ ReadSaveBuf(&m_nPathFindNodesCount, buf);
SkipSaveBuf(buf, 6);
}
#endif \ No newline at end of file
diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp
index 792d3bda..3410c881 100644
--- a/src/control/Garages.cpp
+++ b/src/control/Garages.cpp
@@ -24,6 +24,7 @@
#include "Vehicle.h"
#include "Wanted.h"
#include "World.h"
+#include "SaveBuf.h"
#define CRUSHER_GARAGE_X1 (1135.5f)
#define CRUSHER_GARAGE_Y1 (57.0f)
@@ -2361,22 +2362,25 @@ void CGarages::Load(uint8* buf, uint32 size)
assert(size == 5484);
#endif
CloseHideOutGaragesBeforeSave();
- NumGarages = ReadSaveBuf<uint32>(buf);
- BombsAreFree = ReadSaveBuf<uint32>(buf);
- RespraysAreFree = ReadSaveBuf<uint32>(buf);
- CarsCollected = ReadSaveBuf<int32>(buf);
- BankVansCollected = ReadSaveBuf<int32>(buf);
- PoliceCarsCollected = ReadSaveBuf<int32>(buf);
+ ReadSaveBuf(&NumGarages, buf);
+ int32 tempInt;
+ ReadSaveBuf(&tempInt, buf);
+ BombsAreFree = tempInt ? true : false;
+ ReadSaveBuf(&tempInt, buf);
+ RespraysAreFree = tempInt ? true : false;
+ ReadSaveBuf(&CarsCollected, buf);
+ ReadSaveBuf(&BankVansCollected, buf);
+ ReadSaveBuf(&PoliceCarsCollected, buf);
for (int i = 0; i < TOTAL_COLLECTCARS_GARAGES; i++)
- CarTypesCollected[i] = ReadSaveBuf<uint32>(buf);
- LastTimeHelpMessage = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&CarTypesCollected[i], buf);
+ ReadSaveBuf(&LastTimeHelpMessage, buf);
for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++) {
- aCarsInSafeHouse1[i] = ReadSaveBuf<CStoredCar>(buf);
- aCarsInSafeHouse2[i] = ReadSaveBuf<CStoredCar>(buf);
- aCarsInSafeHouse3[i] = ReadSaveBuf<CStoredCar>(buf);
+ ReadSaveBuf(&aCarsInSafeHouse1[i], buf);
+ ReadSaveBuf(&aCarsInSafeHouse2[i], buf);
+ ReadSaveBuf(&aCarsInSafeHouse3[i], buf);
}
for (int i = 0; i < NUM_GARAGES; i++) {
- aGarages[i] = ReadSaveBuf<CGarage>(buf);
+ ReadSaveBuf(&aGarages[i], buf);
aGarages[i].m_pDoor1 = nil;
aGarages[i].m_pDoor2 = nil;
aGarages[i].m_pTarget = nil;
diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp
index ef7ecead..f9cb1421 100644
--- a/src/control/Phones.cpp
+++ b/src/control/Phones.cpp
@@ -13,6 +13,7 @@
#include "RpAnimBlend.h"
#include "AnimBlendAssociation.h"
#include "soundlist.h"
+#include "SaveBuf.h"
#ifdef FIX_BUGS
#include "Replay.h"
#endif
@@ -212,8 +213,9 @@ void
CPhoneInfo::Load(uint8 *buf, uint32 size)
{
INITSAVEBUF
- int max = ReadSaveBuf<int32>(buf);
- int scriptPhonesMax = ReadSaveBuf<int32>(buf);
+ int32 max, scriptPhonesMax;
+ ReadSaveBuf(&max, buf);
+ ReadSaveBuf(&scriptPhonesMax, buf);
#ifdef PEDS_REPORT_CRIMES_ON_PHONE
m_nMax = Min(NUMPHONES, max);
@@ -223,7 +225,8 @@ INITSAVEBUF
// 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++) {
- CPhone phoneToLoad = ReadSaveBuf<CPhone>(buf);
+ CPhone phoneToLoad;
+ ReadSaveBuf(&phoneToLoad, buf);
if (ignoreOtherPhones)
continue;
@@ -249,7 +252,7 @@ INITSAVEBUF
m_nScriptPhonesMax = scriptPhonesMax;
for (int i = 0; i < NUMPHONES; i++) {
- m_aPhones[i] = ReadSaveBuf<CPhone>(buf);
+ ReadSaveBuf(&m_aPhones[i], buf);
// It's saved as building pool index in save file, convert it to true entity
if (m_aPhones[i].m_pEntity) {
m_aPhones[i].m_pEntity = CPools::GetBuildingPool()->GetSlot((uintptr)m_aPhones[i].m_pEntity - 1);
diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp
index a1e2a851..10175fba 100644
--- a/src/control/Pickups.cpp
+++ b/src/control/Pickups.cpp
@@ -23,6 +23,7 @@
#ifdef FIX_BUGS
#include "Replay.h"
#endif
+#include "SaveBuf.h"
#include "Script.h"
#include "Shadows.h"
#include "SpecialFX.h"
@@ -999,18 +1000,18 @@ CPickups::Load(uint8 *buf, uint32 size)
INITSAVEBUF
for (int32 i = 0; i < NUMPICKUPS; i++) {
- aPickUps[i] = ReadSaveBuf<CPickup>(buf);
+ ReadSaveBuf(&aPickUps[i], buf);
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);
}
- CollectedPickUpIndex = ReadSaveBuf<uint16>(buf);
- ReadSaveBuf<uint16>(buf);
+ ReadSaveBuf(&CollectedPickUpIndex, buf);
+ SkipSaveBuf(buf, 2);
NumMessages = 0;
for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++)
- aPickUpsCollected[i] = ReadSaveBuf<int32>(buf);
+ ReadSaveBuf(&aPickUpsCollected[i], buf);
VALIDATESAVEBUF(size)
}
diff --git a/src/control/Restart.cpp b/src/control/Restart.cpp
index 4ca18c3b..2f5e3d45 100644
--- a/src/control/Restart.cpp
+++ b/src/control/Restart.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include "Restart.h"
+#include "SaveBuf.h"
#include "Zones.h"
#include "PathFind.h"
@@ -173,29 +174,28 @@ INITSAVEBUF
CheckSaveHeader(buf, 'R','S','T','\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
- HospitalRestartPoints[i] = ReadSaveBuf<CVector>(buf);
- HospitalRestartHeadings[i] = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&HospitalRestartPoints[i], buf);
+ ReadSaveBuf(&HospitalRestartHeadings[i], buf);
}
for (int i = 0; i < NUM_RESTART_POINTS; i++) {
- PoliceRestartPoints[i] = ReadSaveBuf<CVector>(buf);
- PoliceRestartHeadings[i] = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&PoliceRestartPoints[i], buf);
+ ReadSaveBuf(&PoliceRestartHeadings[i], buf);
}
- NumberOfHospitalRestarts = ReadSaveBuf<uint16>(buf);
- NumberOfPoliceRestarts = ReadSaveBuf<uint16>(buf);
- bOverrideRestart = ReadSaveBuf<bool>(buf);
+ ReadSaveBuf(&NumberOfHospitalRestarts, buf);
+ ReadSaveBuf(&NumberOfPoliceRestarts, buf);
+ ReadSaveBuf(&bOverrideRestart, buf);
// skip something unused
- ReadSaveBuf<uint8>(buf);
- ReadSaveBuf<uint16>(buf);
-
- OverridePosition = ReadSaveBuf<CVector>(buf);
- OverrideHeading = ReadSaveBuf<float>(buf);
- bFadeInAfterNextDeath = ReadSaveBuf<bool>(buf);
- bFadeInAfterNextArrest = ReadSaveBuf<bool>(buf);
- OverrideHospitalLevel = ReadSaveBuf<uint8>(buf);
- OverridePoliceStationLevel = ReadSaveBuf<uint8>(buf);
+ SkipSaveBuf(buf, 3);
+
+ ReadSaveBuf(&OverridePosition, buf);
+ ReadSaveBuf(&OverrideHeading, buf);
+ ReadSaveBuf(&bFadeInAfterNextDeath, buf);
+ ReadSaveBuf(&bFadeInAfterNextArrest, buf);
+ ReadSaveBuf(&OverrideHospitalLevel, buf);
+ ReadSaveBuf(&OverridePoliceStationLevel, buf);
VALIDATESAVEBUF(size);
}
diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp
index c83c3edc..a9aec18e 100644
--- a/src/control/Script5.cpp
+++ b/src/control/Script5.cpp
@@ -12,6 +12,7 @@
#include "Pools.h"
#include "Population.h"
#include "RpAnimBlend.h"
+#include "SaveBuf.h"
#include "Shadows.h"
#include "SpecialFX.h"
#include "World.h"
@@ -2002,21 +2003,25 @@ void CTheScripts::LoadAllScripts(uint8* buf, uint32 size)
Init();
INITSAVEBUF
CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE);
- uint32 varSpace = ReadSaveBuf<uint32>(buf);
+ uint32 varSpace, type, handle;
+ uint32 tmp;
+
+ ReadSaveBuf(&varSpace, buf);
for (uint32 i = 0; i < varSpace; i++)
- ScriptSpace[i] = ReadSaveBuf<uint8>(buf);
- script_assert(ReadSaveBuf<uint32>(buf) == SCRIPT_DATA_SIZE);
- OnAMissionFlag = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&ScriptSpace[i], buf);
+ ReadSaveBuf(&tmp, buf);
+ script_assert(tmp == SCRIPT_DATA_SIZE);
+ ReadSaveBuf(&OnAMissionFlag, buf);
for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) {
- OnAMissionForContactFlag[i] = ReadSaveBuf<uint32>(buf);
- BaseBriefIdForContact[i] = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&OnAMissionForContactFlag[i], buf);
+ ReadSaveBuf(&BaseBriefIdForContact[i], buf);
}
for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++)
- CollectiveArray[i] = ReadSaveBuf<tCollectiveData>(buf);
- NextFreeCollectiveIndex = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&CollectiveArray[i], buf);
+ ReadSaveBuf(&NextFreeCollectiveIndex, buf);
for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) {
- uint32 type = ReadSaveBuf<uint32>(buf);
- uint32 handle = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&type, buf);
+ ReadSaveBuf(&handle, buf);
switch (type) {
case 0:
BuildingSwapArray[i].m_pBuilding = nil;
@@ -2030,14 +2035,14 @@ INITSAVEBUF
default:
script_assert(false);
}
- BuildingSwapArray[i].m_nNewModel = ReadSaveBuf<uint32>(buf);
- BuildingSwapArray[i].m_nOldModel = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&BuildingSwapArray[i].m_nNewModel, buf);
+ ReadSaveBuf(&BuildingSwapArray[i].m_nOldModel, buf);
if (BuildingSwapArray[i].m_pBuilding)
BuildingSwapArray[i].m_pBuilding->ReplaceWithNewModel(BuildingSwapArray[i].m_nNewModel);
}
for (uint32 i = 0; i < MAX_NUM_INVISIBILITY_SETTINGS; i++) {
- uint32 type = ReadSaveBuf<uint32>(buf);
- uint32 handle = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&type, buf);
+ ReadSaveBuf(&handle, buf);
switch (type) {
case 0:
InvisibilitySettingArray[i] = nil;
@@ -2060,14 +2065,20 @@ INITSAVEBUF
if (InvisibilitySettingArray[i])
InvisibilitySettingArray[i]->bIsVisible = false;
}
- script_assert(ReadSaveBuf<bool>(buf) == bUsingAMultiScriptFile);
- ReadSaveBuf<uint8>(buf);
- ReadSaveBuf<uint16>(buf);
- script_assert(ReadSaveBuf<uint32>(buf) == MainScriptSize);
- script_assert(ReadSaveBuf<uint32>(buf) == LargestMissionScriptSize);
- script_assert(ReadSaveBuf<uint16>(buf) == NumberOfMissionScripts);
- ReadSaveBuf<uint16>(buf);
- uint32 runningScripts = ReadSaveBuf<uint32>(buf);
+ bool tmpBool;
+ ReadSaveBuf(&tmpBool, buf);
+ script_assert(tmpBool == bUsingAMultiScriptFile);
+ SkipSaveBuf(buf, 3);
+ ReadSaveBuf(&tmp, buf);
+ script_assert(tmp == MainScriptSize);
+ ReadSaveBuf(&tmp, buf);
+ script_assert(tmp == LargestMissionScriptSize);
+ uint16 tmp16;
+ ReadSaveBuf(&tmp16, buf);
+ script_assert(tmp16 == NumberOfMissionScripts);
+ SkipSaveBuf(buf, 2);
+ uint32 runningScripts;
+ ReadSaveBuf(&runningScripts, buf);
for (uint32 i = 0; i < runningScripts; i++)
StartNewScript(0)->Load(buf);
VALIDATESAVEBUF(size)
@@ -2115,35 +2126,35 @@ void CRunningScript::Load(uint8*& buf)
#ifdef COMPATIBLE_SAVES
SkipSaveBuf(buf, 8);
for (int i = 0; i < 8; i++)
- m_abScriptName[i] = ReadSaveBuf<char>(buf);
- m_nIp = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&m_abScriptName[i], buf);
+ ReadSaveBuf(&m_nIp, buf);
#ifdef CHECK_STRUCT_SIZES
static_assert(MAX_STACK_DEPTH == 6, "Compatibility loss: MAX_STACK_DEPTH != 6");
#endif
for (int i = 0; i < MAX_STACK_DEPTH; i++)
- m_anStack[i] = ReadSaveBuf<uint32>(buf);
- m_nStackPointer = ReadSaveBuf<uint16>(buf);
+ ReadSaveBuf(&m_anStack[i], buf);
+ ReadSaveBuf(&m_nStackPointer, buf);
SkipSaveBuf(buf, 2);
#ifdef CHECK_STRUCT_SIZES
static_assert(NUM_LOCAL_VARS + NUM_TIMERS == 18, "Compatibility loss: NUM_LOCAL_VARS + NUM_TIMERS != 18");
#endif
for (int i = 0; i < NUM_LOCAL_VARS + NUM_TIMERS; i++)
- m_anLocalVariables[i] = ReadSaveBuf<int32>(buf);
- m_bCondResult = ReadSaveBuf<bool>(buf);
- m_bIsMissionScript = ReadSaveBuf<bool>(buf);
- m_bSkipWakeTime = ReadSaveBuf<bool>(buf);
+ ReadSaveBuf(&m_anLocalVariables[i], buf);
+ ReadSaveBuf(&m_bCondResult, buf);
+ ReadSaveBuf(&m_bIsMissionScript, buf);
+ ReadSaveBuf(&m_bSkipWakeTime, buf);
SkipSaveBuf(buf, 1);
- m_nWakeTime = ReadSaveBuf<uint32>(buf);
- m_nAndOrState = ReadSaveBuf<uint16>(buf);
- m_bNotFlag = ReadSaveBuf<bool>(buf);
- m_bDeatharrestEnabled = ReadSaveBuf<bool>(buf);
- m_bDeatharrestExecuted = ReadSaveBuf<bool>(buf);
- m_bMissionFlag = ReadSaveBuf<bool>(buf);
+ ReadSaveBuf(&m_nWakeTime, buf);
+ ReadSaveBuf(&m_nAndOrState, buf);
+ ReadSaveBuf(&m_bNotFlag, buf);
+ ReadSaveBuf(&m_bDeatharrestEnabled, buf);
+ ReadSaveBuf(&m_bDeatharrestExecuted, buf);
+ ReadSaveBuf(&m_bMissionFlag, buf);
SkipSaveBuf(buf, 2);
#else
CRunningScript* n = next;
CRunningScript* p = prev;
- *this = ReadSaveBuf<CRunningScript>(buf);
+ ReadSaveBuf(this, buf);
next = n;
prev = p;
#endif
diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp
index 39cfb1d4..5cffe9e4 100644
--- a/src/core/Pools.cpp
+++ b/src/core/Pools.cpp
@@ -9,6 +9,7 @@
#endif
#include "Population.h"
#include "ProjectileInfo.h"
+#include "SaveBuf.h"
#include "Streaming.h"
#include "Wanted.h"
#include "World.h"
@@ -130,14 +131,19 @@ CPools::MakeSureSlotInObjectPoolIsEmpty(int32 slot)
void CPools::LoadVehiclePool(uint8* buf, uint32 size)
{
INITSAVEBUF
- int nNumCars = ReadSaveBuf<int>(buf);
- int nNumBoats = ReadSaveBuf<int>(buf);
+ int nNumCars, nNumBoats;
+ ReadSaveBuf(&nNumCars, buf);
+ ReadSaveBuf(&nNumBoats, buf);
for (int i = 0; i < nNumCars + nNumBoats; i++) {
- uint32 type = ReadSaveBuf<uint32>(buf);
- int16 model = ReadSaveBuf<int16>(buf);
+ uint32 type;
+ int16 model;
+ int32 slot;
+
+ ReadSaveBuf(&type, buf);
+ ReadSaveBuf(&model, buf);
CStreaming::RequestModel(model, STREAMFLAGS_DEPENDENCY);
CStreaming::LoadAllRequestedModels(false);
- int32 slot = ReadSaveBuf<int32>(buf);
+ ReadSaveBuf(&slot, buf);
CVehicle* pVehicle;
#ifdef COMPATIBLE_SAVES
if (type == VEHICLE_TYPE_BOAT)
diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp
index 8f2c1747..77d6cc7f 100644
--- a/src/core/Radar.cpp
+++ b/src/core/Radar.cpp
@@ -16,6 +16,7 @@
#include "Script.h"
#include "TxdStore.h"
#include "World.h"
+#include "SaveBuf.h"
#include "Streaming.h"
#include "SpecialFX.h"
@@ -1055,7 +1056,7 @@ INITSAVEBUF
CheckSaveHeader(buf, 'R', 'D', 'R', '\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUMRADARBLIPS; i++)
- ms_RadarTrace[i] = ReadSaveBuf<sRadarTrace>(buf);
+ ReadSaveBuf(&ms_RadarTrace[i], buf);
VALIDATESAVEBUF(size);
}
diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp
index cdae85e1..107b1db8 100644
--- a/src/core/Zones.cpp
+++ b/src/core/Zones.cpp
@@ -8,6 +8,7 @@
#include "Text.h"
#include "World.h"
#include "Timer.h"
+#include "SaveBuf.h"
eLevelName CTheZones::m_CurrLevel;
CZone *CTheZones::m_pPlayersZone;
@@ -696,17 +697,18 @@ void
CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
{
INITSAVEBUF
- int i;
+ int32 i;
CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE);
- m_pPlayersZone = GetPointerForZoneIndex(ReadSaveBuf<int32>(buffer));
- m_CurrLevel = ReadSaveBuf<eLevelName>(buffer);
- FindIndex = ReadSaveBuf<int16>(buffer);
- ReadSaveBuf<int16>(buffer);
+ ReadSaveBuf(&i, buffer);
+ m_pPlayersZone = GetPointerForZoneIndex(i);
+ ReadSaveBuf(&m_CurrLevel, buffer);
+ ReadSaveBuf(&FindIndex, buffer);
+ SkipSaveBuf(buffer, 2);
for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){
- ZoneArray[i] = ReadSaveBuf<CZone>(buffer);
+ ReadSaveBuf(&ZoneArray[i], buffer);
ZoneArray[i].child = GetPointerForZoneIndex((uintptr)ZoneArray[i].child);
ZoneArray[i].parent = GetPointerForZoneIndex((uintptr)ZoneArray[i].parent);
@@ -714,13 +716,13 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
}
for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++)
- ZoneInfoArray[i] = ReadSaveBuf<CZoneInfo>(buffer);
+ ReadSaveBuf(&ZoneInfoArray[i], buffer);
- TotalNumberOfZones = ReadSaveBuf<int16>(buffer);
- TotalNumberOfZoneInfos = ReadSaveBuf<int16>(buffer);
+ ReadSaveBuf(&TotalNumberOfZones, buffer);
+ ReadSaveBuf(&TotalNumberOfZoneInfos, buffer);
for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){
- MapZoneArray[i] = ReadSaveBuf<CZone>(buffer);
+ ReadSaveBuf(&MapZoneArray[i], buffer);
/*
The call of GetPointerForZoneIndex is wrong, as it is
@@ -736,10 +738,10 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size)
}
for(i = 0; i < ARRAY_SIZE(AudioZoneArray); i++)
- AudioZoneArray[i] = ReadSaveBuf<int16>(buffer);
+ ReadSaveBuf(&AudioZoneArray[i], buffer);
- TotalNumberOfMapZones = ReadSaveBuf<uint16>(buffer);
- NumberOfAudioZones = ReadSaveBuf<uint16>(buffer);
+ ReadSaveBuf(&TotalNumberOfMapZones, buffer);
+ ReadSaveBuf(&NumberOfAudioZones, buffer);
VALIDATESAVEBUF(size)
}
diff --git a/src/core/common.h b/src/core/common.h
index e5077611..7207f08d 100644
--- a/src/core/common.h
+++ b/src/core/common.h
@@ -393,173 +393,3 @@ template<int s, int t> struct check_size {
#define STR(x) STRINGIFY(x)
#define CONCAT_(x,y) 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*, ...);
diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp
index 9d5bf73c..a7f4bd45 100644
--- a/src/entities/Entity.cpp
+++ b/src/entities/Entity.cpp
@@ -22,6 +22,7 @@
#include "MemoryHeap.h"
#include "Bones.h"
#include "Debug.h"
+#include "SaveBuf.h"
int gBuildings;
@@ -753,7 +754,8 @@ CEntity::SaveEntityFlags(uint8*& buf)
void
CEntity::LoadEntityFlags(uint8*& buf)
{
- uint32 tmp = ReadSaveBuf<uint32>(buf);
+ uint32 tmp;
+ ReadSaveBuf(&tmp, buf);
m_type = (tmp & ((BIT(3) - 1)));
m_status = ((tmp >> 3) & (BIT(5) - 1));
@@ -784,7 +786,7 @@ CEntity::LoadEntityFlags(uint8*& buf)
bZoneCulled = !!(tmp & BIT(30));
bZoneCulled2 = !!(tmp & BIT(31));
- tmp = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&tmp, buf);
bRemoveFromWorld = !!(tmp & BIT(0));
bHasHitWall = !!(tmp & BIT(1));
diff --git a/src/extras/debugmenu.h b/src/extras/debugmenu.h
index c2198aca..45b65d04 100644
--- a/src/extras/debugmenu.h
+++ b/src/extras/debugmenu.h
@@ -2,6 +2,120 @@
#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);
struct Menu;
diff --git a/src/peds/Gangs.cpp b/src/peds/Gangs.cpp
index 8859e61e..be29379c 100644
--- a/src/peds/Gangs.cpp
+++ b/src/peds/Gangs.cpp
@@ -3,6 +3,7 @@
#include "ModelIndices.h"
#include "Gangs.h"
#include "Weapon.h"
+#include "SaveBuf.h"
CGangInfo CGangs::Gang[NUM_GANGS];
@@ -72,6 +73,6 @@ INITSAVEBUF
CheckSaveHeader(buf, 'G','N','G','\0', size - SAVE_HEADER_SIZE);
for (int i = 0; i < NUM_GANGS; i++)
- Gang[i] = ReadSaveBuf<CGangInfo>(buf);
+ ReadSaveBuf(&Gang[i], buf);
VALIDATESAVEBUF(size);
}
diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp
index 5b25c92e..977766c3 100644
--- a/src/peds/Ped.cpp
+++ b/src/peds/Ped.cpp
@@ -32,6 +32,7 @@
#include "Floater.h"
#include "Range2D.h"
#include "Wanted.h"
+#include "SaveBuf.h"
CPed *gapTempPedList[50];
uint16 gnNumTempPedList;
diff --git a/src/peds/PedType.cpp b/src/peds/PedType.cpp
index bacb1a78..dcd4c717 100644
--- a/src/peds/PedType.cpp
+++ b/src/peds/PedType.cpp
@@ -3,6 +3,7 @@
#include "General.h"
#include "FileMgr.h"
#include "PedType.h"
+#include "SaveBuf.h"
CPedType *CPedType::ms_apPedType[NUM_PEDTYPES];
CPedStats *CPedStats::ms_apPedStats[NUM_PEDSTATS];
@@ -201,7 +202,7 @@ INITSAVEBUF
CheckSaveHeader(buf, 'P', 'T', 'P', '\0', size - SAVE_HEADER_SIZE);
for(int i = 0; i < NUM_PEDTYPES; i++)
- *ms_apPedType[i] = ReadSaveBuf<CPedType>(buf);
+ ReadSaveBuf(ms_apPedType[i], buf);
VALIDATESAVEBUF(size)
}
diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp
index 46578486..a67e2abc 100644
--- a/src/peds/PlayerPed.cpp
+++ b/src/peds/PlayerPed.cpp
@@ -16,6 +16,7 @@
#include "Pools.h"
#include "Darkel.h"
#include "CarCtrl.h"
+#include "SaveBuf.h"
#define PAD_MOVE_TO_GAME_WORLD_MOVE 60.0f
diff --git a/src/render/Console.h b/src/render/Console.h
index b4fa60c4..9f22236f 100644
--- a/src/render/Console.h
+++ b/src/render/Console.h
@@ -23,3 +23,5 @@ public:
};
extern CConsole TheConsole;
+
+void cprintf(char*, ...); \ No newline at end of file
diff --git a/src/render/Particle.cpp b/src/render/Particle.cpp
index 07e80abe..c971955f 100644
--- a/src/render/Particle.cpp
+++ b/src/render/Particle.cpp
@@ -14,6 +14,7 @@
#include "ParticleObject.h"
#include "Particle.h"
#include "soundlist.h"
+#include "debugmenu.h"
#define MAX_PARTICLES_ON_SCREEN (1000)
diff --git a/src/save/SaveBuf.h b/src/save/SaveBuf.h
new file mode 100644
index 00000000..ed48a650
--- /dev/null
+++ b/src/save/SaveBuf.h
@@ -0,0 +1,64 @@
+#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 \ No newline at end of file
diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp
index c29c0536..7be6ed0b 100644
--- a/src/vehicles/Automobile.cpp
+++ b/src/vehicles/Automobile.cpp
@@ -45,6 +45,7 @@
#include "Object.h"
#include "Automobile.h"
#include "Wanted.h"
+#include "SaveBuf.h"
bool bAllCarCheat; // unused
@@ -4724,7 +4725,7 @@ void
CAutomobile::Load(uint8*& buf)
{
CVehicle::Load(buf);
- Damage = ReadSaveBuf<CDamageManager>(buf);
+ ReadSaveBuf(&Damage, buf);
SkipSaveBuf(buf, 800 - sizeof(CDamageManager));
SetupDamageAfterLoad();
}
diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp
index 4bbbadbd..bbe17f0b 100644
--- a/src/vehicles/Boat.cpp
+++ b/src/vehicles/Boat.cpp
@@ -19,6 +19,7 @@
#include "Pools.h"
#include "Pad.h"
#include "Boat.h"
+#include "SaveBuf.h"
#define INVALID_ORIENTATION (-9999.99f)
diff --git a/src/vehicles/CarGen.cpp b/src/vehicles/CarGen.cpp
index 7524444b..22b2fc60 100644
--- a/src/vehicles/CarGen.cpp
+++ b/src/vehicles/CarGen.cpp
@@ -13,6 +13,7 @@
#include "Timer.h"
#include "Vehicle.h"
#include "World.h"
+#include "SaveBuf.h"
uint8 CTheCarGenerators::ProcessCounter;
uint32 CTheCarGenerators::NumOfCarGenerators;
@@ -254,14 +255,17 @@ void CTheCarGenerators::LoadAllCarGenerators(uint8* buffer, uint32 size)
Init();
INITSAVEBUF
CheckSaveHeader(buffer, 'C','G','N','\0', size - SAVE_HEADER_SIZE);
- assert(ReadSaveBuf<uint32>(buffer) == nGeneralDataSize);
- NumOfCarGenerators = ReadSaveBuf<uint32>(buffer);
- CurrentActiveCount = ReadSaveBuf<uint32>(buffer);
- ProcessCounter = ReadSaveBuf<uint8>(buffer);
- GenerateEvenIfPlayerIsCloseCounter = ReadSaveBuf<uint8>(buffer);
- ReadSaveBuf<int16>(buffer); // alignment
- assert(ReadSaveBuf<uint32>(buffer) == sizeof(CarGeneratorArray));
+ uint32 tmp;
+ ReadSaveBuf(&tmp, buffer);
+ assert(tmp == nGeneralDataSize);
+ ReadSaveBuf(&NumOfCarGenerators, buffer);
+ ReadSaveBuf(&CurrentActiveCount, buffer);
+ ReadSaveBuf(&ProcessCounter, buffer);
+ ReadSaveBuf(&GenerateEvenIfPlayerIsCloseCounter, buffer);
+ SkipSaveBuf(buffer, 2);
+ ReadSaveBuf(&tmp, buffer);
+ assert(tmp == sizeof(CarGeneratorArray));
for (int i = 0; i < NUM_CARGENS; i++)
- CarGeneratorArray[i] = ReadSaveBuf<CCarGenerator>(buffer);
+ ReadSaveBuf(&CarGeneratorArray[i], buffer);
VALIDATESAVEBUF(size)
}
diff --git a/src/vehicles/Cranes.cpp b/src/vehicles/Cranes.cpp
index 0c7913af..0f1b8b4c 100644
--- a/src/vehicles/Cranes.cpp
+++ b/src/vehicles/Cranes.cpp
@@ -11,6 +11,7 @@
#include "Replay.h"
#include "Object.h"
#include "World.h"
+#include "SaveBuf.h"
#define MAX_DISTANCE_TO_FIND_CRANE (10.0f)
#define CRANE_UPDATE_RADIUS (300.0f)
@@ -653,10 +654,10 @@ void CCranes::Load(uint8* buf, uint32 size)
{
INITSAVEBUF
- NumCranes = ReadSaveBuf<int32>(buf);
- CarsCollectedMilitaryCrane = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&NumCranes, buf);
+ ReadSaveBuf(&CarsCollectedMilitaryCrane, buf);
for (int i = 0; i < NUM_CRANES; i++)
- aCranes[i] = ReadSaveBuf<CCrane>(buf);
+ ReadSaveBuf(&aCranes[i], buf);
for (int i = 0; i < NUM_CRANES; i++) {
CCrane *pCrane = &aCranes[i];
if (pCrane->m_pCraneEntity != nil)
diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp
index fee2eb10..86159c4e 100644
--- a/src/vehicles/Vehicle.cpp
+++ b/src/vehicles/Vehicle.cpp
@@ -18,6 +18,7 @@
#include "Radar.h"
#include "Fire.h"
#include "Darkel.h"
+#include "SaveBuf.h"
bool CVehicle::bWheelsOnlyCheat;
bool CVehicle::bAllDodosCheat;
@@ -1323,43 +1324,44 @@ CVehicle::Load(uint8*& buf)
{
CMatrix tmp;
SkipSaveBuf(buf, 4);
- tmp.GetRight().x = ReadSaveBuf<float>(buf);
- tmp.GetRight().y = ReadSaveBuf<float>(buf);
- tmp.GetRight().z = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&tmp.GetRight().x, buf);
+ ReadSaveBuf(&tmp.GetRight().y, buf);
+ ReadSaveBuf(&tmp.GetRight().z, buf);
SkipSaveBuf(buf, 4);
- tmp.GetForward().x = ReadSaveBuf<float>(buf);
- tmp.GetForward().y = ReadSaveBuf<float>(buf);
- tmp.GetForward().z = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&tmp.GetForward().x, buf);
+ ReadSaveBuf(&tmp.GetForward().y, buf);
+ ReadSaveBuf(&tmp.GetForward().z, buf);
SkipSaveBuf(buf, 4);
- tmp.GetUp().x = ReadSaveBuf<float>(buf);
- tmp.GetUp().y = ReadSaveBuf<float>(buf);
- tmp.GetUp().z = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&tmp.GetUp().x, buf);
+ ReadSaveBuf(&tmp.GetUp().y, buf);
+ ReadSaveBuf(&tmp.GetUp().z, buf);
SkipSaveBuf(buf, 4);
- tmp.GetPosition().x = ReadSaveBuf<float>(buf);
- tmp.GetPosition().y = ReadSaveBuf<float>(buf);
- tmp.GetPosition().z = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&tmp.GetPosition().x, buf);
+ ReadSaveBuf(&tmp.GetPosition().y, buf);
+ ReadSaveBuf(&tmp.GetPosition().z, buf);
m_matrix = tmp;
SkipSaveBuf(buf, 16);
LoadEntityFlags(buf);
SkipSaveBuf(buf, 212);
AutoPilot.Load(buf);
- m_currentColour1 = ReadSaveBuf<int8>(buf);
- m_currentColour2 = ReadSaveBuf<int8>(buf);
+ ReadSaveBuf(&m_currentColour1, buf);
+ ReadSaveBuf(&m_currentColour2, buf);
SkipSaveBuf(buf, 2);
- m_nAlarmState = ReadSaveBuf<int16>(buf);
+ ReadSaveBuf(&m_nAlarmState, buf);
SkipSaveBuf(buf, 43);
- m_nNumMaxPassengers = ReadSaveBuf<int8>(buf);
+ ReadSaveBuf(&m_nNumMaxPassengers, buf);
SkipSaveBuf(buf, 2);
- field_1D0[0] = ReadSaveBuf<float>(buf);
- field_1D0[1] = ReadSaveBuf<float>(buf);
- field_1D0[2] = ReadSaveBuf<float>(buf);
- field_1D0[3] = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&field_1D0[0], buf);
+ ReadSaveBuf(&field_1D0[1], buf);
+ ReadSaveBuf(&field_1D0[2], buf);
+ ReadSaveBuf(&field_1D0[3], buf);
SkipSaveBuf(buf, 8);
- m_fSteerAngle = ReadSaveBuf<float>(buf);
- m_fGasPedal = ReadSaveBuf<float>(buf);
- m_fBrakePedal = ReadSaveBuf<float>(buf);
- VehicleCreatedBy = ReadSaveBuf<uint8>(buf);
- uint8 flags = ReadSaveBuf<uint8>(buf);
+ ReadSaveBuf(&m_fSteerAngle, buf);
+ ReadSaveBuf(&m_fGasPedal, buf);
+ ReadSaveBuf(&m_fBrakePedal, buf);
+ ReadSaveBuf(&VehicleCreatedBy, buf);
+ uint8 flags;
+ ReadSaveBuf(&flags, buf);
bIsLawEnforcer = !!(flags & BIT(0));
bIsLocked = !!(flags & BIT(3));
bEngineOn = !!(flags & BIT(4));
@@ -1367,16 +1369,17 @@ CVehicle::Load(uint8*& buf)
bLightsOn = !!(flags & BIT(6));
bFreebies = !!(flags & BIT(7));
SkipSaveBuf(buf, 10);
- m_fHealth = ReadSaveBuf<float>(buf);
- m_nCurrentGear = ReadSaveBuf<uint8>(buf);
+ ReadSaveBuf(&m_fHealth, buf);
+ ReadSaveBuf(&m_nCurrentGear, buf);
SkipSaveBuf(buf, 3);
- m_fChangeGearTime = ReadSaveBuf<float>(buf);
+ ReadSaveBuf(&m_fChangeGearTime, buf);
SkipSaveBuf(buf, 4);
- m_nTimeOfDeath = ReadSaveBuf<uint32>(buf);
+ ReadSaveBuf(&m_nTimeOfDeath, buf);
SkipSaveBuf(buf, 2);
- m_nBombTimer = ReadSaveBuf<int16>(buf);
+ ReadSaveBuf(&m_nBombTimer, buf);
SkipSaveBuf(buf, 12);
- m_nDoorLock = (eCarLock)ReadSaveBuf<int8>(buf);
+ ReadSaveBuf(&flags, buf);
+ m_nDoorLock = (eCarLock)flags;
SkipSaveBuf(buf, 99);
}
#endif
diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp
index b3909a08..b4d04a4b 100644
--- a/src/weapons/Weapon.cpp
+++ b/src/weapons/Weapon.cpp
@@ -30,6 +30,7 @@
#include "WaterLevel.h"
#include "WeaponInfo.h"
#include "World.h"
+#include "SaveBuf.h"
uint16 gReloadSampleTime[WEAPONTYPE_LAST_WEAPONTYPE] =
{