From 969952a4e0a04cca1ef03d03f7d7e63075c96226 Mon Sep 17 00:00:00 2001 From: DudeMcDude Date: Sat, 16 Jan 2021 13:51:57 +0200 Subject: [PATCH] savehook changes to support new modules using save archivation --- TemplePlus/gamesystems/gamelib_load.cpp | 9 ++++++++- TemplePlus/gamesystems/gamelib_save.cpp | 10 +++++++++- tpdata/templeplus/lib/templeplus/savehook.py | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/TemplePlus/gamesystems/gamelib_load.cpp b/TemplePlus/gamesystems/gamelib_load.cpp index a03190abd..ffd535f5b 100644 --- a/TemplePlus/gamesystems/gamelib_load.cpp +++ b/TemplePlus/gamesystems/gamelib_load.cpp @@ -186,6 +186,13 @@ bool GameSystems::LoadGame(const string& filename) { return false; } + { + // user savehook + auto saveHookArgs = Py_BuildValue("(s)", filename.c_str()); + pythonObjIntegration.ExecuteScript("templeplus.savehook", "load", saveHookArgs); + Py_DECREF(saveHookArgs); + } + addresses.UiMmRelated2(63); logger->info("Completed loading of save game"); @@ -195,7 +202,7 @@ bool GameSystems::LoadGame(const string& filename) { if (temple::Dll::GetInstance().HasCo8Hooks()){ // Co8 load hook auto loadHookArgs = Py_BuildValue("(s)", filename.c_str()); - pythonObjIntegration.ExecuteScript("templeplus.savehook", "load", loadHookArgs); + pythonObjIntegration.ExecuteScript("templeplus.savehook", "post_load", loadHookArgs); Py_DECREF(loadHookArgs); if (modSupport.IsCo8NCEdition()){ diff --git a/TemplePlus/gamesystems/gamelib_save.cpp b/TemplePlus/gamesystems/gamelib_save.cpp index 77cd682bf..d86dce9e4 100644 --- a/TemplePlus/gamesystems/gamelib_save.cpp +++ b/TemplePlus/gamesystems/gamelib_save.cpp @@ -211,6 +211,14 @@ bool GameSystems::SaveGame(const string& filename, const string& displayName) { tio_fclose(file); + { + // user savehook + auto saveHookArgs = Py_BuildValue("(s)", filename.c_str()); + pythonObjIntegration.ExecuteScript("templeplus.savehook", "save", saveHookArgs); + Py_DECREF(saveHookArgs); + } + + if (!addresses.UiSaveGame()) { tio_remove(fullPath); return false; @@ -256,7 +264,7 @@ bool GameSystems::SaveGame(const string& filename, const string& displayName) { // co8 savehook auto saveHookArgs = Py_BuildValue("(s)", filename.c_str()); - pythonObjIntegration.ExecuteScript("templeplus.savehook", "save", saveHookArgs); + pythonObjIntegration.ExecuteScript("templeplus.savehook", "post_save", saveHookArgs); Py_DECREF(saveHookArgs); return true; diff --git a/tpdata/templeplus/lib/templeplus/savehook.py b/tpdata/templeplus/lib/templeplus/savehook.py index b6aa2e3ca..bdfd71e90 100644 --- a/tpdata/templeplus/lib/templeplus/savehook.py +++ b/tpdata/templeplus/lib/templeplus/savehook.py @@ -1,20 +1,27 @@ #use 4 space indentation! -# save hook (default - Co8 hook; will silently fail for vanilla; feel free to change for your own custom mod!) def save(filename): + return + +def load(filename): + return + +# Co8 python save hook - executes after the archive is done +# save hook (default - Co8 hook; will silently fail for vanilla; feel free to change for your own custom mod!) +def post_save(filename): try: import _co8init print "imported Co8Init inside templeplus package" _co8init.save(filename) - print "Save hook successful" + print "Co8 Save hook successful" except: - print "Save hook failed\n" + print "Co8 Save hook failed\n" # save hook (default - Co8 hook; will silently fail for vanilla; feel free to change for your own custom mod!) -def load(filename): +def post_load(filename): try: import _co8init _co8init.load(filename) except: - print "Load hook failed\n" \ No newline at end of file + print "Co8 Load hook failed\n" \ No newline at end of file