From 1b90889a28ef228a2fdcdc46b432b5d7dc7f35f1 Mon Sep 17 00:00:00 2001 From: Reonu Date: Sun, 18 Jan 2026 01:55:52 +0000 Subject: [PATCH] Analog camera sensitivity (#94) * WIP analog camera sensitivity * Fix implementation errors. --------- Co-authored-by: Dario --- include/banjo_config.h | 3 +++ patches/camera_and_axis_inversion_patches.c | 4 ++-- patches/input.h | 1 + patches/syms.ld | 1 + src/game/config.cpp | 20 ++++++++++++++++++++ src/game/recomp_api.cpp | 5 +++++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/banjo_config.h b/include/banjo_config.h index 911235c..4f77afc 100644 --- a/include/banjo_config.h +++ b/include/banjo_config.h @@ -19,6 +19,7 @@ namespace banjo { inline const std::string third_person_camera_invert_mode = "third_person_camera_invert_mode"; inline const std::string flying_and_swimming_invert_mode = "flying_and_swimming_invert_mode"; inline const std::string first_person_invert_mode = "first_person_invert_mode"; + inline const std::string analog_camera_sensitivity = "analog_camera_sensitivity"; } namespace sound { @@ -61,6 +62,8 @@ namespace banjo { AnalogCamMode get_analog_cam_mode(); + uint32_t get_analog_cam_sensitivity(); + enum class NoteSavingMode { On, Off, diff --git a/patches/camera_and_axis_inversion_patches.c b/patches/camera_and_axis_inversion_patches.c index e0bd3c0..ed63907 100644 --- a/patches/camera_and_axis_inversion_patches.c +++ b/patches/camera_and_axis_inversion_patches.c @@ -240,7 +240,7 @@ bool recomp_analog_camera_held(bool read_x, bool read_y) { // @recomp If movement is allowed, update the current camera mode's yaw with the input. void recomp_analog_camera_update() { if (recomp_analog_camera_enabled() && recomp_analog_camera_allowed(FALSE)) { - f32 analog_yaw = recomp_analog_camera_get_x() * 120.0f * time_getDelta(); + f32 analog_yaw = recomp_analog_camera_get_x() * recomp_get_analog_cam_sensitivity() * 40.0f * time_getDelta(); if (mlAbsF(analog_yaw) > 1e-6f) { if (ncDynamicCamera_getState() != DYNAMIC_CAMERA_STATE_R_LOOK) { ncDynamicCamera_setState(DYNAMIC_CAMERA_STATE_R_LOOK); @@ -503,7 +503,7 @@ RECOMP_PATCH void func_80290F14(void) { // If they are, use the vertical movement to update the zoom level. if (recomp_analog_camera_enabled()) { if (!func_80298850() && player_movementGroup() != BSGROUP_4_LOOK && batimer_get(7) == 0.0f && recomp_analog_camera_allowed(FALSE)) { - analog_zoom = ml_clamp_f(analog_zoom + recomp_analog_camera_get_y() * 4.5f * time_getDelta(), 0.5f, 3.0f); + analog_zoom = ml_clamp_f(analog_zoom + recomp_analog_camera_get_y() * recomp_get_analog_cam_sensitivity() * 1.5f * time_getDelta(), 0.5f, 3.0f); } } diff --git a/patches/input.h b/patches/input.h index 59720d3..ac1bd1c 100644 --- a/patches/input.h +++ b/patches/input.h @@ -20,6 +20,7 @@ extern RecompAimingOverideMode recomp_aiming_override_mode; DECLARE_FUNC(void, recomp_get_gyro_deltas, float* x, float* y); DECLARE_FUNC(void, recomp_get_mouse_deltas, float* x, float* y); DECLARE_FUNC(void, recomp_get_inverted_axes, s32* x, s32* y); +DECLARE_FUNC(u32, recomp_get_analog_cam_sensitivity); DECLARE_FUNC(s32, recomp_get_analog_cam_enabled); DECLARE_FUNC(void, recomp_get_analog_inverted_axes, s32* x, s32* y); DECLARE_FUNC(void, recomp_get_flying_and_swimming_inverted_axes, s32* x, s32* y); diff --git a/patches/syms.ld b/patches/syms.ld index d52e735..6ba9568 100644 --- a/patches/syms.ld +++ b/patches/syms.ld @@ -50,3 +50,4 @@ recomp_get_note_saving_enabled = 0x8F0000B4; recomp_get_cutscene_aspect_ratio = 0x8F0000B8; recomp_get_flying_and_swimming_inverted_axes = 0x8F0000BC; recomp_get_first_person_inverted_axes = 0x8F0000C0; +recomp_get_analog_cam_sensitivity = 0x8F0000C4; \ No newline at end of file diff --git a/src/game/config.cpp b/src/game/config.cpp index 093e371..cba21fe 100644 --- a/src/game/config.cpp +++ b/src/game/config.cpp @@ -46,6 +46,17 @@ static void add_general_options(recomp::config::Config &config) { analog_cam_mode_options, banjo::AnalogCamMode::Off ); + config.add_number_option( + banjo::configkeys::general::analog_camera_sensitivity, + "Analog Camera Sensitivity", + "Sets the sensitivity of the right stick analog camera, if enabled.", + 1, 10, 1, 0, false, 3 + ); + config.add_option_hidden_dependency( + banjo::configkeys::general::analog_camera_sensitivity, + banjo::configkeys::general::analog_cam_mode, + banjo::AnalogCamMode::Off + ); static EnumOptionVector camera_invert_mode_options = { {banjo::CameraInvertMode::InvertNone, "InvertNone", "None"}, {banjo::CameraInvertMode::InvertX, "InvertX", "Invert X"}, @@ -92,6 +103,11 @@ T get_general_config_enum_value(const std::string& option_id) { return static_cast(std::get(recompui::config::get_general_config().get_option_value(option_id))); } +template +T get_general_config_number_value(const std::string& option_id) { + return static_cast(std::get(recompui::config::get_general_config().get_option_value(option_id))); +} + banjo::NoteSavingMode banjo::get_note_saving_mode() { return get_general_config_enum_value(banjo::configkeys::general::note_saving_mode); } @@ -116,6 +132,10 @@ banjo::AnalogCamMode banjo::get_analog_cam_mode() { return get_general_config_enum_value(banjo::configkeys::general::analog_cam_mode); } +uint32_t banjo::get_analog_cam_sensitivity() { + return get_general_config_number_value(banjo::configkeys::general::analog_camera_sensitivity); +} + template T get_graphics_config_enum_value(const std::string& option_id) { return static_cast(std::get(recompui::config::get_graphics_config().get_option_value(option_id))); diff --git a/src/game/recomp_api.cpp b/src/game/recomp_api.cpp index 89f57da..26b90db 100644 --- a/src/game/recomp_api.cpp +++ b/src/game/recomp_api.cpp @@ -125,6 +125,11 @@ extern "C" void recomp_get_bgm_volume(uint8_t* rdram, recomp_context* ctx) { _return(ctx, banjo::get_bgm_volume() / 100.0f); } +extern "C" void recomp_get_analog_cam_sensitivity(uint8_t* rdram, recomp_context* ctx) { + _return(ctx, banjo::get_analog_cam_sensitivity()); +} + + extern "C" void recomp_time_us(uint8_t* rdram, recomp_context* ctx) { _return(ctx, static_cast(std::chrono::duration_cast(ultramodern::time_since_start()).count())); }