aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Snover2017-09-23 01:40:25 -0500
committerColin Snover2017-09-23 20:56:48 -0500
commit9298f6a81e6218e7745a0ab6e530ecb5fabc460b (patch)
treea7c345551aec9864cf3f8356b055f7cb392249af
parentd17ae077dd014d380e8091161fe1f584a8cc29ba (diff)
downloadscummvm-rg350-9298f6a81e6218e7745a0ab6e530ecb5fabc460b.tar.gz
scummvm-rg350-9298f6a81e6218e7745a0ab6e530ecb5fabc460b.tar.bz2
scummvm-rg350-9298f6a81e6218e7745a0ab6e530ecb5fabc460b.zip
SCI: Split save game metadata writing to separate function
RAMA has its own custom save game format that game scripts write, but we still want to be able to use these save game files from the ScummVM launcher, so the metadata has to be able to be written separately from the rest of the game saving.
-rw-r--r--engines/sci/engine/savegame.cpp47
-rw-r--r--engines/sci/engine/savegame.h4
2 files changed, 27 insertions, 24 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 8c89b90517..60ad497b84 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -1184,30 +1184,8 @@ void SegManager::reconstructClones() {
bool gamestate_save(EngineState *s, Common::WriteStream *fh, const Common::String &savename, const Common::String &version) {
- TimeDate curTime;
- g_system->getTimeAndDate(curTime);
-
- SavegameMetadata meta;
- meta.version = CURRENT_SAVEGAME_VERSION;
- meta.name = savename;
- meta.gameVersion = version;
- meta.saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
- meta.saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
-
- Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false);
- meta.script0Size = script0->size();
- meta.gameObjectOffset = g_sci->getGameObject().getOffset();
-
- // Checking here again
-// TODO: This breaks Torin autosave, is there actually any reason for it?
-// if (s->executionStackBase) {
-// warning("Cannot save from below kernel function");
-// return false;
-// }
-
- Common::Serializer ser(0, fh);
- sync_SavegameMetadata(ser, meta);
- Graphics::saveThumbnail(*fh);
+ set_savegame_metadata(fh, savename, version);
+ Common::Serializer ser(nullptr, fh);
s->saveLoadWithSerializer(ser); // FIXME: Error handling?
if (g_sci->_gfxPorts)
g_sci->_gfxPorts->saveLoadWithSerializer(ser);
@@ -1395,6 +1373,27 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
s->gameIsRestarting = GAMEISRESTARTING_RESTORE;
}
+void set_savegame_metadata(Common::WriteStream *fh, const Common::String &savename, const Common::String &version) {
+ TimeDate curTime;
+ g_system->getTimeAndDate(curTime);
+
+ SavegameMetadata meta;
+ meta.version = CURRENT_SAVEGAME_VERSION;
+ meta.name = savename;
+ meta.gameVersion = version;
+ meta.saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
+ meta.saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
+
+ Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false);
+ assert(script0);
+ meta.script0Size = script0->size();
+ meta.gameObjectOffset = g_sci->getGameObject().getOffset();
+
+ Common::Serializer ser(nullptr, fh);
+ sync_SavegameMetadata(ser, meta);
+ Graphics::saveThumbnail(*fh);
+}
+
bool get_savegame_metadata(Common::SeekableReadStream *stream, SavegameMetadata &meta) {
assert(stream);
diff --git a/engines/sci/engine/savegame.h b/engines/sci/engine/savegame.h
index f862b961e0..1ac25b26a9 100644
--- a/engines/sci/engine/savegame.h
+++ b/engines/sci/engine/savegame.h
@@ -120,6 +120,10 @@ void gamestate_restore(EngineState *s, Common::SeekableReadStream *save);
*/
bool get_savegame_metadata(Common::SeekableReadStream *stream, SavegameMetadata &meta);
+/**
+ * Write the header to a savegame.
+ */
+void set_savegame_metadata(Common::WriteStream *fh, const Common::String &savename, const Common::String &version);
} // End of namespace Sci