mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2024-11-15 01:01:33 +00:00
parent
235bf724f0
commit
053a9fc2e2
1 changed files with 30 additions and 28 deletions
58
src/g_game.c
58
src/g_game.c
|
@ -4612,6 +4612,8 @@ void G_LoadGameData(gamedata_t *data)
|
|||
// Saves the main data file, which stores information such as emblems found, etc.
|
||||
void G_SaveGameData(gamedata_t *data)
|
||||
{
|
||||
UINT8 *data_p;
|
||||
|
||||
size_t length;
|
||||
INT32 i, j;
|
||||
UINT8 btemp;
|
||||
|
@ -4621,8 +4623,8 @@ void G_SaveGameData(gamedata_t *data)
|
|||
if (!data->loaded)
|
||||
return; // If never loaded (-nodata), don't save
|
||||
|
||||
save_p = savebuffer = (UINT8 *)malloc(GAMEDATASIZE);
|
||||
if (!save_p)
|
||||
data_p = savebuffer = (UINT8 *)malloc(GAMEDATASIZE);
|
||||
if (!data_p)
|
||||
{
|
||||
CONS_Alert(CONS_ERROR, M_GetText("No more free memory for saving game data\n"));
|
||||
return;
|
||||
|
@ -4631,20 +4633,20 @@ void G_SaveGameData(gamedata_t *data)
|
|||
if (usedCheats)
|
||||
{
|
||||
free(savebuffer);
|
||||
save_p = savebuffer = NULL;
|
||||
savebuffer = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// Version test
|
||||
WRITEUINT32(save_p, GAMEDATA_ID);
|
||||
WRITEUINT32(data_p, GAMEDATA_ID);
|
||||
|
||||
WRITEUINT32(save_p, data->totalplaytime);
|
||||
WRITEUINT32(data_p, data->totalplaytime);
|
||||
|
||||
WRITEUINT32(save_p, quickncasehash(timeattackfolder, sizeof timeattackfolder));
|
||||
WRITEUINT32(data_p, quickncasehash(timeattackfolder, sizeof timeattackfolder));
|
||||
|
||||
// TODO put another cipher on these things? meh, I don't care...
|
||||
for (i = 0; i < NUMMAPS; i++)
|
||||
WRITEUINT8(save_p, (data->mapvisited[i] & MV_MAX));
|
||||
WRITEUINT8(data_p, (data->mapvisited[i] & MV_MAX));
|
||||
|
||||
// To save space, use one bit per collected/achieved/unlocked flag
|
||||
for (i = 0; i < MAXEMBLEMS;)
|
||||
|
@ -4652,7 +4654,7 @@ void G_SaveGameData(gamedata_t *data)
|
|||
btemp = 0;
|
||||
for (j = 0; j < 8 && j+i < MAXEMBLEMS; ++j)
|
||||
btemp |= (data->collected[j+i] << j);
|
||||
WRITEUINT8(save_p, btemp);
|
||||
WRITEUINT8(data_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXEXTRAEMBLEMS;)
|
||||
|
@ -4660,7 +4662,7 @@ void G_SaveGameData(gamedata_t *data)
|
|||
btemp = 0;
|
||||
for (j = 0; j < 8 && j+i < MAXEXTRAEMBLEMS; ++j)
|
||||
btemp |= (data->extraCollected[j+i] << j);
|
||||
WRITEUINT8(save_p, btemp);
|
||||
WRITEUINT8(data_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXUNLOCKABLES;)
|
||||
|
@ -4668,7 +4670,7 @@ void G_SaveGameData(gamedata_t *data)
|
|||
btemp = 0;
|
||||
for (j = 0; j < 8 && j+i < MAXUNLOCKABLES; ++j)
|
||||
btemp |= (data->unlocked[j+i] << j);
|
||||
WRITEUINT8(save_p, btemp);
|
||||
WRITEUINT8(data_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
for (i = 0; i < MAXCONDITIONSETS;)
|
||||
|
@ -4676,30 +4678,30 @@ void G_SaveGameData(gamedata_t *data)
|
|||
btemp = 0;
|
||||
for (j = 0; j < 8 && j+i < MAXCONDITIONSETS; ++j)
|
||||
btemp |= (data->achieved[j+i] << j);
|
||||
WRITEUINT8(save_p, btemp);
|
||||
WRITEUINT8(data_p, btemp);
|
||||
i += j;
|
||||
}
|
||||
|
||||
WRITEUINT32(save_p, data->timesBeaten);
|
||||
WRITEUINT32(save_p, data->timesBeatenWithEmeralds);
|
||||
WRITEUINT32(save_p, data->timesBeatenUltimate);
|
||||
WRITEUINT32(data_p, data->timesBeaten);
|
||||
WRITEUINT32(data_p, data->timesBeatenWithEmeralds);
|
||||
WRITEUINT32(data_p, data->timesBeatenUltimate);
|
||||
|
||||
// Main records
|
||||
for (i = 0; i < NUMMAPS; i++)
|
||||
{
|
||||
if (data->mainrecords[i])
|
||||
{
|
||||
WRITEUINT32(save_p, data->mainrecords[i]->score);
|
||||
WRITEUINT32(save_p, data->mainrecords[i]->time);
|
||||
WRITEUINT16(save_p, data->mainrecords[i]->rings);
|
||||
WRITEUINT32(data_p, data->mainrecords[i]->score);
|
||||
WRITEUINT32(data_p, data->mainrecords[i]->time);
|
||||
WRITEUINT16(data_p, data->mainrecords[i]->rings);
|
||||
}
|
||||
else
|
||||
{
|
||||
WRITEUINT32(save_p, 0);
|
||||
WRITEUINT32(save_p, 0);
|
||||
WRITEUINT16(save_p, 0);
|
||||
WRITEUINT32(data_p, 0);
|
||||
WRITEUINT32(data_p, 0);
|
||||
WRITEUINT16(data_p, 0);
|
||||
}
|
||||
WRITEUINT8(save_p, 0); // compat
|
||||
WRITEUINT8(data_p, 0); // compat
|
||||
}
|
||||
|
||||
// NiGHTS records
|
||||
|
@ -4707,25 +4709,25 @@ void G_SaveGameData(gamedata_t *data)
|
|||
{
|
||||
if (!data->nightsrecords[i] || !data->nightsrecords[i]->nummares)
|
||||
{
|
||||
WRITEUINT8(save_p, 0);
|
||||
WRITEUINT8(data_p, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
WRITEUINT8(save_p, data->nightsrecords[i]->nummares);
|
||||
WRITEUINT8(data_p, data->nightsrecords[i]->nummares);
|
||||
|
||||
for (curmare = 0; curmare < (data->nightsrecords[i]->nummares + 1); ++curmare)
|
||||
{
|
||||
WRITEUINT32(save_p, data->nightsrecords[i]->score[curmare]);
|
||||
WRITEUINT8(save_p, data->nightsrecords[i]->grade[curmare]);
|
||||
WRITEUINT32(save_p, data->nightsrecords[i]->time[curmare]);
|
||||
WRITEUINT32(data_p, data->nightsrecords[i]->score[curmare]);
|
||||
WRITEUINT8(data_p, data->nightsrecords[i]->grade[curmare]);
|
||||
WRITEUINT32(data_p, data->nightsrecords[i]->time[curmare]);
|
||||
}
|
||||
}
|
||||
|
||||
length = save_p - savebuffer;
|
||||
length = data_p - savebuffer;
|
||||
|
||||
FIL_WriteFile(va(pandf, srb2home, gamedatafilename), savebuffer, length);
|
||||
free(savebuffer);
|
||||
save_p = savebuffer = NULL;
|
||||
savebuffer = NULL;
|
||||
}
|
||||
|
||||
#define VERSIONSIZE 16
|
||||
|
|
Loading…
Reference in a new issue