RivenScriptList RivenScriptManager::readScripts(Common::ReadStream *stream) { RivenScriptList scriptList; uint16 scriptCount = stream->readUint16BE(); for (uint16 i = 0; i < scriptCount; i++) { RivenTypedScript script; script.type = stream->readUint16BE(); script.script = readScript(stream); scriptList.push_back(script); } return scriptList; }
bool RivenConsole::Cmd_DumpScript(int argc, const char **argv) { if (argc < 4) { DebugPrintf("Usage: dumpScript <stack> <CARD or HSPT> <card>\n"); return true; } uint16 oldStack = _vm->getCurStack(); byte newStack = 0; for (byte i = 1; i <= tspit + 1; i++) if (!scumm_stricmp(argv[1], _vm->getStackName(i - 1).c_str())) { newStack = i; break; } if (!newStack) { DebugPrintf("\'%s\' is not a stack name!\n", argv[1]); return true; } newStack--; _vm->changeToStack(newStack); // Load in Variable Names Common::SeekableReadStream *nameStream = _vm->getResource(ID_NAME, VariableNames); Common::StringArray varNames; uint16 namesCount = nameStream->readUint16BE(); uint16 *stringOffsets = new uint16[namesCount]; for (uint16 i = 0; i < namesCount; i++) stringOffsets[i] = nameStream->readUint16BE(); nameStream->seek(namesCount * 2, SEEK_CUR); int32 curNamesPos = nameStream->pos(); for (uint32 i = 0; i < namesCount; i++) { nameStream->seek(curNamesPos + stringOffsets[i]); Common::String name; for (char c = nameStream->readByte(); c; c = nameStream->readByte()) name += c; varNames.push_back(name); } delete nameStream; // Load in External Command Names nameStream = _vm->getResource(ID_NAME, ExternalCommandNames); Common::StringArray xNames; namesCount = nameStream->readUint16BE(); stringOffsets = new uint16[namesCount]; for (uint16 i = 0; i < namesCount; i++) stringOffsets[i] = nameStream->readUint16BE(); nameStream->seek(namesCount * 2, SEEK_CUR); curNamesPos = nameStream->pos(); for (uint32 i = 0; i < namesCount; i++) { nameStream->seek(curNamesPos + stringOffsets[i]); Common::String name; for (char c = nameStream->readByte(); c; c = nameStream->readByte()) name += c; xNames.push_back(name); } delete nameStream; // Get CARD/HSPT data and dump their scripts if (!scumm_stricmp(argv[2], "CARD")) { // Use debugN to print these because the scripts can get very large and would // really be useless if the the text console is not used. A DumpFile could also // theoretically be used, but I (clone2727) typically use this dynamically and // don't want countless files laying around without game context. If one would // want a file of a script they could just redirect stdout to a file or use // deriven. debugN("\n\nDumping scripts for %s\'s card %d!\n", argv[1], (uint16)atoi(argv[3])); debugN("==================================\n\n"); Common::SeekableReadStream *cardStream = _vm->getResource(MKTAG('C','A','R','D'), (uint16)atoi(argv[3])); cardStream->seek(4); RivenScriptList scriptList = _vm->_scriptMan->readScripts(cardStream, false); for (uint32 i = 0; i < scriptList.size(); i++) { scriptList[i]->dumpScript(varNames, xNames, 0); delete scriptList[i]; } delete cardStream; } else if (!scumm_stricmp(argv[2], "HSPT")) { // See above for why this is printed via debugN debugN("\n\nDumping scripts for %s\'s card %d hotspots!\n", argv[1], (uint16)atoi(argv[3])); debugN("===========================================\n\n"); Common::SeekableReadStream *hsptStream = _vm->getResource(MKTAG('H','S','P','T'), (uint16)atoi(argv[3])); uint16 hotspotCount = hsptStream->readUint16BE(); for (uint16 i = 0; i < hotspotCount; i++) { debugN("Hotspot %d:\n", i); hsptStream->seek(22, SEEK_CUR); // Skip non-script related stuff RivenScriptList scriptList = _vm->_scriptMan->readScripts(hsptStream, false); for (uint32 j = 0; j < scriptList.size(); j++) { scriptList[j]->dumpScript(varNames, xNames, 1); delete scriptList[j]; } } delete hsptStream; } else { DebugPrintf("%s doesn't have any scripts!\n", argv[2]); } // See above for why this is printed via debugN debugN("\n\n"); _vm->changeToStack(oldStack); DebugPrintf("Script 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"); return true; } uint16 oldStack = _vm->getStack()->getId(); uint newStack = RivenStacks::getId(argv[1]); if (newStack == kStackUnknown) { debugPrintf("\'%s\' is not a stack name!\n", argv[1]); return true; } _vm->changeToStack(newStack); // Get CARD/HSPT data and dump their scripts if (!scumm_stricmp(argv[2], "CARD")) { // Use debugN to print these because the scripts can get very large and would // really be useless if the the text console is not used. A DumpFile could also // theoretically be used, but I (clone2727) typically use this dynamically and // don't want countless files laying around without game context. If one would // want a file of a script they could just redirect stdout to a file or use // deriven. debugN("\n\nDumping scripts for %s\'s card %d!\n", argv[1], (uint16)atoi(argv[3])); debugN("==================================\n\n"); Common::SeekableReadStream *cardStream = _vm->getResource(MKTAG('C','A','R','D'), (uint16)atoi(argv[3])); cardStream->seek(4); RivenScriptList scriptList = _vm->_scriptMan->readScripts(cardStream); for (uint32 i = 0; i < scriptList.size(); i++) { debugN("Stream Type %d:\n", scriptList[i].type); scriptList[i].script->dumpScript(0); } delete cardStream; } else if (!scumm_stricmp(argv[2], "HSPT")) { // See above for why this is printed via debugN debugN("\n\nDumping scripts for %s\'s card %d hotspots!\n", argv[1], (uint16)atoi(argv[3])); debugN("===========================================\n\n"); Common::SeekableReadStream *hsptStream = _vm->getResource(MKTAG('H','S','P','T'), (uint16)atoi(argv[3])); uint16 hotspotCount = hsptStream->readUint16BE(); for (uint16 i = 0; i < hotspotCount; i++) { debugN("Hotspot %d:\n", i); hsptStream->seek(22, SEEK_CUR); // Skip non-script related stuff RivenScriptList scriptList = _vm->_scriptMan->readScripts(hsptStream); for (uint32 j = 0; j < scriptList.size(); j++) { debugN("\tStream Type %d:\n", scriptList[j].type); scriptList[j].script->dumpScript(1); } } delete hsptStream; } else { debugPrintf("%s doesn't have any scripts!\n", argv[2]); } // See above for why this is printed via debugN debugN("\n\n"); _vm->changeToStack(oldStack); debugPrintf("Script dump complete.\n"); return true; }