2014-09-21 17:09:55 +02:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* 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 2
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/console.h"
|
2015-01-03 07:39:54 +01:00
|
|
|
|
2015-01-14 18:10:09 +01:00
|
|
|
#include "engines/stark/formats/xarc.h"
|
2014-12-27 11:04:43 +01:00
|
|
|
#include "engines/stark/resources/resource.h"
|
2014-12-28 14:23:54 +01:00
|
|
|
#include "engines/stark/resources/level.h"
|
|
|
|
#include "engines/stark/resources/location.h"
|
|
|
|
#include "engines/stark/resources/root.h"
|
2015-01-11 10:39:24 +01:00
|
|
|
#include "engines/stark/services/archiveloader.h"
|
2015-01-11 10:47:52 +01:00
|
|
|
#include "engines/stark/services/global.h"
|
2015-01-11 10:39:24 +01:00
|
|
|
#include "engines/stark/services/resourceprovider.h"
|
2015-01-11 11:01:01 +01:00
|
|
|
#include "engines/stark/services/services.h"
|
2014-09-21 17:09:55 +02:00
|
|
|
|
|
|
|
#include "common/file.h"
|
|
|
|
|
|
|
|
namespace Stark {
|
|
|
|
|
2015-01-11 11:01:01 +01:00
|
|
|
Console::Console() : GUI::Debugger() {
|
2014-09-21 17:09:55 +02:00
|
|
|
registerCmd("dumpArchive", WRAP_METHOD(Console, Cmd_DumpArchive));
|
2015-01-05 07:27:24 +01:00
|
|
|
registerCmd("dumpGlobal", WRAP_METHOD(Console, Cmd_DumpGlobal));
|
|
|
|
registerCmd("dumpLevel", WRAP_METHOD(Console, Cmd_DumpLevel));
|
|
|
|
registerCmd("dumpLocation", WRAP_METHOD(Console, Cmd_DumpLocation));
|
2014-12-28 11:50:12 +01:00
|
|
|
registerCmd("listLocations", WRAP_METHOD(Console, Cmd_ListLocations));
|
2015-02-13 09:19:47 +01:00
|
|
|
registerCmd("location", WRAP_METHOD(Console, Cmd_Location));
|
|
|
|
registerCmd("chapter", WRAP_METHOD(Console, Cmd_Chapter));
|
2015-01-03 07:39:54 +01:00
|
|
|
registerCmd("changeLocation", WRAP_METHOD(Console, Cmd_ChangeLocation));
|
2015-02-13 09:19:47 +01:00
|
|
|
registerCmd("changeChapter", WRAP_METHOD(Console, Cmd_ChangeChapter));
|
2014-09-21 17:09:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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', must exist.\n");
|
|
|
|
debugPrintf("Usage :\n");
|
2014-10-05 19:25:00 +02:00
|
|
|
debugPrintf("dumpArchive [archive name]\n");
|
2014-09-21 17:09:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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::String fileName = Common::String::format("dump/%s", it->get()->getName().c_str());
|
|
|
|
|
|
|
|
// Open the output file
|
|
|
|
Common::DumpFile outFile;
|
|
|
|
if (!outFile.open(fileName)) {
|
2014-09-28 08:51:44 +02:00
|
|
|
debugPrintf("Unable to open file '%s' for writing\n", fileName.c_str());
|
2014-09-21 17:09:55 +02:00
|
|
|
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();
|
|
|
|
|
2014-09-28 08:51:44 +02:00
|
|
|
debugPrintf("Extracted '%s'\n", it->get()->getName().c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-05 07:27:24 +01:00
|
|
|
bool Console::Cmd_DumpGlobal(int argc, const char **argv) {
|
|
|
|
Global *global = StarkServices::instance().global;
|
2014-09-28 08:51:44 +02:00
|
|
|
|
2015-01-05 07:27:24 +01:00
|
|
|
global->getLevel()->print();
|
2014-12-28 11:50:12 +01:00
|
|
|
|
2015-01-05 07:27:24 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::Cmd_DumpLevel(int argc, const char **argv) {
|
|
|
|
Global *global = StarkServices::instance().global;
|
|
|
|
|
|
|
|
global->getCurrent()->getLevel()->print();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-28 08:51:44 +02:00
|
|
|
|
2015-01-05 07:27:24 +01:00
|
|
|
bool Console::Cmd_DumpLocation(int argc, const char **argv) {
|
|
|
|
Global *global = StarkServices::instance().global;
|
2014-12-28 11:50:12 +01:00
|
|
|
|
2015-01-05 07:27:24 +01:00
|
|
|
global->getCurrent()->getLocation()->print();
|
2014-10-05 19:25:00 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
bool Console::Cmd_ListLocations(int argc, const char **argv) {
|
|
|
|
ArchiveLoader *archiveLoader = new ArchiveLoader();
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
archiveLoader->load("x.xarc");
|
2014-12-28 14:23:54 +01:00
|
|
|
Root *root = archiveLoader->useRoot<Root>("x.xarc");
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 12:48:50 +01:00
|
|
|
// Find all the levels
|
2014-12-28 14:23:54 +01:00
|
|
|
Common::Array<Level *> levels = root->listChildren<Level>();
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 12:48:50 +01:00
|
|
|
// Loop over the levels
|
|
|
|
for (uint i = 0; i < levels.size(); i++) {
|
2014-12-28 14:23:54 +01:00
|
|
|
Level *level = levels[i];
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 14:23:54 +01:00
|
|
|
Common::String levelArchive = archiveLoader->buildArchiveName(level);
|
2014-10-05 19:25:00 +02:00
|
|
|
debugPrintf("%s - %s\n", levelArchive.c_str(), level->getName().c_str());
|
|
|
|
|
|
|
|
// Load the detailed level archive
|
2014-12-28 11:50:12 +01:00
|
|
|
archiveLoader->load(levelArchive);
|
2014-12-28 14:23:54 +01:00
|
|
|
level = archiveLoader->useRoot<Level>(levelArchive);
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 14:23:54 +01:00
|
|
|
Common::Array<Location *> locations = level->listChildren<Location>();
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
// Loop over the locations
|
2014-12-28 12:48:50 +01:00
|
|
|
for (uint j = 0; j < locations.size(); j++) {
|
2014-12-28 14:23:54 +01:00
|
|
|
Location *location = locations[j];
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-12-28 14:23:54 +01:00
|
|
|
Common::String roomArchive = archiveLoader->buildArchiveName(level, location);
|
2014-12-28 11:50:12 +01:00
|
|
|
debugPrintf("%s - %s\n", roomArchive.c_str(), location->getName().c_str());
|
2014-10-05 19:25:00 +02:00
|
|
|
}
|
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
archiveLoader->returnRoot(levelArchive);
|
|
|
|
archiveLoader->unloadUnused();
|
2014-10-05 19:25:00 +02:00
|
|
|
}
|
|
|
|
|
2014-12-28 11:50:12 +01:00
|
|
|
delete archiveLoader;
|
2014-10-05 19:25:00 +02:00
|
|
|
|
2014-09-21 17:09:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-03 07:39:54 +01:00
|
|
|
bool Console::Cmd_ChangeLocation(int argc, const char **argv) {
|
|
|
|
if (argc != 3) {
|
|
|
|
debugPrintf("Change the current location.\n");
|
|
|
|
debugPrintf("Usage :\n");
|
|
|
|
debugPrintf("changeLocation [level] [location]\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint levelIndex = strtol(argv[1] , nullptr, 16);
|
|
|
|
uint locationIndex = strtol(argv[2] , nullptr, 16);
|
|
|
|
|
|
|
|
ResourceProvider *resourceProvider = StarkServices::instance().resourceProvider;
|
|
|
|
resourceProvider->requestLocationChange(levelIndex, locationIndex);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-13 09:19:47 +01:00
|
|
|
bool Console::Cmd_ChangeChapter(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Change the current chapter.\n");
|
|
|
|
debugPrintf("Usage :\n");
|
|
|
|
debugPrintf("changeChapter [value]\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 value = atoi(argv[1]);
|
|
|
|
|
|
|
|
Global *global = StarkServices::instance().global;
|
|
|
|
global->setCurrentChapter(value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::Cmd_Location(int argc, const char **argv) {
|
|
|
|
if (argc != 1) {
|
|
|
|
debugPrintf("Display the current location.\n");
|
|
|
|
debugPrintf("Usage :\n");
|
|
|
|
debugPrintf("location\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Global *global = StarkServices::instance().global;
|
|
|
|
Current *current = global->getCurrent();
|
|
|
|
|
|
|
|
debugPrintf("location: %02x %02x\n", current->getLevel()->getIndex(), current->getLocation()->getIndex());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Console::Cmd_Chapter(int argc, const char **argv) {
|
|
|
|
if (argc != 1) {
|
|
|
|
debugPrintf("Display the current chapter.\n");
|
|
|
|
debugPrintf("Usage :\n");
|
|
|
|
debugPrintf("chapter\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Global *global = StarkServices::instance().global;
|
|
|
|
int32 value = global->getCurrentChapter();
|
|
|
|
|
|
|
|
debugPrintf("chapter: %d\n", value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-09-21 17:09:55 +02:00
|
|
|
} // End of namespace Stark
|