ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

engines/myst3/console.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/myst3/console.h"
00024 
00025 #include "engines/myst3/archive.h"
00026 #include "engines/myst3/database.h"
00027 #include "engines/myst3/effects.h"
00028 #include "engines/myst3/inventory.h"
00029 #include "engines/myst3/script.h"
00030 #include "engines/myst3/state.h"
00031 
00032 namespace Myst3 {
00033 
00034 Console::Console(Myst3Engine *vm) : GUI::Debugger(), _vm(vm) {
00035     registerCmd("infos",                WRAP_METHOD(Console, Cmd_Infos));
00036     registerCmd("lookAt",               WRAP_METHOD(Console, Cmd_LookAt));
00037     registerCmd("initScript",           WRAP_METHOD(Console, Cmd_InitScript));
00038     registerCmd("var",              WRAP_METHOD(Console, Cmd_Var));
00039     registerCmd("listNodes",            WRAP_METHOD(Console, Cmd_ListNodes));
00040     registerCmd("run",              WRAP_METHOD(Console, Cmd_Run));
00041     registerCmd("runOp",                WRAP_METHOD(Console, Cmd_RunOp));
00042     registerCmd("go",               WRAP_METHOD(Console, Cmd_Go));
00043     registerCmd("extract",              WRAP_METHOD(Console, Cmd_Extract));
00044     registerCmd("fillInventory",            WRAP_METHOD(Console, Cmd_FillInventory));
00045     registerCmd("dumpArchive",          WRAP_METHOD(Console, Cmd_DumpArchive));
00046     registerCmd("dumpMasks",            WRAP_METHOD(Console, Cmd_DumpMasks));
00047 }
00048 
00049 Console::~Console() {
00050 }
00051 
00052 void Console::describeScript(const Common::Array<Opcode> &script) {
00053     for (uint j = 0; j < script.size(); j++) {
00054         debugPrintf("%s", _vm->_scriptEngine->describeOpcode(script[j]).c_str());
00055     }
00056 }
00057 
00058 bool Console::Cmd_Infos(int argc, const char **argv) {
00059     uint16 nodeId = _vm->_state->getLocationNode();
00060     uint32 roomId = _vm->_state->getLocationRoom();
00061     uint32 ageID = _vm->_state->getLocationAge();
00062 
00063     if (argc >= 2) {
00064         nodeId = atoi(argv[1]);
00065     }
00066 
00067     if (argc >= 3) {
00068         RoomKey roomKey = _vm->_db->getRoomKey(argv[2]);
00069         if (roomKey.roomID == 0 || roomKey.ageID == 0) {
00070             debugPrintf("Unknown room name %s\n", argv[2]);
00071             return true;
00072         }
00073 
00074         roomId = roomKey.roomID;
00075         ageID = roomKey.ageID;
00076     }
00077 
00078     NodePtr nodeData = _vm->_db->getNodeData(nodeId, roomId, ageID);
00079 
00080     if (!nodeData) {
00081         debugPrintf("No node with id %d\n", nodeId);
00082         return true;
00083     }
00084 
00085     Common::String roomName = _vm->_db->getRoomName(roomId, ageID);
00086 
00087     debugPrintf("node: %s %d    ", roomName.c_str(), nodeId);
00088 
00089     for (uint i = 0; i < nodeData->scripts.size(); i++) {
00090         debugPrintf("\ninit %d > %s (%s)\n", i,
00091                 _vm->_state->describeCondition(nodeData->scripts[i].condition).c_str(),
00092                 _vm->_state->evaluate(nodeData->scripts[i].condition) ? "true" : "false");
00093 
00094         describeScript(nodeData->scripts[i].script);
00095     }
00096 
00097     for (uint i = 0; i < nodeData->hotspots.size(); i++) {
00098         debugPrintf("\nhotspot %d > %s (%s)\n", i,
00099                 _vm->_state->describeCondition(nodeData->hotspots[i].condition).c_str(),
00100                 _vm->_state->evaluate(nodeData->hotspots[i].condition) ? "true" : "false");
00101 
00102         for(uint j = 0; j < nodeData->hotspots[i].rects.size(); j++) {
00103             PolarRect &rect = nodeData->hotspots[i].rects[j];
00104 
00105             debugPrintf("    rect > pitch: %d heading: %d width: %d height: %d\n",
00106                     rect.centerPitch, rect.centerHeading, rect.width, rect.height);
00107         }
00108 
00109         describeScript(nodeData->hotspots[i].script);
00110     }
00111 
00112     for (uint i = 0; i < nodeData->soundScripts.size(); i++) {
00113         debugPrintf("\nsound %d > %s (%s)\n", i,
00114                 _vm->_state->describeCondition(nodeData->soundScripts[i].condition).c_str(),
00115                 _vm->_state->evaluate(nodeData->soundScripts[i].condition) ? "true" : "false");
00116 
00117         describeScript(nodeData->soundScripts[i].script);
00118     }
00119 
00120     for (uint i = 0; i < nodeData->backgroundSoundScripts.size(); i++) {
00121         debugPrintf("\nbackground sound %d > %s (%s)\n", i,
00122                 _vm->_state->describeCondition(nodeData->backgroundSoundScripts[i].condition).c_str(),
00123                 _vm->_state->evaluate(nodeData->backgroundSoundScripts[i].condition) ? "true" : "false");
00124 
00125         describeScript(nodeData->backgroundSoundScripts[i].script);
00126     }
00127 
00128     return true;
00129 }
00130 
00131 bool Console::Cmd_LookAt(int argc, const char **argv) {
00132     if (argc != 1 && argc != 3) {
00133         debugPrintf("Usage :\n");
00134         debugPrintf("lookAt pitch heading\n");
00135         return true;
00136     }
00137 
00138     float pitch = _vm->_state->getLookAtPitch();
00139     float heading = _vm->_state->getLookAtHeading();
00140 
00141     debugPrintf("pitch: %d heading: %d\n", (int)pitch, (int)heading);
00142 
00143     if (argc >= 3){
00144         _vm->_state->lookAt(atof(argv[1]), atof(argv[2]));
00145         return false;
00146     }
00147 
00148     return true;
00149 }
00150 
00151 bool Console::Cmd_InitScript(int argc, const char **argv) {
00152     describeScript(_vm->_db->getNodeInitScript());
00153 
00154     return true;
00155 }
00156 
00157 
00158 bool Console::Cmd_Var(int argc, const char **argv) {
00159 
00160     if (argc != 2 && argc != 3) {
00161         debugPrintf("Usage :\n");
00162         debugPrintf("var variable : Display var value\n");
00163         debugPrintf("var variable value : Change var value\n");
00164         return true;
00165     }
00166 
00167     uint16 var = atoi(argv[1]);
00168     if (var < 1 || var > 2047) {
00169         debugPrintf("Variable out of range %d\n", var);
00170         return true;
00171     }   
00172     uint32 value = _vm->_state->getVar(var);
00173 
00174     if (argc == 3) {
00175         value = atoi(argv[2]);
00176         _vm->_state->setVar(var, value);
00177     }
00178 
00179     debugPrintf("%s: %d\n", _vm->_state->describeVar(var).c_str(), value);
00180 
00181     return true;
00182 }
00183 
00184 bool Console::Cmd_ListNodes(int argc, const char **argv) {
00185     uint32 roomID = _vm->_state->getLocationRoom();
00186     uint32 ageID = _vm->_state->getLocationAge();
00187 
00188     if (argc == 2) {
00189         RoomKey roomKey = _vm->_db->getRoomKey(argv[1]);
00190         if (roomKey.roomID == 0 || roomKey.ageID == 0) {
00191             debugPrintf("Unknown room name %s\n", argv[1]);
00192             return true;
00193         }
00194 
00195         roomID = roomKey.roomID;
00196         ageID = roomKey.ageID;
00197     }
00198 
00199     debugPrintf("Nodes:\n");
00200 
00201     Common::Array<uint16> list = _vm->_db->listRoomNodes(roomID, ageID);
00202     for (uint i = 0; i < list.size(); i++) {
00203         debugPrintf("%d\n", list[i]);
00204     }
00205 
00206     return true;
00207 }
00208 
00209 bool Console::Cmd_Run(int argc, const char **argv) {
00210     uint16 nodeId = _vm->_state->getLocationNode();
00211     uint32 roomId = _vm->_state->getLocationRoom();
00212     uint32 ageId = _vm->_state->getLocationAge();
00213 
00214     if (argc >= 2) {
00215         nodeId = atoi(argv[1]);
00216     }
00217 
00218     if (argc >= 3) {
00219         RoomKey roomKey = _vm->_db->getRoomKey(argv[2]);
00220 
00221         if (roomKey.roomID == 0 || roomKey.ageID == 0) {
00222             debugPrintf("Unknown room name %s\n", argv[2]);
00223             return true;
00224         }
00225 
00226         roomId = roomKey.roomID;
00227         ageId = roomKey.ageID;
00228     }
00229 
00230     _vm->runScriptsFromNode(nodeId, roomId, ageId);
00231 
00232     return false;
00233 }
00234 
00235 bool Console::Cmd_RunOp(int argc, const char **argv) {
00236     if (argc < 2) {
00237         debugPrintf("Usage :\n");
00238         debugPrintf("runOp [opcode] [argument 1] [argument 2] ... : Run specified command\n");
00239         return true;
00240     }
00241 
00242     Opcode op;
00243     op.op = atoi(argv[1]);
00244 
00245     for (int i = 2; i < argc; i++) {
00246         op.args.push_back(atoi(argv[i]));
00247     }
00248 
00249     debugPrintf("Running opcode :\n");
00250     debugPrintf("%s\n", _vm->_scriptEngine->describeOpcode(op).c_str());
00251 
00252     _vm->_scriptEngine->runSingleOp(op);
00253 
00254     return false;
00255 }
00256 
00257 bool Console::Cmd_Go(int argc, const char **argv) {
00258     if (argc != 3) {
00259         debugPrintf("Usage :\n");
00260         debugPrintf("go [room name] [node id] : Go to node\n");
00261         return true;
00262     }
00263 
00264     RoomKey roomKey = _vm->_db->getRoomKey(argv[1]);
00265     if (roomKey.roomID == 0 || roomKey.ageID == 0) {
00266         debugPrintf("Unknown room name %s\n", argv[1]);
00267         return true;
00268     }
00269 
00270     uint16 nodeId = atoi(argv[2]);
00271 
00272     _vm->_state->setLocationNextAge(roomKey.ageID);
00273     _vm->_state->setLocationNextRoom(roomKey.roomID);
00274     _vm->_state->setLocationNextNode(nodeId);
00275 
00276     _vm->goToNode(0, kTransitionFade);
00277 
00278     return false;
00279 }
00280 
00281 bool Console::Cmd_Extract(int argc, const char **argv) {
00282     if (argc != 5) {
00283         debugPrintf("Extract a file from the game's archives\n");
00284         debugPrintf("Usage :\n");
00285         debugPrintf("extract [room] [node id] [face number] [object type]\n");
00286         return true;
00287     }
00288 
00289     // Room names are uppercase
00290     Common::String room = Common::String(argv[1]);
00291     room.toUppercase();
00292 
00293     uint16 id = atoi(argv[2]);
00294     uint16 face = atoi(argv[3]);
00295     DirectorySubEntry::ResourceType type = (DirectorySubEntry::ResourceType) atoi(argv[4]);
00296 
00297     const DirectorySubEntry *desc = _vm->getFileDescription(room, id, face, type);
00298 
00299     if (!desc) {
00300         debugPrintf("File with room %s, id %d, face %d and type %d does not exist\n", room.c_str(), id, face, type);
00301         return true;
00302     }
00303 
00304     Common::MemoryReadStream *s = desc->getData();
00305     Common::String filename = Common::String::format("node%s_%d_face%d.%d", room.c_str(), id, face, type);
00306     Common::DumpFile f;
00307     f.open(filename);
00308 
00309     uint8 *buf = new uint8[s->size()];
00310 
00311     s->read(buf, s->size());
00312     f.write(buf, s->size());
00313 
00314     delete[] buf;
00315 
00316     f.close();
00317 
00318     delete s;
00319 
00320     debugPrintf("File '%s' successfully written\n", filename.c_str());
00321 
00322     return true;
00323 }
00324 
00325 bool Console::Cmd_FillInventory(int argc, const char **argv) {
00326     _vm->_inventory->addAll();
00327     return false;
00328 }
00329 
00330 bool Console::Cmd_DumpArchive(int argc, const char **argv) {
00331     if (argc != 2) {
00332         debugPrintf("Extract all the files from a game archive.\n");
00333         debugPrintf("The destination folder, named 'dump', must exist.\n");
00334         debugPrintf("Usage :\n");
00335         debugPrintf("dumpArchive [file name]\n");
00336         return true;
00337     }
00338 
00339     // Is the archive multi-room
00340     Common::String temp = Common::String(argv[1]);
00341     temp.toUppercase();
00342 
00343     bool multiRoom = !temp.hasSuffix(".M3A");
00344     if (!multiRoom) {
00345         temp = Common::String(argv[1], 4);
00346         temp.toUppercase();
00347     }
00348 
00349     Archive archive;
00350     if (!archive.open(argv[1], multiRoom ? 0 : temp.c_str())) {
00351         debugPrintf("Can't open archive with name '%s'\n", argv[1]);
00352         return true;
00353     }
00354 
00355     archive.dumpToFiles();
00356     archive.close();
00357 
00358     return true;
00359 }
00360 
00361 bool Console::Cmd_DumpMasks(int argc, const char **argv) {
00362     if (argc != 1 && argc != 2) {
00363         debugPrintf("Extract the masks of the faces of a cube node.\n");
00364         debugPrintf("The destination folder, named 'dump', must exist.\n");
00365         debugPrintf("Usage :\n");
00366         debugPrintf("dumpMasks [node]\n");
00367         return true;
00368     }
00369 
00370     uint16 nodeId = _vm->_state->getLocationNode();
00371 
00372     if (argc >= 2) {
00373         nodeId = atoi(argv[1]);
00374     }
00375 
00376     debugPrintf("Extracting masks for node %d:\n", nodeId);
00377 
00378     for (uint i = 0; i < 6; i++) {
00379         bool water = dumpFaceMask(nodeId, i, DirectorySubEntry::kWaterEffectMask);
00380         if (water)
00381             debugPrintf("Face %d: water OK\n", i);
00382 
00383         bool effect2 = dumpFaceMask(nodeId, i, DirectorySubEntry::kLavaEffectMask);
00384         if (effect2)
00385             debugPrintf("Face %d: effect 2 OK\n", i);
00386 
00387         bool magnet = dumpFaceMask(nodeId, i, DirectorySubEntry::kMagneticEffectMask);
00388         if (magnet)
00389             debugPrintf("Face %d: magnet OK\n", i);
00390 
00391         if (!water && !effect2 && !magnet)
00392             debugPrintf("Face %d: No mask found\n", i);
00393     }
00394 
00395     return true;
00396 }
00397 
00398 bool Console::dumpFaceMask(uint16 index, int face, DirectorySubEntry::ResourceType type) {
00399     const DirectorySubEntry *maskDesc = _vm->getFileDescription("", index, face, type);
00400 
00401     if (!maskDesc)
00402         return false;
00403 
00404     Common::MemoryReadStream *maskStream = maskDesc->getData();
00405 
00406     Effect::FaceMask *mask = Effect::loadMask(maskStream);
00407 
00408     delete maskStream;
00409 
00410     Common::DumpFile outFile;
00411     outFile.open(Common::String::format("dump/%d-%d.masku_%d", index, face, type));
00412     outFile.write(mask->surface->getPixels(), mask->surface->pitch * mask->surface->h);
00413     outFile.close();
00414 
00415     delete mask;
00416 
00417     return true;
00418 }
00419 
00420 } // End of namespace Myst3


Generated on Sat Mar 16 2019 05:01:22 for ResidualVM by doxygen 1.7.1
curved edge   curved edge