Decompiled source of Terminal History v1.0.5

BepInEx/plugins/Terminal History.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using TerminalApi;
using TerminalApi.Events;
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: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("Terminal History")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Terminal Command History")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b37a379d4013c9ea1604b23b463a2daa1030bc21")]
[assembly: AssemblyProduct("Terminal History")]
[assembly: AssemblyTitle("Terminal History")]
[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 TerminalHistory
{
	[BepInPlugin("atomic.terminalhistory", "Terminal History", "1.0.4")]
	[BepInDependency("atomic.terminalapi", "1.3.0")]
	[BepInDependency("com.rune580.LethalCompanyInputUtils", "0.4.2")]
	public class Plugin : BaseUnityPlugin
	{
		private const int SIZE = 20;

		private Terminal Terminal;

		private List<string> _commands = new List<string>();

		private string _commandDraft = "";

		private Keybinds _keybinds = new Keybinds();

		private int _index = -1;

		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)"\n\n\nPlugin Terminal History is loaded!\n\n\n");
			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 (_index != -1 && e.CurrentInputText != _commands[_index])
			{
				_commandDraft = e.CurrentInputText;
				_index = -1;
			}
		}

		private void OnTerminalSubmit(object sender, TerminalParseSentenceEventArgs e)
		{
			if (_commands.Contains(e.SubmittedText))
			{
				_commands.Remove(e.SubmittedText);
			}
			_commands.Insert(0, e.SubmittedText);
			if (_commands.Count > 20)
			{
				_commands.RemoveRange(20, _commands.Count - 20);
			}
			_index = -1;
		}

		private void OnTerminalExited(object sender, TerminalEventArgs e)
		{
			_keybinds.NextTerminalKey.performed -= OnUpArrowPerformed;
			_keybinds.NextTerminalKey.Disable();
			_keybinds.PrevTerminalKey.performed -= OnDownArrowPerformed;
			_keybinds.PrevTerminalKey.Disable();
			_index = -1;
			_commandDraft = "";
		}

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

		private void OnTerminalStarted(object sender, TerminalEventArgs e)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			_commands.Clear();
			_keybinds.NextTerminalKey = new InputAction("UpArrow", (InputActionType)0, "<Keyboard>/uparrow", "Press", (string)null, (string)null);
			_keybinds.PrevTerminalKey = new InputAction("DownArrow", (InputActionType)0, "<Keyboard>/downarrow", "Press", (string)null, (string)null);
			Terminal = TerminalApi.Terminal;
		}

		private void OnDownArrowPerformed(CallbackContext context)
		{
			if (_commands.Count <= 0 || !Terminal.terminalInUse)
			{
				return;
			}
			_index--;
			if (_index <= -1)
			{
				if (_index == -1)
				{
					SetTerminalText(_commandDraft);
				}
				_index = -1;
			}
			else
			{
				string terminalText = _commands[_index];
				SetTerminalText(terminalText);
			}
		}

		private void OnUpArrowPerformed(CallbackContext context)
		{
			if (Terminal.terminalInUse && _commands.Count > 0)
			{
				if (_index == -1)
				{
					_commandDraft = TerminalApi.GetTerminalInput();
				}
				_index++;
				if (_index >= _commands.Count)
				{
					_index = _commands.Count - 1;
					string terminalText = _commands[_commands.Count - 1];
					SetTerminalText(terminalText);
				}
				else
				{
					string terminalText2 = _commands[_index];
					SetTerminalText(terminalText2);
				}
			}
		}

		private void SetTerminalText(string text)
		{
			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>/downArrow", Name = "Next Command")]
		public InputAction NextTerminalKey { get; set; }

		[InputAction("<Keyboard>/upArrow", Name = "Previous Command")]
		public InputAction PrevTerminalKey { get; set; }
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Terminal History";

		public const string PLUGIN_NAME = "Terminal History";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}