Decompiled source of LBM ALL MODS v1.0.0

BepInEx/config/TerminalCommander.dll

Decompiled 10 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.Logging;
using HarmonyLib;
using TMPro;
using TerminalApi;
using TerminalApi.Classes;
using TerminalCommander.Patches;
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.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace TerminalCommander
{
	[BepInPlugin("Tronald.TerminalCommander", "TerminalCommander", "1.0.0")]
	public class Commander : BaseUnityPlugin
	{
		public const string modGUID = "Tronald.TerminalCommander";

		public const string modName = "TerminalCommander";

		public const string modVersion = "1.0.0";

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

		private static Commander instance;

		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!");
			harmony.PatchAll(typeof(Commander));
			harmony.PatchAll(typeof(TerminalPatch));
			TerminalPatch.SetSource(this);
		}
	}
}
namespace TerminalCommander.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		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;
			SetCommands();
		}

		private static TerminalKeyword CheckForExactSentences(Terminal t, string playerWord)
		{
			for (int i = 0; i < t.terminalNodes.allKeywords.Length; i++)
			{
				if (t.terminalNodes.allKeywords[i].word == playerWord)
				{
					return t.terminalNodes.allKeywords[i];
				}
			}
			return null;
		}

		[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))
				{
					return;
				}
				Terminal val = FindActiveTerminal();
				RoundManager val2 = FindRoundManager();
				if ((Object)(object)val == (Object)null)
				{
					logSource.LogInfo((object)"TerminalCommander ERROR: Terminal could not be found.");
				}
				if (UnityInput.Current.GetKeyDown((KeyCode)115))
				{
					string text = "switch";
					TMP_InputField screenText = val.screenText;
					screenText.text += text;
					val.textAdded = text.Length;
					val.OnSubmit();
				}
				else if (UnityInput.Current.GetKeyDown((KeyCode)116))
				{
					TMP_InputField obj = ___screenText;
					obj.text += "transmit ";
				}
				else if (UnityInput.Current.GetKeyDown((KeyCode)100))
				{
					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(val, "Opening all doors\n\n");
						openDoors = false;
					}
					else
					{
						SetTerminalText(val, "Closing all doors\n\n");
						openDoors = true;
					}
					val.terminalAudio.PlayOneShot(val.codeBroadcastSFX, 1f);
					val.codeBroadcastAnimator.SetTrigger("display");
					logSource.LogInfo((object)string.Format("{0} TerminalAccessibleObjects Called: Count{1} - ({2})", "TerminalCommander", source.Count(), string.Join(", ", list)));
				}
				else if (UnityInput.Current.GetKeyDown((KeyCode)106))
				{
					TerminalAccessibleObject[] source2 = (from x in Object.FindObjectsOfType<TerminalAccessibleObject>()
						select (x)).ToArray();
					List<string> list2 = new List<string>();
					foreach (TerminalAccessibleObject item2 in source2.Where((TerminalAccessibleObject x) => ((Object)x).name.ToLower() == turretName || ((Object)x).name.ToLower() == landmineName))
					{
						list2.Add(item2.objectCode);
						item2.CallFunctionFromTerminal();
					}
					SetTerminalText(val, "Jamming turrets and land mines\n\n");
					val.terminalAudio.PlayOneShot(val.codeBroadcastSFX, 1f);
					val.codeBroadcastAnimator.SetTrigger("display");
					logSource.LogInfo((object)string.Format("{0} TerminalAccessibleObjects Called: Count{1} - ({2})", "TerminalCommander", source2.Count(), string.Join(", ", list2)));
				}
				else if (UnityInput.Current.GetKeyDown((KeyCode)109))
				{
					string text2 = "view monitor";
					TMP_InputField screenText2 = val.screenText;
					screenText2.text += text2;
					val.textAdded = text2.Length;
					val.OnSubmit();
				}
			}
			catch (Exception ex)
			{
				logSource.LogInfo((object)("TerminalCommander ERROR: " + ex.Message));
			}
		}

		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 Terminal FindActiveTerminal()
		{
			Terminal[] array = Object.FindObjectsOfType<Terminal>();
			if (array.Length != 0)
			{
				return array[0];
			}
			return null;
		}

		private static RoundManager FindRoundManager()
		{
			RoundManager[] array = Object.FindObjectsOfType<RoundManager>();
			if (array.Length != 0)
			{
				return array[0];
			}
			return null;
		}

		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
			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);
		}

		private static string OnHotKeyHelpCommand()
		{
			return ">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.";
		}
	}
}