From c0848ccba8de116288871d779f1a1e0d83a0ab38 Mon Sep 17 00:00:00 2001 From: Jordan Longstaff Date: Sun, 9 Nov 2025 20:27:52 -0500 Subject: [PATCH] Modularize custom skeleton hooks (#5931) --- soh/soh/Enhancements/CustomSkeletons.cpp | 37 ++++++++++++++++++++++++ soh/soh/Enhancements/mods.cpp | 25 ---------------- 2 files changed, 37 insertions(+), 25 deletions(-) create mode 100644 soh/soh/Enhancements/CustomSkeletons.cpp diff --git a/soh/soh/Enhancements/CustomSkeletons.cpp b/soh/soh/Enhancements/CustomSkeletons.cpp new file mode 100644 index 000000000..8d22e0e1c --- /dev/null +++ b/soh/soh/Enhancements/CustomSkeletons.cpp @@ -0,0 +1,37 @@ +#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" +#include "soh/resource/type/Skeleton.h" +#include "soh/ShipInit.hpp" + +extern "C" { +#include "macros.h" +#include "variables.h" +extern PlayState* gPlayState; +} + +static void UpdateCustomSkeletonOnEquipTunic() { + if (!GameInteractor::IsSaveLoaded() || gPlayState == NULL) { + return; + } + + static int8_t previousTunic = -1; + int8_t equippedTunic = CUR_EQUIP_VALUE(EQUIP_TYPE_TUNIC); + if (equippedTunic != previousTunic) { + SOH::SkeletonPatcher::UpdateCustomSkeletons(); + previousTunic = equippedTunic; + } +} + +static void UpdateCustomSkeletonOnAssetAltChange() { + if (!GameInteractor::IsSaveLoaded() || gPlayState == NULL) { + return; + } + + SOH::SkeletonPatcher::UpdateCustomSkeletons(); +} + +static void RegisterCustomSkeletons() { + COND_HOOK(OnGameFrameUpdate, true, UpdateCustomSkeletonOnEquipTunic); + COND_HOOK(OnAssetAltChange, true, UpdateCustomSkeletonOnAssetAltChange); +} + +static RegisterShipInitFunc initFunc(RegisterCustomSkeletons); diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index 6c38d5de7..e583c2d6e 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -5,7 +5,6 @@ #include "soh/OTRGlobals.h" #include "soh/SaveManager.h" #include "soh/ResourceManagerHelpers.h" -#include "soh/resource/type/Skeleton.h" #include "soh/Enhancements/boss-rush/BossRush.h" #include "soh/Enhancements/enhancementTypes.h" #include @@ -657,29 +656,6 @@ void RegisterRandomizedEnemySizes() { }); } -void RegisterCustomSkeletons() { - static int8_t previousTunic = -1; - - GameInteractor::Instance->RegisterGameHook([]() { - if (!GameInteractor::IsSaveLoaded() || gPlayState == NULL) { - return; - } - - if (CUR_EQUIP_VALUE(EQUIP_TYPE_TUNIC) != previousTunic) { - SOH::SkeletonPatcher::UpdateCustomSkeletons(); - } - previousTunic = CUR_EQUIP_VALUE(EQUIP_TYPE_TUNIC); - }); - - GameInteractor::Instance->RegisterGameHook([]() { - if (!GameInteractor::IsSaveLoaded() || gPlayState == NULL) { - return; - } - - SOH::SkeletonPatcher::UpdateCustomSkeletons(); - }); -} - void InitMods() { RandomizerRegisterHooks(); TimeSaverRegisterHooks(); @@ -695,5 +671,4 @@ void InitMods() { RegisterPatchHandHandler(); RegisterHurtContainerModeHandler(); RandoKaleido_RegisterHooks(); - RegisterCustomSkeletons(); }