Skip to content

Commit

Permalink
DIRECTOR: Parse the RIFX from v4 Mac versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hoops authored and sev- committed Aug 3, 2016
1 parent 09f6949 commit 9a9df86
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions engines/director/director.cpp
Expand Up @@ -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"
Expand All @@ -42,17 +43,21 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam
syncSoundSettings();

_mainArchive = 0;
_macBinary = 0;
}

DirectorEngine::~DirectorEngine() {
delete _mainArchive;
delete _macBinary;
}

Common::Error DirectorEngine::run() {
debug("Starting v%d Director game", getVersion());

if (getPlatform() == Common::kPlatformWindows)
loadEXE();
else
loadMac();

return Common::kNoError;
}
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions engines/director/director.h
Expand Up @@ -29,6 +29,10 @@

class OSystem;

namespace Common {
class MacResManager;
}

namespace Director {

enum DirectorGameID {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9a9df86

Please sign in to comment.