[Scummvm-cvs-logs] CVS: tools compress.c,NONE,1.1 compress.h,NONE,1.1 compress_queen.c,NONE,1.1 .cvsignore,1.14,1.15 Makefile,1.44,1.45 Makefile.mingw,1.23,1.24 README,1.30,1.31 compress_saga.c,1.1,1.2 compress_scumm_sou.c,1.1,1.2 compress_simon.c,1.1,1.2 compress_sword1.c,1.1,1.2 compress_sword2.c,1.1,1.2 extract-common.c,1.13,NONE extract.h,1.16,NONE queenrebuild.c,1.12,NONE

Max Horn fingolfin at users.sourceforge.net
Thu Dec 23 18:02:02 CET 2004


Update of /cvsroot/scummvm/tools
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5377

Modified Files:
	.cvsignore Makefile Makefile.mingw README compress_saga.c 
	compress_scumm_sou.c compress_simon.c compress_sword1.c 
	compress_sword2.c 
Added Files:
	compress.c compress.h compress_queen.c 
Removed Files:
	extract-common.c extract.h queenrebuild.c 
Log Message:
Finished renaming the compression tools

--- NEW FILE: compress.c ---
/* Scumm Tools
 * Copyright (C) 2003  The ScummVM Team
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/tools/compress.c,v 1.1 2004/12/24 02:00:52 fingolfin Exp $
 *
 */

#include "compress.h"

typedef struct  {
	uint32 minBitr;
	uint32 maxBitr; 
	bool abr;
	uint32 algqual;
	uint32 vbrqual;
	bool silent;
} lameparams;

typedef struct {
	int nominalBitr;
	int minBitr;
	int maxBitr;
	int quality;
	bool silent;
} oggencparams;

/* FIXME: This is an evil way to pass on the params to FLAC.
 It makes it near impossible to reliably pass default params to the
 encoder, which is why the ScummVM README has to tell the user to
 use this command:
   extract --best -b 1152 monster.sou
 If those are the best default options, then they should be *default*
 and the user shouldn't have to specify them.
*/
typedef struct {
	char * const* argv;
	int numArgs;
} flaccparams;

typedef struct {
    bool isLittleEndian, isStereo;
	uint8 bitsPerSample;
} rawtype;

lameparams encparms = { minBitrDef, maxBitrDef, false, algqualDef, vbrqualDef, 0 };
oggencparams oggparms = { -1, -1, -1, oggqualDef, 0 };
flaccparams flacparms;
rawtype	rawAudioType = { false, false, 8 };

const char *tempEncoded = TEMP_MP3;

void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample) {
	rawAudioType.isLittleEndian = isLittleEndian;
	rawAudioType.isStereo = isStereo;
	rawAudioType.bitsPerSample = bitsPerSample;
}

int getSampleRateFromVOCRate(int vocSR) {
	if (vocSR == 0xa5 || vocSR == 0xa6 || vocSR == 0x83) {
		return 11025;
	} else if (vocSR == 0xd2 || vocSR == 0xd3) {
		return 22050;
	} else {
		int sr = 1000000L / (256L - vocSR);
		warning("inexact sample rate used: %i (0x%x)", sr, vocSR);
		return sr;
	}
}

