2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-10-02 22:21:57 +00:00
|
|
|
*
|
|
|
|
* 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 22:25:25 +00:00
|
|
|
#define AD_ENTRY1(f, x) {{ f, 0, x, -1}, {NULL, 0, NULL, 0}}
|
|
|
|
#define AD_ENTRY1s(f, x, s) {{ f, 0, x, s}, {NULL, 0, NULL, 0}}
|
|
|
|
|
2007-02-13 01:28:18 +00:00
|
|
|
enum ADGameFlags {
|
2007-02-13 13:42:28 +00:00
|
|
|
ADGF_NO_FLAGS = 0,
|
2007-02-13 20:34:17 +00:00
|
|
|
ADGF_DEMO = (1 << 30)
|
2007-02-13 01:28:18 +00:00
|
|
|
};
|
|
|
|
|
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-06-12 12:22:25 +00:00
|
|
|
/**
|
|
|
|
* Encapsulates ADGameDescription and makes gameid and extra strings dynamic.
|
|
|
|
* Used in fallback detection when dynamically creating string content.
|
|
|
|
*/
|
|
|
|
struct EncapsulatedADGameDesc {
|
|
|
|
Common::String gameid;
|
|
|
|
Common::String extra;
|
|
|
|
const ADGameDescription *realDesc;
|
|
|
|
|
|
|
|
// Constructor for the EncapsulatedADGameDesc
|
|
|
|
EncapsulatedADGameDesc() : realDesc(0) {}
|
|
|
|
EncapsulatedADGameDesc(const ADGameDescription *paramRealDesc,
|
|
|
|
Common::String paramGameID = Common::String(""),
|
|
|
|
Common::String paramExtra = Common::String(""))
|
|
|
|
: realDesc(paramRealDesc), gameid(paramGameID), extra(paramExtra) {
|
|
|
|
assert(paramRealDesc != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Functions for getting the correct gameid and extra values from the struct
|
|
|
|
const char *getGameID() const { return (gameid.empty() && realDesc != 0) ? realDesc->gameid : gameid.c_str(); }
|
|
|
|
const char *getExtra() const { return (extra.empty() && realDesc != 0) ? realDesc->extra : extra.c_str(); }
|
|
|
|
};
|
|
|
|
|
2007-02-14 00:21:53 +00:00
|
|
|
/**
|
|
|
|
* A list of pointers to ADGameDescription structs (or subclasses thereof).
|
|
|
|
*/
|
|
|
|
typedef Array<const ADGameDescription*> ADGameDescList;
|
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
|
|
|
* End marker for a table of ADGameDescription structs. Use this to
|
|
|
|
* terminate a list to be passed to the AdvancedDetector API.
|
|
|
|
*/
|
2007-02-13 01:28:18 +00:00
|
|
|
#define AD_TABLE_END_MARKER \
|
2007-02-13 13:42:28 +00:00
|
|
|
{ NULL, NULL, { { NULL, 0, NULL, 0 } }, Common::UNK_LANG, Common::kPlatformUnknown, Common::ADGF_NO_FLAGS }
|
2007-02-13 01:28:18 +00:00
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
|
2006-11-10 22:43:10 +00:00
|
|
|
struct ADObsoleteGameID {
|
|
|
|
const char *from;
|
|
|
|
const char *to;
|
|
|
|
Common::Platform platform;
|
|
|
|
};
|
|
|
|
|
2007-02-14 23:46:39 +00:00
|
|
|
struct ADFileBasedFallback {
|
|
|
|
/**
|
2007-03-08 21:33:55 +00:00
|
|
|
* Pointer to an ADGameDescription or subclass thereof which will get
|
|
|
|
* returned if there's a detection match.
|
2007-02-14 23:46:39 +00:00
|
|
|
*/
|
|
|
|
const void *desc;
|
|
|
|
|
|
|
|
/**
|
2007-03-08 21:33:55 +00:00
|
|
|
* A zero-terminated list of filenames used for matching. All files in
|
|
|
|
* the list must be present to get a detection match.
|
2007-02-14 23:46:39 +00:00
|
|
|
*/
|
|
|
|
const char *filenames[10];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-28 07:31:26 +00:00
|
|
|
enum ADFlags {
|
2007-02-13 13:17:46 +00:00
|
|
|
/**
|
|
|
|
* Generate/augment preferred target with information on the language (if
|
|
|
|
* not equal to english) and platform (if not equal to PC).
|
|
|
|
*/
|
|
|
|
kADFlagAugmentPreferredTarget = (1 << 0),
|
2007-03-08 21:40:47 +00:00
|
|
|
kADFlagPrintWarningOnFileBasedFallback = (1 << 1)
|
2007-01-28 07:31:26 +00:00
|
|
|
};
|
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
|
|
|
* A structure containing all parameters for the AdvancedDetector.
|
|
|
|
* Typically, an engine will have a single instance of this which is
|
|
|
|
* then passed to the various AdvancedDetector functions.
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
struct ADParams {
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
|
|
|
* Pointer to an array of objects which are either ADGameDescription
|
|
|
|
* or superset structures (i.e. start with an ADGameDescription member.
|
|
|
|
* The list is terminated by an entry with a gameid equal to 0
|
|
|
|
* (see AD_TABLE_END_MARKER).
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
const byte *descs;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The size of a single entry of the above descs array. Always
|
|
|
|
* must be >= sizeof(ADGameDescription).
|
|
|
|
*/
|
|
|
|
uint descItemSize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of bytes to compute MD5 sum for. The AdvancedDetector
|
|
|
|
* is primarily based on computing and matching MD5 checksums of files.
|
|
|
|
* Since doing that for large files can be slow, it can be restricted
|
|
|
|
* to a subset of all files.
|
|
|
|
* Typically this will be set to something between 5 and 50 kilobyte,
|
|
|
|
* but arbitrary non-zero values are possible.
|
|
|
|
*/
|
|
|
|
uint md5Bytes;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of all gameids (and their corresponding descriptions) supported
|
|
|
|
* by this engine.
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
const PlainGameDescriptor *list;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
2007-02-13 23:37:44 +00:00
|
|
|
* Structure for autoupgrading obsolete targets (optional).
|
2007-02-13 22:25:25 +00:00
|
|
|
*
|
|
|
|
* @todo Properly explain this.
|
|
|
|
*/
|
2007-01-24 22:24:52 +00:00
|
|
|
const Common::ADObsoleteGameID *obsoleteList;
|
2007-02-13 22:25:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of single gameid (optional).
|
|
|
|
*
|
|
|
|
* @todo Properly explain this -- what does it do?
|
|
|
|
*/
|
2007-01-28 07:31:26 +00:00
|
|
|
const char *singleid;
|
2007-01-24 22:24:52 +00:00
|
|
|
|
2007-02-13 22:25:25 +00:00
|
|
|
/**
|
2007-02-13 23:37:44 +00:00
|
|
|
* List of files for file-based fallback detection (optional).
|
|
|
|
* This is used if the regular MD5 based detection failed to
|
|
|
|
* detect anything.
|
2007-02-14 23:46:39 +00:00
|
|
|
* As usual this list is terminated by an all-zero entry.
|
2007-02-13 23:37:44 +00:00
|
|
|
*
|
2007-02-13 22:25:25 +00:00
|
|
|
* @todo Properly explain this
|
|
|
|
*/
|
2007-02-14 23:46:39 +00:00
|
|
|
const ADFileBasedFallback *fileBasedFallback;
|
2007-02-13 23:37:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A callback pointing to an (optional) generic fallback detect
|
2007-02-14 00:21:53 +00:00
|
|
|
* function. If present, this callback is invoked if both the regular
|
2007-02-13 23:37:44 +00:00
|
|
|
* MD5 based detection as well as the file based fallback failed
|
2007-02-14 00:21:53 +00:00
|
|
|
* to detect anything.
|
2007-02-13 23:37:44 +00:00
|
|
|
*
|
|
|
|
* @note The fslist parameter may be 0 -- in that case, it is assumed
|
|
|
|
* that the callback searchs the current directory.
|
2007-02-14 00:21:53 +00:00
|
|
|
*
|
|
|
|
* @todo
|
2007-02-13 23:37:44 +00:00
|
|
|
*/
|
2007-06-12 12:22:25 +00:00
|
|
|
EncapsulatedADGameDesc (*fallbackDetectFunc)(const FSList *fslist);
|
2006-10-02 22:21:57 +00:00
|
|
|
|
2007-02-13 23:37:44 +00:00
|
|
|
/**
|
|
|
|
* A bitmask of flags which can be used to configure the behavior
|
|
|
|
* of the AdvancedDetector. Refer to ADFlags for a list of flags
|
|
|
|
* that can be ORed together and passed here.
|
|
|
|
*/
|
2007-02-13 22:25:25 +00:00
|
|
|
uint32 flags;
|
|
|
|
};
|
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
|
|
|
|
*/
|
2007-02-13 14:55:11 +00:00
|
|
|
GameList gameIDList(const Common::ADParams ¶ms);
|
2007-01-29 23:25:51 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2007-06-15 17:36:41 +00:00
|
|
|
GameDescriptor findGameID(
|
|
|
|
const char *gameid,
|
|
|
|
const PlainGameDescriptor *list,
|
|
|
|
const Common::ADObsoleteGameID *obsoleteList = 0
|
|
|
|
);
|
2006-11-12 03:23:29 +00:00
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
2007-02-13 23:37:44 +00:00
|
|
|
GameList detectAllGames(const FSList &fslist, const Common::ADParams ¶ms);
|
2006-11-12 03:23:29 +00:00
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
2007-06-12 12:22:25 +00:00
|
|
|
EncapsulatedADGameDesc detectBestMatchingGame(const Common::ADParams ¶ms);
|
2006-11-12 03:23:29 +00:00
|
|
|
|
|
|
|
// FIXME/TODO: Rename this function to something more sensible.
|
2007-05-30 18:39:35 +00:00
|
|
|
// Only used by ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_FUNC
|
2007-02-13 23:37:44 +00:00
|
|
|
PluginError detectGameForEngineCreation(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
|
|
|
|
|
|
|
|
|
2007-08-13 08:58:04 +00:00
|
|
|
#define _ADVANCED_DETECTOR_DEFINE_PLUGIN_HEAD(engine,params) \
|
2006-12-19 23:37:03 +00:00
|
|
|
GameList Engine_##engine##_gameIDList() { \
|
2007-02-13 14:55:11 +00:00
|
|
|
return Common::AdvancedDetector::gameIDList(params); \
|
2006-12-19 23:37:03 +00:00
|
|
|
} \
|
|
|
|
GameDescriptor Engine_##engine##_findGameID(const char *gameid) { \
|
2007-06-15 17:36:41 +00:00
|
|
|
return Common::AdvancedDetector::findGameID(gameid, params.list, params.obsoleteList); \
|
2006-12-19 23:37:03 +00:00
|
|
|
} \
|
2007-01-20 21:27:57 +00:00
|
|
|
GameList Engine_##engine##_detectGames(const FSList &fslist) { \
|
2007-02-13 14:55:11 +00:00
|
|
|
return Common::AdvancedDetector::detectAllGames(fslist, params); \
|
2006-11-10 22:43:10 +00:00
|
|
|
} \
|
2007-08-13 08:58:04 +00:00
|
|
|
void dummyFuncToAllowTrailingSemicolon()
|
|
|
|
|
|
|
|
#define _ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_PREDEFINED_FUNC(engine,factoryFunc,params) \
|
|
|
|
_ADVANCED_DETECTOR_DEFINE_PLUGIN_HEAD(engine,params); \
|
2006-11-10 22:43:10 +00:00
|
|
|
PluginError Engine_##engine##_create(OSystem *syst, Engine **engine) { \
|
|
|
|
assert(syst); \
|
|
|
|
assert(engine); \
|
2007-02-13 14:55:11 +00:00
|
|
|
PluginError err = Common::AdvancedDetector::detectGameForEngineCreation(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-08-13 08:58:04 +00:00
|
|
|
#define ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_COMPLEX_CREATION(engine,factoryFunc,params) \
|
|
|
|
_ADVANCED_DETECTOR_DEFINE_PLUGIN_HEAD(engine,params); \
|
|
|
|
PluginError Engine_##engine##_create(OSystem *syst, Engine **engine) { \
|
|
|
|
assert(engine); \
|
|
|
|
Common::EncapsulatedADGameDesc encapsulatedDesc = Common::AdvancedDetector::detectBestMatchingGame(params); \
|
|
|
|
if (encapsulatedDesc.realDesc == 0) { \
|
|
|
|
return kNoGameDataFoundError; \
|
|
|
|
} \
|
|
|
|
if (!factoryFunc(syst,engine,encapsulatedDesc)) { \
|
|
|
|
return kNoGameDataFoundError; \
|
|
|
|
} \
|
|
|
|
return kNoError; \
|
|
|
|
} \
|
|
|
|
void dummyFuncToAllowTrailingSemicolon()
|
|
|
|
|
2007-02-13 14:55:11 +00:00
|
|
|
#define ADVANCED_DETECTOR_DEFINE_PLUGIN(engine,className,params) \
|
|
|
|
static Engine *engine##_createInstance(OSystem *syst) { \
|
2007-01-25 21:16:57 +00:00
|
|
|
return new className(syst); \
|
|
|
|
} \
|
2007-08-13 08:58:04 +00:00
|
|
|
_ADVANCED_DETECTOR_DEFINE_PLUGIN_WITH_PREDEFINED_FUNC(engine,engine##_createInstance,params); \
|
2007-01-25 21:16:57 +00:00
|
|
|
void dummyFuncToAllowTrailingSemicolon()
|
|
|
|
|
2006-11-12 03:23:29 +00:00
|
|
|
|
2006-10-02 22:21:57 +00:00
|
|
|
} // End of namespace Common
|
|
|
|
|
|
|
|
#endif
|