Decompiled source of ServersideQoL PortalProgression BETA v1.99.8

ServersideQoL.PortalProgression.dll

Decompiled 11 hours 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.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
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("Allows progressively more ores/metals to be taken through portals after bosses are defeated")]
[assembly: AssemblyFileVersion("1.99.8.0")]
[assembly: AssemblyInformationalVersion("1.99.8-beta+328851184cc278c858ffbc70e717af9f9d7b6973")]
[assembly: AssemblyProduct("ServersideQoL.PortalProgression")]
[assembly: AssemblyTitle("ServersideQoL.PortalProgression")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("1.99.8.0")]
[module: RefSafetyRules(11)]
[CompilerGenerated]
internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T>
	{
		object IEnumerator.Current => _item;

		T IEnumerator<T>.Current => _item;

		public Enumerator(T item)
		{
			_item = item;
		}

		bool IEnumerator.MoveNext()
		{
			if (!_moveNextCalled)
			{
				return _moveNextCalled = true;
			}
			return false;
		}

		void IEnumerator.Reset()
		{
			_moveNextCalled = false;
		}

		void IDisposable.Dispose()
		{
		}
	}

	int ICollection.Count => 1;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => 1;

	T IReadOnlyList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
	}

	int ICollection<T>.Count => 1;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlySingleElementList(T item)
	{
		_item = item;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return new Enumerator(_item);
	}

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

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

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

	bool IList.Contains(object value)
	{
		return EqualityComparer<T>.Default.Equals(_item, (T)value);
	}

	int IList.IndexOf(object value)
	{
		if (!EqualityComparer<T>.Default.Equals(_item, (T)value))
		{
			return -1;
		}
		return 0;
	}

	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 new Enumerator(_item);
	}

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

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

	bool ICollection<T>.Contains(T item)
	{
		return EqualityComparer<T>.Default.Equals(_item, item);
	}

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

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

	int IList<T>.IndexOf(T item)
	{
		if (!EqualityComparer<T>.Default.Equals(_item, item))
		{
			return -1;
		}
		return 0;
	}

	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.PortalProgression
{
	public sealed class Config : ConfigBase<Config>
	{
		public sealed record Entry(ItemDrop ItemDrop, ConfigEntry<string> Config);

		public sealed class LocalizationConfig
		{
			public string ItemsReturned { get; init; } = "Portal returned your items";

			private string ItemsTaken { get; init; } = "Portal took {0} items";

			public string FormatItemsTaken(int count)
			{
				return string.Format(ItemsTaken, count);
			}
		}

		private const string Section = "PortalProgression";

		internal const string BossKeyNone = "--";

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "PortalProgression", true, "Enables/disables the entire mod\r\nItems which are not teleportable by default (e.g. ores, metals, etc.) will be temporarily taken from a player's inventory when they enter a certain range around a portal so that they can travel through, according to the settings below.\r\nWhen the player leaves the range (e.g. by travelling through the portal), the items will be returned to their inventory.", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<float> PortalRange { get; } = ConfigBase<Config>.BindEx<float>(cfg, "PortalProgression", 4f, "The range around a portal in which items will be taken from a player's inventory.\r\nDecreasing this value will lead to a longer delay before players with non-teleportable items in their inventory can use the portal.\r\nIncreasing this value will leave players unable to have certain items in their inventory in a larger range around portals.", (AcceptableValueBase)null, (Deprecated<Config>)null, "PortalRange");

		public ConfigEntry<MessageTypes> MessageType { get; } = ConfigBase<Config>.BindEx<MessageTypes>(cfg, "PortalProgression", (MessageTypes)0, "Type of message to show when a non-teleportable item is taken from/returned to a player's inventory", (AcceptableValueBase)(object)AcceptableEnum<MessageTypes>.Default, (Deprecated<Config>)null, "MessageType");

		public IReadOnlyList<Entry> Entries { get; } = ((Func<IReadOnlyList<Entry>>)delegate
		{
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			List<string> list = new List<string>();
			list.Add("--");
			list.AddRange(from x in ConfigBase<Config>.BossesByBiome.Values
				orderby x.m_health
				select x.m_defeatSetGlobalKey);
			AcceptableValueList<string> val = new AcceptableValueList<string>(list.ToArray());
			List<Entry> list2 = new List<Entry>();
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				ItemDrop component = item.GetComponent<ItemDrop>();
				if (component != null)
				{
					ItemData itemData = component.m_itemData;
					if (itemData != null)
					{
						SharedData shared = itemData.m_shared;
						if (shared != null && !shared.m_teleportable)
						{
							string text = "--";
							if (Regex.IsMatch(((Object)item).name, "copper|tin|bronze", RegexOptions.IgnoreCase))
							{
								text = ConfigBase<Config>.BossesByBiome[(Biome)8].m_defeatSetGlobalKey;
							}
							else if (((Object)item).name.Contains("iron", StringComparison.OrdinalIgnoreCase))
							{
								text = ConfigBase<Config>.BossesByBiome[(Biome)2].m_defeatSetGlobalKey;
							}
							else if (Regex.IsMatch(((Object)item).name, "silver|DragonEgg", RegexOptions.IgnoreCase))
							{
								text = ConfigBase<Config>.BossesByBiome[(Biome)4].m_defeatSetGlobalKey;
							}
							else if (((Object)item).name.Contains("blackmetal", StringComparison.OrdinalIgnoreCase))
							{
								text = ConfigBase<Config>.BossesByBiome[(Biome)16].m_defeatSetGlobalKey;
							}
							else if (Regex.IsMatch(((Object)item).name, "DvergrNeedle|MechanicalSpring", RegexOptions.IgnoreCase))
							{
								text = ConfigBase<Config>.BossesByBiome[(Biome)512].m_defeatSetGlobalKey;
							}
							else if (Regex.IsMatch(((Object)item).name, "flametal|CharredCogwheel", RegexOptions.IgnoreCase))
							{
								text = ConfigBase<Config>.BossesByBiome[(Biome)32].m_defeatSetGlobalKey;
							}
							list2.Add(new Entry(component, cfg.Bind<string>("PortalProgression", ((Object)item).name, text, new ConfigDescription("Key of the boss that will allow '" + Localization.instance.Localize(component.m_itemData.m_shared.m_name) + "' to be teleported when defeated", (AcceptableValueBase)(object)val, Array.Empty<object>()))));
						}
					}
				}
			}
			return list2;
		})();

		public YamlConfigEntry<LocalizationConfig> Localization { get; } = ConfigBase<Config>.BindYaml<LocalizationConfig>(cfg, "Localization");

		public Config(ConfigFile cfg, Logger logger)
			: base(cfg, logger)
		{
		}
	}
	[Processor("87d052fd-a4dc-4095-9d5d-7fb765f02f52")]
	[DependsOn<PlayerRegistryProcessor>]
	[DependsOn<ContainerRegistryProcessor>]
	public sealed class PortalProcessor : Processor<PortalProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(TeleportWorld TeleportWorld) : ProcessorPrefabInfo()
		{
			public override bool IsValid => !TeleportWorld.m_allowAllItems;

			[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("TeleportWorld = ");
				builder.Append(TeleportWorld);
				return true;
			}

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

			[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))
					{
						return EqualityComparer<TeleportWorld>.Default.Equals(TeleportWorld, other.TeleportWorld);
					}
					return false;
				}
				return true;
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				TeleportWorld = original.TeleportWorld;
			}
		}

		private sealed class State
		{
			[CompilerGenerated]
			private Timestamp <NextRequest>k__BackingField;

			public Peer Peer { get; }

			public ContainerState Container { get; set; }

			public PlayerState Player { get; }

			public Vector3 InitialPosition { get; }

			public Vector3 PortalPosition { get; }

			public bool Stacked { get; set; }

			public Timestamp NextRequest
			{
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <NextRequest>k__BackingField;
				}
				set
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0002: 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)
					<NextRequest>k__BackingField = value;
					DestroyAfter = ((Timestamp)(ref value)).AddSeconds(5f);
				}
			}

			public Timestamp DestroyAfter { get; private set; }

			public State(Peer peer, ContainerState container, PlayerState player, ServersideQoLZDO portal)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				Peer = peer;
				Container = container;
				Player = player;
				InitialPosition = player.ZDO.ZDO.GetPosition();
				PortalPosition = portal.ZDO.GetPosition();
				base..ctor();
			}
		}

		private readonly Dictionary<ItemData, GameObject> _teleportableItems = new Dictionary<ItemData, GameObject>((IEqualityComparer<ItemData>?)SharedItemDataKeyComparer.Instance);

		private readonly List<State> _containers = new List<State>();

		private float _rangeSqr;

		private static int ContainerPrefabHash => Prefabs.PrivateChest;

		public IReadOnlyDictionary<ItemData, GameObject> TeleportableItems => _teleportableItems;

		protected override void Initialize()
		{
			_rangeSqr = ConfigBase<Config>.Instance.PortalRange.Value;
			_rangeSqr *= _rangeSqr;
			_containers.Clear();
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= UpdateTeleportableItems;
			UpdateTeleportableItems();
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged += UpdateTeleportableItems;
		}

		protected override void PreProcess(PeersEnumerable peers)
		{
			//IL_005b: 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_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			for (int num = _containers.Count - 1; num >= 0; num--)
			{
				State state = _containers[num];
				IInventory inventory = state.Container.GetInventory();
				if (inventory.Items.Count == 0)
				{
					((Processor)this).DestroyObject(state.Container.ZDO);
				}
				else if (state.Stacked)
				{
					if (Utils.DistanceSqr(state.PortalPosition, state.Player.ZDO.ZDO.GetPosition()) > _rangeSqr)
					{
						if (state.Container.ZDO.ZDO.GetOwner() == state.Player.Owner && ZNetScene.InActiveArea(state.Container.ZDO.ZDO.GetSector(), state.Player.ZDO.ZDO.GetSector()))
						{
							Timestamp now = Timestamp.Now;
							if (now > state.NextRequest)
							{
								state.NextRequest = ((Timestamp)(ref now)).AddSeconds(0.2f);
								RPC.TakeAllResponse(state.Container.ZDO, true);
								Processor.ShowMessage((IEnumerable<Peer>)new <>z__ReadOnlySingleElementList<Peer>(state.Peer), state.PortalPosition, ConfigBase<Config>.Instance.Localization.Value.ItemsReturned, ConfigBase<Config>.Instance.MessageType.Value, (TextType)0);
							}
						}
						else
						{
							state.Container.ZDO.ZDO.SetOwnerInternal(state.Player.Owner);
							ZDO zDO = state.Container.ZDO.ZDO;
							Vector3 position = state.Player.ZDO.ZDO.GetPosition();
							position.y = -1000f;
							zDO.SetPosition(position);
							state.Container.ZDO.Destroyed -= OnContainerDestroyed;
							state.Container = Processor.Instance<ContainerRegistryProcessor>().GetState(((Processor)this).RecreatePiece(state.Container.ZDO));
							state.Container.ZDO.UnregisterAll();
							state.Container.ZDO.Destroyed += OnContainerDestroyed;
						}
					}
				}
				else 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;
				}))
				{
					int num2 = 0;
					for (int num3 = inventory.Items.Count - 1; num3 >= 0; num3--)
					{
						ItemData val = inventory.Items[num3];
						if (val.m_gridPos.x == 0)
						{
							if (--val.m_stack == 0)
							{
								inventory.Items.RemoveAt(num3);
							}
							num2 += val.m_stack;
						}
					}
					inventory.Save();
					Processor.Instance<ContainerRegistryProcessor>().SetReturnContentToCreator(state.Container.ZDO, true);
					ZDOVars vars = state.Container.ZDO.Vars;
					((ZDOVars)(ref vars)).SetCreator(state.Player.PlayerID, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.PortalProgression\\PortalProcessor.cs", 83);
					state.Stacked = true;
					state.Container.ZDO.Destroyed -= OnContainerDestroyed;
					state.Container = Processor.Instance<ContainerRegistryProcessor>().GetState(((Processor)this).RecreatePiece(state.Container.ZDO));
					state.Container.ZDO.UnregisterAll();
					state.Container.ZDO.Destroyed += OnContainerDestroyed;
					Processor.ShowMessage((IEnumerable<Peer>)new <>z__ReadOnlySingleElementList<Peer>(state.Peer), state.PortalPosition, ConfigBase<Config>.Instance.Localization.Value.FormatItemsTaken(num2), ConfigBase<Config>.Instance.MessageType.Value, (TextType)0);
					Timestamp now2 = Timestamp.Now;
					state.NextRequest = ((Timestamp)(ref now2)).AddSeconds(1f);
				}
				else if (Utils.DistanceSqr(state.PortalPosition, state.Player.ZDO.ZDO.GetPosition()) <= _rangeSqr)
				{
					Timestamp now3 = Timestamp.Now;
					if (now3 > state.NextRequest)
					{
						state.NextRequest = ((Timestamp)(ref now3)).AddSeconds(0.2f);
						if (state.Container.ZDO.ZDO.GetOwner() != state.Player.Owner || !ZNetScene.InActiveArea(state.Container.ZDO.ZDO.GetSector(), state.Player.ZDO.ZDO.GetSector()))
						{
							state.Container.ZDO.ZDO.SetOwnerInternal(state.Player.Owner);
							ZDO zDO2 = state.Container.ZDO.ZDO;
							Vector3 position = state.Player.ZDO.ZDO.GetPosition();
							position.y = -1000f;
							zDO2.SetPosition(position);
							state.Container.ZDO.Destroyed -= OnContainerDestroyed;
							state.Container = Processor.Instance<ContainerRegistryProcessor>().GetState(((Processor)this).RecreatePiece(state.Container.ZDO));
							state.Container.ZDO.UnregisterAll();
							state.Container.ZDO.Destroyed += OnContainerDestroyed;
						}
						RPC.StackResponse(state.Container.ZDO, true);
						RPC.ShowMessage(state.Player.Owner, (MessageType)2, "");
					}
				}
				else if (Timestamp.Now > state.DestroyAfter)
				{
					((Processor)this).DestroyObject(state.Container.ZDO);
				}
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			if (!zdo.Fields<TeleportWorld>().GetBool((Func<Expression<Func<TeleportWorld, bool>>>)(() => (TeleportWorld x) => x.m_allowAllItems), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.PortalProgression\\PortalProcessor.cs", 123))
			{
				if (_teleportableItems.Count != 0)
				{
					Enumerator<Peer> enumerator = ListExtensions.Enumerate<Peer>(peers).GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							Peer current = enumerator.Current;
							PlayerState player = current.PlayerState;
							if (player == null || Utils.DistanceSqr(zdo.ZDO.GetPosition(), player.ZDO.ZDO.GetPosition()) > _rangeSqr || _containers.Any((State x) => x.Player == player))
							{
								continue;
							}
							Vector3 position = player.ZDO.ZDO.GetPosition();
							position.y = -1000f;
							ServersideQoLZDO val = ((Processor)this).PlacePiece(position, Prefabs.PrivateChest, 0f, (CreatorMarkers)0);
							val.UnregisterAll();
							int num = Math.Max(4, TeleportableItems.Count);
							val.Fields<Container>().Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_width), 8, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.PortalProgression\\PortalProcessor.cs", 142).Set((Func<Expression<Func<Container, int>>>)(() => (Container x) => x.m_height), num, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.PortalProgression\\PortalProcessor.cs", 143);
							int num2 = 0;
							ContainerState state = Processor.Instance<ContainerRegistryProcessor>().GetState(val);
							IInventory inventory = state.GetInventory();
							foreach (KeyValuePair<ItemData, GameObject> teleportableItem in TeleportableItems)
							{
								teleportableItem.Deconstruct(out var key, out var value);
								ItemData val2 = key;
								GameObject dropPrefab = value;
								ItemData val3 = val2.Clone();
								val3.m_dropPrefab = dropPrefab;
								val3.m_stack = 1;
								val3.m_gridPos = new Vector2i(0, num2++);
								inventory.Items.Add(val3);
							}
							inventory.Save();
							val.ZDO.SetOwnerInternal(current.ZNetPeer.m_uid);
							List<State> containers = _containers;
							State state2 = new State(current, state, player, zdo);
							Timestamp now = Timestamp.Now;
							state2.NextRequest = ((Timestamp)(ref now)).AddSeconds(0.2f);
							containers.Add(state2);
							val.Destroyed += OnContainerDestroyed;
							if (!current.ZNetPeer.m_server)
							{
								player.ZDO.Destroyed += OnPlayerDestroyed;
							}
							RPC.StackResponse(val, true);
							RPC.ShowMessage(player.Owner, (MessageType)2, "");
						}
					}
					finally
					{
						((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
					}
					return (ProcessResult)32;
				}
				return (ProcessResult)32;
			}
			return (ProcessResult)2;
		}

		private void UpdateTeleportableItems()
		{
			_teleportableItems.Clear();
			if (!((ConfigBase<Config>)(object)ConfigBase<Config>.Instance).Enabled.Value)
			{
				ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= UpdateTeleportableItems;
				return;
			}
			foreach (Config.Entry entry in ConfigBase<Config>.Instance.Entries)
			{
				if (!string.IsNullOrEmpty(entry.Config.Value) && !(entry.Config.Value == "--") && ZoneSystem.instance.GetGlobalKey(entry.Config.Value))
				{
					_teleportableItems.Add(entry.ItemDrop.m_itemData, ((Component)entry.ItemDrop).gameObject);
				}
			}
		}

		private void OnContainerDestroyed(ServersideQoLZDO zdo)
		{
			for (int i = 0; i < _containers.Count; i++)
			{
				State state = _containers[i];
				if (state.Container.ZDO == zdo)
				{
					state.Player.ZDO.Destroyed -= OnPlayerDestroyed;
					_containers.RemoveAt(i);
					break;
				}
			}
		}

		private void OnPlayerDestroyed(ServersideQoLZDO zdo)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _containers.Count; i++)
			{
				State state = _containers[i];
				if (state.Player.ZDO != zdo)
				{
					continue;
				}
				state.Container.ZDO.Destroyed -= OnContainerDestroyed;
				if (!state.Stacked)
				{
					((Processor)this).DestroyObject(state.Container.ZDO);
				}
				else
				{
					state.Container.ZDO.ReleaseOwnershipInternal();
					ZDO zDO = state.Container.ZDO.ZDO;
					Vector3 initialPosition = state.InitialPosition;
					initialPosition.y = -1000f;
					zDO.SetPosition(initialPosition);
					state.Container.ZDO.Fields<Container>().Set((Func<Expression<Func<Container, bool>>>)(() => (Container x) => x.m_autoDestroyEmpty), true, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.PortalProgression\\PortalProcessor.cs", 215);
					state.Container.ZDO.CreateClone(false);
					((Processor)this).DestroyObject(state.Container.ZDO);
				}
				_containers.RemoveAt(i);
				break;
			}
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.PortalProgression", "ServersideQoL.PortalProgression", "1.99.8")]
	public sealed class PortalProgressionPlugin : ServersideQoLPluginBase<PortalProgressionPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.PortalProgression";

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

		public const string PluginVersion = "1.99.8";

		public const string PluginInformationalVersion = "1.99.8-beta";

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

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

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

		private void Awake()
		{
			ServersideQoLPluginBase<PortalProgressionPlugin, Config>.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.8-beta", BuildTimestamp.LocalDateTime));
		}
	}
}