[Scummvm-git-logs] scummvm master -> ad5393531950f1b0d7a84c2e98836491fad28653

dreammaster paulfgilbert at gmail.com
Mon Jan 13 01:46:48 UTC 2020


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ad53935319 GLK: ADRIFT: Improved fallback detection


Commit: ad5393531950f1b0d7a84c2e98836491fad28653
    https://github.com/scummvm/scummvm/commit/ad5393531950f1b0d7a84c2e98836491fad28653
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-01-12T17:45:48-08:00

Commit Message:
GLK: ADRIFT: Improved fallback detection

Now fallback detection only lists a game if it has a known header

Changed paths:
    engines/glk/adrift/detection.cpp
    engines/glk/adrift/detection.h
    engines/glk/adrift/sctaffil.cpp


diff --git a/engines/glk/adrift/detection.cpp b/engines/glk/adrift/detection.cpp
index 0ee01fd..002085e 100644
--- a/engines/glk/adrift/detection.cpp
+++ b/engines/glk/adrift/detection.cpp
@@ -22,6 +22,7 @@
 
 #include "glk/adrift/detection.h"
 #include "glk/adrift/detection_tables.h"
+#include "glk/adrift/scprotos.h"
 #include "glk/blorb.h"
 #include "common/debug.h"
 #include "common/file.h"
@@ -31,6 +32,28 @@
 namespace Glk {
 namespace Adrift {
 
+enum {
+	VERSION_HEADER_SIZE = 14
+};
+
+/* Various version TAF file signatures. */
+static const byte V500_SIGNATURE[VERSION_HEADER_SIZE] = {
+	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x92, 0x45, 0x3e, 0x61, 0x30, 0x30
+};
+
+static const byte V400_SIGNATURE[VERSION_HEADER_SIZE] = {
+	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x93, 0x45, 0x3e, 0x61, 0x39, 0xfa
+};
+
+static const byte V390_SIGNATURE[VERSION_HEADER_SIZE] = {
+	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x94, 0x45, 0x37, 0x61, 0x39, 0xfa
+};
+
+static const byte V380_SIGNATURE[VERSION_HEADER_SIZE] = {
+	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x94, 0x45, 0x36, 0x61, 0x39, 0xfa
+};
+
+
 void AdriftMetaEngine::getSupportedGames(PlainGameList &games) {
 	for (const PlainGameDescriptor *pd = ADRIFT_GAME_LIST; pd->gameId; ++pd) {
 		games.push_back(*pd);
@@ -47,6 +70,9 @@ GameDescriptor AdriftMetaEngine::findGame(const char *gameId) {
 }
 
 bool AdriftMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) {
+	int version;
+	byte header[VERSION_HEADER_SIZE];
+
 	// Loop through the files of the folder
 	for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
 		// Check for a recognised filename
@@ -64,6 +90,10 @@ bool AdriftMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &
 
 		Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000);
 		size_t filesize = gameFile.size();
+
+		gameFile.seek(0);
+		gameFile.read(header, VERSION_HEADER_SIZE);
+
 		gameFile.seek(0);
 		bool isBlorb = Blorb::isBlorb(gameFile, ID_ADRI);
 		gameFile.close();
@@ -76,12 +106,16 @@ bool AdriftMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &
 		while (p->_gameId && (md5 != p->_md5 || filesize != p->_filesize))
 			++p;
 
-		if (!p->_gameId) {
-			const PlainGameDescriptor &desc = ADRIFT_GAME_LIST[0];
-			gameList.push_back(GlkDetectedGame(desc.gameId, desc.description, filename, md5, filesize));
-		} else {
+		if (p->_gameId) {
 			PlainGameDescriptor gameDesc = findGame(p->_gameId);
 			gameList.push_back(GlkDetectedGame(p->_gameId, gameDesc.description, p->_extra, filename, p->_language));
+		} else {
+			version = isBlorb ? 0 : detectGameVersion(header);
+
+			if (isBlorb || version != TAF_VERSION_NONE) {
+				const PlainGameDescriptor &desc = ADRIFT_GAME_LIST[0];
+				gameList.push_back(GlkDetectedGame(desc.gameId, desc.description, filename, md5, filesize));
+			}
 		}
 	}
 
@@ -96,5 +130,23 @@ void AdriftMetaEngine::detectClashes(Common::StringMap &map) {
 	}
 }
 
+int AdriftMetaEngine::detectGameVersion(const byte *header) {
+	if (memcmp(header, V500_SIGNATURE, VERSION_HEADER_SIZE) == 0) {
+		return TAF_VERSION_500;
+
+	} else if (memcmp(header, V400_SIGNATURE, VERSION_HEADER_SIZE) == 0) {
+		return TAF_VERSION_400;
+
+	} else if (memcmp(header, V390_SIGNATURE, VERSION_HEADER_SIZE) == 0) {
+		return TAF_VERSION_390;
+
+	} else if (memcmp(header, V380_SIGNATURE, VERSION_HEADER_SIZE) == 0) {
+		return TAF_VERSION_380;
+
+	} else {
+		return TAF_VERSION_NONE;
+	}
+}
+
 } // End of namespace Adrift
 } // End of namespace Glk