/* TODO: Check rawAudioType for Flac encoding */
void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode) {
	char fbuf[2048];
	char *tmp = fbuf;
	int i;
	bool err = false;

	switch (compmode) {
	case kVorbisMode:
		tmp += sprintf(tmp, "oggenc ");
		if (rawInput) {
			tmp += sprintf(tmp, "--raw --raw-chan=%d --raw-bits=%d ", (rawAudioType.isStereo ? 2 : 1), rawAudioType.bitsPerSample);
			tmp += sprintf(tmp, "--raw-rate=%i ", rawSamplerate);
			tmp += sprintf(tmp, "--raw-endianness=%d ", (rawAudioType.isLittleEndian ? 0 : 1));
		}

		if (oggparms.nominalBitr != -1)
			tmp += sprintf(tmp, "--bitrate=%i ", oggparms.nominalBitr);
		if (oggparms.minBitr != -1)
			tmp += sprintf(tmp, "--min-bitrate=%i ", oggparms.minBitr);
		if (oggparms.maxBitr != -1)
			tmp += sprintf(tmp, "--max-bitrate=%i ", oggparms.maxBitr);
		if (oggparms.silent)
			tmp += sprintf(tmp, "--quiet ");
		tmp += sprintf(tmp, "--quality=%i ", oggparms.quality);
		tmp += sprintf(tmp, "--output=%s ", outname);
		tmp += sprintf(tmp, "%s ", inname);
		err = system(fbuf) != 0;
		break;

	case kMP3Mode:
		tmp += sprintf(tmp, "lame -t -m m ");
		if (rawInput) {
			tmp += sprintf(tmp, "-r ");
			tmp += sprintf(tmp, "--bitwidth %d ", rawAudioType.bitsPerSample);
			if (rawAudioType.isLittleEndian)
				tmp += sprintf(tmp, "-x ");
			tmp += sprintf(tmp, "-s %d ", rawSamplerate);
		}

		if (encparms.abr)
			tmp += sprintf(tmp, "--abr %i ", encparms.minBitr);
		else
			tmp += sprintf(tmp, "--vbr-new -b %i ", encparms.minBitr);
		if (encparms.silent)
			tmp += sprintf(tmp, " --silent ");
		tmp += sprintf(tmp, "-q %i ", encparms.algqual);
		tmp += sprintf(tmp, "-V %i ", encparms.vbrqual);
		tmp += sprintf(tmp, "-B %i ", encparms.maxBitr);
		tmp += sprintf(tmp, "%s %s ", inname, outname);
		err = system(fbuf) != 0;
		break;

	case kFlacMode:
		/* --lax is needed to allow 11kHz, we dont need place for meta-tags, and no seektable */
		tmp += sprintf(tmp, "flac --lax --no-padding --no-seektable --no-ogg " );

		if (rawInput) {
			tmp += sprintf(tmp, "--force-raw-format --endian=little --sign=unsigned ");
			tmp += sprintf(tmp, "--bps=8 --channels=1 --sample-rate=%d ", rawSamplerate );
		}

		for (i = 0; i < flacparms.numArgs; i++) {
			/* Append optional encoder arguments */
			tmp += sprintf(tmp, "%s ", flacparms.argv[i]);
		}

		tmp += sprintf(tmp, "-o %s ", outname);
		tmp += sprintf(tmp, "%s ", inname);

		err = system(fbuf) != 0;
		break;
	}

	if (err) {
		printf("Got error from encoder. (check your parameters)\n");
		printf("Encoder Commandline: %s\n", fbuf );
		exit(-1);
	}
} 

void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode) {
	int length;
	FILE *f;
	char fbuf[2048];
	size_t size;

	fseek(input, -4, SEEK_CUR);
	length = readUint32LE(input);
	length += 8;
	fseek(input, -8, SEEK_CUR);

	/* Copy the WAV data to a temporary file */
	f = fopen(outName, "wb");
	while (length > 0) {
		size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : length, input);
		if (size <= 0)
			break;
		length -= size;
		fwrite(fbuf, 1, size, f);
	}
	fclose(f);

	/* Convert the WAV temp file to OGG/MP3 */
	encodeAudio(outName, false, -1, tempEncoded, compMode);
}

void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode) {
	FILE *f;
	int blocktype;
	int length;
	int sample_rate;
	int comp;
	char fbuf[2048];
	size_t size;
	int real_samplerate = -1;

	f = fopen(outName, "wb");

	while ((blocktype = fgetc(input))) {
		if (blocktype != 1) {
			/*
			   We only generate a warning, instead of erroring out, because
			   at least the monster.sou file of Full Throttle contains VOCs
			   with an invalid length field (value to small). So we encounter
			   the "block types" 0x80, 0x82 etc.. Not sure if there is another
			   (maybe even better) way to work around that... ?
			 */
			warning("Unsupported VOC block type: %02x", blocktype);
			break;
		}
	
		/* Sound Data */
		printf(" Sound Data\n");
		length = fgetc(input);
		length |= fgetc(input) << 8;
		length |= fgetc(input) << 16;
		length -= 2;
		sample_rate = fgetc(input);
		comp = fgetc(input);

		real_samplerate = getSampleRateFromVOCRate(sample_rate);

		printf(" - length = %d\n", length);
		printf(" - sample rate = %d (%02x)\n", real_samplerate, sample_rate);
		printf(" - compression = %s (%02x)\n",
			   (comp ==	   0 ? "8bits"   :
				(comp ==   1 ? "4bits"   :
				 (comp ==  2 ? "2.6bits" :
				  (comp == 3 ? "2bits"   :
								"Multi")))), comp);

		if (comp != 0)
			error("Cannot handle compressed VOC data");

		/* Copy the raw data to a temporary file */
		while (length > 0) {
			size = fread(fbuf, 1, length > sizeof(fbuf) ? sizeof(fbuf) : (uint32)length, input);
			if (size <= 0)
				break;
			length -= size;
			fwrite(fbuf, 1, size, f);
		}
	}

	fclose(f);
	
	assert(real_samplerate != -1);

	/* Convert the raw temp file to OGG/MP3 */
	encodeAudio(outName, true, real_samplerate, tempEncoded, compMode);
}

