Decompiled source of EaglesEye v3.0.1

plugins/com.github.misterbubb.EaglesEye.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 UnityEngine;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.misterbubb.EaglesEye")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("3.0.1.0")]
[assembly: AssemblyInformationalVersion("3.0.1+e55eaee87419752dcb43ed9861bbe859f205f04c")]
[assembly: AssemblyProduct("com.github.misterbubb.EaglesEye")]
[assembly: AssemblyTitle("EaglesEye")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.0.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace MrBub.EaglesEye
{
	[BepInPlugin("mrbub.eagleseye", "EaglesEye", "3.0.1")]
	public class EaglesEyePlugin : BaseUnityPlugin
	{
		public const string GUID = "mrbub.eagleseye";

		public const string ModName = "EaglesEye";

		public const string Version = "3.0.1";

		private readonly Harmony _harmony = new Harmony("mrbub.eagleseye");

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"EaglesEye: Initializing...");
			EaglesEyeFovPatch.Initialize(((BaseUnityPlugin)this).Config, ((BaseUnityPlugin)this).Logger);
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"EaglesEye: Loaded successfully.");
		}

		private void OnDestroy()
		{
			_harmony.UnpatchSelf();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"EaglesEye: Unloaded.");
		}
	}
	[HarmonyPatch(typeof(MainCameraMovement), "GetFov")]
	public class EaglesEyeFovPatch
	{
		private static float currentFov;

		private static float targetZoomFov;

		private static bool isZooming;

		private static bool initialized;

		private static ConfigEntry<float> minZoomFov;

		private static ConfigEntry<float> scrollSpeed;

		private static ConfigEntry<KeyCode> holdKey;

		private static ConfigEntry<bool> showOverlay;

		private static ManualLogSource Logger;

		public static void Initialize(ConfigFile config, ManualLogSource logger)
		{
			Logger = logger;
			minZoomFov = config.Bind<float>("Zoom", "MinZoomFOV", 10f, "Minimum FOV when fully zoomed in.");
			scrollSpeed = config.Bind<float>("Zoom", "ScrollSpeed", 2f, "How fast to zoom with scroll wheel.");
			holdKey = config.Bind<KeyCode>("Zoom", "HoldKey", (KeyCode)99, "Key to hold for zoom.");
			showOverlay = config.Bind<bool>("Zoom", "ShowBinocularOverlay", true, "Show binocular overlay while zooming.");
		}

		private static bool Prefix(ref float __result, MainCameraMovement __instance)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			if (minZoomFov == null || scrollSpeed == null || holdKey == null || showOverlay == null)
			{
				ManualLogSource logger = Logger;
				if (logger != null)
				{
					logger.LogWarning((object)"EaglesEye: Config not initialized, using default FOV behavior.");
				}
				return true;
			}
			if ((Object)(object)GameHandler.Instance == (Object)null)
			{
				return true;
			}
			FovSetting setting = GameHandler.Instance.SettingsHandler.GetSetting<FovSetting>();
			if (setting == null)
			{
				ManualLogSource logger2 = Logger;
				if (logger2 != null)
				{
					logger2.LogError((object)"EaglesEye: Could not find FovSetting! Using fallback FOV 70.");
				}
				__result = 70f;
				return false;
			}
			float num = ((FloatSetting)setting).Value;
			if (num < 60f)
			{
				num = 70f;
			}
			if ((Object)(object)Character.localCharacter == (Object)null)
			{
				__result = num;
				return false;
			}
			ExtraFovSetting setting2 = GameHandler.Instance.SettingsHandler.GetSetting<ExtraFovSetting>();
			float num2 = ((Character.localCharacter.data.isClimbing && setting2 != null) ? ((FloatSetting)setting2).Value : 0f);
			float num3 = num + num2;
			if (!initialized)
			{
				currentFov = num3;
				initialized = true;
			}
			if (Input.GetKey(holdKey.Value))
			{
				if (!isZooming)
				{
					targetZoomFov = num3 / 3f;
					isZooming = true;
				}
				targetZoomFov -= Input.mouseScrollDelta.y * scrollSpeed.Value;
				targetZoomFov = Mathf.Clamp(targetZoomFov, minZoomFov.Value, num3);
				currentFov = Mathf.Lerp(currentFov, targetZoomFov, Time.deltaTime * 5f);
				if (showOverlay.Value && (Object)(object)GUIManager.instance != (Object)null)
				{
					GUIManager.instance.EnableBinocularOverlay();
				}
			}
			else
			{
				if (isZooming)
				{
					isZooming = false;
				}
				currentFov = Mathf.Lerp(currentFov, num3, Time.deltaTime * 5f);
			}
			__result = currentFov;
			return false;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}