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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 /*
24 * This code is based on original Sfinx source code
25 * Copyright (c) 1994-1997 Janus B. Wisniewski and L.K. Avalon
26 */
27
28 #include "cge2/cge2.h"
29 #include "cge2/fileio.h"
30 #include "engines/advancedDetector.h"
31 #include "common/translation.h"
32 #include "graphics/surface.h"
33
34 namespace CGE2 {
35
36 #define GAMEOPTION_COLOR_BLIND_DEFAULT_OFF GUIO_GAMEOPTIONS1
37
38 static const PlainGameDescriptor CGE2Games[] = {
39 { "sfinx", "Sfinx" },
40 { 0, 0 }
41 };
42
43 static const ADGameDescription gameDescriptions[] = {
44 {
45 "sfinx", "Freeware",
46 {
47 { "vol.cat", 0, "21197b287d397c53261b6616bf0dd880", 129024 },
48 { "vol.dat", 0, "de14291869a8eb7c2732ab783c7542ef", 34180844 },
49 AD_LISTEND
50 },
51 Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
52 },
53
54 {
55 "sfinx", "Freeware v1.0",
56 {
57 {"vol.cat", 0, "aa402aed24a72c53a4d1211c456b79dd", 129024},
58 {"vol.dat", 0, "5966ac26d91d664714349669f9dd09b5", 34180164},
59 AD_LISTEND
60 },
61 Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
62 },
63
64 {
65 "sfinx", "Freeware v1.1",
66 {
67 {"vol.cat", 0, "aa402aed24a72c53a4d1211c456b79dd", 129024},
68 {"vol.dat", 0, "5966ac26d91d664714349669f9dd09b5", 34180367},
69 AD_LISTEND
70 },
71 Common::PL_POL, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
72 },
73
74 {
75 "sfinx", "Freeware v0.3",
76 {
77 {"vol.cat", 0, "f158e469dccbebc5a632eb848df89779", 129024},
78 {"vol.dat", 0, "d40a6b4ae173d6930be54ba56bee15d5", 34183430},
79 AD_LISTEND
80 },
81 Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
82 },
83
84 {
85 "sfinx", "Freeware v1.0",
86 {
87 {"vol.cat", 0, "f158e469dccbebc5a632eb848df89779", 129024},
88 {"vol.dat", 0, "d40a6b4ae173d6930be54ba56bee15d5", 34183443},
89 AD_LISTEND
90 },
91 Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
92 },
93
94 {
95 "sfinx", "Freeware v1.1",
96 {
97 {"vol.cat", 0, "f158e469dccbebc5a632eb848df89779", 129024},
98 {"vol.dat", 0, "d40a6b4ae173d6930be54ba56bee15d5", 34182773},
99 AD_LISTEND
100 },
101 Common::EN_ANY, Common::kPlatformDOS, ADGF_NO_FLAGS, GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
102 },
103
104 AD_TABLE_END_MARKER
105 };
106
107 static const ADExtraGuiOptionsMap optionsList[] = {
108 {
109 GAMEOPTION_COLOR_BLIND_DEFAULT_OFF,
110 {
111 _s("Color Blind Mode"),
112 _s("Enable Color Blind Mode by default"),
113 "enable_color_blind",
114 false
115 }
116 },
117
118 AD_EXTRA_GUI_OPTIONS_TERMINATOR
119 };
120
121 class CGE2MetaEngine : public AdvancedMetaEngine {
122 public:
CGE2MetaEngine()123 CGE2MetaEngine() : AdvancedMetaEngine(gameDescriptions, sizeof(ADGameDescription), CGE2Games, optionsList) {
124 _singleId = "sfinx";
125 }
126
getName() const127 virtual const char *getName() const {
128 return "CGE2";
129 }
130
getOriginalCopyright() const131 virtual const char *getOriginalCopyright() const {
132 return "Sfinx (C) 1994-1997 Janus B. Wisniewski and L.K. Avalon";
133 }
134
135 ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const override;
136 virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const;
137 virtual bool hasFeature(MetaEngineFeature f) const;
138 virtual int getMaximumSaveSlot() const;
139 virtual SaveStateList listSaves(const char *target) const;
140 SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const;
141 virtual void removeSaveState(const char *target, int slot) const;
142 };
143
144 static ADGameDescription s_fallbackDesc = {
145 "sfinx",
146 "Unknown version",
147 AD_ENTRY1(0, 0), // This should always be AD_ENTRY1(0, 0) in the fallback descriptor
148 Common::UNK_LANG,
149 Common::kPlatformDOS,
150 ADGF_NO_FLAGS,
151 GUIO1(GAMEOPTION_COLOR_BLIND_DEFAULT_OFF)
152 };
153
154 static const ADFileBasedFallback fileBasedFallback[] = {
155 { &s_fallbackDesc, { "vol.cat", "vol.dat", 0 } },
156 { 0, { 0 } }
157 };
158
159 // This fallback detection looks identical to the one used for CGE. In fact, the difference resides
160 // in the ResourceManager which handles a different archive format. The rest of the detection is identical.
fallbackDetect(const FileMap & allFiles,const Common::FSList & fslist) const161 ADDetectedGame CGE2MetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
162 ADDetectedGame game = detectGameFilebased(allFiles, fslist, CGE2::fileBasedFallback);
163
164 if (!game.desc)
165 return ADDetectedGame();
166
167 SearchMan.addDirectory("CGE2MetaEngine::fallbackDetect", fslist.begin()->getParent());
168 ResourceManager *resman;
169 resman = new ResourceManager();
170 bool sayFileFound = resman->exist("CGE.SAY");
171 delete resman;
172
173 SearchMan.remove("CGE2MetaEngine::fallbackDetect");
174
175 if (!sayFileFound)
176 return ADDetectedGame();
177
178 return game;
179 }
180
createInstance(OSystem * syst,Engine ** engine,const ADGameDescription * desc) const181 bool CGE2MetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
182 if (desc)
183 *engine = new CGE2::CGE2Engine(syst, desc);
184
185 return desc != 0;
186 }
187
hasFeature(MetaEngineFeature f) const188 bool CGE2MetaEngine::hasFeature(MetaEngineFeature f) const {
189 return
190 (f == kSupportsDeleteSave) ||
191 (f == kSavesSupportMetaInfo) ||
192 (f == kSavesSupportThumbnail) ||
193 (f == kSavesSupportCreationDate) ||
194 (f == kSavesSupportPlayTime) ||
195 (f == kSupportsListSaves) ||
196 (f == kSupportsLoadingDuringStartup) ||
197 (f == kSimpleSavesNames);
198 }
199
getMaximumSaveSlot() const200 int CGE2MetaEngine::getMaximumSaveSlot() const {
201 return 99;
202 }
203
listSaves(const char * target) const204 SaveStateList CGE2MetaEngine::listSaves(const char *target) const {
205 Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
206 Common::StringArray filenames;
207 Common::String pattern = target;
208 pattern += ".###";
209
210 filenames = saveFileMan->listSavefiles(pattern);
211
212 SaveStateList saveList;
213 for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
214 // Obtain the last 3 digits of the filename, since they correspond to the save slot
215 int slotNum = atoi(filename->c_str() + filename->size() - 3);
216
217 if (slotNum >= 0 && slotNum <= 99) {
218
219 Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
220 if (file) {
221 CGE2::SavegameHeader header;
222
223 // Check to see if it's a ScummVM savegame or not
224 char buffer[kSavegameStrSize + 1];
225 file->read(buffer, kSavegameStrSize + 1);
226
227 if (!strncmp(buffer, kSavegameStr, kSavegameStrSize + 1)) {
228 // Valid savegame
229 if (CGE2::CGE2Engine::readSavegameHeader(file, header)) {
230 saveList.push_back(SaveStateDescriptor(slotNum, header.saveName));
231 }
232 } else {
233 // Must be an original format savegame
234 saveList.push_back(SaveStateDescriptor(slotNum, "Unknown"));
235 }
236
237 delete file;
238 }
239 }
240 }
241
242 // Sort saves based on slot number.
243 Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
244 return saveList;
245 }
246
querySaveMetaInfos(const char * target,int slot) const247 SaveStateDescriptor CGE2MetaEngine::querySaveMetaInfos(const char *target, int slot) const {
248 Common::String fileName = Common::String::format("%s.%03d", target, slot);
249 Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName);
250
251 if (f) {
252 CGE2::SavegameHeader header;
253
254 // Check to see if it's a ScummVM savegame or not
255 char buffer[kSavegameStrSize + 1];
256 f->read(buffer, kSavegameStrSize + 1);
257
258 bool hasHeader = !strncmp(buffer, kSavegameStr, kSavegameStrSize + 1) &&
259 CGE2::CGE2Engine::readSavegameHeader(f, header, false);
260 delete f;
261
262 if (!hasHeader) {
263 // Original savegame perhaps?
264 SaveStateDescriptor desc(slot, "Unknown");
265 return desc;
266 } else {
267 // Create the return descriptor
268 SaveStateDescriptor desc(slot, header.saveName);
269 desc.setThumbnail(header.thumbnail);
270 desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay);
271 desc.setSaveTime(header.saveHour, header.saveMinutes);
272
273 if (header.playTime) {
274 desc.setPlayTime(header.playTime * 1000);
275 }
276
277 // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus
278 // we prevent it from being deleted or overwritten by accident.
279 desc.setDeletableFlag(slot != 0);
280 desc.setWriteProtectedFlag(slot == 0);
281
282 return desc;
283 }
284 }
285
286 return SaveStateDescriptor();
287 }
288
removeSaveState(const char * target,int slot) const289 void CGE2MetaEngine::removeSaveState(const char *target, int slot) const {
290 Common::String fileName = Common::String::format("%s.%03d", target, slot);
291 g_system->getSavefileManager()->removeSavefile(fileName);
292 }
293
294 } // End of namespace CGE2
295
296 #if PLUGIN_ENABLED_DYNAMIC(CGE2)
297 REGISTER_PLUGIN_DYNAMIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine);
298 #else
299 REGISTER_PLUGIN_STATIC(CGE2, PLUGIN_TYPE_ENGINE, CGE2::CGE2MetaEngine);
300 #endif
301