From 2cb3a3664efac8b0d72f9a670f21f1d0d48d1e8c Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Fri, 1 Dec 2023 23:57:20 -0600 Subject: [PATCH] Implement gMoveWhileFirstPerson --- .../controls/GameControlEditor.cpp | 7 ++- .../actors/ovl_player_actor/z_player.c | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/controls/GameControlEditor.cpp b/soh/soh/Enhancements/controls/GameControlEditor.cpp index a452bf4b171..4643dc31dbc 100644 --- a/soh/soh/Enhancements/controls/GameControlEditor.cpp +++ b/soh/soh/Enhancements/controls/GameControlEditor.cpp @@ -225,6 +225,10 @@ namespace GameControlEditor { window->BeginGroupPanelPublic("Aiming/First-Person Camera", ImGui::GetContentRegionAvail()); UIWidgets::PaddedEnhancementCheckbox("Right Stick Aiming", "gRightStickAiming"); DrawHelpIcon("Allows for aiming with the right stick in:\n-First-Person/C-Up view\n-Weapon Aiming"); + if (CVarGetInteger("gRightStickAiming", 0)) { + UIWidgets::PaddedEnhancementCheckbox("Allow moving while in first person mode", "gMoveWhileFirstPerson"); + DrawHelpIcon("Changes the left stick to move the player while in first person mode"); + } UIWidgets::PaddedEnhancementCheckbox("Invert Aiming X Axis", "gInvertAimingXAxis"); DrawHelpIcon("Inverts the Camera X Axis in:\n-First-Person/C-Up view\n-Weapon Aiming"); UIWidgets::PaddedEnhancementCheckbox("Invert Aiming Y Axis", "gInvertAimingYAxis", true, true, false, "", UIWidgets::CheckboxGraphics::Cross, true); @@ -237,7 +241,8 @@ namespace GameControlEditor { DrawHelpIcon("Prevents the C-Up view from auto-centering, allowing for Gyro Aiming"); if (UIWidgets::PaddedEnhancementCheckbox("Enable Custom Aiming/First-Person sensitivity", "gEnableFirstPersonSensitivity", true, false)) { if (!CVarGetInteger("gEnableFirstPersonSensitivity", 0)) { - CVarClear("gFirstPersonCameraSensitivity"); + CVarClear("gFirstPersonCameraSensitivityX"); + CVarClear("gFirstPersonCameraSensitivityY"); } } if (CVarGetInteger("gEnableFirstPersonSensitivity", 0)) { diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 41cf88537c2..f192fe1ce64 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -11832,6 +11832,9 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0)) { // First person without weapon // Y Axis + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp2 += sControlInput->rel.stick_y * 240.0f * invertYAxisMulti * yAxisMulti; + } if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_y) > 15.0f) { temp2 += sControlInput->cur.right_stick_y * 240.0f * invertYAxisMulti * yAxisMulti; } @@ -11847,6 +11850,9 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { // X Axis temp2 = 0; + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp2 += sControlInput->rel.stick_x * -16.0f * invertXAxisMulti * xAxisMulti; + } if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_x) > 15.0f) { temp2 += sControlInput->cur.right_stick_x * -16.0f * invertXAxisMulti * xAxisMulti; } @@ -11858,6 +11864,11 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { } else { // First person with weapon // Y Axis temp1 = (this->stateFlags1 & PLAYER_STATE1_ON_HORSE) ? 3500 : 14000; + + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp3 += ((sControlInput->rel.stick_y >= 0) ? 1 : -1) * + (s32)((1.0f - Math_CosS(sControlInput->rel.stick_y * 200)) * 1500.0f) * invertYAxisMulti * yAxisMulti; + } if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_y) > 15.0f) { temp3 += ((sControlInput->cur.right_stick_y >= 0) ? 1 : -1) * (s32)((1.0f - Math_CosS(sControlInput->cur.right_stick_y * 200)) * 1500.0f) * invertYAxisMulti * yAxisMulti; @@ -11872,6 +11883,10 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { temp1 = 19114; temp2 = this->actor.focus.rot.y - this->actor.shape.rot.y; temp3 = 0; + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp3 = ((sControlInput->rel.stick_x >= 0) ? 1 : -1) * + (s32)((1.0f - Math_CosS(sControlInput->rel.stick_x * 200)) * -1500.0f) * invertXAxisMulti * xAxisMulti; + } if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_x) > 15.0f) { temp3 += ((sControlInput->cur.right_stick_x >= 0) ? 1 : -1) * (s32)((1.0f - Math_CosS(sControlInput->cur.right_stick_x * 200)) * -1500.0f) * invertXAxisMulti * xAxisMulti; @@ -11883,6 +11898,34 @@ s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { this->actor.focus.rot.y = CLAMP(temp2, -temp1, temp1) + this->actor.shape.rot.y; } + if (CVarGetInteger("gMoveWhileFirstPerson", 0)) { + f32 movementSpeed = LINK_IS_ADULT ? 9.0f : 8.25f; + if (CVarGetInteger("gMMBunnyHood", BUNNY_HOOD_VANILLA) != BUNNY_HOOD_VANILLA && this->currentMask == PLAYER_MASK_BUNNY) { + movementSpeed *= 1.5f; + } + + f32 relX = (sControlInput->rel.stick_x / 10 * -invertXAxisMulti); + f32 relY = (sControlInput->rel.stick_y / 10); + + // Normalize so that diagonal movement isn't faster + f32 relMag = sqrtf((relX * relX) + (relY * relY)); + if (relMag > 1.0f) { + relX /= relMag; + relY /= relMag; + } + + // Determine what left and right mean based on camera angle + f32 relX2 = relX * Math_CosS(this->actor.focus.rot.y) + relY * Math_SinS(this->actor.focus.rot.y); + f32 relY2 = relY * Math_CosS(this->actor.focus.rot.y) - relX * Math_SinS(this->actor.focus.rot.y); + + // Calculate distance for footstep sound + f32 distance = sqrtf((relX2 * relX2) + (relY2 * relY2)) * movementSpeed; + func_8084029C(this, distance / 4.5f); + + this->actor.world.pos.x += (relX2 * movementSpeed) + this->actor.colChkInfo.displacement.x; + this->actor.world.pos.z += (relY2 * movementSpeed) + this->actor.colChkInfo.displacement.z; + } + this->unk_6AE |= 2; return func_80836AB8(this, (play->shootingGalleryStatus != 0) || func_8002DD78(this) || func_808334B4(this)) - arg3; }