From 30de1f34ca9c5816dd17f452fbc59c785ca42c93 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sat, 26 Oct 2013 18:03:44 -0400 Subject: DIRECTOR: Fix getting RIFF resources --- engines/director/resource.cpp | 30 ++++++++++++++++++++++++++++++ engines/director/resource.h | 1 + 2 files changed, 31 insertions(+) diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp index b9e6b1de8a..1c4bd33a19 100644 --- a/engines/director/resource.cpp +++ b/engines/director/resource.cpp @@ -248,6 +248,36 @@ bool RIFFArchive::openStream(Common::SeekableReadStream *stream) { return true; } +Common::SeekableReadStream *RIFFArchive::getResource(uint32 tag, uint16 id) { + if (!_types.contains(tag)) + error("Archive does not contain '%s' %04x", tag2str(tag), id); + + const ResourceMap &resMap = _types[tag]; + + if (!resMap.contains(id)) + error("Archive does not contain '%s' %04x", tag2str(tag), id); + + const Resource &res = resMap[id]; + + // Adjust to skip the resource header + uint32 offset = res.offset + 12; + uint32 size = res.size - 12; + + // Skip the Pascal string + _stream->seek(offset); + byte stringSize = _stream->readByte() + 1; // 1 for this byte + offset += stringSize; + size -= stringSize; + + // Align to nearest word boundary + if (offset & 1) { + offset++; + size--; + } + + return new Common::SeekableSubReadStream(_stream, offset, offset + size); +} + // RIFX Archive code diff --git a/engines/director/resource.h b/engines/director/resource.h index f757c9c0ee..055abe98f0 100644 --- a/engines/director/resource.h +++ b/engines/director/resource.h @@ -92,6 +92,7 @@ public: ~RIFFArchive() {} bool openStream(Common::SeekableReadStream *stream); + Common::SeekableReadStream *getResource(uint32 tag, uint16 id); }; class RIFXArchive : public Archive { -- cgit v1.2.3