Skip to content

Commit

Permalink
Merge pull request #457 from GrognardsFromHell/SA_bugfix
Browse files Browse the repository at this point in the history
savehook changes to support new modules using save archivation
  • Loading branch information
DudeMcDude authored Jan 20, 2021
2 parents 979f9d3 + 969952a commit e7a5eac
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
9 changes: 8 additions & 1 deletion TemplePlus/gamesystems/gamelib_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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()){
Expand Down
10 changes: 9 additions & 1 deletion TemplePlus/gamesystems/gamelib_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 12 additions & 5 deletions tpdata/templeplus/lib/templeplus/savehook.py
Original file line number Diff line number Diff line change
@@ -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"
print "Co8 Load hook failed\n"

0 comments on commit e7a5eac

Please sign in to comment.