Decompiled source of AutoSprint v1.5.3

AutoSprint.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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.Acolyte.Weapon;
using EntityStates.Croco;
using EntityStates.DroneTech.Weapon;
using EntityStates.Engi.EngiWeapon;
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 MiscFixes.Modules;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using RiskOfOptions;
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+900575d904f539287656d0f7f1eee5d7ea02a983")]
[assembly: AssemblyProduct("AutoSprint")]
[assembly: AssemblyTitle("AutoSprint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[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]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 AutoSprint
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.score.AutoSprint", "AutoSprint", "1.5.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.5.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> EnableMod { get; private set; }

		public static ConfigEntry<bool> HoldSprintToWalk { get; private set; }

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

		public static ConfigEntry<bool> DisableSprintingSpeedLines { get; private set; }

		public static ConfigEntry<int> FovSlider { get; private set; }

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

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

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

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

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

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

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

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

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

		[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());
			}
		}

		public static void Init(ConfigFile cfg)
		{
			if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"))
			{
				InitRoO();
			}
			EnableMod = Extensions.BindOption<bool>(cfg, "General", "Enable Mod", "Set to false to disable all functionality.", true, (ConfigFlags)2);
			HoldSprintToWalk = Extensions.BindOption<bool>(cfg, "General", "Hold Sprint To Walk", "Walk by holding down the sprint key. If disabled, makes the Sprint key toggle AutoSprinting functionality on and off.", true, (ConfigFlags)2);
			DisableSprintingCrosshair = Extensions.BindOption<bool>(cfg, "General", "Disable Sprinting Crosshair", "Disables the special sprinting chevron crosshair.", true, (ConfigFlags)2);
			DisableSprintingSpeedLines = Extensions.BindOption<bool>(cfg, "General", "Disable Sprinting Speed Lines", "Disables the speed lines on the edges of the screen when sprinting.", false, (ConfigFlags)2);
			FovSlider = Extensions.BindOptionSlider<int>(cfg, "General", "Global FOV Increase", "Adds the configured value to all fov calculations. Set to 0 to disable.", 0, 0, 60, (ConfigFlags)2);
			ForceSprintingFOV = Extensions.BindOption<bool>(cfg, "General", "Force Sprinting FOV", "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.", true, (ConfigFlags)2);
			DisableSprintingFOV = Extensions.BindOption<bool>(cfg, "General", "Disable Sprinting FOV Increase", "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.", false, (ConfigFlags)2);
			EnableOmniSprint = Extensions.BindOption<bool>(cfg, "General", "Enable OmniSprint", "Allows sprinting in all directions. This is generally considered cheating, use with discretion.", false, (ConfigFlags)2);
			EnableDebugMode = Extensions.BindOption<bool>(cfg, "Advanced", "Enable Debug Mode", "Prints every entity state that your character changes to.", false, (ConfigFlags)2);
			BaseDelayTicks = Extensions.BindOptionSlider<int>(cfg, "Advanced", "Base Delay", "How long to wait, in game ticks, before sprinting. Game runs at 60hz, so 1 tick == 16ms", 5, 1, 60, (ConfigFlags)3);
			DelayTicks = Extensions.BindOptionSlider<int>(cfg, "Advanced", "Skill Activation Delay", "How long to wait, in game ticks, before sprinting after beginning certain skills. Game runs at 60hz, so 1 tick == 16ms", 20, 5, 60, (ConfigFlags)2);
			DisabledBodies = Extensions.BindOption<string>(cfg, "Advanced", "Disable Body", "Custom body name list, has to match body catalog name.", "", (ConfigFlags)2);
			DisableSprintingCustomList = Extensions.BindOption<string>(cfg, "Advanced", "Disable Sprint Custom List", "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", "", (ConfigFlags)2);
			DisableSprintingCustomList2 = Extensions.BindOption<string>(cfg, "Advanced", "Disable Sprint With Duration List", "(typeFullName, fieldName) --or-- (typeFullName, ###)\r\n\r\nExample: (EntityStates.Toolbot.ToolbotDualWieldStart, baseDuration)\r\n --or--  (EntityStates.Toolbot.ToolbotDualWieldStart, 0.75)", "", (ConfigFlags)2);
		}
	}
}
namespace AutoSprint.Core
{
	public class AutoSprintManager
	{
		public static CharacterBody CachedBody;

