aboutsummaryrefslogtreecommitdiff
path: root/engines/chewy/resource.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2016-09-20 13:00:19 +0300
committerFilippos Karapetis2016-10-03 00:33:32 +0300
commita196bfff57a0fb1a5cca9e242125ed2f5cbd018d (patch)
treef01166a79e47e90a77e891c9f9018db9b0701354 /engines/chewy/resource.cpp
parentc6ccd8bbe8da08534a9f1e23258dc4011a60382c (diff)
downloadscummvm-rg350-a196bfff57a0fb1a5cca9e242125ed2f5cbd018d.tar.gz
scummvm-rg350-a196bfff57a0fb1a5cca9e242125ed2f5cbd018d.tar.bz2
scummvm-rg350-a196bfff57a0fb1a5cca9e242125ed2f5cbd018d.zip
CHEWY: Add support for encrypted text resources
These are mainly used for error messages
Diffstat (limited to 'engines/chewy/resource.cpp')
-rw-r--r--engines/chewy/resource.cpp70
1 files changed, 62 insertions, 8 deletions
diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp
index 1bd9583a72..b8fba3713c 100644
--- a/engines/chewy/resource.cpp
+++ b/engines/chewy/resource.cpp
@@ -30,17 +30,37 @@
namespace Chewy {
Resource::Resource(Common::String filename) {
+ const uint32 headerGeneric = MKTAG('N', 'G', 'S', '\0');
+ const uint32 headerTxtDec = MKTAG('T', 'C', 'F', '\0');
+ const uint32 headerTxtEnc = MKTAG('T', 'C', 'F', '\1');
+
_stream.open(filename);
- uint32 magicBytes = MKTAG('N', 'G', 'S', '\0');
- if (_stream.readUint32BE() != magicBytes)
+
+ uint32 header = _stream.readUint32BE();
+ bool isText = header == headerTxtDec || header == headerTxtEnc;
+
+ if (header != headerGeneric && !isText)
error("Invalid resource - %s", filename.c_str());
- _resType = (ResourceType)_stream.readUint16LE();
+
+ if (isText) {
+ _resType = kResourceTCF;
+ _encrypted = (header == headerTxtEnc);
+ } else {
+ _resType = (ResourceType)_stream.readUint16LE();
+ _encrypted = false;
+ }
+
_chunkCount = _stream.readUint16LE();
for (uint i = 0; i < _chunkCount; i++) {
Chunk cur;
cur.size = _stream.readUint32LE();
- cur.type = (ResourceType)_stream.readUint16LE();
+
+ if (!isText)
+ cur.type = (ResourceType)_stream.readUint16LE();
+ else
+ cur.num = _stream.readUint16LE();
+
cur.pos = _stream.pos();
_stream.skip(cur.size);
@@ -57,11 +77,15 @@ uint32 Resource::getChunkCount() const {
return _chunkList.size();
}
-Chunk *Resource::getChunk(int num) {
+Chunk *Resource::getChunk(uint num) {
+ assert(num < _chunkList.size());
+
return &_chunkList[num];
}
-byte *Resource::getChunkData(int num) {
+byte *Resource::getChunkData(uint num) {
+ assert(num < _chunkList.size());
+
Chunk *chunk = &_chunkList[num];
byte *data = new byte[chunk->size];
@@ -71,7 +95,9 @@ byte *Resource::getChunkData(int num) {
return data;
}
-TBFChunk *BackgroundResource::getImage(int num) {
+TBFChunk *BackgroundResource::getImage(uint num) {
+ assert(num < _chunkList.size());
+
Chunk *chunk = &_chunkList[num];
TBFChunk *tbf = new TBFChunk();
@@ -111,7 +137,9 @@ TBFChunk *BackgroundResource::getImage(int num) {
return tbf;
}
-SoundChunk *SoundResource::getSound(int num) {
+SoundChunk *SoundResource::getSound(uint num) {
+ assert(num < _chunkList.size());
+
Chunk *chunk = &_chunkList[num];
SoundChunk *sound = new SoundChunk();
@@ -155,4 +183,30 @@ SoundChunk *SoundResource::getSound(int num) {
return sound;
}
+Common::String TextResource::getText(uint num) {
+ assert(num < _chunkList.size());
+
+ Chunk *chunk = &_chunkList[num];
+ Common::String str;
+ byte *data = new byte[chunk->size];
+
+ _stream.seek(chunk->pos, SEEK_SET);
+
+ _stream.read(data, chunk->size);
+
+ if (_encrypted) {
+ byte *c = data;
+
+ for (uint i = 0; i < chunk->size; i++) {
+ *c = -(*c);
+ ++c;
+ }
+ }
+
+ str = (char *)data;
+ delete[] data;
+
+ return str;
+}
+
} // End of namespace Chewy