From 0ef3bfde49817390091cc2b4ae5f918390c6815f Mon Sep 17 00:00:00 2001 From: Phlex Date: Sun, 27 Aug 2023 12:27:36 -0600 Subject: [PATCH] Fully implement restorations choice of zora swimming. --- code/include/rnd/link.h | 1 + code/mm.ld | 18 ++++++++++++- code/source/asm/zora_hooks.s | 48 ++++++++++++++++++++++++++++++++-- code/source/asm/zora_patches.s | 20 ++++++++++++++ code/source/rnd/link.cpp | 16 +++++++++--- 5 files changed, 96 insertions(+), 7 deletions(-) diff --git a/code/include/rnd/link.h b/code/include/rnd/link.h index 32dbdccb..8d81002e 100644 --- a/code/include/rnd/link.h +++ b/code/include/rnd/link.h @@ -10,6 +10,7 @@ namespace rnd::link { void FixSpeedIssues(); void HandleFastOcarina(game::GlobalContext*); + } // namespace rnd::link #endif \ No newline at end of file diff --git a/code/mm.ld b/code/mm.ld index 4d6079a6..6b448076 100644 --- a/code/mm.ld +++ b/code/mm.ld @@ -63,6 +63,10 @@ SECTIONS{ *(.patch_SpawnFastElegyStatues) } + .patch_ZoraInWaterFastSwim 0x1F0C78 : { + *(.patch_ZoraInWaterFastSwim) + } + .patch_CheckCurrentInventoryOverrideItem 0x1F3D6C : { *(.patch_CheckCurrentInventoryOverrideItem) } @@ -75,7 +79,11 @@ SECTIONS{ *(.patch_OverrideItemIdIndex) } */ - .patch_UseZoraASwimSecond 0X1FFD74 : { + .patch_FifthZoraSwimCheck 0x1FFA84 : { + *(.patch_FifthZoraSwimCheck) + } + + .patch_UseZoraASwimSecond 0x1FFD74 : { *(.patch_UseZoraASwimSecond) } @@ -87,6 +95,14 @@ SECTIONS{ *(.patch_UseZoraASwimFirst) } + .patch_SixthZoraSwimCheck 0x220F00 : { + *(.patch_SixthZoraSwimCheck) + } + + .patch_FourthZoraSwimCheck 0x220F2C : { + *(.patch_FourthZoraSwimCheck) + } + .patch_FirstZoraSwimCheck 0x220F60 : { *(.patch_FirstZoraSwimCheck) } diff --git a/code/source/asm/zora_hooks.s b/code/source/asm/zora_hooks.s index e7e16ee7..22e5dee1 100644 --- a/code/source/asm/zora_hooks.s +++ b/code/source/asm/zora_hooks.s @@ -3,14 +3,44 @@ .arm .text +.global hook_ZoraInWaterFastSwim +hook_ZoraInWaterFastSwim: + push {r0-r12, lr} + bl SettingsEnabledFastSwim + cmp r0, #0x0 + pop {r0-r12, lr} + beq useDefaultBehaviour + bl SwitchToZoraFastSwim + b 0x1F0C7C +useDefaultBehaviour: + bl 0x220EA0 + b 0x1F0C7C + +.global hook_FifthZoraSwimCheck +hook_FifthZoraSwimCheck: + push {r0-r12, lr} + bl SettingsEnabledFastSwim + cmp r0, #0x0 + pop {r0-r12, lr} + beq fastSwimDisabledTwo + blne ShouldUseZoraFastSwim + cmp r0,#1 + b 0x1FFA94 +fastSwimDisabledTwo: + ldr r1,[r10,#0x9cc] + b 0x1FFA88 + .global hook_UseZoraASwimSecond hook_UseZoraASwimSecond: push {r0-r12, lr} bl SettingsEnabledFastSwim cmp r0, #0x0 - blne ShouldUseZoraFastSwim pop {r0-r12, lr} - cmpeq r0,#0x0 + beq fastSwimDisabled + blne ShouldUseZoraFastSwim + cmp r0,#1 + b 0x1FFD84 +fastSwimDisabled: ldr r1,[r10,#0x9cc] b 0x1FFD78 @@ -35,6 +65,20 @@ hook_UseZoraASwimFirst: ldr r0,[r0,r4] b 0x220F00 +.global hook_FourthZoraSwimCheck +hook_FourthZoraSwimCheck: + push {r0-r12, lr} + bl SettingsEnabledFastSwim + cmp r0, #0x0 + pop {r0-r12, lr} + beq useNormalZoraFourth + cmp r0, #1 + @ Basically calling a nop for 0x220F30 + b 0x220F34 +useNormalZoraFourth: + ldr r0, [r0, #8] + bx lr + .global hook_FirstZoraSwimCheck hook_FirstZoraSwimCheck: push {r0-r12, lr} diff --git a/code/source/asm/zora_patches.s b/code/source/asm/zora_patches.s index dbb48b7d..d24ad11d 100644 --- a/code/source/asm/zora_patches.s +++ b/code/source/asm/zora_patches.s @@ -1,5 +1,15 @@ .arm +.section .patch_ZoraInWaterFastSwim +.global patch_ZoraInWaterFastSwim +patch_ZoraInWaterFastSwim: + bl hook_ZoraInWaterFastSwim + +.section .patch_FifthZoraSwimCheck +.global patch_FifthZoraSwimCheck +patch_FifthZoraSwimCheck: + bl hook_FifthZoraSwimCheck + .section .patch_UseZoraASwimSecond .global patch_UseZoraASwimSecond patch_UseZoraASwimSecond: @@ -15,6 +25,16 @@ patch_ThirdZoraSwimCheck: patch_UseZoraASwimFirst: bl hook_UseZoraASwimFirst +.section .patch_SixthZoraSwimCheck +.global patch_SixthZoraSwimCheck +patch_SixthZoraSwimCheck: + b 0x220F0C + +.section .patch_FourthZoraSwimCheck +.global patch_FourthZoraSwimCheck +patch_FourthZoraSwimCheck: + bl hook_FourthZoraSwimCheck + .section .patch_FirstZoraSwimCheck .global patch_FirstZoraSwimCheck patch_FirstZoraSwimCheck: diff --git a/code/source/rnd/link.cpp b/code/source/rnd/link.cpp index 377eacbb..c6bfdf5b 100644 --- a/code/source/rnd/link.cpp +++ b/code/source/rnd/link.cpp @@ -10,8 +10,8 @@ */ namespace rnd::link { - - extern "C" bool ShouldUseZoraFastSwim() { + extern "C" { + bool ShouldUseZoraFastSwim() { const auto& input = GetContext().gctx->pad_state.input; if (!input.buttons.IsSet(game::pad::Button::A)) @@ -20,8 +20,8 @@ namespace rnd::link { rnd::util::Print("%s: Our current fast swim is %u and we are in fast swim.\n", __func__, GetContext().use_fast_swim); #endif - // Toggle fast swim with D-Pad Up/Down or ZL - if (input.new_buttons.IsOneSet(game::pad::Button::Up, game::pad::Button::Down, game::pad::Button::ZL)) { + // Toggle fast swim with D-Pad Up or ZL + if (input.new_buttons.IsOneSet(game::pad::Button::Up, game::pad::Button::ZL)) { GetContext().use_fast_swim ^= true; } @@ -34,6 +34,14 @@ namespace rnd::link { return GetContext().use_fast_swim; } + bool SwitchToZoraFastSwim(game::GlobalContext* gctx, game::act::Player* player, bool check_magic) { + const auto do_switch = util::GetPointer(0x220EA0); + return (player->zora_swim_a_press_duration >= 7 || + player->flags1.IsSet(game::act::Player::Flag1::IsUsingZoraBarrier)) && + do_switch(gctx, player, check_magic); + } + } + void FixSpeedIssues() { // This reverts some of the MM3D changes to form-specific parameters.