From 5eaa48ec965f4c1701f4fb310c43fa3042845190 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 29 Aug 2017 19:21:20 +0200 Subject: WAGE: Dump scripts by request --- engines/wage/script.cpp | 27 ++++++++++++++++++++++++++- engines/wage/script.h | 2 +- engines/wage/world.cpp | 4 ++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/engines/wage/script.cpp b/engines/wage/script.cpp index bff75d06bd..d2fbc6c9b7 100644 --- a/engines/wage/script.cpp +++ b/engines/wage/script.cpp @@ -50,6 +50,8 @@ #include "wage/script.h" #include "wage/world.h" +#include "common/config-manager.h" +#include "common/file.h" #include "common/stream.h" namespace Wage { @@ -74,7 +76,7 @@ Common::String Script::Operand::toString() { } } -Script::Script(Common::SeekableReadStream *data) : _data(data) { +Script::Script(Common::SeekableReadStream *data, int num) : _data(data) { _engine = NULL; _world = NULL; @@ -85,6 +87,29 @@ Script::Script(Common::SeekableReadStream *data) : _data(data) { _handled = false; convertToText(); + + if (ConfMan.getBool("dump_scripts")) { + Common::DumpFile out; + Common::String name; + + if (num == -1) + name = Common::String::format("./dumps/%s-global.txt", ConfMan.get("gameid").c_str()); + else + name = Common::String::format("./dumps/%s-%d.txt", ConfMan.get("gameid").c_str(), num); + + if (!out.open(name)) { + warning("Can not open dump file %s", name.c_str()); + return; + } + + for (uint i = 0; i < _scriptText.size(); i++) { + out.write(_scriptText[i]->line.c_str(), strlen(_scriptText[i]->line.c_str())); + out.writeByte('\n'); + } + + out.flush(); + out.close(); + } } Script::~Script() { diff --git a/engines/wage/script.h b/engines/wage/script.h index e796195b7f..0237ebea6e 100644 --- a/engines/wage/script.h +++ b/engines/wage/script.h @@ -52,7 +52,7 @@ namespace Wage { class Script { public: - Script(Common::SeekableReadStream *data); + Script(Common::SeekableReadStream *data, int num); ~Script(); private: diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp index a1d3f6e175..a7fce3d816 100644 --- a/engines/wage/world.cpp +++ b/engines/wage/world.cpp @@ -132,7 +132,7 @@ bool World::loadWorld(Common::MacResManager *resMan) { // Load global script res = resMan->getResource(MKTAG('G','C','O','D'), resArray[0]); - _globalScript = new Script(res); + _globalScript = new Script(res, -1); // TODO: read creator @@ -209,7 +209,7 @@ bool World::loadWorld(Common::MacResManager *resMan) { res = resMan->getResource(MKTAG('A','C','O','D'), *iter); if (res != NULL) - scene->_script = new Script(res); + scene->_script = new Script(res, *iter); res = resMan->getResource(MKTAG('A','T','X','T'), *iter); if (res != NULL) { -- cgit v1.2.3