Ticket #1981: smush3.patch

File smush3.patch, 5.0 KB (added by fingolfin, 19 years ago)
  • chunk.cpp

    RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.cpp,v
    retrieving revision 1.36
    diff -u -d -r1.36 chunk.cpp
     
    8585        return true;
    8686}
    8787
    88 FileChunk::FileChunk(const Common::String &name, int offset)
    89         : _name(name) {
    90         if (!g_scumm->openFile(_data, name.c_str()))
     88FileChunk::FileChunk(ScummFile *data, int offset) {
     89        _data = data;
     90        _deleteData = false;
     91
     92        _data->seek(offset, seek_start);
     93        _type = _data->readUint32BE();
     94        _size = _data->readUint32BE();
     95        _offset = _data->pos();
     96        _curPos = 0;
     97}
     98
     99FileChunk::FileChunk(const Common::String &name, int offset) {
     100        _data = new ScummFile();
     101        _deleteData = true;
     102        if (!g_scumm->openFile(*_data, name.c_str()))
    91103                error("FileChunk: Unable to open file %s", name.c_str());
    92104
    93         _data.seek(offset);
    94         _type = _data.readUint32BE();
    95         _size = _data.readUint32BE();
    96         _offset = _data.pos();
     105        _data->seek(offset, seek_start);
     106        _type = _data->readUint32BE();
     107        _size = _data->readUint32BE();
     108        _offset = _data->pos();
    97109        _curPos = 0;
    98110}
    99111
    100112FileChunk::~FileChunk() {
     113        if (_deleteData)
     114                delete _data;
    101115}
    102116
    103117Chunk *FileChunk::subBlock() {
    104         FileChunk *ptr = new FileChunk(_name, _offset + _curPos);
    105         _data.seek(_offset + _curPos + sizeof(Chunk::type) + sizeof(uint32));
     118        FileChunk *ptr = new FileChunk(_data, _offset + _curPos);
    106119        seek(sizeof(Chunk::type) + sizeof(uint32) + ptr->getSize());
    107120        return ptr;
    108121}
    109122
     123void FileChunk::reseek() {
     124        _data->seek(_offset + _curPos);
     125}
     126
    110127bool FileChunk::read(void *buffer, uint32 size) {
    111128        if (size <= 0 || (_curPos + size) > _size)
    112129                error("invalid buffer read request");
    113130
    114 //      _data.seek(_offset + _curPos);
    115         _data.read(buffer, size);
     131        _data->read(buffer, size);
    116132        _curPos += size;
    117133        return true;
    118134}
     
    122138}
    123139
    124140byte FileChunk::getByte() {
    125 //      _data.seek(_offset + _curPos);
    126141        _curPos++;
    127142
    128143        if (_curPos > _size)
    129144                error("invalid byte read request");
    130145
    131         return _data.readByte();
     146        return _data->readByte();
    132147}
    133148
    134149int16 FileChunk::getShort() {
     
    136151}
    137152
    138153uint16 FileChunk::getWord() {
    139 //      _data.seek(_offset + _curPos);
    140154        _curPos += 2;
    141155
    142156        if (_curPos > _size)
    143157                error("invalid word read request");
    144158
    145         return _data.readUint16LE();
     159        return _data->readUint16LE();
    146160}
    147161
    148162uint32 FileChunk::getDword() {
    149 //      _data.seek(_offset + _curPos);
    150163        _curPos += 4;
    151164
    152165        if (_curPos > _size)
    153166                error("invalid dword read request");
    154167
    155         return _data.readUint32LE();
     168        return _data->readUint32LE();
    156169}
    157170
    158171MemoryChunk::MemoryChunk(byte *data) {
     
    171184        return ptr;
    172185}
    173186
     187void MemoryChunk::reseek() {
     188}
     189
    174190bool MemoryChunk::read(void *buffer, uint32 size) {
    175191        if (size <= 0 || (_curPos + size) > _size)
    176192                error("invalid buffer read request");
  • chunk.h

    RCS file: /cvsroot/scummvm/scummvm/scumm/smush/chunk.h,v
    retrieving revision 1.19
    diff -u -d -r1.19 chunk.h
     
    3939        virtual type getType() const = 0;
    4040        virtual uint32 getSize() const = 0;
    4141        virtual Chunk *subBlock() = 0;
     42        virtual void reseek() = 0;
    4243        virtual bool eof() const = 0;
    4344        virtual uint32 tell() const = 0;
    4445        virtual bool seek(int32 delta, seek_type dir = seek_cur) = 0;
     
    4748        virtual byte getByte() = 0;
    4849        virtual int16 getShort() = 0;
    4950        virtual uint16 getWord() = 0;
    50         virtual uint32 getDword()= 0;
     51        virtual uint32 getDword() = 0;
    5152};
    5253
    5354// Common functionality for concrete chunks (FileChunk, MemoryChunk)
     
    6970
    7071class FileChunk : public BaseChunk {
    7172private:
    72         Common::String _name;
    73         ScummFile _data;
     73        ScummFile *_data;
     74        bool _deleteData;
    7475        uint32 _offset;
    7576
     77        FileChunk(ScummFile *data, int offset);
    7678public:
    7779        FileChunk(const Common::String &name, int offset = 0);
    7880        virtual ~FileChunk();
    7981        Chunk *subBlock();
     82        void reseek();
    8083        bool read(void *buffer, uint32 size);
    8184        int8 getChar();
    8285        byte getByte();
     
    9295public:
    9396        MemoryChunk(byte *data);
    9497        Chunk *subBlock();
     98        void reseek();
    9599        bool read(void *buffer, uint32 size);
    96100        int8 getChar();
    97101        byte getByte();
  • smush_player.cpp

    RCS file: /cvsroot/scummvm/scummvm/scumm/smush/smush_player.cpp,v
    retrieving revision 1.170
    diff -u -d -r1.170 smush_player.cpp
     
    892892
    893893        while (!b.eof()) {
    894894                Chunk *sub = b.subBlock();
    895                 if (sub->getSize() & 1) b.seek(1);
    896895                switch (sub->getType()) {
    897896                case TYPE_NPAL:
    898897                        handleNewPalette(*sub);
     
    942941                default:
    943942                        error("Unknown frame subChunk found : %s, %d", Chunk::ChunkString(sub->getType()), sub->getSize());
    944943                }
     944
     945                b.reseek();
     946                if (sub->getSize() & 1)
     947                        b.seek(1);
     948
    945949                delete sub;
    946950        }
    947951
     
    10851089        }
    10861090        delete sub;
    10871091
     1092        _base->reseek();
     1093
    10881094        if (_insanity)
    10891095                _vm->_sound->processSound();
    10901096