From af7573ddbe38e0aaa485877e7ccb2e704b0f5a7f Mon Sep 17 00:00:00 2001 From: erorcun Date: Sat, 26 Jun 2021 00:25:59 +0300 Subject: Revert "Redo ReadSaveBuf + common.h cleanup" This reverts commit 2b67aba94cb6448fb24c869559465eddf2bad069. --- src/control/AutoPilot.cpp | 54 +++++++++++++++--------------- src/control/Garages.cpp | 28 +++++++--------- src/control/Phones.cpp | 11 +++--- src/control/Pickups.cpp | 9 +++-- src/control/Restart.cpp | 32 +++++++++--------- src/control/Script5.cpp | 85 +++++++++++++++++++++-------------------------- 6 files changed, 99 insertions(+), 120 deletions(-) (limited to 'src/control') diff --git a/src/control/AutoPilot.cpp b/src/control/AutoPilot.cpp index 22a73179..77cbd0b4 100644 --- a/src/control/AutoPilot.cpp +++ b/src/control/AutoPilot.cpp @@ -5,7 +5,6 @@ #include "CarCtrl.h" #include "Curves.h" #include "PathFind.h" -#include "SaveBuf.h" void CAutoPilot::ModifySpeed(float speed) { @@ -89,40 +88,39 @@ void CAutoPilot::Save(uint8*& buf) void CAutoPilot::Load(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_nCurrentRouteNode = ReadSaveBuf(buf); + m_nNextRouteNode = ReadSaveBuf(buf); + m_nPrevRouteNode = ReadSaveBuf(buf); + m_nTimeEnteredCurve = ReadSaveBuf(buf); + m_nTimeToSpendOnCurrentCurve = ReadSaveBuf(buf); + m_nCurrentPathNodeInfo = ReadSaveBuf(buf); + m_nNextPathNodeInfo = ReadSaveBuf(buf); + m_nPreviousPathNodeInfo = ReadSaveBuf(buf); + m_nAntiReverseTimer = ReadSaveBuf(buf); + m_nTimeToStartMission = ReadSaveBuf(buf); + m_nPreviousDirection = ReadSaveBuf(buf); + m_nCurrentDirection = ReadSaveBuf(buf); + m_nNextDirection = ReadSaveBuf(buf); + m_nCurrentLane = ReadSaveBuf(buf); + m_nNextLane = ReadSaveBuf(buf); + m_nDrivingStyle = ReadSaveBuf(buf); + m_nCarMission = ReadSaveBuf(buf); + m_nTempAction = ReadSaveBuf(buf); + m_nTimeTempAction = ReadSaveBuf(buf); + m_fMaxTrafficSpeed = ReadSaveBuf(buf); + m_nCruiseSpeed = ReadSaveBuf(buf); + uint8 flags = ReadSaveBuf(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); - ReadSaveBuf(&m_vecDestinationCoors.x, buf); - ReadSaveBuf(&m_vecDestinationCoors.y, buf); - ReadSaveBuf(&m_vecDestinationCoors.z, buf); + m_vecDestinationCoors.x = ReadSaveBuf(buf); + m_vecDestinationCoors.y = ReadSaveBuf(buf); + m_vecDestinationCoors.z = ReadSaveBuf(buf); SkipSaveBuf(buf, 32); - ReadSaveBuf(&m_nPathFindNodesCount, buf); + m_nPathFindNodesCount = ReadSaveBuf(buf); SkipSaveBuf(buf, 6); } #endif \ No newline at end of file diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 3410c881..792d3bda 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -24,7 +24,6 @@ #include "Vehicle.h" #include "Wanted.h" #include "World.h" -#include "SaveBuf.h" #define CRUSHER_GARAGE_X1 (1135.5f) #define CRUSHER_GARAGE_Y1 (57.0f) @@ -2362,25 +2361,22 @@ void CGarages::Load(uint8* buf, uint32 size) assert(size == 5484); #endif CloseHideOutGaragesBeforeSave(); - 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); + NumGarages = ReadSaveBuf(buf); + BombsAreFree = ReadSaveBuf(buf); + RespraysAreFree = ReadSaveBuf(buf); + CarsCollected = ReadSaveBuf(buf); + BankVansCollected = ReadSaveBuf(buf); + PoliceCarsCollected = ReadSaveBuf(buf); for (int i = 0; i < TOTAL_COLLECTCARS_GARAGES; i++) - ReadSaveBuf(&CarTypesCollected[i], buf); - ReadSaveBuf(&LastTimeHelpMessage, buf); + CarTypesCollected[i] = ReadSaveBuf(buf); + LastTimeHelpMessage = ReadSaveBuf(buf); for (int i = 0; i < NUM_GARAGE_STORED_CARS; i++) { - ReadSaveBuf(&aCarsInSafeHouse1[i], buf); - ReadSaveBuf(&aCarsInSafeHouse2[i], buf); - ReadSaveBuf(&aCarsInSafeHouse3[i], buf); + aCarsInSafeHouse1[i] = ReadSaveBuf(buf); + aCarsInSafeHouse2[i] = ReadSaveBuf(buf); + aCarsInSafeHouse3[i] = ReadSaveBuf(buf); } for (int i = 0; i < NUM_GARAGES; i++) { - ReadSaveBuf(&aGarages[i], buf); + aGarages[i] = ReadSaveBuf(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 f9cb1421..ef7ecead 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -13,7 +13,6 @@ #include "RpAnimBlend.h" #include "AnimBlendAssociation.h" #include "soundlist.h" -#include "SaveBuf.h" #ifdef FIX_BUGS #include "Replay.h" #endif @@ -213,9 +212,8 @@ void CPhoneInfo::Load(uint8 *buf, uint32 size) { INITSAVEBUF - int32 max, scriptPhonesMax; - ReadSaveBuf(&max, buf); - ReadSaveBuf(&scriptPhonesMax, buf); + int max = ReadSaveBuf(buf); + int scriptPhonesMax = ReadSaveBuf(buf); #ifdef PEDS_REPORT_CRIMES_ON_PHONE 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 for (int i = 0; i < 50; i++) { - CPhone phoneToLoad; - ReadSaveBuf(&phoneToLoad, buf); + CPhone phoneToLoad = ReadSaveBuf(buf); if (ignoreOtherPhones) continue; @@ -252,7 +249,7 @@ INITSAVEBUF m_nScriptPhonesMax = scriptPhonesMax; for (int i = 0; i < NUMPHONES; i++) { - ReadSaveBuf(&m_aPhones[i], buf); + m_aPhones[i] = ReadSaveBuf(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 10175fba..a1e2a851 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -23,7 +23,6 @@ #ifdef FIX_BUGS #include "Replay.h" #endif -#include "SaveBuf.h" #include "Script.h" #include "Shadows.h" #include "SpecialFX.h" @@ -1000,18 +999,18 @@ CPickups::Load(uint8 *buf, uint32 size) INITSAVEBUF for (int32 i = 0; i < NUMPICKUPS; i++) { - ReadSaveBuf(&aPickUps[i], buf); + aPickUps[i] = ReadSaveBuf(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); } - ReadSaveBuf(&CollectedPickUpIndex, buf); - SkipSaveBuf(buf, 2); + CollectedPickUpIndex = ReadSaveBuf(buf); + ReadSaveBuf(buf); NumMessages = 0; for (uint16 i = 0; i < NUMCOLLECTEDPICKUPS; i++) - ReadSaveBuf(&aPickUpsCollected[i], buf); + aPickUpsCollected[i] = ReadSaveBuf(buf); VALIDATESAVEBUF(size) } diff --git a/src/control/Restart.cpp b/src/control/Restart.cpp index 2f5e3d45..4ca18c3b 100644 --- a/src/control/Restart.cpp +++ b/src/control/Restart.cpp @@ -1,7 +1,6 @@ #include "common.h" #include "Restart.h" -#include "SaveBuf.h" #include "Zones.h" #include "PathFind.h" @@ -174,28 +173,29 @@ INITSAVEBUF CheckSaveHeader(buf, 'R','S','T','\0', size - SAVE_HEADER_SIZE); for (int i = 0; i < NUM_RESTART_POINTS; i++) { - ReadSaveBuf(&HospitalRestartPoints[i], buf); - ReadSaveBuf(&HospitalRestartHeadings[i], buf); + HospitalRestartPoints[i] = ReadSaveBuf(buf); + HospitalRestartHeadings[i] = ReadSaveBuf(buf); } for (int i = 0; i < NUM_RESTART_POINTS; i++) { - ReadSaveBuf(&PoliceRestartPoints[i], buf); - ReadSaveBuf(&PoliceRestartHeadings[i], buf); + PoliceRestartPoints[i] = ReadSaveBuf(buf); + PoliceRestartHeadings[i] = ReadSaveBuf(buf); } - ReadSaveBuf(&NumberOfHospitalRestarts, buf); - ReadSaveBuf(&NumberOfPoliceRestarts, buf); - ReadSaveBuf(&bOverrideRestart, buf); + NumberOfHospitalRestarts = ReadSaveBuf(buf); + NumberOfPoliceRestarts = ReadSaveBuf(buf); + bOverrideRestart = ReadSaveBuf(buf); // skip something unused - SkipSaveBuf(buf, 3); - - ReadSaveBuf(&OverridePosition, buf); - ReadSaveBuf(&OverrideHeading, buf); - ReadSaveBuf(&bFadeInAfterNextDeath, buf); - ReadSaveBuf(&bFadeInAfterNextArrest, buf); - ReadSaveBuf(&OverrideHospitalLevel, buf); - ReadSaveBuf(&OverridePoliceStationLevel, buf); + ReadSaveBuf(buf); + ReadSaveBuf(buf); + + OverridePosition = ReadSaveBuf(buf); + OverrideHeading = ReadSaveBuf(buf); + bFadeInAfterNextDeath = ReadSaveBuf(buf); + bFadeInAfterNextArrest = ReadSaveBuf(buf); + OverrideHospitalLevel = ReadSaveBuf(buf); + OverridePoliceStationLevel = ReadSaveBuf(buf); VALIDATESAVEBUF(size); } diff --git a/src/control/Script5.cpp b/src/control/Script5.cpp index a9aec18e..c83c3edc 100644 --- a/src/control/Script5.cpp +++ b/src/control/Script5.cpp @@ -12,7 +12,6 @@ #include "Pools.h" #include "Population.h" #include "RpAnimBlend.h" -#include "SaveBuf.h" #include "Shadows.h" #include "SpecialFX.h" #include "World.h" @@ -2003,25 +2002,21 @@ void CTheScripts::LoadAllScripts(uint8* buf, uint32 size) Init(); INITSAVEBUF CheckSaveHeader(buf, 'S', 'C', 'R', '\0', size - SAVE_HEADER_SIZE); - uint32 varSpace, type, handle; - uint32 tmp; - - ReadSaveBuf(&varSpace, buf); + uint32 varSpace = ReadSaveBuf(buf); for (uint32 i = 0; i < varSpace; i++) - ReadSaveBuf(&ScriptSpace[i], buf); - ReadSaveBuf(&tmp, buf); - script_assert(tmp == SCRIPT_DATA_SIZE); - ReadSaveBuf(&OnAMissionFlag, buf); + ScriptSpace[i] = ReadSaveBuf(buf); + script_assert(ReadSaveBuf(buf) == SCRIPT_DATA_SIZE); + OnAMissionFlag = ReadSaveBuf(buf); for (uint32 i = 0; i < MAX_NUM_CONTACTS; i++) { - ReadSaveBuf(&OnAMissionForContactFlag[i], buf); - ReadSaveBuf(&BaseBriefIdForContact[i], buf); + OnAMissionForContactFlag[i] = ReadSaveBuf(buf); + BaseBriefIdForContact[i] = ReadSaveBuf(buf); } for (uint32 i = 0; i < MAX_NUM_COLLECTIVES; i++) - ReadSaveBuf(&CollectiveArray[i], buf); - ReadSaveBuf(&NextFreeCollectiveIndex, buf); + CollectiveArray[i] = ReadSaveBuf(buf); + NextFreeCollectiveIndex = ReadSaveBuf(buf); for (uint32 i = 0; i < MAX_NUM_BUILDING_SWAPS; i++) { - ReadSaveBuf(&type, buf); - ReadSaveBuf(&handle, buf); + uint32 type = ReadSaveBuf(buf); + uint32 handle = ReadSaveBuf(buf); switch (type) { case 0: BuildingSwapArray[i].m_pBuilding = nil; @@ -2035,14 +2030,14 @@ INITSAVEBUF default: script_assert(false); } - ReadSaveBuf(&BuildingSwapArray[i].m_nNewModel, buf); - ReadSaveBuf(&BuildingSwapArray[i].m_nOldModel, buf); + BuildingSwapArray[i].m_nNewModel = ReadSaveBuf(buf); + BuildingSwapArray[i].m_nOldModel = ReadSaveBuf(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++) { - ReadSaveBuf(&type, buf); - ReadSaveBuf(&handle, buf); + uint32 type = ReadSaveBuf(buf); + uint32 handle = ReadSaveBuf(buf); switch (type) { case 0: InvisibilitySettingArray[i] = nil; @@ -2065,20 +2060,14 @@ INITSAVEBUF if (InvisibilitySettingArray[i]) InvisibilitySettingArray[i]->bIsVisible = false; } - 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); + script_assert(ReadSaveBuf(buf) == bUsingAMultiScriptFile); + ReadSaveBuf(buf); + ReadSaveBuf(buf); + script_assert(ReadSaveBuf(buf) == MainScriptSize); + script_assert(ReadSaveBuf(buf) == LargestMissionScriptSize); + script_assert(ReadSaveBuf(buf) == NumberOfMissionScripts); + ReadSaveBuf(buf); + uint32 runningScripts = ReadSaveBuf(buf); for (uint32 i = 0; i < runningScripts; i++) StartNewScript(0)->Load(buf); VALIDATESAVEBUF(size) @@ -2126,35 +2115,35 @@ void CRunningScript::Load(uint8*& buf) #ifdef COMPATIBLE_SAVES SkipSaveBuf(buf, 8); for (int i = 0; i < 8; i++) - ReadSaveBuf(&m_abScriptName[i], buf); - ReadSaveBuf(&m_nIp, buf); + m_abScriptName[i] = ReadSaveBuf(buf); + m_nIp = ReadSaveBuf(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++) - ReadSaveBuf(&m_anStack[i], buf); - ReadSaveBuf(&m_nStackPointer, buf); + m_anStack[i] = ReadSaveBuf(buf); + m_nStackPointer = ReadSaveBuf(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++) - ReadSaveBuf(&m_anLocalVariables[i], buf); - ReadSaveBuf(&m_bCondResult, buf); - ReadSaveBuf(&m_bIsMissionScript, buf); - ReadSaveBuf(&m_bSkipWakeTime, buf); + m_anLocalVariables[i] = ReadSaveBuf(buf); + m_bCondResult = ReadSaveBuf(buf); + m_bIsMissionScript = ReadSaveBuf(buf); + m_bSkipWakeTime = ReadSaveBuf(buf); SkipSaveBuf(buf, 1); - ReadSaveBuf(&m_nWakeTime, buf); - ReadSaveBuf(&m_nAndOrState, buf); - ReadSaveBuf(&m_bNotFlag, buf); - ReadSaveBuf(&m_bDeatharrestEnabled, buf); - ReadSaveBuf(&m_bDeatharrestExecuted, buf); - ReadSaveBuf(&m_bMissionFlag, buf); + m_nWakeTime = ReadSaveBuf(buf); + m_nAndOrState = ReadSaveBuf(buf); + m_bNotFlag = ReadSaveBuf(buf); + m_bDeatharrestEnabled = ReadSaveBuf(buf); + m_bDeatharrestExecuted = ReadSaveBuf(buf); + m_bMissionFlag = ReadSaveBuf(buf); SkipSaveBuf(buf, 2); #else CRunningScript* n = next; CRunningScript* p = prev; - ReadSaveBuf(this, buf); + *this = ReadSaveBuf(buf); next = n; prev = p; #endif -- cgit v1.2.3