Skip to content

Commit

Permalink
TOOLS: Added tool for creating HDFRAMES.DAT for Blade Runner
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 1, 2018
1 parent 7d14b3d commit ec9ec3b
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 11 deletions.
1 change: 1 addition & 0 deletions Makefile.common
Expand Up @@ -176,6 +176,7 @@ engines/sword2/sword2_clue.o: CPPFLAGS+=`pkg-config --cflags gtk+-2.0`

tools_OBJS := \
engines/agos/compress_agos.o \
engines/bladerunner/pack_bladerunner.o \
engines/gob/compress_gob.o \
engines/gob/extract_fascination_cd.o \
engines/kyra/compress_kyra.o \
Expand Down
34 changes: 24 additions & 10 deletions README
Expand Up @@ -54,19 +54,19 @@ Extraction Tools:

extract_cge
Unpacks Soltys and Sfinx game data files.

Example of usage:
./scummvm-tools-cli --tool extract_cge [-o outputdir] <inputfile>

pack_cge
Packs Soltys and Sfinx game data files.

Example of usage:
./scummvm-tools-cli --tool pack_cge [-o outputdir] <inputdir>

extract_cine
Unpacks Delphine's Cinematique engine's archive files.

Should work at least with Future Wars and Operation Stealth.
It seems to work also with Cruise for a Corpse. It accepts only
one input file. This may be either one of the archive file, in
Expand Down Expand Up @@ -94,7 +94,7 @@ Extraction Tools:

extract_kyra
Unpacks .PAK files from Kyrandia games.

It is also able to extract the installer package files from
Hand of Fate DOS floppy version. You should make sure you got
all WESTWOOD.### files for that, since they are one big package
Expand All @@ -109,7 +109,7 @@ Extraction Tools:

extract_loom_tg16
Extracts data files from the PC-Engine version of Loom.

Example of usage:
./scummvm-tools-cli --tool extract_loom_tg16 [-o outputdir] <infile>

Expand All @@ -132,7 +132,7 @@ Extraction Tools:

extract_mm_nes
Extracts data files from the NES version of Maniac Mansion.

Example of usage:
./scummvm-tools-cli --tool extract_mm_nes [-o outputdir] <infile.PRG>

Expand Down Expand Up @@ -177,7 +177,7 @@ Compression Tools:

Example of usage:
./scummvm-tools-cli --tool compress_gob [-o outputpath] -f <conf_file>

<conf file> is a .gob file generated by extract_gob_stk.
-f forces compression for all files.
The stick archive (STK/ITK/LTK) will be created in the directory
Expand Down Expand Up @@ -300,7 +300,7 @@ Compression Tools:

Example of usage:
./scummvm-tools-cli --tool compress_sword1 --vorbis -q 7 BS1/swordres.rif

NOTE: Only the PC and Mac versions are currently supported.
The PSX version is not supported by this tool.

Expand All @@ -316,9 +316,9 @@ Compression Tools:

compress_tinsel
Used to compress tinsel .smp files.

The corresponding .idx file must be part of the command.

Example of usage:
./scummvm-tools-cli --tool compress_tinsel [mode_params] [-o outputfile] <infile.smp> <infile.idx>
./scummvm-tools-cli --tool compress_tinsel --vorbis -q 9 ENGLISH.SMP ENGLISH.IDX
Expand Down Expand Up @@ -438,3 +438,17 @@ Encoder Tools:

Same as the above convert_dxa.bat, just for *nix-based systems.
It uses Wine to run RAD Game Tools.

Other Tools:
pack_bladerunner
Used to combine Blade Runner CDFRAMES.DAT files into HDFRAMES.DAT.

1. Copy CDFRAMES.DAT file from CD1 to some directory.

2. Copy CDFRAMES.DAT files from CDs 2-4 to the same directory
but name them CDFRAMES2.DAT - CDFRAMES4.DAT respectively.

3. Run the tool:
./scummvm-tools-cli --tool pack_bladerunner [-o outputfile] <inputdir>

4. Copy the resulting HDFRAMES.DAT file to the game directory.
184 changes: 184 additions & 0 deletions engines/bladerunner/pack_bladerunner.cpp
@@ -0,0 +1,184 @@
/* ScummVM Tools
*
* ScummVM Tools 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.
*/

#include <string.h>
#include "pack_bladerunner.h"
#include "common/endian.h"

PackBladeRunner::PackBladeRunner(const std::string &name) : Tool(name, TOOLTYPE_EXTRACTION) {
ToolInput input;
input.format = "/";
_inputPaths.push_back(input);

_outputToDirectory = true;

_shorthelp = "Used to combine Blade Runner CDFRAMES.DAT files into HDFRAMES.DAT.";
_helptext = "\nUsage: " + getName() + " [-o /path/to/output/dir/] /path/to/inputfiles\n";
}

