From 3a11bbb6d4a823db223667aee9e3016e4513c404 Mon Sep 17 00:00:00 2001 From: Jonathan Haas Date: Wed, 7 Oct 2015 20:53:55 +0200 Subject: [PATCH] Recalculate peep count after loading a save --- src/game.c | 20 +++++++++++++++++++- src/game.h | 1 + src/scenario.c | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/game.c b/src/game.c index b55434f975..00c414563b 100644 --- a/src/game.c +++ b/src/game.c @@ -775,15 +775,33 @@ int game_load_sv6(SDL_RWops* rw) return 0;//This never gets called } - // The rest is the same as in scenario load and play + // The rest is the same as in scenario_load reset_loaded_objects(); map_update_tile_pointers(); reset_0x69EBE4(); openrct2_reset_object_tween_locations(); game_convert_strings_to_utf8(); + game_fix_save_vars(); // OpenRCT2 fix broken save games + return 1; } +// 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 game_fix_save_vars() { + + // Recalculates peep count after loading a save to fix corrupted files + rct_peep* peep; + uint16 spriteIndex; + uint16 peepCount = 0; + FOR_ALL_GUESTS(spriteIndex, peep) { + if(!peep->outside_of_park) + peepCount++; + } + + RCT2_GLOBAL(RCT2_ADDRESS_GUESTS_IN_PARK, uint16) = peepCount; +} + // Load game state for multiplayer int game_load_network(SDL_RWops* rw) { diff --git a/src/game.h b/src/game.h index 6817ab3e8d..115030495e 100644 --- a/src/game.h +++ b/src/game.h @@ -140,5 +140,6 @@ void rct2_exit_reason(rct_string_id title, rct_string_id body); void game_autosave(); void game_convert_strings_to_utf8(); void game_convert_strings_to_rct2(rct_s6_data *s6); +void game_fix_save_vars(); #endif diff --git a/src/scenario.c b/src/scenario.c index b1b7ae7a45..daa7af63a4 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -204,6 +204,8 @@ int scenario_load(const char *path) reset_0x69EBE4(); openrct2_reset_object_tween_locations(); game_convert_strings_to_utf8(); + game_fix_save_vars(); // OpenRCT2 fix broken save games + return 1; }