22 #ifndef ENGINES_ADVANCED_DETECTOR_H 23 #define ENGINES_ADVANCED_DETECTOR_H 25 #include "engines/metaengine.h" 26 #include "engines/engine.h" 28 #include "common/hash-str.h" 30 #include "common/gui_options.h" 48 static inline uint32 strSizeBuffer(
const char *
const &field) {
49 return field ? (uint32)strlen(field) + 1 : 0;
51 static inline void *strToBuffer(
void *buffer,
const char *&field) {
53 int len = (int)strlen(field) + 1;
54 memcpy((
char *)buffer, field, len);
55 field = (
const char *)buffer;
56 buffer = (
char *)buffer + len;
61 static inline uint32 alignSizeBuffer() {
63 return sizeof(
void *) - 1;
65 static inline void *alignToBuffer(
void *buffer) {
67 uintptr tmp = (uintptr)buffer +
sizeof(
void *) - 1;
68 return (
void *)(tmp & -(int)
sizeof(
void *));
84 uint32 sizeBuffer()
const {
86 ret += ADDynamicDescription::strSizeBuffer(fileName);
87 ret += ADDynamicDescription::strSizeBuffer(md5);
91 void *toBuffer(
void *buffer) {
92 buffer = ADDynamicDescription::strToBuffer(buffer, fileName);
93 buffer = ADDynamicDescription::strToBuffer(buffer, md5);
98 #define AD_NO_SIZE ((uint32)-1) 104 #define AD_LISTEND {NULL, 0, NULL, 0} 110 #define AD_ENTRY1(f, x) {{ f, 0, x, AD_NO_SIZE}, AD_LISTEND} 116 #define AD_ENTRY1s(f, x, s) {{ f, 0, x, s}, AD_LISTEND} 122 #define AD_ENTRY2s(f1, x1, s1, f2, x2, s2) {{f1, 0, x1, s1}, {f2, 0, x2, s2}, AD_LISTEND} 128 #define AD_ENTRY3s(f1, x1, s1, f2, x2, s2, f3, x3, s3) {{f1, 0, x1, s1}, {f2, 0, x2, s2}, {f3, 0, x3, s3}, AD_LISTEND} 129 #define AD_ENTRY4s(f1, x1, s1, f2, x2, s2, f3, x3, s3, f4, x4, s4) {{f1, 0, x1, s1}, {f2, 0, x2, s2}, {f3, 0, x3, s3}, {f4, 0, x4, s4}, AD_LISTEND} 130 #define AD_ENTRY5s(f1, x1, s1, f2, x2, s2, f3, x3, s3, f4, x4, s4, f5, x5, s5) {{f1, 0, x1, s1}, {f2, 0, x2, s2}, {f3, 0, x3, s3}, {f4, 0, x4, s4}, {f5, 0, x5, s5}, AD_LISTEND} 131 #define AD_ENTRY6s(f1, x1, s1, f2, x2, s2, f3, x3, s3, f4, x4, s4, f5, x5, s5, f6, x6, s6) {{f1, 0, x1, s1}, {f2, 0, x2, s2}, {f3, 0, x3, s3}, {f4, 0, x4, s4}, {f5, 0, x5, s5}, {f6, 0, x6, s6}, AD_LISTEND} 223 ret += ADDynamicDescription::strSizeBuffer(gameId);
224 ret += ADDynamicDescription::strSizeBuffer(extra);
225 for(
int i = 0; i <
ARRAYSIZE(filesDescriptions); i++) {
226 ret += filesDescriptions[i].sizeBuffer();
228 ret += ADDynamicDescription::strSizeBuffer(guiOptions);
240 buffer = ADDynamicDescription::strToBuffer(buffer, gameId);
241 buffer = ADDynamicDescription::strToBuffer(buffer, extra);
242 for(
int i = 0; i <
ARRAYSIZE(filesDescriptions); i++) {
243 buffer = filesDescriptions[i].toBuffer(buffer);
245 buffer = ADDynamicDescription::strToBuffer(buffer, guiOptions);
256 #define AD_GAME_DESCRIPTION_HELPERS(field) \ 257 uint32 sizeBuffer() const { \ 258 return field.sizeBuffer(); \ 260 void *toBuffer(void *buffer) { \ 261 return field.toBuffer(buffer); \ 275 memcpy(static_cast<T*>(
this), other,
sizeof(T));
280 uint32 sz = other->sizeBuffer();
281 _buffer =
new byte[sz];
285 void *end = this->toBuffer(_buffer);
286 assert(end <= _buffer + sz);
328 #define AD_TABLE_END_MARKER \ 329 { NULL, NULL, { { NULL, 0, NULL, 0 } }, Common::UNK_LANG, Common::kPlatformUnknown, ADGF_NO_FLAGS, GUIO0() } 342 const char *filenames[10];
405 #define AD_EXTRA_GUI_OPTIONS_TERMINATOR { 0, { 0, 0, 0, 0, 0, 0 } } 522 for (
const byte *descPtr = _gameDescriptors; ((
const ADGameDescription *)descPtr)->gameId !=
nullptr; descPtr += _descItemSize)
527 void dumpDetectionEntries()
const override;
549 void preprocessDescriptions();
552 void detectClashes()
const;
557 bool _hashMapsInited;
605 bool cleanupPirated(ADDetectedGames &matched)
const;
607 friend class FileMapArchive;
610 template<
class Descriptor>
656 const char *getName()
const override = 0;
720 template<
class Descriptor>
725 return createInstance(syst, engine, static_cast<const Descriptor *>(desc));
731 const_cast<void *
>(meDescriptor));
745 md5HashMap.setVal(fname, md5);
749 return md5HashMap.getVal(fname);
753 sizeHashMap.setVal(fname, size);
757 return sizeHashMap.getVal(fname);
761 return (md5HashMap.contains(fname) && sizeHashMap.contains(fname));
770 if (archiveHashMap.contains(filename)) {
771 delete archiveHashMap[filename];
774 archiveHashMap.setVal(filename, archivePtr);
778 return archiveHashMap.getValOrDefault(node.
getPath(),
nullptr);
785 void clearArchives() {
786 for (
auto &entry : archiveHashMap) {
789 archiveHashMap.clear(
true);
793 md5HashMap.clear(
true);
794 sizeHashMap.clear(
true);
804 FileHashMap md5HashMap;
805 SizeHashMap sizeHashMap;
806 ArchiveHashMap archiveHashMap;
810 #define ADCacheMan AdvancedDetectorCacheManager::instance() #define ARRAYSIZE(x)
Definition: util.h:103
Always add English as a language option.
Definition: advancedDetector.h:150
uint32 sizeBuffer() const
Definition: advancedDetector.h:221
Flag to designate not yet officially supported games that are not fit for public testing.
Definition: advancedDetector.h:143
Definition: advancedDetector.h:380
Definition: advancedDetector.h:46
uint32 fileSize
Size of the described file. Set to AD_NO_SIZE to ignore.
Definition: advancedDetector.h:82
ErrorCode getCode() const
Definition: error.h:112
const char * md5
MD5 of (the beginning of) the described file. Optional. Set to NULL to ignore.
Definition: advancedDetector.h:81
Common::Array< ADDetectedGame > ADDetectedGames
Definition: advancedDetector.h:322
const char * extra
Definition: advancedDetector.h:181
Definition: advancedDetector.h:164
const ADGameDescription * desc
Definition: advancedDetector.h:312
const char * fileName
Name of the described file.
Definition: advancedDetector.h:79
const ADGameDescription * desc
Definition: advancedDetector.h:336
const char * gameId
Definition: advancedDetector.h:170
Do not add platform to gameid.
Definition: advancedDetector.h:154
No error occurred.
Definition: error.h:48
ADDetectedGame(const ADGameDescription *d)
Definition: advancedDetector.h:318
MD5Properties
Definition: game.h:106
No flags.
Definition: advancedDetector.h:139
uint16 fileType
Optional. Not used during detection, only by engines.
Definition: advancedDetector.h:80
Definition: advancedDetector.h:271
Definition: advancedDetector.h:370
bool hasUnknownFiles
Definition: advancedDetector.h:310
uint32 flags
Definition: advancedDetector.h:207
Add "-dvd" to gameid.
Definition: advancedDetector.h:156
Calculate the MD5 for this entry from the resource fork.
Definition: advancedDetector.h:151
ADGameFlags
Definition: advancedDetector.h:138
ADFlags
Definition: advancedDetector.h:346
Definition: archive.h:141
Flag to designate not yet officially supported games that are fit for public testing.
Definition: advancedDetector.h:144
void * toBuffer(void *buffer)
Definition: advancedDetector.h:239
Common::Language language
Definition: advancedDetector.h:194
Do not add language to gameid.
Definition: advancedDetector.h:153
Add "-cd" to gameid.
Definition: advancedDetector.h:155
Automatically generate gameid from ADGameDescription::extra.
Definition: advancedDetector.h:142
Use ADGameDescription::extra as the main game title, not gameid.
Definition: advancedDetector.h:152
Definition: advancedDetector.h:387
An add-on game, that cannot be run independently without its base game.
Definition: advancedDetector.h:140
Definition: algorithm.h:29
Definition: advancedDetector.h:146
Definition: advancedDetector.h:742
const char * guiOptions
Definition: advancedDetector.h:216
Flag to designate well-known pirated versions with cracks.
Definition: advancedDetector.h:145
Definition: advancedDetector.h:309
Calculate the MD5 for this entry from the end of the file.
Definition: advancedDetector.h:141
Definition: advancedDetector.h:331
Definition: advancedDetector.h:148
FilePropertiesMap matchedFiles
Definition: advancedDetector.h:311
Definition: advancedDetector.h:392
Add "-demo" to gameid.
Definition: advancedDetector.h:157
Common::Platform platform
Definition: advancedDetector.h:199
Definition: advancedDetector.h:357
Add "-remastered' to gameid.
Definition: advancedDetector.h:158
Definition: singleton.h:42
Language
Definition: language.h:45
Definition: advancedDetector.h:78