Skip to content

Commit

Permalink
DM: Add support for loading from launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendegúz Nagy committed Aug 26, 2016
1 parent 4442b0b commit bcb0676
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
69 changes: 65 additions & 4 deletions engines/dm/detection.cpp
Expand Up @@ -32,6 +32,8 @@
#include "common/fs.h"

#include "engines/advancedDetector.h"
#include <common/system.h>

namespace DM {
static const PlainGameDescriptor DMGames[] = {
{"dm", "Dungeon Master"},
Expand All @@ -46,7 +48,7 @@ static const ADGameDescription gameDescriptions[] = {
{"Dungeon.dat", 0, "43a213da8eda413541dd12f90ce202f6", 25006},
AD_LISTEND
},
Common::EN_ANY, Common::kPlatformAmiga, ADGF_NO_FLAGS, GUIO1(GUIO_NONE)
Common::EN_ANY, Common::kPlatformAmiga, ADGF_NO_FLAGS, GUIO1(GUIO_NONE)
},
{
"dm", "Atari ???v English",
Expand Down Expand Up @@ -94,13 +96,72 @@ class DMMetaEngine : public AdvancedMetaEngine {
virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { return gameDescriptions; }

virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
if(desc)
if (desc)
*engine = new DM::DMEngine(syst, desc);
return desc != nullptr;
}

virtual bool hasFeature(MetaEngineFeature f) const {
return
(f == kSupportsListSaves) ||
(f == kSupportsLoadingDuringStartup) ||
(f == kSavesSupportThumbnail) ||
(f == kSavesSupportMetaInfo) ||
(f == kSavesSupportCreationDate);
}

virtual int getMaximumSaveSlot() const { return 99; }
virtual SaveStateList listSaves(const char *target) const { return SaveStateList(); }
SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const { return SaveStateDescriptor(); }

virtual SaveStateList listSaves(const char *target) const {
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
SaveGameHeader header;
Common::String pattern = target;
pattern += ".###";

Common::StringArray filenames;
filenames = saveFileMan->listSavefiles(pattern.c_str());

SaveStateList saveList;

for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
// Obtain the last 3 digits of the filename, since they correspond to the save slot
int slotNum = atoi(file->c_str() + file->size() - 3);

if ((slotNum >= 0) && (slotNum <= 999)) {
Common::InSaveFile *in = saveFileMan->openForLoading(file->c_str());
if (in) {
if (DM::readSaveGameHeader(in, &header))
saveList.push_back(SaveStateDescriptor(slotNum, header._descr.getDescription()));
delete in;
}
}
}

// Sort saves based on slot number.
Common::sort(saveList.begin(), saveList.end(), SaveStateDescriptorSlotComparator());
return saveList;
}

SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const {
Common::String filename = Common::String::format("%s.%03u", target, slot);
Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename.c_str());

if (in) {
DM::SaveGameHeader header;

bool successfulRead = DM::readSaveGameHeader(in, &header);
delete in;

if (successfulRead) {
SaveStateDescriptor desc(slot, header._descr.getDescription());

return header._descr;
}
}

return SaveStateDescriptor();
}

virtual void removeSaveState(const char *target, int slot) const {}
};

Expand Down
15 changes: 11 additions & 4 deletions engines/dm/dm.cpp
Expand Up @@ -25,6 +25,7 @@
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
*/

#include "common/config-manager.h"
#include "common/scummsys.h"
#include "common/system.h"

Expand Down Expand Up @@ -262,11 +263,17 @@ void DMEngine::f463_initializeGame() {
_textMan->f54_textInitialize();
_objectMan->loadObjectNames();
_eventMan->initMouse();

int16 saveSlot = 1;
do {
f441_processEntrance();
if (_engineShouldQuit)
return;
} while (f435_loadgame(1) != k1_LoadgameSuccess);
if (ConfMan.hasKey("save_slot")) {
saveSlot = ConfMan.getInt("save_slot");
} else {
f441_processEntrance();
if (_engineShouldQuit)
return;
}
} while (f435_loadgame(saveSlot) != k1_LoadgameSuccess);

_displayMan->f466_loadIntoBitmap(k11_MenuSpellAreLinesIndice, _menuMan->_gK73_bitmapSpellAreaLines); // @ F0396_MENUS_LoadSpellAreaLinesBitmap

Expand Down
3 changes: 2 additions & 1 deletion engines/dm/dm.h
Expand Up @@ -212,7 +212,6 @@ class DMEngine : public Engine {
void initArrays();
Common::String getSavefileName(uint16 slot);
void writeSaveGameHeader(Common::OutSaveFile *out, const Common::String &saveName);
bool readSaveGameHeader(Common::InSaveFile *file, SaveGameHeader *header);
void f439_drawEntrance(); // @ F0439_STARTEND_DrawEntrance
public:
explicit DMEngine(OSystem *syst, const ADGameDescription *gameDesc);
Expand Down Expand Up @@ -295,6 +294,8 @@ class DMEngine : public Engine {
int16 _g318_waitForInputMaxVerticalBlankCount; // @ G0318_i_WaitForInputMaximumVerticalBlankCount
};

bool readSaveGameHeader(Common::InSaveFile* in, SaveGameHeader* header);

} // End of namespace DM

#endif
2 changes: 1 addition & 1 deletion engines/dm/loadsave.cpp
Expand Up @@ -375,7 +375,7 @@ void DMEngine::writeSaveGameHeader(Common::OutSaveFile* out, const Common::Strin
}


bool DMEngine::readSaveGameHeader(Common::InSaveFile* in, SaveGameHeader* header) {
bool readSaveGameHeader(Common::InSaveFile* in, SaveGameHeader* header) {
uint32 id = in->readUint32BE();

// Check if it's a valid ScummVM savegame
Expand Down

0 comments on commit bcb0676

Please sign in to comment.