Decompiled source of Upgrade World v1.51.0

UpgradeWorld.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Service;
using TMPro;
using UnityEngine;
using UpgradeWorld;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("UpgradeWorld")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UpgradeWorld")]
[assembly: AssemblyTitle("UpgradeWorld")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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 Service
{
	public class ComponentInfo
	{
		private static Type[]? types;

		private static readonly Dictionary<string, HashSet<int>> PrefabComponents = new Dictionary<string, HashSet<int>>();

		public static Type[] Types => types ?? (types = LoadTypes());

		private static Type[] LoadTypes()
		{
			List<Assembly> list = new List<Assembly>();
			list.Add(Assembly.GetAssembly(typeof(ZNetView)));
			foreach (Assembly item in from p in Chainloader.PluginInfos.Values
				where (Object)(object)p.Instance != (Object)null
				select ((object)p.Instance).GetType().Assembly)
			{
				list.Add(item);
			}
			Assembly.GetAssembly(typeof(ZNetView));
			Type baseType = typeof(MonoBehaviour);
			return list.SelectMany(delegate(Assembly s)
			{
				try
				{
					return s.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					return ex.Types.Where((Type t) => t != null);
				}
			}).Where(delegate(Type t)
			{
				try
				{
					return baseType.IsAssignableFrom(t);
				}
				catch
				{
					return false;
				}
			}).ToArray();
		}

		public static IEnumerable<KeyValuePair<int, GameObject>> HaveComponent(IEnumerable<KeyValuePair<int, GameObject>> objs, List<string[]> typeSets)
		{
			List<string[]> typeSets2 = typeSets;
			if (PrefabComponents.Count == 0)
			{
				foreach (KeyValuePair<int, GameObject> namedPrefab in ZNetScene.instance.m_namedPrefabs)
				{
					namedPrefab.Value.GetComponentsInChildren<MonoBehaviour>(ZNetView.m_tempComponents);
					foreach (MonoBehaviour tempComponent in ZNetView.m_tempComponents)
					{
						string key = ((object)tempComponent).GetType().Name.ToLowerInvariant();
						if (!PrefabComponents.ContainsKey(key))
						{
							PrefabComponents[key] = new HashSet<int>();
						}
						PrefabComponents[key].Add(namedPrefab.Key);
					}
				}
			}
			HashSet<int> value;
			return objs.Where<KeyValuePair<int, GameObject>>((KeyValuePair<int, GameObject> obj) => typeSets2.Any((string[] types) => types.All((string type) => PrefabComponents.TryGetValue(type.ToLowerInvariant(), out value) && value.Contains(obj.Key))));
		}
	}
	public class DataHelper
	{
		public static string GetData(ZDO zdo, string key, string type)
		{
			//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_0035: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = zdo.m_uid;
			int stableHashCode = StringExtensionMethods.GetStableHashCode(key);
			int stableHashCode2 = StringExtensionMethods.GetStableHashCode(key + "_u");
			int stableHashCode3 = StringExtensionMethods.GetStableHashCode(key + "_i");
			bool num = ZDOExtraData.s_vec3.ContainsKey(uid) && ZDOExtraData.s_vec3[uid].ContainsKey(stableHashCode);
			bool flag = ZDOExtraData.s_quats.ContainsKey(uid) && ZDOExtraData.s_quats[uid].ContainsKey(stableHashCode);
			bool flag2 = ZDOExtraData.s_longs.ContainsKey(uid) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode);
			bool flag3 = ZDOExtraData.s_strings.ContainsKey(uid) && ZDOExtraData.s_strings[uid].ContainsKey(stableHashCode);
			bool flag4 = ZDOExtraData.s_ints.ContainsKey(uid) && ZDOExtraData.s_ints[uid].ContainsKey(stableHashCode);
			bool flag5 = ZDOExtraData.s_floats.ContainsKey(uid) && ZDOExtraData.s_floats[uid].ContainsKey(stableHashCode);
			bool flag6 = ZDOExtraData.s_longs.ContainsKey(uid) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode2) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode3);
			if (num && (type == "" || type == "vector"))
			{
				return Helper.PrintVectorXZY(ZDOExtraData.s_vec3[uid][stableHashCode]) + " (vector)";
			}
			if (flag && (type == "" || type == "quat"))
			{
				return Helper.PrintAngleYXZ(ZDOExtraData.s_quats[uid][stableHashCode]) + " (quat)";
			}
			if (flag2 && (type == "" || type == "long"))
			{
				if (stableHashCode == ZDOVars.s_timeOfDeath)
				{
					return Helper.PrintDay(ZDOExtraData.s_longs[uid][stableHashCode]) + " (long)";
				}
				return ZDOExtraData.s_longs[uid][stableHashCode] + " (long)";
			}
			if (flag3 && (type == "" || type == "string"))
			{
				return ZDOExtraData.s_strings[uid][stableHashCode] + " (string)";
			}
			if (flag4 && (type == "" || type == "int"))
			{
				return ZDOExtraData.s_ints[uid][stableHashCode] + " (int)";
			}
			if (flag5 && (type == "" || type == "float"))
			{
				return ZDOExtraData.s_floats[uid][stableHashCode].ToString("F1") + " (float)";
			}
			if (flag6 && (type == "" || type == "id"))
			{
				return ZDOExtraData.s_longs[uid][stableHashCode2] + "/" + ZDOExtraData.s_longs[uid][stableHashCode3] + " (id)";
			}
			return "No data";
		}

		public static bool SetData(ZDO zdo, string key, string data, string type)
		{
			//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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = zdo.m_uid;
			int stableHashCode = StringExtensionMethods.GetStableHashCode(key);
			int stableHashCode2 = StringExtensionMethods.GetStableHashCode(key + "_u");
			bool flag = ZDOExtraData.s_vec3.ContainsKey(uid) && ZDOExtraData.s_vec3[uid].ContainsKey(stableHashCode);
			bool flag2 = ZDOExtraData.s_quats.ContainsKey(uid) && ZDOExtraData.s_quats[uid].ContainsKey(stableHashCode);
			bool flag3 = ZDOExtraData.s_longs.ContainsKey(uid) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode);
			bool flag4 = ZDOExtraData.s_strings.ContainsKey(uid) && ZDOExtraData.s_strings[uid].ContainsKey(stableHashCode);
			bool flag5 = ZDOExtraData.s_ints.ContainsKey(uid) && ZDOExtraData.s_ints[uid].ContainsKey(stableHashCode);
			bool flag6 = ZDOExtraData.s_floats.ContainsKey(uid) && ZDOExtraData.s_floats[uid].ContainsKey(stableHashCode);
			bool flag7 = ZDOExtraData.s_longs.ContainsKey(uid) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode2);
			if (type == "vector" || (type == "" && flag))
			{
				zdo.Set(stableHashCode, Parse.VectorXZY(Parse.Split(data), Vector3.zero));
			}
			else if (type == "quat" || (type == "" && flag2))
			{
				zdo.Set(stableHashCode, Parse.AngleYXZ(data));
			}
			else if (type == "long" || (type == "" && flag3))
			{
				if (stableHashCode == ZDOVars.s_timeOfDeath)
				{
					zdo.Set(stableHashCode, Helper.ToTick(Parse.Long(data, 0L)));
				}
				else
				{
					zdo.Set(stableHashCode, Parse.Long(data, 0L));
				}
			}
			else if (type == "string" || (type == "" && flag4))
			{
				zdo.Set(stableHashCode, data.Replace('_', ' '));
			}
			else if (type == "int" || (type == "" && flag5))
			{
				zdo.Set(stableHashCode, Parse.Int(data), false);
			}
			else if (type == "float" || (type == "" && flag6))
			{
				zdo.Set(stableHashCode, Parse.Float(data));
			}
			else
			{
				if (!(type == "id") && !(type == "" && flag7))
				{
					return false;
				}
				string[] array = Parse.Split(data, '/');
				int stableHashCode3 = StringExtensionMethods.GetStableHashCode(key + "_i");
				zdo.Set(stableHashCode2, Parse.Long(array[0], 0L));
				zdo.Set(stableHashCode3, Parse.Long(array, 1, 0L));
			}
			return true;
		}

		public static bool HasData(ZDO zdo, string key, string data, bool includeEmpty)
		{
			//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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0052: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = zdo.m_uid;
			int stableHashCode = StringExtensionMethods.GetStableHashCode(key);
			int stableHashCode2 = StringExtensionMethods.GetStableHashCode(key + "_u");
			if (ZDOExtraData.s_vec3.ContainsKey(uid) && ZDOExtraData.s_vec3[uid].ContainsKey(stableHashCode))
			{
				return Parse.VectorXZYRange(data, Vector3.zero).Includes(ZDOExtraData.s_vec3[uid][stableHashCode]);
			}
			if (ZDOExtraData.s_quats.ContainsKey(uid) && ZDOExtraData.s_quats[uid].ContainsKey(stableHashCode))
			{
				return Parse.AngleYXZ(data) == ZDOExtraData.s_quats[uid][stableHashCode];
			}
			if (ZDOExtraData.s_longs.ContainsKey(uid) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode))
			{
				if (stableHashCode == ZDOVars.s_timeOfDeath)
				{
					return Parse.LongRange(data, 0L).Includes(Helper.ToDay(ZDOExtraData.s_longs[uid][stableHashCode]));
				}
				return Parse.LongRange(data, 0L).Includes(ZDOExtraData.s_longs[uid][stableHashCode]);
			}
			if (ZDOExtraData.s_strings.ContainsKey(uid) && ZDOExtraData.s_strings[uid].ContainsKey(stableHashCode))
			{
				return data.Replace('_', ' ') == ZDOExtraData.s_strings[uid][stableHashCode];
			}
			if (ZDOExtraData.s_ints.ContainsKey(uid) && ZDOExtraData.s_ints[uid].ContainsKey(stableHashCode))
			{
				return Parse.IntRange(data).Includes(ZDOExtraData.s_ints[uid][stableHashCode]);
			}
			if (ZDOExtraData.s_floats.ContainsKey(uid) && ZDOExtraData.s_floats[uid].ContainsKey(stableHashCode))
			{
				return Parse.FloatRange(data).Includes(ZDOExtraData.s_floats[uid][stableHashCode]);
			}
			int stableHashCode3 = StringExtensionMethods.GetStableHashCode(key + "_i");
			if (ZDOExtraData.s_longs.ContainsKey(uid) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode2) && ZDOExtraData.s_longs[uid].ContainsKey(stableHashCode3))
			{
				return data == ZDOExtraData.s_longs[uid][stableHashCode2] + "/" + ZDOExtraData.s_longs[uid][stableHashCode3];
			}
			return includeEmpty;
		}
	}
	public static class Hash
	{
		public static int Changed = StringExtensionMethods.GetStableHashCode("override_changed");

		public static int OverrideItems = StringExtensionMethods.GetStableHashCode("override_items");
	}
	public class Range<T> where T : IComparable
	{
		public T Min;

		public T Max;

		public Range(T value)
		{
			Min = value;
			Max = value;
		}

		public Range(T min, T max)
		{
			Min = min;
			Max = max;
		}

		public bool Includes(T value)
		{
			if (Min.CompareTo(value) <= 0)
			{
				return Max.CompareTo(value) >= 0;
			}
			return false;
		}
	}
	public class Vector3Range
	{
		public Vector3 Min;

		public Vector3 Max;

		public Vector3Range(Vector3 value)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Min = value;
			Max = value;
		}

		public Vector3Range(Vector3 min, Vector3 max)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Min = min;
			Max = max;
		}

		public bool Includes(Vector3 value)
		{
			if (((Vector3)(ref Min)).sqrMagnitude <= ((Vector3)(ref value)).sqrMagnitude)
			{
				return ((Vector3)(ref value)).sqrMagnitude <= ((Vector3)(ref Max)).sqrMagnitude;
			}
			return false;
		}
	}
	public static class Parse
	{
		private static readonly HashSet<string> Truthies = new HashSet<string> { "1", "true", "yes", "on" };

		private static readonly HashSet<string> Falsies = new HashSet<string> { "0", "false", "no", "off" };

		private static Range<string> Range(string arg)
		{
			List<string> list = arg.Split(new char[1] { '-' }).ToList();
			if (list.Count > 1 && list[0] == "")
			{
				list[0] = "-" + list[1];
				list.RemoveAt(1);
			}
			if (list.Count > 2 && list[1] == "")
			{
				list[1] = "-" + list[2];
				list.RemoveAt(2);
			}
			if (list.Count == 1)
			{
				return new Range<string>(list[0]);
			}
			return new Range<string>(list[0], list[1]);
		}

		public static int Int(string arg, int defaultValue = 0)
		{
			if (!int.TryParse(arg, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return defaultValue;
			}
			return result;
		}

		public static int Int(string[] args, int index, int defaultValue = 0)
		{
			if (args.Length <= index)
			{
				return defaultValue;
			}
			return Int(args[index], defaultValue);
		}

		public static Range<int> IntRange(string arg, int defaultValue = 0)
		{
			Range<string> range = Range(arg);
			return new Range<int>(Int(range.Min, defaultValue), Int(range.Max, defaultValue));
		}

		public static Range<int> IntRange(string[] args, int index, int defaultValue = 0)
		{
			if (args.Length <= index)
			{
				return new Range<int>(defaultValue);
			}
			return IntRange(args[index], defaultValue);
		}

		public static uint UInt(string arg, uint defaultValue = 0u)
		{
			if (!uint.TryParse(arg, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return defaultValue;
			}
			return result;
		}

		public static uint UInt(string[] args, int index, uint defaultValue = 0u)
		{
			if (args.Length <= index)
			{
				return defaultValue;
			}
			return UInt(args[index], defaultValue);
		}

		public static Range<uint> UIntRange(string arg, uint defaultValue = 0u)
		{
			Range<string> range = Range(arg);
			return new Range<uint>(UInt(range.Min, defaultValue), UInt(range.Max, defaultValue));
		}

		public static Range<uint> UIntRange(string[] args, int index, uint defaultValue = 0u)
		{
			if (args.Length <= index)
			{
				return new Range<uint>(defaultValue);
			}
			return UIntRange(args[index], defaultValue);
		}

		public static long Long(string arg, long defaultValue = 0L)
		{
			if (!long.TryParse(arg, NumberStyles.Integer, CultureInfo.InvariantCulture, out var result))
			{
				return defaultValue;
			}
			return result;
		}

		public static long Long(string[] args, int index, long defaultValue = 0L)
		{
			if (args.Length <= index)
			{
				return defaultValue;
			}
			return Long(args[index], defaultValue);
		}

		public static Range<long> LongRange(string arg, long defaultValue = 0L)
		{
			Range<string> range = Range(arg);
			return new Range<long>(Long(range.Min, defaultValue), Long(range.Max, defaultValue));
		}

		public static Range<long> LongRange(string[] args, int index, long defaultValue = 0L)
		{
			if (args.Length <= index)
			{
				return new Range<long>(defaultValue);
			}
			return LongRange(args[index], defaultValue);
		}

		public static bool TryFloat(string arg, out float value)
		{
			return float.TryParse(arg, NumberStyles.Float, CultureInfo.InvariantCulture, out value);
		}

		public static float Float(string arg, float defaultValue = 0f)
		{
			if (!TryFloat(arg, out var value))
			{
				return defaultValue;
			}
			return value;
		}

		public static float Float(string[] args, int index, float defaultValue = 0f)
		{
			if (args.Length <= index)
			{
				return defaultValue;
			}
			return Float(args[index], defaultValue);
		}

		public static Range<float> FloatRange(string arg, float defaultValue = 0f)
		{
			Range<string> range = Range(arg);
			return new Range<float>(Float(range.Min, defaultValue), Float(range.Max, defaultValue));
		}

		public static Range<float> FloatRange(string[] args, int index, float defaultValue = 0f)
		{
			if (args.Length <= index)
			{
				return new Range<float>(defaultValue);
			}
			return FloatRange(args[index], defaultValue);
		}

		public static string String(string[] args, int index, string defaultValue = "")
		{
			if (args.Length <= index)
			{
				return defaultValue;
			}
			return args[index];
		}

		public static Quaternion AngleYXZ(string arg)
		{
			//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)
			return AngleYXZ(arg, Quaternion.identity);
		}

		public static Quaternion AngleYXZ(string arg, Quaternion defaultValue)
		{
			//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_0015: 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_0049: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			string[] args = Split(arg);
			Vector3 zero = Vector3.zero;
			zero.y = Float(args, 0, ((Quaternion)(ref defaultValue)).eulerAngles.y);
			zero.x = Float(args, 1, ((Quaternion)(ref defaultValue)).eulerAngles.x);
			zero.z = Float(args, 2, ((Quaternion)(ref defaultValue)).eulerAngles.z);
			return Quaternion.Euler(zero);
		}

		public static Vector3 VectorXZY(string[] args)
		{
			//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)
			return VectorXZY(args, 0, Vector3.zero);
		}

		public static Vector3 VectorXZY(string[] args, Vector3 defaultValue)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return VectorXZY(args, 0, defaultValue);
		}

		public static Vector3 VectorXZY(string[] args, int index)
		{
			//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)
			return VectorXZY(args, index, Vector3.zero);
		}

		public static Vector3 VectorXZY(string[] args, int index, Vector3 defaultValue)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector3 zero = Vector3.zero;
			zero.x = Float(args, index, defaultValue.x);
			zero.y = Float(args, index + 2, defaultValue.y);
			zero.z = Float(args, index + 1, defaultValue.z);
			return zero;
		}

		public static Vector3Range VectorXZYRange(string arg, Vector3 defaultValue)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			string[] args = Split(arg);
			Range<float> x = FloatRange(args, 0, defaultValue.x);
			Range<float> y = FloatRange(args, 2, defaultValue.y);
			Range<float> z = FloatRange(args, 1, defaultValue.z);
			return ToVectorRange(x, y, z);
		}

		public static Vector3 VectorZXY(string[] args)
		{
			//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)
			return VectorZXY(args, 0, Vector3.zero);
		}

		public static Vector3 VectorZXY(string[] args, Vector3 defaultValue)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return VectorZXY(args, 0, defaultValue);
		}

		public static Vector3 VectorZXY(string[] args, int index)
		{
			//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)
			return VectorZXY(args, index, Vector3.zero);
		}

		public static Vector3 VectorZXY(string[] args, int index, Vector3 defaultValue)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector3 zero = Vector3.zero;
			zero.x = Float(args, index + 1, defaultValue.x);
			zero.y = Float(args, index + 2, defaultValue.y);
			zero.z = Float(args, index, defaultValue.z);
			return zero;
		}

		public static Vector3Range VectorZXYRange(string arg, Vector3 defaultValue)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			string[] args = Split(arg);
			Range<float> x = FloatRange(args, 1, defaultValue.x);
			Range<float> y = FloatRange(args, 2, defaultValue.y);
			Range<float> z = FloatRange(args, 0, defaultValue.z);
			return ToVectorRange(x, y, z);
		}

		private static Vector3Range ToVectorRange(Range<float> x, Range<float> y, Range<float> z)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Vector3 min = new Vector3(x.Min, y.Min, z.Min);
			Vector3 max = default(Vector3);
			((Vector3)(ref max))..ctor(x.Max, y.Max, z.Max);
			return new Vector3Range(min, max);
		}

		public static Vector3 VectorYXZ(string[] args)
		{
			//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)
			return VectorYXZ(args, 0, Vector3.zero);
		}

		public static Vector3 VectorYXZ(string[] args, Vector3 defaultValue)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			return VectorYXZ(args, 0, defaultValue);
		}

		public static Vector3 VectorYXZ(string[] args, int index)
		{
			//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)
			return VectorYXZ(args, index, Vector3.zero);
		}

		public static Vector3 VectorYXZ(string[] args, int index, Vector3 defaultValue)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector3 zero = Vector3.zero;
			zero.y = Float(args, index, defaultValue.y);
			zero.x = Float(args, index + 1, defaultValue.x);
			zero.z = Float(args, index + 2, defaultValue.z);
			return zero;
		}

		public static Vector3Range VectorYXZRange(string arg, Vector3 defaultValue)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			string[] args = Split(arg);
			Range<float> x = FloatRange(args, 1, defaultValue.x);
			Range<float> y = FloatRange(args, 0, defaultValue.y);
			Range<float> z = FloatRange(args, 2, defaultValue.z);
			return ToVectorRange(x, y, z);
		}

		public static Vector3 Scale(string[] args)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Scale(args, 0);
		}

		public static Vector3 Scale(string[] args, int index)
		{
			//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)
			return SanityCheck(VectorXZY(args, index));
		}

		private static Vector3 SanityCheck(Vector3 scale)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0028: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			if (scale.x == 0f)
			{
				scale.x = 1f;
			}
			if (scale.y == 0f)
			{
				scale.y = scale.x;
			}
			if (scale.z == 0f)
			{
				scale.z = scale.x;
			}
			return scale;
		}

		public static Vector3Range ScaleRange(string arg)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0049: 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)
			string[] args = Split(arg);
			Range<float> x = FloatRange(args, 0);
			Range<float> y = FloatRange(args, 1);
			Range<float> z = FloatRange(args, 2);
			Vector3Range vector3Range = ToVectorRange(x, y, z);
			vector3Range.Min = SanityCheck(vector3Range.Min);
			vector3Range.Max = SanityCheck(vector3Range.Max);
			return vector3Range;
		}

		public static string[] Split(string arg, char separator = ',')
		{
			return (from s in arg.Split(new char[1] { separator })
				select s.Trim() into s
				where s != ""
				select s).ToArray();
		}

		public static string[] Split(string[] args, int index, char separator)
		{
			if (args.Length > index)
			{
				return Split(args[index], separator);
			}
			return new string[0];
		}

		private static bool IsTruthy(string value)
		{
			return Truthies.Contains(value);
		}

		private static bool IsFalsy(string value)
		{
			return Falsies.Contains(value);
		}

		public static bool? Boolean(string arg)
		{
			if (IsTruthy(arg))
			{
				return true;
			}
			if (IsFalsy(arg))
			{
				return false;
			}
			return null;
		}

		public static IEnumerable<string> Flag(IEnumerable<string> parameters, string flag, out bool value)
		{
			string flag2 = flag;
			value = parameters.FirstOrDefault((string arg) => arg.ToLower() == flag2) != null;
			return parameters.Where((string arg) => arg.ToLower() != flag2);
		}

		public static bool Flag(List<string> parameters, string flag)
		{
			string flag2 = flag;
			string text = parameters.FirstOrDefault((string value) => value.ToLower() == flag2.ToLower());
			if (text == null)
			{
				return false;
			}
			return parameters.Remove(text);
		}

		public static Vector2i Zone(string arg)
		{
			//IL_0010: 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)
			string[] array = Split(arg).ToArray();
			Vector2i result = default(Vector2i);
			if (array.Length != 0)
			{
				result.x = Int(array[0]);
			}
			if (array.Length > 1)
			{
				result.y = Int(array[1]);
			}
			return result;
		}

		public static Vector2 Pos(string arg)
		{
			//IL_0010: 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)
			string[] array = Split(arg).ToArray();
			Vector2 result = default(Vector2);
			if (array.Length != 0)
			{
				result.x = Float(array[0]);
			}
			if (array.Length > 1)
			{
				result.y = Float(array[1]);
			}
			return result;
		}

		public static HashSet<Biome> Biomes(string arg)
		{
			return Split(arg).Select(Helper.GetBiome).ToHashSet();
		}
	}
	public class ZDOData
	{
		public ZDO Zdo;

		public int Prefab;

		public Dictionary<int, string> Strings = new Dictionary<int, string>();

		public Dictionary<int, float> Floats = new Dictionary<int, float>();

		public Dictionary<int, int> Ints = new Dictionary<int, int>();

		public Dictionary<int, long> Longs = new Dictionary<int, long>();

		public Dictionary<int, Vector3> Vecs = new Dictionary<int, Vector3>();

		public Dictionary<int, Quaternion> Quats = new Dictionary<int, Quaternion>();

		public Dictionary<int, byte[]> ByteArrays = new Dictionary<int, byte[]>();

		public ConnectionType ConnectionType;

		public int ConnectionHash;

		public ZDOID OriginalId = ZDOID.None;

		public ZDOID TargetConnectionId = ZDOID.None;

		public ZDOData(ZDO zdo)
		{
			//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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			Zdo = zdo;
			Load(zdo);
		}

		public ZDO Clone()
		{
			//IL_000b: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			ZDO val = ZDOMan.instance.CreateNewZDO(Zdo.m_position, 0);
			val.Persistent = Zdo.Persistent;
			val.Type = Zdo.Type;
			val.Distant = Zdo.Distant;
			val.m_prefab = Prefab;
			val.m_rotation = Zdo.m_rotation;
			val.SetOwnerInternal(Zdo.GetOwner());
			Write(val);
			return val;
		}

		private void Write(ZDO zdo)
		{
			//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_001a: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = zdo.m_uid;
			if (Floats.Count > 0)
			{
				ZDOHelper.Init<float>(ZDOExtraData.s_floats, uid);
			}
			if (Vecs.Count > 0)
			{
				ZDOHelper.Init<Vector3>(ZDOExtraData.s_vec3, uid);
			}
			if (Quats.Count > 0)
			{
				ZDOHelper.Init<Quaternion>(ZDOExtraData.s_quats, uid);
			}
			if (Ints.Count > 0)
			{
				ZDOHelper.Init<int>(ZDOExtraData.s_ints, uid);
			}
			if (Longs.Count > 0)
			{
				ZDOHelper.Init<long>(ZDOExtraData.s_longs, uid);
			}
			if (Strings.Count > 0)
			{
				ZDOHelper.Init<string>(ZDOExtraData.s_strings, uid);
			}
			if (ByteArrays.Count > 0)
			{
				ZDOHelper.Init<byte[]>(ZDOExtraData.s_byteArrays, uid);
			}
			foreach (KeyValuePair<int, float> @float in Floats)
			{
				ZDOExtraData.s_floats[uid].SetValue(@float.Key, @float.Value);
			}
			foreach (KeyValuePair<int, Vector3> vec in Vecs)
			{
				ZDOExtraData.s_vec3[uid].SetValue(vec.Key, vec.Value);
			}
			foreach (KeyValuePair<int, Quaternion> quat in Quats)
			{
				ZDOExtraData.s_quats[uid].SetValue(quat.Key, quat.Value);
			}
			foreach (KeyValuePair<int, int> @int in Ints)
			{
				ZDOExtraData.s_ints[uid].SetValue(@int.Key, @int.Value);
			}
			foreach (KeyValuePair<int, long> @long in Longs)
			{
				ZDOExtraData.s_longs[uid].SetValue(@long.Key, @long.Value);
			}
			foreach (KeyValuePair<int, string> @string in Strings)
			{
				ZDOExtraData.s_strings[uid].SetValue(@string.Key, @string.Value);
			}
			foreach (KeyValuePair<int, byte[]> byteArray in ByteArrays)
			{
				ZDOExtraData.s_byteArrays[uid].SetValue(byteArray.Key, byteArray.Value);
			}
			HandleConnection(zdo);
			HandleHashConnection(zdo);
		}

		private void HandleConnection(ZDO ownZdo)
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (OriginalId == ZDOID.None)
			{
				return;
			}
			ZDOID uid = ownZdo.m_uid;
			if (TargetConnectionId != ZDOID.None)
			{
				ZDO zDO = ZDOMan.instance.GetZDO(TargetConnectionId);
				if (zDO != null)
				{
					ownZdo.SetConnection(ConnectionType, TargetConnectionId);
					if ((int)ConnectionType == 1)
					{
						zDO.SetConnection((ConnectionType)1, uid);
					}
				}
				return;
			}
			KeyValuePair<ZDOID, ZDOConnection> keyValuePair = ZDOExtraData.s_connections.FirstOrDefault((KeyValuePair<ZDOID, ZDOConnection> kvp) => kvp.Value.m_target == OriginalId);
			if (keyValuePair.Value != null)
			{
				ZDO zDO2 = ZDOMan.instance.GetZDO(keyValuePair.Key);
				if (zDO2 != null)
				{
					zDO2.SetConnection(keyValuePair.Value.m_type, uid);
				}
			}
		}

		private void HandleHashConnection(ZDO ownZdo)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002c: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Invalid comparison between Unknown and I4
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Invalid comparison between Unknown and I4
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Invalid comparison between Unknown and I4
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (ConnectionHash == 0 || (int)ConnectionType == 0)
			{
				return;
			}
			ZDOID uid = ownZdo.m_uid;
			ZDOExtraData.SetConnectionData(uid, ConnectionType, ConnectionHash);
			? val = ConnectionType ^ 0x10;
			bool flag = (ConnectionType & 0x10) == 0;
			ZDOID val2 = ((IEnumerable<ZDOID>)ZDOExtraData.GetAllConnectionZDOIDs((ConnectionType)val)).FirstOrDefault((Func<ZDOID, bool>)((ZDOID z) => ZDOExtraData.GetConnectionHashData(z, ConnectionType)?.m_hash == ConnectionHash));
			if (val2 == ZDOID.None)
			{
				return;
			}
			ZDO zDO = ZDOMan.instance.GetZDO(val2);
			if (zDO != null)
			{
				if ((ConnectionType & 3) > 0)
				{
					ZDO val3 = (ZDO)(flag ? ((object)ownZdo) : ((object)zDO));
					ZDOID val4 = (flag ? val2 : uid);
					val3.SetConnection((ConnectionType)3, val4);
				}
				if ((ConnectionType & 2) > 0)
				{
					ZDO val5 = (ZDO)(flag ? ((object)ownZdo) : ((object)zDO));
					ZDOID val6 = (flag ? val2 : uid);
					val5.SetConnection((ConnectionType)2, val6);
				}
				if ((ConnectionType & 1) > 0)
				{
					zDO.SetConnection((ConnectionType)1, uid);
					ownZdo.SetConnection((ConnectionType)1, val2);
				}
			}
		}

		private void Load(ZDO zdo)
		{
			//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_0019: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: 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_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			ZDOID uid = zdo.m_uid;
			Prefab = zdo.m_prefab;
			Floats = (ZDOExtraData.s_floats.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, float>>)ZDOExtraData.s_floats[uid]).ToDictionary((KeyValuePair<int, float> kvp) => kvp.Key, (KeyValuePair<int, float> kvp) => kvp.Value) : new Dictionary<int, float>());
			Ints = (ZDOExtraData.s_ints.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, int>>)ZDOExtraData.s_ints[uid]).ToDictionary((KeyValuePair<int, int> kvp) => kvp.Key, (KeyValuePair<int, int> kvp) => kvp.Value) : new Dictionary<int, int>());
			Longs = (ZDOExtraData.s_longs.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, long>>)ZDOExtraData.s_longs[uid]).ToDictionary((KeyValuePair<int, long> kvp) => kvp.Key, (KeyValuePair<int, long> kvp) => kvp.Value) : new Dictionary<int, long>());
			Strings = (ZDOExtraData.s_strings.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, string>>)ZDOExtraData.s_strings[uid]).ToDictionary((KeyValuePair<int, string> kvp) => kvp.Key, (KeyValuePair<int, string> kvp) => kvp.Value) : new Dictionary<int, string>());
			Vecs = (ZDOExtraData.s_vec3.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, Vector3>>)ZDOExtraData.s_vec3[uid]).ToDictionary((KeyValuePair<int, Vector3> kvp) => kvp.Key, (KeyValuePair<int, Vector3> kvp) => kvp.Value) : new Dictionary<int, Vector3>());
			Quats = (ZDOExtraData.s_quats.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, Quaternion>>)ZDOExtraData.s_quats[uid]).ToDictionary((KeyValuePair<int, Quaternion> kvp) => kvp.Key, (KeyValuePair<int, Quaternion> kvp) => kvp.Value) : new Dictionary<int, Quaternion>());
			ByteArrays = (ZDOExtraData.s_byteArrays.ContainsKey(uid) ? ((IEnumerable<KeyValuePair<int, byte[]>>)ZDOExtraData.s_byteArrays[uid]).ToDictionary((KeyValuePair<int, byte[]> kvp) => kvp.Key, (KeyValuePair<int, byte[]> kvp) => kvp.Value) : new Dictionary<int, byte[]>());
			if (ZDOExtraData.s_connectionsHashData.TryGetValue(uid, out var value))
			{
				ConnectionType = value.m_type;
				ConnectionHash = value.m_hash;
			}
			OriginalId = uid;
			if (ZDOExtraData.s_connections.TryGetValue(uid, out var value2) && value2.m_target != ZDOID.None)
			{
				TargetConnectionId = value2.m_target;
				ConnectionType = value2.m_type;
			}
		}
	}
}
namespace UpgradeWorld
{
	public abstract class BaseOperation
	{
		protected int LocationProxyHash = StringExtensionMethods.GetStableHashCode("LocationProxy");

