1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "engines/stark/console.h"
#include "engines/stark/formats/xarc.h"
#include "engines/stark/resources/object.h"
#include "engines/stark/resources/anim.h"
#include "engines/stark/resources/level.h"
#include "engines/stark/resources/location.h"
#include "engines/stark/resources/knowledge.h"
#include "engines/stark/resources/root.h"
#include "engines/stark/resources/script.h"
#include "engines/stark/resources/knowledgeset.h"
#include "engines/stark/resources/item.h"
#include "engines/stark/resources/textureset.h"
#include "engines/stark/services/archiveloader.h"
#include "engines/stark/services/dialogplayer.h"
#include "engines/stark/services/global.h"
#include "engines/stark/services/resourceprovider.h"
#include "engines/stark/services/userinterface.h"
#include "engines/stark/services/services.h"
#include "engines/stark/services/staticprovider.h"
#include "engines/stark/tools/decompiler.h"
#include "common/file.h"
namespace Stark {
Console::Console() :
GUI::Debugger() {
registerCmd("dumpArchive", WRAP_METHOD(Console, Cmd_DumpArchive));
registerCmd("dumpRoot", WRAP_METHOD(Console, Cmd_DumpRoot));
registerCmd("dumpStatic", WRAP_METHOD(Console, Cmd_DumpStatic));
registerCmd("dumpGlobal", WRAP_METHOD(Console, Cmd_DumpGlobal));
registerCmd("dumpLevel", WRAP_METHOD(Console, Cmd_DumpLevel));
registerCmd("dumpKnowledge", WRAP_METHOD(Console, Cmd_DumpKnowledge));
registerCmd("dumpLocation", WRAP_METHOD(Console, Cmd_DumpLocation));
registerCmd("listScripts", WRAP_METHOD(Console, Cmd_ListScripts));
registerCmd("enableScript", WRAP_METHOD(Console, Cmd_EnableScript));
registerCmd("forceScript", WRAP_METHOD(Console, Cmd_ForceScript));
registerCmd("decompileScript", WRAP_METHOD(Console, Cmd_DecompileScript));
registerCmd("testDecompiler", WRAP_METHOD(Console, Cmd_TestDecompiler));
registerCmd("listAnimations", WRAP_METHOD(Console, Cmd_ListAnimations));
registerCmd("forceAnimation", WRAP_METHOD(Console, Cmd_ForceAnimation));
registerCmd("listInventoryItems", WRAP_METHOD(Console, Cmd_ListInventoryItems));
registerCmd("listLocations", WRAP_METHOD(Console, Cmd_ListLocations));
registerCmd("location", WRAP_METHOD(Console, Cmd_Location));
registerCmd("chapter", WRAP_METHOD(Console, Cmd_Chapter));
registerCmd("changeLocation", WRAP_METHOD(Console, Cmd_ChangeLocation));
registerCmd("changeChapter", WRAP_METHOD(Console, Cmd_ChangeChapter));
registerCmd("changeKnowledge", WRAP_METHOD(Console, Cmd_ChangeKnowledge));
registerCmd("enableInventoryItem", WRAP_METHOD(Console, Cmd_EnableInventoryItem));
registerCmd("extractAllTextures", WRAP_METHOD(Console, Cmd_ExtractAllTextures));
}
Console::~Console() {
}
bool Console::Cmd_DumpArchive(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Extract all the files from a game archive\n");
debugPrintf("The destination folder, named 'dump', is in the location ScummVM was launched from\n");
debugPrintf("Usage :\n");
debugPrintf("dumpArchive [path to archive]\n");
return true;
}
Formats::XARCArchive xarc;
if (!xarc.open(argv[1])) {
debugPrintf("Can't open archive with name '%s'\n", argv[1]);
return true;
}
Common::ArchiveMemberList members;
xarc.listMembers(members);
for (Common::ArchiveMemberList::const_iterator it = members.begin(); it != members.end(); it++) {
Common::Path fileName(Common::String::format("dump/%s", it->get()->getName().c_str()));
// Open the output file
Common::DumpFile outFile;
if (!outFile.open(fileName, true)) {
debugPrintf("Unable to open file '%s' for writing\n", fileName.toString().c_str());
return true;
}
// Copy the archive content to the output file using a temporary buffer
Common::SeekableReadStream *inStream = it->get()->createReadStream();
uint8 *buf = new uint8[inStream->size()];
inStream->read(buf, inStream->size());
outFile.write(buf, inStream->size());
delete[] buf;
delete inStream;
outFile.close();
debugPrintf("Extracted '%s'\n", it->get()->getName().c_str());
}
return true;
}
bool Console::Cmd_DumpRoot(int argc, const char **argv) {
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) {
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) {
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) {
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<Resources::Knowledge *> knowledge = level->listChildrenRecursive<Resources::Knowledge>();
knowledge.insert_at(knowledge.size(), location->listChildrenRecursive<Resources::Knowledge>());
Common::Array<Resources::Knowledge *>::iterator it;
for (it = knowledge.begin(); it != knowledge.end(); ++it) {
(*it)->print();
}
return true;
}
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;
if (argc >= 4) {
index = atoi(argv[1]);
type = argv[2][0];
if (type == 'b' || type == 'i') {
Resources::Level *level = current->getLevel();
Resources::Location *location = current->getLocation();
Common::Array<Resources::Knowledge *> knowledgeArr = level->listChildrenRecursive<Resources::Knowledge>();
knowledgeArr.insert_at(knowledgeArr.size(), location->listChildrenRecursive<Resources::Knowledge>());
if (index < knowledgeArr.size() ) {
Resources::Knowledge *knowledge = knowledgeArr[index];
if (type == 'b') {
knowledge->setBooleanValue(atoi(argv[3]));
} else if (type == 'i') {
knowledge->setIntegerValue(atoi(argv[3]));
}
return true;
} else {
debugPrintf("Invalid index %d, only %d indices available\n", index, knowledgeArr.size());
}
} else {
debugPrintf("Invalid type: %c, only b and i are available\n", type);
}
} else if (argc > 1 ) {
debugPrintf("Too few args\n");
}
debugPrintf("Change the value of some knowledge. Use dumpKnowledge to get an id\n");
debugPrintf("Usage :\n");
debugPrintf("changeKnowledge [id] [type] [value]\n");
debugPrintf("available types: b(inary), i(nteger)\n");
return true;
}
Common::Array<Resources::Script *> Console::listAllLocationScripts() const {
Common::Array<Resources::Script *> scripts;
Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
scripts.push_back(level->listChildrenRecursive<Resources::Script>());
scripts.push_back(location->listChildrenRecursive<Resources::Script>());
return scripts;
}
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<Resources::Script *> scripts = listAllLocationScripts();
for (uint i = 0; i < scripts.size(); i++) {
Resources::Script *script = scripts[i];
debugPrintf("%d: %s - enabled: %d", i, script->getName().c_str(), script->isEnabled());
// Print which resource is causing the script to wait
if (script->isSuspended()) {
Resources::Object *suspending = script->getSuspendingResource();
if (suspending) {
debugPrintf(", waiting for: %s (%s)", suspending->getName().c_str(), suspending->getType().getName());
} else {
debugPrintf(", paused");
}
}
debugPrintf("\n");
}
return true;
}
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) {
index = atoi(argv[1]);
bool value = true;
if (argc >= 3) {
value = atoi(argv[2]);
}
Common::Array<Resources::Script *> scripts = listAllLocationScripts();
if (index < scripts.size() ) {
Resources::Script *script = scripts[index];
script->enable(value);
return true;
} else {
debugPrintf("Invalid index %d, only %d indices available\n", index, scripts.size());
}
}
debugPrintf("Enable or disable a script. Use listScripts to get an id\n");
debugPrintf("Usage :\n");
debugPrintf("enableScript [id] (value)\n");
return true;
}
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) {
index = atoi(argv[1]);
Common::Array<Resources::Script *> scripts = listAllLocationScripts();
if (index < scripts.size() ) {
Resources::Script *script = scripts[index];
script->enable(true);
script->goToNextCommand(); // Skip the begin command to avoid checks
script->execute(Resources::Script::kCallModePlayerAction);
return true;
} else {
debugPrintf("Invalid index %d, only %d indices available\n", index, scripts.size());
}
}
debugPrintf("Force the execution of a script. Use listScripts to get an id\n");
debugPrintf("Usage :\n");
debugPrintf("forceScript [id]\n");
return true;
}
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]);
Common::Array<Resources::Script *> scripts = listAllLocationScripts();
if (index < scripts.size()) {
Resources::Script *script = scripts[index];
Tools::Decompiler *decompiler = new Tools::Decompiler(script);
if (decompiler->getError() != "") {
debugPrintf("Decompilation failure: %s\n", decompiler->getError().c_str());
}
debug("Script %d - %s:", index, script->getName().c_str());
decompiler->printDecompiled();
delete decompiler;
return true;
} else {
debugPrintf("Invalid index %d, only %d indices available\n", index, scripts.size());
}
}
debugPrintf("Decompile a script. Use listScripts to get an id\n");
debugPrintf("Usage :\n");
debugPrintf("decompileScript [id]\n");
return true;
}
class ArchiveVisitor {
public:
virtual ~ArchiveVisitor() {}
virtual void acceptLevelArchive(Resources::Level *level) = 0;
virtual void acceptLocationArchive(Resources::Location *location) = 0;
};
void Console::walkAllArchives(ArchiveVisitor *visitor) {
ArchiveLoader *archiveLoader = new ArchiveLoader();
// Temporarily replace the global archive loader with our instance
ArchiveLoader *gameArchiveLoader = StarkArchiveLoader;
StarkArchiveLoader = archiveLoader;
archiveLoader->load("x.xarc");
Resources::Root *root = archiveLoader->useRoot<Resources::Root>("x.xarc");
// Find all the levels
Common::Array<Resources::Level *> levels = root->listChildren<Resources::Level>();
// Loop over the levels
for (uint i = 0; i < levels.size(); i++) {
Resources::Level *level = levels[i];
Common::Path levelArchive = archiveLoader->buildArchiveName(level);
debug("%s - %s", levelArchive.toString(Common::Path::kNativeSeparator).c_str(), level->getName().c_str());
// Load the detailed level archive
archiveLoader->load(levelArchive);
level = archiveLoader->useRoot<Resources::Level>(levelArchive);
// Visit the level archive
visitor->acceptLevelArchive(level);
Common::Array<Resources::Location *> locations = level->listChildren<Resources::Location>();
// Loop over the locations
for (uint j = 0; j < locations.size(); j++) {
Resources::Location *location = locations[j];
Common::Path locationArchive = archiveLoader->buildArchiveName(level, location);
debug("%s - %s", locationArchive.toString(Common::Path::kNativeSeparator).c_str(), location->getName().c_str());
// Load the detailed location archive
archiveLoader->load(locationArchive);
location = archiveLoader->useRoot<Resources::Location>(locationArchive);
// Visit the location archive
visitor->acceptLocationArchive(location);
archiveLoader->returnRoot(locationArchive);
archiveLoader->unloadUnused();
}
archiveLoader->returnRoot(levelArchive);
archiveLoader->unloadUnused();
}
// Restore the global archive loader
StarkArchiveLoader = gameArchiveLoader;
delete archiveLoader;
}
class DecompilingArchiveVisitor : public ArchiveVisitor {
public:
DecompilingArchiveVisitor() :
_totalScripts(0),
_okScripts(0) {}
void acceptLevelArchive(Resources::Level *level) override {
decompileScriptChildren(level);
}
void acceptLocationArchive(Resources::Location *location) override {
decompileScriptChildren(location);
}
int getTotalScripts() const { return _totalScripts; }
int getOKScripts() const { return _okScripts; }
private:
int _totalScripts;
int _okScripts;
void decompileScriptChildren(Resources::Object *resource) {
Common::Array<Resources::Script *> scripts = resource->listChildrenRecursive<Resources::Script>();
for (uint i = 0; i < scripts.size(); i++) {
Resources::Script *script = scripts[i];
Tools::Decompiler decompiler(script);
_totalScripts++;
Common::String result;
if (decompiler.getError() == "") {
result = "OK";
_okScripts++;
} else {
result = decompiler.getError();
}
debug("%d - %s: %s", script->getIndex(), script->getName().c_str(), result.c_str());
}
}
};
bool Console::Cmd_TestDecompiler(int argc, const char **argv) {
DecompilingArchiveVisitor visitor;
walkAllArchives(&visitor);
debugPrintf("Successfully decompiled %d scripts out of %d\n", visitor.getOKScripts(), visitor.getTotalScripts());
return true;
}
class TextureExtractingArchiveVisitor : public ArchiveVisitor {
public:
void acceptLevelArchive(Resources::Level *level) override {
decompileScriptChildren(level);
}
void acceptLocationArchive(Resources::Location *location) override {
decompileScriptChildren(location);
}
private:
void decompileScriptChildren(Resources::Object *resource) {
Common::Array<Resources::TextureSet *> textureSets = resource->listChildrenRecursive<Resources::TextureSet>();
for (uint i = 0; i < textureSets.size(); i++) {
Resources::TextureSet *textureSet = textureSets[i];
textureSet->extractArchive();
}
}
};
bool Console::Cmd_ExtractAllTextures(int argc, const char **argv) {
TextureExtractingArchiveVisitor visitor;
walkAllArchives(&visitor);
return true;
}
Common::Array<Resources::Anim *> Console::listAllLocationAnimations() const {
Common::Array<Resources::Anim *> animations;
Resources::Level *level = StarkGlobal->getCurrent()->getLevel();
Resources::Location *location = StarkGlobal->getCurrent()->getLocation();
animations.push_back(level->listChildrenRecursive<Resources::Anim>());
animations.push_back(location->listChildrenRecursive<Resources::Anim>());
return animations;
}
bool Console::Cmd_ListAnimations(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("This command is only available in game.\n");
return true;
}
Common::Array<Resources::Anim *> animations = listAllLocationAnimations();
for (uint i = 0; i < animations.size(); i++) {
Resources::Anim *anim = animations[i];
Resources::Item *item = anim->findParent<Resources::Item>();
debugPrintf("%d: %s - %s - in use: %d\n", i, item->getName().c_str(), anim->getName().c_str(), anim->isInUse());
}
return true;
}
bool Console::Cmd_ForceAnimation(int argc, const char **argv) {
Current *current = StarkGlobal->getCurrent();
if (!current) {
debugPrintf("This command is only available in game.\n");
return true;
}
if (argc < 2) {
debugPrintf("Force the execution of an animation. Use listAnimations to get an id\n");
debugPrintf("Usage :\n");
debugPrintf("forceAnimation [id]\n");
return true;
}
uint index = atoi(argv[1]);
Common::Array<Resources::Anim *> animations = listAllLocationAnimations();
if (index >= animations.size() ) {
debugPrintf("Invalid animation %d\n", index);
return true;
}
Resources::Anim *anim = animations[index];
Resources::Item *item = anim->findParent<Resources::Item>();
Resources::ItemVisual *sceneItem = item->getSceneInstance();
if (!sceneItem->isEnabled()) {
sceneItem->setEnabled(true);
}
sceneItem->playActionAnim(anim);
return false;
}
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 {
debugPrintf("Locations have not been loaded\n");
}
return true;
}
bool Console::Cmd_ListInventoryItems(int argc, const char **argv) {
Resources::KnowledgeSet *inventory = StarkGlobal->getInventory();
if (!inventory) {
debugPrintf("The inventory has not been loaded\n");
return true;
}
Common::Array<Resources::Item*> inventoryItems = inventory->listChildren<Resources::Item>(Resources::Item::kItemInventory);
Common::Array<Resources::Item*>::iterator it = inventoryItems.begin();
for (int i = 0; it != inventoryItems.end(); ++it, i++) {
debugPrintf("Item %d: %s%s\n", i, (*it)->getName().c_str(), (*it)->isEnabled() ? " (enabled)" : "");
}
return true;
}
bool Console::Cmd_EnableInventoryItem(int argc, const char **argv) {
Resources::KnowledgeSet *inventory = StarkGlobal->getInventory();
if (!inventory) {
debugPrintf("The inventory has not been loaded\n");
return true;
}
if (argc != 2) {
debugPrintf("Enable a specific inventory item. Use listInventoryItems to get an id\n");
debugPrintf("Usage :\n");
debugPrintf("enableInventoryItem [id]\n");
return true;
}
uint num = atoi(argv[1]);
Common::Array<Resources::Item*> inventoryItems = inventory->listChildren<Resources::Item>(Resources::Item::kItemInventory);
if (num < inventoryItems.size()) {
inventoryItems[num]->setEnabled(true);
} else {
debugPrintf("Invalid index %d, only %d indices available\n", num, inventoryItems.size());
}
return true;
}
bool Console::Cmd_ListLocations(int argc, const char **argv) {
ArchiveLoader *archiveLoader = new ArchiveLoader();
// Temporarily replace the global archive loader with our instance
ArchiveLoader *gameArchiveLoader = StarkArchiveLoader;
StarkArchiveLoader = archiveLoader;
archiveLoader->load("x.xarc");
Resources::Root *root = archiveLoader->useRoot<Resources::Root>("x.xarc");
// Find all the levels
Common::Array<Resources::Level *> levels = root->listChildren<Resources::Level>();
// Loop over the levels
for (uint i = 0; i < levels.size(); i++) {
Resources::Level *level = levels[i];
Common::Path levelArchive = archiveLoader->buildArchiveName(level);
debugPrintf("%s - %s\n", levelArchive.toString(Common::Path::kNativeSeparator).c_str(), level->getName().c_str());
// Load the detailed level archive
archiveLoader->load(levelArchive);
level = archiveLoader->useRoot<Resources::Level>(levelArchive);
Common::Array<Resources::Location *> locations = level->listChildren<Resources::Location>();
// Loop over the locations
for (uint j = 0; j < locations.size(); j++) {
Resources::Location *location = locations[j];
Common::Path roomArchive = archiveLoader->buildArchiveName(level, location);
debugPrintf("%s - %s\n", roomArchive.toString(Common::Path::kNativeSeparator).c_str(), location->getName().c_str());
}
archiveLoader->returnRoot(levelArchive);
archiveLoader->unloadUnused();
}
// Restore the global archive loader
StarkArchiveLoader = gameArchiveLoader;
delete archiveLoader;
return true;
}
bool Console::Cmd_ChangeLocation(int argc, const char **argv) {
if (argc >= 3) {
// Assert indices
Common::Path xarcFileName(Common::String::format("%s/%s/%s.xarc", argv[1], argv[2], argv[2]));
if (!Common::File::exists(xarcFileName)) {
debugPrintf("Invalid location %s %s. Use listLocations to get correct indices\n", argv[1], argv[2]);
return true;
}
uint levelIndex = strtol(argv[1] , nullptr, 16);
uint locationIndex = strtol(argv[2] , nullptr, 16);
StarkUserInterface->changeScreen(Screen::kScreenGame);
if (!StarkGlobal->getRoot()) {
StarkResourceProvider->initGlobal();
}
StarkResourceProvider->requestLocationChange(levelIndex, locationIndex);
return false;
} else if (argc > 1) {
debugPrintf("Too few args\n");
}
debugPrintf("Change the current location. Use listLocations to get indices\n");
debugPrintf("Usage :\n");
debugPrintf("changeLocation [level] [location]\n");
return true;
}
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");
debugPrintf("changeChapter [value]\n");
return true;
}
char *endPtr = nullptr;
long value = strtol(argv[1], &endPtr, 10);
if (*endPtr == '\0' && value >= 0 && value <= INT_MAX)
StarkGlobal->setCurrentChapter((int32) value);
else
debugPrintf("Invalid chapter\n");
return true;
}
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");
debugPrintf("location\n");
return true;
}
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");
debugPrintf("chapter\n");
return true;
}
int32 value = StarkGlobal->getCurrentChapter();
debugPrintf("chapter: %d\n", value);
return true;
}
} // End of namespace Stark
|