Decompiled source of DoubleTapToggleSprint v1.0.0

DoubleTapToggleSprint.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API;
using GTFO.API.Utilities;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DoubleTapToggleSprint")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b0b5cc39bb7443f9b99b7239954b29cb4cc8113f")]
[assembly: AssemblyProduct("DoubleTapToggleSprint")]
[assembly: AssemblyTitle("DoubleTapToggleSprint")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace DoubleTapToggleSprint
{
	internal static class Configuration
	{
		private static readonly ConfigEntry<float> _toggleBufferTime;

		private static readonly ConfigEntry<bool> _requireForward;

		private static readonly ConfigFile _configFile;

		public static float ToggleBufferTime => _toggleBufferTime.Value;

		public static bool RequireForward => _requireForward.Value;

		static Configuration()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			_configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "DoubleTapToggleSprint.cfg"), true);
			string text = "General Settings";
			string text2 = "Requires a forward input for sprint to be toggled. If the forward input is released, the toggle is disabled.";
			_requireForward = _configFile.Bind<bool>(text, "Require Forward Input", true, text2);
			text2 = "Maximum allowed time between sprint inputs to toggle sprint.";
			_toggleBufferTime = _configFile.Bind<float>(text, "Toggle Buffer Time", 0.3f, text2);
		}

		internal static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			LiveEdit.CreateListener(Paths.ConfigPath, "DoubleTapToggleSprint.cfg", false).FileChanged += new LiveEditEventHandler(OnFileChanged);
		}

		private static void OnFileChanged(LiveEditEventArgs _)
		{
			_configFile.Reload();
		}
	}
	[BepInPlugin("Dinorush.DoubleTapToggleSprint", "DoubleTapToggleSprint", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "DoubleTapToggleSprint";

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			((BasePlugin)this).Log.LogMessage((object)"Loading DoubleTapToggleSprint");
			new Harmony("DoubleTapToggleSprint").PatchAll();
			Configuration.Init();
			AssetAPI.OnStartupAssetsLoaded += OnStartupAssetsLoaded;
			((BasePlugin)this).Log.LogMessage((object)"Loaded DoubleTapToggleSprint");
		}

		private void OnStartupAssetsLoaded()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			ClassInjector.RegisterTypeInIl2Cpp<SprintCheckHandler>();
			GameObject val = new GameObject("DoubleTapToggleSprint");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<SprintCheckHandler>();
		}
	}
	internal sealed class SprintCheckHandler : MonoBehaviour
	{
		private PlayerAgent? _cachedPlayer;

		private PlayerLocomotion? _cachedLocomotion;

		private float _lastTapTime;

		public static SprintCheckHandler Instance { get; private set; }

		public static bool ToggleSprint { get; private set; }

		public SprintCheckHandler(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cachedPlayer == (Object)null)
			{
				_cachedPlayer = PlayerManager.GetLocalPlayerAgent();
				if ((Object)(object)_cachedPlayer == (Object)null)
				{
					return;
				}
				ToggleSprint = false;
				_cachedLocomotion = _cachedPlayer.Locomotion;
			}
			if (Configuration.RequireForward && !_cachedLocomotion.InputIsForwardEnoughForRun())
			{
				ToggleSprint = false;
			}
			else
			{
				if (!InputMapper.GetButtonDown.Invoke((InputAction)9, _cachedPlayer.InputFilter))
				{
					return;
				}
				if (ToggleSprint)
				{
					ToggleSprint = false;
					return;
				}
				if (Clock.Time - _lastTapTime < Configuration.ToggleBufferTime)
				{
					ToggleSprint = true;
				}
				_lastTapTime = Clock.Time;
			}
		}

		public static void StopSprint()
		{
			ToggleSprint = false;
		}
	}
}
namespace DoubleTapToggleSprint.Utils
{
	internal static class DinoLogger
	{
		private static ManualLogSource logger = Logger.CreateLogSource("DoubleTapToggleSprint");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)32, (object)str);
			}
		}
	}
}
namespace DoubleTapToggleSprint.SprintPatches
{
	[HarmonyPatch]
	internal static class SprintPatch
	{
		[HarmonyPatch(typeof(PlayerLocomotion), "RunInput")]
		[HarmonyPrefix]
		private static bool AllowToggle(ref bool __result)
		{
			if (SprintCheckHandler.ToggleSprint)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(PLOC_Crouch), "Enter")]
		[HarmonyPostfix]
		private static void StopSprinting()
		{
			SprintCheckHandler.StopSprint();
		}
	}
}