mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-21 09:21:08 +00:00
GLK: ADRIFT: Improved fallback detection
Now fallback detection only lists a game if it has a known header
This commit is contained in:
parent
f435a1592c
commit
ad53935319
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user