		protected int LocationHash = StringExtensionMethods.GetStableHashCode("location");

		protected Terminal Context;

		public ZRpc? User;

		private readonly List<Vector3> Pins = new List<Vector3>();

		private readonly bool Pin;

		protected BaseOperation(Terminal context, bool pin = false)
		{
			Context = (Terminal)(((object)context) ?? ((object)Console.instance));
			User = ServerExecution.User;
			Pin = pin;
		}

		public void Print(string value, bool addDot = true)
		{
			if (addDot && !value.EndsWith("."))
			{
				value += ".";
			}
			Helper.Print(Context, User, value);
		}

		protected void Log(IEnumerable<string> values)
		{
			ZLog.Log((object)("\n" + string.Join("\n", values)));
		}

		protected void Print(IEnumerable<string> values, bool addDot = true)
		{
			foreach (string value in values)
			{
				Print(value, addDot);
			}
		}

		protected void PrintOnce(string value, bool addDot = true)
		{
			if (addDot && !value.EndsWith("."))
			{
				value += ".";
			}
			Helper.PrintOnce(Context, User, value, 10f);
		}

		protected void AddPin(Vector3 pos)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (Pin)
			{
				Pins.Add(pos);
			}
		}

		protected void PrintPins()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (!Pin)
			{
				return;
			}
			if (User != null)
			{
				User.Invoke(ServerExecution.RPC_Pins, new object[1] { string.Join("|", Pins.Select(Helper.PrintVectorXZY)) });
				return;
			}
			List<PinData> findPins = ((Terminal)Console.instance).m_findPins;
			foreach (PinData item in findPins)
			{
				Minimap instance = Minimap.instance;
				if (instance != null)
				{
					instance.RemovePin(item);
				}
			}
			findPins.Clear();
			foreach (Vector3 pin in Pins)
			{
				Minimap instance2 = Minimap.instance;
				PinData val = ((instance2 != null) ? instance2.AddPin(pin, (PinType)3, "", false, false, Player.m_localPlayer.GetPlayerID(), "") : null);
				if (val != null)
				{
					findPins.Add(val);
				}
			}
		}
	}
	public abstract class EntityOperation : BaseOperation
	{
		private static readonly int PlayerHash = StringExtensionMethods.GetStableHashCode("Player");

		private static Dictionary<int, string> HashToName = new Dictionary<int, string>();

		protected EntityOperation(Terminal context, bool pin = false)
			: base(context, pin)
		{
		}

		private static bool IsIncluded(string id, string name)
		{
			if (id == "*")
			{
				return true;
			}
			if (id[0] == '*' && id[id.Length - 1] == '*')
			{
				return name.Contains(id.Substring(1, id.Length - 2));
			}
			if (id[0] == '*')
			{
				return name.EndsWith(id.Substring(1), StringComparison.OrdinalIgnoreCase);
			}
			if (id[id.Length - 1] == '*')
			{
				return name.StartsWith(id.Substring(0, id.Length - 1), StringComparison.OrdinalIgnoreCase);
			}
			return id == name;
		}

		public static string GetName(int prefab)
		{
			if (!HashToName.TryGetValue(prefab, out string value))
			{
				return "";
			}
			return value;
		}

		public static HashSet<int> GetPrefabs(IEnumerable<string> id, List<string[]> types)
		{
			List<string[]> types2 = types;
			if (id.Count() != 0)
			{
				return id.SelectMany((string id) => GetPrefabs(id, types2)).ToHashSet();
			}
			return GetPrefabs("*", types2);
		}

		public static HashSet<int> GetPrefabs(string id, List<string[]> types)
		{
			string id2 = id;
			if (HashToName.Count == 0)
			{
				HashToName = ZNetScene.instance.m_namedPrefabs.ToDictionary((KeyValuePair<int, GameObject> kvp) => StringExtensionMethods.GetStableHashCode(((Object)kvp.Value).name), (KeyValuePair<int, GameObject> kvp) => ((Object)kvp.Value).name);
			}
			IEnumerable<KeyValuePair<int, GameObject>> source = ZNetScene.instance.m_namedPrefabs.Where((KeyValuePair<int, GameObject> kvp) => kvp.Key != PlayerHash);
			if (!(id2 == "*"))
			{
				source = ((!id2.Contains("*")) ? source.Where((KeyValuePair<int, GameObject> kvp) => string.Equals(((Object)kvp.Value).name, id2, StringComparison.OrdinalIgnoreCase)) : source.Where((KeyValuePair<int, GameObject> kvp) => IsIncluded(id2, ((Object)kvp.Value).name)));
			}
			if (types.Count > 0)
			{
				source = ComponentInfo.HaveComponent(source.ToArray(), types);
			}
			return source.Select((KeyValuePair<int, GameObject> kvp) => kvp.Key).ToHashSet();
		}

		public static ZDO[] GetZDOs(ZDO[] zdos, int hash)
		{
			return zdos.Where((ZDO zdo) => hash == zdo.m_prefab).ToArray();
		}

		public static ZDO[] GetZDOs(FiltererParameters args, HashSet<int> prefabs)
		{
			HashSet<int> prefabs2 = prefabs;
			return FilterZdos(ZDOMan.instance.m_objectsByID.Values.Where((ZDO zdo) => prefabs2.Contains(zdo.m_prefab)), args).ToArray();
		}

		public static ZDO[] GetZDOs(DataParameters args, HashSet<int> prefabs)
		{
			HashSet<int> prefabs2 = prefabs;
			return FilterZdos(ZDOMan.instance.m_objectsByID.Values.Where((ZDO zdo) => prefabs2.Contains(zdo.m_prefab)), args).ToArray();
		}

		public static ZDO[] GetZDOs(FiltererParameters args)
		{
			return FilterZdos(ZDOMan.instance.m_objectsByID.Values, args).ToArray();
		}

		public static ZDO[] GetZDOs(DataParameters args)
		{
			return FilterZdos(ZDOMan.instance.m_objectsByID.Values, args).ToArray();
		}

		public static ZDO[] GetZDOs(string id)
		{
			return GetZDOs(StringExtensionMethods.GetStableHashCode(id));
		}

		public static ZDO[] GetZDOs(int hash)
		{
			return ZDOMan.instance.m_objectsByID.Values.Where((ZDO zdo) => hash == zdo.m_prefab).ToArray();
		}

		public static IEnumerable<ZDO> FilterZdos(IEnumerable<ZDO> zdos, DataParameters args)
		{
			return args.LimitZdos(args.FilterZdos(zdos, checkExcludedZones: false));
		}

		public static IEnumerable<ZDO> FilterZdos(IEnumerable<ZDO> zdos, FiltererParameters args)
		{
			return args.LimitZdos(args.FilterZdos(zdos, checkExcludedZones: false));
		}
	}
	public abstract class ExecutedOperation : BaseOperation
	{
		protected int Attempts;

		protected int Failed;

		public bool AutoStart;

		public bool First = true;

		protected ExecutedOperation(Terminal context, bool autoStart, bool pin = false)
			: base(context, pin)
		{
			AutoStart = autoStart;
		}

		public bool Execute()
		{
			try
			{
				if (First)
				{
					OnStart();
					First = false;
				}
				bool num = OnExecute();
				Attempts++;
				if (num)
				{
					PrintPins();
					OnEnd();
				}
				return num;
			}
			catch (InvalidOperationException ex)
			{
				Helper.Print(Context, User, ex.Message);
				OnEnd();
				return true;
			}
		}

		protected abstract bool OnExecute();

		public void Init()
		{
			string text = OnInit();
			if (text != "")
			{
				Print(text);
			}
		}

		protected abstract string OnInit();

		protected virtual void OnStart()
		{
		}

		protected virtual void OnEnd()
		{
		}
	}
	public abstract class TimeOperation : BaseOperation
	{
		public TimeOperation(Terminal context)
			: base(context)
		{
		}

		protected void Change(double time)
		{
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (time < 0.0)
			{
				Print("Error: New time would be negative.");
				return;
			}
			ZNet instance = ZNet.instance;
			long ticks = instance.GetTime().Ticks;
			instance.SetNetTime(time);
			_ = instance.GetTime().Ticks;
			int num = 0;
			int num2 = 0;
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			IEnumerable<string> timeBasedDataNames = Settings.TimeBasedDataNames;
			HashSet<int> hashSet = timeBasedDataNames.Select((string par) => StringExtensionMethods.GetStableHashCode(par)).ToHashSet();
			foreach (int item in hashSet)
			{
				dictionary.Add(item, 0);
			}
			foreach (ZDO value2 in ZDOMan.instance.m_objectsByID.Values)
			{
				if (!ZDOExtraData.s_longs.TryGetValue(value2.m_uid, out var value))
				{
					continue;
				}
				bool flag = false;
				if (value2.m_prefab == Settings.ZoneControlHash)
				{
					num2++;
					foreach (int item2 in value.Keys.ToList())
					{
						if (value[item2] != 0L)
						{
							flag = true;
							num++;
							value[item2] = (long)time;
						}
					}
				}
				foreach (int item3 in hashSet)
				{
					if (value.ContainsKey(item3) && value[item3] != 0L)
					{
						value[item3] = (long)time;
						dictionary[item3]++;
						flag = true;
					}
				}
				if (flag)
				{
					value2.IncreaseDataRevision();
				}
			}
			if (Settings.Verbose)
			{
				Print("Updated " + num + " spawn zones in " + num2 + " of zones");
				foreach (string item4 in timeBasedDataNames)
				{
					int stableHashCode = StringExtensionMethods.GetStableHashCode(item4);
					Print("Updated " + dictionary[stableHashCode] + " of " + item4);
				}
			}
			Print("Setting time to " + time.ToString("0") + "s , Day: " + EnvMan.instance.GetDay(time));
		}
	}
	public abstract class ZoneOperation : ExecutedOperation
	{
		public string Operation = "BaseOperation";

		protected Vector2i[] ZonesToUpgrade;

		protected int ZonesPerUpdate = 1;

		protected int ZoneIndex;

		protected int PreOperated;

		protected FiltererParameters Args;

		protected List<IZoneFilterer> Filterers = new List<IZoneFilterer>();

		protected string InitString = "";

		protected ZoneOperation(Terminal context, FiltererParameters args)
			: base(context, args.Start, args.Pin)
		{
			ZonesToUpgrade = Zones.GetZones(args);
			Args = args;
		}

		protected override string OnInit()
		{
			List<string> messages = new List<string>();
			ZonesToUpgrade = Filterers.Aggregate(ZonesToUpgrade, (Vector2i[] zones, IZoneFilterer filterer) => filterer.FilterZones(zones, ref messages));
			InitString += $" {ZonesToUpgrade.Length} zones";
			if (messages.Count > 0)
			{
				InitString = InitString + ": " + Helper.JoinRows(messages);
			}
			InitString += ".";
			return InitString;
		}

		protected abstract bool ExecuteZone(Vector2i zone);

		protected override bool OnExecute()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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)
			if (ZonesToUpgrade == null || ZonesToUpgrade.Length == 0)
			{
				return true;
			}
			for (int i = 0; i < ZonesPerUpdate; i++)
			{
				if (ZoneIndex >= ZonesToUpgrade.Length)
				{
					break;
				}
				Vector2i val = ZonesToUpgrade[ZoneIndex];
				bool flag = ExecuteZone(val);
				if (flag && ZoneSystem.instance.m_zones.TryGetValue(val, out var value))
				{
					value.m_ttl = ZoneSystem.instance.m_zoneTTL;
				}
				MoveToNextZone(flag);
				if (!flag)
				{
					break;
				}
			}
			UpdateConsole();
			return ZoneIndex >= ZonesToUpgrade.Length;
		}

		private void MoveToNextZone(bool success = true)
		{
			if (success)
			{
				Attempts = 0;
				ZoneIndex++;
				return;
			}
			Attempts++;
			if (Attempts > 1000)
			{
				Failed++;
				Attempts = 0;
				ZoneIndex++;
			}
		}

		private void UpdateConsole()
		{
			if (Settings.Verbose)
			{
				string text = (ZonesToUpgrade.Length + PreOperated).ToString();
				string text2 = (ZoneIndex + PreOperated).ToString().PadLeft(text.Length, '0');
				PrintOnce(Operation + ": " + text2 + "/" + text, addDot: false);
			}
			else
			{
				int num = Math.Min(100, (ZonesToUpgrade.Length == 0) ? 100 : ((int)Math.Floor(100.0 * (double)(ZoneIndex + PreOperated) / (double)(ZonesToUpgrade.Length + PreOperated))));
				PrintOnce(Operation + ": " + num + "%", addDot: false);
			}
		}
	}
	public class ChangeTime : TimeOperation
	{
		public ChangeTime(Terminal context, double time)
			: base(context)
		{
			Change(ZNet.instance.GetTimeSeconds() + time);
		}
	}
	public class CountBiomes : BaseOperation
	{
		public CountBiomes(Terminal context, float frequency, FiltererParameters args)
			: base(context)
		{
			Count(frequency, args);
		}

		private void Count(float frequency, FiltererParameters args)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (!args.Pos.HasValue)
			{
				return;
			}
			if (args.MaxDistance == 0f)
			{
				args.MaxDistance = Settings.WorldRadius;
			}
			Dictionary<Biome, int> dictionary = new Dictionary<Biome, int>();
			float num = (0f - (float)Math.Ceiling(args.MaxDistance / frequency)) * frequency;
			for (float num2 = num; num2 <= args.MaxDistance; num2 += frequency)
			{
				for (float num3 = num; num3 <= args.MaxDistance; num3 += frequency)
				{
					Vector2 val = new Vector2(num2, num3);
					float magnitude = ((Vector2)(ref val)).magnitude;
					if (magnitude < args.MinDistance || magnitude > args.MaxDistance)
					{
						continue;
					}
					Biome biome = WorldGenerator.instance.GetBiome(args.Pos.Value.x + num2, args.Pos.Value.y + num3);
					if (args.IsBiomeValid(biome))
					{
						if (!dictionary.ContainsKey(biome))
						{
							dictionary[biome] = 0;
						}
						dictionary[biome]++;
					}
				}
			}
			float total = dictionary.Values.Sum();
			IEnumerable<string> values = from kvp in dictionary
				orderby Enum.GetName(typeof(Biome), kvp.Key)
				select Enum.GetName(typeof(Biome), kvp.Key) + ": " + kvp.Value + "/" + total + " (" + ((float)kvp.Value / total).ToString("P2", CultureInfo.InvariantCulture) + ")";
			Print(string.Join("\n", values));
		}
	}
	public class Generate : ZoneOperation
	{
		public Generate(Terminal context, FiltererParameters args)
			: base(context, args)
		{
			Operation = "Generate";
			InitString = args.Print("Generate");
			Filterers = FiltererFactory.Create(args);
		}

		protected override bool ExecuteZone(Vector2i zone)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			ZoneSystem instance = ZoneSystem.instance;
			if (instance.IsZoneGenerated(zone))
			{
				return true;
			}
			GameObject val = default(GameObject);
			return instance.SpawnZone(zone, (SpawnMode)2, ref val);
		}

		protected override void OnEnd()
		{
			int num = ZonesToUpgrade.Length - Failed;
			string text = Operation + " completed. " + num + " zones generated.";
			if (Failed > 0)
			{
				text = text + " " + Failed + " errors.";
			}
			Print(text);
		}
	}
	public class DistributeLocations : ExecutedOperation
	{
		private readonly string[] Ids = new string[0];

		public float Chance = 1f;

		public int Added;

		private int Total;

		public static bool SpawnToAlreadyGenerated = false;

		public static HashSet<Vector2i> AllowedZones = new HashSet<Vector2i>();

		public DistributeLocations(Terminal context, HashSet<string> ids, FiltererParameters args)
			: base(context, args.Start)
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			List<string> list = new List<string>();
			foreach (string id in ids)
			{
				list.Add(id);
			}
			Ids = list.ToArray();
			if (Ids.Length == 0)
			{
				Ids = (from loc in ZoneSystem.instance.m_locations
					orderby loc.m_prioritized descending
					where loc.m_enable && loc.m_quantity != 0
					select loc.m_prefab.Name).ToArray();
			}
			Chance = args.Chance;
			args = new FiltererParameters(args)
			{
				TargetZones = TargetZones.All
			};
			List<IZoneFilterer> source = FiltererFactory.Create(args);
			List<string> messages = new List<string>();
			HashSet<Vector2i> hashSet = new HashSet<Vector2i>();
			foreach (Vector2i item in source.Aggregate(Zones.GetZones(args), (Vector2i[] zones, IZoneFilterer filterer) => filterer.FilterZones(zones, ref messages)).Distinct())
			{
				hashSet.Add(item);
			}
			AllowedZones = hashSet;
		}

		protected override bool OnExecute()
		{
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			if (Attempts == 0)
			{
				Print("Generating locations " + Ids[Attempts] + ". This may take a while...");
				return false;
			}
			if (Attempts <= Ids.Length)
			{
				SpawnToAlreadyGenerated = true;
				ZoneSystem instance = ZoneSystem.instance;
				string id = Ids[Attempts - 1];
				ZoneLocation val = ((IEnumerable<ZoneLocation>)instance.m_locations).FirstOrDefault((Func<ZoneLocation, bool>)((ZoneLocation location) => location.m_prefab.Name == id));
				if (val == null)
				{
					return false;
				}
				if (Attempts < Ids.Length)
				{
					Print("Generating locations " + Ids[Attempts] + ". This may take a while...");
				}
				int count = instance.m_locationInstances.Count;
				ClearNotSpawned(id);
				instance.GenerateLocations(val);
				if (Chance < 1f)
				{
					instance.m_locationInstances = instance.m_locationInstances.Where((KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Value.m_placed || kvp.Value.m_location.m_prefab.Name != id || FiltererParameters.random.NextDouble() < (double)Chance).ToDictionary((KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Key, (KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Value);
				}
				foreach (KeyValuePair<Vector2i, LocationInstance> item in instance.m_locationInstances.Where((KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Value.m_location.m_prefab.Name == id && !kvp.Value.m_placed).ToList())
				{
					AddPin(item.Value.m_position);
				}
				Total += Count(id);
				Added += instance.m_locationInstances.Count - count;
				SpawnToAlreadyGenerated = false;
				return false;
			}
			return true;
		}

		private void ClearNotSpawned(string id)
		{
			string id2 = id;
			ZoneSystem instance = ZoneSystem.instance;
			instance.m_locationInstances = instance.m_locationInstances.Where((KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Value.m_placed || kvp.Value.m_location.m_prefab.Name != id2).ToDictionary((KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Key, (KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Value);
		}

		private int Count(string id)
		{
			string id2 = id;
			return ZoneSystem.instance.m_locationInstances.Where((KeyValuePair<Vector2i, LocationInstance> kvp) => kvp.Value.m_location.m_prefab.Name == id2).Count();
		}

		protected override void OnEnd()
		{
			if (Added >= 0)
			{
				Print($"{Added} locations{Helper.LocationIdString(Ids)} added to the world (total amount in the world: {Total}).");
			}
			else
			{
				Print($"{Math.Abs(Added)} locations{Helper.LocationIdString(Ids)} removed from the world (total amount in the world: {Total}).");
			}
		}

		protected override string OnInit()
		{
			return "Generate locations" + Helper.LocationIdString(Ids) + ".";
		}
	}
	public class ListLocationPositions : EntityOperation
	{
		public ListLocationPositions(Terminal context, HashSet<string> ids, LocationIdParameters args)
			: base(context, args.Pin)
		{
			ListPositions(ids, args);
		}

		private void ListPositions(HashSet<string> ids, LocationIdParameters args)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//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_009b: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> ids2 = ids;
			ZoneSystem instance = ZoneSystem.instance;
			List<string> list = new List<string>();
			foreach (LocationInstance item in (from l in args.FilterLocations(instance.m_locationInstances.Values)
				where ids2.Count() == 0 || ids2.Contains(l.m_location?.m_prefab.Name ?? "")
				select l).ToList())
			{
				string name = item.m_location.m_prefab.Name;
				list.Add($"{name}: {Helper.PrintVectorXZY(item.m_position)} {WorldGenerator.instance.GetBiome(item.m_position)}");
				AddPin(item.m_position);
			}
			if (args.Log)
			{
				Log(list);
			}
			else
			{
				Print(list, addDot: false);
			}
			PrintPins();
		}
	}
	public abstract class LocationOperation : ZoneOperation
	{
		protected int Operated;

		protected string Verb = "";

		private readonly List<GameObject> spawnedObjects = new List<GameObject>();

		public LocationOperation(Terminal context, FiltererParameters args)
			: base(context, args)
		{
			args.TargetZones = TargetZones.Generated;
			Filterers = FiltererFactory.Create(args);
		}

		protected override bool ExecuteZone(Vector2i zone)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (Attempts == 0 && !Args.Roll())
			{
				return true;
			}
			ZoneSystem instance = ZoneSystem.instance;
			if (!instance.m_locationInstances.TryGetValue(zone, out var value))
			{
				return true;
			}
			if (instance.IsZoneLoaded(zone))
			{
				if (ExecuteLocation(zone, value))
				{
					Operated++;
				}
				return true;
			}
			instance.PokeLocalZone(zone);
			return false;
		}

		protected abstract bool ExecuteLocation(Vector2i zone, LocationInstance location);

		protected override void OnEnd()
		{
			string text = $"{Operation} completed. {Operated} locations {Verb}.";
			if (Failed > 0)
			{
				text = text + " " + Failed + " errors.";
			}
			Print(text);
		}

		protected void SpawnLocation(Vector2i zone, LocationInstance location, float clearRadius)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			ZoneSystem instance = ZoneSystem.instance;
			GameObject root = instance.m_zones[zone].m_root;
			Vector3 zonePos = ZoneSystem.instance.GetZonePos(zone);
			Heightmap heightmap = Zones.GetHeightmap(root);
			Helper.ClearAreaForLocation(zone, location, clearRadius);
			ResetTerrain.Execute(radius: (Args.TerrainReset == 0f) ? location.m_location.m_exteriorRadius : Args.TerrainReset, pos: location.m_position);
			List<ClearArea> list = new List<ClearArea>();
			instance.PlaceLocations(zone, zonePos, root.transform, heightmap, list, (SpawnMode)2, spawnedObjects);
			foreach (GameObject spawnedObject in spawnedObjects)
			{
				Object.Destroy((Object)(object)spawnedObject);
			}
			spawnedObjects.Clear();
		}
	}
	public class RegisterLocation : BaseOperation
	{
		public RegisterLocation(Terminal context, string id, Vector3 position)
			: base(context)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			Register(id, position);
		}

		private void Register(string id, Vector3 position)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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)
			//IL_0096: 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)
			int stableHashCode = StringExtensionMethods.GetStableHashCode(id);
			ZoneSystem instance = ZoneSystem.instance;
			if (!instance.m_locationsByHash.TryGetValue(stableHashCode, out var value))
			{
				throw new InvalidOperationException("Location " + id + " not found.");
			}
			Vector2i zone = instance.GetZone(position);
			int num = ZDOMan.instance.SectorToIndex(zone);
			List<ZDO> list = ZDOMan.instance.m_objectsBySector[num];
			if (list != null)
			{
				foreach (ZDO item in list)
				{
					if (item.m_prefab == LocationProxyHash && item.GetInt(LocationHash, 0) == stableHashCode)
					{
						position = item.GetPosition();
						Print("Using position " + Helper.PrintVectorXZY(position) + " of already existing location.");
						break;
					}
				}
			}
			instance.m_locationInstances.Remove(zone);
			instance.RegisterLocation(value, position, instance.IsZoneGenerated(zone));
			AddPin(position);
			Print("Location " + id + " registered to " + Helper.PrintVectorXZY(position) + ".");
			Print("To actually spawn the registered locations, reset the zone or spawn them manually.");
		}
	}
	public class RemoveLocations : ExecutedOperation
	{
		private readonly HashSet<string> Ids;

		private readonly FiltererParameters Args;

		public RemoveLocations(Terminal context, IEnumerable<string> ids, FiltererParameters args)
			: base(context, args.Start)
		{
			Args = new FiltererParameters(args)
			{
				TargetZones = TargetZones.All
			};
			Ids = ids.ToHashSet();
		}

		protected override void OnStart()
		{
			if (Args.SafeZones != 0)
			{
				new PlayerBaseFilterer(Args.SafeZones).CalculateExcluded();
			}
		}

		private int RemoveSpawned()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0117: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			ZoneSystem instance = ZoneSystem.instance;
			IEnumerable<ZDO> zdos = ZDOMan.instance.m_objectsByID.Values.Where((ZDO zdo) => LocationProxyHash == zdo.m_prefab);
			zdos = Args.FilterZdos(zdos, checkExcludedZones: true);
			int num = 0;
			foreach (ZDO item in zdos)
			{
				if (!Args.Roll())
				{
					continue;
				}
				Vector2i zone = instance.GetZone(item.GetPosition());
				string text = "???";
				if (instance.m_locationsByHash.TryGetValue(item.GetInt(LocationHash, 0), out var value))
				{
					text = value.m_prefab.Name;
					if (Ids.Count > 0 && !Ids.Contains(text))
					{
						continue;
					}
					float distance = value.m_exteriorRadius;
					if (Args.ObjectReset.HasValue)
					{
						distance = Args.ObjectReset.Value;
					}
					AddPin(item.GetPosition());
					Helper.ClearZDOsWithinDistance(zone, item.GetPosition(), distance);
				}
				Helper.RemoveZDO(item);
				num++;
				instance.m_locationInstances.Remove(zone);
				if (Settings.Verbose)
				{
					Print($"Location {text} removed at {zone}.");
				}
			}
			foreach (KeyValuePair<Vector2i, LocationInstance> item2 in instance.m_locationInstances.Where((KeyValuePair<Vector2i, LocationInstance> kvp) => Args.FilterPosition(kvp.Value.m_position, checkExcludedZones: true)).ToList())
			{
				if (!Args.Roll())
				{
					continue;
				}
				Vector2i key = item2.Key;
				ZoneLocation location = item2.Value.m_location;
				string name = location.m_prefab.Name;
				if (Ids.Count <= 0 || Ids.Contains(name))
				{
					float distance2 = location.m_exteriorRadius;
					if (Args.ObjectReset.HasValue)
					{
						distance2 = Args.ObjectReset.Value;
					}
					Helper.ClearZDOsWithinDistance(key, item2.Value.m_position, distance2);
					AddPin(item2.Value.m_position);
					float radius = ((Args.TerrainReset == 0f) ? location.m_exteriorRadius : Args.TerrainReset);
					ResetTerrain.Execute(item2.Value.m_position, radius);
					num++;
					instance.m_locationInstances.Remove(key);
					if (Settings.Verbose)
					{
						Print($"Location {name} removed at {key}.");
					}
				}
			}
			return num;
		}

		private int RemoveNotSpawned()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			ZoneSystem instance = ZoneSystem.instance;
			List<IZoneFilterer> list = FiltererFactory.Create(Args);
			List<IZoneFilterer> list2 = new List<IZoneFilterer>();
			foreach (IZoneFilterer item in list)
			{
				list2.Add(item);
			}
			list2.Add(new LocationFilterer(Ids, OnlyMissing: false));
			List<string> messages = new List<string>();
			Vector2i[] array = list2.Aggregate(Zones.GetZones(TargetZones.All), (Vector2i[] zones, IZoneFilterer filterer) => filterer.FilterZones(zones, ref messages));
			int num = 0;
			Vector2i[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				Vector2i key = array2[i];
				if (Args.Roll() && instance.m_locationInstances.TryGetValue(key, out var value))
				{
					num++;
					AddPin(value.m_position);
					if (Settings.Verbose)
					{
						Print("Location " + value.m_location.m_prefab.Name + " removed at " + ((object)(Vector2i)(ref key)).ToString());
					}
					instance.m_locationInstances.Remove(key);
				}
			}
			return num;
		}

		protected override bool OnExecute()
		{
			int num = RemoveSpawned() + RemoveNotSpawned();
			Print($"Removed {num} locations.");
			return true;
		}

		protected override string OnInit()
		{
			return Args.Print("Remove locations" + Helper.LocationIdString(Ids) + " from");
		}
	}
	public class RegenerateLocations : LocationOperation
	{
		public RegenerateLocations(Terminal context, HashSet<string> ids, FiltererParameters args)
			: base(context, args)
		{
			Operation = "Reset locations";
			InitString = args.Print("Reset locations at");
			Verb = "reseted";
			List<IZoneFilterer> list = new List<IZoneFilterer>();
			foreach (IZoneFilterer filterer in Filterers)
			{
				list.Add(filterer);
			}
			list.Add(new LocationFilterer(ids, OnlyMissing: false));
			Filterers = list;
		}

		protected override bool ExecuteLocation(Vector2i zone, LocationInstance location)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			if (!location.m_placed)
			{
				return false;
			}
			location.m_placed = false;
			ZoneSystem.instance.m_locationInstances[zone] = location;
			ZoneLocation location2 = location.m_location;
			if (location2 != null)
			{
				_ = location2.m_prefab;
				if (0 == 0)
				{
					float clearRadius = location.m_location.m_exteriorRadius;
					if (Args.ObjectReset.HasValue)
					{
						clearRadius = Args.ObjectReset.Value;
					}
					SpawnLocation(zone, location, clearRadius);
					AddPin(location.m_position);
					if (Settings.Verbose)
					{
						Print("Location " + location.m_location.m_prefab.Name + " reseted at " + ((object)(Vector2i)(ref zone)).ToString());
					}
					return true;
				}
			}
			Print("Location " + (location.m_location?.m_prefab.Name ?? "???") + " is missing at " + ((object)(Vector2i)(ref zone)).ToString());
			return false;
		}
	}
	public class SpawnLocations : LocationOperation
	{
		private readonly HashSet<string> Ids;

		public SpawnLocations(Terminal context, HashSet<string> ids, FiltererParameters args)
			: base(context, args)
		{
			Operation = "Spawn missing locations";
			InitString = args.Print("Spawn missing locations to");
			Verb = "spawned to already generated areas";
			args.Chance = 1f;
			Ids = ids;
		}

		protected override void OnStart()
		{
			LocationFilterer locationFilterer = new LocationFilterer(Ids, OnlyMissing: true);
			List<string> messages = new List<string>();
			ZonesToUpgrade = locationFilterer.FilterZones(ZonesToUpgrade, ref messages);
		}

		protected override bool ExecuteLocation(Vector2i zone, LocationInstance location)
		{
			//IL_0000: 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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (location.m_placed)
			{
				return false;
			}
			ZoneLocation location2 = location.m_location;
			if (location2 != null)
			{
				_ = location2.m_prefab;
				if (0 == 0)
				{
					float clearRadius = (location.m_location.m_clearArea ? location.m_location.m_exteriorRadius : 0f);
					if (Args.ObjectReset.HasValue)
					{
						clearRadius = Args.ObjectReset.Value;
					}
					SpawnLocation(zone, location, clearRadius);
					AddPin(location.m_position);
					if (Settings.Verbose)
					{
						Print("Location " + location.m_location.m_prefab.Name + " spawned at " + ((object)(Vector2i)(ref zone)).ToString());
					}
					return true;
				}
			}
			Print("Location " + (location.m_location?.m_prefab.Name ?? "???") + " is missing at " + ((object)(Vector2i)(ref zone)).ToString());
			return false;
		}
	}
	public class SwapLocations : EntityOperation
	{
		public SwapLocations(Terminal context, IEnumerable<string> ids, DataParameters args)
			: base(context)
		{
			Swap(ids, args);
		}

		private void Swap(IEnumerable<string> ids, DataParameters args)
		{
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			int stableHashCode = StringExtensionMethods.GetStableHashCode(ids.FirstOrDefault());
			HashSet<int> prefabs = (from id in ids.Skip(1)
				select StringExtensionMethods.GetStableHashCode(id)).ToHashSet();
			int num = 0;
			ZDO[] array = (from zdo in EntityOperation.GetZDOs(args)
				where LocationProxyHash == zdo.m_prefab
				select zdo).ToArray();
			foreach (ZDO val in array)
			{
				if (args.Roll() && prefabs.Contains(val.GetInt(LocationHash, 0)))
				{
					num++;
					if (!val.IsOwner())
					{
						val.SetOwner(ZDOMan.GetSessionID());
					}
					val.Set(LocationHash, stableHashCode, false);
					AddPin(val.GetPosition());
					Refresh(val);
				}
			}
			Dictionary<Vector2i, LocationInstance> locationInstances = ZoneSystem.instance.m_locationInstances;
			ZoneLocation location = ZoneSystem.instance.m_locationsByHash[stableHashCode];
			KeyValuePair<Vector2i, LocationInstance>[] array2 = locationInstances.Where(delegate(KeyValuePair<Vector2i, LocationInstance> kvp)
			{
				//IL_0008: 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)
				HashSet<int> hashSet = prefabs;
				ZoneLocation location2 = kvp.Value.m_location;
				if (!hashSet.Contains((location2 != null) ? location2.Hash : 0))
				{
					HashSet<int> hashSet2 = prefabs;
					ZoneLocation location3 = kvp.Value.m_location;
					return hashSet2.Contains((location3 != null) ? StringExtensionMethods.GetStableHashCode(location3.m_prefab.Name) : 0);
				}
				return true;
			}).ToArray();
			KeyValuePair<Vector2i, LocationInstance>[] array3 = array2;
			for (int i = 0; i < array3.Length; i++)
			{
				KeyValuePair<Vector2i, LocationInstance> keyValuePair = array3[i];
				LocationInstance value = locationInstances[keyValuePair.Key];
				value.m_location = location;
				locationInstances[keyValuePair.Key] = value;
			}
			int num2 = array2.Length;
			Print($"Swapped {num} location objects and {num2} location entries.", addDot: false);
			PrintPins();
		}

		private static void Refresh(ZDO zdo)
		{
			if (ZNetScene.instance.m_instances.TryGetValue(zdo, out var value))
			{
				GameObject val = ZNetScene.instance.CreateObject(zdo);
				Object.Destroy((Object)(object)((Component)value).gameObject);
				ZNetScene.instance.m_instances[zdo] = val.GetComponent<ZNetView>();
			}
		}
	}
	public class CleanObjects : EntityOperation
	{
		public CleanObjects(Terminal context, FiltererParameters args)
			: base(context)
		{
			Clean(args);
		}

		private void Clean(FiltererParameters args)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Expected O, but got Unknown
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: 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_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			ZDO[] zDOs = EntityOperation.GetZDOs(args);
			ZNetScene instance = ZNetScene.instance;
			ZoneSystem instance2 = ZoneSystem.instance;
			List<Vector2i> list = (from x in instance2.m_locationInstances.Where(delegate(KeyValuePair<Vector2i, LocationInstance> x)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					ZoneLocation location = x.Value.m_location;
					return location == null || !location.m_prefab.IsValid;
				})
				select x.Key).ToList();
			foreach (Vector2i item in list)
			{
				instance2.m_locationInstances.Remove(item);
			}
			if (list.Count > 0)
			{
				Print($"Removed {list.Count} missing location entries.");
			}
			int num = 0;
			ZDO[] array = zDOs;
			foreach (ZDO val in array)
			{
				if (val.m_prefab == LocationProxyHash && instance2.GetLocation(val.GetInt(LocationHash, 0)) == null)
				{
					Helper.RemoveZDO(val);
					num++;
				}
			}
			if (num > 0)
			{
				Print($"Removed {num} missing location objects.");
			}
			num = 0;
			array = zDOs;
			foreach (ZDO val2 in array)
			{
				if (!instance.m_namedPrefabs.ContainsKey(val2.m_prefab))
				{
					Helper.RemoveZDO(val2);
					num++;
				}
			}
			if (num > 0)
			{
				Print($"Removed {num} missing objects.");
			}
			num = 0;
			array = zDOs;
			foreach (ZDO zdo in array)
			{
				if (Clean(zdo, ""))
				{
					num++;
				}
			}
			if (num > 0)
			{
				Print($"Removed {num} missing objects from item stands");
			}
			num = 0;
			array = zDOs;
			foreach (ZDO zdo2 in array)
			{
				if (Clean(zdo2, "0_"))
				{
					num++;
				}
				if (Clean(zdo2, "1_"))
				{
					num++;
				}
				if (Clean(zdo2, "2_"))
				{
					num++;
				}
				if (Clean(zdo2, "3_"))
				{
					num++;
				}
				if (Clean(zdo2, "4_"))
				{
					num++;
				}
				if (Clean(zdo2, "5_"))
				{
					num++;
				}
				if (Clean(zdo2, "6_"))
				{
					num++;
				}
				if (Clean(zdo2, "7_"))
				{
					num++;
				}
				if (Clean(zdo2, "8_"))
				{
					num++;
				}
				if (Clean(zdo2, "9_"))
				{
					num++;
				}
			}
			if (num > 0)
			{
				Print($"Removed {num} missing objects from armor stands");
			}
			num = 0;
			array = zDOs;
			foreach (ZDO val3 in array)
			{
				string @string = val3.GetString(ZDOVars.s_items, "");
				if (@string == "")
				{
					continue;
				}
				ZPackage from = new ZPackage(@string);
				ZPackage val4 = new ZPackage();
				int num2 = CleanChest(from, val4);
				if (num2 != 0)
				{
					num += num2;
					if (!val3.IsOwner())
					{
						val3.SetOwner(ZDOMan.GetSessionID());
					}
					val3.Set(ZDOVars.s_items, val4.GetBase64());
				}
			}
			if (num > 0)
			{
				Print($"Removed {num} missing objects from chests");
			}
			int stableHashCode = StringExtensionMethods.GetStableHashCode(((Object)instance2.m_zoneCtrlPrefab).name);
			int num3 = 0;
			int num4 = 0;
			array = zDOs;
			foreach (ZDO val5 in array)
			{
				if (val5.m_prefab != stableHashCode)
				{
					continue;
				}
				ZDOID uid = val5.m_uid;
				List<KeyValuePair<int, long>> longs = ZDOExtraData.GetLongs(uid);
				if (longs.Count >= 1)
				{
					num4 += longs.Count;
					if (!val5.IsOwner())
					{
						val5.SetOwner(ZDOMan.GetSessionID());
					}
					ZDOHelper.Release<long>(ZDOExtraData.s_longs, uid);
					val5.IncreaseDataRevision();
					num3++;
				}
			}
			if (num4 > 0)
			{
				Print($"Cleared {num4} spawn data from {num3} zone controls.");
			}
			int num5 = 0;
			array = zDOs;
			foreach (ZDO val6 in array)
			{
				if (val6.GetInt(ZDOVars.s_rooms, 0) != 0)
				{
					ZDOMan.instance.ConvertDungeonRooms(new List<ZDO> { val6 });
					Print("Optimized dungeon at " + Helper.PrintVectorXZY(val6.GetPosition()) + ".");
					num5++;
				}
			}
			if (num5 > 0)
			{
				Print($"Optimized {num5} dungeons.");
			}
			Print("World cleaned.");
		}

		private bool Clean(ZDO zdo, string prefix)
		{
			ZNetScene instance = ZNetScene.instance;
			string @string = zdo.GetString(prefix + "item", "");
			if (@string == "")
			{
				return false;
			}
			if (instance.m_namedPrefabs.ContainsKey(StringExtensionMethods.GetStableHashCode(@string)))
			{
				return false;
			}
			if (!zdo.IsOwner())
			{
				zdo.SetOwner(ZDOMan.GetSessionID());
			}
			zdo.Set(prefix + "item", "");
			zdo.Set(prefix + "variant", 0);
			if (prefix == "")
			{
				zdo.Set(prefix + "quality", 1);
			}
			return true;
		}

		private int CleanChest(ZPackage from, ZPackage to)
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			int num = from.ReadInt();
			if (num == 0)
			{
				return 0;
			}
			to.Write(num);
			int num2 = from.ReadInt();
			to.Write(num2);
			int num3 = 0;
			try
			{
				for (int i = 0; i < num2; i++)
				{
					string text = from.ReadString();
					if (ZNetScene.instance.m_namedPrefabs.ContainsKey(StringExtensionMethods.GetStableHashCode(text)))
					{
						to.Write(text);
						to.Write(from.ReadInt());
						to.Write(from.ReadSingle());
						to.Write(from.ReadVector2i());
						to.Write(from.ReadBool());
						if (num >= 101)
						{
							to.Write(from.ReadInt());
						}
						if (num >= 102)
						{
							to.Write(from.ReadInt());
						}
						if (num >= 103)
						{
							to.Write(from.ReadLong());
							to.Write(from.ReadString());
						}
						if (num >= 104)
						{
							int num4 = from.ReadInt();
							to.Write(num4);
							for (int j = 0; j < num4; j++)
							{
								to.Write(from.ReadString());
								to.Write(from.ReadString());
							}
						}
						if (num >= 105)
						{
							to.Write(from.ReadInt());
						}
						if (num >= 106)
						{
							to.Write(from.ReadBool());
						}
						continue;
					}
					num3++;
					from.ReadInt();
					from.ReadSingle();
					from.ReadVector2i();
					from.ReadBool();
					if (num >= 101)
					{
						from.ReadInt();
					}
					if (num >= 102)
					{
						from.ReadInt();
					}
					if (num >= 103)
					{
						from.ReadLong();
						from.ReadString();
					}
					if (num >= 104)
					{
						int num5 = from.ReadInt();
						for (int k = 0; k < num5; k++)
						{
							from.ReadString();
							from.ReadString();
						}
					}
					if (num >= 105)
					{
						from.ReadInt();
					}
					if (num >= 106)
					{
						from.ReadBool();
					}
				}
			}
			catch
			{
				num3 = num2;
			}
			if (num3 > 0)
			{
				to.SetPos(4);
				to.Write(num2 - num3);
			}
			return num3;
		}
	}
	public class CountObjects : EntityOperation
	{
		publi