Decompiled source of ControllerSensitivityFix v1.0.0

BepInEx/plugins/ControllerSensitivityFix.dll

Decompiled 3 days 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MycopunkModder")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Decouples controller sensitivity from framerate for consistent look speed at any FPS")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("ControllerSensitivityFix")]
[assembly: AssemblyTitle("ControllerSensitivityFix")]
[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 ControllerSensitivityFix
{
	[BepInPlugin("coruscnium.controllersensitivityfix", "ControllerSensitivityFix", "1.0.0.0")]
	[BepInProcess("Mycopunk.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[MycoMod(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private static ConfigEntry<float> _referenceFpsConfig;

		private static FileSystemWatcher _configWatcher;

		private static volatile bool _pendingConfigReload;

		private static float _referenceFps = 60f;

		private void Awake()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"ControllerSensitivityFix loading...");
			_referenceFpsConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ReferenceFPS", 60f, new ConfigDescription("The framerate (FPS) the controller sensitivity was tuned for.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(15f, 240f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Config.Save();
			_referenceFps = _referenceFpsConfig.Value;
			_referenceFpsConfig.SettingChanged += delegate
			{
				_referenceFps = _referenceFpsConfig.Value;
			};
			Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
			try
			{
				_configWatcher = new FileSystemWatcher(Paths.ConfigPath, "coruscnium.controllersensitivityfix.cfg")
				{
					NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite),
					EnableRaisingEvents = true
				};
				_configWatcher.Changed += OnConfigFileChanged;
				_configWatcher.Created += OnConfigFileChanged;
				_configWatcher.Renamed += OnConfigFileChanged;
			}
			catch
			{
			}
			Logger.LogInfo((object)"ControllerSensitivityFix initialized.");
		}

		private void Update()
		{
			if (_pendingConfigReload)
			{
				_pendingConfigReload = false;
				try
				{
					((BaseUnityPlugin)this).Config.Reload();
				}
				catch
				{
				}
				_referenceFps = _referenceFpsConfig.Value;
			}
		}

		private void OnConfigFileChanged(object sender, FileSystemEventArgs e)
		{
			_pendingConfigReload = true;
		}

		private void OnDestroy()
		{
			if (_configWatcher != null)
			{
				_configWatcher.EnableRaisingEvents = false;
				_configWatcher.Dispose();
				_configWatcher = null;
			}
		}

		[HarmonyPatch(typeof(PlayerInput), "LookInput")]
		[HarmonyPostfix]
		private static void LookInput_Postfix(ref Vector2 __result)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)PlayerInput.Device > 0)
			{
				__result *= Mathf.Min(Time.unscaledDeltaTime, 0.1f) * _referenceFps;
			}
		}
	}
}