[Scummvm-git-logs] scummvm master -> ebd457841cc8b7b417b82ff0f89e6d7c9faebf35

sev- noreply at scummvm.org
Sun Dec 18 19:46:39 UTC 2022


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

Summary:
7b9f0ab75d SAGA: Switch from custom macbinary parser to MacResManager
0b8d67ff8d SAGA: Remove contextOffset/contextSize
0482b7cb2a SAGA: Change ITE Mac Guild CD entry to use MACRESFORK
ebd457841c SAGA: Support having game files under "ITE Data Files"


Commit: 7b9f0ab75daa4ce8862bbd36a06753df736fc5f3
    https://github.com/scummvm/scummvm/commit/7b9f0ab75daa4ce8862bbd36a06753df736fc5f3
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2022-12-18T20:46:34+01:00

Commit Message:
SAGA: Switch from custom macbinary parser to MacResManager

This makes it compatible with other resource fork formats after
update of detection entries

Changed paths:
    engines/saga/music.cpp
    engines/saga/resource.cpp
    engines/saga/resource.h
    engines/saga/resource_res.cpp
    engines/saga/resource_rsc.cpp
    engines/saga/sndres.cpp


diff --git a/engines/saga/music.cpp b/engines/saga/music.cpp
index 2262234c191..542223cb508 100644
--- a/engines/saga/music.cpp
+++ b/engines/saga/music.cpp
@@ -385,7 +385,7 @@ bool Music::playDigital(uint32 resourceId, MusicFlags flags) {
 
 				// Digital music
 				ResourceData *resData = _digitalMusicContext->getResourceData(resourceId - 9);
-				Common::File *musicFile = _digitalMusicContext->getFile(resData);
+				Common::SeekableReadStream *musicFile = _digitalMusicContext->getFile(resData);
 				int offs = (_digitalMusicContext->isCompressed()) ? 9 : 0;
 
 				Common::SeekableSubReadStream *musicStream = new Common::SeekableSubReadStream(musicFile,
diff --git a/engines/saga/resource.cpp b/engines/saga/resource.cpp
index ad1fa342e60..fae00692b47 100644
--- a/engines/saga/resource.cpp
+++ b/engines/saga/resource.cpp
@@ -168,22 +168,22 @@ bool ResourceContext::loadResIteAmigaSound(SagaEngine *_vm, uint32 contextOffset
 bool ResourceContext::loadResIteAmiga(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type, bool isFloppy) {
 	if (_fileType & (GAME_VOICEFILE | GAME_SOUNDFILE))
 		return loadResIteAmigaSound(_vm, contextOffset, contextSize, type);
-	_file.seek(contextOffset);
-	uint16 resourceCount = _file.readUint16BE();
-	uint16 scriptCount = _file.readUint16BE();
+	_file->seek(contextOffset);
+	uint16 resourceCount = _file->readUint16BE();
+	uint16 scriptCount = _file->readUint16BE();
 	uint32 count = (type &  GAME_SCRIPTFILE) ? scriptCount : resourceCount;
 	uint32 extraOffset = isFloppy ? 1024 : 0;
 
 	if (type &  GAME_SCRIPTFILE)
-		_file.seek(resourceCount * 10, SEEK_CUR);
+		_file->seek(resourceCount * 10, SEEK_CUR);
 
 	_table.resize(count);
 
 	for (uint32 i = 0; i < count; i++) {
 		ResourceData *resourceData = &_table[i];
-		resourceData->offset = _file.readUint32BE() + extraOffset;
-		resourceData->size = _file.readUint32BE();
-		resourceData->diskNum = _file.readUint16BE();
+		resourceData->offset = _file->readUint32BE() + extraOffset;
+		resourceData->size = _file->readUint32BE();
+		resourceData->diskNum = _file->readUint16BE();
 	}
 
 	return true;
@@ -203,9 +203,9 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
 		return false;
 	}
 
-	_file.seek(contextOffset + contextSize - RSC_TABLEINFO_SIZE);
+	_file->seek(contextOffset + contextSize - RSC_TABLEINFO_SIZE);
 
-	if (_file.read(tableInfo, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
+	if (_file->read(tableInfo, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
 		warning("ResourceContext::loadResV1(): Incorrect table size: %d for %s", RSC_TABLEINFO_SIZE, _fileName);
 		return false;
 	}
@@ -226,9 +226,9 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
 	// Load resource table
 	tableBuffer.resize(RSC_TABLEENTRY_SIZE * count);
 
-	_file.seek(resourceTableOffset + contextOffset, SEEK_SET);
+	_file->seek(resourceTableOffset + contextOffset, SEEK_SET);
 
-	result = (_file.read(tableBuffer.getBuffer(), tableBuffer.size()) == tableBuffer.size());
+	result = (_file->read(tableBuffer.getBuffer(), tableBuffer.size()) == tableBuffer.size());
 	if (result) {
 		_table.resize(count);
 
@@ -253,28 +253,22 @@ bool ResourceContext::load(SagaEngine *vm, Resource *resource) {
 	if (_fileName == nullptr) // IHNM special case
 		return true;
 
-	if (!_file.open(_fileName))
+	_file.reset(Common::MacResManager::openFileOrDataFork(_fileName));
+	if (!_file)
 		return false;
 
-	_fileSize = _file.size();
+	_fileSize = _file->size();
 	_isBigEndian = vm->isBigEndian();
 
 	if (_fileType & GAME_SWAPENDIAN)
 		_isBigEndian = !_isBigEndian;
 
-	if (_fileType & GAME_MACBINARY) {
-		// Special case for the MacBinary packed files in the old Mac ITE
-		// release. There are no patch files in this case.
-		if (!(_fileType & GAME_MUSICFILE_GM)) {
-			// Find the actual size, as there may be padded data in the end.
-			_file.seek(83);
-			uint32 macDataSize = _file.readSint32BE();
-			// Skip the MacBinary headers, and read the resource data.
-			return loadRes(vm, MAC_BINARY_HEADER_SIZE, macDataSize, _fileType);
-		} else {
-			// Unpack MacBinary packed MIDI files
-			return loadMacMIDI();
-		}
+	if ((_fileType & (GAME_MACBINARY | GAME_MUSICFILE_GM)) == (GAME_MACBINARY | GAME_MUSICFILE_GM)) {
+		_macRes.reset(new Common::MacResManager());
+		if (!_macRes->open(_fileName))
+			return false;
+		// Unpacking MacBinary packed MIDI files happens on-demand
+		return true;
 	}
 
 
@@ -289,7 +283,7 @@ bool ResourceContext::load(SagaEngine *vm, Resource *resource) {
 	// This prevents having all voice files open in IHNM for no reason, as each chapter uses
 	// a different voice file.
 	if (_serial > 0)
-		_file.close();
+		closeFile();
 
 	return true;
 }
@@ -379,7 +373,7 @@ bool Resource::createContexts() {
 		// as big endian
 		{	GID_ITE,	"inherit the earth voices",		false	,	(uint16)(_vm->isBigEndian() ? 0 : GAME_SWAPENDIAN)},
 		{	GID_ITE,	"inherit the earth voices.cmp",	true	,	(uint16)(_vm->isBigEndian() ? 0 : GAME_SWAPENDIAN)},
-		{	GID_ITE,	"ite voices.bin",				false	,	GAME_MACBINARY},
+		{	GID_ITE,	"ite voices",				false	,	GAME_MACBINARY},
 #ifdef ENABLE_IHNM
 		{	GID_IHNM,	"voicess.res",					false	,	0},
 		{	GID_IHNM,	"voicess.cmp",					true	,	0},
@@ -394,7 +388,8 @@ bool Resource::createContexts() {
 	if (!voiceFileInArray) {
 		for (SoundFileInfo *curSoundFile = voiceFiles; (curSoundFile->gameId != -1); curSoundFile++) {
 			if (curSoundFile->gameId != _vm->getGameId()) continue;
-			if (!Common::File::exists(curSoundFile->fileName)) continue;
+			bool exists = curSoundFile->voiceFileAddType & GAME_MACBINARY ? Common::MacResManager::exists(curSoundFile->fileName) : Common::File::exists(curSoundFile->fileName);
+			if (!exists) continue;
 
 			Common::strcpy_s(_voicesFileName[0], curSoundFile->fileName);
 			addContext(_voicesFileName[0], GAME_VOICEFILE | curSoundFile->voiceFileAddType, curSoundFile->isCompressed);
@@ -477,15 +472,29 @@ void Resource::clearContexts() {
 	}
 }
 
+#define ID_MIDI     MKTAG('M','i','d','i')
+
 void Resource::loadResource(ResourceContext *context, uint32 resourceId, ByteArray &resourceBuffer) {
+	if ((context->_fileType & (GAME_MACBINARY | GAME_MUSICFILE_GM)) == (GAME_MACBINARY | GAME_MUSICFILE_GM) && context->_macRes) {
+		Common::SeekableReadStream *s = context->_macRes->getResource(ID_MIDI, resourceId);
+		if (!s)
+			return;
+		resourceBuffer.resize(s->size());
+		s->read(resourceBuffer.getBuffer(), s->size());
+
+		delete s;
+		
+		return;
+	}
+
 	ResourceData *resourceData = context->getResourceData(resourceId);
-	Common::File *file = nullptr;
+	Common::SeekableReadStream *file = nullptr;
 	uint32 resourceOffset = resourceData->offset;
 
-	if (resourceData->diskNum < 0)
+	if (resourceData->diskNum == -1)
 		file = context->getFile(resourceData);
 	else {
-		file = new Common::File();
+		Common::File *actualFile = new Common::File();
 		Common::String fileName = context->_fileName;
 		int sz = fileName.size();
 		while(sz > 0 && fileName[sz - 1] != '.')
@@ -496,8 +505,9 @@ void Resource::loadResource(ResourceContext *context, uint32 resourceId, ByteArr
 			fileName = Common::String::format("%s%02d.adf", fileName.substr(0, sz).c_str(), resourceData->diskNum + 1);
 		else
 			fileName = Common::String::format("%s.%03d", fileName.substr(0, sz).c_str(), resourceData->diskNum);
-		if (!file->open(fileName))
+		if (!actualFile->open(fileName))
 			error("Resource::loadResource() failed to open %s", fileName.c_str());
+		file = actualFile;
 	}
 
 	debug(8, "loadResource %d 0x%X:0x%X", resourceId, resourceOffset, uint(resourceData->size));
@@ -513,7 +523,7 @@ void Resource::loadResource(ResourceContext *context, uint32 resourceId, ByteArr
 	// anymore (as they're in memory), so close them here. IHNM uses only
 	// 1 patch file, which is reused, so don't close it
 	if (resourceData->patchData != nullptr && _vm->getGameId() == GID_ITE)
-		file->close();
+		context->closeFile();
 
 	if (_vm->getPlatform() == Common::Platform::kPlatformAmiga &&
 	    resourceBuffer.size() >= 16 && READ_BE_UINT32(resourceBuffer.getBuffer()) == MKTAG('H', 'E', 'A', 'D')
diff --git a/engines/saga/resource.h b/engines/saga/resource.h
index 48c6878326a..4286ee67865 100644
--- a/engines/saga/resource.h
+++ b/engines/saga/resource.h
@@ -27,10 +27,10 @@
 #include "common/array.h"
 #include "common/file.h"
 #include "common/list.h"
+#include "common/macresman.h"
 
 namespace Saga {
 
-#define MAC_BINARY_HEADER_SIZE 128
 #define RSC_TABLEINFO_SIZE 8
 #define RSC_TABLEENTRY_SIZE 8
 
@@ -39,15 +39,33 @@ namespace Saga {
 class SagaEngine;
 class ByteArray;
 
-struct PatchData {
-	Common::File *_patchFile;
+class PatchData {
+private:
+	Common::SeekableReadStream *_patchFile;
 	const char *_fileName;
 	bool _deletePatchFile;
 
-	PatchData(const char *fileName): _fileName(fileName), _deletePatchFile(true) {
-		_patchFile = new Common::File();
+public:
+	PatchData(const char *fileName): _fileName(fileName), _deletePatchFile(true), _patchFile(nullptr) {
+	}
+	PatchData(Common::SeekableReadStream *patchFile, const char *fileName): _patchFile(patchFile), _fileName(fileName), _deletePatchFile(false) {
 	}
-	PatchData(Common::File *patchFile, const char *fileName): _patchFile(patchFile), _fileName(fileName), _deletePatchFile(false) {
+
+	Common::SeekableReadStream *getStream() {
+		if (_patchFile)
+			return _patchFile;
+		
+		Common::File *file = new Common::File();
+		file->open(_fileName);
+		_patchFile = file;
+		return _patchFile;
+	}
+
+	void closeStream() {
+		if (_deletePatchFile) {
+			delete _patchFile;
+			_patchFile = nullptr;
+		}
 	}
 
 	~PatchData() {
@@ -60,7 +78,7 @@ struct PatchData {
 struct ResourceData {
 	size_t offset;
 	size_t size;
-	int diskNum;
+	int diskNum; // -1 = without disk id. -2 = mac res fork
 	PatchData *patchData;
 
 	ResourceData() :
@@ -96,19 +114,12 @@ public:
 	bool isBigEndian() const { return _isBigEndian; }
 	const char * fileName() const {	return _fileName; }
 
-	Common::File *getFile(ResourceData *resourceData) {
-		Common::File *file;
-		const char * fn;
+	Common::SeekableReadStream *getFile(ResourceData *resourceData) {
 		if (resourceData && resourceData->patchData != NULL) {
-			file = resourceData->patchData->_patchFile;
-			fn = resourceData->patchData->_fileName;
+			return resourceData->patchData->getStream();
 		} else {
-			file = &_file;
-			fn = _fileName;
+			return _file.get();
 		}
-		if (!file->isOpen())
-			file->open(fn);
-		return file;
 	}
 
 	bool validResourceId(uint32 resourceId) const {
@@ -122,6 +133,10 @@ public:
 		return &_table[resourceId];
 	}
 
+	void closeFile() {
+		_file.reset();
+	}
+
 protected:
 	const char *_fileName;
 	uint16 _fileType;
@@ -130,7 +145,8 @@ protected:
 
 	bool _isBigEndian;
 	ResourceDataArray _table;
-	Common::File _file;
+	Common::ScopedPtr<Common::SeekableReadStream> _file;
+	Common::ScopedPtr<Common::MacResManager> _macRes;
 	int32 _fileSize;
 
 	bool load(SagaEngine *_vm, Resource *resource);
@@ -138,7 +154,6 @@ protected:
 	bool loadResIteAmiga(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type, bool isFloppy);
 	bool loadResIteAmigaSound(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type);
 
-	virtual bool loadMacMIDI() { return false; }
 	virtual bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) = 0;
 	virtual void processPatches(Resource *resource, const GamePatchDescription *patchFiles) { }
 };
@@ -195,7 +210,6 @@ protected:
 // ITE
 class ResourceContext_RSC: public ResourceContext {
 protected:
-	bool loadMacMIDI() override;
 	bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) override {
 		return loadResV1(contextOffset, contextSize);
 	}
diff --git a/engines/saga/resource_res.cpp b/engines/saga/resource_res.cpp
index 1f1bf76ef2c..7b1af04fca5 100644
--- a/engines/saga/resource_res.cpp
+++ b/engines/saga/resource_res.cpp
@@ -221,7 +221,7 @@ void ResourceContext_RES::processPatches(Resource *resource, const GamePatchDesc
 			patchResourceId = readS2.readUint32();
 			subjectResourceData = subjectContext->getResourceData(subjectResourceId);
 			resourceData = getResourceData(patchResourceId);
-			subjectResourceData->patchData = new PatchData(&_file, _fileName);
+			subjectResourceData->patchData = new PatchData(_file.get(), _fileName);
 			subjectResourceData->offset = resourceData->offset;
 			subjectResourceData->size = resourceData->size;
 		}
diff --git a/engines/saga/resource_rsc.cpp b/engines/saga/resource_rsc.cpp
index 4df242ac8b3..3fc7b0615fa 100644
--- a/engines/saga/resource_rsc.cpp
+++ b/engines/saga/resource_rsc.cpp
@@ -26,60 +26,6 @@
 
 namespace Saga {
 
-#define ID_MIDI     MKTAG('M','i','d','i')
-
-bool ResourceContext_RSC::loadMacMIDI() {
-	// Sanity check
-	if (_fileSize < RSC_MIN_FILESIZE + MAC_BINARY_HEADER_SIZE)
-		return false;
-
-	_file.seek(83);
-	int macDataSize = _file.readSint32BE();
-	int macResOffset = MAC_BINARY_HEADER_SIZE + (((macDataSize + 127) >> 7) << 7);
-
-	_file.seek(macResOffset);
-	uint32 macDataOffset = _file.readUint32BE() + macResOffset;
-	uint32 macMapOffset = _file.readUint32BE() + macResOffset;
-
-	_file.seek(macMapOffset + 22);
-	_file.readUint16BE();	// resAttr
-	int16 typeOffset = _file.readUint16BE();
-	_file.readUint16BE();	// nameOffset
-	uint16 numTypes = _file.readUint16BE() + 1;
-
-	_file.seek(macMapOffset + typeOffset + 2);
-
-	// Find the MIDI files
-	for (uint16 i = 0; i < numTypes; i++) {
-		uint32 id = _file.readUint32BE();
-		uint16 items = _file.readUint16BE() + 1;
-		uint16 offset = _file.readUint16BE();
-
-		if (id == ID_MIDI) {
-			for (uint16 curMidi = 0; curMidi < items; curMidi++) {
-				// Jump to the header of the entry and read its fields
-				_file.seek(offset + macMapOffset + typeOffset + curMidi * 12);
-				uint16 midiID = _file.readUint16BE();
-				_file.readUint16BE();	// nameOffset
-				uint32 midiOffset = _file.readUint32BE() & 0xFFFFFF;
-				_file.readUint32BE();	// macResSize
-
-				// Jump to the actual data and read the file size
-				_file.seek(macDataOffset + midiOffset);
-				uint32 midiSize = _file.readUint32BE();
-
-				// Add the entry
-				if (_table.size() <= midiID)
-					_table.resize(midiID + 1);
-				_table[midiID].offset = macDataOffset + midiOffset + 4;
-				_table[midiID].size = midiSize;
-			}
-		}
-	}
-
-	return true;
-}
-
 void ResourceContext_RSC::processPatches(Resource *resource, const GamePatchDescription *patchFiles) {
 	const GamePatchDescription *patchDescription;
 	ResourceData *resourceData;
@@ -92,11 +38,12 @@ void ResourceContext_RSC::processPatches(Resource *resource, const GamePatchDesc
 				// Check if we've already found a patch for this resource. One is enough.
 				if (!resourceData->patchData) {
 					resourceData->patchData = new PatchData(patchDescription->fileName);
-					if (resourceData->patchData->_patchFile->open(patchDescription->fileName)) {
+					Common::SeekableReadStream *s = resourceData->patchData->getStream();
+					if (s) {
 						resourceData->offset = 0;
-						resourceData->size = resourceData->patchData->_patchFile->size();
+						resourceData->size = s->size();
 						// The patched ITE file is in memory, so close the patch file
-						resourceData->patchData->_patchFile->close();
+						resourceData->patchData->closeStream();
 					} else {
 						delete resourceData->patchData;
 						resourceData->patchData = nullptr;
diff --git a/engines/saga/sndres.cpp b/engines/saga/sndres.cpp
index 8e5983e565b..1ab5c8963b8 100644
--- a/engines/saga/sndres.cpp
+++ b/engines/saga/sndres.cpp
@@ -104,7 +104,6 @@ SndRes::~SndRes() {
 }
 
 void SndRes::setVoiceBank(int serial) {
-	Common::File *file;
 	if (_voiceSerial == serial)
 		return;
 
@@ -125,10 +124,7 @@ void SndRes::setVoiceBank(int serial) {
 
 	// Close previous voice bank file
 	if (_voiceContext != nullptr) {
-		file = _voiceContext->getFile(nullptr);
-		if (file->isOpen()) {
-			file->close();
-		}
+		_voiceContext->closeFile();
 	}
 
 	_voiceSerial = serial;
@@ -199,7 +195,7 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
 	bool result = false;
 	GameSoundType resourceType = kSoundPCM;
 	int rate = 0, size = 0;
-	Common::File *file;
+	Common::SeekableReadStream *file;
 
 	if (context == nullptr)
 		return false;
@@ -224,10 +220,11 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
 			Common::sprintf_s(soundFileName, "SFX/SFX%d/SFX%03x", dirIndex, resourceId);
 		}
 
-		file = new Common::File();
+		Common::File *actualFile = new Common::File();
 
-		file->open(soundFileName);
-		soundResourceLength = file->size();
+		actualFile->open(soundFileName);
+		soundResourceLength = actualFile->size();
+		file = actualFile;
 	} else
 #endif
 	{


Commit: 0b8d67ff8d9882a5e6b7c8701121a00fb94dc40a
    https://github.com/scummvm/scummvm/commit/0b8d67ff8d9882a5e6b7c8701121a00fb94dc40a
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2022-12-18T20:46:34+01:00

Commit Message:
SAGA: Remove contextOffset/contextSize

It was used only in now defunct custom macbinary parser

Changed paths:
    engines/saga/resource.cpp
    engines/saga/resource.h


diff --git a/engines/saga/resource.cpp b/engines/saga/resource.cpp
index fae00692b47..3b767e119e1 100644
--- a/engines/saga/resource.cpp
+++ b/engines/saga/resource.cpp
@@ -107,7 +107,7 @@ struct ITEAmigaEXEDescriptor {
 	ITEAmigaIndex soundIndex;
 };
 
-bool ResourceContext::loadResIteAmigaSound(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) {
+bool ResourceContext::loadResIteAmigaSound(SagaEngine *_vm, int type) {
 	Common::String exeName;
 
 	for (const ADGameFileDescription *gameFileDescription = _vm->getFilesDescriptions();
@@ -165,10 +165,10 @@ bool ResourceContext::loadResIteAmigaSound(SagaEngine *_vm, uint32 contextOffset
 	return true;
 }
 
-bool ResourceContext::loadResIteAmiga(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type, bool isFloppy) {
+bool ResourceContext::loadResIteAmiga(SagaEngine *_vm, int type, bool isFloppy) {
 	if (_fileType & (GAME_VOICEFILE | GAME_SOUNDFILE))
-		return loadResIteAmigaSound(_vm, contextOffset, contextSize, type);
-	_file->seek(contextOffset);
+		return loadResIteAmigaSound(_vm, type);
+	_file->seek(0);
 	uint16 resourceCount = _file->readUint16BE();
 	uint16 scriptCount = _file->readUint16BE();
 	uint32 count = (type &  GAME_SCRIPTFILE) ? scriptCount : resourceCount;
@@ -189,7 +189,7 @@ bool ResourceContext::loadResIteAmiga(SagaEngine *_vm, uint32 contextOffset, uin
 	return true;
 }
 
-bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
+bool ResourceContext::loadResV1() {
 	size_t i;
 	bool result;
 	byte tableInfo[RSC_TABLEINFO_SIZE];
@@ -198,12 +198,12 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
 	uint32 resourceTableOffset;
 	ResourceData *resourceData;
 
-	if (contextSize < RSC_MIN_FILESIZE) {
-		warning("ResourceContext::loadResV1(): Incorrect contextSize: %d < %d", contextSize, RSC_MIN_FILESIZE);
+	if (_fileSize < RSC_MIN_FILESIZE) {
+		warning("ResourceContext::loadResV1(): Incorrect contextSize: %d < %d", (int) _fileSize, RSC_MIN_FILESIZE);
 		return false;
 	}
 
-	_file->seek(contextOffset + contextSize - RSC_TABLEINFO_SIZE);
+	_file->seek(-RSC_TABLEINFO_SIZE, SEEK_END);
 
 	if (_file->read(tableInfo, RSC_TABLEINFO_SIZE) != RSC_TABLEINFO_SIZE) {
 		warning("ResourceContext::loadResV1(): Incorrect table size: %d for %s", RSC_TABLEINFO_SIZE, _fileName);
@@ -216,9 +216,9 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
 	count = readS.readUint32();
 
 	// Check for sane table offset
-	if (resourceTableOffset != contextSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * count) {
+	if (resourceTableOffset != _fileSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * count) {
 		warning("ResourceContext::loadResV1(): Incorrect tables offset: %d != %d for %s, endian is %d",
-			resourceTableOffset, contextSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * count,
+			resourceTableOffset, (int)_fileSize - RSC_TABLEINFO_SIZE - RSC_TABLEENTRY_SIZE * count,
 			_fileName, _isBigEndian);
 		return false;
 	}
@@ -226,7 +226,7 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
 	// Load resource table
 	tableBuffer.resize(RSC_TABLEENTRY_SIZE * count);
 
-	_file->seek(resourceTableOffset + contextOffset, SEEK_SET);
+	_file->seek(resourceTableOffset, SEEK_SET);
 
 	result = (_file->read(tableBuffer.getBuffer(), tableBuffer.size()) == tableBuffer.size());
 	if (result) {
@@ -236,10 +236,10 @@ bool ResourceContext::loadResV1(uint32 contextOffset, uint32 contextSize) {
 
 		for (i = 0; i < count; i++) {
 			resourceData = &_table[i];
-			resourceData->offset = contextOffset + readS1.readUint32();
+			resourceData->offset = readS1.readUint32();
 			resourceData->size = readS1.readUint32();
 			// Sanity check
-			if ((resourceData->offset > (uint)_fileSize) || (resourceData->size > contextSize)) {
+			if ((resourceData->offset > (uint)_fileSize) || (resourceData->size > (uint)_fileSize)) {
 				result = false;
 				break;
 			}
@@ -272,7 +272,7 @@ bool ResourceContext::load(SagaEngine *vm, Resource *resource) {
 	}
 
 
-	if (!loadRes(vm, 0, _fileSize, _fileType))
+	if (!loadRes(vm, _fileType))
 		return false;
 
 	GamePatchList index = vm->getPatchList();
diff --git a/engines/saga/resource.h b/engines/saga/resource.h
index 4286ee67865..d54aa02e449 100644
--- a/engines/saga/resource.h
+++ b/engines/saga/resource.h
@@ -150,11 +150,11 @@ protected:
 	int32 _fileSize;
 
 	bool load(SagaEngine *_vm, Resource *resource);
-	bool loadResV1(uint32 contextOffset, uint32 contextSize);
-	bool loadResIteAmiga(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type, bool isFloppy);
-	bool loadResIteAmigaSound(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type);
+	bool loadResV1();
+	bool loadResIteAmiga(SagaEngine *_vm, int type, bool isFloppy);
+	bool loadResIteAmigaSound(SagaEngine *_vm, int type);
 
-	virtual bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) = 0;
+	virtual bool loadRes(SagaEngine *_vm, int type) = 0;
 	virtual void processPatches(Resource *resource, const GamePatchDescription *patchFiles) { }
 };
 
@@ -210,8 +210,8 @@ protected:
 // ITE
 class ResourceContext_RSC: public ResourceContext {
 protected:
-	bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) override {
-		return loadResV1(contextOffset, contextSize);
+	bool loadRes(SagaEngine *_vm, int type) override {
+		return loadResV1();
 	}
 	void processPatches(Resource *resource, const GamePatchDescription *patchFiles) override;
 };
@@ -221,8 +221,8 @@ public:
 	ResourceContext_RSC_ITE_Amiga(bool isFloppy) : _isFloppy(isFloppy) {}
 
 protected:
-	bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) override {
-		return loadResIteAmiga(_vm, contextOffset, contextSize, type, _isFloppy);
+	bool loadRes(SagaEngine *_vm, int type) override {
+		return loadResIteAmiga(_vm, type, _isFloppy);
 	}
 
 	bool _isFloppy;
@@ -252,8 +252,8 @@ protected:
 // IHNM
 class ResourceContext_RES: public ResourceContext {
 protected:
-	bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) override {
-		return loadResV1(0, contextSize);
+	bool loadRes(SagaEngine *_vm, int type) override {
+		return loadResV1();
 	}
 
 	void processPatches(Resource *resource, const GamePatchDescription *patchFiles) override;
@@ -262,7 +262,7 @@ protected:
 // TODO: move load routines from sndres
 class VoiceResourceContext_RES: public ResourceContext {
 protected:
-	bool loadRes(SagaEngine *_vm, uint32 contextOffset, uint32 contextSize, int type) override {
+	bool loadRes(SagaEngine *_vm, int type) override {
 		return false;
 	}
 public:


Commit: 0482b7cb2aba5e0c1ff9dcbe7fab58e26593c93c
    https://github.com/scummvm/scummvm/commit/0482b7cb2aba5e0c1ff9dcbe7fab58e26593c93c
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2022-12-18T20:46:34+01:00

Commit Message:
SAGA: Change ITE Mac Guild CD entry to use MACRESFORK

Now this CD version works with dumper-companion

Changed paths:
    engines/saga/detection_tables.h


diff --git a/engines/saga/detection_tables.h b/engines/saga/detection_tables.h
index 6772ff29af9..b653c704248 100644
--- a/engines/saga/detection_tables.h
+++ b/engines/saga/detection_tables.h
@@ -230,16 +230,16 @@ static const SAGAGameDescription gameDescriptions[] = {
 			"ite",
 			"CD",
 			{
-				{"ite resources.bin",	GAME_RESOURCEFILE | GAME_MACBINARY,	"0bd506aa887bfc7965f695c6bd28237d", -1},
-				{"ite scripts.bin",		GAME_SCRIPTFILE | GAME_MACBINARY,	"af0d7a2588e09ad3ecbc5b474ea238bf", -1},
-				{"ite sounds.bin",		GAME_SOUNDFILE | GAME_MACBINARY,	"441426c6bb2a517f65c7e49b57f7a345", -1},
-				{"ite music.bin",		GAME_MUSICFILE_GM | GAME_MACBINARY,	"c1d20324b7cdf1650e67061b8a93251c", -1},
-				//{"ite voices.bin",		GAME_VOICEFILE | GAME_MACBINARY,	"dba92ae7d57e942250fe135609708369", -1},
+				{"ite resources",	GAME_RESOURCEFILE | GAME_MACBINARY,	"ee65f8e713127cf7f2d56371d2b8e63d", 2264},
+				{"ite scripts",		GAME_SCRIPTFILE | GAME_MACBINARY,	"ee65f8e713127cf7f2d56371d2b8e63d", 2264},
+				{"ite sounds",		GAME_SOUNDFILE | GAME_MACBINARY,	"ee65f8e713127cf7f2d56371d2b8e63d", 2264},
+				{"ite music",		GAME_MUSICFILE_GM | GAME_MACBINARY,	"b0d66d7ae48f35c5c9a3444343b86f85", 3135053},
+				// {"ite voices",		GAME_VOICEFILE | GAME_MACBINARY,	"ee65f8e713127cf7f2d56371d2b8e63d", 2264},
 				AD_LISTEND
 			},
 			Common::EN_ANY,
 			Common::kPlatformMacintosh,
-			ADGF_CD,
+			ADGF_CD | ADGF_MACRESFORK,
 			GUIO0()
 		},
 		GID_ITE,


Commit: ebd457841cc8b7b417b82ff0f89e6d7c9faebf35
    https://github.com/scummvm/scummvm/commit/ebd457841cc8b7b417b82ff0f89e6d7c9faebf35
Author: Vladimir Serbinenko (phcoder at gmail.com)
Date: 2022-12-18T20:46:34+01:00

Commit Message:
SAGA: Support having game files under "ITE Data Files"

This is the case for Mac Guild CD version. Normally we ask user to just
select this subdirectory but selecting CD root is more logical

Changed paths:
    engines/saga/detection.cpp
    engines/saga/saga.cpp


diff --git a/engines/saga/detection.cpp b/engines/saga/detection.cpp
index 7732c8fc985..6fb28c12247 100644
--- a/engines/saga/detection.cpp
+++ b/engines/saga/detection.cpp
@@ -37,7 +37,7 @@ static const PlainGameDescriptor sagaGames[] = {
 class SagaMetaEngineDetection : public AdvancedMetaEngineDetection {
 public:
 	SagaMetaEngineDetection() : AdvancedMetaEngineDetection(Saga::gameDescriptions, sizeof(Saga::SAGAGameDescription), sagaGames) {
-		static const char *const DIRECTORY_GLOBS[2] = { "music", nullptr };
+		static const char *const DIRECTORY_GLOBS[3] = { "music", "ITE Data Files", nullptr };
 		_maxScanDepth = 2;
 		_directoryGlobs = DIRECTORY_GLOBS;
 		_flags = kADFlagUseExtraAsHint;
diff --git a/engines/saga/saga.cpp b/engines/saga/saga.cpp
index 0f487d4a3d0..6317d5e4139 100644
--- a/engines/saga/saga.cpp
+++ b/engines/saga/saga.cpp
@@ -274,6 +274,9 @@ SagaEngine::SagaEngine(OSystem *syst, const SAGAGameDescription *gameDesc)
 	// Mac CD Wyrmkeep
 	SearchMan.addSubDirectoryMatching(gameDataDir, "patch");
 
+	if (getPlatform() == Common::Platform::kPlatformMacintosh)
+		SearchMan.addSubDirectoryMatching(gameDataDir, "ITE Data Files");
+
 	_displayClip.left = _displayClip.top = 0;
 }
 




More information about the Scummvm-git-logs mailing list