diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index 9a6a361bf..08adbebf5 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -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; } diff --git a/source/blood/src/loadsave.h b/source/blood/src/loadsave.h index 760fda235..3da580a62 100644 --- a/source/blood/src/loadsave.h +++ b/source/blood/src/loadsave.h @@ -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; diff --git a/source/duke3d/src/savegame.cpp b/source/duke3d/src/savegame.cpp index efbd75a0c..c78d38acd 100644 --- a/source/duke3d/src/savegame.cpp +++ b/source/duke3d/src/savegame.cpp @@ -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(); diff --git a/source/rr/src/savegame.cpp b/source/rr/src/savegame.cpp index 0021b377b..9b7431ec6 100644 --- a/source/rr/src/savegame.cpp +++ b/source/rr/src/savegame.cpp @@ -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();