diff options
author | Max Horn | 2010-11-23 22:25:36 +0000 |
---|---|---|
committer | Max Horn | 2010-11-23 22:25:36 +0000 |
commit | 09ba53dcfb3acb4d4041c30ccde095e89e89517c (patch) | |
tree | decf9becca8504b85058b84221cdc0be23bd3260 /engines | |
parent | 54e0390752b299d739daaf211e6b84b485738ada (diff) | |
download | scummvm-rg350-09ba53dcfb3acb4d4041c30ccde095e89e89517c.tar.gz scummvm-rg350-09ba53dcfb3acb4d4041c30ccde095e89e89517c.tar.bz2 scummvm-rg350-09ba53dcfb3acb4d4041c30ccde095e89e89517c.zip |
SCUMM: Use explicit XOR decoding code in BaseScummFile subclasses
This made it possible to turn some MemoryReadStream pointers into plain
SeekableReadStream pointers.
svn-id: r54435
Diffstat (limited to 'engines')
-rw-r--r-- | engines/scumm/file.cpp | 24 | ||||
-rw-r--r-- | engines/scumm/file.h | 15 | ||||
-rw-r--r-- | engines/scumm/file_nes.cpp | 17 | ||||
-rw-r--r-- | engines/scumm/file_nes.h | 8 | ||||
-rw-r--r-- | engines/scumm/he/resource_he.cpp | 2 | ||||
-rw-r--r-- | engines/scumm/he/sound_he.cpp | 1 |
6 files changed, 40 insertions, 27 deletions
diff --git a/engines/scumm/file.cpp b/engines/scumm/file.cpp index 95b99d22bd..20050e5d4c 100644 --- a/engines/scumm/file.cpp +++ b/engines/scumm/file.cpp @@ -27,6 +27,7 @@ #include "scumm/scumm.h" +#include "common/memstream.h" #include "common/substream.h" namespace Scumm { @@ -35,11 +36,7 @@ namespace Scumm { #pragma mark --- ScummFile --- #pragma mark - -ScummFile::ScummFile() : _encbyte(0), _subFileStart(0), _subFileLen(0) { -} - -void ScummFile::setEnc(byte value) { - _encbyte = value; +ScummFile::ScummFile() : _subFileStart(0), _subFileLen(0) { } void ScummFile::setSubfileRange(int32 start, int32 len) { @@ -248,10 +245,6 @@ ScummDiskImage::ScummDiskImage(const char *disk1, const char *disk2, GameSetting } } -void ScummDiskImage::setEnc(byte enc) { - _stream->setEnc(enc); -} - byte ScummDiskImage::fileReadByte() { byte b = 0; File::read(&b, 1); @@ -499,4 +492,17 @@ bool ScummDiskImage::openSubFile(const Common::String &filename) { return true; } +uint32 ScummDiskImage::read(void *dataPtr, uint32 dataSize) { + uint32 realLen = _stream->read(dataPtr, dataSize); + + if (_encbyte) { + byte *p = (byte *)dataPtr; + byte *end = p + realLen; + while (p < end) + *p++ ^= _encbyte; + } + + return realLen; +} + } // End of namespace Scumm diff --git a/engines/scumm/file.h b/engines/scumm/file.h index 1dcd3cd7a8..8a25277ded 100644 --- a/engines/scumm/file.h +++ b/engines/scumm/file.h @@ -27,15 +27,19 @@ #define SCUMM_FILE_H #include "common/file.h" -#include "common/memstream.h" +#include "common/stream.h" #include "scumm/detection.h" namespace Scumm { class BaseScummFile : public Common::File { +protected: + byte _encbyte; + public: - virtual void setEnc(byte value) = 0; + BaseScummFile() : _encbyte(0) {} + void setEnc(byte value) { _encbyte = value; } virtual bool open(const Common::String &filename) = 0; virtual bool openSubFile(const Common::String &filename) = 0; @@ -53,7 +57,6 @@ public: class ScummFile : public BaseScummFile { private: - byte _encbyte; int32 _subFileStart; int32 _subFileLen; bool _myEos; // Have we read past the end of the subfile? @@ -63,7 +66,6 @@ private: public: ScummFile(); - void setEnc(byte value); bool open(const Common::String &filename); bool openSubFile(const Common::String &filename); @@ -79,7 +81,7 @@ public: class ScummDiskImage : public BaseScummFile { private: - Common::MemoryReadStream *_stream; + Common::SeekableReadStream *_stream; byte _roomDisks[59], _roomTracks[59], _roomSectors[59]; byte *_buf; @@ -109,7 +111,6 @@ private: public: ScummDiskImage(const char *disk1, const char *disk2, GameSettings game); - void setEnc(byte value); bool open(const Common::String &filename); bool openSubFile(const Common::String &filename); @@ -119,7 +120,7 @@ public: int32 pos() const { return _stream->pos(); } int32 size() const { return _stream->size(); } bool seek(int32 offs, int whence = SEEK_SET) { return _stream->seek(offs, whence); } - uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); } + uint32 read(void *dataPtr, uint32 dataSize); }; } // End of namespace Scumm diff --git a/engines/scumm/file_nes.cpp b/engines/scumm/file_nes.cpp index 5403354830..d9d84f04ff 100644 --- a/engines/scumm/file_nes.cpp +++ b/engines/scumm/file_nes.cpp @@ -27,6 +27,7 @@ #include "common/debug.h" #include "common/endian.h" #include "common/md5.h" +#include "common/memstream.h" namespace Scumm { @@ -47,10 +48,6 @@ struct ScummNESFile::ResourceGroup { ScummNESFile::ScummNESFile() : _stream(0), _buf(0), _ROMset(kROMsetNum) { } -void ScummNESFile::setEnc(byte enc) { - _stream->setEnc(enc); -} - static const ScummNESFile::Resource res_roomgfx_usa[40] = { { 0x04001, 0x03C9 }, { 0x043CA, 0x069E }, { 0x04A68, 0x0327 }, { 0x04D8F, 0x053B }, { 0x052CA, 0x06BE }, { 0x05988, 0x0682 }, { 0x0600A, 0x0778 }, { 0x06782, 0x0517 }, { 0x06C99, 0x07FB }, { 0x07494, 0x07BE }, @@ -1450,5 +1447,17 @@ bool ScummNESFile::openSubFile(const Common::String &filename) { } } +uint32 ScummNESFile::read(void *dataPtr, uint32 dataSize) { + uint32 realLen = _stream->read(dataPtr, dataSize); + + if (_encbyte) { + byte *p = (byte *)dataPtr; + byte *end = p + realLen; + while (p < end) + *p++ ^= _encbyte; + } + + return realLen; +} } // End of namespace Scumm diff --git a/engines/scumm/file_nes.h b/engines/scumm/file_nes.h index df2528c357..f2ce3e19fd 100644 --- a/engines/scumm/file_nes.h +++ b/engines/scumm/file_nes.h @@ -26,9 +26,6 @@ #ifndef SCUMM_FILE_NES_H #define SCUMM_FILE_NES_H -#include "common/file.h" -#include "common/memstream.h" - #include "scumm/file.h" namespace Scumm { @@ -71,7 +68,7 @@ public: private: - Common::MemoryReadStream *_stream; + Common::SeekableReadStream *_stream; ROMset _ROMset; byte *_buf; @@ -84,7 +81,6 @@ private: public: ScummNESFile(); - void setEnc(byte value); bool open(const Common::String &filename); bool openSubFile(const Common::String &filename); @@ -94,7 +90,7 @@ public: int32 pos() const { return _stream->pos(); } int32 size() const { return _stream->size(); } bool seek(int32 offs, int whence = SEEK_SET) { return _stream->seek(offs, whence); } - uint32 read(void *dataPtr, uint32 dataSize) { return _stream->read(dataPtr, dataSize); } + uint32 read(void *dataPtr, uint32 dataSize); }; } // End of namespace Scumm diff --git a/engines/scumm/he/resource_he.cpp b/engines/scumm/he/resource_he.cpp index 70663b1b33..09b7b54253 100644 --- a/engines/scumm/he/resource_he.cpp +++ b/engines/scumm/he/resource_he.cpp @@ -34,7 +34,7 @@ #include "graphics/cursorman.h" #include "common/archive.h" -#include "common/stream.h" +#include "common/memstream.h" #include "common/system.h" namespace Scumm { diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp index 1d02a95b30..6feeb2bb8f 100644 --- a/engines/scumm/he/sound_he.cpp +++ b/engines/scumm/he/sound_he.cpp @@ -32,6 +32,7 @@ #include "scumm/util.h" #include "common/config-manager.h" +#include "common/memstream.h" #include "common/timer.h" #include "common/util.h" |