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 NM Sprint Limiter REPO v0.2.0
BepInEx/plugins/NM_Sprint_Limiter_REPO/NM_Sprint_Limiter_REPO.dll
Decompiled 2 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Nightmare.REPO.Core; using Nightmare.REPO.Localization; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Nightmare Community / NM")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) 2026 Nick1Z2 (Nightmare Community / NM).")] [assembly: AssemblyFileVersion("0.2.0.0")] [assembly: AssemblyInformationalVersion("0.2.0")] [assembly: AssemblyProduct("NM_Sprint_Limiter_REPO")] [assembly: AssemblyTitle("NM_Sprint_Limiter_REPO")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Nightmare.REPO.Localization { internal static class L { internal static readonly Dictionary<string, string> Translations = new Dictionary<string, string>(StringComparer.Ordinal) { { "Nur das eigene Sprinttempo begrenzen; auch als Gast. Upgrade-Zähler und Ausdauerverbrauch bleiben unverändert.", "Limit only your own sprint speed, including as a guest. Upgrade counters and stamina consumption remain unchanged." }, { "Maximal genutzte Speed-Stufen. Erhöht niemals das vorhandene Tempo.", "Maximum effective Speed levels. Never increases your existing speed." }, { "Optional begrenztes/volles Tempo umschalten, wenn kein Menü/Textfeld aktiv ist.", "Optional key to switch between limited / full speed while no menu or text field is active." }, { "Sprint-Begrenzer", "Sprint Limiter" }, { "Eigenes Tempo begrenzen, ohne Upgrades zu verändern.", "Limit your own speed without changing upgrades." }, { "Tempo unverändert: ", "Speed unchanged: " }, { "Sprint-Berechnung hat sich geändert (", "Sprint calculation has changed (" }, { " Treffer).", " matches)." }, { "Sprint-Begrenzung an.", "Sprint limiter enabled." }, { "Volles vorhandenes Sprinttempo.", "Full available sprint speed." }, { "SPRINT-BEGRENZER", "SPRINT LIMITER" }, { "Eigenes Sprinttempo begrenzen", "Limit my sprint speed" }, { "Maximal genutzte Speed-Stufen: ", "Maximum effective Speed levels: " }, { "Bitte eine ganze Zahl von 0 bis 10000 eingeben; bisheriger Wert bleibt aktiv.", "Enter an integer from 0 to 10000; the previous value remains active." }, { "Sprinttempo: ", "Sprint speed: " }, { "Automatisch gespeichert. Wirkt nur auf dich, auch als Gast. Upgrades, persönliche Offsets und Ausdauerverbrauch bleiben erhalten. Andere Tempo-Mods können die Berechnung beeinflussen.", "Saved automatically. Affects only you, including as a guest. Upgrades, personal offsets and stamina consumption are retained. Other speed mods may affect the calculation." } }; [ThreadStatic] private static string? captureLanguage; internal static string Language => captureLanguage ?? CoreApi.Language; internal static string T(string german) { if (!(Language == "de")) { return English(german); } return german; } internal static string English(string german) { if (!Translations.TryGetValue(german, out string value) || value == null) { return german; } return value; } internal static string Help(string german) { return "DE: " + german + "\nEN: " + English(german); } internal static LocalText Capture(Func<string> render) { string text = captureLanguage; try { captureLanguage = "de"; string german = render(); captureLanguage = "en"; return new LocalText(german, render()); } finally { captureLanguage = text; } } internal static AddonDefinition Describe(AddonDefinition definition, string name, string description) { definition.NameProvider = () => T(name); definition.DescriptionProvider = () => T(description); return definition; } } internal sealed class LocalText { private readonly string de; private readonly string en; internal int Length => ToString().Length; internal LocalText(string german, string english) { de = german; en = english; } public override string ToString() { if (!(L.Language == "de")) { return en; } return de; } public static implicit operator string(LocalText value) { return value.ToString(); } public static implicit operator LocalText(string value) { return new LocalText(value, value); } } } namespace Nightmare.REPO.SprintLimiter { [BepInPlugin("nightmare.repo.sprintlimiter", "NM_Sprint_Limiter_REPO", "0.2.0")] [BepInDependency("nightmare.repo.core", "2.10.1")] [BepInProcess("REPO.exe")] public sealed class Plugin : BaseUnityPlugin { public const string Id = "nightmare.repo.sprintlimiter"; public const string Version = "0.2.0"; private static Plugin? instance; private readonly Harmony patches = new Harmony("nightmare.repo.sprintlimiter"); private AddonHandle? page; private ConfigEntry<bool> active; private ConfigEntry<int> stages; private ConfigEntry<KeyCode> toggle; private LocalText fault = ""; private string stageText = ""; private void Awake() { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Expected O, but got Unknown active = ((BaseUnityPlugin)this).Config.Bind<bool>("Tempo", "Aktiv", false, L.Help("Nur das eigene Sprinttempo begrenzen; auch als Gast. Upgrade-Zähler und Ausdauerverbrauch bleiben unverändert.")); stages = ((BaseUnityPlugin)this).Config.Bind<int>("Tempo", "WirksameSpeedStufen", 4, new ConfigDescription(L.Help("Maximal genutzte Speed-Stufen. Erhöht niemals das vorhandene Tempo."), (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>())); stageText = stages.Value.ToString(); toggle = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Bedienung", "Umschalttaste", (KeyCode)0, L.Help("Optional begrenztes/volles Tempo umschalten, wenn kein Menü/Textfeld aktiv ist.")); page = CoreApi.Register(L.Describe(new AddonDefinition("nightmare.repo.sprintlimiter", "Sprint-Begrenzer", "0.2.0", "Eigenes Tempo begrenzen, ohne Upgrades zu verändern.", (Action<AddonUi>)Draw, 1), "Sprint-Begrenzer", "Eigenes Tempo begrenzen, ohne Upgrades zu verändern.")); instance = this; try { patches.Patch((MethodBase)AccessTools.Method(typeof(PlayerController), "FixedUpdate", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "Rewrite", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception ex) { Exception ex2 = ex; Exception ex3 = ex2; patches.UnpatchSelf(); fault = L.Capture(() => L.T("Tempo unverändert: ") + ex3.Message); ((BaseUnityPlugin)this).Logger.LogError((object)ex3); } } private static IEnumerable<CodeInstruction> Rewrite(IEnumerable<CodeInstruction> input) { List<CodeInstruction> list = new List<CodeInstruction>(input); int num = 0; FieldInfo objB = AccessTools.Field(typeof(PlayerController), "SprintSpeed"); foreach (CodeInstruction item in list) { if (item.opcode == OpCodes.Ldfld && object.Equals(item.operand, objB)) { item.opcode = OpCodes.Call; item.operand = AccessTools.Method(typeof(Plugin), "Effective", (Type[])null, (Type[])null); num++; } } if (num != 1) { throw new InvalidOperationException(L.T("Sprint-Berechnung hat sich geändert (") + num + L.T(" Treffer).")); } return list; } private static float Effective(PlayerController player) { float sprintSpeed = player.SprintSpeed; Plugin plugin = instance; if ((Object)(object)plugin == (Object)null || !((Behaviour)plugin).isActiveAndEnabled || !plugin.active.Value || (Object)(object)player != (Object)(object)PlayerController.instance) { return sprintSpeed; } float original = ((CoreReflection.Field(typeof(PlayerController), "playerOriginalSprintSpeed")?.GetValue(player) is float num) ? num : sprintSpeed); return SprintPolicy.Cap(sprintSpeed, original, player.SprintSpeedUpgrades, plugin.stages.Value); } private void Update() { //IL_0006: 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) //IL_0021: Invalid comparison between Unknown and I4 //IL_0029: Unknown result type (might be due to invalid IL or missing references) if ((int)toggle.Value != 0 && !CoreApi.IsOpen && SemiFunc.NoTextInputsActive() && (int)Cursor.lockState == 1 && Input.GetKeyDown(toggle.Value)) { active.Value = !active.Value; AddonHandle? obj = page; if (obj != null) { obj.Notify(active.Value ? L.T("Sprint-Begrenzung an.") : L.T("Volles vorhandenes Sprinttempo."), 8f); } } } private void Draw(AddonUi ui) { GUILayout.Label(L.T("SPRINT-BEGRENZER"), ui.Title, Array.Empty<GUILayoutOption>()); if (fault.Length > 0) { GUILayout.Label((string)fault, ui.Danger, Array.Empty<GUILayoutOption>()); } if (GUILayout.Button((active.Value ? "✓ " : "○ ") + L.T("Eigenes Sprinttempo begrenzen"), ui.Button, Array.Empty<GUILayoutOption>())) { active.Value = !active.Value; } GUILayout.Label(L.T("Maximal genutzte Speed-Stufen: ") + stages.Value, ui.Body, Array.Empty<GUILayoutOption>()); stageText = GUILayout.TextField(stageText, 5, ui.TextField, Array.Empty<GUILayoutOption>()); if (int.TryParse(stageText, out var result) && result >= 0 && result <= 10000) { if (result != stages.Value) { stages.Value = result; } } else { GUILayout.Label(L.T("Bitte eine ganze Zahl von 0 bis 10000 eingeben; bisheriger Wert bleibt aktiv."), ui.Small, Array.Empty<GUILayoutOption>()); } if (Object.op_Implicit((Object)(object)PlayerController.instance)) { GUILayout.Label(L.T("Sprinttempo: ") + PlayerController.instance.SprintSpeed.ToString("0.0") + " → " + Effective(PlayerController.instance).ToString("0.0"), ui.Body, Array.Empty<GUILayoutOption>()); } GUILayout.Label(L.T("Automatisch gespeichert. Wirkt nur auf dich, auch als Gast. Upgrades, persönliche Offsets und Ausdauerverbrauch bleiben erhalten. Andere Tempo-Mods können die Berechnung beeinflussen."), ui.Small, Array.Empty<GUILayoutOption>()); } private void OnDestroy() { patches.UnpatchSelf(); AddonHandle? obj = page; if (obj != null) { obj.Dispose(); } if ((Object)(object)instance == (Object)(object)this) { instance = null; } } } internal static class SprintPolicy { internal static float Cap(float current, float original, float upgrades, int allowed) { if (float.IsNaN(current) || float.IsInfinity(current) || float.IsNaN(original) || float.IsInfinity(original) || float.IsNaN(upgrades) || float.IsInfinity(upgrades) || current <= 0f || original <= 0f) { return current; } float num = Math.Max(0f, upgrades - (float)Math.Max(0, allowed)); return current * Math.Max(0f, Math.Min(1f, (original - num) / original)); } } }