diff options
author | Thierry Crozat | 2017-09-30 23:26:06 +0100 |
---|---|---|
committer | Thierry Crozat | 2018-01-23 02:15:33 +0000 |
commit | 184b3a166217ba5c0ea3eddd3e01798d8e752417 (patch) | |
tree | 34d304ef90ef1fa05033c92270e2a93e1bdfbbed /engines | |
parent | d76b44ee57c5a5db6d825af16e82bf778ba0d30b (diff) | |
download | scummvm-rg350-184b3a166217ba5c0ea3eddd3e01798d8e752417.tar.gz scummvm-rg350-184b3a166217ba5c0ea3eddd3e01798d8e752417.tar.bz2 scummvm-rg350-184b3a166217ba5c0ea3eddd3e01798d8e752417.zip |
SUPERNOVA: Load strings from the supernova.dat file
Diffstat (limited to 'engines')
-rw-r--r-- | engines/supernova/supernova.cpp | 65 | ||||
-rw-r--r-- | engines/supernova/supernova.h | 9 |
2 files changed, 74 insertions, 0 deletions
diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp index 7fb95c507c..67c6fdd96c 100644 --- a/engines/supernova/supernova.cpp +++ b/engines/supernova/supernova.cpp @@ -33,6 +33,7 @@ #include "common/savefile.h" #include "common/str.h" #include "common/system.h" +#include "common/translation.h" #include "engines/util.h" #include "graphics/cursorman.h" #include "graphics/surface.h" @@ -138,6 +139,11 @@ SupernovaEngine::~SupernovaEngine() { Common::Error SupernovaEngine::run() { initGraphics(_screenWidth, _screenHeight); + + Common::Error status = loadGameStrings(); + if (status.getCode() != Common::kNoError) + return status; + _gm = new GameManager(this); _console = new Console(this, _gm); @@ -243,6 +249,65 @@ void SupernovaEngine::pauseTimer(bool pause) { } } +Common::Error SupernovaEngine::loadGameStrings() { + Common::String cur_lang = ConfMan.get("language"); + Common::String string_id("TEXT"); + + // Note: we don't print any warning or errors here if we cannot find the file + // or the format is not as expected. We will get those warning when reading the + // strings anyway (actually the engine will even refuse to start). + Common::File f; + if (!f.open(SUPERNOVA_DAT)) { + Common::String msg = Common::String::format(_("Unable to locate the '%s' engine data file."), SUPERNOVA_DAT); + GUIErrorMessage(msg); + return Common::kReadingFailed; + } + + // Validate the data file header + char id[5], lang[5]; + id[4] = lang[4] = '\0'; + f.read(id, 3); + if (strncmp(id, "MSN", 3) != 0) { + Common::String msg = Common::String::format(_("The '%s' engine data file is corrupt."), SUPERNOVA_DAT); + GUIErrorMessage(msg); + return Common::kReadingFailed; + } + + int version = f.readByte(); + if (version != SUPERNOVA_DAT_VERSION) { + Common::String msg = Common::String::format( + _("Incorrect version of the '%s' engine data file found. Expected %d but got %d."), + SUPERNOVA_DAT, SUPERNOVA_DAT_VERSION, version); + GUIErrorMessage(msg); + return Common::kReadingFailed; + } + + while (!f.eos()) { + f.read(id, 4); + f.read(lang, 4); + uint32 size = f.readUint32LE(); + if (f.eos()) + break; + if (string_id == id && cur_lang == lang) { + while (size > 0) { + Common::String s; + char ch; + while ((ch = (char)f.readByte()) != '\0') + s += ch; + _gameStrings.push_back(s); + size -= s.size() + 1; + } + return Common::kNoError; + } else + f.skip(size); + } + + Common::Language l = Common::parseLanguage(cur_lang); + Common::String msg = Common::String::format(_("Unable to locate the text for %s language in '%s' engine data file."), Common::getLanguageDescription(l), SUPERNOVA_DAT); + GUIErrorMessage(msg); + return Common::kReadingFailed; +} + void SupernovaEngine::initData() { // Images for (int i = 0; i < 44; ++i) diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h index a1a682d02f..356cfe482c 100644 --- a/engines/supernova/supernova.h +++ b/engines/supernova/supernova.h @@ -104,6 +104,8 @@ public: int _screenHeight; bool _allowLoadGame; bool _allowSaveGame; + Common::StringArray _gameStrings; + Common::String _nullString; byte _imageIndex; byte _sectionIndex; @@ -120,6 +122,7 @@ public: void pauseTimer(bool pause); int textWidth(const char *text); int textWidth(const uint16 key); + Common::Error loadGameStrings(); void initData(); void initPalette(); void paletteFadeIn(); @@ -146,6 +149,12 @@ public: bool loadGame(int slot); bool saveGame(int slot, const Common::String &description); + const Common::String &getGameString(int idx) const { + if (idx < 0 || idx >= _gameStrings.size()) + return _nullString; + return _gameStrings[idx]; + } + Common::MemoryReadStream *convertToMod(const char *filename, int version = 1); virtual Common::Error loadGameState(int slot); |