Swim Speed Modifiers (#3308)

* Add CVars for swimming, apply to swim speed calc

* Prevent modifer from working underwater

* Re-enable swim speed mod when underwater, use new (orig) function for y-velocity while diving

* Add to presets list

* Fix spacing

* block out vanilla + comments

* re-org vanilla code block in a sane way

* new documentation format

* rename Surface function + comment for usage

* handle merge conflicts, but like an adult this time
This commit is contained in:
Eric Hoey 2024-02-01 20:32:50 -05:00 committed by GitHub
parent a19056cd3d
commit d9310e4543
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 84 additions and 6 deletions

View File

@ -315,15 +315,21 @@ namespace GameControlEditor {
"certain items."); "certain items.");
UIWidgets::Spacer(0); UIWidgets::Spacer(0);
ImGui::BeginDisabled(CVarGetInteger("gDisableChangingSettings", 0)); ImGui::BeginDisabled(CVarGetInteger("gDisableChangingSettings", 0));
UIWidgets::PaddedEnhancementCheckbox("Enable walk speed modifiers", "gEnableWalkModify", true, false); UIWidgets::PaddedEnhancementCheckbox("Enable speed modifiers", "gEnableWalkModify", true, false);
DrawHelpIcon("Hold the assigned button to change the maximum walking speed\nTo change the assigned button, go into the Ports tabs above"); DrawHelpIcon("Hold the assigned button to change the maximum walking or swimming speed\nTo change the assigned button, go into the Ports tabs above");
if (CVarGetInteger("gEnableWalkModify", 0)) { if (CVarGetInteger("gEnableWalkModify", 0)) {
UIWidgets::Spacer(5); UIWidgets::Spacer(5);
window->BeginGroupPanelPublic("Walk Modifier", ImGui::GetContentRegionAvail()); window->BeginGroupPanelPublic("Speed Modifier", ImGui::GetContentRegionAvail());
UIWidgets::PaddedEnhancementCheckbox("Toggle modifier instead of holding", "gWalkSpeedToggle", true, false); UIWidgets::PaddedEnhancementCheckbox("Toggle modifier instead of holding", "gWalkSpeedToggle", true, false);
window->BeginGroupPanelPublic("Walk Modifier", ImGui::GetContentRegionAvail());
UIWidgets::PaddedEnhancementCheckbox("Don't affect jump distance/velocity", "gWalkModifierDoesntChangeJump", true, false); UIWidgets::PaddedEnhancementCheckbox("Don't affect jump distance/velocity", "gWalkModifierDoesntChangeJump", true, false);
UIWidgets::PaddedEnhancementSliderFloat("Modifier 1: %.0f %%", "##WalkMod1", "gWalkModifierOne", 0.0f, 5.0f, "", 1.0f, true, true, false, true); UIWidgets::PaddedEnhancementSliderFloat("Walk Modifier 1: %.0f %%", "##WalkMod1", "gWalkModifierOne", 0.0f, 5.0f, "", 1.0f, true, true, false, true);
UIWidgets::PaddedEnhancementSliderFloat("Modifier 2: %.0f %%", "##WalkMod2", "gWalkModifierTwo", 0.0f, 5.0f, "", 1.0f, true, true, false, true); UIWidgets::PaddedEnhancementSliderFloat("Walk Modifier 2: %.0f %%", "##WalkMod2", "gWalkModifierTwo", 0.0f, 5.0f, "", 1.0f, true, true, false, true);
window->EndGroupPanelPublic(0);
window->BeginGroupPanelPublic("Swim Modifier", ImGui::GetContentRegionAvail());
UIWidgets::PaddedEnhancementSliderFloat("Swim Modifier 1: %.0f %%", "##SwimMod1", "gSwimModifierOne", 0.0f, 5.0f, "", 1.0f, true, true, false, true);
UIWidgets::PaddedEnhancementSliderFloat("Swim Modifier 2: %.0f %%", "##SwimMod2", "gSwimModifierTwo", 0.0f, 5.0f, "", 1.0f, true, true, false, true);
window->EndGroupPanelPublic(0);
window->EndGroupPanelPublic(0); window->EndGroupPanelPublic(0);
} }
ImGui::EndDisabled(); ImGui::EndDisabled();

View File

