Decompiled source of LBM Base QoL v1.0.4

BepInEx/config/TerminalCommander.dll

Decompiled 6 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 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.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.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.SetLogSource(log);
		}
	}
}
namespace TerminalCommander.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		private static string turretName = "turretscript";

		private static string landmineName = "landmine";

		private static ManualLogSource logSource;

		public static void SetLogSource(ManualLogSource log)
		{
			logSource = 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))
				{
					return;
				}
				Terminal val = FindActiveTerminal();
				if ((Object)(object)val == (Object)null)
				{
					logSource.LogInfo((object)"TerminalCommander ERROR: Terminal could not be found.");
				}
				if (UnityInput.Current.GetKeyDown((KeyCode)115))
				{
					TerminalNode val2 = val.terminalNodes.specialNodes[20];
					StartOfRound.Instance.mapScreen.SwitchRadarTargetForward(true);
					val.LoadNewNode(val2);
				}
				else if (UnityInput.Current.GetKeyDown((KeyCode)116))
				{
					TMP_InputField obj = ___screenText;
					obj.text += "transmit ";
				}
				else
				{
					if (!UnityInput.Current.GetKeyDown((KeyCode)106))
					{
						return;
					}
					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(val, "Jamming turrets and land mines");
					logSource.LogInfo((object)string.Format("{0} TerminalAccessibleObjects Called: Count{1} - ({2})", "TerminalCommander", source.Count(), string.Join(", ", list)));
				}
			}
			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 = "Jamming turrets and land mines.\n\n";
			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;
		}
	}
}