From 9118f38b299f6ec5bfc6971306f5b99cf0a1fd6c Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Wed, 23 Jul 2014 02:43:38 +0300 Subject: MADS: Add support for FAB decompression in the dump_file command --- engines/mads/debugger.cpp | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/engines/mads/debugger.cpp b/engines/mads/debugger.cpp index 1ff42c5e2b..6bc6cf572d 100644 --- a/engines/mads/debugger.cpp +++ b/engines/mads/debugger.cpp @@ -21,6 +21,7 @@ */ #include "common/file.h" +#include "mads/compression.h" #include "mads/mads.h" #include "mads/debugger.h" @@ -169,8 +170,10 @@ bool Debugger::Cmd_ShowCodes(int argc, const char **argv) { } bool Debugger::Cmd_DumpFile(int argc, const char **argv) { - if (argc != 2) { - debugPrintf("Usage: %s \n", argv[0]); + if (argc < 2) { + debugPrintf("Usage: %s \n", argv[0]); + debugPrintf(" resource: the resource name\n"); + debugPrintf(" unpack: optional, when specified, the FAB/MADSPACK compressed resource is unpacked\n"); } else { Common::DumpFile outFile; Common::File inFile; @@ -179,10 +182,32 @@ bool Debugger::Cmd_DumpFile(int argc, const char **argv) { debugPrintf("Specified resource does not exist\n"); } else { outFile.open(argv[1]); - byte *data = new byte[inFile.size()]; - - inFile.read(data, inFile.size()); - outFile.write(data, inFile.size()); + bool unpack = ((argc >= 3) && !scumm_stricmp(argv[2], "unpack")); + + byte *data; + int totalSize = 0; + + if (!unpack) { + totalSize = inFile.size(); + data = new byte[totalSize]; + inFile.read(data, totalSize); + } else { + MadsPack dataPack(&inFile); + int count = dataPack.getCount(); + for (int i = 0; i < count; i++) { + totalSize += dataPack.getItem(i)._size; + } + data = new byte[totalSize]; + byte *ptr = data; + + for (int i = 0; i < count; i++) { + Common::SeekableReadStream *readStream = dataPack.getItemStream(i); + readStream->read(ptr, readStream->size()); + ptr += readStream->size(); + } + } + + outFile.write(data, totalSize); outFile.flush(); delete[] data; -- cgit v1.2.3