Decompiled source of DetectiveSquint v1.0.0

DetectiveSquint.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DetectiveSquint")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DetectiveSquint")]
[assembly: AssemblyTitle("DetectiveSquint")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 DetectiveSquint
{
	[BepInPlugin("sodmods.detectivesquint", "Detective Squint", "1.0.0")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<KeyCode> SquintKey;

		internal static ConfigEntry<bool> Toggle;

		internal static ConfigEntry<float> Zoom;

		internal static ConfigEntry<float> Speed;

		internal static ConfigEntry<bool> ScaleSensitivity;

		public override void Load()
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BasePlugin)this).Log;
			SquintKey = ((BasePlugin)this).Config.Bind<KeyCode>("Controls", "SquintKey", (KeyCode)122, "Key to squint (zoom in).");
			Toggle = ((BasePlugin)this).Config.Bind<bool>("Controls", "Toggle", false, "Press once to squint, again to stop, instead of holding the key.");
			Zoom = ((BasePlugin)this).Config.Bind<float>("Squint", "Zoom", 2.5f, "Magnification while squinting (2.5 = the view is 2.5x closer).");
			Speed = ((BasePlugin)this).Config.Bind<float>("Squint", "Speed", 6f, "How quickly the view zooms in and out (higher = snappier).");
			ScaleSensitivity = ((BasePlugin)this).Config.Bind<bool>("Squint", "ScaleMouseSensitivity", true, "Slow mouse look down in proportion to the zoom, so aiming stays steady.");
			new Harmony("sodmods.detectivesquint").PatchAll(typeof(Plugin).Assembly);
			((BasePlugin)this).Log.LogInfo((object)"Detective Squint loaded");
		}
	}
	[HarmonyPatch(typeof(Player), "Update")]
	internal static class SquintPatch
	{
		internal static float Current = 1f;

		private static bool toggledOn;

		private static bool applied;

		private static void Postfix()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				CameraController instance = CameraController.Instance;
				Camera val = ((instance != null) ? instance.cam : null);
				if ((Object)(object)val == (Object)null || (Object)(object)Game.Instance == (Object)null)
				{
					return;
				}
				bool flag = InFreeMovement();
				KeyCode value = Plugin.SquintKey.Value;
				bool flag2;
				if (Plugin.Toggle.Value)
				{
					if (flag && (int)value != 0 && Input.GetKeyDown(value))
					{
						toggledOn = !toggledOn;
					}
					if (!flag)
					{
						toggledOn = false;
					}
					flag2 = toggledOn;
				}
				else
				{
					flag2 = flag && (int)value != 0 && Input.GetKey(value);
				}
				float num = (flag2 ? Mathf.Max(1f, Plugin.Zoom.Value) : 1f);
				float num2 = 1f - Mathf.Exp((0f - Plugin.Speed.Value) * Time.unscaledDeltaTime);
				Current = Mathf.Lerp(Current, num, num2);
				if (Mathf.Abs(Current - num) < 0.005f)
				{
					Current = num;
				}
				if (Current > 1f)
				{
					val.fieldOfView = (float)Game.Instance.fov / Current;
					applied = true;
				}
				else if (applied)
				{
					val.fieldOfView = Game.Instance.fov;
					applied = false;
				}
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)ex);
			}
		}

		private static bool InFreeMovement()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			if ((Object)(object)SessionData.Instance == (Object)null || !SessionData.Instance.play)
			{
				return false;
			}
			if ((int)Cursor.lockState != 1)
			{
				return false;
			}
			if ((Object)(object)InterfaceController.Instance != (Object)null && InterfaceController.Instance.desktopMode)
			{
				return false;
			}
			if ((Object)(object)InteractionController.Instance != (Object)null && InteractionController.Instance.dialogMode)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MouseLook), "LookRotation")]
	internal static class SensitivityPatch
	{
		private static bool scaled;

		private static Vector2 savedMouse;

		private static Vector2 savedController;

		private static void Prefix()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			scaled = false;
			if (Plugin.ScaleSensitivity.Value && !(SquintPatch.Current <= 1.001f) && !((Object)(object)Game.Instance == (Object)null))
			{
				savedMouse = Game.Instance.mouseSensitivity;
				savedController = Game.Instance.controllerSensitivity;
				Game.Instance.mouseSensitivity = savedMouse / SquintPatch.Current;
				Game.Instance.controllerSensitivity = savedController / SquintPatch.Current;
				scaled = true;
			}
		}

		private static void Finalizer()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (scaled)
			{
				Game.Instance.mouseSensitivity = savedMouse;
				Game.Instance.controllerSensitivity = savedController;
				scaled = false;
			}
		}
	}
}