Decompiled source of LCNoPropsLost v1.0.0

BepInEx/plugins/LCNoPropsLost.dll

Decompiled 11 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 HarmonyLib;
using LCNoPropsLost.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCNoPropsLost")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCNoPropsLost")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("18fd8daa-f213-4766-b479-21b9228e73ee")]
[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 LCNoPropsLost
{
	[BepInPlugin("LCNoPropsLost", "LC No Props Lost", "1.0.0")]
	public class LCNoPropsLostPlugin : BaseUnityPlugin
	{
		private const string modGUID = "LCNoPropsLost";

		private const string modName = "LC No Props Lost";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("LCNoPropsLost");

		private static LCNoPropsLostPlugin instance;

		public static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			Logger = Logger.CreateLogSource("LCNoPropsLost");
			harmony.PatchAll(typeof(LCNoPropsLostPlugin));
			harmony.PatchAll(typeof(RoundManagerPatch));
		}
	}
}
namespace LCNoPropsLost.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> keepProps(IEnumerable<CodeInstruction> instructions, ILGenerator il)
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			int num = -1;
			Label item = il.DefineLabel();
			Type typeFromHandle = typeof(StartOfRound);
			PropertyInfo property = typeFromHandle.GetProperty("Instance");
			MethodInfo getMethod = property.GetMethod;
			FieldInfo field = typeFromHandle.GetField("allPlayersDead");
			object obj = null;
			for (int i = 0; i < list.Count - 2; i++)
			{
				if (list[i].opcode == OpCodes.Call && CodeInstructionExtensions.Calls(list[i], getMethod) && list[i + 1].opcode == OpCodes.Ldfld && CodeInstructionExtensions.LoadsField(list[i + 1], field, false) && list[i + 2].opcode == OpCodes.Brfalse)
				{
					num = i;
					list[i].labels.Add(item);
					obj = list[i + 2].operand;
					break;
				}
			}
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			list2.Add(new CodeInstruction(OpCodes.Br, obj));
			if (num != -1)
			{
				list.InsertRange(num, list2);
			}
			return list;
		}
	}
}