From d74699740e889ee2e492ec15327ccc45f781e1ab Mon Sep 17 00:00:00 2001 From: Patrick12115 <115201185+Patrick12115@users.noreply.github.com> Date: Sun, 18 Aug 2024 23:24:14 -0400 Subject: [PATCH] [Enhancement] Instant Recall (#589) * Instant Recall * clang it * Moved to Category "Equipment" * pr review feedback --------- Co-authored-by: Archez --- mm/2s2h/BenGui/BenMenuBar.cpp | 7 ++++ mm/2s2h/Enhancements/Enhancements.cpp | 1 + mm/2s2h/Enhancements/Enhancements.h | 1 + .../Enhancements/Equipment/InstantRecall.cpp | 42 +++++++++++++++++++ .../Enhancements/Equipment/InstantRecall.h | 6 +++ 5 files changed, 57 insertions(+) create mode 100644 mm/2s2h/Enhancements/Equipment/InstantRecall.cpp create mode 100644 mm/2s2h/Enhancements/Equipment/InstantRecall.h diff --git a/mm/2s2h/BenGui/BenMenuBar.cpp b/mm/2s2h/BenGui/BenMenuBar.cpp index 9d5d00378..c52df59a1 100644 --- a/mm/2s2h/BenGui/BenMenuBar.cpp +++ b/mm/2s2h/BenGui/BenMenuBar.cpp @@ -515,6 +515,12 @@ void DrawEnhancementsMenu() { if (UIWidgets::BeginMenu("Equipment")) { UIWidgets::CVarCheckbox("Fast Magic Arrow Equip Animation", "gEnhancements.Equipment.MagicArrowEquipSpeed", { .tooltip = "Removes the animation for equipping Magic Arrows." }); + + UIWidgets::CVarCheckbox( + "Instant Fin Boomerangs Recall", "gEnhancements.PlayerActions.InstantRecall", + { .tooltip = + "Pressing B will instantly recall the fin boomerang back to Zora Link after they are thrown." }); + ImGui::EndMenu(); } @@ -618,6 +624,7 @@ void DrawEnhancementsMenu() { } ImGui::EndMenu(); } + if (UIWidgets::BeginMenu("Player")) { UIWidgets::CVarSliderInt("Climb speed", "gEnhancements.Player.ClimbSpeed", 1, 5, 1, { .tooltip = "Increases the speed at which Link climbs vines and ladders." }); diff --git a/mm/2s2h/Enhancements/Enhancements.cpp b/mm/2s2h/Enhancements/Enhancements.cpp index 99c9a00c5..d0c3cd939 100644 --- a/mm/2s2h/Enhancements/Enhancements.cpp +++ b/mm/2s2h/Enhancements/Enhancements.cpp @@ -28,6 +28,7 @@ void InitEnhancements() { // Equipment RegisterSkipMagicArrowEquip(); + RegisterInstantRecall(); // Graphics RegisterDisableBlackBars(); diff --git a/mm/2s2h/Enhancements/Enhancements.h b/mm/2s2h/Enhancements/Enhancements.h index 7da2ad77a..c69692e49 100644 --- a/mm/2s2h/Enhancements/Enhancements.h +++ b/mm/2s2h/Enhancements/Enhancements.h @@ -28,6 +28,7 @@ #include "Restorations/TatlISG.h" #include "Graphics/3DItemDrops.h" #include "Graphics/PlayAsKafei.h" +#include "Equipment/InstantRecall.h" #include "Player/Player.h" #include "Songs/EnableSunsSong.h" #include "Songs/PauseOwlWarp.h" diff --git a/mm/2s2h/Enhancements/Equipment/InstantRecall.cpp b/mm/2s2h/Enhancements/Equipment/InstantRecall.cpp new file mode 100644 index 000000000..dad419353 --- /dev/null +++ b/mm/2s2h/Enhancements/Equipment/InstantRecall.cpp @@ -0,0 +1,42 @@ +#include +#include "Enhancements/GameInteractor/GameInteractor.h" +#include "InstantRecall.h" +#include "src/overlays/actors/ovl_En_Boom/z_en_boom.h" + +extern "C" { +extern PlayState* gPlayState; +} + +static HOOK_ID onActorUpdateHookId = 0; + +void Player_ReturnBoomerangs() { + Player* player = GET_PLAYER(gPlayState); + + if (player == NULL) { + return; + } + + EnBoom* boomerangs = (EnBoom*)player->boomerangActor; + + // Kill both boomerangs + if (boomerangs != NULL) { + Actor_Kill(&boomerangs->actor); + if (boomerangs->actor.child != NULL) { + Actor_Kill(boomerangs->actor.child); + } + } +} + +void RegisterInstantRecall() { + GameInteractor::Instance->UnregisterGameHookForID(onActorUpdateHookId); + onActorUpdateHookId = 0; + + onActorUpdateHookId = GameInteractor::Instance->RegisterGameHookForID( + ACTOR_EN_BOOM, [](Actor* outerActor) { + if (CVarGetInteger("gEnhancements.PlayerActions.InstantRecall", 0)) { + if (CHECK_BTN_ALL(gPlayState->state.input->press.button, BTN_B)) { + Player_ReturnBoomerangs(); + } + } + }); +} diff --git a/mm/2s2h/Enhancements/Equipment/InstantRecall.h b/mm/2s2h/Enhancements/Equipment/InstantRecall.h new file mode 100644 index 000000000..4dd58d4fc --- /dev/null +++ b/mm/2s2h/Enhancements/Equipment/InstantRecall.h @@ -0,0 +1,6 @@ +#ifndef EQUIPMENT_INSTAND_RECALL_H +#define EQUIPMENT_INSTAND_RECALL_H + +void RegisterInstantRecall(); + +#endif // EQUIPMENT_INSTAND_RECALL_H