aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Crozat2017-09-30 16:28:42 +0100
committerThierry Crozat2018-01-23 02:15:33 +0000
commit0f4d364e63bbc1cb2a14917245a4e8d0abe82150 (patch)
tree27d140479266f118182f38dd7e108f2c1e39daf1
parenta13086ad25b573e7b6f580f7ed38c4c37f6a9d17 (diff)
downloadscummvm-rg350-0f4d364e63bbc1cb2a14917245a4e8d0abe82150.tar.gz
scummvm-rg350-0f4d364e63bbc1cb2a14917245a4e8d0abe82150.tar.bz2
scummvm-rg350-0f4d364e63bbc1cb2a14917245a4e8d0abe82150.zip
SUPERNOVA: Add getting translated images from the engine data file
-rw-r--r--engines/supernova/graphics.cpp95
-rw-r--r--engines/supernova/graphics.h1
-rw-r--r--engines/supernova/supernova.h3
3 files changed, 76 insertions, 23 deletions
diff --git a/engines/supernova/graphics.cpp b/engines/supernova/graphics.cpp
index 70f05903ea..87485e0edc 100644
--- a/engines/supernova/graphics.cpp
+++ b/engines/supernova/graphics.cpp
@@ -24,11 +24,13 @@
#include "common/file.h"
#include "common/stream.h"
#include "common/system.h"
+#include "common/config-manager.h"
#include "graphics/palette.h"
#include "graphics/surface.h"
#include "graphics.h"
#include "msn_def.h"
+#include "supernova.h"
namespace Supernova {
@@ -57,6 +59,48 @@ bool MSNImageDecoder::init(int filenumber) {
return true;
}
+bool MSNImageDecoder::loadFromEngineDataFile() {
+ Common::String name;
+ if (_filenumber == 1)
+ name = "IMG1";
+ else if (_filenumber == 2)
+ name = "IMG2";
+ else
+ return false;
+
+ Common::String cur_lang = ConfMan.get("language");
+
+ // 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))
+ return false;
+
+ char id[5], lang[5];
+ id[4] = lang[4] = '\0';
+ f.read(id, 3);
+ if (strncmp(id, "MSN", 3) != 0)
+ return false;
+ int version = f.readByte();
+ if (version != SUPERNOVA_DAT_VERSION)
+ return false;
+
+ 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.read(_encodedImage, size) == size;
+ } else
+ f.skip(size);
+ }
+
+ return false;
+}
+
bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) {
destroy();
@@ -113,30 +157,35 @@ bool MSNImageDecoder::loadStream(Common::SeekableReadStream &stream) {
_clickField[i].next = stream.readByte();
}
- byte zwCodes[256] = {0};
- byte numRepeat = stream.readByte();
- byte numZw = stream.readByte();
- stream.read(zwCodes, numZw);
- numZw += numRepeat;
-
- byte input = 0;
- uint i = 0;
-
- while (stream.read(&input, 1)) {
- if (input < numRepeat) {
- ++input;
- byte value = stream.readByte();
- for (--value; input > 0; --input) {
- _encodedImage[i++] = value;
+ // Newspaper images may be in the engine data file. So first try to read
+ // it from there.
+ if (!loadFromEngineDataFile()) {
+ // Load the image from the stream
+ byte zwCodes[256] = {0};
+ byte numRepeat = stream.readByte();
+ byte numZw = stream.readByte();
+ stream.read(zwCodes, numZw);
+ numZw += numRepeat;
+
+ byte input = 0;
+ uint i = 0;
+
+ while (stream.read(&input, 1)) {
+ if (input < numRepeat) {
+ ++input;
+ byte value = stream.readByte();
+ for (--value; input > 0; --input) {
+ _encodedImage[i++] = value;
+ }
+ } else if (input < numZw) {
+ input = zwCodes[input - numRepeat];
+ --input;
+ _encodedImage[i++] = input;
+ _encodedImage[i++] = input;
+ } else {
+ input -= pal_diff;
+ _encodedImage[i++] = input;
}
- } else if (input < numZw) {
- input = zwCodes[input - numRepeat];
- --input;
- _encodedImage[i++] = input;
- _encodedImage[i++] = input;
- } else {
- input -= pal_diff;
- _encodedImage[i++] = input;
}
}
diff --git a/engines/supernova/graphics.h b/engines/supernova/graphics.h
index c04afbadf9..a77ea20cf2 100644
--- a/engines/supernova/graphics.h
+++ b/engines/supernova/graphics.h
@@ -79,6 +79,7 @@ public:
} _clickField[kMaxClickFields];
private:
+ bool loadFromEngineDataFile();
bool loadSections();
};
diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h
index 91dc5a1b5f..a1a682d02f 100644
--- a/engines/supernova/supernova.h
+++ b/engines/supernova/supernova.h
@@ -45,6 +45,9 @@ namespace Supernova {
#define SAVEGAME_HEADER MKTAG('M','S','N','1')
#define SAVEGAME_VERSION 1
+#define SUPERNOVA_DAT "supernova.dat"
+#define SUPERNOVA_DAT_VERSION 1
+
struct ScreenBuffer {
ScreenBuffer()