Decompiled source of AutoSprint v1.3.5

AutoSprint.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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 HarmonyLib;
using IL.RoR2;
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.Skills;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AutoSprint")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ecdaf50178ac9cc89ccd66555275dab3ce030256")]
[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
{
	public class AutoSprintManager
	{
		public static readonly Hashtable animDelayList = new Hashtable();

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

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

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

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

		public static bool enableSprintOverride = true;

		public CharacterBody cachedBody;

		public EntityStateMachine[] cachedStateMachines;

		public float timer;

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

		public static AutoSprintManager Instance { get; private set; }

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

		private AutoSprintManager()
		{
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)delegate
			{
				UpdateBodyDisabledList(null, null);
				PluginConfig.DisableSprintingCustomList.SettingChanged += Instance.UpdateBodyDisabledList;
			});
		}

		public static void OnLoad()
		{
			Instance.UpdateSprintDisabledList(null, null);
			Instance.UpdateSprintDisabledList2(null, null);
			PluginConfig.DisableSprintingCustomList.SettingChanged += Instance.UpdateSprintDisabledList;
			PluginConfig.DisableSprintingCustomList2.SettingChanged += Instance.UpdateSprintDisabledList2;
		}

		public void AddItem(string typeFullName, string fieldName)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (typeFullNameToStateIndex.TryGetValue(typeFullName, out var value))
			{
				Type stateType = EntityStateCatalog.GetStateType(value);
				if (stateType != null)
				{
					AddItem(stateType, fieldName);
					return;
				}
				Log.Error("Type: " + typeFullName + " | Field: " + fieldName + " | The state exists in the EntityStateCatalog but the type is null.");
			}
			else
			{
				Log.Error("Type: " + typeFullName + " | Field: " + fieldName + " | The type does not exist in the EntityStateCatalog.");
			}
		}

		public void AddItem<T>(string name)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
			if (typeFullNameToStateIndex.TryGetValue(typeof(T).FullName, out var value))
			{
				if (float.TryParse((name ?? "0").Replace(" ", string.Empty), out var result))
				{
					Log.Message($"Type: {typeof(T).FullName} | Field: {result} | Has been added to the custom entity state list.");
					animDelayList[value] = result;
					return;
				}
				FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(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" + typeof(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" + typeof(T).FullName + " : " + fieldInfo.Name);
					return;
				}
				if (animDelayList.ContainsKey(value))
				{
					Log.Warning("\r\nOverwriting duplicate entry\r\n" + typeof(T).FullName + " : " + fieldInfo.Name + "\r\nold " + (animDelayList[value]?.ToString() ?? "NULL") + " | new " + fieldInfo.Name);
				}
				else
				{
					Log.Message("Type: " + typeof(T).FullName + " | Field: " + name + " | Has been added to the custom entity state list.");
				}
				animDelayList[value] = fieldInfo;
			}
			else
			{
				Log.Error("\r\nType name could not be found in the entityStateCatalog\r\n" + typeof(T).FullName + " : " + name);
			}
		}

		public void AddItem(Type T, string name)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			if (typeFullNameToStateIndex.TryGetValue(T.FullName, out var value))
			{
				if (float.TryParse((name ?? "0").Replace(" ", string.Empty), out var result))
				{
					Log.Message($"Type: {T.FullName} | Field: {result} | Has been added to the custom entity state list.");
					animDelayList[value] = result;
					return;
				}
				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 (animDelayList.ContainsKey(value))
				{
					Log.Warning("\r\nOverwriting duplicate entry\r\n" + T.FullName + " : " + fieldInfo.Name + "\r\nold " + (animDelayList[value]?.ToString() ?? "NULL") + " | new " + fieldInfo.Name);
				}
				else
				{
					Log.Message("Type: " + T.FullName + " | Field: " + name + " | Has been added to the custom entity state list.");
				}
				animDelayList[value] = fieldInfo;
			}
			else
			{
				Log.Error("\r\nType name could not be found in the entityStateCatalog\r\n" + T.FullName + " : " + name);
			}
		}

		private void UpdateSprintDisabledList2(object _, EventArgs __)
		{
			animDelayList.Clear();
			AddItem<ToolbotDualWieldStart>("baseDuration");
			AddItem<Slash>("durationBeforeInterruptable");
			AddItem<Bite>("durationBeforeInterruptable");
			string[] array = PluginConfig.DisableSprintingCustomList2.Value.Replace(" ", string.Empty).Split(')');
			foreach (string text in array)
			{
				if (!string.IsNullOrEmpty(text))
				{
					string[] array2 = text.Replace("(", string.Empty).Split(',');
					if (array2.Length == 2)
					{
						AddItem(array2[0], array2[1]);
					}
					else
					{
						Log.Warning(text + " is not in the valid (key, value) pair format, skipping...");
					}
				}
			}
		}

		private void UpdateBodyDisabledList(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...");
				}
			}
		}

		private void UpdateSprintDisabledList(object _, EventArgs __)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			sprintDisabledSet.Clear();
			foreach (string sprintDisabled in sprintDisabledList)
			{
				if (typeFullNameToStateIndex.TryGetValue(sprintDisabled, out var value))
				{
					sprintDisabledSet.Add(value);
					Log.Debug(sprintDisabled + " added to the custom entity state list.");
				}
				else
				{
					Log.Warning(sprintDisabled + " is not a valid entity state, skipping...");
				}
			}
			List<string> list = new List<string>(12)
			{
				"LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.EnterSnipe", "LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.Snipe", "LeeHyperrealMod.SkillStates.LeeHyperreal.Secondary.ExitSnipe", "PaladinMod.States.Spell.ChannelCruelSun", "PaladinMod.States.Spell.ChannelHealZone", "PaladinMod.States.Spell.ChannelSmallHeal", "PaladinMod.States.Spell.ChannelTorpor", "PaladinMod.States.Spell.ChannelWarcry", "PaladinMod.States.Spell.CastCruelSun", "PaladinMod.States.Spell.CastChanneledWarcry",
				"PaladinMod.States.Spell.CastChanneledTorpor", "PaladinMod.States.Spell.CastChanneledHealZone"
			};
			string[] array = PluginConfig.DisableSprintingCustomList.Value.Replace(" ", string.Empty).Split(',');
			foreach (string text in array)
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					list.Add(text);
				}
			}
			foreach (string item in list)
			{
				if (typeFullNameToStateIndex.TryGetValue(item, out var value2))
				{
					sprintDisabledSet.Add(value2);
					Log.Info(item + " added to the custom entity state list.");
				}
				else
				{
					Log.Warning(item + " is not a valid entity state, skipping...");
				}
			}
		}

		public static void Sprint(PlayerCharacterMasterController pcmc, Player inputPlayer, bool isSprinting)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (Instance != null && !disabledBodies.Contains(pcmc.body.bodyIndex))
			{
				if (PluginConfig.HoldSprintToWalk.Value)
				{
					enableSprintOverride = !inputPlayer.GetButton("Sprint");
				}
				else if (pcmc.sprintInputPressReceived)
				{
					enableSprintOverride = !enableSprintOverride;
				}
				if (enableSprintOverride && !isSprinting)
				{
					Instance.HandleSprint(pcmc);
				}
				else
				{
					Instance.timer = 0f;
				}
			}
		}

		private void HandleSprint(PlayerCharacterMasterController pcmc)
		{
			float sprintDelayTime;
			bool flag = CanSprintBeEnabled(pcmc.body, out sprintDelayTime);
			if (!flag)
			{
				timer = sprintDelayTime;
			}
			if (timer > 0f)
			{
				timer -= Time.fixedDeltaTime;
			}
			else
			{
				pcmc.sprintInputPressReceived = pcmc.sprintInputPressReceived || flag;
			}
		}

		private bool CanSprintBeEnabled(CharacterBody targetBody, out float sprintDelayTime)
		{
			//IL_0016: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			sprintDelayTime = 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 (Object.op_Implicit((Object)(object)val) && val.state != null)
				{
					EntityStateIndex stateIndex = EntityStateCatalog.GetStateIndex(((object)val.state).GetType());
					if (sprintDisabledSet.Contains(stateIndex))
					{
						sprintDelayTime = Mathf.Max(sprintDelayTime, AnimationExitDelay);
					}
					else if (animDelayList.ContainsKey(stateIndex))
					{
						float duration = GetDuration(animDelayList[stateIndex], val.state);
						sprintDelayTime = Mathf.Max(sprintDelayTime, duration - val.state.fixedAge + AnimationExitDelay);
					}
				}
			}
			return sprintDelayTime == 0f;
		}

		private float GetDuration(object field, EntityState state)
		{
			if (field is float)
			{
				return (float)field;
			}
			if (field is FieldInfo fieldInfo && fieldInfo.FieldType == typeof(float) && fieldInfo.DeclaringType.IsAssignableFrom(((object)state).GetType()))
			{
				return (float)fieldInfo.GetValue(state);
			}
			Log.Error("Field is invalid, default is ~0.1s delay. " + ((object)state).GetType().FullName);
			return 0f;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.score.AutoSprint", "AutoSprint", "1.3.5")]
	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.3.5";

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

		public static AutoSprintPlugin Instance { get; private set; }

		public void Awake()
		{
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			PluginConfig.Init(((BaseUnityPlugin)this).Config);
			AutoSprintManager.Init();
			Hooks.Init();
		}
	}
	internal class Hooks
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static EventHandler <0>__EnableDebugMode_SettingChanged;

			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 hook_OnEnter <5>__EntityState_OnEnter;

			public static Action<PlayerCharacterMasterController, Player, bool> <6>__Sprint;
		}

		private static bool hooksEnabled;

		public static Hooks Instance { get; private set; }

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

		private Hooks()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			EnableDebugMode_SettingChanged(null, null);
			PluginConfig.EnableDebugMode.SettingChanged += EnableDebugMode_SettingChanged;
			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;
		}

		private static void EnableDebugMode_SettingChanged(object sender, EventArgs e)
		{
			//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)
			//IL_005c: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if (PluginConfig.EnableDebugMode.Value)
			{
				if (!hooksEnabled)
				{
					object obj = <>O.<5>__EntityState_OnEnter;
					if (obj == null)
					{
						hook_OnEnter val = EntityState_OnEnter;
						<>O.<5>__EntityState_OnEnter = val;
						obj = (object)val;
					}
					EntityState.OnEnter += (hook_OnEnter)obj;
					hooksEnabled = true;
				}
			}
			else if (hooksEnabled)
			{
				object obj2 = <>O.<5>__EntityState_OnEnter;
				if (obj2 == null)
				{
					hook_OnEnter val2 = EntityState_OnEnter;
					<>O.<5>__EntityState_OnEnter = val2;
					obj2 = (object)val2;
				}
				EntityState.OnEnter -= (hook_OnEnter)obj2;
				hooksEnabled = false;
			}
		}

		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_025d: 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.Sprint);
			}
			else
			{
				Log.Error("Autosprint IL hook1 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.EmitDelegate<Func<bool>>((Func<bool>)(() => PluginConfig.EnableOmniSprint.Value));
				c.Emit(OpCodes.Brtrue, (object)label);
			}
			else
			{
				Log.Error("Autosprint IL hook 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("Crosshair IL hook failed");
			}
		}

		private static IEnumerator EntityStateCatalog_Init(orig_Init orig)
		{
			yield return orig.Invoke();
			for (int i = 0; i < EntityStateCatalog.stateIndexToType.Length; i++)
			{
				AutoSprintManager.typeFullNameToStateIndex[EntityStateCatalog.stateIndexToType[i].FullName] = (EntityStateIndex)i;
			}
			yield return null;
			AutoSprintManager.OnLoad();
		}

		private static void SkillCatalog_Init(orig_Init orig)
		{
			orig.Invoke();
			foreach (SkillDef allSkillDef in SkillCatalog.allSkillDefs)
			{
				if (Object.op_Implicit((Object)(object)allSkillDef) && !allSkillDef.forceSprintDuringState && (object)((SerializableEntityStateType)(ref allSkillDef.activationState)).stateType != null && !(((SerializableEntityStateType)(ref allSkillDef.activationState)).stateType == typeof(Idle)))
				{
					Type stateType = ((SerializableEntityStateType)(ref allSkillDef.activationState)).stateType;
					if (allSkillDef.canceledFromSprinting)
					{
						AutoSprintManager.sprintDisabledList.Add(stateType.FullName);
					}
				}
			}
			AutoSprintManager.sprintDisabledList.Add(typeof(FireNailgun).FullName);
			AutoSprintManager.sprintDisabledList.Add(typeof(FireCorruptHandBeam).FullName);
			AutoSprintManager.sprintDisabledList.Add(typeof(ActiveScopeHeavy).FullName);
			AutoSprintManager.sprintDisabledList.Add(typeof(ActiveScopeLight).FullName);
			AutoSprintManager.sprintDisabledList.Add(typeof(WindUpScopeHeavy).FullName);
			AutoSprintManager.sprintDisabledList.Add(typeof(WindUpScopeLight).FullName);
			AutoSprintManager.sprintDisabledList.Remove(typeof(LaserFather).FullName);
			AutoSprintManager.sprintDisabledList.Remove(typeof(Slash).FullName);
			AutoSprintManager.sprintDisabledList.Remove(typeof(Bite).FullName);
		}
	}
	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 ConfigFile myConfig;

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

		public static ConfigEntry<bool> DisableSprintingCrosshair { 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)
		{
			myConfig = cfg;
			HoldSprintToWalk = 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 = BindOption("General", "Disable Sprinting Crosshair", defaultValue: true, "Disables the special sprinting chevron crosshair.");
			EnableOmniSprint = BindOption("General", "Enable OmniSprint", defaultValue: false, "Allows sprinting in all directions. This is generally considered cheating, use with discretion.");
			DelayTicks = BindOptionSlider("General", "DelayTicks", 5, "How long to wait before sprinting. A tick == 60hz == 16ms", 0f, 60f);
			EnableDebugMode = BindOption("General", "Enable Debug Mode", defaultValue: false, "Prints every entity state that your character changes to.");
			DisabledBodies = BindOption("Advanced", "Disable Body", "", "Custom body name list, has to match body catalog name.");
			DisableSprintingCustomList = BindOption("Advanced", "Disable Sprint Custom List", "", "Custom EntityState list for when broken things break, separated by commas.\r\nUse console (Ctrl Alt ~) and enter dump_state to find this info (last couple lines).\r\nMany skills have multiple states, so it may help to pause while doing this.\r\n\r\nExample -> PaladinMod.States.Spell.ChannelCruelSun");
			DisableSprintingCustomList2 = 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()
		{
			ModSettingsManager.SetModDescription("AutoSprint, as God intended.");
		}

		public static ConfigEntry<T> BindOption<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			bool flag = ((defaultValue is int || defaultValue is float) ? true : false);
			if (flag && !typeof(T).IsEnum)
			{
				return 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> obj = myConfig.Bind<T>(section, name, defaultValue, new ConfigDescription(description, val, Array.Empty<object>()));
			TryRegisterOption<T>(obj, restartRequired);
			return obj;
		}

		public static ConfigEntry<T> BindOptionSlider<T>(string section, string name, T defaultValue, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			bool flag = ((defaultValue is int || defaultValue is float) ? true : false);
			if (!flag || typeof(T).IsEnum)
			{
				return 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> obj = myConfig.Bind<T>(section, name, defaultValue, new ConfigDescription(description, val2, Array.Empty<object>()));
			TryRegisterOptionSlider<T>(obj, min, max, restartRequired);
			return obj;
		}

		public static ConfigEntry<T> BindOptionSteppedSlider<T>(string section, string name, T defaultValue, float increment = 1f, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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> obj = myConfig.Bind<T>(section, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
			TryRegisterOptionSteppedSlider<T>(obj, increment, min, max, restartRequired);
			return obj;
		}

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

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

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