Decompiled source of DisableAimFov v1.0.0

BepInEx/plugins/DisableAimFov.dll

Decompiled 2 weeks 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Math;
using Pigeon.Movement;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("DisableAimFov")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0")]
[assembly: AssemblyProduct("DisableAimFov")]
[assembly: AssemblyTitle("DisableAimFov")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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;
		}
	}
}
[BepInPlugin("com.yourname.mycopunk.disableaimfov", "DisableAimFov", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class DisableAimFOVPlugin : BaseUnityPlugin
{
	internal static ConfigEntry<bool> disableFOVChange;

	private void Awake()
	{
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Expected O, but got Unknown
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Expected O, but got Unknown
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Expected O, but got Unknown
		disableFOVChange = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableFOVChange", true, "If true, disables FOV zoom changes when aiming.");
		AimPatches.defaultFOVGetter = AccessTools.PropertyGetter(typeof(PlayerLook), "DefaultFOV");
		_ = AimPatches.defaultFOVGetter == null;
		AimPatches.isAimingPLField = AccessTools.Field(typeof(PlayerLook), "isAiming");
		_ = AimPatches.isAimingPLField == null;
		AimPatches.fovField = AccessTools.Field(typeof(PlayerLook), "_fov");
		_ = AimPatches.fovField == null;
		AimPatches.aimFOVPLField = AccessTools.Field(typeof(PlayerLook), "aimFOV");
		_ = AimPatches.aimFOVPLField == null;
		AimPatches.aimDurationPLField = AccessTools.Field(typeof(PlayerLook), "aimDuration");
		_ = AimPatches.aimDurationPLField == null;
		AimPatches.aimStateChangeTimeField = AccessTools.Field(typeof(PlayerLook), "aimStateChangeTime");
		_ = AimPatches.aimStateChangeTimeField == null;
		Harmony val = new Harmony("com.yourname.mycopunk.disableaimfov");
		((BaseUnityPlugin)this).Logger.LogInfo((object)(val.Id + " loaded!"));
		MethodInfo methodInfo = AccessTools.Method(typeof(PlayerLook), "UpdateAiming", (Type[])null, (Type[])null);
		if (methodInfo != null)
		{
			val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(AimPatches), "UpdateAimingPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		MethodInfo methodInfo2 = AccessTools.Method(typeof(PlayerLook), "UpdateCameraFOV", (Type[])null, (Type[])null);
		if (methodInfo2 != null)
		{
			val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(AimPatches), "UpdateCameraFOVPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
}
internal class AimPatches
{
	internal static MethodInfo defaultFOVGetter;

	internal static FieldInfo isAimingPLField;

	internal static FieldInfo fovField;

	internal static FieldInfo aimFOVPLField;

	internal static FieldInfo aimDurationPLField;

	internal static FieldInfo aimStateChangeTimeField;

	public static bool UpdateAimingPrefix(PlayerLook __instance)
	{
		Logger.CreateLogSource("DisableAimFOV");
		if (DisableAimFOVPlugin.disableFOVChange.Value && isAimingPLField != null && aimStateChangeTimeField != null && aimDurationPLField != null && aimFOVPLField != null && defaultFOVGetter != null && fovField != null)
		{
			if ((bool)isAimingPLField.GetValue(__instance))
			{
				float num = (float)aimStateChangeTimeField.GetValue(__instance);
				num = Mathf.Min(num + Time.deltaTime / (float)aimDurationPLField.GetValue(__instance), 1f);
				aimStateChangeTimeField.SetValue(__instance, num);
				float num2 = (float)defaultFOVGetter.Invoke(__instance, null);
				aimFOVPLField.SetValue(__instance, num2);
				fovField.SetValue(__instance, Mathf.LerpUnclamped(num2, num2, EaseFunctions.EaseInOutCubic(num)));
			}
			else if ((float)aimStateChangeTimeField.GetValue(__instance) > 0f)
			{
				float num3 = (float)aimStateChangeTimeField.GetValue(__instance);
				num3 = Mathf.Max(num3 - Time.deltaTime / (float)aimDurationPLField.GetValue(__instance), 0f);
				aimStateChangeTimeField.SetValue(__instance, num3);
				float num4 = (float)defaultFOVGetter.Invoke(__instance, null);
				aimFOVPLField.SetValue(__instance, num4);
				fovField.SetValue(__instance, Mathf.LerpUnclamped(num4, num4, EaseFunctions.EaseInOutCubic(num3)));
			}
			return false;
		}
		return true;
	}

	public static void UpdateCameraFOVPostfix(PlayerLook __instance)
	{
		Logger.CreateLogSource("DisableAimFOV");
		if (DisableAimFOVPlugin.disableFOVChange.Value && isAimingPLField != null && fovField != null && defaultFOVGetter != null)
		{
			object value = isAimingPLField.GetValue(__instance);
			bool flag = default(bool);
			int num;
			if (value is bool)
			{
				flag = (bool)value;
				num = 1;
			}
			else
			{
				num = 0;
			}
			if (((uint)num & (flag ? 1u : 0u)) != 0)
			{
				fovField.SetValue(__instance, defaultFOVGetter.Invoke(__instance, null));
			}
		}
	}
}
namespace DisableAimFov
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DisableAimFov";

		public const string PLUGIN_NAME = "DisableAimFov";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}