aboutsummaryrefslogtreecommitdiff
path: root/engines/supernova/supernova.cpp
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-07-02 11:39:35 +0200
committerThierry Crozat2019-07-28 15:09:14 +0100
commit37c53c420f9a3ccf2bc21de8caea9e0b65edacec (patch)
treef266d06184c1a40abb669e4de8f98dfa37b01af5 /engines/supernova/supernova.cpp
parent16bad91f4b18427ebd210d6bebf826b364c3feba (diff)
downloadscummvm-rg350-37c53c420f9a3ccf2bc21de8caea9e0b65edacec.tar.gz
scummvm-rg350-37c53c420f9a3ccf2bc21de8caea9e0b65edacec.tar.bz2
scummvm-rg350-37c53c420f9a3ccf2bc21de8caea9e0b65edacec.zip
SUPERNOVA: Load info files from .dat file
Diffstat (limited to 'engines/supernova/supernova.cpp')
-rw-r--r--engines/supernova/supernova.cpp85
1 files changed, 79 insertions, 6 deletions
diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp
index 07d91285e8..d186995f6b 100644
--- a/engines/supernova/supernova.cpp
+++ b/engines/supernova/supernova.cpp
@@ -510,14 +510,87 @@ void SupernovaEngine::showHelpScreen2() {
_gm->animationOn();
}
-Common::Error SupernovaEngine::showTextReader(const char *filename) {
- Common::File file;
+Common::SeekableReadStream *SupernovaEngine::getBlockFromDatFile(Common::String name) {
+ Common::String cur_lang = ConfMan.get("language");
+
+ // Validate the data file header
+ Common::File f;
+ char id[5], lang[5];
+ id[4] = lang[4] = '\0';
+ if (_MSPart == 1) {
+ if (!f.open(SUPERNOVA_DAT)) {
+ GUIErrorMessageFormat(_("Unable to locate the '%s' engine data file."), SUPERNOVA_DAT);
+ return nullptr;
+ }
+ f.read(id, 3);
+ if (strncmp(id, "MSN", 3) != 0) {
+ GUIErrorMessageFormat(_("The '%s' engine data file is corrupt."), SUPERNOVA_DAT);
+ return nullptr;
+ }
+
+ int version = f.readByte();
+ if (version != SUPERNOVA_DAT_VERSION) {
+ GUIErrorMessageFormat(
+ _("Incorrect version of the '%s' engine data file found. Expected %d but got %d."),
+ SUPERNOVA_DAT, SUPERNOVA_DAT_VERSION, version);
+ return nullptr;
+ }
+ }
+ else if (_MSPart == 2) {
+ if (!f.open(SUPERNOVA2_DAT)) {
+ GUIErrorMessageFormat(_("Unable to locate the '%s' engine data file."), SUPERNOVA2_DAT);
+ return nullptr;
+ }
+ f.read(id, 3);
+ if (strncmp(id, "MS2", 3) != 0) {
+ GUIErrorMessageFormat(_("The '%s' engine data file is corrupt."), SUPERNOVA2_DAT);
+ return nullptr;
+ }
+
+ int version = f.readByte();
+ if (version != SUPERNOVA2_DAT_VERSION) {
+ GUIErrorMessageFormat(
+ _("Incorrect version of the '%s' engine data file found. Expected %d but got %d."),
+ SUPERNOVA2_DAT, SUPERNOVA2_DAT_VERSION, version);
+ return nullptr;
+ }
+ }
- if (!file.open(filename)) {
- GUIErrorMessageFormat(_("Unable to find '%s' in game folder."), filename);
- return Common::kReadingFailed;
+
+ while (!f.eos()) {
+ f.read(id, 4);
+ f.read(lang, 4);
+ uint32 size = f.readUint32LE();
+ if (f.eos())
+ break;
+ if (name == id && cur_lang == lang) {
+ return f.readStream(size);
+ } else
+ f.skip(size);
+ }
+
+ return nullptr;
+}
+
+Common::Error SupernovaEngine::showTextReader(const char *extension) {
+ Common::SeekableReadStream *stream;
+ Common::String blockName;
+ blockName = Common::String::format("%s%d", extension, _MSPart);
+ blockName.toUppercase();
+ if ((stream = getBlockFromDatFile(blockName)) == nullptr) {
+ Common::File file;
+ Common::String filename;
+ if (_MSPart == 1)
+ filename = Common::String::format("msn.%s", extension);
+ if (_MSPart == 2)
+ filename = Common::String::format("ms2.%s", extension);
+
+ if (!file.open(filename)) {
+ GUIErrorMessageFormat(_("Unable to find '%s' in game folder or the engine data file."), filename);
+ return Common::kReadingFailed;
+ }
+ stream = file.readStream(file.size());
}
- Common::SeekableReadStream *stream = file.readStream(file.size());
int linesInFile = 0;
while (!stream->eos()) {
stream->readLine();