Decompiled source of DropItemFixed v0.1.6

DropItem.dll

Decompiled a week ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
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 Agents;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils;
using CullingSystem;
using DropItem.Comps;
using DropItem.Handlers;
using GTFO.API;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.InteropTypes.Fields;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Localization;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DropItem")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1+git23513b5-dirty-master.23513b5660352a96926d753391e3a64812864f1f")]
[assembly: AssemblyProduct("DropItem")]
[assembly: AssemblyTitle("DropItem")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace DropItem
{
	[BepInPlugin("DropItem.GUID", "DropItem", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class EntryPoint : BasePlugin
	{
		private Harmony _Harmony;

		public override void Load()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			ClassInjector.RegisterTypeInIl2Cpp<DropItemUpdater>();
			ClassInjector.RegisterTypeInIl2Cpp<DropItemInteractionHandler>();
			ClassInjector.RegisterTypeInIl2Cpp<DropItemGhostHandler>();
			ClassInjector.RegisterTypeInIl2Cpp<ResourceContainerSlot>();
			_Harmony = new Harmony("DropItem.Harmony");
			_Harmony.PatchAll();
			LevelAPI.OnLevelCleanup += ResourceContainerSlot.OnLevelCleanup;
		}
	}
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			_Logger = new ManualLogSource("DropItem");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
		}
	}
	internal class SlotInfo
	{
		public static readonly SlotInfo[] LockerSlotInfo = new SlotInfo[6]
		{
			new SlotInfo(new Vector3(-0.724f, -0.252f, 1.754f), new Vector3(0.42f, 0.433f, 0.3f)),
			new SlotInfo(new Vector3(-0.672f, -0.252f, 1.454f), new Vector3(0.5f, 0.433f, 0.25f)),
			new SlotInfo(new Vector3(-0.672f, -0.252f, 1.154f), new Vector3(0.5f, 0.433f, 0.25f)),
			new SlotInfo(new Vector3(-0.672f, -0.252f, 0.854f), new Vector3(0.5f, 0.433f, 0.25f)),
			new SlotInfo(new Vector3(-0.672f, -0.252f, 0.354f), new Vector3(0.5f, 0.433f, 0.67f)),
			new SlotInfo(new Vector3(-0.276f, -0.252f, 1.754f), new Vector3(0.42f, 0.433f, 0.3f))
		};

		public static readonly SlotInfo[] BoxSlotInfo = new SlotInfo[3]
		{
			new SlotInfo(new Vector3(0.009f, 0f, 0.163f), new Vector3(0.33f, 0.54f, 0.323f)),
			new SlotInfo(new Vector3(-0.343f, 0f, 0.163f), new Vector3(0.34f, 0.54f, 0.323f)),
			new SlotInfo(new Vector3(0.358f, 0f, 0.163f), new Vector3(0.33f, 0.54f, 0.323f))
		};

		public readonly Vector3 LocalPosition;

		public readonly Vector3 LocalScale;

		public SlotInfo(Vector3 position, Vector3 scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			LocalPosition = position;
			LocalScale = scale;
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.1.3+git35c0c2a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "DropItem";

		public const string Version = "1.0.1";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = "git23513b5-dirty-master";

		public const string SemVer = "1.0.1+git23513b5-dirty-master";

		public const string GitRevShort = "23513b5-dirty";

		public const string GitRevLong = "23513b5660352a96926d753391e3a64812864f1f-dirty";

		public const string GitBranch = "master";

		public const string GitTag = null;

		public const int GitCommitsSinceTag = 0;

		public const bool GitIsDirty = true;
	}
}
namespace DropItem.Inject
{
	[HarmonyPatch(typeof(LG_PickupItem_Sync))]
	internal static class Inject_LG_PickupItem_Sync
	{
		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		private static void Post_Setup(LG_PickupItem_Sync __instance)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (ResourceContainerSlot.IsValidItemForSlot(__instance.item))
			{
				pPickupItemState currentState = __instance.GetCurrentState();
				if ((int)currentState.status == 0 && ResourceContainerSlot.TryFindSlotInPosition(currentState.placement.position, out var slot))
				{
					slot.AddItem(__instance);
				}
			}
		}

		[HarmonyPatch("OnStateChange")]
		[HarmonyPrefix]
		private static void Pre_OnStateChange(LG_PickupItem_Sync __instance, pPickupItemState newState, bool isRecall)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!ResourceContainerSlot.IsValidItemForSlot(__instance.item) || newState.updateCustomDataOnly || isRecall)
			{
				return;
			}
			ResourceContainerSlot slot2;
			if ((int)newState.status == 0)
			{
				if (ResourceContainerSlot.TryFindSlotInPosition(newState.placement.position, out var slot))
				{
					slot.AddItem(__instance);
				}
			}
			else if ((int)newState.status == 1 && ResourceContainerSlot.TryFindSlotInPosition(((Component)__instance).transform.position, out slot2))
			{
				slot2.RemoveItem(__instance);
			}
		}

		[HarmonyPatch("OnStateChange")]
		[HarmonyPostfix]
		private static void Post_OnStateChange(LG_PickupItem_Sync __instance)
		{
			ItemCuller component = ((Component)__instance).GetComponent<ItemCuller>();
			if ((Object)(object)component != (Object)null)
			{
				((C_Cullable)((C_SpecialRenderableObject)component).CullBucket).NeedsShadowRefresh = true;
				((C_SpecialRenderableObject)component).CullBucket.SetDirtyCMDBuffer();
			}
		}

		private static IEnumerator ItemUpdateRoutine(GameObject item)
		{
			Vector3 lastPosition = item.transform.position;
			while (true)
			{
				Vector3 position = item.transform.position;
				_ = lastPosition != position;
				yield return null;
			}
		}
	}
	[HarmonyPatch(typeof(LG_WeakResourceContainer))]
	internal static class Inject_LG_WeakResourceContainer
	{
		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void Post_Setup(LG_WeakResourceContainer __instance)
		{
			LG_WeakResourceContainer_Graphics val = ((Il2CppObjectBase)__instance.m_graphics).TryCast<LG_WeakResourceContainer_Graphics>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			LG_ResourceContainer_Storage val2 = ((Il2CppObjectBase)__instance.m_storage).TryCast<LG_ResourceContainer_Storage>();
			if (!((Object)(object)val2 == (Object)null) && !((Object)(object)((Il2CppObjectBase)__instance.m_sync).TryCast<LG_ResourceContainer_Sync>() == (Object)null))
			{
				Transform transform = ((Component)__instance).transform;
				if (__instance.m_isLocker)
				{
					CreateSlot(transform, SlotInfo.LockerSlotInfo[0]).Setup(val, val2, 0);
					CreateSlot(transform, SlotInfo.LockerSlotInfo[1]).Setup(val, val2, 1);
					CreateSlot(transform, SlotInfo.LockerSlotInfo[2]).Setup(val, val2, 2);
					CreateSlot(transform, SlotInfo.LockerSlotInfo[3]).Setup(val, val2, 3);
					CreateSlot(transform, SlotInfo.LockerSlotInfo[4]).Setup(val, val2, 4);
					CreateSlot(transform, SlotInfo.LockerSlotInfo[5]).Setup(val, val2, 5);
				}
				else
				{
					CreateSlot(transform, SlotInfo.BoxSlotInfo[0]).Setup(val, val2, 0);
					CreateSlot(transform, SlotInfo.BoxSlotInfo[1]).Setup(val, val2, 1);
					CreateSlot(transform, SlotInfo.BoxSlotInfo[2]).Setup(val, val2, 2);
				}
			}
		}

		private static ResourceContainerSlot CreateSlot(Transform root, SlotInfo info)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject
			{
				layer = DropItemManager.InteractionLayer
			};
			val.transform.SetParent(root);
			val.transform.localRotation = Quaternion.identity;
			val.transform.localPosition = info.LocalPosition;
			val.transform.localScale = info.LocalScale;
			ResourceContainerSlot resourceContainerSlot = val.AddComponent<ResourceContainerSlot>();
			resourceContainerSlot.Collider.Set(val.AddComponent<BoxCollider>());
			return resourceContainerSlot;
		}
	}
	[HarmonyPatch(typeof(LocalPlayerAgent), "Setup")]
	internal static class Inject_LocalPlayerAgent
	{
		private static void Postfix(LocalPlayerAgent __instance)
		{
			GameObject gameObject = ((Component)__instance).gameObject;
			if ((Object)(object)gameObject.GetComponent<DropItemUpdater>() == (Object)null)
			{
				DropItemUpdater dropItemUpdater = gameObject.AddComponent<DropItemUpdater>();
				gameObject.AddComponent<DropItemGhostHandler>();
				gameObject.AddComponent<DropItemInteractionHandler>();
				dropItemUpdater.Agent = __instance;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerInteraction), "UpdateWorldInteractions")]
	internal static class Inject_PlayerInteraction
	{
		private static bool Prefix()
		{
			return !DropItemManager.InteractionAllowed;
		}
	}
	[HarmonyPatch(typeof(ResourcePackFirstPerson), "UpdateInteraction")]
	internal static class Inject_ResourcePackFirstPerson
	{
		private static bool Prefix()
		{
			return !DropItemManager.InteractionAllowed;
		}
	}
	[HarmonyPatch(typeof(SNet_SyncManager), "OnRecallDone")]
	internal static class Inject_SNet_SyncManager
	{
		private static void Postfix()
		{
			//IL_006b: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			foreach (Object item in (Il2CppArrayBase<Object>)(object)Object.FindObjectsOfTypeAll(Il2CppType.Of<ResourceContainerSlot>()))
			{
				((Il2CppObjectBase)item).Cast<ResourceContainerSlot>().RemoveAllItem();
			}
			foreach (Object item2 in (Il2CppArrayBase<Object>)(object)Object.FindObjectsOfTypeAll(Il2CppType.Of<LG_PickupItem_Sync>()))
			{
				LG_PickupItem_Sync val = ((Il2CppObjectBase)item2).TryCast<LG_PickupItem_Sync>();
				if (!((Object)(object)val == (Object)null) && ResourceContainerSlot.IsValidItemForSlot(val.item))
				{
					pPickupItemState currentState = val.GetCurrentState();
					if ((int)currentState.status == 0 && ResourceContainerSlot.TryFindSlotInPosition(currentState.placement.position, out var slot))
					{
						slot.AddItem(val);
					}
				}
			}
			Logger.Error("Recalled!");
		}
	}
}
namespace DropItem.Handlers
{
	internal sealed class DropItemGhostHandler : MonoBehaviour
	{
		private GameObject _ItemGhost;

