Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of CrouchAndCrawlSprint v1.0.1
CrouchAndCrawlSprint.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("CrouchAndCrawlSprint")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("HP")] [assembly: AssemblyProduct("CrouchAndCrawlSprint")] [assembly: AssemblyCopyright("Copyright © HP 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("e9e10d94-5f30-40b8-af64-4f4133769cba")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace CrouchAndCrawlSprint; [BepInPlugin("TechedCrayon413.CrouchAndCrawlSprint", "Crouch And Crawl Sprint", "1.0.1")] public class CrouchAndCrawlSprint : BaseUnityPlugin { public static ConfigEntry<KeyCode> CrawlKey; public static ConfigEntry<bool> ToggleMode; public static ConfigEntry<float> SprintSpeedAndStaminaScaler; private void Awake() { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Expected O, but got Unknown CrawlKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Crawl Key", (KeyCode)308, "Key used to crawl"); ToggleMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "Crawl Key Toggle Mode", true, "If true then toggle crawl key to crawl, if false then hold crawl key to crawl"); SprintSpeedAndStaminaScaler = ((BaseUnityPlugin)this).Config.Bind<float>("Options", "Crouch and crawl sprint speed and stamina scaler", 1.6f, new ConfigDescription("ratio of crawling or crouching sprint speed to stamia usage", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.4f, 4f), Array.Empty<object>())); Harmony val = new Harmony("TechedCrayon413.CrouchAndCrawlSprint"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CrouchAndCrawlSprint v1.0.1 loaded successfully"); } } public static class CrawlState { public static bool IsCrawling = false; public static bool AttemptToSprint = false; public static bool SprintLock = false; public static float StaminaOverride = -1f; public static Dictionary<int, float> DefaultSpeed = new Dictionary<int, float>(); } [HarmonyPatch(typeof(PlayerController), "Update")] public static class Patch_PlayerController { public static void Postfix(PlayerController __instance) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) KeyCode value = CrouchAndCrawlSprint.CrawlKey.Value; if (CrouchAndCrawlSprint.ToggleMode.Value) { if (Input.GetKeyDown(value)) { CrawlState.IsCrawling = !CrawlState.IsCrawling; } } else { CrawlState.IsCrawling = Input.GetKey(value); } if (CrawlState.IsCrawling) { __instance.SetCrawl(); } } } [HarmonyPatch(typeof(PlayerController), "FixedUpdate")] public static class PlayerController_FixedUpdate_Patch { private const float AreYouPressingSprintKeyWhilstMoving = 0.01f; public static bool CheckIfWalking(PlayerController player) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) Traverse val = Traverse.Create((object)player); bool value = val.Field<bool>("moving").Value; Vector3 value2 = val.Field<Vector3>("InputDirection").Value; bool flag = ((Vector3)(ref value2)).sqrMagnitude > 0.01f; return value || flag; } public static void Prefix(PlayerController __instance) { Traverse val = Traverse.Create((object)__instance); int instanceID = ((Object)__instance).GetInstanceID(); if (!CrawlState.DefaultSpeed.ContainsKey(instanceID)) { CrawlState.DefaultSpeed[instanceID] = val.Field<float>("CrouchSpeed").Value; } bool value = val.Field<bool>("Crouching").Value; bool isCrawling = CrawlState.IsCrawling; CrawlState.StaminaOverride = -1f; CrawlState.AttemptToSprint = false; if (value || isCrawling) { bool value2 = val.Field<bool>("toggleSprint").Value; bool flag = CheckIfWalking(__instance); float value3 = val.Field<float>("EnergyCurrent").Value; float value4 = val.Field<float>("crawlTimer").Value; bool flag2 = SemiFunc.InputHold((InputKey)15) || value2; CrawlState.AttemptToSprint = flag2 && flag; if (!flag2) { CrawlState.SprintLock = false; } val.Field<float>("CrouchSpeed").Value = CrawlState.DefaultSpeed[instanceID]; if (!CrawlState.AttemptToSprint) { return; } if (!CrawlState.SprintLock && value3 > 0f) { float value5 = val.Field<float>("SprintSpeed").Value; float value6 = val.Field<float>("SprintSpeedUpgrades").Value; float num = value5 + value6; float value7 = CrouchAndCrawlSprint.SprintSpeedAndStaminaScaler.Value; num /= value7; val.Field<float>("CrouchSpeed").Value = num; float value8 = val.Field<float>("EnergySprintDrain").Value; float num2 = 1.6f / value7; value3 -= value8 * num2 * Time.fixedDeltaTime; if (value3 <= 0f) { value3 = 0f; CrawlState.SprintLock = true; if (value2) { val.Field<bool>("toggleSprint").Value = false; } } val.Field<float>("EnergyCurrent").Value = value3; CrawlState.StaminaOverride = value3; } else if (CrawlState.SprintLock) { CrawlState.StaminaOverride = 0f; if (value2) { val.Field<bool>("toggleSprint").Value = false; } } } else { val.Field<float>("CrouchSpeed").Value = CrawlState.DefaultSpeed[instanceID]; } } public static void Postfix(PlayerController __instance) { if (CrawlState.StaminaOverride >= 0f) { Traverse.Create((object)__instance).Field<float>("EnergyCurrent").Value = CrawlState.StaminaOverride; } } } [HarmonyPatch(typeof(PlayerAvatar), "CrouchRestUpgrade")] public static class PlayerAvatar_CrouchRestUpgrade_Patch { public static bool Prefix(PlayerAvatar __instance) { if (CrawlState.AttemptToSprint) { Traverse.Create((object)__instance).Field<bool>("upgradeCrouchRestActive").Value = false; return false; } return true; } }