Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully implement restorations choice of zora swimming #63

Merged
merged 1 commit into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/include/rnd/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace rnd::link {
void FixSpeedIssues();
void HandleFastOcarina(game::GlobalContext*);

} // namespace rnd::link

#endif
18 changes: 17 additions & 1 deletion code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ SECTIONS{
*(.patch_SpawnFastElegyStatues)
}

.patch_ZoraInWaterFastSwim 0x1F0C78 : {
*(.patch_ZoraInWaterFastSwim)
}

.patch_CheckCurrentInventoryOverrideItem 0x1F3D6C : {
*(.patch_CheckCurrentInventoryOverrideItem)
}
Expand All @@ -75,7 +79,11 @@ SECTIONS{
*(.patch_OverrideItemIdIndex)
} */

.patch_UseZoraASwimSecond 0X1FFD74 : {
.patch_FifthZoraSwimCheck 0x1FFA84 : {
*(.patch_FifthZoraSwimCheck)
}

.patch_UseZoraASwimSecond 0x1FFD74 : {
*(.patch_UseZoraASwimSecond)
}

Expand All @@ -87,6 +95,14 @@ SECTIONS{
*(.patch_UseZoraASwimFirst)
}

.patch_SixthZoraSwimCheck 0x220F00 : {
*(.patch_SixthZoraSwimCheck)
}

.patch_FourthZoraSwimCheck 0x220F2C : {
*(.patch_FourthZoraSwimCheck)
}

.patch_FirstZoraSwimCheck 0x220F60 : {
*(.patch_FirstZoraSwimCheck)
}
Expand Down
48 changes: 46 additions & 2 deletions code/source/asm/zora_hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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}
Expand Down
20 changes: 20 additions & 0 deletions code/source/asm/zora_patches.s
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down
16 changes: 12 additions & 4 deletions code/source/rnd/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}

Expand All @@ -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<decltype(SwitchToZoraFastSwim)>(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.

Expand Down
Loading