/* 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 3 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, see .
*
*/
#include "common/file.h"
#include "common/savefile.h"
#include "common/system.h"
#include "mm/shared/utils/strings.h"
#include "mm/mm1/console.h"
#include "mm/mm1/globals.h"
#include "mm/mm1/events.h"
#include "mm/mm1/game/spells_party.h"
namespace MM {
namespace MM1 {
Console::Console() : GUI::Debugger() {
registerCmd("dump_map", WRAP_METHOD(Console, cmdDumpMap));
registerCmd("dump_monsters", WRAP_METHOD(Console, cmdDumpMonsters));
registerCmd("dump_items", WRAP_METHOD(Console, cmdDumpItems));
registerCmd("map_string", WRAP_METHOD(Console, cmdMapString));
registerCmd("map", WRAP_METHOD(Console, cmdMap));
registerCmd("pos", WRAP_METHOD(Console, cmdPos));
registerCmd("intangible", WRAP_METHOD(Console, cmdIntangible));
registerCmd("cast", WRAP_METHOD(Console, cmdCast));
registerCmd("spells", WRAP_METHOD(Console, cmdSpellsAll));
registerCmd("encounter", WRAP_METHOD(Console, cmdEncounter));
registerCmd("encounters", WRAP_METHOD(Console, cmdEncounters));
registerCmd("specials", WRAP_METHOD(Console, cmdSpecials));
registerCmd("special", WRAP_METHOD(Console, cmdSpecial));
}
bool Console::cmdDumpMap(int argc, const char **argv) {
Common::File f;
Common::OutSaveFile *dest;
if (argc != 2) {
debugPrintf("%s \n", argv[0]);
} else {
int mapId = strToInt(argv[1]);
Maps::Map *map = g_globals->_maps.getMap(mapId);
// Dump the map data
if (f.open("mazedata.dta")) {
dest = g_system->getSavefileManager()->openForSaving(
Common::String::format("map%.2d-maze.bin", mapId), false);
assert(dest);
byte buffer[512];
f.seek(mapId * 512);
f.read(buffer, 512);
dest->write(buffer, 512);
dest->finalize();
delete dest;
f.close();
}
if (f.open(Common::String::format("%s.ovr", map->getName().c_str()))) {
int magicId = f.readUint16LE();
int codePtr = f.readUint16LE();
int codeSize = f.readUint16LE();
int dataPtr = f.readUint16LE();
int dataSize = f.readUint16LE();
int extrasSize = f.readUint16LE();
int startPtr = f.readUint16LE();
assert(magicId == 0xf2);
assert(startPtr >= codePtr &&
startPtr < (codePtr + codeSize));
dest = g_system->getSavefileManager()->openForSaving(
Common::String::format("map%.2d-code.bin", mapId), false);
byte *code = new byte[codeSize];
f.read(code, codeSize);
for (int i = 0; i < (codePtr % 16); ++i)
dest->writeByte(0);
dest->write(code, codeSize);
dest->flush();
delete dest;
delete[] code;
dest = g_system->getSavefileManager()->openForSaving(
Common::String::format("map%.2d-data.bin", mapId), false);
byte *data = new byte[dataSize];
f.read(data, dataSize);
dest->write(data, dataSize);
dest->flush();
delete dest;
delete[] data;
f.close();
debugPrintf("data: ptr=%xh, size=%xh\n", dataPtr, dataSize);
debugPrintf("code: ptr=%xh, size=%xh start=%xh\n",
codePtr, codeSize, startPtr);
debugPrintf("Extras size=%xh\n", extrasSize);
}
debugPrintf("Done.\n");
}
return true;
}
bool Console::cmdDumpMonsters(int argc, const char **argv) {
Common::File f;
Common::DumpFile df;
if (f.open("mm.exe")) {
if (df.open("monsters.txt")) {
f.seek(0x1b312);
for (int i = 0; i < 195; ++i) {
Common::String line = "\"";
for (int j = 0; j < 15; ++j)
line += f.readByte();
line += '"';
for (int j = 0; j < 16; ++j) {
line += ", ";
int val = (j == 7) ? f.readUint16LE() : f.readByte();
line += Common::String::format("%d", val);
}
df.writeString(line);
df.writeByte('\n');
}
df.close();
f.close();
debugPrintf("Done\n");
return true;
}
}
debugPrintf("Could not create\n");
return true;
}
bool Console::cmdDumpItems(int argc, const char **argv) {
Common::File f;
Common::DumpFile df;
Common::String line;
if (f.open("mm.exe")) {
if (df.open("items.txt")) {
f.seek(0x19b2a);
for (int i = 0; i < 255; ++i) {
if (i == 85) {
// Add the blank unused item line
line = "\" \", 0, 0, 0, 0, 0, 0, 0, 0, 0";
df.writeString(line);
df.writeByte('\n');
}
line = "\"";
for (int j = 0; j < 14; ++j)
line += f.readByte();
line += '"';
for (int j = 0; j < 9; ++j) {
line += ", ";
line += Common::String::format("%d",
(j == 6) ? f.readUint16BE() : f.readByte());
}
df.writeString(line);
df.writeByte('\n');
}
df.close();
f.close();
debugPrintf("Done\n");
return true;
}
}
debugPrintf("Could not create\n");
return true;
}
bool Console::cmdMapString(int argc, const char **argv) {
Common::File f;
if (argc != 3) {
debugPrintf("%s