Skip to content

Commit

Permalink
hexen: Fix wrong save being deleted
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikeday0 committed Sep 14, 2024
1 parent 6e5c5b4 commit b3430ef
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/hexen/sv_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ----------------------------------------------

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand Down

0 comments on commit b3430ef

Please sign in to comment.