Decompiled source of ServersideQoL WorldOptions v2.0.0

ServersideQoL.WorldOptions.dll

Decompiled a day ago
using System;
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 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("Remove Mistland's mist. Configure trader progression requirements. Let workstations share their build range.")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+cdafe98fecdc9c33d99ba13f064e37dcaca41712")]
[assembly: AssemblyProduct("ServersideQoL.WorldOptions")]
[assembly: AssemblyTitle("ServersideQoL.WorldOptions")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("2.0.0.0")]
[module: RefSafetyRules(11)]
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.WorldOptions
{
	public sealed class Config : ConfigBase<Config>
	{
		public enum RemoveMistlandsMistOptions
		{
			Never,
			Always,
			AfterQueenKilled
		}

		private const string Section = "WorldOptions";

		internal const string GlobalKeyNone = "--";

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

		public ConfigEntry<RemoveMistlandsMistOptions> RemoveMistlandsMist { get; } = ConfigBase<Config>.BindEx<RemoveMistlandsMistOptions>(cfg, "WorldOptions", RemoveMistlandsMistOptions.AfterQueenKilled, "Condition to remove the mist from the mistlands.\r\nBeware that there are a few cases of mist (namely mist around POIs like ancient bones/skulls)\r\nthat cannot be removed by this mod and will remain regardless of this setting.", (AcceptableValueBase)(object)AcceptableEnum<RemoveMistlandsMistOptions>.Default, (Deprecated<Config>)null, "RemoveMistlandsMist");

		public ConfigEntry<float> MapTableMapViewDistance { get; } = ConfigBase<Config>.BindEx<float>(cfg, "WorldOptions", 0f, $"Max distance to a map table at which players can view their map.\r\nHas no effect unless the {(object)(GlobalKeys)31} global key is set.\r\n0 to disable this feature.", (AcceptableValueBase)null, (Deprecated<Config>)null, "MapTableMapViewDistance");

		public ConfigEntry<bool> CraftingStationsShareBuildRadius { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "WorldOptions", false, "True to make crafting stations share their build radius.\r\nFor example, a workbench and a stone cutter with overlapping build radius will enable players to build\r\nwith stone also in the workbench's build range and vice versa.", (AcceptableValueBase)null, (Deprecated<Config>)null, "CraftingStationsShareBuildRadius");

		public IReadOnlyDictionary<Trader, IReadOnlyList<ConfigEntry<string>>> TaderProgressRequirements { get; } = GetTaderProgressRequirements(cfg);

		public Config(ConfigFile cfg, Logger logger)
			: base(cfg, logger)
		{
		}

		private static IReadOnlyDictionary<Trader, IReadOnlyList<ConfigEntry<string>>> GetTaderProgressRequirements(ConfigFile cfg)
		{
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Expected O, but got Unknown
			List<Trader> list = new List<Trader>();
			Dictionary<string, Character?> keys = new Dictionary<string, Character>();
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				Trader component = prefab.GetComponent<Trader>();
				if (component != null)
				{
					list.Add(component);
					foreach (string item in from x in component.m_items
						select x.m_requiredGlobalKey into x
						where !string.IsNullOrEmpty(x)
						select x)
					{
						keys.TryAdd(item, null);
					}
					continue;
				}
				Character component2 = prefab.GetComponent<Character>();
				if (component2 != null)
				{
					string defeatSetGlobalKey = component2.m_defeatSetGlobalKey;
					if (defeatSetGlobalKey != null && defeatSetGlobalKey.Length > 0)
					{
						keys[component2.m_defeatSetGlobalKey] = component2;
					}
				}
			}
			List<string> list2 = new List<string>();
			list2.Add("--");
			list2.AddRange(from x in keys
				orderby x.Key
				select x.Key);
			AcceptableValueList<string> val = new AcceptableValueList<string>(list2.ToArray());
			Dictionary<Trader, IReadOnlyList<ConfigEntry<string>>> dictionary = null;
			foreach (Trader item2 in list)
			{
				List<ConfigEntry<string>> list3 = null;
				foreach (IGrouping<string, TradeItem> item3 in from x in item2.m_items
					where !string.IsNullOrEmpty(x.m_requiredGlobalKey)
					group x by x.m_requiredGlobalKey into x
					orderby keys[x.Key]?.m_health ?? float.MaxValue, x.Key
					select x)
				{
					Character? obj = keys[item3.Key];
					string text = "Set" + NormalizeKey(((obj != null) ? ((Object)obj).name : null) ?? item3.Key);
					string key = item3.Key;
					string text2 = string.Join(", ", item3.Select((TradeItem x) => Localization.instance.Localize((x.m_prefab == null) ? x.m_name : x.m_prefab.m_itemData.m_shared.m_name)));
					(list3 ?? (list3 = new List<ConfigEntry<string>>())).Add(cfg.Bind<string>(((Object)item2).name + "ProgressionRequirements", text, key, new ConfigDescription("The required global key for buying " + text2 + " from " + Localization.instance.Localize(item2.m_name), (AcceptableValueBase)(object)val, Array.Empty<object>())));
				}
				if (list3 != null)
				{
					(dictionary ?? (dictionary = new Dictionary<Trader, IReadOnlyList<ConfigEntry<string>>>())).Add(item2, list3);
				}
			}
			IReadOnlyDictionary<Trader, IReadOnlyList<ConfigEntry<string>>> readOnlyDictionary = dictionary;
			return readOnlyDictionary ?? EmptyReadOnlyCollections<Trader, IReadOnlyList<ConfigEntry<string>>>.Dictionary;
			static string NormalizeKey(string input)
			{
				return Regex.Replace(input, "(?:^|_)([a-z])", (Match m) => m.Groups[1].Value.ToUpperInvariant());
			}
		}
	}
	[Processor("aaa674b7-2a64-42f1-aab5-e871f5dc0c63")]
	public sealed class CraftingStationProcessor : Processor<CraftingStationProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(CraftingStation? CraftingStation, StationExtension? StationExtension) : ProcessorPrefabInfo()
		{
			[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("CraftingStation = ");
				builder.Append(CraftingStation);
				builder.Append(", StationExtension = ");
				builder.Append(StationExtension);
				return true;
			}

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

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

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

		private sealed class StationInfo(CraftingStation craftingStation)
		{
			public CraftingStation CraftingStation { get; } = craftingStation;

			public Dictionary<ServersideQoLZDO, State> States { get; } = new Dictionary<ServersideQoLZDO, State>();

			public List<ServersideQoLZDO> Extensions { get; } = new List<ServersideQoLZDO>();
		}

		private sealed class State(ServersideQoLZDO zdo, StationInfo info)
		{
			private float? _buildRange;

			public ServersideQoLZDO ZDO { get; } = zdo;

			public StationInfo Info { get; } = info;

			public Dictionary<int, ServersideQoLZDO>? Stations { get; set; }

			public void ResetBuildRange()
			{
				_buildRange = null;
			}

			public float GetBuildRange()
			{
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				float? buildRange = _buildRange;
				float result;
				if (buildRange.HasValue)
				{
					result = buildRange.GetValueOrDefault();
				}
				else
				{
					int num = 0;
					foreach (ServersideQoLZDO extension in Info.Extensions)
					{
						float num2 = extension.Fields<StationExtension>().GetFloat((Func<Expression<Func<StationExtension, float>>>)(() => (StationExtension x) => x.m_maxStationDistance), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\CraftingStationProcessor.cs", 155);
						num2 *= num2;
						if (Utils.DistanceSqr(ZDO.ZDO.GetPosition(), extension.ZDO.GetPosition()) <= num2)
						{
							num++;
						}
					}
					ComponentFieldAccessor<CraftingStation> val = ZDO.Fields<CraftingStation>();
					_buildRange = (result = val.GetFloat((Func<Expression<Func<CraftingStation, float>>>)(() => (CraftingStation x) => x.m_rangeBuild), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\CraftingStationProcessor.cs", 162) + (float)num * val.GetFloat((Func<Expression<Func<CraftingStation, float>>>)(() => (CraftingStation x) => x.m_extraRangePerLevel), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\CraftingStationProcessor.cs", 163));
				}
				return result;
			}
		}

		public const string Id = "aaa674b7-2a64-42f1-aab5-e871f5dc0c63";

		private readonly Dictionary<CraftingStation, StationInfo> _infos = new Dictionary<CraftingStation, StationInfo>();

		protected override void Initialize()
		{
			_infos.Clear();
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			if (ConfigBase<Config>.Instance.CraftingStationsShareBuildRadius.Value && !((Processor)this).PlacedObjects.Contains(zdo))
			{
				if (prefabInfo.CraftingStation != null)
				{
					if (!_infos.TryGetValue(prefabInfo.CraftingStation, out StationInfo value))
					{
						_infos.Add(prefabInfo.CraftingStation, value = new StationInfo(prefabInfo.CraftingStation));
					}
					if (!value.States.TryGetValue(zdo, out State value2))
					{
						value.States.Add(zdo, value2 = new State(zdo, value));
						zdo.Destroyed += OnCraftingStationDestroyed;
					}
					Dictionary<int, ServersideQoLZDO> stations = value2.Stations;
					if (stations != null && stations.Count > 0)
					{
						foreach (ServersideQoLZDO value4 in value2.Stations.Values)
						{
							((Processor)this).DestroyObject(value4);
						}
						value2.Stations.Clear();
					}
					foreach (StationInfo value5 in _infos.Values)
					{
						if (value5 == value)
						{
							continue;
						}
						foreach (State value6 in value5.States.Values)
						{
							float num = value2.GetBuildRange() + value6.GetBuildRange();
							num *= num;
							if (!(Utils.DistanceSqr(zdo.ZDO.GetPosition(), value6.ZDO.ZDO.GetPosition()) > num))
							{
								PlaceStation(value2, value6.ZDO.ZDO.GetPrefab());
								PlaceStation(value6, zdo.ZDO.GetPrefab());
								break;
							}
						}
					}
					return (ProcessResult)0;
				}
				if (prefabInfo.StationExtension != null)
				{
					if (!_infos.TryGetValue(prefabInfo.StationExtension.m_craftingStation, out StationInfo value3))
					{
						_infos.Add(prefabInfo.StationExtension.m_craftingStation, value3 = new StationInfo(prefabInfo.StationExtension.m_craftingStation));
					}
					value3.Extensions.Add(zdo);
					zdo.Destroyed += OnExtensionDestroyed;
					ScheduleReprocessStationsInRange(value3, zdo, prefabInfo.StationExtension);
				}
				return (ProcessResult)2;
			}
			return (ProcessResult)2;
		}

		private void OnCraftingStationDestroyed(ServersideQoLZDO zdo)
		{
			CraftingStation val = Processor<PrefabInfo>.GetProcessorPrefabInfo(zdo)?.CraftingStation;
			if (val == null || !_infos.TryGetValue(val, out StationInfo value) || !value.States.Remove(zdo, out State value2))
			{
				return;
			}
			Dictionary<int, ServersideQoLZDO> stations = value2.Stations;
			if (stations != null && stations.Count > 0)
			{
				foreach (ServersideQoLZDO value3 in value2.Stations.Values)
				{
					((Processor)this).DestroyObject(value3);
				}
			}
			foreach (StationInfo value4 in _infos.Values)
			{
				if (value4 == value)
				{
					continue;
				}
				foreach (ServersideQoLZDO key in value4.States.Keys)
				{
					((Processor)this).ScheduleReprocessing(key, 0f);
				}
			}
		}

		private void OnExtensionDestroyed(ServersideQoLZDO zdo)
		{
			StationExtension val = Processor<PrefabInfo>.GetProcessorPrefabInfo(zdo)?.StationExtension;
			if (val != null && _infos.TryGetValue(val.m_craftingStation, out StationInfo value) && value.Extensions.Remove(zdo))
			{
				ScheduleReprocessStationsInRange(value, zdo, val);
			}
		}

		private void ScheduleReprocessStationsInRange(StationInfo info, ServersideQoLZDO zdo, StationExtension stationExtension)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			float num = zdo.Fields<StationExtension>().GetFloat((Func<Expression<Func<StationExtension, float>>>)(() => (StationExtension x) => x.m_maxStationDistance), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\CraftingStationProcessor.cs", 106);
			num *= num;
			foreach (State value in info.States.Values)
			{
				if (!((Object)(object)info.CraftingStation != (Object)(object)stationExtension.m_craftingStation) && !(Utils.DistanceSqr(value.ZDO.ZDO.GetPosition(), zdo.ZDO.GetPosition()) > num))
				{
					value.ResetBuildRange();
					((Processor)this).ScheduleReprocessing(value.ZDO, 0f);
				}
			}
		}

		private void PlaceStation(State state, int prefab)
		{
			//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_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((!(state.Stations?.ContainsKey(prefab))) ?? true))
			{
				return;
			}
			Vector3 position = state.ZDO.ZDO.GetPosition();
			position.y -= 10000f;
			ServersideQoLZDO val = ((Processor)this).PlacePiece(position, prefab, 0f, (CreatorMarkers)0);
			val.Fields<CraftingStation>().Set((Func<Expression<Func<CraftingStation, float>>>)(() => (CraftingStation x) => x.m_rangeBuild), state.GetBuildRange(), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\CraftingStationProcessor.cs", 129).Set((Func<Expression<Func<CraftingStation, float>>>)(() => (CraftingStation x) => x.m_extraRangePerLevel), 0f, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\CraftingStationProcessor.cs", 130);
			(state.Stations ?? (state.Stations = new Dictionary<int, ServersideQoLZDO>())).Add(prefab, val);
		}
	}
	[Processor("09966489-a911-4bc0-be43-4dbd01212f19")]
	[DependsOn<PlayerRegistryProcessor>]
	public sealed class MapTableProcessor : Processor<ProcessorPrefabInfo<MapTable>>
	{
		public const string Id = "09966489-a911-4bc0-be43-4dbd01212f19";

		private float _mapTableRangeSqr;

		protected override void Initialize()
		{
			_mapTableRangeSqr = ConfigBase<Config>.Instance.MapTableMapViewDistance.Value * ConfigBase<Config>.Instance.MapTableMapViewDistance.Value;
			if (_mapTableRangeSqr > 0f && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)31))
			{
				_mapTableRangeSqr = 0f;
				((Processor)this).Logger.LogWarning((object)$"[{((ConfigEntryBase)ConfigBase<Config>.Instance.MapTableMapViewDistance).Definition.Section}].[{((ConfigEntryBase)ConfigBase<Config>.Instance.MapTableMapViewDistance).Definition.Key}] has no effect unless the {(object)(GlobalKeys)31} global key is set");
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, ProcessorPrefabInfo<MapTable> prefabInfo)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			Enumerator<Peer> enumerator = ListExtensions.Enumerate<Peer>(peers).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Peer current = enumerator.Current;
					PlayerState playerState = current.PlayerState;
					if (playerState != null)
					{
						if (Utils.DistanceSqr(current.RefPos, zdo.ZDO.GetPosition()) < _mapTableRangeSqr)
						{
							playerState.AddGlobalKeyModification(new GlobalKey((GlobalKeys)31), false, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\MapTableProcessor.cs");
						}
						else
						{
							playerState.RemoveGlobalKeyModification(new GlobalKey((GlobalKeys)31), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\MapTableProcessor.cs");
						}
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			return ((Processor)this).ScheduleReprocessing(0f);
		}
	}
	[Processor("edd9c927-c22e-413d-b6d9-a67c0a3268b9")]
	public sealed class MisterProcessor : Processor<ProcessorPrefabInfo<Mister>>
	{
		private const string QueenDefeatedKey = "defeated_queen";

		private bool _queenDefeated;

		private readonly HashSet<ServersideQoLZDO> _misters = new HashSet<ServersideQoLZDO>();

		protected override void Initialize()
		{
			_queenDefeated = ZoneSystem.instance.GetGlobalKey("defeated_queen");
			_misters.Clear();
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= OnGlobalKeysChanged;
			if (!_queenDefeated)
			{
				ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged += OnGlobalKeysChanged;
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, ProcessorPrefabInfo<Mister> prefabInfo)
		{
			switch (ConfigBase<Config>.Instance.RemoveMistlandsMist.Value)
			{
			case Config.RemoveMistlandsMistOptions.Always:
				if (zdo.Fields<Mister>().UpdateValue((Func<Expression<Func<Mister, float>>>)(() => (Mister x) => x.m_radius), float.MinValue, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\MisterProcessor.cs", 30))
				{
					return (ProcessResult)10;
				}
				break;
			case Config.RemoveMistlandsMistOptions.AfterQueenKilled:
				if (_queenDefeated)
				{
					if (zdo.Fields<Mister>().UpdateValue((Func<Expression<Func<Mister, float>>>)(() => (Mister x) => x.m_radius), float.MinValue, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\MisterProcessor.cs", 37))
					{
						return (ProcessResult)10;
					}
					break;
				}
				_misters.Add(zdo);
				return (ProcessResult)0;
			}
			return (ProcessResult)2;
		}

		private void OnGlobalKeysChanged()
		{
			_queenDefeated = ZoneSystem.instance.GetGlobalKey("defeated_queen");
			if (!_queenDefeated)
			{
				return;
			}
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= OnGlobalKeysChanged;
			foreach (ServersideQoLZDO mister in _misters)
			{
				((Processor)this).ScheduleReprocessing(mister, 0f);
			}
			_misters.Clear();
		}
	}
	[Processor("a4dbfa59-0d8c-4910-8f02-5097a0449786")]
	[DependsOn<PlayerRegistryProcessor>]
	public sealed class TraderProcessor : Processor<ProcessorPrefabInfo<Trader>>
	{
		private readonly record struct GlobalKeyModification(GlobalKey Key, bool Add);

		public const string Id = "a4dbfa59-0d8c-4910-8f02-5097a0449786";

		private readonly Dictionary<Trader, IReadOnlyList<GlobalKeyModification>> _globalKeyModifications = new Dictionary<Trader, IReadOnlyList<GlobalKeyModification>>();

		protected override void Initialize()
		{
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= OnGlobalKeysChanged;
			OnGlobalKeysChanged();
			ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged += OnGlobalKeysChanged;
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, ProcessorPrefabInfo<Trader> prefabInfo)
		{
			//IL_003a: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (!_globalKeyModifications.TryGetValue(prefabInfo.Component, out IReadOnlyList<GlobalKeyModification> value))
			{
				return ((Processor)this).ScheduleReprocessing(0f);
			}
			float num = prefabInfo.Component.m_standRange * prefabInfo.Component.m_standRange;
			Enumerator<Peer> enumerator = ListExtensions.Enumerate<Peer>(peers).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Peer current = enumerator.Current;
					PlayerState playerState = current.PlayerState;
					if (playerState == null)
					{
						continue;
					}
					GlobalKey Key;
					bool Add;
					if (Utils.DistanceSqr(current.RefPos, zdo.ZDO.GetPosition()) < num)
					{
						foreach (GlobalKeyModification item in value)
						{
							item.Deconstruct(out Key, out Add);
							GlobalKey val = Key;
							bool flag = Add;
							playerState.AddGlobalKeyModification(val, flag, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\TraderProcessor.cs");
						}
						continue;
					}
					foreach (GlobalKeyModification item2 in value)
					{
						item2.Deconstruct(out Key, out Add);
						GlobalKey val2 = Key;
						playerState.RemoveGlobalKeyModification(val2, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.WorldOptions\\TraderProcessor.cs");
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			return ((Processor)this).ScheduleReprocessing(0f);
		}

		private void OnGlobalKeysChanged()
		{
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			if (!((ConfigBase<Config>)(object)ConfigBase<Config>.Instance).Enabled.Value)
			{
				ServersideQoLPluginBase<ServersideQoLPlugin, Config>.Instance.GlobalKeysChanged -= OnGlobalKeysChanged;
				return;
			}
			_globalKeyModifications.Clear();
			foreach (KeyValuePair<Trader, IReadOnlyList<ConfigEntry<string>>> taderProgressRequirement in ConfigBase<Config>.Instance.TaderProgressRequirements)
			{
				taderProgressRequirement.Deconstruct(out var key, out var value);
				Trader key2 = key;
				IReadOnlyList<ConfigEntry<string>> readOnlyList = value;
				List<GlobalKeyModification> list = null;
				foreach (ConfigEntry<string> item in readOnlyList)
				{
					if (item.Value.Equals(((ConfigEntryBase)item).BoxedValue))
					{
						continue;
					}
					string key3 = (string)((ConfigEntryBase)item).DefaultValue;
					bool globalKey = ZoneSystem.instance.GetGlobalKey(key3);
					if (globalKey == (item.Value == "--" || ZoneSystem.instance.GetGlobalKey(item.Value)))
					{
						continue;
					}
					bool flag = !globalKey;
					if (list == null)
					{
						list = new List<GlobalKeyModification>(1)
						{
							new GlobalKeyModification(new GlobalKey(key3), flag)
						};
						continue;
					}
					int num = list.FindIndex(delegate(GlobalKeyModification x)
					{
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						//IL_0007: Unknown result type (might be due to invalid IL or missing references)
						GlobalKey key4 = x.Key;
						return GlobalKey.op_Implicit(ref key4) == key3;
					});
					if (num < 0)
					{
						list.Add(new GlobalKeyModification(new GlobalKey(key3), flag));
					}
					else if (list[num].Add != flag)
					{
						((Processor)this).Logger.LogWarning((object)("[" + ((ConfigEntryBase)item).Definition.Section + "].[" + ((ConfigEntryBase)item).Definition.Key + "]: Conflicting requirements for global key " + key3));
						if (flag)
						{
							list[num] = new GlobalKeyModification(new GlobalKey(key3), flag);
						}
					}
				}
				if (list != null)
				{
					_globalKeyModifications.Add(key2, list);
				}
			}
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.WorldOptions", "ServersideQoL.WorldOptions", "2.0.0")]
	public sealed class WorldOptionsPlugin : ServersideQoLPluginBase<WorldOptionsPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.WorldOptions";

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

		public const string PluginVersion = "2.0.0";

		public const string PluginInformationalVersion = "2.0.0";

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

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

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<MisterProcessor>().Add<TraderProcessor>().Add<MapTableProcessor>()
				.Add<CraftingStationProcessor>();
		}

		private void Awake()
		{
		}
	}
}