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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using DoNotEatItems.Dependency;
using GameNetcodeStuff;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("DoNotEatItems")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0+d6effa733d3b24f81d4e0184e365ca4a70aa65bf")]
[assembly: AssemblyProduct("Do Not Eat Items")]
[assembly: AssemblyTitle("DoNotEatItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.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 DoNotEatItems
{
[BepInPlugin("mattymatty.DoNotEatItems", "DoNotEatItems", "2.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class DoNotEatItems : BaseUnityPlugin
{
public const string GUID = "mattymatty.DoNotEatItems";
public const string NAME = "DoNotEatItems";
public const string VERSION = "2.1.0";
internal static ManualLogSource Log;
private void Awake()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
try
{
if (LobbyCompatibilityChecker.Enabled)
{
LobbyCompatibilityChecker.Init();
}
Log.LogInfo((object)"Patching Methods");
Harmony val = new Harmony("mattymatty.DoNotEatItems");
val.PatchAll(Assembly.GetExecutingAssembly());
Log.LogInfo((object)"DoNotEatItems v2.1.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_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Expected O, but got Unknown
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
MethodInfo method = typeof(PlayerControllerB).GetMethod("KillPlayerClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo method2 = typeof(PlayerControllerB).GetMethod("DropAllHeldItemsAndSync", BindingFlags.Instance | BindingFlags.Public);
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))
{
CodeInstruction val2 = list[i + 1];
if (CodeInstructionExtensions.Branches(val2, ref label))
{
num = i + 2;
}
}
if (num != -1 && CodeInstructionExtensions.Calls(val, method))
{
int index = i - (method.GetParameters().Length + ((!method.IsStatic) ? 1 : 0));
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
});
list.Insert(num, new CodeInstruction(OpCodes.Call, (object)method2)
{
labels = list[num].labels,
blocks = list[num].blocks
});
list.Insert(num, new CodeInstruction(OpCodes.Ldarg_0, (object)null)
{
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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Expected O, but got Unknown
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Expected O, but got Unknown
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
MethodInfo method = typeof(PlayerControllerB).GetMethod("DropAllHeldItems");
MethodInfo method2 = typeof(DropItemOnDeathPatch).GetMethod("LogDrop", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
for (int i = 0; i < list.Count; i++)
{
CodeInstruction val = list[i];
if (CodeInstructionExtensions.Calls(val, method))
{
list[i - 2] = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null)
{
labels = list[i - 2].labels,
blocks = list[i - 2].blocks
};
list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)method2));
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
DoNotEatItems.Log.LogDebug((object)"KillPlayer Patched!");
break;
}
}
return list;
}
private static void LogDrop(PlayerControllerB controllerB)
{
DoNotEatItems.Log.LogWarning((object)$"Dropped all items for dead player {((Object)controllerB).GetInstanceID()}({controllerB.playerUsername})!");
}
}
}
namespace DoNotEatItems.Dependency
{
public static class LobbyCompatibilityChecker
{
public static bool Enabled => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void Init()
{
PluginHelper.RegisterPlugin("mattymatty.DoNotEatItems", Version.Parse("2.1.0"), (CompatibilityLevel)1, (VersionStrictness)2);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}