Decompiled source of Sprinterviews v1.0.0

bonkposting.Sprinterviews.dll

Decompiled 2 months ago
using System;
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.Configuration;
using BepInEx.Logging;
using IL;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using On;
using Sprinterviews.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("bonkposting.Sprinterviews")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Sprinterviews")]
[assembly: AssemblyTitle("bonkposting.Sprinterviews")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Sprinterviews
{
	public class Config
	{
		public static ConfigFile Configurations = new ConfigFile(Paths.ConfigPath + "\\bonkposting.Sprinterviews.cfg", true);

		public static ConfigEntry<float> SprintMultiplier;

		public static ConfigEntry<float> MaxStamina;

		public static ConfigEntry<float> StaminaRegen;

		public static ConfigEntry<float> StaminaReactivationThreshold;

		public static ConfigEntry<bool> CanSprintAnyDirection;

		public void LoadFile()
		{
			SprintMultiplier = Configurations.Bind<float>("General", "SprintSpeed", 2f, "Sets the speed bonus sprinting gives you.");
			MaxStamina = Configurations.Bind<float>("General", "MaxStamina", 10f, "Sets the maximum amount of stamina you have.");
			StaminaRegen = Configurations.Bind<float>("General", "StaminaRegen", 1f, "Sets the stamina regeneration speed. Number is a multiplier. Number can only be an positive number.");
			StaminaReactivationThreshold = Configurations.Bind<float>("General", "StaminaReactivationThreshold", 0.3f, "Percentage of stamina that must be reached before the player can sprint again.");
			CanSprintAnyDirection = Configurations.Bind<bool>("General", "CanSprintAnyDirection", false, "Sets whether the player can sprint in any direction or not.");
			SprinterviewsCore.Logger.LogInfo((object)$"SprintMultiplier: {SprintMultiplier.Value}");
			SprinterviewsCore.Logger.LogInfo((object)$"MaxStamina: {MaxStamina.Value}");
			SprinterviewsCore.Logger.LogInfo((object)$"StaminaRegen: {StaminaRegen.Value}");
			SprinterviewsCore.Logger.LogInfo((object)$"StaminaReactivationThreshold: {StaminaReactivationThreshold.Value}");
			SprinterviewsCore.Logger.LogInfo((object)$"CanSprintAnyDirection: {CanSprintAnyDirection.Value}");
			Configurations.Save();
		}
	}
	[ContentWarningPlugin("bonkposting.Sprinterviews", "1.0.0", false)]
	[BepInPlugin("bonkposting.Sprinterviews", "Sprinterviews", "1.0.0")]
	public class SprinterviewsCore : BaseUnityPlugin
	{
		public static Config ConfigFile = new Config();

		public static SprinterviewsCore Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			HookAll();
			Logger.LogInfo((object)"bonkposting.Sprinterviews v1.0.0 has loaded!");
			ConfigFile.LoadFile();
		}

		internal static void HookAll()
		{
			Logger.LogDebug((object)"Hooking...");
			SprintPatch.Init();
			Logger.LogDebug((object)"Finished Hooking!");
		}

		internal static void UnhookAll()
		{
			Logger.LogDebug((object)"Unhooking...");
			HookEndpointManager.RemoveAllOwnedBy((object)Assembly.GetExecutingAssembly());
			Logger.LogDebug((object)"Finished Unhooking!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "bonkposting.Sprinterviews";

		public const string PLUGIN_NAME = "Sprinterviews";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Sprinterviews.Patches
{
	public class SprintPatch
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Start <0>__On_PlayerController_Start;

			public static hook_Update <1>__On_PlayerController_Update;

			public static Manipulator <2>__PlayerController_Update;
		}

		internal static void Init()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			object obj = <>O.<0>__On_PlayerController_Start;
			if (obj == null)
			{
				hook_Start val = On_PlayerController_Start;
				<>O.<0>__On_PlayerController_Start = val;
				obj = (object)val;
			}
			PlayerController.Start += (hook_Start)obj;
			object obj2 = <>O.<1>__On_PlayerController_Update;
			if (obj2 == null)
			{
				hook_Update val2 = On_PlayerController_Update;
				<>O.<1>__On_PlayerController_Update = val2;
				obj2 = (object)val2;
			}
			PlayerController.Update += (hook_Update)obj2;
			object obj3 = <>O.<2>__PlayerController_Update;
			if (obj3 == null)
			{
				Manipulator val3 = PlayerController_Update;
				<>O.<2>__PlayerController_Update = val3;
				obj3 = (object)val3;
			}
			PlayerController.Update += (Manipulator)obj3;
		}

		private static void On_PlayerController_Start(orig_Start orig, PlayerController self)
		{
			orig.Invoke(self);
			self.maxStamina = Config.MaxStamina.Value;
			self.sprintMultiplier = Config.SprintMultiplier.Value;
			self.staminaReActivationThreshold = Config.StaminaReactivationThreshold.Value * Config.MaxStamina.Value;
			Player.localPlayer.data.currentStamina = Config.MaxStamina.Value;
		}

		private static void On_PlayerController_Update(orig_Update orig, PlayerController self)
		{
			orig.Invoke(self);
			self.staminaRegRate = Config.StaminaRegen.Value;
			self.canSprintInAnyDirection = Config.CanSprintAnyDirection.Value;
		}

		private static void PlayerController_Update(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext((MoveType)2, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerController>(x, "player"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<Player>(x, "data"),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<PlayerData>(x, "sinceSprint")
			});
			val.Index += 12;
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldfld, typeof(PlayerController).GetField("staminaRegRate"));
			val.Emit(OpCodes.Mul);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}