Decompiled source of LCZoom v1.1.0

LCZoom.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCZoom.Patches;
using LethalCompanyInputUtils.Api;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LCZoom")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCZoom")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("66898a81-a28e-4b5e-a6e5-ee9c70935d16")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCZoom
{
	[BepInPlugin("sysfab.lczoom", "LC Zoom", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ZoomBase : BaseUnityPlugin
	{
		private const string modGUID = "sysfab.lczoom";

		private const string modName = "LC Zoom";

		private const string modVersion = "1.1.0";

		private readonly Harmony harmony = new Harmony("sysfab.lczoom");

		public static ZoomBase Instance;

		public static ZoomInputClass InputInstance;

		internal static ConfigEntry<float> NormalFovMultiplier;

		internal static ConfigEntry<float> ZoomFovMultiplier;

		internal static ConfigEntry<bool> EnableScrollZoom;

		internal static ConfigEntry<float> ScrollZoomSpeed;

		internal ManualLogSource Log;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				InputInstance = new ZoomInputClass();
			}
			NormalFovMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "NormalFovMultiplier", 1f, "Normal FOV multiplier. Default is 1.0");
			ZoomFovMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ZoomFovMultiplier", 0.001f, "Zoom FOV multiplier. Default is 0.001");
			EnableScrollZoom = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "EnableScrollZoom", true, "Enable scroll zoom");
			ScrollZoomSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "ScrollZoomSpeed", 0.05f, "Scroll Zoom Speed. Default is 0.05");
			Log = Logger.CreateLogSource("sysfab.lczoom");
			Log.LogInfo((object)"LC Zoom is loaded!");
			harmony.PatchAll(typeof(ZoomBase));
			harmony.PatchAll(typeof(CameraPatch));
		}
	}
	public class ZoomInputClass : LcInputActions
	{
		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction ZoomKey { get; set; }
	}
}
namespace LCZoom.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class CameraPatch
	{
		internal static bool isZooming = false;

		internal static int zoomTicks = 0;

		internal static float ScrollZoomLevel = 0f;

		private static ConfigEntry<float> NormalFov = ZoomBase.NormalFovMultiplier;

		private static ConfigEntry<float> ZoomFov = ZoomBase.ZoomFovMultiplier;

		private static ConfigEntry<bool> EnableScrollZoom = ZoomBase.EnableScrollZoom;

		private static ConfigEntry<float> ScrollZoomSpeed = ZoomBase.ScrollZoomSpeed;

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void patchAwake()
		{
			isZooming = false;
			zoomTicks = 0;
			ScrollZoomLevel = 0.5f;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void patchUpdate(ref float ___targetFOV, ref Camera ___gameplayCamera, ref bool ___inTerminalMenu, ref QuickMenuManager ___quickMenuManager, ref bool ___isTypingChat, ref bool ___disableMoveInput, ref bool ___inSpecialInteractAnimation, ref bool ___isClimbingLadder, ref bool ___inShockingMinigame)
		{
			if (((___inTerminalMenu || ___quickMenuManager.isMenuOpen) | ___isTypingChat | ___disableMoveInput) || (___inSpecialInteractAnimation & ___isClimbingLadder & ___inShockingMinigame))
			{
				isZooming = false;
				return;
			}
			isZooming = ZoomBase.InputInstance.ZoomKey.IsPressed();
			if (isZooming)
			{
				if (zoomTicks == 0)
				{
					ScrollZoomLevel = (EnableScrollZoom.Value ? 0.5f : 1f);
				}
				zoomTicks++;
			}
			else
			{
				zoomTicks = 0;
			}
			float num = (isZooming ? Mathf.Lerp(NormalFov.Value, ZoomFov.Value, ScrollZoomLevel) : NormalFov.Value);
			___gameplayCamera.fieldOfView = Mathf.Lerp(___gameplayCamera.fieldOfView, ___targetFOV * num, 6f * Time.deltaTime);
		}

		[HarmonyPatch("ScrollMouse_performed")]
		[HarmonyPrefix]
		private static void patchScroll(ref CallbackContext context, ref float ___timeSinceSwitchingSlots)
		{
			if (EnableScrollZoom.Value)
			{
				float num = Mathf.Sign(((CallbackContext)(ref context)).ReadValue<float>());
				if (isZooming)
				{
					ScrollZoomLevel = Math.Max(0f, Math.Min(1f, ScrollZoomLevel + 0.05f * num));
					___timeSinceSwitchingSlots = 0f;
				}
			}
		}
	}
}