		private void Awake()
		{
			DropItemManager.OnUpdated += DropItemManager_OnUpdated;
		}

		private void OnDestroy()
		{
			DropItemManager.OnUpdated -= DropItemManager_OnUpdated;
			DespawnGhost();
		}

		private void DropItemManager_OnUpdated()
		{
			TryUpdateGhost();
		}

		[HideFromIl2Cpp]
		private void TryUpdateGhost()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if (!DropItemManager.InteractionAllowed)
			{
				DespawnGhost();
				return;
			}
			InventorySlot wieldingSlot = DropItemManager.WieldingSlot;
			ResourceContainerSlot slot = DropItemManager.Slot;
			uint itemID_gearCRC = ((Item)DropItemManager.WieldingItem).Get_pItemData().itemID_gearCRC;
			List<GameObject> val = ((Il2CppArrayBase<Dictionary<uint, List<GameObject>>>)(object)ItemSpawnManager.m_loadedPrefabsPerItemMode)[2][itemID_gearCRC];
			if (val == null || val.Count < 1 || (Object)(object)val[0] == (Object)null)
			{
				return;
			}
			Transform transform = slot.GetTransform(wieldingSlot);
			DespawnGhost();
			_ItemGhost = Object.Instantiate<GameObject>(val[0], transform.position, transform.rotation);
			foreach (Renderer componentsInChild in _ItemGhost.GetComponentsInChildren<Renderer>())
			{
				foreach (Material item in (Il2CppArrayBase<Material>)(object)componentsInChild.materials)
				{
					item.shader = Shader.Find("Transparent/Diffuse");
					Color black = Color.black;
					item.color = ((Color)(ref black)).AlphaMultiplied(0.25f);
				}
			}
		}

