[Scummvm-cvs-logs] SF.net SVN: scummvm:[33358] tools/trunk

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Mon Jul 28 10:12:11 CEST 2008


Revision: 33358
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33358&view=rev
Author:   lordhoto
Date:     2008-07-28 08:12:10 +0000 (Mon, 28 Jul 2008)

Log Message:
-----------
Fix for bug #2027682 "TOOLS: compress_kyra crashes with kyra3 and --kyra3 not used".

Modified Paths:
--------------
    tools/trunk/README
    tools/trunk/compress_kyra.cpp
    tools/trunk/kyra_pak.cpp
    tools/trunk/kyra_pak.h

Modified: tools/trunk/README
===================================================================
--- tools/trunk/README	2008-07-28 07:20:55 UTC (rev 33357)
+++ tools/trunk/README	2008-07-28 08:12:10 UTC (rev 33358)
@@ -91,12 +91,9 @@
 
                 Examples of usage:
                 compress_kyra [params] GEMCUT.VRM inputdir/ outputdir/
+                compress_kyra [params] BATH1.AUD inputdir/ outputdir/
                 compress_kyra [params] ANYTALK.TLK inputdir/ outputdir/
 
-                For The Legend of Kyrandia: Malcolm's Revenge use: 
-                compress_kyra --kyra3 [params] BATH1.AUD inputdir/ outputdir/
-                compress_kyra --kyra3 [params] ANYTALK.TLK inputdir/ outputdir/
-
                 Note: You have to keep the file extension the tool will append
                 else it will NOT work. Use it as shown above, copy all speech
                 files to a directory and let the tool put the output file in

Modified: tools/trunk/compress_kyra.cpp
===================================================================
--- tools/trunk/compress_kyra.cpp	2008-07-28 07:20:55 UTC (rev 33357)
+++ tools/trunk/compress_kyra.cpp	2008-07-28 08:12:10 UTC (rev 33358)
@@ -26,6 +26,7 @@
 static void showhelp(const char *exename);
 static void process(const char *infile, const char *output);
 static void processKyra3(const char *infile, const char *output);
+static bool detectKyra3File(const char *infile);
 
 #define OUTPUT_MP3 ".VO3"
 #define OUTPUT_OGG ".VOG"
@@ -45,7 +46,6 @@
 	int i = 0;
 
 	/* Compression mode */
-	bool isKyra3 = false;
 	gCompMode = kMP3Mode;
 	i = 1;
 
@@ -56,8 +56,6 @@
 			gCompMode = kVorbisMode;
 		else if (strcmp(argv[i], "--flac") == 0)
 			gCompMode = kFlacMode;
-		else if (strcmp(argv[i], "--kyra3") == 0)
-			isKyra3 = true;
 		else
 			break;
 	}
@@ -89,6 +87,7 @@
 	if (scumm_stricmp(inputFile, outputFile) == 0)
 		error("infile and outfile are the same file");
 
+	bool isKyra3 = detectKyra3File(inputFile); 
 	if (!isKyra3)
 		process(inputFile, outputFile);
 	else
@@ -101,8 +100,6 @@
 	printf("\nUsage: %s [params] [mode params] <file> <inputdir> <outputdir>\n", exename);
 
 	printf("\nParams:\n");
-	printf(" --kyra3      compress files from The Legend of Kyrandia: Book Three: Malcolm's Revenge\n");
-	printf("\n");
 	printf(" --mp3        encode to MP3 format (default)\n");
 	printf(" --vorbis     encode to Vorbis format\n");
 	printf(" --flac       encode to Flac format\n");
@@ -501,3 +498,42 @@
 	}
 }
 
