Decompiled source of LethalSex Core v2.0.1

LethalSex-Core.dll

Decompiled 6 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalSex_Core.Modules;
using LethalSex_Core.Properties;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LethalSex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalSex")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("aec54baa-710e-4860-aed4-d905e4489577")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 LethalSex_Core
{
	internal class Config
	{
		private static ConfigFile config { get; set; }

		internal static bool ToggleDebugConsole { get; private set; }

		internal void Init()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			config = new ConfigFile(Path.Combine(Paths.ConfigPath, "LethalSexCore.cfg"), true);
			ToggleDebugConsole = config.Bind<bool>("Console", "Toggle debug console", false, "Allow the console to be toggled on and off? (F10)").Value;
		}
	}
	public static class Extensions
	{
		private static Dictionary<string, CancellationTokenSource> ctsDict = new Dictionary<string, CancellationTokenSource>();

		public static T GetOrAddComponent<T>(this GameObject gameObject, bool Log = false) where T : Component
		{
			T val = gameObject.GetComponent<T>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = gameObject.AddComponent<T>();
				if (Log)
				{
					Main.mls.LogError((object)("Added " + ((Object)(object)val).name));
				}
			}
			return val;
		}

		public static bool TryDestroy(this Object o)
		{
			try
			{
				Object.Destroy(o);
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static string Join(this object[] array)
		{
			return string.Join(", ", array);
		}

		public static string ColorWrap(string text, string hexCode)
		{
			return "<color=" + hexCode + ">" + text + "</color>";
		}

		public static string HexColor(Color baseColor)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			return "#" + Convert.ToInt32(baseColor.r * 255f).ToString("X2") + Convert.ToInt32(baseColor.g * 255f).ToString("X2") + Convert.ToInt32(baseColor.b * 255f).ToString("X2");
		}

		public static string GetObjPath(this Transform transform)
		{
			string text = ((Object)transform).name;
			while ((Object)(object)transform.parent != (Object)null)
			{
				transform = transform.parent;
				text = ((Object)transform).name + "/" + text;
			}
			return text;
		}

		public static async void SmoothIncrementValue(string ActionName, Action<float> action, float start, float target, float duration)
		{
			if (ctsDict.ContainsKey(ActionName))
			{
				ctsDict[ActionName].Cancel();
				ctsDict[ActionName].Dispose();
				Main.mls.LogWarning((object)("Cancelling smooth increment task: " + ActionName));
				ctsDict.Remove(ActionName);
			}
			ctsDict.Add(ActionName, new CancellationTokenSource());
			await SmoothIncrementValueTask(delegate(float value)
			{
				action(value);
			}, start, target, duration, ctsDict[ActionName].Token);
			ctsDict.Remove(ActionName);
		}

		private static async Task SmoothIncrementValueTask(Action<float> action, float start, float target, float duration, CancellationToken cancellationToken)
		{
			float elapsedTime = 0f;
			float obj;
			while (elapsedTime < duration)
			{
				if (cancellationToken.IsCancellationRequested)
				{
					return;
				}
				obj = Mathf.Lerp(start, target, elapsedTime / duration);
				action(obj);
				elapsedTime += Time.deltaTime;
				await Task.Yield();
			}
			obj = target;
			action(obj);
		}

		public static bool TryCatch(object description, Action action)
		{
			try
			{
				action();
				return true;
			}
			catch (Exception ex)
			{
				MethodBase? method = new StackTrace().GetFrame(1).GetMethod();
				string text = method.DeclaringType?.FullName;
				string name = method.Name;
				string msg = $"An error occoured in {text}.{name}:\nDescription: {description}\nLog: {ex.Message}\n";
				ConsoleManager.Error(msg);
				return false;
			}
		}

		public static Vector3 GetRandomNavMeshPositionInRadiusSpherical(Vector3 origin, float minRadius, float maxRadius, float rayHit = 20f, float samHit = 10f)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val2 = default(RaycastHit);
			NavMeshHit val3 = default(NavMeshHit);
			for (int i = 0; i < 10; i++)
			{
				float num = Mathf.Sin(Time.time * NumberUtils.NextF(1f, 361f));
				float num2 = Mathf.Cos(Time.time * NumberUtils.NextF(1f, 361f));
				Vector3 val = new Vector3(NumberUtils.NextF(minRadius, maxRadius) * num, Random.insideUnitSphere.y * maxRadius, NumberUtils.NextF(minRadius, maxRadius) * num2) + origin + Vector3.up * 20f;
				if (Physics.Raycast(new Ray(val, Vector3.down), ref val2, rayHit))
				{
					if (NavMesh.SamplePosition(((RaycastHit)(ref val2)).point, ref val3, samHit, -1))
					{
						return ((NavMeshHit)(ref val3)).position;
					}
					ConsoleManager.Log("Sample not hit");
				}
				else
				{
					ConsoleManager.Log("Ray not hit");
				}
			}
			return new Vector3(0f, -10000f, 0f);
		}
	}
	public static class NumberUtils
	{
		public static readonly Random random = new Random(GenerateTrulyRandomNumber());

		public static int GenerateTrulyRandomNumber()
		{
			using RNGCryptoServiceProvider rNGCryptoServiceProvider = new RNGCryptoServiceProvider();
			byte[] array = new byte[4];
			rNGCryptoServiceProvider.GetBytes(array);
			return Math.Abs(BitConverter.ToInt32(array, 0) % 40) + 10;
		}

		public static bool Chance(int percentage = 50)
		{
			if (percentage < 0 || percentage > 100)
			{
				throw new Exception("Uh...?");
			}
			return Next(0, 100) < percentage;
		}

		public static bool Chance(float percentage = 50f)
		{
			if (percentage < 0f || percentage > 100f)
			{
				throw new Exception("Uh...?");
			}
			return NextF(0f, 100f) < percentage;
		}

		public static long GenInt64()
		{
			byte[] array = new byte[8];
			random.NextBytes(array);
			return BitConverter.ToInt64(array, 0);
		}

		public static int Next()
		{
			return Next(0, int.MaxValue);
		}

		public static int NextL(int max)
		{
			return Next(0, max - 1);
		}

		public static int Next(int max)
		{
			return Next(0, max + 1);
		}

		public static int Next(int min, int max)
		{
			return random.Next(min, max + 1);
		}

		public static int NextO(int input, int offset)
		{
			return Mathf.Clamp(Next(input - offset, input + offset), 0, int.MaxValue);
		}

		public static int NextO(int input, int offset, int max)
		{
			return Mathf.Clamp(Next(input - offset, input + offset), 0, max);
		}

		public static int NextO(int input, int offset, int min, int max)
		{
			return Mathf.Clamp(Next(input - offset, input + offset), min, max);
		}

		public static float NextO(float input, float offset)
		{
			return Mathf.Clamp(NextF(input - offset, input + offset), 0f, float.MaxValue);
		}

		public static float NextO(float input, float offset, float max)
		{
			return Mathf.Clamp(NextF(input - offset, input + offset), 0f, max);
		}

		public static float NextO(float input, float offset, float min, float max)
		{
			return Mathf.Clamp(NextF(input - offset, input + offset), min, max);
		}

		public static float NextF()
		{
			return NextF(0f, float.MaxValue);
		}

		public static float NextF(float max)
		{
			return NextF(0f, max + 1f);
		}

		public static float NextF(float min, float max)
		{
			return (float)(NextD() * (double)(max - min) + (double)min);
		}

		public static double NextD()
		{
			return random.NextDouble();
		}

		public static string String128(object input)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Hash128 val = default(Hash128);
			((Hash128)(ref val)).Append(input.ToString());
			return ((object)(Hash128)(ref val)).ToString();
		}

		public static Vector3 NextV3(float x, float y, float z)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(NextF(0f - x, x), NextF(0f - y, y), NextF(0f - z, z));
		}

		public static string MD5(object input)
		{
			using MD5 mD = System.Security.Cryptography.MD5.Create();
			byte[] bytes = Encoding.UTF8.GetBytes(input.ToString());
			byte[] array = mD.ComputeHash(bytes);
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < array.Length; i++)
			{
				stringBuilder.Append(array[i].ToString("x2"));
			}
			return stringBuilder.ToString();
		}
	}
	public static class LocalPlayer
	{
		public static InputActionAsset Actions;

		public static PlayerControllerB? PlayerController => GameNetworkManager.Instance?.localPlayerController ?? null;

		public static GameObject? Player
		{
			get
			{
				PlayerControllerB? playerController = PlayerController;
				if (playerController == null)
				{
					return null;
				}
				return ((Component)playerController).gameObject;
			}
		}

		public static float Insanity
		{
			get
			{
				return PlayerController?.insanityLevel ?? (-1f);
			}
			set
			{
				PlayerController.insanityLevel = value;
			}
		}

		public static float MaxInsanity
		{
			get
			{
				return PlayerController?.maxInsanityLevel ?? (-1f);
			}
			set
			{
				PlayerController.maxInsanityLevel = value;
			}
		}

		public static Camera? Camera
		{
			get
			{
				GameObject? player = Player;
				if (player == null)
				{
					return null;
				}
				return player.GetComponentInChildren<Camera>();
			}
		}

		public static bool IsNearOtherPlayers => PlayersNearMe().Length != 0;

		public static bool IsMenuOpen => PlayerController.quickMenuManager.isMenuOpen;

		public static bool IsTermOpen => PlayerController.inTerminalMenu;

		public static bool Interected => Actions.FindAction("Interact", false).WasPressedThisFrame();

		public static async Task<PlayerControllerB> PlayerControllerAsync(int maxIter = 25, int delay = 250)
		{
			if ((Object)(object)PlayerController != (Object)null)
			{
				return PlayerController;
			}
			int iterCount = 0;
			PlayerControllerB player;
			int num;
			do
			{
				player = GameNetworkManager.Instance?.localPlayerController;
				if (!Object.op_Implicit((Object)(object)player))
				{
					await Task.Delay(delay);
				}
				num = iterCount + 1;
				iterCount = num;
			}
			while (num < maxIter || !Object.op_Implicit((Object)(object)player));
			return player;
		}

		public static async Task<GameObject> PlayerAsync(int maxIter = 25, int delay = 250)
		{
			int iterCount = 0;
			GameObject player;
			int num;
			do
			{
				StartOfRound instance = StartOfRound.Instance;
				object obj;
				if (instance == null)
				{
					obj = null;
				}
				else
				{
					PlayerControllerB localPlayerController = instance.localPlayerController;
					obj = ((localPlayerController != null) ? ((Component)localPlayerController).gameObject : null);
				}
				player = (GameObject)obj;
				if (!Object.op_Implicit((Object)(object)player))
				{
					await Task.Delay(delay);
				}
				num = iterCount + 1;
				iterCount = num;
			}
			while (num < maxIter || !Object.op_Implicit((Object)(object)player));
			return player;
		}

		public static async Task<float> InsanityAsync(int maxIter = 25, int delay = 250)
		{
			int iterCount = 0;
			float insanity;
			int num;
			do
			{
				insanity = (StartOfRound.Instance?.localPlayerController?.insanityLevel).GetValueOrDefault(-1f);
				if (insanity < 0f)
				{
					await Task.Delay(delay);
				}
				num = iterCount + 1;
				iterCount = num;
			}
			while (num < maxIter || insanity < 0f);
			return insanity;
		}

		public static async Task<float> MaxInsanityAsync(int maxIter = 25, int delay = 250)
		{
			int iterCount = 0;
			float insanity;
			int num;
			do
			{
				insanity = (StartOfRound.Instance?.localPlayerController?.maxInsanityLevel).GetValueOrDefault(-1f);
				if (insanity < 0f)
				{
					await Task.Delay(delay);
				}
				num = iterCount + 1;
				iterCount = num;
			}
			while (num < maxIter || insanity < 0f);
			return insanity;
		}

		public static async Task<Camera> CameraAsync(int maxIter = 25, int delay = 250)
		{
			int iterCount = 0;
			Camera cam;
			int num;
			do
			{
				GameObject? player = Player;
				cam = ((player != null) ? player.GetComponentInChildren<Camera>() : null);
				if (!Object.op_Implicit((Object)(object)cam))
				{
					await Task.Delay(delay);
				}
				num = iterCount + 1;
				iterCount = num;
			}
			while (num < maxIter || !Object.op_Implicit((Object)(object)cam));
			return cam;
		}

		public static PlayerControllerB[] PlayersNearMe(float rad = 10f)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB[] array = null;
			PlayerControllerB[] array2 = Resources.FindObjectsOfTypeAll<PlayerControllerB>();
			foreach (PlayerControllerB val in array2)
			{
				if (Vector3.Distance(((Component)val).transform.position, Player.transform.position) <= rad)
				{
					array[array.Length] = val;
				}
			}
			return array;
		}

		static LocalPlayer()
		{
			IngamePlayerSettings instance = IngamePlayerSettings.Instance;
			object actions;
			if (instance == null)
			{
				actions = null;
			}
			else
			{
				PlayerInput playerInput = instance.playerInput;
				actions = ((playerInput != null) ? playerInput.actions : null);
			}
			Actions = (InputActionAsset)actions;
		}
	}
	public class LethalMod
	{
		public string Name { get; private set; }

		public string Author { get; private set; }

		public string Version { get; private set; }

		public string AssemblyName { get; private set; }

		public List<LethalModule> Modules { get; private set; }

		public LethalMod(string assemblyName, string modName, string modVersion, string modAuthor)
		{
			Modules = new List<LethalModule>();
			Name = modName;
			Author = modAuthor;
			Version = modVersion;
			AssemblyName = assemblyName;
		}

		public LethalModule? RegisterModule(Type module, string moduleName)
		{
			try
			{
				if (Modules.Exists((LethalModule m) => string.Equals(m.ModuleName, moduleName, StringComparison.OrdinalIgnoreCase)))
				{
					Main.mls.LogError((object)("[" + moduleName + "] already exists in [" + Name + "]"));
					return null;
				}
				LethalModule lethalModule = (LethalModule)Activator.CreateInstance(module);
				lethalModule.Mod = this;
				lethalModule.ModuleName = moduleName;
				Modules.Add(lethalModule);
				lethalModule.OnRegister();
				Main.mls.LogWarning((object)("[" + Name + "] loaded module of: [" + moduleName + "]"));
				ConsoleManager.Warn("[" + Name + "] loaded module of: [" + moduleName + "]");
				return lethalModule;
			}
			catch (Exception arg)
			{
				Main.mls.LogError((object)$"[{Name}] failed to load module of: [{moduleName}]\n{arg}\n");
				ConsoleManager.Error($"[{Name}] failed to load module of: [{moduleName}]\n{arg}\n");
				return null;
			}
		}

		public LethalModule? RegisterModule(Type module)
		{
			return RegisterModule(module, module.Name);
		}

		public void UnregisterModule(string moduleName)
		{
			if (Modules.Exists((LethalModule m) => string.Equals(m.ModuleName, moduleName, StringComparison.OrdinalIgnoreCase)))
			{
				Modules.ForEach(delegate(LethalModule m)
				{
					if (string.Equals(m.ModuleName, moduleName, StringComparison.OrdinalIgnoreCase))
					{
						UnregisterModule(m);
					}
				});
			}
			else
			{
				Main.mls.LogError((object)("Could not unregister [" + moduleName + "] since it cannot be found"));
				ConsoleManager.Error("Could not unregister [" + moduleName + "] since it cannot be found");
			}
		}

		public void UnregisterModule(Type module)
		{
			foreach (LethalModule module2 in Modules)
			{
				if (((object)module2).GetType() == module)
				{
					UnregisterModule(module2);
				}
			}
			Main.mls.LogError((object)("Could not unregister [" + module.Name + "] since it cannot be found"));
		}

		public void UnregisterModule(LethalModule module)
		{
			try
			{
				if (Modules.Contains(module))
				{
					module.Module = null;
					Modules.Remove(module);
					Main.mls.LogWarning((object)("[" + module.ModuleName + "] has been unregistered"));
				}
				else
				{
					Main.mls.LogError((object)("Could not unregister [" + module.ModuleName + "] since it cannot be found"));
				}
			}
			catch (Exception arg)
			{
				Main.mls.LogError((object)$"Failed to unregister a module from [{module.ModuleName}]\n{arg}\n");
				ConsoleManager.Error($"Failed to unregister a module from  [{module.ModuleName}]\n{arg}\n");
			}
		}
	}
	public abstract class LethalModule : MonoBehaviour
	{
		public struct Event
		{
			public float Sanity;

			public Action OnAction;

			public Action OffAction;

			public bool Applied;

			internal Event(float sanity, Action onAct = null, Action offAct = null)
			{
				Sanity = sanity;
				OnAction = onAct;
				OffAction = offAct;
				Applied = false;
			}
		}

		public string ModuleName { get; set; }

		public LethalMod Mod { get; set; }

		public LethalModule Module { get; set; }

		public LethalModule()
		{
			Module = this;
		}

		public virtual void Unregister()
		{
			Mod.UnregisterModule(this);
			Module = null;
		}

		public virtual void OnRegister()
		{
		}

		protected virtual void Enabled()
		{
			Main.mls.LogWarning((object)("Behaviour: " + ((object)this).GetType().Name + " has been enabled"));
			ConsoleManager.Warn("Behaviour: " + ((object)this).GetType().Name + " has been enabled");
		}

		protected virtual void Disabled()
		{
			Main.mls.LogWarning((object)("Behaviour: " + ((object)this).GetType().Name + " has been disabled"));
			ConsoleManager.Warn("Behaviour: " + ((object)this).GetType().Name + " has been disabled");
		}

		protected virtual void Destroyed()
		{
			Main.mls.LogWarning((object)("Behaviour: " + ((object)this).GetType().Name + " has been destroyed"));
			ConsoleManager.Warn("Behaviour: " + ((object)this).GetType().Name + " has been destroyed");
		}

		public virtual void OnHUDAwake()
		{
		}

		public virtual void OnHUDStart()
		{
		}

		public virtual void OnLocalStart(PlayerControllerB _LocalPlayer)
		{
		}

		public virtual void OnShipLand()
		{
		}

		public virtual void OnGrabObject(GrabbableObject obj)
		{
		}

		public virtual void OnLocalDie()
		{
		}

		public virtual bool OnDamagePlayer(ref int damageNumber, ref bool hasDamageSFX, ref bool callRPC, ref CauseOfDeath causeOfDeath, ref int deathAnimation, ref bool fallDamage, ref Vector3 force)
		{
			return true;
		}

		public virtual void OnSanityChanged(float sanity)
		{
		}

		public virtual void OnFinishedGen()
		{
		}

		public void AddSanityEvent(float sanity, Action onAct = null, Action offAct = null)
		{
			SanityEventManager.Instance.New(sanity, onAct, offAct);
		}
	}
	[BepInPlugin("com.GitHub.IGNOREDSOUL.LethalSex.LethalSexCore", "LethalSex-Core", "2.0.1")]
	[BepInProcess("Lethal Company.exe")]
	public class Main : BaseUnityPlugin
	{
		internal readonly Harmony harmony = new Harmony("com.GitHub.IGNOREDSOUL.LethalSex.LethalSexCore");

		internal const string modVersion = "2.0.1";

		private const string modGUID = "com.GitHub.IGNOREDSOUL.LethalSex.LethalSexCore";

		private const string modName = "LethalSex-Core";

		private const string waterMark = "\r\n ▄▀▀▀▀▄     ▄▀▀█▄▄▄▄  ▄▀▀▀█▀▀▄  ▄▀▀▄ ▄▄   ▄▀▀█▄   ▄▀▀▀▀▄         ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄  ▄▀▄\r\n█    █     ▐  ▄▀   ▐ █    █  ▐ █  █   ▄▀ ▐ ▄▀ ▀▄ █    █         █ █   ▐ ▐  ▄▀   ▐ █    █   █\r\n▐    █       █▄▄▄▄▄  ▐   █     ▐  █▄▄▄█    █▄▄▄█ ▐    █            ▀▄     █▄▄▄▄▄  ▐     ▀▄▀\r\n    █        █    ▌     █         █   █   ▄▀   █     █          ▀▄   █    █    ▌       ▄▀ █\r\n  ▄▀▄▄▄▄▄▄▀ ▄▀▄▄▄▄    ▄▀         ▄▀  ▄▀  █   ▄▀    ▄▀▄▄▄▄▄▄▀     █▀▀▀    ▄▀▄▄▄▄       █  ▄▀\r\n  █         █    ▐   █          █   █    ▐   ▐     █             ▐       █    ▐     ▄▀  ▄▀\r\n  ▐         ▐        ▐ IGNORED  ▐   ▐   SOUL       ▐                     ▐         █    ▐    ";

		protected internal static List<LethalMod> LethalMods = new List<LethalMod>();

		public static Main instance { get; private set; }

		internal static ManualLogSource mls { get; private set; }

		internal static LethalMod CoreMod { get; private set; }

		internal static AssetBundle bundle { get; private set; }

		private void Awake()
		{
			while (!Object.op_Implicit((Object)(object)instance))
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("LethalSex-Core");
			mls.LogError((object)"\r\n ▄▀▀▀▀▄     ▄▀▀█▄▄▄▄  ▄▀▀▀█▀▀▄  ▄▀▀▄ ▄▄   ▄▀▀█▄   ▄▀▀▀▀▄         ▄▀▀▀▀▄  ▄▀▀█▄▄▄▄  ▄▀▀▄  ▄▀▄\r\n█    █     ▐  ▄▀   ▐ █    █  ▐ █  █   ▄▀ ▐ ▄▀ ▀▄ █    █         █ █   ▐ ▐  ▄▀   ▐ █    █   █\r\n▐    █       █▄▄▄▄▄  ▐   █     ▐  █▄▄▄█    █▄▄▄█ ▐    █            ▀▄     █▄▄▄▄▄  ▐     ▀▄▀\r\n    █        █    ▌     █         █   █   ▄▀   █     █          ▀▄   █    █    ▌       ▄▀ █\r\n  ▄▀▄▄▄▄▄▄▀ ▄▀▄▄▄▄    ▄▀         ▄▀  ▄▀  █   ▄▀    ▄▀▄▄▄▄▄▄▀     █▀▀▀    ▄▀▄▄▄▄       █  ▄▀\r\n  █         █    ▐   █          █   █    ▐   ▐     █             ▐       █    ▐     ▄▀  ▄▀\r\n  ▐         ▐        ▐ IGNORED  ▐   ▐   SOUL       ▐                     ▐         █    ▐    ");
			bundle = AssetBundle.LoadFromMemory(resources.lethalsex_core);
			new Config().Init();
			harmony.PatchAll(typeof(Patching));
			CoreMod = RegisterMod("LethalSex-Core", "2.0.1", "IGNOREDSOUL");
			CoreMod.RegisterModule(typeof(ConsoleManager));
			CoreMod.RegisterModule(typeof(SanityEventManager));
		}

		public static LethalMod RegisterMod(string modName, string modVersion, string modAuthor)
		{
			LethalMod lethalMod = new LethalMod(Assembly.GetCallingAssembly().GetName().Name, modName, modVersion, modAuthor);
			mls.LogMessage((object)("[" + modAuthor + "] created a new mod of: [" + modName + " v" + modVersion + "]"));
			ConsoleManager.Log("[" + modAuthor + "] created a new mod of: [" + modName + " v" + modVersion + "]");
			LethalMods.Add(lethalMod);
			return lethalMod;
		}
	}
	[HarmonyPatch]
	public static class Patching
	{
		private static float prev_san { get; set; } = -666f;


		[HarmonyPatch(typeof(HUDManager), "Start")]
		[HarmonyPostfix]
		private static void ONHUDSTART()
		{
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONHUDSTART. Failed to send OnHUDStart to module: " + module.ModuleName, delegate
					{
						module?.OnHUDStart();
					});
				});
			});
		}

		[HarmonyPatch(typeof(HUDManager), "Awake")]
		[HarmonyPostfix]
		private static void ONHUDAWAKE()
		{
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONHUDAWAKE. Failed to send OnHUDAwake to module: " + module.ModuleName, delegate
					{
						module?.OnHUDAwake();
					});
				});
			});
		}

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		private static void ONHUDUPDATE()
		{
			ONSANITYCHANGED();
		}

		[HarmonyPatch(typeof(StartOfRound), "OnShipLandedMiscEvents")]
		[HarmonyPostfix]
		private static void ONSHIPLAND()
		{
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONSHIPLAND. Failed to send OnShipLand to module: " + module.ModuleName, delegate
					{
						module?.OnShipLand();
					});
				});
			});
		}

		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		private static void ONLOCALSTART(PlayerControllerB __instance)
		{
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONPLAYERSTART. Failed to send OnHUDAwake to module: " + module.ModuleName, delegate
					{
						module?.OnLocalStart(__instance);
					});
				});
			});
		}

		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		[HarmonyPostfix]
		private static void ONLOCALDIE()
		{
			PlayerControllerB? playerController = LocalPlayer.PlayerController;
			if (((playerController != null) ? new bool?(!playerController.isPlayerDead) : null).Value)
			{
				return;
			}
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONKILLPLAYER. Failed to send OnLocalPlayerDie to module: " + module.ModuleName, delegate
					{
						module?.OnLocalDie();
					});
				});
			});
		}

		[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
		[HarmonyPostfix]
		private static void ONGRABOBJECT()
		{
			PlayerControllerB? playerController = LocalPlayer.PlayerController;
			if (((playerController != null) ? new bool?(!playerController.isPlayerDead) : null).Value || !LocalPlayer.Interected)
			{
				return;
			}
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONGRABOBJECT. Failed to send OnGrabObject to module: " + module.ModuleName, delegate
					{
						//IL_000f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0023: Unknown result type (might be due to invalid IL or missing references)
						//IL_0028: Unknown result type (might be due to invalid IL or missing references)
						RaycastHit val = default(RaycastHit);
						if (Physics.Raycast(new Ray(((Component)LocalPlayer.PlayerController.gameplayCamera).transform.position, ((Component)LocalPlayer.PlayerController.gameplayCamera).transform.forward), ref val, LocalPlayer.PlayerController.grabDistance, 832))
						{
							Collider collider = ((RaycastHit)(ref val)).collider;
							object obj;
							if (collider == null)
							{
								obj = null;
							}
							else
							{
								GameObject gameObject = ((Component)((Component)collider).transform).gameObject;
								obj = ((gameObject != null) ? gameObject.GetComponent<GrabbableObject>() : null);
							}
							if ((Object)obj != (Object)null)
							{
								module?.OnGrabObject(((Component)((Component)((RaycastHit)(ref val)).collider).transform).gameObject.GetComponent<GrabbableObject>());
							}
						}
					});
				});
			});
		}

		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingLevel")]
		[HarmonyPostfix]
		private static void ONFINISHEDGEN()
		{
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONFINISHEDGEN. Failed to send OnFinishedGen to module: " + module.ModuleName, delegate
					{
						module?.OnFinishedGen();
					});
				});
			});
		}

		private static void ONSANITYCHANGED()
		{
			if (!Object.op_Implicit((Object)(object)LocalPlayer.Player) || (LocalPlayer.PlayerController?.isPlayerDead).Value || prev_san == float.Parse(LocalPlayer.Insanity.ToString("0.0")))
			{
				return;
			}
			prev_san = float.Parse(LocalPlayer.Insanity.ToString("0.0"));
			Main.LethalMods.ForEach(delegate(LethalMod mod)
			{
				mod.Modules.ForEach(delegate(LethalModule module)
				{
					Extensions.TryCatch("An error occoured at ONSANITYCHANGED. Failed to send OnSanityChanged to module: " + module.ModuleName, delegate
					{
						module?.OnSanityChanged(LocalPlayer.Insanity);
					});
				});
			});
		}
	}
}
namespace LethalSex_Core.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("LethalSex_Core.Properties.resources", typeof(resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] lethalsex_core => (byte[])ResourceManager.GetObject("lethalsex_core", resourceCulture);

		internal resources()
		{
		}
	}
}
namespace LethalSex_Core.Modules
{
	public class ConsoleManager : LethalModule
	{
		private static StringBuilder _consoleTextBuffer = new StringBuilder();

