Decompiled source of WhoPulledTheLever v1.0.0

WhoPulledTheLever.dll

Decompiled 10 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;
using WhoPulledTheLever.Patches;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WhoPulledTheLever")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WhoPulledTheLever")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("62233214-0313-42f5-a8b9-ae374ccdfafa")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WhoPulledTheLever
{
	[BepInPlugin("ImoutoSama.WhoPulledTheLever", "Who Pulled the Lever", "1.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "ImoutoSama.WhoPulledTheLever";

		private const string modName = "Who Pulled the Lever";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("ImoutoSama.WhoPulledTheLever");

		internal static ManualLogSource logger;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("ImoutoSama.WhoPulledTheLever");
			logger.LogInfo((object)"Plugin Who Pulled the Lever has been added!");
			harmony.PatchAll(typeof(StartMatchLeverPatch));
		}
	}
	public class InstructionSequence
	{
		private List<Func<CodeInstruction, bool>> seq;

		private string name;

		private int stage = 0;

		private bool completed = false;

		private bool single;

		public static ManualLogSource logger => Plugin.logger;

		public InstructionSequence(string name, bool single = true)
		{
			this.name = name;
			this.single = single;
			seq = new List<Func<CodeInstruction, bool>>();
		}

		public void Add(Func<CodeInstruction, bool> next)
		{
			seq.Add(next);
		}

		public void AddBasic(OpCode opcode)
		{
			seq.Add((CodeInstruction i) => i.opcode == opcode);
		}

		public void AddBasic(OpCode opcode, object operand)
		{
			seq.Add((CodeInstruction i) => i.opcode == opcode && i.operand == operand);
		}

		public void AddSpecial(OpCode opcode, Func<CodeInstruction, bool> extra)
		{
			seq.Add((CodeInstruction i) => i.opcode == opcode && extra(i));
		}

		public bool VerifyStage(CodeInstruction current)
		{
			Func<CodeInstruction, bool> func = seq[stage];
			if (func(current))
			{
				stage++;
			}
			else
			{
				stage = 0;
			}
			if (stage >= seq.Count)
			{
				if (completed && single)
				{
					throw new Exception("Found multiple valid " + name + " instructions");
				}
				stage = 0;
				completed = true;
				return true;
			}
			return false;
		}

		public void ReportComplete()
		{
			if (!completed)
			{
				logger.LogError((object)("HarmonyTranspiler for " + name + " has failed. BIG PROBLEM!"));
			}
		}
	}
	internal class TranspilerUtilities
	{
		public static bool IsInstructionNearFloatValue(CodeInstruction instruction, float value)
		{
			return Mathf.Abs((float)instruction.operand - value) < 0.1f;
		}
	}
}
namespace WhoPulledTheLever.Patches
{
	public class StartMatchLeverPatch
	{
		[HarmonyPatch(typeof(InteractTrigger), "UpdateUsedByPlayerClientRpc")]
		[HarmonyPostfix]
		public static void UpdateUsedByPlayerClientRpcPatch(ref InteractTrigger __instance, int playerNum)
		{
			StartMatchLever component = ((Component)__instance).GetComponent<StartMatchLever>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			try
			{
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerNum];
				string playerUsername = val.playerUsername;
				Plugin.logger.LogInfo((object)("!!! " + playerUsername + " pulled the lever"));
			}
			catch (Exception ex)
			{
				Plugin.logger.LogError((object)ex);
			}
		}
	}
}