diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor.h b/soh/soh/Enhancements/game-interactor/GameInteractor.h index 91a2711c2..1379339f1 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor.h @@ -88,7 +88,7 @@ public: DEFINE_HOOK(OnExitGame, void(int32_t fileNum)); DEFINE_HOOK(OnReceiveItem, void(u8 item)); DEFINE_HOOK(OnSceneInit, void(s16 sceneNum)); - + DEFINE_HOOK(OnPlayerUpdate, void()); DEFINE_HOOK(OnSaveFile, void(int32_t fileNum)); DEFINE_HOOK(OnLoadFile, void(int32_t fileNum)); diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp index fcce3e827..9405f201e 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp @@ -22,6 +22,10 @@ void GameInteractor_ExecuteOnSceneInitHooks(s16 sceneNum) { GameInteractor::Instance->ExecuteHooks(sceneNum); } +void GameInteractor_ExecuteOnPlayerUpdate() { + GameInteractor::Instance->ExecuteHooks(); +} + // MARK: - Save Files void GameInteractor_ExecuteOnSaveFile(int32_t fileNum) { diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h index 6e540c66f..302102552 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h @@ -5,6 +5,7 @@ extern "C" void GameInteractor_ExecuteOnLoadGame(int32_t fileNum); extern "C" void GameInteractor_ExecuteOnExitGame(int32_t fileNum); extern "C" void GameInteractor_ExecuteOnReceiveItemHooks(u8 item); extern "C" void GameInteractor_ExecuteOnSceneInit(s16 sceneNum); +extern "C" void GameInteractor_ExecuteOnPlayerUpdate(); // MARK: - Save Files extern "C" void GameInteractor_ExecuteOnSaveFile(int32_t fileNum); diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index e0f2ff71e..c5aecd397 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -7,6 +7,8 @@ extern "C" { extern SaveContext gSaveContext; extern PlayState* gPlayState; extern void Play_PerformSave(PlayState* play); +extern s32 Health_ChangeBy(PlayState* play, s16 healthChange); +extern void Rupees_ChangeBy(s16 rupeeChange); } void RegisterAutoSaveOnReceiveItemHook() { @@ -72,6 +74,31 @@ void RegisterAutoSaveOnReceiveItemHook() { }); } +void RegisterRupeeDash() { + GameInteractor::Instance->RegisterGameHook([]() { + if (!CVarGetInteger("gRupeeDash", 0)) { + return; + } + + // Initialize Timer + static uint16_t rupeeDashTimer = 0; + uint16_t rdmTime = CVarGetInteger("gDashInterval", 5) * 20; + + // Did time change by DashInterval? + if (rupeeDashTimer >= rdmTime) { + rupeeDashTimer = 0; + if (gSaveContext.rupees > 0) { + Rupees_ChangeBy(-1); + } else { + Health_ChangeBy(gPlayState, -16); + } + } else { + rupeeDashTimer++; + } + }); +} + void InitMods() { + RegisterRupeeDash(); RegisterAutoSaveOnReceiveItemHook(); } diff --git a/soh/soh/GameMenuBar.cpp b/soh/soh/GameMenuBar.cpp index 89991d4e6..0b1052c5d 100644 --- a/soh/soh/GameMenuBar.cpp +++ b/soh/soh/GameMenuBar.cpp @@ -617,6 +617,14 @@ namespace GameMenuBar { ImGui::EndMenu(); } + UIWidgets::Spacer(0); + + UIWidgets::PaddedEnhancementCheckbox("Rupee Dash Mode", "gRupeeDash", true, false); + UIWidgets::Tooltip("Rupees reduced over time, Link suffers damage when the count hits 0."); + UIWidgets::PaddedEnhancementSliderInt("Rupee Dash Interval: %d", "##DashInterval", "gDashInterval", 3, 5, "", 5, false, true, false, + !CVarGetInteger("gRupeeDash", 0), "This option is disabled because \"Rupee Dash Mode\" is turned off"); + UIWidgets::Tooltip("Interval between Rupee reduction in Rupee Dash Mode"); + ImGui::EndMenu(); } diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 2c6b8b668..cd9d50e00 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -11038,6 +11038,8 @@ void Player_Update(Actor* thisx, PlayState* play) { default: break; } + + GameInteractor_ExecuteOnPlayerUpdate(); } static struct_80858AC8 D_80858AC8;