2012-10-06 16:26:16 +02:00
|
|
|
/* 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 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-10-07 17:25:52 +02:00
|
|
|
#include "common/system.h"
|
|
|
|
#include "graphics/surface.h"
|
2012-10-06 16:26:16 +02:00
|
|
|
#include "nancy/console.h"
|
|
|
|
#include "nancy/nancy.h"
|
2012-10-07 17:25:52 +02:00
|
|
|
#include "nancy/resource.h"
|
2012-10-06 16:26:16 +02:00
|
|
|
|
|
|
|
namespace Nancy {
|
|
|
|
|
|
|
|
NancyConsole::NancyConsole(NancyEngine *vm) : GUI::Debugger(), _vm(vm) {
|
2012-10-08 16:25:26 +02:00
|
|
|
registerCmd("res_load_ciftree", WRAP_METHOD(NancyConsole, Cmd_resLoadCifTree));
|
2012-10-07 17:25:52 +02:00
|
|
|
registerCmd("res_hexdump", WRAP_METHOD(NancyConsole, Cmd_resHexDump));
|
2012-10-08 16:25:26 +02:00
|
|
|
registerCmd("res_diskdump", WRAP_METHOD(NancyConsole, Cmd_resDiskDump));
|
2012-10-07 17:25:52 +02:00
|
|
|
registerCmd("res_list", WRAP_METHOD(NancyConsole, Cmd_resList));
|
|
|
|
registerCmd("res_info", WRAP_METHOD(NancyConsole, Cmd_resInfo));
|
|
|
|
registerCmd("res_show_image", WRAP_METHOD(NancyConsole, Cmd_resShowImage));
|
2012-10-06 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NancyConsole::~NancyConsole() {
|
|
|
|
}
|
|
|
|
|
2012-10-07 17:25:52 +02:00
|
|
|
bool NancyConsole::Cmd_resHexDump(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Dumps the specified resource to standard output\n");
|
|
|
|
debugPrintf("Usage: %s <resource name>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint size;
|
|
|
|
byte *buf = _vm->_res->loadResource(argv[1], size);
|
|
|
|
if (!buf) {
|
2012-10-08 16:25:26 +02:00
|
|
|
debugPrintf("Failed to load resource '%s'\n", argv[1]);
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::hexdump(buf, size);
|
2012-10-08 16:25:26 +02:00
|
|
|
delete[] buf;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NancyConsole::Cmd_resDiskDump(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Dumps the specified resource to disk\n");
|
|
|
|
debugPrintf("Usage: %s <resource name>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint size;
|
|
|
|
byte *buf = _vm->_res->loadResource(argv[1], size);
|
|
|
|
if (!buf) {
|
|
|
|
debugPrintf("Failed to load resource '%s'\n", argv[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String filename = argv[1];
|
|
|
|
filename += ".raw";
|
|
|
|
Common::DumpFile dump;
|
|
|
|
if (!dump.open(filename)) {
|
|
|
|
debugPrintf("Failed to open dump file '%s'\n", filename.c_str());
|
|
|
|
delete[] buf;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dump.write(buf, size) < size)
|
|
|
|
debugPrintf("Failed to write dump file '%s'\n", filename.c_str());
|
|
|
|
|
|
|
|
dump.close();
|
|
|
|
delete[] buf;
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NancyConsole::Cmd_resList(int argc, const char **argv) {
|
2012-10-07 19:42:17 +02:00
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("List resources of a certain type\n");
|
|
|
|
debugPrintf("Types - 0: all, 2: image, 3: script\n");
|
|
|
|
debugPrintf("Usage: %s <resource type>\n", argv[0]);
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Array<Common::String> list;
|
2012-10-07 19:42:17 +02:00
|
|
|
_vm->_res->listResources(list, atoi(argv[1]));
|
2012-10-07 17:25:52 +02:00
|
|
|
for (uint i = 0; i < list.size(); i++) {
|
2012-10-08 02:51:10 +02:00
|
|
|
debugPrintf("%-38s", list[i].c_str());
|
|
|
|
if ((i % 2) == 1 && i + 1 != list.size())
|
2012-10-07 17:25:52 +02:00
|
|
|
debugPrintf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
debugPrintf("\n");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NancyConsole::Cmd_resInfo(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Prints information about a resource\n");
|
|
|
|
debugPrintf("Usage: %s <resource name>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
debugPrintf("%s", _vm->_res->getResourceDesc(argv[1]).c_str());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NancyConsole::Cmd_resShowImage(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Draws an image on the screen\n");
|
|
|
|
debugPrintf("Usage: %s <resource name>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Graphics::Surface surf;
|
|
|
|
if (_vm->_res->loadImage(argv[1], surf)) {
|
|
|
|
_vm->_system->fillScreen(0);
|
2012-10-07 19:42:17 +02:00
|
|
|
_vm->_system->copyRectToScreen(surf.getPixels(), surf.pitch, 0, 0, surf.w > 640 ? 640 : surf.w, surf.h > 480 ? 480 : surf.h);
|
2012-10-07 17:25:52 +02:00
|
|
|
surf.free();
|
|
|
|
} else
|
|
|
|
debugPrintf("Failed to load image\n");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-08 16:25:26 +02:00
|
|
|
bool NancyConsole::Cmd_resLoadCifTree(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Loads a new CifTree file\n");
|
|
|
|
debugPrintf("Usage: %s <filename>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_vm->_res->loadCifTree(argv[1]))
|
|
|
|
debugPrintf("Failed to load CifTree '%s'\n", argv[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-06 16:26:16 +02:00
|
|
|
} // End of namespace Nancy
|