scummvm/engines/myst3/console.cpp

409 lines
11 KiB
C++
Raw Normal View History

2012-01-10 20:41:51 +01:00
/* ResidualVM - A 3D game interpreter
*
2012-01-10 20:41:51 +01:00
* 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.
*
2012-01-05 10:07:48 +01:00
* 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.
2014-04-05 18:18:42 +02:00
*
2012-01-05 10:07:48 +01:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2012-01-05 10:07:48 +01:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
2014-04-05 18:18:42 +02:00
*
2012-01-05 10:07:48 +01:00
* 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/myst3/console.h"
2012-01-07 17:36:25 +01:00
#include "engines/myst3/database.h"
#include "engines/myst3/effects.h"
#include "engines/myst3/inventory.h"
#include "engines/myst3/script.h"
2012-01-13 08:47:32 +01:00
#include "engines/myst3/state.h"
namespace Myst3 {
Console::Console(Myst3Engine *vm) : GUI::Debugger(), _vm(vm) {
2014-07-02 01:02:35 +02:00
registerCmd("infos", WRAP_METHOD(Console, Cmd_Infos));
registerCmd("lookAt", WRAP_METHOD(Console, Cmd_LookAt));
registerCmd("initScript", WRAP_METHOD(Console, Cmd_InitScript));
registerCmd("var", WRAP_METHOD(Console, Cmd_Var));
registerCmd("listNodes", WRAP_METHOD(Console, Cmd_ListNodes));
registerCmd("run", WRAP_METHOD(Console, Cmd_Run));
registerCmd("runOp", WRAP_METHOD(Console, Cmd_RunOp));
registerCmd("go", WRAP_METHOD(Console, Cmd_Go));
registerCmd("extract", WRAP_METHOD(Console, Cmd_Extract));
registerCmd("fillInventory", WRAP_METHOD(Console, Cmd_FillInventory));
registerCmd("dumpArchive", WRAP_METHOD(Console, Cmd_DumpArchive));
registerCmd("dumpMasks", WRAP_METHOD(Console, Cmd_DumpMasks));
}
Console::~Console() {
}
2011-09-04 20:08:37 +02:00
void Console::describeScript(const Common::Array<Opcode> &script) {
2011-09-04 09:24:06 +02:00
for(uint j = 0; j < script.size(); j++) {
2014-07-02 01:02:35 +02:00
debugPrintf("%s", _vm->_scriptEngine->describeOpcode(script[j]).c_str());
2011-09-04 09:24:06 +02:00
}
2011-09-04 20:08:37 +02:00
}
bool Console::Cmd_Infos(int argc, const char **argv) {
2012-01-13 08:47:32 +01:00
uint16 nodeId = _vm->_state->getLocationNode();
uint32 roomId = _vm->_state->getLocationRoom();
2011-09-04 11:16:27 +02:00
if (argc >= 2) {
nodeId = atoi(argv[1]);
}
2011-09-04 20:08:37 +02:00
if (argc >= 3) {
roomId = _vm->_db->getRoomId(argv[2]);
if (roomId == 0) {
2014-07-02 01:02:35 +02:00
debugPrintf("Unknown room name %s\n", argv[2]);
return true;
}
2011-09-04 20:08:37 +02:00
}
NodePtr nodeData = _vm->_db->getNodeData(nodeId, roomId);
if (!nodeData) {
2014-07-02 01:02:35 +02:00
debugPrintf("No node with id %d\n", nodeId);
return true;
}
char roomName[8];
2011-09-04 20:08:37 +02:00
_vm->_db->getRoomName(roomName, roomId);
2014-07-02 01:02:35 +02:00
debugPrintf("node: %s %d ", roomName, nodeId);
for (uint i = 0; i < nodeData->scripts.size(); i++) {
2014-07-02 01:02:35 +02:00
debugPrintf("\ninit %d > %s (%s)\n", i,
_vm->_state->describeCondition(nodeData->scripts[i].condition).c_str(),
_vm->_state->evaluate(nodeData->scripts[i].condition) ? "true" : "false");
describeScript(nodeData->scripts[i].script);
}
2011-09-04 09:24:06 +02:00
for (uint i = 0; i < nodeData->hotspots.size(); i++) {
2014-07-02 01:02:35 +02:00
debugPrintf("\nhotspot %d > %s (%s)\n", i,
2012-01-13 08:47:32 +01:00
_vm->_state->describeCondition(nodeData->hotspots[i].condition).c_str(),
_vm->_state->evaluate(nodeData->hotspots[i].condition) ? "true" : "false");
2011-09-04 09:24:06 +02:00
for(uint j = 0; j < nodeData->hotspots[i].rects.size(); j++) {
PolarRect &rect = nodeData->hotspots[i].rects[j];
2014-07-02 01:02:35 +02:00
debugPrintf(" rect > pitch: %d heading: %d width: %d height: %d\n",
2011-09-04 09:24:06 +02:00
rect.centerPitch, rect.centerHeading, rect.width, rect.height);
}
2011-09-04 20:08:37 +02:00
describeScript(nodeData->hotspots[i].script);
2011-09-04 09:24:06 +02:00
}
for (uint i = 0; i < nodeData->soundScripts.size(); i++) {
2014-07-02 01:02:35 +02:00
debugPrintf("\nsound %d > %s (%s)\n", i,
_vm->_state->describeCondition(nodeData->soundScripts[i].condition).c_str(),
_vm->_state->evaluate(nodeData->soundScripts[i].condition) ? "true" : "false");
describeScript(nodeData->soundScripts[i].script);
}
for (uint i = 0; i < nodeData->backgroundSoundScripts.size(); i++) {
2014-07-02 01:02:35 +02:00
debugPrintf("\nbackground sound %d > %s (%s)\n", i,
_vm->_state->describeCondition(nodeData->backgroundSoundScripts[i].condition).c_str(),
_vm->_state->evaluate(nodeData->backgroundSoundScripts[i].condition) ? "true" : "false");
describeScript(nodeData->backgroundSoundScripts[i].script);
}
return true;
}
bool Console::Cmd_LookAt(int argc, const char **argv) {
if (argc != 1 && argc != 3) {
2014-07-02 01:02:35 +02:00
debugPrintf("Usage :\n");
debugPrintf("lookAt pitch heading\n");
return true;
}
float pitch = _vm->_state->getLookAtPitch();
float heading = _vm->_state->getLookAtHeading();
2014-07-02 01:02:35 +02:00
debugPrintf("pitch: %d heading: %d\n", (int)pitch, (int)heading);
if (argc >= 3){
_vm->_state->lookAt(atof(argv[1]), atof(argv[2]));
return false;
}
return true;
}
2011-09-04 09:24:06 +02:00
bool Console::Cmd_InitScript(int argc, const char **argv) {
2011-09-04 20:08:37 +02:00
describeScript(_vm->_db->getNodeInitScript());
2011-09-04 09:24:06 +02:00
return true;
}
2011-09-04 11:16:27 +02:00
bool Console::Cmd_Var(int argc, const char **argv) {
if (argc != 2 && argc != 3) {
2014-07-02 01:02:35 +02:00
debugPrintf("Usage :\n");
debugPrintf("var variable : Display var value\n");
debugPrintf("var variable value : Change var value\n");
2011-09-04 11:16:27 +02:00
return true;
}
uint16 var = atoi(argv[1]);
2012-01-13 08:47:32 +01:00
uint32 value = _vm->_state->getVar(var);
2011-09-04 11:16:27 +02:00
if (argc == 3) {
value = atoi(argv[2]);
2012-01-13 08:47:32 +01:00
_vm->_state->setVar(var, value);
2011-09-04 11:16:27 +02:00
}
2014-07-02 01:02:35 +02:00
debugPrintf("%s: %d\n", _vm->_state->describeVar(var).c_str(), value);
2011-09-04 11:16:27 +02:00
return true;
}
2011-09-04 20:08:37 +02:00
bool Console::Cmd_ListNodes(int argc, const char **argv) {
uint32 roomID = 0;
2011-09-04 20:08:37 +02:00
if (argc == 2) {
roomID = _vm->_db->getRoomId(argv[1]);
if (roomID == 0) {
2014-07-02 01:02:35 +02:00
debugPrintf("Unknown room name %s\n", argv[1]);
return true;
}
2011-09-04 20:08:37 +02:00
}
2014-07-02 01:02:35 +02:00
debugPrintf("Nodes:\n");
2011-09-04 20:08:37 +02:00
Common::Array<uint16> list = _vm->_db->listRoomNodes(roomID);
for (uint i = 0; i < list.size(); i++) {
2014-07-02 01:02:35 +02:00
debugPrintf("%d\n", list[i]);
2011-09-04 20:08:37 +02:00
}
return true;
}
2011-09-04 20:57:57 +02:00
bool Console::Cmd_Run(int argc, const char **argv) {
2012-01-13 08:47:32 +01:00
uint16 nodeId = _vm->_state->getLocationNode();
uint32 roomId = 0;
2011-09-04 20:57:57 +02:00
if (argc >= 2) {
nodeId = atoi(argv[1]);
}
if (argc >= 3) {
roomId = _vm->_db->getRoomId(argv[2]);
if (roomId == 0) {
2014-07-02 01:02:35 +02:00
debugPrintf("Unknown room name %s\n", argv[2]);
return true;
}
2011-09-04 20:57:57 +02:00
}
_vm->runScriptsFromNode(nodeId, roomId);
return false;
}
bool Console::Cmd_RunOp(int argc, const char **argv) {
if (argc < 2) {
2014-07-02 01:02:35 +02:00
debugPrintf("Usage :\n");
debugPrintf("runOp [opcode] [argument 1] [argument 2] ... : Run specified command\n");
return true;
}
Opcode op;
op.op = atoi(argv[1]);
for (int i = 2; i < argc; i++) {
op.args.push_back(atoi(argv[i]));
}
2014-07-02 01:02:35 +02:00
debugPrintf("Running opcode :\n");
debugPrintf("%s\n", _vm->_scriptEngine->describeOpcode(op).c_str());
_vm->_scriptEngine->runSingleOp(op);
return false;
}
bool Console::Cmd_Go(int argc, const char **argv) {
if (argc != 3) {
2014-07-02 01:02:35 +02:00
debugPrintf("Usage :\n");
debugPrintf("go [room name] [node id] : Go to node\n");
return true;
}
uint32 roomID = _vm->_db->getRoomId(argv[1]);
uint16 nodeId = atoi(argv[2]);
if (roomID == 0) {
2014-07-02 01:02:35 +02:00
debugPrintf("Unknown room name %s\n", argv[1]);
return true;
}
2012-01-13 08:47:32 +01:00
_vm->_state->setLocationNextRoom(roomID);
_vm->_state->setLocationNextNode(nodeId);
2014-07-01 17:43:28 +02:00
_vm->goToNode(0, kTransitionFade);
return false;
}
bool Console::Cmd_Extract(int argc, const char **argv) {
if (argc != 5) {
2014-07-02 01:02:35 +02:00
debugPrintf("Extract a file from the game's archives\n");
debugPrintf("Usage :\n");
debugPrintf("extract [room] [node id] [face number] [object type]\n");
return true;
}
// Room names are uppercase
Common::String room = Common::String(argv[1]);
room.toUppercase();
uint16 id = atoi(argv[2]);
uint16 face = atoi(argv[3]);
DirectorySubEntry::ResourceType type = (DirectorySubEntry::ResourceType) atoi(argv[4]);
const DirectorySubEntry *desc = _vm->getFileDescription(room.c_str(), id, face, type);
if (!desc) {
2014-07-02 01:02:35 +02:00
debugPrintf("File with room %s, id %d, face %d and type %d does not exist\n", room.c_str(), id, face, type);
return true;
}
Common::MemoryReadStream *s = desc->getData();
Common::String filename = Common::String::format("node%s_%d_face%d.%d", room.c_str(), id, face, type);
Common::DumpFile f;
f.open(filename);
uint8 *buf = new uint8[s->size()];
s->read(buf, s->size());
f.write(buf, s->size());
delete[] buf;
f.close();
delete s;
2014-07-02 01:02:35 +02:00
debugPrintf("File '%s' successfully written\n", filename.c_str());
return true;
}
bool Console::Cmd_FillInventory(int argc, const char **argv) {
_vm->_inventory->addAll();
return false;
}
bool Console::Cmd_DumpArchive(int argc, const char **argv) {
if (argc != 2) {
2014-07-02 01:02:35 +02:00
debugPrintf("Extract all the files from a game archive.\n");
debugPrintf("The destination folder, named 'dump', must exist.\n");
debugPrintf("Usage :\n");
debugPrintf("dumpArchive [file name]\n");
return true;
}
// Is the archive multi-room
Common::String temp = Common::String(argv[1]);
temp.toUppercase();
bool multiRoom = !temp.hasSuffix(".M3A");
if (!multiRoom) {
temp = Common::String(argv[1], 4);
temp.toUppercase();
}
Archive archive;
if (!archive.open(argv[1], multiRoom ? 0 : temp.c_str())) {
2014-07-02 01:02:35 +02:00
debugPrintf("Can't open archive with name '%s'\n", argv[1]);
return true;
}
archive.dumpToFiles();
archive.close();
return true;
}
bool Console::Cmd_DumpMasks(int argc, const char **argv) {
if (argc != 1 && argc != 2) {
2014-07-02 01:02:35 +02:00
debugPrintf("Extract the masks of the faces of a cube node.\n");
debugPrintf("The destination folder, named 'dump', must exist.\n");
debugPrintf("Usage :\n");
debugPrintf("dumpMasks [node]\n");
return true;
}
uint16 nodeId = _vm->_state->getLocationNode();
if (argc >= 2) {
nodeId = atoi(argv[1]);
}
2014-07-02 01:02:35 +02:00
debugPrintf("Extracting masks for node %d:\n", nodeId);
for (uint i = 0; i < 6; i++) {
bool water = dumpFaceMask(nodeId, i, DirectorySubEntry::kWaterEffectMask);
if (water)
2014-07-02 01:02:35 +02:00
debugPrintf("Face %d: water OK\n", i);
2014-03-15 16:37:21 +01:00
bool effect2 = dumpFaceMask(nodeId, i, DirectorySubEntry::kLavaEffectMask);
if (effect2)
2014-07-02 01:02:35 +02:00
debugPrintf("Face %d: effect 2 OK\n", i);
bool magnet = dumpFaceMask(nodeId, i, DirectorySubEntry::kMagneticEffectMask);
if (magnet)
2014-07-02 01:02:35 +02:00
debugPrintf("Face %d: magnet OK\n", i);
if (!water && !effect2 && !magnet)
2014-07-02 01:02:35 +02:00
debugPrintf("Face %d: No mask found\n", i);
}
return true;
}
bool Console::dumpFaceMask(uint16 index, int face, DirectorySubEntry::ResourceType type) {
const DirectorySubEntry *maskDesc = _vm->getFileDescription(0, index, face, type);
if (!maskDesc)
return false;
Common::MemoryReadStream *maskStream = maskDesc->getData();
Graphics::Surface *mask = Effect::loadMask(maskStream);
delete maskStream;
Common::DumpFile outFile;
outFile.open(Common::String::format("dump/%d-%d.masku_%d", index, face, type));
outFile.write(mask->getPixels(), mask->pitch * mask->h);
outFile.close();
mask->free();
delete mask;
return true;
}
} /* namespace Myst3 */