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 1/5] 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(); From 4e7587db13fa24fe975bc93d8f900a027b372d41 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:26:30 +0300 Subject: [PATCH 2/5] Re-calculate the amount of guests heading to the park on import --- src/openrct2/Game.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 0e3ddf1de1..cb064d33f7 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -345,6 +345,21 @@ void RCT2StringToUTF8Self(char* buffer, size_t length) } } +static void FixGuestsHeadingToParkCount() +{ + uint32_t guestsHeadingToPark = 0; + + for (auto* peep : EntityList()) + { + if (peep->OutsideOfPark && peep->State != PeepState::LeavingPark) + { + guestsHeadingToPark++; + } + } + + gNumGuestsHeadingForPark = guestsHeadingToPark; +} + static void FixGuestCount() { // Recalculates peep count after loading a save to fix corrupted files @@ -454,6 +469,8 @@ static void FixInvalidSurfaces() // For example recalculate guest count by looking at all the guests instead of trusting the value in the file. void GameFixSaveVars() { + FixGuestsHeadingToParkCount(); + FixGuestCount(); FixPeepsWithInvalidRideReference(); From 37bc7238e62f6b4345d1933ff06ee929ce12be9d 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:27:02 +0300 Subject: [PATCH 3/5] Remove unnecessary scope --- src/openrct2/Game.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index cb064d33f7..bffd858984 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -364,13 +364,12 @@ static void FixGuestCount() { // Recalculates peep count after loading a save to fix corrupted files uint32_t guestCount = 0; + + for (auto guest : EntityList()) { - for (auto guest : EntityList()) + if (!guest->OutsideOfPark) { - if (!guest->OutsideOfPark) - { - guestCount++; - } + guestCount++; } } From b43af1cf14ecc2c64fadf1bed37488e3b45646ad 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:28:10 +0300 Subject: [PATCH 4/5] Remove obsolete code in s4 importer --- src/openrct2/rct1/S4Importer.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index d17d7bf052..d8c0ada15d 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2911,15 +2911,6 @@ namespace RCT1 } dst->SetItemFlags(src->GetItemFlags()); - - if (dst->OutsideOfPark && dst->State != PeepState::LeavingPark) - { - IncrementGuestsHeadingForPark(); - } - else - { - IncrementGuestsInPark(); - } } template<> void S4Importer::ImportEntity(const RCT12EntityBase& srcBase) From 897579b5de126997d4eb124727792612094461be 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 15:02:28 +0300 Subject: [PATCH 5/5] Print a warning if there is a disagreement with the imported data --- src/openrct2/Game.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index bffd858984..bed3ce61b7 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -357,6 +357,11 @@ static void FixGuestsHeadingToParkCount() } } + if (gNumGuestsHeadingForPark != guestsHeadingToPark) + { + LOG_WARNING("Corrected bad amount of guests heading to park: %u -> %u", gNumGuestsHeadingForPark, guestsHeadingToPark); + } + gNumGuestsHeadingForPark = guestsHeadingToPark; } @@ -373,6 +378,11 @@ static void FixGuestCount() } } + if (gNumGuestsInPark != guestCount) + { + LOG_WARNING("Corrected bad amount of guests in park: %u -> %u", gNumGuestsInPark, guestCount); + } + gNumGuestsInPark = guestCount; }