Decompiled source of GraveBuilder v1.3.0

plugins/GraveBuilder/GraveBuilder.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using GraveFramework;
using GraveyardOrbit;
using GraveyardOrbit.UI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.TextCore.Text;
using UnityEngine.UIElements;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 GraveBuilder
{
	[HarmonyPatch(typeof(ModeSelectController), "FillOvertimeList")]
	internal static class ContractsCustomMapsPatch
	{
		private static readonly FieldInfo ListField = AccessTools.Field(typeof(ModeSelectController), "_list");

		private static readonly MethodInfo ListHeaderMethod = AccessTools.Method(typeof(ModeSelectController), "ListHeader", new Type[1] { typeof(string) }, (Type[])null);

		private static readonly MethodInfo AddRowMethod = AccessTools.Method(typeof(ModeSelectController), "AddRow", new Type[3]
		{
			typeof(VisualElement),
			typeof(StructureDef),
			typeof(bool)
		}, (Type[])null);

		private static readonly MethodInfo PaintRowsMethod = AccessTools.Method(typeof(ModeSelectController), "PaintRows", (Type[])null, (Type[])null);

		private static void Postfix(ModeSelectController __instance)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			try
			{
				if (ListField == null || ListHeaderMethod == null || AddRowMethod == null)
				{
					Plugin.Log.LogError((object)"CustomMaps: ModeSelectController._list, ListHeader(string) or AddRow(VisualElement, StructureDef, bool) not found; no CUSTOM MAPS section.");
					return;
				}
				object? value = ListField.GetValue(__instance);
				VisualElement val = (VisualElement)((value is VisualElement) ? value : null);
				StructureCatalog i = StructureCatalog.I;
				StructureDef[] array = ((i != null) ? i.Contracts : null);
				if (val == null || array == null)
				{
					return;
				}
				List<StructureDef> list = new List<StructureDef>();
				StructureDef[] array2 = array;
				foreach (StructureDef val2 in array2)
				{
					if ((Object)(object)val2 != (Object)null && StructuresInjectPatch.IsInjected(val2.id))
					{
						list.Add(val2);
					}
				}
				if (list.Count == 0)
				{
					return;
				}
				val.Add((VisualElement)ListHeaderMethod.Invoke(null, new object[1] { Loc.T("gravebuilder.contracts.custom_maps_header", "CUSTOM MAPS") }));
				foreach (StructureDef item in list)
				{
					AddRowMethod.Invoke(__instance, new object[3] { val, item, false });
				}
				PaintRowsMethod?.Invoke(__instance, null);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"CustomMaps: adding the CUSTOM MAPS section failed: {arg}");
			}
		}
	}
	internal interface IHexCanvasHost
	{
		SandboxMap Map { get; }

		bool FillMode { get; }

		bool SelectMode { get; }

		IEnumerable<Vector2Int> SelectedCells { get; }

		bool PasteActive { get; }

		IReadOnlyList<ClipCell> Clipboard { get; }

		bool BrushPreviewActive { get; }

		HexShape ShapeTool { get; }

		void StrokeBegin();

		bool StrokePaint(int q, int r, bool erase);

		void StrokeEnd();

		bool Fill(int q, int r, bool erase);

		void Hover(int q, int r);

		Color MarkerColour(string tile);

		bool SelectPaint(int q, int r, bool remove);

		void SelectEnd(bool removed);

		bool FloodSelect(int q, int r, bool remove);

		bool PasteAt(int q, int r);

		void CancelPaste();

		void BrushFootprint(int q, int r, HashSet<Vector2Int> into);

		void ShapeFootprint(HexShape shape, Vector2Int start, Vector2Int end, HashSet<Vector2Int> into);

		bool ShapeCommit(HexShape shape, Vector2Int start, Vector2Int end, bool erase);

		Color? ShapePaintColour(bool erase);
	}
	internal enum HexShape
	{
		None,
		Line,
		Circle
	}
	internal struct ClipCell
	{
		public Vector2Int Offset;

		public Cell? Cell;
	}
	internal sealed class HexCanvas : VisualElement
	{
		private struct Hex
		{
			public Vector2 Centre;

			public float Shrink;

			public Color32 Colour;
		}

		private struct Ring
		{
			public Vector2 Centre;

			public float Outer;

			public float Inner;

			public Color32 Colour;
		}

		private const float HexW = 1.71875f;

		private const float HexRow = 1.5f;

		private const float HexHalfW = 55f / 64f;

		private const float HexHalfH = 1f;

		private const float CellShrink = 0.9f;

		private const float MarkerShrink = 0.5f;

		private const float FitMargin = 0.96f;

		public const float MinZoom = 0.25f;

		public const float MaxZoom = 20f;

		private const float WheelClamp = 1.5f;

		private const float WheelBase = 1.3f;

		private const int HexesPerChunk = 8000;

		private static readonly Color EmptyColour = new Color(0.11f, 0.12f, 0.15f, 1f);

		private static readonly Color BackgroundColour = new Color(0.02f, 0.02f, 0.03f, 1f);

		private static readonly Color SelectionRingColour = new Color(0.55f, 1f, 0.95f, 1f);

		private const float SelectionRingOuter = 0.9f;

		private const float SelectionRingInner = 0.68f;

		private const float GhostAlpha = 0.55f;

		private static readonly Color GhostEmptyColour = new Color(0.02f, 0.02f, 0.03f, 0.7f);

		private static readonly Color GhostRingColour = new Color(1f, 0.72f, 0.2f, 0.9f);

		private const float GhostRingOuter = 1f;

		private const float GhostRingInner = 0.86f;

		private static readonly Color BrushWashColour = new Color(1f, 1f, 1f, 0.2f);

		private static readonly Color BrushRingColour = new Color(1f, 1f, 1f, 0.95f);

		private const float BrushRingOuter = 1f;

		private const float BrushRingInner = 0.92f;

		private static readonly Color ShapeRingColour = new Color(0.62f, 1f, 0.3f, 0.95f);

		private static readonly Color ShapeEraseRingColour = new Color(1f, 0.3f, 0.3f, 0.95f);

		private const float ShapeRingOuter = 1f;

		private const float ShapeRingInner = 0.86f;

		private const double LineNudge = 0.001;

		private const int RingsPerChunk = 5000;

		public static readonly Vector2Int[] Neighbours = (Vector2Int[])(object)new Vector2Int[6]
		{
			new Vector2Int(1, 0),
			new Vector2Int(-1, 0),
			new Vector2Int(0, 1),
			new Vector2Int(0, -1),
			new Vector2Int(1, -1),
			new Vector2Int(-1, 1)
		};

		private readonly IHexCanvasHost _host;

		private readonly VisualElement _drawLayer;

		private readonly Vector2[] _cornerOffsets = (Vector2[])(object)new Vector2[6];

		private readonly List<Hex> _hexes = new List<Hex>(4096);

		private readonly List<Ring> _selectionRings = new List<Ring>();

		private readonly List<Hex> _ghostHexes = new List<Hex>();

		private readonly List<Ring> _ghostRings = new List<Ring>();

		private readonly HashSet<Vector2Int> _brushCells = new HashSet<Vector2Int>();

		private readonly List<Hex> _brushHexes = new List<Hex>();

		private readonly List<Ring> _brushRings = new List<Ring>();

		private int _extent;

		private float _scale = 1f;

		private Vector2 _origin;

		private float _zoom = 1f;

		private Vector2 _pan = Vector2.zero;

		private bool _stroking;

		private bool _strokeErase;

		private bool _strokeSelect;

		private int _strokePointerId = -1;

		private bool _shaping;

		private HexShape _shapeKind;

		private Vector2Int _shapeStart;

		private Vector2Int _shapeEnd;

		private bool _shapeErase;

		private int _shapePointerId = -1;

		private Vector2Int _hoverCell;

		private bool _hasHover;

		private Vector2 _lastPos;

		private Vector2Int _lastCell;

		private bool _hasLastCell;

		private bool _panning;

		private int _panPointerId = -1;

		private Vector2 _panLast;

		public int Extent => _extent;

		private float ViewScale => _scale * _zoom;

		private Vector2 ViewOrigin => _origin + _pan;

		public HexCanvas(IHexCanvasHost host)
		{
			//IL_0075: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			_host = host;
			Vector3[] array = HexLayout.HexCorners(Vector3.zero, 1f);
			for (int i = 0; i < 6; i++)
			{
				_cornerOffsets[i] = new Vector2(array[i].x, 0f - array[i].z);
			}
			((VisualElement)this).style.flexGrow = StyleFloat.op_Implicit(1f);
			((VisualElement)this).style.backgroundColor = StyleColor.op_Implicit(BackgroundColour);
			((VisualElement)this).style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			((VisualElement)this).pickingMode = (PickingMode)0;
			_drawLayer = new VisualElement
			{
				pickingMode = (PickingMode)1
			};
			_drawLayer.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			_drawLayer.style.left = StyleLength.op_Implicit(0f);
			_drawLayer.style.top = StyleLength.op_Implicit(0f);
			_drawLayer.style.right = StyleLength.op_Implicit(0f);
			_drawLayer.style.bottom = StyleLength.op_Implicit(0f);
			VisualElement drawLayer = _drawLayer;
			drawLayer.generateVisualContent = (Action<MeshGenerationContext>)Delegate.Combine(drawLayer.generateVisualContent, new Action<MeshGenerationContext>(Draw));
			((VisualElement)this).Add(_drawLayer);
			((CallbackEventHandler)this).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
			{
				Repaint();
			}, (TrickleDown)0);
			((CallbackEventHandler)this).RegisterCallback<PointerDownEvent>((EventCallback<PointerDownEvent>)OnPointerDown, (TrickleDown)0);
			((CallbackEventHandler)this).RegisterCallback<PointerMoveEvent>((EventCallback<PointerMoveEvent>)OnPointerMove, (TrickleDown)0);
			((CallbackEventHandler)this).RegisterCallback<PointerUpEvent>((EventCallback<PointerUpEvent>)OnPointerUp, (TrickleDown)0);
			((CallbackEventHandler)this).RegisterCallback<PointerCaptureOutEvent>((EventCallback<PointerCaptureOutEvent>)delegate
			{
				EndStroke();
				EndShape();
				EndPan();
			}, (TrickleDown)0);
			((CallbackEventHandler)this).RegisterCallback<PointerLeaveEvent>((EventCallback<PointerLeaveEvent>)delegate
			{
				_hasHover = false;
				if (_host.PasteActive || _host.BrushPreviewActive)
				{
					Repaint();
				}
			}, (TrickleDown)0);
			((CallbackEventHandler)this).RegisterCallback<WheelEvent>((EventCallback<WheelEvent>)OnWheel, (TrickleDown)0);
			Refresh();
		}

		public void Refresh()
		{
			//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)
			SandboxMap map = _host.Map;
			int num = map?.radius ?? 0;
			if (map != null)
			{
				foreach (Vector2Int key in map.cells.Keys)
				{
					Vector2Int current = key;
					num = Mathf.Max(num, HexLayout.Distance(0, 0, ((Vector2Int)(ref current)).x, ((Vector2Int)(ref current)).y));
				}
			}
			_extent = Mathf.Max(1, num);
			Repaint();
		}

		public void Repaint()
		{
			_drawLayer.MarkDirtyRepaint();
		}

		public void ResetView()
		{
			//IL_000c: 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)
			_zoom = 1f;
			_pan = Vector2.zero;
			Repaint();
		}

		public bool InExtent(int q, int r)
		{
			return HexLayout.Distance(0, 0, q, r) <= _extent;
		}

		private void UpdateLayout()
		{
			//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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Rect contentRect = ((VisualElement)this).contentRect;
			float num = 1.71875f * (float)_extent + 55f / 64f;
			float num2 = 1.5f * (float)_extent + 1f;
			float num3 = ((Rect)(ref contentRect)).width / (2f * num);
			float num4 = ((Rect)(ref contentRect)).height / (2f * num2);
			_scale = Mathf.Max(0.0001f, Mathf.Min(num3, num4) * 0.96f);
			_origin = ((Rect)(ref contentRect)).center;
		}

		private Vector2 AxialToLocal(int q, int r)
		{
			//IL_000c: 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_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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = HexLayout.AxialToWorld(q, r, 1f, 0f);
			return ViewOrigin + new Vector2(val.x, 0f - val.z) * ViewScale;
		}

		private Vector2Int LocalToAxial(Vector2 local)
		{
			//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_000e: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			Vector2 viewOrigin = ViewOrigin;
			float viewScale = ViewScale;
			float num = (local.x - viewOrigin.x) / viewScale;
			float num2 = (0f - (0f - (local.y - viewOrigin.y)) / viewScale) / 1.5f;
			return CubeRound(num / 1.71875f - num2 * 0.5f, num2);
		}

		private static Vector2Int CubeRound(float fq, float fr)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f - fq - fr;
			int num2 = Mathf.RoundToInt(fq);
			int num3 = Mathf.RoundToInt(fr);
			int num4 = Mathf.RoundToInt(num);
			float num5 = Mathf.Abs((float)num2 - fq);
			float num6 = Mathf.Abs((float)num3 - fr);
			float num7 = Mathf.Abs((float)num4 - num);
			if (num5 > num6 && num5 > num7)
			{
				num2 = -num3 - num4;
			}
			else if (num6 > num7)
			{
				num3 = -num2 - num4;
			}
			return new Vector2Int(num2, num3);
		}

		public static void HexLine(Vector2Int a, Vector2Int b, List<Vector2Int> into)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Max(HexLayout.Distance(((Vector2Int)(ref a)).x, ((Vector2Int)(ref a)).y, ((Vector2Int)(ref b)).x, ((Vector2Int)(ref b)).y), 1);
			double num2 = (double)((Vector2Int)(ref a)).x + 0.001;
			double num3 = (double)((Vector2Int)(ref a)).y + 0.001;
			double num4 = (double)((Vector2Int)(ref b)).x + 0.001;
			double num5 = (double)((Vector2Int)(ref b)).y + 0.001;
			bool flag = false;
			Vector2Int val = default(Vector2Int);
			for (int i = 0; i <= num; i++)
			{
				double num6 = (double)i / (double)num;
				Vector2Int val2 = CubeRound((float)(num2 + (num4 - num2) * num6), (float)(num3 + (num5 - num3) * num6));
				if (!flag || !(val2 == val))
				{
					into.Add(val2);
					val = val2;
					flag = true;
				}
			}
		}

		private void Draw(MeshGenerationContext ctx)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a9: 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_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05de: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_069f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			SandboxMap map = _host.Map;
			Rect contentRect = ((VisualElement)this).contentRect;
			if (map == null || ((Rect)(ref contentRect)).width < 1f || ((Rect)(ref contentRect)).height < 1f)
			{
				return;
			}
			UpdateLayout();
			float viewScale = ViewScale;
			float num = 55f / 64f * viewScale;
			float num2 = 1f * viewScale;
			float num3 = ((Rect)(ref contentRect)).xMin - num;
			float num4 = ((Rect)(ref contentRect)).xMax + num;
			float num5 = ((Rect)(ref contentRect)).yMin - num2;
			float num6 = ((Rect)(ref contentRect)).yMax + num2;
			_hexes.Clear();
			for (int i = -_extent; i <= _extent; i++)
			{
				for (int j = -_extent; j <= _extent; j++)
				{
					if (HexLayout.Distance(0, 0, j, i) > _extent)
					{
						continue;
					}
					Vector2 val = AxialToLocal(j, i);
					if (val.x < num3 || val.x > num4 || val.y < num5 || val.y > num6)
					{
						continue;
					}
					if (map.cells.TryGetValue(new Vector2Int(j, i), out var value))
					{
						_hexes.Add(new Hex
						{
							Centre = val,
							Shrink = 0.9f,
							Colour = Color32.op_Implicit(StructureSilhouette.LayerColour((int)value.layer))
						});
						string text = value.tile ?? "substrate";
						if (text != "substrate")
						{
							_hexes.Add(new Hex
							{
								Centre = val,
								Shrink = 0.5f,
								Colour = Color32.op_Implicit(_host.MarkerColour(text))
							});
						}
					}
					else
					{
						_hexes.Add(new Hex
						{
							Centre = val,
							Shrink = 0.9f,
							Colour = Color32.op_Implicit(EmptyColour)
						});
					}
				}
			}
			_selectionRings.Clear();
			IEnumerable<Vector2Int> selectedCells = _host.SelectedCells;
			if (selectedCells != null)
			{
				foreach (Vector2Int item in selectedCells)
				{
					Vector2Int current = item;
					if (InExtent(((Vector2Int)(ref current)).x, ((Vector2Int)(ref current)).y))
					{
						Vector2 val2 = AxialToLocal(((Vector2Int)(ref current)).x, ((Vector2Int)(ref current)).y);
						if (!(val2.x < num3) && !(val2.x > num4) && !(val2.y < num5) && !(val2.y > num6))
						{
							_selectionRings.Add(new Ring
							{
								Centre = val2,
								Outer = 0.9f,
								Inner = 0.68f,
								Colour = Color32.op_Implicit(SelectionRingColour)
							});
						}
					}
				}
			}
			_ghostHexes.Clear();
			_ghostRings.Clear();
			IReadOnlyList<ClipCell> clipboard = _host.Clipboard;
			if (_host.PasteActive && _hasHover && clipboard != null)
			{
				foreach (ClipCell item2 in clipboard)
				{
					ClipCell current2 = item2;
					int q = ((Vector2Int)(ref _hoverCell)).x + ((Vector2Int)(ref current2.Offset)).x;
					int r = ((Vector2Int)(ref _hoverCell)).y + ((Vector2Int)(ref current2.Offset)).y;
					if (!InExtent(q, r))
					{
						continue;
					}
					Vector2 val3 = AxialToLocal(q, r);
					if (val3.x < num3 || val3.x > num4 || val3.y < num5 || val3.y > num6)
					{
						continue;
					}
					if (current2.Cell.HasValue)
					{
						Cell value2 = current2.Cell.Value;
						_ghostHexes.Add(new Hex
						{
							Centre = val3,
							Shrink = 0.9f,
							Colour = Color32.op_Implicit(Translucent(StructureSilhouette.LayerColour((int)value2.layer)))
						});
						string text2 = value2.tile ?? "substrate";
						if (text2 != "substrate")
						{
							_ghostHexes.Add(new Hex
							{
								Centre = val3,
								Shrink = 0.5f,
								Colour = Color32.op_Implicit(Translucent(_host.MarkerColour(text2)))
							});
						}
					}
					else
					{
						_ghostHexes.Add(new Hex
						{
							Centre = val3,
							Shrink = 0.9f,
							Colour = Color32.op_Implicit(GhostEmptyColour)
						});
					}
					_ghostRings.Add(new Ring
					{
						Centre = val3,
						Outer = 1f,
						Inner = 0.86f,
						Colour = Color32.op_Implicit(GhostRingColour)
					});
				}
			}
			_brushHexes.Clear();
			_brushRings.Clear();
			if (_shaping)
			{
				_brushCells.Clear();
				_host.ShapeFootprint(_shapeKind, _shapeStart, _shapeEnd, _brushCells);
				Color? val4 = _host.ShapePaintColour(_shapeErase);
				FootprintOverlay(num3, num4, num5, num6, val4.HasValue ? Color32.op_Implicit(Translucent(val4.Value)) : Color32.op_Implicit(GhostEmptyColour), Color32.op_Implicit(val4.HasValue ? ShapeRingColour : ShapeEraseRingColour), 1f, 0.86f);
			}
			else if (_hasHover && _host.BrushPreviewActive && InExtent(((Vector2Int)(ref _hoverCell)).x, ((Vector2Int)(ref _hoverCell)).y))
			{
				_brushCells.Clear();
				_host.BrushFootprint(((Vector2Int)(ref _hoverCell)).x, ((Vector2Int)(ref _hoverCell)).y, _brushCells);
				FootprintOverlay(num3, num4, num5, num6, Color32.op_Implicit(BrushWashColour), Color32.op_Implicit(BrushRingColour), 1f, 0.92f);
			}
			DrawHexes(ctx, _hexes, viewScale);
			DrawRings(ctx, _selectionRings, viewScale);
			DrawHexes(ctx, _brushHexes, viewScale);
			DrawRings(ctx, _brushRings, viewScale);
			DrawHexes(ctx, _ghostHexes, viewScale);
			DrawRings(ctx, _ghostRings, viewScale);
		}

		private static Color Translucent(Color c)
		{
			//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_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)
			return new Color(c.r, c.g, c.b, 0.55f);
		}

		private void FootprintOverlay(float minX, float maxX, float minY, float maxY, Color32 fill, Color32 ring, float ringOuter, float ringInner)
		{
			//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_0041: 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_0047: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0093: 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_00b0: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			foreach (Vector2Int brushCell in _brushCells)
			{
				Vector2Int current = brushCell;
				if (InExtent(((Vector2Int)(ref current)).x, ((Vector2Int)(ref current)).y))
				{
					Vector2 val = AxialToLocal(((Vector2Int)(ref current)).x, ((Vector2Int)(ref current)).y);
					if (!(val.x < minX) && !(val.x > maxX) && !(val.y < minY) && !(val.y > maxY))
					{
						_brushHexes.Add(new Hex
						{
							Centre = val,
							Shrink = 0.9f,
							Colour = fill
						});
						_brushRings.Add(new Ring
						{
							Centre = val,
							Outer = ringOuter,
							Inner = ringInner,
							Colour = ring
						});
					}
				}
			}
		}

		private void DrawHexes(MeshGenerationContext ctx, List<Hex> hexes, float s)
		{
			//IL_0049: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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)
			for (int i = 0; i < hexes.Count; i += 8000)
			{
				int num = Mathf.Min(8000, hexes.Count - i);
				MeshWriteData val = ctx.Allocate(num * 7, num * 36, (Texture)null);
				for (int j = 0; j < num; j++)
				{
					Hex hex = hexes[i + j];
					float num2 = s * hex.Shrink;
					val.SetNextVertex(new Vertex
					{
						position = new Vector3(hex.Centre.x, hex.Centre.y, Vertex.nearZ),
						tint = hex.Colour
					});
					for (int k = 0; k < 6; k++)
					{
						Vector2 val2 = hex.Centre + _cornerOffsets[k] * num2;
						val.SetNextVertex(new Vertex
						{
							position = new Vector3(val2.x, val2.y, Vertex.nearZ),
							tint = hex.Colour
						});
					}
					ushort num3 = (ushort)(j * 7);
					for (int l = 0; l < 6; l++)
					{
						ushort nextIndex = (ushort)(num3 + 1 + l);
						ushort nextIndex2 = (ushort)(num3 + 1 + (l + 1) % 6);
						val.SetNextIndex(num3);
						val.SetNextIndex(nextIndex);
						val.SetNextIndex(nextIndex2);
						val.SetNextIndex(num3);
						val.SetNextIndex(nextIndex2);
						val.SetNextIndex(nextIndex);
					}
				}
			}
		}

		private void DrawRings(MeshGenerationContext ctx, List<Ring> rings, float s)
		{
			//IL_0059: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_0114: 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)
			for (int i = 0; i < rings.Count; i += 5000)
			{
				int num = Mathf.Min(5000, rings.Count - i);
				MeshWriteData val = ctx.Allocate(num * 12, num * 72, (Texture)null);
				for (int j = 0; j < num; j++)
				{
					Ring ring = rings[i + j];
					float num2 = s * ring.Outer;
					float num3 = s * ring.Inner;
					for (int k = 0; k < 6; k++)
					{
						Vector2 val2 = ring.Centre + _cornerOffsets[k] * num2;
						val.SetNextVertex(new Vertex
						{
							position = new Vector3(val2.x, val2.y, Vertex.nearZ),
							tint = ring.Colour
						});
					}
					for (int l = 0; l < 6; l++)
					{
						Vector2 val3 = ring.Centre + _cornerOffsets[l] * num3;
						val.SetNextVertex(new Vertex
						{
							position = new Vector3(val3.x, val3.y, Vertex.nearZ),
							tint = ring.Colour
						});
					}
					ushort num4 = (ushort)(j * 12);
					for (int m = 0; m < 6; m++)
					{
						int num5 = (m + 1) % 6;
						ushort nextIndex = (ushort)(num4 + m);
						ushort nextIndex2 = (ushort)(num4 + num5);
						ushort nextIndex3 = (ushort)(num4 + 6 + m);
						ushort nextIndex4 = (ushort)(num4 + 6 + num5);
						val.SetNextIndex(nextIndex);
						val.SetNextIndex(nextIndex2);
						val.SetNextIndex(nextIndex4);
						val.SetNextIndex(nextIndex);
						val.SetNextIndex(nextIndex4);
						val.SetNextIndex(nextIndex2);
						val.SetNextIndex(nextIndex);
						val.SetNextIndex(nextIndex4);
						val.SetNextIndex(nextIndex3);
						val.SetNextIndex(nextIndex);
						val.SetNextIndex(nextIndex3);
						val.SetNextIndex(nextIndex4);
					}
				}
			}
		}

		private void OnPointerDown(PointerDownEvent e)
		{
			//IL_0026: 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_0030: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: 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)
			if (_stroking || _shaping || _panning)
			{
				((EventBase)e).StopPropagation();
				return;
			}
			UpdateLayout();
			Vector2 val = Vector2.op_Implicit(((PointerEventBase<PointerDownEvent>)(object)e).localPosition);
			if (((PointerEventBase<PointerDownEvent>)(object)e).button == 2)
			{
				_panning = true;
				_panPointerId = ((PointerEventBase<PointerDownEvent>)(object)e).pointerId;
				_panLast = val;
				PointerCaptureHelper.CapturePointer((IEventHandler)(object)this, ((PointerEventBase<PointerDownEvent>)(object)e).pointerId);
				((EventBase)e).StopPropagation();
			}
			else
			{
				if (((PointerEventBase<PointerDownEvent>)(object)e).button != 0 && ((PointerEventBase<PointerDownEvent>)(object)e).button != 1)
				{
					return;
				}
				bool flag = ((PointerEventBase<PointerDownEvent>)(object)e).button == 1;
				if (_host.PasteActive)
				{
					Vector2Int val2 = (_hoverCell = LocalToAxial(val));
					_hasHover = true;
					if (flag)
					{
						_host.CancelPaste();
					}
					else
					{
						_host.Hover(((Vector2Int)(ref val2)).x, ((Vector2Int)(ref val2)).y);
						_host.PasteAt(((Vector2Int)(ref val2)).x, ((Vector2Int)(ref val2)).y);
					}
					Repaint();
					((EventBase)e).StopPropagation();
					return;
				}
				HexShape shapeTool = _host.ShapeTool;
				if (shapeTool != HexShape.None)
				{
					Vector2Int val3 = (_hoverCell = LocalToAxial(val));
					_hasHover = true;
					if (InExtent(((Vector2Int)(ref val3)).x, ((Vector2Int)(ref val3)).y))
					{
						_shaping = true;
						_shapeKind = shapeTool;
						_shapeStart = val3;
						_shapeEnd = val3;
						_shapeErase = flag;
						_shapePointerId = ((PointerEventBase<PointerDownEvent>)(object)e).pointerId;
						PointerCaptureHelper.CapturePointer((IEventHandler)(object)this, ((PointerEventBase<PointerDownEvent>)(object)e).pointerId);
						_host.Hover(((Vector2Int)(ref val3)).x, ((Vector2Int)(ref val3)).y);
						Repaint();
					}
					((EventBase)e).StopPropagation();
					return;
				}
				if (_host.FillMode && _host.SelectMode)
				{
					Vector2Int val4 = LocalToAxial(val);
					if (InExtent(((Vector2Int)(ref val4)).x, ((Vector2Int)(ref val4)).y))
					{
						_host.Hover(((Vector2Int)(ref val4)).x, ((Vector2Int)(ref val4)).y);
						if (_host.FloodSelect(((Vector2Int)(ref val4)).x, ((Vector2Int)(ref val4)).y, flag))
						{
							Repaint();
						}
					}
					((EventBase)e).StopPropagation();
					return;
				}
				if (_host.FillMode && !_host.SelectMode)
				{
					Vector2Int val5 = LocalToAxial(val);
					if (InExtent(((Vector2Int)(ref val5)).x, ((Vector2Int)(ref val5)).y))
					{
						_host.Hover(((Vector2Int)(ref val5)).x, ((Vector2Int)(ref val5)).y);
						if (_host.Fill(((Vector2Int)(ref val5)).x, ((Vector2Int)(ref val5)).y, flag))
						{
							Repaint();
						}
					}
					((EventBase)e).StopPropagation();
					return;
				}
				_stroking = true;
				_strokeErase = flag;
				_strokeSelect = _host.SelectMode;
				_strokePointerId = ((PointerEventBase<PointerDownEvent>)(object)e).pointerId;
				_hasLastCell = false;
				PointerCaptureHelper.CapturePointer((IEventHandler)(object)this, ((PointerEventBase<PointerDownEvent>)(object)e).pointerId);
				if (!_strokeSelect)
				{
					_host.StrokeBegin();
				}
				_lastPos = val;
				_hoverCell = LocalToAxial(val);
				_hasHover = true;
				if (PaintAt(val))
				{
					Repaint();
				}
				((EventBase)e).StopPropagation();
			}
		}

		private void OnPointerMove(PointerMoveEvent e)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_01e0: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(((PointerEventBase<PointerMoveEvent>)(object)e).localPosition);
			if (_panning)
			{
				if ((((PointerEventBase<PointerMoveEvent>)(object)e).pressedButtons & 4) == 0)
				{
					EndPan();
					return;
				}
				_pan += val - _panLast;
				_panLast = val;
				UpdateLayout();
				_hoverCell = LocalToAxial(val);
				_hasHover = true;
				Repaint();
				((EventBase)e).StopPropagation();
				return;
			}
			if (_shaping)
			{
				if ((((PointerEventBase<PointerMoveEvent>)(object)e).pressedButtons & ((!_shapeErase) ? 1 : 2)) == 0)
				{
					EndShape();
					return;
				}
				UpdateLayout();
				Vector2Int val2 = (_hoverCell = LocalToAxial(val));
				_hasHover = true;
				if (val2 != _shapeEnd)
				{
					_shapeEnd = val2;
					_host.Hover(((Vector2Int)(ref val2)).x, ((Vector2Int)(ref val2)).y);
					Repaint();
				}
				((EventBase)e).StopPropagation();
				return;
			}
			if (!_stroking)
			{
				Rect contentRect = ((VisualElement)this).contentRect;
				if (((Rect)(ref contentRect)).width >= 1f)
				{
					UpdateLayout();
					Vector2Int val3 = LocalToAxial(val);
					_host.Hover(((Vector2Int)(ref val3)).x, ((Vector2Int)(ref val3)).y);
					bool num = !_hasHover || val3 != _hoverCell;
					_hoverCell = val3;
					_hasHover = true;
					if (num && (_host.PasteActive || _host.BrushPreviewActive))
					{
						Repaint();
					}
				}
				return;
			}
			int num2 = ((!_strokeErase) ? 1 : 2);
			if ((((PointerEventBase<PointerMoveEvent>)(object)e).pressedButtons & num2) == 0)
			{
				EndStroke();
				return;
			}
			bool flag = false;
			float num3 = Mathf.Max(1f, ViewScale * 0.5f);
			float num4 = Vector2.Distance(_lastPos, val);
			int num5 = Mathf.Max(1, Mathf.CeilToInt(num4 / num3));
			for (int i = 1; i <= num5; i++)
			{
				flag |= PaintAt(Vector2.Lerp(_lastPos, val, (float)i / (float)num5));
			}
			_lastPos = val;
			Vector2Int val4 = LocalToAxial(val);
			if (val4 != _hoverCell || !_hasHover)
			{
				_hoverCell = val4;
				_hasHover = true;
				flag |= _host.BrushPreviewActive;
			}
			if (flag)
			{
				Repaint();
			}
			((EventBase)e).StopPropagation();
		}

		private void OnPointerUp(PointerUpEvent e)
		{
			if (_stroking && ((PointerEventBase<PointerUpEvent>)(object)e).pointerId == _strokePointerId)
			{
				EndStroke();
				((EventBase)e).StopPropagation();
			}
			else if (_shaping && ((PointerEventBase<PointerUpEvent>)(object)e).pointerId == _shapePointerId)
			{
				EndShape();
				((EventBase)e).StopPropagation();
			}
			else if (_panning && ((PointerEventBase<PointerUpEvent>)(object)e).pointerId == _panPointerId && ((PointerEventBase<PointerUpEvent>)(object)e).button == 2)
			{
				EndPan();
				((EventBase)e).StopPropagation();
			}
		}

		private void OnWheel(WheelEvent e)
		{
			//IL_0001: 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)
			//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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a0: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp(e.delta.y, -1.5f, 1.5f);
			if (Mathf.Abs(num) < 0.001f)
			{
				return;
			}
			UpdateLayout();
			float num2 = Mathf.Clamp(_zoom * Mathf.Pow(1.3f, 0f - num), 0.25f, 20f);
			if (!Mathf.Approximately(num2, _zoom))
			{
				Vector2 val = VisualElementExtensions.WorldToLocal((VisualElement)(object)this, ((MouseEventBase<WheelEvent>)(object)e).mousePosition);
				float num3 = num2 / _zoom;
				_pan = (val - _origin) * (1f - num3) + _pan * num3;
				_zoom = num2;
				if (_hasHover)
				{
					_hoverCell = LocalToAxial(val);
				}
				if (_shaping)
				{
					_shapeEnd = LocalToAxial(val);
				}
				Repaint();
			}
			((EventBase)e).StopPropagation();
		}

		private void EndStroke()
		{
			if (_stroking)
			{
				_stroking = false;
				bool strokeSelect = _strokeSelect;
				_strokeSelect = false;
				int strokePointerId = _strokePointerId;
				_strokePointerId = -1;
				_hasLastCell = false;
				if (strokePointerId >= 0 && PointerCaptureHelper.HasPointerCapture((IEventHandler)(object)this, strokePointerId))
				{
					PointerCaptureHelper.ReleasePointer((IEventHandler)(object)this, strokePointerId);
				}
				if (strokeSelect)
				{
					_host.SelectEnd(_strokeErase);
				}
				else
				{
					_host.StrokeEnd();
				}
			}
		}

		private void EndShape()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (_shaping)
			{
				_shaping = false;
				int shapePointerId = _shapePointerId;
				_shapePointerId = -1;
				if (shapePointerId >= 0 && PointerCaptureHelper.HasPointerCapture((IEventHandler)(object)this, shapePointerId))
				{
					PointerCaptureHelper.ReleasePointer((IEventHandler)(object)this, shapePointerId);
				}
				_host.ShapeCommit(_shapeKind, _shapeStart, _shapeEnd, _shapeErase);
				Repaint();
			}
		}

		private void EndPan()
		{
			if (_panning)
			{
				_panning = false;
				int panPointerId = _panPointerId;
				_panPointerId = -1;
				if (panPointerId >= 0 && PointerCaptureHelper.HasPointerCapture((IEventHandler)(object)this, panPointerId))
				{
					PointerCaptureHelper.ReleasePointer((IEventHandler)(object)this, panPointerId);
				}
			}
		}

		private bool PaintAt(Vector2 local)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0012: Unknown result type (might be due to invalid IL or missing references)
			Vector2Int val = LocalToAxial(local);
			if (_hasLastCell && val == _lastCell)
			{
				return false;
			}
			_lastCell = val;
			_hasLastCell = true;
			if (!InExtent(((Vector2Int)(ref val)).x, ((Vector2Int)(ref val)).y))
			{
				return false;
			}
			_host.Hover(((Vector2Int)(ref val)).x, ((Vector2Int)(ref val)).y);
			if (!_strokeSelect)
			{
				return _host.StrokePaint(((Vector2Int)(ref val)).x, ((Vector2Int)(ref val)).y, _strokeErase);
			}
			return _host.SelectPaint(((Vector2Int)(ref val)).x, ((Vector2Int)(ref val)).y, _strokeErase);
		}
	}
	internal sealed class MapBuilderScreen : MonoBehaviour, IHexCanvasHost
	{
		private struct SpecialTileEntry
		{
			public int Alt;

			public string Key;

			public string Label;

			public bool Material;
		}

		private sealed class BandField
		{
			public string Key;

			public string Label;

			public string Default;

			public bool IsFloat;

			public float Min;

			public float Max;

			public string Tooltip;
		}

		private sealed class PanelDef
		{
			public string Id;

			public string Label;

			public float Width;

			public bool AnchorRight;

			public Action<VisualElement> Build;
		}

		private sealed class Edit
		{
			public string Label;

			public List<(Vector2Int pos, Cell? before, Cell? after)> Cells;

			public int RadiusBefore;

			public int RadiusAfter;
		}

		private sealed class LoadEntry
		{
			public string Label;

			public bool Local;

			public string Id;

			public string DefPath;

			public StructureDef Def;
		}

		private enum LibraryTab
		{
			Structures,
			Parts,
			Image,
			Export
		}

		private sealed class PartEntry
		{
			public string Name;

			public string Path;

			public int CellCount;

			public int EmptyCount;

			public Dictionary<int, int> LayerCounts;

			public Dictionary<string, int> TileCounts;
		}

		private sealed class LibraryArtFrame : VisualElement
		{
			private readonly Texture2D _tex;

			public LibraryArtFrame(Texture2D tex)
			{
				_tex = tex;
				((VisualElement)this).pickingMode = (PickingMode)1;
				((VisualElement)this).generateVisualContent = (Action<MeshGenerationContext>)Delegate.Combine(((VisualElement)this).generateVisualContent, new Action<MeshGenerationContext>(Gen));
			}

			private void Gen(MeshGenerationContext mgc)
			{
				//IL_0012: 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_00c8: 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_0199: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_tex == (Object)null)
				{
					return;
				}
				Rect r = ((VisualElement)this).contentRect;
				float cr;
				MeshWriteData mwd;
				Rect uvR;
				int vi;
				ushort[] idx;
				int ii;
				Painter2D p;
				if (!(((Rect)(ref r)).width < 1f) && !(((Rect)(ref r)).height < 1f))
				{
					float num = ((Rect)(ref r)).width * 0.023828125f;
					float num2 = ((Rect)(ref r)).height * 0.10972222f;
					float num3 = ((Rect)(ref r)).width * 0.9753906f;
					float num4 = ((Rect)(ref r)).height * 0.8715278f;
					cr = ((Rect)(ref r)).width * (1f / 64f);
					mwd = mgc.Allocate(16, 24, (Texture)(object)_tex);
					uvR = mwd.uvRegion;
					vi = 0;
					idx = new ushort[24];
					ii = 0;
					Quad(0f, 0f, ((Rect)(ref r)).width, num2);
					Quad(0f, num4, ((Rect)(ref r)).width, ((Rect)(ref r)).height);
					Quad(0f, num2, num, num4);
					Quad(num3, num2, ((Rect)(ref r)).width, num4);
					for (int i = 0; i < idx.Length; i++)
					{
						mwd.SetNextIndex(idx[i]);
					}
					p = mgc.painter2D;
					p.fillColor = ArtFrameRingColor;
					Corner(num + cr, num2 + cr, num, num2, num + cr, num2, 270f, 180f);
					Corner(num3 - cr, num2 + cr, num3, num2, num3, num2 + cr, 0f, -90f);
					Corner(num3 - cr, num4 - cr, num3, num4, num3 - cr, num4, 90f, 0f);
					Corner(num + cr, num4 - cr, num, num4, num, num4 - cr, 180f, 90f);
				}
				void Corner(float cx, float cy, float ax, float ay, float bx, float by, float a0, float a1)
				{
					//IL_0015: 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_003d: Unknown result type (might be due to invalid IL or missing references)
					//IL_004b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0052: Unknown result type (might be due to invalid IL or missing references)
					p.BeginPath();
					p.MoveTo(new Vector2(ax, ay));
					p.LineTo(new Vector2(bx, by));
					p.Arc(new Vector2(cx, cy), cr, Angle.op_Implicit(a0), Angle.op_Implicit(a1), (ArcDirection)1);
					p.ClosePath();
					p.Fill((FillRule)0);
				}
				void Quad(float ax, float ay, float bx, float by)
				{
					V(ax, ay);
					V(bx, ay);
					V(bx, by);
					V(ax, by);
					idx[ii++] = (ushort)vi;
					idx[ii++] = (ushort)(vi + 1);
					idx[ii++] = (ushort)(vi + 2);
					idx[ii++] = (ushort)(vi + 2);
					idx[ii++] = (ushort)(vi + 3);
					idx[ii++] = (ushort)vi;
					vi += 4;
				}
				void V(float px, float py)
				{
					//IL_002a: 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_0045: 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_004f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0088: Unknown result type (might be due to invalid IL or missing references)
					//IL_008d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0092: Unknown result type (might be due to invalid IL or missing references)
					float num5 = px / ((Rect)(ref r)).width;
					float num6 = 1f - py / ((Rect)(ref r)).height;
					mwd.SetNextVertex(new Vertex
					{
						position = new Vector3(px, py, Vertex.nearZ),
						tint = Color32.op_Implicit(Color.white),
						uv = new Vector2(((Rect)(ref uvR)).xMin + num5 * ((Rect)(ref uvR)).width, ((Rect)(ref uvR)).yMin + num6 * ((Rect)(ref uvR)).height)
					});
				}
			}
		}

		private const string PanelSettingsPath = "Assets/UI/Settings/CassettePanelSettings.asset";

		private const string FontPath = "Assets/UI/Fonts/SpaceGrotesk-Bold UITK.asset";

		private const float PanelSortingOrder = 900f;

		private const int DefaultRadius = 24;

		private const int MinRadius = 1;

		private const int MaxRadius = 300;

		private const int MaxBrush = 10;

		private const int DefaultImageSize = 140;

		private const int MaxImageSize = 400;

		private const int DefaultImageAlpha = 16;

		private const int DefaultStartingMoney = 500;

		private const string DefaultId = "builder_map";

		private const string DefaultName = "Builder Map";

		private const int MaxHistory = 50;

		private const int MaxHistoryCells = 2000000;

		private const string Substrate = "substrate";

		private const string Erase = "erase";

		private static readonly string[] MaterialTiles = new string[4] { "special_1", "special_2", "special_3", "meta_1" };

		private static string _lastSpecialTileLog;

		private static readonly Dictionary<string, string> SpecialTileLabel = new Dictionary<string, string>
		{
			["explosive"] = Loc.T("gravebuilder.tiles.explosive", "Explosive"),
			["lightning"] = Loc.T("gravebuilder.tiles.lightning", "Lightning"),
			["void"] = Loc.T("gravebuilder.tiles.void", "Void"),
			["swarm"] = Loc.T("gravebuilder.tiles.swarm", "Swarm"),
			["special_1"] = Loc.T("gravebuilder.tiles.laser_shard", "Laser Shard"),
			["special_2"] = Loc.T("gravebuilder.tiles.breacher_shard", "Breacher Shard"),
			["special_3"] = Loc.T("gravebuilder.tiles.dynamo_shard", "Dynamo Shard"),
			["meta_1"] = Loc.T("gravebuilder.tiles.pulse_shard", "Pulse Shard")
		};

		private static readonly Regex IdPattern = new Regex("^[a-z0-9_]+$");

		private const string PartsDirName = "parts";

		private const int MaxPartFileNameLength = 48;

		private static readonly Regex PartNameInvalid = new Regex("[^a-z0-9_]+");

		private static readonly Color Accent = MetaUi.Orange;

		private static readonly Color AccentLt = MetaUi.OrangeLt;

		private static readonly Color BodyText = MetaUi.Fade(MetaUi.Ink, 0.82f);

		private static readonly Color DimText = MetaUi.Fade(MetaUi.Ink, 0.6f);

		private static readonly Color Neutral = new Color(0.55f, 0.58f, 0.62f);

		private static readonly Color SelectedEdge = Color.white;

		private static readonly Color SwitchControl = Color32.op_Implicit(new Color32((byte)18, (byte)18, (byte)26, byte.MaxValue));

		private static readonly Color SwitchInk = Color32.op_Implicit(new Color32((byte)18, (byte)10, (byte)0, byte.MaxValue));

		private static readonly BandField[] BandFields = new BandField[12]
		{
			new BandField
			{
				Key = "layer",
				Label = Loc.T("gravebuilder.bands.layer_label", "Substrate colour"),
				Default = "1",
				Min = 1f,
				Max = 5f,
				Tooltip = Loc.T("gravebuilder.bands.layer_tooltip", "Which painted colour this stage is made of: every cell painted this colour belongs to this stage. If two stages pick the same colour, the first one gets all of its tiles.")
			},
			new BandField
			{
				Key = "outer_frac",
				Label = Loc.T("gravebuilder.bands.outer_frac_label", "Preview icon ring size"),
				Default = "1",
				IsFloat = true,
				Min = 0f,
				Max = 1f,
				Tooltip = Loc.T("gravebuilder.bands.outer_frac_tooltip", "Cosmetic only. How far out this stage's ring is drawn on the little hex icon in the Contracts list, as a fraction of the icon's radius (0 to 1). It doesn't change which tiles are in the stage.")
			},
			new BandField
			{
				Key = "hp_sealed",
				Label = Loc.T("gravebuilder.bands.hp_sealed_label", "While sealed"),
				Default = "75",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.hp_sealed_tooltip", "Hit points each of this stage's tiles has while the stage is still sealed (locked). Higher = slower to mine through. Default 75.")
			},
			new BandField
			{
				Key = "special_1",
				Label = Loc.T("gravebuilder.bands.special_1_label", "Laser shards"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.special_1_tooltip", "How many Laser Shard pickups (the shard currency used to research Mods) are seeded into this stage's tiles.")
			},
			new BandField
			{
				Key = "special_2",
				Label = Loc.T("gravebuilder.bands.special_2_label", "Breacher shards"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.special_2_tooltip", "How many Breacher Shard pickups (the shard currency used to research Mods) are seeded into this stage's tiles.")
			},
			new BandField
			{
				Key = "special_3",
				Label = Loc.T("gravebuilder.bands.special_3_label", "Dynamo shards"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.special_3_tooltip", "How many Dynamo Shard pickups (the shard currency used to research Mods) are seeded into this stage's tiles.")
			},
			new BandField
			{
				Key = "meta_1",
				Label = Loc.T("gravebuilder.bands.meta_1_label", "Pulse shards"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.meta_1_tooltip", "How many Pulse Shard pickups (the shard currency used to research Mods) are seeded into this stage's tiles.")
			},
			new BandField
			{
				Key = "explosive",
				Label = Loc.T("gravebuilder.bands.explosive_label", "Explosive"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.explosive_tooltip", "How many hidden Explosive enemy encounters are seeded into this stage's tiles. Destroying such a tile (or mining close to it) wakes the enemy.")
			},
			new BandField
			{
				Key = "lightning",
				Label = Loc.T("gravebuilder.bands.lightning_label", "Lightning"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.lightning_tooltip", "How many hidden Lightning enemy encounters are seeded into this stage's tiles. Destroying such a tile (or mining close to it) wakes the enemy.")
			},
			new BandField
			{
				Key = "void",
				Label = Loc.T("gravebuilder.bands.void_label", "Void"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.void_tooltip", "How many hidden Void enemy encounters are seeded into this stage's tiles. Destroying such a tile (or mining close to it) wakes the enemy.")
			},
			new BandField
			{
				Key = "swarm",
				Label = Loc.T("gravebuilder.bands.swarm_label", "Swarm"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.swarm_tooltip", "How many hidden Swarm enemy encounters are seeded into this stage's tiles. Destroying such a tile (or mining close to it) wakes the enemy.")
			},
			new BandField
			{
				Key = "unsealed_look",
				Label = Loc.T("gravebuilder.bands.unsealed_look_label", "Core look after unlocking"),
				Default = "0",
				Min = 0f,
				Max = 2.1474836E+09f,
				Tooltip = Loc.T("gravebuilder.bands.unsealed_look_tooltip", "Cosmetic only, no gameplay effect. Once this stage unlocks, its tiles are drawn with the look of another colour: 1 Grey, 2 Blue, 3 Pink, 4 Gold, 5 Purple. 0 keeps the colour you painted.")
			}
		};

		private const int BandLayer = 0;

		private const int BandHpSealed = 2;

		private const string PanelPalette = "palette";

		private const string PanelTools = "tools";

		private const string PanelMap = "map";

		private const float LibraryMaxWidth = 1200f;

		private const float LibraryListWidth = 640f;

		private static readonly Color WarnText = TerminalUi.Red;

		private const float PanelEdge = 14f;

		private const float PanelGap = 10f;

		private static MapBuilderScreen _instance;

		private static SandboxMap _map;

		private static string _tool = "substrate";

		private static int _layer = 1;

		private static int _brush;

		private static bool _fillMode;

		private static bool _mirror;

		private static bool _axisMirror;

		private static bool _lineMode;

		private static bool _circleMode;

		private static bool _selectMode;

		private static bool _pasteMode;

		private static bool _autoFillLoops;

		private static readonly HashSet<Vector2Int> _selection = new HashSet<Vector2Int>();

		private static readonly List<ClipCell> _clipboard = new List<ClipCell>();

		private static int _clipboardVersion;

		private static readonly Dictionary<string, bool> _panelOpen = new Dictionary<string, bool> { ["palette"] = true };

		private static LibraryTab _libraryTab = LibraryTab.Structures;

		private static readonly List<Edit> _undo = new List<Edit>();

		private static readonly List<Edit> _redo = new List<Edit>();

		private static string _radiusText = 24.ToString();

		private static string _brushText = "1";

		private static string _idText = "builder_map";

		private static string _nameText = "Builder Map";

		private static string _moneyText = 500.ToString();

		private static string _partNameText = "";

		private static string _imagePathText = "";

		private static string _imageSizeText = 140.ToString();

		private static string _imageAlphaText = 16.ToString();

		private static bool _imageLuminance;

		private static bool _imageInvert;

		private static bool _imageDither = true;

		private static readonly List<string[]> _bands = new List<string[]> { DefaultBand() };

		private static string _lastStatus;

		private static bool _lastStatusError;

		private UIDocument _doc;

		private PanelSettings _panelCopy;

		private HexCanvas _canvas;

		private bool _libraryOpen;

		private VisualElement _libraryOverlay;

		private VisualElement _stage;

		private VisualElement _tipStage;

		private VisualElement _paintTooltip;

		private Label _paintTooltipText;

		private VisualElement _paintStatusHost;

		private List<PanelDef> _panelDefs = new List<PanelDef>();

		private readonly Dictionary<string, VisualElement> _panels = new Dictionary<string, VisualElement>();

		private readonly Dictionary<string, VisualElement> _panelKeyHosts = new Dictionary<string, VisualElement>();

		private Label _hoverLabel;

		private VisualElement _statusHost;

		private VisualElement _historyRow;

		private VisualElement _toggleRow;

		private VisualElement _selectRow;

		private VisualElement _loopRow;

		private VisualElement _clipRow;

		private VisualElement _bandHost;

		private VisualElement _loadListHost;

		private VisualElement _loadDetailHost;

		private VisualElement _libraryTabRow;

		private Label _libraryCentreTitle;

		private readonly Dictionary<LibraryTab, VisualElement> _libraryTabPages = new Dictionary<LibraryTab, VisualElement>();

		private VisualElement _partSaveHost;

		private VisualElement _partsListHost;

		private VisualElement _partDetailHost;

		private TextField _partNameField;

		private TextField _radiusField;

		private TextField _imagePathField;

		private TextField _imageSizeField;

		private TextField _imageAlphaField;

		private VisualElement _imageOptionsHost;

		private VisualElement _imagePreviewHost;

		private Texture2D _imagePreviewTex;

		private Label _loadSummary;

		private Label _partsSummary;

		private SliderInt _radiusSlider;

		private TextField _brushField;

		private SliderInt _brushSlider;

		private TextField _idField;

		private TextField _nameField;

		private TextField _moneyField;

		private Label _idHint;

		private Label _nameHint;

		private Label _moneyHint;

		private readonly Dictionary<string, VisualElement> _toolHolders = new Dictionary<string, VisualElement>();

		private readonly Dictionary<string, Label> _statValues = new Dictionary<string, Label>();

		private bool _statsDirty;

		private bool _statsTickScheduled;

		private bool _shortcutsWired;

		private readonly List<LoadEntry> _loadEntries = new List<LoadEntry>();

		private readonly List<VisualElement> _loadHolders = new List<VisualElement>();

		private readonly List<(SlabFrame frame, Label name, Color family)> _loadRowPaint = new List<(SlabFrame, Label, Color)>();

		private int _loadSelected = -1;

		private int _loadHover = -1;

		private bool _structRenaming;

		private string _structRenameText;

		private readonly List<PartEntry> _partEntries = new List<PartEntry>();

		private int _partsSkipped;

		private readonly List<(SlabFrame frame, Label name, Color family)> _partRowPaint = new List<(SlabFrame, Label, Color)>();

		private int _partSelected = -1;

		private int _partHover = -1;

		private bool _partRenaming;

		private string _partRenameText;

		private VisualElement _tooltip;

		private Label _tooltipText;

		private VisualElement _tooltipOwner;

		private static readonly HashSet<StructureDef> _deletedInjected = new HashSet<StructureDef>();

		private Dictionary<Vector2Int, Cell?> _pending;

		private string _pendingLabel;

		private int _pendingRadius;

		private static bool _swapPending;

		private static float _swapPendingSince;

		private const float ArtFrameHoleX0 = 0.023828125f;

		private const float ArtFrameHoleY0 = 0.10972222f;

		private const float ArtFrameHoleX1 = 0.9753906f;

		private const float ArtFrameHoleY1 = 0.8715278f;

		private const float ArtFrameCornerR = 1f / 64f;

		private static readonly Color ArtFrameRingColor = new Color(29f / 85f, 0.35686275f, 0.41960785f);

		private const float CentreTitleBoxX0 = 0.43906f;

		private const float CentreTitleBoxX1 = 0.55898f;

		private const float CentreTitleBoxY0 = 0.03403f;

		private const float CentreTitleBoxY1 = 0.06458f;

		private static readonly (LibraryTab tab, string label)[] LibraryTabKeys = new(LibraryTab, string)[4]
		{
			(LibraryTab.Structures, Loc.T("gravebuilder.library.tab_structures", "STRUCTURES")),
			(LibraryTab.Parts, Loc.T("gravebuilder.library.tab_parts", "PARTS")),
			(LibraryTab.Image, Loc.T("gravebuilder.library.tab_image", "IMAGE")),
			(LibraryTab.Export, Loc.T("gravebuilder.library.tab_export", "EXPORT"))
		};

		private const float DetailStatsColumnWidth = 430f;

		private const float TooltipOffset = 18f;

		private const float TooltipMaxWidth = 440f;

		private const int BrushDisplayOffset = 1;

		private readonly List<Vector2Int> _lineCells = new List<Vector2Int>();

		private const float LoadThumbSize = 34f;

		private static readonly Dictionary<string, (DateTime stamp, Texture2D tex, int count)> _localThumbs = new Dictionary<string, (DateTime, Texture2D, int)>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, (DateTime stamp, Texture2D tex, int count)> _partThumbs = new Dictionary<string, (DateTime, Texture2D, int)>(StringComparer.OrdinalIgnoreCase);

		private static int _clipboardThumbVersion = -1;

		private static Texture2D _clipboardThumbTex;

		public static bool IsOpen => (Object)(object)_instance != (Object)null;

		private static bool FillActive => _fillMode;

		private static bool MirrorActive => _mirror;

		private static bool AxisMirrorActive => _axisMirror;

		private static bool SelectActive => _selectMode;

		private static bool PasteModeActive
		{
			get
			{
				if (_pasteMode)
				{
					return _clipboard.Count > 0;
				}
				return false;
			}
		}

		private static bool LineActive => _lineMode;

		private static bool CircleActive => _circleMode;

		private static bool AutoFillLoopsActive => _autoFillLoops;

		public HexShape ShapeTool
		{
			get
			{
				if (!LineActive)
				{
					if (!CircleActive)
					{
						return HexShape.None;
					}
					return HexShape.Circle;
				}
				return HexShape.Line;
			}
		}

		public SandboxMap Map => _map;

		public bool FillMode => FillActive;

		public bool SelectMode => SelectActive;

		public IEnumerable<Vector2Int> SelectedCells => _selection;

		public bool PasteActive => PasteModeActive;

		public IReadOnlyList<ClipCell> Clipboard => _clipboard;

		public bool BrushPreviewActive
		{
			get
			{
				if (!PasteModeActive && !CircleActive)
				{
					if (!LineActive && (!SelectActive || FillActive))
					{
						return !FillActive;
					}
					return true;
				}
				return false;
			}
		}

		private static List<KeyValuePair<int, string>> LiveAltToTile()
		{
			return (from kv in SandboxMap.AltToTile
				where !string.IsNullOrEmpty(kv.Value) && kv.Value != "substrate" && kv.Value != "erase"
				orderby kv.Key
				select kv).ToList();
		}

		private static Dictionary<string, int> LiveTileToAlt()
		{
			return (from kv in LiveAltToTile()
				group kv by kv.Value).ToDictionary((IGrouping<string, KeyValuePair<int, string>> g) => g.Key, (IGrouping<string, KeyValuePair<int, string>> g) => g.First().Key);
		}

		private static List<SpecialTileEntry> ResolveSpecialTiles()
		{
			Dictionary<string, int> source = LiveTileToAlt();
			List<SpecialTileEntry> list = new List<SpecialTileEntry>();
			List<SpecialTileEntry> list2 = new List<SpecialTileEntry>();
			List<SpecialTileEntry> list3 = new List<SpecialTileEntry>();
			foreach (KeyValuePair<string, int> item2 in source.OrderBy((KeyValuePair<string, int> kv) => kv.Value))
			{
				int num = Array.IndexOf(MaterialTiles, item2.Key);
				SpecialTileEntry item = new SpecialTileEntry
				{
					Alt = item2.Value,
					Key = item2.Key,
					Label = TileLabel(item2.Key),
					Material = (num >= 0)
				};
				if (item.Material)
				{
					list3.Add(item);
				}
				else if (SpecialTileLabel.ContainsKey(item2.Key))
				{
					list.Add(item);
				}
				else
				{
					list2.Add(item);
				}
			}
			list3.Sort((SpecialTileEntry a, SpecialTileEntry b) => Array.IndexOf(MaterialTiles, a.Key).CompareTo(Array.IndexOf(MaterialTiles, b.Key)));
			return list.Concat(list2).Concat(list3).ToList();
		}

		private static void LogSpecialTiles(List<SpecialTileEntry> tiles)
		{
			string text = string.Join(", ", tiles.Select((SpecialTileEntry t) => $"{t.Alt}={t.Key}({t.Label})"));
			if (!(text == _lastSpecialTileLog))
			{
				_lastSpecialTileLog = text;
				Plugin.Log.LogInfo((object)("[GraveBuilder] palette special tiles: " + text));
			}
		}

		private static void SyncGameTileToAlt()
		{
			foreach (KeyValuePair<string, int> item in LiveTileToAlt())
			{
				if (!SandboxMap.TileToAlt.ContainsKey(item.Key))
				{
					SandboxMap.TileToAlt[item.Key] = item.Value;
				}
			}
		}

		private static string FallbackTileLabel(string key)
		{
			string text = string.Join(" ", from w in key.Split(new char[1] { '_' }, StringSplitOptions.RemoveEmptyEntries)
				select char.ToUpperInvariant(w[0]) + w.Substring(1));
			if (text.Length <= 0)
			{
				return key;
			}
			return text;
		}

		private static Color HashedTileColour(string key)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			uint num = 2166136261u;
			foreach (char c in key)
			{
				num ^= c;
				num *= 16777619;
			}
			return Color.HSVToRGB((float)(num % 360) / 360f, 0.7f, 0.95f);
		}

		private static void WipeSwap(Action swap)
		{
			if (_swapPending && Time.realtimeSinceStartup - _swapPendingSince < 3f)
			{
				return;
			}
			_swapPending = true;
			_swapPendingSince = Time.realtimeSinceStartup;
			try
			{
				FlowManager.I.WipeSwap((Action)Run);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("MapBuilder: wipe transition unavailable (" + ex.Message + "); swapping instantly."));
				if (_swapPending)
				{
					Run();
				}
			}
			void Run()
			{
				_swapPending = false;
				swap();
			}
		}

		public static void Toggle()
		{
			WipeSwap(delegate
			{
				if (IsOpen)
				{
					CloseNow();
				}
				else
				{
					OpenNow();
				}
			});
		}

		public static void Open()
		{
			if (!IsOpen)
			{
				WipeSwap(OpenNow);
			}
		}

		public static void Close()
		{
			if (IsOpen)
			{
				WipeSwap(CloseNow);
			}
		}

		private static void OpenNow()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (IsOpen)
			{
				return;
			}
			PanelSettings val = AssetCatalog.Load<PanelSettings>("Assets/UI/Settings/CassettePanelSettings.asset");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"MapBuilder: PanelSettings 'Assets/UI/Settings/CassettePanelSettings.asset' not found, cannot open the map builder.");
				return;
			}
			if (_map == null)
			{
				_map = SandboxMap.NewFilled(24);
			}
			GameObject val2 = new GameObject("MapBuilderScreen");
			MapBuilderScreen mapBuilderScreen = val2.AddComponent<MapBuilderScreen>();
			mapBuilderScreen._panelCopy = Object.Instantiate<PanelSettings>(val);
			((Object)mapBuilderScreen._panelCopy).name = "MapBuilderPanel";
			mapBuilderScreen._panelCopy.sortingOrder = 900f;
			mapBuilderScreen._doc = val2.AddComponent<UIDocument>();
			mapBuilderScreen._doc.panelSettings = mapBuilderScreen._panelCopy;
			_instance = mapBuilderScreen;
			if (mapBuilderScreen._doc.rootVisualElement == null)
			{
				Plugin.Log.LogError((object)"MapBuilder: UIDocument has no root visual element, closing.");
				CloseNow();
			}
			else
			{
				mapBuilderScreen.Build(mapBuilderScreen._doc.rootVisualElement);
				Plugin.Log.LogInfo((object)"MapBuilder: opened.");
			}
		}

		private static void CloseNow()
		{
			if ((Object)(object)_instance != (Object)null)
			{
				_instance.CommitAction();
				Object.Destroy((Object)(object)((Component)_instance).gameObject);
				Plugin.Log.LogInfo((object)"MapBuilder: closed.");
			}
			_instance = null;
		}

		private void OnDestroy()
		{
			CommitAction();
			if ((Object)(object)_panelCopy != (Object)null)
			{
				Object.Destroy((Object)(object)_panelCopy);
				_panelCopy = null;
			}
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
			}
		}

		private void Build(VisualElement root)
		{
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			root.Clear();
			_stage = null;
			_tipStage = null;
			_libraryOverlay = null;
			_paintTooltip = null;
			_paintTooltipText = null;
			_paintStatusHost = null;
			_tooltip = null;
			_tooltipText = null;
			_tooltipOwner = null;
			_hoverLabel = null;
			_statusHost = null;
			_panels.Clear();
			_panelKeyHosts.Clear();
			_panelDefs = new List<PanelDef>();
			_toolHolders.Clear();
			_statValues.Clear();
			_idHint = null;
			_nameHint = null;
			_moneyHint = null;
			_loadRowPaint.Clear();
			_loadHover = -1;
			_toggleRow = null;
			_selectRow = null;
			_loopRow = null;
			_clipRow = null;
			_historyRow = null;
			_bandHost = null;
			_loadListHost = null;
			_loadDetailHost = null;
			_loadHolders.Clear();
			_libraryTabRow = null;
			_libraryTabPages.Clear();
			_partRowPaint.Clear();
			_partHover = -1;
			_partDetailHost = null;
			_partSaveHost = null;
			_partsListHost = null;
			_partNameField = null;
			_radiusField = null;
			_imagePathField = null;
			_imageSizeField = null;
			_imageAlphaField = null;
			_imageOptionsHost = null;
			_imagePreviewHost = null;
			_imagePreviewTex = null;
			_loadSummary = null;
			_partsSummary = null;
			_radiusSlider = null;
			_brushField = null;
			_brushSlider = null;
			_idField = null;
			_nameField = null;
			_moneyField = null;
			root.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			root.style.left = StyleLength.op_Implicit(0f);
			root.style.top = StyleLength.op_Implicit(0f);
			root.style.right = StyleLength.op_Implicit(0f);
			root.style.bottom = StyleLength.op_Implicit(0f);
			root.style.backgroundColor = StyleColor.op_Implicit(new Color(0f, 0f, 0f, 0.8f));
			TryApplyFont(root);
			VisualElement val = default(VisualElement);
			VisualElement foot = default(VisualElement);
			TerminalUi.Frame(root, Accent, Loc.T("gravebuilder.screen.frame_title", "MAP BUILDER"), ref val, ref foot, "map-builder-frame");
			val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)0);
			val.style.paddingLeft = StyleLength.op_Implicit(3f);
			val.style.paddingRight = StyleLength.op_Implicit(3f);
			val.style.paddingTop = StyleLength.op_Implicit(0f);
			val.style.paddingBottom = StyleLength.op_Implicit(0f);
			BuildPaintingView(val, foot);
			if (_libraryOpen)
			{
				ShowLibrary(root);
			}
			UpdateStatsNow();
			if (_lastStatus != null)
			{
				SetStatus(_lastStatus, _lastStatusError, log: false);
			}
			else
			{
				SetStatus(Loc.T("gravebuilder.status.builder_ready", "Map builder ready."), error: false, log: false);
			}
			if (!_statsTickScheduled)
			{
				_statsTickScheduled = true;
				root.schedule.Execute((Action)delegate
				{
					if (_statsDirty)
					{
						UpdateStatsNow();
					}
				}).Every(100L);
			}
			UiSfx.Wire(root);
			if (!_shortcutsWired)
			{
				IPanel panel = root.panel;
				((CallbackEventHandler)(((panel != null) ? panel.visualTree : null) ?? root)).RegisterCallback<KeyDownEvent>((EventCallback<KeyDownEvent>)OnShortcutKey, (TrickleDown)0);
				_shortcutsWired = true;
			}
		}

		private void OnShortcutKey(KeyDownEvent e)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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)
			if (!((KeyboardEventBase<KeyDownEvent>)(object)e).ctrlKey || _libraryOpen || (Object)(object)_instance != (Object)(object)this || (Object)(object)_doc == (Object)null || IsTextInput((VisualElement)/*isinst with value type is only supported in some contexts*/))
			{
				return;
			}
			VisualElement rootVisualElement = _doc.rootVisualElement;
			object obj;
			if (rootVisualElement == null)
			{
				obj = null;
			}
			else
			{
				IPanel panel = rootVisualElement.panel;
				if (panel == null)
				{
					obj = null;
				}
				else
				{
					FocusController focusController = panel.focusController;
					obj = ((focusController != null) ? focusController.focusedElement : null);
				}
			}
			if (IsTextInput((VisualElement)((obj is VisualElement) ? obj : null)))
			{
				return;
			}
			bool flag = true;
			if (IsShortcut(((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode, "undo"))
			{
				if (((KeyboardEventBase<KeyDownEvent>)(object)e).shiftKey)
				{
					Redo();
				}
				else
				{
					Undo();
				}
			}
			else if (IsShortcut(((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode, "redo"))
			{
				Redo();
			}
			else if (IsShortcut(((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode, "copy"))
			{
				Copy();
			}
			else if (IsShortcut(((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode, "cut"))
			{
				Cut();
			}
			else if (IsShortcut(((KeyboardEventBase<KeyDownEvent>)(object)e).keyCode, "paste"))
			{
				if (!PasteModeActive)
				{
					TogglePaste();
				}
			}
			else
			{
				flag = false;
			}
			if (flag)
			{
				((EventBase)e).StopPropagation();
			}
		}

		private static bool IsShortcut(KeyCode pressed, string actionId)
		{
			//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_000a: 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)
			KeyCode val = ShortcutBindings.Get(actionId);
			if ((int)val != 0)
			{
				return pressed == val;
			}
			return false;
		}

		private static bool IsTextInput(VisualElement ve)
		{
			while (ve != null)
			{
				if (ve is TextField)
				{
					return true;
				}
				ve = ve.parent;
			}
			return false;
		}

		private void BuildPaintingView(VisualElement body, VisualElement foot)
		{
			//IL_0016: 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_005c: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Expected O, but got Unknown
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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_0299: 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_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_02df: 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_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Expected O, but got Unknown
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Expected O, but got Unknown
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			_hoverLabel = MetaUi.Text(Loc.T("gravebuilder.screen.hover_none", "CELL  -"), (Face)3, 18f, DimText, 2f, false);
			((VisualElement)_hoverLabel).style.flexShrink = StyleFloat.op_Implicit(1f);
			foot.Add((VisualElement)(object)_hoverLabel);
			foot.style.paddingRight = StyleLength.op_Implicit(0f);
			VisualElement val = new VisualElement
			{
				pickingMode = (PickingMode)1
			};
			val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
			val.style.alignSelf = StyleEnum<Align>.op_Implicit((Align)4);
			val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
			val.style.flexShrink = StyleFloat.op_Implicit(0.2f);
			val.style.minWidth = StyleLength.op_Implicit(0f);
			foot.Add(val);
			val.Add(BuildStatsReadout());
			VisualElement obj = TerminalUi.FootKeys(val, 18f);
			obj.style.flexShrink = StyleFloat.op_Implicit(0f);
			obj.Add((VisualElement)(object)TerminalUi.FootKey("map-builder-library", Loc.T("gravebuilder.screen.foot_library", "STRUCTURES & PARTS"), Accent, (Action)OpenLibrary, false, 440f, false));
			obj.Add((VisualElement)(object)TerminalUi.FootKey("map-builder-close", Loc.T("gravebuilder.screen.foot_close", "CLOSE"), Accent, (Action)Close, true, 280f, false));
			_stage = new VisualElement
			{
				name = "map-builder-stage"
			};
			_stage.style.flexGrow = StyleFloat.op_Implicit(1f);
			_stage.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)0);
			_stage.style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			body.Add(_stage);
			_tipStage = _stage;
			if (_canvas == null)
			{
				_canvas = new HexCanvas(this);
			}
			_stage.Add((VisualElement)(object)_canvas);
			_canvas.Refresh();
			_statusHost = new VisualElement
			{
				pickingMode = (PickingMode)1
			};
			_statusHost.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			_statusHost.style.left = StyleLength.op_Implicit(Length.Percent(24f));
			_statusHost.style.right = StyleLength.op_Implicit(Length.Percent(24f));
			_statusHost.style.bottom = StyleLength.op_Implicit(14f);
			_stage.Add(_statusHost);
			_panelDefs = Panels();
			VisualElement val2 = new VisualElement
			{
				name = "map-builder-panel-keys",
				pickingMode = (PickingMode)1
			};
			val2.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			val2.style.left = StyleLength.op_Implicit(14f);
			val2.style.right = StyleLength.op_Implicit(14f);
			val2.style.top = StyleLength.op_Implicit(14f);
			val2.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
			val2.style.alignItems = StyleEnum<Align>.op_Implicit((Align)1);
			_stage.Add(val2);
			BuildTooltip();
			bool flag = false;
			foreach (PanelDef panelDef in _panelDefs)
			{
				if (panelDef.AnchorRight && !flag)
				{
					VisualElement val3 = new VisualElement
					{
						pickingMode = (PickingMode)1
					};
					val3.style.flexGrow = StyleFloat.op_Implicit(1f);
					val2.Add(val3);
					flag = true;
				}
				VisualElement val4 = new VisualElement
				{
					pickingMode = (PickingMode)1
				};
				val4.style.flexShrink = StyleFloat.op_Implicit(0f);
				val4.style.marginRight = StyleLength.op_Implicit(panelDef.AnchorRight ? 0f : 10f);
				((CallbackEventHandler)val4).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
				{
					LayoutPanels();
				}, (TrickleDown)0);
				val2.Add(val4);
				_panelKeyHosts[panelDef.Id] = val4;
			}
			foreach (PanelDef panelDef2 in _panelDefs)
			{
				VisualElement val5 = BuildPanel(panelDef2);
				_stage.Add(val5);
				_panels[panelDef2.Id] = val5;
				RefreshPanelKey(panelDef2.Id);
			}
			((CallbackEventHandler)_stage).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
			{
				LayoutPanels();
			}, (TrickleDown)0);
			RefreshToolButtons();
			RefreshToggles();
			RefreshClipboardButtons();
			RefreshHistoryButtons();
		}

		private VisualElement BuildStatsReadout()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_00a1: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			VisualElement val = new VisualElement
			{
				name = "map-builder-stats"
			};
			val.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)0);
			val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
			val.style.flexShrink = StyleFloat.op_Implicit(0.2f);
			val.style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			val.style.marginRight = StyleLength.op_Implicit(28f);
			VisualElement val2 = Row();
			val2.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
			val2.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)2);
			val2.style.marginBottom = StyleLength.op_Implicit(4f);
			val.Add(val2);
			ReadoutItem(val2, "cells", Loc.T("gravebuilder.stats.cells", "CELLS"), null);
			ReadoutItem(val2, "radius", Loc.T("gravebuilder.stats.radius", "RADIUS"), null);
			ReadoutItem(val2, "specials", Loc.T("gravebuilder.stats.special", "SPECIAL"), null);
			VisualElement val3 = Row();
			val3.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
			val3.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)2);
			val.Add(val3);
			for (int i = 1; i <= 5; i++)
			{
				ReadoutItem(val3, "L" + i, null, StructureSilhouette.LayerColour(i));
			}
			return AttachTooltip(val, Loc.T("gravebuilder.stats.tooltip", "Live map stats. Top line: painted cells, map radius, and special tiles (enemy markers and shards). Bottom line: painted cells of each substrate colour (Grey, Blue,