Skip to content

Commit

Permalink
SLUDGE: add fall back detection
Browse files Browse the repository at this point in the history
  • Loading branch information
yinsimei authored and sev- committed Jul 13, 2017
1 parent 52b627b commit 03f43f7
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions engines/sludge/detection.cpp
Expand Up @@ -20,6 +20,7 @@
*
*/
#include "common/debug.h"
#include "common/stream.h"

#include "engines/advancedDetector.h"

Expand Down Expand Up @@ -50,7 +51,18 @@ static const PlainGameDescriptor sludgeGames[] = {
{ "verbcoin", "Verb Coin" },
{ 0, 0 }
};


static ADGameDescription s_fallbackDesc = {
"",
"",
AD_ENTRY1(0, 0), // This should always be AD_ENTRY1(0, 0) in the fallback descriptor
Common::UNK_LANG,
Common::kPlatformWindows,
ADGF_NO_FLAGS,
GUIO0()
};
static char s_fallbackFileNameBuffer[51];

#include "sludge/detection_tables.h"

class SludgeMetaEngine : public AdvancedMetaEngine {
Expand All @@ -68,16 +80,70 @@ class SludgeMetaEngine : public AdvancedMetaEngine {
return "Copyright (C) 2000-2014 Hungry Software and contributors";
}


virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
const Sludge::SludgeGameDescription *gd = (const Sludge::SludgeGameDescription *)desc;
if (gd) {
*engine = new Sludge::SludgeEngine(syst, gd);
}
return gd != 0;
}

// for fall back detection
virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const;
};

const ADGameDescription *SludgeMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
// reset fallback description
s_fallbackDesc.gameId = "sludge";
s_fallbackDesc.extra = "";
s_fallbackDesc.language = Common::EN_ANY;
s_fallbackDesc.flags = ADGF_UNSTABLE;
s_fallbackDesc.platform = Common::kPlatformUnknown;
s_fallbackDesc.guiOptions = GUIO0();

for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
if (file->isDirectory())
continue;

Common::String fileName = file->getName();
fileName.toLowercase();
if (!(fileName.hasSuffix(".slg") || fileName == "gamedata"))
continue;

SearchMan.clear();
SearchMan.addDirectory(file->getParent().getName(), file->getParent());

Common::SeekableReadStream *stream = SearchMan.createReadStreamForMember(file->getName());

if (!stream)
continue;

bool headerBad = false;
if (stream->readByte() != 'S')
headerBad = true;
if (stream->readByte() != 'L')
headerBad = true;
if (stream->readByte() != 'U')
headerBad = true;
if (stream->readByte() != 'D')
headerBad = true;
if (stream->readByte() != 'G')
headerBad = true;
if (stream->readByte() != 'E')
headerBad = true;
if (headerBad) {
continue;
}

strncpy(s_fallbackFileNameBuffer, fileName.c_str(), 50);
s_fallbackFileNameBuffer[50] = '\0';
s_fallbackDesc.filesDescriptions[0].fileName = s_fallbackFileNameBuffer;

return &s_fallbackDesc;;
}
return 0;
}

#if PLUGIN_ENABLED_DYNAMIC(SLUDGE)
REGISTER_PLUGIN_DYNAMIC(SLUDGE, PLUGIN_TYPE_ENGINE, SludgeMetaEngine);
#else
Expand Down

0 comments on commit 03f43f7

Please sign in to comment.