From b3430efc074ab14bf8486646c0807ea2e1274fa2 Mon Sep 17 00:00:00 2001 From: Michael Day Date: Sat, 14 Sep 2024 15:13:56 -0400 Subject: [PATCH 1/2] hexen: Fix wrong save being deleted If a save occurs on pages 1, 2 or 3, it has the potential to delete the save in the corresponding slot on pages 2, 4 or 6. --- src/hexen/sv_save.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/hexen/sv_save.c b/src/hexen/sv_save.c index d05e10a0f6..79b2b13f62 100644 --- a/src/hexen/sv_save.c +++ b/src/hexen/sv_save.c @@ -132,6 +132,7 @@ static void SV_WriteByte(byte val); static void SV_WriteWord(unsigned short val); static void SV_WriteLong(unsigned int val); static void SV_WritePtr(void *ptr); +static void ClearSaveSlot(int slot); // [crispy] // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -2028,7 +2029,7 @@ void SV_SaveGame(int slot, const char *description) SV_SaveMap(true); // true = save player info // Clear all save files at destination slot - SV_ClearSaveSlot(slot); + ClearSaveSlot(slot); // Copy base slot to destination slot CopySaveSlot(BASE_SLOT, slot); @@ -3279,17 +3280,12 @@ static void AssertSegment(gameArchiveSegment_t segType) // //========================================================================== -void SV_ClearSaveSlot(int slot) +// [crispy] Add wrapper to handle multiple save pages +static void ClearSaveSlot(int slot) { int i; char fileName[100]; - // [crispy] get expanded save slot number - if (slot != BASE_SLOT && slot != REBORN_SLOT) - { - slot += savepage * 10; - } - for (i = 0; i < MAX_MAPS; i++) { M_snprintf(fileName, sizeof(fileName), @@ -3300,6 +3296,16 @@ void SV_ClearSaveSlot(int slot) M_remove(fileName); } +void SV_ClearSaveSlot(int slot) +{ + if (slot != BASE_SLOT && slot != REBORN_SLOT) + { + slot += savepage * 10; + } + + ClearSaveSlot(slot); +} + //========================================================================== // // CopySaveSlot From 05a92f4e86dab45dce245822b9b366fe2880f372 Mon Sep 17 00:00:00 2001 From: Michael Day Date: Sun, 15 Sep 2024 21:57:22 -0400 Subject: [PATCH 2/2] hexen: Refactor savefile page handling --- src/hexen/g_game.c | 6 ++++-- src/hexen/mn_menu.c | 4 +++- src/hexen/sv_save.c | 30 ++---------------------------- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/hexen/g_game.c b/src/hexen/g_game.c index f7177b8267..6adb44f461 100644 --- a/src/hexen/g_game.c +++ b/src/hexen/g_game.c @@ -2094,7 +2094,8 @@ void G_LoadGame(int slot) void G_DoLoadGame(void) { gameaction = ga_nothing; - SV_LoadGame(GameLoadSlot); + // [crispy] support multiple pages of saves + SV_LoadGame(GameLoadSlot + savepage * 10); if (!netgame) { // Copy the base slot to the reborn slot SV_UpdateRebornSlot(); @@ -2127,7 +2128,8 @@ void G_SaveGame(int slot, char *description) void G_DoSaveGame(void) { - SV_SaveGame(savegameslot, savedescription); + // [crispy] support multiple pages of saves + SV_SaveGame(savegameslot + savepage * 10, savedescription); gameaction = ga_nothing; savedescription[0] = 0; P_SetMessage(&players[consoleplayer], TXT_GAMESAVED, true); diff --git a/src/hexen/mn_menu.c b/src/hexen/mn_menu.c index 492f39292e..e09a0b929a 100644 --- a/src/hexen/mn_menu.c +++ b/src/hexen/mn_menu.c @@ -181,6 +181,8 @@ int InfoType; int messageson = true; boolean mn_SuicideConsole; +int savepage; // [crispy] support 8 pages of savegames + // PRIVATE DATA DEFINITIONS ------------------------------------------------ static int FontABaseLump; @@ -1263,7 +1265,7 @@ static void SCDeleteGame(int option) return; } - SV_ClearSaveSlot(option); + SV_ClearSaveSlot(option + savepage * 10); CurrentMenu->oldItPos = CurrentItPos; MN_LoadSlotText(); BorderNeedRefresh = true; diff --git a/src/hexen/sv_save.c b/src/hexen/sv_save.c index 79b2b13f62..08b6074e87 100644 --- a/src/hexen/sv_save.c +++ b/src/hexen/sv_save.c @@ -132,7 +132,6 @@ static void SV_WriteByte(byte val); static void SV_WriteWord(unsigned short val); static void SV_WriteLong(unsigned int val); static void SV_WritePtr(void *ptr); -static void ClearSaveSlot(int slot); // [crispy] // EXTERNAL DATA DECLARATIONS ---------------------------------------------- @@ -144,8 +143,6 @@ char *SavePath = DEFAULT_SAVEPATH; int vanilla_savegame_limit = 1; -int savepage; // [crispy] support 8 pages of savegames - // PRIVATE DATA DEFINITIONS ------------------------------------------------ static int MobjCount; @@ -1981,12 +1978,6 @@ void SV_SaveGame(int slot, const char *description) char versionText[HXS_VERSION_TEXT_LENGTH]; unsigned int i; - // [crispy] get expanded save slot number - if (slot != BASE_SLOT && slot != REBORN_SLOT) - { - slot += savepage * 10; - } - // Open the output file M_snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, BASE_SLOT); SV_OpenWrite(fileName); @@ -2029,7 +2020,7 @@ void SV_SaveGame(int slot, const char *description) SV_SaveMap(true); // true = save player info // Clear all save files at destination slot - ClearSaveSlot(slot); + SV_ClearSaveSlot(slot); // Copy base slot to destination slot CopySaveSlot(BASE_SLOT, slot); @@ -2093,12 +2084,6 @@ void SV_LoadGame(int slot) p = &players[consoleplayer]; // [crispy] - // [crispy] get expanded save slot number - if (slot != BASE_SLOT && slot != REBORN_SLOT) - { - slot += savepage * 10; - } - // Copy all needed save files to the base slot if (slot != BASE_SLOT) { @@ -3280,8 +3265,7 @@ static void AssertSegment(gameArchiveSegment_t segType) // //========================================================================== -// [crispy] Add wrapper to handle multiple save pages -static void ClearSaveSlot(int slot) +void SV_ClearSaveSlot(int slot) { int i; char fileName[100]; @@ -3296,16 +3280,6 @@ static void ClearSaveSlot(int slot) M_remove(fileName); } -void SV_ClearSaveSlot(int slot) -{ - if (slot != BASE_SLOT && slot != REBORN_SLOT) - { - slot += savepage * 10; - } - - ClearSaveSlot(slot); -} - //========================================================================== // // CopySaveSlot