		public static ConsoleManager instance { get; private set; }

		public static ConsoleManager component { get; private set; }

		public static TextMeshProUGUI ConsoleText { get; private set; }

		public static GameObject ConsoleObject { get; private set; }

		public static ScrollRect ConsoleScroll { get; private set; }

		public override void OnRegister()
		{
			if (!Config.ToggleDebugConsole)
			{
				base.Mod.UnregisterModule(this);
			}
			instance = this;
		}

		public override void OnHUDAwake()
		{
			if (!Object.op_Implicit((Object)(object)ConsoleObject))
			{
				ConsoleObject = Object.Instantiate<GameObject>(Main.bundle.LoadAsset<GameObject>("assets/lethalsex-core/console/ls-console.prefab"), GameObject.Find("Systems/UI/Canvas/").transform);
				ConsoleText = ((Component)ConsoleObject.transform.Find("ConsoleArea/Viewport/ConsoleText")).GetComponent<TextMeshProUGUI>();
				ConsoleScroll = ((Component)ConsoleObject.transform.Find("ConsoleArea")).GetComponent<ScrollRect>();
				if (Object.op_Implicit((Object)(object)ConsoleText) && Object.op_Implicit((Object)(object)ConsoleScroll))
				{
					((TMP_Text)ConsoleText).text = _consoleTextBuffer.ToString();
				}
				component = ConsoleObject.AddComponent<ConsoleManager>();
				((TMP_Text)((Component)ConsoleObject.transform.Find("ConsoleArea/ConsoleBackground/GameVersion")).GetComponent<TextMeshProUGUI>()).text = "v2.0.1";
			}
		}