		[HideFromIl2Cpp]
		private void DespawnGhost()
		{
			if ((Object)(object)_ItemGhost != (Object)null)
			{
				Object.Destroy((Object)(object)_ItemGhost);
			}
			_ItemGhost = null;
		}
	}
	internal sealed class DropItemInteractionHandler : MonoBehaviour
	{
		private bool _DropAllowed;

		private bool _HoldingKey;

		private static string _DropPromptMessage = string.Empty;

		private static string _DropPromptButton = string.Empty;

		private Coroutine _InteractionRoutine;

		private void Awake()
		{
			DropItemManager.OnUpdated += DropItemManager_OnUpdated;
		}

		private void OnDestroy()
		{
			DropItemManager.OnUpdated -= DropItemManager_OnUpdated;
		}

		[HideFromIl2Cpp]
		private void DropItemManager_OnUpdated()
		{
			_DropAllowed = DropItemManager.InteractionAllowed;
			if (_DropAllowed)
			{
				UpdateDropMessage();
				SetDropMessage();
			}
			else
			{
				GuiManager.InteractionLayer.InteractPromptVisible = false;
				GuiManager.InteractionLayer.SetInteractPrompt("", "", (ePUIMessageStyle)0);
			}
		}

		private void Update()
		{
			if (_DropAllowed && !_HoldingKey)
			{
				if (InputMapper.GetButtonDownKeyMouseGamepad((InputAction)6, (eFocusState)4))
				{
					StartRoutine();
					_HoldingKey = true;
				}
			}
			else if (InputMapper.GetButtonUpKeyMouseGamepad((InputAction)6, (eFocusState)4))
			{
				StopRoutine();
				_HoldingKey = false;
			}
		}

		[HideFromIl2Cpp]
		private static void UpdateDropMessage()
		{
			_DropPromptMessage = string.Format(Text.Get(864u), ((Item)DropItemManager.WieldingItem).PublicName);
			_DropPromptButton = string.Format(Text.Get(827u), InputMapper.GetBindingName((InputAction)6));
		}

		private static void SetDropMessage()
		{
			GuiManager.InteractionLayer.InteractPromptVisible = true;
			GuiManager.InteractionLayer.SetInteractPrompt(_DropPromptMessage, _DropPromptButton, (ePUIMessageStyle)0);
		}

		[HideFromIl2Cpp]
		private void StartRoutine()
		{
			StopRoutine();
			_InteractionRoutine = MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)this, Interaction(0.4f));
			StartInteraction();
		}

		[HideFromIl2Cpp]
		private void StopRoutine()
		{
			if (_InteractionRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_InteractionRoutine);
				StopInteraction();
			}
		}

		[HideFromIl2Cpp]
		private static void StartInteraction()
		{
			GuiManager.InteractionLayer.InteractPromptVisible = true;
		}

		[HideFromIl2Cpp]
		private static void StopInteraction()
		{
			GuiManager.InteractionLayer.InteractPromptVisible = false;
		}

		[HideFromIl2Cpp]
		private IEnumerator Interaction(float interactionTime)
		{
			SetDropMessage();
			float timer = 0f;
			bool timerInterrupted = false;
			while (timer <= interactionTime)
			{
				if (!DropItemManager.InteractionAllowed)
				{
					timerInterrupted = true;
					break;
				}
				SetDropMessage();
				GuiManager.InteractionLayer.SetTimer(timer / interactionTime);
				timer += Time.deltaTime;
				yield return null;
			}
			if (!timerInterrupted)
			{
				DropItemManager.DropWieldingItemToSlot();
			}
			StopInteraction();
			_InteractionRoutine = null;
		}
	}
	internal static class DropItemManager
	{
		public static readonly int InteractionLayer = LayerMask.NameToLayer("Debris");

		public static readonly int InteractionMask = LayerMask.GetMask(new string[1] { "Debris" });

		public static readonly int InteractionBlockMask = LayerMask.GetMask(new string[4] { "Default", "Default_NoGraph", "Default_BlockGraph", "Dynamic" });

		public static ItemEquippable WieldingItem { get; private set; }

		public static InventorySlot WieldingSlot { get; private set; } = (InventorySlot)0;


		public static ResourceContainerSlot Slot { get; private set; }

		public static bool HasValidItem
		{
			get
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Invalid comparison between Unknown and I4
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Invalid comparison between Unknown and I4
				if ((Object)(object)WieldingItem != (Object)null)
				{
					if ((int)WieldingSlot != 5)
					{
						return (int)WieldingSlot == 4;
					}
					return true;
				}
				return false;
			}
		}

		public static bool InteractionAllowed { get; private set; } = false;


		public static event Action OnUpdated;

		public static void SetWieldingItem(ItemEquippable wieldingItem, InventorySlot slot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (WieldingSlot != slot)
			{
				WieldingItem = wieldingItem;
				WieldingSlot = slot;
				Update();
				return;
			}
			IntPtr intPtr = IntPtr.Zero;
			IntPtr intPtr2 = IntPtr.Zero;
			if ((Object)(object)WieldingItem != (Object)null)
			{
				intPtr = ((Il2CppObjectBase)WieldingItem).Pointer;
			}
			if ((Object)(object)wieldingItem != (Object)null)
			{
				intPtr2 = ((Il2CppObjectBase)wieldingItem).Pointer;
			}
			if (intPtr != intPtr2)
			{
				WieldingItem = wieldingItem;
				WieldingSlot = slot;
				Update();
			}
		}

		public static void SetDropSlot(ResourceContainerSlot slot)
		{
			IntPtr intPtr = IntPtr.Zero;
			IntPtr intPtr2 = IntPtr.Zero;
			if ((Object)(object)Slot != (Object)null)
			{
				intPtr = ((Il2CppObjectBase)Slot).Pointer;
			}
			if ((Object)(object)slot != (Object)null)
			{
				intPtr2 = ((Il2CppObjectBase)slot).Pointer;
			}
			if (intPtr != intPtr2)
			{
				Slot = slot;
				Update();
			}
		}

		public static bool TryGetItemInLevel(out ItemInLevel itemInLevel)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (!HasValidItem)
			{
				itemInLevel = null;
				return false;
			}
			Item val = default(Item);
			if (!PlayerBackpackManager.TryGetItemInLevelFromItemData(((Item)WieldingItem).Get_pItemData(), ref val))
			{
				itemInLevel = null;
				return false;
			}
			itemInLevel = ((Il2CppObjectBase)val).TryCast<ItemInLevel>();
			return (Object)(object)itemInLevel != (Object)null;
		}

		public static void DropWieldingItemToSlot()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!WieldingItem.AllowPlayerInteraction || !TryGetItemInLevel(out var itemInLevel))
			{
				return;
			}
			iPickupItemSync syncComponent = itemInLevel.GetSyncComponent();
			if (syncComponent == null)
			{
				return;
			}
			Transform transform = Slot.GetTransform(WieldingSlot);
			pItemData_Custom customData = syncComponent.GetCustomData();
			if (PlayerBackpackManager.LocalBackpack != null)
			{
				PlayerAmmoStorage ammoStorage = PlayerBackpackManager.LocalBackpack.AmmoStorage;
				if (ammoStorage != null)
				{
					customData.ammo = ammoStorage.GetInventorySlotAmmo(WieldingSlot).AmmoInPack;
					syncComponent.AttemptPickupInteraction((ePickupItemInteractionType)1, SNet.LocalPlayer, customData, transform.position, transform.rotation, Slot.Storage.Value.m_core.SpawnNode, false, false);
				}
			}
		}

		private static void Update()
		{
			InteractionAllowed = IsInteractionAllowed();
			DropItemManager.OnUpdated?.Invoke();
		}

		private static bool IsInteractionAllowed()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			if ((Object)(object)WieldingItem == (Object)null)
			{
				return false;
			}
			if ((Object)(object)Slot == (Object)null)
			{
				return false;
			}
			bool num = (int)WieldingSlot == 5 || (int)WieldingSlot == 4;
			bool flag = !Slot.GetIsSlotInUse();
			bool flag2 = Slot.IsContainerOpened();
			bool allowPlayerInteraction = WieldingItem.AllowPlayerInteraction;
			return num && flag && flag2 && allowPlayerInteraction;
		}

		public static void Clear()
		{
			InteractionAllowed = false;
			WieldingItem = null;
			WieldingSlot = (InventorySlot)0;
			Slot = null;
		}
	}
	internal sealed class DropItemUpdater : MonoBehaviour
	{
		public LocalPlayerAgent Agent;

		[HideFromIl2Cpp]
		public Ray AgentRay
		{
			get
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				Ray result = default(Ray);
				((Ray)(ref result)).origin = ((PlayerAgent)Agent).FPSCamera.Position;
				((Ray)(ref result)).direction = ((PlayerAgent)Agent).FPSCamera.Forward;
				return result;
			}
		}

		private void Awake()
		{
			DropItemManager.Clear();
		}

		private void OnDestroy()
		{
			DropItemManager.Clear();
		}

		private void FixedUpdate()
		{
			UpdateSlotInRay();
			UpdateWieldingItem();
		}

		private void UpdateSlotInRay()
		{
			//IL_0001: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(AgentRay, ref val, 1.35f, DropItemManager.InteractionMask) && !((Object)(object)((RaycastHit)(ref val)).collider == (Object)null) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).gameObject == (Object)null))
			{
				ResourceContainerSlot component = ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponent<ResourceContainerSlot>();
				if (!((Object)(object)component == (Object)null) && !component.GetIsSlotInUse() && component.IsContainerOpened() && !Physics.Linecast(((Agent)Agent).EyePosition, ((RaycastHit)(ref val)).point, DropItemManager.InteractionBlockMask))
				{
					DropItemManager.SetDropSlot(component);
					return;
				}
			}
			DropItemManager.SetDropSlot(null);
		}

		private void UpdateWieldingItem()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			PlayerInventoryBase inventory = ((PlayerAgent)Agent).Inventory;
			if ((Object)(object)inventory != (Object)null)
			{
				InventorySlot wieldedSlot = inventory.WieldedSlot;
				DropItemManager.SetWieldingItem(inventory.WieldedItem, wieldedSlot);
			}
			else
			{
				DropItemManager.SetWieldingItem(null, (InventorySlot)0);
			}
		}
	}
}
namespace DropItem.Comps
{
	internal sealed class ResourceContainerSlot : MonoBehaviour
	{
		private static readonly Dictionary<IntPtr, ResourceContainerSlot> _CreatedSlots = new Dictionary<IntPtr, ResourceContainerSlot>();

