From 459115fb7855cfe10c6db3273cc1be0045b21254 Mon Sep 17 00:00:00 2001 From: Scott Percival Date: Wed, 12 Apr 2023 01:49:18 +0800 Subject: [PATCH] DIRECTOR: Fix castInfo loading for D5 --- engines/director/archive.cpp | 21 +++++++++++++- engines/director/cast.cpp | 56 ++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 32 deletions(-) diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp index d7131bb12f1..7f163c71b51 100644 --- a/engines/director/archive.cpp +++ b/engines/director/archive.cpp @@ -339,7 +339,7 @@ void MacArchive::readTags() { res.name = _resFork->getResName(tagArray[i], idArray[j]); res.tag = tagArray[i]; res.index = idArray[j]; - debug(3, "Found MacArchive resource '%s' %d: %s", tag2str(tagArray[i]), idArray[j], res.name.c_str()); + debug(3, "MacArchive::readTags(): Found MacArchive resource '%s' %d: %s", tag2str(tagArray[i]), idArray[j], res.name.c_str()); if (ConfMan.getBool("dump_scripts")) dumpChunk(res, out); } @@ -349,6 +349,12 @@ void MacArchive::readTags() { _types[tagArray[i]] = resMap; } } + if (debugChannelSet(5, kDebugLoading)) { + debugC(5, kDebugLoading, "MacArchive::readTags(): Resources found:"); + for (const auto &it : _types) { + debugC(5, kDebugLoading, "%s: %d", tag2str(it._key), it._value.size()); + } + } } Common::SeekableReadStreamEndian *MacArchive::getResource(uint32 tag, uint16 id) { @@ -449,6 +455,12 @@ bool RIFFArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff stream->seek(startResPos); } + if (debugChannelSet(5, kDebugLoading)) { + debugC(5, kDebugLoading, "RIFFArchive::openStream(): Resources found:"); + for (const auto &it : _types) { + debugC(5, kDebugLoading, "%s: %d", tag2str(it._key), it._value.size()); + } + } return true; } @@ -741,6 +753,13 @@ bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 _resources.push_back(&res); } + if (debugChannelSet(5, kDebugLoading)) { + debugC(5, kDebugLoading, "RIFXArchive::readMemoryMap(): Resources found:"); + for (const auto &it : _types) { + debugC(5, kDebugLoading, "%s: %d", tag2str(it._key), it._value.size()); + } + } + return true; } diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp index 8e586c20466..7d3f905bcf7 100644 --- a/engines/director/cast.cpp +++ b/engines/director/cast.cpp @@ -1094,7 +1094,7 @@ void Cast::loadCastData(Common::SeekableReadStreamEndian &stream, uint16 id, Res if (debugChannelSet(5, kDebugLoading) && stream.size() < 2048) stream.hexdump(stream.size()); - uint32 castSize, castInfoSize, size3, castType, castSizeToRead; + uint32 castDataSize, castInfoSize, castType, castDataSizeToRead, castDataOffset, castInfoOffset; byte flags1 = 0, unk1 = 0, unk2 = 0, unk3 = 0; // D2-3 cast members should be loaded in loadCastDataVWCR @@ -1103,7 +1103,6 @@ void Cast::loadCastData(Common::SeekableReadStreamEndian &stream, uint16 id, Res size1 = stream.readUint16(); sizeToRead = size1 +16; // 16 is for bounding rects size2 = stream.readUint32(); - size3 = 0; castType = stream.readByte(); unk1 = stream.readByte(); unk2 = stream.readByte(); @@ -1112,44 +1111,38 @@ void Cast::loadCastData(Common::SeekableReadStreamEndian &stream, uint16 id, Res #endif if (_version >= kFileVer400 && _version < kFileVer500) { - castSize = stream.readUint16(); - castSizeToRead = castSize; + castDataSize = stream.readUint16(); + castDataSizeToRead = castDataSize; castInfoSize = stream.readUint32(); - size3 = 0; // these bytes are common but included in cast size castType = stream.readByte(); - castSizeToRead -= 1; - if (castSizeToRead) { + castDataSizeToRead -= 1; + if (castDataSizeToRead) { flags1 = stream.readByte(); - castSizeToRead -= 1; + castDataSizeToRead -= 1; } + castDataOffset = stream.pos(); + castInfoOffset = stream.pos() + castDataSizeToRead; } else if (_version >= kFileVer500 && _version < kFileVer600) { castType = stream.readUint32(); - size3 = stream.readUint32(); castInfoSize = stream.readUint32(); - castSize = stream.readUint32(); - if (castType == 1) { - if (size3 == 0) - return; - for (uint32 skip = 0; skip < (castSize - 4) / 4; skip++) - stream.readUint32(); - } - - castSizeToRead = stream.size(); + castDataSize = stream.readUint32(); + castDataSizeToRead = castDataSize; + castInfoOffset = stream.pos(); + castDataOffset = stream.pos() + castInfoSize; } else { error("Cast::loadCastData: unsupported Director version (%d)", _version); } - debugC(3, kDebugLoading, "Cast::loadCastData(): CASt: id: %d type: %x castSize: %d castInfoSize: %d (%x) size3: %d unk1: %d unk2: %d unk3: %d", - id, castType, castSize, castInfoSize, castInfoSize, size3, unk1, unk2, unk3); + debugC(3, kDebugLoading, "Cast::loadCastData(): CASt: id: %d type: %x castDataSize: %d castInfoSize: %d (%x) unk1: %d unk2: %d unk3: %d", + id, castType, castDataSize, castInfoSize, castInfoSize, unk1, unk2, unk3); // read the cast member itself - - byte *data = (byte *)calloc(castSizeToRead, 1); - stream.read(data, castSizeToRead); - - Common::MemoryReadStreamEndian castStream(data, castSizeToRead, stream.isBE()); + byte *data = (byte *)calloc(castDataSizeToRead, 1); + stream.seek(castDataOffset); + stream.read(data, castDataSizeToRead); + Common::MemoryReadStreamEndian castStream(data, castDataSizeToRead, stream.isBE()); if (_loadedCast->contains(id)) { warning("Cast::loadCastData(): Multiple cast members with ID %d, overwriting", id); @@ -1225,13 +1218,14 @@ void Cast::loadCastData(Common::SeekableReadStreamEndian &stream, uint16 id, Res free(data); // read the cast member info - - if (castInfoSize && _version < kFileVer500) { - loadCastInfo(stream, id); + if (castInfoSize) { + data = (byte *)calloc(castInfoSize, 1); + stream.seek(castInfoOffset); + stream.read(data, castInfoSize); + Common::MemoryReadStreamEndian castInfoStream(data, castInfoSize, stream.isBE()); + loadCastInfo(castInfoStream, id); + free(data); } - - if (size3) - warning("Cast::loadCastData(): size3: %x", size3); } struct LingoContextEntry {