aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWalter van Niftrik2018-02-01 22:20:52 +0100
committerWalter van Niftrik2018-02-02 22:18:25 +0100
commitb497ec30655a95134e0db62fff2b2324e58f4ffb (patch)
tree04340afc8ede324f56c3971f4f8109be3ef8a122 /engines
parent3850b115f86a7e01fb4902d924eaa94b10328576 (diff)
downloadscummvm-rg350-b497ec30655a95134e0db62fff2b2324e58f4ffb.tar.gz
scummvm-rg350-b497ec30655a95134e0db62fff2b2324e58f4ffb.tar.bz2
scummvm-rg350-b497ec30655a95134e0db62fff2b2324e58f4ffb.zip
ADL: Implement new detection method for disk images
Diffstat (limited to 'engines')
-rw-r--r--engines/adl/adl_v2.cpp8
-rw-r--r--engines/adl/detection.cpp223
-rw-r--r--engines/adl/detection.h2
-rw-r--r--engines/adl/disk.cpp52
-rw-r--r--engines/adl/disk.h3
5 files changed, 244 insertions, 44 deletions
diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp
index 075c2ef3f4..b142839850 100644
--- a/engines/adl/adl_v2.cpp
+++ b/engines/adl/adl_v2.cpp
@@ -48,13 +48,7 @@ AdlEngine_v2::AdlEngine_v2(OSystem *syst, const AdlGameDescription *gd) :
}
Common::String AdlEngine_v2::getDiskImageName(byte volume) const {
- const ADGameFileDescription *ag;
-
- for (ag = _gameDescription->desc.filesDescriptions; ag->fileName; ag++)
- if (ag->fileType == volume)
- return ag->fileName;
-
- error("Disk volume %d not found", volume);
+ return Adl::getDiskImageName(_gameDescription->desc, volume);
}
void AdlEngine_v2::insertDisk(byte volume) {
diff --git a/engines/adl/detection.cpp b/engines/adl/detection.cpp
index 64574ec094..60971d58ff 100644
--- a/engines/adl/detection.cpp
+++ b/engines/adl/detection.cpp
@@ -23,12 +23,16 @@
#include "common/system.h"
#include "common/savefile.h"
#include "common/translation.h"
+#include "common/file.h"
+#include "common/md5.h"
+#include "common/debug.h"
#include "graphics/thumbnail.h"
#include "engines/advancedDetector.h"
#include "adl/detection.h"
+#include "adl/disk.h"
namespace Adl {
@@ -83,8 +87,8 @@ static const PlainGameDescriptor adlGames[] = {
{ 0, 0 }
};
-static const AdlGameDescription gameDescriptions[] = {
- { // Hi-Res Adventure #1: Mystery House - Apple II - 1987 PD release - Plain files
+static const AdlGameDescription gameFileDescriptions[] = {
+ { // Hi-Res Adventure #1: Mystery House - Apple II - 1987 PD release
{
"hires1", 0,
{
@@ -100,11 +104,15 @@ static const AdlGameDescription gameDescriptions[] = {
},
GAME_TYPE_HIRES1
},
- { // Hi-Res Adventure #1: Mystery House - Apple II - 1987 PD release - .DSK format
+ { AD_TABLE_END_MARKER, GAME_TYPE_NONE }
+};
+
+static const AdlGameDescription gameDiskDescriptions[] = {
+ { // Hi-Res Adventure #1: Mystery House - Apple II - Roberta Williams Anthology
{
"hires1", 0,
{
- { "MYSTHOUS.DSK", 0, "34ba05e62bf51404c4475c349ca48921", 143360 },
+ { "mysthous", 0, "54d20eb1ef0084ac3c2d16c31c5b7eb7", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -118,7 +126,7 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires2", 0,
{
- { "WIZARD.DSK", 0, "816fdfc35e25496213c8db40ecf26569", 143360 },
+ { "wizard", 0, "72b114bf8f94fafe5672daac2a70c765", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -132,7 +140,7 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires0", 0,
{
- { "MISSION.NIB", 0, "b158f6f79681d4edd651e1932f9e01d7", 232960 },
+ { "mission", 0, "6bc53f51a3c8ee65c020af55fb8bd875", 116480 },
AD_LISTEND
},
Common::EN_ANY,
@@ -146,7 +154,7 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires3", 0,
{
- { "CRANSTON.D13", 0, "474d92b845337ec189867fac035304c7", 116480 },
+ { "cranston", 0, "e4d35440791a36e55299c7be1ccd2b04", 116480 },
AD_LISTEND
},
Common::EN_ANY,
@@ -160,8 +168,8 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires4", 0,
{
- { "ULYSSESA.DSK", 0, "df21f28ae94440f958dbbcfdfaf0c36e", 143360 },
- { "ULYSSESB.DSK", 1, "c204e8fe265e9534049f3c0f816cc9fc", 143360 },
+ { "ulyssesa", 0, "1eaeb2f1a773ce2d1cb9f16b2ef09049", 143360 },
+ { "ulyssesb", 1, "9fa8552255ae651b252844168b8b6617", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -175,10 +183,10 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires4", 0,
{
- { "ULYS1A.XFD", 0, "26365d2b06509fd21e7a7919e33f7199", 92160 },
- { "ULYS1B.XFD", 0, "37919c72a4103e6f897ee7daa8261d1d", 92160 },
+ { "ulys1b", 0, "bb6aab9a35b41d160b6eefa088165f56", 92160 },
+ { "ulys1a", 0, "c227eeee34d0bacd62b2d6231c409204", 92160 },
// Load 'N' Go Software release XAG-0646 appears to be missing the second disk
- { "ULYS2C.XFD", 0, "ff33830246e65dc71c954acb7fd5621a", 92160 },
+ { "ulys2c", 0, "8c6a76d1767e4ffa2f0118c9c56c0e90", 92160 },
AD_LISTEND
},
Common::EN_ANY,
@@ -192,18 +200,18 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires5", 0,
{
- { "TZONE1A.NIB", 2, "475dedb7396fdcea81c1a2a4046caebe", 232960 },
- { "TZONE1B.NIB", 3, "f8aaea094ebbe41cf4354d9fe2c30d9a", 232960 },
- { "TZONE2C.NIB", 4, "b351a367dc48e776bf08e42a3f50ae74", 232960 },
- { "TZONE2D.NIB", 5, "9583b287a5c95960f5335878102bb8b1", 232960 },
- { "TZONE3E.NIB", 6, "502e42a0cb69ffe4a48cd51c1ff210cf", 232960 },
- { "TZONE3F.NIB", 7, "3d6e0aae15f590b72b6759535b6b7d3c", 232960 },
- { "TZONE4G.NIB", 8, "ede4113a9c9e17745faf71d099808a18", 232960 },
- { "TZONE4H.NIB", 9, "f95dae4aae1155a27f7120230464d4e1", 232960 },
- { "TZONE5I.NIB", 10, "92b3b376877f81a7b7ae426bf1e65456", 232960 },
- { "TZONE5J.NIB", 11, "c9ef796fa596548dbf8f085901f0bac3", 232960 },
- { "TZONE6K.NIB", 12, "2e5323be637002efce1d4c813ae20a3f", 232960 },
- { "TZONE6L.NIB", 13, "7c9268f0ea2d02120c77a46337b3d975", 232960 },
+ { "tzone1a", 2, "731844b1d19c2801e3a5bc61d109af54", 143360 },
+ { "tzone1b", 3, "4eaf8d790e3f93097cca9ddbe863df50", 143360 },
+ { "tzone2c", 4, "e3aa4f56e727339b1ec00978ce9d435b", 143360 },
+ { "tzone2d", 5, "77b8219a380410015c986fa192d4c3bf", 143360 },
+ { "tzone3e", 6, "f7acc03edd8d8aecb90711cd5f9e5593", 143360 },
+ { "tzone3f", 7, "ed74c056976ecea2eab07448c8a72eb8", 143360 },
+ { "tzone4g", 8, "de7bda8a641169fc2dedd8a7b0b7e7de", 143360 },
+ { "tzone4h", 9, "21cf76d97505ff09fff5d5e4711bc47c", 143360 },
+ { "tzone5i", 10, "d665df374e594cd0978b73c3490e5de2", 143360 },
+ { "tzone5j", 11, "5095be23d13201d0897b9169c4e473df", 143360 },
+ { "tzone6k", 12, "bef044503f21af5f0a4088e99aa778b1", 143360 },
+ { "tzone6l", 13, "84801b7c2ab6c09e62a2a0809b94d16a", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -217,10 +225,10 @@ static const AdlGameDescription gameDescriptions[] = {
{
"hires6", 0,
{
- { "DARK1A.DSK", 0, "00c2646d6943d1405717332a6f42d493", 143360 },
- { "DARK1B.NIB", 3, "dbedd736617343ade0e6bead8bf2b10c", 232960 },
- { "DARK2A.NIB", 4, "271eb92db107e8d5829437f8ba77991e", 232960 },
- { "DARK2B.NIB", 5, "cb72044a9b391c4285f4752f746bea2e", 232960 },
+ { "dark1a", 0, "9a5968a8f378c84454d88f4cd4e143a9", 143360 },
+ { "dark1b", 3, "1271ff9c3e1bdb4942301dd37dd0ef87", 143360 },
+ { "dark2a", 4, "090e77563add7b4c9ab25f444d727316", 143360 },
+ { "dark2b", 5, "f2db96af0955324900b800505af4d91f", 143360 },
AD_LISTEND
},
Common::EN_ANY,
@@ -233,9 +241,22 @@ static const AdlGameDescription gameDescriptions[] = {
{ AD_TABLE_END_MARKER, GAME_TYPE_NONE }
};
+struct DiskImageExt {
+ Common::Platform platform;
+ const char *extension;
+};
+
+const DiskImageExt diskImageExts[] {
+ { Common::kPlatformApple2, ".nib" },
+ { Common::kPlatformApple2, ".dsk" },
+ { Common::kPlatformApple2, ".d13" },
+ { Common::kPlatformAtari8Bit, ".xfd" },
+ { Common::kPlatformUnknown, nullptr }
+};
+
class AdlMetaEngine : public AdvancedMetaEngine {
public:
- AdlMetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(AdlGameDescription), adlGames, optionsList) { }
+ AdlMetaEngine() : AdvancedMetaEngine(gameFileDescriptions, sizeof(AdlGameDescription), adlGames, optionsList) { }
const char *getName() const {
return "ADL";
@@ -250,6 +271,9 @@ public:
int getMaximumSaveSlot() const { return 'O' - 'A'; }
SaveStateList listSaves(const char *target) const;
void removeSaveState(const char *target, int slot) const;
+ virtual ADGameDescList detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const;
+
+ bool addFileProps(const FileMap &allFiles, Common::String fname, ADFilePropertiesMap &filePropsMap) const;
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const;
};
@@ -369,6 +393,147 @@ void AdlMetaEngine::removeSaveState(const char *target, int slot) const {
g_system->getSavefileManager()->removeSavefile(fileName);
}
+Common::String getDiskImageName(const ADGameDescription &desc, byte volume) {
+ for (uint i = 0; desc.filesDescriptions[i].fileName; ++i) {
+ const ADGameFileDescription &fDesc = desc.filesDescriptions[i];
+
+ if (fDesc.fileType == volume) {
+ for (uint e = 0; e < ARRAYSIZE(diskImageExts); ++e) {
+ if (diskImageExts[e].platform == desc.platform) {
+ Common::String testFileName(fDesc.fileName);
+ testFileName += diskImageExts[e].extension;
+ if (Common::File::exists(testFileName))
+ return testFileName;
+ }
+ }
+
+ error("Failed to find disk image '%s'", fDesc.fileName);
+ }
+ }
+
+ error("Disk volume %d not found", volume);
+}
+
+bool AdlMetaEngine::addFileProps(const FileMap &allFiles, Common::String fname, ADFilePropertiesMap &filePropsMap) const {
+ if (filePropsMap.contains(fname))
+ return true;
+
+ if (!allFiles.contains(fname))
+ return false;
+
+ ADFileProperties fileProps;
+ fileProps.size = computeMD5(allFiles[fname], fileProps.md5, 16384);
+
+ if (fileProps.size != -1) {
+ debug(3, "> '%s': '%s'", fname.c_str(), fileProps.md5.c_str());
+ filePropsMap[fname] = fileProps;
+ }
+
+ return true;
+}
+
+// Based on AdvancedMetaEngine::detectGame
+ADGameDescList AdlMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const {
+ // We run the file-based detector first and then add to the returned list
+ ADGameDescList matched = AdvancedMetaEngine::detectGame(parent, allFiles, language, platform, extra);
+
+ debug(3, "Starting disk image detection in dir '%s'", parent.getPath().c_str());
+
+ ADFilePropertiesMap filesProps;
+ ADGameIdList matchedGameIds;
+ bool gotAnyMatchesWithAllFiles = false;
+
+ for (uint g = 0; gameDiskDescriptions[g].desc.gameId != 0; ++g) {
+ const ADGameDescription &desc = gameDiskDescriptions[g].desc;
+
+ // Skip games that don't meet the language/platform/extra criteria
+ if (language != Common::UNK_LANG && desc.language != Common::UNK_LANG) {
+ if (desc.language != language && !(language == Common::EN_ANY && (desc.flags & ADGF_ADDENGLISH)))
+ continue;
+ }
+
+ if (platform != Common::kPlatformUnknown && desc.platform != Common::kPlatformUnknown && desc.platform != platform)
+ continue;
+
+ if ((_flags & kADFlagUseExtraAsHint) && !extra.empty() && desc.extra != extra)
+ continue;
+
+ bool fileMissing = false;
+ bool allFilesPresent = true;
+ bool hashOrSizeMismatch = false;
+
+ for (uint f = 0; desc.filesDescriptions[f].fileName; ++f) {
+ const ADGameFileDescription &fDesc = desc.filesDescriptions[f];
+ Common::String fileName;
+ bool foundDiskImage = false;
+
+ for (uint e = 0; e < ARRAYSIZE(diskImageExts); ++e) {
+ if (diskImageExts[e].platform == desc.platform) {
+ Common::String testFileName(fDesc.fileName);
+ testFileName += diskImageExts[e].extension;
+
+ if (addFileProps(allFiles, testFileName, filesProps)) {
+ if (foundDiskImage) {
+ warning("Ignoring '%s' (already found '%s')", testFileName.c_str(), fileName.c_str());
+ filesProps.erase(testFileName);
+ } else {
+ foundDiskImage = true;
+ fileName = testFileName;
+ }
+ }
+ }
+ }
+
+ if (!foundDiskImage) {
+ fileMissing = true;
+ allFilesPresent = false;
+ break;
+ }
+
+ if (hashOrSizeMismatch)
+ continue;
+
+ if (fDesc.md5 && fDesc.md5 != filesProps[fileName].md5) {
+ debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fDesc.md5, filesProps[fileName].md5.c_str());
+ fileMissing = true;
+ hashOrSizeMismatch = true;
+ continue;
+ }
+
+ if (fDesc.fileSize != -1 && fDesc.fileSize != filesProps[fileName].size) {
+ debug(3, "Size Mismatch. Skipping");
+ fileMissing = true;
+ hashOrSizeMismatch = true;
+ continue;
+ }
+
+ debug(3, "Matched file: %s", fileName.c_str());
+ }
+
+ if (!fileMissing) {
+ debug(2, "Found game: %s (%s/%s) (%d)", desc.gameId, getPlatformDescription(desc.platform), getLanguageDescription(desc.language), g);
+ matched.push_back(&desc);
+ } else {
+ if (allFilesPresent) {
+ gotAnyMatchesWithAllFiles = true;
+ if (!matchedGameIds.size() || strcmp(matchedGameIds.back(), desc.gameId) != 0)
+ matchedGameIds.push_back(desc.gameId);
+ }
+
+ debug(5, "Skipping game: %s (%s/%s) (%d)", desc.gameId, getPlatformDescription(desc.platform), getLanguageDescription(desc.language), g);
+ }
+ }
+
+ // TODO: This should be improved to handle matched and unknown games together in a single directory
+ if (matched.empty()) {
+ if (!filesProps.empty() && gotAnyMatchesWithAllFiles) {
+ reportUnknown(parent, filesProps, matchedGameIds);
+ }
+ }
+
+ return matched;
+}
+
Engine *HiRes1Engine_create(OSystem *syst, const AdlGameDescription *gd);
Engine *HiRes2Engine_create(OSystem *syst, const AdlGameDescription *gd);
Engine *HiRes0Engine_create(OSystem *syst, const AdlGameDescription *gd);
diff --git a/engines/adl/detection.h b/engines/adl/detection.h
index cb147c7ff7..ac8d834059 100644
--- a/engines/adl/detection.h
+++ b/engines/adl/detection.h
@@ -46,6 +46,8 @@ struct AdlGameDescription {
GameType gameType;
};
+Common::String getDiskImageName(const ADGameDescription &desc, byte volume);
+
} // End of namespace Adl
#endif
diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp
index ba07f23c0b..2abfe8be21 100644
--- a/engines/adl/disk.cpp
+++ b/engines/adl/disk.cpp
@@ -23,11 +23,14 @@
#include "common/stream.h"
#include "common/substream.h"
#include "common/memstream.h"
+#include "common/md5.h"
#include "adl/disk.h"
namespace Adl {
+const uint trackLen = 256 * 26;
+
static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
if (f.size() != 232960)
return false;
@@ -36,7 +39,7 @@ static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
uint dos32 = 0, dos33 = 0;
uint32 window = 0;
- while (count++ < 6656) {
+ while (count++ < trackLen) {
window &= 0xffff;
window <<= 8;
window |= f.readByte();
@@ -53,8 +56,6 @@ static bool detectDOS33_NIB(Common::SeekableReadStream &f) {
return dos33 > dos32;
}
-const uint trackLen = 256 * 26;
-
static bool readSector_NIB(byte outBuf[], const byte inBuf[], uint size, uint &pos, const byte minNibble, const byte lookup[], const uint track, const uint sector) {
uint z = trackLen - (pos % trackLen);
if (z < size) {
@@ -102,8 +103,8 @@ static uint8 read44(byte *buffer, uint &pos) {
return ((ret << 1) | 1) & buffer[pos++ % trackLen];
}
-static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
- if (f.size() != 232960) {
+static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33, uint tracks = 35) {
+ if (f.size() != 35 * trackLen) {
warning("NIB: image '%s' has invalid size of %d bytes", f.getName(), f.size());
return nullptr;
}
@@ -115,7 +116,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
const uint sectorsPerTrack = (dos33 ? 16 : 13);
const uint bytesPerSector = 256;
- const uint imageSize = 35 * sectorsPerTrack * bytesPerSector;
+ const uint imageSize = tracks * sectorsPerTrack * bytesPerSector;
byte *const diskImage = (byte *)calloc(imageSize, 1);
bool sawAddress = false;
@@ -127,7 +128,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
while (true) {
if (pos >= trackLen+firstGoodTrackPos) {
- if (f.pos() == f.size())
+ if (f.pos() == (int)(tracks * trackLen))
break;
f.read(buffer, sizeof(buffer));
firstGoodTrackPos = 0;
@@ -167,7 +168,7 @@ static Common::SeekableReadStream *readImage_NIB(Common::File &f, bool dos33) {
continue;
}
- if (track >= 35 || sector >= sectorsPerTrack) {
+ if (track >= tracks || sector >= sectorsPerTrack) {
warning("NIB: sector out of bounds @ (%x, %x)", track, sector);
sawAddress = false;
continue;
@@ -327,6 +328,41 @@ Common::SeekableReadStream *DiskImage::createReadStream(uint track, uint sector,
return new Common::MemoryReadStream(data, bytesToRead, DisposeAfterUse::YES);
}
+int32 computeMD5(const Common::FSNode &node, Common::String &md5, uint32 md5Bytes) {
+ Common::File f;
+
+ if (!f.open(node))
+ return -1;
+
+ if (node.getName().matchString("*.nib", true) && f.size() == 35 * trackLen) {
+ uint lastSector = md5Bytes / 256;
+ uint tracks;
+ bool isDOS33 = detectDOS33_NIB(f);
+
+ if (isDOS33)
+ tracks = (lastSector / 16) + 1;
+ else
+ tracks = (lastSector / 13) + 1;
+
+ // Tracks 1 and 2 are swapped in some copy protections, so we read three tracks when two tracks are needed
+ if (tracks == 2)
+ tracks = 3;
+
+ f.seek(0);
+ Common::SeekableReadStream *stream = readImage_NIB(f, isDOS33, tracks);
+ if (stream) {
+ md5 = Common::computeStreamMD5AsString(*stream, md5Bytes);
+ delete stream;
+ return 35 * (isDOS33 ? 16 : 13) * 256;
+ }
+
+ return -1;
+ } else {
+ md5 = Common::computeStreamMD5AsString(f, md5Bytes);
+ return f.size();
+ }
+}
+
const DataBlockPtr Files_Plain::getDataBlock(const Common::String &filename, uint offset) const {
return Common::SharedPtr<Files::DataBlock>(new Files::DataBlock(this, filename, offset));
}
diff --git a/engines/adl/disk.h b/engines/adl/disk.h
index d7fb52e588..0ebe2e05c3 100644
--- a/engines/adl/disk.h
+++ b/engines/adl/disk.h
@@ -34,6 +34,9 @@ class String;
namespace Adl {
+// Used for disk image detection
+int32 computeMD5(const Common::FSNode &node, Common::String &md5, uint32 md5Bytes);
+
class DataBlock {
public:
virtual ~DataBlock() { }