Decompiled source of PowerUserTerminal v1.0.4

PowerUserTerminal.dll

Decompiled 5 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 System.Text.RegularExpressions;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using TerminalApi;
using TerminalApi.Events;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
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("PowerUserTerminal")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PowerUserTerminal")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1ac9a221-5f6d-45a9-9247-9eece36a168b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PowerUserTerminal;

[BepInPlugin("Valafi.PowerUserTerminal", "Power User Terminal", "1.0.4")]
public class Plugin : BaseUnityPlugin
{
	public class PluginInput : LcInputActions
	{
		[InputAction("<Keyboard>/tab", Name = "Autocomplete")]
		public InputAction FakeAutocompleteKey { get; set; }

		[InputAction("<Keyboard>/ctrl", Name = "Autocomplete Reverse Modifier")]
		public InputAction FakeAutocompleteReverseModifierKey { get; set; }

		[InputAction("<Keyboard>/tab", Name = "Internal (Leave Blank)")]
		public InputAction AutocompleteKey { get; set; }
	}

	[HarmonyPatch(typeof(Terminal))]
	public static class TerminalPatch
	{
		[HarmonyPriority(800)]
		[HarmonyPatch("ParseWordOverrideOptions")]
		[HarmonyPrefix]
		public static bool ParseWordOverrideOptions(string playerWord, CompatibleNoun[] options, ref TerminalNode __result)
		{
			List<string> list = new List<string>();
			foreach (CompatibleNoun val in options)
			{
				string word = val.noun.word;
				if (word.StartsWith(playerWord))
				{
					if (word == playerWord)
					{
						__result = val.result;
						return false;
					}
					list.Add(word);
				}
			}
			if (list.Count <= 0)
			{
				__result = null;
				return false;
			}
			list.Add(playerWord);
			list.Sort(delegate(string x, string y)
			{
				int num = StringComparer.OrdinalIgnoreCase.Compare(x, y);
				if (num != 0)
				{
					return num;
				}
				int num2 = x.Length.CompareTo(y.Length);
				return (num2 != 0) ? num2 : StringComparer.Ordinal.Compare(x, y);
			});
			string text = list[(list.IndexOf(playerWord) + 1) % list.Count];
			foreach (CompatibleNoun val2 in options)
			{
				if (val2.noun.word == text)
				{
					__result = val2.result;
					return false;
				}
			}
			__result = null;
			return false;
		}

		[HarmonyPriority(800)]
		[HarmonyPatch("CheckForPlayerNameCommand")]
		[HarmonyPrefix]
		public static bool CheckForPlayerNameCommandPatch(string firstWord, string secondWord, ref int __result)
		{
			if (secondWord.Length <= 0)
			{
				__result = -1;
				return false;
			}
			List<string> list = new List<string>();
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			for (int i = 0; i < Instance.mapScreen.radarTargets.Count; i++)
			{
				TransformAndName val = Instance.mapScreen.radarTargets[i];
				if (!val.name.StartsWith(secondWord))
				{
					continue;
				}
				if (!val.isNonPlayer)
				{
					if (firstWord == "ping" || firstWord == "flash")
					{
						continue;
					}
					PlayerControllerB component = ((Component)val.transform).gameObject.GetComponent<PlayerControllerB>();
					if ((Object)(object)component == (Object)null)
					{
						continue;
					}
					bool flag = !component.isPlayerControlled && !component.isPlayerDead;
					bool flag2 = (Object)(object)component.deadBody == (Object)null && (Object)(object)component.redirectToEnemy == (Object)null;
					if (flag && flag2)
					{
						continue;
					}
				}
				if (val.name == secondWord)
				{
					__result = i;
					return false;
				}
				list.Add(val.name);
				dictionary.Add(val.name, i);
			}
			list.Add(secondWord);
			if (!dictionary.ContainsKey(secondWord))
			{
				dictionary.Add(secondWord, -1);
			}
			list.Sort(delegate(string x, string y)
			{
				int num = StringComparer.OrdinalIgnoreCase.Compare(x, y);
				if (num != 0)
				{
					return num;
				}
				int num2 = x.Length.CompareTo(y.Length);
				return (num2 != 0) ? num2 : (StringComparer.Ordinal.Compare(x, y) * -1);
			});
			__result = dictionary[list[(list.IndexOf(secondWord) + 1) % list.Count]];
			return false;
		}

