From b37a41286099faf4a36e73e69b377022345091e7 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 27 Dec 2018 13:20:53 +0200 Subject: GLK: ALAN2: Initial skeleton sub-engine --- engines/glk/alan2/alan2.cpp | 74 ++++++++++++++++++++++ engines/glk/alan2/alan2.h | 75 ++++++++++++++++++++++ engines/glk/alan2/detection.cpp | 118 +++++++++++++++++++++++++++++++++++ engines/glk/alan2/detection.h | 77 +++++++++++++++++++++++ engines/glk/alan2/detection_tables.h | 57 +++++++++++++++++ 5 files changed, 401 insertions(+) create mode 100644 engines/glk/alan2/alan2.cpp create mode 100644 engines/glk/alan2/alan2.h create mode 100644 engines/glk/alan2/detection.cpp create mode 100644 engines/glk/alan2/detection.h create mode 100644 engines/glk/alan2/detection_tables.h (limited to 'engines/glk/alan2') diff --git a/engines/glk/alan2/alan2.cpp b/engines/glk/alan2/alan2.cpp new file mode 100644 index 0000000000..3869e34c90 --- /dev/null +++ b/engines/glk/alan2/alan2.cpp @@ -0,0 +1,74 @@ +/* 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/alan2/alan2.h" +#include "common/config-manager.h" +#include "common/translation.h" +#include "common/error.h" +#include "common/scummsys.h" +#include "common/system.h" +#include "glk/glk.h" +#include "glk/streams.h" + +namespace Glk { +namespace Alan2 { + + +Alan2::Alan2(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), + vm_exited_cleanly(false) { +} + +void Alan2::runGame(Common::SeekableReadStream *gameFile) { + _gameFile = gameFile; + + if (!is_gamefile_valid()) + return; + + // TODO +} + +Common::Error Alan2::loadGameData(strid_t file) { + // TODO + return Common::kNoError; +} + +Common::Error Alan2::saveGameData(strid_t file, const Common::String &desc) { + // TODO + return Common::kNoError; +} + +bool Alan2::is_gamefile_valid() { + if (_gameFile->size() < 8) { + GUIErrorMessage(_("This is too short to be a valid Alan2 file.")); + return false; + } + + if (_gameFile->readUint32BE() != MKTAG(2, 8, 1, 0)) { + GUIErrorMessage(_("This is not a valid Alan2 file.")); + return false; + } + + return true; +} + +} // End of namespace Alan2 +} // End of namespace Glk diff --git a/engines/glk/alan2/alan2.h b/engines/glk/alan2/alan2.h new file mode 100644 index 0000000000..f4515516f7 --- /dev/null +++ b/engines/glk/alan2/alan2.h @@ -0,0 +1,75 @@ +/* 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. + * + */ + +#ifndef GLK_ALAN2 +#define GLK_ALAN2 + +#include "common/scummsys.h" +#include "common/stack.h" +#include "glk/glk_api.h" + +namespace Glk { +namespace Alan2 { + +/** + * Alan2 game interpreter + */ +class Alan2 : public GlkAPI { +public: + Common::SeekableReadStream *_gameFile; + bool vm_exited_cleanly; +private: + /** + * Validates the game file, and if it's invalid, displays an error dialog + */ + bool is_gamefile_valid(); +public: + /** + * Constructor + */ + Alan2(OSystem *syst, const GlkGameDescription &gameDesc); + + /** + * Run the game + */ + void runGame(Common::SeekableReadStream *gameFile); + + /** + * Returns the running interpreter type + */ + virtual InterpreterType getInterpreterType() const override { return INTERPRETER_ALAN2; } + + /** + * Load a savegame from the passed stream + */ + virtual Common::Error loadGameData(strid_t file) override; + + /** + * Save the game to the passed stream + */ + virtual Common::Error saveGameData(strid_t file, const Common::String &desc) override; +}; + +} // End of namespace Alan2 +} // End of namespace Glk + +#endif diff --git a/engines/glk/alan2/detection.cpp b/engines/glk/alan2/detection.cpp new file mode 100644 index 0000000000..f4be3f1c16 --- /dev/null +++ b/engines/glk/alan2/detection.cpp @@ -0,0 +1,118 @@ +/* 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/alan2/detection.h" +#include "glk/alan2/detection_tables.h" +#include "common/debug.h" +#include "common/file.h" +#include "common/md5.h" +#include "engines/game.h" + +namespace Glk { +namespace Alan2 { + +void Alan2MetaEngine::getSupportedGames(PlainGameList &games) { + for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { + games.push_back(*pd); + } +} + +Alan2Descriptor Alan2MetaEngine::findGame(const char *gameId) { + for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { + if (!strcmp(gameId, pd->gameId)) + return *pd; + } + + return Alan2Descriptor(); +} + +bool Alan2MetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { + const char *const EXTENSIONS[3] = { ".acd", ".dat" }; + + // Loop through the files of the folder + for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { + // Check for a recognised filename + if (file->isDirectory()) + continue; + Common::String filename = file->getName(); + bool hasExt = false; + for (int idx = 0; idx < 3 && !hasExt; ++idx) + hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]); + if (!hasExt) + continue; + + // Open up the file and calculate the md5 + Common::File gameFile; + if (!gameFile.open(*file)) + continue; + Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000); + size_t filesize = gameFile.size(); + gameFile.close(); + + // Check for known games + const Alan2GameDescription *p = ALAN2_GAMES; + while (p->_gameId && (md5 != p->_md5 || filesize != p->_filesize)) + ++p; + + DetectedGame gd; + if (!p->_gameId) { + if (filename.hasSuffixIgnoreCase(".dat")) + continue; + + if (gDebugLevel > 0) { + // Print an entry suitable for putting into the detection_tables.h, using the + // name of the parent folder the game is in as the presumed game Id + Common::String folderName = file->getParent().getName(); + if (folderName.hasSuffix("\\")) + folderName.deleteLastChar(); + Common::String fname = filename; + const char *dot = strchr(fname.c_str(), '.'); + if (dot) + fname = Common::String(fname.c_str(), dot); + + debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize); + } + const PlainGameDescriptor &desc = ALAN2_GAME_LIST[0]; + gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown); + } else { + PlainGameDescriptor gameDesc = findGame(p->_gameId); + gd = DetectedGame(p->_gameId, gameDesc.description, p->_language, Common::kPlatformUnknown, p->_extra); + gd.setGUIOptions(GUIO4(GUIO_NOSPEECH, GUIO_NOSFX, GUIO_NOMUSIC, GUIO_NOSUBTITLES)); + } + + gd.addExtraEntry("filename", filename); + gameList.push_back(gd); + } + + return !gameList.empty(); +} + +void Alan2MetaEngine::detectClashes(Common::StringMap &map) { + for (const Alan2Descriptor *pd = ALAN2_GAME_LIST; pd->gameId; ++pd) { + if (map.contains(pd->gameId)) + error("Duplicate game Id found - %s", pd->gameId); + map[pd->gameId] = ""; + } +} + +} // End of namespace Alan2 +} // End of namespace Glk diff --git a/engines/glk/alan2/detection.h b/engines/glk/alan2/detection.h new file mode 100644 index 0000000000..b3fa3bd473 --- /dev/null +++ b/engines/glk/alan2/detection.h @@ -0,0 +1,77 @@ +/* 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. + * + */ + +#ifndef GLK_ALAN2_DETECTION +#define GLK_ALAN2_DETECTION + +#include "common/fs.h" +#include "common/hash-str.h" +#include "engines/game.h" + +namespace Glk { +namespace Alan2 { + +/** + * Alan2 game descriptior + */ +struct Alan2Descriptor { + const char *gameId; + const char *description; + + operator PlainGameDescriptor() const { + PlainGameDescriptor pd; + pd.gameId = gameId; + pd.description = description; + return pd; + } +}; + +/** + * Meta engine for Alan2 interpreter + */ +class Alan2MetaEngine { +public: + /** + * Get a list of supported games + */ + static void getSupportedGames(PlainGameList &games); + + /** + * Returns a game description for the given game Id, if it's supported + */ + static Alan2Descriptor findGame(const char *gameId); + + /** + * Detect supported games + */ + static bool detectGames(const Common::FSList &fslist, DetectedGames &gameList); + + /** + * Check for game Id clashes with other sub-engines + */ + static void detectClashes(Common::StringMap &map); +}; + +} // End of namespace Alan2 +} // End of namespace Glk + +#endif diff --git a/engines/glk/alan2/detection_tables.h b/engines/glk/alan2/detection_tables.h new file mode 100644 index 0000000000..2a09a02ed0 --- /dev/null +++ b/engines/glk/alan2/detection_tables.h @@ -0,0 +1,57 @@ +/* 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 "engines/game.h" +#include "common/gui_options.h" +#include "common/language.h" + +namespace Glk { +namespace Alan2 { + +/** + * Game description + */ +struct Alan2GameDescription { + const char *const _gameId; + const char *const _extra; + const char *const _md5; + size_t _filesize; + Common::Language _language; +}; + +const Alan2Descriptor ALAN2_GAME_LIST[] = { + { "alan2", "Alan2 Game" }, + //{ "cragne", "Cragne Manor" }, + + { nullptr, nullptr } +}; + +#define ENTRY0(ID, MD5, FILESIZE) { ID, nullptr, MD5, FILESIZE, Common::EN_ANY } +#define TABLE_END_MARKER { nullptr, nullptr, nullptr, 0, Common::EN_ANY } + +const Alan2GameDescription ALAN2_GAMES[] = { + //ENTRY0("cragne", "082f518c0120d2323ce340bef8a2d5a9", 8869096), + TABLE_END_MARKER +}; + +} // End of namespace Alan2 +} // End of namespace Glk -- cgit v1.2.3