From a45d72f5624a7f2aa5df3dcc6165a30aac0a0000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Fri, 20 Oct 2023 14:22:14 +0300 Subject: [PATCH] Extract functions out of GameFixSaveVars --- src/openrct2/Game.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 0defe78448..0e3ddf1de1 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -345,9 +345,7 @@ void RCT2StringToUTF8Self(char* buffer, size_t length) } } -// OpenRCT2 workaround to recalculate some values which are saved redundantly in the save to fix corrupted files. -// For example recalculate guest count by looking at all the guests instead of trusting the value in the file. -void GameFixSaveVars() +static void FixGuestCount() { // Recalculates peep count after loading a save to fix corrupted files uint32_t guestCount = 0; @@ -362,7 +360,10 @@ void GameFixSaveVars() } gNumGuestsInPark = guestCount; +} +static void FixPeepsWithInvalidRideReference() +{ // Peeps to remove have to be cached here, as removing them from within the loop breaks iteration std::vector peepsToRemove; @@ -412,9 +413,13 @@ void GameFixSaveVars() { ptr->Remove(); } +} +static void FixInvalidSurfaces() +{ // Fixes broken saves where a surface element could be null // and broken saves with incorrect invisible map border tiles + for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++) { for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++) @@ -443,6 +448,17 @@ void GameFixSaveVars() } } } +} + +// OpenRCT2 workaround to recalculate some values which are saved redundantly in the save to fix corrupted files. +// For example recalculate guest count by looking at all the guests instead of trusting the value in the file. +void GameFixSaveVars() +{ + FixGuestCount(); + + FixPeepsWithInvalidRideReference(); + + FixInvalidSurfaces(); ResearchFix();