		[HarmonyPriority(800)]
		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPrefix]
		public static bool ParsePlayerSentencePatch(ref Terminal __instance, ref TerminalNode __result)
		{
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_09c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c7: Expected O, but got Unknown
			MethodInfo method = typeof(Terminal).GetMethod("RemovePunctuation", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method2 = typeof(Terminal).GetMethod("ParseWordOverrideOptions", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method3 = typeof(Terminal).GetMethod("CheckForPlayerNameCommand", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method4 = typeof(Terminal).GetMethod("CheckForExactSentences", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method5 = typeof(Terminal).GetMethod("CallFunctionInAccessibleTerminalObject", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method6 = typeof(Terminal).GetMethod("PlayBroadcastCodeEffect", BindingFlags.Instance | BindingFlags.NonPublic);
			MethodInfo method7 = typeof(Terminal).GetMethod("ParseWord", BindingFlags.Instance | BindingFlags.NonPublic);
			Traverse val = Traverse.Create((object)__instance).Field("broadcastedCodeThisFrame");
			Traverse val2 = Traverse.Create((object)__instance).Field("hasGottenNoun");
			Traverse val3 = Traverse.Create((object)__instance).Field("hasGottenVerb");
			val.SetValue((object)false);
			string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
			string text2 = (string)method.Invoke(__instance, new object[1] { text });
			string[] array = text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			if ((Object)(object)__instance.currentNode != (Object)null && __instance.currentNode.overrideOptions)
			{
				__result = (TerminalNode)method2.Invoke(__instance, new object[2]
				{
					text2,
					__instance.currentNode.terminalOptions
				});
				return false;
			}
			if (array.Length > 1)
			{
				switch (array[0])
				{
				case "switch":
				{
					int num3 = (int)method3.Invoke(__instance, new object[2]
					{
						array[0],
						Regex.Replace(text, "^\\s*\\w+\\s*", "")
					});
					if (num3 != -1)
					{
						Instance.mapScreen.SwitchRadarTargetAndSync(num3);
						__result = __instance.terminalNodes.specialNodes[20];
						return false;
					}
					break;
				}
				case "flash":
				{
					int num2 = (int)method3.Invoke(__instance, new object[2]
					{
						array[0],
						Regex.Replace(text, "^\\s*\\w+\\s*", "")
					});
					if (num2 != -1)
					{
						Instance.mapScreen.FlashRadarBooster(num2);
						__result = __instance.terminalNodes.specialNodes[23];
						return false;
					}
					if (Instance.mapScreen.radarTargets[Instance.mapScreen.targetTransformIndex].isNonPlayer)
					{
						Instance.mapScreen.FlashRadarBooster(Instance.mapScreen.targetTransformIndex);
						__result = __instance.terminalNodes.specialNodes[23];
						return false;
					}
					break;
				}
				case "ping":
				{
					int num = (int)method3.Invoke(__instance, new object[2]
					{
						array[0],
						Regex.Replace(text, "^\\s*\\w+\\s*", "")
					});
					if (num != -1)
					{
						Instance.mapScreen.PingRadarBooster(num);
						__result = __instance.terminalNodes.specialNodes[21];
						return false;
					}
					break;
				}
				case "transmit":
				{
					SignalTranslator val4 = Object.FindObjectOfType<SignalTranslator>();
					if (!((Object)(object)val4 != (Object)null) || !(Time.realtimeSinceStartup - val4.timeLastUsingSignalTranslator > 8f) || array.Length < 2)
					{
						break;
					}
					string text3 = Regex.Replace(text, "^\\s*\\w+\\s*", "");
					if (string.IsNullOrEmpty(text3))
					{
						break;
					}
					if (!((NetworkBehaviour)__instance).IsServer)
					{
						val4.timeLastUsingSignalTranslator = Time.realtimeSinceStartup;
					}
					HUDManager.Instance.UseSignalTranslatorServerRpc(text3.Substring(0, Mathf.Min(text3.Length, 10)));
					__result = __instance.terminalNodes.specialNodes[22];
					return false;
				}
				}
			}
			string value = Regex.Match(array.Last(), "^\\d+$").Value;
			string text4 = text2;
			if (!string.IsNullOrWhiteSpace(value))
			{
				__instance.playerDefinedAmount = Mathf.Clamp(int.Parse(value), 0, 10);
				text4 = text2.Substring(0, text2.Length - array.Last().Length - 1);
			}
			else
			{
				__instance.playerDefinedAmount = 1;
			}
			List<string> list = new List<string>();
			Dictionary<string, (TerminalKeyword, CompatibleNoun)> dictionary = new Dictionary<string, (TerminalKeyword, CompatibleNoun)>();
			TerminalKeyword[] allKeywords = __instance.terminalNodes.allKeywords;
			foreach (TerminalKeyword val5 in allKeywords)
			{
				if (val5.word == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Keyword object \"" + ((Object)val5).name + "\" has null \"word\" property, skipping it."));
					continue;
				}
				if (val5.word.StartsWith(text4))
				{
					if (!dictionary.ContainsKey(val5.word))
					{
						list.Add(val5.word);
						dictionary.Add(val5.word, (val5, null));
					}
					else
					{
						((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Keyword \"" + val5.word + "\" is a duplicate of a vanilla or modded keyword. Depending on the context, it might not be usable."));
					}
				}
				if (!val5.isVerb)
				{
					continue;
				}
				if (val5.compatibleNouns == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Keyword \"" + val5.word + "\" is a verb, but has null compatibleNouns property, skipping compatibleNouns."));
					continue;
				}
				CompatibleNoun[] compatibleNouns = val5.compatibleNouns;
				foreach (CompatibleNoun val6 in compatibleNouns)
				{
					if ((Object)(object)val6.noun == (Object)null)
					{
						((BaseUnityPlugin)Instance).Logger.LogWarning((object)("A compatible noun for keyword \"" + val5.word + "\" has null noun property, skipping it."));
						continue;
					}
					if (val6.noun.word == null)
					{
						((BaseUnityPlugin)Instance).Logger.LogWarning((object)("The keyword of a compatible noun for keyword \"" + val5.word + "\" has null word property, skipping it."));
						continue;
					}
					string text5 = val5.word + " " + val6.noun.word;
					if (text5.StartsWith(text4))
					{
						if (!dictionary.ContainsKey(text5))
						{
							list.Add(text5);
							dictionary.Add(text5, (val5, val6));
						}
						else
						{
							((BaseUnityPlugin)Instance).Logger.LogWarning((object)("The verb, noun pair \"" + text5 + "\" is a duplicate of a vanilla or modded verb, noun pair. Depending on the context, it might not be usable."));
						}
					}
				}
			}
			if (list.Count > 0)
			{
				list.Add(text4);
				list.Sort(delegate(string x, string y)
				{
					int num4 = StringComparer.OrdinalIgnoreCase.Compare(x, y);
					if (num4 != 0)
					{
						return num4;
					}
					int num5 = x.Length.CompareTo(y.Length);
					return (num5 != 0) ? num5 : StringComparer.Ordinal.Compare(x, y);
				});
				(TerminalKeyword, CompatibleNoun) tuple = dictionary[list[(list.IndexOf(text4) + 1) % list.Count]];
				if (tuple.Item1.accessTerminalObjects)
				{
					method5.Invoke(__instance, new object[1] { tuple.Item1.word });
					if ((bool)val.GetValue())
					{
						method6.Invoke(__instance, new object[0]);
						__result = __instance.terminalNodes.specialNodes[19];
						return false;
					}
					__result = null;
					return false;
				}
				if ((Object)(object)tuple.Item1.specialKeywordResult != (Object)null)
				{
					__result = tuple.Item1.specialKeywordResult;
					return false;
				}
				if (tuple.Item1.isVerb)
				{
					if (tuple.Item2 != null)
					{
						__result = tuple.Item2.result;
						return false;
					}
				}
				else if ((Object)(object)tuple.Item1.defaultVerb != (Object)null)
				{
					CompatibleNoun[] compatibleNouns2 = tuple.Item1.defaultVerb.compatibleNouns;
					foreach (CompatibleNoun val7 in compatibleNouns2)
					{
						if ((Object)(object)val7.noun == (Object)(object)tuple.Item1)
						{
							__result = val7.result;
							return false;
						}
					}
				}
			}
			value = Regex.Match(text2, "\\d+").Value;
			__instance.playerDefinedAmount = (string.IsNullOrWhiteSpace(value) ? 1 : Mathf.Clamp(int.Parse(value), 0, 10));
			TerminalKeyword val8 = null;
			TerminalKeyword val9 = null;
			val2.SetValue((object)false);
			val3.SetValue((object)false);
			string[] array2 = array;
			foreach (string text6 in array2)
			{
				TerminalKeyword val10 = (TerminalKeyword)method7.Invoke(__instance, new object[2] { text6, 2 });
				if ((Object)(object)val10 != (Object)null)
				{
					Debug.Log((object)("Parsed word: " + text6));
					if (val10.isVerb)
					{
						if ((bool)val3.GetValue())
						{
							continue;
						}
						val3.SetValue((object)true);
						val8 = val10;
					}
					else
					{
						if ((bool)val2.GetValue())
						{
							continue;
						}
						val2.SetValue((object)true);
						if (val10.accessTerminalObjects)
						{
							method5.Invoke(__instance, new object[1] { val10.word });
							if ((bool)val.GetValue())
							{
								val2.SetValue((object)false);
								val3.SetValue((object)false);
								method6.Invoke(__instance, new object[0]);
								__result = __instance.terminalNodes.specialNodes[19];
								return false;
							}
							__result = null;
							return false;
						}
						val9 = val10;
					}
					if ((bool)val2.GetValue() && (bool)val3.GetValue())
					{
						break;
					}
				}
				else
				{
					Debug.Log((object)("Could not parse word: " + text6));
				}
			}
			val2.SetValue((object)false);
			val3.SetValue((object)false);
			if ((Object)(object)val9 == (Object)null)
			{
				__result = __instance.terminalNodes.specialNodes[10];
				return false;
			}
			if ((Object)(object)val8 == (Object)null)
			{
				if (!((Object)(object)val9.defaultVerb != (Object)null))
				{
					__result = __instance.terminalNodes.specialNodes[11];
					return false;
				}
				val8 = val9.defaultVerb;
			}
			CompatibleNoun[] compatibleNouns3 = val8.compatibleNouns;
			foreach (CompatibleNoun val11 in compatibleNouns3)
			{
				if ((Object)(object)val11.noun == (Object)(object)val9)
				{
					Debug.Log((object)$"noun keyword: {val9.word} ; verb keyword: {val8.word} ; result null? : {(Object)(object)val11.result == (Object)null}");
					Debug.Log((object)("result: " + ((Object)val11.result).name));
					__result = val11.result;
					return false;
				}
			}
			__result = __instance.terminalNodes.specialNodes[12];
			return false;
		}
	}