+bool detectKyra3File(const char *infile) {
+	if (hasSuffix(infile, ".AUD")) {
+		return true;
+	} else if (hasSuffix(infile, ".VRM")) {
+		if (!PAKFile::isPakFile(infile))
+			error("Unknown filetype of file: '%s'", infile);
+		return false;
+	} else if (hasSuffix(infile, ".TLK")) {
+		if (PAKFile::isPakFile(infile))
+			return false;
+
+		FILE *f = fopen(infile, "rb");
+		if (!f)
+			error("Couldn't open file '%s'", infile);
+
+		uint16 entries = readUint16LE(f);
+		uint32 entryTableSize = (entries * 8);
+		const uint32 filesize = fileSize(f);
+
+		if (entryTableSize + 2 > filesize) {
+			fclose(f);
+			error("Unknown filetype of file: '%s'", infile);
+		}
+
+		uint32 offset = 0;
+		for (uint i = 0; i < entries; ++i) {
+			readUint32LE(f);
+			offset = readUint32LE(f);
+
+			if (offset > filesize)
+				error("Unknown filetype of file: '%s'", infile);
+		}
+
+		return true;
+	}
+
+	error("Unknown filetype of file: '%s'", infile);
+}
+

Modified: tools/trunk/kyra_pak.cpp
===================================================================
--- tools/trunk/kyra_pak.cpp	2008-07-28 07:20:55 UTC (rev 33357)
+++ tools/trunk/kyra_pak.cpp	2008-07-28 08:12:10 UTC (rev 33358)
@@ -22,6 +22,62 @@
 
 #include "kyra_pak.h"
 
+bool PAKFile::isPakFile(const char *filename) {
+	FILE *f = fopen(filename, "rb");
+	if (!f)
+		error("Couldn't open file '%s'", filename);
+
+	uint32 filesize = fileSize(f);
+	uint32 offset = 0;
+	bool switchEndian = false;
+	bool firstFile = true;
+
+	offset = readUint32LE(f);
+	if (offset > filesize) {
+		switchEndian = true;
+		offset = SWAP_32(offset);
+	}
+
+	char lastFilenameByte = 0;
+	while (!feof(f)) {
+		// The start offset of a file should never be in the filelist
+		if (offset < ftell(f) || offset > filesize) {
+			fclose(f);
+			return false;
+		}
+
+		byte c = 0;
+
+		lastFilenameByte = 0;
+		while (!feof(f) && (c = readByte(f)) != 0)
+			lastFilenameByte = c;
+
+		if (feof(f)) {
+			fclose(f);
+			return false;
+		}
+
+		// Quit now if we encounter an empty string
+		if (!lastFilenameByte) {
+			if (firstFile) {
+				fclose(f);
+				return false;
+			} else {
+				break;
+			}
+		}
+
+		firstFile = false;
+		offset = switchEndian ? readUint32BE(f) : readUint32LE(f);
+
+		if (!offset || offset == filesize)
+			break;
+	}
+
+	fclose(f);
+	return true;
+}
+
 bool PAKFile::loadFile(const char *file, const bool isAmiga) {
 	_isAmiga = isAmiga;
 	if (!file)
@@ -51,7 +107,7 @@
 	uint8* position = buffer + 4;
 
 	while (true) {
-		uint32 strlgt = strlen((const char*)position);
+		uint32 strlgt = (uint32)strlen((const char*)position);
 		currentName = (const char*)position;
 
 		if (!(*currentName))
@@ -161,7 +217,7 @@
 }
 
 bool PAKFile::addFile(const char *name, uint8 *data, uint32 size) {
-	if (_fileList && _fileList->findEntry(name) || (_links && _links->findSrcEntry(name))) {
+	if ((_fileList && _fileList->findEntry(name)) || (_links && _links->findSrcEntry(name))) {
 		error("entry '%s' already exists");
 		return false;
 	}

Modified: tools/trunk/kyra_pak.h
===================================================================
--- tools/trunk/kyra_pak.h	2008-07-28 07:20:55 UTC (rev 33357)
+++ tools/trunk/kyra_pak.h	2008-07-28 08:12:10 UTC (rev 33358)
@@ -31,6 +31,8 @@
 	PAKFile() : _fileList(0), _isAmiga(false), _links(0) {}
 	~PAKFile() { delete _fileList; }
 
+	static bool isPakFile(const char *file);
+
 	bool loadFile(const char *file, const bool isAmiga);
 	bool saveFile(const char *file);
 	void clearFile() { delete _fileList; _fileList = 0; }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list