From 185e761f78a05ba7ac1e9988d3c09362b9ef4a11 Mon Sep 17 00:00:00 2001 From: Eblo <7004497+Eblo@users.noreply.github.com> Date: Tue, 3 Sep 2024 23:00:11 -0400 Subject: [PATCH] [Enhancement] Fierce Deity Anchored Backwalk Animation (#670) * Add Fierce Deity anchored backwalk enhancement * adjust ztarget hook to clamp speed instead of modifying animation frame logic --------- Co-authored-by: Archez --- mm/2s2h/BenGui/BenMenuBar.cpp | 4 ++++ mm/2s2h/Enhancements/Enhancements.cpp | 3 +++ mm/2s2h/Enhancements/Enhancements.h | 1 + .../Fixes/FierceDeityZTargetMovement.cpp | 21 +++++++++++++++++++ mm/2s2h/Enhancements/Fixes/Fixes.h | 6 ++++++ .../GameInteractor/GameInteractor.h | 1 + .../actors/ovl_player_actor/z_player.c | 3 +++ 7 files changed, 39 insertions(+) create mode 100644 mm/2s2h/Enhancements/Fixes/FierceDeityZTargetMovement.cpp create mode 100644 mm/2s2h/Enhancements/Fixes/Fixes.h diff --git a/mm/2s2h/BenGui/BenMenuBar.cpp b/mm/2s2h/BenGui/BenMenuBar.cpp index c01729ab0..75251fccf 100644 --- a/mm/2s2h/BenGui/BenMenuBar.cpp +++ b/mm/2s2h/BenGui/BenMenuBar.cpp @@ -529,6 +529,10 @@ void DrawEnhancementsMenu() { { .tooltip = "Fixes a missing gDPSetEnvColor, which causes the ammo count to be " "the wrong color prior to obtaining magic or other conditions." }); + UIWidgets::CVarCheckbox("Fix Fierce Deity Z-Target movement", + "gEnhancements.Fixes.FierceDeityZTargetMovement", + { .tooltip = "Fixes Fierce Deity movement being choppy when Z-targeting" }); + UIWidgets::CVarCheckbox("Fix Hess and Weirdshot Crash", "gEnhancements.Fixes.HessCrash", { .tooltip = "Fixes a crash that can occur when performing a HESS or Weirdshot.", .defaultValue = true }); diff --git a/mm/2s2h/Enhancements/Enhancements.cpp b/mm/2s2h/Enhancements/Enhancements.cpp index 2acb6db07..6d14e8388 100644 --- a/mm/2s2h/Enhancements/Enhancements.cpp +++ b/mm/2s2h/Enhancements/Enhancements.cpp @@ -30,6 +30,9 @@ void InitEnhancements() { RegisterSkipMagicArrowEquip(); RegisterInstantRecall(); + // Fixes + RegisterFierceDeityZTargetMovement(); + // Graphics RegisterDisableBlackBars(); Register3DItemDrops(); diff --git a/mm/2s2h/Enhancements/Enhancements.h b/mm/2s2h/Enhancements/Enhancements.h index 20ef77abc..84ad3b1f5 100644 --- a/mm/2s2h/Enhancements/Enhancements.h +++ b/mm/2s2h/Enhancements/Enhancements.h @@ -15,6 +15,7 @@ #include "Cheats/TimeStop.h" #include "Cycle/EndOfCycle.h" #include "Equipment/SkipMagicArrowEquip.h" +#include "Fixes/Fixes.h" #include "Masks/BlastMaskKeg.h" #include "Masks/FierceDeityAnywhere.h" #include "Masks/NoBlastMaskCooldown.h" diff --git a/mm/2s2h/Enhancements/Fixes/FierceDeityZTargetMovement.cpp b/mm/2s2h/Enhancements/Fixes/FierceDeityZTargetMovement.cpp new file mode 100644 index 000000000..50c291912 --- /dev/null +++ b/mm/2s2h/Enhancements/Fixes/FierceDeityZTargetMovement.cpp @@ -0,0 +1,21 @@ +#include +#include "Enhancements/GameInteractor/GameInteractor.h" + +extern "C" { +#include "variables.h" +} + +void RegisterFierceDeityZTargetMovement() { + REGISTER_VB_SHOULD(GI_VB_ZTARGET_SPEED_CHECK, { + Player* player = GET_PLAYER(gPlayState); + float* speedArg = (float*)opt; + + // If the player is Fierce Deity and targeting, + if (player->lockOnActor != NULL && player->transformation == PLAYER_FORM_FIERCE_DEITY && + CVarGetInteger("gEnhancements.Fixes.FierceDeityZTargetMovement", 0)) { + // 6.0f is the maximum speed of Zora/Goron/Deku link, whereas FD can be up to 10 + // Clamping to 6.0 keeps z target movement similar to other transformations + *speedArg = CLAMP_MAX(*speedArg, 6.0f); + } + }); +} diff --git a/mm/2s2h/Enhancements/Fixes/Fixes.h b/mm/2s2h/Enhancements/Fixes/Fixes.h new file mode 100644 index 000000000..5e61df6f1 --- /dev/null +++ b/mm/2s2h/Enhancements/Fixes/Fixes.h @@ -0,0 +1,6 @@ +#ifndef ENHANCEMENTS_FIXES_H +#define ENHANCEMENTS_FIXES_H + +void RegisterFierceDeityZTargetMovement(); + +#endif // ENHANCEMENTS_FIXES_H diff --git a/mm/2s2h/Enhancements/GameInteractor/GameInteractor.h b/mm/2s2h/Enhancements/GameInteractor/GameInteractor.h index 2ef0b487f..a076e8f2a 100644 --- a/mm/2s2h/Enhancements/GameInteractor/GameInteractor.h +++ b/mm/2s2h/Enhancements/GameInteractor/GameInteractor.h @@ -59,6 +59,7 @@ typedef enum { GI_VB_DISABLE_LETTERBOX, GI_VB_CLOCK_TOWER_OPENING_CONSIDER_THIS_FIRST_CYCLE, GI_VB_DRAW_SLIME_BODY_ITEM, + GI_VB_ZTARGET_SPEED_CHECK, } GIVanillaBehavior; typedef enum { diff --git a/mm/src/overlays/actors/ovl_player_actor/z_player.c b/mm/src/overlays/actors/ovl_player_actor/z_player.c index 16e9c9ca7..36df61bc9 100644 --- a/mm/src/overlays/actors/ovl_player_actor/z_player.c +++ b/mm/src/overlays/actors/ovl_player_actor/z_player.c @@ -9595,6 +9595,9 @@ s32 func_8083E404(Player* this, f32 arg1, s16 arg2) { func_8083C62C(this, func_800B7128(this) || func_8082EF20(this)); } + // Using Should hook, but ignoring return value, to be able to modify the speed argument + GameInteractor_Should(GI_VB_ZTARGET_SPEED_CHECK, false, &arg1); + temp_fv1 = fabsf(sp1C) / 0x8000; if (((SQ(temp_fv1) * 50.0f) + 6.0f) < arg1) { return 1;