Decompiled source of TerminalConflictFix v1.2.2

TerminalConflictFix.dll

Decompiled 9 months ago
using System;
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.Configuration;
using BepInEx.Logging;
using IL;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;

[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("TerminalConflictFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3f7f6cc6f8b42b1e8e5527bbd41d70f55c3ff7a6")]
[assembly: AssemblyProduct("TerminalConflictFix")]
[assembly: AssemblyTitle("TerminalConflictFix")]
[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 TerminalConflictFix
{
	public class Config
	{
		public static ConfigEntry<bool> RemoveCommandPunctuation { get; private set; }

		public Config(ConfigFile cfg)
		{
			RemoveCommandPunctuation = cfg.Bind<bool>("General", "RemoveCommandPunctuation", true, "Whether dashes and other punctuation in commands should be ignored, to fix issues with modded names. It's recommended to leave this ON.");
		}
	}
	[BepInPlugin("SylviBlossom.TerminalConflictFix", "TerminalConflictFix", "1.2.2")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__Terminal_ParseWord;

			public static Manipulator <1>__Terminal_ParseWordOverrideOptions;

			public static Manipulator <2>__Terminal_CheckForExactSentences;

			public static Manipulator <3>__Terminal_CheckForPlayerNameCommand;
		}

		private static string currentWord;

		private static TerminalNode longestMatch;

		private static int longestMatchIndex;

		private static int matchLength;

		public static Plugin Instance { get; internal set; }

		public static Config Config { get; internal set; }

		public static ManualLogSource Logger { get; internal set; }

		private void Awake()
		{
			//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_0040: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			Instance = this;
			Config = new Config(((BaseUnityPlugin)this).Config);
			Logger = ((BaseUnityPlugin)this).Logger;
			object obj = <>O.<0>__Terminal_ParseWord;
			if (obj == null)
			{
				Manipulator val = Terminal_ParseWord;
				<>O.<0>__Terminal_ParseWord = val;
				obj = (object)val;
			}
			Terminal.ParseWord += (Manipulator)obj;
			object obj2 = <>O.<1>__Terminal_ParseWordOverrideOptions;
			if (obj2 == null)
			{
				Manipulator val2 = Terminal_ParseWordOverrideOptions;
				<>O.<1>__Terminal_ParseWordOverrideOptions = val2;
				obj2 = (object)val2;
			}
			Terminal.ParseWordOverrideOptions += (Manipulator)obj2;
			object obj3 = <>O.<2>__Terminal_CheckForExactSentences;
			if (obj3 == null)
			{
				Manipulator val3 = Terminal_CheckForExactSentences;
				<>O.<2>__Terminal_CheckForExactSentences = val3;
				obj3 = (object)val3;
			}
			Terminal.CheckForExactSentences += (Manipulator)obj3;
			object obj4 = <>O.<3>__Terminal_CheckForPlayerNameCommand;
			if (obj4 == null)
			{
				Manipulator val4 = Terminal_CheckForPlayerNameCommand;
				<>O.<3>__Terminal_CheckForPlayerNameCommand = val4;
				obj4 = (object)val4;
			}
			Terminal.CheckForPlayerNameCommand += (Manipulator)obj4;
			Logger.LogInfo((object)"Plugin TerminalConflictFix is loaded!");
		}

		private static void Terminal_ParseWord(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int keywordLoc = 0;
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchLdnull(instr1),
				(Instruction instr2) => ILPatternMatchingExt.MatchStloc(instr2, ref keywordLoc)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ After keyword local");
				return;
			}
			val.EmitDelegate<Action>((Action)delegate
			{
				matchLength = 0;
			});
			int iLoc = -1;
			ILCursor[] array = default(ILCursor[]);
			if (!val.TryFindNext(ref array, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchLdfld<TerminalNodesList>(instr1, "allKeywords"),
				(Instruction instr2) => ILPatternMatchingExt.MatchLdloc(instr2, ref iLoc)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ Find 'i' variable");
				return;
			}
			ILLabel val3 = default(ILLabel);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchLdfld<Terminal>(instr1, "hasGottenVerb"),
				(Instruction instr2) => ILPatternMatchingExt.MatchBrtrue(instr2, ref val3)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ currentWord optimization");
				return;
			}
			val.MoveAfterLabels();
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldloc, iLoc);
			val.EmitDelegate<Action<Terminal, int>>((Action<Terminal, int>)delegate(Terminal self, int i)
			{
				currentWord = self.terminalNodes.allKeywords[i].word;
				if (Config.RemoveCommandPunctuation.Value)
				{
					currentWord = self.RemovePunctuation(currentWord.Replace(' ', '-'));
				}
			});
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdfld<TerminalKeyword>(instr, "word")
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ Fix word dashes 1");
				return;
			}
			val.EmitDelegate<Func<string, string>>((Func<string, string>)((string word) => currentWord));
			ILLabel continueLabel = null;
			if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdloc(instr, keywordLoc)
			}) || !val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchBrfalse(instr, ref continueLabel)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ Keyword null check");
				return;
			}
			val.Emit(OpCodes.Pop);
			val.Emit(OpCodes.Ldc_I4_1);
			int jLoc = 2;
			ILLabel val2 = default(ILLabel);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchCallOrCallvirt<string>(instr1, "get_Length"),
				(Instruction instr2) => ILPatternMatchingExt.MatchStloc(instr2, ref jLoc),
				(Instruction instr3) => ILPatternMatchingExt.MatchBr(instr3, ref val2)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ Substring loop");
				return;
			}
			val.MoveAfterLabels();
			val.Emit(OpCodes.Ldloc, jLoc);
			val.EmitDelegate<Func<int, bool>>((Func<int, bool>)((int j) => j <= matchLength));
			val.Emit(OpCodes.Brtrue_S, (object)continueLabel);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdfld<TerminalKeyword>(instr, "word")
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ Fix word dashes 2");
				return;
			}
			val.EmitDelegate<Func<string, string>>((Func<string, string>)((string word) => currentWord));
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchStloc(instr, keywordLoc)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWord @ Set matched keyword");
				return;
			}
			val.Emit(OpCodes.Ldloc, jLoc);
			val.EmitDelegate<Action<int>>((Action<int>)delegate(int j)
			{
				matchLength = j;
				Logger.LogInfo((object)$"Parsed \"{currentWord}\" with {j} letters");
			});
		}

		private static void Terminal_ParseWordOverrideOptions(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.EmitDelegate<Action>((Action)delegate
			{
				longestMatch = null;
				matchLength = 0;
			});
			int num = 0;
			int jLoc = -1;
			ILLabel loopStart = null;
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchCallOrCallvirt<string>(instr1, "get_Length"),
				(Instruction instr2) => ILPatternMatchingExt.MatchStloc(instr2, ref jLoc),
				(Instruction instr3) => ILPatternMatchingExt.MatchBr(instr3, ref loopStart)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWordOverrideOptions @ Substring loop");
				return;
			}
			ILLabel val2 = val.DefineLabel();
			ILLabel val3 = val.DefineLabel();
			val.MoveAfterLabels();
			val.Emit(OpCodes.Ldloc, jLoc);
			val.EmitDelegate<Func<int, bool>>((Func<int, bool>)((int j) => j <= matchLength));
			val.Emit(OpCodes.Brtrue_S, (object)val3);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdfld<TerminalKeyword>(instr, "word")
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWordOverrideOptions @ Fix word dashes");
				return;
			}
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<string, Terminal, string>>((Func<string, Terminal, string>)((string word, Terminal self) => Config.RemoveCommandPunctuation.Value ? self.RemovePunctuation(word.Replace(' ', '-')) : word));
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdfld<CompatibleNoun>(instr, "result")
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWordOverrideOptions @ Return result");
				return;
			}
			val.Emit(OpCodes.Ldloc, jLoc);
			val.Emit(OpCodes.Ldloc, num);
			val.Emit(OpCodes.Ldarg_2);
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<TerminalNode, int, int, CompatibleNoun[], Terminal>>((Action<TerminalNode, int, int, CompatibleNoun[], Terminal>)delegate(TerminalNode result, int j, int i, CompatibleNoun[] options, Terminal self)
			{
				longestMatch = result;
				matchLength = j;
				string text = options[i].noun.word;
				if (Config.RemoveCommandPunctuation.Value)
				{
					text = self.RemovePunctuation(text.Replace(' ', '-'));
				}
				Logger.LogInfo((object)$"Parsed \"{text}\" with {j} letters");
			});
			val.Emit(OpCodes.Br_S, (object)val2);
			val.Emit(OpCodes.Ldnull);
			int index = val.Index;
			val.Index = index + 1;
			val.MarkLabel(val2);
			val.GotoLabel(loopStart, (MoveType)1, false);
			ILLabel val4 = default(ILLabel);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchBgt(instr, ref val4)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWordOverrideOptions @ Loop end");
				return;
			}
			val.MarkLabel(val3);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdnull(instr)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.ParseWordOverrideOptions @ Final return");
				return;
			}
			val.Emit(OpCodes.Pop);
			val.EmitDelegate<Func<TerminalNode>>((Func<TerminalNode>)(() => longestMatch));
		}

		private static void Terminal_CheckForExactSentences(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdfld<TerminalKeyword>(instr, "word")
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForExactSentences @ Word");
				return;
			}
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<string, Terminal, string>>((Func<string, Terminal, string>)((string word, Terminal self) => Config.RemoveCommandPunctuation.Value ? self.RemovePunctuation(word) : word));
		}

		private static void Terminal_CheckForPlayerNameCommand(ILContext il)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int num = default(int);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchCallOrCallvirt<string>(instr1, "ToLower"),
				(Instruction instr2) => ILPatternMatchingExt.MatchStloc(instr2, ref num)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ Check exact");
				return;
			}
			int index = val.Index;
			val.Index = index - 1;
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<string, Terminal, string>>((Func<string, Terminal, string>)((string word, Terminal self) => Config.RemoveCommandPunctuation.Value ? self.RemovePunctuation(word.Replace(' ', '-')) : word));
			int kLoc = -1;
			ILLabel val5 = default(ILLabel);
			if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchStloc(instr1, ref kLoc),
				(Instruction instr2) => ILPatternMatchingExt.MatchBr(instr2, ref val5)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ Before loop");
				return;
			}
			index = val.Index;
			val.Index = index - 1;
			val.EmitDelegate<Action>((Action)delegate
			{
				longestMatchIndex = -1;
				matchLength = 0;
			});
			int textLoc = -1;
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchCallOrCallvirt<string>(instr1, "ToLower"),
				(Instruction instr2) => ILPatternMatchingExt.MatchStloc(instr2, ref textLoc)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ Player name variable");
				return;
			}
			index = val.Index;
			val.Index = index - 1;
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<string, Terminal, string>>((Func<string, Terminal, string>)((string word, Terminal self) => Config.RemoveCommandPunctuation.Value ? self.RemovePunctuation(word.Replace(' ', '-')) : word));
			int lLoc = -1;
			ILLabel substrLoopMidEnd = null;
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchStloc(instr1, ref lLoc),
				(Instruction instr2) => ILPatternMatchingExt.MatchBr(instr2, ref substrLoopMidEnd)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ Start substring loop");
				return;
			}
			ILLabel val2 = val.DefineLabel();
			val.MoveAfterLabels();
			val.Emit(OpCodes.Ldloc, lLoc);
			val.EmitDelegate<Func<int, bool>>((Func<int, bool>)((int l) => l <= matchLength));
			val.Emit(OpCodes.Brtrue_S, (object)val2);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr1) => ILPatternMatchingExt.MatchLdloc(instr1, kLoc)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ Original return match");
				return;
			}
			ILLabel val3 = val.DefineLabel();
			val.Emit(OpCodes.Ldloc, lLoc);
			val.Emit(OpCodes.Ldloc, textLoc);
			val.EmitDelegate<Action<int, int, string>>((Action<int, int, string>)delegate(int k, int l, string text)
			{
				longestMatchIndex = k;
				matchLength = l;
				Logger.LogInfo((object)$"Parsed player name \"{text}\" with {l} letters");
			});
			val.Emit(OpCodes.Br_S, (object)val3);
			val.Emit(OpCodes.Ldc_I4_M1);
			index = val.Index;
			val.Index = index + 1;
			val.MarkLabel(val3);
			val.GotoLabel(substrLoopMidEnd, (MoveType)1, false);
			ILLabel val4 = default(ILLabel);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchBgt(instr, ref val4)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ End substring loop");
				return;
			}
			val.MarkLabel(val2);
			if (!val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
			{
				(Instruction instr) => ILPatternMatchingExt.MatchLdcI4(instr, -1)
			}))
			{
				Logger.LogError((object)"Failed IL hook for Terminal.CheckForPlayerNameCommand @ Final return");
				return;
			}
			val.Emit(OpCodes.Pop);
			val.EmitDelegate<Func<int>>((Func<int>)(() => longestMatchIndex));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "SylviBlossom.TerminalConflictFix";

		public const string PLUGIN_NAME = "TerminalConflictFix";

		public const string PLUGIN_VERSION = "1.2.2";
	}
}