diff options
author | Paul Gilbert | 2016-02-15 16:17:38 -0500 |
---|---|---|
committer | Paul Gilbert | 2016-02-15 16:17:38 -0500 |
commit | 2753998868fe9f456b87f87a786fb5d58fb2c232 (patch) | |
tree | fa7d1c82c6144e84e4d720a26a5a46f2a7abf983 /engines | |
parent | 84c24b08079bc787e17995868fdd426f0a58d3da (diff) | |
download | scummvm-rg350-2753998868fe9f456b87f87a786fb5d58fb2c232.tar.gz scummvm-rg350-2753998868fe9f456b87f87a786fb5d58fb2c232.tar.bz2 scummvm-rg350-2753998868fe9f456b87f87a786fb5d58fb2c232.zip |
TITANIC: Work on decompressor
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/files.cpp | 96 | ||||
-rw-r--r-- | engines/titanic/files.h | 53 |
2 files changed, 126 insertions, 23 deletions
diff --git a/engines/titanic/files.cpp b/engines/titanic/files.cpp index a49c47a9ab..6432595748 100644 --- a/engines/titanic/files.cpp +++ b/engines/titanic/files.cpp @@ -171,8 +171,79 @@ double SimpleFile::readFloat() { /*------------------------------------------------------------------------*/ +DecompressorData::DecompressorData() { + _field0 = 0; + _field4 = 0; + _field8 = 0; + _fieldC = 0; + _field10 = 0; + _field14 = 0; +} + +/*------------------------------------------------------------------------*/ + +Decompressor::Decompressor() { + _createFn = nullptr; + _destroyFn = nullptr; + _field18 = 0; + _dataPtr = nullptr; + _field28 = 0; +} + +void Decompressor::load(const char *version, int v) { + if (!version || *version != '1') + error("Bad version"); + + _field18 = 0; + if (!_createFn) { + _createFn = &Decompressor::createMethod; + _field28 = 0; + } + + if (!_destroyFn) { + _destroyFn = &Decompressor::destroyMethod; + } + + _dataPtr = (this->*_createFn)(_field28, 1, 24); + _dataPtr->_field14 = 0; + _dataPtr->_fieldC = 0; + if (v < 0) { + v = -v; + _dataPtr->_fieldC = 1; + } + + if (v < 8 || v > 15) + error("Bad parameter"); + + _dataPtr->_field10 = v; + _dataPtr->_field14 = sub1(_dataPtr->_fieldC ? nullptr : &Decompressor::method3, 1 << v); + + if (_dataPtr->_field14) + sub2(); + else + close(); +} + +int Decompressor::sub1(Method3Fn fn, int v) { + +} + +void Decompressor::close() { + +} + +DecompressorData *Decompressor::createMethod(int v1, int v2, int v3) { + return new DecompressorData(); +} + +void Decompressor::destroyMethod(DecompressorData *ptr) { + delete ptr; +} + +/*------------------------------------------------------------------------*/ + CompressedFile::CompressedFile() : SimpleFile() { - _field48 = 0; + _fileMode = 0; _isReading = 0; _field260 = 0; _mode = 0; @@ -185,10 +256,11 @@ void CompressedFile::open(const Common::String &name, FileMode mode) { SimpleFile::open(name, mode); if (mode == FILE_READ) { - validate(&_mode, "1.0.4", 0x38); - _field48 = 2; + _decompressor.load(); + _fileMode = 2; } else if (mode == FILE_WRITE) { - validate(&_mode, "1.0.4", 0x38); + _decompressor.load(); + _fileMode = 1; } } void CompressedFile::close() { @@ -211,7 +283,8 @@ size_t CompressedFile::unsafeRead(void *dst, size_t count) { while (count > 0) { if (_queue.empty()) { decompress(); - + if (_queue.empty()) + break; } *dataPtr++ = _queue.pop(); @@ -222,19 +295,6 @@ size_t CompressedFile::unsafeRead(void *dst, size_t count) { return bytesRead; } -void CompressedFile::validate(int *mode, const char *version, int v3) { - validate2(mode, 15, version, v3); -} - -int CompressedFile::validate2(int *mode, int v15, const char *version, int v3) { - if (!version || *version != '1' || v3 != 0x38) - return -6; - if (!mode) - return -2; - - // TODO -} - void CompressedFile::decompress() { } diff --git a/engines/titanic/files.h b/engines/titanic/files.h index a1fb741602..1689f392d2 100644 --- a/engines/titanic/files.h +++ b/engines/titanic/files.h @@ -32,6 +32,9 @@ namespace Titanic { enum FileMode { FILE_READ = 1, FILE_WRITE = 2 }; +class Decompressor; +class DecompressorData; + class SimpleFile { protected: Common::File _file; @@ -75,10 +78,54 @@ public: virtual double readFloat(); }; +typedef DecompressorData *(Decompressor::*DecompressorCreateFn)(int v1, int v2, int v3); +typedef void(Decompressor::*DecompressorDestroyFn)(DecompressorData *ptr); +typedef void(Decompressor::*Method3Fn)(); + +class DecompressorData { +public: + int _field0; + int _field4; + int _field8; + int _fieldC; + int _field10; + int _field14; +public: + DecompressorData(); +}; + +class Decompressor { +private: + DecompressorCreateFn _createFn; + DecompressorDestroyFn _destroyFn; + int _field18; + DecompressorData *_dataPtr; + int _field28; + + DecompressorData *createMethod(int v1, int v2, int v3); + + void destroyMethod(DecompressorData *ptr); + + void method3() { + // TODO + } + + int sub1(Method3Fn fn, int v); + + void sub2(); +public: + Decompressor(); + + void load(const char *version = "1.0.4", int v = 15); + + void close(); +}; + class CompressedFile : public SimpleFile { private: + Decompressor _decompressor; Common::Queue<byte> _queue; - int _field48; + int _fileMode; int _isReading; int _field260; int _mode; @@ -87,10 +134,6 @@ private: * Decompress data from the source file */ void decompress(); - - void validate(int *mode, const char *version, int v3); - - int validate2(int *mode, int v15, const char *version, int v3); public: CompressedFile(); virtual ~CompressedFile(); |