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-13 10:09:56 +02:00
|
|
|
#include "audio/audiostream.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-11 21:24:50 +02:00
|
|
|
#include "nancy/video.h"
|
2012-10-13 10:09:56 +02:00
|
|
|
#include "nancy/audio.h"
|
2012-10-06 16:26:16 +02:00
|
|
|
|
|
|
|
namespace Nancy {
|
|
|
|
|
|
|
|
NancyConsole::NancyConsole(NancyEngine *vm) : GUI::Debugger(), _vm(vm) {
|
2012-10-13 13:39:08 +02:00
|
|
|
registerCmd("load_cal", WRAP_METHOD(NancyConsole, Cmd_loadCal));
|
|
|
|
registerCmd("cif_hexdump", WRAP_METHOD(NancyConsole, Cmd_cifHexDump));
|
|
|
|
registerCmd("cif_export", WRAP_METHOD(NancyConsole, Cmd_cifExport));
|
|
|
|
registerCmd("cif_list", WRAP_METHOD(NancyConsole, Cmd_cifList));
|
|
|
|
registerCmd("cif_info", WRAP_METHOD(NancyConsole, Cmd_cifInfo));
|
|
|
|
registerCmd("show_image", WRAP_METHOD(NancyConsole, Cmd_showImage));
|
2012-10-11 21:24:50 +02:00
|
|
|
registerCmd("play_video", WRAP_METHOD(NancyConsole, Cmd_playVideo));
|
2012-10-13 10:09:56 +02:00
|
|
|
registerCmd("play_audio", WRAP_METHOD(NancyConsole, Cmd_playAudio));
|
2012-10-06 16:26:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NancyConsole::~NancyConsole() {
|
|
|
|
}
|
|
|
|
|
2012-10-11 21:24:50 +02:00
|
|
|
void NancyConsole::postEnter() {
|
|
|
|
if (!_videoFile.empty()) {
|
|
|
|
Video::VideoDecoder *dec = new AVFDecoder;
|
|
|
|
|
|
|
|
if (dec->loadFile(_videoFile)) {
|
|
|
|
dec->start();
|
|
|
|
while (!dec->endOfVideo()) {
|
|
|
|
const Graphics::Surface *frame = dec->decodeNextFrame();
|
|
|
|
_vm->_system->fillScreen(0);
|
|
|
|
_vm->_system->copyRectToScreen(frame->getPixels(), frame->pitch, 0, 0, frame->w, frame->h);
|
|
|
|
_vm->_system->updateScreen();
|
|
|
|
_vm->_system->delayMillis(60);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
debugPrintf("Failed to load '%s'\n", _videoFile.c_str());
|
|
|
|
}
|
|
|
|
_videoFile.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:39:08 +02:00
|
|
|
bool NancyConsole::Cmd_cifHexDump(int argc, const char **argv) {
|
2012-10-10 16:15:12 +02:00
|
|
|
if (argc < 2 || argc > 3) {
|
2012-10-07 17:25:52 +02:00
|
|
|
debugPrintf("Dumps the specified resource to standard output\n");
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("Usage: %s name [cal]\n", argv[0]);
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint size;
|
2012-10-10 16:15:12 +02:00
|
|
|
byte *buf = _vm->_res->loadCif((argc == 2 ? "ciftree" : argv[2]), argv[1], size);
|
2012-10-07 17:25:52 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:39:08 +02:00
|
|
|
bool NancyConsole::Cmd_cifExport(int argc, const char **argv) {
|
2012-10-10 16:15:12 +02:00
|
|
|
if (argc < 2 || argc > 3) {
|
2012-10-13 13:15:00 +02:00
|
|
|
debugPrintf("Exports the specified resource to .cif file\n");
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("Usage: %s name [cal]\n", argv[0]);
|
2012-10-08 16:25:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:15:00 +02:00
|
|
|
if (!_vm->_res->exportCif((argc == 2 ? "ciftree" : argv[2]), argv[1]))
|
|
|
|
debugPrintf("Failed to export '%s'\n", argv[1]);
|
2012-10-08 16:25:26 +02:00
|
|
|
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:39:08 +02:00
|
|
|
bool NancyConsole::Cmd_cifList(int argc, const char **argv) {
|
2012-10-10 16:15:12 +02:00
|
|
|
if (argc < 2 || argc > 3) {
|
2012-10-07 19:42:17 +02:00
|
|
|
debugPrintf("List resources of a certain type\n");
|
|
|
|
debugPrintf("Types - 0: all, 2: image, 3: script\n");
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("Usage: %s type [cal]\n", argv[0]);
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Array<Common::String> list;
|
2012-10-10 16:15:12 +02:00
|
|
|
_vm->_res->list((argc == 2 ? "ciftree" : argv[2]), 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;
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:39:08 +02:00
|
|
|
bool NancyConsole::Cmd_cifInfo(int argc, const char **argv) {
|
2012-10-10 16:15:12 +02:00
|
|
|
if (argc < 2 || argc > 3) {
|
2012-10-07 17:25:52 +02:00
|
|
|
debugPrintf("Prints information about a resource\n");
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("Usage: %s name [cal]\n", argv[0]);
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("%s", _vm->_res->getCifDescription((argc == 2 ? "ciftree" : argv[2]), argv[1]).c_str());
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-13 13:39:08 +02:00
|
|
|
bool NancyConsole::Cmd_showImage(int argc, const char **argv) {
|
2012-10-10 16:15:12 +02:00
|
|
|
if (argc < 2 || argc > 3) {
|
2012-10-07 17:25:52 +02:00
|
|
|
debugPrintf("Draws an image on the screen\n");
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("Usage: %s name [cal]\n", argv[0]);
|
2012-10-07 17:25:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Graphics::Surface surf;
|
2012-10-10 16:15:12 +02:00
|
|
|
if (_vm->_res->loadImage((argc == 2 ? "ciftree" : argv[2]), argv[1], surf)) {
|
2012-10-07 17:25:52 +02:00
|
|
|
_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();
|
2012-10-11 21:24:50 +02:00
|
|
|
return cmdExit(0, 0);
|
|
|
|
} else {
|
2012-10-07 17:25:52 +02:00
|
|
|
debugPrintf("Failed to load image\n");
|
2012-10-11 21:24:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
2012-10-07 17:25:52 +02:00
|
|
|
}
|
|
|
|
|
2012-10-13 13:39:08 +02:00
|
|
|
bool NancyConsole::Cmd_loadCal(int argc, const char **argv) {
|
2012-10-08 16:25:26 +02:00
|
|
|
if (argc != 2) {
|
2012-10-10 16:15:12 +02:00
|
|
|
debugPrintf("Loads a .cal file\n");
|
|
|
|
debugPrintf("Usage: %s <name>\n", argv[0]);
|
2012-10-08 16:25:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-10 16:15:12 +02:00
|
|
|
if (!_vm->_res->loadCifTree(argv[1], "cal"))
|
|
|
|
debugPrintf("Failed to load '%s.cal'\n", argv[1]);
|
2012-10-08 16:25:26 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-11 21:24:50 +02:00
|
|
|
bool NancyConsole::Cmd_playVideo(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Plays a video\n");
|
|
|
|
debugPrintf("Usage: %s <name>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_videoFile = argv[1];
|
|
|
|
_videoFile += ".avf";
|
|
|
|
return cmdExit(0, 0);
|
|
|
|
}
|
|
|
|
|
2012-10-13 10:09:56 +02:00
|
|
|
bool NancyConsole::Cmd_playAudio(int argc, const char **argv) {
|
|
|
|
if (argc != 2) {
|
|
|
|
debugPrintf("Plays an audio file\n");
|
|
|
|
debugPrintf("Usage: %s <name>\n", argv[0]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::File *f = new Common::File;
|
|
|
|
if (!f->open(Common::String(argv[1]) + ".his")) {
|
|
|
|
debugPrintf("Failed to open '%s.his'\n", argv[1]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Audio::AudioStream *stream = makeHISStream(f, DisposeAfterUse::YES);
|
|
|
|
|
|
|
|
if (!stream) {
|
|
|
|
debugPrintf("Failed to load '%s.his'\n", argv[1]);
|
|
|
|
delete f;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Audio::SoundHandle handle;
|
|
|
|
_vm->_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &handle, stream);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-06 16:26:16 +02:00
|
|
|
} // End of namespace Nancy
|