Decompiled source of Mansion Build Property v1.1.1

Mods/WoodStudios.MansionBuild.dll

Decompiled 33 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using HarmonyLib;
using HoldTheFort;
using Il2Cpp;
using Il2CppFishNet;
using Il2CppFishNet.Connection;
using Il2CppFishNet.Managing.Server;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.AvatarFramework;
using Il2CppScheduleOne.AvatarFramework.Animation;
using Il2CppScheduleOne.Building;
using Il2CppScheduleOne.Core.Items.Framework;
using Il2CppScheduleOne.Delivery;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.EntityFramework;
using Il2CppScheduleOne.Instancing;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.Persistence.Datas;
using Il2CppScheduleOne.Persistence.Loaders;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Property;
using Il2CppScheduleOne.Tiles;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.Variables;
using Il2CppScheduleOne.Weather;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Il2CppTMPro;
using MansionBuild;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Lifecycle;
using S1API.Money;
using S2_MB.FybCommon;
using Schedule2;
using Schedule2.Game;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MansionCore), "Mansion Build Property", "1.1.1", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonOptionalDependencies(new string[] { "HoldTheFort" })]
[assembly: MelonAdditionalDependencies(new string[] { "WoodStudios.HouseBuilder" })]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Schedule2
{
	internal static class Prim
	{
		private static readonly Dictionary<PrimitiveType, Mesh> Meshes = new Dictionary<PrimitiveType, Mesh>();

		private static Mesh MeshOf(PrimitiveType t)
		{
			//IL_0005: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			if (Meshes.TryGetValue(t, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			GameObject obj = GameObject.CreatePrimitive(t);
			value = obj.GetComponent<MeshFilter>().sharedMesh;
			Object.DestroyImmediate((Object)(object)obj);
			Meshes[t] = value;
			return value;
		}

		internal unsafe static GameObject Part(Transform parent, PrimitiveType type, Vector3 pos, Vector3 scale, Material m, Vector3? euler, bool collider, string name)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			GameObject val;
			if (collider)
			{
				val = GameObject.CreatePrimitive(type);
			}
			else
			{
				val = new GameObject(((object)(*(PrimitiveType*)(&type))/*cast due to .constrained prefix*/).ToString());
				val.AddComponent<MeshFilter>().sharedMesh = MeshOf(type);
				val.AddComponent<MeshRenderer>();
			}
			Transform transform = val.transform;
			transform.SetParent(parent, false);
			transform.localPosition = pos;
			transform.localRotation = Quaternion.Euler((Vector3)(((??)euler) ?? Vector3.zero));
			transform.localScale = scale;
			((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = m;
			if (name != null)
			{
				((Object)val).name = name;
			}
			return val;
		}
	}
	internal static class S2Asm
	{
		internal static Type T(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type = null;
				try
				{
					type = assembly.GetType(name, throwOnError: false);
				}
				catch
				{
				}
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}

		internal static bool Is(Assembly a)
		{
			if (a == null)
			{
				return false;
			}
			try
			{
				string name = a.GetName().Name;
				return name == "HoldTheFort" || name == "WoodStudios.Schedule2";
			}
			catch
			{
				return false;
			}
		}
	}
	internal static class Perf
	{
		internal const bool On = false;

		internal static long Start()
		{
			return 0L;
		}

		internal static void Stop(string k, long t0)
		{
		}
	}
	internal static class FrameShare
	{
		private static int _frame = -1;

		private static Vector2 _mouse;

		private static bool _down;

		private static bool _legacyBroken;

		public static void Mouse(out Vector2 guiMouse, out bool leftDown)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008e: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//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)
			int frameCount = Time.frameCount;
			if (frameCount != _frame)
			{
				_frame = frameCount;
				Vector2 val = default(Vector2);
				bool flag = false;
				bool down = false;
				if (!_legacyBroken)
				{
					try
					{
						val = Vector2.op_Implicit(Input.mousePosition);
						down = Input.GetMouseButtonDown(0);
						flag = true;
					}
					catch
					{
						_legacyBroken = true;
					}
				}
				if (!flag)
				{
					try
					{
						Mouse current = Mouse.current;
						if (current != null)
						{
							val = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
							down = current.leftButton.wasPressedThisFrame;
						}
					}
					catch
					{
					}
				}
				_mouse = new Vector2(val.x, (float)Screen.height - val.y);
				_down = down;
			}
			guiMouse = _mouse;
			leftDown = _down;
		}
	}
	internal static class PlayerSnap
	{
		private static readonly List<Player> _l = new List<Player>();

		private static int _f = -1;

		public static List<Player> List()
		{
			if (_f == Time.frameCount)
			{
				return _l;
			}
			_f = Time.frameCount;
			_l.Clear();
			try
			{
				List<Player> playerList = Player.PlayerList;
				int num = playerList?.Count ?? 0;
				for (int i = 0; i < num; i++)
				{
					Player val = playerList[i];
					if ((Object)(object)val != (Object)null)
					{
						_l.Add(val);
					}
				}
			}
			catch
			{
			}
			return _l;
		}
	}
	internal static class CamSnap
	{
		private static int _f = -1;

		private static bool _ok;

		private static Vector3 _p;

		public static bool Pos(out Vector3 p)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (_f != Time.frameCount)
			{
				_f = Time.frameCount;
				_ok = false;
				try
				{
					PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
					Transform val = (((Object)(object)instance != (Object)null && (Object)(object)instance.Camera != (Object)null) ? ((Component)instance.Camera).transform : (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform : null));
					if ((Object)(object)val != (Object)null)
					{
						_p = val.position;
						_ok = true;
					}
				}
				catch
				{
				}
			}
			p = _p;
			return _ok;
		}
	}
	internal static class Npcs
	{
		internal sealed class Info
		{
			public IntPtr Key;

			public NPC Npc;

			private NPCMovement _move;

			private NavMeshAgent _agent;

			private Transform _agentTr;

			private bool _haveMove;

			private string _id;

			private bool _haveId;

			public NPCMovement Move
			{
				get
				{
					if (!_haveMove)
					{
						_haveMove = true;
						try
						{
							_move = Npc.Movement;
							_agent = (((Object)(object)_move != (Object)null) ? _move._agent : null);
							_agentTr = (((Object)(object)_agent != (Object)null) ? ((Component)_agent).transform : null);
						}
						catch
						{
						}
					}
					return _move;
				}
			}

			public NavMeshAgent Agent
			{
				get
				{
					_ = Move;
					return _agent;
				}
			}

			public Transform AgentTr
			{
				get
				{
					_ = Move;
					return _agentTr;
				}
			}

			public string Id
			{
				get
				{
					if (!_haveId)
					{
						_haveId = true;
						try
						{
							_id = Npc.ID ?? "";
						}
						catch
						{
							_id = "";
						}
					}
					return _id;
				}
			}
		}

		private static readonly List<Info> _list = new List<Info>();

		private static readonly Dictionary<IntPtr, Info> _byKey = new Dictionary<IntPtr, Info>();

		private static readonly HashSet<IntPtr> _seen = new HashSet<IntPtr>();

		private static float _at = -10f;

		private static int _count = -1;

		public static List<Info> All
		{
			get
			{
				float unscaledTime = Time.unscaledTime;
				if (unscaledTime - _at < 1f && unscaledTime >= _at)
				{
					return _list;
				}
				_at = unscaledTime;
				try
				{
					List<NPC> nPCRegistry = NPCManager.NPCRegistry;
					int num = nPCRegistry?.Count ?? 0;
					_list.Clear();
					_seen.Clear();
					for (int i = 0; i < num; i++)
					{
						NPC val = nPCRegistry[i];
						if (!((Object)(object)val == (Object)null))
						{
							IntPtr pointer = ((Il2CppObjectBase)val).Pointer;
							if (!_byKey.TryGetValue(pointer, out var value) || (Object)(object)value.Npc == (Object)null)
							{
								value = new Info
								{
									Key = pointer,
									Npc = val
								};
								_byKey[pointer] = value;
							}
							_list.Add(value);
							_seen.Add(pointer);
						}
					}
					if (_byKey.Count > _list.Count + 32)
					{
						List<IntPtr> list = new List<IntPtr>();
						foreach (IntPtr key in _byKey.Keys)
						{
							if (!_seen.Contains(key))
							{
								list.Add(key);
							}
						}
						foreach (IntPtr item in list)
						{
							_byKey.Remove(item);
						}
					}
					_count = num;
				}
				catch
				{
				}
				return _list;
			}
		}

		public static void Reset()
		{
			_list.Clear();
			_byKey.Clear();
			_at = -10f;
		}
	}
}
namespace Schedule2.Game
{
	internal static class PropKit
	{
		internal sealed class Spec
		{
			public string Code;

			public string Name;

			public Func<Transform> Frame;

			public Vector3 Centre;

			public float W;

			public float D;

			public float H = 3.2f;

			public bool AutoFloor;

			public Func<bool> Owned;

			public Property Prop;

			public string Why = "not made";

			public PropertyData Pending;

			public string PendingJson;

			public string PendingFile;

			public Il2CppReferenceArray<DynamicSaveData> SavedObjects;

			public float SavedObjectsAt;

			public Vector3? Dock;

			public float DockYaw;

			public GameObject DockObj;

			public int Employees;
		}

		internal const string Prefix = "ws_mb_";

		internal static readonly Dictionary<string, Spec> Specs = new Dictionary<string, Spec>();

		internal static bool DevAllOwned;

		private static GameObject _holder;

		private static float _next;

		internal static bool OurLoad;

		private static MethodInfo _hbRestore;

		private static bool _hbLooked;

		public static void SetEmployees(string code, int count)
		{
			if (!code.StartsWith("ws_mb_"))
			{
				code = "ws_mb_" + code;
			}
			if (Specs.TryGetValue(code, out var value))
			{
				value.Employees = Math.Max(0, count);
			}
		}

		public static void SetDock(string code, Vector3 local, float yaw)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (!code.StartsWith("ws_mb_"))
			{
				code = "ws_mb_" + code;
			}
			if (Specs.TryGetValue(code, out var value))
			{
				value.Dock = local;
				value.DockYaw = yaw;
			}
		}

