diff options
author | Paul Gilbert | 2018-12-08 17:28:57 -0800 |
---|---|---|
committer | Paul Gilbert | 2018-12-08 19:05:59 -0800 |
commit | ac9830614d07d80f0c02d9d7c75d709f9d534466 (patch) | |
tree | c87d78b6a90fbe405a9f34dfe2efd847b9d6e1ec /engines/glk/glulxe | |
parent | 290196946dab0ee60498be16d8e33bb911e5a166 (diff) | |
download | scummvm-rg350-ac9830614d07d80f0c02d9d7c75d709f9d534466.tar.gz scummvm-rg350-ac9830614d07d80f0c02d9d7c75d709f9d534466.tar.bz2 scummvm-rg350-ac9830614d07d80f0c02d9d7c75d709f9d534466.zip |
GLK: GLULXE: Validate game file version
Diffstat (limited to 'engines/glk/glulxe')
-rw-r--r-- | engines/glk/glulxe/glulxe.cpp | 33 | ||||
-rw-r--r-- | engines/glk/glulxe/glulxe.h | 8 |
2 files changed, 40 insertions, 1 deletions
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 */ |