Decompiled source of GrabMaterials v0.0.1

GrabMaterials.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GrabMaterials;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("GrabMaterials")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GrabMaterials")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f3f4f7f9-7343-4b53-9531-aa1e3d80ea19")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GrabMaterialsMod
{
	[BepInPlugin("DeathMonger.GrabMaterialsMod", "Automatically Grab Materials", "1.0.0")]
	[BepInProcess("valheim.exe")]
	public class GrabMaterialsMod : BaseUnityPlugin
	{
		private struct ItemToGrab
		{
			public string Name;

			public int Count;

			public string FullName => "$item_" + Name;

			public ItemToGrab(string name, int count)
			{
				Name = name;
				Count = count;
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__9_0;

			public static ConsoleEvent <>9__9_1;

			public static ConsoleEvent <>9__9_2;

			public static ConsoleEvent <>9__9_3;

			public static ConsoleEvent <>9__9_4;

			public static ConsoleEvent <>9__9_5;

			public static ConsoleEvent <>9__9_6;

			internal void <InitCommands>b__9_0(ConsoleEventArgs args)
			{
				ListKnownContainers();
			}

			internal void <InitCommands>b__9_1(ConsoleEventArgs args)
			{
				ListLocalContainers(args);
			}

			internal void <InitCommands>b__9_2(ConsoleEventArgs args)
			{
				ListLocalContainerContents(args);
			}

			internal void <InitCommands>b__9_3(ConsoleEventArgs args)
			{
				FindContainersWithMatchingItems(args);
			}

			internal void <InitCommands>b__9_4(ConsoleEventArgs args)
			{
				GrabItemsFromNearbyContainers(args);
			}

			internal void <InitCommands>b__9_5(ConsoleEventArgs args)
			{
				StoreItemsInNearbyContainers();
			}

			internal void <InitCommands>b__9_6(ConsoleEventArgs args)
			{
				CountInventory(args);
			}
		}

		private const string ModGuid = "DeathMonger.GrabMaterialsMod";

		private readonly Harmony harmony = new Harmony("DeathMonger.GrabMaterialsMod");

		private ButtonConfig GrabPortalMatsButton;

		private ConfigEntry<KeyCode> GrabPortalMatsKeyboardConfig;

		private ConfigEntry<GamepadButton> GrabPortalMatsGamepadConfig;

		private void Awake()
		{
			harmony.PatchAll();
			InitCommands();
			InitInputs();
		}

		private void InitInputs()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription("Key to grab portal materials", (AcceptableValueBase)null, Array.Empty<object>());
			GrabPortalMatsKeyboardConfig = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Client config", "GrabPortalMaterialsKey", (KeyCode)103, val);
			GrabPortalMatsGamepadConfig = ((BaseUnityPlugin)this).Config.Bind<GamepadButton>("Client config", "", (GamepadButton)5, val);
			GrabPortalMatsButton = new ButtonConfig
			{
				Name = "GrabPortalMaterials",
				Config = GrabPortalMatsKeyboardConfig,
				GamepadConfig = GrabPortalMatsGamepadConfig
			};
			InputManager.Instance.AddButton("DeathMonger.GrabMaterialsMod", GrabPortalMatsButton);
		}

		private void Update()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)Chat.instance) && !Chat.instance.IsChatDialogWindowVisible())
			{
				IInputSystem current = UnityInput.Current;
				if (current.GetKeyDown(GrabPortalMatsButton.Key))
				{
					GrabItemsFromNearbyContainers("explore");
				}
			}
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		private static void InitCommands()
		{
			//IL_0033: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//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_0062: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_0183: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			object obj = <>c.<>9__9_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate
				{
					ListKnownContainers();
				};
				<>c.<>9__9_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("list", "list all known containers", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj2 = <>c.<>9__9_1;
			if (obj2 == null)
			{
				ConsoleEvent val2 = delegate(ConsoleEventArgs args)
				{
					ListLocalContainers(args);
				};
				<>c.<>9__9_1 = val2;
				obj2 = (object)val2;
			}
			new ConsoleCommand("listlocal", "[radius] - Finds containers within the radius.", (ConsoleEvent)obj2, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj3 = <>c.<>9__9_2;
			if (obj3 == null)
			{
				ConsoleEvent val3 = delegate(ConsoleEventArgs args)
				{
					ListLocalContainerContents(args);
				};
				<>c.<>9__9_2 = val3;
				obj3 = (object)val3;
			}
			new ConsoleCommand("listcontents", "[radius] - Finds containers within the radius and lists their contents.", (ConsoleEvent)obj3, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj4 = <>c.<>9__9_3;
			if (obj4 == null)
			{
				ConsoleEvent val4 = delegate(ConsoleEventArgs args)
				{
					FindContainersWithMatchingItems(args);
				};
				<>c.<>9__9_3 = val4;
				obj4 = (object)val4;
			}
			new ConsoleCommand("search", "[search-text] - search for items matching this string in nearby containers", (ConsoleEvent)obj4, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj5 = <>c.<>9__9_4;
			if (obj5 == null)
			{
				ConsoleEvent val5 = delegate(ConsoleEventArgs args)
				{
					GrabItemsFromNearbyContainers(args);
				};
				<>c.<>9__9_4 = val5;
				obj5 = (object)val5;
			}
			new ConsoleCommand("grab", "[items] - grab items from nearby containers - 'help' to see supported options", (ConsoleEvent)obj5, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj6 = <>c.<>9__9_5;
			if (obj6 == null)
			{
				ConsoleEvent val6 = delegate
				{
					StoreItemsInNearbyContainers();
				};
				<>c.<>9__9_5 = val6;
				obj6 = (object)val6;
			}
			new ConsoleCommand("store", "[items] - grab items from nearby containers - 'help' to see supported options", (ConsoleEvent)obj6, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj7 = <>c.<>9__9_6;
			if (obj7 == null)
			{
				ConsoleEvent val7 = delegate(ConsoleEventArgs args)
				{
					CountInventory(args);
				};
				<>c.<>9__9_6 = val7;
				obj7 = (object)val7;
			}
			new ConsoleCommand("count", "[name of item to count] - omit to count everything", (ConsoleEvent)obj7, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		private static void ListKnownContainers()
		{
			int num = 0;
			Debug.Log((object)$"listing {Boxes.Containers.Count} known containers");
			foreach (Container container in Boxes.Containers)
			{
				Debug.Log((object)$"{++num}. {((Object)container).name} {container.m_name}  ({((object)container).GetType()} {((Object)container).GetInstanceID()})");
			}
		}

		private static void ListLocalContainers(ConsoleEventArgs args)
		{
			int num = 0;
			float result = 10f;
			if (args.Length > 1)
			{
				float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result);
			}
			List<Container> nearbyContainers = Boxes.GetNearbyContainers(result);
			Debug.Log((object)$"listing {nearbyContainers.Count} containers within {result} meters out of {Boxes.Containers.Count} known containers");
			foreach (Container item in nearbyContainers)
			{
				Debug.Log((object)$"{++num}. {((Object)item).name} {item.m_name}  ({((object)item).GetType()} {((Object)item).GetInstanceID()})");
			}
		}

		private static void ListLocalContainerContents(ConsoleEventArgs args)
		{
			float result = 10f;
			if (args.Length > 1)
			{
				float.TryParse(args[1], NumberStyles.Float, CultureInfo.InvariantCulture, out result);
			}
			List<Container> nearbyContainers = Boxes.GetNearbyContainers(result);
			Debug.Log((object)$"listing {nearbyContainers.Count} containers within {result} meters out of {Boxes.Containers.Count} known containers");
			Debug.Log((object)$"showing the contents of {nearbyContainers.Count} nearby containers");
			foreach (Container item in nearbyContainers)
			{
				Debug.Log((object)$"contents of {((Object)item).name} {((Object)item).GetInstanceID()}:");
				Inventory inventory = item.GetInventory();
				List<ItemData> allItems = inventory.GetAllItems();
				foreach (ItemData item2 in allItems)
				{
					Debug.Log((object)$"{item2.Name()} {item2.Count()}");
				}
			}
		}

		private static void FindContainersWithMatchingItems(ConsoleEventArgs args)
		{
			if (args.Length <= 1)
			{
				string text = "Please specify the text you want to search for in nearby containers";
				((Component)Chat.instance).SendMessage(text);
				Debug.Log((object)text);
				return;
			}
			float num = 50f;
			string text2 = args[1];
			List<Container> nearbyContainers = Boxes.GetNearbyContainers(num);
			Debug.Log((object)$"searching for {text2} in {nearbyContainers.Count} containers within {num} meters");
			foreach (Container item in nearbyContainers)
			{
				Inventory inventory = item.GetInventory();
				List<ItemData> allItems = inventory.GetAllItems();
				foreach (ItemData item2 in allItems)
				{
					if (item2.Name().Contains(text2))
					{
						Debug.Log((object)("it contains " + text2 + "!"));
						HighlightContainer(item);
					}
				}
				if (inventory.ContainsItemByName(text2))
				{
					Debug.Log((object)("it contains " + text2 + "!"));
					HighlightContainer(item);
				}
			}
		}

		private static void GrabItemsFromNearbyContainers(ConsoleEventArgs args)
		{
			Debug.Log((object)("GrabItemsFromNearbyContainers(" + args.FullLine + ")"));
			if (args.Length <= 1)
			{
				string text = "usage: /grab <all | name> [count], e.g. /grab wood 10";
				((Component)Chat.instance).SendMessage(text);
				Debug.Log((object)text);
				return;
			}
			string text2 = args[1];
			Debug.Log((object)("name of materials to grab: " + text2));
			int result = 1;
			if (args.Length > 2)
			{
				int.TryParse(args[2], out result);
			}
			Debug.Log((object)$"count to grab: {result}");
			GrabItemsFromNearbyContainers(text2, result);
		}

		private static void GrabItemsFromNearbyContainers(string name, int count = 1)
		{
			float num = 50f;
			List<ItemToGrab> list = new List<ItemToGrab>();
			switch (name)
			{
			case "workbench":
				list.Add(new ItemToGrab("wood", 10));
				break;
			case "portal":
				list.Add(new ItemToGrab("finewood", 20));
				list.Add(new ItemToGrab("greydwarfeye", 10));
				list.Add(new ItemToGrab("surtlingcore", 2));
				break;
			case "explore":
				list.Add(new ItemToGrab("wood", 10));
				list.Add(new ItemToGrab("finewood", 20));
				list.Add(new ItemToGrab("greydwarfeye", 10));
				list.Add(new ItemToGrab("surtlingcore", 2));
				break;
			default:
				list.Add(new ItemToGrab(name, count));
				break;
			}
			List<Container> nearbyContainers = Boxes.GetNearbyContainers(num);
			for (int i = 0; i < list.Count; i++)
			{
				ItemToGrab itemToGrab = list[i];
				Debug.Log((object)$"grabbing {itemToGrab.Count} {itemToGrab.Name} from {nearbyContainers.Count} containers within {num} meters");
				for (int j = 0; j < nearbyContainers.Count; j++)
				{
					Container container = nearbyContainers[j];
					int num2 = GrabItemFromContainer(container, itemToGrab.Name, itemToGrab.Count);
					itemToGrab.Count -= num2;
					if (itemToGrab.Count <= 0)
					{
					}
				}
			}
		}

		private static int GrabItemFromContainer(Container container, string name, int count)
		{
			Debug.Log((object)$"looking for {count} {name} in {container} {((Object)container).GetInstanceID()}");
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			Inventory inventory2 = container.GetInventory();
			int num = 0;
			List<ItemData> allItems = inventory2.GetAllItems();
			for (int i = 0; i < allItems.Count; i++)
			{
				ItemData val = allItems[i];
				if (val.Name() == name)
				{
					Debug.Log((object)$"found {val.Count()} {name} in {container} {((Object)container).GetInstanceID()}");
					int num2 = ((count > val.Count()) ? val.Count() : count);
					ItemData val2 = val.Clone();
					val2.m_stack = num2;
					inventory2.RemoveItem(val, num2);
					inventory.AddItem(val2);
					num += num2;
					Debug.Log((object)$"grabbed {num2} {name} from {container} {((Object)container).GetInstanceID()}");
				}
			}
			Debug.Log((object)$"grabbed a total of {num} {name} from {container} {((Object)container).GetInstanceID()}");
			return num;
		}

		private static void StoreItemsInNearbyContainers()
		{
			float num = 50f;
			List<Container> nearbyContainers = Boxes.GetNearbyContainers(num);
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			List<ItemData> list = new List<ItemData>();
			for (int i = 1; i < inventory.GetHeight(); i++)
			{
				for (int j = 0; j < inventory.GetWidth(); j++)
				{
					ItemData itemAt = inventory.GetItemAt(j, i);
					if (itemAt != null)
					{
						list.Add(itemAt);
					}
				}
			}
			Debug.Log((object)$"storing {list.Count()} items in {nearbyContainers.Count} containers within {num} meters");
			int num2 = 0;
			while (list.Count > 0)
			{
				StoreItemInContainer(nearbyContainers[num2], list[0]);
				num2++;
				if (num2 == nearbyContainers.Count)
				{
					num2 = 0;
				}
				list.RemoveAt(0);
			}
		}

		private static bool StoreItemInContainer(Container container, ItemData item)
		{
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			Inventory inventory2 = container.GetInventory();
			if (!inventory2.CanAddItem(item, -1))
			{
				Debug.LogWarning((object)"Container's inventory full.");
				return false;
			}
			Debug.Log((object)$"moving {item.Name()} {item.Count()}");
			inventory2.MoveItemToThis(inventory, item);
			Debug.Log((object)$"moved {item.Name()} {item.Count()}");
			return true;
		}

		private static void CountInventory(ConsoleEventArgs args)
		{
			string text = "";
			int num = 0;
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory = ((Humanoid)localPlayer).GetInventory();
			if (args.Length > 1)
			{
				text = args[1];
				num = CountItemsInInventory(inventory, text);
				Debug.Log((object)$"{num} {text} in inventory");
			}
			else
			{
				num = CountItemsInInventory(inventory);
				Debug.Log((object)$"{num} items in inventory");
			}
		}

		private static int CountItemsInInventory(Inventory inventory)
		{
			int num = 0;
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory2 = ((Humanoid)localPlayer).GetInventory();
			foreach (ItemData allItem in inventory2.GetAllItems())
			{
				num += allItem.Count();
			}
			return num;
		}

		private static int CountItemsInInventory(Inventory inventory, string name)
		{
			int num = 0;
			Player localPlayer = Player.m_localPlayer;
			Inventory inventory2 = ((Humanoid)localPlayer).GetInventory();
			foreach (ItemData allItem in inventory2.GetAllItems())
			{
				if (allItem.Name() == name)
				{
					num += allItem.Count();
				}
			}
			return num;
		}

		private static void HighlightContainer(Container container)
		{
			WearNTear component = ((Component)container).GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.Highlight();
			}
		}
	}
}
namespace GrabMaterials
{
	internal class Boxes
	{
		internal static readonly List<Container> Containers = new List<Container>();

		private static readonly List<Container> ContainersToAdd = new List<Container>();

		private static readonly List<Container> ContainersToRemove = new List<Container>();

		internal static void AddContainer(Container container)
		{
			if (!Containers.Contains(container))
			{
				ContainersToAdd.Add(container);
				Debug.Log((object)$"Added container {((Object)container).name} ({((object)container).GetType()} {((Object)container).GetInstanceID()}) to list");
			}
			UpdateContainers();
		}

		internal static void RemoveContainer(Container container)
		{
			if (Containers.Contains(container))
			{
				ContainersToRemove.Add(container);
				Debug.Log((object)$"Removed container {((Object)container).name} ({((object)container).GetType()} {((Object)container).GetInstanceID()}) from list");
			}
			UpdateContainers();
		}

		internal static void UpdateContainers()
		{
			foreach (Container item in ContainersToAdd)
			{
				Containers.Add(item);
			}
			ContainersToAdd.Clear();
			foreach (Container item2 in ContainersToRemove)
			{
				Containers.Remove(item2);
			}
			ContainersToRemove.Clear();
		}

		internal static void ConditionallyAddContainer(Container container, string trigger)
		{
			if (container.GetInventory() != null)
			{
				long playerID = Game.instance.GetPlayerProfile().GetPlayerID();
				AddContainer(container);
			}
		}

		internal static List<Container> GetNearbyContainers(float radius)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			List<Container> list = new List<Container>();
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return list;
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Debug.Log((object)$"checking distance of {Containers.Count} containers");
			foreach (Container container in Containers)
			{
				float num = Vector3.Distance(position, ((Component)container).transform.position);
				if (num < radius)
				{
					list.Add(container);
				}
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(Chat), "SendText")]
	public class HookChatInputText
	{
		private const float SearchRadius = 50f;

		private static void SearchNearbyContainersFor(string query)
		{
			foreach (Piece nearbyMatchingPiece in GetNearbyMatchingPieces(query))
			{
				HighlightPiece(nearbyMatchingPiece);
			}
		}

		private static IEnumerable<Piece> GetNearbyMatchingPieces(string query)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			List<Piece> list = new List<Piece>();
			Piece.GetAllPiecesInRadius(((Component)Player.m_localPlayer).transform.position, 50f, list);
			return from p in list
				where Object.op_Implicit((Object)(object)((Component)p).GetComponent<Container>())
				where ContainerContainsMatchingItem(p, query)
				select p;
		}

		private static bool ContainerContainsMatchingItem(Piece container, string query)
		{
			return (from i in ((Component)container).GetComponent<Container>().GetInventory().GetAllItems()
				where NormalizedItemName(i).Contains(query)
				select i).Any();
		}

		private static string NormalizedItemName(ItemData itemData)
		{
			return itemData.m_shared.m_name.ToLower();
		}

		private static void HighlightPiece(Piece p)
		{
			WearNTear component = ((Component)p).GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.Highlight();
			}
		}
	}
	internal class ContainerFinder
	{
		public static List<Container> FindNearbyContainers(Vector3 position, float radius)
		{
			//IL_0017: 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)
			Debug.Log((object)$"FindNearbyContainers with {radius} meters");
			Debug.Log((object)position);
			List<Container> list = new List<Container>();
			Collider[] array = Physics.OverlapSphere(position, radius);
			Debug.Log((object)$"{array.Count()} colliders");
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				Debug.Log((object)(((Object)val).name ?? ""));
				Container component = ((Component)val).GetComponent<Container>();
				ContainerFilterService component2 = ((Component)component).GetComponent<ContainerFilterService>();
				if ((Object)(object)component != (Object)null)
				{
					list.Add(component);
				}
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(Container), "Load")]
	internal class ContainerLoadPatch
	{
		private static void Postfix(Container __instance)
		{
			Boxes.ConditionallyAddContainer(__instance, "Load");
		}
	}
	[HarmonyPatch(typeof(Container), "Awake")]
	internal static class ContainerAwakePatch
	{
		private static void Postfix(Container __instance)
		{
			Debug.Log((object)$"*** CONTAINER AWAKE POSTFIX GOT CALLED *** {((Object)__instance).name} {((Object)__instance).GetInstanceID()}");
			Boxes.ConditionallyAddContainer(__instance, "Awake");
		}
	}
	[HarmonyPatch(typeof(Container), "OnDestroyed")]
	internal static class ContainerOnDestroyedPatch
	{
		private static void Postfix(Container __instance)
		{
			Boxes.RemoveContainer(__instance);
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateTeleport")]
	public static class PlayerUpdateTeleportPatchCleanupContainers
	{
		public static void Prefix(float dt)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsTeleporting())
			{
				return;
			}
			foreach (Container item in from container in Boxes.Containers.ToList()
				where !((Object)container != (Object)null) || !((Object)((Component)container).transform != (Object)null) || container.GetInventory() == null
				where (Object)container != (Object)null
				select container)
			{
				Boxes.RemoveContainer(item);
			}
		}
	}
	[HarmonyPatch(typeof(WearNTear), "OnDestroy")]
	internal static class WearNTearOnDestroyPatch
	{
		private static void Prefix(WearNTear __instance)
		{
			Container[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Container>();
			Container[] componentsInParent = ((Component)__instance).GetComponentsInParent<Container>();
			if (componentsInChildren.Length != 0)
			{
				Container[] array = componentsInChildren;
				for (int i = 0; i < array.Length; i++)
				{
					Boxes.RemoveContainer(array[i]);
				}
			}
			if (componentsInParent.Length != 0)
			{
				Container[] array2 = componentsInParent;
				for (int j = 0; j < array2.Length; j++)
				{
					Boxes.RemoveContainer(array2[j]);
				}
			}
		}
	}
	internal static class Extensions
	{
		public static string Name(this ItemData self)
		{
			return self.m_shared.m_name.Substring(6);
		}

		public static int Count(this ItemData self)
		{
			return self.m_stack;
		}
	}
}