void process_mp3_parms(int argc, char *argv[], int i) {
	for (; i < argc; i++) {
		if (strcmp(argv[i], "--vbr") == 0) {
			encparms.abr=0;
		} else if (strcmp(argv[i], "--abr") == 0) {
			encparms.abr=1;
		} else if (strcmp(argv[i], "-b") == 0) {
			encparms.minBitr = atoi(argv[i + 1]);
			if ((encparms.minBitr % 8) != 0)
				encparms.minBitr -= encparms.minBitr % 8;
			if (encparms.minBitr >160)
				encparms.minBitr = 160;
			if (encparms.minBitr < 8)
				encparms.minBitr=8;
			i++;
		} else if (strcmp(argv[i], "-B") == 0) {
			encparms.maxBitr = atoi(argv[i + 1]);
			if ((encparms.maxBitr % 8) != 0)
				encparms.maxBitr -= encparms.maxBitr % 8;
			if (encparms.maxBitr > 160)
				encparms.maxBitr = 160;
			if (encparms.maxBitr < 8)
				encparms.maxBitr = 8;
			i++;
		} else if (strcmp(argv[i], "-V") == 0) {
			encparms.vbrqual = atoi(argv[i + 1]);
			if(encparms.vbrqual < 0)
				encparms.vbrqual = 0;
			if(encparms.vbrqual > 9)
				encparms.vbrqual = 9;
			i++;
		} else if (strcmp(argv[i], "-q") == 0) {
			encparms.algqual = atoi(argv[i + 1]);
			if (encparms.algqual < 0)
				encparms.algqual = 0;
			if (encparms.algqual > 9)
				encparms.algqual = 9;
			i++;
		} else if (strcmp(argv[i], "--silent") == 0) {
			encparms.silent = 1;
		} else if (strcmp(argv[i], "--help") == 0) {
			showhelp(argv[0]);
		} else if (argv[i][0] == '-') {
			showhelp(argv[0]);
		} else {
			break;
		}
	}
	if (i != (argc - 1)) {
		showhelp(argv[0]);
	}
}

void process_ogg_parms(int argc, char *argv[], int i) {
	for (; i < argc; i++) {
		if (strcmp(argv[i], "-b") == 0) {
			oggparms.nominalBitr = atoi(argv[i + 1]);
			i++;
		}
		else if (strcmp(argv[i], "-m") == 0) {
			oggparms.minBitr = atoi(argv[i + 1]);
			i++;
		}
		else if (strcmp(argv[i], "-M") == 0) {
			oggparms.maxBitr = atoi(argv[i + 1]);
			i++;
		}
		else if (strcmp(argv[i], "-q") == 0) {
			oggparms.quality = atoi(argv[i + 1]);
			i++;
		}
		else if (strcmp(argv[i], "--silent") == 0) {
			oggparms.silent = 1;
		}
		else if (strcmp(argv[i], "--help") == 0) {
			showhelp(argv[0]);
		}
		else if (argv[i][0] == '-') {
			showhelp(argv[0]);
		}
		else
			break;
	}
	if (i != argc - 1)
		showhelp(argv[0]);
}

void process_flac_parms(int argc, char *argv[], int i){
	flacparms.argv = &argv[i];
	flacparms.numArgs = argc - 1 - i;

	if (i >= argc)
		showhelp(argv[0]);
}


--- NEW FILE: compress.h ---
/* Scumm Tools
 * Copyright (C) 2003-2004 The ScummVM project
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/tools/compress.h,v 1.1 2004/12/24 02:00:52 fingolfin Exp $
 *
 */

#ifndef EXTRACT_H
#define EXTRACT_H

#include "util.h"


/* These are the defaults parameters for the Lame invocation */
#define minBitrDef 24
#define maxBitrDef 64
#define algqualDef 2
#define vbrqualDef 4

/* The default for oggenc invocation is to use the --quality option only */
#define oggqualDef 3

#define TEMP_WAV	"tempfile.wav"
#define TEMP_RAW	"tempfile.raw"
#define TEMP_MP3	"tempfile.mp3"
#define TEMP_OGG	"tempfile.ogg"
#define TEMP_FLAC	"tempfile.fla"

typedef enum { kMP3Mode, kVorbisMode, kFlacMode } CompressMode;

/*
 * Stuff which is in compress.c
 */

const extern char *tempEncoded;

