2020-08-06 23:17:03 +00: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.
|
|
|
|
*
|
2021-12-26 17:47:58 +00:00
|
|
|
* 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-08-06 23:17:03 +00:00
|
|
|
*
|
|
|
|
* 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
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-08-06 23:17:03 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "base/plugins.h"
|
|
|
|
#include "common/savefile.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "engines/advancedDetector.h"
|
|
|
|
|
|
|
|
#include "cruise/cruise.h"
|
|
|
|
#include "cruise/saveload.h"
|
2020-08-25 08:22:43 +00:00
|
|
|
#include "cruise/detection.h"
|
2020-08-06 23:17:03 +00:00
|
|
|
|
|
|
|
namespace Cruise {
|
|
|
|
|
|
|
|
const char *CruiseEngine::getGameId() const {
|
|
|
|
return _gameDescription->desc.gameId;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Language CruiseEngine::getLanguage() const {
|
|
|
|
return _gameDescription->desc.language;
|
|
|
|
}
|
|
|
|
Common::Platform CruiseEngine::getPlatform() const {
|
|
|
|
return _gameDescription->desc.platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Cruise
|
|
|
|
|
2020-10-02 06:55:08 +00:00
|
|
|
class CruiseMetaEngine : public AdvancedMetaEngine {
|
2020-08-06 23:17:03 +00:00
|
|
|
public:
|
|
|
|
const char *getName() const override {
|
|
|
|
return "cruise";
|
|
|
|
}
|
|
|
|
|
2021-04-15 19:20:04 +00:00
|
|
|
bool hasFeature(MetaEngineFeature f) const override;
|
2020-08-06 23:17:03 +00:00
|
|
|
int getMaximumSaveSlot() const override { return 99; }
|
|
|
|
|
|
|
|
SaveStateList listSaves(const char *target) const override;
|
|
|
|
void removeSaveState(const char *target, int slot) const override;
|
|
|
|
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const override;
|
2020-11-17 00:06:05 +00:00
|
|
|
Common::Error createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const override;
|
2020-08-06 23:17:03 +00:00
|
|
|
};
|
|
|
|
|
2020-10-02 06:55:08 +00:00
|
|
|
bool CruiseMetaEngine::hasFeature(MetaEngineFeature f) const {
|
2020-08-06 23:17:03 +00:00
|
|
|
return
|
|
|
|
(f == kSupportsListSaves) ||
|
|
|
|
(f == kSupportsDeleteSave) ||
|
|
|
|
(f == kSavesSupportMetaInfo) ||
|
|
|
|
(f == kSavesSupportThumbnail) ||
|
|
|
|
(f == kSupportsLoadingDuringStartup);
|
|
|
|
}
|
|
|
|
|
2020-10-02 06:55:08 +00:00
|
|
|
SaveStateList CruiseMetaEngine::listSaves(const char *target) const {
|
2020-08-06 23:17:03 +00:00
|
|
|
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
|
|
|
Common::StringArray filenames;
|
|
|
|
Common::String pattern("cruise.s##");
|
|
|
|
|
|
|
|
filenames = saveFileMan->listSavefiles(pattern);
|
|
|
|
|
|
|
|
SaveStateList saveList;
|
|
|
|
for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
|
|
|
|
// Obtain the last 2 digits of the filename, since they correspond to the save slot
|
|
|
|
int slotNum = atoi(file->c_str() + file->size() - 2);
|
|
|
|
|
|
|
|
if (slotNum >= 0 && slotNum <= 99) {
|
|
|
|
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
|
|
|
|
if (in) {
|
|
|
|
Cruise::CruiseSavegameHeader header;
|
|
|
|
if (Cruise::readSavegameHeader(in, header))
|
2021-10-19 06:28:14 +00:00
|
|
|
saveList.push_back(SaveStateDescriptor(this, slotNum, header.saveName));
|
2020-08-06 23:17:03 +00:00
|
|
|
delete in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort saves based on slot number.
|
|
|
|
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
|
|
|
|
return saveList;
|
|
|
|
}
|
|
|
|
|
2020-10-02 06:55:08 +00:00
|
|
|
void CruiseMetaEngine::removeSaveState(const char *target, int slot) const {
|
2020-08-06 23:17:03 +00:00
|
|
|
g_system->getSavefileManager()->removeSavefile(Cruise::CruiseEngine::getSavegameFile(slot));
|
|
|
|
}
|
|
|
|
|
2020-10-02 06:55:08 +00:00
|
|
|
SaveStateDescriptor CruiseMetaEngine::querySaveMetaInfos(const char *target, int slot) const {
|
2020-08-06 23:17:03 +00:00
|
|
|
Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(
|
|
|
|
Cruise::CruiseEngine::getSavegameFile(slot));
|
|
|
|
|
|
|
|
if (f) {
|
|
|
|
Cruise::CruiseSavegameHeader header;
|
|
|
|
if (!Cruise::readSavegameHeader(f, header, false)) {
|
|
|
|
delete f;
|
|
|
|
return SaveStateDescriptor();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete f;
|
|
|
|
|
|
|
|
// Create the return descriptor
|
2021-10-19 06:28:14 +00:00
|
|
|
SaveStateDescriptor desc(this, slot, header.saveName);
|
2020-08-06 23:17:03 +00:00
|
|
|
desc.setThumbnail(header.thumbnail);
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SaveStateDescriptor();
|
|
|
|
}
|
|
|
|
|
2020-11-17 00:06:05 +00:00
|
|
|
Common::Error CruiseMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
|
|
|
|
*engine = new Cruise::CruiseEngine(syst, (const Cruise::CRUISEGameDescription *)desc);
|
|
|
|
return Common::kNoError;
|
2020-08-06 23:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if PLUGIN_ENABLED_DYNAMIC(CRUISE)
|
2020-10-02 06:55:08 +00:00
|
|
|
REGISTER_PLUGIN_DYNAMIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine);
|
2020-08-06 23:17:03 +00:00
|
|
|
#else
|
2020-10-02 06:55:08 +00:00
|
|
|
REGISTER_PLUGIN_STATIC(CRUISE, PLUGIN_TYPE_ENGINE, CruiseMetaEngine);
|
2020-08-06 23:17:03 +00:00
|
|
|
#endif
|