diff options
| -rw-r--r-- | engines/mohawk/livingbooks.cpp | 77 | ||||
| -rw-r--r-- | engines/mohawk/livingbooks.h | 26 | 
2 files changed, 59 insertions, 44 deletions
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index 64383f6d2d..2e7f5e6d9d 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -32,6 +32,7 @@  #include "common/archive.h"  #include "common/textconsole.h"  #include "common/system.h" +#include "common/memstream.h"  #include "graphics/palette.h" @@ -1873,6 +1874,7 @@ uint16 LBAnimation::getParentId() {  LBScriptEntry::LBScriptEntry() {  	state = 0; +	data = NULL;  	argvParam = NULL;  	argvTarget = NULL;  } @@ -1880,6 +1882,7 @@ LBScriptEntry::LBScriptEntry() {  LBScriptEntry::~LBScriptEntry() {  	delete[] argvParam;  	delete[] argvTarget; +	delete[] data;  	for (uint i = 0; i < subentries.size(); i++)  		delete subentries[i]; @@ -1943,7 +1946,10 @@ void LBItem::readFrom(Common::SeekableSubReadStreamEndian *stream) {  		uint16 dataSize = stream->readUint16();  		debug(4, "Data type %04x, size %d", dataType, dataSize); -		readData(dataType, dataSize, stream); +		byte *buf = new byte[dataSize]; +		stream->read(buf, dataSize); +		readData(dataType, dataSize, buf); +		delete[] buf;  		if ((uint)stream->pos() != oldPos + 4 + (uint)dataSize)  			error("Failed to read correct number of bytes (off by %d) for data type %04x (size %d)", @@ -1956,7 +1962,7 @@ void LBItem::readFrom(Common::SeekableSubReadStreamEndian *stream) {  	}  } -LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::SeekableSubReadStreamEndian *stream, bool isSubentry) { +LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::MemoryReadStreamEndian *stream, bool isSubentry) {  	if (size < 6)  		error("Script entry of type 0x%04x was too small (%d)", type, size); @@ -2081,37 +2087,33 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Seeka  		debug(4, "kLBOpSendExpression: offset %08x", entry->offset);  		size -= 4;  	} -	if (entry->opcode == 0xffff) { +	if (entry->opcode == kLBOpRunData) {  		if (size < 4) -			error("didn't get enough bytes (%d) to read message in script entry", size); -		uint16 msgId = stream->readUint16(); -		uint16 msgLen = stream->readUint16(); +			error("didn't get enough bytes (%d) to read data header in script entry", size); +		entry->dataType = stream->readUint16(); +		entry->dataLen = stream->readUint16();  		size -= 4; -		if (msgId == kLBSetPlayInfo) { -			if (size != 20) -				error("wah, more than just the kLBSetPlayInfo in here"); -			// FIXME -			warning("ignoring kLBSetPlayInfo"); -			size -= 20; -			stream->skip(20); -			return entry; -		} -		if (msgId != kLBCommand) -			error("expected a command in script entry, got 0x%04x", msgId); +		if (size < entry->dataLen) +			error("didn't get enough bytes (%d) to read data in script entry", size); -		if (msgLen != size - (entry->event == kLBEventNotified ? 4 : 0) && !conditionTag) -			error("script entry msgLen %d is not equal to size %d", msgLen, size); - -		Common::String command = _vm->readString(stream); -		if (command.size() + 1 > size) { -			error("failed to read command in script entry: msgLen %d, command '%s' (%d chars)", -				msgLen, command.c_str(), command.size()); +		if (entry->dataType == kLBCommand) { +			Common::String command = _vm->readString(stream); +			uint commandSize = command.size() + 1; +			if (commandSize > entry->dataLen) +				error("failed to read command in script entry: dataLen %d, command '%s' (%d chars)", +					 entry->dataLen, command.c_str(), commandSize); +			entry->dataLen = commandSize; +			entry->data = new byte[commandSize]; +			memcpy(entry->data, command.c_str(), commandSize); +			size -= commandSize; +		} else { +			if (conditionTag) +				error("kLBOpRunData had unexpected conditionTag"); +			entry->data = new byte[entry->dataLen]; +			stream->read(entry->data, entry->dataLen); +			size -= entry->dataLen;  		} -		size -= command.size() + 1; - -		entry->command = command; -		debug(4, "script entry command '%s'", command.c_str());  	}  	if (entry->event == kLBEventNotified) {  		if (size < 4) @@ -2162,7 +2164,12 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Seeka  	return entry;  } -void LBItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { +void LBItem::readData(uint16 type, uint16 size, byte *data) { +	Common::MemoryReadStreamEndian stream(data, size, _vm->isBigEndian()); +	readData(type, size, &stream); +} + +void LBItem::readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream) {  	switch (type) {  	case kLBMsgListScript:  	case kLBNotifyScript: @@ -2831,8 +2838,8 @@ int LBItem::runScriptEntry(LBScriptEntry *entry) {  			}  			break; -		case kLBOpRunCommand: -			runCommand(entry->command); +		case kLBOpRunData: +			readData(entry->dataType, entry->dataLen, entry->data);  			break;  		case kLBOpJumpUnlessExpression: @@ -3168,7 +3175,7 @@ LBGroupItem::LBGroupItem(MohawkEngine_LivingBooks *vm, LBPage *page, Common::Rec  	_starting = false;  } -void LBGroupItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { +void LBGroupItem::readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream) {  	switch (type) {  	case kLBGroupData:  		{ @@ -3289,7 +3296,7 @@ LBPaletteItem::~LBPaletteItem() {  	delete[] _palette;  } -void LBPaletteItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { +void LBPaletteItem::readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream) {  	switch (type) {  	case kLBPaletteXData:  		{ @@ -3369,7 +3376,7 @@ LBLiveTextItem::LBLiveTextItem(MohawkEngine_LivingBooks *vm, LBPage *page, Commo  	debug(3, "new LBLiveTextItem");  } -void LBLiveTextItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { +void LBLiveTextItem::readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream) {  	switch (type) {  	case kLBLiveTextData:  		{ @@ -3614,7 +3621,7 @@ LBPictureItem::LBPictureItem(MohawkEngine_LivingBooks *vm, LBPage *page, Common:  	debug(3, "new LBPictureItem");  } -void LBPictureItem::readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream) { +void LBPictureItem::readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream) {  	switch (type) {  	case kLBSetDrawMode:  		{ diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index c39e7f4227..02cf6c3f64 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -29,7 +29,6 @@  #include "mohawk/sound.h"  #include "common/config-file.h" -#include "common/substream.h"  #include "common/rect.h"  #include "common/queue.h"  #include "common/random.h" @@ -38,6 +37,11 @@  #include "livingbooks_code.h" +namespace Common { +	class SeekableSubReadStreamEndian; +	class MemoryReadStreamEndian; +} +  namespace Mohawk {  #define LBKEY_MOD_CTRL 1 @@ -218,7 +222,7 @@ enum {  	kLBOpBreakExpression = 0xfffc,  	kLBOpJumpToExpression = 0xfffd,  	kLBOpRunSubentries = 0xfffe, -	kLBOpRunCommand = 0xffff +	kLBOpRunData = 0xffff  };  enum { @@ -277,7 +281,10 @@ struct LBScriptEntry {  	// kLBOpJumpUnlessExpression  	uint16 target; -	Common::String command; +	uint16 dataType; +	uint16 dataLen; +	byte *data; +  	Common::Array<Common::String> conditions;  	Common::Array<LBScriptEntry *> subentries;  }; @@ -368,7 +375,8 @@ public:  	virtual ~LBItem();  	void readFrom(Common::SeekableSubReadStreamEndian *stream); -	virtual void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); +	void readData(uint16 type, uint16 size, byte *data); +	virtual void readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream);  	virtual void destroySelf(); // 0x2  	virtual void setEnabled(bool enabled); // 0x3 @@ -430,7 +438,7 @@ protected:  	void runCommand(const Common::String &command);  	bool checkCondition(const Common::String &condition); -	LBScriptEntry *parseScriptEntry(uint16 type, uint16 &size, Common::SeekableSubReadStreamEndian *stream, bool isSubentry = false); +	LBScriptEntry *parseScriptEntry(uint16 type, uint16 &size, Common::MemoryReadStreamEndian *stream, bool isSubentry = false);  };  class LBSoundItem : public LBItem { @@ -455,7 +463,7 @@ class LBGroupItem : public LBItem {  public:  	LBGroupItem(MohawkEngine_LivingBooks *_vm, LBPage *page, Common::Rect rect); -	void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); +	void readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream);  	void destroySelf();  	void setEnabled(bool enabled); @@ -480,7 +488,7 @@ public:  	LBPaletteItem(MohawkEngine_LivingBooks *_vm, LBPage *page, Common::Rect rect);  	~LBPaletteItem(); -	void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); +	void readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream);  	bool togglePlaying(bool playing, bool restart);  	void update(); @@ -506,7 +514,7 @@ class LBLiveTextItem : public LBItem {  public:  	LBLiveTextItem(MohawkEngine_LivingBooks *_vm, LBPage *page, Common::Rect rect); -	void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); +	void readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream);  	bool contains(Common::Point point);  	void update(); @@ -535,7 +543,7 @@ class LBPictureItem : public LBItem {  public:  	LBPictureItem(MohawkEngine_LivingBooks *_vm, LBPage *page, Common::Rect rect); -	void readData(uint16 type, uint16 size, Common::SeekableSubReadStreamEndian *stream); +	void readData(uint16 type, uint16 size, Common::MemoryReadStreamEndian *stream);  	bool contains(Common::Point point);  	void draw();  | 
