Decompiled source of Ultimate Builder v1.6.1

DigiCreative.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DigiShared;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: AssemblyCompany("DigiCreative")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DigiCreative")]
[assembly: AssemblyTitle("DigiCreative")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 DigiShared
{
	internal static class Buildings
	{
		internal static Bounds BoundsOf(Piece piece)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(((Component)piece).transform.position, Vector3.zero);
			Collider[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if (val.enabled && !val.isTrigger)
				{
					((Bounds)(ref result)).Encapsulate(val.bounds);
				}
			}
			return result;
		}

		internal static IEnumerable<Piece> Connected(Piece start, List<Piece> found, int max = 20000)
		{
			HashSet<Piece> seen = new HashSet<Piece> { start };
			found.Add(start);
			Collider[] hits = (Collider[])(object)new Collider[128];
			int mask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" });
			for (int i = 0; i < found.Count; i++)
			{
				if (found.Count >= max)
				{
					break;
				}
				Piece val = found[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Bounds val2 = BoundsOf(val);
				int num = Physics.OverlapBoxNonAlloc(((Bounds)(ref val2)).center, ((Bounds)(ref val2)).extents + Vector3.one * 0.1f, hits, Quaternion.identity, mask);
				for (int j = 0; j < num; j++)
				{
					Piece val3 = (((Object)(object)hits[j] != (Object)null) ? ((Component)hits[j]).GetComponentInParent<Piece>() : null);
					if ((Object)(object)val3 != (Object)null && val3.IsPlacedByPlayer() && seen.Add(val3))
					{
						found.Add(val3);
					}
				}
				yield return val;
			}
		}
	}
	internal sealed class IconSheet
	{
		private const int Cell = 128;

		private const int Columns = 4;

		private readonly Assembly _assembly;

		private readonly string _resource;

		private readonly Action<string> _warn;

		private Texture2D _sheet;

		private readonly Dictionary<string, int[]> _cells = new Dictionary<string, int[]>();

		private bool _loaded;

		private static readonly MethodInfo LoadImage = Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule")?.GetMethod("LoadImage", new Type[2]
		{
			typeof(Texture2D),
			typeof(byte[])
		});

		internal static bool LoadPng(Texture2D texture, byte[] png)
		{
			bool flag = default(bool);
			int num;
			if (LoadImage != null)
			{
				object obj = LoadImage.Invoke(null, new object[2] { texture, png });
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		internal IconSheet(Assembly assembly, string resource, Action<string> warn)
		{
			_assembly = assembly;
			_resource = resource;
			_warn = warn;
		}

		private void Init()
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			if (_loaded)
			{
				return;
			}
			_loaded = true;
			try
			{
				byte[] png;
				using (Stream stream = _assembly.GetManifestResourceStream(_resource + ".png"))
				{
					using MemoryStream memoryStream = new MemoryStream();
					if (stream == null)
					{
						return;
					}
					stream.CopyTo(memoryStream);
					png = memoryStream.ToArray();
				}
				string text;
				using (Stream stream2 = _assembly.GetManifestResourceStream(_resource + ".txt"))
				{
					if (stream2 == null)
					{
						return;
					}
					using StreamReader streamReader = new StreamReader(stream2);
					text = streamReader.ReadToEnd();
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!LoadPng(val, png))
				{
					return;
				}
				_sheet = val;
				int num = 0;
				string[] array = text.Split(new char[1] { '\n' });
				for (int i = 0; i < array.Length; i++)
				{
					string[] array2 = array[i].Trim().Split(new char[1] { ' ' });
					if (array2.Length >= 4)
					{
						_cells[array2[0]] = new int[4]
						{
							num++,
							int.Parse(array2[1]),
							int.Parse(array2[2]),
							int.Parse(array2[3])
						};
					}
				}
			}
			catch (Exception ex)
			{
				_warn?.Invoke("Tool icons not loaded: " + ex.Message);
			}
		}

		internal Sprite For(string id, Sprite under)
		{
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			Init();
			if ((Object)(object)_sheet == (Object)null || !_cells.TryGetValue(id, out var value))
			{
				return null;
			}
			try
			{
				int num = value[0] % 4;
				int num2 = value[0] / 4;
				Color[] pixels = _sheet.GetPixels(num * 128, ((Texture)_sheet).height - (num2 + 1) * 128, 128, 128);
				int num3 = value[3];
				Texture2D val = ((num3 > 0 && (Object)(object)under != (Object)null) ? Readable(under) : null);
				if ((Object)(object)val != (Object)null)
				{
					for (int i = 0; i < num3; i++)
					{
						for (int j = 0; j < num3; j++)
						{
							int num4 = value[1] + j;
							int num5 = value[2] + i;
							if (num4 >= 0 && num4 < 128 && num5 >= 0 && num5 < 128)
							{
								Color pixelBilinear = val.GetPixelBilinear(((float)j + 0.5f) / (float)num3, 1f - ((float)i + 0.5f) / (float)num3);
								int num6 = (127 - num5) * 128 + num4;
								pixels[num6] = Over(pixels[num6], pixelBilinear);
							}
						}
					}
					Object.Destroy((Object)(object)val);
				}
				Texture2D val2 = new Texture2D(128, 128, (TextureFormat)4, false)
				{
					name = "Digi icon " + id,
					wrapMode = (TextureWrapMode)1
				};
				val2.SetPixels(pixels);
				val2.Apply(false, true);
				return Sprite.Create(val2, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f);
			}
			catch (Exception ex)
			{
				_warn?.Invoke("Icon " + id + ": " + ex.Message);
				return null;
			}
		}

		private static Color Over(Color top, Color bottom)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			float num = top.a + bottom.a * (1f - top.a);
			if (num <= 0f)
			{
				return new Color(0f, 0f, 0f, 0f);
			}
			Color result = (top * top.a + bottom * bottom.a * (1f - top.a)) / num;
			result.a = num;
			return result;
		}

		private static Texture2D Readable(Sprite sprite)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			Texture2D texture = sprite.texture;
			if ((Object)(object)texture == (Object)null)
			{
				return null;
			}
			Rect textureRect = sprite.textureRect;
			int num = Mathf.Max(1, Mathf.RoundToInt(((Rect)(ref textureRect)).width));
			int num2 = Mathf.Max(1, Mathf.RoundToInt(((Rect)(ref textureRect)).height));
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0);
			RenderTexture active = RenderTexture.active;
			try
			{
				Graphics.Blit((Texture)(object)texture, temporary, new Vector2(((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height), new Vector2(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height));
				RenderTexture.active = temporary;
				Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)1
				};
				val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0);
				val.Apply();
				return val;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}
	}
	internal static class MaterialsList
	{
		private enum Column
		{
			Name,
			Total,
			Have,
			Missing
		}

		private sealed class Line
		{
			public string Name;

			public Sprite Icon;

			public int Amount;

			public int Have;

			public int Missing => Mathf.Max(0, Amount - Have);
		}

		internal static float ChestRange = 50f;

		private const float Width = 880f;

		private const float Height = 820f;

		private const float RowHeight = 40f;

		private const float ColumnWidth = 110f;

		private const float HeaderY = 146f;

		private const float ListTop = 184f;

		private static readonly Color Green = new Color(0.5f, 0.88f, 0.42f);

		private static readonly Color Red = new Color(1f, 0.45f, 0.38f);

		private static readonly string[] Titles = new string[4] { "Material", "Total", "Have", "Missing" };

		private static readonly MethodInfo CheckAccess = AccessTools.Method(typeof(Container), "CheckAccess", new Type[1] { typeof(long) }, (Type[])null);

		private static Column _sort = Column.Total;

		private static bool _descending = true;

		private static List<Line> _materials = new List<Line>();

		private static List<Line> _pieces = new List<Line>();

		private static Windows.Window _window;

		private static string _query = "";

		private static readonly TextMeshProUGUI[] Headers = (TextMeshProUGUI[])(object)new TextMeshProUGUI[4];

		internal static string Number(int n)
		{
			return n.ToString("N0", CultureInfo.InvariantCulture);
		}

		internal static void Show(string subtitle, List<string> prefabs, Action back = null)
		{
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Expected O, but got Unknown
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Line> dictionary = new Dictionary<string, Line>();
			Dictionary<string, Line> dictionary2 = new Dictionary<string, Line>();
			SortedSet<string> sortedSet = new SortedSet<string>();
			float num = 0f;
			foreach (string prefab in prefabs)
			{
				GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(prefab) : null);
				Piece val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Piece>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Add(dictionary2, prefab, Localization.instance.Localize(val2.m_name), val2.m_icon, 1);
				if ((Object)(object)val2.m_craftingStation != (Object)null)
				{
					sortedSet.Add(Localization.instance.Localize(val2.m_craftingStation.m_name));
				}
				if (val2.m_resources == null)
				{
					continue;
				}
				Requirement[] resources = val2.m_resources;
				foreach (Requirement val3 in resources)
				{
					if (!((Object)(object)val3?.m_resItem == (Object)null) && val3.m_amount > 0)
					{
						ItemData itemData = val3.m_resItem.m_itemData;
						Add(dictionary, itemData.m_shared.m_name, Localization.instance.Localize(itemData.m_shared.m_name), itemData.GetIcon(), val3.m_amount);
						num += itemData.m_shared.m_weight * (float)val3.m_amount;
					}
				}
			}
			Player localPlayer = Player.m_localPlayer;
			List<Inventory> source = Stores(localPlayer);
			foreach (KeyValuePair<string, Line> pair in dictionary)
			{
				pair.Value.Have = (((Object)(object)localPlayer != (Object)null) ? ((Humanoid)localPlayer).GetInventory().CountItems(pair.Key, -1, true) : 0) + source.Sum((Inventory inv) => inv.CountItems(pair.Key, -1, true));
			}
			_materials = dictionary.Values.ToList();
			_pieces = dictionary2.Values.ToList();
			string footer = "Total weight " + Number(Mathf.RoundToInt(num)) + ((sortedSet.Count > 0) ? ("   ·   Needs " + string.Join(", ", sortedSet)) : "") + $"   ·   Have: inventory + chests within {ChestRange:0} m";
			_window = Windows.Open("Build Materials", subtitle, 880f, 820f, footer, 80f, back, 184f);
			if (_window == null)
			{
				return;
			}
			_query = "";
			TMP_InputField val4 = Windows.SearchBox(_window.Panel, 24f, 100f, 340f, 38f, "Search material or piece...");
			((UnityEvent<string>)(object)val4.onValueChanged).AddListener((UnityAction<string>)delegate(string text)
			{
				_query = (text ?? "").Trim();
				Fill();
			});
			_window.Search = val4;
			int num2 = _materials.Count((Line l) => l.Missing > 0);
			Windows.Place(((TMP_Text)Windows.Text((Transform)(object)_window.Panel, (_materials.Count == 0) ? "" : ((num2 == 0) ? "You have everything" : $"Short of {num2} of {_materials.Count} materials"), 20f, (num2 == 0) ? Green : Red, (TextAlignmentOptions)516)).rectTransform, 384f, 104f, 472f, 30f);
			RectTransform val5 = Windows.Rect("Header", (Transform)(object)_window.Panel);
			Windows.Place(val5, 24f, 146f, _window.RowWidth, 32f);
			for (int num3 = 0; num3 < Titles.Length; num3++)
			{
				Column column = (Column)num3;
				RectTransform val6 = Windows.Rect("Column " + Titles[num3], (Transform)(object)val5);
				if (num3 == 0)
				{
					Windows.Place(val6, 12f, 0f, NameWidth(), 32f);
				}
				else
				{
					Windows.Place(val6, ColumnX(num3), 0f, 110f, 32f);
				}
				((Graphic)((Component)val6).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0f);
				((UnityEvent)((Component)val6).gameObject.AddComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					SortBy(column);
				});
				TextMeshProUGUI val7 = Windows.Text((Transform)(object)val6, Titles[num3], 19f, Windows.Gold, (TextAlignmentOptions)((num3 == 0) ? 513 : 516));
				Windows.Stretch(((TMP_Text)val7).rectTransform);
				Headers[num3] = val7;
			}
			Fill();
		}

		private static float NameWidth()
		{
			return _window.RowWidth - 52f - 330f - 16f;
		}

		private static float ColumnX(int i)
		{
			return _window.RowWidth - (float)(4 - i) * 110f - 12f;
		}

		private static void SortBy(Column column)
		{
			if (_sort == column)
			{
				_descending = !_descending;
			}
			else
			{
				_sort = column;
				_descending = column != Column.Name;
			}
			Fill();
		}

		private static void Add(Dictionary<string, Line> lines, string key, string name, Sprite icon, int amount)
		{
			if (!lines.TryGetValue(key, out var value))
			{
				Line obj = new Line
				{
					Name = name,
					Icon = icon
				};
				value = obj;
				lines[key] = obj;
			}
			value.Amount += amount;
		}

		private static List<Inventory> Stores(Player player)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			List<Inventory> list = new List<Inventory>();
			if ((Object)(object)player == (Object)null || ChestRange <= 0f)
			{
				return list;
			}
			Vector3 position = ((Component)player).transform.position;
			float num = ChestRange * ChestRange;
			Container[] array = Object.FindObjectsByType<Container>((FindObjectsSortMode)0);
			foreach (Container val in array)
			{
				if ((Object)(object)val == (Object)null || val.GetInventory() == null)
				{
					continue;
				}
				Vector3 val2 = ((Component)val).transform.position - position;
				if (!(((Vector3)(ref val2)).sqrMagnitude > num))
				{
					Piece componentInParent = ((Component)val).GetComponentInParent<Piece>();
					if (!((Object)(object)componentInParent == (Object)null) && componentInParent.IsPlacedByPlayer() && (!(CheckAccess != null) || (bool)CheckAccess.Invoke(val, new object[1] { player.GetPlayerID() })))
					{
						list.Add(val.GetInventory());
					}
				}
			}
			return list;
		}

		private static IEnumerable<Line> Sorted(IEnumerable<Line> lines, bool material)
		{
			Func<Line, int> keySelector = _sort switch
			{
				Column.Have => (Line l) => (!material) ? l.Amount : l.Have, 
				Column.Missing => (Line l) => (!material) ? l.Amount : l.Missing, 
				_ => (Line l) => l.Amount, 
			};
			if (_sort == Column.Name)
			{
				if (!_descending)
				{
					return lines.OrderBy<Line, string>((Line l) => l.Name, StringComparer.OrdinalIgnoreCase);
				}
				return lines.OrderByDescending<Line, string>((Line l) => l.Name, StringComparer.OrdinalIgnoreCase);
			}
			if (!_descending)
			{
				return lines.OrderBy(keySelector).ThenBy((Line l) => l.Name);
			}
			return lines.OrderByDescending(keySelector).ThenBy((Line l) => l.Name);
		}

		private static void Fill()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (_window == null || (Object)(object)_window.Content == (Object)null)
			{
				return;
			}
			for (int i = 0; i < Headers.Length; i++)
			{
				if (!((Object)(object)Headers[i] == (Object)null))
				{
					bool flag = _sort == (Column)i;
					((TMP_Text)Headers[i]).text = Titles[i] + ((!flag) ? "" : (_descending ? " <size=70%>v</size>" : " <size=70%>^</size>"));
					((Graphic)Headers[i]).color = (flag ? Color.white : Windows.Gold);
				}
			}
			for (int num = ((Transform)_window.Content).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)_window.Content).GetChild(num)).gameObject);
			}
			float num2 = Section(0f, "Materials", material: true, Sorted(_materials.Where(Matches), material: true).ToList());
			num2 = Section(num2 + 12f, "Pieces", material: false, Sorted(_pieces.Where(Matches), material: false).ToList());
			Windows.Done(_window, num2);
			static bool Matches(Line l)
			{
				if (_query.Length != 0)
				{
					return l.Name.IndexOf(_query, StringComparison.OrdinalIgnoreCase) >= 0;
				}
				return true;
			}
		}

		private static float Section(float y, string title, bool material, List<Line> lines)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_01d5: 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_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			float rowWidth = _window.RowWidth;
			RectTransform val = Windows.Rect("Heading", (Transform)(object)_window.Content);
			Windows.Place(val, 0f, y, rowWidth, 34f);
			Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val, title, 22f, Windows.Gold, (TextAlignmentOptions)513)).rectTransform, 12f, 2f, NameWidth(), 30f);
			if (!material)
			{
				Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val, "Count", 19f, Windows.Gold, (TextAlignmentOptions)516)).rectTransform, ColumnX(1), 4f, 110f, 28f);
			}
			RectTransform obj = Windows.Rect("Line", (Transform)(object)val);
			Windows.Place(obj, 8f, 33f, rowWidth - 16f, 1f);
			((Graphic)((Component)obj).gameObject.AddComponent<Image>()).color = new Color(Windows.Gold.r, Windows.Gold.g, Windows.Gold.b, 0.4f);
			y += 36f;
			if (lines.Count == 0)
			{
				RectTransform obj2 = Windows.Rect("None", (Transform)(object)_window.Content);
				Windows.Place(obj2, 0f, y, rowWidth, 40f);
				Windows.Place(((TMP_Text)Windows.Text((Transform)(object)obj2, (_query.Length > 0) ? "nothing matches" : "nothing", 19f, Windows.Dim, (TextAlignmentOptions)513)).rectTransform, 52f, 6f, rowWidth - 60f, 28f);
				return y + 40f;
			}
			for (int i = 0; i < lines.Count; i++)
			{
				Line line = lines[i];
				RectTransform val2 = Windows.Rect("Row", (Transform)(object)_window.Content);
				Windows.Place(val2, 0f, y, rowWidth, 40f);
				((Graphic)((Component)val2).gameObject.AddComponent<Image>()).color = ((i % 2 == 0) ? Windows.RowEven : Windows.RowOdd);
				if ((Object)(object)line.Icon != (Object)null)
				{
					Windows.Picture(val2, line.Icon, 10f, 4f, 32f, 32f);
				}
				Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val2, line.Name, 20f, Windows.Body, (TextAlignmentOptions)513)).rectTransform, 52f, 6f, NameWidth(), 28f);
				Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val2, Number(line.Amount), 20f, Windows.Body, (TextAlignmentOptions)516)).rectTransform, ColumnX(1), 6f, 110f, 28f);
				if (material)
				{
					bool flag = line.Missing == 0;
					Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val2, Number(line.Have), 20f, flag ? Green : Red, (TextAlignmentOptions)516)).rectTransform, ColumnX(2), 6f, 110f, 28f);
					Windows.Place(((TMP_Text)Windows.Text((Transform)(object)val2, flag ? "-" : Number(line.Missing), 20f, flag ? Windows.Dim : Red, (TextAlignmentOptions)516)).rectTransform, ColumnX(3), 6f, 110f, 28f);
				}
				y += 40f;
			}
			return y;
		}
	}
	internal class StabilityMeter : MonoBehaviour
	{
		private struct Link
		{
			public int To;

			public float Factor;
		}

		private struct Rest
		{
			public int To;

			public float Factor;
		}

		private struct Memory
		{
			public int To;

			public float Value;

			public float Fixed;
		}

		private sealed class Node
		{
			public WearNTear Piece;

			public float Max;

			public float Min;

			public float Horizontal;

			public float Vertical;

			public bool Grounded;

			public bool Static;

			public bool Outside;

			public bool Read;

			public bool Alive = true;

			public bool CanBreak;

			public bool CanBreakKnown;

			public bool Tell;

			public bool Skip;

			public int Order;

			public float Value;

			public readonly List<Link> Links = new List<Link>();

			public readonly List<Rest> Rests = new List<Rest>();

			public List<int> Pairs = new List<int>();

			public List<WearNTear> Touching = new List<WearNTear>();

			public readonly List<Memory> Memory = new List<Memory>();
		}

		private struct Shown
		{
			public float Value;

			public float Max;

			public float Min;

			public bool Breaks;
		}

		private sealed class Geometry
		{
			public bool Grounded;

			public float At;

			public readonly List<WearNTear> Touching = new List<WearNTear>();

			public readonly List<WearNTear> LinkPieces = new List<WearNTear>();

			public readonly List<float> LinkFactors = new List<float>();

			public readonly List<WearNTear> RestPieces = new List<WearNTear>();

			public readonly List<float> RestFactors = new List<float>();

			public readonly List<int> Pairs = new List<int>();
		}

		internal static Func<bool> Wanted = () => true;

		internal static Func<bool> ShowValue = () => false;

		private const int MaxPieces = 5000;

		private const int MaxRounds = 3000;

		private const int MaxSteps = 3000000;

		private const float UrgentBudget = 0.01f;

		private const float BackgroundBudget = 0.0015f;

		private const float CellSize = 8f;

		private const float CacheAge = 60f;

		private const float Refresh = 3f;

		private static readonly MethodInfo MaterialProperties = AccessTools.Method(typeof(WearNTear), "GetMaterialProperties", (Type[])null, (Type[])null);

		private static readonly Func<WearNTear, float> SupportNow = AccessTools.MethodDelegate<Func<WearNTear, float>>(AccessTools.Method(typeof(WearNTear), "GetSupport", (Type[])null, (Type[])null), (object)null, true);

		private static readonly FieldRef<WearNTear, List<WearNTear>> RememberedPieces = AccessTools.FieldRefAccess<WearNTear, List<WearNTear>>("m_supportWearNTear");

		private static readonly FieldRef<WearNTear, List<float>> RememberedValues = AccessTools.FieldRefAccess<WearNTear, List<float>>("m_supportValue");

		private static readonly FieldRef<WearNTear, List<Collider>> RememberedColliders = AccessTools.FieldRefAccess<WearNTear, List<Collider>>("m_supportColliders");

		private static readonly FieldRef<WearNTear, bool> TellNeighbours = AccessTools.FieldRefAccess<WearNTear, bool>("m_clearCachedSupport");

		private static readonly FieldRef<WearNTear, int> ListIndex = AccessTools.FieldRefAccess<WearNTear, int>("m_myIndex");

		private static readonly List<Node> Nodes = new List<Node>();

		private static readonly Dictionary<WearNTear, int> Index = new Dictionary<WearNTear, int>();

		private static readonly Dictionary<int, int> AtOrder = new Dictionary<int, int>();

		private static readonly List<int> Round = new List<int>();

		private static int _read;

		private static int _roundPos;

		private static int _rounds;

		private static int _steps;

		private static int _listCount;

		private static bool _solving;

		private static bool _changed;

		private static bool _reorder;

		private static bool _dirty;

		private static bool _noFall;

		private static float _solvedAt;

		private static float _nextWarmUp;

		private static int _prepared;

		private static readonly Dictionary<MaterialType, float[]> Materials = new Dictionary<MaterialType, float[]>();

		private static readonly Collider[] Hits = (Collider[])(object)new Collider[128];

		private static readonly List<Collider> HitColliders = new List<Collider>();

		private static readonly List<WearNTear> HitPieces = new List<WearNTear>();

		private static readonly List<Collider> Own = new List<Collider>();

		private static int _mask;

		private static int _pieceMask;

		private static int _terrain = -1;

		private static readonly Dictionary<WearNTear, Shown> Result = new Dictionary<WearNTear, Shown>();

		private static readonly Dictionary<WearNTear, Geometry> Cache = new Dictionary<WearNTear, Geometry>();

		private static readonly Dictionary<long, List<WearNTear>> Cells = new Dictionary<long, List<WearNTear>>();

		private static ZNetScene _scene;

		private GameObject _root;

		private RectTransform _fill;

		private Image _fillImage;

		private TextMeshProUGUI _text;

		internal static void Patch(Harmony harmony)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(WearNTear), "OnPlaced", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(StabilityMeter), "Changed", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(WearNTear), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(StabilityMeter), "Appeared", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(WearNTear), "OnDestroy", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(StabilityMeter), "Gone", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void Changed()
		{
			_dirty = true;
		}

		private static void Appeared(WearNTear __instance)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.Count != 0)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.GetZDO() != null)
				{
					Forget(((Component)__instance).transform.position);
				}
			}
		}

		private static void Gone(WearNTear __instance)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (Index.ContainsKey(__instance) || Result.Remove(__instance))
			{
				_dirty = true;
			}
			if (Cache.Count > 0)
			{
				Forget(((Component)__instance).transform.position);
			}
		}

		private static long CellOf(Vector3 p, int dx, int dy, int dz)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			long num = Mathf.FloorToInt(p.x / 8f) + dx;
			long num2 = Mathf.FloorToInt(p.y / 8f) + dy;
			long num3 = Mathf.FloorToInt(p.z / 8f) + dz;
			return ((num & 0x1FFFFF) << 42) | ((num2 & 0x1FFFFF) << 21) | (num3 & 0x1FFFFF);
		}

		private static void Forget(Vector3 p)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = -1; i <= 1; i++)
			{
				for (int j = -1; j <= 1; j++)
				{
					for (int k = -1; k <= 1; k++)
					{
						long key = CellOf(p, i, j, k);
						if (!Cells.TryGetValue(key, out var value))
						{
							continue;
						}
						foreach (WearNTear item in value)
						{
							Cache.Remove(item);
						}
						Cells.Remove(key);
					}
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			Clear();
			Result.Clear();
			Cache.Clear();
			Cells.Clear();
		}

		private void Update()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)Hud.instance == (Object)null || !Wanted() || !((Character)localPlayer).InPlaceMode())
			{
				Show(on: false);
				return;
			}
			Piece val = (Hud.IsPieceSelectionVisible() ? null : localPlayer.GetHoveringPiece());
			WearNTear val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<WearNTear>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Show(on: false);
				WarmUp();
				return;
			}
			Shown value;
			bool flag = Result.TryGetValue(val2, out value);
			if (!_solving)
			{
				if (!flag || _dirty || Time.time - _solvedAt > 3f)
				{
					Begin(val2);
				}
			}
			else if (!flag && !Index.ContainsKey(val2))
			{
				Begin(val2);
			}
			if (_solving)
			{
				Advance(flag ? 0.0015f : 0.01f);
				if (!flag)
				{
					flag = Result.TryGetValue(val2, out value);
				}
			}
			if (!flag)
			{
				Show(on: false);
			}
			else
			{
				Display(val2, value);
			}
		}

		private static void WarmUp()
		{
			if (_solving)
			{
				Advance(0.0015f);
			}
			else if (!(Time.time < _nextWarmUp))
			{
				_nextWarmUp = Time.time + 0.5f;
				if (_pieceMask == 0)
				{
					_pieceMask = LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" });
				}
				WearNTear val = Ahead() ?? Nearest();
				if (!((Object)(object)val == (Object)null) && val.m_noSupportWear && (!Result.ContainsKey(val) || _dirty || !(Time.time - _solvedAt <= 3f)))
				{
					Begin(val);
					Advance(0.0015f);
				}
			}
		}

		private static WearNTear Ahead()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			GameCamera instance = GameCamera.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			Transform transform = ((Component)instance).transform;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(transform.position, transform.forward, ref val, 60f, _pieceMask))
			{
				return null;
			}
			return ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<WearNTear>();
		}

		private static WearNTear Nearest()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			int num = Physics.OverlapSphereNonAlloc(position, 15f, Hits, _pieceMask);
			WearNTear result = null;
			float num2 = float.MaxValue;
			for (int i = 0; i < num; i++)
			{
				WearNTear componentInParent = ((Component)Hits[i]).GetComponentInParent<WearNTear>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					Vector3 val = ((Component)componentInParent).transform.position - position;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (!(sqrMagnitude >= num2))
					{
						num2 = sqrMagnitude;
						result = componentInParent;
					}
				}
			}
			return result;
		}

		private static void Clear()
		{
			Nodes.Clear();
			Index.Clear();
			AtOrder.Clear();
			Round.Clear();
			Materials.Clear();
			_read = (_roundPos = (_rounds = (_steps = 0)));
			_solving = (_changed = false);
			_prepared = 0;
			_reorder = true;
		}

		private static void Begin(WearNTear piece)
		{
			if ((Object)(object)_scene != (Object)(object)ZNetScene.instance)
			{
				_scene = ZNetScene.instance;
				Cache.Clear();
				Cells.Clear();
				Result.Clear();
			}
			if (Cache.Count > 50000)
			{
				Cache.Clear();
				Cells.Clear();
			}
			Clear();
			_dirty = false;
			_solving = true;
			if (_mask == 0)
			{
				_mask = LayerMask.GetMask(new string[5] { "piece", "Default", "static_solid", "Default_small", "terrain" });
			}
			if (_terrain < 0)
			{
				_terrain = LayerMask.NameToLayer("terrain");
			}
			_noFall = (Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGlobalKey((GlobalKeys)37);
			NodeOf(piece);
		}

		private static void Advance(float budget)
		{
			float num = Time.realtimeSinceStartup + budget;
			while (_read < Nodes.Count)
			{
				Read(_read++);
				if ((_read & 0xF) == 0 && Time.realtimeSinceStartup > num)
				{
					return;
				}
			}
			if (_prepared == 0)
			{
				_listCount = WearNTear.GetAllInstances().Count;
			}
			while (_prepared < Nodes.Count)
			{
				Prepare(_prepared++);
				if ((_prepared & 0x1F) == 0 && Time.realtimeSinceStartup > num)
				{
					return;
				}
			}
			while (true)
			{
				if (_roundPos >= Round.Count)
				{
					if ((_rounds > 0 && !_changed) || _rounds >= 3000 || _steps >= 3000000)
					{
						break;
					}
					StartRound();
					continue;
				}
				if (Step(Round[_roundPos++]))
				{
					_changed = true;
				}
				if ((++_steps & 0xFF) != 0 || !(Time.realtimeSinceStartup > num))
				{
					continue;
				}
				return;
			}
			_solving = false;
			_solvedAt = Time.time;
			if (Result.Count > 30000)
			{
				Result.Clear();
			}
			foreach (Node node in Nodes)
			{
				if (!node.Outside && (Object)(object)node.Piece != (Object)null)
				{
					Result[node.Piece] = new Shown
					{
						Value = node.Value,
						Max = node.Max,
						Min = node.Min,
						Breaks = !node.Alive
					};
				}
			}
		}

		private static int NodeOf(WearNTear piece)
		{
			if (Index.TryGetValue(piece, out var value))
			{
				return value;
			}
			Node node = new Node
			{
				Piece = piece
			};
			Properties(node);
			if (!piece.m_noSupportWear)
			{
				node.Static = (node.Grounded = true);
				node.Value = node.Max;
			}
			else if (Nodes.Count >= 5000)
			{
				node.Static = (node.Outside = true);
				node.Value = SupportNow(piece);
			}
			value = Nodes.Count;
			Nodes.Add(node);
			Index[piece] = value;
			return value;
		}

		private static void Properties(Node node)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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)
			MaterialType materialType = node.Piece.m_materialType;
			if (!Materials.TryGetValue(materialType, out var value))
			{
				object[] array = new object[4];
				MaterialProperties.Invoke(node.Piece, array);
				value = new float[4]
				{
					(float)array[0],
					(float)array[1],
					(float)array[2],
					(float)array[3]
				};
				Materials[materialType] = value;
			}
			node.Max = value[0];
			node.Min = value[1];
			node.Horizontal = value[2];
			node.Vertical = value[3];
		}

		private static Vector3 Com(WearNTear piece)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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)
			return ((Component)piece).transform.position + ((Component)piece).transform.rotation * piece.m_comOffset;
		}

		private static void Read(int i)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Node node = Nodes[i];
			if (node.Static || node.Read)
			{
				return;
			}
			node.Read = true;
			WearNTear piece = node.Piece;
			if ((Object)(object)piece == (Object)null)
			{
				node.Static = true;
				node.Alive = false;
				return;
			}
			if (!Cache.TryGetValue(piece, out var value) || !Fresh(value))
			{
				value = Measure(piece);
				Cache[piece] = value;
				long key = CellOf(((Component)piece).transform.position, 0, 0, 0);
				if (!Cells.TryGetValue(key, out var value2))
				{
					value2 = (Cells[key] = new List<WearNTear>());
				}
				value2.Add(piece);
			}
			node.Touching = value.Touching;
			if (value.Grounded)
			{
				node.Grounded = true;
				return;
			}
			for (int j = 0; j < value.LinkPieces.Count; j++)
			{
				node.Links.Add(new Link
				{
					To = NodeOf(value.LinkPieces[j]),
					Factor = value.LinkFactors[j]
				});
			}
			for (int k = 0; k < value.RestPieces.Count; k++)
			{
				node.Rests.Add(new Rest
				{
					To = NodeOf(value.RestPieces[k]),
					Factor = value.RestFactors[k]
				});
			}
			node.Pairs = value.Pairs;
		}

		private static bool Fresh(Geometry g)
		{
			if (Time.time - g.At > 60f)
			{
				return false;
			}
			foreach (WearNTear linkPiece in g.LinkPieces)
			{
				if ((Object)(object)linkPiece == (Object)null)
				{
					return false;
				}
			}
			return true;
		}

		private static Geometry Measure(WearNTear piece)
		{
			//IL_001e: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: 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_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			Geometry geometry = new Geometry
			{
				At = Time.time
			};
			((Component)piece).GetComponentsInChildren<Collider>(true, Own);
			Vector3 val = Com(piece);
			HitColliders.Clear();
			HitPieces.Clear();
			bool flag = false;
			bool flag2 = true;
			Vector3 val5 = default(Vector3);
			foreach (Collider item in Own)
			{
				if ((Object)(object)item == (Object)null || item.isTrigger || (Object)(object)item.attachedRigidbody != (Object)null)
				{
					continue;
				}
				BoxCollider val2 = (BoxCollider)(object)((item is BoxCollider) ? item : null);
				Quaternion val3;
				Vector3 val4;
				if ((Object)(object)val2 != (Object)null)
				{
					Transform transform = ((Component)val2).transform;
					val3 = transform.rotation;
					val4 = transform.position + transform.TransformVector(val2.center);
					Vector3 lossyScale = transform.lossyScale;
					((Vector3)(ref val5))..ctor(lossyScale.x * val2.size.x, lossyScale.y * val2.size.y, lossyScale.z * val2.size.z);
				}
				else
				{
					val3 = Quaternion.identity;
					Bounds bounds = item.bounds;
					val4 = ((Bounds)(ref bounds)).center;
					bounds = item.bounds;
					val5 = ((Bounds)(ref bounds)).size;
				}
				val5 = (val5 + new Vector3(0.3f, 0.3f, 0.3f)) * 0.5f;
				int num = Physics.OverlapBoxNonAlloc(val4, val5, Hits, val3, _mask);
				for (int i = 0; i < num; i++)
				{
					Collider val6 = Hits[i];
					if (!((Object)(object)val6.attachedRigidbody != (Object)null) && !val6.isTrigger && !Own.Contains(val6))
					{
						WearNTear componentInParent = ((Component)val6).GetComponentInParent<WearNTear>();
						if (flag2 && (Object)(object)componentInParent != (Object)null)
						{
							geometry.Touching.Add(componentInParent);
						}
						if (((Component)val6).gameObject.layer == _terrain)
						{
							flag = true;
						}
						else if ((Object)(object)componentInParent == (Object)null)
						{
							flag = true;
						}
						else if (componentInParent.m_supports)
						{
							HitColliders.Add(val6);
							HitPieces.Add(componentInParent);
						}
					}
				}
				flag2 = false;
			}
			if (flag)
			{
				geometry.Grounded = true;
				return geometry;
			}
			Losses(piece, out var horizontal, out var vertical);
			List<Vector3> list = new List<Vector3>();
			for (int j = 0; j < HitPieces.Count; j++)
			{
				WearNTear val7 = HitPieces[j];
				Vector3 val8 = Com(val7);
				float num2 = Vector3.Distance(val, val8) + 0.1f;
				float num3 = Vector3.Distance(val, ((Component)val7).transform.position) + 0.1f;
				if (num3 < num2 && !piece.m_forceCorrectCOMCalculation)
				{
					num2 = num3;
				}
				geometry.LinkPieces.Add(val7);
				geometry.LinkFactors.Add(1f - horizontal * num2);
				Vector3 val9 = SupportPoint(val, val8, HitColliders[j]);
				if (val9.y < val.y + 0.05f)
				{
					Vector3 val10 = val9 - val;
					Vector3 normalized = ((Vector3)(ref val10)).normalized;
					if (normalized.y < 0f)
					{
						float num4 = Mathf.Acos(1f - Mathf.Abs(normalized.y)) / ((float)Math.PI / 2f);
						geometry.LinkPieces.Add(val7);
						geometry.LinkFactors.Add(1f - Mathf.Lerp(horizontal, vertical, num4) * num2);
					}
					geometry.RestPieces.Add(val7);
					geometry.RestFactors.Add(1f - vertical * num2);
					list.Add(val9);
				}
			}
			for (int k = 0; k < list.Count - 1; k++)
			{
				Vector3 val11 = list[k] - val;
				val11.y = 0f;
				for (int l = k + 1; l < list.Count; l++)
				{
					Vector3 val12 = list[l] - val;
					val12.y = 0f;
					if (Vector3.Angle(val11, val12) >= 100f)
					{
						geometry.Pairs.Add(k);
						geometry.Pairs.Add(l);
					}
				}
			}
			return geometry;
		}

		private static void Losses(WearNTear piece, out float horizontal, out float vertical)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			MaterialType materialType = piece.m_materialType;
			if (!Materials.TryGetValue(materialType, out var value))
			{
				object[] array = new object[4];
				MaterialProperties.Invoke(piece, array);
				value = new float[4]
				{
					(float)array[0],
					(float)array[1],
					(float)array[2],
					(float)array[3]
				};
				Materials[materialType] = value;
			}
			horizontal = value[2];
			vertical = value[3];
		}

		private static Vector3 SupportPoint(Vector3 com, Vector3 otherCom, Collider collider)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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)
			MeshCollider val = (MeshCollider)(object)((collider is MeshCollider) ? collider : null);
			if ((Object)(object)val != (Object)null && !val.convex)
			{
				RaycastHit val2 = default(RaycastHit);
				if (!((Collider)val).Raycast(new Ray(com, Vector3.down), ref val2, 10f))
				{
					return (com + otherCom) * 0.5f;
				}
				return ((RaycastHit)(ref val2)).point;
			}
			return collider.ClosestPoint(com);
		}

		private static void Prepare(int i)
		{
			Node node = Nodes[i];
			if (node.Outside || node.Static || !node.Alive)
			{
				return;
			}
			WearNTear piece = node.Piece;
			if ((Object)(object)piece == (Object)null)
			{
				node.Alive = false;
				return;
			}
			node.Order = ListIndex.Invoke(piece);
			AtOrder[node.Order] = i;
			node.Tell = TellNeighbours.Invoke(piece);
			node.Value = (node.Grounded ? node.Max : SupportNow(piece));
			List<WearNTear> list = RememberedPieces.Invoke(piece);
			List<float> list2 = RememberedValues.Invoke(piece);
			List<Collider> list3 = RememberedColliders.Invoke(piece);
			for (int j = 0; j < list.Count && j < list2.Count; j++)
			{
				WearNTear val = list[j];
				int value;
				if ((Object)(object)val == (Object)null || j >= list3.Count || (Object)(object)list3[j] == (Object)null)
				{
					node.Memory.Add(new Memory
					{
						To = -2
					});
				}
				else if (Index.TryGetValue(val, out value) && !Nodes[value].Outside)
				{
					node.Memory.Add(new Memory
					{
						To = value,
						Value = list2[j]
					});
				}
				else
				{
					node.Memory.Add(new Memory
					{
						To = -1,
						Value = list2[j],
						Fixed = SupportNow(val)
					});
				}
			}
		}

		private static void StartRound()
		{
			_rounds++;
			_changed = false;
			_roundPos = 0;
			if (!_reorder)
			{
				foreach (int item in Round)
				{
					Nodes[item].Skip = false;
				}
				return;
			}
			_reorder = false;
			Round.Clear();
			for (int i = 0; i < Nodes.Count; i++)
			{
				Node node = Nodes[i];
				node.Skip = false;
				if (node.Alive && !node.Outside && !node.Static && node.Order >= 0)
				{
					Round.Add(i);
				}
			}
			Round.Sort((int a, int b) => Nodes[a].Order.CompareTo(Nodes[b].Order));
		}

		private static float ValueOf(int j)
		{
			return Nodes[j].Value;
		}

		private static bool Step(int i)
		{
			Node node = Nodes[i];
			if (!node.Alive || node.Skip)
			{
				return false;
			}
			if (node.Grounded)
			{
				if (!node.Tell)
				{
					return false;
				}
				TellAll(node);
				return true;
			}
			if (node.Memory.Count > 0)
			{
				int num = 0;
				float num2 = 0f;
				foreach (Memory item in node.Memory)
				{
					if (item.To == -2 || (item.To >= 0 && !Nodes[item.To].Alive))
					{
						break;
					}
					float num3 = ((item.To >= 0) ? ValueOf(item.To) : item.Fixed);
					if (num3 > num2)
					{
						num2 = num3;
					}
					if (!num3.Equals(item.Value))
					{
						break;
					}
					num++;
				}
				if (num == node.Memory.Count && num2 >= node.Value)
				{
					return Damage(i);
				}
				node.Memory.Clear();
			}
			bool flag = false;
			if (node.Tell)
			{
				TellAll(node);
				flag = true;
			}
			float num4 = 0f;
			foreach (Link link in node.Links)
			{
				if (Nodes[link.To].Alive)
				{
					num4 = Mathf.Max(num4, ValueOf(link.To) * link.Factor);
				}
			}
			for (int j = 0; j + 1 < node.Pairs.Count; j += 2)
			{
				Rest rest = node.Rests[node.Pairs[j]];
				Rest rest2 = node.Rests[node.Pairs[j + 1]];
				if (Nodes[rest.To].Alive && Nodes[rest2.To].Alive)
				{
					num4 = Mathf.Max(num4, (ValueOf(rest.To) * rest.Factor + ValueOf(rest2.To) * rest2.Factor) * 0.5f);
				}
			}
			foreach (Rest rest3 in node.Rests)
			{
				if (Nodes[rest3.To].Alive)
				{
					node.Memory.Add(new Memory
					{
						To = rest3.To,
						Value = ValueOf(rest3.To)
					});
				}
			}
			num4 = Mathf.Min(num4, node.Max);
			if (!num4.Equals(node.Value))
			{
				node.Value = num4;
				flag = true;
			}
			if (node.Value < node.Min)
			{
				node.Memory.Clear();
			}
			return Damage(i) || flag;
		}

		private static bool Damage(int i)
		{
			Node node = Nodes[i];
			if (node.Value >= node.Min)
			{
				return false;
			}
			if (!node.CanBreakKnown)
			{
				node.CanBreakKnown = true;
				Piece val = (((Object)(object)node.Piece != (Object)null) ? ((Component)node.Piece).GetComponent<Piece>() : null);
				node.CanBreak = !_noFall && ((Object)(object)val == (Object)null || val.CanBeRemoved());
			}
			if (!node.CanBreak)
			{
				return false;
			}
			Break(i);
			return true;
		}

		private static void TellAll(Node node)
		{
			node.Tell = false;
			foreach (WearNTear item in node.Touching)
			{
				if ((Object)(object)item != (Object)null && Index.TryGetValue(item, out var value))
				{
					Nodes[value].Memory.Clear();
				}
			}
		}

		private static void Break(int i)
		{
			Node node = Nodes[i];
			node.Alive = false;
			_reorder = true;
			AtOrder.Remove(node.Order);
			_listCount--;
			if (AtOrder.TryGetValue(_listCount, out var value) && value != i)
			{
				AtOrder.Remove(_listCount);
				Nodes[value].Order = node.Order;
				Nodes[value].Skip = true;
				AtOrder[node.Order] = value;
			}
		}

		private void Display(WearNTear piece, Shown shown)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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 (!((Object)(object)_root == (Object)null) || Build())
			{
				Show(on: true);
				float value = shown.Value;
				float max = shown.Max;
				float min = shown.Min;
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.25f, 0.2f);
				float num = ((max > min) ? Mathf.Clamp01((value - min) / (max - min)) : 1f);
				string text;
				Color color = default(Color);
				if (!piece.m_noSupportWear)
				{
					text = "Needs no support";
					((Color)(ref color))..ctor(0.6f, 0.8f, 1f);
					num = 1f;
				}
				else if (shown.Breaks)
				{
					text = "Will collapse";
					color = val;
					num = 0f;
				}
				else if (value < min)
				{
					text = "Unsupported";
					color = val;
				}
				else if (value >= max - 0.001f)
				{
					text = "Stability 100%";
					((Color)(ref color))..ctor(0.6f, 0.8f, 1f);
				}
				else
				{
					float num2 = Mathf.Clamp01((value - min) / (max * 0.5f - min));
					color = ((num2 < 0.5f) ? Color.Lerp(val, new Color(1f, 0.85f, 0.2f), num2 * 2f) : Color.Lerp(new Color(1f, 0.85f, 0.2f), new Color(0.35f, 1f, 0.35f), (num2 - 0.5f) * 2f));
					text = $"Stability {Mathf.FloorToInt(num * 100f)}%";
				}
				if (ShowValue() && piece.m_noSupportWear && !shown.Breaks)
				{
					text += $" <size=80%><color=#C8C8C8>({Mathf.Max(0f, value):0.#}/{max:0}, needs {min:0})</color></size>";
				}
				((TMP_Text)_text).text = text;
				((Graphic)_text).color = color;
				((Graphic)_fillImage).color = color;
				_fill.sizeDelta = new Vector2(Mathf.Max(1f, 70f * num), 0f);
			}
		}

		private void Show(bool on)
		{
			if ((Object)(object)_root != (Object)null && _root.activeSelf != on)
			{
				_root.SetActive(on);
			}
		}

		private bool Build()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_01b8: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Expected O, but got Unknown
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: 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_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			Hud instance = Hud.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.m_crosshair == (Object)null)
			{
				return false;
			}
			RectTransform rectTransform = ((Graphic)instance.m_crosshair).rectTransform;
			_root = new GameObject("DigiStabilityMeter", new Type[1] { typeof(RectTransform) });
			RectTransform val = (RectTransform)_root.transform;
			((Transform)val).SetParent(((Transform)rectTransform).parent, false);
			val.anchorMin = rectTransform.anchorMin;
			val.anchorMax = rectTransform.anchorMax;
			val.pivot = new Vector2(0.5f, 1f);
			val.anchoredPosition = rectTransform.anchoredPosition + new Vector2(0f, -20f);
			val.sizeDelta = new Vector2(300f, 30f);
			GameObject val2 = new GameObject("Bar", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform val3 = (RectTransform)val2.transform;
			((Transform)val3).SetParent((Transform)(object)val, false);
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 1f);
			val3.anchorMax = val4;
			val3.anchorMin = val4;
			val3.pivot = new Vector2(0.5f, 1f);
			val3.anchoredPosition = Vector2.zero;
			val3.sizeDelta = new Vector2(72f, 7f);
			Image component = val2.GetComponent<Image>();
			((Graphic)component).color = new Color(0f, 0f, 0f, 0.6f);
			((Graphic)component).raycastTarget = false;
			GameObject val5 = new GameObject("Fill", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			_fill = (RectTransform)val5.transform;
			((Transform)_fill).SetParent((Transform)(object)val3, false);
			_fill.anchorMin = new Vector2(0f, 0f);
			_fill.anchorMax = new Vector2(0f, 1f);
			_fill.pivot = new Vector2(0f, 0.5f);
			_fill.anchoredPosition = new Vector2(1f, 0f);
			_fill.offsetMin = new Vector2(1f, 1f);
			_fill.offsetMax = new Vector2(1f, -1f);
			_fillImage = val5.GetComponent<Image>();
			((Graphic)_fillImage).raycastTarget = false;
			GameObject val6 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			RectTransform val7 = (RectTransform)val6.transform;
			((Transform)val7).SetParent((Transform)(object)val, false);
			((Vector2)(ref val4))..ctor(0.5f, 1f);
			val7.anchorMax = val4;
			val7.anchorMin = val4;
			val7.pivot = new Vector2(0.5f, 1f);
			val7.anchoredPosition = new Vector2(0f, -9f);
			val7.sizeDelta = new Vector2(300f, 22f);
			_text = val6.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)instance.m_hoverName != (Object)null)
			{
				((TMP_Text)_text).font = ((TMP_Text)instance.m_hoverName).font;
				((TMP_Text)_text).fontSharedMaterial = ((TMP_Text)instance.m_hoverName).fontSharedMaterial;
			}
			((TMP_Text)_text).fontSize = 16f;
			((TMP_Text)_text).alignment = (TextAlignmentOptions)258;
			((TMP_Text)_text).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)_text).overflowMode = (TextOverflowModes)0;
			((Graphic)_text).raycastTarget = false;
			((TMP_Text)_text).richText = true;
			return true;
		}
	}
	internal class Windows : MonoBehaviour
	{
		internal sealed class Window
		{
			public GameObject Root;

			public RectTransform Panel;

			public RectTransform View;

			public RectTransform Content;

			public TMP_InputField Search;

			public float Width;

			public float Height;

			public float RowWidth;

			public float Step;

			public float Target;

			public bool Gliding;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Close;
		}

		internal const float Pad = 24f;

		internal const float ScrollWidth = 14f;

		internal static readonly Color Gold = new Color(1f, 0.72f, 0.36f);

		internal static readonly Color Body = new Color(0.92f, 0.9f, 0.86f);

		internal static readonly Color Dim = new Color(0.6f, 0.58f, 0.55f);

		internal static readonly Color RowEven = new Color(1f, 1f, 1f, 0.035f);

		internal static readonly Color RowOdd = new Color(0f, 0f, 0f, 0.12f);

		internal static Window Current;

		private static TMP_FontAsset _font;

		private static Material _fontMaterial;

		private static bool _readingWheel;

		internal static bool IsOpen
		{
			get
			{
				if (Current != null)
				{
					return (Object)(object)Current.Root != (Object)null;
				}
				return false;
			}
		}

		internal static bool Searching
		{
			get
			{
				if (IsOpen && (Object)(object)Current.Search != (Object)null)
				{
					return Current.Search.isFocused;
				}
				return false;
			}
		}

		internal static void Patch(Harmony harmony)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(PlayerController), "TakeInput", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Windows), "NoInput", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(GameCamera), "UpdateMouseCapture", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Windows), "FreeMouse", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(ZInput), "Internal_GetMouseScrollWheel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Windows), "OwnWheel", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Menu), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Windows), "EscapeCloses", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(TextInput), "IsVisible", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Windows), "SearchTyping", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private void OnDestroy()
		{
			Close();
		}

		private void Update()
		{
			if (IsOpen)
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || InventoryGui.IsVisible() || Minimap.IsOpen() || StoreGui.IsVisible())
				{
					Close();
					return;
				}
				_readingWheel = true;
				float mouseScrollWheel = ZInput.GetMouseScrollWheel();
				_readingWheel = false;
				Scroll(Current, mouseScrollWheel, Time.unscaledDeltaTime);
			}
		}

		internal static Window Open(string title, string subtitle, float width, float height, string footer, float step, Action back = null, float listTop = 108f)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: 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_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Expected O, but got Unknown
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Expected O, but got Unknown
			//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0574: Unknown result type (might be due to invalid IL or missing references)
			//IL_057e: Expected O, but got Unknown
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Expected O, but got Unknown
			InventoryGui instance = InventoryGui.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			Close();
			_font = instance.m_recipeName.font;
			_fontMaterial = instance.m_recipeName.fontSharedMaterial;
			Window window = new Window
			{
				Width = width,
				Height = height,
				Step = step
			};
			object obj;
			if (!((Object)(object)instance.m_crafting != (Object)null))
			{
				obj = null;
			}
			else
			{
				Canvas componentInParent = ((Component)instance.m_crafting).GetComponentInParent<Canvas>();
				obj = ((componentInParent != null) ? componentInParent.rootCanvas : null);
			}
			Canvas val = (Canvas)obj;
			window.Root = new GameObject("DigiCreative_Window", new Type[1] { typeof(RectTransform) });
			window.Root.transform.SetParent(((Component)instance).transform.parent, false);
			Canvas obj2 = window.Root.AddComponent<Canvas>();
			obj2.renderMode = (RenderMode)0;
			obj2.sortingOrder = (((Object)(object)val != (Object)null) ? val.sortingOrder : 0) + 5;
			CanvasScaler val2 = window.Root.AddComponent<CanvasScaler>();
			CanvasScaler val3 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<CanvasScaler>() : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val2.uiScaleMode = val3.uiScaleMode;
				val2.scaleFactor = val3.scaleFactor;
				val2.referenceResolution = val3.referenceResolution;
				val2.screenMatchMode = val3.screenMatchMode;
				val2.matchWidthOrHeight = val3.matchWidthOrHeight;
				val2.referencePixelsPerUnit = val3.referencePixelsPerUnit;
			}
			window.Root.AddComponent<GraphicRaycaster>();
			RectTransform val4 = (window.Panel = Rect("Window", window.Root.transform));
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(0.5f, 0.5f);
			val4.pivot = val5;
			Vector2 anchorMin = (val4.anchorMax = val5);
			val4.anchorMin = anchorMin;
			val4.sizeDelta = new Vector2(width, height);
			val4.anchoredPosition = Vector2.zero;
			Image val7 = ((Component)val4).gameObject.AddComponent<Image>();
			Image val8 = (((Object)(object)instance.m_crafting != (Object)null) ? ((IEnumerable<Image>)((Component)instance.m_crafting).GetComponentsInChildren<Image>(true)).FirstOrDefault((Func<Image, bool>)((Image i) => ((Object)i).name == "Bkg")) : null);
			if ((Object)(object)val8 != (Object)null && (Object)(object)val8.sprite != (Object)null)
			{
				val7.sprite = val8.sprite;
				val7.type = val8.type;
				((Graphic)val7).material = ((Graphic)val8).material;
				((Graphic)val7).color = ((Graphic)val8).color;
				val7.pixelsPerUnitMultiplier = val8.pixelsPerUnitMultiplier;
			}
			else
			{
				((Graphic)val7).color = new Color(0.08f, 0.07f, 0.06f, 0.96f);
			}
			Place(((TMP_Text)Text((Transform)(object)val4, title, 34f, Gold, (TextAlignmentOptions)513)).rectTransform, 24f, 14f, width - 120f, 44f);
			TextMeshProUGUI obj3 = Text((Transform)(object)val4, "X", 28f, Body, (TextAlignmentOptions)514);
			Place(((TMP_Text)obj3).rectTransform, width - 24f - 36f, 14f, 36f, 36f);
			((Graphic)obj3).raycastTarget = true;
			ButtonClickedEvent onClick = ((Component)obj3).gameObject.AddComponent<Button>().onClick;
			object obj4 = <>O.<0>__Close;
			if (obj4 == null)
			{
				UnityAction val9 = Close;
				<>O.<0>__Close = val9;
				obj4 = (object)val9;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj4);
			if (back != null)
			{
				Button(val4, "Back", width - 24f - 36f - 12f - 116f, 15f, 116f, 36f, (UnityAction)delegate
				{
					back();
				});
			}
			Place(((TMP_Text)Text((Transform)(object)val4, subtitle, 20f, Dim, (TextAlignmentOptions)513)).rectTransform, 24f, 62f, width - 48f, 30f);
			float height2 = height - listTop - 52f;
			window.View = Rect("List", (Transform)(object)val4);
			Place(window.View, 24f, listTop, width - 48f - 14f - 6f, height2);
			((Graphic)((Component)window.View).gameObject.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.28f);
			((Component)window.View).gameObject.AddComponent<RectMask2D>();
			window.Content = Rect("Content", (Transform)(object)window.View);
			window.Content.anchorMin = new Vector2(0f, 1f);
			window.Content.anchorMax = new Vector2(1f, 1f);
			window.Content.pivot = new Vector2(0.5f, 1f);
			window.Content.anchoredPosition = Vector2.zero;
			ScrollRect val10 = ((Component)window.View).gameObject.AddComponent<ScrollRect>();
			val10.content = window.Content;
			val10.viewport = window.View;
			val10.horizontal = false;
			val10.vertical = true;
			val10.movementType = (MovementType)2;
			val10.scrollSensitivity = 0f;
			val10.inertia = false;
			if ((Object)(object)instance.m_recipeListScroll != (Object)null)
			{
				Scrollbar component = Object.Instantiate<GameObject>(((Component)instance.m_recipeListScroll).gameObject, (Transform)(object)val4, false).GetComponent<Scrollbar>();
				((Object)component).name = "Scrollbar";
				component.onValueChanged = new ScrollEvent();
				component.direction = (Direction)2;
				Place((RectTransform)((Component)component).transform, width - 24f - 14f, listTop, 14f, height2);
				val10.verticalScrollbar = component;
				val10.verticalScrollbarVisibility = (ScrollbarVisibility)0;
			}
			window.RowWidth = width - 48f - 14f - 6f;
			Place(((TMP_Text)Text((Transform)(object)val4, footer, 18f, Dim, (TextAlignmentOptions)513)).rectTransform, 24f, height - 42f, width - 48f, 28f);
			Current = window;
			return window;
		}

		internal static void Done(Window w, float contentHeight)
		{
			//IL_000c: 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)
			w.Content.sizeDelta = new Vector2(0f, contentHeight);
			w.Content.anchoredPosition = Vector2.zero;
			w.Gliding = false;
		}

		internal static void Close()
		{
			if (Current != null && (Object)(object)Current.Root != (Object)null)
			{
				Object.Destroy((Object)(object)Current.Root);
			}
			Current = null;
		}

		private static void Scroll(Window w, float wheel, float dt)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)w.Content == (Object)null || (Object)(object)w.View == (Object)null)
			{
				return;
			}
			Rect rect = w.Content.rect;
			float height = ((Rect)(ref rect)).height;
			rect = w.View.rect;
			float num = Mathf.Max(0f, height - ((Rect)(ref rect)).height);
			float y = w.Content.anchoredPosition.y;
			if (Mathf.Abs(wheel) > 0.0001f && num > 0f)
			{
				if (!w.Gliding)
				{
					w.Target = y;
				}
				w.Target = Mathf.Clamp(w.Target - Mathf.Sign(wheel) * w.Step, 0f, num);
				w.Gliding = true;
			}
			if (w.Gliding)
			{
				float num2 = Mathf.Lerp(y, w.Target, 1f - Mathf.Exp((0f - dt) * 16f));
				if (Mathf.Abs(num2 - w.Target) < 0.5f)
				{
					num2 = w.Target;
					w.Gliding = false;
				}
				w.Content.anchoredPosition = new Vector2(w.Content.anchoredPosition.x, num2);
			}
		}

		private static void NoInput(ref bool __result)
		{
			if (IsOpen)
			{
				__result = false;
			}
		}

		private static void FreeMouse()
		{
			if (IsOpen)
			{
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
			}
		}

		private static void OwnWheel(ref float __result)
		{
			if (IsOpen && !_readingWheel)
			{
				__result = 0f;
			}
		}

		private static bool EscapeCloses()
		{
			if (!IsOpen)
			{
				return true;
			}
			if (Searching)
			{
				return false;
			}
			if (ZInput.GetKeyDown((KeyCode)27, true) || ZInput.GetButtonDown("Menu"))
			{
				Close();
			}
			return false;
		}

		private static void SearchTyping(ref bool __result)
		{
			if (Searching)
			{
				__result = true;
			}
		}

		internal static RectTransform Rect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			return (RectTransform)val.transform;
		}

		internal static void Place(RectTransform rect, float x, float y, float width, float height)
		{
			//IL_0013: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			rect.anchorMax = val;
			rect.anchorMin = val;
			rect.pivot = new Vector2(0f, 1f);
			rect.anchoredPosition = new Vector2(x, 0f - y);
			rect.sizeDelta = new Vector2(width, height);
		}

		internal static TextMeshProUGUI Text(Transform parent, string text, float size, Color color, TextAlignmentOptions align)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = ((Component)Rect("Text", parent)).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)_font != (Object)null)
			{
				((TMP_Text)val).font = _font;
			}
			if ((Object)(object)_fontMaterial != (Object)null)
			{
				((TMP_Text)val).fontSharedMaterial = _fontMaterial;
			}
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = align;
			((TMP_Text)val).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val).overflowMode = (TextOverflowModes)1;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).richText = true;
			((TMP_Text)val).text = text;
			return val;
		}

		internal static Image Picture(RectTransform parent, Sprite sprite, float x, float y, float width, float height)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Rect("Picture", (Transform)(object)parent);
			Place(obj, x, y, width, height);
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = sprite;
			obj2.preserveAspect = true;
			((Graphic)obj2).raycastTarget = false;
			((Graphic)obj2).color = (Color)(((Object)(object)sprite != (Object)null) ? Color.white : new Color(0f, 0f, 0f, 0.3f));
			return obj2;
		}

		internal static Button Button(RectTransform parent, string label, float x, float y, float width, float height, UnityAction click)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			InventoryGui instance = InventoryGui.instance;
			GameObject val;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_tabCraft != (Object)null)
			{
				val = Object.Instantiate<GameObject>(((Component)instance.m_tabCraft).gameObject, (Transform)(object)parent, false);
				TMP_Text[] componentsInChildren = val.GetComponentsInChildren<TMP_Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].text = label;
				}
			}
			else
			{
				val = ((Component)Rect("Button", (Transform)(object)parent)).gameObject;
				((Graphic)val.AddComponent<Image>()).color = new Color(0.3f, 0.25f, 0.2f, 0.9f);
				val.AddComponent<Button>();
				((TMP_Text)Text(val.transform, label, 18f, Body, (TextAlignmentOptions)514)).rectTransform.sizeDelta = new Vector2(width, height);
			}
			((Object)val).name = "Button " + label;
			Button component = val.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener(click);
			((Selectable)component).interactable = true;
			Place((RectTransform)val.transform, x, y, width, height);
			return component;
		}

		internal static TMP_InputField SearchBox(RectTransform parent, float x, float y, float width, float height, string hint)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: 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_026f: Expected O, but got Unknown
			RectTransform val = Rect("Search", (Transform)(object)parent);
			Place(val, x, y, width, height);
			((Component)val).gameObject.SetActive(false);
			Image val2 = ((Component)val).gameObject.AddComponent<Image>();
			Sprite val3 = SlotSprite();
			if ((Object)(object)val3 != (Object)null)
			{
				val2.sprite = val3;
				val2.type = (Type)1;
			}
			((Graphic)val2).color = new Color(0f, 0f, 0f, 0.6f);
			RectTransform val4 = Rect("Text Area", (Transform)(object)val);
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			val4.offsetMin = new Vector2(12f, 2f);
			val4.offsetMax = new Vector2(-34f, -2f);
			((Component)val4).gameObject.AddComponent<RectMask2D>();
			TextMeshProUGUI val5 = Text((Transform)(object)val4, hint, 19f, Dim, (TextAlignmentOptions)513);
			Stretch(((TMP_Text)val5).rectTransform);
			((TMP_Text)val5).fontStyle = (FontStyles)2;
			TextMeshProUGUI val6 = Text((Transform)(object)val4, "", 19f, Body, (TextAlignmentOptions)513);
			Stretch(((TMP_Text)val6).rectTransform);
			((TMP_Text)val6).richText = false;
			TMP_InputField field = ((Component)val).gameObject.AddComponent<TMP_InputField>();
			field.textViewport = val4;
			field.textComponent = (TMP_Text)(object)val6;
			field.placeholder = (Graphic)(object)val5;
			((Selectable)field).targetGraphic = (Graphic)(object)val2;
			if ((Object)(object)_font != (Object)null)
			{
				field.fontAsset = _font;
			}
			field.pointSize = 19f;
			field.characterLimit = 40;
			field.richText = false;
			field.customCaretColor = true;
			field.caretColor = Body;
			field.caretWidth = 2;
			field.selectionColor = new Color(1f, 0.72f, 0.36f, 0.35f);
			((Component)val).gameObject.SetActive(true);
			TextMeshProUGUI obj = Text((Transform)(object)val, "x", 22f, Dim, (TextAlignmentOptions)514);
			Place(((TMP_Text)obj).rectTransform, width - 32f, 0f, 30f, height);
			((Graphic)obj).raycastTarget = true;
			((UnityEvent)((Component)obj).gameObject.AddComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				field.text = "";
			});
			return field;
		}

		private static Sprite SlotSprite()
		{
			GameObject val = InventoryGui.instance?.m_playerGrid?.m_elementPrefab;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Image[] componentsInChildren = val.GetComponentsInChildren<Image>(true);
			foreach (Image val2 in componentsInChildren)
			{
				if ((Object)(object)val2.sprite != (Object)null && ((Object)val2.sprite).name == "item_background")
				{
					return val2.sprite;
				}
			}
			return null;
		}

		internal static void Stretch(RectTransform rect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = Vector2.zero;
			rect.offsetMax = Vector2.zero;
		}

		internal static void SetLabel(Button button, string label)
		{
			TMP_Text[] componentsInChildren = ((Component)button).GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].text = label;
			}
		}
	}
	internal static class WoodShapes
	{
		internal sealed class Member
		{
			public string[][] Row;

			public int Type;
		}

		internal sealed class Fit
		{
			public Piece Piece;

			public Quaternion Turn;

			public Vector3 Move;
		}

		internal static readonly string[] Types = new string[8] { "Wood", "Log", "Darkwood", "Wood Iron", "Ashwood", "Scalewood", "Timber", "Decorated Timber" };

		internal static readonly string[] IconPieces = new string[8] { "woodwall", "wood_wall_log", "darkwood_roof", "woodiron_beam", "ashwood_wall_2x2", "scale_wall_2x2", "stave_wall_2x2", "stave_deco_wall_2x2" };

		private static readonly string[] Shapes = new string[38]
		{
			"wood_beam_1 | | | | ashwood_beam_1m | | |", "wood_beam | wood_wall_log | darkwood_beam | woodiron_beam | ashwood_beam_2m | | stave_beam_2m | stave_deco_beam_2m", "| wood_wall_log_4x0.5 | darkwood_beam4x4 | | | | stave_beam_4m |", "wood_beam_26 | wood_log_26 | darkwood_beam_26 | woodiron_beam_26 | ashwood_wall_beam_26 | | stave_beam_26 | stave_deco_beam_26", "wood_beam_45 | wood_log_45 | darkwood_beam_45 | woodiron_beam_45 | ashwood_wall_beam_45 | | stave_beam_45 | stave_deco_beam_45", "wood_beam_67 | wood_log_67 | darkwood_beam_67 | woodiron_beam_67 | ashwood_wall_beam_67 | | stave_beam_67 | stave_deco_beam_67", "wood_pole | | | | ashwood_pole_1m | | |", "wood_pole2 | wood_pole_log | darkwood_pole | woodiron_pole | ashwood_pole_2m | | stave_pole_2m | stave_deco_pole_2m", "| wood_pole_log_4 | darkwood_pole4 | | | | stave_pole_4m |", "woodwall | | | | ashwood_wall_2x2 ashwood_decowall_2x2 | scale_wall_2x2 | stave_wall_2x2 | stave_deco_wall_2x2",
			"wood_wall_half | | | | ashwood_halfwall_1x2 | scale_halfwall_1x2 | |", "wood_wall_quarter | | | | ashwood_quarterwall_1x1 | scale_quarterwall_1x1 | |", "wood_wall_roof_a | | | | ashwood_wall_roof_26 | scale_wall_roof_26 scale_wall_roof_26_flipped | |", "wood_wall_roof_45 | | | | ashwood_wall_roof_45 | scale_wall_roof_45 scale_wall_roof_45_flipped | |", "wood_wall_roof_67_a | | | | ashwood_wall_roof_67_a | scale_wall_roof_67 scale_wall_roof_67_flipped | |", "wood_wall_roof_upsidedown | | | | ashwood_wall_roof_26_upsidedown | scale_wall_roof_26_upsidedown scale_wall_roof_26_upsidedown_flipped | |", "wood_wall_roof_45_upsidedown | | | | ashwood_wall_roof_45_upsidedown | scale_wall_roof_45_upsidedown scale_wall_roof_45_upsidedown_flipped | |", "wood_wall_roof_67_upsidedown | | | | ashwood_wall_roof_67_upsidedown | scale_wall_roof_67_upsidedown scale_wall_roof_67_upsidedown_flipped | |", "wood_wall_roof_top | | | | ashwood_wall_cross_26 | | stave_wall_cross_26 |", "wood_wall_roof_top_45 | | | | ashwood_wall_cross_45 | | stave_wall_cross_45 |",
			"wood_wall_roof_top_67 | | | | ashwood_wall_cross_67 | | stave_wall_cross_67 |", "wood_roof | | darkwood_roof | | | | |", "wood_roof_45 | | darkwood_roof_45 | | | | |", "wood_roof_67 | | darkwood_roof_67 | | | | |", "wood_roof_icorner | | darkwood_roof_icorner | | | | |", "wood_roof_icorner_45 | | darkwood_roof_icorner_45 | | | | |", "wood_roof_icorner_67 | | darkwood_roof_icorner_67 | | | | |", "wood_roof_ocorner | | darkwood_roof_ocorner | | | | |", "wood_roof_ocorner_45 | | darkwood_roof_ocorner_45 | | | | |", "wood_roof_ocorner_67 | | darkwood_roof_ocorner_67 | | | | |",
			"wood_roof_top | | darkwood_roof_top | | | | |", "wood_roof_top_45 | | darkwood_roof_top_45 | | | | |", "wood_roof_top_67 | | darkwood_roof_top_67 | | | | |", "wood_floor | | | | ashwood_floor_2x2 ashwood_deco_floor | | |", "wood_floor_1x1 | | | | ashwood_floor_1x1 | | |", "wood_door | | | | ashwood_door | | |", "| | darkwood_arch | | ashwood_arch_big | | |", "| | darkwood_decowall | | ashwood_decowall_divider | | |"
		};

		private static Dictionary<string, Member> _members;

		private static readonly Dictionary<string, Fit> Fits = new Dictionary<string, Fit>();

		private static readonly List<Transform> SnapList = new List<Transform>();

		internal static string ToolId(int type)
		{
			return "woodswap_" + Types[type].Replace(" ", "").ToLowerInvariant();
		}

		internal static Member MemberOf(string prefab)
		{
			if (_members == null)
			{
				_members = new Dictionary<string, Member>();
				string[] shapes = Shapes;
				for (int i = 0; i < shapes.Length; i++)
				{
					string[] array = shapes[i].Split(new char[1] { '|' });
					string[][] array2 = new string[Types.Length][];
					for (int j = 0; j < array2.Length; j++)
					{
						array2[j] = ((j < array.Length) ? array[j].Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries) : new string[0]);
					}
					for (int k = 0; k < array2.Length; k++)
					{
						string[] array3 = array2[k];
						foreach (string key in array3)
						{
							_members[key] = new Member
							{
								Row = array2,
								Type = k
							};
						}
					}
				}
			}
			if (prefab == null || !_members.TryGetValue(prefab, out var value))
			{
				return null;
			}
			return value;
		}

		internal static Piece PieceOf(string name)
		{
			GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(name) : null);
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return val.GetComponent<Piece>();
		}

		private static List<Vector3> SnapsOf(Piece piece)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			if ((Object)(object)piece == (Object)null)
			{
				return list;
			}
			SnapList.Clear();
			piece.GetSnapPoints(SnapList);
			foreach (Transform snap in SnapList)
			{
				list.Add(((Component)piece).transform.InverseTransformPoint(snap.position));
			}
			return list;
		}

		private static Vector3 Middle(List<Vector3> points)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0030: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (points.Count == 0)
			{
				return Vector3.zero;
			}
			Vector3 val = points[0];
			Vector3 val2 = points[0];
			foreach (Vector3 point in points)
			{
				val = Vector3.Min(val, point);
				val2 = Vector3.Max(val2, point);
			}
			return (val + val2) * 0.5f;
		}

		private static float Distance(List<Vector3> a, List<Vector3> b)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			float num = 0f;
			foreach (Vector3 p in a)
			{
				num += Mathf.Sqrt(b.Min(delegate(Vector3 val2)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val = p - val2;
					return ((Vector3)(ref val)).sqrMagnitude;
				}));
			}
			foreach (Vector3 q in b)
			{
				num += Mathf.Sqrt(a.Min(delegate(Vector3 val2)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_0