From 83e1896b35fe5f41beda2d782da43be7283cb9d4 Mon Sep 17 00:00:00 2001 From: Justin99x Date: Sun, 3 Aug 2025 07:53:59 -0700 Subject: [PATCH] Go back to EndLoadGame hook, add hook to handle resetting to defaults --- src/save_options/hooks.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/save_options/hooks.py b/src/save_options/hooks.py index 4457b4a..35d9f68 100644 --- a/src/save_options/hooks.py +++ b/src/save_options/hooks.py @@ -120,19 +120,24 @@ def save_game(_1: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> N save_options.options.any_option_changed = False -@hook("WillowGame.WillowPlayerController:FinishSaveGameLoad", immediately_enable=True) -def end_load_game(_1: UObject, args: WrappedStruct, _3: Any, _4: BoundFunction) -> None: # noqa: D103 - # We hook this to send data back to any registered mod save options. This gets called when - # loading character in main menu also. No callback here because the timing of when this is - # called doesn't make much sense to do anything with it. See hook on LoadPlayerSaveGame. - - # Often we'll load a save from a character with no save data. We'll set all save options - # to default first to cover for any missing data. +@hook("WillowGame.WillowPlayerController:LoadGame", immediately_enable=True) +def load_game(*_: Any) -> None: # noqa: D103 + # We hook this to set all options to default whenever a new character is loaded. This covers + # both new characters and existing. Characters with existing save options will have their + # options set in the EndLoadGame hook. for mod_save_options in registered_save_options.values(): for save_option in mod_save_options.values(): set_option_to_default(save_option) - save_game = args.SaveGame + +@hook("WillowGame.WillowSaveGameManager:EndLoadGame", Type.POST, immediately_enable=True) +def end_load_game(_1: UObject, _2: WrappedStruct, ret: Any, _4: BoundFunction) -> None: # noqa: D103 + # We hook this to send data back to any registered mod save options. This gets called when + # loading character in main menu also. No callback here because the timing of when this is + # called doesn't make much sense to do anything with it. See hook on LoadPlayerSaveGame. + + # This function returns the new save game object, so use a post hook and grab it from `ret` + save_game = ret if not save_game: return extracted_save_data = _extract_save_data(save_game.UnloadableDlcLockoutList)