[Scummvm-cvs-logs] SF.net SVN: scummvm: [31368] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Apr 3 21:56:45 CEST 2008


Revision: 31368
          http://scummvm.svn.sourceforge.net/scummvm/?rev=31368&view=rev
Author:   lordhoto
Date:     2008-04-03 12:56:45 -0700 (Thu, 03 Apr 2008)

Log Message:
-----------
- Added support for filename length > 64 in static resource code.
- Updated warning when 'INDEX' is not found
- Added filesize check for 'INDEX' file

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/resource.h
    scummvm/trunk/engines/kyra/staticres.cpp

Modified: scummvm/trunk/engines/kyra/resource.h
===================================================================
--- scummvm/trunk/engines/kyra/resource.h	2008-04-03 18:31:30 UTC (rev 31367)
+++ scummvm/trunk/engines/kyra/resource.h	2008-04-03 19:56:45 UTC (rev 31368)
@@ -282,6 +282,7 @@
 	void freeRoomTable(void *&ptr, int &size);
 	void freePaletteTable(void *&ptr, int &size);
 
+	const char *getFilename(const char *name);
 	uint8 *getFile(const char *name, int &size);
 
 	enum kResTypes {

Modified: scummvm/trunk/engines/kyra/staticres.cpp
===================================================================
--- scummvm/trunk/engines/kyra/staticres.cpp	2008-04-03 18:31:30 UTC (rev 31367)
+++ scummvm/trunk/engines/kyra/staticres.cpp	2008-04-03 19:56:45 UTC (rev 31368)
@@ -268,10 +268,16 @@
 	int tempSize = 0;
 	uint8 *temp = getFile("INDEX", tempSize);
 	if (!temp) {
-		warning("no matching INDEX file found");
+		warning("no matching INDEX file found ('%s')", getFilename("INDEX"));
 		return false;
 	}
 
+	if (tempSize != 3*4) {
+		delete [] temp;
+		warning("'%s' has illegal filesize %d", getFilename("INDEX"), tempSize);
+		return false;
+	}
+
 	uint32 version = READ_BE_UINT32(temp);
 	uint32 gameID = READ_BE_UINT32((temp+4));
 	uint32 featuresValue = READ_BE_UINT32((temp+8));
@@ -447,20 +453,20 @@
 }
 
 bool StaticResource::loadLanguageTable(const char *filename, void *&ptr, int &size) {
-	char file[64];
+	static Common::String file;
 	for (int i = 0; languages[i].ext; ++i) {
 		if (languages[i].flags != createLanguage(_vm->gameFlags()))
 			continue;
 
-		strcpy(file, filename);
-		strcat(file, languages[i].ext);
-		if (loadStringTable(file, ptr, size))
+		file = filename;
+		file += languages[i].ext;
+		if (loadStringTable(file.c_str(), ptr, size))
 			return true;
 	}
 
-	strcpy(file, filename);
-	strcat(file, languages[0].ext);
-	if (loadStringTable(file, ptr, size)) {
+	file = filename;
+	file += languages[0].ext;
+	if (loadStringTable(file.c_str(), ptr, size)) {
 		static bool warned = false;
 		if (!warned) {
 			warned = true;
@@ -636,25 +642,29 @@
 	size = 0;
 }
 
-uint8 *StaticResource::getFile(const char *name, int &size) {
-	char buffer[64];
-	const char *ext = "";
+const char *StaticResource::getFilename(const char *name) {
+	static Common::String filename;
+
+	filename = name;
+
 	if (_vm->gameFlags().gameID == GI_KYRA2)
-		ext = ".K2";
-	snprintf(buffer, 64, "%s%s", name, ext);
-	ext = "";
+		filename += ".K2";
 
 	if (_vm->gameFlags().isTalkie)
-		ext = ".CD";
+		filename += ".CD";
 	else if (_vm->gameFlags().isDemo)
-		ext = ".DEM";
+		filename += ".DEM";
 	else if (_vm->gameFlags().platform == Common::kPlatformFMTowns || _vm->gameFlags().platform == Common::kPlatformPC98)
-		ext = ".TNS";
+		filename += ".TNS";
 	else if (_vm->gameFlags().platform == Common::kPlatformAmiga)
-		ext = ".AMG";
-	strcat(buffer, ext);
+		filename += ".AMG";
+
+	return filename.c_str();
+}
+
+uint8 *StaticResource::getFile(const char *name, int &size) {
 	uint32 tempSize = 0;
-	uint8 *data = _vm->resource()->fileData(buffer, &tempSize);
+	uint8 *data = _vm->resource()->fileData(getFilename(name), &tempSize);
 	size = tempSize;
 	return data;
 }


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