Gamedata: Fix issues with cup windata handling

- G_SaveGameData: correctly increase length of buffer to account for cup name
- G_LoadGameData: digest the cup's associated windata even if it's not loaded
This commit is contained in:
toaster 2023-03-17 13:09:58 +00:00
parent b0a028c756
commit c33ae4ae62

View file

@ -4721,16 +4721,23 @@ void G_LoadGameData(void)
char cupname[16]; char cupname[16];
cupheader_t *cup; cupheader_t *cup;
// Find the relevant cup.
READSTRINGN(save.p, cupname, sizeof(cupname)); READSTRINGN(save.p, cupname, sizeof(cupname));
for (cup = kartcupheaders; cup; cup = cup->next) for (cup = kartcupheaders; cup; cup = cup->next)
{ {
if (strcmp(cup->name, cupname)) if (strcmp(cup->name, cupname))
continue; continue;
break;
}
for (j = 0; j < KARTGP_MAX; j++) // Digest its data...
for (j = 0; j < KARTGP_MAX; j++)
{
rtemp = READUINT8(save.p);
// ...but only record it if we actually found the associated cup.
if (cup)
{ {
rtemp = READUINT8(save.p);
cup->windata[j].best_placement = (rtemp & 0x0F); cup->windata[j].best_placement = (rtemp & 0x0F);
cup->windata[j].best_grade = (rtemp & 0x70)>>4; cup->windata[j].best_grade = (rtemp & 0x70)>>4;
if (rtemp & 0x80) if (rtemp & 0x80)
@ -4741,8 +4748,6 @@ void G_LoadGameData(void)
cup->windata[j].got_emerald = true; cup->windata[j].got_emerald = true;
} }
} }
break;
} }
} }
} }
@ -4819,7 +4824,7 @@ void G_SaveGameData(boolean dirty)
{ {
numcups++; numcups++;
} }
length += 4 + (numcups * 4); length += 4 + (numcups * (4+16));
if (P_SaveBufferAlloc(&save, length) == false) if (P_SaveBufferAlloc(&save, length) == false)
{ {