[Scummvm-git-logs] scummvm master -> 8cc72754d7ebd358067f8c1fd1e2fedda53909bc

lephilousophe noreply at scummvm.org
Tue Oct 15 19:24:20 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
8cc72754d7 GRIM: Patch saves on the fly


Commit: 8cc72754d7ebd358067f8c1fd1e2fedda53909bc
    https://github.com/scummvm/scummvm/commit/8cc72754d7ebd358067f8c1fd1e2fedda53909bc
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-10-15T21:24:17+02:00

Commit Message:
GRIM: Patch saves on the fly

This is a follow up to fix #13139 and #14987.
All saves created with the faulty patch get contaminated so we
decontaminate them at load time by applying a minimized fixup.

This will avoid players to restart a game from scratch and any game
saved again will get this fix.

Changed paths:
  A engines/grim/lua_grim_patch.cpp
    engines/grim/grim.cpp
    engines/grim/lua.h
    engines/grim/module.mk


diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp
index 366b6aaa3ba..9525248f3b1 100644
--- a/engines/grim/grim.cpp
+++ b/engines/grim/grim.cpp
@@ -1263,6 +1263,18 @@ void GrimEngine::savegameRestore() {
 	lua_Restore(_savedState);
 	Debug::debug(Debug::Engine, "Lua restored successfully.");
 
+	if (getGameType() == GType_GRIM && !(getGameFlags() & ADGF_DEMO) &&
+		_savedState->saveMajorVersion() == 22 &&
+		_savedState->saveMinorVersion() >= 7 &&
+		_savedState->saveMinorVersion() <= 28) {
+		// Since ResidualVM 0.2.0, a ResidualVM/ScummVM specific patch was provided broken.
+		// We patch here the code to fix all saves containing this invalid code.
+		// cf. bug #13139 and #14987
+		lua_PatchGrimSave();
+	}
+
+	delete _savedState;
+
 	_justSaveLoaded = true;
 
 	//Re-read the values, since we may have been in some state that changed them when loading the savegame,
@@ -1278,13 +1290,6 @@ void GrimEngine::savegameRestore() {
 
 	debug(2, "GrimEngine::savegameRestore() finished.");
 
-	// Related to bug #13139 and #14987
-	if (getGameType() == GType_GRIM && !(getGameFlags() & ADGF_DEMO) && _savedState->saveMajorVersion() == SaveGame::SAVEGAME_MAJOR_VERSION && _savedState->saveMinorVersion() <= 28) {
-		GUI::displayErrorDialog(Common::U32String::format(_("The game save file may be invalid and prevent game to be completed.")));
-	}
-
-	delete _savedState;
-
 	_shortFrame = true;
 	clearEventQueue();
 	invalidateActiveActorsList();
diff --git a/engines/grim/lua.h b/engines/grim/lua.h
index 95f9bab9542..e1c24ac0848 100644
--- a/engines/grim/lua.h
+++ b/engines/grim/lua.h
@@ -58,6 +58,11 @@ class PoolObjectBase;
 #define LUA_OPCODE(class, func) \
 	class::static_##func
 
+/**
+ * Patch Lua state after loading a broken Grim save
+ */
+void lua_PatchGrimSave();
+
 /**
  * @brief A list of arguments to be passed to a Lua function.
  *
diff --git a/engines/grim/lua_grim_patch.cpp b/engines/grim/lua_grim_patch.cpp
new file mode 100644
index 00000000000..ad44d1b8928
--- /dev/null
+++ b/engines/grim/lua_grim_patch.cpp
@@ -0,0 +1,49 @@
+/* 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.
+ *
+ * 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.
+ *
+ * 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
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#define FORBIDDEN_SYMBOL_EXCEPTION_setjmp
+#define FORBIDDEN_SYMBOL_EXCEPTION_longjmp
+
+#include "engines/grim/lua/lstate.h"
+#include "engines/grim/lua/lua.h"
+
+namespace Grim {
+
+void lua_PatchGrimSave() {
+	// Since ResidualVM 0.2.0, a ResidualVM/ScummVM specific patch was provided broken.
+	// We patch here the code to fix all saves containing this invalid code.
+	// cf. bug #13139 and #14987
+	// The patch here doesn't match exactly the fixed patch.
+	// We minimize here the number of bytes to patch with an equivalent result.
+	TProtoFunc *tempProtoFunc = (TProtoFunc *)rootproto.next;
+	while (tempProtoFunc) {
+		if ((tempProtoFunc->lineDefined == 77) &&
+			(strcmp(tempProtoFunc->fileName->str, "Scripts\\vd.lua") == 0) &&
+			(memcmp(tempProtoFunc->code + 210, "\x22\x29\x39\x03\x32\x22\x30\x79\x02", 9) == 0)) {
+			tempProtoFunc->code[211] = 0x33;
+			tempProtoFunc->code[218] = 0x03;
+			break;
+		}
+		tempProtoFunc = (TProtoFunc *)tempProtoFunc->head.next;
+	}
+}
+
+} // end of namespace Grim
diff --git a/engines/grim/module.mk b/engines/grim/module.mk
index 67607db9fb7..eda8a07dd27 100644
--- a/engines/grim/module.mk
+++ b/engines/grim/module.mk
@@ -111,6 +111,7 @@ MODULE_OBJS := \
 	lipsync.o \
 	localize.o \
 	lua.o \
+	lua_grim_patch.o \
 	lua_v1.o \
 	lua_v1_actor.o \
 	lua_v1_graphics.o \




More information about the Scummvm-git-logs mailing list