Decompiled source of LCFlashCommandFix v0.0.1

LCFlashCommandFix.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCFlashCommandFix.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCFlashCommandFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCFlashCommandFix")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7d99d53d-0af9-44c4-a057-82326ecd3748")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCFlashCommandFix
{
	[BepInPlugin("io.github.echoman-dev.LCFlashCommandFix", "Lethal Company Flash Command Fix", "0.0.1")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "io.github.echoman-dev.LCFlashCommandFix";

		private const string modName = "Lethal Company Flash Command Fix";

		private const string modVersion = "0.0.1";

		private readonly Harmony harmony = new Harmony("io.github.echoman-dev.LCFlashCommandFix");

		internal static ManualLogSource log;

		private void Awake()
		{
			log = ((BaseUnityPlugin)this).Logger;
			log.LogInfo((object)"Lethal Company Flash Command Fix loaded.");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(TerminalPatch));
		}
	}
}
namespace LCFlashCommandFix.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	public static class TerminalPatch
	{
		private static readonly FieldInfo specialNodes = typeof(TerminalNodesList).GetField("specialNodes");

		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> flashCommandFix(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)typeof(TransformAndName).GetField("isNonPlayer"), (string)null)
			});
			CodeInstruction instruction2 = val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
			}).Instruction;
			Label label = (Label)instruction2.operand;
			val = val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction instruction) => instruction.opcode == OpCodes.Ldarg_0 && instruction.labels.Any((Label l) => l.Equals(label))), (string)null)
			});
			val.Instruction.labels = val.Instruction.labels.Except(new List<Label> { label }).ToList();
			return val.Insert((CodeInstruction[])(object)new CodeInstruction[6]
			{
				CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Ldarg_0, (object)null), new Label[1] { label }),
				new CodeInstruction(OpCodes.Ldfld, (object)typeof(Terminal).GetField("terminalNodes")),
				new CodeInstruction(OpCodes.Ldfld, (object)specialNodes),
				new CodeInstruction(OpCodes.Ldc_I4_S, (object)10),
				new CodeInstruction(OpCodes.Callvirt, (object)getListGetterMethod(instructions)),
				new CodeInstruction(OpCodes.Ret, (object)null)
			}).InstructionEnumeration();
		}

		private static MethodInfo getListGetterMethod(IEnumerable<CodeInstruction> codes)
		{
			CodeInstruction val = codes.First((CodeInstruction i) => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo && (i.operand as MethodInfo).ReturnType == typeof(TerminalNode) && (i.operand as MethodInfo).Name == "get_Item" && (i.operand as MethodInfo).GetParameters().Count() == 1 && (i.operand as MethodInfo).GetParameters().ElementAt(0).ParameterType == typeof(int) && (i.operand as MethodInfo).DeclaringType == specialNodes.FieldType);
			return (val == null) ? null : (val.operand as MethodInfo);
		}
	}
}