Decompiled source of BetterTerminal v1.2.0

BepInEx/plugins/BetterTerminal.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BetterTerminal.NetcodePatcher;
using Computerdores.AdvancedTerminalAPI;
using Computerdores.AdvancedTerminalAPI.Vanillin;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("BetterTerminal")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+455a5a4130788d228a431e33367187f354855f6a")]
[assembly: AssemblyProduct("BetterTerminal")]
[assembly: AssemblyTitle("BetterTerminal")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 Computerdores
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterTerminal";

		public const string PLUGIN_NAME = "BetterTerminal";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Computerdores.BetterTerminal
{
	public class InputHandler : LcInputActions
	{
		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction PrevCommand { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction NextCommand { get; set; }

		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction AutoComplete { get; set; }
	}
	[BepInPlugin("BetterTerminal", "BetterTerminal", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static InputHandler InputHandler;

		private readonly Harmony _harmony = new Harmony("BetterTerminal");

		private static Plugin Instance { get; set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		public void Awake()
		{
			InputHandler = new InputHandler();
			Plugin.ReplaceITerminal((Method<ITerminal, InputFieldDriver>)((InputFieldDriver d) => (ITerminal)(object)new VanillinPlusTerminal(d)));
		}
	}
	public class VanillinPlusTerminal : VanillinTerminal
	{
		private readonly List<string> _history = new List<string> { "" };

		private int _index;

		private int Index
		{
			get
			{
				return _index;
			}
			set
			{
				_index = Math.Clamp(value, 0, _history.Count - 1);
				base.driver.Input = _history[_index];
			}
		}

		public VanillinPlusTerminal(InputFieldDriver driver)
			: base(driver)
		{
			Plugin.InputHandler.PrevCommand.performed += PrevCommand;
			Plugin.InputHandler.NextCommand.performed += NextCommand;
			Plugin.InputHandler.AutoComplete.performed += AutoComplete;
		}

		protected override void OnSubmit(string text)
		{
			((VanillinTerminal)this).OnSubmit(text);
			if (base.wrapper.TerminalInUse)
			{
				Index = 0;
				if (_history.Count <= 1 || !(_history[1] == text))
				{
					_history.Insert(1, text);
				}
			}
		}

		private void PrevCommand(CallbackContext context)
		{
			if (base.wrapper.TerminalInUse)
			{
				Index++;
			}
		}

		private void NextCommand(CallbackContext context)
		{
			if (base.wrapper.TerminalInUse)
			{
				Index--;
			}
		}

		private void AutoComplete(CallbackContext context)
		{
			if (!base.wrapper.TerminalInUse)
			{
				return;
			}
			if (base.currentCommand != null)
			{
				ICommand currentCommand = base.currentCommand;
				IPredictable val = (IPredictable)(object)((currentCommand is IPredictable) ? currentCommand : null);
				if (val != null)
				{
					base.driver.Input = val.PredictInput(base.driver.Input, (ITerminal)(object)this);
				}
				return;
			}
			string[] array = base.driver.Input.Split(' ');
			if (array.Length == 1)
			{
				ICommand val2 = ((VanillinTerminal)this).FindCommand(array[0]);
				if (val2 != null)
				{
					base.driver.Input = val2.GetName() + " ";
				}
				return;
			}
			ICommand val3 = ((VanillinTerminal)this).FindCommand(array[0]);
			IPredictable val4 = (IPredictable)(object)((val3 is IPredictable) ? val3 : null);
			if (val4 != null)
			{
				base.driver.Input = val3.GetName() + " " + val4.PredictInput(GeneralExtensions.Join<string>(array.Skip(1), (Func<string, string>)null, " "), (ITerminal)(object)this);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace BetterTerminal.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}