[Scummvm-git-logs] scummvm master -> 57845187a2db0d21afe2f72039f99851f3d3da6f

sev- noreply at scummvm.org
Thu Jun 26 19:20:19 UTC 2025


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

Summary:
e5348fbd8e DIRECTOR: Start writing director movies: imap, mmap, keymap
7e6e1d086a DIRECTOR: Archive:: Write Cast data in writeStream()
be3a2da0fc DIRECTOR: CHUNK: Start writing the chunk.h file
10ff5f5ed2 DIRECTOR: Write resource chunks verbatim except imap, mmap, keymap
36d599c0d3 DIRECTOR: Calling write from DirectorEngine and minor fixes
57845187a2 DIRECTOR: Fix formatting and other minor issues


Commit: e5348fbd8eaa721f1a73f08002ac7b3bb617be42
    https://github.com/scummvm/scummvm/commit/e5348fbd8eaa721f1a73f08002ac7b3bb617be42
Author: Malhar (themalharbdv2046 at gmail.com)
Date: 2025-06-26T21:20:09+02:00

Commit Message:
DIRECTOR: Start writing director movies: imap, mmap, keymap

Writing movies in Director (introduced in Director 4) is essential
for quite a few games in Director.
This is the start of being able to write director movies in ScummVM
Currently only write imap, mmap and keymap
Incomplete function for reading After Burner Map

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


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index 455f02ae5c2..a6afb39e0e3 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -61,7 +61,6 @@ bool Archive::openFile(const Common::Path &path) {
 		close();
 		return false;
 	}
-
 	return true;
 }
 
@@ -218,6 +217,7 @@ Common::SeekableReadStreamEndian *Archive::getMovieResourceIfPresent(uint32 tag)
 	if (g_director->getVersion() >= 400) {
 		if (_movieChunks.contains(tag) && hasResource(tag, _movieChunks[tag]))
 			return getResource(tag, _movieChunks[tag]);
+
 	} else if (hasResource(tag, -1)) {
 		return getFirstResource(tag);
 	}
@@ -587,6 +587,7 @@ RIFXArchive::~RIFXArchive() {
 		free(it._value);
 }
 
