Decompiled source of SimpleZoom v1.1.1

SimpleZoom.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("SimpleZoom")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+9c496707cfb69bb14e17762ac0a406be14c192d0")]
[assembly: AssemblyProduct("SimpleZoom")]
[assembly: AssemblyTitle("SimpleZoom")]
[assembly: AssemblyVersion("1.0.0.0")]
[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("simplezoom_1.1.1", "Simple Zoom", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		File.Delete(Path.Combine(Paths.ConfigPath, "com.cyfral.simplezoom.cfg"));
		File.Delete(Path.Combine(Paths.ConfigPath, "simplezoom_1.1.0.cfg"));
		ZoomConfig.Init((BaseUnityPlugin)(object)this);
		new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID).PatchAll();
	}
}
public class ZoomConfig
{
	public static KeyCode ZoomKey { get; private set; }

	public static float MaxZoom { get; private set; }

	public static float ZoomSpeed { get; private set; }

	public static float ScrollStep { get; private set; }

	public static int CoolPerkMachine { get; private set; }

	public static void Init(BaseUnityPlugin plugin)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		ZoomKey = plugin.Config.Bind<KeyCode>("General", "Zoom Key", (KeyCode)103, "Key used to activate zoom").Value;
		MaxZoom = plugin.Config.Bind<float>("General", "Max Zoom", 600f, "Maximum zoom amount").Value;
		ZoomSpeed = plugin.Config.Bind<float>("General", "Zoom Speed", 8f, "Speed of FOV change").Value;
		ScrollStep = plugin.Config.Bind<float>("General", "Scroll Step", 50f, "Step size when adjusting zoom with mouse wheel").Value;
		CoolPerkMachine = plugin.Config.Bind<int>("General", "Cool Perk Machine", 90, new ConfigDescription("FOV while using Perk Machine or computers (it only for fun and doesn't make sense)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(60, 140), Array.Empty<object>())).Value;
	}
}
[HarmonyPatch]
public static class ZoomPatch
{
	[HarmonyPatch(typeof(UT_CameraTakeover), "Start")]
	public static class CameraTakeoverPatch
	{
		[HarmonyPrefix]
		public static bool CoolPerkMachine(UT_CameraTakeover __instance)
		{
			__instance.fov = ZoomConfig.CoolPerkMachine;
			return true;
		}
	}

	private static float _zoomOffset;

	private static float _targetZoomOffset;

	private static float _zoomBase;

	private static readonly FieldInfo _curFOVField;

	private static readonly FieldInfo _smoothedFOVField;

	private static readonly FieldInfo _slowFOVAdjustField;

	static ZoomPatch()
	{
		_zoomOffset = -1f;
		_targetZoomOffset = -1f;
		_zoomBase = 60f;
		Type typeFromHandle = typeof(ENT_Player);
		_curFOVField = typeFromHandle.GetField("curFOV", BindingFlags.Instance | BindingFlags.NonPublic);
		_smoothedFOVField = typeFromHandle.GetField("smoothedFOV", BindingFlags.Instance | BindingFlags.NonPublic);
		_slowFOVAdjustField = typeFromHandle.GetField("slowFOVAdjust", BindingFlags.Instance | BindingFlags.NonPublic);
	}

	[HarmonyPatch(typeof(ENT_Player), "LateUpdate")]
	[HarmonyPostfix]
	public static void LateUpdatePostfix(ENT_Player __instance)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.cam == (Object)null) && !__instance.IsLocked() && !__instance.IsInputLocked())
		{
			float y = Input.mouseScrollDelta.y;
			if (Mathf.Abs(y) > 0.01f)
			{
				_zoomBase = Mathf.Clamp(_zoomBase + y * ZoomConfig.ScrollStep, 10f, ZoomConfig.MaxZoom);
			}
			_targetZoomOffset = (Input.GetKey(ZoomConfig.ZoomKey) ? (0f - _zoomBase) : 0f);
			_zoomOffset = Mathf.Lerp(_zoomOffset, _targetZoomOffset, Time.deltaTime * ZoomConfig.ZoomSpeed);
		}
	}

	[HarmonyPatch(typeof(ENT_Player), "FixedUpdate")]
	[HarmonyPrefix]
	public static void FixedUpdatePrefix(ENT_Player __instance)
	{
		if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.cam == (Object)null) && !__instance.IsLocked())
		{
			float num = (float)_curFOVField.GetValue(__instance);
			_curFOVField.SetValue(__instance, num + _zoomOffset);
		}
	}

	[HarmonyPatch(typeof(ENT_Player), "FixedUpdate")]
	[HarmonyPostfix]
	public static void FixedUpdatePostfix(ENT_Player __instance)
	{
		if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.cam == (Object)null) && !__instance.IsLocked())
		{
			float num = (float)_curFOVField.GetValue(__instance);
			float num2 = (float)_smoothedFOVField.GetValue(__instance);
			float num3 = (float)_slowFOVAdjustField.GetValue(__instance);
			_smoothedFOVField.SetValue(__instance, Mathf.Lerp(num2, num + num3 + _zoomOffset, Time.deltaTime));
		}
	}
}