diff options
-rw-r--r-- | engines/glk/POTFILES | 1 | ||||
-rw-r--r-- | engines/glk/glulxe/glulxe.cpp | 33 | ||||
-rw-r--r-- | engines/glk/glulxe/glulxe.h | 8 |
3 files changed, 41 insertions, 1 deletions
diff --git a/engines/glk/POTFILES b/engines/glk/POTFILES index d672609765..935c263619 100644 --- a/engines/glk/POTFILES +++ b/engines/glk/POTFILES @@ -1,3 +1,4 @@ engines/glk/streams.cpp engines/glk/scott/scott.cpp engines/glk/frotz/detection.cpp +engines/glk/glulxe/glulxe.cpp diff --git a/engines/glk/glulxe/glulxe.cpp b/engines/glk/glulxe/glulxe.cpp index 25af4c2f4d..e2e1a477e5 100644 --- a/engines/glk/glulxe/glulxe.cpp +++ b/engines/glk/glulxe/glulxe.cpp @@ -27,10 +27,16 @@ namespace Glk { namespace Glulxe { -Glulxe::Glulxe(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc) { +Glulxe::Glulxe(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), + vm_exited_cleanly(false) { } void Glulxe::runGame(Common::SeekableReadStream *gameFile) { + _gameFile = gameFile; + + if (!is_gamefile_valid()) + return; + // TODO } @@ -44,5 +50,30 @@ Common::Error Glulxe::saveGameData(strid_t file, const Common::String &desc) { return Common::kNoError; } +bool Glulxe::is_gamefile_valid() { + if (_gameFile->size() < 8) { + GUIError(_("This is too short to be a valid Glulx file.")); + return false; + } + + if (_gameFile->readUint32BE() != MKTAG('G', 'l', 'u', 'l')) { + GUIError(_("This is not a valid Glulx file.")); + return false; + } + + // We support version 2.0 through 3.1.* + uint version = _gameFile->readUint32BE(); + if (version < 0x20000) { + GUIError(_("This Glulx file is too old a version to execute.")); + return false; + } + if (version >= 0x30200) { + GUIError(_("This Glulx file is too new a version to execute.")); + return false; + } + + return true; +} + } // End of namespace Glulxe } // End of namespace Glk diff --git a/engines/glk/glulxe/glulxe.h b/engines/glk/glulxe/glulxe.h index eb4aaf3657..3764ca4fe0 100644 --- a/engines/glk/glulxe/glulxe.h +++ b/engines/glk/glulxe/glulxe.h @@ -34,6 +34,14 @@ namespace Glulxe { */ class Glulxe : public GlkAPI { public: + Common::SeekableReadStream *_gameFile; + bool vm_exited_cleanly; +private: + /** + * Validates the game file, and if it's invalid, displays an error dialog + */ + bool is_gamefile_valid(); +public: /** * Constructor */ |