+// Parallel to DirectorFile::read from ProjectorRays
 bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOffset) {
 	if (stream != _stream) {
 		close();
@@ -597,10 +598,10 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 
 	uint32 moreOffset = 0;
 
-	uint32 headerTag = stream->readUint32BE();
+	_metaTag = stream->readUint32BE();
 
-	if (headerTag != MKTAG('R', 'I', 'F', 'X') &&
-		headerTag != MKTAG('X', 'F', 'I', 'R')) {
+	if (_metaTag != MKTAG('R', 'I', 'F', 'X') &&
+		_metaTag != MKTAG('X', 'F', 'I', 'R')) {
 		// Check if it is MacBinary
 
 		stream->seek(startOffset);
@@ -622,40 +623,40 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 			moreOffset = Common::MacResManager::getDataForkOffset();
 			stream->seek(startOffset + moreOffset);
 
-			headerTag = stream->readUint32BE();
+			_metaTag = stream->readUint32BE();
 		}
 	}
 
-	if (headerTag == MKTAG('R', 'I', 'F', 'X')) {
+	if (_metaTag == MKTAG('R', 'I', 'F', 'X')) {
 		_isBigEndian = true;
-	} else if (SWAP_BYTES_32(headerTag) == MKTAG('R', 'I', 'F', 'X')) {
+	} else if (SWAP_BYTES_32(_metaTag) == MKTAG('R', 'I', 'F', 'X')) {
 		_isBigEndian = false;
 	} else {
-		warning("RIFXArchive::openStream(): RIFX or XFIR expected but %s found", tag2str(headerTag));
+		warning("RIFXArchive::openStream(): RIFX or XFIR expected but %s found", tag2str(_metaTag));
 		return false;
 	}
 
 	Common::SeekableReadStreamEndianWrapper endianStream(stream, _isBigEndian, DisposeAfterUse::NO);
 	endianStream.seek(startOffset + moreOffset + 4);
 
-	uint32 sz = endianStream.readUint32() + 8; // size
+	_size = endianStream.readUint32() + 8; // size
 
 	// 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) {
-		dumpData = (byte *)malloc(sz);
-		dumpStream = new Common::SeekableMemoryWriteStream(dumpData, sz);
+		dumpData = (byte *)malloc(_size);
+		dumpStream = new Common::SeekableMemoryWriteStream(dumpData, _size);
 		stream->seek(startOffset);
-		stream->read(dumpData, sz);
+		stream->read(dumpData, _size);
 		stream->seek(startOffset + 8);
 
 		// Add the padding data to match the file size
-		endianStream.seek(sz - 4);
+		endianStream.seek(_size - 4);
 		uint32 _junk = endianStream.readUint32();
 		if (_junk != 0) {
-			dumpStream->seek(sz - 4);
+			dumpStream->seek(_size - 4);
 			dumpStream->writeUint32BE(0);
 		}
 
@@ -671,11 +672,10 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 	switch (_rifxType) {
 	case MKTAG('M', 'V', '9', '3'):
 	case MKTAG('M', 'C', '9', '5'):
-		readMapSuccess = readMemoryMap(endianStream, moreOffset, dumpStream, startOffset);
-		break;
 	case MKTAG('A', 'P', 'P', 'L'):
 		readMapSuccess = readMemoryMap(endianStream, moreOffset, dumpStream, startOffset);
 		break;
+
 	case MKTAG('F', 'G', 'D', 'M'):
 	case MKTAG('F', 'G', 'D', 'C'):
 		readMapSuccess = readAfterburnerMap(endianStream, moreOffset);
@@ -694,7 +694,7 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 		Common::sprintf_s(buf, "./dumps/%s-%08x", encodePathForDump(g_director->getEXEName()).c_str(), startOffset);
 
 		if (out.open(buf, true)) {
-			out.write(dumpData, sz);
+			out.write(dumpData, _size);
 			out.flush();
 			out.close();
 		} else {
@@ -771,6 +771,8 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 		}
 	}
 
+	// writeStream();
+	// g_system->quit();
 	return true;
 }
 
@@ -780,23 +782,23 @@ bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32
 
 	_types[MKTAG('i', 'm', 'a', 'p')][0].accessed = true; // Mark it as accessed
 
-	stream.readUint32(); // imap length
-	uint32 mapversion = stream.readUint32(); // version, seen 0 or 1
-	uint32 mmapOffsetPos = stream.pos();
-	uint32 mmapOffset = stream.readUint32() + moreOffset;
+	_imapLength = stream.readUint32(); // imap length
+	_mapversion = stream.readUint32(); // version, seen 0 or 1
+	_mmapOffsetPos = stream.pos();
+	_mmapOffset = stream.readUint32() + moreOffset;
+
 	if (dumpStream) {
 		// If we're dumping the movie, patch this offset in the dump data.
-		dumpStream->seek(mmapOffsetPos - movieStartOffset);
+		dumpStream->seek(_mmapOffsetPos - movieStartOffset);
 		if (stream.isBE())
-			dumpStream->writeUint32BE(mmapOffset - movieStartOffset);
+			dumpStream->writeUint32BE(_mmapOffset - movieStartOffset);
 		else
-			dumpStream->writeUint32LE(mmapOffset - movieStartOffset);
+			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
-	debugC(2, kDebugLoading, "RIFXArchive::readMemoryMap: mapversion: %d version: %x offset: 0x%x (%d)", mapversion, version, mmapOffset, mmapOffset);
-
-	stream.seek(mmapOffset);
+	_version = stream.readUint32(); // 0 for 4.0, 0x4c1 for 5.0, 0x4c7 for 6.0, 0x708 for 8.5, 0x742 for 10.0
+	debugC(2, kDebugLoading, "RIFXArchive::readMemoryMap: _mapversion: %d version: %x offset: 0x%x (%d)", _mapversion, _version, _mmapOffset, _mmapOffset);
 
+	stream.seek(_mmapOffset);
 	if (stream.readUint32() != MKTAG('m', 'm', 'a', 'p')) {
 		warning("RIFXArchive::readMemoryMap: mmap expected but not found");
 		return false;
@@ -838,6 +840,9 @@ bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32
 		res.offset = offset;
 		res.size = size;
 		res.tag = tag;
+		res.flags = flags;
+		res.unk1 = unk1;
+		res.nextFreeResourceID = nextFreeResourceId;
 		res.accessed = false;
 		_resources.push_back(&res);
 	}
@@ -861,15 +866,15 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableReadStreamEndian &stream, u
 		return false;
 	}
 
-	uint32 fverLength = readVarInt(stream);
+	_fverLength = readVarInt(stream);
 	start = stream.pos();
-	uint32 version = readVarInt(stream);
-	debugC(3, kDebugLoading, "Fver: version: %x", version);
+	_afterBurnerVersion = readVarInt(stream);
+	debugC(3, kDebugLoading, "Fver: version: %x", _afterBurnerVersion);
 	end = stream.pos();
 
-	if (end - start != fverLength) {
-		warning("RIFXArchive::readAfterburnerMap(): Expected Fver of length %d but read %d bytes", fverLength, end - start);
-		stream.seek(start + fverLength);
+	if (end - start != _fverLength) {
+		warning("RIFXArchive::readAfterburnerMap(): Expected Fver of length %d but read %d bytes", _fverLength, end - start);
+		stream.seek(start + _fverLength);
 	}
 
 	// Compression types
@@ -878,29 +883,29 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableReadStreamEndian &stream, u
 		return false;
 	}
 
-	uint32 fcdrLength = readVarInt(stream);
-	stream.skip(fcdrLength);
+	_fcdrLength = readVarInt(stream);
+	stream.skip(_fcdrLength);
 
 	// Afterburner map
 	if (stream.readUint32() != MKTAG('A', 'B', 'M', 'P')) {
 		warning("RIFXArchive::readAfterburnerMap(): ABMP expected but not found");
 		return false;
 	}
-	uint32 abmpLength = readVarInt(stream);
-	uint32 abmpEnd = stream.pos() + abmpLength;
-	uint32 abmpCompressionType = readVarInt(stream);
-	unsigned long abmpUncompLength = readVarInt(stream);
-	unsigned long abmpActualUncompLength = abmpUncompLength;
+	_abmpLength = readVarInt(stream);
+	_abmpEnd = stream.pos() + _abmpLength;
+	_abmpCompressionType = readVarInt(stream);
+	_abmpUncompLength = readVarInt(stream);
+	_abmpActualUncompLength = _abmpUncompLength;
 	debugC(3, kDebugLoading, "ABMP: length: %d compressionType: %d uncompressedLength: %lu",
-		abmpLength, abmpCompressionType, abmpUncompLength);
+		_abmpLength, _abmpCompressionType, _abmpUncompLength);
 
-	Common::SeekableReadStreamEndian *abmpStream = readZlibData(stream, abmpEnd - stream.pos(), &abmpActualUncompLength, _isBigEndian);
+	Common::SeekableReadStreamEndian *abmpStream = readZlibData(stream, _abmpEnd - stream.pos(), &_abmpActualUncompLength, _isBigEndian);
 	if (!abmpStream) {
 		warning("RIFXArchive::readAfterburnerMap(): Could not uncompress ABMP");
 		return false;
 	}
-	if (abmpUncompLength != abmpActualUncompLength) {
-		warning("ABMP: Expected uncompressed length %lu but got length %lu", abmpUncompLength, abmpActualUncompLength);
+	if (_abmpUncompLength != _abmpActualUncompLength) {
+		warning("ABMP: Expected uncompressed length %lu but got length %lu", _abmpUncompLength, _abmpActualUncompLength);
 	}
 
 	if (ConfMan.getBool("dump_scripts")) {
@@ -1022,16 +1027,16 @@ void RIFXArchive::readCast(Common::SeekableReadStreamEndian &casStream, uint16 l
 }
 
 void RIFXArchive::readKeyTable(Common::SeekableReadStreamEndian &keyStream) {
-	uint16 entrySize = keyStream.readUint16(); // Should always be 12 (3 uint32's)
-	uint16 entrySize2 = keyStream.readUint16();
-	uint32 entryCount = keyStream.readUint32(); // There are more entries than actually used
-	uint32 usedCount = keyStream.readUint32();
+	_keyTableEntrySize = keyStream.readUint16(); // Should always be 12 (3 uint32's)
+	_keyTableEntrySize2 = keyStream.readUint16();
+	_keyTableEntryCount = keyStream.readUint32(); // There are more entries than actually used
+	_keyTableUsedCount = keyStream.readUint32();
 
-	debugC(2, kDebugLoading, "KEY*: entrySize: %d entrySize2: %d entryCount: %d usedCount: %d", entrySize, entrySize2, entryCount, usedCount);
+	debugC(2, kDebugLoading, "KEY*: _keyTableEntrySize: %d _keyTableEntrySize2: %d _keyTableEntryCount: %d usedCount: %d", _keyTableEntrySize, _keyTableEntrySize2, _keyTableEntryCount, _keyTableUsedCount);
 
 	ResourceMap &castResMap = _types[MKTAG('C', 'A', 'S', 't')];
 
-	for (uint16 i = 0; i < usedCount; i++) {
+	for (uint16 i = 0; i < _keyTableUsedCount; i++) {
 		uint32 childIndex = keyStream.readUint32();
 		uint32 parentIndex = keyStream.readUint32();
 		uint32 childTag = keyStream.readUint32();
@@ -1148,4 +1153,165 @@ Common::String RIFXArchive::formatArchiveInfo() {
 	return result;
 }
 
+bool RIFXArchive::writeStream() {
+	// I'm ignoring the startOffset
+	// For RIFX stream, moreoffset = 0
+	byte *dumpData = nullptr;
+
+	// Probably don't need to allocate this much size
+	debug("What is the _size while writing = %d", _size);
+	dumpData = (byte *)malloc(_size);
+
+	Common::SeekableMemoryWriteStream *writeStream = new Common::SeekableMemoryWriteStream(dumpData, _size);
+	
+	writeStream->writeUint32BE(_metaTag); // The _metaTag is "RIFX" or "XFIR" for this case 
+										  	// the reason for writing it BigEndian is because that's how we read it, we don't change it
+	writeStream->writeUint32LE(_size); // The size of the RIFX archive
+	writeStream->writeUint32LE(_rifxType);	// e.g. "MV93", "MV95"
+
+	switch (_rifxType) {
+	case MKTAG('M', 'V', '9', '3'):
+	case MKTAG('M', 'C', '9', '5'):
+	case MKTAG('A', 'P', 'P', 'L'):
+		writeMemoryMap(writeStream);
+		break;
+
+	case MKTAG('F', 'G', 'D', 'M'):
+	case MKTAG('F', 'G', 'D', 'C'):
+		writeAfterBurnerMap(writeStream);
+		break;
+	default:
+		break;
+	}
+
+	int32 keyTag = MKTAG('K', 'E', 'Y', '*');
+	if (hasResource(keyTag, -1)) {
+		uint16 firstID = getResourceIDList(keyTag)[0];
+		uint32 offset = getOffset(keyTag, firstID) + 8;	// I'm not sure why this +8 is there for
+														// But its consistent with RIFXArchive::getResource()
+		writeKeyTable(writeStream, offset);
+	}
+
+	Common::DumpFile out;
+	char buf[256];
+	Common::sprintf_s(buf, "./writtenMovie.dir");
+	
+	// Write the movie out, stored in dumpData
+	if (out.open(buf, true)) {
+		out.write(dumpData, _size);
+		out.flush();
+		out.close();
+		debugC(3, kDebugLoading, "RIFXArchive::writeStream:Saved the movie as file %s", buf);
+	} else {
+		warning("RIFXArchive::writeStream: Error saving the file %s", buf);
+	}
+
+	free(dumpData);
+	delete writeStream;
+	return true;
+}
+
+bool RIFXArchive::writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream) {
+	writeStream->writeUint32LE(MKTAG('i', 'm', 'a', 'p')); // The "imap" resource
+	writeStream->writeUint32LE(_imapLength);		// length of "imap" resource
+	writeStream->writeUint32LE(_mapversion);		// "imap" version
+	writeStream->writeUint32LE(_mmapOffset);		// offset of the "mmap" resource
+	writeStream->writeUint32LE(_version);
+
+	writeStream->seek(_mmapOffset);
+	writeStream->writeUint32LE(MKTAG('m', 'm', 'a', 'p'));
+
+
+	uint32 newSize = 0;
+	uint32 newResCount = _resources.size();
+	debug("What is the newRescount = %d", newResCount);
+	for (auto &it : _resources) {
+		newSize += it->size;
+	}
+
+	debug("Position before writing the mmap = %ld", writeStream->pos());
+	writeStream->writeUint32LE(newSize);
+	// I need to see what header size is
+	writeStream->writeUint16LE(0);
+	writeStream->writeUint16LE(0);
+	writeStream->writeUint32LE(0);
+
+	writeStream->writeUint32LE(newResCount);
+	writeStream->seek(8, SEEK_CUR);
+
+	// ID of the first 'free' resource
+	writeStream->writeUint32LE(0);
+
+	for (auto &it : _resources) {
+		debugC(3, kDebugLoading, "Writing RIFX Resource: tag: %s, size: %d, offset: %08x, flags: %x, unk1: %x, nextFreeResourceID: %d", 
+			tag2str(it->tag), it->size, it->offset, it->flags, it->unk1, it->nextFreeResourceID);
+		
+		// Write down the tag, the size and offset of the current resource
+		writeStream->writeUint32LE(it->tag);
+		writeStream->writeUint32LE(it->size);
+		writeStream->writeUint32LE(it->offset);
+		
+		// Currently ignoring flags, unk1 and nextFreeResourceID
+		writeStream->writeUint16LE(it->flags);
+		writeStream->writeUint16LE(it->unk1);
+		writeStream->writeUint32LE(it->nextFreeResourceID);
+	}
+
+	return true;
+}
+
+// This Function is incomplete, needs further changes before can be used
+bool RIFXArchive::writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStream) {
+	warning("RIFXArchive::writeAfterBurnerMap: STUB: Incomplete function, needs further changes, AfterBurnerMap not written");
+	return;
+
+	writeStream->writeUint32LE(MKTAG('F', 'v', 'e', 'r'));
+
+	// _fverLength and _afterBurnerVersion are shockwave variable type intagers
+	// So I'm writing them as 32bit intagers
+	writeStream->writeUint32LE(_fverLength);
+	uint32 start = writeStream->pos(); 
+
+	writeStream->writeUint32LE(_afterBurnerVersion);
+	uint32 end = writeStream->pos();
+
+	if (end - start != _fverLength) {
+		warning("RIFXArchive::writeAfterburnerMap(): Expected Fver of length %d but read %d bytes", _fverLength, end - start);
+		writeStream->seek(start + _fverLength);
+	}
+
+	writeStream->writeUint32LE(MKTAG('F', 'c', 'd', 'r'));
+	writeStream->writeUint32LE(_fcdrLength);
+	writeStream->seek(_fcdrLength, SEEK_CUR);
+
+	writeStream->writeUint32LE(MKTAG('A', 'B', 'M', 'P'));
+
+	return true;
+}
+
+bool RIFXArchive::writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset) {
+	writeStream->seek(offset);
+
+	writeStream->writeUint16LE(_keyTableEntrySize);
+	writeStream->writeUint16LE(_keyTableEntrySize2);
+	writeStream->writeUint32LE(_keyTableEntryCount);
+	writeStream->writeUint32LE(_keyTableUsedCount);
+
+	for (auto &childTag : _keyData) {
+		KeyMap keyMap = childTag._value;
+
+		for (auto &parentIndex : keyMap) {
+			KeyArray keyArray = parentIndex._value;
+
+			for (auto childIndex : keyArray) {
+				debug("RIFXArchive::writeKeyTable: _keyData contains tag: %s, parentIndex: %d, childIndex: %d", tag2str(childTag._key), parentIndex._key, childIndex);
+				writeStream->writeUint32LE(childIndex);
+				writeStream->writeUint32LE(parentIndex._key);
+				writeStream->writeUint32LE(childTag._key);	
+			}
+		}
+	}
+	
+	return true;
+}
 } // End of namespace Director
diff --git a/engines/director/archive.h b/engines/director/archive.h
index 987574f6078..34ba6b04a01 100644
--- a/engines/director/archive.h
+++ b/engines/director/archive.h
@@ -22,6 +22,7 @@
 #ifndef DIRECTOR_ARCHIVE_H
 #define DIRECTOR_ARCHIVE_H
 
+#include "common/hash-str.h"
 #include "common/file.h"
 
 namespace Common {
@@ -45,6 +46,9 @@ struct Resource {
 	uint32 castId;
 	uint32 libResourceId;
 	uint32 tag;
+	uint16 flags;
+	uint16 unk1;
+	uint32 nextFreeResourceID;
 	Common::String name;
 	Common::Array<Resource> children;
 	bool accessed;
@@ -57,8 +61,17 @@ public:
 
 	virtual bool openFile(const Common::Path &path);
 	virtual bool openStream(Common::SeekableReadStream *stream, uint32 offset = 0) = 0;
+	virtual bool writeStream() { 
+		// Saving Director movies was introduced in Director 4
+		// However, from DirectorEngine::createArchive, it is evident that after Director 4 only RIFX Archives were written
+		error("Archive::writeStream was called on a non-RIFX Archive, which is not allowed");
+		return false;
+	} 
 	virtual void close();
 
+	/* Loading Functions for Cast */
+	bool loadConfig(Cast *cast);
+
 	Common::Path getPathName() const { return _pathName; }
 	Common::String getFileName() const;
 	void setPathName(const Common::Path &name) { _pathName = name; }
@@ -134,6 +147,11 @@ public:
 	~RIFXArchive() override;
 
 	bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
+	bool writeStream() override;
+	bool writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream);
+	bool writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStreaa);
+	bool writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset);
+
 	Common::SeekableReadStreamEndian *getFirstResource(uint32 tag) override;
 	virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, bool fileEndianness);
 	Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, uint16 parentId) override;