extern void process_mp3_parms(int argc, char *argv[], int i);
extern void process_ogg_parms(int argc, char *argv[], int i);
extern void process_flac_parms(int argc, char *argv[], int i);

extern void extractAndEncodeVOC(const char *outName, FILE *input, CompressMode compMode);
extern void extractAndEncodeWAV(const char *outName, FILE *input, CompressMode compMode);

extern void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, CompressMode compmode);
extern void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
/*
 * Stuff which is in compress_scumm_sou.c / compress_simon.c / compress_sword2.c
 */
extern void showhelp(char *exename);


#endif

--- NEW FILE: compress_queen.c ---
/* QueenRebuild - Rebuild QUEEN.1 file to contain Resource Table (and optionally compress sound & speech)
 * Copyright (C) 2003  The ScummVM Team
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header: /cvsroot/scummvm/tools/compress_queen.c,v 1.1 2004/12/24 02:00:52 fingolfin Exp $
 *
 */

#include "util.h"

static const uint32 QTBL = 'QTBL';

#define INPUT_TBL	"queen.tbl"
#define FINAL_OUT	"queen.1c"

#define TEMP_DAT	"tempfile.dat"
#define TEMP_TBL	"tempfile.tbl"
#define TEMP_SB		"tempfile.sb"

#define TEMP_MP3	"tempfile.mp3"
#define TEMP_OGG	"tempfile.ogg"
#define TEMP_FLAC	"tempfile.fla"

const char *tempEncoded;

#define CURRENT_TBL_VERSION	1
#define EXTRA_TBL_HEADER 8
#define SB_HEADER_SIZE	110


enum {
	COMPRESSION_NONE = 0,
	COMPRESSION_MP3 = 1,
	COMPRESSION_OGG = 2,
	COMPRESSION_FLAC = 3
};

enum {
	VER_ENG_FLOPPY   = 0,
	VER_ENG_TALKIE   = 1,
	VER_FRE_FLOPPY   = 2,
	VER_FRE_TALKIE   = 3,
	VER_GER_FLOPPY   = 4,
	VER_GER_TALKIE   = 5,
	VER_ITA_FLOPPY   = 6,
	VER_ITA_TALKIE   = 7,
	VER_SPA_TALKIE   = 8,
	VER_HEB_TALKIE   = 9,
	VER_DEMO_PCGAMES = 10,
	VER_DEMO         = 11,
	VER_INTERVIEW    = 12,

	VER_NUMBER       = 13
};

struct GameVersion {
	char versionString[6];
	uint8 isFloppy;
	uint8 isDemo;
	uint32 tableOffset;
	uint32 dataFileSize;
};

struct {
	char filename[13];
	uint8 bundle;
	uint32 offset;
	uint32 size;
} entry;

struct {
	uint8	compression;
	uint16	entries;
} versionExtra;

struct PatchFile {
	const char *filename;
	char lang;
};

const struct GameVersion gameVersions[] = {
	{ "PEM10", 1, 0, 0x00000008,  22677657 },
	{ "CEM10", 0, 0, 0x0000584E, 190787021 },
	{ "PFM10", 1, 0, 0x0002CD93,  22157304 },
	{ "CFM10", 0, 0, 0x00032585, 186689095 },
	{ "PGM10", 1, 0, 0x00059ACA,  22240013 },
	{ "CGM10", 0, 0, 0x0005F2A7, 217648975 },
	{ "PIM10", 1, 0, 0x000866B1,  22461366 },
	{ "CIM10", 0, 0, 0x0008BEE2, 190795582 },
	{ "CSM10", 0, 0, 0x000B343C, 190730602 },
	{ "CHM10", 0, 0, 0x000DA981, 190705558 },
	{ "PE100", 1, 1, 0x00101EC6,   3724538 },
	{ "PE100", 1, 1, 0x00102B7F,   3732177 },
	{ "PEint", 1, 1, 0x00103838,   1915913 }
};

const struct PatchFile patchFiles[] = {
	{ "CHIEF1.DOG", 'F' },
	{ "CHIEF2.DOG", 'F' },
	{ "BUD1.DOG",   'I' }
};

const struct GameVersion *version;


void showhelp(char *exename)
{
	printf("\nUsage: %s [--mp3/--ogg/--flac <args>] queen.1\n", exename);
	printf("\nParams:\n");
	printf(" --mp3 <args>         encode to MP3 format\n"); 
	printf(" --ogg <args>         encode to Ogg Vorbis Format\n");
	printf(" --flac <args>        encode to Flac Format\n");
	printf("                      (Optional: <args> are passed on to the encoder)\n");
	printf("\nExample: %s --mp3 -q 5 queen.1\n", exename);
	exit(2);
}

