From 46b502b2f451d68b3f7de5e160825f130665fc07 Mon Sep 17 00:00:00 2001 From: "LT_Schmiddy (Alex Schmid)" Date: Fri, 22 Nov 2024 18:45:17 -0500 Subject: [PATCH] Added Recomp Events for first-person aiming. --- patches/input.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/patches/input.c b/patches/input.c index 2962204..26caa45 100644 --- a/patches/input.c +++ b/patches/input.c @@ -6,6 +6,9 @@ #include "z64voice.h" #include "audiothread_cmd.h" +RECOMP_DECLARE_EVENT(recomp_before_first_person_aiming_update(PlayState* play, Player* this, bool in_free_look, bool* disable_left_stick_aiming)); +RECOMP_DECLARE_EVENT(recomp_after_first_person_aiming_update(PlayState* play, Player* this, bool in_free_look)); + s32 func_80847190(PlayState* play, Player* this, s32 arg2); s16 func_80832754(Player* this, s32 arg1); s32 func_8082EF20(Player* this); @@ -36,8 +39,17 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { // analog_x, analog_y); if (!func_800B7128(this) && !func_8082EF20(this) && !arg2) { + // Checking if any mods have disabled aiming with the left stick. + int disable_left_stick_aiming = 0; + recomp_before_first_person_aiming_update(play, this, true, &disable_left_stick_aiming); + // @recomp Add in the analog camera Y input. Clamp to prevent moving the camera twice as fast if both sticks are held. - var_s0 = CLAMP(play->state.input[0].rel.stick_y + analog_y, -61, 61) * 0xF0; + if (disable_left_stick_aiming) { + var_s0 = CLAMP(analog_y, -61, 61) * 0xF0; + } + else { + var_s0 = CLAMP(play->state.input[0].rel.stick_y + analog_y, -61, 61) * 0xF0; + } // @recomp Invert the Y axis accordingly (default is inverted, so negate if not inverted). if (!inverted_y) { @@ -46,7 +58,12 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { Math_SmoothStepToS(&this->actor.focus.rot.x, var_s0, 0xE, 0xFA0, 0x1E); // @recomp Add in the analog camera X input. Clamp to prevent moving the camera twice as fast if both sticks are held. - var_s0 = CLAMP(play->state.input[0].rel.stick_x + analog_x, -61, 61) * -0x10; + if (disable_left_stick_aiming) { + var_s0 = CLAMP(analog_x, -61, 61) * -0x10; + } + else { + var_s0 = CLAMP(play->state.input[0].rel.stick_x + analog_x, -61, 61) * -0x10; + } // @recomp Invert the X axis accordingly if (inverted_x) { @@ -54,8 +71,14 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { } var_s0 = CLAMP(var_s0, -0xBB8, 0xBB8); this->actor.focus.rot.y += var_s0; + + recomp_after_first_person_aiming_update(play, this, true); } else { + // Checking if any mods have disabled aiming with the left stick. + int disable_left_stick_aiming = 0; + recomp_before_first_person_aiming_update(play, this, false, &disable_left_stick_aiming); + static float total_gyro_x, total_gyro_y; static float total_mouse_x, total_mouse_y; static float filtered_gyro_x, filtered_gyro_y; @@ -97,7 +120,14 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { // @recomp Invert the Y axis accordingly (default is inverted, so negate if not inverted). // Also add in the analog camera Y input. Clamp to prevent moving the camera twice as fast if both sticks are held. - s32 stick_y = CLAMP(play->state.input[0].rel.stick_y + analog_y, -61, 61); + s32 stick_y; + if (disable_left_stick_aiming) { + stick_y = CLAMP(analog_y, -61, 61); + } + else { + stick_y = CLAMP(play->state.input[0].rel.stick_y + analog_y, -61, 61); + } + if (!inverted_y) { stick_y = -stick_y; } @@ -118,7 +148,14 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { // @recomp Invert the X axis accordingly. Also add in the analog camera Y input. // Clamp to prevent moving the camera twice as fast if both sticks are held. - s32 stick_x = CLAMP(play->state.input[0].rel.stick_x + analog_x, -61, 61); + s32 stick_x; + if (disable_left_stick_aiming) { + stick_x = CLAMP(analog_x, -61, 61); + } + else { + stick_x = CLAMP(play->state.input[0].rel.stick_x + analog_x, -61, 61); + } + if (inverted_x) { stick_x = -stick_x; } @@ -128,6 +165,8 @@ RECOMP_PATCH s32 func_80847190(PlayState* play, Player* this, s32 arg2) { applied_aim_y = target_aim_y; this->actor.focus.rot.y = CLAMP(var_s0, -0x4AAA, 0x4AAA) + this->actor.shape.rot.y; + + recomp_after_first_person_aiming_update(play, this, false); } this->unk_AA6 |= 2;