Decompiled source of TerminalHistory v1.1.0

TerminalHistory.dll

Decompiled 10 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 Keybinds;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using TerminalApi;
using TerminalApi.Classes;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TerminalHistory")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds the ability to cycle through recent terminal commands with rebindable keys.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("TerminalHistory")]
[assembly: AssemblyTitle("TerminalHistory")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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("TerminalHistory", "TerminalHistory", "1.1.0")]
	[BepInProcess("Lethal Company.exe")]
	[BepInDependency("com.rune580.LethalCompanyInputUtils", "0.4.4")]
	[BepInDependency("atomic.terminalapi", "1.5.0")]
	[BepInIncompatibility("atomic.terminalhistory")]
	public class Plugin : BaseUnityPlugin
	{
		internal static global::Keybinds.Keybinds InputActionsInstance = new global::Keybinds.Keybinds();

		private bool terminalInUse = false;

		private bool pointing = false;

		private readonly int MEMORY_LIMIT = 10;

		private int pointer = 0;

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

		private void Awake()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			Events.TerminalBeginUsing += new TerminalEventHandler(OnBeginUsing);
			Events.TerminalExited += new TerminalEventHandler(OnTerminalExit);
			Events.TerminalParsedSentence += new TerminalParseSentenceEventHandler(TextSubmitted);
			TerminalApi.AddCommand("history", new CommandInfo
			{
				Category = "other",
				Description = "Displays the most recent commands.",
				DisplayTextSupplier = delegate
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Displaying most recent commands.");
					return ParseCommandHistory(Commands);
				}
			}, "show", true);
			InputActionsInstance.InputLast.performed += delegate
			{
				if (terminalInUse)
				{
					MovePointer(increase: false);
					SendCommandLine(SafeCommandRetrieval(Commands, pointer));
				}
			};
			InputActionsInstance.InputNext.performed += delegate
			{
				if (terminalInUse)
				{
					MovePointer(increase: true);
					SendCommandLine(SafeCommandRetrieval(Commands, pointer));
				}
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TerminalHistory is loaded!");
		}

		private void OnBeginUsing(object sender, TerminalEventArgs e)
		{
			terminalInUse = true;
			pointing = false;
		}

		private void OnTerminalExit(object sender, TerminalEventArgs e)
		{
			terminalInUse = false;
			pointing = false;
		}

		private void TextSubmitted(object sender, TerminalParseSentenceEventArgs e)
		{
			string submittedText = e.SubmittedText;
			if (Commands.Count >= MEMORY_LIMIT)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Removing oldest entry due to memory limit.");
				Commands.RemoveAt(0);
			}
			Commands.Add(submittedText);
			pointer = Commands.Count - 1;
			pointing = false;
		}

		private void SendCommandLine(string command)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Replacing command text with: " + command));
			TerminalApi.SetTerminalInput(command);
		}

		private string SafeCommandRetrieval(List<string> List, int index)
		{
			if (index < 0 || index >= List.Count)
			{
				return "";
			}
			return List[index];
		}

		private void MovePointer(bool increase)
		{
			if (!pointing)
			{
				pointing = true;
			}
			else if (increase)
			{
				if (pointer < Commands.Count)
				{
					pointer++;
				}
			}
			else if (pointer >= 0)
			{
				pointer--;
			}
		}

		private string ParseCommandHistory(List<string> List)
		{
			string text = "[Most recent commands listed bottom-up]\n\n";
			foreach (string item in List)
			{
				text = text + item + "\n";
			}
			return text;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TerminalHistory";

		public const string PLUGIN_NAME = "TerminalHistory";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace Keybinds
{
	public class Keybinds : LcInputActions
	{
		[InputAction("<Keyboard>/UpArrow", Name = "Last Terminal Command")]
		public InputAction InputLast { get; set; }

		[InputAction("<Keyboard>/DownArrow", Name = "Next Terminal Command")]
		public InputAction InputNext { get; set; }
	}
}