From db8440e744d043533c13fc8d6e83cddcd6a0deae Mon Sep 17 00:00:00 2001 From: Jordan Longstaff Date: Fri, 23 May 2025 17:04:43 -0400 Subject: [PATCH] Move Shadow Tag Mode hook to its own file (#5179) * Move Shadow Tag Mode hook to its own file * Rename initFunc --- soh/soh/Enhancements/ExtraModes/ShadowTag.cpp | 50 +++++++++++++++++++ soh/soh/Enhancements/mods.cpp | 33 ------------ 2 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 soh/soh/Enhancements/ExtraModes/ShadowTag.cpp diff --git a/soh/soh/Enhancements/ExtraModes/ShadowTag.cpp b/soh/soh/Enhancements/ExtraModes/ShadowTag.cpp new file mode 100644 index 000000000..dc85534c8 --- /dev/null +++ b/soh/soh/Enhancements/ExtraModes/ShadowTag.cpp @@ -0,0 +1,50 @@ +#include +#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" +#include "soh/ShipInit.hpp" +#include "functions.h" + +extern "C" PlayState* gPlayState; + +static constexpr int32_t CVAR_SHADOW_TAG_DEFAULT = 0; +#define CVAR_SHADOW_TAG_NAME CVAR_ENHANCEMENT("ShadowTag") +#define CVAR_SHADOW_TAG_VALUE CVarGetInteger(CVAR_SHADOW_TAG_NAME, CVAR_SHADOW_TAG_DEFAULT) + +static bool shouldSpawn = false; +static uint16_t delayTimer = 60; + +static constexpr s8 ROOM_GREEN_POE = 16; +static constexpr s8 ROOM_BLUE_POE = 13; +static constexpr s8 ROOM_RED_POE = 12; + +void OnPlayerUpdateShadowTag() { + if (gPlayState->sceneNum == SCENE_FOREST_TEMPLE) { + switch (gPlayState->roomCtx.curRoom.num) { + case ROOM_GREEN_POE: + case ROOM_BLUE_POE: + case ROOM_RED_POE: + return; + default: + break; + } + } + + if (shouldSpawn && (delayTimer <= 0)) { + Actor_Spawn(&gPlayState->actorCtx, gPlayState, ACTOR_EN_WALLMAS, 0, 0, 0, 0, 0, 0, 3, false); + shouldSpawn = false; + } else { + delayTimer--; + } +} + +void ResetShadowTagSpawnTimer() { + shouldSpawn = true; + delayTimer = 60; +} + +void RegisterShadowTag() { + COND_HOOK(OnPlayerUpdate, CVAR_SHADOW_TAG_VALUE, OnPlayerUpdateShadowTag); + COND_HOOK(OnSceneSpawnActors, true, []() { ResetShadowTagSpawnTimer(); }); + COND_HOOK(OnSceneInit, true, [](int16_t) { ResetShadowTagSpawnTimer(); }); +} + +static RegisterShipInitFunc initFunc_ShadowTag(RegisterShadowTag, { CVAR_SHADOW_TAG_NAME }); diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index f57e13c01..2e302ea1d 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -159,38 +159,6 @@ void RegisterRupeeDash() { }); } -void RegisterShadowTag() { - static bool shouldSpawn = false; - static uint16_t delayTimer = 60; - - GameInteractor::Instance->RegisterGameHook([]() { - if (!CVarGetInteger(CVAR_ENHANCEMENT("ShadowTag"), 0)) { - return; - } - if (gPlayState->sceneNum == SCENE_FOREST_TEMPLE && // Forest Temple Scene - gPlayState->roomCtx.curRoom.num == 16 || // Green Poe Room - gPlayState->roomCtx.curRoom.num == 13 || // Blue Poe Room - gPlayState->roomCtx.curRoom.num == 12) { // Red Poe Room - return; - } else { - if (shouldSpawn && (delayTimer <= 0)) { - Actor_Spawn(&gPlayState->actorCtx, gPlayState, ACTOR_EN_WALLMAS, 0, 0, 0, 0, 0, 0, 3, false); - shouldSpawn = false; - } else { - delayTimer--; - } - } - }); - GameInteractor::Instance->RegisterGameHook([]() { - shouldSpawn = true; - delayTimer = 60; - }); - GameInteractor::Instance->RegisterGameHook([](int16_t sceneNum) { - shouldSpawn = true; - delayTimer = 60; - }); -} - static bool hasAffectedHealth = false; void UpdatePermanentHeartLossState() { if (!GameInteractor::IsSaveLoaded()) @@ -1015,7 +983,6 @@ void InitMods() { RegisterTTS(); RegisterOcarinaTimeTravel(); RegisterRupeeDash(); - RegisterShadowTag(); RegisterPermanentHeartLoss(); RegisterDeleteFileOnDeath(); RegisterHyperBosses();