@@ -148,6 +166,38 @@ private:
 	void readCast(Common::SeekableReadStreamEndian &casStream, uint16 libResourceId);
 	void readKeyTable(Common::SeekableReadStreamEndian &keyStream);
 
+	/* Memory Map data to save the file */
+	uint32 _metaTag;
+	uint32 _moreOffset;
+	uint32 _mapversion;
+	uint32 _mmapOffsetPos;
+	uint32 _mmapOffset;
+	uint32 _imapLength;
+	uint32 _version;
+	uint32 _size;
+
+	/* Key Table data to save the file */
+	uint16 _keyTableEntrySize;
+	uint16 _keyTableEntrySize2;
+	uint32 _keyTableEntryCount;
+	uint32 _keyTableUsedCount;
+	
+	/* AfterBurner data to save the file */
+	uint32 _fverLength;
+	uint32 _afterBurnerVersion;
+	uint32 _fcdrLength;
+	uint32 _abmpLength;
+	uint32 _abmpEnd;
+	uint32 _abmpCompressionType;
+	unsigned long _abmpUncompLength;
+	unsigned long _abmpActualUncompLength;
+
+	/* Config data to save the file */
+	Cast *_cast;
+
+	/* Movie Cast Lib Mapping data to save the file */
+	Movie *_movie;
+
 protected:
 	uint32 _rifxType;
 	Common::Array<Resource *> _resources;
diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 392bf9b9a22..876044e877a 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -1252,6 +1252,11 @@ uint32 readVarInt(Common::SeekableReadStream &stream) {
 	return val;
 }
 
+uint32 writeVarInt(Common::SeekableReadStream &stream, uint32 value) {
+	warning("STUB::writeVarInt: Can't write variable intager types yet");
+	return 0;
+}
+
 Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long *outLen, bool bigEndian) {
 	byte *in = (byte *)malloc(len);
 	byte *out = (byte *)malloc(*outLen);


Commit: 7e6e1d086ac8ac4b1692c126b6ae8e18656a4117
    https://github.com/scummvm/scummvm/commit/7e6e1d086ac8ac4b1692c126b6ae8e18656a4117
Author: Malhar (themalharbdv2046 at gmail.com)
Date: 2025-06-26T21:20:09+02:00

Commit Message:
DIRECTOR: Archive:: Write Cast data in writeStream()

Add a function Archive::writeCast() in Archive::writeStream() to
save 'CASt' data while writing a director movie
Parallel to readCast()

Part of Director Movie saving functionality

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


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index a6afb39e0e3..2769379a136 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -188,6 +188,18 @@ uint32 Archive::getOffset(uint32 tag, uint16 id) const {
 	return resMap[id].offset;
 }
 
+uint Archive::getResourceSize(uint32 tag, uint16 id) const {
+	if (!_types.contains(tag))
+		error("Archive::getResourceSize(): Archive does not contain '%s' %d", tag2str(tag), id);
+
+	const ResourceMap &resMap = _types[tag];
+
+	if (!resMap.contains(id))
+		error("Archive::getResourceSize(): Archive does not contain '%s' %d", tag2str(tag), id);
+
+	return resMap[id].size;
+}
+
 uint16 Archive::findResourceID(uint32 tag, const Common::String &resName, bool ignoreCase) const {
 	if (!_types.contains(tag) || resName.empty())
 		return 0xFFFF;
@@ -763,7 +775,6 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 		for (auto &it : _keyData[casTag]) {
 			for (auto &jt : it._value) {
 				if (Common::SeekableReadStreamEndian *casStream = getResource(casTag, jt)) {
-					Resource res = getResourceDetail(casTag, jt);
 					readCast(*casStream, it._key);
 					delete casStream;
 				}
@@ -1006,7 +1017,7 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableReadStreamEndian &stream, u
 }
 
 void RIFXArchive::readCast(Common::SeekableReadStreamEndian &casStream, uint16 libResourceId) {
-	uint castTag = MKTAG('C', 'A', 'S', 't');
+	int castTag = MKTAG('C', 'A', 'S', 't');
 
 	uint casSize = casStream.size() / 4;
 
@@ -1192,6 +1203,21 @@ bool RIFXArchive::writeStream() {
 		writeKeyTable(writeStream, offset);
 	}
 
+	int32 casTag = MKTAG('C', 'A', 'S', '*');
+	if (_keyData.contains(casTag)) {
+		for (auto &it : _keyData[casTag]) {
+			for (auto &jt : it._value) {
+				uint32 offset = getOffset(casTag, jt) + 8;	
+				writeCast(writeStream, offset);
+			}
+		}
+	}
+
+	// All the write functions will be called before flushing the dumpfile
+	// I need to store all these loaded chunks in a single structure so that
+	// Writing them is a as easy as just calling a single write function
+	// Currently I'm only working with the 'XFIR' file that I have, so all the 
+	// data is written low endian, will add a single check to switch to big endian 
 	Common::DumpFile out;
 	char buf[256];
 	Common::sprintf_s(buf, "./writtenMovie.dir");
@@ -1314,4 +1340,19 @@ bool RIFXArchive::writeKeyTable(Common::SeekableMemoryWriteStream *writeStream,
 	
 	return true;
 }
+
+bool RIFXArchive::writeCast(Common::SeekableWriteStream *writeStream, uint32 offset) {
+	writeStream->seek(offset);
+
+	uint castTag = MKTAG('C', 'A', 'S', 't'); 
+
+	for (auto &it : _types[castTag]) {
+		if (it._value.libResourceId) { 
+			writeStream->writeUint32LE(it._key);
+		}
+	}
+
+	return true;
+}
+
 } // End of namespace Director
diff --git a/engines/director/archive.h b/engines/director/archive.h
index 34ba6b04a01..2ac6761a94b 100644
--- a/engines/director/archive.h
+++ b/engines/director/archive.h
@@ -86,6 +86,7 @@ public:
 	virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, uint16 parentId);
 	virtual Resource getResourceDetail(uint32 tag, uint16 id);
 	uint32 getOffset(uint32 tag, uint16 id) const;
+	uint getResourceSize(uint32 tag, uint16 id) const;
 	uint16 findResourceID(uint32 tag, const Common::String &resName, bool ignoreCase = false) const;
 	Common::String getName(uint32 tag, uint16 id) const;
 	Common::SeekableReadStreamEndian *getMovieResourceIfPresent(uint32 tag);
@@ -148,9 +149,6 @@ public:
 
 	bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
 	bool writeStream() override;
-	bool writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream);
-	bool writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStreaa);
-	bool writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset);
 
 	Common::SeekableReadStreamEndian *getFirstResource(uint32 tag) override;
 	virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, bool fileEndianness);
