aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm
diff options
context:
space:
mode:
authorMax Horn2008-02-04 10:15:21 +0000
committerMax Horn2008-02-04 10:15:21 +0000
commit5fb7f7a4d66c48be928440c3142b196a479ca94c (patch)
tree14d1855b57dc2306ef094887a1b735b2722148b1 /engines/scumm
parentdd7fcd686790ea6a2e9021eac5b9e1c8bff88d26 (diff)
downloadscummvm-rg350-5fb7f7a4d66c48be928440c3142b196a479ca94c.tar.gz
scummvm-rg350-5fb7f7a4d66c48be928440c3142b196a479ca94c.tar.bz2
scummvm-rg350-5fb7f7a4d66c48be928440c3142b196a479ca94c.zip
Commited updated version of my own patch #1868402: Basic savestate plugin API
svn-id: r30786
Diffstat (limited to 'engines/scumm')
-rw-r--r--engines/scumm/detection.cpp36
-rw-r--r--engines/scumm/dialogs.cpp4
-rw-r--r--engines/scumm/saveload.cpp35
-rw-r--r--engines/scumm/script_v5.cpp4
-rw-r--r--engines/scumm/script_v8.cpp6
-rw-r--r--engines/scumm/scumm.h2
6 files changed, 64 insertions, 23 deletions
diff --git a/engines/scumm/detection.cpp b/engines/scumm/detection.cpp
index b1f14acc61..2b30780a6b 100644
--- a/engines/scumm/detection.cpp
+++ b/engines/scumm/detection.cpp
@@ -29,6 +29,8 @@
#include "common/fs.h"
#include "common/list.h"
#include "common/md5.h"
+#include "common/savefile.h"
+#include "common/system.h"
#include "scumm/detection.h"
#include "scumm/detection_tables.h"
@@ -675,6 +677,8 @@ public:
virtual GameList detectGames(const FSList &fslist) const;
virtual PluginError createInstance(OSystem *syst, Engine **engine) const;
+
+ virtual SaveStateList listSaves(const char *target) const;
};
GameList ScummMetaEngine::getSupportedGames() const {
@@ -928,4 +932,36 @@ const char *ScummMetaEngine::getCopyright() const {
"Humongous SCUMM Games (C) Humongous";
}
+namespace Scumm {
+ extern bool getSavegameName(Common::InSaveFile *in, Common::String &desc, int heversion);
+}
+
+SaveStateList ScummMetaEngine::listSaves(const char *target) const {
+ Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
+ Common::StringList filenames;
+ Common::String saveDesc;
+ Common::String pattern = target;
+ pattern += ".s??";
+
+ filenames = saveFileMan->listSavefiles(pattern.c_str());
+ sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..)
+
+ SaveStateList saveList;
+ for (Common::StringList::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->c_str());
+ if (in) {
+ Scumm::getSavegameName(in, saveDesc, 0); // FIXME: heversion?!?
+ saveList.push_back(SaveStateDescriptor(slotNum, saveDesc, *file));
+ delete in;
+ }
+ }
+ }
+
+ return saveList;
+}
+
REGISTER_PLUGIN(SCUMM, ScummMetaEngine);
diff --git a/engines/scumm/dialogs.cpp b/engines/scumm/dialogs.cpp
index e008ce2179..23efa05dd2 100644
--- a/engines/scumm/dialogs.cpp
+++ b/engines/scumm/dialogs.cpp
@@ -421,16 +421,14 @@ void SaveLoadChooser::updateInfos() {
Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) {
// Get savegame descriptions
Common::StringList descriptions;
- char name[32];
uint i = saveMode ? 1 : 0; //the autosave is on slot #0
bool avail_saves[81];
scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves));
for (; i < ARRAYSIZE(avail_saves); i++) {
+ Common::String name;
if (avail_saves[i])
scumm->getSavegameName(i, name);
- else
- name[0] = 0;
descriptions.push_back(name);
}
diff --git a/engines/scumm/saveload.cpp b/engines/scumm/saveload.cpp
index b9e3a9287b..8d23e47bbf 100644
--- a/engines/scumm/saveload.cpp
+++ b/engines/scumm/saveload.cpp
@@ -431,39 +431,46 @@ void ScummEngine::listSavegames(bool *marks, int num) {
}
}
-bool ScummEngine::getSavegameName(int slot, char *desc) {
+bool getSavegameName(Common::InSaveFile *in, Common::String &desc, int heversion);
+
+bool ScummEngine::getSavegameName(int slot, Common::String &desc) {
+ Common::InSaveFile *in = 0;
+ bool result = false;
char filename[256];
- Common::SeekableReadStream *in;
- SaveGameHeader hdr;
+ desc.clear();
makeSavegameName(filename, slot, false);
- if (!(in = _saveFileMan->openForLoading(filename))) {
- strcpy(desc, "");
- return false;
+ in = _saveFileMan->openForLoading(filename);
+ if (in) {
+ result = Scumm::getSavegameName(in, desc, _game.heversion);
+ delete in;
}
+ return result;
+}
+
+bool getSavegameName(Common::InSaveFile *in, Common::String &desc, int heversion) {
+ SaveGameHeader hdr;
if (!loadSaveGameHeader(in, hdr)) {
- delete in;
- strcpy(desc, "Invalid savegame");
+ desc = "Invalid savegame";
return false;
}
- delete in;
if (hdr.ver > CURRENT_VER)
hdr.ver = TO_LE_32(hdr.ver);
if (hdr.ver < VER(7) || hdr.ver > CURRENT_VER) {
- strcpy(desc, "Invalid version");
+ desc = "Invalid version";
return false;
}
// We (deliberately) broke HE savegame compatibility at some point.
- if (hdr.ver < VER(57) && _game.heversion >= 60) {
- strcpy(desc, "Unsupported version");
+ if (hdr.ver < VER(57) && heversion >= 60) {
+ desc = "Unsupported version";
return false;
}
- memcpy(desc, hdr.name, sizeof(hdr.name));
- desc[sizeof(hdr.name) - 1] = 0;
+ hdr.name[sizeof(hdr.name) - 1] = 0;
+ desc = hdr.name;
return true;
}
diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp
index d54ec4b45a..431321f459 100644
--- a/engines/scumm/script_v5.cpp
+++ b/engines/scumm/script_v5.cpp
@@ -942,7 +942,6 @@ void ScummEngine_v5::loadVars() {
int slotSize;
byte* slotContent;
int savegameId;
- char name[32];
bool avail_saves[100];
if (a == STRINGID_IQ_SERIES && b == STRINGID_IQ_SERIES) {
@@ -960,9 +959,10 @@ void ScummEngine_v5::loadVars() {
// load savegame names
savegameId = slot - a + 1;
+ Common::String name;
if (avail_saves[savegameId] && getSavegameName(savegameId, name)) {
int pos;
- char *ptr = name;
+ const char *ptr = name.c_str();
// slotContent ends with {'\0','@'} -> max. length = slotSize-2
for (pos = 0; pos < slotSize - 2; ++pos) {
if (!ptr[pos])
diff --git a/engines/scumm/script_v8.cpp b/engines/scumm/script_v8.cpp
index b97626d3d9..08629afb07 100644
--- a/engines/scumm/script_v8.cpp
+++ b/engines/scumm/script_v8.cpp
@@ -1235,9 +1235,9 @@ void ScummEngine_v8::o8_kernelSetFunctions() {
removeBlastTexts();
break;
case 25: { // saveGameReadName
- char name[30];
+ Common::String name;
if (getSavegameName(args[1], name)) {
- int size = resStrLen((const byte *)name) + 1;
+ int size = name.size() + 1;
_res->nukeResource(rtString, args[2]);
ArrayHeader *ah = (ArrayHeader *)_res->createResource(rtString, args[2], size + sizeof(ArrayHeader));
@@ -1245,7 +1245,7 @@ void ScummEngine_v8::o8_kernelSetFunctions() {
ah->dim1 = TO_LE_16(size + 1);
ah->dim2 = TO_LE_16(1);
- memcpy(getStringAddress(args[2]), name, size);
+ memcpy(getStringAddress(args[2]), name.c_str(), size);
}
break;
}
diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h
index f636fee825..767aa53cf8 100644
--- a/engines/scumm/scumm.h
+++ b/engines/scumm/scumm.h
@@ -623,7 +623,7 @@ protected:
int getKeyState(int key);
public:
- bool getSavegameName(int slot, char *desc);
+ bool getSavegameName(int slot, Common::String &desc);
void listSavegames(bool *marks, int num);
void requestSave(int slot, const char *name, bool temporary = false);