const struct GameVersion *detectGameVersion(uint32 size) {
	const struct GameVersion *pgv = gameVersions;
	int i;
	for (i = 0; i < VER_NUMBER; ++i, ++pgv) {
		if (pgv->dataFileSize == size) {
			return pgv;
		}
 	}
	printf("Unknown/unsupported FOTAQ version!\n");
	exit(1);
	return NULL;
}

void checkOpen(FILE *fp, const char *filename) {
	if (!fp) {
		printf("Cannot open file: %s\n", filename);
		exit(-1);
	}
}

void fromFileToFile(FILE *in, FILE *out, uint32 amount) {
	char fBuf[2048];
	uint32 numRead;
	while (amount > 0) {
		numRead = fread(fBuf, 1, amount > 2048 ? 2048 : amount, in);
		if (numRead <= 0)
			break;
		amount -= numRead;
		fwrite(fBuf, 1, numRead, out);
	}
}

void createFinalFile(void) {
	FILE *inTbl, *inData, *outFinal;
	int i;
	uint32 dataStartOffset;
	uint32 dataSize;

	inTbl = fopen(TEMP_TBL, "rb");
	checkOpen(inTbl, TEMP_TBL);
	inData = fopen(TEMP_DAT, "rb");
	checkOpen(inData, TEMP_DAT);
	outFinal = fopen(FINAL_OUT, "wb");
	checkOpen(outFinal, FINAL_OUT);
	
	dataStartOffset = fileSize(inTbl) + EXTRA_TBL_HEADER;
	dataSize = fileSize(inData);

	fseek(inTbl, 7, SEEK_SET);	/* Skip past header */

	/* Write new header */
	writeUint32BE(outFinal, QTBL);
	fwrite(version->versionString, 6, 1, outFinal);
	writeByte(outFinal, version->isFloppy);
	writeByte(outFinal, version->isDemo);	
	writeByte(outFinal, versionExtra.compression);
	writeUint16BE(outFinal, versionExtra.entries);

	for (i = 0; i < versionExtra.entries; i++) {
		fromFileToFile(inTbl, outFinal, 12);
		writeByte(outFinal, readByte(inTbl));
		writeUint32BE(outFinal, dataStartOffset + readUint32BE(inTbl));
		writeUint32BE(outFinal, readUint32BE(inTbl));		
	}

	/* Append contents of temporary datafile to final datafile */
	fromFileToFile(inData, outFinal, dataSize);

	fclose(inTbl);
	fclose(inData);
	fclose(outFinal);

	/* Cleanup */
	unlink(TEMP_TBL);
	unlink(TEMP_DAT);
}