@@ -161,6 +159,12 @@ public:
 	Common::String formatArchiveInfo() override;
 
 private:
+	/* These functions are for writing movies parallel to readMemoryMap, readAfterBurnerMap and readKeyTable */
+	bool writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream);
+	bool writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStreaa);
+	bool writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset);
+	bool writeCast(Common::SeekableWriteStream *writeStream, uint32 offset);
+
 	bool readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset, Common::SeekableMemoryWriteStream *dumpStream, uint32 movieStartOffset);
 	bool readAfterburnerMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset);
 	void readCast(Common::SeekableReadStreamEndian &casStream, uint16 libResourceId);


Commit: be3a2da0fce1950f8f1d7c0df8456b2102c9f256
    https://github.com/scummvm/scummvm/commit/be3a2da0fce1950f8f1d7c0df8456b2102c9f256
Author: Malhar (themalharbdv2046 at gmail.com)
Date: 2025-06-26T21:20:09+02:00

Commit Message:
DIRECTOR: CHUNK: Start writing the chunk.h file

This file will contain all the structs for Chunk data read during
loading of a Director Movie, so that it will be straightforward
to save the Movie

Changed paths:
  A engines/director/chunk.h


diff --git a/engines/director/chunk.h b/engines/director/chunk.h
new file mode 100644
index 00000000000..e9afe318ce5
--- /dev/null
+++ b/engines/director/chunk.h
@@ -0,0 +1,130 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef DIRECTOR_CHUNK_H
+#define DIRECTOR_CHUNK_H
+
+namespace Common {
+struct Rect;
+class SeekableReadStreamEndian;
+class SeekableMemoryWriteStream;
+}
+
+namespace Director {
+
+class Archive;
+class Cast;
+struct CastMemberInfo;
+class CastMember;
+class DirectorEngine;
+class Lingo;
+struct LingoArchive;
+struct LingoEvent;
+class ScriptContext;
+class Window;
+struct Symbol;
+
+enum ArchiveChunkType {
+	kCastChunk,
+	// kCastListChunk,
+	// kCastMemberChunk,
+	// kCastInfoChunk,
+	kConfigChunk,
+	// kInitialMapChunk,
+	// kKeyTableChunk,
+	// kMemoryMapChunk,
+	// kScriptChunk,
+	// kScriptContextChunk,
+	// kScriptNamesChunk
+};
+
+struct Chunk {
+	Archive *dir;
+	ArchiveChunkType _chunkType;
+	bool _writable;
+
+	Chunk(Archive *d, ArchiveChunkType t) : dir(d), _chunkType(t), _writable(false) {}
+	virtual ~Chunk() = default;
+	virtual void read(Common::SeekableReadStreamEndian &stream) = 0;
+	virtual uint16 size() { return 0; }
+	virtual void write(Common::SeekableMemoryWriteStream&) {}
+	
+};
+
+struct ConfigChunk : Chunk {
+	/*  0 */ uint16 len;
+	/*  2 */ uint16 fileVersion;
+	/*  4, 6, 8, 10 */ Common::Rect checkRect; 
+    /* 12 */ uint16 castArrayStart;
+	/* 14 */ uint16 castArrayEnd;
+	/* 16 */ byte readRate;
+	/* 17 */ byte lightswitch;
+
+	// Director 6 and below
+		/* 18 */ int16 unk1;	// Mentioned in ProjectorRays as preD7field11 
+	
+	// Director 7 and above
+	// Currently not supporting Director 7
+		// /* 18 */ int8 D7stageColorG;
+		// /* 19 */ int8 D7stageColorB;
+
+	/* 20 */ uint16 commentFont;
+	/* 22 */ uint16 commentSize;
+	/* 24 */ uint16 commentStyle;
+
+	// Director 6 and below
+		/* 26 */ uint16 stageColor;
+	// Director 7 and above
+		/* 26 */ uint8 D7stageColorIsRGB;
+		/* 27 */ uint8 D7stageColorR;
+
+	/* 28 */ uint16 bitDepth;
+	/* 30 */ uint8 field17;
+	/* 31 */ uint8 field18;
+	/* 32 */ int32 field19;
+	/* 36 */ int16 directorVersion;
+	/* 38 */ int16 field21;
+	/* 40 */ int32 field22;
+	/* 44 */ int32 field23;
+	/* 48 */ int32 field24;
+	/* 52 */ int8 field25;
+	/* 53 */ uint8 field26;
+	/* 54 */ int16 frameRate;
+	/* 56 */ int16 platformID;
+	/* 58 */ int16 protection;
+	/* 60 */ int32 field29;
+	/* 64 */ uint32 checksum;
+	/* 68 */ uint16 field30;	// Marked as remnants in ProjectorRays
+
+	ConfigChunk(Archive *m) : Chunk(m, kConfigChunk) {
+		_writable = true;
+	}
+	~ConfigChunk() = default;
+	void read(Common::SeekableReadStreamEndian &stream) { return; };
+	uint16 size() { return len; }
+	void write(Common::SeekableMemoryWriteStream &stream) { return; };
+	uint32 computeChecksum() { return 0; };
+};
+
+}   // End of namespace Director
+
+#endif
\ No newline at end of file


Commit: 10ff5f5ed21f39989151142b78b479f9a16772c5
    https://github.com/scummvm/scummvm/commit/10ff5f5ed21f39989151142b78b479f9a16772c5
Author: Malhar (themalharbdv2046 at gmail.com)
Date: 2025-06-26T21:20:09+02:00

Commit Message:
DIRECTOR: Write resource chunks verbatim except imap, mmap, keymap

Changed paths:
    engines/director/archive.cpp


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index 2769379a136..69a47be2205 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -782,8 +782,8 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 		}
 	}
 
-	// writeStream();
-	// g_system->quit();
+	writeStream();
+	g_system->quit();
 	return true;
 }
 
