Decompiled source of Infinity Tools v1.5.0

InfinityTools.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using InfinityHammer;
using Microsoft.CodeAnalysis;
using ServerDevcommands;
using Service;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("InfinityTools")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InfinityTools")]
[assembly: AssemblyTitle("InfinityTools")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace InfinityTools
{
	public class BuildMenuTool : Piece
	{
		public Tool? tool;
	}
	[HarmonyPatch(typeof(PieceTable), "UpdateAvailable")]
	public static class UpdateAvailable
	{
		private static Piece Build(Tool tool)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			BuildMenuTool buildMenuTool = new GameObject().AddComponent<BuildMenuTool>();
			buildMenuTool.tool = tool;
			((Piece)buildMenuTool).m_description = tool.Description;
			((Piece)buildMenuTool).m_name = tool.Name;
			((Piece)buildMenuTool).m_icon = tool.Icon;
			return (Piece)(object)buildMenuTool;
		}

		private static void Postfix(PieceTable __instance)
		{
			if (!Configuration.IsCheats)
			{
				return;
			}
			string text = Hammer.Get();
			List<Tool> list = ToolManager.Get(text);
			int num = 0;
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			foreach (Tool item in list)
			{
				num = item.TabIndex ?? num;
				if (__instance.m_availablePieces.Count <= num)
				{
					break;
				}
				if (!dictionary.ContainsKey(num))
				{
					dictionary[num] = ((!(text == "hammer")) ? (__instance.m_availablePieces[num].Count - 1) : 0);
				}
				int val = item.Index ?? (dictionary[num] + 1);
				List<Piece> list2 = __instance.m_availablePieces[num];
				val = Math.Min(val, list2.Count);
				list2.Insert(val, Build(item));
				dictionary[num] = val;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "SetSelectedPiece", new Type[] { typeof(Vector2Int) })]
	public class RunBuildMenuCommands
	{
		[HarmonyPriority(200)]
		public static bool Prefix(Player __instance, Vector2Int p)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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)
			Piece piece = __instance.GetPiece(p);
			BuildMenuTool buildMenuTool = default(BuildMenuTool);
			if (Object.op_Implicit((Object)(object)piece) && ((Component)piece).TryGetComponent<BuildMenuTool>(ref buildMenuTool) && buildMenuTool.tool != null)
			{
				Tool tool = buildMenuTool.tool;
				if (tool.Instant)
				{
					((Terminal)Console.instance).TryRunCommand(tool.Command, false, false);
				}
				else
				{
					HoldUse.Selecting = true;
					((Terminal)Console.instance).TryRunCommand("tool " + tool.Name, false, false);
					PieceTable buildPieces = __instance.m_buildPieces;
					buildPieces.m_selectedPiece[buildPieces.m_selectedCategory] = p;
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Terminal), "TryRunCommand")]
	public class ReplaceModifierKeys
	{
		[HarmonyPriority(600)]
		private static void Prefix(ref string text)
		{
			if (!text.StartsWith("bind ", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("alias ", StringComparison.OrdinalIgnoreCase))
			{
				text = text.Replace("<mod1>", Configuration.ModifierKey1());
				text = text.Replace("<mod2>", Configuration.ModifierKey2());
			}
		}
	}
	public abstract class BaseRuler : MonoBehaviour
	{
		private static LayerMask Mask = LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "terrain" }));

		private static GameObject? basePrefab;

		public static bool SnapToGround = true;

		public bool Visible = true;

		protected List<GameObject> Segments = new List<GameObject>();

		public static float Offset = 0f;

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

		private static GameObject BasePrefab => basePrefab ?? (basePrefab = GetBasePrefab());

		protected static Vector3 BaseScale => BasePrefab.transform.localScale;

		private static GameObject GetBasePrefab()
		{
			GameObject prefab = ZNetScene.instance.GetPrefab("piece_workbench");
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				throw new InvalidOperationException("Error: Unable to find the workbench object.");
			}
			return prefab.GetComponentInChildren<CircleProjector>().m_prefab;
		}

		public void OnDestroy()
		{
			foreach (GameObject segment in Segments)
			{
				Object.Destroy((Object)(object)segment);
			}
			foreach (GameObject offsetSegment in OffsetSegments)
			{
				Object.Destroy((Object)(object)offsetSegment);
			}
			Segments.Clear();
			OffsetSegments.Clear();
		}

		public void Update()
		{
			if (!Visible)
			{
				CreateSegments(0);
				CreateOffsetSegments(0);
				return;
			}
			CreateLines();
			if (SnapToGround)
			{
				Snap();
			}
			CreateOffsetSegments(Segments.Count);
			CreateOffsetLines();
		}

		protected void CreateSegments(int count)
		{
			if (Segments.Count == count)
			{
				return;
			}
			foreach (GameObject segment in Segments)
			{
				Object.Destroy((Object)(object)segment);
			}
			Segments.Clear();
			for (int i = 0; i < count; i++)
			{
				Segments.Add(Object.Instantiate<GameObject>(BasePrefab, ((Component)this).transform));
			}
		}

		protected abstract void CreateLines();

		private void Snap()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject segment in Segments)
			{
				segment.transform.position = Snap(segment.transform.position);
			}
		}

		private Vector3 Snap(Vector3 pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(pos + Vector3.up * 500f, Vector3.down, ref val, 1000f, ((LayerMask)(ref Mask)).value))
			{
				pos.y = ((RaycastHit)(ref val)).point.y;
			}
			return pos;
		}

		private void CreateOffsetSegments(int count)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Approximately(Offset, 0f))
			{
				count = 0;
			}
			if (OffsetSegments.Count == count)
			{
				return;
			}
			foreach (GameObject offsetSegment in OffsetSegments)
			{
				Object.Destroy((Object)(object)offsetSegment);
			}
			OffsetSegments.Clear();
			for (int i = 0; i < count; i++)
			{
				OffsetSegments.Add(Object.Instantiate<GameObject>(BasePrefab, Vector3.zero, Quaternion.identity, ((Component)this).transform));
			}
		}

		private void CreateOffsetLines()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < OffsetSegments.Count; i++)
			{
				GameObject val = Segments[i];
				GameObject obj = OffsetSegments[i];
				obj.transform.localPosition = val.transform.localPosition + Vector3.up * Offset;
				obj.transform.localRotation = val.transform.localRotation;
				obj.transform.localScale = val.transform.localScale;
				obj.SetActive(val.activeSelf);
			}
		}

		protected Transform Get(int index)
		{
			return Segments[index].transform;
		}

		protected void Set(int index, Vector3 pos)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Get(index).localPosition = pos;
		}

		protected void SetRot(int index, Vector3 rot)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			Get(index).localRotation = Quaternion.LookRotation(rot, Vector3.up);
		}
	}
	public class CircleRuler : BaseRuler
	{
		public float Radius = 20f;

		private readonly float Speed = 0.1f;

		protected override void CreateLines()
		{
			int count = Math.Max(3, (int)(Radius * 4f));
			CreateSegments(count);
			UpdateLines();
		}

		private void UpdateLines()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			int count = Segments.Count;
			float num = (float)Math.PI * 2f / (float)count;
			float num2 = Time.time * Speed;
			Vector3 pos = default(Vector3);
			for (int i = 0; i < count; i++)
			{
				float num3 = (float)i * num + num2;
				((Vector3)(ref pos))..ctor(Mathf.Sin(num3) * Radius, 0f, Mathf.Cos(num3) * Radius);
				Set(i, pos);
			}
			for (int j = 0; j < count; j++)
			{
				GameObject obj = ((j == 0) ? Segments[Segments.Count - 1] : Segments[j - 1]);
				GameObject val = ((j == Segments.Count - 1) ? Segments[0] : Segments[j + 1]);
				Vector3 val2 = obj.transform.localPosition - val.transform.localPosition;
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				SetRot(j, normalized);
			}
		}
	}
	public class RectangleRuler : BaseRuler
	{
		public float Width = 20f;

		public float Depth = 20f;

		private void EdgeFix(int index, float percent, float max, float start, float end, Vector3 direction)
		{
			//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_0034: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_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_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			float num = percent * max;
			Transform val = Get(index);
			Vector3 baseScale = BaseRuler.BaseScale;
			if (num - start < 0.5f)
			{
				baseScale.z *= num - start + 0.5f;
				val.localPosition += direction * (0.5f - baseScale.z / 2f);
			}
			if (end - num < 0.5f)
			{
				baseScale.z *= Mathf.Max(0f, end - num + 0.5f);
				val.localPosition -= direction * (0.5f - baseScale.z / 2f);
			}
			if (baseScale.z == 0f)
			{
				((Component)val).gameObject.SetActive(false);
			}
			else
			{
				((Component)val).gameObject.SetActive(true);
			}
			val.localScale = baseScale;
		}

		protected override void CreateLines()
		{
			float num = 2f * Width + 2f * Depth;
			int num2 = Math.Max(3, (int)num);
			int num3 = (int)Mathf.Max(2f, Mathf.Ceil((float)num2 * Depth / num));
			int num4 = (int)Mathf.Max(2f, Mathf.Ceil((float)num2 * Width / num));
			num2 = 2 * (num3 + num4);
			CreateSegments(num2);
			UpdateLines(num4, num3);
		}

		private void UpdateLines(int w, int d)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: 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_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_01ca: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: 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_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: 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_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			int count = Segments.Count;
			int num = 0;
			int num2 = 0;
			while (num2 < d)
			{
				SetRot(num, Vector3.forward);
				num2++;
				num++;
			}
			int num3 = 0;
			while (num3 < w)
			{
				SetRot(num, Vector3.right);
				num3++;
				num++;
			}
			int num4 = 0;
			while (num4 < d)
			{
				SetRot(num, Vector3.back);
				num4++;
				num++;
			}
			int num5 = 0;
			while (num5 < w)
			{
				SetRot(num, Vector3.left);
				num5++;
				num++;
			}
			num = 0;
			float num6 = Time.time * 0.025f * (float)(count - 4);
			float num7 = 0.5f;
			Vector3 val = Width * Vector3.left - (Depth + num7) * Vector3.forward;
			float num8 = 0.5f;
			float end = num8 + 2f * Depth;
			float num9 = 2f * Depth * (float)d / (float)(d - 1);
			float num10 = num6 / (float)d;
			int num11 = 0;
			while (num11 < d)
			{
				float num12 = ((float)num11 / (float)d + num10) % 1f;
				Vector3 pos = val + num12 * num9 * Vector3.forward;
				Set(num, pos);
				EdgeFix(num, num12, num9, num8, end, Vector3.forward);
				num11++;
				num++;
			}
			val = Depth * Vector3.forward - (Width + num7) * Vector3.right;
			end = num8 + 2f * Width;
			num9 = 2f * Width * (float)w / (float)(w - 1);
			num10 = num6 / (float)w;
			int num13 = 0;
			while (num13 < w)
			{
				float num14 = ((float)num13 / (float)w + num10) % 1f;
				Vector3 pos2 = val + num14 * num9 * Vector3.right;
				Set(num, pos2);
				EdgeFix(num, num14, num9, num8, end, Vector3.right);
				num13++;
				num++;
			}
			val = Width * Vector3.right - (Depth + num7) * Vector3.back;
			end = num8 + 2f * Depth;
			num9 = 2f * Depth * (float)d / (float)(d - 1);
			num10 = num6 / (float)d;
			int num15 = 0;
			while (num15 < d)
			{
				float num16 = ((float)num15 / (float)d + num10) % 1f;
				Vector3 pos3 = val + num16 * num9 * Vector3.back;
				Set(num, pos3);
				EdgeFix(num, num16, num9, num8, end, Vector3.back);
				num15++;
				num++;
			}
			val = Depth * Vector3.back - (Width + num7) * Vector3.left;
			end = num8 + 2f * Width;
			num9 = 2f * Width * (float)w / (float)(w - 1);
			num10 = num6 / (float)w;
			int num17 = 0;
			while (num17 < w)
			{
				float num18 = ((float)num17 / (float)w + num10) % 1f;
				Vector3 pos4 = val + num18 * num9 * Vector3.left;
				Set(num, pos4);
				EdgeFix(num, num18, num9, num8, end, Vector3.left);
				num17++;
				num++;
			}
		}
	}
	public class RulerParameters
	{
		public bool Radius;

		public bool Ring;

		public bool Width;

		public bool Grid;

		public bool Depth;

		public bool Height;

		public bool RotateWithPlayer;

		public bool IsTargeted;

		public bool IsId;
	}
	public enum RulerShape
	{
		Circle,
		Ring,
		Frame,
		Square,
		Rectangle
	}
	public class Ruler
	{
		public static RulerShape Shape;

		public static GameObject? Projector;

		public static GameObject? Circle;

		public static GameObject? Ring;

		public static GameObject? Rectangle;

		public static GameObject? Square;

		public static GameObject? Frame;

		public static bool IsActive => (Object)(object)Projector != (Object)null;

		public static void SanityCheckShape()
		{
			if (Shape == RulerShape.Circle && (!Object.op_Implicit((Object)(object)Circle) || !Configuration.ShapeCircle))
			{
				Shape = RulerShape.Ring;
			}
			if (Shape == RulerShape.Ring && (!Object.op_Implicit((Object)(object)Ring) || !Configuration.ShapeRing))
			{
				Shape = RulerShape.Square;
			}
			if (Shape == RulerShape.Square && (!Object.op_Implicit((Object)(object)Square) || !Configuration.ShapeSquare))
			{
				Shape = RulerShape.Frame;
			}
			if (Shape == RulerShape.Frame && (!Object.op_Implicit((Object)(object)Frame) || !Configuration.ShapeFrame))
			{
				Shape = RulerShape.Rectangle;
			}
			if (Shape == RulerShape.Rectangle && (!Object.op_Implicit((Object)(object)Rectangle) || !Configuration.ShapeRectangle))
			{
				Shape = RulerShape.Circle;
			}
		}

		private static void SetTerrainGrid(float width, float height)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			bool flag = Math.Floor((double)width / 0.5) % 2.0 == 0.0;
			bool flag2 = Math.Floor((double)height / 0.5) % 2.0 == 0.0;
			Grid.SetPreciseMode(new Vector3(flag ? 0f : 0.5f, 0f, flag2 ? 0f : 0.5f));
		}

		private static void BuildCircle(GameObject obj, float radius)
		{
			CircleRuler component = obj.GetComponent<CircleRuler>();
			component.Visible = obj.activeSelf;
			component.Radius = radius;
		}

		private static void BuildRectangle(GameObject obj, float width, float depth)
		{
			RectangleRuler component = obj.GetComponent<RectangleRuler>();
			component.Visible = obj.activeSelf;
			component.Width = width;
			component.Depth = depth;
		}

		public static void Update()
		{
			//IL_00dd: 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_007e: 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_009c: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_0122: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)Projector == (Object)null || !Object.op_Implicit((Object)(object)localPlayer) || !(Selection.Get() is ToolSelection toolSelection))
			{
				return;
			}
			GameObject placementGhost = localPlayer.m_placementGhost;
			Transform transform = ((Component)localPlayer).transform;
			Projector.SetActive(Object.op_Implicit((Object)(object)placementGhost));
			if (!Object.op_Implicit((Object)(object)placementGhost))
			{
				return;
			}
			Transform transform2 = placementGhost.transform;
			ScalingData val = Scaling.Get();
			Tool tool = toolSelection.Tool;
			if (tool.IsTargetEdge)
			{
				Vector3 position = default(Vector3);
				((Vector3)(ref position))..ctor((transform.position.x + transform2.position.x) / 2f, transform2.position.y, (transform.position.z + transform2.position.z) / 2f);
				Projector.transform.position = position;
			}
			else
			{
				Projector.transform.position = transform2.position;
			}
			Quaternion rotation = transform2.rotation;
			float num = ((Quaternion)(ref rotation)).eulerAngles.y;
			if (tool.RotateWithPlayer)
			{
				num = Vector3.SignedAngle(Vector3.forward, Utils.DirectionXZ(transform2.position - transform.position), Vector3.up);
			}
			if (((BaseSelection)toolSelection).TerrainGrid)
			{
				num = 0f;
			}
			Projector.transform.rotation = Quaternion.Euler(0f, num, 0f);
			if (tool.IsTargetEdge)
			{
				float scaleZ = Utils.DistanceXZ(transform.position, transform2.position) / 2f;
				val.SetScaleZ(scaleZ);
			}
			SanityCheckShape();
			RulerShape shape = Shape;
			if (((BaseSelection)toolSelection).TerrainGrid)
			{
				val.SetPrecisionXZ(0.25f, 0.5f);
			}
			if ((Object)(object)Circle != (Object)null)
			{
				Circle.SetActive(shape == RulerShape.Circle || shape == RulerShape.Ring);
				BuildCircle(Circle, val.X);
				if (Circle.activeSelf && ((BaseSelection)toolSelection).TerrainGrid)
				{
					SetTerrainGrid(val.X, val.X);
				}
			}
			if ((Object)(object)Circle != (Object)null && (Object)(object)Ring != (Object)null)
			{
				Ring.SetActive(shape == RulerShape.Ring);
				BuildCircle(Ring, val.Z);
			}
			if ((Object)(object)Square != (Object)null)
			{
				Square.SetActive(shape == RulerShape.Square || shape == RulerShape.Frame);
				BuildRectangle(Square, val.X, val.X);
				if (Square.activeSelf && ((BaseSelection)toolSelection).TerrainGrid)
				{
					SetTerrainGrid(val.X, val.X);
				}
			}
			if ((Object)(object)Square != (Object)null && (Object)(object)Frame != (Object)null)
			{
				Frame.SetActive(shape == RulerShape.Frame);
				BuildRectangle(Frame, val.Z, val.Z);
				if (Frame.activeSelf && ((BaseSelection)toolSelection).TerrainGrid)
				{
					SetTerrainGrid(val.Z, val.Z);
				}
			}
			if ((Object)(object)Rectangle != (Object)null)
			{
				Rectangle.SetActive(shape == RulerShape.Rectangle);
				BuildRectangle(Rectangle, val.X, val.Z);
				if (Rectangle.activeSelf && ((BaseSelection)toolSelection).TerrainGrid)
				{
					SetTerrainGrid(val.X, val.Z);
				}
			}
			if (tool.Highlight)
			{
				if (shape == RulerShape.Circle)
				{
					HighlightCircle(Projector.transform.position, val.X, val.Y);
				}
				if (shape == RulerShape.Ring)
				{
					HighlightRing(Projector.transform.position, val.X, val.Z, val.Y);
				}
				if (shape == RulerShape.Square)
				{
					HighlightRectangle(Projector.transform.position, num, val.X, val.X, val.Y);
				}
				if (shape == RulerShape.Frame)
				{
					HighlightFrame(Projector.transform.position, num, val.X, val.Z, val.Y);
				}
				if (shape == RulerShape.Rectangle)
				{
					HighlightRectangle(Projector.transform.position, num, val.X, val.Z, val.Y);
				}
			}
			BaseRuler.SnapToGround = toolSelection.Tool.SnapGround;
			BaseRuler.Offset = (toolSelection.Tool.Height ? val.Y : 0f);
		}

		public static string DescriptionScale(ToolSelection selection)
		{
			if ((Object)(object)Projector == (Object)null)
			{
				return "";
			}
			Tool tool = selection.Tool;
			ScalingData val = Scaling.Get();
			string text = (tool.Height ? (", h: " + Format2(val.Y)) : "");
			switch (Shape)
			{
			case RulerShape.Rectangle:
				return "w: " + Format2(val.X) + ", d: " + Format2(val.Z) + text;
			case RulerShape.Square:
				return "w: " + Format2(val.X) + text;
			case RulerShape.Circle:
				return "r: " + Format2(val.X) + text;
			case RulerShape.Ring:
			{
				float f3 = Mathf.Min(val.X, val.Z);
				float f4 = Mathf.Max(val.X, val.Z);
				return "r: " + Format2(f3) + "-" + Format2(f4) + text;
			}
			case RulerShape.Frame:
			{
				float f = Mathf.Min(val.X, val.Z);
				float f2 = Mathf.Max(val.X, val.Z);
				return "w: " + Format2(f) + "-" + Format2(f2) + text;
			}
			default:
				return "";
			}
		}

		public static string DescriptionPosition()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Projector == (Object)null)
			{
				return "";
			}
			Vector3 position = Projector.transform.position;
			return "x: " + Format1(position.x) + ", z: " + Format1(position.z) + ", y: " + Format1(position.y);
		}

		private static string Format1(float f)
		{
			return f.ToString("F1", CultureInfo.InvariantCulture);
		}

		private static string Format2(float f)
		{
			return f.ToString("F2", CultureInfo.InvariantCulture);
		}

		private static GameObject InitializeGameObject()
		{
			//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_001a: Expected O, but got Unknown
			Projector = new GameObject
			{
				layer = LayerMask.NameToLayer("character_trigger")
			};
			return Projector;
		}

		private static GameObject CreateCircle(GameObject obj)
		{
			GameObject obj2 = CreateChild(obj);
			obj2.AddComponent<CircleRuler>();
			return obj2;
		}

		private static GameObject CreateRectangle(GameObject obj)
		{
			GameObject obj2 = CreateChild(obj);
			obj2.AddComponent<RectangleRuler>();
			return obj2;
		}

		private static GameObject CreateChild(GameObject obj)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0037: Expected O, but got Unknown
			GameObject val = new GameObject();
			val.transform.SetParent(obj.transform);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			return val;
		}

		public static void Constrain(Range<float?> size, Range<float?> height)
		{
			ScalingData val = Scaling.Get();
			if (size.Min.HasValue && size.Max.HasValue)
			{
				val.SetScaleX(Mathf.Clamp(val.X, size.Min.Value, size.Max.Value));
				val.SetScaleZ(Mathf.Clamp(val.Z, size.Min.Value, size.Max.Value));
			}
			if (height.Min.HasValue && height.Max.HasValue)
			{
				val.SetScaleY(Mathf.Clamp(val.Y, height.Min.Value, height.Max.Value));
			}
		}

		public static void InitializeProjector(Tool tool, GameObject obj)
		{
			if (tool.Width)
			{
				Square = CreateRectangle(obj);
			}
			if (tool.Frame)
			{
				Frame = CreateRectangle(obj);
			}
			if (tool.Width && tool.Depth)
			{
				Rectangle = CreateRectangle(obj);
			}
			if (tool.Radius)
			{
				Circle = CreateCircle(obj);
			}
			if (tool.Ring)
			{
				Ring = CreateCircle(obj);
			}
		}

		public static void Create(Tool tool)
		{
			Remove();
			if (tool.Radius || tool.Width || tool.Depth)
			{
				InitializeProjector(tool, InitializeGameObject());
			}
		}

		public static void Remove()
		{
			if ((Object)(object)Projector != (Object)null)
			{
				Object.Destroy((Object)(object)Projector);
			}
			Projector = null;
			if ((Object)(object)Circle != (Object)null)
			{
				Object.Destroy((Object)(object)Circle);
			}
			Circle = null;
			if ((Object)(object)Ring != (Object)null)
			{
				Object.Destroy((Object)(object)Ring);
			}
			Ring = null;
			if ((Object)(object)Frame != (Object)null)
			{
				Object.Destroy((Object)(object)Frame);
			}
			Frame = null;
			if ((Object)(object)Rectangle != (Object)null)
			{
				Object.Destroy((Object)(object)Rectangle);
			}
			Rectangle = null;
			if ((Object)(object)Square != (Object)null)
			{
				Object.Destroy((Object)(object)Square);
			}
			Square = null;
		}

		private static void HighlightCircle(Vector3 center, float radius, float height)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Range<float> val = new Range<float>(radius);
			foreach (WearNTear s_allInstance in WearNTear.s_allInstances)
			{
				if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, val, height))
				{
					s_allInstance.Highlight();
				}
			}
		}

		private static void HighlightRing(Vector3 center, float radius1, float radius2, float height)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Min(radius1, radius2);
			float num2 = Mathf.Max(radius1, radius2);
			Range<float> val = new Range<float>(num, num2);
			foreach (WearNTear s_allInstance in WearNTear.s_allInstances)
			{
				if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, val, height))
				{
					s_allInstance.Highlight();
				}
			}
		}

		private static void HighlightRectangle(Vector3 center, float angle, float width, float depth, float height)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			Range<float> val = new Range<float>(width);
			Range<float> val2 = new Range<float>(depth);
			foreach (WearNTear s_allInstance in WearNTear.s_allInstances)
			{
				if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, angle, val, val2, height))
				{
					s_allInstance.Highlight();
				}
			}
		}

		private static void HighlightFrame(Vector3 center, float angle, float size1, float size2, float height)
		{
			//IL_0057: 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)
			float num = Mathf.Min(size1, size2);
			Mathf.Max(size1, size2);
			Range<float> val = new Range<float>(num);
			foreach (WearNTear s_allInstance in WearNTear.s_allInstances)
			{
				if (Object.op_Implicit((Object)(object)s_allInstance) && Object.op_Implicit((Object)(object)s_allInstance.m_nview) && s_allInstance.m_nview.GetZDO() != null && Selector.Within(s_allInstance.m_nview.GetZDO().GetPosition(), center, angle, val, val, height))
				{
					s_allInstance.Highlight();
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateWearNTearHover")]
	public class UpdateWearNTearHover
	{
		private static bool Prefix()
		{
			return !Ruler.IsActive;
		}
	}
	[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
	public class AddExtraInfo
	{
		private static Vector2? DefaultOffset;

		private static Vector2? ToolOffset;

		private static string DescriptionHover()
		{
			if (Object.op_Implicit((Object)(object)Ruler.Projector))
			{
				return "";
			}
			ZNetView hovered = Selector.GetHovered(Configuration.Range, new string[0], Configuration.IgnoredIds);
			string text = (((Object)(object)hovered == (Object)null) ? "" : Utils.GetPrefabName(((Component)hovered).gameObject));
			return "id: " + text;
		}

		private static string Description(ToolSelection selection)
		{
			if (Hud.instance.m_pieceSelectionWindow.activeSelf)
			{
				return "";
			}
			string[] source = new string[3]
			{
				DescriptionHover(),
				Ruler.DescriptionScale(selection),
				Ruler.DescriptionPosition()
			};
			return string.Join("\n", source.Where((string s) => s != ""));
		}

		private static void Prefix(Hud __instance)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			RectTransform rectTransform = __instance.m_pieceDescription.rectTransform;
			if (!DefaultOffset.HasValue)
			{
				DefaultOffset = rectTransform.offsetMin;
			}
			if (!ToolOffset.HasValue)
			{
				ToolOffset = new Vector2(rectTransform.offsetMin.x, -160f);
			}
			if (rectTransform.offsetMin != DefaultOffset.Value)
			{
				rectTransform.offsetMin = DefaultOffset.Value;
			}
		}

		private static void Postfix(Hud __instance, Piece piece)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)piece) || !(Selection.Get() is ToolSelection selection) || !ToolOffset.HasValue)
			{
				return;
			}
			RectTransform rectTransform = __instance.m_pieceDescription.rectTransform;
			if (rectTransform.offsetMin != ToolOffset.Value)
			{
				rectTransform.offsetMin = ToolOffset.Value;
			}
			if (!Hud.instance.m_pieceSelectionWindow.activeSelf)
			{
				string text = Description(selection);
				if (__instance.m_pieceDescription.text != "")
				{
					text = "\n" + text;
				}
				TMP_Text pieceDescription = __instance.m_pieceDescription;
				pieceDescription.text += text;
			}
		}
	}
	public class ToolSelection : BaseSelection
	{
		public Tool Tool;

		public override bool IsTool => true;

		public override bool Continuous => Tool.Continuous;

		public override bool PlayerHeight => Tool.PlayerHeight;

		public override bool TerrainGrid => Tool.TerrainGrid;

		public ToolSelection(Tool tool)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			Tool = tool;
			ScalingData val = Scaling.Get(true);
			if (tool.InitialHeight.HasValue)
			{
				val.SetScaleY(tool.InitialHeight.Value);
			}
			if (tool.InitialSize.HasValue)
			{
				val.SetScaleX(tool.InitialSize.Value);
				val.SetScaleZ(tool.InitialSize.Value);
			}
			if (tool.InitialShape != "")
			{
				Ruler.Shape = (Enum.TryParse<RulerShape>(tool.InitialShape, ignoreCase: true, out var result) ? result : RulerShape.Circle);
			}
			base.SelectedPrefab = new GameObject();
			Piece obj = base.SelectedPrefab.AddComponent<Piece>();
			obj.m_name = tool.Name;
			obj.m_icon = tool.Icon;
			obj.m_description = tool.Description;
			obj.m_clipEverything = true;
			Ruler.Create(tool);
		}

		public override float MaxPlaceDistance(float value)
		{
			return 1000f;
		}

		public override bool IsScalingSupported()
		{
			return true;
		}

		public override void AfterPlace(GameObject obj)
		{
			HandleCommand(obj);
		}

		private void HandleCommand(GameObject obj)
		{
			//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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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)
			PlacedCommand placedCommand = obj.AddComponent<PlacedCommand>();
			Transform transform = HammerHelper.GetPlacementGhost().transform;
			string newValue = transform.position.x.ToString(CultureInfo.InvariantCulture);
			string newValue2 = transform.position.y.ToString(CultureInfo.InvariantCulture);
			string newValue3 = transform.position.z.ToString(CultureInfo.InvariantCulture);
			ScalingData val = Scaling.Get();
			string text = val.X.ToString(CultureInfo.InvariantCulture);
			string text2 = Mathf.Min(val.X, val.Z).ToString(CultureInfo.InvariantCulture);
			string text3 = Mathf.Max(val.X, val.Z).ToString(CultureInfo.InvariantCulture);
			string newValue4 = val.Z.ToString(CultureInfo.InvariantCulture);
			string text4 = val.X.ToString(CultureInfo.InvariantCulture);
			RulerShape shape = Ruler.Shape;
			if (shape == RulerShape.Circle)
			{
				text2 = text;
				text3 = text;
			}
			if (shape != RulerShape.Rectangle)
			{
				newValue4 = text4;
			}
			if (shape == RulerShape.Square)
			{
				text2 = text;
				text3 = text;
			}
			if (shape == RulerShape.Rectangle)
			{
				text2 = text4;
				text3 = text4;
			}
			string newValue5 = val.Y.ToString(CultureInfo.InvariantCulture);
			Quaternion rotation = transform.rotation;
			string newValue6 = ((Quaternion)(ref rotation)).eulerAngles.y.ToString(CultureInfo.InvariantCulture);
			if (((BaseSelection)this).TerrainGrid)
			{
				newValue6 = "0";
			}
			string text5 = Tool.Command;
			if (text5.Contains("<r>") && (text5.Contains("<w>") || text5.Contains("<d>")))
			{
				text5 = RemoveUnusedShapeParameters(text5, shape);
			}
			if (text5.Contains("<id>"))
			{
				ZNetView hovered = Selector.GetHovered(Configuration.Range, new string[0], Configuration.IgnoredIds);
				if ((Object)(object)hovered == (Object)null)
				{
					Helper.AddError((Terminal)(object)Console.instance, "Nothing is being hovered.", true);
					return;
				}
				text5 = text5.Replace("<id>", Utils.GetPrefabName(((Component)hovered).gameObject));
			}
			text5 = ((shape != RulerShape.Frame) ? text5.Replace("<d>", newValue4) : text5.Replace("<d>", text2 + "-" + text3));
			text5 = text5.Replace("<r>", text);
			text5 = text5.Replace("<r2>", text3);
			text5 = text5.Replace("<w>", text4);
			text5 = text5.Replace("<w2>", text3);
			text5 = text5.Replace("<a>", newValue6);
			text5 = text5.Replace("<x>", newValue);
			text5 = text5.Replace("<y>", newValue2);
			text5 = text5.Replace("<z>", newValue3);
			text5 = text5.Replace("<h>", newValue5);
			text5 = text5.Replace("<ignore>", Configuration.configIgnoredIds.Value);
			if (!Configuration.DisableMessages)
			{
				((Terminal)Console.instance).AddString("Hammering command: " + text5);
			}
			placedCommand.Command = text5;
		}

		private string RemoveUnusedShapeParameters(string command, RulerShape shape)
		{
			bool flag = shape == RulerShape.Circle || shape == RulerShape.Ring;
			string[] array = MultiCommands.Split(command);
			for (int i = 0; i < array.Length; i++)
			{
				List<string> list = array[i].Split(new char[1] { ' ' }).ToList();
				for (int num = list.Count - 1; num > -1; num--)
				{
					if (flag && (list[num].Contains("<w>") || list[num].Contains("<d>")))
					{
						list.RemoveAt(num);
					}
					if (!flag && list[num].Contains("<r>"))
					{
						list.RemoveAt(num);
					}
				}
				array[i] = string.Join(" ", list);
			}
			return string.Join("; ", array);
		}

		public override void Activate()
		{
			((BaseSelection)this).Activate();
			BindCommand.SetMode("command");
			Ruler.Create(Tool);
		}

		public override void Deactivate()
		{
			((BaseSelection)this).Deactivate();
			Ruler.Remove();
			BindCommand.SetMode("");
		}
	}
	public class PlacedCommand : MonoBehaviour
	{
		public string Command = "";

		public void Start()
		{
			if (Command != "")
			{
				((Terminal)Console.instance).TryRunCommand(Command, false, false);
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	public class ToolCmdCommand
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ConsoleEvent <0>__Execute;
		}

		public ToolCmdCommand()
		{
			//IL_0020: 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_002b: Expected O, but got Unknown
			object obj = <>O.<0>__Execute;
			if (obj == null)
			{
				ConsoleEvent val = Execute;
				<>O.<0>__Execute = val;
				obj = (object)val;
			}
			Helper.Command("tool_cmd", "[command] - Selects a command to be used when placed.", (ConsoleEvent)obj);
			AutoComplete.RegisterEmpty("tool_cmd");
			AutoComplete.Offsets["tool_cmd"] = 0;
		}

		protected static void Execute(ConsoleEventArgs args)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Helper.ArgsCheck(args, 2, "Missing the command.");
			if (!Hammer.HasAny())
			{
				Hammer.Equip();
			}
			string text = string.Join(" ", args.Args, 1, args.Length - 1);
			Tool tool = new Tool(new ToolData
			{
				name = "Command",
				command = text,
				description = text
			});
			Hammer.Clear();
			Selection.CreateGhost((BaseSelection)(object)new ToolSelection(tool));
			PlaceRotation.Set(Quaternion.identity);
			HammerHelper.Message(args.Context, "Selected command " + tool.Name + ".");
		}
	}
	public class ToolCommand
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ConsoleEvent <0>__Execute;
		}

		public ToolCommand()
		{
			//IL_0020: 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_002b: Expected O, but got Unknown
			object obj = <>O.<0>__Execute;
			if (obj == null)
			{
				ConsoleEvent val = Execute;
				<>O.<0>__Execute = val;
				obj = (object)val;
			}
			Helper.Command("tool", "[tool] - Selects a tool to be used when placed.", (ConsoleEvent)obj);
			AutoComplete.Register("tool", (Func<int, int, List<string>>)((int index, int subIndex) => (from tool in ToolManager.GetAll()
				select tool.Name).ToList()));
		}

		protected static void Execute(ConsoleEventArgs args)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			Helper.ArgsCheck(args, 2, "Missing the tool name.");
			if (!Hammer.HasAny())
			{
				Hammer.Equip();
			}
			string text = string.Join(" ", args.Args, 1, args.Length - 1);
			if (!ToolManager.TryGetTool(Hammer.Get(), text, out Tool tool))
			{
				tool = new Tool(new ToolData
				{
					name = "Command",
					command = text,
					description = text
				});
			}
			Hammer.Clear();
			Selection.CreateGhost((BaseSelection)(object)new ToolSelection(tool));
			PlaceRotation.Set(Quaternion.identity);
			HammerHelper.Message(args.Context, "Selected tool " + tool.Name + ".");
		}
	}
	public class ToolData
	{
		[DefaultValue("")]
		public string name = "";

		[DefaultValue("")]
		public string description = "";

		[DefaultValue("")]
		public string icon = "";

		public string command = "";

		[DefaultValue("")]
		public string continuous = "";

		[DefaultValue("")]
		public string initialHeight = "";

		[DefaultValue("")]
		public string initialSize = "";

		[DefaultValue("")]
		public string initialShape = "";

		[DefaultValue("false")]
		public string targetEdge = "false";

		[DefaultValue("false")]
		public string snapGround = "false";

		[DefaultValue("")]
		public string playerHeight = "";

		[DefaultValue("false")]
		public string highlight = "false";

		[DefaultValue("false")]
		public string terrainGrid = "false";

		[DefaultValue(null)]
		public bool? instant;

		[DefaultValue(null)]
		public int? tabIndex;

		[DefaultValue(null)]
		public int? index;
	}
	public class Tool
	{
		public string Name;

		public string Command;

		private readonly string description;

		private readonly string iconName;

		private Sprite? icon;

		private readonly string continuous;

		public float? InitialHeight;

		public float? InitialSize;

		public string InitialShape;

		private readonly string snapGround;

		private readonly string playerHeight;

		private readonly string highlight;

		private readonly string terrainGrid;

		public bool Instant;

		public int? TabIndex;

		public int? Index;

		public bool Radius;

		public bool Ring;

		public bool Width;

		public bool Frame;

		public bool Depth;

		public bool Height;

		public bool RotateWithPlayer;

		private readonly string targetEdge;

		public bool IsId;

		public string Description => ReplaceKeys(description);

		public Sprite? Icon => icon ?? (icon = HammerHelper.FindSprite(iconName));

		public bool Continuous
		{
			get
			{
				if (!(continuous == "true"))
				{
					return HammerHelper.IsDown(ReplaceKeys(continuous));
				}
				return true;
			}
		}

		public bool SnapGround
		{
			get
			{
				if (!(snapGround == "true"))
				{
					return HammerHelper.IsDown(ReplaceKeys(snapGround));
				}
				return true;
			}
		}

		public bool PlayerHeight
		{
			get
			{
				if (!(playerHeight == "true"))
				{
					return HammerHelper.IsDown(ReplaceKeys(playerHeight));
				}
				return true;
			}
		}

		public bool Highlight
		{
			get
			{
				if (!(highlight == "true"))
				{
					return HammerHelper.IsDown(ReplaceKeys(highlight));
				}
				return true;
			}
		}

		public bool TerrainGrid
		{
			get
			{
				if (!(terrainGrid == "true"))
				{
					return HammerHelper.IsDown(ReplaceKeys(terrainGrid));
				}
				return true;
			}
		}

		public bool IsTargetEdge
		{
			get
			{
				if (!(targetEdge == "true"))
				{
					return HammerHelper.IsDown(ReplaceKeys(targetEdge));
				}
				return true;
			}
		}

		public Tool(ToolData data)
		{
			Name = data.name;
			Command = Plain(MultiCommands.Split(ReplaceHelpers(data.command)));
			description = data.description.Replace("\\n", "\n");
			iconName = data.icon;
			continuous = data.continuous;
			InitialHeight = ((data.initialHeight == "") ? null : new float?(Parse.Float(data.initialHeight, 0f)));
			InitialSize = ((data.initialSize == "") ? null : new float?(Parse.Float(data.initialSize, 0f)));
			InitialShape = data.initialShape;
			snapGround = data.snapGround;
			playerHeight = data.playerHeight;
			highlight = data.highlight;
			terrainGrid = data.terrainGrid;
			TabIndex = data.tabIndex;
			targetEdge = data.targetEdge;
			Index = data.index;
			Instant = !Command.Contains("<") && !Command.Contains("hammer ");
			Instant = ((!data.instant.HasValue) ? Instant : data.instant.Value);
			ParseParameters(Command);
		}

		private string ReplaceHelpers(string command)
		{
			return command.Replace("hoe_", "tool_").Replace("hammer_command", "").Replace("<area>", "from=<x>,<z>,<y> circle=<r>-<r2> angle=<a> rect=<w>-<w2>,<d>")
				.Replace("<place>", "from=<x>,<z>,<y>")
				.Replace("<to>", "to=<x>,<z>,<y> circle=<r>-<r2> rect=<w>-<w2>,<d>");
		}

		private void ParseParameters(string command)
		{
			string[] array = command.Split(new char[1] { ' ' }).ToArray();
			RotateWithPlayer = true;
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].Contains("<id>"))
				{
					IsId = true;
				}
				if (array[i].Contains("<a>"))
				{
					RotateWithPlayer = false;
				}
				if (array[i].Contains("<r>"))
				{
					Radius = true;
				}
				if (array[i].Contains("<r2>"))
				{
					Ring = true;
				}
				if (array[i].Contains("<w>"))
				{
					Width = true;
				}
				if (array[i].Contains("<w2>"))
				{
					Frame = true;
				}
				if (array[i].Contains("<d>"))
				{
					Depth = true;
				}
				if (array[i].Contains("<h>"))
				{
					Height = true;
				}
			}
		}

		private static string ReplaceKeys(string text)
		{
			string newValue = ((object)(Key)(ref ZInput.instance.GetButtonDef("AltPlace").m_key)).ToString().ToLowerInvariant();
			return text.Replace("<mod1>", Configuration.ModifierKey1()).Replace("<mod2>", Configuration.ModifierKey2()).Replace("<alt>", newValue);
		}

		private static string Plain(string[] commands)
		{
			for (int i = 0; i < commands.Length; i++)
			{
				commands[i] = Aliasing.Plain(commands[i]);
			}
			return string.Join("; ", commands);
		}
	}
	public class InitialData
	{
		public static string Get()
		{
			return "hammer:\n- name: Pipette\n  description: |-\n    Press <mod1> to pick up.\n    Press <mod2> to freeze.\n  icon: hammer\n  command: hammer pick=<mod1> freeze=<mod2>\n  index: 1\n- name: Building pipette\n  description: |-\n    Select entire buildings.\n    Press <mod1> to pick up.\n    Press <mod2> to freeze.\n  icon: hammer\n  command: hammer connect pick=<mod1> freeze=<mod2>\n- name: Area pipette\n  description: |-\n    Select multiple objects.\n    Press <mod1> to pick up.\n    Press <mod2> to freeze.\n  icon: hammer\n  command: hammer pick=<mod1> freeze=<mod2> height=<h> <area>\n  initialHeight: 0\n  highlight: true\nhoe:\n- name: Level\n  description: |-\n    Flattens terrain.\n    Hold <mod1> to smooth.\n    Hold <mod2> for free mode.\n    Hold <alt> for player height.\n  icon: mud_road\n  command: terrain level smooth=<mod1>?.5:0 <area>\n  index: 10\n  terrainGrid: -<mod2>\n  playerHeight: <alt>\n- name: Raise\n  description: |-\n    Raises terrain.\n    Hold <mod1> to smooth.\n    Hold <mod2> for free mode.\n  icon: raise\n  command: terrain raise=<h> smooth=<mod1>?.5:0 <area>\n  initialHeight: 0.2\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: Pave\n  description: |-\n    Paves terrain.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: paved_road\n  command: terrain paint=paved <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: Grass\n  description: |-\n    Grass.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: replant\n  command: terrain paint=grass <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: Dirt\n  description: |-\n    Dirt.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: Hoe\n  command: terrain paint=dirt <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: Cultivate\n  description: |-\n    Cultivates terrain.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: cultivate\n  command: terrain paint=cultivated <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: DarkGrass\n  description: |-\n    Dark Grass.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: trophyabomination\n  command: terrain paint=grass_dark <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: PatchyGrass\n  description: |-\n    Patchy Grass.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: iron_wall_2x2\n  command: terrain paint=patches <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: MossyPaving\n  description: |-\n    Paving with moss.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: trophygreydwarfshaman\n  command: terrain paint=paved_moss <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: DarkPaving\n  description: |-\n    Dark Paving.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: tar\n  command: terrain paint=paved_dark <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: Reset\n  description: |-\n    Resets terrain.\n    Hold <mod1> for single use.\n    Hold <mod2> for free mode.\n  icon: Hoe\n  command: terrain reset <area>\n  continuous: -<mod1>\n  terrainGrid: -<mod2>\n  snapGround : true\n- name: Slope\n  description: Slope between you and aim point.\n  icon: wood_wall_roof_45\n  command: terrain slope <to>\n  targetEdge: true\n  initialShape: rectangle\n- name: Remove\n  description: |-\n    Removes objects.\n    Hold <mod1> to also reset the terrain.\n  icon: softdeath\n  command: object remove id=* <area>;terrain keys=<mod1> reset <area>\n  highlight: true\n- name: Tame\n  description: |-\n    Tames creatures.\n    Hold <mod1> to untame\n  icon: Carrot\n  command: object tame keys=-<mod1> <area>;object wild keys=<mod1> <area>\n";
		}
	}
	public class ToolExportCommand
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ConsoleEvent <0>__Execute;
		}

		public ToolExportCommand()
		{
			//IL_0020: 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_002b: Expected O, but got Unknown
			object obj = <>O.<0>__Execute;
			if (obj == null)
			{
				ConsoleEvent val = Execute;
				<>O.<0>__Execute = val;
				obj = (object)val;
			}
			Helper.Command("tool_export", "[name] - Exports a tool", (ConsoleEvent)obj);
			AutoComplete.Register("tool_export", (Func<int, int, List<string>>)((int index, int subIndex) => (from tool in ToolManager.GetAll()
				select tool.Name).ToList()));
		}

		protected static void Execute(ConsoleEventArgs args)
		{
			Helper.ArgsCheck(args, 2, "Missing the tool name.");
			string text = string.Join(" ", args.Args, 1, args.Length - 1);
			string text2 = ToolManager.Export(Hammer.Get(), text);
			if (string.IsNullOrEmpty(text2))
			{
				HammerHelper.Message(args.Context, "Unable to find the tool " + text + ".");
				return;
			}
			GUIUtility.systemCopyBuffer = text2;
			HammerHelper.Message(args.Context, "Exported tool " + text + " to the clipboard.");
		}
	}
	public class ToolImportCommand
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static ConsoleEvent <0>__Execute;
		}

		public ToolImportCommand()
		{
			//IL_0020: 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_002b: Expected O, but got Unknown
			object obj = <>O.<0>__Execute;
			if (obj == null)
			{
				ConsoleEvent val = Execute;
				<>O.<0>__Execute = val;
				obj = (object)val;
			}
			Helper.Command("tool_import", "[hammer/hoe/etc[data] - Imports a new tool.", (ConsoleEvent)obj);
			AutoComplete.Register("tool_import", (Func<int, int, List<string>>)delegate(int index, int subIndex)
			{
				if (index == 0)
				{
					List<string> list = new List<string>();
					{
						foreach (string key in ToolManager.Tools.Keys)
						{
							list.Add(key);
						}
						return list;
					}
				}
				return ParameterInfo.Create("Tool data");
			});
		}

		protected static void Execute(ConsoleEventArgs args)
		{
			Helper.ArgsCheck(args, 2, "Missing the equipment.");
			Helper.ArgsCheck(args, 3, "Missing the tool data.");
			string text = args[1];
			string tool = string.Join(" ", args.Args, 2, args.Length - 2);
			ToolData toolData = ToolManager.Import(text, tool);
			HammerHelper.Message(args.Context, "Imported tool " + toolData.name + " to " + text + ".");
		}
	}
	[HarmonyPatch]
	public class ToolManager
	{
		public const string CmdMod1 = "<mod1>";

		public const string CmdMod2 = "<mod2>";

		public const string CmdAlt = "<alt>";

		public static string FilePath = Path.Combine(Paths.ConfigPath, "infinity_tools.yaml");

		public static string Pattern = "infinity_tools.yaml";

		private static Dictionary<string, List<ToolData>> ToolData = new Dictionary<string, List<ToolData>>();

		public static Dictionary<string, List<Tool>> Tools = new Dictionary<string, List<Tool>>();

		public static void CreateFile()
		{
			if (!File.Exists(FilePath))
			{
				File.WriteAllText(FilePath, InitialData.Get());
			}
		}

		public static void ToFile()
		{
			string contents = Yaml.Serializer().Serialize((object)ToolData);
			File.WriteAllText(FilePath, contents);
		}

		public static ToolData Import(string equipment, string tool)
		{
			ToolData toolData = Yaml.Deserialize<ToolData>(tool.Replace("\\n", "\n"), "Import");
			Add(equipment, toolData);
			return toolData;
		}

		public static void Add(string equipment, ToolData tool)
		{
			if (!ToolData.ContainsKey(equipment))
			{
				ToolData.Add(equipment, new List<ToolData>());
			}
			ToolData[equipment].Add(tool);
			ToFile();
		}

		public static string Export(string equipment, string name)
		{
			if (!TryGetToolData(equipment, name, out ToolData tool) && !TryGetToolData(name, out tool, out equipment))
			{
				return "";
			}
			string text = Yaml.Serializer().Serialize((object)tool).Replace("\r\n", "\\n")
				.Replace("\n", "\\n");
			return "tool_import " + equipment + " " + text;
		}

		public static bool TryGetTool(string equipment, string name, out Tool tool)
		{
			string name2 = name;
			tool = null;
			if (Tools.TryGetValue(equipment, out List<Tool> value))
			{
				tool = value.FirstOrDefault((Tool tool) => string.Equals(tool.Name, name2, StringComparison.OrdinalIgnoreCase));
			}
			if (tool == null)
			{
				tool = Tools.Values.SelectMany((List<Tool> tool) => tool).FirstOrDefault((Tool tool) => string.Equals(tool.Name, name2, StringComparison.OrdinalIgnoreCase));
			}
			return tool != null;
		}

		public static bool TryGetToolData(string equipment, string name, out ToolData tool)
		{
			string name2 = name;
			tool = null;
			if (ToolData.TryGetValue(equipment, out List<ToolData> value))
			{
				tool = value.FirstOrDefault((ToolData tool) => string.Equals(tool.name, name2, StringComparison.OrdinalIgnoreCase));
				return tool != null;
			}
			return tool != null;
		}

		public static bool TryGetToolData(string name, out ToolData tool, out string equipment)
		{
			tool = null;
			equipment = "";
			foreach (KeyValuePair<string, List<ToolData>> toolDatum in ToolData)
			{
				foreach (ToolData item in toolDatum.Value)
				{
					if (string.Equals(item.name, name, StringComparison.OrdinalIgnoreCase))
					{
						tool = item;
						equipment = toolDatum.Key;
						return true;
					}
				}
			}
			return false;
		}

		public static List<Tool> Get(string equipment)
		{
			if (!Tools.TryGetValue(equipment, out List<Tool> value))
			{
				return new List<Tool>();
			}
			return value;
		}

		public static List<Tool> GetAll()
		{
			return Tools.SelectMany<KeyValuePair<string, List<Tool>>, Tool>((KeyValuePair<string, List<Tool>> kvp) => kvp.Value).ToList();
		}

		public static void FromFile()
		{
			Dictionary<string, List<ToolData>> dictionary = Yaml.Read<ToolData>(Pattern, (Func<string, string, Dictionary<string, ToolData[]>>)Yaml.Deserialize<Dictionary<string, ToolData[]>>);
			if (dictionary.Count == 0)
			{
				CreateFile();
				return;
			}
			try
			{
				int num = dictionary.Values.SelectMany((List<ToolData> x) => x).Count();
				if (num == 0)
				{
					InfinityTools.Log.LogWarning((object)"Failed to load any tools.");
					return;
				}
				ToolData = dictionary.ToDictionary((KeyValuePair<string, List<ToolData>> kvp) => kvp.Key.ToLower(), (KeyValuePair<string, List<ToolData>> kvp) => kvp.Value);
				Tools = dictionary.ToDictionary((KeyValuePair<string, List<ToolData>> kvp) => kvp.Key.ToLower(), (KeyValuePair<string, List<ToolData>> kvp) => kvp.Value.Select((ToolData s) => new Tool(s)).ToList());
				InfinityTools.Log.LogInfo((object)$"Reloading {num} tools.");
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					localPlayer.UpdateAvailablePiecesList();
				}
			}
			catch (Exception ex)
			{
				InfinityTools.Log.LogError((object)ex.StackTrace);
			}
		}

		public static void SetupWatcher()
		{
			Yaml.SetupWatcher(Pattern, (Action)FromFile);
		}
	}
	public class ToolShapeCommand
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__0_1;

			internal void <.ctor>b__0_1(ConsoleEventArgs args)
			{
				if (!(Selection.Get() is ToolSelection))
				{
					return;
				}
				if (args.Length > 1)
				{
					string text = args[1].ToLower();
					if (text == RulerShape.Circle.ToString().ToLower())
					{
						Ruler.Shape = RulerShape.Circle;
					}
					else if (text == RulerShape.Ring.ToString().ToLower())
					{
						Ruler.Shape = RulerShape.Ring;
					}
					else if (text == RulerShape.Rectangle.ToString().ToLower())
					{
						Ruler.Shape = RulerShape.Rectangle;
					}
					else if (text == RulerShape.Frame.ToString().ToLower())
					{
						Ruler.Shape = RulerShape.Frame;
					}
					else
					{
						if (!(text == RulerShape.Square.ToString().ToLower()))
						{
							return;
						}
						Ruler.Shape = RulerShape.Square;
					}
				}
				else
				{
					if (Ruler.Shape == RulerShape.Circle)
					{
						Ruler.Shape = RulerShape.Ring;
					}
					else if (Ruler.Shape == RulerShape.Ring)
					{
						Ruler.Shape = RulerShape.Square;
					}
					else if (Ruler.Shape == RulerShape.Square)
					{
						Ruler.Shape = RulerShape.Frame;
					}
					else if (Ruler.Shape == RulerShape.Frame)
					{
						Ruler.Shape = RulerShape.Rectangle;
					}
					else if (Ruler.Shape == RulerShape.Rectangle)
					{
						Ruler.Shape = RulerShape.Circle;
					}
					Ruler.SanityCheckShape();
				}
				HammerHelper.Message(args.Context, $"Selection shape set to {Ruler.Shape}.");
			}
		}

		public ToolShapeCommand()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			List<string> shapes = new List<string>
			{
				RulerShape.Circle.ToString(),
				RulerShape.Rectangle.ToString(),
				RulerShape.Square.ToString()
			};
			AutoComplete.Register("tool_shape", (Func<int, int, List<string>>)((int index, int subIndex) => (index != 0) ? null : shapes));
			object obj = <>c.<>9__0_1;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					if (Selection.Get() is ToolSelection)
					{
						if (args.Length > 1)
						{
							string text = args[1].ToLower();
							if (text == RulerShape.Circle.ToString().ToLower())
							{
								Ruler.Shape = RulerShape.Circle;
							}
							else if (text == RulerShape.Ring.ToString().ToLower())
							{
								Ruler.Shape = RulerShape.Ring;
							}
							else if (text == RulerShape.Rectangle.ToString().ToLower())
							{
								Ruler.Shape = RulerShape.Rectangle;
							}
							else if (text == RulerShape.Frame.ToString().ToLower())
							{
								Ruler.Shape = RulerShape.Frame;
							}
							else
							{
								if (!(text == RulerShape.Square.ToString().ToLower()))
								{
									return;
								}
								Ruler.Shape = RulerShape.Square;
							}
						}
						else
						{
							if (Ruler.Shape == RulerShape.Circle)
							{
								Ruler.Shape = RulerShape.Ring;
							}
							else if (Ruler.Shape == RulerShape.Ring)
							{
								Ruler.Shape = RulerShape.Square;
							}
							else if (Ruler.Shape == RulerShape.Square)
							{
								Ruler.Shape = RulerShape.Frame;
							}
							else if (Ruler.Shape == RulerShape.Frame)
							{
								Ruler.Shape = RulerShape.Rectangle;
							}
							else if (Ruler.Shape == RulerShape.Rectangle)
							{
								Ruler.Shape = RulerShape.Circle;
							}
							Ruler.SanityCheckShape();
						}
						HammerHelper.Message(args.Context, $"Selection shape set to {Ruler.Shape}.");
					}
				};
				<>c.<>9__0_1 = val;
				obj = (object)val;
			}
			Helper.Command("tool_shape", "[shape] - Toggles or sets the selection shape.", (ConsoleEvent)obj);
		}
	}
	public class Configuration
	{
		public static ConfigEntry<bool> configShapeCircle;

		public static ConfigEntry<bool> configShapeRing;

		public static ConfigEntry<bool> configShapeSquare;

		public static ConfigEntry<bool> configShapeRectangle;

		public static ConfigEntry<bool> configShapeFrame;

		public static ConfigEntry<bool> configIgnoreWards;

		public static ConfigEntry<bool> configShowCommandValues;

		public static ConfigEntry<KeyboardShortcut> shapeKey;

		public static ConfigEntry<KeyboardShortcut> commandRadius;

		public static ConfigEntry<KeyboardShortcut> commandRotate;

		public static ConfigEntry<KeyboardShortcut> commandDepth;

		public static ConfigEntry<KeyboardShortcut> commandHeight;

		public static ConfigEntry<KeyboardShortcut> commandModifier1;

		public static ConfigEntry<KeyboardShortcut> commandModifier2;

		public static ConfigEntry<string> commandHeightAmount;

		public static ConfigWrapper Wrapper;

		public static bool ShapeCircle => configShapeCircle.Value;

		public static bool ShapeRing => configShapeRing.Value;

		public static bool ShapeSquare => configShapeSquare.Value;

		public static bool ShapeRectangle => configShapeRectangle.Value;

		public static bool ShapeFrame => configShapeFrame.Value;

		public static bool AlwaysShowCommand => configShowCommandValues.Value;

		public static string ModifierKey1()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (commandModifier1 == null)
			{
				return "leftalt";
			}
			return ConfigWrapper.GetKeys(commandModifier1.Value);
		}

		public static string ModifierKey2()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (commandModifier2 == null)
			{
				return "leftcontrol";
			}
			return ConfigWrapper.GetKeys(commandModifier2.Value);
		}

		public static void Init(ConfigWrapper wrapper)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			Wrapper = wrapper;
			string text = "1. General";
			configShowCommandValues = wrapper.Bind<bool>(text, "Show command values", false, "Always shows the command in the tool descriptions.");
			configShapeCircle = wrapper.Bind<bool>(text, "Shape circle", true, "Enables circle shape for commands.");
			configShapeRing = wrapper.Bind<bool>(text, "Shape ring", false, "Enables ring shape for commands.");
			configShapeRectangle = wrapper.Bind<bool>(text, "Shape rectangle", true, "Enables rectangle shape for commands.");
			configShapeSquare = wrapper.Bind<bool>(text, "Shape square", true, "Enables square shape for commands.");
			configShapeFrame = wrapper.Bind<bool>(text, "Shape frame", false, "Enables frame shape for commands.");
			commandHeightAmount = wrapper.Bind<string>(text, "Command height amount", "0.1", "Meters to move.");
			text = "2. Binds";
			commandModifier1 = wrapper.Bind<KeyboardShortcut>(text, "Command modifier 1", new KeyboardShortcut((KeyCode)308, Array.Empty<KeyCode>()), "");
			commandModifier2 = wrapper.Bind<KeyboardShortcut>(text, "Command modifier 2", new KeyboardShortcut((KeyCode)306, Array.Empty<KeyCode>()), "");
			shapeKey = wrapper.BindCommand("tool_shape", text, "Change shape", new KeyboardShortcut((KeyCode)113, Array.Empty<KeyCode>()), "Changes the selection shape.", "command");
			commandRadius = wrapper.BindWheelCommand((Func<string>)(() => "hammer_zoom_x " + (Selection.Get().TerrainGrid ? "0.5" : "1")), text, "Command radius (mouse wheel)", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), "Changes the command radius.", "command");
			commandDepth = wrapper.BindWheelCommand((Func<string>)(() => "hammer_zoom_z " + (Selection.Get().TerrainGrid ? "0.5" : "1")), text, "Command depth (mouse wheel)", new KeyboardShortcut((KeyCode)304, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), "Changes the command rectangle depth.", "command");
			commandHeight = wrapper.BindWheelCommand((Func<string>)(() => "hammer_zoom_y " + commandHeightAmount.Value), text, "Command height (mouse wheel)", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), "Changes the command height.", "command");
			commandRotate = wrapper.BindWheelCommand("hammer_rotate", text, "Command rotation (mouse wheel)", new KeyboardShortcut((KeyCode)304, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "Changes the command rotation.", "command");
		}
	}
	public static class Hammer
	{
		public static bool IsHammer(string name)
		{
			return ToolManager.Tools.ContainsKey(name.ToLower());
		}

		public static bool IsHammer(GameObject obj)
		{
			if (Object.op_Implicit((Object)(object)obj))
			{
				return IsHammer(Utils.GetPrefabName(obj));
			}
			return false;
		}

		public static bool IsHammer(ItemData item)
		{
			if (item != null)
			{
				return IsHammer(item.m_dropPrefab);
			}
			return false;
		}

		public static bool HasHammer(Player player)
		{
			if (Object.op_Implicit((Object)(object)player))
			{
				return IsHammer(((Humanoid)player).GetRightItem());
			}
			return false;
		}

		public static void Equip()
		{
			Player player = Helper.GetPlayer();
			if (!HasHammer(player))
			{
				ItemData val = ((Humanoid)player).GetInventory().m_inventory.Find(IsHammer) ?? throw new InvalidOperationException("Unable to find the hammer.");
				((Humanoid)player).EquipItem(val, true);
			}
		}

		public static bool Is(ItemData item)
		{
			if (item != null)
			{
				return (Object)(object)item.m_shared.m_buildPieces != (Object)null;
			}
			return false;
		}

		public static bool HasAny()
		{
			Player player = Helper.GetPlayer();
			if (Object.op_Implicit((Object)(object)player))
			{
				return Is(((Humanoid)player).GetRightItem());
			}
			return false;
		}

		public static string Get()
		{
			Player player = Helper.GetPlayer();
			if (!Object.op_Implicit((Object)(object)player))
			{
				return "";
			}
			ItemData rightItem = ((Humanoid)player).GetRightItem();
			if (rightItem == null)
			{
				return "";
			}
			return Utils.GetPrefabName(rightItem.m_dropPrefab).ToLower();
		}
	}
	[BepInPlugin("infinity_tools", "Infinity Tools", "1.5")]
	[BepInDependency("world_edit_commands", "1.57")]
	[BepInDependency("server_devcommands", "1.77")]
	[BepInDependency("infinity_hammer", "1.52")]
	public class InfinityTools : BaseUnityPlugin
	{
		public const string GUID = "infinity_tools";

		public const string NAME = "Infinity Tools";

		public const string VERSION = "1.5";

		public static ManualLogSource Log;

		public static ConfigWrapper Wrapper;

		public void Awake()
		{
			//IL_0010: 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_002f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("infinity_tools").PatchAll();
			Wrapper = new ConfigWrapper("tool_config", ((BaseUnityPlugin)this).Config);
			Configuration.Init(Wrapper);
			try
			{
				SetupWatcher();
				ToolManager.CreateFile();
				ToolManager.SetupWatcher();
				ToolManager.FromFile();
			}
			catch
			{
			}
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Path.GetDirectoryName(((BaseUnityPlugin)this).Config.ConfigFilePath), Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath));
			fileSystemWatcher.NotifyFilter = NotifyFilters.Size;
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
			{
				return;
			}
			try
			{
				Log.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Log.LogError((object)("There was an issue loading your " + ((BaseUnityPlugin)this).Config.ConfigFilePath));
				Log.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		public void Start()
		{
			new ToolShapeCommand();
			new ToolCommand();
			new ToolImportCommand();
			new ToolExportCommand();
			new ToolCmdCommand();
		}

		public void LateUpdate()
		{
			Ruler.Update();
		}
	}
	[HarmonyPatch(typeof(Chat), "Awake")]
	public class SetCommands
	{
		private static bool Initialized;

		private static void CreateAlias()
		{
			if (!Initialized)
			{
				Initialized = true;
				string text = "from=<x>,<z>,<y> circle=<r>-<r2> angle=<a> rect=<w>-<w2>,<d>";
				string text2 = "from=<x>,<z>,<y> radius=<r>-<r2>";
				string text3 = "to=<x>,<z>,<y> circle=<r>-<r2> rect=<w>-<w2>,<d>";
				string substitution = Settings.Substitution;
				((Terminal)Console.instance).TryRunCommand("alias tool_terrain terrain " + text, false, false);
				((Terminal)Console.instance).TryRunCommand("alias t_t tool tool_terrain", false, false);
				((Terminal)Console.instance).TryRunCommand("alias tool_object object " + text + " height=<h> ignore=<ignore>", false, false);
				((Terminal)Console.instance).TryRunCommand("alias t_o tool tool_object", false, false);
				((Terminal)Console.instance).TryRunCommand("alias tool_spawn spawn_object " + substitution + " " + text2, false, false);
				((Terminal)Console.instance).TryRunCommand("alias t_s tool tool_spawn", false, false);
				((Terminal)Console.instance).TryRunCommand("alias tool_terrain_to terrain " + text3, false, false);
				((Terminal)Console.instance).TryRunCommand("alias tool_slope tool_terrain_to slope", false, false);
				((Terminal)Console.instance).TryRunCommand("alias tool_area hammer " + text + " height=<h>", false, false);
			}
		}

		private static void Postfix()
		{
			CreateAlias();
			InfinityTools.Wrapper.Bind();
		}
	}
}