int main(int argc, char *argv[])
{
	FILE *inputData, *inputTbl, *outputTbl, *outputData, *tmpFile, *compFile;
	uint8 compressionType = COMPRESSION_NONE;
	char tmp[5];
	char sysBuf[1024];
	char *ptr = sysBuf;
	int size, i = 1;
	uint32 prevOffset;

	if (argc < 2 || (strcmp(argv[1], "--mp3") != 0 && strcmp(argv[1], "--ogg") != 0 && strcmp(argv[1], "--flac") != 0))
		showhelp(argv[0]);
	
	if (strcmp(argv[1], "--mp3") == 0) {
		compressionType = COMPRESSION_MP3;
		tempEncoded = TEMP_MP3;
		i++;
		ptr += sprintf(ptr, "lame -r -h -s 11 --bitwidth 8 -m m ");
		for (; i < (argc - 1); i++) {
			/* Append optional encoder arguments */
			ptr += sprintf(ptr, "%s ", argv[i]);
		}
		ptr += sprintf(ptr, "%s %s", TEMP_SB, tempEncoded);
	}

	if (strcmp(argv[1], "--ogg") == 0) {
		compressionType = COMPRESSION_OGG;
		tempEncoded = TEMP_OGG;
		i++;
		ptr += sprintf(ptr, "oggenc -r -B 8 -C 1 -R 11025 %s -o %s ", TEMP_SB, tempEncoded);
		for (; i < (argc - 1); i++) {
			/* Append optional encoder arguments */
			ptr += sprintf(ptr, "%s ", argv[i]);
		}
	}

	if (strcmp(argv[1], "--flac") == 0) {
		compressionType = COMPRESSION_FLAC;
		tempEncoded = TEMP_FLAC;
		i++;
		ptr += sprintf(ptr, "flac --force-raw-format --endian=little --sign=unsigned --bps=8 --channels=1 --sample-rate=11025 " );
		ptr += sprintf(ptr, "--no-padding --lax --no-seektable --no-ogg " );
		for (; i < (argc - 1); i++) {
			/* Append optional encoder arguments */
			ptr += sprintf(ptr, "%s ", argv[i]);
		}

		ptr += sprintf(ptr, "-o %s %s", tempEncoded, TEMP_SB );
	}

	/* Open input file (QUEEN.1) */
	inputData = fopen(argv[argc-1], "rb");
	checkOpen(inputData, argv[argc-1]);

	/* Open TBL file (QUEEN.TBL) */
	inputTbl = fopen(INPUT_TBL, "rb");
	checkOpen(inputTbl, INPUT_TBL);

	size = fileSize(inputData);
	fread(tmp, 1, 4, inputTbl);
	tmp[4] = '\0';
	if (memcmp(tmp, "QTBL", 4)) {
		printf("Invalid TBL file!\n");
		exit(-1);
	} 

	if (readUint32BE(inputTbl) != CURRENT_TBL_VERSION) {
		printf("Error: You are using an incorrect (outdated?) version of the queen.tbl file\n");
		exit(1);
	}
	version = detectGameVersion(size);
	fseek(inputTbl, version->tableOffset, SEEK_SET); 

	versionExtra.compression = compressionType;
	versionExtra.entries = readUint16BE(inputTbl);
		
	outputTbl = fopen(TEMP_TBL, "wb");
	checkOpen(outputTbl, TEMP_TBL);	

	outputData = fopen(TEMP_DAT, "wb");
	checkOpen(outputData, TEMP_DAT);
	
	/* Write tablefile header */
	writeUint32BE(outputTbl, QTBL);
	writeByte(outputTbl, versionExtra.compression);
	writeUint16BE(outputTbl, versionExtra.entries);

	for (i = 0; i < versionExtra.entries; i++) {
		prevOffset = ftell(outputData);
		
		/* Read entry */
		fread(entry.filename, 1, 12, inputTbl);
		entry.filename[12] = '\0';
		entry.bundle = readByte(inputTbl);
		entry.offset = readUint32BE(inputTbl);
		entry.size = readUint32BE(inputTbl);

		printf("Processing entry: %s\n", entry.filename);
		fseek(inputData, entry.offset, SEEK_SET);

		if (versionExtra.compression && strstr(entry.filename, ".SB")) { /* Do we want to compress? */
			/* Read in .SB */
			tmpFile = fopen(TEMP_SB, "wb");
			fseek(inputData, entry.offset + SB_HEADER_SIZE, SEEK_SET);
			fromFileToFile(inputData, tmpFile, entry.size - SB_HEADER_SIZE);
			fclose(tmpFile);

			/* Invoke encoder */
			if (system(sysBuf)) {
				printf("Got error from encoder. (check your parameters)\n");
				unlink(TEMP_SB);
				exit(-1);
			}

			/* Append MP3/OGG to data file */
			compFile = fopen(tempEncoded, "rb");
			entry.size = fileSize(compFile);
			fromFileToFile(compFile, outputData, entry.size);
			fclose(compFile);

			/* Delete temporary files */
			unlink(TEMP_SB);
			unlink(tempEncoded);
		} else {
			/* Non .SB file */	
			bool patched = false;
			/* Check for external files */
			uint8 j;
			for (j = 0; j < ARRAYSIZE(patchFiles); ++j) {
				const struct PatchFile *pf = &patchFiles[j];
				if (version->versionString[1] == pf->lang && strcmp(pf->filename, entry.filename) == 0) {
					/* XXX patched data files are supposed to be in cwd */
					FILE *fpPatch = fopen(pf->filename, "rb");
					if (fpPatch) {
						entry.size = fileSize(fpPatch);
						printf("Patching entry, new size = %d bytes\n", entry.size);
						fromFileToFile(fpPatch, outputData, entry.size);
						fclose(fpPatch);
						patched = true;
					}
					break;
				}
			}
			if (!patched) {
				fromFileToFile(inputData, outputData, entry.size);
			}
		}

		/* Write entry to table */
		fwrite(entry.filename, 12, 1, outputTbl);
		writeByte(outputTbl, entry.bundle);
		writeUint32BE(outputTbl, prevOffset);
		writeUint32BE(outputTbl, entry.size);	
	}	

	/* Close files */
	fclose(outputTbl);
	fclose(outputData);
	fclose(inputTbl);
	fclose(inputData);

	/* Merge the temporary table and temporary datafile to create final file */
	createFinalFile();
	
	return 0;
}

