Decompiled source of ServersideQoL AutoStore v2.5.1

ServersideQoL.AutoStore.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using ServersideQoL.Processors;
using ServersideQoL.Utilities;
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("ArgusMagnus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("ArgusMagnus")]
[assembly: AssemblyDescription("Automatically put dropped items and items in player inventories into nearby containers")]
[assembly: AssemblyFileVersion("2.5.1.0")]
[assembly: AssemblyInformationalVersion("2.5.1+50a2d79d10d8f52c59a18f4ca854667464c9ca9b")]
[assembly: AssemblyProduct("ServersideQoL.AutoStore")]
[assembly: AssemblyTitle("ServersideQoL.AutoStore")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.5.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[CompilerGenerated]
internal sealed class <>z__ReadOnlyList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Count;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Count;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Count;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyList(List<T> items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return _items.Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		_items.CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return _items.IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServersideQoL.AutoStore
{
	[BepInPlugin("ArgusMagnus.ServersideQoL.AutoStore", "ServersideQoL.AutoStore", "2.5.1")]
	public sealed class AutoStorePlugin : ServersideQoLPluginBase<AutoStorePlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.AutoStore";

		public const string PluginGuid = "ArgusMagnus.ServersideQoL.AutoStore";

		public const string PluginVersion = "2.5.1";

		public const string PluginInformationalVersion = "2.5.1";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639286779712107886L, default(TimeSpan));

		protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger)
		{
			return new Config(configFile, logger);
		}

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<ContainerProcessor>().Add<ItemDropProcessor>();
		}

		private void Awake()
		{
		}
	}
	public sealed class Config : ConfigBase<Config>
	{
		public sealed class LocalizationConfig
		{
			private string ContainerSorted { get; init; } = "{0} sorted";

			private string AutoPickup { get; init; } = "{0}: $msg_added {1} {2}x";

			private string Stacked { get; init; } = "{0}: $msg_added {1} {2}x";

			public string FormatContainerSorted(string containerName)
			{
				return string.Format(ContainerSorted, containerName);
			}

			public string FormatAutoPickup(string containerName, string itemName, int stack)
			{
				return string.Format(AutoPickup, containerName, itemName, stack);
			}

			public string FormatStacked(string containerName, string itemName, int stack)
			{
				return string.Format(Stacked, containerName, itemName, stack);
			}
		}

		public sealed class AdvancedConfig
		{
			public sealed class ProcessingDelaysConfig
			{
				public float AfterItemDropOwnershipRequest { get; init; } = 0.2f;

				public float StackContainerWhenMovingItems { get; init; } = 0.2f;
			}

			public string ContainerModifiedEffectPrefabName { get; init; } = "fx_Potion_frostresist";

			public ProcessingDelaysConfig ProcessingDelays { get; init; } = new ProcessingDelaysConfig();
		}

		private const string DefaultPickupRangeEmoji = "\ud83e\uddf2";

		private static readonly AcceptableArrayValues<ItemType> __acceptableExcludeItemTypes;

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, true, "Enables/disables the entire mod", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<bool> AutoSort { get; } = ConfigBase<Config>.BindEx<bool>(cfg, true, "True to auto sort container inventories", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "AutoSort");

		public ConfigEntry<MessageTypes> SortedMessageType { get; } = ConfigBase<Config>.BindEx<MessageTypes>(cfg, (MessageTypes)0, "Type of message to show when a container was sorted", (IAcceptableValueBase<MessageTypes>)(object)AcceptableEnum<MessageTypes>.Default, (Deprecated<Config>)null, "SortedMessageType");

		public ConfigEntry<bool> AutoPickup { get; } = Shared.AutoStorePickup = ConfigBase<Config>.BindEx<bool>(cfg, true, "True to automatically put dropped items into containers if they already contain said item", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "AutoPickup");

		public ConfigEntry<float> AutoPickupRange { get; } = ConfigBase<Config>.BindEx<float>(cfg, 64f, "Required proximity of a container to a dropped item to be considered as auto pickup target.\r\nCan be overridden per chest by putting '<AutoPickupRangeSignPrefix><Range>' on a chest sign, e.g. '\ud83e\uddf216'.\r\n  For example, '\ud83e\uddf20' will disable auto pickup/stacking from player inventory into that chest.\r\n  Only works with automatic chest signs added by the ServersideQoL.ContainerSigns mod.", (IAcceptableValueBase<float>)null, (Deprecated<Config>)null, "AutoPickupRange");

		public ConfigEntry<string> AutoPickupRangeSignPrefix { get; } = Shared.AutoStorePickupRangeSignPrefix = ConfigBase<Config>.BindEx<string>(cfg, "\ud83e\uddf2", "Requires the ServersideQoL.ContainerSigns mod.\r\nThe prefix used to identify the container specifc auto pickup range value in chest sign text.", (IAcceptableValueBase<string>)null, (Deprecated<Config>)null, "AutoPickupRangeSignPrefix");

		public ConfigEntry<int> AutoPickupMaxRange { get; } = Shared.AutoStorePickupMaxRange = ConfigBase<Config>.BindEx<int>(cfg, 64, "Requires the ServersideQoL.ContainerSigns mod. \r\nMax auto pickup range players can set per chest (by putting '<AutoPickupRangeSignPrefix><Range>' on a chest sign).", (IAcceptableValueBase<int>)null, (Deprecated<Config>)null, "AutoPickupMaxRange");

		public ConfigEntry<float> AutoPickupMinPlayerDistance { get; } = ConfigBase<Config>.BindEx<float>(cfg, 4f, "Min distance all players must have to a dropped item for it to be picked up", (IAcceptableValueBase<float>)null, (Deprecated<Config>)null, "AutoPickupMinPlayerDistance");

		public ConfigEntry<ConfigArray<ItemType>> AutoPickupExcludeItemTypes { get; } = ConfigBase<Config>.BindEx<ConfigArray<ItemType>>(cfg, ConfigArray<ItemType>.Empty, "Item types which will be excluded from auto pickup", (IAcceptableValueBase<ConfigArray<ItemType>>)(object)__acceptableExcludeItemTypes, (Deprecated<Config>)null, "AutoPickupExcludeItemTypes");

		public ConfigEntry<bool> AutoPickupExcludeFodder { get; } = ConfigBase<Config>.BindEx<bool>(cfg, true, "True to exclude food items for tames when tames are within search range", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "AutoPickupExcludeFodder");

		public ConfigEntry<bool> AutoPickupRequestOwnership { get; } = ConfigBase<Config>.BindEx<bool>(cfg, true, "True to make the server request (and receive) ownership of dropped items from the clients before they are picked up. This will reduce the risk of data conflicts (e.g. item duplication) but will drastically decrease performance", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "AutoPickupRequestOwnership");

		public ConfigEntry<MessageTypes> PickedUpMessageType { get; } = ConfigBase<Config>.BindEx<MessageTypes>(cfg, (MessageTypes)5, "Type of message to show when a dropped item is added to a container", (IAcceptableValueBase<MessageTypes>)(object)AcceptableEnum<MessageTypes>.Default, (Deprecated<Config>)null, "PickedUpMessageType");

		public ConfigEntry<bool> ShowContainerModifiedEffect { get; } = ConfigBase<Config>.BindEx<bool>(cfg, true, "True to show an effect when a container is modified due to auto pickup or player inventory stacking", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "ShowContainerModifiedEffect");

		public ConfigEntry<bool> SuppressContainerModifiedEffectSound { get; } = ConfigBase<Config>.BindEx<bool>(cfg, false, "True to suppress the sound of the container modified effect when ShowContainerModifiedEffect = true", (IAcceptableValueBase<bool>)null, (Deprecated<Config>)null, "SuppressContainerModifiedEffectSound");

		public ConfigEntry<Emotes> StackInventoryIntoContainersEmote { get; }

		public ConfigEntry<ConfigArray<ItemType>> StackInventoryIntoContainersExcludeItemTypes { get; }

		public ConfigEntry<float> StackInventoryIntoContainersReturnDelay { get; }

		public YamlConfigEntry<LocalizationConfig> Localization { get; }

		public YamlConfigEntry<AdvancedConfig> Advanced { get; }

		public Config(ConfigFile cfg, Logger logger)
		{
			string text = $"Emote to stack inventory into containers.\r\nIf a player uses this emote, their inventory will be automatically stacked into nearby containers.\r\nThe rules for which containers are used are the same as for auto pickup.\r\n{(object)(Emotes)(-1)} to disable this feature, {(object)(Emotes)(-2)} to use any emote as trigger.\r\nFor example, on xbox you can use D-Pad down to execute the {(object)(Emotes)1} emote.\r\nIf you use emotes exclusively for this feature, it is recommended to set the value to {(object)(Emotes)(-2)} as it is more reliably detected than specific emotes, especially on bad connection/with crossplay.";
			List<Emotes> list = new List<Emotes>();
			list.Add((Emotes)(-1));
			list.Add((Emotes)(-2));
			list.AddRange(Enum.GetValues(typeof(Emotes)).Cast<Emotes>());
			StackInventoryIntoContainersEmote = ConfigBase<Config>.BindEx<Emotes>(cfg, (Emotes)1, text, (IAcceptableValueBase<Emotes>)(object)new AcceptableEnum<Emotes>((IEnumerable<Emotes>)new <>z__ReadOnlyList<Emotes>(list)), (Deprecated<Config>)null, "StackInventoryIntoContainersEmote");
			StackInventoryIntoContainersExcludeItemTypes = ConfigBase<Config>.BindEx<ConfigArray<ItemType>>(cfg, ConfigArray<ItemType>.Empty, "Item types which will be excluded from stacking into containers via emote", (IAcceptableValueBase<ConfigArray<ItemType>>)(object)__acceptableExcludeItemTypes, (Deprecated<Config>)null, "StackInventoryIntoContainersExcludeItemTypes");
			StackInventoryIntoContainersReturnDelay = ConfigBase<Config>.BindEx<float>(cfg, 1f, "Time in seconds after which items which could not be stacked into containers are returned to the player.\r\nIncreasing this value can help with bad connections.", (IAcceptableValueBase<float>)(object)new AcceptableValueRange<float>(1f, 10f), (Deprecated<Config>)null, "StackInventoryIntoContainersReturnDelay");
			Localization = ConfigBase<Config>.BindYaml<LocalizationConfig>(cfg, "Localization");
			Advanced = ConfigBase<Config>.BindYaml<AdvancedConfig>(cfg, "Advanced");
			base..ctor(cfg, logger);
		}

		unsafe static Config()
		{
			List<ItemType> list = new List<ItemType>();
			list.AddRange(from x in (from x in ObjectDB.instance.m_items
					select x.GetComponent<ItemDrop>() into x
					where x != null && Extensions[x]
					select x.m_itemData.m_shared.m_itemType).Distinct()
				orderby ((object)(*(ItemType*)(&x))/*cast due to .constrained prefix*/).ToString()
				select x);
			__acceptableExcludeItemTypes = new AcceptableArrayValues<ItemType>((IReadOnlyList<ItemType>)new <>z__ReadOnlyList<ItemType>(list));
		}
	}
	[Processor("e1c6ea7a-996b-4aad-8595-af86f02fe25b")]
	[RunBefore<ContainerRegistryProcessor>]
	[DependsOn<PlayerRegistryProcessor>]
	public sealed class ContainerProcessor : Processor<PrefabInfo>
	{
		private sealed record StackContainerState(ServersideQoLZDO PlayerZDO)
		{
			public Timestamp RemoveAfter { get; set; }

			public bool Stacked { get; set; }
		}

		public const string Id = "e1c6ea7a-996b-4aad-8595-af86f02fe25b";

		private readonly Dictionary<ItemDataKey, int> _stackPerItem = new Dictionary<ItemDataKey, int>();

		private readonly Dictionary<ServersideQoLZDO, StackContainerState> _stackContainers = new Dictionary<ServersideQoLZDO, StackContainerState>();

		private SectorDictionary<SharedItemDataKey, HashSet<ServersideQoLZDO>>? _containersByItemName;

		private SectorDictionary<HashSet<ServersideQoLZDO>>? _containers;

		private readonly HashSet<ItemType> _excludedTypes = new HashSet<ItemType>();

		private int _effectPrefab;

		internal void SpawnModifiedEffect(ServersideQoLZDO container)
		{
			//IL_0015: 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)
			if (_effectPrefab == 0)
			{
				return;
			}
			ServersideQoLZDO val = Processor.Spawn(_effectPrefab, container.ZDO.GetPosition(), container.ZDO.GetRotation(), 0L);
			if (!ConfigBase<Config>.Instance.SuppressContainerModifiedEffectSound.Value || !Processor.GetPrefabInfo(val).HasComponent<ZSFX>())
			{
				return;
			}
			val.Fields<ZSFX>().Set((Func<Expression<Func<ZSFX, bool>>>)(() => (ZSFX x) => x.m_playOnAwake), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ContainerProcessor.cs", 27);
		}

		protected override void Initialize()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			Processor.Instance<PlayerRegistryProcessor>().EmoteDetected -= OnPlayerEmoteDetected;
			if ((int)ConfigBase<Config>.Instance.StackInventoryIntoContainersEmote.Value == -1)
			{
				_containersByItemName = null;
				_containers = null;
			}
			else
			{
				_containersByItemName = Processor.Instance<ContainerRegistryProcessor>().GetContainersByItemName(Mathf.Max(ConfigBase<Config>.Instance.AutoPickupRange.Value, (float)ConfigBase<Config>.Instance.AutoPickupMaxRange.Value));
				_containers = Processor.Instance<ContainerRegistryProcessor>().GetContainers(_containersByItemName.SectorWidth);
				Processor.Instance<PlayerRegistryProcessor>().EmoteDetected += OnPlayerEmoteDetected;
			}
			ConfigBase<Config>.Instance.StackInventoryIntoContainersExcludeItemTypes.SettingChanged -= UpdateExcludedTypes;
			UpdateExcludedTypes(null, null);
			ConfigBase<Config>.Instance.StackInventoryIntoContainersExcludeItemTypes.SettingChanged += UpdateExcludedTypes;
			ConfigBase<Config>.Instance.Advanced.ValueChanged -= UpdateEffectPrefab;
			UpdateEffectPrefab(ConfigBase<Config>.Instance.Advanced);
			ConfigBase<Config>.Instance.Advanced.ValueChanged += UpdateEffectPrefab;
			void UpdateEffectPrefab(YamlConfigEntry<Config.AdvancedConfig> sender)
			{
				_effectPrefab = 0;
				string text = sender.Value.ContainerModifiedEffectPrefabName.Trim();
				if (!string.IsNullOrEmpty(text))
				{
					int stableHashCode = StringExtensionMethods.GetStableHashCode(text);
					GameObject prefab = ZNetScene.instance.GetPrefab(stableHashCode);
					if (((prefab != null) ? prefab.GetComponent<TimedDestruction>() : null) == null)
					{
						((Processor)this).Logger.LogWarning((object)("Prefab '" + text + "' does not have the TimedDestruction component and is not suitable as effect"));
					}
					else
					{
						_effectPrefab = stableHashCode;
					}
				}
			}
			void UpdateExcludedTypes(object? sender, EventArgs? args)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: 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)
				_excludedTypes.Clear();
				foreach (ItemType item in ConfigBase<Config>.Instance.StackInventoryIntoContainersExcludeItemTypes.Value.Items)
				{
					_excludedTypes.Add(item);
				}
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0025: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_069e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0568: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			if (_stackContainers.TryGetValue(zdo, out StackContainerState value))
			{
				return ProcessStackContainer(zdo, peers, Processor.Instance<ContainerRegistryProcessor>().GetState(zdo, prefabInfo.Container), value);
			}
			if (ConfigBase<Config>.Instance.AutoSort.Value)
			{
				ZDOVars vars = zdo.Vars;
				if (!((ZDOVars)(ref vars)).GetInUse(false))
				{
					ContainerState state = Processor.Instance<ContainerRegistryProcessor>().GetState(zdo, prefabInfo.Container);
					bool flag = false;
					ItemData val = null;
					IInventory inventory = state.GetInventory();
					_stackPerItem.Clear();
					foreach (ItemData item in from x in inventory.Items
						orderby (!x.IsEquipable()) ? 1 : 0, x.m_shared.m_name, x.m_stack descending
						select x)
					{
						if (val != null && new ItemDataKey(item) == ItemDataKey.op_Implicit(val))
						{
							flag = true;
							if (!zdo.IsOwnerOrUnassigned())
							{
								break;
							}
							int num = Math.Min(item.m_stack, val.m_shared.m_maxStackSize - val.m_stack);
							ItemData obj = val;
							obj.m_stack += num;
							item.m_stack -= num;
						}
						if (item.m_stack != 0)
						{
							if (!_stackPerItem.TryGetValue(ItemDataKey.op_Implicit(item), out var value2))
							{
								value2 = 0;
							}
							_stackPerItem[ItemDataKey.op_Implicit(item)] = value2 + 1;
							if (item.m_stack < item.m_shared.m_maxStackSize)
							{
								val = item;
							}
						}
					}
					if (flag && zdo.IsOwnerOrUnassigned())
					{
						for (int num2 = inventory.Items.Count - 1; num2 >= 0; num2--)
						{
							if (inventory.Items[num2].m_stack == 0)
							{
								inventory.Items.RemoveAt(num2);
							}
						}
					}
					if (_stackPerItem.Count > 0)
					{
						ComponentFieldAccessor<Container> val2 = zdo.Fields<Container>();
						int width = val2.GetInt((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_width), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ContainerProcessor.cs", 132);
						int height = val2.GetInt((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_height), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ContainerProcessor.cs", 133);
						if (_stackPerItem.Values.Sum((int x) => (int)Math.Ceiling((double)x / (double)width)) <= height)
						{
							int num3 = -1;
							int num4 = 0;
							ItemDataKey? val3 = null;
							foreach (ItemData item2 in from x in inventory.Items
								orderby (!x.IsEquipable()) ? 1 : 0, x.m_shared.m_name, x.m_stack descending
								select x)
							{
								if (++num3 >= width)
								{
									goto IL_03ac;
								}
								if (val3.HasValue)
								{
									ItemDataKey? val4 = val3;
									ItemDataKey val5 = ItemDataKey.op_Implicit(item2);
									if (!val4.HasValue || val4.GetValueOrDefault() != val5)
									{
										goto IL_03ac;
									}
								}
								goto IL_03b5;
								IL_03ac:
								num3 = 0;
								num4++;
								goto IL_03b5;
								IL_03b5:
								if (item2.m_gridPos.x != num3 || item2.m_gridPos.y != num4)
								{
									flag = true;
									if (zdo.IsOwnerOrUnassigned())
									{
										item2.m_gridPos = new Vector2i(num3, num4);
									}
								}
								val3 = ItemDataKey.op_Implicit(item2);
							}
						}
						else if (_stackPerItem.Values.Sum((int x) => (int)Math.Ceiling((double)x / (double)height)) <= width)
						{
							int num5 = 0;
							int num6 = height;
							ItemDataKey? val6 = null;
							foreach (ItemData item3 in from x in inventory.Items
								orderby (!x.IsEquipable()) ? 1 : 0, x.m_shared.m_name, x.m_stack descending
								select x)
							{
								if (--num6 < 0)
								{
									goto IL_051b;
								}
								if (val6.HasValue)
								{
									ItemDataKey? val4 = val6;
									ItemDataKey val5 = ItemDataKey.op_Implicit(item3);
									if (!val4.HasValue || val4.GetValueOrDefault() != val5)
									{
										goto IL_051b;
									}
								}
								goto IL_052c;
								IL_051b:
								num6 = height - 1;
								num5++;
								goto IL_052c;
								IL_052c:
								if (item3.m_gridPos.x != num5 || item3.m_gridPos.y != num6)
								{
									flag = true;
									if (zdo.IsOwnerOrUnassigned())
									{
										item3.m_gridPos = new Vector2i(num5, num6);
									}
								}
								val6 = ItemDataKey.op_Implicit(item3);
							}
						}
						else
						{
							int num7 = 0;
							int num8 = 0;
							foreach (ItemData item4 in from x in inventory.Items
								orderby (!x.IsEquipable()) ? 1 : 0, x.m_shared.m_name, x.m_stack descending
								select x)
							{
								if (item4.m_gridPos.x != num7 || item4.m_gridPos.y != num8)
								{
									flag = true;
									if (zdo.IsOwnerOrUnassigned())
									{
										item4.m_gridPos = new Vector2i(num7, num8);
									}
								}
								if (++num7 >= width)
								{
									num7 = 0;
									num8++;
								}
							}
						}
					}
					if (flag)
					{
						if (!zdo.IsOwnerOrUnassigned())
						{
							ContainerRegistryProcessor obj2 = Processor.Instance<ContainerRegistryProcessor>();
							vars = zdo.Vars;
							return ((Processor)this).ScheduleReprocessing(obj2.RequestOwnership(state, ((ZDOVars)(ref vars)).GetCreator(default(PlayerID))));
						}
						inventory.Save();
						Processor.ShowMessage((IEnumerable<Peer>)peers, zdo, ConfigBase<Config>.Instance.Localization.Value.FormatContainerSorted(prefabInfo.Container.m_name), ConfigBase<Config>.Instance.SortedMessageType.Value, (TextType)0);
					}
					return (ProcessResult)0;
				}
				return (ProcessResult)0;
			}
			return (ProcessResult)2;
		}

		private void OnPlayerEmoteDetected(PlayerState state, Emotes emote)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_003b: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: 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_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: 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_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			if ((int)ConfigBase<Config>.Instance.StackInventoryIntoContainersEmote.Value != -2 && ConfigBase<Config>.Instance.StackInventoryIntoContainersEmote.Value != emote)
			{
				return;
			}
			List<ServersideQoLZDO> list = null;
			Dictionary<SharedItemDataKey, ItemData> dictionary = null;
			AdjacentEnumerator<HashSet<ServersideQoLZDO>> enumerator = _containers.EnumerateAdjacent(state.ZDO.ZDO.GetPosition()).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					HashSet<ServersideQoLZDO> current = enumerator.Current;
					list?.Clear();
					foreach (ServersideQoLZDO item in current)
					{
						ContainerState state2 = Processor.Instance<ContainerRegistryProcessor>().GetState(item);
						if (state2 == null)
						{
							(list ?? (list = new List<ServersideQoLZDO>())).Add(item);
							continue;
						}
						float num = state2.AutoStorePickupRange ?? ConfigBase<Config>.Instance.AutoPickupRange.Value;
						num *= num;
						if (num == 0f || Utils.DistanceSqr(state.ZDO.ZDO.GetPosition(), item.ZDO.GetPosition()) > num)
						{
							continue;
						}
						if ((int)state2.Container.m_privacy == 0)
						{
							ZDOVars vars = item.Vars;
							PlayerID creator = ((ZDOVars)(ref vars)).GetCreator(default(PlayerID));
							vars = state.ZDO.Vars;
							if (creator != ((ZDOVars)(ref vars)).GetPlayerID(default(PlayerID)))
							{
								continue;
							}
						}
						IInventory inventory = state2.GetInventory();
						foreach (ItemData item2 in inventory.Items)
						{
							if (!_excludedTypes.Contains(item2.m_shared.m_itemType))
							{
								(dictionary ?? (dictionary = new Dictionary<SharedItemDataKey, ItemData>())).TryAdd(SharedItemDataKey.op_Implicit(item2.m_shared), item2);
							}
						}
					}
					if (list == null)
					{
						continue;
					}
					foreach (ServersideQoLZDO item3 in list)
					{
						current.Remove(item3);
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			if (dictionary == null)
			{
				return;
			}
			Vector3 position = state.ZDO.ZDO.GetPosition();
			position.y = -1000f;
			ServersideQoLZDO val = ((Processor)this).PlacePiece(position, Prefabs.PrivateChest, 0f);
			int num2 = Math.Max(4, dictionary.Count);
			val.Fields<Container>().Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_width), 8, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ContainerProcessor.cs", 267).Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_height), num2, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ContainerProcessor.cs", 268);
			int num3 = 0;
			IInventory inventory2 = Processor.Instance<ContainerRegistryProcessor>().GetState(val).GetInventory();
			foreach (ItemData value in dictionary.Values)
			{
				ItemData val2 = value.Clone();
				val2.m_stack = 1;
				val2.m_gridPos = new Vector2i(0, num3++);
				inventory2.Items.Add(val2);
			}
			inventory2.Save();
			val.ZDO.SetOwnerInternal(state.ZDO.ZDO.GetOwner());
			_stackContainers.Add(val, new StackContainerState(state.ZDO));
			val.Destroyed += OnStackContainerDestroyed;
			ZDORpc rPC = val.RPC;
			ContainerRpc container = ((ZDORpc)(ref rPC)).Container;
			((ContainerRpc)(ref container)).StackResponse(true);
		}

		private void OnStackContainerDestroyed(ServersideQoLZDO zdo)
		{
			_stackContainers.Remove(zdo);
		}

		private ProcessResult ProcessStackContainer(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, ContainerState state, StackContainerState stackContainerState)
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			IInventory inventory = state.GetInventory();
			if (inventory.Items.Count == 0)
			{
				return (ProcessResult)4;
			}
			ContainerRpc container;
			Timestamp now;
			if (stackContainerState.Stacked)
			{
				if (stackContainerState.RemoveAfter < Timestamp.Now)
				{
					ZDORpc rPC = zdo.RPC;
					container = ((ZDORpc)(ref rPC)).Container;
					((ContainerRpc)(ref container)).TakeAllResponse(true);
				}
				else if (MoveItems(zdo, peers, state, stackContainerState))
				{
					zdo.Destroyed -= OnStackContainerDestroyed;
					_stackContainers.Remove(zdo);
					if (inventory.Items.Count == 0)
					{
						return (ProcessResult)4;
					}
					_stackContainers.Add(zdo = ((Processor)this).RecreatePiece(zdo), stackContainerState);
					zdo.Destroyed += OnStackContainerDestroyed;
					now = Timestamp.Now;
					stackContainerState.RemoveAfter = ((Timestamp)(ref now)).AddSeconds(0.5f);
				}
				return ((Processor)this).ScheduleReprocessing(ConfigBase<Config>.Instance.Advanced.Value.ProcessingDelays.StackContainerWhenMovingItems);
			}
			if (inventory.Items.Any(delegate(ItemData x)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				if (x != null)
				{
					Vector2i gridPos = x.m_gridPos;
					int x2 = gridPos.x;
					if (x2 <= 0)
					{
						int stack = x.m_stack;
						if (stack <= 1)
						{
							goto IL_0024;
						}
					}
					return true;
				}
				goto IL_0024;
				IL_0024:
				return false;
			}))
			{
				for (int num = inventory.Items.Count - 1; num >= 0; num--)
				{
					ItemData val = inventory.Items[num];
					if (val.m_gridPos.x == 0)
					{
						if (--val.m_stack == 0)
						{
							inventory.Items.RemoveAt(num);
						}
					}
				}
				inventory.Save();
				stackContainerState.Stacked = true;
				now = Timestamp.Now;
				stackContainerState.RemoveAfter = ((Timestamp)(ref now)).AddSeconds(ConfigBase<Config>.Instance.StackInventoryIntoContainersReturnDelay.Value);
				zdo.Destroyed -= OnStackContainerDestroyed;
				_stackContainers.Remove(zdo);
				_stackContainers.Add(zdo = ((Processor)this).RecreatePiece(zdo), stackContainerState);
				zdo.Destroyed += OnStackContainerDestroyed;
			}
			else
			{
				if (stackContainerState.RemoveAfter < Timestamp.Now)
				{
					return (ProcessResult)4;
				}
				ZDORpc rPC2 = zdo.RPC;
				container = ((ZDORpc)(ref rPC2)).Container;
				((ContainerRpc)(ref container)).StackResponse(true);
			}
			return (ProcessResult)0;
		}

		private bool MoveItems(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, ContainerState state, StackContainerState stackContainerState)
		{
			//IL_0042: 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)
			//IL_0058: 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)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Vector2i> hashSet = null;
			List<ServersideQoLZDO> list = null;
			HashSet<ServersideQoLZDO> hashSet2 = null;
			IInventory inventory = state.GetInventory();
			for (int num = inventory.Items.Count - 1; num >= 0; num--)
			{
				ItemData val = inventory.Items[num];
				AdjacentEnumerator<SharedItemDataKey, HashSet<ServersideQoLZDO>> enumerator = _containersByItemName.EnumerateAdjacent((stackContainerState.PlayerZDO.ZDO.GetPosition(), SharedItemDataKey.op_Implicit(val.m_shared))).GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						HashSet<ServersideQoLZDO> current = enumerator.Current;
						list?.Clear();
						foreach (ServersideQoLZDO item in current)
						{
							ContainerState state2 = Processor.Instance<ContainerRegistryProcessor>().GetState(item);
							if (state2 == null)
							{
								(list ?? (list = new List<ServersideQoLZDO>())).Add(item);
								continue;
							}
							ZDOVars vars = item.Vars;
							if (((ZDOVars)(ref vars)).GetInUse(false))
							{
								continue;
							}
							float num2 = state2.AutoStorePickupRange ?? ConfigBase<Config>.Instance.AutoPickupRange.Value;
							num2 *= num2;
							if (num2 == 0f || Utils.DistanceSqr(stackContainerState.PlayerZDO.ZDO.GetPosition(), item.ZDO.GetPosition()) > num2)
							{
								continue;
							}
							int num3 = val.m_stack;
							if (hashSet == null)
							{
								hashSet = new HashSet<Vector2i>();
							}
							hashSet.Clear();
							bool flag = false;
							IInventory inventory2 = state2.GetInventory();
							ItemData val2 = null;
							foreach (ItemData item2 in inventory2.Items)
							{
								hashSet.Add(item2.m_gridPos);
								if (new ItemDataKey(val) != ItemDataKey.op_Implicit(item2))
								{
									continue;
								}
								if (val2 == null)
								{
									val2 = item2;
								}
								int num4 = item2.m_shared.m_maxStackSize - item2.m_stack;
								if (num4 > 0)
								{
									if (!item.IsOwnerOrUnassigned())
									{
										flag = true;
										break;
									}
									int num5 = Math.Min(num3, num4);
									item2.m_stack += num5;
									num3 -= num5;
									if (num3 == 0)
									{
										break;
									}
								}
							}
							if (val2 == null)
							{
								(list ?? (list = new List<ServersideQoLZDO>())).Add(item);
								continue;
							}
							int num6 = inventory2.Inventory.GetEmptySlots();
							while (num3 > 0 && num6 > 0)
							{
								if (!item.IsOwnerOrUnassigned())
								{
									flag = true;
								}
								if (flag)
								{
									break;
								}
								int num7 = Math.Min(num3, val.m_shared.m_maxStackSize);
								ItemData val3 = val2.Clone();
								val3.m_stack = num7;
								val3.m_gridPos.x = -1;
								for (int i = 0; i < inventory2.Inventory.GetWidth(); i++)
								{
									if (val3.m_gridPos.x >= 0)
									{
										break;
									}
									for (int j = 0; j < inventory2.Inventory.GetHeight(); j++)
									{
										if (hashSet.Add(new Vector2i(i, j)))
										{
											ref int x = ref val3.m_gridPos.x;
											ref int y = ref val3.m_gridPos.y;
											int num8 = i;
											int num9 = j;
											x = num8;
											y = num9;
											break;
										}
									}
								}
								inventory2.Items.Add(val3);
								num3 -= num7;
								num6--;
							}
							if (flag)
							{
								ContainerRegistryProcessor obj = Processor.Instance<ContainerRegistryProcessor>();
								vars = stackContainerState.PlayerZDO.Vars;
								obj.RequestOwnership(state2, ((ZDOVars)(ref vars)).GetPlayerID(default(PlayerID)));
								continue;
							}
							if (num3 != val.m_stack)
							{
								inventory2.Save();
								ItemData val4 = val;
								int num9 = num3;
								int stack = val.m_stack;
								val4.m_stack = num9;
								num3 = stack;
								(hashSet2 ?? (hashSet2 = new HashSet<ServersideQoLZDO>())).Add(item);
								Processor.ShowMessage((IEnumerable<Peer>)peers, item, ConfigBase<Config>.Instance.Localization.Value.FormatStacked(state2.Container.m_name, val.m_shared.m_name, num3), ConfigBase<Config>.Instance.PickedUpMessageType.Value, (TextType)0);
							}
							if (val.m_stack != 0)
							{
								continue;
							}
							inventory.Items.RemoveAt(num);
							break;
						}
						if (list != null)
						{
							foreach (ServersideQoLZDO item3 in list)
							{
								current.Remove(item3);
							}
						}
						if (val.m_stack == 0)
						{
							break;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}
			if (hashSet2 != null)
			{
				inventory.Save();
				if (_effectPrefab != 0)
				{
					foreach (ServersideQoLZDO item4 in hashSet2)
					{
						SpawnModifiedEffect(item4);
					}
				}
				return true;
			}
			return false;
		}
	}
	[Processor("5f86a765-e449-4047-afc8-a63e4d681a48")]
	[RunAfter<ContainerRegistryProcessor>]
	[RunAfter<TameableRegistryProcessor>]
	public sealed class ItemDropProcessor : Processor<ItemDropProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(ItemDrop ItemDrop, Piece? Piece, EggGrow? EggGrow, ZSyncTransform? ZSyncTransform) : ProcessorPrefabInfo()
		{
			public override bool IsValid => Extensions[ItemDrop];

			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("ItemDrop = ");
				builder.Append(ItemDrop);
				builder.Append(", Piece = ");
				builder.Append(Piece);
				builder.Append(", EggGrow = ");
				builder.Append(EggGrow);
				builder.Append(", ZSyncTransform = ");
				builder.Append(ZSyncTransform);
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return (((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<ItemDrop>.Default.GetHashCode(ItemDrop)) * -1521134295 + EqualityComparer<Piece>.Default.GetHashCode(Piece)) * -1521134295 + EqualityComparer<EggGrow>.Default.GetHashCode(EggGrow)) * -1521134295 + EqualityComparer<ZSyncTransform>.Default.GetHashCode(ZSyncTransform);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				if ((object)this != other)
				{
					if (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<ItemDrop>.Default.Equals(ItemDrop, other.ItemDrop) && EqualityComparer<Piece>.Default.Equals(Piece, other.Piece) && EqualityComparer<EggGrow>.Default.Equals(EggGrow, other.EggGrow))
					{
						return EqualityComparer<ZSyncTransform>.Default.Equals(ZSyncTransform, other.ZSyncTransform);
					}
					return false;
				}
				return true;
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				ItemDrop = original.ItemDrop;
				Piece = original.Piece;
				EggGrow = original.EggGrow;
				ZSyncTransform = original.ZSyncTransform;
			}
		}

		public const string Id = "5f86a765-e449-4047-afc8-a63e4d681a48";

		private readonly Dictionary<ServersideQoLZDO, DateTimeOffset> _eggDropTime = new Dictionary<ServersideQoLZDO, DateTimeOffset>();

		private SectorDictionary<HashSet<ServersideQoLZDO>>? _itemDrops;

		private SectorDictionary<SharedItemDataKey, HashSet<ServersideQoLZDO>>? _containersByItemName;

		private readonly HashSet<ItemType> _excludedTypes = new HashSet<ItemType>();

		protected override void Initialize()
		{
			Processor.Instance<ContainerRegistryProcessor>().ContainerChanged -= OnContainerChanged;
			if (ConfigBase<Config>.Instance.AutoPickup.Value)
			{
				_containersByItemName = Processor.Instance<ContainerRegistryProcessor>().GetContainersByItemName(Mathf.Max(ConfigBase<Config>.Instance.AutoPickupRange.Value, (float)ConfigBase<Config>.Instance.AutoPickupMaxRange.Value));
				_itemDrops = new SectorDictionary<HashSet<ServersideQoLZDO>>(_containersByItemName.SectorWidth);
				Processor.Instance<ContainerRegistryProcessor>().ContainerChanged += OnContainerChanged;
			}
			else
			{
				_containersByItemName = null;
				_itemDrops = null;
			}
			_eggDropTime.Clear();
			ConfigBase<Config>.Instance.AutoPickupExcludeItemTypes.SettingChanged -= UpdateExcludedTypes;
			UpdateExcludedTypes(null, null);
			ConfigBase<Config>.Instance.AutoPickupExcludeItemTypes.SettingChanged += UpdateExcludedTypes;
			void UpdateExcludedTypes(object? sender, EventArgs? args)
			{
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: 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)
				_excludedTypes.Clear();
				foreach (ItemType item in ConfigBase<Config>.Instance.AutoPickupExcludeItemTypes.Value.Items)
				{
					_excludedTypes.Add(item);
				}
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//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_0161: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_086a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0845: Unknown result type (might be due to invalid IL or missing references)
			//IL_084a: Unknown result type (might be due to invalid IL or missing references)
			//IL_084e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0853: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0802: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Expected O, but got Unknown
			//IL_086d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0758: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_060a: Unknown result type (might be due to invalid IL or missing references)
			if (_containersByItemName == null || _itemDrops == null)
			{
				return (ProcessResult)2;
			}
			if (_excludedTypes.Contains(prefabInfo.ItemDrop.m_itemData.m_shared.m_itemType))
			{
				return (ProcessResult)2;
			}
			ZDOVars vars;
			if (prefabInfo.Piece != null)
			{
				vars = zdo.Vars;
				if (((ZDOVars)(ref vars)).GetPiece(false))
				{
					return (ProcessResult)2;
				}
			}
			if (prefabInfo.EggGrow != null)
			{
				vars = zdo.Vars;
				if (((ZDOVars)(ref vars)).GetGrowStart(0f) > 0f)
				{
					return (ProcessResult)0;
				}
				float num = 2f * prefabInfo.EggGrow.m_updateInterval + 2f;
				if (!_eggDropTime.TryGetValue(zdo, out var value))
				{
					_eggDropTime.Add(zdo, DateTimeOffset.UtcNow);
					zdo.Destroyed += delegate(ServersideQoLZDO key)
					{
						_eggDropTime.Remove(key);
					};
					return ((Processor)this).ScheduleReprocessing(num);
				}
				num -= (float)(DateTimeOffset.UtcNow - value).TotalSeconds;
				if (num > 0f)
				{
					return ((Processor)this).ScheduleReprocessing(num);
				}
			}
			if (!Processor.CheckMinDistance(peers, zdo, ConfigBase<Config>.Instance.AutoPickupMinPlayerDistance.Value))
			{
				return ((Processor)this).ScheduleReprocessing(0f);
			}
			SharedData shared = prefabInfo.ItemDrop.m_itemData.m_shared;
			bool flag = false;
			bool flag2 = !ConfigBase<Config>.Instance.AutoPickupExcludeFodder.Value;
			HashSet<Vector2i> hashSet = null;
			List<ServersideQoLZDO> list = null;
			ItemData val = null;
			ProcessResult result = (ProcessResult)0;
			AdjacentEnumerator<SharedItemDataKey, HashSet<ServersideQoLZDO>> enumerator = _containersByItemName.EnumerateAdjacent((zdo.ZDO.GetPosition(), SharedItemDataKey.op_Implicit(shared))).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					HashSet<ServersideQoLZDO> current = enumerator.Current;
					if (current.Count > 0 && !flag2)
					{
						flag2 = true;
						AdjacentEnumerator<HashSet<ServersideQoLZDO>> enumerator2 = Processor.Instance<TameableRegistryProcessor>().Tameables.EnumerateAdjacent(zdo.ZDO.GetPosition()).GetEnumerator();
						try
						{
							while (enumerator2.MoveNext())
							{
								HashSet<ServersideQoLZDO> current2 = enumerator2.Current;
								foreach (ServersideQoLZDO item in current2)
								{
									TameableState state = Processor.Instance<TameableRegistryProcessor>().GetState(item);
									if (state == null || !state.PrefabInfo.MonsterAI.m_consumeItems.Any((ItemDrop val6) => val6.m_itemData.m_shared.m_name == shared.m_name))
									{
										continue;
									}
									float consumeSearchRange = state.PrefabInfo.MonsterAI.m_consumeSearchRange;
									consumeSearchRange *= consumeSearchRange;
									if (!(Utils.DistanceSqr(zdo.ZDO.GetPosition(), item.ZDO.GetPosition()) < consumeSearchRange))
									{
										continue;
									}
									if (prefabInfo.ZSyncTransform != null)
									{
										float num2 = (float)(10.0 - GetTimeSinceSpawned(zdo).TotalSeconds);
										if (num2 > 0f)
										{
											return ((Processor)this).ScheduleReprocessing(num2);
										}
									}
									result = (ProcessResult)2;
									ComponentFieldAccessor<ItemDrop> val2 = zdo.Fields<ItemDrop>();
									if (val2.UpdateValue((Func<Expression<Func<ItemDrop, bool>>>)(() => (ItemDrop val6) => val6.m_autoPickup), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ItemDropProcessor.cs", 118))
									{
										result = (ProcessResult)8;
									}
									if (val2.UpdateValue((Func<Expression<Func<ItemDrop, bool>>>)(() => (ItemDrop val6) => val6.m_autoDestroy), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.AutoStore\\ItemDropProcessor.cs", 120))
									{
										result = (ProcessResult)8;
									}
									return result;
								}
							}
						}
						finally
						{
							((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
						}
					}
					list?.Clear();
					foreach (ServersideQoLZDO item2 in current)
					{
						ContainerState state2 = Processor.Instance<ContainerRegistryProcessor>().GetState(item2);
						if (state2 == null)
						{
							(list ?? (list = new List<ServersideQoLZDO>())).Add(item2);
							continue;
						}
						vars = item2.Vars;
						if (((ZDOVars)(ref vars)).GetInUse(false))
						{
							continue;
						}
						float num3 = state2.AutoStorePickupRange ?? ConfigBase<Config>.Instance.AutoPickupRange.Value;
						num3 *= num3;
						if (num3 == 0f || Utils.DistanceSqr(zdo.ZDO.GetPosition(), item2.ZDO.GetPosition()) > num3)
						{
							continue;
						}
						if (val == null)
						{
							val = new ItemData
							{
								m_shared = shared
							};
							ItemDrop.LoadFromZDO(val, zdo.ZDO, -1);
						}
						int num4 = val.m_stack;
						(hashSet ?? (hashSet = new HashSet<Vector2i>())).Clear();
						bool flag3 = false;
						ItemData val3 = null;
						IInventory inventory = state2.GetInventory();
						foreach (ItemData item3 in inventory.Items)
						{
							hashSet.Add(item3.m_gridPos);
							if (new ItemDataKey(val) != ItemDataKey.op_Implicit(item3))
							{
								continue;
							}
							if (val3 == null)
							{
								val3 = item3;
							}
							int num5 = item3.m_shared.m_maxStackSize - item3.m_stack;
							if (num5 > 0)
							{
								if (ConfigBase<Config>.Instance.AutoPickupRequestOwnership.Value && !zdo.IsOwnerOrUnassigned())
								{
									flag = true;
								}
								if (!item2.IsOwnerOrUnassigned())
								{
									flag3 = true;
								}
								if (flag || flag3)
								{
									break;
								}
								int num6 = Math.Min(num4, num5);
								item3.m_stack += num6;
								num4 -= num6;
								if (num4 == 0)
								{
									break;
								}
							}
						}
						if (val3 == null)
						{
							(list ?? (list = new List<ServersideQoLZDO>())).Add(item2);
							continue;
						}
						int num7 = inventory.Inventory.GetEmptySlots();
						while (num4 > 0 && num7 > 0)
						{
							if (ConfigBase<Config>.Instance.AutoPickupRequestOwnership.Value && !zdo.IsOwnerOrUnassigned())
							{
								flag = true;
							}
							if (!item2.IsOwnerOrUnassigned())
							{
								flag3 = true;
							}
							if (flag || flag3)
							{
								break;
							}
							int num8 = Math.Min(num4, val.m_shared.m_maxStackSize);
							ItemData val4 = val3.Clone();
							val4.m_stack = num8;
							val4.m_gridPos.x = -1;
							for (int num9 = 0; num9 < inventory.Inventory.GetWidth(); num9++)
							{
								if (val4.m_gridPos.x >= 0)
								{
									break;
								}
								for (int num10 = 0; num10 < inventory.Inventory.GetHeight(); num10++)
								{
									if (hashSet.Add(new Vector2i(num9, num10)))
									{
										ref int x = ref val4.m_gridPos.x;
										ref int y = ref val4.m_gridPos.y;
										int num11 = num9;
										int num12 = num10;
										x = num11;
										y = num12;
										break;
									}
								}
							}
							inventory.Items.Add(val4);
							num4 -= num8;
							num7--;
						}
						if (flag || flag3)
						{
							float num13 = 0f;
							if (flag3)
							{
								num13 = Processor.Instance<ContainerRegistryProcessor>().RequestOwnership(item2, default(PlayerID));
							}
							result = (ProcessResult)(((Processor)this).ScheduleReprocessing(num13) | 0x10);
							continue;
						}
						if (num4 != val.m_stack)
						{
							inventory.Save();
							ItemData val5 = val;
							int num12 = num4;
							int stack = val.m_stack;
							val5.m_stack = num12;
							num4 = stack;
							ItemDrop.SaveToZDO(val, zdo.ZDO, -1);
							Processor.ShowMessage((IEnumerable<Peer>)peers, item2, ConfigBase<Config>.Instance.Localization.Value.FormatAutoPickup(state2.Container.m_name, val.m_shared.m_name, num4), ConfigBase<Config>.Instance.PickedUpMessageType.Value, (TextType)0);
							Processor.Instance<ContainerProcessor>().SpawnModifiedEffect(item2);
						}
						if (val.m_stack != 0)
						{
							continue;
						}
						break;
					}
					if (list != null)
					{
						foreach (ServersideQoLZDO item4 in list)
						{
							current.Remove(item4);
						}
					}
					int? num14 = val?.m_stack;
					if (num14.HasValue && num14.GetValueOrDefault() == 0)
					{
						return (ProcessResult)4;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			if (flag)
			{
				zdo.DelaySchedulingFor(ConfigBase<Config>.Instance.Advanced.Value.ProcessingDelays.AfterItemDropOwnershipRequest);
				ZDORpc rPC = zdo.RPC;
				ItemDropRpc itemDrop = ((ZDORpc)(ref rPC)).ItemDrop;
				((ItemDropRpc)(ref itemDrop)).RequestOwn();
			}
			SectorDictionary.TryAdd(_itemDrops, zdo, true);
			return result;
		}

		private void OnContainerChanged(ServersideQoLZDO containerZdo, ContainerState containerState)
		{
			//IL_0074: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			if (_itemDrops == null)
			{
				Processor.Instance<ContainerRegistryProcessor>().ContainerChanged -= OnContainerChanged;
			}
			else
			{
				if (containerState.GetInventory().Items.Count == 0)
				{
					return;
				}
				float num = containerState.AutoStorePickupRange ?? ConfigBase<Config>.Instance.AutoPickupRange.Value;
				num *= num;
				if (num == 0f)
				{
					return;
				}
				AdjacentEnumerator<HashSet<ServersideQoLZDO>> enumerator = _itemDrops.EnumerateAdjacent(containerZdo.ZDO.GetPosition()).GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						HashSet<ServersideQoLZDO> current = enumerator.Current;
						foreach (ServersideQoLZDO item in current)
						{
							if (Utils.DistanceSqr(item.ZDO.GetPosition(), containerZdo.ZDO.GetPosition()) <= num)
							{
								((Processor)this).ScheduleReprocessing(item, 0f);
							}
						}
					}
				}
				finally
				{
					((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
				}
			}
		}

		private static TimeSpan GetTimeSinceSpawned(ServersideQoLZDO zdo)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			DateTime time = ZNet.instance.GetTime();
			ZDOVars vars = zdo.Vars;
			return time - ((ZDOVars)(ref vars)).GetSpawnTime(default(DateTime));
		}
	}
}