Decompiled source of Lean Fatigue v0.1.3

LeanFatigue.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using ComputerysModdingUtilities;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModMenu.Api;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: StraftatMod(true)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Koki")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bf0f6e422af1bd463e9c06f1442fd5849eee698f")]
[assembly: AssemblyProduct("LeanFatigue")]
[assembly: AssemblyTitle("LeanFatigue")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[HarmonyPatch(typeof(FirstPersonController), "CameraLean")]
internal class LeanBlock
{
	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<float> LeanResetTolerance;

	private static bool _leanAttempted = false;

	private static bool _allowLean = true;

	private static bool Prepare()
	{
		return Enabled.Value;
	}

	private static void Prefix(FirstPersonController __instance, ref Quaternion rot)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//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_002e: Unknown result type (might be due to invalid IL or missing references)
		if (((Quaternion)(ref rot)).eulerAngles.z != 0f)
		{
			if (!_leanAttempted)
			{
				_leanAttempted = true;
				Quaternion localRotation = __instance.leanCamera.localRotation;
				float z = ((Quaternion)(ref localRotation)).eulerAngles.z;
				if ((z > 300f && z < 360f - LeanResetTolerance.Value) || (z < 300f && z > LeanResetTolerance.Value))
				{
					_allowLean = false;
				}
				else
				{
					_allowLean = true;
				}
			}
		}
		else
		{
			_leanAttempted = false;
		}
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		FieldInfo fieldInfo = AccessTools.Field(typeof(LeanBlock), "_allowLean");
		Label label = default(Label);
		return new CodeMatcher(instructions, generator).End().MatchBack(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((OpCode?)OpCodes.Ret, (object)null, (string)null)
		}).MatchBack(true, (CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch((OpCode?)OpCodes.Ret, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null)
		})
			.CreateLabel(ref label)
			.Start()
			.Insert((CodeInstruction[])(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo),
				new CodeInstruction(OpCodes.Brfalse, (object)label)
			})
			.InstructionEnumeration();
	}
}
[HarmonyPatch(typeof(FirstPersonController), "CameraLean")]
internal class LeanSlow
{
	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<float> FatiguePerLean;

	internal static ConfigEntry<float> MinLeanSpeed;

	internal static ConfigEntry<float> LeanRecoverPerSecond;

	private static readonly float DefaultLeanSpeed = 8f;

	private static float _lastLeanTime = 0f;

	private static bool _inLean = false;

	private static bool Prepare()
	{
		if (Object.op_Implicit((Object)(object)FirstPersonController.instance))
		{
			FirstPersonController.instance.leanSpeed = DefaultLeanSpeed;
		}
		return Enabled.Value;
	}

	private static void Postfix(ref Quaternion rot)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		if (((Quaternion)(ref rot)).eulerAngles.z != 0f)
		{
			if (!_inLean)
			{
				_inLean = true;
				float num = Time.time - _lastLeanTime;
				_lastLeanTime = Time.time;
				float num2 = FatiguePerLean.Value - num * LeanRecoverPerSecond.Value;
				FirstPersonController.instance.leanSpeed = Math.Clamp(FirstPersonController.instance.leanSpeed - num2, MinLeanSpeed.Value, DefaultLeanSpeed);
			}
		}
		else
		{
			_inLean = false;
		}
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.koki.leanfatigue", "Lean Fatigue", "0.1.3")]
public class LFPlugin : BaseUnityPlugin
{
	internal static LFPlugin Instance;

	private Harmony _harmony = new Harmony("com.koki.leanfatigue");

	private ConfigEntry<bool> _enableMod;

	private void Awake()
	{
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Expected O, but got Unknown
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Expected O, but got Unknown
		Instance = this;
		((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
		_enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Mod", true, (ConfigDescription)null);
		LeanSlow.Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("OPTION 1: Slow Lean", "Slow Lean", false, "Make leaning slower and slower the more often it is done.");
		LeanSlow.FatiguePerLean = ((BaseUnityPlugin)this).Config.Bind<float>("OPTION 1: Slow Lean", "Slow amount", 6f, new ConfigDescription("Lean speed has a vanilla value of 8. This amount is removed from your lean speed AFTER each lean.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 8f), Array.Empty<object>()));
		LeanSlow.LeanRecoverPerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("OPTION 1: Slow Lean", "Lean Recovery Rate", 6f, new ConfigDescription("How much lean speed is regained per second. Speed is regained continuously (as opposed to all at once every second), so if you have a regain rate of 6 speed/second and you lean 2 times per second, you'll only regain 3 speed in between each lean. \n\n1With the default slow amount of 6, this means that after your first lean, you will regain your full lean speed over the course of 1 full second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 8f), Array.Empty<object>()));
		LeanSlow.MinLeanSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("OPTION 1: Slow Lean", "Min lean speed", 2f, new ConfigDescription("Use this to prevent leaning from becoming too slow and freezing when spammed", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 8f), Array.Empty<object>()));
		LeanBlock.Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("OPTION 2: Block Lean", "Block Lean", false, "Prevent doing a new lean until the old lean has finished");
		LeanBlock.LeanResetTolerance = ((BaseUnityPlugin)this).Config.Bind<float>("OPTION 2: Block Lean", "Block Tolerance", 0.5f, new ConfigDescription("When you lean, your lean angle effectively moves between 0 and 30. The default value of 0.5 means that you can't lean again until your lean angle falls below 0.5.", (AcceptableValueBase)null, Array.Empty<object>()));
		((BaseUnityPlugin)this).Config.SettingChanged += ApplyConfig;
		if (_enableMod.Value)
		{
			_harmony.PatchAll();
		}
		if (Chainloader.PluginInfos.ContainsKey("kestrel.straftat.modmenu"))
		{
			ModMenuCompat.Start();
		}
	}

	private void ApplyConfig(object sender, EventArgs e)
	{
		_harmony.UnpatchSelf();
		if (_enableMod.Value)
		{
			_harmony.PatchAll();
		}
	}
}
internal static class ModMenuCompat
{
	internal static void Start()
	{
		ModMenuCustomisation.SetPluginDescription("This mod attempts to balance lean spam. THIS IS A TESTING VERSION OF THE MOD. Try both methods to block spam and see which you prefer.");
		ModMenuCustomisation.RegisterContentBuilder((Action<OptionListContext>)ConfigBuilder);
	}

	private static void ConfigBuilder(OptionListContext c)
	{
	}
}
namespace LeanFatigue
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.koki.leanfatigue";

		public const string PLUGIN_NAME = "Lean Fatigue";

		public const string PLUGIN_VERSION = "0.1.3";
	}
}