diff --git a/engines/stark/console.cpp b/engines/stark/console.cpp index d8f8e61f03b..2e4b7ba0f48 100644 --- a/engines/stark/console.cpp +++ b/engines/stark/console.cpp @@ -116,32 +116,55 @@ bool Console::Cmd_DumpArchive(int argc, const char **argv) { } bool Console::Cmd_DumpRoot(int argc, const char **argv) { - StarkGlobal->getRoot()->print(); + Resources::Root *root = StarkGlobal->getRoot(); + if (root) { + root->print(); + } else { + debugPrintf("The global root has not been loaded\n"); + } return true; } bool Console::Cmd_DumpGlobal(int argc, const char **argv) { - StarkGlobal->getLevel()->print(); + Resources::Level *level = StarkGlobal->getLevel(); + if (level) { + level->print(); + } else { + debugPrintf("The global level has not been loaded\n"); + } return true; } bool Console::Cmd_DumpStatic(int argc, const char **argv) { + // Static resources are initialized in the beginning of the running StarkStaticProvider->getLevel()->print(); return true; } bool Console::Cmd_DumpLevel(int argc, const char **argv) { - StarkGlobal->getCurrent()->getLevel()->print(); + Current *current = StarkGlobal->getCurrent(); + if (current) { + current->getLevel()->print(); + } else { + debugPrintf("Game levels have not been loaded\n"); + } return true; } bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { - Resources::Level *level = StarkGlobal->getCurrent()->getLevel(); - Resources::Location *location = StarkGlobal->getCurrent()->getLocation(); + Current *current = StarkGlobal->getCurrent(); + + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + + Resources::Level *level = current->getLevel(); + Resources::Location *location = current->getLocation(); Common::Array knowledge = level->listChildrenRecursive(); knowledge.insert_at(knowledge.size(), location->listChildrenRecursive()); Common::Array::iterator it; @@ -152,6 +175,13 @@ bool Console::Cmd_DumpKnowledge(int argc, const char **argv) { } bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) { + Current *current = StarkGlobal->getCurrent(); + + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + uint index = 0; char type = 0; @@ -159,8 +189,8 @@ bool Console::Cmd_ChangeKnowledge(int argc, const char **argv) { index = atoi(argv[1]); type = argv[2][0]; if (type == 'b' || type == 'i') { - Resources::Level *level = StarkGlobal->getCurrent()->getLevel(); - Resources::Location *location = StarkGlobal->getCurrent()->getLocation(); + Resources::Level *level = current->getLevel(); + Resources::Location *location = current->getLocation(); Common::Array knowledgeArr = level->listChildrenRecursive(); knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive()); if (index < knowledgeArr.size() ) { @@ -200,6 +230,12 @@ Common::Array Console::listAllLocationScripts() const { } bool Console::Cmd_ListScripts(int argc, const char **argv) { + Current *current = StarkGlobal->getCurrent(); + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + Common::Array scripts = listAllLocationScripts(); for (uint i = 0; i < scripts.size(); i++) { @@ -224,6 +260,12 @@ bool Console::Cmd_ListScripts(int argc, const char **argv) { } bool Console::Cmd_EnableScript(int argc, const char **argv) { + Current *current = StarkGlobal->getCurrent(); + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + uint index = 0; if (argc >= 2) { @@ -253,6 +295,12 @@ bool Console::Cmd_EnableScript(int argc, const char **argv) { } bool Console::Cmd_ForceScript(int argc, const char **argv) { + Current *current = StarkGlobal->getCurrent(); + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + uint index = 0; if (argc >= 2) { @@ -279,6 +327,12 @@ bool Console::Cmd_ForceScript(int argc, const char **argv) { } bool Console::Cmd_DecompileScript(int argc, const char **argv) { + Current *current = StarkGlobal->getCurrent(); + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + if (argc >= 2) { uint index = atoi(argv[1]); @@ -400,27 +454,44 @@ void Console::decompileScriptChildren(Resources::Object *level) { bool Console::Cmd_DumpLocation(int argc, const char **argv) { if (StarkStaticProvider->isStaticLocation()) { StarkStaticProvider->getLocation()->print(); + return true; + } + + Current *current = StarkGlobal->getCurrent(); + if (current) { + current->getLocation()->print(); } else { - StarkGlobal->getCurrent()->getLocation()->print(); + debugPrintf("Locations have not been loaded\n"); } return true; } bool Console::Cmd_ListInventory(int argc, const char **argv) { - StarkGlobal->printInventory(argc != 2); + if (StarkGlobal->getInventory()) { + StarkGlobal->printInventory(argc != 2); + } else { + debugPrintf("The inventory has not been loaded\n"); + } return true; } bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) { + if (!StarkGlobal->getInventory()) { + debugPrintf("The inventory has not been loaded\n"); + return true; + } + if (argc != 2) { debugPrintf("Enable a specific inventory item. Use listInventory to get an id\n"); debugPrintf("Usage :\n"); debugPrintf("enableInventoryItem [id]\n"); return true; } + StarkGlobal->enableInventoryItem(atoi(argv[1])); + return true; } @@ -471,6 +542,11 @@ bool Console::Cmd_ListLocations(int argc, const char **argv) { } bool Console::Cmd_ChangeLocation(int argc, const char **argv) { + if (!StarkGlobal->getRoot()) { + debugPrintf("The global root has not been loaded\n"); + return true; + } + if (argc != 3) { debugPrintf("Change the current location. Use listLocations to get ids\n"); debugPrintf("Usage :\n"); @@ -487,6 +563,11 @@ bool Console::Cmd_ChangeLocation(int argc, const char **argv) { } bool Console::Cmd_ChangeChapter(int argc, const char **argv) { + if (!StarkGlobal->getLevel()) { + debugPrintf("The global level has not been loaded\n"); + return true; + } + if (argc != 2) { debugPrintf("Change the current chapter\n"); debugPrintf("Usage :\n"); @@ -502,6 +583,13 @@ bool Console::Cmd_ChangeChapter(int argc, const char **argv) { } bool Console::Cmd_Location(int argc, const char **argv) { + Current *current = StarkGlobal->getCurrent(); + + if (!current) { + debugPrintf("Game levels have not been loaded\n"); + return true; + } + if (argc != 1) { debugPrintf("Display the current location\n"); debugPrintf("Usage :\n"); @@ -509,14 +597,17 @@ bool Console::Cmd_Location(int argc, const char **argv) { return true; } - Current *current = StarkGlobal->getCurrent(); - debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex()); return true; } bool Console::Cmd_Chapter(int argc, const char **argv) { + if (!StarkGlobal->getLevel()) { + debugPrintf("The global level has not been loaded\n"); + return true; + } + if (argc != 1) { debugPrintf("Display the current chapter\n"); debugPrintf("Usage :\n");