Decompiled source of Sprint v2026.217.0

plugins/Sprint/Sprint.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Sprint.Config;
using Sprint.Core;
using Sprint.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sprint")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+437444b1a6e723b4b612f549cacd88f5827ddee8")]
[assembly: AssemblyProduct("Sprint")]
[assembly: AssemblyTitle("Sprint")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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 Sprint
{
	[BepInPlugin("wow-much.sprint", "Sprint", "2026.217.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private Harmony? _harmony;

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			SprintConfig sprintConfig = new SprintConfig(((BaseUnityPlugin)this).Config);
			SprintManager.Initialize(sprintConfig, Log);
			CalcStatsPatch.Initialize(sprintConfig);
			((Component)this).gameObject.AddComponent<SprintManager>();
			_harmony = new Harmony("wow-much.sprint");
			try
			{
				_harmony.PatchAll();
				Log.LogInfo((object)"Harmony patches applied successfully");
				IEnumerable<MethodBase> patchedMethods = _harmony.GetPatchedMethods();
				foreach (MethodBase item in patchedMethods)
				{
					Log.LogInfo((object)("  Patched: " + item.DeclaringType?.Name + "." + item.Name));
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to apply Harmony patches: {arg}");
			}
			Log.LogInfo((object)"Sprint v2026.217.0 loaded");
			Log.LogInfo((object)$"  Sprint Key: {sprintConfig.SprintKey.Value}");
			Log.LogInfo((object)("  Toggle Mode: " + (sprintConfig.ToggleMode.Value ? "Enabled" : "Disabled")));
			Log.LogInfo((object)$"  Speed Multiplier: {sprintConfig.SprintMultiplier.Value}x");
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal static class PluginInfo
	{
		public const string GUID = "wow-much.sprint";

		public const string Name = "Sprint";

		public const string Version = "2026.217.0";
	}
}
namespace Sprint.Patches
{
	[HarmonyPatch(typeof(Stats), "CalcStats")]
	internal static class CalcStatsPatch
	{
		private static SprintConfig? _config;

		public static void Initialize(SprintConfig config)
		{
			_config = config;
		}

		[HarmonyPostfix]
		private static void CalcStats_Postfix(Stats __instance)
		{
			if (_config == null)
			{
				return;
			}
			bool flag = SprintManager.IsSprintActive(__instance);
			SprintManager.ApplySprint(__instance, flag);
			if (flag && _config.ModLogLevel.Value == LogLevel.Debug)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogDebug((object)$"Sprint reapplied in CalcStats: actualRunSpeed={__instance.actualRunSpeed:F2}");
				}
			}
		}
	}
}
namespace Sprint.Core
{
	public class SprintManager : MonoBehaviour
	{
		private static SprintManager? _instance;

		private static SprintConfig? _config;

		private static ManualLogSource? _log;

		private bool _sprintActive;

		private bool _previousKeyState;

		private Stats? _playerStats;

		public static void Initialize(SprintConfig config, ManualLogSource log)
		{
			_config = config;
			_log = log;
		}

		public static bool IsSprintActive(Stats stats)
		{
			if ((Object)(object)_instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)_instance._playerStats == (Object)null || (Object)(object)stats != (Object)(object)_instance._playerStats)
			{
				return false;
			}
			return _instance._sprintActive;
		}

		public static void ApplySprint(Stats stats, bool shouldSprint)
		{
			if (!((Object)(object)stats == (Object)null) && _config != null)
			{
				float value = Traverse.Create((object)stats).Field("seRunSpeed").GetValue<float>();
				if (shouldSprint)
				{
					stats.actualRunSpeed = (stats.RunSpeed + value) * _config.SprintMultiplier.Value;
				}
				else
				{
					stats.actualRunSpeed = stats.RunSpeed + value;
				}
				if (stats.actualRunSpeed < 2f)
				{
					stats.actualRunSpeed = 2f;
				}
			}
		}

		private void Awake()
		{
			_instance = this;
			_sprintActive = false;
			_previousKeyState = false;
		}

		private void Update()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (_config == null)
			{
				return;
			}
			if ((Object)(object)_playerStats == (Object)null)
			{
				GameObject val = GameObject.Find("Player");
				if ((Object)(object)val != (Object)null)
				{
					_playerStats = val.GetComponent<Stats>();
					if ((Object)(object)_playerStats != (Object)null && _log != null)
					{
						_log.LogDebug((object)"Sprint: Player found and cached");
					}
				}
				return;
			}
			bool key = Input.GetKey(_config.SprintKey.Value);
			if (_config.ToggleMode.Value)
			{
				if (key && !_previousKeyState)
				{
					_sprintActive = !_sprintActive;
					if (_log != null && _config.ModLogLevel.Value == LogLevel.Debug)
					{
						_log.LogDebug((object)("Sprint toggled: " + (_sprintActive ? "ON" : "OFF")));
					}
				}
				_previousKeyState = key;
			}
			else
			{
				if (_sprintActive != key && _log != null && _config.ModLogLevel.Value == LogLevel.Debug)
				{
					_log.LogDebug((object)("Sprint: " + (key ? "ON" : "OFF")));
				}
				_sprintActive = key;
			}
			ApplySprint(_playerStats, _sprintActive);
		}

		private void OnDestroy()
		{
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}
	}
}
namespace Sprint.Config
{
	public enum LogLevel
	{
		Debug,
		Info,
		Warning,
		Error
	}
	public class SprintConfig
	{
		public ConfigEntry<KeyCode> SprintKey { get; }

		public ConfigEntry<bool> ToggleMode { get; }

		public ConfigEntry<float> SprintMultiplier { get; }

		public ConfigEntry<LogLevel> ModLogLevel { get; }

		public SprintConfig(ConfigFile config)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			SprintKey = config.Bind<KeyCode>("Controls", "SprintKey", (KeyCode)304, "Key to activate sprint. See Unity KeyCode documentation for valid values (e.g., LeftShift, RightShift, Space, LeftControl).");
			ToggleMode = config.Bind<bool>("Controls", "ToggleMode", false, "If true, tap sprint key to toggle sprint on/off. If false, hold sprint key to sprint.");
			SprintMultiplier = config.Bind<float>("Speed", "SprintMultiplier", 1.5f, new ConfigDescription("Speed multiplier when sprinting. 1.0 = normal speed, 1.5 = 50% faster, 2.0 = double speed, 10.0 = ludicrous speed!", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f), Array.Empty<object>()));
			ModLogLevel = config.Bind<LogLevel>("Logging", "LogLevel", LogLevel.Info, "Log level for the mod. Debug shows detailed diagnostics, Info shows important events (recommended).");
		}
	}
}