From 9a9df86fded26b253e8d1c02a5a048839084f0e7 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Wed, 14 Nov 2012 14:27:42 -0500 Subject: [PATCH] DIRECTOR: Parse the RIFX from v4 Mac versions --- engines/director/director.cpp | 33 +++++++++++++++++++++++++++++++++ engines/director/director.h | 7 +++++++ 2 files changed, 40 insertions(+) diff --git a/engines/director/director.cpp b/engines/director/director.cpp index 4df959d05dbb..5cb5f2089cda 100644 --- a/engines/director/director.cpp +++ b/engines/director/director.cpp @@ -25,6 +25,7 @@ #include "common/debug.h" #include "common/scummsys.h" #include "common/error.h" +#include "common/macresman.h" #include "common/stream.h" #include "common/system.h" #include "common/textconsole.h" @@ -42,10 +43,12 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam syncSoundSettings(); _mainArchive = 0; + _macBinary = 0; } DirectorEngine::~DirectorEngine() { delete _mainArchive; + delete _macBinary; } Common::Error DirectorEngine::run() { @@ -53,6 +56,8 @@ Common::Error DirectorEngine::run() { if (getPlatform() == Common::kPlatformWindows) loadEXE(); + else + loadMac(); return Common::kNoError; } @@ -142,6 +147,34 @@ void DirectorEngine::loadEXERIFX(Common::SeekableReadStream *stream, uint32 offs error("Failed to load RIFX from EXE"); } +void DirectorEngine::loadMac() { + if (getVersion() < 4) + error("Unhandled pre-v4 Mac version"); + + _macBinary = new Common::MacResManager(); + + if (!_macBinary->open(getEXEName()) || !_macBinary->hasDataFork()) + error("Failed to open Mac binary '%s'", getEXEName().c_str()); + + Common::SeekableReadStream *dataFork = _macBinary->getDataFork(); + _mainArchive = new RIFXArchive(); + + // First we need to detect PPC vs. 68k + + uint32 tag = dataFork->readUint32LE(); + + if (tag == MKTAG('P', 'J', '9', '3')) { + // PPC: The RIFX shares the data fork with the binary + dataFork->seek(dataFork->readUint32BE()); + } else { + // 68k: The RIFX is the only thing in the data fork + dataFork->seek(0); + } + + if (!_mainArchive->openStream(dataFork)) + error("Failed to load RIFX from Mac binary"); +} + Common::String DirectorEngine::readPascalString(Common::SeekableReadStream &stream) { byte length = stream.readByte(); Common::String x; diff --git a/engines/director/director.h b/engines/director/director.h index f1186f3b20e1..00198014e5fb 100644 --- a/engines/director/director.h +++ b/engines/director/director.h @@ -29,6 +29,10 @@ class OSystem; +namespace Common { +class MacResManager; +} + namespace Director { enum DirectorGameID { @@ -65,9 +69,12 @@ class DirectorEngine : public ::Engine { void loadEXEv5(Common::SeekableReadStream *stream); void loadEXERIFX(Common::SeekableReadStream *stream, uint32 offset); + void loadMac(); + Common::String readPascalString(Common::SeekableReadStream &stream); Archive *_mainArchive; + Common::MacResManager *_macBinary; }; } // End of namespace Director