Modularize custom skeleton hooks (#5931)

This commit is contained in:
Jordan Longstaff
2025-11-09 20:27:52 -05:00
committed by GitHub
parent a3e540ebfe
commit c0848ccba8
2 changed files with 37 additions and 25 deletions

View File

@@ -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);

View File

@@ -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 <soh/Enhancements/item-tables/ItemTableManager.h>
@@ -657,29 +656,6 @@ void RegisterRandomizedEnemySizes() {
});
}
void RegisterCustomSkeletons() {
static int8_t previousTunic = -1;
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameFrameUpdate>([]() {
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<GameInteractor::OnAssetAltChange>([]() {
if (!GameInteractor::IsSaveLoaded() || gPlayState == NULL) {
return;
}
SOH::SkeletonPatcher::UpdateCustomSkeletons();
});
}
void InitMods() {
RandomizerRegisterHooks();
TimeSaverRegisterHooks();
@@ -695,5 +671,4 @@ void InitMods() {
RegisterPatchHandHandler();
RegisterHurtContainerModeHandler();
RandoKaleido_RegisterHooks();
RegisterCustomSkeletons();
}