		public static NetworkStateMachine CachedStateMachine;

		private float _delayTimer;

		private bool _enableSprintOverride = true;

		public static AutoSprintManager Instance { get; private set; }

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

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

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

		private AutoSprintManager()
		{
		}

		public static bool TryHandleSprint(PlayerCharacterMasterController pcmc, PerButtonStruct<PollResult> pollResult, bool isSprinting)
		{
			//IL_004d: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pcmc.body != (Object)(object)CachedBody)
			{
				Log.Info(BodyCatalog.GetBodyName(pcmc.body.bodyIndex));
				CachedBody = pcmc.body;
				CachedStateMachine = ((Component)pcmc.body).GetComponent<NetworkStateMachine>();
			}
			if (StateManager.DisabledBodies.Contains(pcmc.body.bodyIndex))
			{
				return isSprinting;
			}
			return Instance.HandleSprint(pcmc, pollResult, isSprinting);
		}

		private bool HandleSprint(PlayerCharacterMasterController pcmc, PerButtonStruct<PollResult> pollResult, bool isSprinting)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (PluginConfig.HoldSprintToWalk.Value)
			{
				_enableSprintOverride = !pollResult.sprint.value;
			}
			else if (pollResult.sprint.justPressed)
			{
				_enableSprintOverride = !_enableSprintOverride;
			}
			if (!_enableSprintOverride || isSprinting || pcmc.bodyInputs.moveVector == Vector3.zero)
			{
				_delayTimer = BaseExitDelay;
				return isSprinting;
			}
			if (!CanSprintBeEnabled(out var activeDelayTimer))
			{
				_delayTimer = activeDelayTimer;
			}
			if (_delayTimer > 0f)
			{
				_delayTimer -= Time.fixedDeltaTime;
				return isSprinting;
			}
			return true;
		}

