LILLIPUT: Split detection features & adapt to new plugins.

This commit is contained in:
aryanrawlani28 2020-08-06 22:54:31 +05:30 committed by Eugene Sandulenko
parent 06cb6c50e6
commit 5593b47e88
7 changed files with 281 additions and 180 deletions

2
configure vendored
View File

@ -6164,7 +6164,7 @@ declare -a static_detect_engines=("PLUMBERS" "AGI" "SCUMM" "SKY" "DREAMWEB" "DRA
"SWORD1" "SWORD2" "SWORD25" "ADL" "QUEEN" "CGE" "CGE2" "ACCESS"
"ZVISION" "AGOS" "GOB" "COMPOSER" "DM" "DRACI" "DRAGONS" "GNAP"
"GRIFFON" "GROOVIE" "HDB" "HOPKINS" "HUGO" "ILLUSIONS" "KINGDOM"
"KYRA" "LAB" "LASTEXPRESS")
"KYRA" "LAB" "LASTEXPRESS" "LILLIPUT")
detectId="_DETECTION"
echo "Creating engines/plugins_table.h"

View File

@ -20,31 +20,15 @@
*
*/
#include "base/plugins.h"
#include "engines/advancedDetector.h"
#include "common/system.h"
#include "common/savefile.h"
#include "common/textconsole.h"
#include "graphics/thumbnail.h"
#include "graphics/surface.h"
#include "lilliput/lilliput.h"
#include "lilliput/detection_enums.h"
#include "lilliput/detection.h"
namespace Lilliput {
struct LilliputGameDescription {
ADGameDescription desc;
GameType gameType;
};
uint32 LilliputEngine::getFeatures() const {
return _gameDescription->desc.flags;
}
const char *LilliputEngine::getGameId() const {
return _gameDescription->desc.gameId;
}
static const PlainGameDescriptor lilliputGames[] = {
// Games
{"robin", "Adventures of Robin Hood"},
@ -137,160 +121,8 @@ public:
const char *getOriginalCopyright() const override {
return "Lilliput (C) S.L.Grand, Brainware, 1991-1992";
}
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const override;
bool hasFeature(MetaEngineFeature f) const override;
int getMaximumSaveSlot() const override;
SaveStateList listSaves(const char *target) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
void removeSaveState(const char *target, int slot) const override;
};
bool LilliputMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
if (gd) {
*engine = new LilliputEngine(syst, (const LilliputGameDescription *)gd);
((LilliputEngine *)*engine)->initGame((const LilliputGameDescription *)gd);
}
return gd != 0;
}
bool LilliputMetaEngine::hasFeature(MetaEngineFeature f) const {
return
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
(f == kSavesSupportCreationDate);
}
int LilliputMetaEngine::getMaximumSaveSlot() const {
return 99;
}
SaveStateList LilliputMetaEngine::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String pattern = target;
pattern += "-##.SAV";
filenames = saveFileMan->listSavefiles(pattern);
SaveStateList saveList;
char slot[3];
int slotNum = 0;
for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
slot[0] = filename->c_str()[filename->size() - 6];
slot[1] = filename->c_str()[filename->size() - 5];
slot[2] = '\0';
// Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot
slotNum = atoi(slot);
if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
if (file) {
int saveVersion = file->readByte();
if (saveVersion != kSavegameVersion) {
warning("Savegame of incompatible version");
delete file;
continue;
}
// read name
uint16 nameSize = file->readUint16BE();
if (nameSize >= 255) {
delete file;
continue;
}
char name[256];
file->read(name, nameSize);
name[nameSize] = 0;
saveList.push_back(SaveStateDescriptor(slotNum, name));
delete file;
}
}
}
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
return saveList;
}
SaveStateDescriptor LilliputMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName);
if (file) {
int saveVersion = file->readByte();
if (saveVersion != kSavegameVersion) {
warning("Savegame of incompatible version");
delete file;
return SaveStateDescriptor();
}
uint32 saveNameLength = file->readUint16BE();
Common::String saveName;
for (uint32 i = 0; i < saveNameLength; ++i) {
char curChr = file->readByte();
saveName += curChr;
}
SaveStateDescriptor desc(slot, saveName);
Graphics::Surface *thumbnail;
if (!Graphics::loadThumbnail(*file, thumbnail)) {
delete file;
return SaveStateDescriptor();
}
desc.setThumbnail(thumbnail);
desc.setDeletableFlag(true);
desc.setWriteProtectedFlag(false);
uint32 saveDate = file->readUint32BE();
uint16 saveTime = file->readUint16BE();
int day = (saveDate >> 24) & 0xFF;
int month = (saveDate >> 16) & 0xFF;
int year = saveDate & 0xFFFF;
desc.setSaveDate(year, month, day);
int hour = (saveTime >> 8) & 0xFF;
int minutes = saveTime & 0xFF;
desc.setSaveTime(hour, minutes);
// Slot 0 is used for the 'restart game' save in all Robin games, thus
// we prevent it from being deleted.
desc.setDeletableFlag(slot != 0);
desc.setWriteProtectedFlag(slot == 0);
delete file;
return desc;
}
return SaveStateDescriptor();
}
void LilliputMetaEngine::removeSaveState(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
g_system->getSavefileManager()->removeSavefile(fileName);
}
} // End of namespace Lilliput
#if PLUGIN_ENABLED_DYNAMIC(LILLIPUT)
REGISTER_PLUGIN_DYNAMIC(LILLIPUT, PLUGIN_TYPE_ENGINE, Lilliput::LilliputMetaEngine);
#else
REGISTER_PLUGIN_STATIC(LILLIPUT, PLUGIN_TYPE_ENGINE, Lilliput::LilliputMetaEngine);
#endif
namespace Lilliput {
void LilliputEngine::initGame(const LilliputGameDescription *gd) {
_gameType = gd->gameType;
_platform = gd->desc.platform;
}
} // End of namespace Lilliput
REGISTER_PLUGIN_STATIC(LILLIPUT_DETECTION, PLUGIN_TYPE_METAENGINE, Lilliput::LilliputMetaEngine);

