Decompiled source of AutoSprint v1.4.3

AutoSprint.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AutoSprint.Core;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Croco;
using EntityStates.FalseSon;
using EntityStates.Railgunner.Scope;
using EntityStates.Toolbot;
using EntityStates.VoidSurvivor.Weapon;
using HG.Reflection;
using HarmonyLib;
using IL.RoR2;
using IL.RoR2.CameraModes;
using IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.EntityStates;
using On.RoR2;
using On.RoR2.Skills;
using Rewired;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.CameraModes;
using RoR2.Skills;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AutoSprint")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+56d71077fd82c4eb2b5e0bf783ff97a995370bf2")]
[assembly: AssemblyProduct("AutoSprint")]
[assembly: AssemblyTitle("AutoSprint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 AutoSprint
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.score.AutoSprint", "AutoSprint", "1.4.3")]
	public class AutoSprintPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.score.AutoSprint";

		public const string PluginAuthor = "score";

		public const string PluginName = "AutoSprint";

		public const string PluginVersion = "1.4.3";

		internal static bool RooInstalled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		public static AutoSprintPlugin Instance { get; private set; }

		internal string DirectoryName => Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);

		public void Awake()
		{
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			PluginConfig.Init(((BaseUnityPlugin)this).Config);
			AutoSprintManager.Init();
			Hooks.Init();
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(string data)
		{
			if (PluginConfig.EnableDebugMode.Value)
			{
				_logSource.LogDebug((object)data);
			}
		}

		internal static void Info(string data)
		{
			if (PluginConfig.EnableDebugMode.Value)
			{
				_logSource.LogInfo((object)data);
			}
		}

		internal static void Message(string data)
		{
			_logSource.LogMessage((object)data);
		}

		internal static void Warning(string data)
		{
			_logSource.LogWarning((object)data);
		}

		internal static void Error(string data)
		{
			_logSource.LogError((object)data);
		}

		internal static void Fatal(string data)
		{
			_logSource.LogFatal((object)data);
		}
	}
	internal static class PluginConfig
	{
		public static ConfigEntry<bool> HoldSprintToWalk { get; set; }

		public static ConfigEntry<bool> DisableSprintingCrosshair { get; set; }

		public static ConfigEntry<bool> DisableSprintingFOV { get; set; }

		public static ConfigEntry<bool> ForceSprintingFOV { get; set; }

		public static ConfigEntry<int> BaseDelayTicks { get; set; }

		public static ConfigEntry<int> DelayTicks { get; set; }

		public static ConfigEntry<bool> EnableOmniSprint { get; set; }

		public static ConfigEntry<bool> EnableDebugMode { get; set; }

		public static ConfigEntry<string> DisabledBodies { get; set; }

		public static ConfigEntry<string> DisableSprintingCustomList { get; set; }

		public static ConfigEntry<string> DisableSprintingCustomList2 { get; set; }

		public static void Init(ConfigFile cfg)
		{
			if (AutoSprintPlugin.RooInstalled)
			{
				InitRoO();
			}
			HoldSprintToWalk = cfg.BindOption("General", "Hold Sprint To Walk", defaultValue: true, "Walk by holding down the sprint key. If disabled, makes the Sprint key toggle AutoSprinting functionality on and off.");
			DisableSprintingCrosshair = cfg.BindOption("General", "Disable Sprinting Crosshair", defaultValue: true, "Disables the special sprinting chevron crosshair.");
			ForceSprintingFOV = cfg.BindOption("General", "Force Sprinting FOV", defaultValue: true, "Changes the FOV to be constantly set to the 1.3x multiplier. This overrides the \"Disable Sprinting FOV Increase\" setting. Disable both for vanilla behavior.");
			DisableSprintingFOV = cfg.BindOption("General", "Disable Sprinting FOV Increase", defaultValue: false, "Disables the change in FOV when sprinting. This setting requires the \"Force Sprinting FOV\" to be disabled for it to have any effect. Disable both for vanilla behavior.");
			EnableOmniSprint = cfg.BindOption("General", "Enable OmniSprint", defaultValue: false, "Allows sprinting in all directions. This is generally considered cheating, use with discretion.");
			BaseDelayTicks = cfg.BindOptionSlider("General", "Base Delay", 5, "How long to wait, in game ticks, before sprinting. Game runs at 60hz, so 1 tick == 16ms", 0f, 60f);
			DelayTicks = cfg.BindOptionSlider("General", "Skill Activation Delay", 20, "How long to wait, in game ticks, before sprinting after beginning certain skills. Game runs at 60hz, so 1 tick == 16ms", 0f, 60f);
			EnableDebugMode = cfg.BindOption("General", "Enable Debug Mode", defaultValue: false, "Prints every entity state that your character changes to.");
			DisabledBodies = cfg.BindOption("Advanced", "Disable Body", "", "Custom body name list, has to match body catalog name.");
			DisableSprintingCustomList = cfg.BindOption("Advanced", "Disable Sprint Custom List", "EntityStates.Toolbot.ToolbotDualWield,", "Custom EntityState list for when a skill is cancelled by sprinting when it shouldn't, separated by commas.\r\nThe Debug Mode cfg option will print the state names to the Bepinex console/log output.\r\n\r\nExample: EntityStates.Toolbot.ToolbotDualWield");
			DisableSprintingCustomList2 = cfg.BindOption("Advanced", "Disable Sprint With Duration List", "(EntityStates.Croco.Slash, durationBeforeInterruptable) (EntityStates.Toolbot.ToolbotDualWieldStart, 0.9)", "(typeFullName, fieldName) --or-- (typeFullName, ###)\r\n\r\nExample: (EntityStates.Toolbot.ToolbotDualWieldStart, baseDuration)\r\n --or--  (EntityStates.Toolbot.ToolbotDualWieldStart, 0.75)");
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void InitRoO()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			try
			{
				ModSettingsManager.SetModDescription("AutoSprint, as God intended.", "com.score.AutoSprint", "AutoSprint");
				byte[] array = File.ReadAllBytes(Path.Combine(AutoSprintPlugin.Instance.DirectoryName, "icon.png"));
				Texture2D val = new Texture2D(256, 256);
				ImageConversion.LoadImage(val, array);
				ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f)));
			}
			catch (Exception ex)
			{
				Log.Debug(ex.ToString());
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static ConfigEntry<T> BindOption<T>(this ConfigFile myConfig, string section, string name, T defaultValue, string description = "", bool restartRequired = false)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			bool flag = ((defaultValue is int || defaultValue is float) ? true : false);
			if (flag && !typeof(T).IsEnum)
			{
				return myConfig.BindOptionSlider(section, name, defaultValue, description, 0f, 20f, restartRequired);
			}
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			if (restartRequired)
			{
				description += " (restart required)";
			}
			AcceptableValueBase val = null;
			if (typeof(T).IsEnum)
			{
				val = (AcceptableValueBase)(object)new AcceptableValueList<string>(Enum.GetNames(typeof(T)));
			}
			ConfigEntry<T> val2 = myConfig.Bind<T>(section, name, defaultValue, new ConfigDescription(description, val, Array.Empty<object>()));
			if (AutoSprintPlugin.RooInstalled)
			{
				TryRegisterOption<T>(val2, restartRequired);
			}
			return val2;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static ConfigEntry<T> BindOptionSlider<T>(this ConfigFile myConfig, string section, string name, T defaultValue, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			bool flag = ((defaultValue is int || defaultValue is float) ? true : false);
			if (!flag || typeof(T).IsEnum)
			{
				return myConfig.BindOption(section, name, defaultValue, description, restartRequired);
			}
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			string text = description;
			T val = defaultValue;
			description = text + " (Default: " + val?.ToString() + ")";
			if (restartRequired)
			{
				description += " (restart required)";
			}
			AcceptableValueBase val2 = (AcceptableValueBase)((typeof(T) == typeof(int)) ? ((object)new AcceptableValueRange<int>((int)min, (int)max)) : ((object)new AcceptableValueRange<float>(min, max)));
			ConfigEntry<T> val3 = myConfig.Bind<T>(section, name, defaultValue, new ConfigDescription(description, val2, Array.Empty<object>()));
			if (AutoSprintPlugin.RooInstalled)
			{
				TryRegisterOptionSlider<T>(val3, min, max, restartRequired);
			}
			return val3;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static ConfigEntry<T> BindOptionSteppedSlider<T>(this ConfigFile myConfig, string section, string name, T defaultValue, float increment = 1f, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			if (string.IsNullOrEmpty(description))
			{
				description = name;
			}
			string text = description;
			T val = defaultValue;
			description = text + " (Default: " + val?.ToString() + ")";
			if (restartRequired)
			{
				description += " (restart required)";
			}
			ConfigEntry<T> val2 = myConfig.Bind<T>(section, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
			if (AutoSprintPlugin.RooInstalled)
			{
				TryRegisterOptionSteppedSlider<T>(val2, increment, min, max, restartRequired);
			}
			return val2;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void TryRegisterOption<T>(ConfigEntry<T> entry, bool restartRequired)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			if (entry is ConfigEntry<string> val)
			{
				ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(val, new InputFieldConfig
				{
					submitOn = (SubmitEnum)6,
					restartRequired = restartRequired
				}));
			}
			else if (entry is ConfigEntry<bool> val2)
			{
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(val2, restartRequired));
			}
			else if (entry is ConfigEntry<KeyboardShortcut> val3)
			{
				ModSettingsManager.AddOption((BaseOption)new KeyBindOption(val3, restartRequired));
			}
			else if (typeof(T).IsEnum)
			{
				ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)entry, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void TryRegisterOptionSlider<T>(ConfigEntry<T> entry, float min, float max, bool restartRequired)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			if (entry is ConfigEntry<int> val)
			{
				ModSettingsManager.AddOption((BaseOption)new IntSliderOption(val, new IntSliderConfig
				{
					min = (int)min,
					max = (int)max,
					formatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
			else if (entry is ConfigEntry<float> val2)
			{
				ModSettingsManager.AddOption((BaseOption)new SliderOption(val2, new SliderConfig
				{
					min = min,
					max = max,
					FormatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void TryRegisterOptionSteppedSlider<T>(ConfigEntry<T> entry, float increment, float min, float max, bool restartRequired)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (entry is ConfigEntry<float> val)
			{
				ModSettingsManager.AddOption((BaseOption)new StepSliderOption(val, new StepSliderConfig
				{
					increment = increment,
					min = min,
					max = max,
					FormatString = "{0:0.00}",
					restartRequired = restartRequired
				}));
			}
		}
	}
}
namespace AutoSprint.Core
{
	public class AutoSprintManager
	{
		private CharacterBody _cachedBody;

		private EntityStateMachine[] _cachedStateMachines;

		private float _delayTimer;

		private bool _enableSprintOverride = true;

		public float AnimationExitDelay => (float)PluginConfig.DelayTicks.Value * Time.fixedDeltaTime;

		public float BaseExitDelay => (float)PluginConfig.BaseDelayTicks.Value * Time.fixedDeltaTime;

		public CharacterBody CachedBody => _cachedBody;

		public static AutoSprintManager Instance { get; private set; }

		public static void Init()
		{
			if (Instance == null)
			{
				Instance = new AutoSprintManager();
			}
		}

		private AutoSprintManager()
		{
		}

		public static void TryHandleSprint(PlayerCharacterMasterController pcmc, Player inputPlayer, bool isSprinting)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (Instance == null)
			{
				Log.Error("You must be fucking retarded, how did you manage that");
			}
			else if (!StateManager.DisabledBodies.Contains(pcmc.body.bodyIndex))
			{
				Instance.HandleSprint(pcmc, inputPlayer, isSprinting);
			}
		}

		private void HandleSprint(PlayerCharacterMasterController pcmc, Player inputPlayer, bool isSprinting)
		{
			if (PluginConfig.HoldSprintToWalk.Value)
			{
				_enableSprintOverride = !inputPlayer.GetButton("Sprint");
			}
			else if (pcmc.sprintInputPressReceived)
			{
				_enableSprintOverride = !_enableSprintOverride;
			}
			if (!_enableSprintOverride || isSprinting)
			{
				_delayTimer = BaseExitDelay;
				return;
			}
			if (!CanSprintBeEnabled(pcmc.body, out var activeDelayTimer))
			{
				_delayTimer = activeDelayTimer;
			}
			if (_delayTimer > 0f)
			{
				_delayTimer -= Time.fixedDeltaTime;
			}
			else
			{
				pcmc.sprintInputPressReceived = true;
			}
		}

		private bool CanSprintBeEnabled(CharacterBody targetBody, out float activeDelayTimer)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			activeDelayTimer = 0f;
			if ((Object)(object)targetBody != (Object)(object)_cachedBody)
			{
				Log.Info(BodyCatalog.GetBodyName(targetBody.bodyIndex));
				_cachedBody = targetBody;
				_cachedStateMachines = ((Component)targetBody).GetComponents<EntityStateMachine>();
			}
			for (int i = 0; i < _cachedStateMachines.Length; i++)
			{
				EntityStateMachine val = _cachedStateMachines[i];
				if (((val != null) ? val.state : null) != null)
				{
					EntityStateIndex stateIndex = EntityStateCatalog.GetStateIndex(((object)val.state).GetType());
					if (StateManager.EntityStateDisabledSet.Contains(stateIndex))
					{
						activeDelayTimer = Mathf.Max(activeDelayTimer, BaseExitDelay);
					}
					if (StateManager.EntityStateDelayTable.ContainsKey(stateIndex))
					{
						activeDelayTimer = Mathf.Max(activeDelayTimer, GetDurationRemaining(val.state, stateIndex));
					}
				}
			}
			return activeDelayTimer == 0f;
		}

		private float GetDurationRemaining(EntityState state, EntityStateIndex stateIndex)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if (StateManager.EntityStateDelayTable[stateIndex] is float num)
			{
				return AnimationExitDelay + (num - state.fixedAge);
			}
			if (StateManager.EntityStateDelayTable[stateIndex] is FieldInfo fieldInfo && fieldInfo.FieldType == typeof(float) && fieldInfo.DeclaringType.IsAssignableFrom(((object)state).GetType()))
			{
				return AnimationExitDelay + ((float)fieldInfo.GetValue(state) - state.fixedAge);
			}
			Log.Error($"Field for {((object)state).GetType().FullName} is invalid, default is delay is {AnimationExitDelay}.");
			return AnimationExitDelay - state.fixedAge;
		}
	}
	internal class Hooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__UpdateFromBodyCatalog;

			public static hook_Init <1>__EntityStateCatalog_Init;

			public static hook_Init <2>__SkillCatalog_Init;

			public static Manipulator <3>__PlayerCharacterMasterController_PollButtonInput;

			public static Manipulator <4>__CrosshairManager_UpdateCrosshair;

			public static Manipulator <5>__CameraModePlayerBasic_UpdateInternal;

			public static hook_OnEnter <6>__EntityState_OnEnter;

			public static Action<PlayerCharacterMasterController, Player, bool> <7>__TryHandleSprint;
		}

		private bool _hooksEnabled;

		public static Hooks Instance { get; private set; }

		public static void Init()
		{
			if (Instance == null)
			{
				Instance = new Hooks();
			}
		}

		private Hooks()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			EnableDebugMode_SettingChanged(null, null);
			PluginConfig.EnableDebugMode.SettingChanged += EnableDebugMode_SettingChanged;
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)StateManager.UpdateFromBodyCatalog);
			object obj = <>O.<1>__EntityStateCatalog_Init;
			if (obj == null)
			{
				hook_Init val = EntityStateCatalog_Init;
				<>O.<1>__EntityStateCatalog_Init = val;
				obj = (object)val;
			}
			EntityStateCatalog.Init += (hook_Init)obj;
			object obj2 = <>O.<2>__SkillCatalog_Init;
			if (obj2 == null)
			{
				hook_Init val2 = SkillCatalog_Init;
				<>O.<2>__SkillCatalog_Init = val2;
				obj2 = (object)val2;
			}
			SkillCatalog.Init += (hook_Init)obj2;
			object obj3 = <>O.<3>__PlayerCharacterMasterController_PollButtonInput;
			if (obj3 == null)
			{
				Manipulator val3 = PlayerCharacterMasterController_PollButtonInput;
				<>O.<3>__PlayerCharacterMasterController_PollButtonInput = val3;
				obj3 = (object)val3;
			}
			PlayerCharacterMasterController.PollButtonInput += (Manipulator)obj3;
			object obj4 = <>O.<4>__CrosshairManager_UpdateCrosshair;
			if (obj4 == null)
			{
				Manipulator val4 = CrosshairManager_UpdateCrosshair;
				<>O.<4>__CrosshairManager_UpdateCrosshair = val4;
				obj4 = (object)val4;
			}
			CrosshairManager.UpdateCrosshair += (Manipulator)obj4;
			object obj5 = <>O.<5>__CameraModePlayerBasic_UpdateInternal;
			if (obj5 == null)
			{
				Manipulator val5 = CameraModePlayerBasic_UpdateInternal;
				<>O.<5>__CameraModePlayerBasic_UpdateInternal = val5;
				obj5 = (object)val5;
			}
			CameraModePlayerBasic.UpdateInternal += (Manipulator)obj5;
		}

		private void EnableDebugMode_SettingChanged(object sender, EventArgs e)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			if (_hooksEnabled == PluginConfig.EnableDebugMode.Value)
			{
				return;
			}
			_hooksEnabled = PluginConfig.EnableDebugMode.Value;
			if (_hooksEnabled)
			{
				object obj = <>O.<6>__EntityState_OnEnter;
				if (obj == null)
				{
					hook_OnEnter val = EntityState_OnEnter;
					<>O.<6>__EntityState_OnEnter = val;
					obj = (object)val;
				}
				EntityState.OnEnter += (hook_OnEnter)obj;
			}
			else
			{
				object obj2 = <>O.<6>__EntityState_OnEnter;
				if (obj2 == null)
				{
					hook_OnEnter val2 = EntityState_OnEnter;
					<>O.<6>__EntityState_OnEnter = val2;
					obj2 = (object)val2;
				}
				EntityState.OnEnter -= (hook_OnEnter)obj2;
			}
		}

		private static IEnumerator EntityStateCatalog_Init(orig_Init orig)
		{
			yield return orig.Invoke();
			StateManager.UpdateFromEntityStateCatalog();
		}

		private static void SkillCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			StateManager.UpdateFromSkillCatalog();
		}

		private static void CameraModePlayerBasic_UpdateInternal(ILContext il)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			ILLabel noFovLabel = null;
			ILCursor[] array = null;
			int num = default(int);
			if (val.TryGotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchLdflda<CameraModeContext>(x, "targetInfo"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<TargetInfo>(x, "isSprinting")
			}) && val.TryFindNext(ref array, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref noFovLabel)
			}))
			{
				ILCursor obj = array[0];
				int index = obj.Index;
				obj.Index = index + 1;
				ILLabel val2 = array[0].MarkLabel();
				val.Emit(OpCodes.Call, (MethodBase)AccessTools.PropertyGetter(typeof(PluginConfig), "ForceSprintingFOV"));
				val.Emit(OpCodes.Callvirt, (MethodBase)AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), "Value"));
				val.Emit(OpCodes.Brtrue, (object)val2);
				val.Emit(OpCodes.Call, (MethodBase)AccessTools.PropertyGetter(typeof(PluginConfig), "DisableSprintingFOV"));
				val.Emit(OpCodes.Callvirt, (MethodBase)AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), "Value"));
				val.Emit(OpCodes.Brtrue, (object)noFovLabel);
			}
			else
			{
				Log.Error("AutoSprint IL hook for CameraModePlayerBasic_UpdateInternal failed");
			}
		}

		private static void EntityState_OnEnter(orig_OnEnter orig, EntityState self)
		{
			orig.Invoke(self);
			if (Object.op_Implicit((Object)(object)self.characterBody) && (Object)(object)self.characterBody == (Object)(object)AutoSprintManager.Instance?.CachedBody)
			{
				Log.Info(((object)self).GetType().FullName);
			}
		}

		private static void PlayerCharacterMasterController_PollButtonInput(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			ILCursor c = new ILCursor(il);
			int playerLoc = 0;
			int isSprintingLoc = 0;
			int num = default(int);
			if (c.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertyGetter(typeof(PlayerCharacterMasterController), "networkUser")),
				(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref playerLoc)
			}) && c.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerCharacterMasterController>(x, "body"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertyGetter(typeof(CharacterBody), "isSprinting"))
			}) && c.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref isSprintingLoc)
			}))
			{
				c.Emit(OpCodes.Ldarg_0);
				c.Emit(OpCodes.Ldloc, playerLoc);
				c.Emit(OpCodes.Ldloc, isSprintingLoc);
				c.EmitDelegate<Action<PlayerCharacterMasterController, Player, bool>>((Action<PlayerCharacterMasterController, Player, bool>)AutoSprintManager.TryHandleSprint);
			}
			else
			{
				Log.Error("AutoSprint IL hook for PlayerCharacterMasterController_PollButtonInput failed");
			}
			ILLabel label = null;
			ILCursor[] array = default(ILCursor[]);
			if (c.TryGotoNext((MoveType)0, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerCharacterMasterController>(x, "body"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<CharacterBody>(x, "bodyFlags") && c.TryFindNext(ref array, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchBrtrue(x, ref label)
				})
			}))
			{
				c.Emit(OpCodes.Call, (MethodBase)AccessTools.PropertyGetter(typeof(PluginConfig), "EnableOmniSprint"));
				c.Emit(OpCodes.Callvirt, (MethodBase)AccessTools.PropertyGetter(typeof(ConfigEntry<bool>), "Value"));
				c.Emit(OpCodes.Brtrue, (object)label);
			}
			else
			{
				Log.Error("AutoSprint IL hook for PlayerCharacterMasterController_PollButtonInput - Enable Omni Sprint failed");
			}
		}

		private static void CrosshairManager_UpdateCrosshair(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ILCursor val2 = new ILCursor(il);
			if (val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertyGetter(typeof(CharacterBody), "isSprinting"))
			}))
			{
				val2.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool val) => val && !PluginConfig.DisableSprintingCrosshair.Value));
			}
			else
			{
				Log.Error("AutoSprint IL hook for CrosshairManager_UpdateCrosshair failed");
			}
		}
	}
	public static class StateManager
	{
		public static readonly HashSet<(string, string)> SprintDelayTypeValuePairs = new HashSet<(string, string)>();

		public static readonly Hashtable EntityStateDelayTable = new Hashtable();

		public static readonly HashSet<string> SprintDisabledTypeNames = new HashSet<string>();

		public static readonly HashSet<EntityStateIndex> EntityStateDisabledSet = new HashSet<EntityStateIndex>();

		public static readonly HashSet<BodyIndex> DisabledBodies = new HashSet<BodyIndex>();

		public static readonly Dictionary<string, EntityStateIndex> TypeFullNameToStateIndex = new Dictionary<string, EntityStateIndex>();

		internal static void UpdateFromBodyCatalog()
		{
			UpdateDisabledBodies(null, null);
			PluginConfig.DisableSprintingCustomList.SettingChanged += UpdateDisabledBodies;
		}

		internal static void UpdateFromEntityStateCatalog()
		{
			for (int i = 0; i < EntityStateCatalog.stateIndexToType.Length; i++)
			{
				TypeFullNameToStateIndex[EntityStateCatalog.stateIndexToType[i].FullName] = (EntityStateIndex)i;
			}
			UpdateDisabledStates(null, null);
			UpdateDelayStates(null, null);
			PluginConfig.DisableSprintingCustomList.SettingChanged += UpdateDisabledStates;
			PluginConfig.DisableSprintingCustomList2.SettingChanged += UpdateDelayStates;
		}

		internal static void UpdateFromSkillCatalog()
		{
			foreach (SkillDef allSkillDef in SkillCatalog.allSkillDefs)
			{
				if (!Object.op_Implicit((Object)(object)allSkillDef) || allSkillDef.forceSprintDuringState)
				{
					continue;
				}
				Type stateType = ((SerializableEntityStateType)(ref allSkillDef.activationState)).stateType;
				if ((object)stateType != null && !(stateType == typeof(Idle)) && !stateType.IsSubclassOf(typeof(Idle)))
				{
					if (allSkillDef.canceledFromSprinting)
					{
						SprintDisabledTypeNames.Add(stateType.FullName);
					}
					else if (allSkillDef.cancelSprintingOnActivation)
					{
						SprintDelayTypeValuePairs.Add((stateType.FullName, "0"));
					}
				}
			}
			SprintDisabledTypeNames.Add(typeof(FireNailgun).FullName);
			SprintDisabledTypeNames.Add(typeof(ToolbotDualWieldBase).FullName);
			SprintDisabledTypeNames.Add(typeof(FireCorruptHandBeam).FullName);
			SprintDisabledTypeNames.Add(typeof(ActiveScopeHeavy).FullName);
			SprintDisabledTypeNames.Add(typeof(ActiveScopeLight).FullName);
			SprintDisabledTypeNames.Add(typeof(WindUpScopeHeavy).FullName);
			SprintDisabledTypeNames.Add(typeof(WindUpScopeLight).FullName);
			SprintDisabledTypeNames.Remove(typeof(LaserFather).FullName);
			SprintDisabledTypeNames.Remove(typeof(Slash).FullName);
			SprintDisabledTypeNames.Remove(typeof(Bite).FullName);
			SprintDelayTypeValuePairs.Add((typeof(ToolbotDualWieldStart).FullName, "baseDuration"));
			SprintDelayTypeValuePairs.Add((typeof(Slash).FullName, "durationBeforeInterruptable"));
			SprintDelayTypeValuePairs.Add((typeof(Bite).FullName, "durationBeforeInterruptable"));
		}

		internal static void UpdateDisabledBodies(object _, EventArgs __)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Invalid comparison between Unknown and I4
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			DisabledBodies.Clear();
			List<string> list = new List<string>(3) { "JohnnyBody", "PantheraBody", "RA2ChronoBody" };
			string[] array = PluginConfig.DisabledBodies.Value.Replace(" ", string.Empty).Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					list.Add(text);
				}
			}
			foreach (string item in list)
			{
				BodyIndex val = BodyCatalog.FindBodyIndex(item);
				if ((int)val != -1)
				{
					DisabledBodies.Add(val);
					Log.Message(item + " added to the disabled bodies list.");
				}
				else
				{
					Log.Warning(item + " is not a valid body, skipping...");
				}
			}
		}

		internal static void UpdateDisabledStates(object _, EventArgs __)
		{
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			EntityStateDisabledSet.Clear();
			HashSet<string> sprintDisabledTypeNames = SprintDisabledTypeNames;
			List<string> list = new List<string>(13 + sprintDisabledTypeNames.Count);
			list.AddRange(sprintDisabledTypeNames);
			list.Add("LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.EnterSnipe");
			list.Add("LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.Snipe");
			list.Add("LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.IdleSnipe");
			list.Add("LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.ExitSnipe");
			list.Add("PaladinMod.States.Spell.ChannelCruelSun");
			list.Add("PaladinMod.States.Spell.ChannelHealZone");
			list.Add("PaladinMod.States.Spell.ChannelSmallHeal");
			list.Add("PaladinMod.States.Spell.ChannelTorpor");
			list.Add("PaladinMod.States.Spell.ChannelWarcry");
			list.Add("PaladinMod.States.Spell.CastCruelSun");
			list.Add("PaladinMod.States.Spell.CastChanneledWarcry");
			list.Add("PaladinMod.States.Spell.CastChanneledTorpor");
			list.Add("PaladinMod.States.Spell.CastChanneledHealZone");
			List<string> list2 = list;
			string[] array = PluginConfig.DisableSprintingCustomList.Value.Replace(" ", string.Empty).Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					list2.Add(text);
				}
			}
			foreach (string item in list2)
			{
				if (TypeFullNameToStateIndex.TryGetValue(item, out var value))
				{
					EntityStateDisabledSet.Add(value);
					Log.Info(item + " added to the custom entity state list.");
				}
				else
				{
					Log.Warning(item + " is not a valid entity state, skipping...");
				}
			}
		}

		internal static void UpdateDelayStates(object _, EventArgs __)
		{
			EntityStateDelayTable.Clear();
			foreach (var (typeFullName, value) in SprintDelayTypeValuePairs)
			{
				AddSprintDelay(typeFullName, value);
			}
			string[] array = PluginConfig.DisableSprintingCustomList2.Value.Replace(" ", string.Empty).Split(')');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					string[] array2 = text.Split(',');
					if (array2.Length != 2)
					{
						Log.Warning(text + " is not in the valid (key, value) pair format, skipping...");
					}
					else
					{
						AddSprintDelay(array2[0].Replace("(", string.Empty), array2[1]);
					}
				}
			}
		}

		private static void AddSprintDelay(string typeFullName, string value)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			if (value == null)
			{
				value = string.Empty;
			}
			if (!TypeFullNameToStateIndex.TryGetValue(typeFullName, out var value2))
			{
				Log.Error("Type: " + typeFullName + " | Field: " + value + " | The type does not exist in the EntityStateCatalog.");
				return;
			}
			Type stateType = EntityStateCatalog.GetStateType(value2);
			if ((object)stateType == null)
			{
				Log.Error("Type: " + typeFullName + " | Field: " + value + " | The state exists in the EntityStateCatalog but the type is null.");
				return;
			}
			value = value.Replace(" ", string.Empty);
			if (string.IsNullOrEmpty(value))
			{
				value = "0";
			}
			if (float.TryParse(value, out var result))
			{
				Log.Info($"Type: {stateType.FullName} | Value: {result} | Has been added to the custom entity state list.");
				EntityStateDelayTable[value2] = result;
			}
			else
			{
				AddFieldInfo(stateType, value2, value);
			}
		}

		private static void AddFieldInfo(Type T, EntityStateIndex index, string name)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			FieldInfo fieldInfo = AccessTools.DeclaredField(T, name);
			if ((object)fieldInfo == null)
			{
				Log.Error("\r\nField with that name could not be found and wasnt able to parse the value as numeric. Type not added.\r\n" + T.FullName + " : " + (name ?? "NULL"));
				return;
			}
			if (fieldInfo.FieldType != typeof(float))
			{
				Log.Error("\r\nField must be a float, but the field does exist. Type not added.\r\n" + T.FullName + " : " + fieldInfo.Name);
				return;
			}
			if (EntityStateDelayTable.ContainsKey(index))
			{
				Log.Warning("\r\nOverwriting duplicate entry\r\n" + T.FullName + " : " + fieldInfo.Name + "\r\nold " + (EntityStateDelayTable[index]?.ToString() ?? "NULL") + " | new " + fieldInfo.Name);
			}
			else
			{
				Log.Info("Type: " + T.FullName + " | Field: " + name + " | Has been added to the custom entity state list.");
			}
			EntityStateDelayTable[index] = fieldInfo;
		}
	}
}