		private bool CanSprintBeEnabled(out float activeDelayTimer)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			activeDelayTimer = 0f;
			for (int i = 0; i < CachedStateMachine.stateMachines.Length; i++)
			{
				EntityStateMachine val = CachedStateMachine.stateMachines[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.SprintStateDelayTable.ContainsKey(stateIndex))
					{
						activeDelayTimer = Mathf.Max(activeDelayTimer, GetDurationRemaining(val.state, StateManager.SprintStateDelayTable[stateIndex]));
					}
				}
			}
			return activeDelayTimer == 0f;
		}

		private float GetDurationRemaining(EntityState state, object value)
		{
			float num = 0f;
			if (value is float num2)
			{
				num = num2;
			}
			else if (value is FieldInfo fieldInfo && fieldInfo.FieldType == typeof(float) && (fieldInfo.IsStatic || fieldInfo.DeclaringType.IsAssignableFrom(((object)state).GetType())))
			{
				num = (float)fieldInfo.GetValue((!fieldInfo.IsStatic) ? state : null);
			}
			return AnimationExitDelay + (num - state.fixedAge);
		}
	}
	internal class Hooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Init <0>__EntityStateCatalog_Init;

			public static Manipulator <1>__PlayerCharacterMasterController_PollButtonInput;

			public static Func<PlayerCharacterMasterController, PerButtonStruct<PollResult>, bool, bool> <2>__TryHandleSprint;

			public static hook_SetState <3>__EntityStateMachine_SetState;

			public static Manipulator <4>__CameraModePlayerBasic_UpdateInternal2;

			public static Manipulator <5>__CameraModePlayerBasic_UpdateInternal;

			public static hook_SetParticleSystemActive <6>__CameraRigController_SetParticleSystemActive;

			public static hook_SetSprintParticlesActive <7>__CameraRigController_SetSprintParticlesActive;

			public static Manipulator <8>__CrosshairManager_UpdateCrosshair;
		}

		[CompilerGenerated]
		private static bool <MainHooksEnabled>k__BackingField;

		[CompilerGenerated]
		private bool <DebugModeEnabled>k__BackingField;

		[CompilerGenerated]
		private bool <FovSliderEnabled>k__BackingField;

		[CompilerGenerated]
		private bool <ForceFovEnabled>k__BackingField;

		[CompilerGenerated]
		private bool <DisableSprintingSpeedLinesEnabled>k__BackingField;

		[CompilerGenerated]
		private bool <DisableSprintingCrosshairEnabled>k__BackingField;

		public static Hooks Instance { get; private set; }

		private static bool MainHooksEnabled
		{
			set
			{
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Expected O, but got Unknown
				//IL_0026: 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_0031: Expected O, but got Unknown
				if (<MainHooksEnabled>k__BackingField == value)
				{
					return;
				}
				<MainHooksEnabled>k__BackingField = value;
				if (<MainHooksEnabled>k__BackingField)
				{
					object obj = <>O.<1>__PlayerCharacterMasterController_PollButtonInput;
					if (obj == null)
					{
						Manipulator val = PlayerCharacterMasterController_PollButtonInput;
						<>O.<1>__PlayerCharacterMasterController_PollButtonInput = val;
						obj = (object)val;
					}
					PlayerCharacterMasterController.PollButtonInput += (Manipulator)obj;
				}
				else
				{
					object obj2 = <>O.<1>__PlayerCharacterMasterController_PollButtonInput;
					if (obj2 == null)
					{
						Manipulator val2 = PlayerCharacterMasterController_PollButtonInput;
						<>O.<1>__PlayerCharacterMasterController_PollButtonInput = val2;
						obj2 = (object)val2;
					}
					PlayerCharacterMasterController.PollButtonInput -= (Manipulator)obj2;
				}
			}
		}

		private bool DebugModeEnabled
		{
			set
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				if (<DebugModeEnabled>k__BackingField == value)
				{
					return;
				}
				<DebugModeEnabled>k__BackingField = value;
				if (<DebugModeEnabled>k__BackingField)
				{
					object obj = <>O.<3>__EntityStateMachine_SetState;
					if (obj == null)
					{
						hook_SetState val = EntityStateMachine_SetState;
						<>O.<3>__EntityStateMachine_SetState = val;
						obj = (object)val;
					}
					EntityStateMachine.SetState += (hook_SetState)obj;
				}
				else
				{
					object obj2 = <>O.<3>__EntityStateMachine_SetState;
					if (obj2 == null)
					{
						hook_SetState val2 = EntityStateMachine_SetState;
						<>O.<3>__EntityStateMachine_SetState = val2;
						obj2 = (object)val2;
					}
					EntityStateMachine.SetState -= (hook_SetState)obj2;
				}
			}
		}

		private bool FovSliderEnabled
		{
			set
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				if (<FovSliderEnabled>k__BackingField == value)
				{
					return;
				}
				<FovSliderEnabled>k__BackingField = value;
				if (<FovSliderEnabled>k__BackingField)
				{
					object obj = <>O.<4>__CameraModePlayerBasic_UpdateInternal2;
					if (obj == null)
					{
						Manipulator val = CameraModePlayerBasic_UpdateInternal2;
						<>O.<4>__CameraModePlayerBasic_UpdateInternal2 = val;
						obj = (object)val;
					}
					CameraModePlayerBasic.UpdateInternal += (Manipulator)obj;
				}
				else
				{
					object obj2 = <>O.<4>__CameraModePlayerBasic_UpdateInternal2;
					if (obj2 == null)
					{
						Manipulator val2 = CameraModePlayerBasic_UpdateInternal2;
						<>O.<4>__CameraModePlayerBasic_UpdateInternal2 = val2;
						obj2 = (object)val2;
					}
					CameraModePlayerBasic.UpdateInternal -= (Manipulator)obj2;
				}
			}
		}

		private bool ForceFovEnabled
		{
			set
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				if (<ForceFovEnabled>k__BackingField == value)
				{
					return;
				}
				<ForceFovEnabled>k__BackingField = value;
				if (<ForceFovEnabled>k__BackingField)
				{
					object obj = <>O.<5>__CameraModePlayerBasic_UpdateInternal;
					if (obj == null)
					{
						Manipulator val = CameraModePlayerBasic_UpdateInternal;
						<>O.<5>__CameraModePlayerBasic_UpdateInternal = val;
						obj = (object)val;
					}
					CameraModePlayerBasic.UpdateInternal += (Manipulator)obj;
				}
				else
				{
					object obj2 = <>O.<5>__CameraModePlayerBasic_UpdateInternal;
					if (obj2 == null)
					{
						Manipulator val2 = CameraModePlayerBasic_UpdateInternal;
						<>O.<5>__CameraModePlayerBasic_UpdateInternal = val2;
						obj2 = (object)val2;
					}
					CameraModePlayerBasic.UpdateInternal -= (Manipulator)obj2;
				}
			}
		}

		private bool DisableSprintingSpeedLinesEnabled
		{
			set
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				//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_0095: Expected O, but got Unknown
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Expected O, but got Unknown
				if (<DisableSprintingSpeedLinesEnabled>k__BackingField == value)
				{
					return;
				}
				<DisableSprintingSpeedLinesEnabled>k__BackingField = value;
				if (<DisableSprintingSpeedLinesEnabled>k__BackingField)
				{
					object obj = <>O.<6>__CameraRigController_SetParticleSystemActive;
					if (obj == null)
					{
						hook_SetParticleSystemActive val = CameraRigController_SetParticleSystemActive;
						<>O.<6>__CameraRigController_SetParticleSystemActive = val;
						obj = (object)val;
					}
					CameraRigController.SetParticleSystemActive += (hook_SetParticleSystemActive)obj;
					object obj2 = <>O.<7>__CameraRigController_SetSprintParticlesActive;
					if (obj2 == null)
					{
						hook_SetSprintParticlesActive val2 = CameraRigController_SetSprintParticlesActive;
						<>O.<7>__CameraRigController_SetSprintParticlesActive = val2;
						obj2 = (object)val2;
					}
					CameraRigController.SetSprintParticlesActive += (hook_SetSprintParticlesActive)obj2;
				}
				else
				{
					object obj3 = <>O.<6>__CameraRigController_SetParticleSystemActive;
					if (obj3 == null)
					{
						hook_SetParticleSystemActive val3 = CameraRigController_SetParticleSystemActive;
						<>O.<6>__CameraRigController_SetParticleSystemActive = val3;
						obj3 = (object)val3;
					}
					CameraRigController.SetParticleSystemActive -= (hook_SetParticleSystemActive)obj3;
					object obj4 = <>O.<7>__CameraRigController_SetSprintParticlesActive;
					if (obj4 == null)
					{
						hook_SetSprintParticlesActive val4 = CameraRigController_SetSprintParticlesActive;
						<>O.<7>__CameraRigController_SetSprintParticlesActive = val4;
						obj4 = (object)val4;
					}
					CameraRigController.SetSprintParticlesActive -= (hook_SetSprintParticlesActive)obj4;
				}
			}
		}

		private bool DisableSprintingCrosshairEnabled
		{
			set
			{
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				if (<DisableSprintingCrosshairEnabled>k__BackingField == value)
				{
					return;
				}
				<DisableSprintingCrosshairEnabled>k__BackingField = value;
				if (<DisableSprintingCrosshairEnabled>k__BackingField)
				{
					object obj = <>O.<8>__CrosshairManager_UpdateCrosshair;
					if (obj == null)
					{
						Manipulator val = CrosshairManager_UpdateCrosshair;
						<>O.<8>__CrosshairManager_UpdateCrosshair = val;
						obj = (object)val;
					}
					CrosshairManager.UpdateCrosshair += (Manipulator)obj;
				}
				else
				{
					object obj2 = <>O.<8>__CrosshairManager_UpdateCrosshair;
					if (obj2 == null)
					{
						Manipulator val2 = CrosshairManager_UpdateCrosshair;
						<>O.<8>__CrosshairManager_UpdateCrosshair = val2;
						obj2 = (object)val2;
					}
					CrosshairManager.UpdateCrosshair -= (Manipulator)obj2;
				}
			}
		}

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

		private Hooks()
		{
			//IL_0016: 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: Expected O, but got Unknown
			object obj = <>O.<0>__EntityStateCatalog_Init;
			if (obj == null)
			{
				hook_Init val = StateManager.EntityStateCatalog_Init;
				<>O.<0>__EntityStateCatalog_Init = val;
				obj = (object)val;
			}
			EntityStateCatalog.Init += (hook_Init)obj;
			SettingsChanged();
			((BaseUnityPlugin)AutoSprintPlugin.Instance).Config.SettingChanged += SettingsChanged;
		}

		private void SettingsChanged(object _ = null, EventArgs __ = null)
		{
			if (PluginConfig.EnableMod.Value)
			{
				MainHooksEnabled = true;
				DebugModeEnabled = PluginConfig.EnableDebugMode.Value;
				FovSliderEnabled = PluginConfig.FovSlider.Value > 0;
				ForceFovEnabled = PluginConfig.DisableSprintingFOV.Value || PluginConfig.ForceSprintingFOV.Value;
				DisableSprintingSpeedLinesEnabled = PluginConfig.DisableSprintingSpeedLines.Value;
				DisableSprintingCrosshairEnabled = PluginConfig.DisableSprintingCrosshair.Value;
			}
			else
			{
				MainHooksEnabled = false;
				DebugModeEnabled = false;
				FovSliderEnabled = false;
				ForceFovEnabled = false;
				DisableSprintingSpeedLinesEnabled = false;
				DisableSprintingCrosshairEnabled = false;
			}
		}

		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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			ILCursor c = new ILCursor(il);
			int pollResultLoc = 0;
			int isSprintingLoc = 0;
			if (!c.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(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)
			}))
			{
				Log.Error("AutoSprint IL hook for PlayerCharacterMasterController_PollButtonInput #1 failed");
			}
			else if (c.TryGotoNext((MoveType)1, new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref pollResultLoc),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, AccessTools.DeclaredField(typeof(PerButtonStruct<PollResult>), "sprint")),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<PollResult>(x, "justPressed")
			}))
			{
				c.Emit(OpCodes.Ldarg_0);
				c.Emit(OpCodes.Ldloc, pollResultLoc);
				c.Emit(OpCodes.Ldloc, isSprintingLoc);
				c.EmitDelegate<Func<PlayerCharacterMasterController, PerButtonStruct<PollResult>, bool, bool>>((Func<PlayerCharacterMasterController, PerButtonStruct<PollResult>, bool, bool>)AutoSprintManager.TryHandleSprint);
				c.Emit(OpCodes.Stloc, isSprintingLoc);
			}
			else
			{
				Log.Error("AutoSprint IL hook for PlayerCharacterMasterController_PollButtonInput failed #2");
			}
		}

		private static void EntityStateMachine_SetState(orig_SetState orig, EntityStateMachine self, EntityState newState)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)self.networker) && (Object)(object)self.networker == (Object)(object)AutoSprintManager.CachedStateMachine && newState != null)
			{
				Type type = ((object)newState).GetType();
				EntityStateIndex stateIndex = EntityStateCatalog.GetStateIndex(type);
				bool flag = StateManager.EntityStateDisabledSet.Contains(stateIndex) || StateManager.SprintStateDelayTable.ContainsKey(stateIndex);
				Log.Info($"Disable Sprint? {flag}  |  {type.FullName}");
			}
			orig.Invoke(self, newState);
		}

		private static void CameraModePlayerBasic_UpdateInternal2(ILContext il)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			ILCursor[] array = null;
			if (!new ILCursor(il).TryFindNext(ref array, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<CameraInfo>(x, "baseFov"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<CameraRigController>(x, "baseFov")
			}))
			{
				Log.Error("AutoSprint IL hook for CameraModePlayerBasic_UpdateInternal Custom FOV failed");
				return;
			}
			ILCursor obj = array[0];
			int index = obj.Index;
			obj.Index = index + 1;
			array[0].EmitDelegate<Func<float, float>>((Func<float, float>)((float fov) => fov + (float)PluginConfig.FovSlider.Value));
			ILCursor obj2 = array[1];
			index = obj2.Index;
			obj2.Index = index + 1;
			array[1].EmitDelegate<Func<float, float>>((Func<float, float>)((float fov) => fov + (float)PluginConfig.FovSlider.Value));
		}

		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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			ILCursor[] array = null;
			ILLabel noFovLabel = 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.EmitDelegate<Func<bool>>((Func<bool>)(() => PluginConfig.ForceSprintingFOV.Value));
				val.Emit(OpCodes.Brtrue, (object)val2);
				val.EmitDelegate<Func<bool>>((Func<bool>)(() => PluginConfig.DisableSprintingFOV.Value));
				val.Emit(OpCodes.Brtrue, (object)noFovLabel);
			}
			else
			{
				Log.Error("AutoSprint IL hook for CameraModePlayerBasic_UpdateInternal Sprinting FOV failed");
			}
		}

		private static void CameraRigController_SetSprintParticlesActive(orig_SetSprintParticlesActive orig, CameraRigController self, bool newSprintParticlesActive)
		{
			orig.Invoke(self, false);
		}

		private static void CameraRigController_SetParticleSystemActive(orig_SetParticleSystemActive orig, CameraRigController self, bool newParticlesActive, ParticleSystem particleSystem)
		{
			if ((Object)(object)particleSystem == (Object)(object)self.sprintingParticleSystem)
			{
				newParticlesActive = false;
			}
			orig.Invoke(self, newParticlesActive, particleSystem);
		}

		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 val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertyGetter(typeof(CharacterBody), "isSprinting"))
			}))
			{
				val.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool flag) => false));
			}
			else
			{
				Log.Error("AutoSprint IL hook for CrosshairManager_UpdateCrosshair failed");
			}
		}
	}
	public static class StateManager
	{
		public static readonly Dictionary<string, string> SprintDelayTypeNameValuePairs = new Dictionary<string, string>();

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

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

		internal static readonly Hashtable SprintStateDelayTable = new Hashtable();

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

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

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

		private static readonly Stopwatch timer = new Stopwatch();

		[SystemInitializer(new Type[] { typeof(SkillCatalog) })]
		internal static void UpdateFromSkillCatalog()
		{
			timer.Restart();
			Type typeFromHandle = typeof(Idle);
			for (int i = 0; i < SkillCatalog._allSkillDefs.Length; i++)
			{
				SkillDef val = SkillCatalog._allSkillDefs[i];
				if (val == null || val.forceSprintDuringState)
				{
					continue;
				}
				if (val.canceledFromSprinting)
				{
					Type stateType = ((SerializableEntityStateType)(ref val.activationState)).stateType;
					string text = stateType?.FullName;
					if (!string.IsNullOrEmpty(text) && !typeFromHandle.IsAssignableFrom(stateType))
					{
						SprintDisabledTypeNames.Add(text);
					}
				}
				else if (val.cancelSprintingOnActivation)
				{
					Type stateType2 = ((SerializableEntityStateType)(ref val.activationState)).stateType;
					string text2 = stateType2?.FullName;
					if (!string.IsNullOrEmpty(text2) && !typeFromHandle.IsAssignableFrom(stateType2))
					{
						SprintDelayTypeNameValuePairs[text2] = "0";
					}
				}
			}
			SprintDisabledTypeNames.Add(typeof(FireNailgun).FullName);
			SprintDisabledTypeNames.Add(typeof(ToolbotDualWieldStart).FullName);
			SprintDisabledTypeNames.Add(typeof(ToolbotDualWield).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.Add(typeof(ShieldFormation).FullName);
			SprintDisabledTypeNames.Remove(typeof(LaserFather).FullName);
			SprintDisabledTypeNames.Add(typeof(EnterEngiLaserCutter).FullName);
			SprintDisabledTypeNames.Add(typeof(EngiLaserCutter).FullName);
			SprintDisabledTypeNames.Add(typeof(EngiLaserCutter2).FullName);
			SprintDisabledTypeNames.Add(typeof(EngiLaserCutter3).FullName);
			SprintDisabledTypeNames.Add(typeof(BladeCombo).FullName);
			SprintDisabledTypeNames.Add(typeof(BladeJumpStrike).FullName);
			SprintDisabledTypeNames.Add(typeof(BladeSprintStrike).FullName);
			SprintDisabledTypeNames.Remove(typeof(Slash).FullName);
			SprintDisabledTypeNames.Remove(typeof(Bite).FullName);
			SprintDelayTypeNameValuePairs[typeof(ToolbotDualWieldStart).FullName] = "duration";
			SprintDelayTypeNameValuePairs[typeof(Slash).FullName] = "durationBeforeInterruptable";
			SprintDelayTypeNameValuePairs[typeof(Bite).FullName] = "durationBeforeInterruptable";
			timer.Stop();
			Log.Info($"UpdateFromSkillCatalog: {timer.Elapsed.TotalMilliseconds}ms");
		}

		[SystemInitializer(new Type[] { typeof(BodyCatalog) })]
		internal static void UpdateFromBodyCatalog()
		{
			UpdateDisabledBodies(null, null);
			PluginConfig.DisableSprintingCustomList.SettingChanged += UpdateDisabledBodies;
		}

		internal static IEnumerator EntityStateCatalog_Init(orig_Init orig)
		{
			yield return orig.Invoke();
			timer.Restart();
			for (int i = 0; i < EntityStateCatalog.stateIndexToType.Length; i++)
			{
				TypeFullNameToStateIndex[EntityStateCatalog.stateIndexToType[i].FullName] = (EntityStateIndex)i;
			}
			timer.Stop();
			Log.Info($"EntityStateCatalog_Init: {timer.Elapsed.TotalMilliseconds}ms");
			UpdateDisabledStates(null, null);
			UpdateDelayStates(null, null);
			PluginConfig.DisableSprintingCustomList.SettingChanged += UpdateDisabledStates;
			PluginConfig.DisableSprintingCustomList2.SettingChanged += UpdateDelayStates;
		}

		internal static void UpdateDisabledBodies(object _, EventArgs __)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Invalid comparison between Unknown and I4
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			timer.Restart();
			DisabledBodies.Clear();
			SprintDisabledBodyNames.Add("JohnnyBody");
			SprintDisabledBodyNames.Add("PantheraBody");
			SprintDisabledBodyNames.Add("RA2ChronoBody");
			List<string> list = SprintDisabledBodyNames.ToList();
			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.Info(item + " added to the disabled bodies list.");
				}
				else
				{
					Log.Info(item + " is not a valid body, skipping...");
				}
			}
			timer.Stop();
			Log.Info($"UpdateDisabledBodies: {timer.Elapsed.TotalMilliseconds}ms");
		}

		internal static void UpdateDisabledStates(object _, EventArgs __)
		{
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			timer.Restart();
			EntityStateDisabledSet.Clear();
			HashSet<string> sprintDisabledTypeNames = SprintDisabledTypeNames;
			List<string> list = new List<string>(16 + 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.Add("DanteMod.SkillStates.Dante.LockOn");
			list.Add("DanteMod.SkillStates.Dante.Swap");
			list.Add("HunkMod.SkillStates.Hunk.SteadyAim");
			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.Debug(item + " added to the custom entity state list.");
				}
				else
				{
					Log.Info(item + " is not a valid entity state, skipping...");
				}
			}
			timer.Stop();
			Log.Info($"UpdateDisabledStates: {timer.Elapsed.TotalMilliseconds}ms");
		}

		internal static void UpdateDelayStates(object _, EventArgs __)
		{
			timer.Restart();
			SprintStateDelayTable.Clear();
			foreach (KeyValuePair<string, string> sprintDelayTypeNameValuePair in SprintDelayTypeNameValuePairs)
			{
				AddSprintDelay(sprintDelayTypeNameValuePair.Key, sprintDelayTypeNameValuePair.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]);
					}
				}
			}
			timer.Stop();
			Log.Info($"UpdateDelayStates: {timer.Elapsed.TotalMilliseconds}ms");
		}

		public 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.Warning("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.Debug($"Type: {stateType.FullName} | Value: {result} | Has been added to the custom entity state list.");
				SprintStateDelayTable[value2] = result;
			}
			else
			{
				AddFieldInfo(stateType, value2, value);
			}
		}

		public 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.Field(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 (SprintStateDelayTable.ContainsKey(index))
			{
				Log.Warning("\r\nOverwriting duplicate entry\r\n" + T.FullName + " : " + fieldInfo.Name + "\r\nold " + (SprintStateDelayTable[index]?.ToString() ?? "NULL") + " | new " + fieldInfo.Name);
			}
			else
			{
				Log.Debug("Type: " + T.FullName + " | Field: " + name + " | Has been added to the custom entity state list.");
			}
			SprintStateDelayTable[index] = fieldInfo;
		}
	}
}