Decompiled source of Pollygonsfunpack v1.0.5

BepInEx/config/TerminalCommander.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using TerminalApi;
using TerminalApi.Classes;
using TerminalCommander.Patches;
using Unity.Netcode;
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: AssemblyTitle("Terminal Commander")]
[assembly: AssemblyDescription("Terminal Commander is a mod for Lethal Company designed to enhance your terminal operation experience by introducing convenient hotkeys. This mod simplifies various tasks, allowing you to manage turrets, landmines, player views, and communication more efficiently.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Tronal")]
[assembly: AssemblyProduct("Terminal Commander")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a339852b-b956-4a52-89e6-21f22b77c5cc")]
[assembly: AssemblyFileVersion("1.7.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.7.0.0")]
namespace TerminalCommander
{
	public class TerminalCommanderConfiguration
	{
		public bool AllowJamming { get; set; }

		public void Set_Configs(Commander c)
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)c).Config.Bind<bool>("General", "Allow Jamming", true, "If false, removes turret and mine jamming ability.");
			AllowJamming = val.Value;
			((BaseUnityPlugin)c).Config.Bind<KeyCode>("General", "Jamming Hot Key (Ctrl+)", (KeyCode)106, "If false, removes turret and mine jamming ability.");
		}

		public void Set_Configs(TerminalCommanderConfiguration hostConfig)
		{
			AllowJamming = hostConfig.AllowJamming;
		}
	}
	public class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance;

		private Commander commander;

		public NetworkHandler(Commander c)
		{
			commander = c;
		}

		private void Awake()
		{
			Instance = this;
		}

		public void SyncConfigs(TerminalCommanderConfiguration config)
		{
			if (((NetworkBehaviour)this).IsServer)
			{
				SyncConfigsClientRpc(config);
			}
			else
			{
				SynConfigsServerRpc(config);
			}
		}

		[ClientRpc]
		private void SyncConfigsClientRpc(TerminalCommanderConfiguration config)
		{
			commander.Configs.Set_Configs(config);
		}

		[ServerRpc]
		private void SynConfigsServerRpc(TerminalCommanderConfiguration config)
		{
			SyncConfigsClientRpc(config);
		}
	}
	[BepInPlugin("Tronald.TerminalCommander", "TerminalCommander", "1.7.0")]
	public class Commander : BaseUnityPlugin
	{
		public const string modGUID = "Tronald.TerminalCommander";

		public const string modName = "TerminalCommander";

		public const string modVersion = "1.7.0";

		private readonly Harmony harmony = new Harmony("Tronald.TerminalCommander");

		private static Commander instance;

		public TerminalCommanderConfiguration Configs = new TerminalCommanderConfiguration();

		public NetworkHandler NetworkHandler;

		internal ManualLogSource log;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			log = Logger.CreateLogSource("Tronald.TerminalCommander");
			log.LogInfo((object)"TerminalCommander is loaded!");
			TerminalHotkeys.SetSource(this);
			TerminalCommands.SetSource(this);
			harmony.PatchAll(typeof(Commander));
			harmony.PatchAll(typeof(TerminalHotkeys));
			harmony.PatchAll(typeof(TerminalCommands));
		}
	}
}
namespace TerminalCommander.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class GameManagement
	{
		private static ManualLogSource logSource;

		private static Commander commanderSource;

		public static void SetSource(Commander source)
		{
			commanderSource = source;
			logSource = commanderSource.log;
		}

		[HarmonyPatch("OnClientConnect")]
		[HarmonyPostfix]
		private static void FollowHostConfigurationPatch(StartOfRound __instance, ulong clientId)
		{
			try
			{
				if (((NetworkBehaviour)__instance).IsServer)
				{
					logSource.LogInfo((object)"TerminalCommander syncing configurations for new player.");
					commanderSource.NetworkHandler.SyncConfigs(commanderSource.Configs);
				}
			}
			catch (Exception ex)
			{
				logSource.LogInfo((object)("TerminalCommander GAME MANAGEMENT ERROR (CONFIGS NOT SYNCED): " + ex.Message));
			}
		}

		[HarmonyPatch("PlayerLoadedServerRpc")]
		[HarmonyPostfix]
		private static void PushHostConfigurationPatch(StartOfRound __instance, ulong clientId)
		{
			try
			{
				if (((NetworkBehaviour)__instance).IsServer)
				{
					logSource.LogInfo((object)"TerminalCommander syncing configurations to server.");
					commanderSource.NetworkHandler.SyncConfigs(commanderSource.Configs);
				}
			}
			catch (Exception ex)
			{
				logSource.LogInfo((object)("TerminalCommander GAME MANAGEMENT ERROR (CONFIGS NOT SYNCED TO SERVER): " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalCommands
	{
		private static ManualLogSource logSource;

		private static Commander commanderSource;

		public static void SetSource(Commander source)
		{
			commanderSource = source;
			logSource = commanderSource.log;
			SetCommands();
		}

		private static void SetCommands()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			CommandInfo val = new CommandInfo();
			val.Category = "help";
			val.Description = "View the Terminal Commander hotkeys and commands.";
			val.DisplayTextSupplier = OnHotKeyHelpCommand;
			TerminalApi.AddCommand("Commander", val, (string)null, true);
			val = new CommandInfo();
			val.Category = "Commander";
			val.DisplayTextSupplier = TeleportCommand;
			TerminalApi.AddCommand("tp", val, (string)null, true);
			val = new CommandInfo();
			val.Category = "Commander";
			val.DisplayTextSupplier = InverseTeleportCommand;
			TerminalApi.AddCommand("itp", val, (string)null, true);
		}

		private static string OnHotKeyHelpCommand()
		{
			return "HOTKEYS\n\n>Ctrl+D\nOpen / close all doors.\n\n>Ctrl+J\nJam all turrets and land mines.\n\n>Ctrl+M\nTurn monitor on and off.\n\n>Ctrl+S\nQuickly switch players on the monitor.\n\n>Ctrl+T\nBegin a signal transmission command.\n\nCOMMANDS\n\n>TP\nTeleport currently viewed player on monitor.\n\n>ITP\nActivate inverse teleporter.\n\n";
		}

		private static string TeleportCommand()
		{
			ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
			if (array != null && array.Length != 0)
			{
				ShipTeleporter[] array2 = array;
				foreach (ShipTeleporter val in array2)
				{
					if (!val.isInverseTeleporter)
					{
						val.PressTeleportButtonOnLocalClient();
						return "Teleporting...\n\n";
					}
				}
			}
			return "Nuh uh, no teleporter\n\n";
		}

		private static string EntranceTeleportCommand()
		{
			EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>();
			if (array == null || array.Length == 0)
			{
				return "No inverse teleporter detected.\n\n";
			}
			EntranceTeleport val = array[0];
			val.TeleportPlayer();
			return "Teleporting...\n\n";
		}

		private static string InverseTeleportCommand()
		{
			ShipTeleporter[] array = Object.FindObjectsOfType<ShipTeleporter>();
			if (array != null && array.Length != 0)
			{
				ShipTeleporter[] array2 = array;
				foreach (ShipTeleporter val in array2)
				{
					if (val.isInverseTeleporter)
					{
						if (!StartOfRound.Instance.shipHasLanded)
						{
							return "Cannot inverse teleport until ship has fully landed and stabilized.\n\n";
						}
						FieldInfo field = ((object)val).GetType().GetField("cooldownTime", BindingFlags.Instance | BindingFlags.NonPublic);
						float num = (float)field.GetValue(val);
						if (num > 0f)
						{
							return $"Cooldown time for inverse teleporter: {Math.Round(num)} seconds.\n\n";
						}
						val.PressTeleportButtonOnLocalClient();
						return "Teleporting...\n\n";
					}
				}
			}
			return "Nuh uh, no inverse teleporter\n\n";
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalHotkeys
	{
		private static string turretName = "turretscript";

		private static string landmineName = "landmine";

		private static string doorName = "bigdoor";

		private static bool openDoors = true;

		private static ManualLogSource logSource;

		private static Commander commanderSource;

		public static void SetSource(Commander source)
		{
			commanderSource = source;
			logSource = commanderSource.log;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void HotKeyPatch(ref bool ___terminalInUse, ref TMP_InputField ___screenText)
		{
			try
			{
				if ((___terminalInUse && UnityInput.Current.GetKey((KeyCode)306)) || UnityInput.Current.GetKey((KeyCode)305))
				{
					Terminal val = FindActiveObject<Terminal>();
					if ((Object)(object)val == (Object)null)
					{
						logSource.LogInfo((object)"TerminalCommander ERROR: Terminal could not be found.");
					}
					if (UnityInput.Current.GetKeyDown((KeyCode)115))
					{
						SwitchPlayer(val);
					}
					else if (UnityInput.Current.GetKeyDown((KeyCode)116))
					{
						Transmission(val, ___screenText);
					}
					else if (UnityInput.Current.GetKeyDown((KeyCode)100))
					{
						OperateBigDoors(val);
					}
					else if (UnityInput.Current.GetKeyDown((KeyCode)106))
					{
						JamTurrentMines(val);
					}
					else if (UnityInput.Current.GetKeyDown((KeyCode)109))
					{
						ViewMonitor(val);
					}
				}
			}
			catch (Exception ex)
			{
				logSource.LogInfo((object)("TerminalCommander ERROR: " + ex.Message));
			}
		}

		private static void SwitchPlayer(Terminal t)
		{
			string text = "switch";
			TMP_InputField screenText = t.screenText;
			screenText.text += text;
			t.textAdded = text.Length;
			t.OnSubmit();
		}

		private static void Transmission(Terminal t, TMP_InputField ___screenText)
		{
			___screenText.text += "transmit ";
		}

		private static void OperateBigDoors(Terminal t)
		{
			TerminalAccessibleObject[] source = (from x in Object.FindObjectsOfType<TerminalAccessibleObject>()
				select (x)).ToArray();
			List<string> list = new List<string>();
			foreach (TerminalAccessibleObject item in source.Where((TerminalAccessibleObject x) => ((Object)x).name.ToLower().Contains(doorName)))
			{
				if (!item.isBigDoor)
				{
					return;
				}
				list.Add(item.objectCode);
				item.SetDoorLocalClient(openDoors);
			}
			if (openDoors)
			{
				SetTerminalText(t, "Opening all doors\n\n");
				openDoors = false;
			}
			else
			{
				SetTerminalText(t, "Closing all doors\n\n");
				openDoors = true;
			}
			t.terminalAudio.PlayOneShot(t.codeBroadcastSFX, 1f);
			t.codeBroadcastAnimator.SetTrigger("display");
			logSource.LogInfo((object)string.Format("{0} TerminalAccessibleObjects Called: Count{1} - ({2})", "TerminalCommander", source.Count(), string.Join(", ", list)));
		}

		private static void SetTerminalText(Terminal t, string s)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			TerminalNode val = new TerminalNode();
			val.clearPreviousText = true;
			val.acceptAnything = false;
			val.displayText = s;
			t.LoadNewNode(val);
			t.screenText.ActivateInputField();
			((Selectable)t.screenText).Select();
		}

		private static void JamTurrentMines(Terminal t)
		{
			TerminalAccessibleObject[] source = (from x in Object.FindObjectsOfType<TerminalAccessibleObject>()
				select (x)).ToArray();
			List<string> list = new List<string>();
			foreach (TerminalAccessibleObject item in source.Where((TerminalAccessibleObject x) => ((Object)x).name.ToLower() == turretName || ((Object)x).name.ToLower() == landmineName))
			{
				list.Add(item.objectCode);
				item.CallFunctionFromTerminal();
			}
			SetTerminalText(t, "Jamming turrets and land mines\n\n");
			t.terminalAudio.PlayOneShot(t.codeBroadcastSFX, 1f);
			t.codeBroadcastAnimator.SetTrigger("display");
			logSource.LogInfo((object)string.Format("{0} TerminalAccessibleObjects Called: Count{1} - ({2})", "TerminalCommander", source.Count(), string.Join(", ", list)));
		}

		private static void ViewMonitor(Terminal t)
		{
			string text = "view monitor";
			TMP_InputField screenText = t.screenText;
			screenText.text += text;
			t.textAdded = text.Length;
			t.OnSubmit();
		}

		private static T FindActiveObject<T>() where T : Object
		{
			T[] array = Object.FindObjectsOfType<T>();
			if (array.Length != 0)
			{
				return array[0];
			}
			return default(T);
		}
	}
}