		private void Update()
		{
			if (((ButtonControl)Keyboard.current.f10Key).wasPressedThisFrame && Object.op_Implicit((Object)(object)ConsoleObject))
			{
				GameObject consoleObject = ConsoleObject;
				if (consoleObject != null)
				{
					((Component)consoleObject.transform.GetChild(0)).gameObject.SetActive(!((Component)ConsoleObject.transform.GetChild(0)).gameObject.activeInHierarchy);
				}
			}
			if (InputControlExtensions.IsPressed((InputControl)(object)Keyboard.current.spaceKey, 0f) && Object.op_Implicit((Object)(object)ConsoleScroll))
			{
				ConsoleScroll.verticalNormalizedPosition = 0f;
			}
		}

		public static void Log(object msg)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Log(msg, "Info", Color.cyan);
		}

		public static void Error(object msg)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Log(msg, "Error", Color.red);
		}

		public static void Warn(object msg)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Log(msg, "Warn", Color.yellow);
		}

		public static void Log(object msg, Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Log(msg, "Info", color);
		}

		public static void Log(object msg, object prefix)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			Log(msg, prefix, Color.cyan);
		}

		public static void Log(object msg, object prefix, Color color)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			_consoleTextBuffer.Append($"[{DateTimeOffset.Now:hh:mm:ss:ff}] [{Extensions.ColorWrap($"{prefix}", Extensions.HexColor(color))}] ~> {msg}\n");
			if (Object.op_Implicit((Object)(object)ConsoleObject) && Object.op_Implicit((Object)(object)ConsoleText) && Object.op_Implicit((Object)(object)ConsoleScroll))
			{
				((TMP_Text)ConsoleText).text = _consoleTextBuffer.ToString();
			}
		}

		private void OnDestroy()
		{
			base.Destroyed();
		}

		private void OnDisable()
		{
			base.Disabled();
		}

		private void OnEnable()
		{
			base.Enabled();
		}
	}
	internal class SanityEventManager : LethalModule
	{
		protected List<Event> events = new List<Event>();

		public static SanityEventManager Instance { get; private set; }

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

		public void New(float sanity, Action onAct = null, Action offAct = null)
		{
			events.Add(new Event(sanity, onAct, offAct));
		}

		public override void OnSanityChanged(float sanity)
		{
			Event[] array = events.Where((Event i) => i.Sanity < sanity).ToArray();
			foreach (Event item in array)
			{
				int num = events.IndexOf(item);
				if (num != -1 && !events[num].Applied)
				{
					Event value = events[num];
					value.Applied = true;
					events[num] = value;
					value.OnAction?.Invoke();
				}
			}
			array = events.Where((Event i) => i.Sanity >= sanity).ToArray();
			foreach (Event item2 in array)
			{
				int num2 = events.IndexOf(item2);
				if (num2 != -1 && events[num2].Applied)
				{
					Event value2 = events[num2];
					value2.Applied = false;
					events[num2] = value2;
					value2.OffAction?.Invoke();
				}
			}
		}
	}
}