Decompiled source of DropItem Addition v1.1.2

DropItemAddition.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using RoR2;
using RoR2.Orbs;
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: AssemblyCompany("DropItemAddition")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DropItemAddition")]
[assembly: AssemblyTitle("DropItemAddition")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ShrineClamper.Utils
{
	public static class ListHandlers
	{
		public static List<ItemDef> ItemDefList { get; }
	}
}
namespace DropItemAddition
{
	[BepInPlugin("thebugreport.dropItemAddition", "DropItemAddition", "1.1.0")]
	public class DropItemAdditionMod : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private Harmony _harmony;

		public GameObject gameObjectTransferOrb;

		internal static DropItemAdditionMod Instance { get; private set; }

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("thebugreport.dropItemAddition");
			try
			{
				gameObjectTransferOrb = LegacyResourcesAPI.Load<GameObject>("Prefabs/Effects/OrbEffects/ItemTransferOrbEffect");
				if ((Object)(object)gameObjectTransferOrb == (Object)null)
				{
					Log.LogError((object)"Failed to load ItemTransferOrbEffect!");
				}
				else
				{
					Log.LogInfo((object)("Loaded transfer orb: " + ((Object)gameObjectTransferOrb).name));
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error loading transfer orb: {arg}");
			}
			try
			{
				AccessTools.Method("Dropitem.Give:Give_Item", new Type[2]
				{
					typeof(NetworkUser),
					typeof(string[])
				}, (Type[])null);
				MethodInfo methodInfo = AccessTools.Method("Dropitem.Drop:Drop_item", new Type[2]
				{
					typeof(NetworkUser),
					typeof(string[])
				}, (Type[])null);
				if (methodInfo == null)
				{
					Log.LogError((object)"Failed to find Dropitem.Drop.Drop_item(NetworkUser, string[]). Is Dropitem loaded?");
					return;
				}
				_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(GiveItemPatch), "PrefixDropItem", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"Patched Dropitem_Additions successfully.");
			}
			catch (Exception arg2)
			{
				Log.LogError((object)$"Error patching Dropitem_Additions {arg2}");
			}
			DI.InitializeDI();
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch (Exception arg)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogError((object)$"Error unpatching: {arg}");
				}
			}
		}
	}
	public static class GiveItemPatch
	{
		public static bool PrefixGiveItem(NetworkUser sender, string[] args, ref string __result)
		{
			DropItemAdditionMod instance = DropItemAdditionMod.Instance;
			__result = DropReplacement.GiveItem(sender, args, instance);
			return false;
		}

		public static bool PrefixDropItem(NetworkUser sender, string[] args, ref string __result)
		{
			DropItemAdditionMod instance = DropItemAdditionMod.Instance;
			__result = DropReplacement.DropItem(sender, args, instance);
			return false;
		}
	}
	internal static class DropReplacement
	{
		public static string GiveItem(NetworkUser sender, string[] args, DropItemAdditionMod mod)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Invalid comparison between Unknown and I4
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Invalid comparison between Unknown and I4
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Invalid comparison between Unknown and I4
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Invalid comparison between Unknown and I4
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Invalid comparison between Unknown and I4
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Expected I4, but got Unknown
			//IL_038c: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			if (!DI.Users_CheckUserPerms(sender, out var text))
			{
				return text;
			}
			Inventory inventory = sender.master.inventory;
			PlayerCharacterMasterController val = DI.StringParsers_GetNetUserFromString(args[1]);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return "<color=#FF8282>Could not find specified </color>player<color=#FF8282> '<color=#ff4646>" + args[1] + "</color>'</color>";
			}
			Inventory inventory2 = val.master.inventory;
			if (!Object.op_Implicit((Object)(object)inventory) || !Object.op_Implicit((Object)(object)inventory2))
			{
				return "<color=#ff4646>ERROR: null inventory</color>";
			}
			if ((Object)(object)inventory == (Object)(object)inventory2)
			{
				return "<color=#FF8282>Target can not be the sender</color>";
			}
			string name;
			if (Object.op_Implicit((Object)(object)val.networkUser))
			{
				name = val.networkUser.userName;
			}
			else
			{
				if (!DI.Config_DropFromDisconnected())
				{
					return "<color=#FF8282>Giving to disconnected players is disabled</color>";
				}
				DI.Users_TryGetCachedName(val, out name);
			}
			name = "<color=#AAE6F0>" + name + "</color>";
			string text2 = "<color=#AAE6F0>" + sender.masterController.GetDisplayName() + "</color>";
			if (Object.op_Implicit((Object)(object)val.networkUser) && DI.Users_IsLocked(val.networkUser))
			{
				return "<color=#FF8282>" + name + " has their inventory locked, failed to give item</color>";
			}
			EquipmentIndex val2 = (EquipmentIndex)(-1);
			ItemIndex val3 = (ItemIndex)(-1);
			if (args[0].ToLower() == "e" || args[0].ToLower() == "equip" || args[0].ToLower() == "equipment")
			{
				val2 = inventory.GetEquipmentIndex();
				if ((int)val2 == -1)
				{
					return "<color=#FF8282>Sender does not have an </color><color=#ff7d00>equipment</color>";
				}
			}
			else
			{
				val3 = DI.StringParsers_FindItemInInventroy(args[0], inventory);
			}
			if ((int)val3 == -1)
			{
				if ((int)val2 == -1)
				{
					val2 = inventory.GetEquipmentIndex();
					if ((int)val2 == -1 || !DI.StringParsers_ReformatString(Language.GetString(EquipmentCatalog.GetEquipmentDef(val2).nameToken)).Contains(DI.StringParsers_ReformatString(args[0])))
					{
						return "<color=#FF8282>Could not find item '<color=#ff4646>" + args[0] + "</color>' in " + text2 + "<color=#AAE6F0>'s</color> inventory</color>";
					}
				}
				if ((int)inventory2.GetEquipmentIndex() != -1)
				{
					return "<color=#FF8282>Target already has an equipment</color>";
				}
				PickupIndex val4 = PickupCatalog.FindPickupIndex(val2);
				string text3 = Util.GenerateColoredString(Language.GetString(EquipmentCatalog.GetEquipmentDef(val2).nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val4).baseColor));
				if (val2 != inventory.GetEquipmentIndex())
				{
					return "<color=#FF8282>Sender does not have </color><color=#ff4646>" + text3 + "</color>";
				}
				if (DI.Drop_IsBlacklisted(EquipmentCatalog.GetEquipmentDef(val2), !DI.Config_ApplyAllowToGive()))
				{
					return text3 + "<color=#FF8282> is not dropable</color>";
				}
				inventory2.SetEquipmentIndex(val2);
				inventory.SetEquipmentIndex((EquipmentIndex)(-1));
				return "<color=#96EBAA>" + text2 + " gave " + text3 + " to </color>" + name;
			}
			ItemDef itemDef = ItemCatalog.GetItemDef(val3);
			PickupIndex val5 = PickupCatalog.FindPickupIndex(val3);
			string text4 = Util.GenerateColoredString(Language.GetString(itemDef.nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val5).baseColor));
			if (DI.Drop_IsBlacklisted(itemDef, !DI.Config_ApplyAllowToGive(), isItem: true))
			{
				return text4 + "<color=#FF8282> is not dropable</color>";
			}
			int num = inventory.GetItemCountPermanent(val3);
			if (num == 0)
			{
				return "<color=#FF8282>Sender does not have </color>" + text4;
			}
			if (num > 1)
			{
				text4 += Util.GenerateColoredString("s", Color32.op_Implicit(PickupCatalog.GetPickupDef(val5).baseColor));
			}
			if (num > 30)
			{
				num = 30;
			}
			inventory2.GiveItemPermanent(val3, num);
			inventory.RemoveItemPermanent(val3, num);
			Vector3 corePosition = sender.master.GetBody().corePosition;
			GameObject gameObject = ((Component)val.master.GetBody()).gameObject;
			GameObject gameObjectTransferOrb = mod.gameObjectTransferOrb;
			EffectData val6 = new EffectData
			{
				origin = corePosition,
				genericFloat = 1f,
				genericUInt = (uint)(val3 + 1)
			};
			val6.SetNetworkedObjectReference(gameObject);
			EffectManager.SpawnEffect(gameObjectTransferOrb, val6, true);
			return string.Format("{0}{1} gave {2} {3} to </color>{4}", "<color=#96EBAA>", text2, num, text4, name);
		}

		public static string DropItem(NetworkUser sender, string[] args, DropItemAdditionMod mod)
		{
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Invalid comparison between Unknown and I4
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Invalid comparison between Unknown and I4
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Invalid comparison between Unknown and I4
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Invalid comparison between Unknown and I4
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Invalid comparison between Unknown and I4
			//IL_057b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Expected I4, but got Unknown
			//IL_05b9: Expected O, but got Unknown
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			if (!DI.Users_CheckUserPerms(sender, out var text))
			{
				return text;
			}
			PlayerCharacterMasterController val = sender.masterController;
			Inventory inventory = sender.master.inventory;
			if (args.Length >= 2)
			{
				val = DI.StringParsers_GetNetUserFromString(args[1]);
				if (!Object.op_Implicit((Object)(object)val))
				{
					return "<color=#FF8282>Could not find specified </color>player<color=#FF8282> '<color=#ff4646>" + args[1] + "</color>'</color>";
				}
				inventory = val.master.inventory;
			}
			if (!Object.op_Implicit((Object)(object)inventory))
			{
				return "<color=#ff4646>ERROR: null inventory</color>";
			}
			CharacterBody currentBody = sender.GetCurrentBody();
			Transform val2 = (((Object)(object)currentBody != (Object)null) ? currentBody.coreTransform : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return "<color=#FF8282>Must be alive to drop items</color>";
			}
			string name;
			if (Object.op_Implicit((Object)(object)val.networkUser))
			{
				name = val.networkUser.userName;
			}
			else
			{
				if (!DI.Config_DropFromDisconnected())
				{
					return "<color=#FF8282>Dropping from disconnected players is disabled</color>";
				}
				DI.Users_TryGetCachedName(val, out name);
			}
			name = "<color=#AAE6F0>" + name + "</color>";
			string text2 = "<color=#AAE6F0>" + sender.masterController.GetDisplayName() + "</color>";
			if (Object.op_Implicit((Object)(object)val.networkUser) && (Object)(object)val.networkUser != (Object)(object)sender && DI.Users_IsLocked(val.networkUser))
			{
				return "<color=#FF8282>" + name + " has their inventory locked</color>";
			}
			Vector3 velocity = sender.GetCurrentBody().inputBank.aimDirection;
			velocity.y = 0f;
			velocity = ((Vector3)(ref velocity)).normalized * 8f + Vector3.up * 15f;
			EquipmentIndex val3 = (EquipmentIndex)(-1);
			ItemIndex val4 = (ItemIndex)(-1);
			if (args[0].Equals("all", StringComparison.InvariantCultureIgnoreCase))
			{
				if (!DI.TryAddDropAll(new GameObject("DropAll"), inventory, sender, val2))
				{
					return "<color=#ff4646>Could not start dropping items</color>";
				}
				if ((Object)(object)val.networkUser == (Object)(object)sender)
				{
					return "<color=#96EBAA>Dropping all items from </color>" + name;
				}
				return "<color=#96EBAA>" + text2 + " is dropping all items from </color>" + name;
			}
			if (args[0].Equals("e", StringComparison.InvariantCultureIgnoreCase) || args[0].Equals("equip", StringComparison.InvariantCultureIgnoreCase) || args[0].Equals("equipment", StringComparison.InvariantCultureIgnoreCase))
			{
				val3 = inventory.GetEquipmentIndex();
				if ((int)val3 == -1)
				{
					return "<color=#FF8282>Target does not have an </color><color=#ff7d00>equipment</color>";
				}
			}
			else
			{
				val4 = DI.StringParsers_FindItemInInventroy(args[0], inventory);
			}
			if ((int)val4 == -1)
			{
				if ((int)val3 == -1)
				{
					val3 = inventory.GetEquipmentIndex();
					if ((int)val3 == -1 || !DI.StringParsers_ReformatString(Language.GetString(EquipmentCatalog.GetEquipmentDef(val3).nameToken)).Contains(DI.StringParsers_ReformatString(args[0])))
					{
						return "<color=#FF8282>Could not find item '<color=#ff4646>" + args[0] + "</color>' in " + name + "<color=#AAE6F0>'s</color> inventory</color>";
					}
				}
				PickupIndex val5 = PickupCatalog.FindPickupIndex(val3);
				string text3 = Util.GenerateColoredString(Language.GetString(EquipmentCatalog.GetEquipmentDef(val3).nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val5).baseColor));
				if (val3 != inventory.GetEquipmentIndex())
				{
					return "<color=#FF8282>Target does not have </color><color=#ff4646>" + text3 + "</color>";
				}
				if (DI.Drop_IsBlacklisted(EquipmentCatalog.GetEquipmentDef(val3), invertAllow: false))
				{
					return text3 + "<color=#FF8282> is not dropable</color>";
				}
				if ((Object)(object)val.networkUser == (Object)(object)sender)
				{
					DI.Drop_MakePickupDroplets(val5, val2.position, velocity, inventory);
					inventory.SetEquipmentIndex((EquipmentIndex)(-1), true);
					return "<color=#96EBAA>Dropped " + text3 + " from </color>" + name;
				}
				inventory = sender.master.inventory;
				Inventory inventory2 = val.networkUser.GetCurrentBody().inventory;
				if ((Object)(object)inventory2 != (Object)null)
				{
					if ((int)inventory.GetEquipmentIndex() != -1)
					{
						return "<color=#FF8282>Target already has an equipment</color>";
					}
					inventory.SetEquipmentIndex(val3);
					inventory2.SetEquipmentIndex((EquipmentIndex)(-1));
					return "<color=#96EBAA>" + text2 + " is dropping " + text3 + " from </color>" + name;
				}
				return "<color=#ff4646>ERROR: null inventory</color>";
			}
			ItemDef itemDef = ItemCatalog.GetItemDef(val4);
			PickupIndex val6 = PickupCatalog.FindPickupIndex(val4);
			string text4 = Util.GenerateColoredString(Language.GetString(itemDef.nameToken), Color32.op_Implicit(PickupCatalog.GetPickupDef(val6).baseColor));
			if (DI.Drop_IsBlacklisted(itemDef, invertAllow: false, isItem: true))
			{
				return text4 + "<color=#FF8282> is not dropable</color>";
			}
			if ((Object)(object)val.networkUser == (Object)(object)sender)
			{
				int num = Math.Min(inventory.GetItemCountPermanent(val4), 20);
				if (args.Length > 2 && int.TryParse(args[2], out var result))
				{
					num = Math.Min(num, result);
				}
				if (num == 0)
				{
					return "<color=#FF8282>Target does not have </color>" + text4;
				}
				if (num > 1)
				{
					text4 += Util.GenerateColoredString("s", Color32.op_Implicit(PickupCatalog.GetPickupDef(val6).baseColor));
				}
				DI.Drop_MakePickupDroplets(val6, val2.position, velocity, inventory, num);
				inventory.RemoveItemPermanent(val4, num);
				return string.Format("{0}{1} dropped {2} {3}</color>", "<color=#96EBAA>", name, num, text4);
			}
			inventory = sender.master.inventory;
			Inventory inventory3 = val.networkUser.master.inventory;
			if ((Object)(object)inventory3 != (Object)null)
			{
				int num2 = Math.Min(inventory3.GetItemCountPermanent(val4), 20);
				if (args.Length > 2 && int.TryParse(args[2], out var result2))
				{
					num2 = Math.Min(num2, result2);
				}
				if (num2 == 0)
				{
					return "<color=#FF8282>Target does not have </color>" + text4;
				}
				if (num2 > 1)
				{
					text4 += Util.GenerateColoredString("s", Color32.op_Implicit(PickupCatalog.GetPickupDef(val6).baseColor));
				}
				inventory.GiveItemPermanent(itemDef, num2);
				inventory3.RemoveItemPermanent(itemDef, num2);
				Vector3 corePosition = val.networkUser.master.GetBody().corePosition;
				GameObject gameObject = ((Component)sender.GetCurrentBody()).gameObject;
				GameObject gameObjectTransferOrb = mod.gameObjectTransferOrb;
				EffectData val7 = new EffectData
				{
					origin = corePosition,
					genericFloat = 1f,
					genericUInt = (uint)(val4 + 1)
				};
				val7.SetNetworkedObjectReference(gameObject);
				EffectManager.SpawnEffect(gameObjectTransferOrb, val7, true);
				return string.Format("{0}{1} is taking {2} {3} from </color>{4}", "<color=#96EBAA>", text2, num2, text4, name);
			}
			return "<color=#ff4646>ERROR: null inventory</color>";
		}
	}
	internal static class DI
	{
		private static Type _tUsers;

		private static Type _tConfig;

		private static Type _tStringParsers;

		private static Type _tDrop;

		private static Type _tDropAll = AccessTools.TypeByName("Dropitem.DropAll");

		private static MethodInfo _miCheckUserPerms;

		private static FieldInfo _fiCachedPlayerNames;

		private static FieldInfo _fiLockedUserIds;

		private static FieldInfo _fiApplyAllowToGive;

		private static FieldInfo _fiDropFromDisconnected;

		private static PropertyInfo _piConfigValue;

		private static MethodInfo _miGetNetUserFromString;

		private static MethodInfo _miFindItemInInventroy;

		private static MethodInfo _miReformatString;

		private static MethodInfo _miIsBlacklistedItem;

		private static MethodInfo _miIsBlacklistedEquip;

		private static MethodInfo _miMakeItemDroplets;

		private static FieldInfo _fiOrbEffectPrefab;

		private static MethodInfo _miDropAllAssign;

		private static Type TUsers => _tUsers ?? (_tUsers = AccessTools.TypeByName("Dropitem.Users"));

		private static Type TConfig => _tConfig ?? (_tConfig = AccessTools.TypeByName("Dropitem.Config"));

		private static Type TStringParsers => _tStringParsers ?? (_tStringParsers = AccessTools.TypeByName("Dropitem.StringParsers"));

		private static Type TDrop => _tDrop ?? (_tDrop = AccessTools.TypeByName("Dropitem.Drop"));

		public static bool Users_CheckUserPerms(NetworkUser sender, out string text)
		{
			text = null;
			if (_miCheckUserPerms == null)
			{
				return true;
			}
			object[] array = new object[2] { sender, null };
			bool result = (bool)_miCheckUserPerms.Invoke(null, array);
			text = (string)array[1];
			return result;
		}

		public static bool Users_TryGetCachedName(PlayerCharacterMasterController pcmc, out string name)
		{
			name = null;
			object obj = _fiCachedPlayerNames?.GetValue(null);
			if (obj == null || (Object)(object)pcmc == (Object)null)
			{
				return false;
			}
			MethodInfo method = obj.GetType().GetMethod("TryGetValue");
			object[] array = new object[2] { pcmc, null };
			bool flag = (bool)method.Invoke(obj, array);
			name = (flag ? ((string)array[1]) : null);
			return flag;
		}

		public static bool Users_IsLocked(NetworkUser target)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				return false;
			}
			object obj = _fiLockedUserIds?.GetValue(null);
			if (obj == null)
			{
				return false;
			}
			return (bool)obj.GetType().GetMethod("Contains").Invoke(obj, new object[1] { target.id });
		}

		public static bool Config_ApplyAllowToGive()
		{
			object obj = _fiApplyAllowToGive?.GetValue(null);
			if (obj == null)
			{
				return false;
			}
			if ((object)_piConfigValue == null)
			{
				_piConfigValue = obj.GetType().GetProperty("Value");
			}
			return (bool)(_piConfigValue?.GetValue(obj) ?? ((object)false));
		}

		public static bool Config_DropFromDisconnected()
		{
			object obj = _fiDropFromDisconnected?.GetValue(null);
			if (obj == null)
			{
				return false;
			}
			if ((object)_piConfigValue == null)
			{
				_piConfigValue = obj.GetType().GetProperty("Value");
			}
			return (bool)(_piConfigValue?.GetValue(obj) ?? ((object)false));
		}

		public static PlayerCharacterMasterController StringParsers_GetNetUserFromString(string s)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			return (PlayerCharacterMasterController)(_miGetNetUserFromString?.Invoke(null, new object[1] { s }));
		}

		public static ItemIndex StringParsers_FindItemInInventroy(string s, Inventory inv)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!(_miFindItemInInventroy != null))
			{
				return (ItemIndex)(-1);
			}
			return (ItemIndex)_miFindItemInInventroy.Invoke(null, new object[2] { s, inv });
		}

		public static string StringParsers_ReformatString(string s)
		{
			return (string)_miReformatString?.Invoke(null, new object[1] { s });
		}

		public static bool Drop_IsBlacklisted(ItemDef itemDef, bool invertAllow, bool isItem, bool defaultArg = false)
		{
			if (_miIsBlacklistedItem == null)
			{
				return false;
			}
			return (bool)_miIsBlacklistedItem.Invoke(null, new object[4] { itemDef, invertAllow, true, defaultArg });
		}

		public static bool Drop_IsBlacklisted(EquipmentDef equipDef, bool invertAllow, bool defaultArg = false)
		{
			if (_miIsBlacklistedEquip == null)
			{
				return false;
			}
			return (bool)_miIsBlacklistedEquip.Invoke(null, new object[3] { equipDef, invertAllow, false });
		}

		public static void Drop_MakePickupDroplets(PickupIndex pickupIndex, Vector3 position, Vector3 velocity, Inventory inventory, int amount = 1)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			_miMakeItemDroplets.Invoke(null, new object[5] { pickupIndex, position, velocity, inventory, amount });
		}

		public static GameObject GetItemTransferOrbPrefab()
		{
			if (_fiOrbEffectPrefab == null)
			{
				return null;
			}
			object? value = _fiOrbEffectPrefab.GetValue(null);
			return (GameObject)((value is GameObject) ? value : null);
		}

		public static bool TryAddDropAll(GameObject gameObject, Inventory inventory, NetworkUser sender, Transform transform)
		{
			if (_tDropAll == null)
			{
				ManualLogSource log = DropItemAdditionMod.Log;
				if (log != null)
				{
					log.LogError((object)"Could not find Dropitem.DropAll.");
				}
				return false;
			}
			Component val = gameObject.AddComponent(_tDropAll);
			if ((Object)(object)val == (Object)null)
			{
				ManualLogSource log2 = DropItemAdditionMod.Log;
				if (log2 != null)
				{
					log2.LogError((object)"Could not add Dropitem.DropAll component.");
				}
				return false;
			}
			if (_miDropAllAssign == null)
			{
				ManualLogSource log3 = DropItemAdditionMod.Log;
				if (log3 != null)
				{
					log3.LogError((object)"Could not find DropAll.Assign method.");
				}
				Object.Destroy((Object)(object)gameObject);
				return false;
			}
			_miDropAllAssign.Invoke(val, new object[3] { inventory, sender, transform });
			return true;
		}

		public static void InitializeDI()
		{
			if ((object)_miCheckUserPerms == null)
			{
				_miCheckUserPerms = AccessTools.Method(TUsers, "CheckUserPerms", new Type[2]
				{
					typeof(NetworkUser),
					typeof(string).MakeByRefType()
				}, (Type[])null);
			}
			if ((object)_miGetNetUserFromString == null)
			{
				_miGetNetUserFromString = AccessTools.Method(TStringParsers, "GetNetUserFromString", new Type[1] { typeof(string) }, (Type[])null);
			}
			if ((object)_miFindItemInInventroy == null)
			{
				_miFindItemInInventroy = AccessTools.Method(TStringParsers, "FindItemInInventroy", new Type[2]
				{
					typeof(string),
					typeof(Inventory)
				}, (Type[])null);
			}
			if ((object)_miReformatString == null)
			{
				_miReformatString = AccessTools.Method(TStringParsers, "ReformatString", new Type[1] { typeof(string) }, (Type[])null);
			}
			if ((object)_miIsBlacklistedItem == null)
			{
				_miIsBlacklistedItem = AccessTools.Method(TDrop, "IsBlacklisted", new Type[4]
				{
					typeof(ItemDef),
					typeof(bool),
					typeof(bool),
					typeof(bool)
				}, (Type[])null);
			}
			if ((object)_miIsBlacklistedEquip == null)
			{
				_miIsBlacklistedEquip = AccessTools.Method(TDrop, "IsBlacklisted", new Type[3]
				{
					typeof(EquipmentDef),
					typeof(bool),
					typeof(bool)
				}, (Type[])null);
			}
			if ((object)_miMakeItemDroplets == null)
			{
				_miMakeItemDroplets = AccessTools.Method(TDrop, "MakePickupDroplets", new Type[5]
				{
					typeof(PickupIndex),
					typeof(Vector3),
					typeof(Vector3),
					typeof(Inventory),
					typeof(int)
				}, (Type[])null);
			}
			if ((object)_miDropAllAssign == null)
			{
				_miDropAllAssign = AccessTools.Method(_tDropAll, "Assign", new Type[3]
				{
					typeof(Inventory),
					typeof(NetworkUser),
					typeof(Transform)
				}, (Type[])null);
			}
			if ((object)_fiCachedPlayerNames == null)
			{
				_fiCachedPlayerNames = AccessTools.Field(TUsers, "cachedPlayerNames");
			}
			if ((object)_fiLockedUserIds == null)
			{
				_fiLockedUserIds = AccessTools.Field(TUsers, "lockedUserIds");
			}
			if ((object)_fiOrbEffectPrefab == null)
			{
				_fiOrbEffectPrefab = AccessTools.Field(typeof(ItemTransferOrb), "orbEffectPrefab");
			}
			if ((object)_fiApplyAllowToGive == null)
			{
				_fiApplyAllowToGive = AccessTools.Field(TConfig, "applyAllowToGive");
			}
			if ((object)_fiDropFromDisconnected == null)
			{
				_fiDropFromDisconnected = AccessTools.Field(TConfig, "dropFromDisconnected");
			}
		}
	}
}