[Scummvm-cvs-logs] SF.net SVN: scummvm:[49687] scummvm/trunk/engines/sci/engine

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Tue Jun 15 10:25:51 CEST 2010


Revision: 49687
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49687&view=rev
Author:   thebluegr
Date:     2010-06-15 08:25:51 +0000 (Tue, 15 Jun 2010)

Log Message:
-----------
Added a signature of the game itself inside saved games (the size of script 0, as well as the offset of the game object, which are unique for each game), to prevent users from loading saved games across different versions of the same game. In the cases where we can't load a saved game, throw a nice GUI dialog instead of a console warning

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/savegame.cpp
    scummvm/trunk/engines/sci/engine/savegame.h

Modified: scummvm/trunk/engines/sci/engine/savegame.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-15 08:21:39 UTC (rev 49686)
+++ scummvm/trunk/engines/sci/engine/savegame.cpp	2010-06-15 08:25:51 UTC (rev 49687)
@@ -53,6 +53,8 @@
 #include "sci/graphics/gui32.h"
 #endif
 
+#include "gui/message.h"
+
 namespace Sci {
 
 
@@ -307,6 +309,13 @@
 	s.skip(4, VER(9), VER(9));	// obsolete: used to be game version
 	s.syncAsSint32LE(obj.savegame_date);
 	s.syncAsSint32LE(obj.savegame_time);
+	if (s.getVersion() < 22) {
+		obj.game_object_offset = 0;
+		obj.script0_size = 0;
+	} else {
+		s.syncAsUint16LE(obj.game_object_offset);
+		s.syncAsUint16LE(obj.script0_size);
+	}
 }
 
 void EngineState::saveLoadWithSerializer(Common::Serializer &s) {
@@ -862,6 +871,10 @@
 	meta.savegame_date = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
 	meta.savegame_time = ((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.script0_size = script0->size;
+	meta.game_object_offset = g_sci->getGameObject().offset;
+
 	if (s->executionStackBase) {
 		warning("Cannot save from below kernel function");
 		return 1;
@@ -892,15 +905,33 @@
 
 	if ((meta.savegame_version < MINIMUM_SAVEGAME_VERSION) ||
 	    (meta.savegame_version > CURRENT_SAVEGAME_VERSION)) {
+		/*
 		if (meta.savegame_version < MINIMUM_SAVEGAME_VERSION)
-			warning("Old savegame version detected- can't load");
+			warning("Old savegame version detected, unable to load it");
 		else
-			warning("Savegame version is %d- maximum supported is %0d", meta.savegame_version, CURRENT_SAVEGAME_VERSION);
+			warning("Savegame version is %d, maximum supported is %0d", meta.savegame_version, CURRENT_SAVEGAME_VERSION);
+		*/
 
+		GUI::MessageDialog dialog("The format of this saved game is obsolete, unable to load it", "OK");
+		dialog.runModal();
+
 		s->r_acc = make_reg(0, 1);	// signal failure
 		return;
 	}
 
+	if (meta.game_object_offset > 0 && meta.script0_size > 0) {
+		Resource *script0 = g_sci->getResMan()->findResource(ResourceId(kResourceTypeScript, 0), false);
+		if (script0->size != meta.script0_size || g_sci->getGameObject().offset != meta.game_object_offset) {
+			//warning("This saved game was created with a different version of the game, unable to load it");
+
+			GUI::MessageDialog dialog("This saved game was created with a different version of the game, unable to load it", "OK");
+			dialog.runModal();
+
+			s->r_acc = make_reg(0, 1);	// signal failure
+			return;
+		}
+	}
+
 	if (meta.savegame_version >= 12) {
 		// We don't need the thumbnail here, so just read it and discard it
 		Graphics::Surface *thumbnail = new Graphics::Surface();

Modified: scummvm/trunk/engines/sci/engine/savegame.h
===================================================================
--- scummvm/trunk/engines/sci/engine/savegame.h	2010-06-15 08:21:39 UTC (rev 49686)
+++ scummvm/trunk/engines/sci/engine/savegame.h	2010-06-15 08:25:51 UTC (rev 49687)
@@ -36,7 +36,7 @@
 struct EngineState;
 
 enum {
-	CURRENT_SAVEGAME_VERSION = 21,
+	CURRENT_SAVEGAME_VERSION = 22,
 	MINIMUM_SAVEGAME_VERSION = 9
 };
 
@@ -47,6 +47,8 @@
 	Common::String game_version;
 	int savegame_date;
 	int savegame_time;
+	uint16 game_object_offset;
+	uint16 script0_size;
 };
 
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list