diff options
author | Johannes Schickel | 2009-05-12 14:18:08 +0000 |
---|---|---|
committer | Johannes Schickel | 2009-05-12 14:18:08 +0000 |
commit | 8524bf3a25fe8326fda5364f7691c75903b5eb32 (patch) | |
tree | c802d13990e72bd88a920f884b216aaaee1edd7a /engines/kyra/script.h | |
parent | fa0fe7fada18be6499694f94164af3d06fdf628a (diff) | |
download | scummvm-rg350-8524bf3a25fe8326fda5364f7691c75903b5eb32.tar.gz scummvm-rg350-8524bf3a25fe8326fda5364f7691c75903b5eb32.tar.bz2 scummvm-rg350-8524bf3a25fe8326fda5364f7691c75903b5eb32.zip |
Change script file loading code to use Common::IFFParser instead of a self written IFF reader.
svn-id: r40488
Diffstat (limited to 'engines/kyra/script.h')
-rw-r--r-- | engines/kyra/script.h | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/engines/kyra/script.h b/engines/kyra/script.h index da229d7e2a..c09e4eedf1 100644 --- a/engines/kyra/script.h +++ b/engines/kyra/script.h @@ -29,6 +29,7 @@ #include "common/stream.h" #include "common/array.h" #include "common/func.h" +#include "common/iff_container.h" namespace Kyra { @@ -64,34 +65,28 @@ struct EMCState { #define stackPos(x) (script->stack[script->sp+x]) #define stackPosString(x) ((const char*)&script->dataPtr->text[READ_BE_UINT16(&script->dataPtr->text[stackPos(x)<<1])]) -#define FORM_CHUNK 0x4D524F46 -#define TEXT_CHUNK 0x54584554 -#define DATA_CHUNK 0x41544144 -#define ORDR_CHUNK 0x5244524F -#define AVTL_CHUNK 0x4C545641 - class Resource; class KyraEngine_v1; -class IFFParser { +class IFFParser : public Common::IFFParser { public: - IFFParser() : _stream(0), _startOffset(0), _endOffset(0) {} - IFFParser(const char *filename, Resource *res) : _stream(0), _startOffset(0), _endOffset(0) { setFile(filename, res); } - ~IFFParser() { destroy(); } - - void setFile(const char *filename, Resource *res); - - operator bool() const { return (_startOffset != _endOffset) && _stream; } - - uint32 getFORMBlockSize(); - uint32 getBlockSize(const uint32 chunk); - bool loadBlock(const uint32 chunk, void *loadTo, uint32 ptrSize); -private: - void destroy(); - - Common::SeekableReadStream *_stream; - uint32 _startOffset; - uint32 _endOffset; + IFFParser(Common::SeekableReadStream &input) : Common::IFFParser(input) { + // It seems Westwood missunderstood the 'size' field of the FORM chunk. + // + // For EMC scripts (type EMC2) it's filesize instead of filesize - 8, + // means accidently including the 8 bytes used by the chunk header for the FORM + // chunk. + // + // For TIM scripts (type AVFS) it's filesize - 12 instead of filesize - 8, + // means it will not include the size of the 'type' field in the FORM chunk, + // instead of only not including the chunk header size. + // + // Both lead to some problems in our IFF parser, either reading after the end + // of file or producing a "Chunk overread" error message. To work around this + // we need to adjust the size field properly. + if (_typeId == MKID_BE('EMC2') || _typeId == MKID_BE('AVFS')) + _formChunk.size = input.size() - 8; + } }; class EMCInterpreter { |