Decompiled source of LethalSanity v2.0.0

LethalSanity.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
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 LethalSanity.Modules;
using LethalSex_Core;
using LethalSex_Core.Modules;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LethalSanity")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalSanity")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("14118ff6-85f2-4a97-befd-cc17379fefa9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[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;
		}
	}
}
namespace LethalSanity
{
	internal class Config
	{
		internal int P_PP { get; set; }

		internal Tuple<bool, float, float> P_VC { get; set; }

		internal Tuple<bool, float, float> P_FGC { get; set; }

		internal Tuple<bool, float, float> P_CAC { get; set; }

		internal Tuple<bool, float, float> P_LDC { get; set; }

		internal Tuple<bool, float, float> P_DOFC { get; set; }

		internal Tuple<bool, float, float> P_SC { get; set; }

		internal Tuple<bool, float, float> C_LC { get; set; }

		internal Config()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "LethalSanity.cfg"), true, new BepInPlugin("com.GitHub.IGNOREDSOUL.LethalSex.LethalSanity", "LethalSanity", "2.0.0"));
			P_PP = val.Bind<int>("Post Processing", "Priority", 1, "In Unity, the post-processing priority value determines which volume's effects are applied first when multiple volumes overlap. Higher priority values take precedence, allowing for specific area effects to override global ones.\nSet the value higher if effects are being wacky.").Value;
			P_VC = ConvertInput(val.Bind<string>("Post Processing", "Vignette activation", "true, 25, 3", "Toggle, insanity level, offset"));
			P_FGC = ConvertInput(val.Bind<string>("Post Processing", "Film Grain activation", "true, 30, 5", "Toggle, insanity level, offset"));
			P_CAC = ConvertInput(val.Bind<string>("Post Processing", "Chromatic Aberation activation", "true, 40, 5", "Toggle, insanity level, offset"));
			P_LDC = ConvertInput(val.Bind<string>("Post Processing", "Lens Distortion activation", "true, 35, 4", "Toggle, insanity level, offset"));
			P_DOFC = ConvertInput(val.Bind<string>("Post Processing", "Depth of Field activation", "true, 50, 5", "Toggle, insanity level, offset"));
			P_SC = ConvertInput(val.Bind<string>("Post Processing", "Saturation activation", "true, 50, 3", "Toggle, insanity level, offset"));
			C_LC = ConvertInput(val.Bind<string>("Camera Leaning", "Basic Controls", "true, 0.5, 3", "Toggle, Tilt multiplier, Tilt speed"));
		}

		private static Tuple<bool, float, float> ConvertInput(ConfigEntry<string> input)
		{
			try
			{
				string[] array = input.Value?.Replace(" ", "").Split(new char[1] { ',' });
				if (array == null || array.Length != 3)
				{
					throw new ArgumentException("Invalid amount. Defaulting.");
				}
				if (!bool.TryParse(array[0], out var _))
				{
					throw new ArgumentException("(" + ((ConfigEntryBase)input).Definition.Key + ") Item 1: " + array[0] + ", does not parse into a bool.");
				}
				if (!float.TryParse(array[1], out var result2))
				{
					throw new ArgumentException("(" + ((ConfigEntryBase)input).Definition.Key + ") Item 2: " + array[1] + ", does not parse into a float.");
				}
				if (!float.TryParse(array[2], out result2))
				{
					throw new ArgumentException("(" + ((ConfigEntryBase)input).Definition.Key + ") Item 3: " + array[2] + ", does not parse into a float.");
				}
				return new Tuple<bool, float, float>(bool.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
			}
			catch (ArgumentException ex)
			{
				Main.mls.LogFatal((object)ex);
				ConsoleManager.Error((object)$"Error in config: {ex}");
			}
			string[] array2 = ((ConfigEntryBase)input).DefaultValue.ToString().Replace(" ", "").Split(new char[1] { ',' });
			return new Tuple<bool, float, float>(bool.Parse(array2[0]), float.Parse(array2[1]), float.Parse(array2[2]));
		}
	}
	[BepInPlugin("com.GitHub.IGNOREDSOUL.LethalSex.LethalSanity", "LethalSanity", "2.0.0")]
	[BepInProcess("Lethal Company.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Main : BaseUnityPlugin
	{
		internal readonly Harmony harmony = new Harmony("com.GitHub.IGNOREDSOUL.LethalSex.LethalSanity");

		internal const string modGUID = "com.GitHub.IGNOREDSOUL.LethalSex.LethalSanity";

		internal const string modName = "LethalSanity";

		internal const string modVersion = "2.0.0";

		public static Main instance { get; private set; }

		internal static LethalMod mod { get; private set; }

		internal static ManualLogSource mls { get; private set; }

		internal static Config config { get; private set; }

		private void Awake()
		{
			instance = this;
			mls = Logger.CreateLogSource("LethalSanity");
			config = new Config();
			mod = Main.RegisterMod("LethalSanity", "2.0.0", "IGNOREDSOUL");
			mod.RegisterModule(typeof(PostProcessing));
			mod.RegisterModule(typeof(CameraLeanV2));
		}
	}
}
namespace LethalSanity.Modules
{
	internal class CameraLeanV2 : LethalModule
	{
		public float TiltMultiplier = 0.5f;

		public float MaxTilt = 150f;

		public float TiltSpeed = 5f;

		public float TiltThreshold = 55f;

		private float currentTiltAngle;

		public static CameraLeanV2 instance { get; private set; }

		public static CameraLeanV2 component { get; private set; }

		public override void OnRegister()
		{
			if (!Main.config.C_LC.Item1)
			{
				((LethalModule)this).Unregister();
			}
			instance = this;
		}

		public override void OnLocalStart(PlayerControllerB _LocalPlayer)
		{
			component = ((Component)_LocalPlayer.gameplayCamera).gameObject.AddComponent<CameraLeanV2>();
		}

		private void Update()
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			if ((StartOfRound.Instance.shipDoorsEnabled || StartOfRound.Instance.inShipPhase) && !LocalPlayer.PlayerController.isPlayerDead)
			{
				float num = Mathf.Clamp(((InputControl<float>)(object)((Vector2Control)((Pointer)Mouse.current).delta).x).ReadValue(), 0f, MaxTilt);
				if (num >= TiltThreshold || num <= 0f - TiltThreshold)
				{
					float num2 = (0f - num) * Main.config.C_LC.Item2;
					currentTiltAngle = Mathf.Lerp(currentTiltAngle, num2, Time.deltaTime * Main.config.C_LC.Item3);
				}
				else
				{
					currentTiltAngle = Mathf.Lerp(currentTiltAngle, 0f, Time.deltaTime * Main.config.C_LC.Item3);
				}
				((Component)this).transform.localRotation = Quaternion.Euler(0f, 0f, currentTiltAngle);
			}
		}
	}
	internal class PostProcessing : LethalModule
	{
		public static PostProcessing instance { get; private set; }

		public static PostProcessing component { get; private set; }

		private GameObject VolumeObject { get; set; }

		private VolumeProfile VolumeProfile { get; set; }

		public override void OnRegister()
		{
			instance = this;
		}

		public override void OnLocalStart(PlayerControllerB _LocalPlayer)
		{
			component = ((Component)_LocalPlayer).gameObject.AddComponent<PostProcessing>();
		}

		private void Start()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			VolumeObject = Object.Instantiate<GameObject>(GameObject.Find("Systems/Rendering/VolumeMain"), GameObject.Find("Systems/Rendering/VolumeMain").transform.parent);
			((Object)VolumeObject).name = "LS-Volume";
			VolumeProfile = new VolumeProfile();
			((Object)VolumeProfile).name = "LS-VolumeProfile";
			VolumeObject.GetComponentInChildren<Volume>().priority = Main.config.P_PP;
			VolumeObject.GetComponentInChildren<Volume>().profile = VolumeProfile;
			MakeDOF();
			MakeChrAb();
			MakeVignette();
			MakeLensDist();
			MakeFilmGrain();
			MakeSaturation();
		}

		private void MakeVignette()
		{
			if (Main.config.P_VC.Item1)
			{
				float num = NumberUtils.NextO(Main.config.P_VC.Item2, Main.config.P_VC.Item3, 65f);
				Vignette VignetteComp = VolumeProfile.Add<Vignette>(false);
				((VolumeParameter<float>)(object)VignetteComp.smoothness).value = 1f;
				((VolumeParameter<float>)(object)VignetteComp.roundness).value = 0.842f;
				((Object)VignetteComp).name = "LS-VignetteComp";
				((LethalModule)this).AddSanityEvent(num, (Action)delegate
				{
					float num3 = NumberUtils.NextF(0.45f, 0.6f);
					float num4 = NumberUtils.NextF(10f, 25f);
					ConsoleManager.Log((object)$"Applying Vignette ({num3}/{num4})");
					Extensions.SmoothIncrementValue("Vignette", (Action<float>)((VolumeParameter<float>)(object)VignetteComp.intensity).Override, ((VolumeParameter<float>)(object)VignetteComp.intensity).value, num3, num4);
				}, (Action)delegate
				{
					float num2 = NumberUtils.NextF(0.5f, 2f);
					ConsoleManager.Log((object)$"Resetting Vignette (0/{num2})");
					Extensions.SmoothIncrementValue("Vignette", (Action<float>)((VolumeParameter<float>)(object)VignetteComp.intensity).Override, ((VolumeParameter<float>)(object)VignetteComp.intensity).value, 0f, num2);
				});
				ConsoleManager.Log((object)$"Vignette applies at lvl: {num}");
			}
		}

		private void MakeFilmGrain()
		{
			if (Main.config.P_FGC.Item1)
			{
				float num = NumberUtils.NextO(Main.config.P_FGC.Item2, Main.config.P_FGC.Item3, 65f);
				FilmGrain FilmGrainComp = VolumeProfile.Add<FilmGrain>(false);
				((Object)FilmGrainComp).name = "LS-FilmGrainComp";
				((LethalModule)this).AddSanityEvent(num, (Action)delegate
				{
					float num3 = NumberUtils.NextF(0.5f, 1f);
					float num4 = NumberUtils.NextF(10f, 20f);
					ConsoleManager.Log((object)$"Applying FilmGrain ({num3}/{num4})");
					Extensions.SmoothIncrementValue("FilmGrain", (Action<float>)((VolumeParameter<float>)(object)FilmGrainComp.intensity).Override, ((VolumeParameter<float>)(object)FilmGrainComp.intensity).value, num3, num4);
				}, (Action)delegate
				{
					float num2 = NumberUtils.NextF(0.5f, 2f);
					ConsoleManager.Log((object)$"Resetting FilmGrain (0/{num2})");
					Extensions.SmoothIncrementValue("FilmGrain", (Action<float>)((VolumeParameter<float>)(object)FilmGrainComp.intensity).Override, ((VolumeParameter<float>)(object)FilmGrainComp.intensity).value, 0f, num2);
				});
				ConsoleManager.Log((object)$"Film Grain applies at lvl: {num}");
			}
		}

		private void MakeChrAb()
		{
			if (Main.config.P_CAC.Item1)
			{
				float num = NumberUtils.NextO(Main.config.P_CAC.Item2, Main.config.P_CAC.Item3, 65f);
				ChromaticAberration ChrAbComp = VolumeProfile.Add<ChromaticAberration>(false);
				((Object)ChrAbComp).name = "LS-ChrAbComp";
				((LethalModule)this).AddSanityEvent(num, (Action)delegate
				{
					float num3 = NumberUtils.NextF(1f, 2f);
					float num4 = NumberUtils.NextF(10f, 20f);
					ConsoleManager.Log((object)$"Applying Chromatic Aberation ({num3}/{num4})");
					Extensions.SmoothIncrementValue("ChrAb", (Action<float>)((VolumeParameter<float>)(object)ChrAbComp.intensity).Override, ((VolumeParameter<float>)(object)ChrAbComp.intensity).value, NumberUtils.NextF(0.5f, 1.5f), NumberUtils.NextF(10f, 20f));
				}, (Action)delegate
				{
					float num2 = NumberUtils.NextF(0.5f, 2f);
					ConsoleManager.Log((object)$"Resetting Chromatic Aberration (0/{num2})");
					Extensions.SmoothIncrementValue("ChrAb", (Action<float>)((VolumeParameter<float>)(object)ChrAbComp.intensity).Override, ((VolumeParameter<float>)(object)ChrAbComp.intensity).value, 0f, NumberUtils.NextF(0.5f, 2f));
				});
				ConsoleManager.Log((object)$"Chromatic Aberration applies at lvl: {num}");
			}
		}

		private void MakeLensDist()
		{
			if (Main.config.P_LDC.Item1)
			{
				float num = NumberUtils.NextO(Main.config.P_LDC.Item2, Main.config.P_LDC.Item3, 65f);
				LensDistortion LensDistComp = VolumeProfile.Add<LensDistortion>(false);
				((Object)LensDistComp).name = "LS-LensDistComp";
				((LethalModule)this).AddSanityEvent(num, (Action)delegate
				{
					float num3 = NumberUtils.NextF(0.4f, 0.6f);
					float num4 = NumberUtils.NextF(20f, 30f);
					ConsoleManager.Log((object)$"Applying Lens Distortion ({num3}/{num4})");
					Extensions.SmoothIncrementValue("LensDist", (Action<float>)((VolumeParameter<float>)(object)LensDistComp.intensity).Override, ((VolumeParameter<float>)(object)LensDistComp.intensity).value, num3, num4);
				}, (Action)delegate
				{
					float num2 = NumberUtils.NextF(0.5f, 2f);
					ConsoleManager.Log((object)$"Resetting Lens Distortion (0/{num2})");
					Extensions.SmoothIncrementValue("LensDist", (Action<float>)((VolumeParameter<float>)(object)LensDistComp.intensity).Override, ((VolumeParameter<float>)(object)LensDistComp.intensity).value, 0f, num2);
				});
				ConsoleManager.Log((object)$"Lens Distortion applies at lvl: {num}");
			}
		}

		private void MakeDOF()
		{
			if (Main.config.P_DOFC.Item1)
			{
				float num = NumberUtils.NextO(Main.config.P_DOFC.Item2, Main.config.P_DOFC.Item3, 65f);
				DepthOfField DOFComp = VolumeProfile.Add<DepthOfField>(false);
				((VolumeParameter<float>)(object)DOFComp.farFocusStart).Override(2000f);
				((VolumeParameter<float>)(object)DOFComp.farFocusEnd).Override(2000f);
				((Object)DOFComp).name = "LS-DOFComp";
				((LethalModule)this).AddSanityEvent(num, (Action)delegate
				{
					float num4 = NumberUtils.NextF(3f, 8f);
					float num5 = NumberUtils.NextF(10f, 17f);
					ConsoleManager.Log((object)$"Applying Depth of Field (Start) ({num4}/{num5})");
					Extensions.SmoothIncrementValue("DOFStart", (Action<float>)((VolumeParameter<float>)(object)DOFComp.farFocusStart).Override, ((VolumeParameter<float>)(object)DOFComp.farFocusStart).value, num4, num5);
					float num6 = NumberUtils.NextF(10f, 15f);
					float num7 = NumberUtils.NextF(18f, 25f);
					ConsoleManager.Log((object)$"Applying Depth of Field (End) ({num6}/{num7})");
					Extensions.SmoothIncrementValue("DOFEnd", (Action<float>)((VolumeParameter<float>)(object)DOFComp.farFocusEnd).Override, ((VolumeParameter<float>)(object)DOFComp.farFocusEnd).value, num6, num7);
				}, (Action)delegate
				{
					float num2 = NumberUtils.NextF(10f, 13f);
					ConsoleManager.Log((object)$"Resseting Depth of Field (Start) (2000/{num2})");
					Extensions.SmoothIncrementValue("DOFStart", (Action<float>)((VolumeParameter<float>)(object)DOFComp.farFocusStart).Override, ((VolumeParameter<float>)(object)DOFComp.farFocusStart).value, 2000f, num2);
					float num3 = NumberUtils.NextF(13f, 16f);
					ConsoleManager.Log((object)$"Resseting Depth of Field (End) (2000/{num3})");
					Extensions.SmoothIncrementValue("DOFEnd", (Action<float>)((VolumeParameter<float>)(object)DOFComp.farFocusEnd).Override, ((VolumeParameter<float>)(object)DOFComp.farFocusEnd).value, 2000f, num3);
				});
				ConsoleManager.Log((object)$"Depth Of Field applies at lvl: {num}");
			}
		}

		private void MakeSaturation()
		{
			if (Main.config.P_SC.Item1)
			{
				float num = NumberUtils.NextO(Main.config.P_SC.Item2, Main.config.P_SC.Item3, 65f);
				ColorAdjustments CAComp = VolumeProfile.Add<ColorAdjustments>(false);
				((Object)CAComp).name = "LS-CAComp";
				((LethalModule)this).AddSanityEvent(num, (Action)delegate
				{
					float num3 = NumberUtils.NextF(50f, 70f);
					float num4 = NumberUtils.NextF(18f, 28f);
					ConsoleManager.Log((object)$"Applying Color Adjustments ({num3}/{num4})");
					Extensions.SmoothIncrementValue("CA", (Action<float>)((VolumeParameter<float>)(object)CAComp.saturation).Override, ((VolumeParameter<float>)(object)CAComp.saturation).value, 0f - num3, num4);
				}, (Action)delegate
				{
					float num2 = NumberUtils.NextF(0.5f, 2f);
					ConsoleManager.Log((object)$"Resseting Color Adjustments (0/{num2})");
					Extensions.SmoothIncrementValue("CA", (Action<float>)((VolumeParameter<float>)(object)CAComp.saturation).Override, ((VolumeParameter<float>)(object)CAComp.saturation).value, 0f, num2);
				});
				ConsoleManager.Log((object)$"Color Adjustments applies at lvl: {num}");
			}
		}

		private void OnDestroy()
		{
			((LethalModule)this).Destroyed();
		}

		private void OnDisable()
		{
			((LethalModule)this).Disabled();
		}

		private void OnEnable()
		{
			((LethalModule)this).Enabled();
		}
	}
}