Decompiled source of Drop Item Key v1.8.0

DropItemMod.dll

Decompiled 2 months ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("com.batman.dropitem", "Drop Item Key", "1.8.0")]
public class DropItemPlugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		Harmony val = new Harmony("com.batman.dropitem");
		Type type = AccessTools.TypeByName("Character.CoreCharacterController");
		if (type != null)
		{
			MethodInfo methodInfo = AccessTools.Method(type, "Update", (Type[])null, (Type[])null);
			HarmonyMethod val2 = new HarmonyMethod(typeof(DropItemPatch), "Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
}
public static class DropItemPatch
{
	public static void Postfix(object __instance)
	{
		if (!Input.GetKeyDown((KeyCode)103))
		{
			return;
		}
		try
		{
			Type type = __instance.GetType();
			PropertyInfo property = type.GetProperty("IsOwner");
			if (!(property == null) && (bool)property.GetValue(__instance))
			{
				PropertyInfo property2 = type.GetProperty("HeldItemIdx");
				int num = (int)property2.GetValue(__instance);
				MethodInfo method = type.GetMethod("ExpendItemInSlot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(__instance, new object[2] { num, false });
				}
			}
		}
		catch (Exception)
		{
		}
	}
}