2006-10-02 22:21:57 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2005-2006 The ScummVM project
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef COMMON_ADVANCED_DETECTOR_H
|
|
|
|
#define COMMON_ADVANCED_DETECTOR_H
|
|
|
|
|
|
|
|
#include "common/fs.h"
|
|
|
|
|
2006-11-12 03:23:29 +00:00
|
|
|
#include "base/game.h" // For PlainGameDescriptor and GameList
|
2007-01-24 22:57:40 +00:00
|
|
|
#include "base/plugins.h" // For PluginError
|
2006-11-12 03:23:29 +00:00
|
|
|
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
namespace Common {
|
|
|
|
|
|
|
|
struct ADGameFileDescription {
|
|
|
|
const char *fileName;
|
2007-01-28 23:24:16 +00:00
|
|
|
uint16 fileType; // Optional. Not used during detection, only by engines.
|
|
|
|
const char *md5; // Optional. May be NULL.
|
|
|
|
int32 fileSize; // Optional. Set to -1 to ignore.
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 01:28:18 +00:00
|
|
|
enum ADGameFlags {
|
|
|
|
GF_NO_FLAGS = 0,
|
|
|
|
GF_DEMO = 1 << 31
|
|
|
|
};
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
struct ADGameDescription {
|
2006-12-19 23:37:03 +00:00
|
|
|
const char *gameid;
|
2006-10-02 22:21:57 +00:00
|
|
|
const char *extra;
|
2007-01-28 23:24:16 +00:00
|
|
|
ADGameFileDescription filesDescriptions[14];
|
2006-10-02 22:21:57 +00:00
|
|
|
Language language;
|
|
|
|
Platform platform;
|
2007-02-13 01:28:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A bitmask of extra flags. The top 8 bits are reserved for generic flags
|
|
|
|
* defined in the ADGameFlags. This leaves 24 flags to be used by client
|
|
|
|
* code.
|
|
|
|
*/
|
|
|
|
uint32 flags;
|
2006-10-02 22:21:57 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 01:28:18 +00:00
|
|
|
#define AD_TABLE_END_MARKER \
|
|
|
|
{ NULL, NULL, { { NULL, 0, NULL, 0 } }, Common::UNK_LANG, Common::kPlatformUnknown, Common::GF_NO_FLAGS }
|
|
|
|
|
2006-11-10 22:43:10 +00:00
|
|
|
struct ADObsoleteGameID {
|
|
|
|
const char *from;
|
|
|
|
const char *to;
|
|
|
|
Common::Platform platform;
|
|
|
|
};
|
|
|
|
|
2007-01-28 07:31:26 +00:00
|
|
|
enum ADFlags {
|
2007-02-04 03:10:27 +00:00
|
|
|
kADFlagComplexID = (1 << 0), // Generate complex suggested IDs
|
|
|
|
kADFlagFilebasedFallback = (1 << 1) // Use file based fallback detection
|
2007-01-28 07:31:26 +00:00
|
|
|
};
|
|
|
|
|
2007-01-24 22:24:52 +00:00
|
|
|
struct ADParams {
|
|
|
|
// Pointer to ADGameDescription or its superset structure
|
|
|
|
const byte *descs;
|
|
|
|
// Size of that superset structure
|
2007-01-28 23:24:16 +00:00
|
|
|
int descItemSize;
|
2007-01-24 22:24:52 +00:00
|
|
|
// Number of bytes to compute MD5 sum for
|
2007-01-28 23:24:16 +00:00
|
|
|
int md5Bytes;
|
2007-01-24 22:24:52 +00:00
|
|
|
// List of all engine targets
|
|
|
|
const PlainGameDescriptor *list;
|
2007-01-28 07:31:26 +00:00
|
|
|
// Structure for autoupgrading obsolete targets (optional)
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADObsoleteGameID *obsoleteList;
|
2007-01-28 07:31:26 +00:00
|
|
|
// Name of single gameid (optional)
|
|
|
|
const char *singleid;
|
2007-02-04 03:10:27 +00:00
|
|
|
// List of files for file-based fallback detection (optional)
|
|
|
|
const char **fileBased;
|
2007-01-28 07:31:26 +00:00
|
|
|
// Flags
|
2007-01-30 20:20:05 +00:00
|
|
|
uint32 flags;
|
2007-01-24 22:24:52 +00:00
|
|
|
};
|
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
typedef Array<int> ADList;
|
2006-10-24 09:44:20 +00:00
|
|
|
typedef Array<const ADGameDescription*> ADGameDescList;
|
2006-10-02 22:21:57 +00:00
|
|
|
|
2007-01-24 22:42:44 +00:00
|
|
|
#define AD_ENTRY1(f, x) {{ f, 0, x, -1}, {NULL, 0, NULL, 0}}
|
2007-01-28 07:31:26 +00:00
|
|
|
#define AD_ENTRY1s(f, x, s) {{ f, 0, x, s}, {NULL, 0, NULL, 0}}
|
2006-12-19 22:43:15 +00:00
|
|
|
|
|
|
|
|
2007-01-25 21:16:57 +00:00
|
|
|
namespace AdvancedDetector {
|
|
|
|
|
2007-01-29 23:25:51 +00:00
|
|
|
/**
|
|
|
|
* Returns list of targets supported by the engine.
|
|
|
|
* Distinguishes engines with single ID
|
|
|
|
*/
|
|
|
|
GameList genGameList(const Common::ADParams ¶ms);
|
|
|
|
|
2007-01-25 21:16:57 +00:00
|
|
|
/**
|
|
|
|
* Scan through the game descriptors specified in params and search for
|
|
|
|
* 'gameid' in there. If a match is found, returns a GameDescriptor
|
|
|
|
* with gameid and description set.
|
|
|
|
*/
|
|
|
|
GameDescriptor findGameID(
|
2006-11-12 03:23:29 +00:00
|
|
|
const char *gameid,
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADParams ¶ms
|
2006-11-12 03:23:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
2007-01-25 21:16:57 +00:00
|
|
|
GameList detectAllGames(
|
2006-11-12 03:23:29 +00:00
|
|
|
const FSList &fslist,
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADParams ¶ms
|
2006-11-12 03:23:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
2007-01-25 21:16:57 +00:00
|
|
|
int detectBestMatchingGame(
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADParams ¶ms
|
2006-11-12 03:23:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
2007-01-25 21:16:57 +00:00
|
|
|
void upgradeTargetIfNecessary(const Common::ADParams ¶ms);
|
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
|
|
|
PluginError detectGameForEngineCreation(
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList (*detectFunc)(const FSList &fslist),
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADParams ¶ms
|
2006-11-12 03:23:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2007-01-25 21:16:57 +00:00
|
|
|
// FIXME: It would probably be good to merge detectBestMatchingGame
|
|
|
|
// and detectGameForEngineCreation into a single function. Right now, the
|
|
|
|
// detection code called priort to creating an engine instance
|
|
|
|
// (i.e. detectGameForEngineCreation) differs from the detection code the
|
|
|
|
// engines call internally (i.e. detectBestMatchingGame). This could lead
|
|
|
|
// to hard to debug and odd errors.
|
|
|
|
|
|
|
|
|
|
|
|
} // End of namespace AdvancedDetector
|
|
|
|
|
|
|
|
|
|
|
|
#define ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_FUNC(engine,factoryFunc,detectFunc,params) \
|
2006-12-19 23:37:03 +00:00
|
|
|
GameList Engine_##engine##_gameIDList() { \
|
2007-01-29 23:25:51 +00:00
|
|
|
return Common::AdvancedDetector::genGameList(params); \
|
2006-12-19 23:37:03 +00:00
|
|
|
} \
|
|
|
|
GameDescriptor Engine_##engine##_findGameID(const char *gameid) { \
|
2007-01-25 21:16:57 +00:00
|
|
|
return Common::AdvancedDetector::findGameID(gameid, params); \
|
2006-12-19 23:37:03 +00:00
|
|
|
} \
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList Engine_##engine##_detectGames(const FSList &fslist) { \
|
2006-11-12 03:23:29 +00:00
|
|
|
return detectFunc(fslist); \
|
2006-11-10 22:43:10 +00:00
|
|
|
} \
|
|
|
|
PluginError Engine_##engine##_create(OSystem *syst, Engine **engine) { \
|
|
|
|
assert(syst); \
|
|
|
|
assert(engine); \
|
2007-01-25 21:16:57 +00:00
|
|
|
Common::AdvancedDetector::upgradeTargetIfNecessary(params); \
|
|
|
|
PluginError err = Common::AdvancedDetector::detectGameForEngineCreation(detectFunc, params); \
|
2006-11-12 03:23:29 +00:00
|
|
|
if (err == kNoError) \
|
2007-01-25 21:16:57 +00:00
|
|
|
*engine = factoryFunc(syst); \
|
2006-11-12 03:23:29 +00:00
|
|
|
return err; \
|
2006-11-10 22:43:10 +00:00
|
|
|
} \
|
|
|
|
void dummyFuncToAllowTrailingSemicolon()
|
|
|
|
|
2007-01-25 21:16:57 +00:00
|
|
|
#define ADVANCED_DETECTOR_DEFINE_PLUGIN(engine,className,detectFunc,params) \
|
|
|
|
static className *engine##_createInstance(OSystem *syst) { \
|
|
|
|
return new className(syst); \
|
|
|
|
} \
|
|
|
|
ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_FUNC(engine,engine##_createInstance,detectFunc,params); \
|
|
|
|
void dummyFuncToAllowTrailingSemicolon()
|
|
|
|
|
2006-11-12 03:23:29 +00:00
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
|
|
|
#endif
|