From c4f9712eff7f22f41d1636fb5e799e928089245e Mon Sep 17 00:00:00 2001 From: Jordan Longstaff Date: Sat, 25 Oct 2025 16:25:33 -0400 Subject: [PATCH] Modularize scene-specific Dirt Path fix (#5871) * Modularize scene-specific Dirt Path fix * Use macro in fix function * Condition hook on fix being enabled * Rename update function --- soh/soh/Enhancements/Fixes/DirtPathFix.cpp | 26 ++++++++++++++++++++++ soh/soh/Enhancements/mods.cpp | 19 ---------------- soh/soh/Enhancements/mods.h | 2 +- soh/soh/SohGui/SohMenuEnhancements.cpp | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 soh/soh/Enhancements/Fixes/DirtPathFix.cpp diff --git a/soh/soh/Enhancements/Fixes/DirtPathFix.cpp b/soh/soh/Enhancements/Fixes/DirtPathFix.cpp new file mode 100644 index 000000000..0ceafc9c1 --- /dev/null +++ b/soh/soh/Enhancements/Fixes/DirtPathFix.cpp @@ -0,0 +1,26 @@ +#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h" +#include "soh/Enhancements/enhancementTypes.h" +#include "soh/Enhancements/mods.h" +#include "soh/ShipInit.hpp" + +static constexpr ZFightingFixType CVAR_DIRT_PATH_DEFAULT = ZFIGHT_FIX_DISABLED; +#define CVAR_DIRT_PATH_NAME CVAR_ENHANCEMENT("SceneSpecificDirtPathFix") +#define CVAR_DIRT_PATH_VALUE CVarGetInteger(CVAR_DIRT_PATH_NAME, CVAR_DIRT_PATH_DEFAULT) + +void DirtPathFix_UpdateZFightingMode(int32_t sceneNum) { + switch (sceneNum) { + case SCENE_HYRULE_FIELD: + case SCENE_KOKIRI_FOREST: + case SCENE_HYRULE_CASTLE: + CVarSetInteger(CVAR_Z_FIGHTING_MODE, CVAR_DIRT_PATH_VALUE); + return; + default: + CVarClear(CVAR_Z_FIGHTING_MODE); + } +} + +static void RegisterDirtPathFix() { + COND_HOOK(OnTransitionEnd, CVAR_DIRT_PATH_VALUE, DirtPathFix_UpdateZFightingMode); +} + +static RegisterShipInitFunc initFunc(RegisterDirtPathFix, { CVAR_DIRT_PATH_NAME }); diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index 00f92e7bf..cd53428bd 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -296,24 +296,6 @@ void UpdateHyperEnemiesState() { } } -void UpdateDirtPathFixState(int32_t sceneNum) { - switch (sceneNum) { - case SCENE_HYRULE_FIELD: - case SCENE_KOKIRI_FOREST: - case SCENE_HYRULE_CASTLE: - CVarSetInteger(CVAR_Z_FIGHTING_MODE, - CVarGetInteger(CVAR_ENHANCEMENT("SceneSpecificDirtPathFix"), ZFIGHT_FIX_DISABLED)); - return; - default: - CVarClear(CVAR_Z_FIGHTING_MODE); - } -} - -void RegisterMenuPathFix() { - GameInteractor::Instance->RegisterGameHook( - [](int32_t sceneNum) { UpdateDirtPathFixState(sceneNum); }); -} - void UpdateMirrorModeState(int32_t sceneNum) { static bool prevMirroredWorld = false; bool nextMirroredWorld = false; @@ -890,7 +872,6 @@ void InitMods() { RegisterDeleteFileOnDeath(); RegisterHyperBosses(); UpdateHyperEnemiesState(); - RegisterMenuPathFix(); RegisterMirrorModeHandler(); RegisterResetNaviTimer(); RegisterEnemyDefeatCounts(); diff --git a/soh/soh/Enhancements/mods.h b/soh/soh/Enhancements/mods.h index 8ada99f1e..643562bfd 100644 --- a/soh/soh/Enhancements/mods.h +++ b/soh/soh/Enhancements/mods.h @@ -7,7 +7,7 @@ extern "C" { #endif -void UpdateDirtPathFixState(int32_t sceneNum); +void DirtPathFix_UpdateZFightingMode(int32_t sceneNum); void UpdateMirrorModeState(int32_t sceneNum); void UpdateHurtContainerModeState(bool newState); void PatchToTMedallions(); diff --git a/soh/soh/SohGui/SohMenuEnhancements.cpp b/soh/soh/SohGui/SohMenuEnhancements.cpp index 639d7469b..844f18687 100644 --- a/soh/soh/SohGui/SohMenuEnhancements.cpp +++ b/soh/soh/SohGui/SohMenuEnhancements.cpp @@ -1083,7 +1083,7 @@ void SohMenu::AddMenuEnhancements() { .RaceDisable(false) .Callback([](WidgetInfo& info) { if (gPlayState != NULL) { - UpdateDirtPathFixState(gPlayState->sceneNum); + DirtPathFix_UpdateZFightingMode(gPlayState->sceneNum); } }) .Options(