void PackBladeRunner::execute() {
Common::Filename mainDir = _inputPaths[0].path;
// We always need to setup default output path, since there is no obligation to specify it
if (_outputPath.empty()) {
_outputPath.setFullPath("./");
}

_outputPath.setFullName("HDFRAMES.DAT");

const int kHDPageCount = 2480;
const int kPageSize = 0x20000;
int32 *hdPageOffsets;
int32 *cdPageOffsets;
byte *buf;
byte timestamp[4];

hdPageOffsets = (int32 *)malloc(kHDPageCount * 4);
cdPageOffsets = (int32 *)malloc(kHDPageCount * 4);
buf = (byte *)malloc(kPageSize);

Common::File out;

out.open(_outputPath, "wb");

for (int i = 0; i < kHDPageCount; i++)
hdPageOffsets[i] = -1;

Common::File in;
int curCD = 1;

mainDir.setFullName("CDFRAMES.DAT");
in.open(mainDir, "rb");

if (!in.isOpen()) {
warning("Cannot open file %s", mainDir.getName().c_str());
return;
}

in.read_noThrow(timestamp, 4); // reading timestamp
out.write(timestamp, 4);

WRITE_LE_UINT32(buf, kHDPageCount);
out.write(buf, 4);

for (int i = 0; i < kHDPageCount; i++) {
WRITE_LE_UINT32(&buf[i * 4], hdPageOffsets[i]);
}

out.write(buf, kHDPageCount * 4);

int hdCurrentPage = 0;

while (true) {
uint32 cdPageCount = in.readUint32LE();
printf("Reading %d pages from %s...\n", cdPageCount, mainDir.getFullName().c_str());

for (uint32 i = 0; i < cdPageCount; i++) {
cdPageOffsets[i] = in.readUint32LE();
}

int cdCurrentPage = 0;

while (cdCurrentPage < cdPageCount) {
while (cdCurrentPage < cdPageCount) {
int i;
for (i = 0; i < hdCurrentPage && cdPageOffsets[cdCurrentPage] != hdPageOffsets[i]; i++)
;
if (i == hdCurrentPage)
break;

in.seek(kPageSize, SEEK_CUR); // skip the page, we've copied it
cdCurrentPage++;
}

if (cdCurrentPage == cdPageCount)
break;

in.read_noThrow(buf, kPageSize);
out.write(buf, kPageSize);

hdPageOffsets[hdCurrentPage++] = cdPageOffsets[cdCurrentPage++];
}

in.close();

updateProgress(curCD, 4);

curCD++;

if (curCD == 5)
break;

char fname[20];
snprintf(fname, 20, "CDFRAMES%d.DAT", curCD);

mainDir.setFullName(fname);
in.open(mainDir, "rb");

if (!in.isOpen()) {
warning("Cannot open file %s", mainDir.getName().c_str());
return;
}

in.seek(4, SEEK_CUR); // skip timestamp
}

for (int i = hdCurrentPage; i < kHDPageCount; i++) {
out.write(buf, kPageSize);
}

#if 0
out.close();
_outputPath.setFullName("HDFRAMES.DAT");

out.open("HDFRAMES.DAT.HEADER");

out.write(timestamp, 4);

WRITE_LE_UINT32(buf, kHDPageCount);
out.write(buf, 4);
#else

out.seek(8, SEEK_SET);
#endif

for (int i = 0; i < kHDPageCount; i++) {
WRITE_LE_UINT32(&buf[i * 4], hdPageOffsets[i]);
}

out.write(buf, kHDPageCount * 4);

out.close();

free(buf);
free(cdPageOffsets);
free(hdPageOffsets);


printf("All done!\n");
printf("File is created in %s\n", _outputPath.getFullPath().c_str());
}

#ifdef STANDALONE_MAIN
int main(int argc, char *argv[]) {
PackBladeRunner bladerunner(argv[0]);
return bladerunner.run(argc, argv);
}
#endif
37 changes: 37 additions & 0 deletions engines/bladerunner/pack_bladerunner.h
@@ -0,0 +1,37 @@
/* ScummVM Tools
*
* ScummVM Tools 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.
*/

/* Construct HDFRAMES.DAT out of CDFRAMES.DAT for Blade Runner */

#ifndef PACK_BLADERUNNER_H
#define PACK_BLADERUNNER_H

#include "tool.h"
#include "common/array.h"

class PackBladeRunner : public Tool {
public:
PackBladeRunner(const std::string &name = "pack_bladerunner");

virtual void execute();
};

#endif
4 changes: 3 additions & 1 deletion tools.cpp
Expand Up @@ -47,6 +47,7 @@
#endif

#include "engines/agos/extract_agos.h"
#include "engines/bladerunner/pack_bladerunner.h"
#include "engines/cge/extract_cge.h"
#include "engines/cge/pack_cge.h"
#include "engines/cine/extract_cine.h"
Expand Down Expand Up @@ -88,6 +89,7 @@ Tools::Tools() {
#endif

_tools.push_back(new ExtractAgos());
_tools.push_back(new PackBladeRunner());
_tools.push_back(new ExtractCge());
_tools.push_back(new PackCge());
_tools.push_back(new ExtractCine());
Expand Down Expand Up @@ -115,7 +117,7 @@ Tools::ToolList Tools::inspectInput(const Common::Filename &filename, ToolType t
ToolList perfect_choices;
ToolList good_choices;
ToolList awful_choices;

Common::Filename dirname;
if (check_directory && !filename.directory())
dirname = filename.getPath();
Expand Down

0 comments on commit ec9ec3b

Please sign in to comment.