[Scummvm-cvs-logs] scummvm master -> ede71596ba43c777d13201757c974aa22fd0e8ec
fuzzie
fuzzie at fuzzie.org
Tue Jun 28 15:37:17 CEST 2011
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
c2319a3a81 MOHAWK: Make LB's readString/readRect more generic.
c2e9319fa8 MOHAWK: Handle kLBOpRunData properly.
ede71596ba MOHAWK: Better sanity checks in LB scripting.
Commit: c2319a3a81104deeaa1aaae2e5b22c8306ea4fa1
https://github.com/scummvm/scummvm/commit/c2319a3a81104deeaa1aaae2e5b22c8306ea4fa1
Author: Alyssa Milburn (fuzzie at fuzzie.org)
Date: 2011-06-28T06:28:26-07:00
Commit Message:
MOHAWK: Make LB's readString/readRect more generic.
Changed paths:
engines/mohawk/livingbooks.cpp
engines/mohawk/livingbooks.h
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp
index 397281f..64383f6 100644
--- a/engines/mohawk/livingbooks.cpp
+++ b/engines/mohawk/livingbooks.cpp
@@ -42,7 +42,7 @@
namespace Mohawk {
// read a null-terminated string from a stream
-Common::String MohawkEngine_LivingBooks::readString(Common::SeekableSubReadStreamEndian *stream) {
+Common::String MohawkEngine_LivingBooks::readString(Common::ReadStream *stream) {
Common::String ret;
while (!stream->eos()) {
byte in = stream->readByte();
@@ -54,7 +54,7 @@ Common::String MohawkEngine_LivingBooks::readString(Common::SeekableSubReadStrea
}
// read a rect from a stream
-Common::Rect MohawkEngine_LivingBooks::readRect(Common::SeekableSubReadStreamEndian *stream) {
+Common::Rect MohawkEngine_LivingBooks::readRect(Common::ReadStreamEndian *stream) {
Common::Rect rect;
// the V1 mac games have their rects in QuickDraw order
diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h
index 02fe34e..c39e7f4 100644
--- a/engines/mohawk/livingbooks.h
+++ b/engines/mohawk/livingbooks.h
@@ -655,8 +655,8 @@ public:
void addNotifyEvent(NotifyEvent event);
Common::SeekableSubReadStreamEndian *wrapStreamEndian(uint32 tag, uint16 id);
- Common::String readString(Common::SeekableSubReadStreamEndian *stream);
- Common::Rect readRect(Common::SeekableSubReadStreamEndian *stream);
+ Common::String readString(Common::ReadStream *stream);
+ Common::Rect readRect(Common::ReadStreamEndian *stream);
GUI::Debugger *getDebugger() { return _console; }
void addArchive(MohawkArchive *archive);
Commit: c2e9319fa8101051a7f2dc9fda747c76164cb6d9
https://github.com/scummvm/scummvm/commit/c2e9319fa8101051a7f2dc9fda747c76164cb6d9
Author: Alyssa Milburn (fuzzie at fuzzie.org)
Date: 2011-06-28T06:32:25-07:00
Commit Message:
MOHAWK: Handle kLBOpRunData properly.
Changed paths:
engines/mohawk/livingbooks.cpp
engines/mohawk/livingbooks.h
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp
index 64383f6..2e7f5e6 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 c39e7f4..02cf6c3 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();
Commit: ede71596ba43c777d13201757c974aa22fd0e8ec
https://github.com/scummvm/scummvm/commit/ede71596ba43c777d13201757c974aa22fd0e8ec
Author: Alyssa Milburn (fuzzie at fuzzie.org)
Date: 2011-06-28T06:34:09-07:00
Commit Message:
MOHAWK: Better sanity checks in LB scripting.
Changed paths:
engines/mohawk/livingbooks.cpp
engines/mohawk/livingbooks_code.cpp
diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp
index 2e7f5e6..248a9e6 100644
--- a/engines/mohawk/livingbooks.cpp
+++ b/engines/mohawk/livingbooks.cpp
@@ -2016,6 +2016,8 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Memor
if (targetingType == kTargetTypeCode)
error("encountered kTargetTypeCode");
+ if (size < 2)
+ error("not enough bytes (%d) reading special targeting", size);
uint16 count = stream->readUint16();
size -= 2;
@@ -2026,6 +2028,8 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Memor
Common::String target = _vm->readString(stream);
debug(4, "target '%s'", target.c_str());
entry->targets.push_back(target);
+ if (target.size() + 1 > size)
+ error("failed to read target (ran out of stream)");
size -= target.size() + 1;
}
entry->argc = entry->targets.size();
@@ -2134,6 +2138,8 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Memor
}
if (conditionTag == 1) {
+ if (!size)
+ error("failed to read condition (empty stream)");
Common::String condition = _vm->readString(stream);
if (condition.size() == 0) {
size--;
@@ -2148,6 +2154,8 @@ LBScriptEntry *LBItem::parseScriptEntry(uint16 type, uint16 &size, Common::Memor
entry->conditions.push_back(condition);
debug(4, "script entry condition '%s'", condition.c_str());
} else if (conditionTag == 2) {
+ if (size < 4)
+ error("expected more than %d bytes for conditionTag 2", size);
// FIXME
stream->skip(4);
size -= 4;
diff --git a/engines/mohawk/livingbooks_code.cpp b/engines/mohawk/livingbooks_code.cpp
index 8791fc4..e72318d 100644
--- a/engines/mohawk/livingbooks_code.cpp
+++ b/engines/mohawk/livingbooks_code.cpp
@@ -250,8 +250,10 @@ LBValue LBCode::runCode(byte terminator) {
parseStatement();
if (_stack.size())
result = _stack.pop();
- if (_currToken == terminator || _currToken == kTokenEndOfFile)
+ if (_currToken == terminator || _currToken == kTokenEndOfFile) {
+ debugN("\n");
break;
+ }
if (_currToken != kTokenEndOfStatement && _currToken != kTokenEndOfFile)
error("missing EOS (got %02x)", _currToken);
debugN("\n");
More information about the Scummvm-git-logs
mailing list