Skip to content

Commit

Permalink
MOHAWK: Add console commands to dump Riven cards and stacks to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK authored and sev- committed Jul 3, 2017
1 parent ab9b241 commit 9ab0d53
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 2 deletions.
28 changes: 28 additions & 0 deletions engines/mohawk/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,13 @@ bool MystConsole::Cmd_QuickTest(int argc, const char **argv) {
RivenConsole::RivenConsole(MohawkEngine_Riven *vm) : GUI::Debugger(), _vm(vm) {
registerCmd("changeCard", WRAP_METHOD(RivenConsole, Cmd_ChangeCard));
registerCmd("curCard", WRAP_METHOD(RivenConsole, Cmd_CurCard));
registerCmd("dumpCard", WRAP_METHOD(RivenConsole, Cmd_DumpCard));
registerCmd("var", WRAP_METHOD(RivenConsole, Cmd_Var));
registerCmd("playSound", WRAP_METHOD(RivenConsole, Cmd_PlaySound));
registerCmd("playSLST", WRAP_METHOD(RivenConsole, Cmd_PlaySLST));
registerCmd("stopSound", WRAP_METHOD(RivenConsole, Cmd_StopSound));
registerCmd("curStack", WRAP_METHOD(RivenConsole, Cmd_CurStack));
registerCmd("dumpStack", WRAP_METHOD(RivenConsole, Cmd_DumpStack));
registerCmd("changeStack", WRAP_METHOD(RivenConsole, Cmd_ChangeStack));
registerCmd("hotspots", WRAP_METHOD(RivenConsole, Cmd_Hotspots));
registerCmd("zipMode", WRAP_METHOD(RivenConsole, Cmd_ZipMode));
Expand Down Expand Up @@ -542,6 +544,32 @@ bool RivenConsole::Cmd_ZipMode(int argc, const char **argv) {
return true;
}

bool RivenConsole::Cmd_DumpCard(int argc, const char **argv) {
if (argc != 1) {
debugPrintf("Usage: dumpCard\n");
return true;
}

_vm->getCard()->dump();

debugPrintf("Card dump complete.\n");

return true;
}

bool RivenConsole::Cmd_DumpStack(int argc, const char **argv) {
if (argc != 1) {
debugPrintf("Usage: dumpStack\n");
return true;
}

_vm->getStack()->dump();

debugPrintf("Stack dump complete.\n");

return true;
}

bool RivenConsole::Cmd_DumpScript(int argc, const char **argv) {
if (argc < 4) {
debugPrintf("Usage: dumpScript <stack> <CARD or HSPT> <card>\n");
Expand Down
3 changes: 2 additions & 1 deletion engines/mohawk/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class RivenConsole : public GUI::Debugger {
bool Cmd_ChangeStack(int argc, const char **argv);
bool Cmd_Hotspots(int argc, const char **argv);
bool Cmd_ZipMode(int argc, const char **argv);
bool Cmd_RunAllBlocks(int argc, const char **argv);
bool Cmd_DumpCard(int argc, const char **argv);
bool Cmd_DumpStack(int argc, const char **argv);
bool Cmd_DumpScript(int argc, const char **argv);
bool Cmd_ListZipCards(int argc, const char **argv);
bool Cmd_GetRMAP(int argc, const char **argv);
Expand Down
82 changes: 82 additions & 0 deletions engines/mohawk/riven_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,69 @@ void RivenCard::setCurrentCardVariable() {
_vm->_vars["currentcardid"] = _id;
}

void RivenCard::dump() const {
debug("== Card ==");
debug("id: %d", _id);
if (_name >= 0) {
debug("name: %s", _vm->getStack()->getName(kCardNames, _name).c_str());
} else {
debug("name: [no name]");
}
debug("zipModePlace: %d", _zipModePlace);
debug("globalId: %x", _vm->getStack()->getCardGlobalId(_id));
debugN("\n");

for (uint i = 0; i < _scripts.size(); i++) {
debug("== Script %d ==", i);
debug("type: %s", RivenScript::getTypeName(_scripts[i].type));
_scripts[i].script->dumpScript(0);
debugN("\n");
}

for (uint i = 0; i < _hotspots.size(); i++) {
debug("== Hotspot %d ==", i);
_hotspots[i]->dump();
}

for (uint i = 0; i < _pictureList.size(); i++) {
const Common::Rect &rect = _pictureList[i].rect;
debug("== Picture %d ==", _pictureList[i].index);
debug("pictureId: %d", _pictureList[i].id);
debug("rect: (%d, %d, %d, %d)", rect.left, rect.top, rect.right, rect.bottom);
debugN("\n");
}

for (uint i = 0; i < _waterEffectList.size(); i++) {
debug("== Effect %d ==", _waterEffectList[i].index);
debug("sfxeId: %d", _waterEffectList[i].sfxeId);
debug("u0: %d", _waterEffectList[i].u0);
debugN("\n");
}

for (uint i = 0; i < _hotspotEnableList.size(); i++) {
debug("== Hotspot enable %d ==", _hotspotEnableList[i].index);
debug("hotspotId: %d", _hotspotEnableList[i].hotspotId);
debug("enabled: %d", _hotspotEnableList[i].enabled);
debugN("\n");
}

for (uint i = 0; i < _soundList.size(); i++) {
debug("== Ambient sound list %d ==", _soundList[i].index);
debug("globalVolume: %d", _soundList[i].globalVolume);
debug("fadeFlags: %d", _soundList[i].fadeFlags);
debug("loop: %d", _soundList[i].loop);
debug("suspend: %d", _soundList[i].suspend);
debug("u0: %d", _soundList[i].u0);
for (uint j = 0; j < _soundList[i].soundIds.size(); j++) {
debug("sound[%d].id: %d", j, _soundList[i].soundIds[j]);
debug("sound[%d].volume: %d", j, _soundList[i].volumes[j]);
debug("sound[%d].balance: %d", j, _soundList[i].balances[j]);
debug("sound[%d].u2: %d", j, _soundList[i].u2[j]);
}
debugN("\n");
}
}

RivenHotspot::RivenHotspot(MohawkEngine_Riven *vm, Common::ReadStream *stream) :
_vm(vm) {
loadFromStream(stream);
Expand Down Expand Up @@ -547,4 +610,23 @@ int16 RivenHotspot::getNameId() const {
return _nameResource;
}

void RivenHotspot::dump() const {
debug("index: %d", _index);
debug("blstId: %d", _blstID);
debug("name: %s", getName().c_str());
debug("rect: (%d, %d, %d, %d)", _rect.left, _rect.top, _rect.right, _rect.bottom);
debug("flags: %d", _flags);
debug("mouseCursor: %d", _mouseCursor);
debug("u0: %d", _u0);
debug("u1: %d", _u1);
debugN("\n");

for (uint i = 0; i < _scripts.size(); i++) {
debug("=== Hotspot script %d ===", i);
debug("type: %s", RivenScript::getTypeName(_scripts[i].type));
_scripts[i].script->dumpScript(0);
debugN("\n");
}
}

} // End of namespace Mohawk
6 changes: 6 additions & 0 deletions engines/mohawk/riven_card.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class RivenCard {
/** Frame update handler for mouse dragging */
void onMouseDragUpdate();

/** Write all of the card's data to standard output */
void dump() const;

private:
void loadCardResource(uint16 id);
void loadHotspots(uint16 id);
Expand Down Expand Up @@ -209,6 +212,9 @@ class RivenHotspot {
/** Get the hotspot's enable list id */
uint16 getBlstId() const;

/** Write all of the hotspot's data to standard output */
void dump() const;

private:
enum {
kFlagZip = 1,
Expand Down
19 changes: 19 additions & 0 deletions engines/mohawk/riven_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ RivenScript &RivenScript::operator+=(const RivenScript &other) {
return *this;
}

const char *RivenScript::getTypeName(uint16 type) {
static const char *names[] = {
"MouseDown",
"MouseDrag",
"MouseUp",
"MouseEnter",
"MouseInside",
"MouseLeave",
"CardLoad",
"CardLeave",
"CardUnknown",
"CardOpen",
"CardUpdate"
};

assert(type < ARRAYSIZE(names));
return names[type];
}

RivenScriptPtr &operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs) {
*lhs += *rhs;
return lhs;
Expand Down
3 changes: 3 additions & 0 deletions engines/mohawk/riven_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class RivenScript {
/** Append the commands of the other script to this script */
RivenScript &operator+=(const RivenScript &other);

/** Get a caption for a script type */
static const char *getTypeName(uint16 type);

private:
Common::Array<RivenCommand *> _commands;
bool _continueRunning;
Expand Down
21 changes: 20 additions & 1 deletion engines/mohawk/riven_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,32 @@ uint16 RivenStack::getCardStackId(uint32 globalId) const {
}

uint32 RivenStack::getCurrentCardGlobalId() const {
return _cardIdMap[_vm->getCard()->getId()];
return getCardGlobalId(_vm->getCard()->getId());
}

void RivenStack::setCurrentStackVariable() {
_vm->_vars["currentstackid"] = _id;
}

uint32 RivenStack::getCardGlobalId(uint16 cardId) const {
return _cardIdMap[cardId];
}

void RivenStack::dump() const {
debug("= Stack =");
debug("id: %d", _id);
debug("name: %s", _vm->getStackName(_id).c_str());
debugN("\n");

for (uint i = 0; i < _cardIdMap.size(); i++) {
if (!_vm->hasResource(ID_CARD, i)) continue;

RivenCard *card = new RivenCard(_vm, i);
card->dump();
delete card;
}
}

RivenNameList::RivenNameList() {

}
Expand Down
6 changes: 6 additions & 0 deletions engines/mohawk/riven_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class RivenStack {

/** Get the global id of the currently active card */
uint32 getCurrentCardGlobalId() const;

/** Get the global id of a card in the stack */
uint32 getCardGlobalId(uint16 cardId) const;

/** Write all of the stack's data including its cards to standard output */
void dump() const;
private:
void loadResourceNames();
void loadCardIdMap();
Expand Down

0 comments on commit 9ab0d53

Please sign in to comment.