Decompiled source of ZoomFix v1.0.2

ZoomFix.dll

Decompiled a day 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 Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ZoomFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+3f59e49532a19f3a8f82cf79ecdbd97501f8c285")]
[assembly: AssemblyProduct("ZoomFix")]
[assembly: AssemblyTitle("ZoomFix")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Foxyrobo/ZoomFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
}
internal static class Configuration
{
	private static ConfigEntry<KeyCode>? _zoomOut;

	private static ConfigEntry<KeyCode>? _zoomIn;

	private static ConfigEntry<KeyCode>? _resetZoom;

	private static ConfigEntry<float>? _zoomMultiplier;

	public static float ZoomMultiplier = _zoomMultiplier?.Value ?? 0.05f;

	private static ConfigEntry<float>? _defaultZoom;

	public static float DefaultZoom = _defaultZoom?.Value ?? 1f;

	public static KeyCode ZoomOut => (KeyCode)(((??)_zoomOut?.Value) ?? 0);

	public static KeyCode ZoomIn => (KeyCode)(((??)_zoomIn?.Value) ?? 0);

	public static KeyCode ResetZoom => (KeyCode)(((??)_resetZoom?.Value) ?? 0);

	public static void Init(ConfigFile config)
	{
		_zoomOut = config.Bind<KeyCode>("Keybinds", "Zoom Out", (KeyCode)111, (ConfigDescription)null);
		_zoomIn = config.Bind<KeyCode>("Keybinds", "Zoom In", (KeyCode)112, (ConfigDescription)null);
		_resetZoom = config.Bind<KeyCode>("Keybinds", "Reset Zoom", (KeyCode)91, (ConfigDescription)null);
		_zoomMultiplier = config.Bind<float>("Constants", "Zoom Multiplier", 0.05f, (ConfigDescription)null);
		_defaultZoom = config.Bind<float>("Constants", "Default Zoom", 1f, (ConfigDescription)null);
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	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")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace ZoomFix
{
	[BepInPlugin("io.github.foxyrobo.zoomfix", "ZoomFix", "1.0.2")]
	public class ZoomFixPlugin : BaseUnityPlugin
	{
		private float defaultFOV = -1f;

		private float currentFOV = -1f;

		public const string Id = "io.github.foxyrobo.zoomfix";

		public static string Name => "ZoomFix";

		public static string Version => "1.0.2";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.foxyrobo.zoomfix) has loaded!"));
			Configuration.Init(((BaseUnityPlugin)this).Config);
		}

		private void Update()
		{
			HandleInput();
		}

		private void HandleInput()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(Configuration.ZoomOut))
			{
				ZoomOut();
			}
			if (Input.GetKeyDown(Configuration.ZoomIn))
			{
				ZoomIn();
			}
			if (Input.GetKeyDown(Configuration.ResetZoom))
			{
				ResetZoom();
			}
		}

		private void CheckIfDefaultsAreSet()
		{
			if (currentFOV == -1f || defaultFOV == -1f)
			{
				currentFOV = GameCameras.instance.mainCamera.fieldOfView;
				defaultFOV = currentFOV;
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Set fov to {currentFOV}");
			}
		}

		private void ZoomOut()
		{
			CheckIfDefaultsAreSet();
			float zoomFactor = GameCameras.instance.tk2dCam.zoomFactor;
			GameCameras.instance.tk2dCam.zoomFactor = zoomFactor - zoomFactor * Configuration.ZoomMultiplier;
			currentFOV = CalculateNewFOV(defaultFOV, GameCameras.instance.tk2dCam.ZoomFactor);
			Object.FindFirstObjectByType<LightBlurredBackground>().OnCameraFovChanged(currentFOV);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Zoom out to {GameCameras.instance.tk2dCam.ZoomFactor}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Set fov to {currentFOV}");
		}

		private void ZoomIn()
		{
			CheckIfDefaultsAreSet();
			float zoomFactor = GameCameras.instance.tk2dCam.zoomFactor;
			GameCameras.instance.tk2dCam.zoomFactor = zoomFactor + zoomFactor * Configuration.ZoomMultiplier;
			currentFOV = CalculateNewFOV(defaultFOV, GameCameras.instance.tk2dCam.ZoomFactor);
			Object.FindFirstObjectByType<LightBlurredBackground>().OnCameraFovChanged(currentFOV);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Zoom in to {GameCameras.instance.tk2dCam.ZoomFactor}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Set fov to {currentFOV}");
		}

		private void ResetZoom()
		{
			CheckIfDefaultsAreSet();
			GameCameras.instance.tk2dCam.zoomFactor = Configuration.DefaultZoom;
			currentFOV = defaultFOV;
			Object.FindFirstObjectByType<LightBlurredBackground>().OnCameraFovChanged(currentFOV);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Reset zoom to {Configuration.DefaultZoom}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Set fov to {currentFOV}");
		}

		private float CalculateNewFOV(float baseFOV, float zoomFactor)
		{
			return 2f * Mathf.Atan(Mathf.Tan(baseFOV / 2f * (MathF.PI / 180f)) / zoomFactor) * 57.29578f;
		}
	}
}