From 84bd8c6b46b405c3c14e8be6868d3a1534879d52 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 15 May 2019 15:47:15 -1000 Subject: GLK: HUGO: Move savegame code --- engines/glk/hugo/herun.cpp | 248 +++------------------------------------- engines/glk/hugo/hugo.cpp | 177 +++++++++++++++++++++++++++- engines/glk/hugo/hugo.h | 16 +-- engines/glk/hugo/hugo_defines.h | 2 + 4 files changed, 201 insertions(+), 242 deletions(-) diff --git a/engines/glk/hugo/herun.cpp b/engines/glk/hugo/herun.cpp index dca7ac2333..8659544d2e 100644 --- a/engines/glk/hugo/herun.cpp +++ b/engines/glk/hugo/herun.cpp @@ -1151,112 +1151,6 @@ RestartError: return 0; } -#ifndef RESTOREGAMEDATA_REPLACED - -int Hugo::RestoreGameData() { - char testid[3], testserial[9]; - int lbyte, hbyte; - int j; - unsigned int k, undosize; - long i; - - /* Check ID */ - testid[0] = (char)hugo_fgetc(save); - testid[1] = (char)hugo_fgetc(save); - testid[2] = '\0'; - if (hugo_ferror(save)) goto RestoreError; - - if (strcmp(testid, id)) - { - AP("Incorrect save file."); - if (hugo_fclose(save)) FatalError(READ_E); - save = nullptr; - return 0; - } - - /* Check serial number */ - if (!hugo_fgets(testserial, 9, save)) goto RestoreError; - if (strcmp(testserial, serial)) - { - AP("Save file created by different version."); - if (hugo_fclose(save)) FatalError(READ_E); - save = nullptr; - return 0; - } - - /* Restore variables */ - for (k=0; kpos() < s->size() && (c = hugo_fgetc(s)) != '\n') + while (s->pos() < s->size()) { + c = hugo_fgetc(s); + if (c == '\n' || c == '\0' || (max-- == 0)) + break; *ptr++ = c; - return buffer; + } + *ptr++ = '\0'; + return buf; } char *hugo_fgets(char *buf, int max, strid_t s) { Common::SeekableReadStream *rs = *s; @@ -1190,12 +1192,12 @@ public: /** * Load a savegame from the passed stream */ - virtual Common::Error loadGameData(strid_t file) override; + virtual Common::Error loadGameData(strid_t save) override; /** * Save the game to the passed stream */ - virtual Common::Error saveGameData(strid_t file, const Common::String &desc) override; + virtual Common::Error saveGameData(strid_t save, const Common::String &desc) override; }; } // End of namespace Hugo diff --git a/engines/glk/hugo/hugo_defines.h b/engines/glk/hugo/hugo_defines.h index b9ed1379cf..8d5b41b49e 100644 --- a/engines/glk/hugo/hugo_defines.h +++ b/engines/glk/hugo/hugo_defines.h @@ -36,6 +36,8 @@ namespace Hugo { #define GRAPHICS_SUPPORTED #define SOUND_SUPPORTED #define SETTITLE_SUPPORTED +#define SAVEGAMEDATA_REPLACED +#define RESTOREGAMEDATA_REPLACED // There's a bunch of debugging code in the original Hugo sources behind DEBUGGER defines, // but doesn't actually have any implementation of them. I've put in some stub methods, -- cgit v1.2.3