Index: .cvsignore
===================================================================
RCS file: /cvsroot/scummvm/tools/.cvsignore,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- .cvsignore	24 Dec 2004 01:44:28 -0000	1.14
+++ .cvsignore	24 Dec 2004 02:00:52 -0000	1.15
@@ -1,3 +1,4 @@
+compress_queen
 compress_saga
 compress_san
 compress_scumm_sou
@@ -10,6 +11,5 @@
 kyra_unpak
 loom_tg16_extract
 mm_nes_extract
-queenrebuild
 rescumm
 simon1decr

Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- Makefile	24 Dec 2004 01:44:28 -0000	1.44
+++ Makefile	24 Dec 2004 02:00:52 -0000	1.45
@@ -16,21 +16,21 @@
 # CFLAGS += -DSCUMM_BIG_ENDIAN
 
 TARGETS := \
+	compress_queen$(EXEEXT) \
+	compress_saga$(EXEEXT) \
 	compress_san$(EXEEXT) \
+	compress_scumm_sou$(EXEEXT) \
+	compress_simon$(EXEEXT) \
+	compress_sword1$(EXEEXT) \
+	compress_sword2$(EXEEXT) \
+	dekyra$(EXEEXT) \
 	descumm$(EXEEXT) \
 	desword2$(EXEEXT) \
-	dekyra$(EXEEXT) \
 	kyra_unpak$(EXEEXT) \
-	compress_scumm_sou$(EXEEXT) \
 	loom_tg16_extract$(EXEEXT) \
 	mm_nes_extract$(EXEEXT) \
-	queenrebuild$(EXEEXT) \
 	rescumm$(EXEEXT) \
-	simon1decr$(EXEEXT) \
-	compress_simon$(EXEEXT) \
-	compress_sword1$(EXEEXT) \
-	compress_sword2$(EXEEXT) \
-	compress_saga$(EXEEXT)
+	simon1decr$(EXEEXT)
 
 all: $(TARGETS)
 
@@ -49,7 +49,7 @@
 kyra_unpak$(EXEEXT): kyra_unpak.o util.o
 	$(CXX) $(LDFLAGS) -o $@ $+
 
-compress_scumm_sou$(EXEEXT): compress_scumm_sou.o extract-common.o util.o
+compress_scumm_sou$(EXEEXT): compress_scumm_sou.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
 loom_tg16_extract$(EXEEXT): loom_tg16_extract.o
@@ -58,30 +58,30 @@
 mm_nes_extract$(EXEEXT): mm_nes_extract.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
-queenrebuild$(EXEEXT): queenrebuild.o util.o
+compress_queen$(EXEEXT): compress_queen.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
 rescumm$(EXEEXT): rescumm.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
-compress_saga$(EXEEXT): compress_saga.o extract-common.o util.o
+compress_saga$(EXEEXT): compress_saga.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
 simon1decr$(EXEEXT): simon1decr.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
-compress_simon$(EXEEXT): compress_simon.o extract-common.o util.o
+compress_simon$(EXEEXT): compress_simon.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
-compress_sword1$(EXEEXT): compress_sword1.o extract-common.o util.o
+compress_sword1$(EXEEXT): compress_sword1.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
-compress_sword2$(EXEEXT): compress_sword2.o extract-common.o util.o
+compress_sword2$(EXEEXT): compress_sword2.o compress.o util.o
 	$(CC) $(LDFLAGS) -o $@ $+
 
 descumm.o descumm6.o descumm-common.o descumm-tool.o: descumm.h util.h
-compress_saga.o compress_scumm_sou.o compress_simon.o compress_sword1.o compress_sword2.o extract-common.o: util.h extract.h
-desword2.o queenrebuild.o rescumm.o util.o: util.h
+compress_saga.o compress_scumm_sou.o compress_simon.o compress_sword1.o compress_sword2.o compress.o: util.h compress.h
+desword2.o compress_queen.o rescumm.o util.o: util.h
 
 clean:
 	rm -f *.o $(TARGETS)

Index: Makefile.mingw
===================================================================
RCS file: /cvsroot/scummvm/tools/Makefile.mingw,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- Makefile.mingw	24 Dec 2004 01:44:28 -0000	1.23
+++ Makefile.mingw	24 Dec 2004 02:00:52 -0000	1.24
@@ -8,6 +8,7 @@
 install:   all
 	mkdir -p $(SCUMMVMPATH)
 	mkdir -p $(SCUMMVMPATH)/tools
+	strip compress_queen.exe -o $(SCUMMVMPATH)/tools/compress_queen.exe
 	strip compress_saga.exe -o $(SCUMMVMPATH)/tools/compress_saga.exe
 	strip compress_san.exe -o $(SCUMMVMPATH)/tools/compress_san.exe
 	strip compress_scumm_sou.exe -o $(SCUMMVMPATH)/tools/compress_scumm_sou.exe