@@ -1165,12 +1165,15 @@ Common::String RIFXArchive::formatArchiveInfo() {
 }
 
 bool RIFXArchive::writeStream() {
-	// I'm ignoring the startOffset
+	// The offsets used in this function should be not the same as original
+	// That defeats the whole purpose of writing movies
+
+	// ignoring the startOffset
 	// For RIFX stream, moreoffset = 0
 	byte *dumpData = nullptr;
 
-	// Probably don't need to allocate this much size
-	debug("What is the _size while writing = %d", _size);
+	// Don't need to allocate this much size in case 'JUNK' and 'FREE' resources are ignored
+	// Or might need to allocate even more size if extra chunks are written
 	dumpData = (byte *)malloc(_size);
 
 	Common::SeekableMemoryWriteStream *writeStream = new Common::SeekableMemoryWriteStream(dumpData, _size);
@@ -1218,6 +1221,18 @@ bool RIFXArchive::writeStream() {
 	// Writing them is a as easy as just calling a single write function
 	// Currently I'm only working with the 'XFIR' file that I have, so all the 
 	// data is written low endian, will add a single check to switch to big endian 
+
+	for (auto &it : _resources) {
+		if (it->tag != MKTAG('X', 'F', 'I', 'R') ||
+			it->tag != MKTAG('i', 'm', 'a', 'p') ||
+			it->tag != MKTAG('m', 'm', 'a', 'p') ||
+			it->tag != MKTAG('K', 'E', 'Y', '*') 
+		) {
+			writeStream->seek(it->offset + 8);
+			writeStream->writeStream(getResource(it->tag, it->index));
+		}
+	}
+
 	Common::DumpFile out;
 	char buf[256];
 	Common::sprintf_s(buf, "./writtenMovie.dir");
@@ -1250,12 +1265,10 @@ bool RIFXArchive::writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream)
 
 	uint32 newSize = 0;
 	uint32 newResCount = _resources.size();
-	debug("What is the newRescount = %d", newResCount);
 	for (auto &it : _resources) {
 		newSize += it->size;
 	}
 
-	debug("Position before writing the mmap = %ld", writeStream->pos());
 	writeStream->writeUint32LE(newSize);
 	// I need to see what header size is
 	writeStream->writeUint16LE(0);
@@ -1289,7 +1302,7 @@ bool RIFXArchive::writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream)
 // This Function is incomplete, needs further changes before can be used
 bool RIFXArchive::writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStream) {
 	warning("RIFXArchive::writeAfterBurnerMap: STUB: Incomplete function, needs further changes, AfterBurnerMap not written");
-	return;
+	return false;
 
 	writeStream->writeUint32LE(MKTAG('F', 'v', 'e', 'r'));
 


Commit: 36d599c0d31a4445f01cece95e52aa2553db24d0
    https://github.com/scummvm/scummvm/commit/36d599c0d31a4445f01cece95e52aa2553db24d0
Author: Malhar (themalharbdv2046 at gmail.com)
Date: 2025-06-26T21:20:09+02:00

Commit Message:
DIRECTOR: Calling write from DirectorEngine and minor fixes

Calling the writeToFile() function from DirectorEngine()::run()
when debugChannel loading is set.

Other minor fixes include:
- Instead of calculating size, we'll update the size when there is
an update in the resource
- Formatting fixes

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


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index 69a47be2205..02fac1ca802 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -642,6 +642,7 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 	if (_metaTag == MKTAG('R', 'I', 'F', 'X')) {
 		_isBigEndian = true;
 	} else if (SWAP_BYTES_32(_metaTag) == MKTAG('R', 'I', 'F', 'X')) {
+		_metaTag = SWAP_BYTES_32(_metaTag);
 		_isBigEndian = false;
 	} else {
 		warning("RIFXArchive::openStream(): RIFX or XFIR expected but %s found", tag2str(_metaTag));
@@ -782,8 +783,11 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 		}
 	}
 
-	writeStream();
-	g_system->quit();
+	if (debugChannelSet(11, kDebugLoading)) {
+		writeToFile();
+		g_system->quit();
+	}
+
 	return true;
 }
 
@@ -795,12 +799,12 @@ bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32
 
 	_imapLength = stream.readUint32(); // imap length
 	_mapversion = stream.readUint32(); // version, seen 0 or 1
