Skip to content

Commit

Permalink
feat: Add new config options
Browse files Browse the repository at this point in the history
SprintToggleOnAutorun and AllowAutorunInInventory w/ wireup and documentation (README)
  • Loading branch information
afilbert committed Feb 5, 2024
1 parent 3d9ec08 commit 1331f8e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ Configuration allows:
* **Enable**, Enable the mod, default: true
* **OverrideGameAutorun**, This overrides the new auto-run config setting that functions as a sprint toggle, default: true
* **SprintToggle**, Sprint works like a toggle, default: true
* **OnlyToggleWhenAutorunning**, Sprint only works like a toggle when auto-running, default: false
* **SprintToggleAlternate**, Sprint is toggled through use of another key/button, default: false
* **SprintToggleAlternateKey**, Used in conjunction with SprintToggleAlternate. This is the key used to toggle sprint on/off, default: T
* **AutorunToggle**, Fixes auto-run to follow look, default: true
* **AutorunFreelookKey**, Overrides look direction in auto-run while pressed, default: CapsLock
* **AutorunStrafe**, Enable strafing while in auto-run/crouch, default: true
* **AutorunStrafeForwardDisables**, Disable autorun if Forward key/button pressed while AutorunStrafe enabled, default: true
* **AutorunInMap**, Keep running while viewing map, default: true
* **AutorunInInventory**, Keep running while viewing inventory, default: false
* **ReequipWeaponAfterSwimming**, Any weapon stowed in order to swim will reequip once out of swimming state, default: true
* **RunToCrouchToggle**, Go from run to crouch with the click of a button, default: true
* **StopSneakOnNoStam**, Stops sneak movement if no stamina available, default: true
Expand All @@ -103,6 +105,7 @@ Built with [BepInEx](https://valheim.thunderstore.io/package/denikson/BepInExPac

Releases in github repo are packaged for Thunderstore Mod Manager.

* 1.1.0 Add config to only toggle sprinting when auto-running, and/or allow auto-running while in inventory
* 1.0.0 Major version release adds color-coded stamina bar
* Stamina bar will be orange when sprint toggled, else it will appear blue when regenerating, else it will be its normal yellow
* Stamina bar will repeatedly flash while empty if sprint toggled and regen is overridden by directional input
Expand Down
32 changes: 23 additions & 9 deletions ToggleMovementMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using TMPro;

namespace ValheimMovementMods
Expand All @@ -17,7 +16,7 @@ public class ToggleMovementMod : BaseUnityPlugin
{
const string pluginGUID = "afilbert.ValheimToggleMovementMod";
const string pluginName = "Valheim - Toggle Movement Mod";
const string pluginVersion = "1.0.0";
const string pluginVersion = "1.1.0";
public static ManualLogSource logger;

private readonly Harmony _harmony = new Harmony(pluginGUID);
Expand All @@ -42,9 +41,11 @@ public class ToggleMovementMod : BaseUnityPlugin
public static ConfigEntry<float> SprintHealthOverride;
public static ConfigEntry<bool> TrackElapsedZeroStamToggle;
public static ConfigEntry<float> TrackElapsedZeroStamTime;
public static ConfigEntry<bool> OverrideAutoRunSetting;
public static ConfigEntry<bool> AllowAutoRunWhileInMap;
public static ConfigEntry<bool> OverrideAutorunSetting;
public static ConfigEntry<bool> AllowAutorunWhileInMap;
public static ConfigEntry<bool> VisuallyIndicateSprintState;
public static ConfigEntry<bool> SprintToggleOnAutorun;
public static ConfigEntry<bool> AllowAutorunInInventory;

public static bool StaminaRefilling = false, SprintSet = false, AutorunSet = false;
public static bool RunToCrouch = false, Crouching = false;
Expand All @@ -58,15 +59,17 @@ void Awake()
_plugin = this;
logger = Logger;
EnableToggle = Config.Bind<bool>("Mod Config", "Enable", true, "Enable this mod");
OverrideAutoRunSetting = Config.Bind<bool>("Mod Config", "OverrideGameAutorun", true, "This overrides the new auto-run config setting that functions as a sprint toggle");
OverrideAutorunSetting = Config.Bind<bool>("Mod Config", "OverrideGameAutorun", true, "This overrides the new auto-run config setting that functions as a sprint toggle");
SprintToggle = Config.Bind<bool>("Sprint", "SprintToggle", true, "Sprint works like a toggle when true");
SprintToggleOnAutorun = Config.Bind<bool>("Sprint", "OnlyToggleWhenAutorunning", false, "Sprint only works like a toggle when auto-running");
SprintToggleAlternate = Config.Bind<bool>("SprintAlternate", "SprintToggleAlternate", false, "Sprint is toggled through use of another key/button");
SprintToggleAlternateKey = Config.Bind<string>("SprintAlternate", "SprintToggleAlternateKey", "T", "Used in conjunction with SprintToggleAlternate. This is the key used to toggle sprint on/off");
AutorunOverride = Config.Bind<bool>("Auto-run", "AutorunToggle", true, "Fixes auto-run to follow look direction");
AutorunFreelookKey = Config.Bind<string>("Auto-run", "AutorunFreelookKey", "CapsLock", "Overrides look direction in auto-run while pressed");
AutorunStrafe = Config.Bind<bool>("Auto-run", "AutorunStrafe", true, "Enable strafing while in auto-run/crouch");
AutorunStrafeForwardDisables = Config.Bind<bool>("Auto-run", "AutorunStrafeForwardDisables", false, "Disable autorun if Forward key/button pressed while AutorunStrafe enabled");
AllowAutoRunWhileInMap = Config.Bind<bool>("Auto-run", "AutorunInMap", true, "Keep running while viewing map");
AllowAutorunWhileInMap = Config.Bind<bool>("Auto-run", "AutorunInMap", true, "Keep running while viewing map");
AllowAutorunInInventory = Config.Bind<bool>("Auto-run", "AutorunInInventory", false, "Keep running while viewing inventory");
ReequipWeaponAfterSwimming = Config.Bind<bool>("Swim", "ReequipWeaponAfterSwimming", true, "Any weapon stowed in order to swim will reequip once out of swimming state");
RunToCrouchToggle = Config.Bind<bool>("Auto-sneak", "RunToCrouchToggle", true, "Allows going from full run to crouch with a click of the crouch button (and vice versa)");
StopSneakMovementToggle = Config.Bind<bool>("Auto-sneak", "StopSneakOnNoStam", true, "Stops sneak movement if no stamina available. Stock behavior is to pop out of sneak into walk");
Expand Down Expand Up @@ -107,7 +110,7 @@ private static void Prefix(ref Player __instance, ref Vector3 movedir, ref bool
StaminaRefilling = false;
}

if (OverrideAutoRunSetting.Value)
if (OverrideAutorunSetting.Value)
{
run = ZInput.GetButton("Run") || ZInput.GetButton("JoyRun");
}
Expand Down Expand Up @@ -294,7 +297,7 @@ private void OnDestroy()

private bool IsInMenu()
{
return ZInput.GetButtonDown("Esc") || ZInput.GetButtonDown("JoyMenu") || InventoryGui.IsVisible() || (!AllowAutoRunWhileInMap.Value && Minimap.IsOpen()) || Console.IsVisible() || TextInput.IsVisible() || ZNet.instance.InPasswordDialog() || StoreGui.IsVisible() || Hud.IsPieceSelectionVisible() || UnifiedPopup.IsVisible();
return ZInput.GetButtonDown("Esc") || ZInput.GetButtonDown("JoyMenu") || (!AllowAutorunInInventory.Value && InventoryGui.IsVisible()) || (!AllowAutorunWhileInMap.Value && Minimap.IsOpen()) || Console.IsVisible() || TextInput.IsVisible() || ZNet.instance.InPasswordDialog() || StoreGui.IsVisible() || Hud.IsPieceSelectionVisible() || UnifiedPopup.IsVisible();
}

private void Update()
Expand Down Expand Up @@ -332,9 +335,20 @@ private void Update()
{
AutorunSet = !AutorunSet;
}
if (!AutorunSet && SprintToggleOnAutorun.Value)
{
SprintSet = false;
}
if (run && SprintToggle.Value)
{
SprintSet = !SprintSet;
if (!SprintToggleOnAutorun.Value)
{
SprintSet = !SprintSet;
}
if (SprintToggleOnAutorun.Value && AutorunSet)
{
SprintSet = !SprintSet;
}
}
if (crouch && RunToCrouchToggle.Value)
{
Expand Down

0 comments on commit 1331f8e

Please sign in to comment.