Decompiled source of LobotomyMod v1.0.0

LobotomyMod.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LobotomyMod.Patches;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LobotomyMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lobotomy Mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LobotomyMod")]
[assembly: AssemblyTitle("LobotomyMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 LobotomyMod
{
	[BepInPlugin("LobotomyMod", "LobotomyMod", "1.0.0")]
	public class LobotomyMod : BaseUnityPlugin
	{
		private protected Harmony harmony = new Harmony("rudynakodach.LobotomyMod");

		public static ManualLogSource LogSource { get; private set; }

		private void Awake()
		{
			LogSource = Logger.CreateLogSource("rudynakodach.LobotomyMod");
			harmony.PatchAll(typeof(LobotomyPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			LogSource.LogInfo((object)"Plugin LobotomyMod is loaded!");
		}
	}
	public class LobotomyControllerB : MonoBehaviour
	{
		private PlayerControllerB playerController;

		private RawImage rawImage;

		private bool isLobotomyAttackActive = false;

		private bool isUiReady = false;

		public bool lobotomyControllerStarted = false;

		public bool isActive = true;

		public static LobotomyControllerB instance { get; private set; }

		private void Awake()
		{
			playerController = GameNetworkManager.Instance.localPlayerController;
		}

		private void Update()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			if (!isUiReady)
			{
				if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController.gameplayCamera == (Object)null))
				{
					GameObject val = new GameObject("LobotomyModCanvas");
					val = Object.Instantiate<GameObject>(val);
					val.transform.parent = ((Component)GameNetworkManager.Instance.localPlayerController.gameplayCamera).gameObject.transform;
					Canvas val2 = val.AddComponent<Canvas>();
					val2.renderMode = (RenderMode)0;
					val2.sortingOrder = 100;
					GameObject val3 = new GameObject("LobotomyModOverlay");
					val3 = Object.Instantiate<GameObject>(val3);
					val3.transform.parent = val.transform;
					rawImage = val3.AddComponent<RawImage>();
					((Graphic)rawImage).material = new Material(((Graphic)rawImage).material);
					((Object)((Graphic)rawImage).material).name = "LobotomyModUIMaterial";
					((Graphic)rawImage).raycastTarget = false;
					((Graphic)rawImage).rectTransform.sizeDelta = new Vector2((float)Screen.width, (float)Screen.height);
					((Graphic)rawImage).rectTransform.anchoredPosition = Vector2.zero;
					((Graphic)rawImage).color = Color.white;
					((Component)rawImage).gameObject.SetActive(false);
					isUiReady = true;
					instance = this;
					LobotomyMod.LogSource.LogDebug((object)"Lobotomy UI ready!");
				}
			}
			else if (isActive)
			{
				if (!((Object)(object)playerController == (Object)null))
				{
					if (playerController.criticallyInjured && !lobotomyControllerStarted)
					{
						LobotomyMod.LogSource.LogDebug((object)"Started invoking LobotomyContorller.");
						((MonoBehaviour)this).InvokeRepeating("LobotomyController", 1f, 1f);
						lobotomyControllerStarted = true;
					}
					else if ((!playerController.criticallyInjured || playerController.isPlayerDead) && lobotomyControllerStarted)
					{
						LobotomyMod.LogSource.LogDebug((object)"Stopped invoking LobotomyContorller.");
						((MonoBehaviour)this).CancelInvoke("LobotomyController");
						lobotomyControllerStarted = false;
					}
				}
			}
			else if (lobotomyControllerStarted)
			{
				((MonoBehaviour)this).CancelInvoke();
			}
		}

		private IEnumerator fadeLobotomyOut(Action callback)
		{
			Color originalColor = ((Graphic)rawImage).color;
			Color targetColor = new Color(originalColor.r, originalColor.g, originalColor.b, 0f);
			float fadeOutTime = Random.Range(0.75f, 1.75f);
			for (float elapsedTime = 0f; elapsedTime < fadeOutTime; elapsedTime += Time.deltaTime)
			{
				((Graphic)rawImage).color = Color.Lerp(originalColor, targetColor, elapsedTime / fadeOutTime);
				yield return null;
			}
			((Graphic)rawImage).color = targetColor;
			callback();
		}

		private IEnumerator recordFrame(Action<Texture2D> callback)
		{
			yield return (object)new WaitForEndOfFrame();
			Texture2D texture = ScreenCapture.CaptureScreenshotAsTexture();
			callback(texture);
		}

		private IEnumerator stopAttack()
		{
			yield return (object)new WaitForSeconds(Random.Range(0.35f, 0.75f));
			((MonoBehaviour)this).StartCoroutine(fadeLobotomyOut(delegate
			{
				isLobotomyAttackActive = false;
				((Component)rawImage).gameObject.SetActive(false);
			}));
		}

		private IEnumerator startAttack(Texture2D texture)
		{
			yield return (object)new WaitForSeconds(Random.Range(0.35f, 0.75f));
			((Graphic)rawImage).material.mainTexture = (Texture)(object)texture;
			((Component)rawImage).gameObject.SetActive(true);
			((MonoBehaviour)this).StartCoroutine(stopAttack());
		}

		private void LobotomyController()
		{
			if (!isLobotomyAttackActive && Random.Range(0f, 100f) < 5f)
			{
				((MonoBehaviour)this).StartCoroutine(recordFrame(delegate(Texture2D texture)
				{
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					LobotomyMod.LogSource.LogInfo((object)"Starting a lobotomy attack...");
					((Graphic)rawImage).color = new Color(0.85f, 0.85f, 0.85f, 0.85f);
					isLobotomyAttackActive = true;
					((MonoBehaviour)this).StartCoroutine(startAttack(texture));
				}));
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LobotomyMod";

		public const string PLUGIN_NAME = "LobotomyMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LobotomyMod.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class LobotomyPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void patch(PlayerControllerB __instance)
		{
			if ((Object)(object)((Component)__instance).gameObject.GetComponent<LobotomyControllerB>() == (Object)null)
			{
				if (!((Component)__instance).gameObject.activeInHierarchy)
				{
					LobotomyMod.LogSource.LogDebug((object)("Player " + ((Object)((Component)__instance).gameObject).name + " isn't active in hierarchy - skipping the lobotomy controller."));
				}
				else
				{
					((MonoBehaviour)__instance).StartCoroutine(WaitForLocalPlayerControllerAndAddALobotomyControllerIfItIsTheLocalPlayer(__instance));
				}
			}
		}

		private static IEnumerator WaitForLocalPlayerControllerAndAddALobotomyControllerIfItIsTheLocalPlayer(PlayerControllerB other)
		{
			while ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				yield return null;
			}
			if ((Object)(object)other == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				LobotomyMod.LogSource.LogDebug((object)("Ownership of player controller for " + ((Object)other).name + " confirmed!"));
				((Component)other).gameObject.AddComponent<LobotomyControllerB>();
			}
			else
			{
				LobotomyMod.LogSource.LogDebug((object)("Ownership of player controller for " + ((Object)other).name + " failed."));
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("EndOfGame")]
		[HarmonyPrefix]
		private static void EndOfGamePatch()
		{
			if ((Object)(object)LobotomyControllerB.instance != (Object)null)
			{
				LobotomyControllerB.instance.isActive = false;
			}
		}

		[HarmonyPatch("StartGame")]
		[HarmonyPrefix]
		private static void StartOfGamePatch()
		{
			if ((Object)(object)LobotomyControllerB.instance != (Object)null)
			{
				LobotomyControllerB.instance.isActive = true;
			}
		}
	}
}