-	_mmapOffsetPos = stream.pos();
+	uint32 mmapOffsetPos = stream.pos();
 	_mmapOffset = stream.readUint32() + moreOffset;
 
 	if (dumpStream) {
 		// If we're dumping the movie, patch this offset in the dump data.
-		dumpStream->seek(_mmapOffsetPos - movieStartOffset);
+		dumpStream->seek(mmapOffsetPos - movieStartOffset);
 		if (stream.isBE())
 			dumpStream->writeUint32BE(_mmapOffset - movieStartOffset);
 		else
@@ -817,17 +821,17 @@ bool RIFXArchive::readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32
 
 	_types[MKTAG('m', 'm', 'a', 'p')][0].accessed = true; // Mark it as accessed
 
-	stream.readUint32(); // mmap length
-	stream.readUint16(); // header size
-	stream.readUint16(); // size of map entry
-	stream.readUint32(); // resCount + empty entries
-	uint32 resCount = stream.readUint32();
+	_mmapLength = stream.readUint32(); // mmap length
+	_mmapHeaderSize = stream.readUint16(); // header size
+	_mmapEntrySize = stream.readUint16(); // size of map entry
+	_totalCount = stream.readUint32(); // resCount + empty entries
+	_resCount = stream.readUint32();
 	stream.skip(8); // all 0xFF
 	stream.readUint32(); // id of the first free resource, -1 if none.
 
-	_resources.reserve(resCount);
+	_resources.reserve(_resCount);
 
-	for (uint32 i = 0; i < resCount; i++) {
+	for (uint32 i = 0; i < _resCount; i++) {
 		uint32 tag = stream.readUint32();
 		uint32 size = stream.readUint32();
 		uint32 offsetPos = stream.pos();
@@ -1164,7 +1168,7 @@ Common::String RIFXArchive::formatArchiveInfo() {
 	return result;
 }
 
-bool RIFXArchive::writeStream() {
+bool RIFXArchive::writeToFile(Common::Path path) {
 	// The offsets used in this function should be not the same as original
 	// That defeats the whole purpose of writing movies
 
@@ -1178,9 +1182,20 @@ bool RIFXArchive::writeStream() {
 
 	Common::SeekableMemoryWriteStream *writeStream = new Common::SeekableMemoryWriteStream(dumpData, _size);
 	
-	writeStream->writeUint32BE(_metaTag); // The _metaTag is "RIFX" or "XFIR" for this case 
-										  	// the reason for writing it BigEndian is because that's how we read it, we don't change it
-	writeStream->writeUint32LE(_size); // The size of the RIFX archive
+	writeStream->writeUint32LE(_metaTag); // The _metaTag is "RIFX" or "XFIR" for this case 
+	
+	// This includes the size of 'RIFX', 'mmap' and 'imap' resources
+
+	// This method of calculating new size is inefficient and prone to error 
+	/* uint32 newSize = 0;
+	 * for (auto &it: _resources) {
+	 * 	newSize += it->size;
+	 * }
+	*/
+
+	// We'll need to update the size of the RIFX resource whenever there is a modification
+	// The -8 is consistent with RIFXArchive::openStream()
+	writeStream->writeUint32LE(getResourceSize(_metaTag, 0) - 8); // The size of the RIFX archive
 	writeStream->writeUint32LE(_rifxType);	// e.g. "MV93", "MV95"
 
 	switch (_rifxType) {
@@ -1223,9 +1238,10 @@ bool RIFXArchive::writeStream() {
 	// data is written low endian, will add a single check to switch to big endian 
 
 	for (auto &it : _resources) {
-		if (it->tag != MKTAG('X', 'F', 'I', 'R') ||
-			it->tag != MKTAG('i', 'm', 'a', 'p') ||
-			it->tag != MKTAG('m', 'm', 'a', 'p') ||
+		if (it->tag != _metaTag &&
+			it->tag != SWAP_BYTES_32(_metaTag) &&
+			it->tag != MKTAG('i', 'm', 'a', 'p') &&
+			it->tag != MKTAG('m', 'm', 'a', 'p') &&
 			it->tag != MKTAG('K', 'E', 'Y', '*') 
 		) {
 			writeStream->seek(it->offset + 8);
@@ -1234,17 +1250,15 @@ bool RIFXArchive::writeStream() {
 	}
 
 	Common::DumpFile out;
-	char buf[256];
-	Common::sprintf_s(buf, "./writtenMovie.dir");
 	
 	// Write the movie out, stored in dumpData
-	if (out.open(buf, true)) {
+	if (out.open(path, true)) {
 		out.write(dumpData, _size);
 		out.flush();
 		out.close();
-		debugC(3, kDebugLoading, "RIFXArchive::writeStream:Saved the movie as file %s", buf);
+		debugC(3, kDebugLoading, "RIFXArchive::writeStream:Saved the movie as file %s", path.toString().c_str());
 	} else {
-		warning("RIFXArchive::writeStream: Error saving the file %s", buf);
+		warning("RIFXArchive::writeStream: Error saving the file %s", path.toString().c_str());
 	}
 
 	free(dumpData);
@@ -1262,19 +1276,15 @@ bool RIFXArchive::writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream)
 	writeStream->seek(_mmapOffset);
 	writeStream->writeUint32LE(MKTAG('m', 'm', 'a', 'p'));
 
-
-	uint32 newSize = 0;
 	uint32 newResCount = _resources.size();
-	for (auto &it : _resources) {
-		newSize += it->size;
-	}
-
-	writeStream->writeUint32LE(newSize);
-	// I need to see what header size is
-	writeStream->writeUint16LE(0);
-	writeStream->writeUint16LE(0);
-	writeStream->writeUint32LE(0);
-
+	
+	// Need to recalcualte the following things
+	// Similarl to the RIFX resource, we'll need to update the size of the mmap resource whenever there is some change
+	writeStream->writeUint32LE(getResourceSize(MKTAG('m', 'm', 'a', 'p'), 0));
+	writeStream->writeUint16LE(_mmapHeaderSize);
+	writeStream->writeUint16LE(_mmapEntrySize);
+	
+	writeStream->writeUint32LE(newResCount + _totalCount - _resCount); // _totalCount - _resCount is the number of empty entries
 	writeStream->writeUint32LE(newResCount);
 	writeStream->seek(8, SEEK_CUR);
 
@@ -1343,7 +1353,7 @@ bool RIFXArchive::writeKeyTable(Common::SeekableMemoryWriteStream *writeStream,
 			KeyArray keyArray = parentIndex._value;
 
 			for (auto childIndex : keyArray) {
-				debug("RIFXArchive::writeKeyTable: _keyData contains tag: %s, parentIndex: %d, childIndex: %d", tag2str(childTag._key), parentIndex._key, childIndex);
+				debugC(3, kDebugLoading, "RIFXArchive::writeKeyTable: _keyData contains tag: %s, parentIndex: %d, childIndex: %d", tag2str(childTag._key), parentIndex._key, childIndex);
 				writeStream->writeUint32LE(childIndex);
 				writeStream->writeUint32LE(parentIndex._key);
 				writeStream->writeUint32LE(childTag._key);	
diff --git a/engines/director/archive.h b/engines/director/archive.h
index 2ac6761a94b..1702787e5c5 100644
--- a/engines/director/archive.h
+++ b/engines/director/archive.h
@@ -61,10 +61,10 @@ public:
 
 	virtual bool openFile(const Common::Path &path);
 	virtual bool openStream(Common::SeekableReadStream *stream, uint32 offset = 0) = 0;
-	virtual bool writeStream() { 
+	virtual bool writeToFile(Common::Path path) { 
 		// Saving Director movies was introduced in Director 4
 		// However, from DirectorEngine::createArchive, it is evident that after Director 4 only RIFX Archives were written
-		error("Archive::writeStream was called on a non-RIFX Archive, which is not allowed");
+		error("Archive::writeToFile was called on a non-RIFX Archive, which is not allowed");
 		return false;
 	} 
 	virtual void close();
@@ -148,7 +148,7 @@ public:
 	~RIFXArchive() override;
 
 	bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
-	bool writeStream() override;
+	bool writeToFile(Common::Path path = Common::Path("./dumps/writtenMovie.dir")) override;
 
 	Common::SeekableReadStreamEndian *getFirstResource(uint32 tag) override;
 	virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, bool fileEndianness);
@@ -159,11 +159,11 @@ public:
 	Common::String formatArchiveInfo() override;
 
 private:
-	/* These functions are for writing movies parallel to readMemoryMap, readAfterBurnerMap and readKeyTable */
-	bool writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream);
-	bool writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStreaa);
-	bool writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset);
-	bool writeCast(Common::SeekableWriteStream *writeStream, uint32 offset);
+	/* These functions are for writing movies */
+	bool writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream); 	// Parallel to readMemoryMap
+	bool writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStreaa);	// Parallel to readAfterBurnerMap
+	bool writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset);	// Parallel to readKeyTable
+	bool writeCast(Common::SeekableWriteStream *writeStream, uint32 offset);	// Parallel to readCast
 
 	bool readMemoryMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset, Common::SeekableMemoryWriteStream *dumpStream, uint32 movieStartOffset);
 	bool readAfterburnerMap(Common::SeekableReadStreamEndian &stream, uint32 moreOffset);
@@ -174,8 +174,12 @@ private:
 	uint32 _metaTag;
 	uint32 _moreOffset;
 	uint32 _mapversion;
-	uint32 _mmapOffsetPos;
 	uint32 _mmapOffset;
+	uint32 _mmapLength;
+	uint32 _mmapHeaderSize;
+	uint32 _mmapEntrySize;
+	uint32 _totalCount;
+	uint32 _resCount;
 	uint32 _imapLength;
 	uint32 _version;
 	uint32 _size;
@@ -196,12 +200,6 @@ private:
 	unsigned long _abmpUncompLength;
 	unsigned long _abmpActualUncompLength;
 
-	/* Config data to save the file */
-	Cast *_cast;
-
-	/* Movie Cast Lib Mapping data to save the file */
-	Movie *_movie;
-
 protected:
 	uint32 _rifxType;
 	Common::Array<Resource *> _resources;
diff --git a/engines/director/chunk.h b/engines/director/chunk.h
index e9afe318ce5..1322de12d0f 100644
--- a/engines/director/chunk.h
+++ b/engines/director/chunk.h
@@ -127,4 +127,4 @@ struct ConfigChunk : Chunk {
 
 }   // End of namespace Director
 
-#endif
\ No newline at end of file
+#endif
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 91d8bb11330..995e48462ae 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -382,6 +382,9 @@ Common::Error DirectorEngine::run() {
 	_system->setImGuiCallbacks(ImGuiCallbacks());
 #endif
 
+	if (debugChannelSet(-1, kDebugLoading)) { 
+		writeToFile();
+	}
 	return Common::kNoError;
 }
 
diff --git a/engines/director/director.h b/engines/director/director.h
index 4ef8f27c87e..37118b9a815 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -237,6 +237,7 @@ public:
 	Archive *loadEXEv7(Common::SeekableReadStream *stream);
 	Archive *loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);
 	Archive *loadMac(const Common::Path &movie);
+	void writeToFile(Common::Path writePath = Common::Path("./dumps/writtenMovie.dir"));
 
 	bool desktopEnabled();
 
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index dd92494012f..c4047e603f7 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -575,6 +575,15 @@ Archive *DirectorEngine::loadMac(const Common::Path &movie) {
 	return result;
 }
 
+void DirectorEngine::writeToFile(Common::Path writePath) {
+	if (!_mainArchive) {
+		error("DirectorEngine::writeToFile: Write to file called before setting mainArchive");
+	}
+
+	debugC(3, kDebugLoading, "DirectorEngine::writeToFile: Writing the main archive %s, to %s", _mainArchive->getFileName().c_str(), writePath.toString().c_str());
+	_mainArchive->writeToFile(writePath);
+}
+
 void Window::loadXtrasFromPath() {
 	// For D5 and above, Xtras are considered plug and play.
 	// According to Director Demystified: it considers an


Commit: 57845187a2db0d21afe2f72039f99851f3d3da6f
    https://github.com/scummvm/scummvm/commit/57845187a2db0d21afe2f72039f99851f3d3da6f
Author: Malhar (themalharbdv2046 at gmail.com)
Date: 2025-06-26T21:20:09+02:00

Commit Message:
DIRECTOR: Fix formatting and other minor issues

Remove the writeToFile() function from DirectorEngine class
Instead call writeToFile() from _mainArchive directly
Remove unnecessary forward declarations from chunk.h
Remove first person comments

Changed paths:
    engines/director/archive.cpp
    engines/director/archive.h
    engines/director/cast.cpp
    engines/director/chunk.h
    engines/director/director.cpp
    engines/director/director.h
    engines/director/resource.cpp
    engines/director/util.cpp
    engines/director/util.h


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index 02fac1ca802..7737cefd52c 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -783,11 +783,6 @@ bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOff
 		}
 	}
 
-	if (debugChannelSet(11, kDebugLoading)) {
-		writeToFile();
-		g_system->quit();
-	}
-
 	return true;
 }
 
@@ -911,7 +906,7 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableReadStreamEndian &stream, u
 	_abmpCompressionType = readVarInt(stream);
 	_abmpUncompLength = readVarInt(stream);
 	_abmpActualUncompLength = _abmpUncompLength;
-	debugC(3, kDebugLoading, "ABMP: length: %d compressionType: %d uncompressedLength: %lu",
+	debugC(3, kDebugLoading, "ABMP: length: %d compressionType: %d uncompressedLength: %d",
 		_abmpLength, _abmpCompressionType, _abmpUncompLength);
 
 	Common::SeekableReadStreamEndian *abmpStream = readZlibData(stream, _abmpEnd - stream.pos(), &_abmpActualUncompLength, _isBigEndian);
@@ -920,7 +915,7 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableReadStreamEndian &stream, u
 		return false;
 	}
 	if (_abmpUncompLength != _abmpActualUncompLength) {
-		warning("ABMP: Expected uncompressed length %lu but got length %lu", _abmpUncompLength, _abmpActualUncompLength);
+		warning("ABMP: Expected uncompressed length %d but got length %d", _abmpUncompLength, _abmpActualUncompLength);
 	}
 
 	if (ConfMan.getBool("dump_scripts")) {
@@ -994,14 +989,14 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableReadStreamEndian &stream, u
 	debugC(3, kDebugLoading, "ILS: length: %d unk1: %d", ilsRes->size, ilsUnk1);
 	_ilsBodyOffset = stream.pos();
 	uint32 ilsLength = ilsRes->size;
-	unsigned long ilsActualUncompLength = ilsRes->uncompSize;
+	uint32 ilsActualUncompLength = ilsRes->uncompSize;
 	Common::SeekableReadStreamEndian *ilsStream = readZlibData(stream, ilsLength, &ilsActualUncompLength, _isBigEndian);
 	if (!ilsStream) {
 		warning("RIFXArchive::readAfterburnerMap(): Could not uncompress FGEI");
 		return false;
 	}
 	if (ilsRes->uncompSize != ilsActualUncompLength) {
-		warning("ILS: Expected uncompressed length %d but got length %lu", ilsRes->uncompSize, ilsActualUncompLength);
+		warning("ILS: Expected uncompressed length %d but got length %d", ilsRes->uncompSize, ilsActualUncompLength);
 	}
 
 	while (ilsStream->pos() < ilsStream->size()) {
@@ -1125,13 +1120,13 @@ Common::SeekableReadStreamEndian *RIFXArchive::getResource(uint32 tag, uint16 id
 			return new Common::MemoryReadStreamEndian(_ilsData[id], res.uncompSize, bigEndian, DisposeAfterUse::NO);
 		} else {
 			_stream->seek(_ilsBodyOffset + res.offset);
-			unsigned long actualUncompLength = res.uncompSize;
+			uint32 actualUncompLength = res.uncompSize;
 			Common::SeekableReadStreamEndian *stream = readZlibData(*_stream, res.size, &actualUncompLength, _isBigEndian);
 			if (!stream) {
 				error("RIFXArchive::getResource(): Could not uncompress '%s' %d", tag2str(tag), id);
 			}
 			if (res.uncompSize != actualUncompLength) {
-				warning("RIFXArchive::getResource(): For '%s' %d expected uncompressed length %d but got length %lu",
+				warning("RIFXArchive::getResource(): For '%s' %d expected uncompressed length %d but got length %d",
 					tag2str(tag), id, res.uncompSize, actualUncompLength);
 			}
 			return stream;
@@ -1176,17 +1171,16 @@ bool RIFXArchive::writeToFile(Common::Path path) {
 	// For RIFX stream, moreoffset = 0
 	byte *dumpData = nullptr;
 
-	// Don't need to allocate this much size in case 'JUNK' and 'FREE' resources are ignored
+	// Don't need to allocate this much size in case 'junk' and 'free' resources are ignored
 	// Or might need to allocate even more size if extra chunks are written
 	dumpData = (byte *)malloc(_size);
 
 	Common::SeekableMemoryWriteStream *writeStream = new Common::SeekableMemoryWriteStream(dumpData, _size);
-	
-	writeStream->writeUint32LE(_metaTag); // The _metaTag is "RIFX" or "XFIR" for this case 
-	
-	// This includes the size of 'RIFX', 'mmap' and 'imap' resources
 
-	// This method of calculating new size is inefficient and prone to error 
+	writeStream->writeUint32LE(_metaTag); // The _metaTag is "RIFX" or "XFIR" for this case
+
+	// This includes the size of 'RIFX', 'mmap' and 'imap' resources
+	// This method of calculating new size is inefficient and prone to error
 	/* uint32 newSize = 0;
 	 * for (auto &it: _resources) {
 	 * 	newSize += it->size;
@@ -1216,8 +1210,7 @@ bool RIFXArchive::writeToFile(Common::Path path) {
 	int32 keyTag = MKTAG('K', 'E', 'Y', '*');
 	if (hasResource(keyTag, -1)) {
 		uint16 firstID = getResourceIDList(keyTag)[0];
-		uint32 offset = getOffset(keyTag, firstID) + 8;	// I'm not sure why this +8 is there for
-														// But its consistent with RIFXArchive::getResource()
+		uint32 offset = getOffset(keyTag, firstID) + 8;	// The +8 is consistent with RIFXArchive::getResource()
 		writeKeyTable(writeStream, offset);
 	}
 
@@ -1225,24 +1218,18 @@ bool RIFXArchive::writeToFile(Common::Path path) {
 	if (_keyData.contains(casTag)) {
 		for (auto &it : _keyData[casTag]) {
 			for (auto &jt : it._value) {
-				uint32 offset = getOffset(casTag, jt) + 8;	
+				uint32 offset = getOffset(casTag, jt) + 8;
 				writeCast(writeStream, offset);
 			}
 		}
 	}
 
-	// All the write functions will be called before flushing the dumpfile
-	// I need to store all these loaded chunks in a single structure so that
-	// Writing them is a as easy as just calling a single write function
-	// Currently I'm only working with the 'XFIR' file that I have, so all the 
-	// data is written low endian, will add a single check to switch to big endian 
-
 	for (auto &it : _resources) {
 		if (it->tag != _metaTag &&
 			it->tag != SWAP_BYTES_32(_metaTag) &&
 			it->tag != MKTAG('i', 'm', 'a', 'p') &&
 			it->tag != MKTAG('m', 'm', 'a', 'p') &&
-			it->tag != MKTAG('K', 'E', 'Y', '*') 
+			it->tag != MKTAG('K', 'E', 'Y', '*')
 		) {
 			writeStream->seek(it->offset + 8);
 			writeStream->writeStream(getResource(it->tag, it->index));
@@ -1250,7 +1237,7 @@ bool RIFXArchive::writeToFile(Common::Path path) {
 	}
 
 	Common::DumpFile out;
-	
+
 	// Write the movie out, stored in dumpData
 	if (out.open(path, true)) {
 		out.write(dumpData, _size);
@@ -1277,29 +1264,29 @@ bool RIFXArchive::writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream)
 	writeStream->writeUint32LE(MKTAG('m', 'm', 'a', 'p'));
 
 	uint32 newResCount = _resources.size();
-	
+
 	// Need to recalcualte the following things
 	// Similarl to the RIFX resource, we'll need to update the size of the mmap resource whenever there is some change
 	writeStream->writeUint32LE(getResourceSize(MKTAG('m', 'm', 'a', 'p'), 0));
 	writeStream->writeUint16LE(_mmapHeaderSize);
 	writeStream->writeUint16LE(_mmapEntrySize);
-	
+
 	writeStream->writeUint32LE(newResCount + _totalCount - _resCount); // _totalCount - _resCount is the number of empty entries
 	writeStream->writeUint32LE(newResCount);
-	writeStream->seek(8, SEEK_CUR);
+	writeStream->seek(8, SEEK_CUR);		// In the original file, these 8 bytes are all 0xFF, so this will produce a diff 
 
 	// ID of the first 'free' resource
 	writeStream->writeUint32LE(0);
 
 	for (auto &it : _resources) {
-		debugC(3, kDebugLoading, "Writing RIFX Resource: tag: %s, size: %d, offset: %08x, flags: %x, unk1: %x, nextFreeResourceID: %d", 
+		debugC(3, kDebugLoading, "Writing RIFX Resource: tag: %s, size: %d, offset: %08x, flags: %x, unk1: %x, nextFreeResourceID: %d",
 			tag2str(it->tag), it->size, it->offset, it->flags, it->unk1, it->nextFreeResourceID);
-		
+
 		// Write down the tag, the size and offset of the current resource
 		writeStream->writeUint32LE(it->tag);
 		writeStream->writeUint32LE(it->size);
 		writeStream->writeUint32LE(it->offset);
-		
+
 		// Currently ignoring flags, unk1 and nextFreeResourceID
 		writeStream->writeUint16LE(it->flags);
 		writeStream->writeUint16LE(it->unk1);
@@ -1309,17 +1296,15 @@ bool RIFXArchive::writeMemoryMap(Common::SeekableMemoryWriteStream *writeStream)
 	return true;
 }
 
-// This Function is incomplete, needs further changes before can be used
 bool RIFXArchive::writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeStream) {
 	warning("RIFXArchive::writeAfterBurnerMap: STUB: Incomplete function, needs further changes, AfterBurnerMap not written");
 	return false;
 
+#if 0
 	writeStream->writeUint32LE(MKTAG('F', 'v', 'e', 'r'));
 
-	// _fverLength and _afterBurnerVersion are shockwave variable type intagers
-	// So I'm writing them as 32bit intagers
 	writeStream->writeUint32LE(_fverLength);
-	uint32 start = writeStream->pos(); 
+	uint32 start = writeStream->pos();
 
 	writeStream->writeUint32LE(_afterBurnerVersion);
 	uint32 end = writeStream->pos();
@@ -1336,6 +1321,7 @@ bool RIFXArchive::writeAfterBurnerMap(Common::SeekableMemoryWriteStream *writeSt
 	writeStream->writeUint32LE(MKTAG('A', 'B', 'M', 'P'));
 
 	return true;
+#endif
 }
 
 bool RIFXArchive::writeKeyTable(Common::SeekableMemoryWriteStream *writeStream, uint32 offset) {
@@ -1356,21 +1342,21 @@ bool RIFXArchive::writeKeyTable(Common::SeekableMemoryWriteStream *writeStream,
 				debugC(3, kDebugLoading, "RIFXArchive::writeKeyTable: _keyData contains tag: %s, parentIndex: %d, childIndex: %d", tag2str(childTag._key), parentIndex._key, childIndex);
 				writeStream->writeUint32LE(childIndex);
 				writeStream->writeUint32LE(parentIndex._key);
-				writeStream->writeUint32LE(childTag._key);	
+				writeStream->writeUint32LE(childTag._key);
 			}
 		}
 	}
-	
+
 	return true;
 }
 
 bool RIFXArchive::writeCast(Common::SeekableWriteStream *writeStream, uint32 offset) {
 	writeStream->seek(offset);
 
-	uint castTag = MKTAG('C', 'A', 'S', 't'); 
+	uint castTag = MKTAG('C', 'A', 'S', 't');
 
 	for (auto &it : _types[castTag]) {
-		if (it._value.libResourceId) { 
+		if (it._value.libResourceId) {
 			writeStream->writeUint32LE(it._key);
 		}
 	}
diff --git a/engines/director/archive.h b/engines/director/archive.h
index 1702787e5c5..66dc7a1c364 100644
--- a/engines/director/archive.h
+++ b/engines/director/archive.h
@@ -61,12 +61,12 @@ public:
 
 	virtual bool openFile(const Common::Path &path);
 	virtual bool openStream(Common::SeekableReadStream *stream, uint32 offset = 0) = 0;
-	virtual bool writeToFile(Common::Path path) { 
+	virtual bool writeToFile(Common::Path path) {
 		// Saving Director movies was introduced in Director 4
 		// However, from DirectorEngine::createArchive, it is evident that after Director 4 only RIFX Archives were written
 		error("Archive::writeToFile was called on a non-RIFX Archive, which is not allowed");
 		return false;
-	} 
+	}
 	virtual void close();
 
 	/* Loading Functions for Cast */
@@ -148,7 +148,7 @@ public:
 	~RIFXArchive() override;
 
 	bool openStream(Common::SeekableReadStream *stream, uint32 startOffset = 0) override;
-	bool writeToFile(Common::Path path = Common::Path("./dumps/writtenMovie.dir")) override;
+	bool writeToFile(Common::Path writePath) override;
 
 	Common::SeekableReadStreamEndian *getFirstResource(uint32 tag) override;
 	virtual Common::SeekableReadStreamEndian *getFirstResource(uint32 tag, bool fileEndianness);
@@ -189,7 +189,7 @@ private:
 	uint16 _keyTableEntrySize2;
 	uint32 _keyTableEntryCount;
 	uint32 _keyTableUsedCount;
-	
+
 	/* AfterBurner data to save the file */
 	uint32 _fverLength;
 	uint32 _afterBurnerVersion;
@@ -197,8 +197,8 @@ private:
 	uint32 _abmpLength;
 	uint32 _abmpEnd;
 	uint32 _abmpCompressionType;
-	unsigned long _abmpUncompLength;
-	unsigned long _abmpActualUncompLength;
+	uint32 _abmpUncompLength;
+	uint32 _abmpActualUncompLength;
 
 protected:
 	uint32 _rifxType;
diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index 1ab1822b5f9..c3144a4f42d 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -33,6 +33,7 @@
 
 #include "director/director.h"
 #include "director/cast.h"
+#include "director/chunk.h"
 #include "director/movie.h"
 #include "director/rte.h"
 #include "director/score.h"
diff --git a/engines/director/chunk.h b/engines/director/chunk.h
index 1322de12d0f..eb1a2899d6b 100644
--- a/engines/director/chunk.h
+++ b/engines/director/chunk.h
@@ -32,16 +32,6 @@ class SeekableMemoryWriteStream;
 namespace Director {
 
 class Archive;
-class Cast;
-struct CastMemberInfo;
-class CastMember;
-class DirectorEngine;
-class Lingo;
-struct LingoArchive;
-struct LingoEvent;
-class ScriptContext;
-class Window;
-struct Symbol;
 
 enum ArchiveChunkType {
 	kCastChunk,
@@ -67,21 +57,21 @@ struct Chunk {
 	virtual void read(Common::SeekableReadStreamEndian &stream) = 0;
 	virtual uint16 size() { return 0; }
 	virtual void write(Common::SeekableMemoryWriteStream&) {}
-	
+
 };
 
 struct ConfigChunk : Chunk {
 	/*  0 */ uint16 len;
 	/*  2 */ uint16 fileVersion;
-	/*  4, 6, 8, 10 */ Common::Rect checkRect; 
+	/*  4, 6, 8, 10 */ Common::Rect checkRect;
     /* 12 */ uint16 castArrayStart;
 	/* 14 */ uint16 castArrayEnd;
 	/* 16 */ byte readRate;
 	/* 17 */ byte lightswitch;
 
 	// Director 6 and below
-		/* 18 */ int16 unk1;	// Mentioned in ProjectorRays as preD7field11 
-	
+		/* 18 */ int16 unk1;	// Mentioned in ProjectorRays as preD7field11
+
 	// Director 7 and above
 	// Currently not supporting Director 7
 		// /* 18 */ int8 D7stageColorG;
@@ -94,10 +84,11 @@ struct ConfigChunk : Chunk {
 	// Director 6 and below
 		/* 26 */ uint16 stageColor;
 	// Director 7 and above
-		/* 26 */ uint8 D7stageColorIsRGB;
-		/* 27 */ uint8 D7stageColorR;
+	// Currently not supporting Director 7
+		// /* 26 */ uint8 D7stageColorIsRGB;
+		// /* 27 */ uint8 D7stageColorR;
 
-	/* 28 */ uint16 bitDepth;
+	/* 28 */ uint16 bitdepth;
 	/* 30 */ uint8 field17;
 	/* 31 */ uint8 field18;
 	/* 32 */ int32 field19;
@@ -109,7 +100,7 @@ struct ConfigChunk : Chunk {
 	/* 52 */ int8 field25;
 	/* 53 */ uint8 field26;
 	/* 54 */ int16 frameRate;
-	/* 56 */ int16 platformID;
+	/* 56 */ int16 platform;
 	/* 58 */ int16 protection;
 	/* 60 */ int32 field29;
 	/* 64 */ uint32 checksum;
@@ -119,10 +110,10 @@ struct ConfigChunk : Chunk {
 		_writable = true;
 	}
 	~ConfigChunk() = default;
-	void read(Common::SeekableReadStreamEndian &stream) { return; };
+	void read(Common::SeekableReadStreamEndian &stream) {}
 	uint16 size() { return len; }
-	void write(Common::SeekableMemoryWriteStream &stream) { return; };
-	uint32 computeChecksum() { return 0; };
+	void write(Common::SeekableMemoryWriteStream &stream) {}
+	uint32 computeChecksum() { return 0; }
 };
 
 }   // End of namespace Director
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 995e48462ae..8ceef336a4c 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -382,9 +382,11 @@ Common::Error DirectorEngine::run() {
 	_system->setImGuiCallbacks(ImGuiCallbacks());
 #endif
 
-	if (debugChannelSet(-1, kDebugLoading)) { 
-		writeToFile();
+	if (debugChannelSet(-1, kDebugLoading)) {
+		Common::Path writePath("./dumps/writtenMovie.dir");
+		_mainArchive->writeToFile(writePath);
 	}
+
 	return Common::kNoError;
 }
 
diff --git a/engines/director/director.h b/engines/director/director.h
index 37118b9a815..4ef8f27c87e 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -237,7 +237,6 @@ public:
 	Archive *loadEXEv7(Common::SeekableReadStream *stream);
 	Archive *loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset);
 	Archive *loadMac(const Common::Path &movie);
-	void writeToFile(Common::Path writePath = Common::Path("./dumps/writtenMovie.dir"));
 
 	bool desktopEnabled();
 
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index c4047e603f7..dd92494012f 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -575,15 +575,6 @@ Archive *DirectorEngine::loadMac(const Common::Path &movie) {
 	return result;
 }
 
-void DirectorEngine::writeToFile(Common::Path writePath) {
-	if (!_mainArchive) {
-		error("DirectorEngine::writeToFile: Write to file called before setting mainArchive");
-	}
-
-	debugC(3, kDebugLoading, "DirectorEngine::writeToFile: Writing the main archive %s, to %s", _mainArchive->getFileName().c_str(), writePath.toString().c_str());
-	_mainArchive->writeToFile(writePath);
-}
-
 void Window::loadXtrasFromPath() {
 	// For D5 and above, Xtras are considered plug and play.
 	// According to Director Demystified: it considers an
diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 876044e877a..0e5b04a48b0 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -1252,22 +1252,20 @@ uint32 readVarInt(Common::SeekableReadStream &stream) {
 	return val;
 }
 
-uint32 writeVarInt(Common::SeekableReadStream &stream, uint32 value) {
-	warning("STUB::writeVarInt: Can't write variable intager types yet");
-	return 0;
-}
+Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, uint32 len, uint32 *outLen, bool bigEndian) {
+	unsigned long outLenUL = static_cast<unsigned long>(*outLen);
 
-Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long *outLen, bool bigEndian) {
 	byte *in = (byte *)malloc(len);
 	byte *out = (byte *)malloc(*outLen);
 	stream.read(in, len);
 
-	if (!Common::inflateZlib(out, outLen, in, len)) {
+	if (!Common::inflateZlib(out, &outLenUL, in, len)) {
 		free(in);
 		free(out);
 		return nullptr;
 	}
 
+	*outLen = static_cast<uint32>(outLenUL);
 	free(in);
 	return new Common::MemoryReadStreamEndian(out, *outLen, bigEndian, DisposeAfterUse::YES);
 }
diff --git a/engines/director/util.h b/engines/director/util.h
index 0f15d10e58b..e5b3f4f8446 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -93,7 +93,7 @@ private:
 
 uint32 readVarInt(Common::SeekableReadStream &stream);
 
-Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long *outLen, bool bigEndian);
+Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, uint32 len, uint32 *outLen, bool bigEndian);
 
 uint16 humanVersion(uint16 ver);
 




More information about the Scummvm-git-logs mailing list