aboutsummaryrefslogtreecommitdiff
path: root/engines/mads
diff options
context:
space:
mode:
authorPaul Gilbert2014-05-26 17:44:00 -0400
committerPaul Gilbert2014-05-26 17:44:00 -0400
commit2400c77d9153e9746f6b4070154e3d571a98e11a (patch)
tree70043435a09121d7accd2e964f559de6c46c6db2 /engines/mads
parent8061a415c9f7db906d0b4fdcef13e6bf136dde19 (diff)
downloadscummvm-rg350-2400c77d9153e9746f6b4070154e3d571a98e11a.tar.gz
scummvm-rg350-2400c77d9153e9746f6b4070154e3d571a98e11a.tar.bz2
scummvm-rg350-2400c77d9153e9746f6b4070154e3d571a98e11a.zip
MADS: Better handle resource index decompression flags like original
Diffstat (limited to 'engines/mads')
-rw-r--r--engines/mads/compression.cpp35
-rw-r--r--engines/mads/compression.h15
2 files changed, 27 insertions, 23 deletions
diff --git a/engines/mads/compression.cpp b/engines/mads/compression.cpp
index de893e7b1a..2284f17321 100644
--- a/engines/mads/compression.cpp
+++ b/engines/mads/compression.cpp
@@ -65,24 +65,31 @@ void MadsPack::initialise(Common::SeekableReadStream *stream) {
for (int i = 0; i < _count; ++i, header += 10) {
// Get header data
- _items[i].hash = READ_LE_UINT16(header);
- _items[i].size = READ_LE_UINT32(header + 2);
- _items[i].compressedSize = READ_LE_UINT32(header + 6);
+ _items[i]._type = (CompressionType)*header;
+ _items[i]._priority = *(header + 1);
+ _items[i]._size = READ_LE_UINT32(header + 2);
+ _items[i]._compressedSize = READ_LE_UINT32(header + 6);
- byte *sourceData = new byte[_items[i].compressedSize];
- stream->read(sourceData, _items[i].compressedSize);
+ byte *sourceData = new byte[_items[i]._compressedSize];
+ stream->read(sourceData, _items[i]._compressedSize);
- if (_items[i].size == _items[i].compressedSize &&
- !FabDecompressor::isCompressed(sourceData)) {
+ switch (_items[i]._type) {
+ case COMPRESS_NONE:
// Entry isn't compressed
- _items[i].data = sourceData;
- } else {
+ _items[i]._data = sourceData;
+ break;
+
+ case COMPRESS_FAB:
// Decompress the entry
- _items[i].data = new byte[_items[i].size];
+ _items[i]._data = new byte[_items[i]._size];
FabDecompressor fab;
- fab.decompress(sourceData, _items[i].compressedSize, _items[i].data, _items[i].size);
+ fab.decompress(sourceData, _items[i]._compressedSize, _items[i]._data, _items[i]._size);
delete[] sourceData;
+ break;
+
+ default:
+ error("Unknown compression type encountered");
}
}
@@ -92,16 +99,12 @@ void MadsPack::initialise(Common::SeekableReadStream *stream) {
MadsPack::~MadsPack() {
for (int i = 0; i < _count; ++i)
- delete[] _items[i].data;
+ delete[] _items[i]._data;
delete[] _items;
}
//--------------------------------------------------------------------------
-bool FabDecompressor::isCompressed(const byte *srcData) {
- return strncmp((const char *)srcData, "FAB", 3) == 0;
-}
-
void FabDecompressor::decompress(const byte *srcData, int srcSize, byte *destData, int destSize) {
byte copyLen, copyOfsShift, copyOfsMask, copyLenMask;
unsigned long copyOfs;
diff --git a/engines/mads/compression.h b/engines/mads/compression.h
index 43a966f48c..e6eca420b5 100644
--- a/engines/mads/compression.h
+++ b/engines/mads/compression.h
@@ -32,12 +32,15 @@
namespace MADS {
+enum CompressionType { COMPRESS_NONE = 0, COMPRESS_FAB = 1 };
+
struct MadsPackEntry {
public:
- uint16 hash;
- uint32 size;
- uint32 compressedSize;
- byte *data;
+ CompressionType _type;
+ byte _priority;
+ uint32 _size;
+ uint32 _compressedSize;
+ byte *_data;
};
class MadsPack {
@@ -63,7 +66,7 @@ public:
}
Common::MemoryReadStream *getItemStream(int index) {
assert(index < _count);
- return new Common::MemoryReadStream(_items[index].data, _items[index].size,
+ return new Common::MemoryReadStream(_items[index]._data, _items[index]._size,
DisposeAfterUse::NO);
}
int getDataOffset() const { return _dataOffset; }
@@ -79,8 +82,6 @@ private:
int getBit();
public:
void decompress(const byte *srcData, int srcSize, byte *destData, int destSize);
-
- static bool isCompressed(const byte *srcData);
};
} // End of namespace MADS