Decompiled source of DoNotEatItems v2.0.0

DoNotEatItems/DoNotEatItems.dll

Decompiled 5 days 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DoNotEatItems")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("DoNotEatItems")]
[assembly: AssemblyCopyright("Copyright © tinyhoot 2023")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace DoNotEatItems
{
	[BepInPlugin("mattymatty.DoNotEatItems", "DoNotEatItems", "2.0.0")]
	internal class DoNotEatItems : BaseUnityPlugin
	{
		public const string GUID = "mattymatty.DoNotEatItems";

		public const string NAME = "DoNotEatItems";

		public const string VERSION = "2.0.0";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				Log.LogInfo((object)"Patching Methods");
				new Harmony("mattymatty.DoNotEatItems").PatchAll(Assembly.GetExecutingAssembly());
				Log.LogInfo((object)"DoNotEatItems v2.0.0 Loaded!");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Exception while initializing: \n" + ex));
			}
		}
	}
}
namespace DoNotEatItems.Patches
{
	[HarmonyPatch]
	internal class DropItemOnDeathPatch
	{
		[HarmonyTranspiler]
		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayerServerRpc")]
		private static IEnumerable<CodeInstruction> KillPlayerServerRpcPatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			MethodInfo method = typeof(PlayerControllerB).GetMethod("KillPlayerClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
			int num = -1;
			Label? label = default(Label?);
			for (int i = 0; i < list.Count; i++)
			{
				CodeInstruction val = list[i];
				if (CodeInstructionExtensions.IsLdarg(val, (int?)2) && CodeInstructionExtensions.Branches(list[i + 1], ref label))
				{
					num = i + 2;
				}
				if (num != -1 && CodeInstructionExtensions.Calls(val, method))
				{
					int index = i - 6;
					if (list[index].labels.Count > 0)
					{
						Label label2 = list[index].labels[0];
						list.Insert(num, new CodeInstruction(OpCodes.Br, (object)label2)
						{
							labels = list[num].labels,
							blocks = list[num].blocks
						});
						DoNotEatItems.Log.LogDebug((object)"KillPlayerServerRpc Patched!");
						break;
					}
				}
			}
			return list;
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
		private static IEnumerable<CodeInstruction> KillPlayerPatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			MethodInfo method = typeof(PlayerControllerB).GetMethod("DropAllHeldItems");
			MethodInfo method2 = typeof(PlayerControllerB).GetMethod("DropAllHeldItemsAndSync");
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.Calls(list[i], method))
				{
					list[i - 2] = new CodeInstruction(OpCodes.Nop, (object)null)
					{
						labels = list[i - 2].labels,
						blocks = list[i - 2].blocks
					};
					list[i - 1] = new CodeInstruction(OpCodes.Nop, (object)null)
					{
						labels = list[i - 1].labels,
						blocks = list[i - 1].blocks
					};
					list[i] = new CodeInstruction(OpCodes.Call, (object)method2)
					{
						labels = list[i].labels,
						blocks = list[i].blocks
					};
					DoNotEatItems.Log.LogDebug((object)"KillPlayer Patched!");
					break;
				}
			}
			return list;
		}
	}
}