scummvm/engines/glk/detection.cpp

434 lines
15 KiB
C++
Raw Normal View History

2018-10-14 13:02:24 -07: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.
*
* 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.
*
*/
#include "glk/glk.h"
#include "glk/detection.h"
#include "glk/quetzal.h"
2019-09-04 21:21:14 -07:00
#include "glk/adrift/detection.h"
#include "glk/adrift/adrift.h"
2019-06-03 19:18:40 -07:00
#include "glk/advsys/detection.h"
#include "glk/advsys/advsys.h"
2019-11-22 19:27:02 -08:00
#include "glk/agt/detection.h"
#include "glk/agt/agt.h"
#include "glk/alan2/detection.h"
#include "glk/alan2/alan2.h"
2019-06-26 21:42:47 -07:00
#include "glk/alan3/detection.h"
#include "glk/alan3/alan3.h"
2019-10-19 21:26:04 -07:00
#include "glk/archetype/archetype.h"
#include "glk/archetype/detection.h"
2020-05-26 20:02:45 -07:00
#include "glk/comprehend/comprehend.h"
#include "glk/comprehend/detection.h"
#include "glk/zcode/detection.h"
#include "glk/zcode/zcode.h"
#include "glk/glulx/detection.h"
#include "glk/glulx/glulx.h"
2019-05-07 18:57:09 +10:00
#include "glk/hugo/detection.h"
#include "glk/hugo/hugo.h"
2019-09-30 20:33:24 -07:00
#include "glk/jacl/detection.h"
#include "glk/jacl/jacl.h"
2019-10-13 11:31:07 -07:00
#include "glk/level9/detection.h"
#include "glk/level9/level9.h"
#include "glk/magnetic/detection.h"
#include "glk/magnetic/magnetic.h"
2019-07-20 14:58:39 -07:00
#include "glk/quest/detection.h"
#include "glk/quest/quest.h"
#include "glk/scott/detection.h"
#include "glk/scott/scott.h"
2018-11-27 19:48:17 -08:00
#include "glk/tads/detection.h"
#include "glk/tads/tads2/tads2.h"
#include "glk/tads/tads3/tads3.h"
2018-10-14 13:02:24 -07:00
#include "base/plugins.h"
#include "common/md5.h"
#include "common/memstream.h"
2018-10-14 13:02:24 -07:00
#include "common/savefile.h"
#include "common/str-array.h"
#include "common/system.h"
#include "graphics/surface.h"
#include "common/config-manager.h"
#include "common/file.h"
2020-06-21 21:48:22 +01:00
#include "common/translation.h"
2018-10-14 13:02:24 -07:00
namespace Glk {
Common::String GlkDetectedGame::getGlkGUIOptions() {
#if defined (USE_TTS)
return GUIO2(GUIO_NOMUSIC, GUIO_NOSUBTITLES);
#else
return GUIO3(GUIO_NOSPEECH, GUIO_NOMUSIC, GUIO_NOSUBTITLES);
#endif
}
GlkDetectedGame::GlkDetectedGame(const char *id, const char *desc, const Common::String &filename,
GameSupportLevel supportLevel) :
DetectedGame("glk", id, desc, Common::EN_ANY, Common::kPlatformUnknown) {
setGUIOptions(getGlkGUIOptions());
gameSupportLevel = supportLevel;
addExtraEntry("filename", filename);
}
2019-07-06 17:24:37 -07:00
GlkDetectedGame::GlkDetectedGame(const char *id, const char *desc, const Common::String &filename,
Common::Language lang, GameSupportLevel supportLevel) : DetectedGame("glk", id, desc, lang, Common::kPlatformUnknown) {
setGUIOptions(getGlkGUIOptions());
gameSupportLevel = supportLevel;
addExtraEntry("filename", filename);
}
2019-09-25 20:11:12 -07:00
GlkDetectedGame::GlkDetectedGame(const char *id, const char *desc, const char *xtra,
const Common::String &filename, Common::Language lang,
GameSupportLevel supportLevel) :
DetectedGame("glk", id, desc, lang, Common::kPlatformUnknown, xtra) {
setGUIOptions(getGlkGUIOptions());
gameSupportLevel = supportLevel;
2019-09-04 22:36:03 -07:00
addExtraEntry("filename", filename);
}
2019-07-06 17:24:37 -07:00
GlkDetectedGame::GlkDetectedGame(const char *id, const char *desc, const Common::String &filename,
const Common::String &md5, size_t filesize, GameSupportLevel supportLevel) :
DetectedGame("glk", id, desc, Common::UNK_LANG, Common::kPlatformUnknown) {
setGUIOptions(getGlkGUIOptions());
gameSupportLevel = supportLevel;
addExtraEntry("filename", filename);
canBeAdded = true;
hasUnknownFiles = true;
FileProperties fp;
fp.md5 = md5;
fp.size = filesize;
matchedFiles[filename] = fp;
}
} // End of namespace Glk
bool GlkMetaEngine::hasFeature(MetaEngineFeature f) const {
2018-10-14 13:02:24 -07:00
return
2018-11-10 05:42:22 +00:00
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportCreationDate) ||
(f == kSavesSupportPlayTime) ||
(f == kSimpleSavesNames);
2018-10-14 13:02:24 -07:00
}
bool Glk::GlkEngine::hasFeature(EngineFeature f) const {
2018-10-14 13:02:24 -07:00
return
(f == kSupportsReturnToLauncher) ||
2018-11-10 05:42:22 +00:00
(f == kSupportsLoadingDuringRuntime) ||
(f == kSupportsSavingDuringRuntime);
2018-10-14 13:02:24 -07:00
}
bool isGameAllowed(GameSupportLevel supportLevel) {
bool showTestingWarning = false;
#ifdef RELEASE_BUILD
showTestingWarning = true;
#endif
if (((supportLevel == kUnstableGame
|| (supportLevel == kTestingGame && showTestingWarning)))
&& !Engine::warnUserAboutUnsupportedGame())
return false;
return true;
}
template<class META, class ENG>bool create(OSystem *syst,
Glk::GlkGameDescription &gameDesc, Engine *&engine) {
Glk::GameDescriptor gd = META::findGame(gameDesc._gameId.c_str());
if (gd._description) {
if (!isGameAllowed(gd._supportLevel))
return true;
gameDesc._options = gd._options;
engine = new ENG(syst, gameDesc);
return true;
} else {
return false;
}
}
Common::Error GlkMetaEngine::createInstance(OSystem *syst, Engine **engine) const {
Glk::GameDescriptor td = Glk::GameDescriptor::empty();
assert(engine);
2018-10-14 13:02:24 -07:00
// Populate the game description
Glk::GlkGameDescription gameDesc;
gameDesc._gameId = ConfMan.get("gameid");
gameDesc._filename = ConfMan.get("filename");
gameDesc._language = Common::UNK_LANG;
gameDesc._platform = Common::kPlatformUnknown;
if (ConfMan.hasKey("language"))
gameDesc._language = Common::parseLanguage(ConfMan.get("language"));
if (ConfMan.hasKey("platform"))
gameDesc._platform = Common::parsePlatform(ConfMan.get("platform"));
// If the game description has no filename, the engine has been launched directly from
// the command line. Do a scan for supported games for that Id in the game folder
if (gameDesc._filename.empty()) {
gameDesc._filename = findFileByGameId(gameDesc._gameId);
if (gameDesc._filename.empty())
return Common::kNoGameDataFoundError;
}
// Get the MD5
Common::File f;
if (!f.open(Common::FSNode(ConfMan.get("path")).getChild(gameDesc._filename)))
return Common::kNoGameDataFoundError;
gameDesc._md5 = Common::computeStreamMD5AsString(f, 5000);
f.close();
2018-12-08 16:54:31 -08:00
// Create the correct engine
*engine = nullptr;
if ((create<Glk::Adrift::AdriftMetaEngine, Glk::Adrift::Adrift>(syst, gameDesc, *engine))) {}
else if ((create<Glk::AdvSys::AdvSysMetaEngine, Glk::AdvSys::AdvSys>(syst, gameDesc, *engine))) {}
else if ((create<Glk::AGT::AGTMetaEngine, Glk::AGT::AGT>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Alan2::Alan2MetaEngine, Glk::Alan2::Alan2>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Alan3::Alan3MetaEngine, Glk::Alan3::Alan3>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Archetype::ArchetypeMetaEngine, Glk::Archetype::Archetype>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Comprehend::ComprehendMetaEngine, Glk::Comprehend::Comprehend>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Glulx::GlulxMetaEngine, Glk::Glulx::Glulx>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Hugo::HugoMetaEngine, Glk::Hugo::Hugo>(syst, gameDesc, *engine))) {}
else if ((create<Glk::JACL::JACLMetaEngine, Glk::JACL::JACL>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Level9::Level9MetaEngine, Glk::Level9::Level9>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Magnetic::MagneticMetaEngine, Glk::Magnetic::Magnetic>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Quest::QuestMetaEngine, Glk::Quest::Quest>(syst, gameDesc, *engine))) {}
else if ((create<Glk::Scott::ScottMetaEngine, Glk::Scott::Scott>(syst, gameDesc, *engine))) {}
else if ((td = Glk::TADS::TADSMetaEngine::findGame(gameDesc._gameId.c_str()))._description) {
if (!isGameAllowed(td._supportLevel))
return Common::kUserCanceled;
else if (td._options & Glk::TADS::OPTION_TADS3)
new Glk::TADS::TADS3::TADS3(syst, gameDesc);
else
new Glk::TADS::TADS2::TADS2(syst, gameDesc);
} else if ((create<Glk::ZCode::ZCodeMetaEngine, Glk::ZCode::ZCode>(syst, gameDesc, *engine))) {
} else {
return Common::kNoGameDataFoundError;
}
return *engine ? Common::kNoError : Common::kUserCanceled;
}
Common::String GlkMetaEngine::findFileByGameId(const Common::String &gameId) const {
// Get the list of files in the folder and return detection against them
Common::FSNode folder = Common::FSNode(ConfMan.get("path"));
Common::FSList fslist;
folder.getChildren(fslist, Common::FSNode::kListFilesOnly);
// Iterate over the files
for (Common::FSList::iterator i = fslist.begin(); i != fslist.end(); ++i) {
// Run a detection on each file in the folder individually
Common::FSList singleList;
singleList.push_back(*i);
DetectedGames games = detectGames(singleList);
// If a detection was found with the correct game Id, we have a winner
if (!games.empty() && games.front().gameId == gameId)
return (*i).getName();
}
// No match found
return Common::String();
}
PlainGameList GlkMetaEngine::getSupportedGames() const {
PlainGameList list;
Glk::Adrift::AdriftMetaEngine::getSupportedGames(list);
Glk::AdvSys::AdvSysMetaEngine::getSupportedGames(list);
2019-11-22 19:27:02 -08:00
Glk::AGT::AGTMetaEngine::getSupportedGames(list);
Glk::Alan2::Alan2MetaEngine::getSupportedGames(list);
Glk::Alan3::Alan3MetaEngine::getSupportedGames(list);
2019-10-19 21:26:04 -07:00
Glk::Archetype::ArchetypeMetaEngine::getSupportedGames(list);
2020-05-26 20:02:45 -07:00
Glk::Comprehend::ComprehendMetaEngine::getSupportedGames(list);
Glk::Glulx::GlulxMetaEngine::getSupportedGames(list);
Glk::Hugo::HugoMetaEngine::getSupportedGames(list);
Glk::JACL::JACLMetaEngine::getSupportedGames(list);
2019-10-13 11:31:07 -07:00
Glk::Level9::Level9MetaEngine::getSupportedGames(list);
Glk::Magnetic::MagneticMetaEngine::getSupportedGames(list);
2019-07-20 14:58:39 -07:00
Glk::Quest::QuestMetaEngine::getSupportedGames(list);
Glk::Scott::ScottMetaEngine::getSupportedGames(list);
2018-11-27 19:48:17 -08:00
Glk::TADS::TADSMetaEngine::getSupportedGames(list);
Glk::ZCode::ZCodeMetaEngine::getSupportedGames(list);
return list;
}
#define FIND_GAME(SUBENGINE) \
Glk::GameDescriptor gd##SUBENGINE = Glk::SUBENGINE::SUBENGINE##MetaEngine::findGame(gameId); \
if (gd##SUBENGINE._description) return gd##SUBENGINE
PlainGameDescriptor GlkMetaEngine::findGame(const char *gameId) const {
FIND_GAME(Adrift);
FIND_GAME(AdvSys);
FIND_GAME(Alan2);
2019-11-22 19:27:02 -08:00
FIND_GAME(AGT);
FIND_GAME(Alan3);
2019-10-19 21:26:04 -07:00
FIND_GAME(Archetype);
2020-05-26 20:02:45 -07:00
FIND_GAME(Comprehend);
FIND_GAME(Glulx);
FIND_GAME(Hugo);
FIND_GAME(JACL);
2019-10-13 11:31:07 -07:00
FIND_GAME(Level9);
FIND_GAME(Magnetic);
FIND_GAME(Quest);
FIND_GAME(Scott);
FIND_GAME(TADS);
FIND_GAME(ZCode);
return PlainGameDescriptor();
}
#undef FIND_GAME
DetectedGames GlkMetaEngine::detectGames(const Common::FSList &fslist) const {
// This is as good a place as any to detect multiple sub-engines using the same Ids
detectClashes();
DetectedGames detectedGames;
Glk::Adrift::AdriftMetaEngine::detectGames(fslist, detectedGames);
Glk::AdvSys::AdvSysMetaEngine::detectGames(fslist, detectedGames);
2019-11-22 19:27:02 -08:00
Glk::AGT::AGTMetaEngine::detectGames(fslist, detectedGames);
Glk::Alan2::Alan2MetaEngine::detectGames(fslist, detectedGames);
Glk::Alan3::Alan3MetaEngine::detectGames(fslist, detectedGames);
2019-10-19 21:26:04 -07:00
Glk::Archetype::ArchetypeMetaEngine::detectGames(fslist, detectedGames);
2020-05-26 20:02:45 -07:00
Glk::Comprehend::ComprehendMetaEngine::detectGames(fslist, detectedGames);
Glk::Glulx::GlulxMetaEngine::detectGames(fslist, detectedGames);
Glk::Hugo::HugoMetaEngine::detectGames(fslist, detectedGames);
Glk::JACL::JACLMetaEngine::detectGames(fslist, detectedGames);
2019-10-13 11:31:07 -07:00
Glk::Level9::Level9MetaEngine::detectGames(fslist, detectedGames);
Glk::Magnetic::MagneticMetaEngine::detectGames(fslist, detectedGames);
2019-07-20 14:58:39 -07:00
Glk::Quest::QuestMetaEngine::detectGames(fslist, detectedGames);
Glk::Scott::ScottMetaEngine::detectGames(fslist, detectedGames);
2018-11-27 19:48:17 -08:00
Glk::TADS::TADSMetaEngine::detectGames(fslist, detectedGames);
Glk::ZCode::ZCodeMetaEngine::detectGames(fslist, detectedGames);
return detectedGames;
2018-10-14 13:02:24 -07:00
}
void GlkMetaEngine::detectClashes() const {
Common::StringMap map;
Glk::Adrift::AdriftMetaEngine::detectClashes(map);
Glk::AdvSys::AdvSysMetaEngine::detectClashes(map);
2019-11-22 19:27:02 -08:00
Glk::AGT::AGTMetaEngine::detectClashes(map);
Glk::Alan2::Alan2MetaEngine::detectClashes(map);
Glk::Alan3::Alan3MetaEngine::detectClashes(map);
2019-10-19 21:26:04 -07:00
Glk::Archetype::ArchetypeMetaEngine::detectClashes(map);
2020-05-26 20:02:45 -07:00
Glk::Comprehend::ComprehendMetaEngine::detectClashes(map);
Glk::Glulx::GlulxMetaEngine::detectClashes(map);
Glk::Hugo::HugoMetaEngine::detectClashes(map);
Glk::JACL::JACLMetaEngine::detectClashes(map);
2019-10-13 11:31:07 -07:00
Glk::Level9::Level9MetaEngine::detectClashes(map);
Glk::Magnetic::MagneticMetaEngine::detectClashes(map);
2019-07-20 14:58:39 -07:00
Glk::Quest::QuestMetaEngine::detectClashes(map);
Glk::Scott::ScottMetaEngine::detectClashes(map);
Glk::TADS::TADSMetaEngine::detectClashes(map);
Glk::ZCode::ZCodeMetaEngine::detectClashes(map);
}
2020-06-21 21:48:22 +01:00
const ExtraGuiOptions GlkMetaEngine::getExtraGuiOptions(const Common::String &) const {
ExtraGuiOptions options;
#if defined(USE_TTS)
static const ExtraGuiOption ttsSpeakOptions = {
_s("Enable Text to Speech"),
_s("Use TTS to read the text"),
"speak",
false
};
static const ExtraGuiOption ttsSpeakInputOptions = {
_s("Also read input text"),
_s("Use TTS to read the input text"),
"speak_input",
false
};
options.push_back(ttsSpeakOptions);
options.push_back(ttsSpeakInputOptions);
#endif
return options;
}
SaveStateList GlkMetaEngine::listSaves(const char *target) const {
2018-11-04 15:11:11 -08:00
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String saveDesc;
Common::String pattern = Common::String::format("%s.0##", target);
filenames = saveFileMan->listSavefiles(pattern);
2018-10-14 13:02:24 -07:00
SaveStateList saveList;
2018-11-04 15:11:11 -08:00
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
const char *ext = strrchr(file->c_str(), '.');
int slot = ext ? atoi(ext + 1) : -1;
if (slot >= 0 && slot <= MAX_SAVES) {
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file);
if (in) {
Common::String saveName;
if (Glk::QuetzalReader::getSavegameDescription(in, saveName))
saveList.push_back(SaveStateDescriptor(slot, saveName));
2018-11-04 15:11:11 -08:00
delete in;
}
}
}
// Sort saves based on slot number.
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
2018-10-14 13:02:24 -07:00
return saveList;
}
int GlkMetaEngine::getMaximumSaveSlot() const {
2018-10-14 13:02:24 -07:00
return MAX_SAVES;
}
void GlkMetaEngine::removeSaveState(const char *target, int slot) const {
Common::String filename = Common::String::format("%s.%03d", target, slot);
g_system->getSavefileManager()->removeSavefile(filename);
2018-10-14 13:02:24 -07:00
}
SaveStateDescriptor GlkMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Common::String filename = Common::String::format("%s.%03d", target, slot);
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename);
SaveStateDescriptor ssd;
bool result = false;
if (in) {
result = Glk::QuetzalReader::getSavegameMetaInfo(in, ssd);
ssd.setSaveSlot(slot);
delete in;
}
if (result)
return ssd;
2018-10-14 13:02:24 -07:00
return SaveStateDescriptor();
}
2018-11-13 19:47:07 -08:00
#if PLUGIN_ENABLED_DYNAMIC(GLK)
REGISTER_PLUGIN_DYNAMIC(GLK, PLUGIN_TYPE_ENGINE, GlkMetaEngine);
2018-10-14 13:02:24 -07:00
#else
REGISTER_PLUGIN_STATIC(GLK, PLUGIN_TYPE_ENGINE, GlkMetaEngine);
2018-10-14 13:02:24 -07:00
#endif