		public Il2CppReferenceField<BoxCollider> Collider;

		public Il2CppReferenceField<LG_WeakResourceContainer_Graphics> Graphic;

		public Il2CppReferenceField<LG_ResourceContainer_Storage> Storage;

		public Il2CppReferenceField<StorageSlot> Slot;

		public Il2CppValueField<int> SlotIndex;

		public readonly Dictionary<IntPtr, LG_PickupItem_Sync> SlotItems = new Dictionary<IntPtr, LG_PickupItem_Sync>(4);

		[HideFromIl2Cpp]
		public void Setup(LG_WeakResourceContainer_Graphics graphic, LG_ResourceContainer_Storage storage, int slotIndex)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			bool flag = default(bool);
			if ((Object)(object)graphic == (Object)null)
			{
				Object.Destroy((Object)(object)this);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(57, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slot was invalid::Graphic was null! Destroying...: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)this).transform.parent).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Idx: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(slotIndex);
				}
				Logger.Error(val);
			}
			if ((Object)(object)storage == (Object)null)
			{
				Object.Destroy((Object)(object)this);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(57, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slot was invalid::Storage was null! Destroying...: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)this).transform.parent).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Idx: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(slotIndex);
				}
				Logger.Error(val);
			}
			if (((Il2CppArrayBase<StorageSlot>)(object)storage.m_storageSlots).Length <= slotIndex)
			{
				Object.Destroy((Object)(object)this);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(61, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slot was invalid::Index Exceed Capacity! Destroying...: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)this).transform.parent).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(slotIndex);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" of ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(((Il2CppArrayBase<StorageSlot>)(object)storage.m_storageSlots).Length);
				}
				Logger.Error(val);
			}
			StorageSlot val2 = ((Il2CppArrayBase<StorageSlot>)(object)storage.m_storageSlots)[slotIndex];
			if (val2 == null)
			{
				Object.Destroy((Object)(object)this);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(49, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Slot was invalid::Slot Was null? Destroying...: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)this).transform.parent).name);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(slotIndex);
				}
				Logger.Error(val);
			}
			Graphic.Set(graphic);
			Storage.Set(storage);
			Slot.Set(val2);
			SlotIndex.Set(slotIndex);
			_CreatedSlots.Add(((Il2CppObjectBase)this).Pointer, this);
		}

		public void OnDestroy()
		{
			_CreatedSlots.Remove(((Il2CppObjectBase)this).Pointer);
		}

		[HideFromIl2Cpp]
		public bool IsContainerOpened()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			return (int)Graphic.Value.m_status == 3;
		}

		[HideFromIl2Cpp]
		public bool GetIsSlotInUse()
		{
			return SlotItems.Count > 0;
		}

		[HideFromIl2Cpp]
		public void AddItem(LG_PickupItem_Sync sync)
		{
			SlotItems.TryAdd(((Il2CppObjectBase)((Component)sync).gameObject).Pointer, sync);
		}

		[HideFromIl2Cpp]
		public void RemoveItem(LG_PickupItem_Sync sync)
		{
			SlotItems.Remove(((Il2CppObjectBase)((Component)sync).gameObject).Pointer);
		}

		[HideFromIl2Cpp]
		public void RemoveAllItem()
		{
			SlotItems.Clear();
		}

		[HideFromIl2Cpp]
		public Transform GetTransform(InventorySlot slot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)slot != 4)
			{
				if ((int)slot == 5)
				{
					return Slot.Value.Consumable;
				}
				return Slot.Value.Consumable;
			}
			return Slot.Value.ResourcePack;
		}

		[HideFromIl2Cpp]
		public static bool IsValidItemForDrop(Item item)
		{
			//IL_001b: 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)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			if (item.ItemDataBlock == null)
			{
				return false;
			}
			InventorySlot inventorySlot = item.ItemDataBlock.inventorySlot;
			if (inventorySlot - 4 <= 1)
			{
				return true;
			}
			return false;
		}

		[HideFromIl2Cpp]
		public static bool IsValidItemForSlot(Item item)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			if (item.ItemDataBlock == null)
			{
				return false;
			}
			if (((GameDataBlockBase<ItemDataBlock>)(object)item.ItemDataBlock).persistentID == Item.ARTIFACT_Base_ItemData)
			{
				return true;
			}
			InventorySlot inventorySlot = item.ItemDataBlock.inventorySlot;
			if (inventorySlot - 4 <= 1 || (int)inventorySlot == 7)
			{
				return true;
			}
			return false;
		}

		[HideFromIl2Cpp]
		public static bool TryFindSlotInPosition(Vector3 pos, out ResourceContainerSlot slot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			foreach (Collider item in (Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(pos, 0.001f, DropItemManager.InteractionMask))
			{
				slot = ((Component)item).gameObject.GetComponent<ResourceContainerSlot>();
				if ((Object)(object)slot != (Object)null)
				{
					return true;
				}
			}
			slot = null;
			return false;
		}

		[HideFromIl2Cpp]
		public static void OnLevelCleanup()
		{
			foreach (ResourceContainerSlot value in _CreatedSlots.Values)
			{
				if (!((Object)(object)value != (Object)null))
				{
					continue;
				}
				foreach (LG_PickupItem_Sync value2 in value.SlotItems.Values)
				{
					if ((Object)(object)value2 != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)value2).gameObject);
					}
				}
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
			_CreatedSlots.Clear();
		}
	}
}