Decompiled source of LCTerminalAutocomplete v1.0.7

LCTerminalAutocomplete.dll

Decompiled a year ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using TerminalApi;
using TerminalApi.Events;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCTerminalAutoselect")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCTerminalAutoselect")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("18f4d3b8-76be-44d5-b4b3-ade9ee53db90")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCTerminalAutocomplete;

[BepInPlugin("hox.lcterminalautocomplete", "Terminal Autocomplete", "0.0.1")]
[BepInDependency("atomic.terminalapi", "1.3.0")]
[BepInDependency("com.rune580.LethalCompanyInputUtils", "0.4.2")]
public class Plugin : BaseUnityPlugin
{
	private const string modGUID = "hox.lcterminalautocomplete";

	private const string modName = "Terminal Autocomplete";

	private const string modVersion = "0.0.1";

	private Terminal Terminal;

	private Keybinds _keybinds = new Keybinds();

	private string[] _commands = new string[8] { "", "help", "moons", "store", "bestiary", "storage", "other", "view monitor" };

	private int _userInput = 0;

	private int _index = 0;

	private void Awake()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Terminal Autocomplete is loaded!");
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		Events.TerminalStarted += new TerminalEventHandler(OnTerminalStarted);
		Events.TerminalExited += new TerminalEventHandler(OnTerminalExited);
		Events.TerminalBeginUsing += new TerminalEventHandler(OnTerminalBeginUsing);
		Events.TerminalParsedSentence += new TerminalParseSentenceEventHandler(OnTerminalSubmit);
		Events.TerminalTextChanged += new TerminalTextChangedEventHandler(OnTerminalTextChange);
	}

	private void OnTerminalTextChange(object sender, TerminalTextChangedEventArgs e)
	{
		if (_userInput <= 0)
		{
			_commands[0] = e.CurrentInputText;
			_index = 0;
		}
		_userInput--;
	}

	private void OnTerminalSubmit(object sender, TerminalParseSentenceEventArgs e)
	{
		_commands[0] = "";
	}

	private void OnTerminalExited(object sender, TerminalEventArgs e)
	{
		_keybinds.PrevTerminalKey.performed -= OnLeftArrowPerformed;
		_keybinds.PrevTerminalKey.Disable();
		_keybinds.NextTerminalKey.performed -= OnRightArrowPerformed;
		_keybinds.NextTerminalKey.Disable();
	}

	private void OnTerminalBeginUsing(object sender, TerminalEventArgs e)
	{
		_keybinds.PrevTerminalKey.Enable();
		_keybinds.PrevTerminalKey.performed += OnLeftArrowPerformed;
		_keybinds.NextTerminalKey.Enable();
		_keybinds.NextTerminalKey.performed += OnRightArrowPerformed;
	}

	private void OnTerminalStarted(object sender, TerminalEventArgs e)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		_keybinds.PrevTerminalKey = new InputAction("LeftArrow", (InputActionType)0, "<Keyboard>/leftarrow", "Press", (string)null, (string)null);
		_keybinds.NextTerminalKey = new InputAction("RightArrow", (InputActionType)0, "<Keyboard>/rightarrow", "Press", (string)null, (string)null);
		Terminal = TerminalApi.Terminal;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"|Plugin Terminal Autocomplete loaded keywors|");
		TerminalKeyword[] allKeywords = Terminal.terminalNodes.allKeywords;
		List<string> list = new List<string> { "" };
		for (int i = 1; i < allKeywords.Length; i++)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)(((Object)allKeywords[i]).name ?? ""));
			list.Add(((Object)allKeywords[i]).name);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"|Plugin Terminal Autocomplete loaded keywors|");
		_commands = list.ToArray();
	}

	private void OnRightArrowPerformed(CallbackContext context)
	{
		if (!Terminal.terminalInUse)
		{
			return;
		}
		for (int i = 1 + _index; i < _commands.Length - 1; i++)
		{
			if (_commands[i].Substring(0, _commands[0].Length).ToUpper() == _commands[0].ToUpper() || _commands[0].Length == 0)
			{
				_index = i;
				string terminalText = _commands[i];
				SetTerminalText(terminalText);
				break;
			}
		}
	}

	private void OnLeftArrowPerformed(CallbackContext context)
	{
		if (!Terminal.terminalInUse)
		{
			return;
		}
		for (int num = _index - 1; num >= 0; num--)
		{
			if (_commands[num].Substring(0, _commands[0].Length).ToUpper() == _commands[0].ToUpper() || _commands[0].Length == 0)
			{
				_index = num;
				string terminalText = _commands[num];
				SetTerminalText(terminalText);
				break;
			}
		}
	}

	private void SetTerminalText(string text)
	{
		_userInput = 2;
		Terminal.TextChanged(TerminalApi.Terminal.currentText.Substring(0, TerminalApi.Terminal.currentText.Length - TerminalApi.Terminal.textAdded) + text);
		Terminal.screenText.text = TerminalApi.Terminal.currentText;
		Terminal.textAdded = text.Length;
	}
}
public class Keybinds : LcInputActions
{
	[InputAction("<Keyboard>/leftArrow", Name = "Previous Command (AC)")]
	public InputAction PrevTerminalKey { get; set; }

	[InputAction("<Keyboard>/rightArrow", Name = "Next Command (AC)")]
	public InputAction NextTerminalKey { get; set; }
}