@ -256,6 +256,8 @@ const std::vector<const char*> cheatCvars = {
"gWalkSpeedToggle", "gWalkSpeedToggle",
"gWalkModifierOne", "gWalkModifierOne",
"gWalkModifierTwo", "gWalkModifierTwo",
"gSwimModifierOne",
"gSwimModifierTwo",
"gGoronPot", "gGoronPot",
"gDampeWin", "gDampeWin",
"gCustomizeShootingGallery", "gCustomizeShootingGallery",

View File

@ -11927,6 +11927,68 @@ void func_8084AEEC(Player* this, f32* arg1, f32 arg2, s16 arg3) {
f32 temp1; f32 temp1;
f32 temp2; f32 temp2;
// #region SOH [Enhancement]
f32 swimMod = 1.0f;
if (CVarGetInteger("gEnableWalkModify", 0) == 1) {
if (CVarGetInteger("gWalkSpeedToggle", 0) == 1) {
if (gWalkSpeedToggle1) {
swimMod *= CVarGetFloat("gSwimModifierOne", 1.0f);
} else if (gWalkSpeedToggle2) {
swimMod *= CVarGetFloat("gSwimModifierTwo", 1.0f);
}
} else {
if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) {
swimMod *= CVarGetFloat("gSwimModifierOne", 1.0f);
} else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) {
swimMod *= CVarGetFloat("gSwimModifierTwo", 1.0f);
}
}
temp1 = this->skelAnime.curFrame - 10.0f;
temp2 = (R_RUN_SPEED_LIMIT / 100.0f) * 0.8f * swimMod;
if (*arg1 > temp2) {
*arg1 = temp2;
}
if ((0.0f < temp1) && (temp1 < 10.0f)) {
temp1 *= 6.0f;
} else {
temp1 = 0.0f;
arg2 = 0.0f;
}
Math_AsymStepToF(arg1, arg2 * 0.8f * swimMod, temp1, (fabsf(*arg1) * 0.02f) + 0.05f);
Math_ScaledStepToS(&this->currentYaw, arg3, 1600);
// #endregion
} else {
temp1 = this->skelAnime.curFrame - 10.0f;
temp2 = (R_RUN_SPEED_LIMIT / 100.0f) * 0.8f;
if (*arg1 > temp2) {
*arg1 = temp2;
}
if ((0.0f < temp1) && (temp1 < 10.0f)) {
temp1 *= 6.0f;
} else {
temp1 = 0.0f;
arg2 = 0.0f;
}
Math_AsymStepToF(arg1, arg2 * 0.8f, temp1, (fabsf(*arg1) * 0.02f) + 0.05f);
Math_ScaledStepToS(&this->currentYaw, arg3, 1600);
}
}
// #region SOH [Enhancement]
//Diving uses function func_8084AEEC to calculate changes both xz and y velocity (via func_8084DBC4)
//Provide original calculation for y velocity when swim speed mod is active
void SurfaceWithoutSwimMod(Player* this, f32* arg1, f32 arg2, s16 arg3) {
f32 temp1;
f32 temp2;
temp1 = this->skelAnime.curFrame - 10.0f; temp1 = this->skelAnime.curFrame - 10.0f;
temp2 = (R_RUN_SPEED_LIMIT / 100.0f) * 0.8f; temp2 = (R_RUN_SPEED_LIMIT / 100.0f) * 0.8f;
@ -11944,6 +12006,7 @@ void func_8084AEEC(Player* this, f32* arg1, f32 arg2, s16 arg3) {
Math_AsymStepToF(arg1, arg2 * 0.8f, temp1, (fabsf(*arg1) * 0.02f) + 0.05f); Math_AsymStepToF(arg1, arg2 * 0.8f, temp1, (fabsf(*arg1) * 0.02f) + 0.05f);
Math_ScaledStepToS(&this->currentYaw, arg3, 1600); Math_ScaledStepToS(&this->currentYaw, arg3, 1600);
} }
// #endregion
void func_8084B000(Player* this) { void func_8084B000(Player* this) {
f32 phi_f18; f32 phi_f18;
@ -13098,7 +13161,14 @@ void func_8084DBC4(PlayState* play, Player* this, f32 arg2) {
Player_GetMovementSpeedAndYaw(this, &sp2C, &sp2A, 0.0f, play); Player_GetMovementSpeedAndYaw(this, &sp2C, &sp2A, 0.0f, play);
func_8084AEEC(this, &this->linearVelocity, sp2C * 0.5f, sp2A); func_8084AEEC(this, &this->linearVelocity, sp2C * 0.5f, sp2A);
// Original implementation of func_8084AEEC (SurfaceWithoutSwimMod) to prevent velocity increases via swim mod which push Link into the air
// #region SOH [Enhancement]
if (CVarGetInteger("gEnableWalkModify", 0)) {
SurfaceWithoutSwimMod(this, &this->actor.velocity.y, arg2, this->currentYaw);
// #endregion
} else {
func_8084AEEC(this, &this->actor.velocity.y, arg2, this->currentYaw); func_8084AEEC(this, &this->actor.velocity.y, arg2, this->currentYaw);
}
} }
void func_8084DC48(Player* this, PlayState* play) { void func_8084DC48(Player* this, PlayState* play) {