diff --git a/engines/stark/console.cpp b/engines/stark/console.cpp new file mode 100644 index 00000000000..04affe4c80a --- /dev/null +++ b/engines/stark/console.cpp @@ -0,0 +1,82 @@ +/* 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" +#include "engines/stark/archive.h" + +#include "common/file.h" + +namespace Stark { + +Console::Console(StarkEngine *vm) : GUI::Debugger(), _vm(vm) { + registerCmd("dumpArchive", WRAP_METHOD(Console, Cmd_DumpArchive)); +} + +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"); + debugPrintf("dumpArchive [file name]\n"); + 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)) { + debugPrintf("Unable to open file '%s' for writing", fileName.c_str()); + 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(); + + debugPrintf("Extracted '%s'", it->get()->getName().c_str()); + } + + return true; +} + +} // End of namespace Stark diff --git a/engines/stark/console.h b/engines/stark/console.h new file mode 100644 index 00000000000..01057428f98 --- /dev/null +++ b/engines/stark/console.h @@ -0,0 +1,47 @@ +/* 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. + * + */ + +#ifndef CONSOLE_H_ +#define CONSOLE_H_ + +#include "common/debug.h" + +#include "gui/debugger.h" + +#include "engines/stark/stark.h" + +namespace Stark { + +class Console : public GUI::Debugger { +public: + Console(StarkEngine *vm); + virtual ~Console(); + +private: + StarkEngine *_vm; + + bool Cmd_DumpArchive(int argc, const char **argv); +}; + +} // End of namespace Stark + +#endif // CONSOLE_H_ diff --git a/engines/stark/module.mk b/engines/stark/module.mk index 58da4bad135..604665d6adf 100644 --- a/engines/stark/module.mk +++ b/engines/stark/module.mk @@ -4,6 +4,7 @@ MODULE_OBJS := \ actor.o \ adpcm.o \ archive.o \ + console.o \ detection.o \ gfx/coordinate.o \ gfx/driver.o \ diff --git a/engines/stark/stark.cpp b/engines/stark/stark.cpp index 9e2368a6508..74011a838e9 100644 --- a/engines/stark/stark.cpp +++ b/engines/stark/stark.cpp @@ -24,6 +24,7 @@ */ #include "engines/stark/stark.h" +#include "engines/stark/console.h" #include "engines/stark/debug.h" #include "common/config-manager.h" @@ -33,7 +34,9 @@ namespace Stark { -StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc), _gfx(NULL), _scene(NULL) { +StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) : + Engine(syst), _gameDescription(gameDesc), _gfx(NULL), _scene(NULL), + _console(NULL) { _mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, 127); _mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume")); _mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume")); @@ -48,9 +51,11 @@ StarkEngine::StarkEngine(OSystem *syst, const ADGameDescription *gameDesc) : Eng StarkEngine::~StarkEngine() { delete _scene; + delete _console; } Common::Error StarkEngine::run() { + _console = new Console(this); _gfx = GfxDriver::create(); // Get the screen prepared @@ -75,9 +80,15 @@ void StarkEngine::mainLoop() { if (e.kbd.ascii == 'q') { quitGame(); break; + } else if (e.kbd.keycode == Common::KEYCODE_d) { + if (e.kbd.flags & Common::KBD_CTRL) { + _console->attach(); + _console->onFrame(); + } } else { //handleChars(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii); } + } /*if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_KEYUP) { handleControls(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii); diff --git a/engines/stark/stark.h b/engines/stark/stark.h index e051a16cac9..7327a1d40cd 100644 --- a/engines/stark/stark.h +++ b/engines/stark/stark.h @@ -44,6 +44,8 @@ enum StarkGameFeatures { GF_DVD = (1 << 31) }; +class Console; + class StarkEngine : public Engine { public: StarkEngine(OSystem *syst, const ADGameDescription *gameDesc); @@ -52,12 +54,14 @@ public: protected: // Engine APIs virtual Common::Error run(); + virtual GUI::Debugger *getDebugger() { return (GUI::Debugger *)_console; } private: void mainLoop(); void updateDisplayScene(); GfxDriver *_gfx; + Console *_console; const ADGameDescription *_gameDescription;