ScummVM API documentation
metaengine.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef ENGINES_METAENGINE_H
23 #define ENGINES_METAENGINE_H
24 
25 #include "common/scummsys.h"
26 #include "common/error.h"
27 #include "common/array.h"
28 #include "common/debug-channels.h"
29 
30 #include "engines/achievements.h"
31 #include "engines/game.h"
32 #include "engines/savestate.h"
33 
34 #include "base/plugins.h"
35 
36 class Engine;
37 class OSystem;
38 
39 namespace Common {
40 class Keymap;
41 class FSList;
42 class OutSaveFile;
43 class String;
44 
45 typedef SeekableReadStream InSaveFile;
46 }
47 
48 namespace Graphics {
49 struct Surface;
50 }
51 
52 namespace GUI {
53 class GuiObject;
54 class OptionsContainerWidget;
55 }
56 
71  const char *label;
72  const char *tooltip;
73  const char *configOption;
74  bool defaultState;
75  byte groupId;
77 };
78 
83 
87 enum { kSavegameFilePattern = -99 };
88 
89 #define EXTENDED_SAVE_VERSION 4
90 
95  char id[6];
96  uint8 version;
99  uint32 date;
100  uint16 time;
101  uint32 playtime;
103  bool isAutosave;
106  memset(id, 0, 6);
107  version = 0;
108  date = 0;
109  time = 0;
110  playtime = 0;
111  thumbnail = nullptr;
112  isAutosave = false;
113  }
114 };
115 
127 public:
132  static const char GAME_NOT_IMPLEMENTED[];
133 
134  virtual ~MetaEngineDetection() {}
135 
137  virtual const char *getName() const override = 0;
138 
140  virtual const char *getEngineName() const = 0;
141 
143  virtual const char *getOriginalCopyright() const = 0;
144 
146  virtual PlainGameList getSupportedGames() const = 0;
147 
149  virtual PlainGameDescriptor findGame(const char *gameId) const = 0;
150 
152  virtual Common::Error identifyGame(DetectedGame &game, const void **descriptor) = 0;
153 
159  virtual DetectedGames detectGames(const Common::FSList &fslist, uint32 skipADFlags = 0, bool skipIncomplete = false) = 0;
160 
162  virtual uint getMD5Bytes() const = 0;
163 
165  virtual int getGameVariantCount() const {
166  return -1;
167  }
168 
170  virtual void dumpDetectionEntries() const = 0;
171 
179  virtual const DebugChannelDef *getDebugChannels() const {
180  return NULL;
181  }
182 };
183 
196 class MetaEngine : public PluginObject {
197 protected:
203  virtual void getSavegameThumbnail(Graphics::Surface &thumb);
204 
211  int findEmptySaveSlot(const char *target);
212 
227  virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const {
228  return ExtraGuiOptions();
229  }
230 
231 public:
232  virtual ~MetaEngine() {}
233 
244  virtual const char *getName() const override = 0;
245 
262  virtual Common::Error createInstance(OSystem *syst, Engine **engine, const DetectedGame &gameDescriptor, const void *meDescriptor) = 0;
263 
276  virtual void deleteInstance(Engine *engine, const DetectedGame &gameDescriptor, const void *meDescriptor);
277 
297  virtual SaveStateList listSaves(const char *target) const;
298 
309  SaveStateList listSaves(const char *target, bool saveMode) const;
310 
317  virtual int getAutosaveSlot() const {
318  return 0;
319  }
320 
331  virtual int getMaximumSaveSlot() const {
332  // For games using the new save format, assume 99 slots by default
333  return hasFeature(kSavesUseExtendedFormat) ? 99 : 0;
334  }
335 
348  virtual bool removeSaveState(const char *target, int slot) const;
349 
359  virtual SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
360 
369  virtual Common::String getSavegameFile(int saveGameIdx, const char *target = nullptr) const;
370 
376  Common::String getSavegameFilePattern(const char *target = nullptr) const {
377  return getSavegameFile(kSavegameFilePattern, target);
378  }
379 
383  virtual Common::Array<Common::Keymap *> initKeymaps(const char *target) const;
384 
391  virtual void registerDefaultSettings(const Common::String &target) const;
392 
405  virtual GUI::OptionsContainerWidget *buildEngineOptionsWidget(GUI::GuiObject *boss, const Common::String &name, const Common::String &target) const;
406 
422 
427 
434 
450 
459 
468 
477 
495 
506  kSavesUseExtendedFormat
507  };
508 
516  virtual Common::AchievementsPlatform getAchievementsPlatform(const Common::String &target) const;
517 
525  virtual const Common::AchievementsInfo getAchievementsInfo(const Common::String &target) const;
526 
535  return nullptr;
536  }
537 
543  virtual bool hasFeature(MetaEngineFeature f) const;
544 
548  void appendExtendedSave(Common::OutSaveFile *saveFile, uint32 playtime, Common::String desc, bool isAutosave);
549 
553  void appendExtendedSaveToStream(Common::WriteStream *saveFile, uint32 playtime, Common::String desc, bool isAutosave, uint32 offset = 0);
554 
562  bool copySaveFileToFreeSlot(const char *target, int slot);
563 
567  static void parseSavegameHeader(ExtendedSavegameHeader *header, SaveStateDescriptor *desc);
573  static void fillDummyHeader(ExtendedSavegameHeader *header);
574 
578  static void decodeSavegameDate(const ExtendedSavegameHeader *header, uint16 &outYear, uint8 &outMonth, uint8 &outDay);
579 
583  static void decodeSavegameTime(const ExtendedSavegameHeader *header, uint8 &outHour, uint8 &outMinute);
584 
588  WARN_UNUSED_RESULT static bool readSavegameHeader(Common::InSaveFile *in, ExtendedSavegameHeader *header, bool skipThumbnail = true);
589 };
590 
594 class EngineManager : public Common::Singleton<EngineManager> {
595 public:
602  DetectionResults detectGames(const Common::FSList &fslist, uint32 skipADFlags = 0, bool skipIncomplete = false);
603 
605  const Plugin *findDetectionPlugin(const Common::String &engineId) const;
606 
610  const PluginList &getPlugins(const PluginType fetchPluginType) const;
611 
613  QualifiedGameDescriptor findTarget(const Common::String &target) const;
614 
622  QualifiedGameList findGamesMatching(const Common::String &engineId, const Common::String &gameId) const;
623 
629  Common::String createTargetForGame(const DetectedGame &game);
630 
632  void upgradeTargetIfNecessary(const Common::String &target) const;
633 
635  Common::String generateUniqueDomain(const Common::String gameId);
636 
637 private:
639  QualifiedGameList findGameInLoadedPlugins(const Common::String &gameId) const;
640 
642  void upgradeTargetForEngineId(const Common::String &target) const;
643 };
644 
646 #define EngineMan EngineManager::instance()
647 
648 #endif
virtual int getAutosaveSlot() const
Definition: metaengine.h:317
bool isAutosave
Definition: metaengine.h:103
Definition: game.h:79
Definition: metaengine.h:196
Definition: str.h:59
Definition: metaengine.h:494
Definition: surface.h:67
uint8 version
Definition: metaengine.h:96
MetaEngineFeature
Definition: metaengine.h:413
Definition: stream.h:77
Definition: savefile.h:54
Definition: error.h:84
Definition: metaengine.h:426
Definition: game.h:147
Common::String getSavegameFilePattern(const char *target=nullptr) const
Definition: metaengine.h:376
virtual int getMaximumSaveSlot() const
Definition: metaengine.h:331
Definition: metaengine.h:594
Definition: achievements.h:87
const char * label
Definition: metaengine.h:71
Definition: metaengine.h:458
Definition: game.h:64
byte groupLeaderId
Definition: metaengine.h:76
bool defaultState
Definition: metaengine.h:74
Definition: stream.h:745
Common::Array< ExtraGuiOption > ExtraGuiOptions
Definition: metaengine.h:82
Definition: system.h:46
Definition: game.h:49
Definition: object.h:60
Definition: plugins.h:145
Definition: widget.h:532
void upgradeTargetIfNecessary(const ObsoleteGameID *obsoleteList)
Definition: savestate.h:56
Definition: metaengine.h:70
Definition: metaengine.h:433
virtual const Common::AchievementDescriptionList * getAchievementDescriptionList() const
Definition: metaengine.h:534
Definition: game.h:245
virtual const DebugChannelDef * getDebugChannels() const
Definition: metaengine.h:179
Definition: debug-channels.h:36
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: metaengine.h:467
Definition: metaengine.h:449
bool skipThumbnail(Common::SeekableReadStream &in)
const char * configOption
Definition: metaengine.h:73
AchievementsPlatform
Definition: achievements.h:46
Definition: plugins.h:131
Definition: metaengine.h:126
Definition: fs.h:57
uint16 time
Definition: metaengine.h:100
Common::String saveName
Definition: metaengine.h:97
uint32 playtime
Definition: metaengine.h:101
Definition: metaengine.h:476
Definition: metaengine.h:421
SeekableReadStream InSaveFile
Definition: savefile.h:47
byte groupId
Definition: metaengine.h:75
Graphics::Surface * thumbnail
Definition: metaengine.h:102
uint32 date
Definition: metaengine.h:99
Definition: achievements.h:74
Definition: system.h:161
Definition: metaengine.h:94
virtual const ExtraGuiOptions getExtraGuiOptions(const Common::String &target) const
Definition: metaengine.h:227
Common::String description
Definition: metaengine.h:98
virtual int getGameVariantCount() const
Definition: metaengine.h:165
Definition: engine.h:144
const char * tooltip
Definition: metaengine.h:72
Definition: singleton.h:42