- add savegame support for the statistics and secret hint feature.

This commit is contained in:
Christoph Oelckers 2019-11-13 18:23:45 +01:00
parent 8055d10362
commit c6a38faf39
4 changed files with 26 additions and 9 deletions

View file

@ -46,6 +46,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sound.h"
#include "i_specialpaths.h"
#include "view.h"
#include "statistics.h"
#include "secrets.h"
BEGIN_BLD_NS
@ -59,7 +61,7 @@ unsigned int dword_27AA40 = 0;
void *dword_27AA44 = NULL;
LoadSave LoadSave::head(123);
FILE *LoadSave::hSFile = NULL;
FileWriter *LoadSave::hSFile = NULL;
FileReader LoadSave::hLFile;
short word_27AA54 = 0;
@ -95,7 +97,7 @@ void LoadSave::Write(void *pData, int nSize)
dword_27AA38 += nSize;
dword_27AA3C += nSize;
dassert(hSFile != NULL);
if (fwrite(pData, 1, nSize, hSFile) != (size_t)nSize)
if (hSFile->Write(pData, nSize) != (size_t)nSize)
ThrowError("File error #%d writing save file.", errno);
}
@ -124,6 +126,9 @@ void LoadSave::LoadGame(char *pzFile)
rover->Load();
rover = rover->next;
}
if (!ReadStatistics(hLFile) || !SECRET_Load(hLFile)) // read the rest...
ThrowError("Error loading save file.");
hLFile.Close();
if (!gGameStarted)
scrLoadPLUs();
@ -188,7 +193,7 @@ void LoadSave::LoadGame(char *pzFile)
void LoadSave::SaveGame(char *pzFile)
{
hSFile = fopen(pzFile, "wb");
hSFile = FileWriter::Open(pzFile);
if (hSFile == NULL)
ThrowError("File error #%d creating save file.", errno);
dword_27AA38 = 0;
@ -202,7 +207,9 @@ void LoadSave::SaveGame(char *pzFile)
dword_27AA38 = 0;
rover = rover->next;
}
fclose(hSFile);
SaveStatistics(*hSFile);
SECRET_Save(*hSFile);
delete hSFile;
hSFile = NULL;
}

View file

@ -29,7 +29,7 @@ BEGIN_BLD_NS
class LoadSave {
public:
static LoadSave head;
static FILE *hSFile;
static FileWriter *hSFile;
static FileReader hLFile;
LoadSave *prev;
LoadSave *next;

View file

@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "i_specialpaths.h"
#include "gamecontrol.h"
#include "version.h"
#include "statistics.h"
#include "secrets.h"
BEGIN_DUKE_NS
@ -663,7 +665,7 @@ int32_t G_LoadPlayer(savebrief_t & sv)
if (status == 2)
G_NewGame_EnterLevel();
else if ((status = sv_loadsnapshot(fil, 0, &h))) // read the rest...
else if ((status = sv_loadsnapshot(fil, 0, &h)) || !ReadStatistics(fil) || !SECRET_Load(fil)) // read the rest...
{
// in theory, we could load into an initial dump first and trivially
// recover if things go wrong...
@ -796,6 +798,7 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
else
{
fil->Write("DEMOLITION_ED", 13);
CompressedFileWriter fw(fil, true);
sv.isExt = 0;
@ -809,6 +812,8 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
// SAVE!
sv_saveandmakesnapshot(fw, sv.name, 0, 0, 0, 0, isAutoSave);
SaveStatistics(fw);
SECRET_Save(fw);
fw.Close();

View file

@ -28,6 +28,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "i_specialpaths.h"
#include "gamecontrol.h"
#include "version.h"
#include "statistics.h"
#include "secrets.h"
BEGIN_RR_NS
@ -166,6 +168,7 @@ static FileReader OpenSavegame(const char *fn)
catch(std::runtime_error & err)
{
Printf("%s: %s\n", fn, err.what());
return FileReader();
}
return fr;
}
@ -408,14 +411,14 @@ int32_t G_LoadPlayer(savebrief_t & sv)
if (status == 2)
G_NewGame_EnterLevel();
else if ((status = sv_loadsnapshot(fil, 0, &h))) // read the rest...
{
else if ((status = sv_loadsnapshot(fil, 0, &h)) || !ReadStatistics(fil) || !SECRET_Load(fil)) // read the rest...
{
// in theory, we could load into an initial dump first and trivially
// recover if things go wrong...
Bsprintf(tempbuf, "Loading save game file \"%s\" failed (code %d), cannot recover.", sv.path, status);
G_GameExit(tempbuf);
}
sv_postudload(); // ud.m_XXX = ud.XXX
return 0;
@ -549,6 +552,8 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
// SAVE!
sv_saveandmakesnapshot(fw, sv.name, 0, 0, 0, 0, isAutoSave);
SaveStatistics(fw);
SECRET_Save(fw);
fw.Close();