diff --git a/engines/glk/adrift/detection.h b/engines/glk/adrift/detection.h
index f58d3cf..0940b71 100644
--- a/engines/glk/adrift/detection.h
+++ b/engines/glk/adrift/detection.h
@@ -55,6 +55,11 @@ public:
 	 * Check for game Id clashes with other sub-engines
 	 */
 	static void detectClashes(Common::StringMap &map);
+
+	/**
+	 * Detect the game version
+	 */
+	static int detectGameVersion(const byte *header);
 };
 
 } // End of namespace Adrift
diff --git a/engines/glk/adrift/sctaffil.cpp b/engines/glk/adrift/sctaffil.cpp
index ed162bf..da9400d 100644
--- a/engines/glk/adrift/sctaffil.cpp
+++ b/engines/glk/adrift/sctaffil.cpp
@@ -22,6 +22,7 @@
 
 #include "glk/adrift/scare.h"
 #include "glk/adrift/scprotos.h"
+#include "glk/adrift/detection.h"
 #include "common/algorithm.h"
 #include "common/zlib.h"
 #include "common/memstream.h"
@@ -50,23 +51,6 @@ static const sc_char NEWLINE = '\n';
 static const sc_char CARRIAGE_RETURN = '\r';
 static const sc_char NUL = '\0';
 
-/* Various version TAF file signatures. */
-static const sc_byte V500_SIGNATURE[VERSION_HEADER_SIZE] = {
-	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x92, 0x45, 0x3e, 0x61, 0x30, 0x30
-};
-
-static const sc_byte V400_SIGNATURE[VERSION_HEADER_SIZE] = {
-	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x93, 0x45, 0x3e, 0x61, 0x39, 0xfa
-};
-
-static const sc_byte V390_SIGNATURE[VERSION_HEADER_SIZE] = {
-	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x94, 0x45, 0x37, 0x61, 0x39, 0xfa
-};
-
-static const sc_byte V380_SIGNATURE[VERSION_HEADER_SIZE] = {
-	0x3c, 0x42, 0x3f, 0xc9, 0x6a, 0x87, 0xc2, 0xcf, 0x94, 0x45, 0x36, 0x61, 0x39, 0xfa
-};
-
 /*
  * Game TAF data structure.  The game structure contains the original TAF
  * file header, a growable array of "slab" descriptors, each of which holds
@@ -495,14 +479,14 @@ static sc_tafref_t taf_create_from_callback(sc_read_callbackref_t callback,
 			return NULL;
 		}
 
-		/*
-		 * Compare the header with the known TAF signatures, and set TAF version
-		 * appropriately.
-		 */
-		if (memcmp(taf->header, V500_SIGNATURE, VERSION_HEADER_SIZE) == 0) {
+		/* Handle different TAF versions */
+		int version = AdriftMetaEngine::detectGameVersion(taf->header);
+
+		if (version == TAF_VERSION_500 || version == TAF_VERSION_390 ||
+				version == TAF_VERSION_380) {
 			taf->version = TAF_VERSION_500;
 
-		} else if (memcmp(taf->header, V400_SIGNATURE, VERSION_HEADER_SIZE) == 0) {
+		} else if (version == TAF_VERSION_400) {
 			/* Read in the version 4.0 header extension. */
 			in_bytes = callback(opaque,
 			                    taf->header + VERSION_HEADER_SIZE,
@@ -515,11 +499,8 @@ static sc_tafref_t taf_create_from_callback(sc_read_callbackref_t callback,
 			}
 
 			taf->version = TAF_VERSION_400;
-		} else if (memcmp(taf->header, V390_SIGNATURE, VERSION_HEADER_SIZE) == 0)
-			taf->version = TAF_VERSION_390;
-		else if (memcmp(taf->header, V380_SIGNATURE, VERSION_HEADER_SIZE) == 0)
-			taf->version = TAF_VERSION_380;
-		else {
+
+		} else {
 			taf_destroy(taf);
 			return NULL;
 		}




More information about the Scummvm-git-logs mailing list