		public static void Register(string code, string name, Func<Transform> frame, Vector3 centre, float w, float d, Func<bool> owned, float h = 3.2f, bool autoFloor = false)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			code = "ws_mb_" + code;
			if (!Specs.TryGetValue(code, out var value))
			{
				value = new Spec
				{
					Code = code
				};
				Specs[code] = value;
			}
			value.Name = name;
			value.Frame = frame;
			value.Centre = centre;
			value.W = w;
			value.D = d;
			value.Owned = owned;
			value.H = h;
			value.AutoFloor = autoFloor;
		}

		public static bool IsOurs(string code)
		{
			return code?.StartsWith("ws_mb_") ?? false;
		}

		public static bool IsOurs(Property p)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			try
			{
				return (Object)p != (Object)null && IsOurs(p.PropertyCode);
			}
			catch
			{
				return false;
			}
		}

		public static void Reset()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			PropKitLayers.Reset();
			foreach (Spec value in Specs.Values)
			{
				try
				{
					if ((Object)value.Prop != (Object)null)
					{
						Drop(value.Prop);
						Object.Destroy((Object)((Component)value.Prop).gameObject);
					}
					if ((Object)(object)value.DockObj != (Object)null)
					{
						Object.Destroy((Object)(object)value.DockObj);
					}
				}
				catch
				{
				}
				value.Prop = null;
				value.DockObj = null;
				value.Pending = null;
				value.PendingJson = null;
				value.Why = "not made";
			}
			Specs.Clear();
			if ((Object)_holder != (Object)null)
			{
				Object.Destroy((Object)_holder);
			}
			_holder = null;
		}

		public static void Tick()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			try
			{
				PropKitLayers.Tick();
			}
			catch
			{
			}
			if (Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 2f;
			PropKitSave.Hook();
			foreach (Spec value in Specs.Values)
			{
				try
				{
					bool flag = false;
					try
					{
						flag = DevAllOwned || (value.Owned != null && value.Owned());
					}
					catch
					{
					}
					if (!flag && value.Pending == null)
					{
						continue;
					}
					Transform val = null;
					try
					{
						val = value.Frame?.Invoke();
					}
					catch
					{
					}
					if ((Object)val == (Object)null)
					{
						continue;
					}
					if ((Object)value.Prop == (Object)null)
					{
						Make(value, val);
						if ((Object)value.Prop != (Object)null)
						{
							PropKitLayers.Restore(value);
							HbRestore(value.Prop);
						}
					}
					if ((Object)value.Prop == (Object)null)
					{
						continue;
					}
					if (value.Pending != null)
					{
						PropertyData pending = value.Pending;
						string pendingJson = value.PendingJson;
						value.Pending = null;
						value.PendingJson = null;
						OurLoad = true;
						try
						{
							Singleton<PropertyManager>.Instance.LoadProperty(pending, pendingJson);
							S2Game.L.Msg("Properties: " + value.Name + " loaded from the save.");
							if (pending.Objects != null && ((Il2CppArrayBase<DynamicSaveData>)(object)pending.Objects).Length > 0)
							{
								value.SavedObjects = pending.Objects;
								value.SavedObjectsAt = Time.unscaledTime + 1.5f;
							}
						}
						catch (Exception ex)
						{
							S2Game.L.Warning("Properties: " + value.Name + " load: " + (ex.InnerException ?? ex).Message.Split('\n')[0]);
						}
						finally
						{
							OurLoad = false;
						}
					}
					if (flag && !value.Prop.IsOwned)
					{
						SetOwned(value.Prop);
					}
					if (value.SavedObjects == null && Time.unscaledTime >= value.SavedObjectsAt + 1f)
					{
						PropKitStaff.Replay(value.Code);
					}
					if (value.SavedObjects == null || !(Time.unscaledTime >= value.SavedObjectsAt))
					{
						continue;
					}
					Il2CppReferenceArray<DynamicSaveData> savedObjects = value.SavedObjects;
					value.SavedObjects = null;
					int num = 0;
					try
					{
						num = value.Prop.BuildableItems.Count;
					}
					catch
					{
					}
					if (num != 0)
					{
						continue;
					}
					int num2 = 0;
					int num3 = 0;
					for (int i = 0; i < ((Il2CppArrayBase<DynamicSaveData>)(object)savedObjects).Length; i++)
					{
						DynamicSaveData val2 = ((Il2CppArrayBase<DynamicSaveData>)(object)savedObjects)[i];
						try
						{
							BuildableItemLoader val3 = ((val2 != null) ? Singleton<LoadManager>.Instance.GetObjectLoader(((SaveData)val2).DataType) : null);
							if (val3 == null)
							{
								num3++;
								continue;
							}
							val3.Load(val2);
							num2++;
						}
						catch (Exception ex2)
						{
							num3++;
							S2Game.L.Warning("Properties: " + value.Name + " object " + ((val2 != null) ? ((SaveData)val2).DataType : null) + ": " + (ex2.InnerException ?? ex2).Message.Split('\n')[0]);
						}
					}
					S2Game.L.Msg("Properties: " + value.Name + " brought back " + num2 + " saved object(s)" + ((num3 > 0) ? (", " + num3 + " failed") : "") + ".");
				}
				catch (Exception ex3)
				{
					S2Game.L.Warning("Properties: " + value.Name + ": " + ex3.Message);
				}
			}
		}

		private static void HbRestore(Property p)
		{
			try
			{
				if (!_hbLooked)
				{
					_hbLooked = true;
					Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
					foreach (Assembly assembly in assemblies)
					{
						if (!(assembly.GetName().Name != "WoodStudios.HouseBuilder"))
						{
							_hbRestore = assembly.GetType("HouseBuilder.FloorGrids", throwOnError: false)?.GetMethod("RestoreFor", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						}
					}
				}
				_hbRestore?.Invoke(null, new object[1] { p });
			}
			catch
			{
			}
		}

		private static Property Source()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			List<Property> properties = Property.Properties;
			Property val = null;
			int num = 0;
			while (properties != null && num < properties.Count)
			{
				Property val2 = properties[num];
				if (!((Object)val2 == (Object)null) && !IsOurs(val2))
				{
					string text = "";
					try
					{
						text = val2.PropertyCode ?? "";
					}
					catch
					{
					}
					if (text == "storageunit")
					{
						return val2;
					}
					if ((Object)val == (Object)null && text == "motelroom")
					{
						val = val2;
					}
				}
				num++;
			}
			return val;
		}

		private static Guid GuidFor(string s)
		{
			using MD5 mD = MD5.Create();
			return new Guid(mD.ComputeHash(Encoding.UTF8.GetBytes(s)));
		}

		private static void Make(Spec s, Transform frame)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Expected O, but got Unknown
			//IL_0831: Unknown result type (might be due to invalid IL or missing references)
			//IL_0833: Unknown result type (might be due to invalid IL or missing references)
			//IL_089a: Unknown result type (might be due to invalid IL or missing references)
			//IL_089f: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_093d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0967: Unknown result type (might be due to invalid IL or missing references)
			//IL_096c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0971: Unknown result type (might be due to invalid IL or missing references)
			//IL_0976: Unknown result type (might be due to invalid IL or missing references)
			//IL_097e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0980: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cff: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Expected O, but got Unknown
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Expected O, but got Unknown
			//IL_0f5d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Expected O, but got Unknown
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Expected O, but got Unknown
			//IL_0879: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ab4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abf: Expected O, but got Unknown
			//IL_0c6d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c78: Expected O, but got Unknown
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Expected O, but got Unknown
			//IL_09a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b4: Expected O, but got Unknown
			//IL_0ac3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad4: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Expected O, but got Unknown
			//IL_09c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a01: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a18: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a30: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a55: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b60: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b92: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b97: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b9c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ca5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb0: Expected O, but got Unknown
			//IL_0e13: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e1d: Expected O, but got Unknown
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0555: Expected O, but got Unknown
			//IL_0d99: Unknown result type (might be due to invalid IL or missing references)
			//IL_0daa: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Expected O, but got Unknown
			//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Expected O, but got Unknown
			//IL_064d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0652: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0801: Unknown result type (might be due to invalid IL or missing references)
			//IL_0806: Unknown result type (might be due to invalid IL or missing references)
			//IL_072e: Unknown result type (might be due to invalid IL or missing references)
			//IL_081c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0773: Unknown result type (might be due to invalid IL or missing references)
			//IL_0778: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0795: Unknown result type (might be due to invalid IL or missing references)
			//IL_079a: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ee: Unknown result type (might be due to invalid IL or missing references)
			Property val = Source();
			if ((Object)val == (Object)null)
			{
				s.Why = "the game's storage unit wasn't found";
				return;
			}
			if ((Object)_holder == (Object)null)
			{
				_holder = new GameObject("S2_PropKit_Holder");
				_holder.SetActive(false);
				Object.DontDestroyOnLoad((Object)_holder);
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, _holder.transform);
			((Object)val2).name = "S2_Prop_" + s.Code;
			Property component = val2.GetComponent<Property>();
			if ((Object)component == (Object)null)
			{
				Object.Destroy((Object)val2);
				s.Why = "no property on the copy";
				return;
			}
			component.propertyCode = s.Code;
			component.propertyName = s.Name;
			component.Price = 0f;
			component.OwnedByDefault = false;
			component.IsOwnedVariable = "S2_" + s.Code + "_Owned";
			try
			{
				VariableDatabase instance = NetworkSingleton<VariableDatabase>.Instance;
				if ((Object)(object)instance != (Object)null && instance.VariableDict != null && !instance.VariableDict.ContainsKey(component.IsOwnedVariable) && !instance.VariableDict.ContainsKey(component.IsOwnedVariable.ToLower()))
				{
					instance.CreateVariable(component.IsOwnedVariable, (EVariableType)0, "false", false, (EVariableMode)0, (Player)null, (EVariableReplicationMode)0);
				}
			}
			catch
			{
			}
			component._IsOwned_k__BackingField = false;
			component.EmployeeCapacity = s.Employees;
			component.ContentCullingEnabled = false;
			try
			{
				LoadingDock val3 = null;
				Il2CppReferenceArray<LoadingDock> loadingDocks = component.LoadingDocks;
				if (loadingDocks != null && ((Il2CppArrayBase<LoadingDock>)(object)loadingDocks).Length > 0)
				{
					val3 = ((Il2CppArrayBase<LoadingDock>)(object)loadingDocks)[0];
				}
				if (s.Dock.HasValue && (Object)(object)val3 != (Object)null)
				{
					GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, _holder.transform);
					((Object)val4).name = "S2_Dock_" + s.Code;
					LoadingDock component2 = val4.GetComponent<LoadingDock>();
					component2.BakedGUID = GuidFor(s.Code + ":dock").ToString();
					component2.ParentProperty = component;
					try
					{
						int num = 0;
						foreach (ParkingLot componentsInChild in val4.GetComponentsInChildren<ParkingLot>(true))
						{
							componentsInChild.BakedGUID = GuidFor(s.Code + ":lot:" + num++).ToString();
						}
					}
					catch
					{
					}
					s.DockObj = val4;
					component.LoadingDocks = new Il2CppReferenceArray<LoadingDock>((LoadingDock[])(object)new LoadingDock[1] { component2 });
				}
				else
				{
					component.LoadingDocks = new Il2CppReferenceArray<LoadingDock>(0L);
				}
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties: " + s.Name + " dock: " + ex.Message);
			}
			try
			{
				foreach (LoadingDock componentsInChild2 in val2.GetComponentsInChildren<LoadingDock>(true))
				{
					if ((Object)(object)componentsInChild2 != (Object)null && (Object)(object)((Component)componentsInChild2).gameObject != (Object)(object)val2)
					{
						Object.Destroy((Object)(object)((Component)componentsInChild2).gameObject);
					}
				}
			}
			catch
			{
			}
			foreach (BuildableItem componentsInChild3 in val2.GetComponentsInChildren<BuildableItem>(true))
			{
				if ((Object)componentsInChild3 != (Object)null)
				{
					Object.DestroyImmediate((Object)((Component)componentsInChild3).gameObject);
				}
			}
			try
			{
				if ((Object)component.ForSaleSign != (Object)null)
				{
					component.ForSaleSign.SetActive(false);
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)component.ListingPoster != (Object)null)
				{
					((Component)component.ListingPoster).gameObject.SetActive(false);
				}
			}
			catch
			{
			}
			Grid val5 = null;
			try
			{
				Il2CppArrayBase<Grid> componentsInChildren = val2.GetComponentsInChildren<Grid>(true);
				if (componentsInChildren != null && componentsInChildren.Length > 0)
				{
					val5 = componentsInChildren[0];
				}
			}
			catch
			{
			}
			if ((Object)val5 == (Object)null)
			{
				Object.Destroy((Object)val2);
				s.Why = "the storage unit has no grid";
				return;
			}
			HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
			foreach (Transform componentsInChild4 in ((Component)val5).GetComponentsInChildren<Transform>(true))
			{
				hashSet.Add(((Il2CppObjectBase)componentsInChild4).Pointer);
			}
			HashSet<IntPtr> hashSet2 = new HashSet<IntPtr>();
			try
			{
				foreach (BoxCollider item in (Il2CppArrayBase<BoxCollider>)(object)component.propertyBoundsColliders)
				{
					if ((Object)item != (Object)null)
					{
						hashSet2.Add(((Il2CppObjectBase)item).Pointer);
					}
				}
			}
			catch
			{
			}
			foreach (Renderer componentsInChild5 in val2.GetComponentsInChildren<Renderer>(true))
			{
				if ((Object)componentsInChild5 != (Object)null && !hashSet.Contains(((Il2CppObjectBase)((Component)componentsInChild5).transform).Pointer))
				{
					componentsInChild5.enabled = false;
				}
			}
			foreach (Collider componentsInChild6 in val2.GetComponentsInChildren<Collider>(true))
			{
				if ((Object)componentsInChild6 != (Object)null && !hashSet.Contains(((Il2CppObjectBase)((Component)componentsInChild6).transform).Pointer) && !hashSet2.Contains(((Il2CppObjectBase)componentsInChild6).Pointer))
				{
					componentsInChild6.enabled = false;
				}
			}
			foreach (Light componentsInChild7 in val2.GetComponentsInChildren<Light>(true))
			{
				if ((Object)componentsInChild7 != (Object)null)
				{
					((Behaviour)componentsInChild7).enabled = false;
				}
			}
			int num2 = 0;
			foreach (Grid componentsInChild8 in val2.GetComponentsInChildren<Grid>(true))
			{
				componentsInChild8._guid = GuidFor(s.Code + ":grid:" + num2++).ToString();
			}
			Quaternion rotation = frame.rotation;
			if (s.AutoFloor)
			{
				float num3 = float.MaxValue;
				(float, float)[] array = new(float, float)[5]
				{
					(0f, 0f),
					((0f - s.W) / 3f, (0f - s.D) / 3f),
					(s.W / 3f, (0f - s.D) / 3f),
					((0f - s.W) / 3f, s.D / 3f),
					(s.W / 3f, s.D / 3f)
				};
				RaycastHit val6 = default(RaycastHit);
				for (int i = 0; i < array.Length; i++)
				{
					var (num4, num5) = array[i];
					if (Physics.Raycast(frame.TransformPoint(new Vector3(s.Centre.x + num4, 2.4f, s.Centre.z + num5)), Vector3.down, ref val6, 4.5f, -1, (QueryTriggerInteraction)1))
					{
						float y = frame.InverseTransformPoint(((RaycastHit)(ref val6)).point).y;
						if (y < num3)
						{
							num3 = y;
						}
					}
				}
				if (num3 < float.MaxValue)
				{
					s.Centre = new Vector3(s.Centre.x, num3 + 0.01f, s.Centre.z);
				}
				s.AutoFloor = false;
			}
			Vector3 val7 = frame.TransformPoint(s.Centre);
			val2.transform.SetParent((Transform)null, false);
			try
			{
				SceneManager.MoveGameObjectToScene(val2, ((Component)val).gameObject.scene);
			}
			catch
			{
			}
			val2.transform.SetPositionAndRotation(val7, rotation);
			if ((Object)(object)s.DockObj != (Object)null && s.Dock.HasValue)
			{
				try
				{
					s.DockObj.transform.SetParent((Transform)null, false);
					try
					{
						SceneManager.MoveGameObjectToScene(s.DockObj, ((Component)val).gameObject.scene);
					}
					catch
					{
					}
					s.DockObj.transform.SetPositionAndRotation(frame.TransformPoint(s.Dock.Value), rotation * Quaternion.Euler(0f, s.DockYaw, 0f));
					s.DockObj.SetActive(true);
				}
				catch (Exception ex2)
				{
					S2Game.L.Warning("Properties: " + s.Name + " dock place: " + ex2.Message);
				}
			}
			int num6 = Mathf.Max(1, Mathf.FloorToInt((s.W - 0.1f) / 0.5f));
			int num7 = Mathf.Max(1, Mathf.FloorToInt((s.D - 0.1f) / 0.5f));
			Vector3 val8 = frame.TransformPoint(s.Centre + new Vector3((float)(-num6) * 0.25f + 0.25f, 0.01f, (float)(-num7) * 0.25f + 0.25f));
			((Component)val5).transform.SetPositionAndRotation(val8, rotation);
			try
			{
				foreach (BoxCollider item2 in (Il2CppArrayBase<BoxCollider>)(object)component.propertyBoundsColliders)
				{
					if (!((Object)item2 == (Object)null))
					{
						((Component)item2).transform.SetPositionAndRotation(val7, rotation);
						Vector3 lossyScale = ((Component)item2).transform.lossyScale;
						item2.center = new Vector3(0f, s.H * 0.5f / Mathf.Max(0.01f, lossyScale.y), 0f);
						item2.size = new Vector3(s.W / Mathf.Max(0.01f, lossyScale.x), s.H / Mathf.Max(0.01f, lossyScale.y), s.D / Mathf.Max(0.01f, lossyScale.z));
					}
				}
			}
			catch
			{
			}
			Transform[] array2 = (Transform[])(object)new Transform[3] { component.SpawnPoint, component.InteriorSpawnPoint, component.NPCSpawnPoint };
			foreach (Transform val9 in array2)
			{
				try
				{
					if ((Object)val9 != (Object)null)
					{
						val9.position = val7 + Vector3.up * 0.1f;
					}
				}
				catch
				{
				}
			}
			if (s.Employees > 0)
			{
				try
				{
					int num8 = Mathf.Max(4, s.Employees);
					Transform[] array3 = (Transform[])(object)new Transform[num8];
					for (int k = 0; k < num8; k++)
					{
						float num9 = (float)k * (float)Math.PI * 2f / (float)num8;
						Transform transform = new GameObject("S2_IdlePoint_" + k).transform;
						transform.SetParent(val2.transform, true);
						transform.position = frame.TransformPoint(s.Centre + new Vector3(Mathf.Cos(num9) * s.W * 0.3f, 0.1f, Mathf.Sin(num9) * s.D * 0.3f));
						transform.rotation = rotation;
						array3[k] = transform;
					}
					component.EmployeeIdlePoints = new Il2CppReferenceArray<Transform>(array3);
				}
				catch
				{
				}
			}
			Drop(null);
			s.Prop = component;
			val2.SetActive(true);
			try
			{
				if (!Property.Properties.Contains(component))
				{
					Property.Properties.Add(component);
				}
			}
			catch
			{
			}
			try
			{
				if (!Property.UnownedProperties.Contains(component))
				{
					Property.UnownedProperties.Add(component);
				}
			}
			catch
			{
			}
			try
			{
				if (!component.Grids.Contains(val5))
				{
					component.Grids.Add(val5);
				}
			}
			catch
			{
			}
			int num10 = 0;
			int num11 = 0;
			try
			{
				List<Tile> list = new List<Tile>();
				Enumerator<Tile> enumerator10 = val5.Tiles.GetEnumerator();
				while (enumerator10.MoveNext())
				{
					Tile current9 = enumerator10.Current;
					if ((Object)current9 != (Object)null)
					{
						list.Add(current9);
					}
				}
				Tile val10 = ((list.Count > 0) ? list[0] : null);
				if ((Object)val10 != (Object)null)
				{
					GameObject val11 = Object.Instantiate<GameObject>(((Component)val10).gameObject, _holder.transform);
					foreach (Tile item3 in list)
					{
						try
						{
							val5.DeregisterTile(item3);
						}
						catch
						{
						}
						Object.DestroyImmediate((Object)((Component)item3).gameObject);
						num11++;
					}
					for (int l = 0; l < num6; l++)
					{
						for (int m = 0; m < num7; m++)
						{
							GameObject val12 = Object.Instantiate<GameObject>(val11, ((Component)val5).transform);
							((Object)val12).name = "Tile (" + l + "," + m + ")";
							val12.transform.localPosition = new Vector3((float)l * 0.5f, 0f, (float)m * 0.5f);
							val12.transform.localRotation = Quaternion.identity;
							val12.SetActive(true);
							Tile component3 = val12.GetComponent<Tile>();
							component3.InitializePropertyTile(l, m, 0f, val5);
							if (!val5.Tiles.Contains(component3))
							{
								val5.RegisterTile(component3);
							}
							num10++;
						}
					}
					Object.Destroy((Object)val11);
					val5.SetGridSize();
					try
					{
						val5._coordinateToTile?.Clear();
					}
					catch
					{
					}
					val5.ProcessCoordinateDataPairs();
				}
			}
			catch (Exception ex3)
			{
				S2Game.L.Warning("Properties: " + s.Name + " grid: " + (ex3.InnerException ?? ex3).Message.Split('\n')[0]);
			}
			Spawn(val2, s.Code);
			s.Why = "made (" + num10 + " tiles, " + num6 + "x" + num7 + ", grid " + val5.Width + "x" + val5.Height + ", " + num11 + " old tiles out)";
			S2Game.L.Msg("Properties: " + s.Name + " " + s.Why + " at " + Southgate.Fmt(val7) + ".");
		}

		private static void Spawn(GameObject go, string code)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				NetworkObject component = go.GetComponent<NetworkObject>();
				if (!((Object)component == (Object)null) && !component.IsSpawned)
				{
					component._SceneId_k__BackingField = (ulong)(0x5333000000000000L | (code.GetHashCode() & 0x7FFFFFFF));
					ServerManager serverManager = InstanceFinder.ServerManager;
					if (!((Object)serverManager == (Object)null) && InstanceFinder.IsServer)
					{
						serverManager.Spawn(component, (NetworkConnection)null, default(Scene));
					}
				}
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties network: " + (ex.InnerException ?? ex).Message.Split('\n')[0]);
			}
		}

		internal static void SetOwned(Property p)
		{
			try
			{
				p.RecieveOwned();
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties owned: " + ex.Message);
			}
			try
			{
				if (!Property.OwnedProperties.Contains(p))
				{
					Property.OwnedProperties.Add(p);
				}
				Property.UnownedProperties.Remove(p);
			}
			catch
			{
			}
		}

		private static void Drop(Property keep)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			List<Property>[] array = new List<Property>[3]
			{
				Property.Properties,
				Property.OwnedProperties,
				Property.UnownedProperties
			};
			foreach (List<Property> val in array)
			{
				try
				{
					for (int num = val.Count - 1; num >= 0; num--)
					{
						Property val2 = val[num];
						bool flag = (Object)val2 == (Object)null;
						bool flag2 = false;
						try
						{
							if (!flag && IsOurs(val2.PropertyCode))
							{
								flag2 = true;
								foreach (Spec value in Specs.Values)
								{
									if ((Object)value.Prop != (Object)null && ((Il2CppObjectBase)value.Prop).Pointer == ((Il2CppObjectBase)val2).Pointer)
									{
										flag2 = false;
									}
								}
								if ((Object)keep != (Object)null && ((Il2CppObjectBase)keep).Pointer == ((Il2CppObjectBase)val2).Pointer)
								{
									flag2 = false;
								}
							}
						}
						catch
						{
							flag = true;
						}
						if (flag || flag2)
						{
							val.RemoveAt(num);
						}
					}
				}
				catch
				{
				}
			}
		}

		internal static Spec Find(string code)
		{
			if (code == null || !Specs.TryGetValue(code, out var value))
			{
				return null;
			}
			return value;
		}

		public static string DevState()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Spec value2 in Specs.Values)
			{
				bool value = false;
				try
				{
					value = value2.Owned();
				}
				catch
				{
				}
				stringBuilder.Append(value2.Code).Append(" '").Append(value2.Name)
					.Append("' owned ")
					.Append(value)
					.Append(" frame ")
					.Append((Object)(value2.Frame?.Invoke()) != (Object)null)
					.Append(" | ")
					.Append(value2.Why);
				if ((Object)value2.Prop != (Object)null)
				{
					try
					{
						Grid val = value2.Prop.Grids[0];
						StringBuilder stringBuilder2 = stringBuilder.Append(" | grid ").Append(val.Width).Append('x')
							.Append(val.Height)
							.Append(" tiles ")
							.Append(val.Tiles.Count)
							.Append(" propOwned ")
							.Append(value2.Prop.IsOwned)
							.Append(" items ")
							.Append(value2.Prop.BuildableItems.Count)
							.Append(" at ");
						Vector3 position = ((Component)val).transform.position;
						stringBuilder2.Append(((Vector3)(ref position)).ToString("F1"));
					}
					catch
					{
					}
				}
				stringBuilder.Append(" || ");
			}
			return stringBuilder.ToString();
		}

		public static string DevPlace(string code, string id, int x, int y)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00dd: 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_012b: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			Property val = (Find("ws_mb_" + code) ?? Find(code))?.Prop;
			if ((Object)val == (Object)null)
			{
				List<Property> properties = Property.Properties;
				int num = 0;
				while (properties != null && num < properties.Count)
				{
					if ((Object)properties[num] != (Object)null && properties[num].PropertyCode == code)
					{
						val = properties[num];
					}
					num++;
				}
			}
			if ((Object)val == (Object)null)
			{
				return "no property " + code;
			}
			try
			{
				ItemDefinition item = Registry.GetItem(id);
				if ((Object)item == (Object)null)
				{
					return "no item " + id;
				}
				GridItem val2 = NetworkSingleton<BuildManager>.Instance.CreateGridItem(item.GetDefaultInstance(1), val.Grids[0], new Vector2((float)x, (float)y), 0, Guid.NewGuid().ToString(), Action<GridItem>.op_Implicit((Action<GridItem>)null));
				string[] obj = new string[8] { "placed ", id, " -> ", null, null, null, null, null };
				object obj2;
				if (!((Object)val2 != (Object)null))
				{
					obj2 = "null";
				}
				else
				{
					string name = ((Object)val2).name;
					Vector3 position = ((Component)val2).transform.position;
					obj2 = name + " at " + ((Vector3)(ref position)).ToString("F1");
				}
				obj[3] = (string)obj2;
				obj[4] = " | items ";
				obj[5] = val.BuildableItems.Count.ToString();
				obj[6] = " | spawned ";
				NetworkObject component = ((Component)val).GetComponent<NetworkObject>();
				obj[7] = ((Object)(object)component != (Object)null && component.IsSpawned).ToString();
				return string.Concat(obj);
			}
			catch (Exception ex)
			{
				return "place failed: " + (ex.InnerException ?? ex).Message.Split('\n')[0];
			}
		}

		public static string DevGo(string code)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			Spec spec = Find("ws_mb_" + code) ?? Find(code);
			if (spec == null)
			{
				return "no " + code;
			}
			Transform val = spec.Frame?.Invoke();
			if ((Object)val == (Object)null)
			{
				return "no frame";
			}
			Vector3 at = val.TransformPoint(spec.Centre) + Vector3.up * 0.3f;
			Me.Teleport(at);
			return "at " + ((Vector3)(ref at)).ToString("F1");
		}
	}
	[HarmonyPatch(typeof(PropertyManager), "LoadProperty")]
	internal static class PropKitHold
	{
		private static bool Prefix(PropertyData propertyData, ref string propertyDataString)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			try
			{
				if (propertyData != null)
				{
					_ = propertyData.PropertyCode;
				}
				if (PropKit.OurLoad || propertyData == null || !PropKit.IsOurs(propertyData.PropertyCode))
				{
					return true;
				}
				PropKit.Spec spec = PropKit.Find(propertyData.PropertyCode);
				if ((Object)(spec?.Prop) != (Object)null)
				{
					return true;
				}
				if (spec == null)
				{
					spec = new PropKit.Spec
					{
						Code = propertyData.PropertyCode,
						Name = propertyData.PropertyCode
					};
					PropKit.Specs[spec.Code] = spec;
				}
				spec.Pending = propertyData;
				spec.PendingJson = propertyDataString;
				try
				{
					spec.PendingFile = PropKitSave.FindFile(propertyData.PropertyCode);
				}
				catch
				{
				}
				S2Game.L.Msg("Properties: " + propertyData.PropertyCode + " waits for its home to be built before loading.");
				return false;
			}
			catch
			{
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(Property), "Load")]
	internal static class PropKitLoaded
	{
		private static void Postfix(Property __instance, PropertyData propertyData)
		{
			try
			{
				if (PropKit.IsOurs(__instance) && propertyData != null && propertyData.IsOwned && !__instance.IsOwned)
				{
					PropKit.SetOwned(__instance);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(PropertyManager), "GetProperty")]
	internal static class PropKitLookup
	{
		private static bool Prefix(string code, ref Property __result)
		{
			if (!PropKit.IsOurs(code))
			{
				return true;
			}
			__result = PropKit.Find(code)?.Prop;
			return false;
		}
	}
	internal static class PropKitLayers
	{
		private sealed class Layer
		{
			public Grid G;

			public int Key;

			public readonly Dictionary<long, Tile> Tiles = new Dictionary<long, Tile>();
		}

		private const float Half = 0.5f;

		private const string FileName = "S2_GridLayers.json";

		private static readonly Dictionary<string, Dictionary<int, Layer>> Layers = new Dictionary<string, Dictionary<int, Layer>>();

		private static Dictionary<string, Dictionary<string, List<string>>> _saved;

		private static GameObject _holder;

		private static GameObject _emptyGrid;

		private static GameObject _tile;

		private static int _seenVersion = int.MinValue;

		private static float _next;

		private static bool _dirty;

		private static float _writeAt;

		private static float _forceAt;

		private static float _resetAt;

		private static bool _forcedOnce;

		private static int _htf = -1;

		private static FieldInfo _verF;

		private static PropertyInfo _allP;

		private static Type _plT;

		private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static int _fakeVer;

		private const string FloorId = "htf_house_floor";

		private const string FoundationId = "htf_house_foundation";

		private static long K(int j, int k)
		{
			return ((long)j << 32) | (uint)k;
		}

		private static Guid GuidFor(string s)
		{
			using MD5 mD = MD5.Create();
			return new Guid(mD.ComputeHash(Encoding.UTF8.GetBytes(s)));
		}

		private static string SaveFile()
		{
			string text = null;
			try
			{
				text = Singleton<LoadManager>.Instance.LoadedGameFolderPath;
			}
			catch
			{
			}
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			string text2 = text.TrimEnd('/', '\\');
			StringBuilder stringBuilder = new StringBuilder();
			string fileName = Path.GetFileName(text2);
			foreach (char c in fileName)
			{
				stringBuilder.Append((char.IsLetterOrDigit(c) || c == '_' || c == '-') ? c : '_');
			}
			uint num = 2166136261u;
			fileName = text2.ToLowerInvariant().Replace('\\', '/');
			foreach (char c2 in fileName)
			{
				num ^= c2;
				num *= 16777619;
			}
			string path = "Schedule2";
			try
			{
				path = typeof(PropKitLayers).Assembly.GetName().Name.Replace("WoodStudios.", "");
			}
			catch
			{
			}
			string text3 = Path.Combine(MelonEnvironment.UserDataDirectory, "WoodStudiosLayers", path);
			Directory.CreateDirectory(text3);
			return Path.Combine(text3, stringBuilder?.ToString() + "_" + num.ToString("x8") + ".json");
		}

		private static string OldSaveFile()
		{
			string text = null;
			try
			{
				text = Singleton<LoadManager>.Instance.LoadedGameFolderPath;
			}
			catch
			{
			}
			if (!string.IsNullOrEmpty(text))
			{
				return Path.Combine(text, "S2_GridLayers.json");
			}
			return null;
		}

		internal static void Reset()
		{
			_forceAt = 0f;
			_forcedOnce = false;
			_resetAt = Time.unscaledTime;
			Layers.Clear();
			_saved = null;
			_seenVersion = int.MinValue;
			_dirty = false;
			if ((Object)(object)_holder != (Object)null)
			{
				Object.Destroy((Object)(object)_holder);
			}
			_holder = (_emptyGrid = (_tile = null));
		}

		internal static void Restore(PropKit.Spec s)
		{
			try
			{
				if (_saved == null)
				{
					_saved = new Dictionary<string, Dictionary<string, List<string>>>();
					string text = SaveFile();
					if (text == null || !File.Exists(text))
					{
						text = OldSaveFile();
					}
					if (text != null && File.Exists(text))
					{
						_saved = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, List<string>>>>(File.ReadAllText(text)) ?? _saved;
					}
				}
				if (!_saved.TryGetValue(s.Code, out var value))
				{
					return;
				}
				int num = 0;
				foreach (KeyValuePair<string, List<string>> item in value)
				{
					if (!int.TryParse(item.Key, out var result))
					{
						continue;
					}
					HashSet<long> hashSet = new HashSet<long>();
					foreach (string item2 in item.Value)
					{
						string[] array = item2.Split(',');
						if (array.Length == 2 && int.TryParse(array[0], out var result2) && int.TryParse(array[1], out var result3))
						{
							hashSet.Add(K(result2, result3));
						}
					}
					Layer layer = Get(s, result, make: true);
					if (layer != null)
					{
						Sync(layer, hashSet, save: false);
						num++;
					}
				}
				if (num > 0)
				{
					S2Game.L.Msg("Properties: " + s.Name + " upper floor placement: " + num + " layer(s) back from the save.");
				}
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties: " + s.Name + " layers restore: " + ex.Message);
			}
		}

		private static bool HtfHere()
		{
			if (_htf < 0)
			{
				_htf = 0;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					if (assembly.GetName().Name == "HoldTheFort" || assembly.GetType("HoldTheFort.Placement", throwOnError: false) != null)
					{
						_htf = 1;
						break;
					}
				}
			}
			return _htf == 1;
		}

		private static bool Refl()
		{
			if (_plT != null)
			{
				return true;
			}
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type type = assemblies[i].GetType("HoldTheFort.Placement", throwOnError: false);
				if (type != null)
				{
					_plT = type;
					break;
				}
			}
			if (_plT == null)
			{
				return false;
			}
			_verF = _plT.GetField("Version", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			_allP = _plT.GetProperty("All", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			return true;
		}

		private static int HtfVersion()
		{
			if (!Refl())
			{
				return 0;
			}
			if (_verF != null)
			{
				return (int)_verF.GetValue(null);
			}
			return ++_fakeVer / 3;
		}

		private static bool HtfGuest()
		{
			try
			{
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					PropertyInfo propertyInfo = assemblies[i].GetType("HoldTheFort.FortifyApi", throwOnError: false)?.GetProperty("IsGuest", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (propertyInfo != null)
					{
						return (bool)propertyInfo.GetValue(null);
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static IEnumerable<(string id, GameObject go)> HtfPieces()
		{
			List<(string, GameObject)> list = new List<(string, GameObject)>();
			if (!Refl() || _allP == null)
			{
				return list;
			}
			if (!(_allP.GetValue(null) is IEnumerable enumerable))
			{
				return list;
			}
			foreach (object item2 in enumerable)
			{
				if (item2 != null)
				{
					Type type = item2.GetType();
					object? obj = type.GetField("Go", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(item2);
					GameObject val = (GameObject)((obj is GameObject) ? obj : null);
					object obj2 = type.GetField("Spec", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(item2);
					if (!((Object)(object)val == (Object)null) && obj2 != null)
					{
						Type type2 = obj2.GetType();
						string item = (type2.GetField("Id", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj2) ?? type2.GetProperty("Id", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj2)) as string;
						list.Add((item, val));
					}
				}
			}
			return list;
		}

		internal static void Tick()
		{
			if (_dirty && Time.unscaledTime >= _writeAt)
			{
				Write();
			}
			if (Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 1f;
			if (!HtfHere())
			{
				return;
			}
			int num;
			try
			{
				num = HtfVersion();
			}
			catch
			{
				return;
			}
			bool flag = false;
			if (Time.unscaledTime >= _forceAt && Time.unscaledTime - _resetAt > 20f)
			{
				flag = !_forcedOnce || HtfGuest();
				_forcedOnce = true;
				_forceAt = Time.unscaledTime + 15f;
			}
			if (num == _seenVersion && !flag)
			{
				return;
			}
			_seenVersion = num;
			foreach (PropKit.Spec value in PropKit.Specs.Values)
			{
				if (!((Object)(object)value.Prop == (Object)null))
				{
					try
					{
						Rebuild(value);
					}
					catch (Exception ex)
					{
						S2Game.L.Warning("Properties: " + value.Name + " layers: " + ex.Message);
					}
				}
			}
		}

		private static Grid Base(PropKit.Spec s)
		{
			try
			{
				return ((Object)(object)s.Prop != (Object)null && s.Prop.Grids.Count > 0) ? s.Prop.Grids[0] : null;
			}
			catch
			{
				return null;
			}
		}

		private static void Rebuild(PropKit.Spec s)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00ac: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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)
			//IL_00db: 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_0106: 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_017a: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			Grid val = Base(s);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			int width = val.Width;
			int height = val.Height;
			Transform transform = ((Component)val).transform;
			float num = transform.position.y - 0.01f;
			Dictionary<int, HashSet<long>> dictionary = new Dictionary<int, HashSet<long>>();
			Dictionary<int, List<Transform>> dictionary2 = new Dictionary<int, List<Transform>>();
			foreach (var (text, val2) in HtfPieces())
			{
				if ((Object)(object)val2 == (Object)null || (text != "htf_house_floor" && text != "htf_house_foundation"))
				{
					continue;
				}
				Transform transform2 = val2.transform;
				Vector3 position = transform2.position;
				if (position.y - num < 0.25f)
				{
					continue;
				}
				Vector3 val3 = transform.InverseTransformPoint(position);
				if (val3.x < -2f || val3.z < -2f || val3.x > (float)width * 0.5f + 2f || val3.z > (float)height * 0.5f + 2f)
				{
					continue;
				}
				int key = Mathf.RoundToInt(position.y * 20f);
				if (!dictionary.TryGetValue(key, out var value))
				{
					value = (dictionary[key] = new HashSet<long>());
				}
				if (!dictionary2.TryGetValue(key, out var value2))
				{
					value2 = (dictionary2[key] = new List<Transform>());
				}
				value2.Add(transform2);
				int num2 = Mathf.Max(0, Mathf.FloorToInt((val3.x - 1.5f) / 0.5f));
				int num3 = Mathf.Min(width - 1, Mathf.CeilToInt((val3.x + 1.5f) / 0.5f));
				int num4 = Mathf.Max(0, Mathf.FloorToInt((val3.z - 1.5f) / 0.5f));
				int num5 = Mathf.Min(height - 1, Mathf.CeilToInt((val3.z + 1.5f) / 0.5f));
				for (int i = num2; i <= num3; i++)
				{
					for (int j = num4; j <= num5; j++)
					{
						Vector3 val4 = transform.TransformPoint(new Vector3((float)i * 0.5f, 0f, (float)j * 0.5f));
						Vector3 val5 = transform2.InverseTransformPoint(new Vector3(val4.x, position.y, val4.z));
						if (Mathf.Abs(val5.x) <= 1.01f && Mathf.Abs(val5.z) <= 1.01f)
						{
							value.Add(K(i, j));
						}
					}
				}
			}
			foreach (KeyValuePair<int, HashSet<long>> item in dictionary)
			{
				List<Transform> list2 = dictionary2[item.Key];
				HashSet<long> hashSet2 = new HashSet<long>();
				foreach (long item2 in item.Value)
				{
					int num6 = (int)(item2 >> 32);
					int num7 = (int)item2;
					bool flag = true;
					for (int k = -1; k <= 1 && flag; k += 2)
					{
						for (int l = -1; l <= 1 && flag; l += 2)
						{
							Vector3 val6 = transform.TransformPoint(new Vector3((float)num6 * 0.5f + (float)k * 0.24f, 0f, (float)num7 * 0.5f + (float)l * 0.24f));
							bool flag2 = false;
							foreach (Transform item3 in list2)
							{
								Vector3 val7 = item3.InverseTransformPoint(new Vector3(val6.x, item3.position.y, val6.z));
								if (Mathf.Abs(val7.x) <= 1.02f && Mathf.Abs(val7.z) <= 1.02f)
								{
									flag2 = true;
									break;
								}
							}
							flag = flag2;
						}
					}
					if (flag)
					{
						hashSet2.Add(item2);
					}
				}
				item.Value.Clear();
				item.Value.UnionWith(hashSet2);
			}
			Layers.TryGetValue(s.Code, out var value3);
			foreach (KeyValuePair<int, HashSet<long>> item4 in dictionary)
			{
				Layer layer = Get(s, item4.Key, make: true);
				if (layer != null)
				{
					Sync(layer, item4.Value, save: true);
				}
			}
			if (value3 != null)
			{
				foreach (KeyValuePair<int, Layer> item5 in value3)
				{
					if (!dictionary.ContainsKey(item5.Key))
					{
						Sync(item5.Value, new HashSet<long>(), save: true);
					}
				}
			}
			Bounds(s);
		}

		private static Layer Get(PropKit.Spec s, int key, bool make)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			if (!Layers.TryGetValue(s.Code, out var value))
			{
				value = (Layers[s.Code] = new Dictionary<int, Layer>());
			}
			if (value.TryGetValue(key, out var value2) && (Object)(object)value2.G != (Object)null)
			{
				return value2;
			}
			if (!make)
			{
				return null;
			}
			Grid val = Base(s);
			if ((Object)(object)val == (Object)null || !Templates(val))
			{
				return null;
			}
			string text = GuidFor(s.Code + ":layer:" + key).ToString();
			try
			{
				_emptyGrid.GetComponent<Grid>()._guid = text;
			}
			catch
			{
			}
			GameObject obj2 = Object.Instantiate<GameObject>(_emptyGrid, ((Component)val).transform.parent);
			((Object)obj2).name = "S2_FloorLayer_" + key;
			Vector3 position = ((Component)val).transform.position;
			position.y = (float)key / 20f + 0.01f;
			obj2.transform.SetPositionAndRotation(position, ((Component)val).transform.rotation);
			obj2.SetActive(true);
			Grid component = obj2.GetComponent<Grid>();
			try
			{
				Guid val2 = default(Guid);
				((Guid)(ref val2))..ctor(text);
				if ((Object)(object)GUIDManager.GetObject<Grid>(val2) != (Object)(object)component)
				{
					component.SetGUID(val2);
				}
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties: layer id: " + ex.Message);
			}
			try
			{
				if (!s.Prop.Grids.Contains(component))
				{
					s.Prop.Grids.Add(component);
				}
			}
			catch
			{
			}
			Layer obj4 = new Layer
			{
				G = component,
				Key = key
			};
			return value[key] = obj4;
		}

		private static bool Templates(Grid g0)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if ((Object)(object)_emptyGrid != (Object)null && (Object)(object)_tile != (Object)null)
			{
				return true;
			}
			if ((Object)(object)_holder == (Object)null)
			{
				_holder = new GameObject("S2_FloorLayer_Holder");
				_holder.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)_holder);
			}
			Tile val = null;
			try
			{
				Enumerator<Tile> enumerator = g0.Tiles.GetEnumerator();
				while (enumerator.MoveNext())
				{
					if ((Object)(object)enumerator.Current != (Object)null)
					{
						val = enumerator.Current;
						break;
					}
				}
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			_tile = Object.Instantiate<GameObject>(((Component)val).gameObject, _holder.transform);
			_emptyGrid = Object.Instantiate<GameObject>(((Component)g0).gameObject, _holder.transform);
			List<GameObject> list = new List<GameObject>();
			foreach (Tile componentsInChild in _emptyGrid.GetComponentsInChildren<Tile>(true))
			{
				list.Add(((Component)componentsInChild).gameObject);
			}
			foreach (GameObject item in list)
			{
				Object.DestroyImmediate((Object)(object)item);
			}
			Grid component = _emptyGrid.GetComponent<Grid>();
			try
			{
				component._guid = GuidFor("s2_floorlayer_template").ToString();
			}
			catch
			{
			}
			try
			{
				component.Tiles.Clear();
			}
			catch
			{
			}
			try
			{
				component.CoordinateTilePairs.Clear();
			}
			catch
			{
			}
			try
			{
				component._coordinateToTile?.Clear();
			}
			catch
			{
			}
			return true;
		}

		private static void Sync(Layer l, HashSet<long> want, bool save)
		{
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Expected O, but got Unknown
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			List<long> list = new List<long>();
			foreach (KeyValuePair<long, Tile> tile in l.Tiles)
			{
				if (!want.Contains(tile.Key))
				{
					int num = 0;
					try
					{
						num = (((Object)(object)tile.Value != (Object)null) ? tile.Value.BuildableOccupants.Count : 0);
					}
					catch
					{
					}
					if (num == 0)
					{
						list.Add(tile.Key);
					}
				}
			}
			foreach (long item in list)
			{
				Tile val = l.Tiles[item];
				l.Tiles.Remove(item);
				try
				{
					if ((Object)(object)val != (Object)null)
					{
						l.G.DeregisterTile(val);
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
				catch
				{
				}
				flag = true;
			}
			foreach (long item2 in want)
			{
				if (!l.Tiles.ContainsKey(item2))
				{
					int num2 = (int)(item2 >> 32);
					int num3 = (int)item2;
					GameObject val2 = Object.Instantiate<GameObject>(_tile, ((Component)l.G).transform);
					((Object)val2).name = "Tile (" + num2 + "," + num3 + ")";
					val2.transform.localPosition = new Vector3((float)num2 * 0.5f, 0f, (float)num3 * 0.5f);
					val2.transform.localRotation = Quaternion.identity;
					val2.SetActive(true);
					Tile component = val2.GetComponent<Tile>();
					component.InitializePropertyTile(num2, num3, 0f, l.G);
					if (!l.G.Tiles.Contains(component))
					{
						l.G.RegisterTile(component);
					}
					l.Tiles[item2] = component;
					flag = true;
				}
			}
			if (!flag)
			{
				return;
			}
			Vector2Int val3 = Base(l.G);
			try
			{
				l.G._Width_k__BackingField = ((Vector2Int)(ref val3)).x;
				l.G._Height_k__BackingField = ((Vector2Int)(ref val3)).y;
			}
			catch
			{
			}
			try
			{
				l.G.CoordinateTilePairs.Clear();
				foreach (KeyValuePair<long, Tile> tile2 in l.Tiles)
				{
					if (!((Object)(object)tile2.Value == (Object)null))
					{
						CoordinateTilePair val4 = new CoordinateTilePair();
						val4.coord = new Coordinate((int)(tile2.Key >> 32), (int)tile2.Key);
						val4.tile = tile2.Value;
						l.G.CoordinateTilePairs.Add(val4);
					}
				}
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties: layer tiles: " + ex.Message);
			}
			try
			{
				l.G._coordinateToTile?.Clear();
			}
			catch
			{
			}
			try
			{
				l.G.ProcessCoordinateDataPairs();
			}
			catch (Exception ex2)
			{
				S2Game.L.Warning("Properties: layer lookup: " + ex2.Message);
			}
			if (save)
			{
				_dirty = true;
				_writeAt = Time.unscaledTime + 2f;
			}
		}

		private static Vector2Int Base(Grid layer)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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)
			foreach (PropKit.Spec value2 in PropKit.Specs.Values)
			{
				Grid val = Base(value2);
				if (!((Object)(object)val != (Object)null) || !Layers.TryGetValue(value2.Code, out var value))
				{
					continue;
				}
				foreach (Layer value3 in value.Values)
				{
					if ((Object)(object)value3.G == (Object)(object)layer)
					{
						return new Vector2Int(val.Width, val.Height);
					}
				}
			}
			return new Vector2Int(layer.Width, layer.Height);
		}

		private static void Bounds(PropKit.Spec s)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			if (!Layers.TryGetValue(s.Code, out var value) || value.Count == 0)
			{
				return;
			}
			Grid val = Base(s);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			float num = float.MinValue;
			foreach (Layer value2 in value.Values)
			{
				if (value2.Tiles.Count > 0)
				{
					num = Mathf.Max(num, (float)value2.Key / 20f);
				}
			}
			if (num == float.MinValue)
			{
				return;
			}
			float num2 = num - ((Component)val).transform.position.y + 3.5f;
			if (num2 <= s.H)
			{
				return;
			}
			s.H = num2;
			try
			{
				foreach (BoxCollider item in (Il2CppArrayBase<BoxCollider>)(object)s.Prop.propertyBoundsColliders)
				{
					if (!((Object)(object)item == (Object)null))
					{
						Vector3 lossyScale = ((Component)item).transform.lossyScale;
						item.center = new Vector3(item.center.x, s.H * 0.5f / Mathf.Max(0.01f, lossyScale.y), item.center.z);
						item.size = new Vector3(item.size.x, s.H / Mathf.Max(0.01f, lossyScale.y), item.size.z);
					}
				}
			}
			catch
			{
			}
		}

		private static void Write()
		{
			_dirty = false;
			string text = SaveFile();
			if (text == null)
			{
				return;
			}
			try
			{
				Dictionary<string, Dictionary<string, List<string>>> dictionary = new Dictionary<string, Dictionary<string, List<string>>>();
				if (_saved != null)
				{
					foreach (KeyValuePair<string, Dictionary<string, List<string>>> item in _saved)
					{
						dictionary[item.Key] = item.Value;
					}
				}
				foreach (KeyValuePair<string, Dictionary<int, Layer>> layer in Layers)
				{
					Dictionary<string, List<string>> dictionary2 = new Dictionary<string, List<string>>();
					foreach (Layer value in layer.Value.Values)
					{
						if (value.Tiles.Count == 0)
						{
							continue;
						}
						List<string> list = new List<string>(value.Tiles.Count);
						foreach (long key in value.Tiles.Keys)
						{
							list.Add((int)(key >> 32) + "," + (int)key);
						}
						dictionary2[value.Key.ToString()] = list;
					}
					dictionary[layer.Key] = dictionary2;
				}
				File.WriteAllText(text, JsonSerializer.Serialize(dictionary));
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties: layers write: " + ex.Message);
			}
		}

		internal static string DevPlace(string code, string id)
		{
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			if (!code.StartsWith("ws_mb_"))
			{
				code = "ws_mb_" + code;
			}
			if (!Layers.TryGetValue(code, out var value) || value.Count == 0)
			{
				return "no layers on " + code;
			}
			Layer layer = null;
			foreach (Layer value2 in value.Values)
			{
				if (value2.Tiles.Count > 0 && (layer == null || value2.Key > layer.Key))
				{
					layer = value2;
				}
			}
			if (layer == null)
			{
				return "empty layers";
			}
			long num = 0L;
			long num2 = 0L;
			foreach (long key in layer.Tiles.Keys)
			{
				num += (int)(key >> 32);
				num2 += (int)key;
			}
			int num3 = (int)(num / layer.Tiles.Count);
			int num4 = (int)(num2 / layer.Tiles.Count);
			long num5 = 0L;
			int num6 = int.MaxValue;
			foreach (long key2 in layer.Tiles.Keys)
			{
				int num7 = Math.Abs((int)(key2 >> 32) - num3) + Math.Abs((int)key2 - num4);
				if (num7 < num6)
				{
					num6 = num7;
					num5 = key2;
				}
			}
			ItemDefinition item = Registry.GetItem(id);
			if ((Object)(object)item == (Object)null)
			{
				return "no item " + id;
			}
			GridItem val = NetworkSingleton<BuildManager>.Instance.CreateGridItem(item.GetDefaultInstance(1), layer.G, new Vector2((float)(int)(num5 >> 32), (float)(int)num5), 0, Guid.NewGuid().ToString(), (Action<GridItem>)null);
			string[] obj = new string[10]
			{
				"placed ",
				id,
				" on layer y ",
				((float)layer.Key / 20f).ToString("F2"),
				" tile ",
				((int)(num5 >> 32)).ToString(),
				",",
				((int)num5).ToString(),
				" -> ",
				null
			};
			object obj2;
			if (!((Object)(object)val != (Object)null))
			{
				obj2 = "null";
			}
			else
			{
				Vector3 position = ((Component)val).transform.position;
				obj2 = ((Vector3)(ref position)).ToString("F2");
			}
			obj[9] = (string)obj2;
			return string.Concat(obj);
		}

		internal static string Info()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<string, Dictionary<int, Layer>> layer in Layers)
			{
				foreach (Layer value in layer.Value.Values)
				{
					stringBuilder.Append(layer.Key).Append(" y ").Append(((float)value.Key / 20f).ToString("F2"))
						.Append(" tiles ")
						.Append(value.Tiles.Count)
						.Append("; ");
				}
			}
			if (stringBuilder.Length != 0)
			{
				return stringBuilder.ToString();
			}
			return "no layers";
		}
	}
	[HarmonyPatch]
	internal static class PropKitStaff
	{
		private static bool _replaying;

		private static readonly List<(EmployeeLoader loader, DynamicSaveData data, string code)> Held = new List<(EmployeeLoader, DynamicSaveData, string)>();

		private static IEnumerable<MethodBase> TargetMethods()
		{
			Type[] array = new Type[4]
			{
				typeof(BotanistLoader),
				typeof(ChemistLoader),
				typeof(CleanerLoader),
				typeof(PackagerLoader)
			};
			foreach (Type type in array)
			{
				MethodBase methodBase = null;
				try
				{
					methodBase = AccessTools.Method(type, "Load", new Type[1] { typeof(DynamicSaveData) }, (Type[])null);
				}
				catch
				{
				}
				if (methodBase != null)
				{
					yield return methodBase;
				}
			}
		}

		private static bool Prefix(Object __instance, DynamicSaveData saveData)
		{
			if (_replaying || saveData == null)
			{
				return true;
			}
			try
			{
				string baseData = saveData.BaseData;
				if (string.IsNullOrEmpty(baseData))
				{
					return true;
				}
				int num = baseData.IndexOf("\"AssignedProperty\"", StringComparison.Ordinal);
				if (num < 0)
				{
					return true;
				}
				int num2 = baseData.IndexOf(':', num);
				int num3 = baseData.IndexOf('"', num2 + 1);
				int num4 = ((num3 >= 0) ? baseData.IndexOf('"', num3 + 1) : (-1));
				if (num3 < 0 || num4 < 0)
				{
					return true;
				}
				string text = baseData.Substring(num3 + 1, num4 - num3 - 1);
				if (!PropKit.IsOurs(text))
				{
					return true;
				}
				PropKit.Spec spec = PropKit.Find(text);
				if (spec != null && (Object)(object)spec.Prop != (Object)null)
				{
					return true;
				}
				EmployeeLoader val = ((Il2CppObjectBase)__instance).TryCast<EmployeeLoader>();
				if (val == null)
				{
					return true;
				}
				Held.Add((val, saveData, text));
				S2Game.L.Msg("Properties: an employee of " + text + " waits for the property before loading.");
				return false;
			}
			catch
			{
				return true;
			}
		}

		internal static void Replay(string code)
		{
			if (Held.Count == 0)
			{
				return;
			}
			for (int num = Held.Count - 1; num >= 0; num--)
			{
				(EmployeeLoader, DynamicSaveData, string) tuple = Held[num];
				if (string.Equals(tuple.Item3, code, StringComparison.OrdinalIgnoreCase))
				{
					Held.RemoveAt(num);
					_replaying = true;
					try
					{
						((DynamicLoader)tuple.Item1).Load(tuple.Item2);
						S2Game.L.Msg("Properties: employee loaded for " + code + ".");
					}
					catch (Exception ex)
					{
						S2Game.L.Warning("Properties: employee for " + code + ": " + (ex.InnerException ?? ex).Message.Split('\n')[0]);
					}
					finally
					{
						_replaying = false;
					}
				}
			}
		}

		internal static void Reset()
		{
			Held.Clear();
		}
	}
	[HarmonyPatch(typeof(PropertyManager), "WriteData")]
	internal static class PropKitSaveWrite
	{
		private static void Postfix(string parentFolderPath)
		{
			PropKitSave.Keep(parentFolderPath);
		}
	}
	[HarmonyPatch(typeof(PropertyManager), "DeleteUnapprovedFiles")]
	internal static class PropKitSaveDelete
	{
		private static void Postfix(string parentFolderPath)
		{
			PropKitSave.Keep(parentFolderPath);
		}
	}
	internal static class PropKitSave
	{
		private static SaveManager _hooked;

		internal static string FindFile(string code)
		{
			try
			{
				string loadedGameFolderPath = Singleton<LoadManager>.Instance.LoadedGameFolderPath;
				if (string.IsNullOrEmpty(loadedGameFolderPath))
				{
					return null;
				}
				loadedGameFolderPath = Path.Combine(loadedGameFolderPath, "Properties");
				if (!Directory.Exists(loadedGameFolderPath))
				{
					return null;
				}
				Regex regex = new Regex("\"PropertyCode\"\\s*:\\s*\"" + Regex.Escape(code) + "\"");
				string[] files = Directory.GetFiles(loadedGameFolderPath, "*.json");
				foreach (string path in files)
				{
					try
					{
						if (regex.IsMatch(File.ReadAllText(path)))
						{
							return Path.GetFileName(path);
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return null;
		}

		internal static void Hook()
		{
			//IL_0019: 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_002d: Expected O, but got Unknown
			//IL_002d: Expected O, but got Unknown
			try
			{
				if (Singleton<SaveManager>.InstanceExists)
				{
					SaveManager instance = Singleton<SaveManager>.Instance;
					if (!((Object)(object)instance == (Object)null) && !((Object)instance == (Object)_hooked))
					{
						_hooked = instance;
						instance.onSaveComplete.AddListener(DelegateSupport.ConvertDelegate<UnityAction>((Delegate)new Action(AfterSave)));
					}
				}
			}
			catch (Exception ex)
			{
				S2Game.L.Warning("Properties: save hook: " + ex.Message);
			}
		}

		private static void AfterSave()
		{
			try
			{
				string loadedGameFolderPath = Singleton<LoadManager>.Instance.LoadedGameFolderPath;
				if (!string.IsNullOrEmpty(loadedGameFolderPath))
				{
					Keep(loadedGameFolderPath);
				}
			}
			catch
			{
			}
		}

		internal static void Keep(string parentFolderPath)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			if (string.IsNullOrEmpty(parentFolderPath))
			{
				return;
			}
			try
			{
				string text = (string.Equals(Path.GetFileName(parentFolderPath.TrimEnd('/', '\\')), "Properties", StringComparison.OrdinalIgnoreCase) ? parentFolderPath : Path.Combine(parentFolderPath, "Properties"));
				foreach (PropKit.Spec value in PropKit.Specs.Values)
				{
					if (value == null || string.IsNullOrEmpty(value.PendingJson) || (Object)value.Prop != (Object)null)
					{
						continue;
					}
					string text2 = value.PendingFile;
					if (string.IsNullOrEmpty(text2))
					{
						string text3 = value.Name ?? value.Code;
						char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
						foreach (char oldChar in invalidFileNameChars)
						{
							text3 = text3.Replace(oldChar, '_');
						}
						text2 = text3 + ".json";
					}
					try
					{
						Directory.CreateDirectory(text);
						string path = Path.Combine(text, text2);
						if (!File.Exists(path) || File.ReadAllText(path) != value.PendingJson)
						{
							File.WriteAllText(path, value.PendingJson);
						}
					}
					catch (Exception ex)
					{
						S2Game.L.Warning("Properties: keeping " + value.Code + " in the save: " + ex.Message);
					}
				}
			}
			catch
			{
			}
		}

		public static string DevTest(string dir)
		{
			StringBuilder stringBuilder = new StringBuilder();
			PropKit.Spec spec = new PropKit.Spec
			{
				Code = "s2_devtest_lot",
				Name = "Dev Test Lot",
				PendingJson = "{\"PropertyCode\": \"s2_devtest_lot\", \"IsOwned\": true}",
				PendingFile = "Dev Test Lot.json"
			};
			PropKit.Specs[spec.Code] = spec;
			try
			{
				Directory.CreateDirectory(dir);
				string text = Path.Combine(dir, "Properties");
				Directory.CreateDirectory(text);
				File.WriteAllText(Path.Combine(text, "Junk.json"), "{}");
				PropertyManager instance = Singleton<PropertyManager>.Instance;
				instance.WriteData(dir);
				stringBuilder.Append("after write: ").Append(string.Join(",", Array.ConvertAll(Directory.GetFiles(text), Path.GetFileName))).Append(" | ");
				instance.DeleteUnapprovedFiles(dir);
				stringBuilder.Append("after delete: ").Append(string.Join(",", Array.ConvertAll(Directory.GetFiles(text), Path.GetFileName)));
			}
			catch (Exception ex)
			{
				stringBuilder.Append(" err ").Append(ex.Message);
			}
			finally
			{
				PropKit.Specs.Remove(spec.Code);
			}
			return stringBuilder.ToString();
		}
	}
	internal static class S2Game
	{
		internal static Instance L => MansionCore.Log;
	}
	internal static class Southgate
	{
		internal static string Fmt(Vector3 v)
		{
			return "(" + v.x.ToString("0") + ", " + v.y.ToString("0.0") + ", " + v.z.ToString("0") + ")";
		}
	}
	internal static class RoadMarks
	{
		internal static void Kick()
		{
		}
	}
	internal static class Me
	{
		public static void Teleport(Vector3 at)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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)
			try
			{
				Player local = Player.Local;
				if (!((Object)(object)local == (Object)null))
				{
					PlayerMovement instance = PlayerSingleton<PlayerMovement>.Instance;
					if ((Object)(object)instance != (Object)null)
					{
						instance.Teleport(at, ((Component)local).transform.rotation, true);
					}
					else
					{
						((Component)local).transform.position = at;
					}
				}
			}
			catch
			{
			}
		}
	}
}
namespace MansionBuild
{
	internal static class Lot
	{
		public const float Price = 75000f;

		public const string Code = "mb_lot";

		private const string DataKey = "MansionBuildOwned";

		private const float MainX0 = -12f;

		private const float MainX1 = 18f;

		private const float MainZ0 = 138f;

		private const float MainZ1 = 170f;

		private const float LinkX0 = -2f;

		private const float LinkX1 = 18f;

		private static float LinkZ0 = 114f;

		private const float Seabed = -11f;

		public static GameObject Root;

		public static float TopY = -3.85f;

		public static bool Owned;

		public static bool Built;

		private static Vector3 _sign;

		private static TextMeshPro _signText;

		private static GameObject _signGo;

		private static string _hint;

		private static bool _area;

		private static bool _told;

		private static float _nextBuyHint;

		private const float DriveZ = 167.5f;

		private const float DriveHalf = 1.75f;

		private const float DriveStreetX = -36f;

		private const float RampX0 = -21f;

		private const float RampX1 = -10.5f;

		private static readonly List<GameObject> _hidden = new List<GameObject>();

		private static NavMeshDataInstance _navInst;

		private static bool _navOn;

		private static readonly List<NavMeshLinkInstance> _navLinks = new List<NavMeshLinkInstance>();

		private static readonly List<Renderer> _rOff = new List<Renderer>();

		private static readonly List<Renderer> _rOn = new List<Renderer>();

		public static Vector3 PadCentre => new Vector3(10.5f, TopY, LinkZ0 + 8f);

		private static float Bank
		{
			get
			{
				try
				{
					return Money.GetOnlineBalance();
				}
				catch
				{
					return 0f;
				}
			}
		}

		private static float Cash
		{
			get
			{
				try
				{
					return Money.GetCashBalance();
				}
				catch
				{
					return 0f;
				}
			}
		}

		private static Type FindType(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type type = null;
				try
				{
					type = assembly.GetType(name, throwOnError: false);
				}
				catch
				{
				}
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}

		public static bool InLot(Vector3 p)
		{
			//IL_0009: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if (!Built)
			{
				return false;
			}
			if (p.y < TopY - 1.5f || p.y > TopY + 40f)
			{
				return false;
			}
			bool num = p.x >= -12f && p.x <= 18f && p.z >= 138f && p.z <= 170f;
			bool flag = p.x >= -2f && p.x <= 18f && p.z >= LinkZ0 && p.z <= 138f;
			return num || flag;
		}

		private static void ClearTrees()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			float num = 3f;
			float num2 = 154f;
			float num3 = 7.5f;
			float num4 = 8f;
			float radius = Mathf.Sqrt(num3 * num3 + num4 * num4) + 0.5f;
			int num5 = 0;
			float[] array = new float[2] { -1f, 1f };
			foreach (float num6 in array)
			{
				float[] array2 = new float[2] { -1f, 1f };
				foreach (float num7 in array2)
				{
					try
					{
						FortifyApi.AddTreeClearing("mb_lot_" + num5++, new Vector3(num + num6 * num3, TopY, num2 + num7 * num4), radius);
					}
					catch
					{
					}
				}
			}
			float num8 = 8f;
			float num9 = (138f - LinkZ0) * 0.25f;
			float radius2 = Mathf.Sqrt(10f * 10f + num9 * num9) + 0.5f;
			array = new float[2] { 1f, 3f };
			foreach (float num10 in array)
			{
				try
				{
					FortifyApi.AddTreeClearing("mb_lot_" + num5++, new Vector3(num8, TopY, LinkZ0 + num10 * num9), radius2);
				}
				catch
				{
				}
			}
		}

		public static void Build()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: 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_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			Reset();
			try
			{
				Measure();
				Root = new GameObject("MansionBuildProperty");
				Root.transform.position = new Vector3(3f, TopY, 154f);
				Transform transform = Root.transform;
				Material m = FortifyApi.Mat("mb_wall", new Color(0.4f, 0.39f, 0.37f), 0f, 0.1f);
				Material m2 = FortifyApi.Mat("mb_lawn", new Color(0.2f, 0.31f, 0.15f), 0f, 0.05f);
				Material m3 = FortifyApi.Mat("mb_slab", new Color(0.45f, 0.45f, 0.43f), 0f, 0.1f);
				Material m4 = FortifyApi.Mat("mb_pad", new Color(0.24f, 0.25f, 0.27f), 0f, 0.15f);
				Material m5 = FortifyApi.Mat("mb_paint", new Color(0.95f, 0.78f, 0.15f));
				FortifyApi.Mat("mb_rail", new Color(0.18f, 0.19f, 0.2f), 0.6f, 0.4f);
				ClearTrees();
				try
				{
					Driveway(transform);
				}
				catch (Exception ex)
				{
					Instance log = MansionCore.Log;
					if (log != null)
					{
						log.Warning("Mansion: driveway skipped (" + ex.Message + ").");
					}
				}
				float num = TopY - -11f;
				Box(transform, "Main", -11.94f, 17.94f, 138.06f, 169.94f, TopY - num, TopY, m, collider: true);
				Box(transform, "Link", -1.94f, 17.94f, LinkZ0 + 0.06f, 138.3f, TopY - num, TopY - 0.004f, m, collider: true);
				Box(transform, "Lawn", -11.6f, 17.6f, 138.4f, 169.6f, TopY, TopY + 0.02f, m2, collider: false);
				Box(transform, "Paving", -1.6f, 17.6f, LinkZ0 + 0.4f, 138.4f, TopY, TopY + 0.02f, m3, collider: false);
				Vector3 padCentre = PadCentre;
				Box(transform, "Pad", padCentre.x - 5.5f, padCentre.x + 5.5f, padCentre.z - 5.5f, padCentre.z + 5.5f, TopY + 0.02f, TopY + 0.035f, m4, collider: false);
				Box(transform, "PadLineW", padCentre.x - 5.5f, padCentre.x - 5.2f, padCentre.z - 5.5f, padCentre.z + 5.5f, TopY + 0.035f, TopY + 0.045f, m5, collider: false);
				Box(transform, "PadLineE", padCentre.x + 5.2f, padCentre.x + 5.5f, padCentre.z - 5.5f, padCentre.z + 5.5f, TopY + 0.035f, TopY + 0.045f, m5, collider: false);
				Box(transform, "PadLineS", padCentre.x - 5.5f, padCentre.x + 5.5f, padCentre.z - 5.5f, padCentre.z - 5.2f, TopY + 0.035f, TopY + 0.045f, m5, collider: false);
				Box(transform, "PadLineN", padCentre.x - 5.5f, padCentre.x + 5.5f, padCentre.z + 5.2f, padCentre.z + 5.5f, TopY + 0.035f, TopY + 0.045f, m5, collider: false);
				PadText(transform, padCentre);
				Material m6 = FortifyApi.Mat("mb_walk", new Color(0.47f, 0.47f, 0.45f), 0f, 0.05f);
				Box(transform, "WalkW", -12f, -10.5f, 138f, 170f, TopY + 0.021f, TopY + 0.03f, m6, collider: false);
				Box(transform, "WalkN", -12f, 18f, 168.5f, 170f, TopY + 0.021f, TopY + 0.03f, m6, collider: false);
				Box(transform, "WalkE", 16.5f, 18f, LinkZ0, 170f, TopY + 0.021f, TopY + 0.03f, m6, collider: false);
				Box(transform, "WalkS", -2f, 18f, LinkZ0, LinkZ0 + 1.5f, TopY + 0.021f, TopY + 0.03f, m6, collider: false);
				Box(transform, "WalkLinkW", -2f, -0.5f, LinkZ0, 139.5f, TopY + 0.021f, TopY + 0.03f, m6, collider: false);
				Box(transform, "WalkMainS", -12f, -0.5f, 138f, 139.5f, TopY + 0.021f, TopY + 0.03f, m6, collider: false);
				MakeSign(transform);
				Built = true;
				PropKit.Register("mb_lot", "Mansion Build Property", () => (!((Object)(object)Root != (Object)null)) ? null : Root.transform, new Vector3(0f, 0.03f, 0f), 29f, 31f, () => Owned, 12f);
				PropKit.Register("mb_lot_yard", "Mansion Build Property (South Yard)", () => (!((Object)(object)Root != (Object)null)) ? null : Root.transform, new Vector3(5f, 0.03f, (LinkZ0 + 138f) * 0.5f - 154f), 19f, 138f - LinkZ0 + 1f, () => Owned, 12f);
				Vector3 local = Root.transform.InverseTransformPoint(padCentre + Vector3.up * 0.04f);
				PropKit.SetDock("mb_lot", local, 0f);
				PropKit.SetEmployees("mb_lot", 6);
				try
				{
					NavTop(transform);
				}
				catch (Exception ex2)
				{
					Instance log2 = MansionCore.Log;
					if (log2 != null)
					{
						log2.Warning("Mansion: walk surface skipped (" + ex2.Message + ").");
					}
				}
				MansionCore.Log.Msg($"Mansion Build Property: lot built (top {TopY:0.00}, link from z {LinkZ0:0.0}), {(Owned ? "owned" : "for sale")}.");
			}
			catch (Exception ex3)
			{
				MansionCore.Log.Warning("Mansion Build Property: build failed: " + ex3);
			}
		}

		private static void Measure()
		{
			//IL