[Scummvm-git-logs] scummvm master -> 33060e14d83fed5f5fb88e79f4d0b0a8719ad8d9

djsrv dservilla at gmail.com
Thu Jun 3 19:56:19 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
33060e14d8 DIRECTOR: Fix offsets in dumped movies


Commit: 33060e14d83fed5f5fb88e79f4d0b0a8719ad8d9
    https://github.com/scummvm/scummvm/commit/33060e14d83fed5f5fb88e79f4d0b0a8719ad8d9
Author: djsrv (dservilla at gmail.com)
Date: 2021-06-03T15:54:53-04:00

Commit Message:
DIRECTOR: Fix offsets in dumped movies

Changed paths:
    engines/director/archive.cpp
    engines/director/archive.h


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index 21d902e9c3..fbbcf665e5 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -444,50 +444,63 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 
 	uint32 sz = endianStream.readUint32(); // size
 
-	// If it is an embedded file, dump it if requested
+	// If it is an embedded file, dump it if requested.
+	// Start by copying the movie data to a new buffer.
+	byte *dumpData = nullptr;
+	Common::SeekableMemoryWriteStream *dumpStream = nullptr;
 	if (ConfMan.getBool("dump_scripts") && startOffset) {
-		Common::DumpFile out;
-
-		char buf[256];
-		sprintf(buf, "./dumps/%s-%08x", g_director->getEXEName().c_str(), startOffset);
-
-		if (out.open(buf, true)) {
-			byte *data = (byte *)malloc(sz);
-
-			stream->seek(startOffset);
-			stream->read(data, sz);
-			out.write(data, sz);
-			out.flush();
-			out.close();
-
-			free(data);
-
-			stream->seek(startOffset + 8);
-		} else {
-			warning("RIFXArchive::openStream(): Can not open dump file %s", buf);
-		}
+		dumpData = (byte *)malloc(sz);
+		dumpStream = new Common::SeekableMemoryWriteStream(dumpData, sz);
+		stream->seek(startOffset);
+		stream->read(dumpData, sz);
+		stream->seek(startOffset + 8);
 	}
 
 	_rifxType = endianStream.readUint32();
 	warning("RIFX: type: %s", tag2str(_rifxType));
 
+	// Now read the memory map.
+	// At the same time, we will patch the offsets in the dump data.
+	bool readMapSuccess = false;
 	switch (_rifxType) {
 	case MKTAG('M', 'V', '9', '3'):
 	case MKTAG('M', 'C', '9', '5'):
-		if (!readMemoryMap(endianStream, moreOffset))
-			return false;
+		readMapSuccess = readMemoryMap(endianStream, moreOffset, dumpStream, startOffset);
 		break;
 	case MKTAG('A', 'P', 'P', 'L'):
-		return readMemoryMap(endianStream, moreOffset);
+		readMapSuccess = readMemoryMap(endianStream, moreOffset, dumpStream, startOffset);
+		break;
 	case MKTAG('F', 'G', 'D', 'M'):
 	case MKTAG('F', 'G', 'D', 'C'):
-		if (!readAfterburnerMap(endianStream, moreOffset))
-			return false;
+		readMapSuccess = readAfterburnerMap(endianStream, moreOffset);
 		break;
 	default:
-		return false;
+		break;
 	}
 
+	// Now that the dump data has been patched, actually dump it.
+	if (dumpData) {
+		Common::DumpFile out;
+
+		char buf[256];
+		sprintf(buf, "./dumps/%s-%08x", g_director->getEXEName().c_str(), startOffset);
+
+		if (out.open(buf, true)) {
+			out.write(dumpData, sz);
+			out.flush();
+			out.close();
+		} else {
+			warning("RIFXArchive::openStream(): Can not open dump file %s", buf);
+		}
+
+		free(dumpData);
+		delete dumpStream;
+	}
+
+	// If we couldn't read the map, we can't do anything past this point.
+	if (!readMapSuccess)
+		return false;
+
 	if (ConfMan.getBool("dump_scripts")) {
 		debug("RIFXArchive::openStream(): Dumping %d resources", _resources.size());
 
@@ -552,13 +565,22 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 	return true;
 }
 
-bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset) {
+bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset, Common::SeekableMemoryWriteStream *dumpStream, uint32 movieStartOffset) {
 	if (stream.readUint32() != MKTAG('i', 'm', 'a', 'p'))
 		return false;
 
 	stream.readUint32(); // imap length
 	stream.readUint32(); // unknown
+	uint32 mmapOffsetPos = stream.pos();
 	uint32 mmapOffset = stream.readUint32() + moreOffset;
+	if (dumpStream) {
+		// If we're dumping the movie, patch this offset in the dump data.
+		dumpStream->seek(mmapOffsetPos - movieStartOffset);
+		if (stream.isBE())
+			dumpStream->writeUint32BE(mmapOffset - movieStartOffset);
+		else
+			dumpStream->writeUint32LE(mmapOffset - movieStartOffset);
+	}
 	uint32 version = stream.readUint32(); // 0 for 4.0, 0x4c1 for 5.0, 0x4c7 for 6.0, 0x708 for 8.5, 0x742 for 10.0
 	warning("mmap: version: %x", version);
 
@@ -583,7 +605,15 @@ bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32
 	for (uint32 i = 0; i < resCount; i++) {
 		uint32 tag = stream.readUint32();
 		uint32 size = stream.readUint32();
+		uint32 offsetPos = stream.pos();
 		int32 offset = stream.readUint32() + moreOffset;
+		if (dumpStream) {
+			dumpStream->seek(offsetPos - movieStartOffset);
+			if (stream.isBE())
+				dumpStream->writeUint32BE(offset - movieStartOffset);
+			else
+				dumpStream->writeUint32LE(offset - movieStartOffset);
+		}
 		uint16 flags = stream.readUint16();
 		uint16 unk1 = stream.readUint16();
 		uint32 nextFreeResourceId = stream.readUint32(); // for free resources, the next id, flag like for imap and mmap resources
diff --git a/engines/director/archive.h b/engines/director/archive.h
index 0e4c4b1fcf..bfa001f8c1 100644
--- a/engines/director/archive.h
+++ b/engines/director/archive.h
@@ -25,6 +25,7 @@
 
 namespace Common {
 class MacResManager;
+class SeekableMemoryWriteStream;
 class SeekableReadStreamEndian;
 class SeekableReadStream;
 }
@@ -124,7 +125,7 @@ public:
 	Resource getResourceDetail(uint32 tag, uint16 id) override;
 
 private:
-	bool readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset);
+	bool readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset, Common::SeekableMemoryWriteStream *dumpStream, uint32 movieStartOffset);
 	bool readAfterburnerMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset);
 	void readCast(Common::SeekableReadStreamEndian &casStream);
 	void readKeyTable(Common::SeekableReadStreamEndian &keyStream);




More information about the Scummvm-git-logs mailing list