View File

@ -0,0 +1,31 @@
/* 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.
*
*/
namespace Lilliput {
struct LilliputGameDescription {
ADGameDescription desc;
GameType gameType;
};
} // End of namespace Lilliput

View File

@ -0,0 +1,31 @@
/* 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.
*
*/
namespace Lilliput {
enum GameType {
kGameTypeNone = 0,
kGameTypeRobin,
kGameTypeRome
};
} // End of namespace Lilliput

View File

@ -27,6 +27,7 @@
#include "lilliput/script.h"
#include "lilliput/sound.h"
#include "lilliput/stream.h"
#include "lilliput/detection_enums.h"
#include "common/file.h"
#include "common/rect.h"
@ -54,12 +55,6 @@ namespace Lilliput {
static const int kSavegameVersion = 1;
enum GameType {
kGameTypeNone = 0,
kGameTypeRobin,
kGameTypeRome
};
enum LilliputDebugChannels {
kDebugEngine = 1 << 0,
kDebugScript = 1 << 1,

View File

@ -0,0 +1,209 @@
/* 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/advancedDetector.h"
#include "common/system.h"
#include "common/savefile.h"
#include "common/textconsole.h"
#include "graphics/thumbnail.h"
#include "graphics/surface.h"
#include "lilliput/lilliput.h"
#include "lilliput/detection.h"
namespace Lilliput {
uint32 LilliputEngine::getFeatures() const {
return _gameDescription->desc.flags;
}
const char *LilliputEngine::getGameId() const {
return _gameDescription->desc.gameId;
}
} // End of namespace Lilliput
namespace Lilliput {
class LilliputMetaEngineConnect : public AdvancedMetaEngineConnect {
public:
const char *getName() const override {
return "lilliput";
}
bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const override;
bool hasFeature(MetaEngineFeature f) const override;
int getMaximumSaveSlot() const override;
SaveStateList listSaves(const char *target) const override;
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
void removeSaveState(const char *target, int slot) const override;
};
bool LilliputMetaEngineConnect::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *gd) const {
if (gd) {
*engine = new LilliputEngine(syst, (const LilliputGameDescription *)gd);
((LilliputEngine *)*engine)->initGame((const LilliputGameDescription *)gd);
}
return gd != 0;
}
bool LilliputMetaEngineConnect::hasFeature(MetaEngineFeature f) const {
return
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSupportsDeleteSave) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportThumbnail) ||
(f == kSavesSupportCreationDate);
}
int LilliputMetaEngineConnect::getMaximumSaveSlot() const {
return 99;
}
SaveStateList LilliputMetaEngineConnect::listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
Common::StringArray filenames;
Common::String pattern = target;
pattern += "-##.SAV";
filenames = saveFileMan->listSavefiles(pattern);
SaveStateList saveList;
char slot[3];
int slotNum = 0;
for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) {
slot[0] = filename->c_str()[filename->size() - 6];
slot[1] = filename->c_str()[filename->size() - 5];
slot[2] = '\0';
// Obtain the last 2 digits of the filename (without extension), since they correspond to the save slot
slotNum = atoi(slot);
if (slotNum >= 0 && slotNum <= getMaximumSaveSlot()) {
Common::InSaveFile *file = saveFileMan->openForLoading(*filename);
if (file) {
int saveVersion = file->readByte();
if (saveVersion != kSavegameVersion) {
warning("Savegame of incompatible version");
delete file;
continue;
}
// read name
uint16 nameSize = file->readUint16BE();
if (nameSize >= 255) {
delete file;
continue;
}
char name[256];
file->read(name, nameSize);
name[nameSize] = 0;
saveList.push_back(SaveStateDescriptor(slotNum, name));
delete file;
}
}
}
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
return saveList;
}
SaveStateDescriptor LilliputMetaEngineConnect::querySaveMetaInfos(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName);
if (file) {
int saveVersion = file->readByte();
if (saveVersion != kSavegameVersion) {
warning("Savegame of incompatible version");
delete file;
return SaveStateDescriptor();
}
uint32 saveNameLength = file->readUint16BE();
Common::String saveName;
for (uint32 i = 0; i < saveNameLength; ++i) {
char curChr = file->readByte();
saveName += curChr;
}
SaveStateDescriptor desc(slot, saveName);
Graphics::Surface *thumbnail;
if (!Graphics::loadThumbnail(*file, thumbnail)) {
delete file;
return SaveStateDescriptor();
}
desc.setThumbnail(thumbnail);
desc.setDeletableFlag(true);
desc.setWriteProtectedFlag(false);
uint32 saveDate = file->readUint32BE();
uint16 saveTime = file->readUint16BE();
int day = (saveDate >> 24) & 0xFF;
int month = (saveDate >> 16) & 0xFF;
int year = saveDate & 0xFFFF;
desc.setSaveDate(year, month, day);
int hour = (saveTime >> 8) & 0xFF;
int minutes = saveTime & 0xFF;
desc.setSaveTime(hour, minutes);
// Slot 0 is used for the 'restart game' save in all Robin games, thus
// we prevent it from being deleted.
desc.setDeletableFlag(slot != 0);
desc.setWriteProtectedFlag(slot == 0);
delete file;
return desc;
}
return SaveStateDescriptor();
}
void LilliputMetaEngineConnect::removeSaveState(const char *target, int slot) const {
Common::String fileName = Common::String::format("%s-%02d.SAV", target, slot);
g_system->getSavefileManager()->removeSavefile(fileName);
}
} // End of namespace Lilliput
#if PLUGIN_ENABLED_DYNAMIC(LILLIPUT)
REGISTER_PLUGIN_DYNAMIC(LILLIPUT, PLUGIN_TYPE_ENGINE, Lilliput::LilliputMetaEngineConnect);
#else
REGISTER_PLUGIN_STATIC(LILLIPUT, PLUGIN_TYPE_ENGINE, Lilliput::LilliputMetaEngineConnect);
#endif
namespace Lilliput {
void LilliputEngine::initGame(const LilliputGameDescription *gd) {
_gameType = gd->gameType;
_platform = gd->desc.platform;
}
} // End of namespace Lilliput

View File

@ -2,8 +2,8 @@ MODULE := engines/lilliput
MODULE_OBJS = \
console.o \
detection.o \
lilliput.o \
metaengine.o \
script.o \
sound.o \
stream.o
@ -18,3 +18,6 @@ endif
# Include common rules
include $(srcdir)/rules.mk
# Detection objects
DETECT_OBJS += $(MODULE)/detection.o