diff --git a/BepInEx5Plugins.Ash.Alisa.Stairs/BepInEx5Plugins.Ash.Alisa.Stairs.csproj b/BepInEx5Plugins.Ash.Alisa.Stairs/BepInEx5Plugins.Ash.Alisa.Stairs.csproj new file mode 100644 index 0000000..c13505e --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.Stairs/BepInEx5Plugins.Ash.Alisa.Stairs.csproj @@ -0,0 +1,33 @@ + + + + net35 + BepInEx5Plugins.Ash.Alisa.Stairs + Stairs + 1.0.0 + true + 9.0 + + + + + + + + + + + + + + + + ..\lib\SteamRelease\Assembly-CSharp.dll + false + + + + + + + diff --git a/BepInEx5Plugins.Ash.Alisa.Stairs/HarmonyPatches/Interaction_FixedUpdate.cs b/BepInEx5Plugins.Ash.Alisa.Stairs/HarmonyPatches/Interaction_FixedUpdate.cs new file mode 100644 index 0000000..717734e --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.Stairs/HarmonyPatches/Interaction_FixedUpdate.cs @@ -0,0 +1,92 @@ +using HarmonyLib; +using System; +using UnityEngine; + +namespace BepInEx5Plugins.Ash.Alisa.Stairs.HarmonyPatches +{ + [HarmonyPatch(typeof(Interaction), "FixedUpdate")] + public class Interaction_FixedUpdate + { + public static float stairsWalkSpeed = 2f; + + public static bool ignoreAnimation = false; + + public static bool newGamePlusOnly = false; + + // Add speed modifier when moving on stairs. + private static bool Prefix(Interaction __instance, ref float? __state + , ref GameObject ___player + , ref bool ___playerMovingDown + , ref bool ___playerMovingUp + , ref Animator ___anim + ) + { + __state = null; + + if (newGamePlusOnly + && ProgressManager.instance.data.newGamePlus < 1) + { + return true; + } + + try + { + ___anim.SetBool("WalkingDownStairs", ___playerMovingDown); + ___anim.SetBool("WalkingUpStairs", ___playerMovingUp); + + if (!ignoreAnimation) + { + __state = ___anim.speed; + } + + if (___playerMovingDown) + { + if (!ignoreAnimation) + { + __state = stairsWalkSpeed; + } + ___player.transform.Translate(stairsWalkSpeed * Vector3.forward * 0.7f * Time.fixedDeltaTime); + ___player.transform.Translate(stairsWalkSpeed * Vector3.down * 0.475f * Time.fixedDeltaTime); + ___player.GetComponent().velocity = Vector3.zero; + } + + if (___playerMovingUp) + { + if (!ignoreAnimation) + { + __state = stairsWalkSpeed; + } + ___player.transform.Translate(stairsWalkSpeed * Vector3.forward * 0.7f * Time.fixedDeltaTime); + ___player.transform.Translate(stairsWalkSpeed * Vector3.up * 0.48f * Time.fixedDeltaTime); + ___player.GetComponent().velocity = Vector3.zero; + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + + return false; + } + + // Modify the animation speed if necessary. + private static void Postfix(Interaction __instance, ref float? __state + , ref Animator ___anim + ) + { + try + { + __state = null; + + if (__state.HasValue) + { + ___anim.speed = __state.Value; + } + } + catch (Exception ex) + { + Console.WriteLine(ex); + } + } + } +} diff --git a/BepInEx5Plugins.Ash.Alisa.Stairs/NuGet.Config b/BepInEx5Plugins.Ash.Alisa.Stairs/NuGet.Config new file mode 100644 index 0000000..1864ded --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.Stairs/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/BepInEx5Plugins.Ash.Alisa.Stairs/Plugin.cs b/BepInEx5Plugins.Ash.Alisa.Stairs/Plugin.cs new file mode 100644 index 0000000..1f876e1 --- /dev/null +++ b/BepInEx5Plugins.Ash.Alisa.Stairs/Plugin.cs @@ -0,0 +1,63 @@ +using BepInEx; +using BepInEx.Configuration; +using HarmonyLib; +using System; + +namespace BepInEx5Plugins.Ash.Alisa.Stairs +{ + [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] + public class Plugin : BaseUnityPlugin + { + private static ConfigEntry ignoreAnimation; + + private static ConfigEntry newGamePlusOnly; + + private static ConfigEntry stairsWalkSpeed; + + private Plugin() + { + try + { + stairsWalkSpeed = Config.Bind("Stairs", "Walk Speed", 2f); + ignoreAnimation = Config.Bind("Stairs", "Ignore Animation", false); + newGamePlusOnly = Config.Bind("Stairs", "New Game Plus Only", false); + + Config.SettingChanged += Config_SettingChanged; + + ApplySettings(); + } + catch (Exception exception) + { + Console.WriteLine(exception); + } + } + + private static void Config_SettingChanged(object sender, EventArgs e) + { + ApplySettings(); + } + + private static void ApplySettings() + { + HarmonyPatches.Interaction_FixedUpdate.stairsWalkSpeed = stairsWalkSpeed.Value; + HarmonyPatches.Interaction_FixedUpdate.ignoreAnimation = ignoreAnimation.Value; + HarmonyPatches.Interaction_FixedUpdate.newGamePlusOnly = newGamePlusOnly.Value; + } + + private void Awake() + { + try + { + Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); + + var harmony = new Harmony(Info.Metadata.GUID); + + harmony.PatchAll(); + } + catch (Exception exception) + { + Console.WriteLine(exception); + } + } + } +}