@@ -20,7 +21,6 @@
 	strip kyra_unpak.exe -o $(SCUMMVMPATH)/tools/kyra_unpak.exe
 	strip loom_tg16_extract.exe -o $(SCUMMVMPATH)/tools/loom_tg16_extract.exe
 	strip mm_nes_extract.exe -o $(SCUMMVMPATH)/tools/mm_nes_extract.exe
-	strip queenrebuild.exe -o $(SCUMMVMPATH)/tools/queenrebuild.exe
 	strip rescumm.exe -o $(SCUMMVMPATH)/tools/rescumm.exe
 	strip simon1decr.exe -o $(SCUMMVMPATH)/tools/simon1decr.exe
 	cp COPYING $(SCUMMVMPATH)/tools/copying.txt

Index: README
===================================================================
RCS file: /cvsroot/scummvm/tools/README,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- README	24 Dec 2004 01:44:28 -0000	1.30
+++ README	24 Dec 2004 02:00:52 -0000	1.31
@@ -30,7 +30,7 @@
                 Used to compress .sou files to .so3 (MP3), .sog (Vorbis),
                 or .sof (FLAC).
 
-        queenrebuild
+        compress_queen
                 Used to rebuild the datafile of Flight of the Amazon Queen,
                 to allow optional MP3/Ogg/FLAC compression.
 

Index: compress_saga.c
===================================================================
RCS file: /cvsroot/scummvm/tools/compress_saga.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- compress_saga.c	24 Dec 2004 01:16:52 -0000	1.1
+++ compress_saga.c	24 Dec 2004 02:00:52 -0000	1.2
@@ -21,7 +21,7 @@
  */
 
 #include <stdio.h>
-#include "extract.h"
+#include "compress.h"
 
 typedef struct RECORD {
 	uint32 offset;

Index: compress_scumm_sou.c
===================================================================
RCS file: /cvsroot/scummvm/tools/compress_scumm_sou.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- compress_scumm_sou.c	24 Dec 2004 01:44:16 -0000	1.1
+++ compress_scumm_sou.c	24 Dec 2004 02:00:52 -0000	1.2
@@ -19,7 +19,7 @@
  *
  */
 
-#include "extract.h"
+#include "compress.h"
 
 
 static const char f_hdr[] = {

Index: compress_simon.c
===================================================================
RCS file: /cvsroot/scummvm/tools/compress_simon.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- compress_simon.c	24 Dec 2004 01:16:52 -0000	1.1
+++ compress_simon.c	24 Dec 2004 02:00:52 -0000	1.2
@@ -19,7 +19,7 @@
  *
  */
 
-#include "extract.h"
+#include "compress.h"
 
 static FILE *input, *output_idx, *output_snd;
 

Index: compress_sword1.c
===================================================================
RCS file: /cvsroot/scummvm/tools/compress_sword1.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- compress_sword1.c	24 Dec 2004 01:16:52 -0000	1.1
+++ compress_sword1.c	24 Dec 2004 02:00:52 -0000	1.2
@@ -19,7 +19,7 @@
  *
  */
 
-#include "extract.h"
+#include "compress.h"
 
 #define READ_BE_UINT32(x) \
 	((((uint8*)(x))[0] << 24) | (((uint8*)(x))[1] << 16) | (((uint8*)(x))[2] << 8) | (((uint8*)(x))[3] << 0))
@@ -523,7 +523,7 @@
 }
 
 void processArgs(int argc, char *argv[], int i, CompressMode mode) {
-	/* HACK: the functions in extract-common expect the last argument to be a filename. */
+	/* HACK: the functions in compress.c expect the last argument to be a filename. */
 	/*       As we don't expect one, we simply add a dummy argument to the list. */
 	char **args;
 	int cnt;

Index: compress_sword2.c
===================================================================
RCS file: /cvsroot/scummvm/tools/compress_sword2.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- compress_sword2.c	24 Dec 2004 01:16:52 -0000	1.1
+++ compress_sword2.c	24 Dec 2004 02:00:52 -0000	1.2
@@ -19,7 +19,7 @@
  *
  */
 
-#include "extract.h"
+#include "compress.h"
 
 #define TEMP_IDX	"tempfile.idx"
 #define TEMP_DAT	"tempfile.dat"

--- extract-common.c DELETED ---

--- extract.h DELETED ---

--- queenrebuild.c DELETED ---





More information about the Scummvm-git-logs mailing list