	private const string modGUID = "Valafi.PowerUserTerminal";

	private const string modName = "Power User Terminal";

	private const string modVersion = "1.0.4";

	private static Plugin Instance;

	internal static PluginInput InputActionsInstance = new PluginInput();

	public ManualCameraRenderer mapScreen = null;

	private bool reboundOpenMenu = false;

	private bool fixedModifyingText = false;

	private string currentAutocomplete = null;

	private string preAutocomplete = null;

	private string processedPreAutocomplete = null;

	public void SetupKeybindCallbacks()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		InputBinding val = InputActionsInstance.FakeAutocompleteKey.bindings[0];
		string path = ((InputBinding)(ref val)).path;
		val = InputActionsInstance.FakeAutocompleteReverseModifierKey.bindings[0];
		string path2 = ((InputBinding)(ref val)).path;
		InputActionsInstance.FakeAutocompleteKey.Disable();
		InputActionsInstance.FakeAutocompleteReverseModifierKey.Disable();
		InputActionRebindingExtensions.ApplyBindingOverride(InputActionsInstance.AutocompleteKey, 0, "");
		CompositeSyntax val2 = InputActionSetupExtensions.AddCompositeBinding(InputActionsInstance.AutocompleteKey, "OneModifier", (string)null, (string)null);
		val2 = ((CompositeSyntax)(ref val2)).With("Modifier", path2, (string)null, (string)null);
		((CompositeSyntax)(ref val2)).With("Binding", path, (string)null, "invert");
		InputActionSetupExtensions.AddBinding(InputActionsInstance.AutocompleteKey, path, (string)null, (string)null, (string)null);
		InputActionsInstance.AutocompleteKey.performed += OnAutocompleteKeyPressed;
	}

	private void Awake()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		SetupKeybindCallbacks();
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		Events.TerminalAwake += new TerminalEventHandler(OnTerminalAwake);
		Events.TerminalStarted += new TerminalEventHandler(OnTerminalStarted);
		Events.TerminalBeginUsing += new TerminalEventHandler(OnTerminalBeginUsing);
		Events.TerminalBeganUsing += new TerminalEventHandler(OnTerminalBeganUsing);
		Events.TerminalExited += new TerminalEventHandler(OnTerminalExited);
		Events.TerminalTextChanged += new TerminalTextChangedEventHandler(OnTerminalTextChanged);
		Events.TerminalParsedSentence += new TerminalParseSentenceEventHandler(OnTerminalParsedSentence);
	}

	private void OnTerminalAwake(object sender, TerminalEventArgs e)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		MovementActions movement = e.Terminal.playerActions.Movement;
		InputAction openMenu = ((MovementActions)(ref movement)).OpenMenu;
		InputBinding val = default(InputBinding);
		((InputBinding)(ref val)).path = "<Keyboard>/tab";
		((InputBinding)(ref val)).overridePath = "<keyboard>/escape";
		InputActionRebindingExtensions.ApplyBindingOverride(openMenu, val);
		reboundOpenMenu = true;
	}

	private void OnTerminalStarted(object sender, TerminalEventArgs e)
	{
		mapScreen = ((Component)Object.FindObjectOfType<Terminal>()).GetComponent<ManualCameraRenderer>() ?? StartOfRound.Instance.mapScreen;
	}

	private void OnTerminalBeginUsing(object sender, TerminalEventArgs e)
	{
		IngamePlayerSettings.Instance.playerInput.actions.FindAction("OpenMenu", false).Disable();
	}

	private void OnTerminalBeganUsing(object sender, TerminalEventArgs e)
	{
		if (!StartOfRound.Instance.localPlayerUsingController)
		{
			HUDManager.Instance.ChangeControlTip(0, "Quit terminal : [ESC]", true);
		}
	}

	private void OnTerminalExited(object sender, TerminalEventArgs e)
	{
		IngamePlayerSettings.Instance.playerInput.actions.FindAction("OpenMenu", false).Enable();
	}

	private void OnTerminalTextChanged(object sender, TerminalTextChangedEventArgs e)
	{
		if (currentAutocomplete == TerminalApi.GetTerminalInput())
		{
			((BaseUnityPlugin)this).Logger.LogDebug((object)"Ignored text!");
			return;
		}
		currentAutocomplete = null;
		preAutocomplete = null;
		processedPreAutocomplete = null;
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Autocomplete cleared!");
	}

	private void OnTerminalParsedSentence(object sender, TerminalParseSentenceEventArgs e)
	{
		currentAutocomplete = null;
		preAutocomplete = null;
		processedPreAutocomplete = null;
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Autocomplete cleared!");
	}

	public void OnAutocompleteKeyPressed(CallbackContext autocompleteContext)
	{
		if (!((CallbackContext)(ref autocompleteContext)).performed || !reboundOpenMenu || (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)(object)((Component)TerminalApi.Terminal.screenText).gameObject)
		{
			return;
		}
		((BaseUnityPlugin)this).Logger.LogDebug((object)"Triggered autocomplete!");
		bool flag = ((CallbackContext)(ref autocompleteContext)).action.ReadValue<float>() < 0f;
		if (!fixedModifyingText)
		{
			Traverse val = Traverse.Create((object)TerminalApi.Terminal).Field("modifyingText");
			val.SetValue((object)false);
			fixedModifyingText = true;
		}
		MethodInfo method = typeof(Terminal).GetMethod("RemovePunctuation", BindingFlags.Instance | BindingFlags.NonPublic);
		string text = TerminalApi.Terminal.screenText.text.Substring(TerminalApi.Terminal.screenText.text.Length - TerminalApi.Terminal.textAdded);
		string text2 = (string)method.Invoke(TerminalApi.Terminal, new object[1] { text });
		string[] array = text2.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
		if (preAutocomplete == null)
		{
			preAutocomplete = text;
			processedPreAutocomplete = text2;
		}
		if ((Object)(object)TerminalApi.Terminal.currentNode != (Object)null && TerminalApi.Terminal.currentNode.overrideOptions)
		{
			string item = text2;
			CompatibleNoun[] terminalOptions = TerminalApi.Terminal.currentNode.terminalOptions;
			List<string> list = new List<string>();
			CompatibleNoun[] array2 = terminalOptions;
			foreach (CompatibleNoun val2 in array2)
			{
				string word = val2.noun.word;
				if (word.StartsWith(processedPreAutocomplete))
				{
					list.Add(word);
				}
			}
			list.Add(preAutocomplete);
			if (!list.Contains(item))
			{
				list.Add(item);
			}
			list.Sort(delegate(string x, string y)
			{
				int num5 = StringComparer.OrdinalIgnoreCase.Compare(x, y);
				if (num5 != 0)
				{
					return num5;
				}
				int num6 = x.Length.CompareTo(y.Length);
				return (num6 != 0) ? num6 : StringComparer.Ordinal.Compare(x, y);
			});
			int index = (flag ? ((list.IndexOf(item) - 1 + list.Count) % list.Count) : ((list.IndexOf(item) + 1) % list.Count));
			currentAutocomplete = list[index];
			TerminalApi.SetTerminalInput(currentAutocomplete);
			return;
		}
		if (array.Length >= 1)
		{
			switch (array[0])
			{
			case "switch":
			case "flash":
			case "ping":
			{
				string text5 = array[0];
				string item2 = Regex.Replace(text, "^\\s*\\w+\\s*", "");
				List<string> list2 = new List<string>();
				foreach (TransformAndName radarTarget in mapScreen.radarTargets)
				{
					if (!radarTarget.isNonPlayer)
					{
						if (text5 == "ping" || text5 == "flash")
						{
							continue;
						}
						PlayerControllerB component = ((Component)radarTarget.transform).gameObject.GetComponent<PlayerControllerB>();
						if ((Object)(object)component == (Object)null)
						{
							continue;
						}
						bool flag2 = !component.isPlayerControlled && !component.isPlayerDead;
						bool flag3 = (Object)(object)component.deadBody == (Object)null && (Object)(object)component.redirectToEnemy == (Object)null;
						if (flag2 && flag3)
						{
							continue;
						}
					}
					list2.Add(radarTarget.name);
				}
				list2.Add(Regex.Replace(preAutocomplete, "^\\s*\\w+\\s*", ""));
				if (!list2.Contains(item2))
				{
					list2.Add(item2);
				}
				list2.Sort(delegate(string x, string y)
				{
					int num3 = StringComparer.OrdinalIgnoreCase.Compare(x, y);
					if (num3 != 0)
					{
						return num3;
					}
					int num4 = x.Length.CompareTo(y.Length);
					return (num4 != 0) ? num4 : (StringComparer.Ordinal.Compare(x, y) * -1);
				});
				int index2 = (flag ? ((list2.IndexOf(item2) - 1 + list2.Count) % list2.Count) : ((list2.IndexOf(item2) + 1) % list2.Count));
				currentAutocomplete = text5 + " " + list2[index2];
				TerminalApi.SetTerminalInput(currentAutocomplete);
				return;
			}
			case "transmit":
			{
				string text3 = Regex.Replace(text, "^\\s*\\w+\\s*", "");
				string text4 = "transmit " + text3.Substring(0, Mathf.Min(text3.Length, 10));
				if (text3 != text4)
				{
					currentAutocomplete = text4;
					TerminalApi.SetTerminalInput(currentAutocomplete);
				}
				else
				{
					TerminalApi.SetTerminalInput(preAutocomplete);
				}
				return;
			}
			}
		}
		List<string> list3 = new List<string>();
		TerminalKeyword[] allKeywords = TerminalApi.Terminal.terminalNodes.allKeywords;
		foreach (TerminalKeyword val3 in allKeywords)
		{
			if (val3.word == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Keyword object \"" + ((Object)val3).name + "\" has null \"word\" property, skipping it."));
				continue;
			}
			if (val3.word.StartsWith(processedPreAutocomplete) || processedPreAutocomplete == "")
			{
				if (!list3.Contains(val3.word))
				{
					list3.Add(val3.word);
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Keyword \"" + val3.word + "\" is a duplicate of a vanilla or modded keyword. Depending on the context, it might not be usable."));
				}
			}
			if (!val3.isVerb)
			{
				continue;
			}
			if (val3.compatibleNouns == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Keyword \"" + val3.word + "\" is a verb, but has null compatibleNouns property, skipping compatibleNouns."));
				continue;
			}
			CompatibleNoun[] compatibleNouns = val3.compatibleNouns;
			foreach (CompatibleNoun val4 in compatibleNouns)
			{
				if ((Object)(object)val4.noun == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("A compatible noun for keyword \"" + val3.word + "\" has null noun property, skipping it."));
					continue;
				}
				if (val4.noun.word == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("The keyword of a compatible noun for keyword \"" + val3.word + "\" has null word property, skipping it."));
					continue;
				}
				string text6 = val3.word + " " + val4.noun.word;
				if (text6.StartsWith(processedPreAutocomplete) || processedPreAutocomplete == "")
				{
					if (!list3.Contains(text6))
					{
						list3.Add(text6);
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)("The verb, noun pair \"" + text6 + "\" is a duplicate of a vanilla or modded verb, noun pair. Depending on the context, it might not be usable."));
					}
				}
			}
		}
		list3.Add(preAutocomplete);
		if (!list3.Contains(text2))
		{
			list3.Add(text2);
		}
		list3.Sort(delegate(string x, string y)
		{
			int num = StringComparer.OrdinalIgnoreCase.Compare(x, y);
			if (num != 0)
			{
				return num;
			}
			int num2 = x.Length.CompareTo(y.Length);
			return (num2 != 0) ? num2 : StringComparer.Ordinal.Compare(x, y);
		});
		int index3 = (flag ? ((list3.IndexOf(text2) - 1 + list3.Count) % list3.Count) : ((list3.IndexOf(text2) + 1) % list3.Count));
		currentAutocomplete = list3[index3];
		TerminalApi.SetTerminalInput(currentAutocomplete);
	}
}