Add some comments, write an empty string instead of a boolean determining if the bot skin exists or not.

I was a little scared of doing this at first, but after a bit of thought & some testing that it'll be fine.
This commit is contained in:
Sally Coolatta 2021-05-07 20:13:16 -04:00
parent a583027006
commit d136c60a3f
3 changed files with 18 additions and 36 deletions

View file

@ -4647,20 +4647,14 @@ void G_SaveGameOver(UINT32 slot, boolean modifylives)
if (backwardsCompat == NEWSKINSAVES) // New save, read skin names
#endif
{
boolean haveBot = false;
char ourSkinName[SKINNAMESIZE+1];
char botSkinName[SKINNAMESIZE+1];
READSTRINGN(save_p, ourSkinName, SKINNAMESIZE);
CHECKPOS
haveBot = (boolean)READUINT8(save_p);
CHECKPOS
if (haveBot == true)
{
char botSkinName[SKINNAMESIZE+1];
READSTRINGN(save_p, botSkinName, SKINNAMESIZE);
CHECKPOS
}
READSTRINGN(save_p, botSkinName, SKINNAMESIZE);
CHECKPOS
}
WRITEUINT8(save_p, numgameovers);

View file

@ -8671,8 +8671,8 @@ static void M_ReadSavegameInfo(UINT32 slot)
else
#endif
{
boolean haveBot = false;
char ourSkinName[SKINNAMESIZE+1];
char botSkinName[SKINNAMESIZE+1];
CHECKPOS
READSTRINGN(sav_p, ourSkinName, SKINNAMESIZE);
@ -8683,20 +8683,12 @@ static void M_ReadSavegameInfo(UINT32 slot)
BADSAVE
CHECKPOS
haveBot = (boolean)READUINT8(sav_p);
READSTRINGN(sav_p, botSkinName, SKINNAMESIZE);
savegameinfo[slot].botskin = (R_SkinAvailable(botSkinName) + 1);
if (haveBot == true)
{
char botSkinName[SKINNAMESIZE+1];
CHECKPOS
READSTRINGN(sav_p, botSkinName, SKINNAMESIZE);
savegameinfo[slot].botskin = (R_SkinAvailable(botSkinName) + 1);
if (savegameinfo[slot].botskin-1 >= numskins
|| !R_SkinUsable(-1, savegameinfo[slot].botskin-1))
BADSAVE
}
if (savegameinfo[slot].botskin-1 >= numskins
|| !R_SkinUsable(-1, savegameinfo[slot].botskin-1))
BADSAVE
}
CHECKPOS

View file

@ -69,19 +69,22 @@ static inline void P_ArchivePlayer(void)
pllives = startinglivesbalance[numgameovers]; // has less than that.
#ifdef NEWSKINSAVES
// Write a specific value into the old skininfo location.
// If we read something other than this, it's an older save file that used skin numbers.
WRITEUINT16(save_p, NEWSKINSAVES);
#endif
// Write skin names, so that loading skins in different orders
// doesn't change who the save file is for!
WRITESTRINGN(save_p, skins[player->skin].name, SKINNAMESIZE);
if (botskin != 0)
{
WRITEUINT8(save_p, 1);
WRITESTRINGN(save_p, skins[botskin-1].name, SKINNAMESIZE);
}
else
{
WRITEUINT8(save_p, 0);
WRITESTRINGN(save_p, "\0", SKINNAMESIZE);
}
WRITEUINT8(save_p, numgameovers);
@ -97,28 +100,21 @@ static inline void P_UnArchivePlayer(void)
if (backwardsCompat != NEWSKINSAVES)
{
// Backwards compat
// This is an older save file, which used direct skin numbers.
savedata.skin = backwardsCompat & ((1<<5) - 1);
savedata.botskin = backwardsCompat >> 5;
}
else
#endif
{
boolean haveBot = false;
char ourSkinName[SKINNAMESIZE+1];
char botSkinName[SKINNAMESIZE+1];
READSTRINGN(save_p, ourSkinName, SKINNAMESIZE);
savedata.skin = R_SkinAvailable(ourSkinName);
haveBot = (boolean)READUINT8(save_p);
if (haveBot == true)
{
char botSkinName[SKINNAMESIZE+1];
READSTRINGN(save_p, botSkinName, SKINNAMESIZE);
savedata.botskin = R_SkinAvailable(botSkinName) + 1;
}
READSTRINGN(save_p, botSkinName, SKINNAMESIZE);
savedata.botskin = R_SkinAvailable(botSkinName) + 1;
}
savedata.numgameovers = READUINT8(save_p);