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 #include "common/debug.h"
23 #include "common/stream.h"
24
25 #include "engines/advancedDetector.h"
26
27 #include "sludge/sludge.h"
28
29 namespace Sludge {
30
31 struct SludgeGameDescription {
32 ADGameDescription desc;
33 uint languageID;
34 };
35
getLanguageID() const36 uint SludgeEngine::getLanguageID() const { return _gameDescription->languageID; }
getGameId() const37 const char *SludgeEngine::getGameId() const { return _gameDescription->desc.gameId;}
getFeatures() const38 uint32 SludgeEngine::getFeatures() const { return _gameDescription->desc.flags; }
getLanguage() const39 Common::Language SludgeEngine::getLanguage() const { return _gameDescription->desc.language; }
getGameFile() const40 const char *SludgeEngine::getGameFile() const {
41 return _gameDescription->desc.filesDescriptions[0].fileName;
42 }
43
44 } // End of namespace Sludge
45
46 static const PlainGameDescriptor sludgeGames[] = {
47 { "sludge", "Sludge Game" },
48 { "welcome", "Welcome Example" },
49 { "verbcoin", "Verb Coin" },
50 { "robinsrescue", "Robin's Rescue" },
51 { "outoforder", "Out Of Order" },
52 { "frasse", "Frasse and the Peas of Kejick" },
53 { "interview", "The Interview" },
54 { "life", "Life Flashed By"},
55 { "tgttpoacs", "The Game That Takes Place on a Cruise Ship" },
56 { "mandy", "Mandy Christmas Adventure" },
57 { "cubert", "Cubert Badbone, P.I." },
58 { 0, 0 }
59 };
60
61 #include "sludge/detection_tables.h"
62
63 static Sludge::SludgeGameDescription s_fallbackDesc =
64 {
65 {
66 "",
67 "",
68 AD_ENTRY1(0, 0), // This should always be AD_ENTRY1(0, 0) in the fallback descriptor
69 Common::UNK_LANG,
70 Common::kPlatformWindows,
71 ADGF_NO_FLAGS,
72 GUIO0()
73 },
74 0
75 };
76
77 static char s_fallbackFileNameBuffer[51];
78
79 class SludgeMetaEngine : public AdvancedMetaEngine {
80 public:
SludgeMetaEngine()81 SludgeMetaEngine() : AdvancedMetaEngine(Sludge::gameDescriptions, sizeof(Sludge::SludgeGameDescription), sludgeGames) {
82 _singleId = "sludge";
83 _maxScanDepth = 1;
84 }
85
getName() const86 virtual const char *getName() const {
87 return "Sludge";
88 }
89
getOriginalCopyright() const90 virtual const char *getOriginalCopyright() const {
91 return "Sludge (C) 2000-2014 Hungry Software and contributors";
92 }
93
createInstance(OSystem * syst,Engine ** engine,const ADGameDescription * desc) const94 virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
95 const Sludge::SludgeGameDescription *gd = (const Sludge::SludgeGameDescription *)desc;
96 if (gd) {
97 *engine = new Sludge::SludgeEngine(syst, gd);
98 }
99 return gd != 0;
100 }
101
102 // for fall back detection
103 ADDetectedGame fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const override;
104 };
105
fallbackDetect(const FileMap & allFiles,const Common::FSList & fslist) const106 ADDetectedGame SludgeMetaEngine::fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const {
107 // reset fallback description
108 s_fallbackDesc.desc.gameId = "sludge";
109 s_fallbackDesc.desc.extra = "";
110 s_fallbackDesc.desc.language = Common::EN_ANY;
111 s_fallbackDesc.desc.flags = ADGF_UNSTABLE;
112 s_fallbackDesc.desc.platform = Common::kPlatformUnknown;
113 s_fallbackDesc.desc.guiOptions = GUIO0();
114 s_fallbackDesc.languageID = 0;
115
116 for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
117 if (file->isDirectory())
118 continue;
119
120 Common::String fileName = file->getName();
121 fileName.toLowercase();
122 if (!(fileName.hasSuffix(".slg") || fileName == "gamedata"))
123 continue;
124
125 Common::File f;
126 if (!f.open(*file))
127 continue;
128
129 bool headerBad = false;
130 if (f.readByte() != 'S')
131 headerBad = true;
132 if (f.readByte() != 'L')
133 headerBad = true;
134 if (f.readByte() != 'U')
135 headerBad = true;
136 if (f.readByte() != 'D')
137 headerBad = true;
138 if (f.readByte() != 'G')
139 headerBad = true;
140 if (f.readByte() != 'E')
141 headerBad = true;
142 if (headerBad) {
143 continue;
144 }
145
146 strncpy(s_fallbackFileNameBuffer, fileName.c_str(), 50);
147 s_fallbackFileNameBuffer[50] = '\0';
148 s_fallbackDesc.desc.filesDescriptions[0].fileName = s_fallbackFileNameBuffer;
149
150 ADDetectedGame game;
151 game.desc = &s_fallbackDesc.desc;
152
153 FileProperties tmp;
154 if (getFileProperties(file->getParent(), allFiles, s_fallbackDesc.desc, fileName, tmp)) {
155 game.hasUnknownFiles = true;
156 game.matchedFiles[fileName] = tmp;
157 }
158
159 return game;
160 }
161
162 return ADDetectedGame();
163 }
164
165 #if PLUGIN_ENABLED_DYNAMIC(SLUDGE)
166 REGISTER_PLUGIN_DYNAMIC(SLUDGE, PLUGIN_TYPE_ENGINE, SludgeMetaEngine);
167 #else
168 REGISTER_PLUGIN_STATIC(SLUDGE, PLUGIN_TYPE_ENGINE, SludgeMetaEngine);
169 #endif
170