Decompiled source of LethalBang v1.1.0

LethalBang.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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TerminalApi;
using TerminalApi.Classes;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalBang")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Skip confirm! Plus a couple basic term commands for Lethal Company")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("LethalBang")]
[assembly: AssemblyTitle("LethalBang")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 LethalBang
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalBang";

		public const string PLUGIN_NAME = "LethalBang";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace LCTermBasicCmdsMod
{
	[HarmonyPatch(typeof(Terminal))]
	internal class BasicTermPatch
	{
		private static ManualLogSource logSource = Logger.CreateLogSource("twi.LCTermBasicCmds");

		private static bool bangDetected = false;

		[HarmonyPatch("TextChanged")]
		[HarmonyPrefix]
		private static void TextChanged_Pre(ref Terminal __instance)
		{
			if (!((Object)(object)__instance.currentNode == (Object)null))
			{
				__instance.currentNode.maxCharactersToType = 50;
			}
		}

		[HarmonyPatch("OnSubmit")]
		[HarmonyPrefix]
		private static void OnSubmit_Pre(ref Terminal __instance)
		{
			if (__instance.textAdded == 0)
			{
				bangDetected = false;
				return;
			}
			string text = __instance.screenText.text;
			int textAdded = __instance.textAdded;
			int length = text.Length;
			int num = length - textAdded;
			string text2 = text.Substring(num, length - num);
			bangDetected = text2[text2.Length - 1] == '!';
			string[] array = new string[4] { "cowsay", "cowthink", "cs", "ct" };
			for (int i = 0; i < array.Length; i++)
			{
				if (text2.ToLower().StartsWith(array[i]) && (__instance.textAdded == array[i].Length || !char.IsLetterOrDigit(text2[array[i].Length])))
				{
					ParseCowsay(ref __instance);
					TMP_InputField screenText = __instance.screenText;
					string text3 = __instance.screenText.text;
					num = __instance.textAdded - array[i].Length;
					screenText.text = text3.Substring(0, text3.Length - num);
					break;
				}
			}
		}

		[HarmonyPatch("OnSubmit")]
		[HarmonyPostfix]
		private static void OnSubmit_Post(ref Terminal __instance)
		{
			if (bangDetected && __instance.screenText.text.Split('\n', StringSplitOptions.RemoveEmptyEntries)[^1].StartsWith("Please CONFIRM or DENY."))
			{
				logSource.LogInfo((object)"Bang detected on confirmable action! let's go!");
				TMP_InputField screenText = __instance.screenText;
				screenText.text += "c";
				__instance.OnSubmit();
			}
		}

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPrefix]
		private static void ParsePlayerSentence(ref Terminal __instance)
		{
		}

		private static void ParseCowsay(ref Terminal __instance)
		{
			BasicTermCommands instance = BasicTermCommands.GetInstance();
			instance.cowfile = "";
			instance.customEyes = "";
			instance.customTongue = "";
			instance.customWidth = -1;
			instance.currentAction = BasicTermCommands.CowAction.Normal;
			string[] array = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded).Split(' ');
			if (array.Length == 1 || array[1] == "")
			{
				instance.currentAction = BasicTermCommands.CowAction.PrintUsage;
				return;
			}
			int num = 1;
			if (array[1][0] == '-')
			{
				if (array.Length == 2 && !(array[1] == "-l") && !(array[1] == "-h"))
				{
					instance.lastError = "no message!";
					instance.currentAction = BasicTermCommands.CowAction.PrintError;
					return;
				}
				num = 2;
				for (int i = 1; i < array[1].Length; i++)
				{
					switch (array[1][i])
					{
					case 'h':
						instance.currentAction = BasicTermCommands.CowAction.PrintUsage;
						return;
					case 'b':
						instance.customEyes = "==";
						break;
					case 'd':
						instance.customEyes = "xx";
						break;
					case 'g':
						instance.customEyes = "$$";
						break;
					case 'p':
						instance.customEyes = "@@";
						break;
					case 't':
						instance.customEyes = "--";
						break;
					case 'w':
						instance.customEyes = "OO";
						break;
					case 'y':
						instance.customEyes = "..";
						break;
					case 's':
						instance.customEyes = "**";
						instance.customTongue = "U ";
						break;
					case 'e':
					{
						if (i + 2 >= array[1].Length)
						{
							logSource.LogInfo((object)"Need 2 characters for custom eye string!");
							break;
						}
						string obj2 = array[1];
						int num2 = i + 1;
						string customEyes = obj2.Substring(num2, i + 3 - num2).Replace('.', ' ');
						instance.customEyes = customEyes;
						i += 2;
						break;
					}
					case 'T':
					{
						if (i + 2 >= array[1].Length)
						{
							logSource.LogInfo((object)"Need 2 characters for custom tongue string!");
							break;
						}
						string obj = array[1];
						int num2 = i + 1;
						string customTongue = obj.Substring(num2, i + 3 - num2).Replace('.', ' ');
						instance.customTongue = customTongue;
						i += 2;
						break;
					}
					case 'f':
					{
						for (int j = 0; j < BasicTermCommands.cowfiles.Length; j++)
						{
							string text = BasicTermCommands.cowfiles[j];
							string text2 = array[1];
							int num2 = i + 1;
							if (text2.Substring(num2, text2.Length - num2).ToLower().StartsWith(text))
							{
								instance.cowfile = text;
								i += text.Length;
								break;
							}
						}
						break;
					}
					case 'l':
						instance.currentAction = BasicTermCommands.CowAction.ListFiles;
						return;
					default:
						logSource.LogInfo((object)$"Unknown switch {array[1][i]}");
						break;
					}
				}
			}
			if (array.Length <= num)
			{
				instance.lastError = "not enough arguments?";
				instance.currentAction = BasicTermCommands.CowAction.PrintError;
			}
			else
			{
				instance.cowtext = GeneralExtensions.Join<string>((IEnumerable<string>)array[num..], (Func<string, string>)null, " ");
			}
		}
	}
	[BepInPlugin("twi.LethalBang", "LethalBang", "1.1.0")]
	public class BasicTermCommands : BaseUnityPlugin
	{
		public enum CowAction
		{
			Normal,
			PrintError,
			PrintUsage,
			ListFiles
		}

		private const string GUID = "twi.LethalBang";

		private const string Name = "LethalBang";

		private const string Version = "1.1.0";

		public static readonly string[] cowfiles = new string[6] { "neco", "bnuy", "sign", "bong", "udder", "yipee" };

		private readonly Harmony harmony = new Harmony("twi.LethalBang");

		private static BasicTermCommands Instance;

		public string cowtext = "";

		public string cowfile = "";

		public string customEyes = "";

		public string customTongue = "";

		public int customWidth = -1;

		public string lastError = "";

		public CowAction currentAction;

		private static string usageString = "cow{say,think}  (c) 2003, Tony Monroe\nremade for FORTUNE-9 OS by [EXPUNGED]\nUsage: cowsay/cs, cowthink/ct\n   -h    Display this message\n   -f    cowfile    ( list: [-l] )\n   Options ( condense into 1 word (no space)\n                        beginning with '-' ):\n      eyes:    [-bdgpstwy] ( custom: -e{cc} )\n      tongue:  [-T{cc}]    ( . for space )\ne.g. cowsay -e0~Tw. [message]\n\n";

		public static BasicTermCommands GetInstance()
		{
			return Instance;
		}

		private void Awake()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin twi.LethalBang loaded.");
			harmony.PatchAll(typeof(BasicTermCommands));
			harmony.PatchAll(typeof(BasicTermPatch));
			TerminalApi.AddCommand("clear", "", (string)null, true);
			TerminalApi.AddCommand("cls", "", (string)null, true);
			CommandInfo val = new CommandInfo
			{
				Title = "cowsay",
				Description = "it's cowsay",
				DisplayTextSupplier = () => cowsay(cowtext),
				Category = "Misc"
			};
			CommandInfo val2 = new CommandInfo
			{
				Title = "cowthink",
				Description = "the thinker",
				DisplayTextSupplier = () => cowsay(cowtext, think: true),
				Category = "Misc"
			};
			TerminalApi.AddCommand("cowsay", val, (string)null, true);
			TerminalApi.AddCommand("cowthink", val2, (string)null, true);
			TerminalApi.AddCommand("cs", new CommandInfo
			{
				Title = "csay",
				Category = "Misc",
				DisplayTextSupplier = () => cowsay(cowtext)
			}, (string)null, true);
			TerminalApi.AddCommand("ct", new CommandInfo
			{
				Title = "cthink",
				Category = "Misc",
				DisplayTextSupplier = () => cowsay(cowtext, think: true)
			}, (string)null, true);
		}

		private static string cowString(char bubbleTrail, string eyes, string tongue)
		{
			return "       " + bubbleTrail + "   ^__ ^\n        " + bubbleTrail + "  (" + eyes + ")\\_______\n           (__)\\       )\\/\\\n            " + tongue + " ||----w |\n               ||     ||\n";
		}

		private static string necoString(char bubbleTrail)
		{
			return "      " + bubbleTrail + "     /\\    /\\\n        " + bubbleTrail + "  /  \"\"\"\"  \\\n          /  vvvvvv  \\\n          | |(|)(|)| |\n          \\ '._VV_.' /\n           vwvv||vvwv\n          O==[\u00af  \u00af]==O\n              |__|\n              |__|\n             _||||_\n";
		}

		private static string bnuyString(char bubbleTrail, string eyes)
		{
			return "      " + bubbleTrail + "   (\\__/)\r\n       " + bubbleTrail + "  ( " + eyes[0] + "w" + eyes[1] + ")\r\n          ((\")(\")\n";
		}

		private static string bunySignString(string eyes)
		{
			return "    ||(\\__/)\r\n    ||(" + eyes[0] + "w" + eyes[1] + " )\r\n    CC     \\\r\n     (\")(\") )o\n";
		}

		private static string bongString(char bubbleTrail, string eyes)
		{
			return "         " + bubbleTrail + "\n          " + bubbleTrail + "\n            ^__^\n    _______/(" + eyes + ")\n/\\/(       /(__)\n   | W----|| |~|\n   ||     || |~|  ~~\n             |~|  ~\n             |_| o\n             |#|/\n            _+#+_\n";
		}

		private static string udderString(char bubbleTrail, string eyes, string tongue)
		{
			return "  " + bubbleTrail + "\n   " + bubbleTrail + "    (__)               \n        " + eyes[0] + " " + eyes[1] + "\\               \n       ('') \\---------     \n        " + tongue + "\\           \\    \n           |          |\\   \n           ||---(  )_|| *  \n           ||    UU  ||    \n           ==        ==    \n";
		}

		private static string yipeeString(char bubbleTrail, string eyes, string tongue)
		{
			return "    " + bubbleTrail + "\n     " + bubbleTrail + " \\    /\r\n        |__|\r\n    \\  /" + eyes[0] + "  " + eyes[1] + "\\  /\r\n     \\/\\ " + tongue + " /\\/\r\n     /\\ '__' /\\\r\n    /          \\\n";
		}

		private string cowsay(string text, bool think = false)
		{
			switch (currentAction)
			{
			case CowAction.PrintUsage:
				return usageString;
			case CowAction.PrintError:
				return lastError + "\n\n" + usageString;
			case CowAction.ListFiles:
				return GeneralExtensions.Join<string>((IEnumerable<string>)cowfiles, (Func<string, string>)null, "   ") + "\n\n";
			default:
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("cowsay with->" + text));
				string text2 = "";
				string text3 = "";
				string eyes = ((!(customEyes == "")) ? customEyes : ((cowfile == "bnuy" || cowfile == "sign") ? "''" : ((cowfile == "yipee") ? "OO" : "oo")));
				string tongue = ((!(customTongue == "")) ? customTongue : ((cowfile == "yipee") ? "\u00b4`" : "  "));
				string text4 = (think ? "()" : "<>");
				char bubbleTrail = (think ? 'o' : '\\');
				int num = Math.Max(text.Length, customWidth);
				for (int i = 0; i < num; i++)
				{
					text3 += "_";
					text2 += "-";
				}
				return " _" + text3 + "_\n" + text4[0] + " " + text + " " + text4[1] + "\n -" + text2 + "-\n" + ((cowfile == "neco") ? necoString(bubbleTrail) : ((cowfile == "bnuy") ? bnuyString(bubbleTrail, eyes) : ((cowfile == "sign") ? bunySignString(eyes) : ((cowfile == "bong") ? bongString(bubbleTrail, eyes) : ((cowfile == "udder") ? udderString(bubbleTrail, eyes, tongue) : ((cowfile == "yipee") ? yipeeString(bubbleTrail, eyes, tongue) : cowString(bubbleTrail, eyes, tongue)))))));
			}
			}
		}
	}
}