Decompiled source of PrecisionBuild v1.5.0

PrecisionBuild.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using GUIFramework;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ValheimBuildGrid;

public static class FastReflection
{
	public static Func<TTarget, TReturn> CreateGetter<TTarget, TReturn>(string fieldName)
	{
		try
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(TTarget), fieldName);
			if (fieldInfo == null)
			{
				return null;
			}
			DynamicMethod dynamicMethod = new DynamicMethod("Get_" + typeof(TTarget).Name + "_" + fieldName, typeof(TReturn), new Type[1] { typeof(TTarget) }, typeof(TTarget), skipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Ldfld, fieldInfo);
			iLGenerator.Emit(OpCodes.Ret);
			return (Func<TTarget, TReturn>)dynamicMethod.CreateDelegate(typeof(Func<TTarget, TReturn>));
		}
		catch
		{
			return null;
		}
	}

	public static Action<TTarget, TValue> CreateSetter<TTarget, TValue>(string fieldName)
	{
		try
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(TTarget), fieldName);
			if (fieldInfo == null)
			{
				return null;
			}
			DynamicMethod dynamicMethod = new DynamicMethod("Set_" + typeof(TTarget).Name + "_" + fieldName, null, new Type[2]
			{
				typeof(TTarget),
				typeof(TValue)
			}, typeof(TTarget), skipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator();
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Ldarg_1);
			iLGenerator.Emit(OpCodes.Stfld, fieldInfo);
			iLGenerator.Emit(OpCodes.Ret);
			return (Action<TTarget, TValue>)dynamicMethod.CreateDelegate(typeof(Action<TTarget, TValue>));
		}
		catch
		{
			return null;
		}
	}
}
[BepInPlugin("com.awuushy.precisionbuild", "PrecisionBuild", "1.5.0")]
[BepInProcess("valheim.exe")]
public class BuildGridPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "com.awuushy.precisionbuild";

	public const string PluginName = "PrecisionBuild";

	public const string PluginVersion = "1.5.0";

	public static ConfigEntry<bool> ModEnabled;

	public static ConfigEntry<KeyCode> ToggleGridKey;

	public static ConfigEntry<KeyCode> CycleGridSizeKey;

	public static ConfigEntry<KeyCode> CycleRotationKey;

	public static ConfigEntry<KeyCode> ToggleSnapTargetKey;

	public static ConfigEntry<float> ConfigGridSize;

	public static ConfigEntry<bool> SnapToCellCenters;

	public static ConfigEntry<bool> ShowVisualGrid;

	public static ConfigEntry<bool> ShowFootprint;

	public static ConfigEntry<bool> ShowKeyHints;

	public static ConfigEntry<bool> SnapAllPieces;

	public static ConfigEntry<string> GridColorHex;

	public static ConfigEntry<string> ActiveNodeColorHex;

	public static ConfigEntry<string> FootprintColorHex;

	public static ConfigEntry<float> GridLineWidth;

	public static ConfigEntry<int> GridRadiusCells;

	public static ConfigEntry<string> HudKeyColorHex;

	public static ConfigEntry<string> HudTextColorHex;

	public static ConfigEntry<string> HudDimColorHex;

	public static bool IsGridActive = true;

	public static float CurrentGridSize = 0.25f;

	public static float CurrentRotationDegrees = 22.5f;

	public static bool IsSnapToCenter = false;

	private static readonly float[] s_gridSizes = new float[4] { 0.125f, 0.25f, 0.5f, 1f };

	private static int s_currentSizeIndex = 1;

	private static readonly float[] s_rotationSteps = new float[4] { 90f, 45f, 22.5f, 5f };

	private static int s_currentRotationIndex = 2;

	private Harmony m_harmony;

	private static Action<Player, float> s_setPlaceRotationDegrees;

	private static float s_lastAppliedRotationDegrees = -1f;

	private static GameObject s_lastSelectedInputObj = null;

	private static bool s_lastSelectedIsInput = false;

	public static BuildGridPlugin Instance { get; private set; }

	private void Awake()
	{
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Expected O, but got Unknown
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "Enabled", true, "Master switch for PrecisionBuild mod.");
		ToggleGridKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("2. Hotkeys", "ToggleGridKey", (KeyCode)98, "Key to toggle building grid on/off. B is completely free in Valheim.");
		CycleGridSizeKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("2. Hotkeys", "CycleGridSizeKey", (KeyCode)110, "Key to cycle through grid sizes (0.125m -> 0.25m -> 0.5m -> 1.0m).");
		CycleRotationKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("2. Hotkeys", "CycleRotationKey", (KeyCode)107, "Key to cycle rotation angle steps (90° -> 45° -> 22.5° -> 5°).");
		ToggleSnapTargetKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("2. Hotkeys", "ToggleSnapTargetKey", (KeyCode)106, "Key to toggle grid snap target between Intersections (corners) and Cell Centers.");
		ConfigGridSize = ((BaseUnityPlugin)this).Config.Bind<float>("3. Grid", "DefaultGridSize", 0.25f, "Default grid cell size in meters (0.125, 0.25, 0.5, 1.0).");
		SnapToCellCenters = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Grid", "SnapToCellCenters", false, "Default snap target mode: false = Intersections (corners), true = Cell Centers.");
		ShowVisualGrid = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Grid", "ShowVisualGrid", true, "Whether to display the semi-transparent grid on the surface.");
		ShowFootprint = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Grid", "ShowFootprint", false, "Whether to display the rectangular footprint boundary of the object being placed (Default: false).");
		ShowKeyHints = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Grid", "ShowKeyHints", true, "Whether to display compact hotkey hints in the build mode HUD.");
		SnapAllPieces = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Grid", "SnapAllPieces", true, "If true, grid snapping applies to ALL building pieces (walls, floors, roofs, pillars, beams, chests, furniture, etc.).");
		GridRadiusCells = ((BaseUnityPlugin)this).Config.Bind<int>("3. Grid", "GridRadiusCells", 8, "How many grid cells to draw in each direction around the cursor.");
		GridColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("4. Visuals", "GridColor", "#F5E6CC70", "Color of the surface grid in HEX with alpha. Major lines (every 1 m) use it as is, minor lines are drawn dimmer (Default: warm ivory #F5E6CC70).");
		ActiveNodeColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("4. Visuals", "ActiveNodeColor", "#FFC857FF", "Color of the active snap marker: a cross for grid corners, a ring for cell centers (Default: amber gold #FFC857FF).");
		FootprintColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("4. Visuals", "FootprintColor", "#F5E6CCA0", "Color of the projected piece footprint outline (Default: warm ivory #F5E6CCA0).");
		GridLineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("4. Visuals", "GridLineWidth", 0.012f, "Thickness of major grid lines in meters (minor lines are 60% of it). Stays the same for every cell size.");
		HudKeyColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("4. Visuals", "HudKeyColor", "#FFC857", "HUD hint bar and notifications: color of key labels and highlighted values (Default: amber gold #FFC857).");
		HudTextColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("4. Visuals", "HudTextColor", "#F5E6CC", "HUD hint bar: color of enabled modes and current values (Default: warm ivory #F5E6CC).");
		HudDimColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("4. Visuals", "HudDimColor", "#8C8273", "HUD hint bar and notifications: color of disabled modes and separators (Default: muted stone #8C8273).");
		CurrentGridSize = Mathf.Clamp(ConfigGridSize.Value, 0.05f, 5f);
		for (int i = 0; i < s_gridSizes.Length; i++)
		{
			if (Mathf.Approximately(s_gridSizes[i], CurrentGridSize))
			{
				s_currentSizeIndex = i;
				break;
			}
		}
		IsSnapToCenter = SnapToCellCenters.Value;
		GuideRailModule.InitConfig(((BaseUnityPlugin)this).Config);
		SlopeAlignmentModule.InitConfig(((BaseUnityPlugin)this).Config);
		RugPlacementModule.InitConfig(((BaseUnityPlugin)this).Config);
		MigrateOldDefault(GridColorHex, "#FFFFFF45");
		MigrateOldDefault(ActiveNodeColorHex, "#FFFFFFFF");
		MigrateOldDefault(FootprintColorHex, "#FFFFFF85");
		MigrateOldDefault(GuideRailModule.GuideRailColorHex, "#00E5FFFF");
		MigrateOldDefault(GridLineWidth, 0.014f);
		m_harmony = new Harmony("com.awuushy.precisionbuild");
		m_harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} loaded successfully! Hotkeys: Toggle=[{2}], Size=[{3}], Rotation=[{4}], Target=[{5}], Rail=[{6}], Rugs=[{7}]", "PrecisionBuild", "1.5.0", ToggleGridKey.Value, CycleGridSizeKey.Value, CycleRotationKey.Value, ToggleSnapTargetKey.Value, GuideRailModule.ToggleGuideRailKey.Value, RugPlacementModule.ToggleRugModeKey.Value));
	}

	private void Update()
	{
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: 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 (!ModEnabled.Value)
		{
			GridRenderer.Hide();
			GuideRailModule.Reset();
			SlopeAlignmentModule.Reset();
			RugPlacementModule.Reset();
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || !((Character)localPlayer).InPlaceMode())
		{
			GridRenderer.Hide();
			GuideRailModule.Reset();
			SlopeAlignmentModule.Reset();
			RugPlacementModule.Reset();
			return;
		}
		if (IsGridActive)
		{
			SetPlayerRotationDegrees(localPlayer, CurrentRotationDegrees);
		}
		else
		{
			SetPlayerRotationDegrees(localPlayer, 22.5f);
		}
		if (IsTextInputActive())
		{
			return;
		}
		GuideRailModule.HandleInput();
		RugPlacementModule.HandleInput();
		if (Input.GetKeyDown(ToggleGridKey.Value))
		{
			IsGridActive = !IsGridActive;
			if (!IsGridActive)
			{
				GridRenderer.Hide();
			}
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)1, BuildGridLocalization.GridToggleStatus(IsGridActive, CurrentGridSize), 0, (Sprite)null, false, true);
			}
		}
		if (Input.GetKeyDown(CycleGridSizeKey.Value))
		{
			s_currentSizeIndex = (s_currentSizeIndex + 1) % s_gridSizes.Length;
			CurrentGridSize = s_gridSizes[s_currentSizeIndex];
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)1, BuildGridLocalization.GridStepChanged(CurrentGridSize), 0, (Sprite)null, false, true);
			}
		}
		if (Input.GetKeyDown(CycleRotationKey.Value))
		{
			s_currentRotationIndex = (s_currentRotationIndex + 1) % s_rotationSteps.Length;
			CurrentRotationDegrees = s_rotationSteps[s_currentRotationIndex];
			SetPlayerRotationDegrees(localPlayer, CurrentRotationDegrees);
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)1, BuildGridLocalization.RotationStepChanged(CurrentRotationDegrees), 0, (Sprite)null, false, true);
			}
		}
		if (Input.GetKeyDown(ToggleSnapTargetKey.Value))
		{
			IsSnapToCenter = !IsSnapToCenter;
			if ((Object)(object)MessageHud.instance != (Object)null)
			{
				MessageHud.instance.ShowMessage((MessageType)1, BuildGridLocalization.SnapTargetChanged(IsSnapToCenter), 0, (Sprite)null, false, true);
			}
		}
	}

	public static void SetPlayerRotationDegrees(Player p, float degrees)
	{
		if (!((Object)(object)p == (Object)null))
		{
			if (s_setPlaceRotationDegrees == null)
			{
				s_setPlaceRotationDegrees = FastReflection.CreateSetter<Player, float>("m_placeRotationDegrees");
			}
			if (s_setPlaceRotationDegrees != null && Mathf.Abs(degrees - s_lastAppliedRotationDegrees) > 0.01f)
			{
				s_setPlaceRotationDegrees(p, degrees);
				s_lastAppliedRotationDegrees = degrees;
			}
		}
	}

	private void OnDestroy()
	{
		GridRenderer.Destroy();
		GuideRailModule.Reset();
		SlopeAlignmentModule.Reset();
		RugPlacementModule.Reset();
		if (m_harmony != null)
		{
			m_harmony.UnpatchSelf();
		}
	}

	public static bool IsTextInputActive()
	{
		if (Console.IsVisible())
		{
			return true;
		}
		if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
		{
			return true;
		}
		if (TextInput.IsVisible())
		{
			return true;
		}
		if (Menu.IsVisible())
		{
			return true;
		}
		try
		{
			if (Hud.IsPieceSelectionVisible())
			{
				return true;
			}
			if ((Object)(object)Hud.instance != (Object)null && (Object)(object)Hud.instance.m_buildUi != (Object)null && Hud.instance.m_buildUi.SearchFieldFocused)
			{
				return true;
			}
		}
		catch
		{
		}
		try
		{
			if ((Object)(object)EventSystem.current != (Object)null)
			{
				GameObject currentSelectedGameObject = EventSystem.current.currentSelectedGameObject;
				if ((Object)(object)currentSelectedGameObject != (Object)null)
				{
					if ((Object)(object)currentSelectedGameObject == (Object)(object)s_lastSelectedInputObj)
					{
						return s_lastSelectedIsInput;
					}
					s_lastSelectedInputObj = currentSelectedGameObject;
					s_lastSelectedIsInput = (Object)(object)currentSelectedGameObject.GetComponent<InputField>() != (Object)null || (Object)(object)currentSelectedGameObject.GetComponent<TMP_InputField>() != (Object)null || (Object)(object)currentSelectedGameObject.GetComponent<GuiInputField>() != (Object)null;
					return s_lastSelectedIsInput;
				}
				s_lastSelectedInputObj = null;
				s_lastSelectedIsInput = false;
			}
		}
		catch
		{
		}
		return false;
	}

	private static void MigrateOldDefault<T>(ConfigEntry<T> entry, T oldDefault)
	{
		if (entry != null && object.Equals(entry.Value, oldDefault))
		{
			entry.Value = (T)((ConfigEntryBase)entry).DefaultValue;
		}
	}

	public static Color ParseColor(string hex, Color fallback)
	{
		//IL_0008: 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_0014: Unknown result type (might be due to invalid IL or missing references)
		if (string.IsNullOrEmpty(hex))
		{
			return fallback;
		}
		Color result = default(Color);
		if (ColorUtility.TryParseHtmlString(hex, ref result))
		{
			return result;
		}
		return fallback;
	}

	public static void Log(string msg)
	{
		if ((Object)(object)Instance != (Object)null)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}
	}
}
public static class BuildGridLocalization
{
	private static readonly StringBuilder s_hintBuilder = new StringBuilder(512);

	public static bool IsRussian()
	{
		if (Localization.instance != null)
		{
			string selectedLanguage = Localization.instance.GetSelectedLanguage();
			if (!string.IsNullOrEmpty(selectedLanguage) && selectedLanguage.IndexOf("Russian", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private static string HexOf(ConfigEntry<string> entry)
	{
		//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_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)
		Color fallback = BuildGridPlugin.ParseColor((string)((ConfigEntryBase)entry).DefaultValue, Color.white);
		return "#" + ColorUtility.ToHtmlStringRGBA(BuildGridPlugin.ParseColor(entry.Value, fallback));
	}

	private static string Paint(string text, ConfigEntry<string> entry)
	{
		return "<color=" + HexOf(entry) + ">" + text + "</color>";
	}

	private static string Accent(string text)
	{
		return Paint(text, BuildGridPlugin.HudKeyColorHex);
	}

	private static string Bright(string text)
	{
		return Paint(text, BuildGridPlugin.HudTextColorHex);
	}

	private static string Dim(string text)
	{
		return Paint(text, BuildGridPlugin.HudDimColorHex);
	}

	private static string OnOff(bool active, bool ru)
	{
		if (!active)
		{
			return Dim(ru ? "выкл" : "off");
		}
		return Accent(ru ? "вкл" : "on");
	}

	private static string Meters(float size, bool ru)
	{
		return string.Format(ru ? "{0:0.###} м" : "{0:0.###} m", size);
	}

	private static string Degrees(float angle)
	{
		return $"{angle:0.#}°";
	}

	public static string GridToggleStatus(bool active, float size)
	{
		bool flag = IsRussian();
		string text = (flag ? "Сетка: " : "Grid: ") + OnOff(active, flag);
		if (!active)
		{
			return text;
		}
		return text + Dim("  ·  ") + Accent(Meters(size, flag));
	}

	public static string GridStepChanged(float size)
	{
		bool flag = IsRussian();
		return (flag ? "Шаг сетки: " : "Grid step: ") + Accent(Meters(size, flag));
	}

	public static string RotationStepChanged(float angle)
	{
		return (IsRussian() ? "Шаг поворота: " : "Rotation step: ") + Accent(Degrees(angle));
	}

	public static string SnapTargetChanged(bool toCenter)
	{
		if (IsRussian())
		{
			return "Привязка: " + Accent(toCenter ? "центры ячеек" : "узлы сетки");
		}
		return "Snap: " + Accent(toCenter ? "cell centers" : "grid corners");
	}

	public static string GuideRailToggleStatus(bool active)
	{
		bool flag = IsRussian();
		return (flag ? "Направляющая: " : "Guide rail: ") + OnOff(active, flag);
	}

	public static string RugModeToggleStatus(bool active)
	{
		bool flag = IsRussian();
		string text = (flag ? "Укладка ковров: " : "Rug pass-through: ") + OnOff(active, flag);
		if (!active)
		{
			return text;
		}
		return text + Dim(flag ? "  ·  на пол под коврами" : "  ·  onto the floor below");
	}

	private static void AppendHint(string key, string label)
	{
		if (s_hintBuilder.Length > 0)
		{
			s_hintBuilder.Append(Dim("   ·   "));
		}
		s_hintBuilder.Append(Accent("[" + key + "]")).Append(' ').Append(label);
	}

	public static string CompactKeyHint(string toggleKey, string sizeKey, string rotKey, string targetKey, string railKey, string rugKey, bool active, float size, float rot, bool isCenter, bool isRailActive, bool isRugActive)
	{
		bool flag = IsRussian();
		s_hintBuilder.Length = 0;
		string text = (flag ? "сетка" : "grid");
		if (!active)
		{
			AppendHint(toggleKey, Dim(text));
			return s_hintBuilder.ToString();
		}
		AppendHint(toggleKey, Bright(text));
		AppendHint(sizeKey, Bright(Meters(size, flag)));
		AppendHint(rotKey, Bright(Degrees(rot)));
		AppendHint(targetKey, Bright((!isCenter) ? (flag ? "узлы" : "corners") : (flag ? "центры" : "centers")));
		if (railKey != null)
		{
			string text2 = (flag ? "направляющая" : "rail");
			AppendHint(railKey, isRailActive ? Bright(text2) : Dim(text2));
		}
		if (rugKey != null)
		{
			string text3 = (flag ? "ковры" : "rugs");
			AppendHint(rugKey, isRugActive ? Bright(text3) : Dim(text3));
		}
		return s_hintBuilder.ToString();
	}

	public static string KeyName(KeyCode key)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Invalid comparison between Unknown and I4
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Invalid comparison between Unknown and I4
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Invalid comparison between Unknown and I4
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Invalid comparison between Unknown and I4
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Invalid comparison between Unknown and I4
		//IL_0010: 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_0015: Expected I4, but got Unknown
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Invalid comparison between Unknown and I4
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Invalid comparison between Unknown and I4
		//IL_0032: 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_003e: Expected I4, but got Unknown
		//IL_00c5: 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_00e6: Expected I4, but got Unknown
		//IL_007e: 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_00ab: Expected I4, but got Unknown
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Invalid comparison between Unknown and I4
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Invalid comparison between Unknown and I4
		//IL_0203: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Expected I4, but got Unknown
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected I4, but got Unknown
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Invalid comparison between Unknown and I4
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Invalid comparison between Unknown and I4
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Expected I4, but got Unknown
		bool flag = IsRussian();
		if ((int)key >= 48 && (int)key <= 57)
		{
			return (key - 48).ToString();
		}
		if ((int)key >= 256 && (int)key <= 265)
		{
			return "Num" + (key - 256);
		}
		if ((int)key <= 32)
		{
			if ((int)key <= 13)
			{
				if ((int)key == 0)
				{
					return "—";
				}
				if ((int)key == 13)
				{
					return "Enter";
				}
			}
			else
			{
				if ((int)key == 27)
				{
					return "Esc";
				}
				if ((int)key == 32)
				{
					if (!flag)
					{
						return "Space";
					}
					return "Пробел";
				}
			}
		}
		else if ((int)key <= 61)
		{
			switch (key - 39)
			{
			default:
				switch (key - 59)
				{
				case 2:
					return "=";
				case 0:
					return ";";
				}
				break;
			case 6:
				return "-";
			case 0:
				return "'";
			case 5:
				return ",";
			case 7:
				return ".";
			case 8:
				return "/";
			case 1:
			case 2:
			case 3:
			case 4:
				break;
			}
		}
		else
		{
			switch (key - 91)
			{
			default:
				switch (key - 303)
				{
				case 1:
					return "LShift";
				case 0:
					return "RShift";
				case 3:
					return "LCtrl";
				case 2:
					return "RCtrl";
				case 5:
					return "LAlt";
				case 4:
					return "RAlt";
				}
				switch (key - 323)
				{
				case 0:
					if (!flag)
					{
						return "LMB";
					}
					return "ЛКМ";
				case 1:
					if (!flag)
					{
						return "RMB";
					}
					return "ПКМ";
				case 2:
					if (!flag)
					{
						return "MMB";
					}
					return "СКМ";
				case 3:
					return "M4";
				case 4:
					return "M5";
				case 5:
					return "M6";
				case 6:
					return "M7";
				}
				break;
			case 5:
				return "`";
			case 0:
				return "[";
			case 2:
				return "]";
			case 1:
				return "\\";
			case 3:
			case 4:
				break;
			}
		}
		return ((object)key).ToString();
	}
}
public static class GridRenderer
{
	private const int GridTextureSize = 512;

	private const int RingSegments = 24;

	private static GameObject s_visualizerObject;

	private static MeshFilter s_meshFilter;

	private static MeshRenderer s_meshRenderer;

	private static Mesh s_gridMesh;

	private static Material s_gridMaterial;

	private static Material s_overlayMaterial;

	private static Texture2D s_proceduralGridTexture;

	private static readonly List<Vector3> s_vertices = new List<Vector3>(2048);

	private static readonly List<Vector2> s_uvs = new List<Vector2>(2048);

	private static readonly List<Color> s_colors = new List<Color>(2048);

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

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

	private static readonly Vector2 s_overlayUV = new Vector2(0.5f, 0.5f);

	private static Transform s_lastPieceTransform = null;

	private static Vector3 s_lastSnappedPoint = Vector3.negativeInfinity;

	private static Vector3 s_lastGridCenter = Vector3.negativeInfinity;

	private static Quaternion s_lastGhostRotation = Quaternion.identity;

	private static float s_lastGridSize = -1f;

	private static bool s_lastRailActive = false;

	private static GuideRailModule.LockedAxis s_lastRailAxis = GuideRailModule.LockedAxis.None;

	private static bool s_lastSnapToCenter = false;

	private static bool s_isVisible = false;

	private static GameObject s_currentGhost = null;

	private static Color32[] s_gridPixels;

	private static float s_texGridSize = -1f;

	private static float s_texPeriod = -1f;

	private static float s_texLineWidth = -1f;

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

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

	public static float GetMajorPeriod(float gridSize)
	{
		float num = ((gridSize < 0.999f) ? 1f : 2f);
		float num2 = num / gridSize;
		if (num2 < 0.999f || num2 > 32.001f || Mathf.Abs(num2 - Mathf.Round(num2)) > 0.01f)
		{
			return gridSize;
		}
		return num;
	}

	private static Texture2D GetOrCreateGridTexture()
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		if ((Object)(object)s_proceduralGridTexture == (Object)null)
		{
			s_proceduralGridTexture = new Texture2D(512, 512, (TextureFormat)4, false);
			((Object)s_proceduralGridTexture).name = "PrecisionBuild_GridTexture";
			((Texture)s_proceduralGridTexture).wrapMode = (TextureWrapMode)0;
			((Texture)s_proceduralGridTexture).filterMode = (FilterMode)1;
			((Object)s_proceduralGridTexture).hideFlags = (HideFlags)61;
			s_texGridSize = -1f;
		}
		return s_proceduralGridTexture;
	}

	private static void UpdateGridTexture(float gridSize, float period, float majorWidth)
	{
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		Texture2D orCreateGridTexture = GetOrCreateGridTexture();
		if (Mathf.Abs(gridSize - s_texGridSize) < 0.0001f && Mathf.Abs(period - s_texPeriod) < 0.0001f && Mathf.Abs(majorWidth - s_texLineWidth) < 0.0001f)
		{
			return;
		}
		s_texGridSize = gridSize;
		s_texPeriod = period;
		s_texLineWidth = majorWidth;
		int num = 512;
		float num2 = period / (float)num;
		bool flag = period > gridSize + 0.001f;
		float num3 = Mathf.Max(Mathf.Min(majorWidth, gridSize * 0.2f), num2 * 1.5f) * 0.5f;
		float halfWidth = Mathf.Max(Mathf.Min(majorWidth * 0.6f, gridSize * 0.12f), num2 * 1.2f) * 0.5f;
		float halfWidth2 = num3 * 2.6f;
		float num4 = num3 * 5f;
		if (s_gridPixels == null || s_gridPixels.Length != num * num)
		{
			s_gridPixels = (Color32[])(object)new Color32[num * num];
		}
		for (int i = 0; i < num; i++)
		{
			float num5 = ((float)i + 0.5f) * num2;
			float num6 = Mathf.Min(num5, period - num5);
			float num7 = DistanceToMultiple(num5, gridSize);
			for (int j = 0; j < num; j++)
			{
				float num8 = ((float)j + 0.5f) * num2;
				float num9 = Mathf.Min(num8, period - num8);
				float num10 = DistanceToMultiple(num8, gridSize);
				float num11 = Mathf.Min(num9, num6);
				float num12 = Mathf.Clamp01(1f - num11 / num4);
				float num13 = Mathf.Max(0.035f, LineCoverage(num11, num3, num2) + num12 * num12 * 0.22f);
				if (flag)
				{
					num13 = Mathf.Max(num13, LineCoverage(Mathf.Min(num10, num7), halfWidth, num2) * 0.45f);
				}
				float dist = Mathf.Sqrt(num9 * num9 + num6 * num6);
				num13 = Mathf.Max(num13, LineCoverage(dist, halfWidth2, num2));
				ref Color32 reference = ref s_gridPixels[i * num + j];
				reference = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(Mathf.Clamp01(num13) * 255f + 0.5f));
			}
		}
		orCreateGridTexture.SetPixels32(s_gridPixels);
		orCreateGridTexture.Apply(false, false);
	}

	private static float DistanceToMultiple(float p, float step)
	{
		float num = p - Mathf.Floor(p / step) * step;
		return Mathf.Min(num, step - num);
	}

	private static float LineCoverage(float dist, float halfWidth, float antiAlias)
	{
		return Mathf.Clamp01((halfWidth - dist) / antiAlias + 0.5f);
	}

	private static Material CreateMaterial(string name, Texture texture, int renderQueue)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Expected O, but got Unknown
		Shader val = Shader.Find("Sprites/Default");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("GUI/Text Shader");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Hidden/Internal-Colored");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Unlit/Transparent");
		}
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Material val2 = new Material(val);
		((Object)val2).name = name;
		((Object)val2).hideFlags = (HideFlags)61;
		Material val3 = val2;
		val3.mainTexture = texture;
		val3.SetInt("_SrcBlend", 5);
		val3.SetInt("_DstBlend", 10);
		val3.SetInt("_Cull", 0);
		val3.SetInt("_ZWrite", 0);
		val3.renderQueue = renderQueue;
		return val3;
	}

	private static Material GetOrCreateMaterial()
	{
		if ((Object)(object)s_gridMaterial == (Object)null)
		{
			s_gridMaterial = CreateMaterial("BuildGridMaterial", (Texture)(object)GetOrCreateGridTexture(), 3100);
		}
		return s_gridMaterial;
	}

	private static Material GetOrCreateOverlayMaterial()
	{
		if ((Object)(object)s_overlayMaterial == (Object)null)
		{
			s_overlayMaterial = CreateMaterial("BuildGridOverlayMaterial", (Texture)(object)Texture2D.whiteTexture, 3101);
		}
		return s_overlayMaterial;
	}

	private static void EnsureVisualizerObject()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		if ((Object)(object)s_visualizerObject == (Object)null)
		{
			GameObject val = new GameObject("_BuildGridVisualizer");
			((Object)val).hideFlags = (HideFlags)61;
			s_visualizerObject = val;
			s_meshFilter = s_visualizerObject.AddComponent<MeshFilter>();
			s_meshRenderer = s_visualizerObject.AddComponent<MeshRenderer>();
			((Renderer)s_meshRenderer).sharedMaterials = (Material[])(object)new Material[2]
			{
				GetOrCreateMaterial(),
				GetOrCreateOverlayMaterial()
			};
			((Renderer)s_meshRenderer).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)s_meshRenderer).receiveShadows = false;
			((Renderer)s_meshRenderer).lightProbeUsage = (LightProbeUsage)0;
			((Renderer)s_meshRenderer).reflectionProbeUsage = (ReflectionProbeUsage)0;
			Mesh val2 = new Mesh();
			((Object)val2).name = "BuildGridMesh";
			((Object)val2).hideFlags = (HideFlags)61;
			s_gridMesh = val2;
			s_meshFilter.sharedMesh = s_gridMesh;
		}
	}

	public static void UpdateGrid(Piece hitPiece, Collider collider, Vector3 hitPoint, Vector3 hitNormal, Vector3 snappedWorldPoint, float gridSize, GameObject placementGhost)
	{
		//IL_0030: 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_0035: 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_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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: 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_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: 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_0140: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		EnsureVisualizerObject();
		Transform val = (((Object)(object)hitPiece != (Object)null) ? ((Component)hitPiece).transform : null);
		Quaternion val2 = (((Object)(object)placementGhost != (Object)null) ? placementGhost.transform.rotation : Quaternion.identity);
		Vector3 val4 = default(Vector3);
		if ((Object)(object)hitPiece != (Object)null)
		{
			Vector3 val3 = val.InverseTransformPoint(hitPoint);
			float num = Mathf.Round(val3.x / 2f) * 2f;
			float num2 = Mathf.Round(val3.y / 2f) * 2f;
			float num3 = Mathf.Round(val3.z / 2f) * 2f;
			((Vector3)(ref val4))..ctor(num, num2, num3);
		}
		else
		{
			float num4 = Mathf.Round(hitPoint.x / 2f) * 2f;
			float num5 = Mathf.Round(hitPoint.y / 2f) * 2f;
			float num6 = Mathf.Round(hitPoint.z / 2f) * 2f;
			((Vector3)(ref val4))..ctor(num4, num5, num6);
		}
		s_currentGhost = placementGhost;
		if ((Object)(object)val != (Object)(object)s_lastPieceTransform || Mathf.Abs(gridSize - s_lastGridSize) > 0.001f || Vector3.SqrMagnitude(val4 - s_lastGridCenter) > 0.01f || Vector3.SqrMagnitude(snappedWorldPoint - s_lastSnappedPoint) > 0.0001f || Quaternion.Angle(val2, s_lastGhostRotation) > 0.5f || GuideRailModule.IsRailActive != s_lastRailActive || GuideRailModule.CurrentAxis != s_lastRailAxis || BuildGridPlugin.IsSnapToCenter != s_lastSnapToCenter)
		{
			s_lastSnapToCenter = BuildGridPlugin.IsSnapToCenter;
			s_lastPieceTransform = val;
			s_lastGridSize = gridSize;
			s_lastGridCenter = val4;
			s_lastSnappedPoint = snappedWorldPoint;
			s_lastGhostRotation = val2;
			s_lastRailActive = GuideRailModule.IsRailActive;
			s_lastRailAxis = GuideRailModule.CurrentAxis;
			BuildMesh(hitPiece, collider, hitPoint, hitNormal, snappedWorldPoint, gridSize, placementGhost);
		}
		if (!s_isVisible)
		{
			s_visualizerObject.SetActive(true);
			s_isVisible = true;
		}
	}

	public static Bounds GetPieceLocalBounds(Piece p)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)p == (Object)null)
		{
			return new Bounds(Vector3.zero, new Vector3(2f, 2f, 0.2f));
		}
		int instanceID = ((Object)p).GetInstanceID();
		if (s_boundsCache.TryGetValue(instanceID, out var value))
		{
			return value;
		}
		Transform transform = ((Component)p).transform;
		s_collidersCache.Clear();
		((Component)p).GetComponentsInChildren<Collider>(true, s_collidersCache);
		bool flag = false;
		Bounds val = default(Bounds);
		((Bounds)(ref val))..ctor(Vector3.zero, Vector3.zero);
		Vector3 val5 = default(Vector3);
		Bounds val6 = default(Bounds);
		Vector3 val9 = default(Vector3);
		Bounds val10 = default(Bounds);
		for (int i = 0; i < s_collidersCache.Count; i++)
		{
			Collider val2 = s_collidersCache[i];
			if ((Object)(object)val2 == (Object)null || val2.isTrigger || !val2.enabled)
			{
				continue;
			}
			BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null);
			if ((Object)(object)val3 != (Object)null)
			{
				Vector3 val4 = transform.InverseTransformPoint(((Component)val3).transform.TransformPoint(val3.center));
				Vector3 size = val3.size;
				Vector3 lossyScale = ((Component)val3).transform.lossyScale;
				((Vector3)(ref val5))..ctor(Mathf.Abs(size.x * lossyScale.x), Mathf.Abs(size.y * lossyScale.y), Mathf.Abs(size.z * lossyScale.z));
				((Bounds)(ref val6))..ctor(val4, val5);
				if (!flag)
				{
					val = val6;
					flag = true;
				}
				else
				{
					((Bounds)(ref val)).Encapsulate(val6);
				}
			}
			else
			{
				Bounds bounds = val2.bounds;
				Vector3 val7 = transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
				Vector3 val8 = transform.InverseTransformVector(((Bounds)(ref bounds)).size);
				((Vector3)(ref val9))..ctor(Mathf.Abs(val8.x), Mathf.Abs(val8.y), Mathf.Abs(val8.z));
				((Bounds)(ref val10))..ctor(val7, val9);
				if (!flag)
				{
					val = val10;
					flag = true;
				}
				else
				{
					((Bounds)(ref val)).Encapsulate(val10);
				}
			}
		}
		s_collidersCache.Clear();
		if (flag)
		{
			Vector3 size2 = ((Bounds)(ref val)).size;
			if (!(((Vector3)(ref size2)).sqrMagnitude < 0.01f))
			{
				goto IL_0223;
			}
		}
		((Bounds)(ref val))..ctor(Vector3.zero, new Vector3(2f, 2f, 0.2f));
		goto IL_0223;
		IL_0223:
		if (s_boundsCache.Count > 512)
		{
			s_boundsCache.Clear();
		}
		s_boundsCache[instanceID] = val;
		return val;
	}

	private static void BuildMesh(Piece hitPiece, Collider collider, Vector3 hitPoint, Vector3 hitNormal, Vector3 snappedWorldPoint, float gridSize, GameObject placementGhost)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: 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_0142: 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_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: 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_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: 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)
		s_vertices.Clear();
		s_uvs.Clear();
		s_colors.Clear();
		s_triangles.Clear();
		s_overlayTriangles.Clear();
		Color gridColor = BuildGridPlugin.ParseColor(BuildGridPlugin.GridColorHex.Value, BuildGridPlugin.ParseColor((string)((ConfigEntryBase)BuildGridPlugin.GridColorHex).DefaultValue, Color.white));
		Color activeNodeColor = BuildGridPlugin.ParseColor(BuildGridPlugin.ActiveNodeColorHex.Value, BuildGridPlugin.ParseColor((string)((ConfigEntryBase)BuildGridPlugin.ActiveNodeColorHex).DefaultValue, Color.white));
		Color footprintColor = BuildGridPlugin.ParseColor(BuildGridPlugin.FootprintColorHex.Value, BuildGridPlugin.ParseColor((string)((ConfigEntryBase)BuildGridPlugin.FootprintColorHex).DefaultValue, Color.white));
		float majorPeriod = GetMajorPeriod(gridSize);
		UpdateGridTexture(gridSize, majorPeriod, Mathf.Clamp(BuildGridPlugin.GridLineWidth.Value, 0.002f, 0.1f));
		float radiusMeters = Mathf.Clamp((float)BuildGridPlugin.GridRadiusCells.Value * gridSize, 1.8f, 10f);
		Vector3 worldNormal;
		if ((Object)(object)hitPiece != (Object)null)
		{
			worldNormal = ((!SlopeAlignmentModule.LastSlope.IsSlope || !((Object)(object)SlopeAlignmentModule.LastSlope.PieceTransform == (Object)(object)((Component)hitPiece).transform)) ? BuildPieceSurfacePlane(hitPiece, hitPoint, hitNormal, snappedWorldPoint, gridSize, radiusMeters, gridColor, activeNodeColor) : BuildSlopeSurfacePlane(SlopeAlignmentModule.LastSlope, hitPiece, hitPoint, snappedWorldPoint, gridSize, radiusMeters, gridColor, activeNodeColor));
		}
		else
		{
			worldNormal = Vector3.up;
			BuildTerrainPlane(hitPoint, snappedWorldPoint, gridSize, radiusMeters, gridColor, activeNodeColor);
		}
		if (BuildGridPlugin.ShowFootprint.Value && (Object)(object)placementGhost != (Object)null)
		{
			BuildFootprintOnly(placementGhost, snappedWorldPoint, worldNormal, gridSize, footprintColor);
		}
		GuideRailModule.AppendRailVisuals();
		s_gridMesh.Clear();
		s_gridMesh.subMeshCount = 2;
		s_gridMesh.SetVertices(s_vertices);
		s_gridMesh.SetUVs(0, s_uvs);
		s_gridMesh.SetColors(s_colors);
		s_gridMesh.SetTriangles(s_triangles, 0);
		s_gridMesh.SetTriangles(s_overlayTriangles, 1);
		s_gridMesh.RecalculateBounds();
	}

	private static Vector3 BuildSlopeSurfacePlane(SlopeAlignmentModule.SlopeData slope, Piece hitPiece, Vector3 hitPoint, Vector3 snappedWorldPoint, float gridSize, float radiusMeters, Color gridColor, Color activeNodeColor)
	{
		//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_00c7: 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)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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_0110: 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_011c: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: 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_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: 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_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0307: Unknown result type (might be due to invalid IL or missing references)
		//IL_030e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = slope.WorldNormal;
		if ((Object)(object)Camera.main != (Object)null)
		{
			Vector3 forward = ((Component)Camera.main).transform.forward;
			if (Vector3.Dot(val, forward) > 0f)
			{
				val = -val;
			}
		}
		float num = 0.015f;
		float majorPeriod = GetMajorPeriod(gridSize);
		float num2 = Mathf.Round(slope.LocalHitU / 2f) * 2f;
		float num3 = Mathf.Round(slope.LocalHitV / 2f) * 2f;
		float num4 = num2 - radiusMeters;
		float num5 = num2 + radiusMeters;
		float num6 = num3 - radiusMeters;
		float num7 = num3 + radiusMeters;
		int num8 = 12;
		float num9 = (num5 - num4) / (float)num8;
		float num10 = (num7 - num6) / (float)num8;
		int count = s_vertices.Count;
		Vector3 val2 = slope.PieceTransform.TransformPoint(slope.LocalAnchor);
		for (int i = 0; i <= num8; i++)
		{
			float num11 = num6 + (float)i * num10;
			for (int j = 0; j <= num8; j++)
			{
				float num12 = num4 + (float)j * num9;
				Vector3 item = val2 + slope.WorldU * num12 + slope.WorldV * num11 + val * num;
				s_vertices.Add(item);
				s_uvs.Add(new Vector2(num12 / majorPeriod, num11 / majorPeriod));
				float num13 = Mathf.Sqrt((num12 - slope.LocalHitU) * (num12 - slope.LocalHitU) + (num11 - slope.LocalHitV) * (num11 - slope.LocalHitV));
				float num14 = Mathf.Clamp01(1f - num13 / radiusMeters);
				num14 *= num14;
				s_colors.Add(new Color(gridColor.r, gridColor.g, gridColor.b, gridColor.a * num14));
			}
		}
		int num15 = num8 + 1;
		for (int k = 0; k < num8; k++)
		{
			for (int l = 0; l < num8; l++)
			{
				int num16 = count + k * num15 + l;
				int item2 = num16 + 1;
				int num17 = count + (k + 1) * num15 + l;
				int item3 = num17 + 1;
				s_triangles.Add(num16);
				s_triangles.Add(num17);
				s_triangles.Add(item2);
				s_triangles.Add(item2);
				s_triangles.Add(num17);
				s_triangles.Add(item3);
				s_triangles.Add(num16);
				s_triangles.Add(item2);
				s_triangles.Add(num17);
				s_triangles.Add(item2);
				s_triangles.Add(item3);
				s_triangles.Add(num17);
			}
		}
		float size = Mathf.Clamp(gridSize * 0.35f, 0.06f, 0.14f);
		Vector3 center = snappedWorldPoint + val * (num + 0.003f);
		AddSnapMarker(center, slope.WorldU, slope.WorldV, size, activeNodeColor, BuildGridPlugin.IsSnapToCenter);
		return val;
	}

	private static Vector3 BuildPieceSurfacePlane(Piece hitPiece, Vector3 hitPoint, Vector3 hitNormal, Vector3 snappedWorldPoint, float gridSize, float radiusMeters, Color gridColor, Color activeNodeColor)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_0046: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: 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_01f2: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: 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_0119: 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_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: 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_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: 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_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: 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_02ae: 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)
		//IL_02be: 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_0559: Unknown result type (might be due to invalid IL or missing references)
		//IL_055b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0560: Unknown result type (might be due to invalid IL or missing references)
		//IL_0564: Unknown result type (might be due to invalid IL or missing references)
		//IL_0569: Unknown result type (might be due to invalid IL or missing references)
		//IL_056c: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Unknown result type (might be due to invalid IL or missing references)
		//IL_057c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0597: Unknown result type (might be due to invalid IL or missing references)
		//IL_0598: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_03af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: 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_0444: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)hitPiece).transform;
		Vector3 val = transform.InverseTransformPoint(hitPoint);
		Vector3 val2 = transform.InverseTransformDirection(hitNormal);
		Bounds pieceLocalBounds = GetPieceLocalBounds(hitPiece);
		bool flag = ((Bounds)(ref pieceLocalBounds)).size.y > 1.2f && (((Bounds)(ref pieceLocalBounds)).size.z < 0.8f || ((Bounds)(ref pieceLocalBounds)).size.x < 0.8f) && val.y < ((Bounds)(ref pieceLocalBounds)).max.y - 0.15f;
		float num = Mathf.Abs(val2.x);
		float num2 = Mathf.Abs(val2.y);
		float num3 = Mathf.Abs(val2.z);
		if (flag)
		{
			num2 = 0f;
		}
		Vector3 val3;
		Vector3 val4;
		float num4;
		float num5;
		float num7;
		Vector3 val5;
		if (num2 >= num && num2 >= num3)
		{
			val3 = Vector3.right;
			val4 = Vector3.forward;
			num4 = val.x;
			num5 = val.z;
			float num6 = ((val2.y >= 0f) ? 1f : (-1f));
			num7 = ((num6 > 0f) ? ((Bounds)(ref pieceLocalBounds)).max.y : ((Bounds)(ref pieceLocalBounds)).min.y);
			val5 = Vector3.up * num6;
		}
		else if (num3 >= num && num3 >= num2)
		{
			val3 = Vector3.right;
			val4 = Vector3.up;
			num4 = val.x;
			num5 = val.y;
			float num8 = ((Mathf.Abs(val2.z) > 0.1f) ? Mathf.Sign(val2.z) : ((val.z >= ((Bounds)(ref pieceLocalBounds)).center.z) ? 1f : (-1f)));
			num7 = ((num8 > 0f) ? ((Bounds)(ref pieceLocalBounds)).max.z : ((Bounds)(ref pieceLocalBounds)).min.z);
			val5 = Vector3.forward * num8;
		}
		else
		{
			val3 = Vector3.forward;
			val4 = Vector3.up;
			num4 = val.z;
			num5 = val.y;
			float num9 = ((Mathf.Abs(val2.x) > 0.1f) ? Mathf.Sign(val2.x) : ((val.x >= ((Bounds)(ref pieceLocalBounds)).center.x) ? 1f : (-1f)));
			num7 = ((num9 > 0f) ? ((Bounds)(ref pieceLocalBounds)).max.x : ((Bounds)(ref pieceLocalBounds)).min.x);
			val5 = Vector3.right * num9;
		}
		Vector3 val6 = transform.TransformDirection(val5);
		Vector3 val7 = ((Vector3)(ref val6)).normalized;
		if ((Object)(object)Camera.main != (Object)null)
		{
			Vector3 forward = ((Component)Camera.main).transform.forward;
			if (Vector3.Dot(val7, forward) > 0f)
			{
				val7 = -val7;
			}
		}
		float num10 = 0.015f;
		float majorPeriod = GetMajorPeriod(gridSize);
		float num11 = Mathf.Round(num4 / 2f) * 2f;
		float num12 = Mathf.Round(num5 / 2f) * 2f;
		float num13 = num11 - radiusMeters;
		float num14 = num11 + radiusMeters;
		float num15 = num12 - radiusMeters;
		float num16 = num12 + radiusMeters;
		int num17 = 12;
		float num18 = (num14 - num13) / (float)num17;
		float num19 = (num16 - num15) / (float)num17;
		int count = s_vertices.Count;
		Vector3 val8 = default(Vector3);
		for (int i = 0; i <= num17; i++)
		{
			float num20 = num15 + (float)i * num19;
			for (int j = 0; j <= num17; j++)
			{
				float num21 = num13 + (float)j * num18;
				if (num2 >= num && num2 >= num3)
				{
					((Vector3)(ref val8))..ctor(num21, num7, num20);
				}
				else if (num3 >= num && num3 >= num2)
				{
					((Vector3)(ref val8))..ctor(num21, num20, num7);
				}
				else
				{
					((Vector3)(ref val8))..ctor(num7, num20, num21);
				}
				Vector3 item = transform.TransformPoint(val8) + val7 * num10;
				s_vertices.Add(item);
				s_uvs.Add(new Vector2(num21 / majorPeriod, num20 / majorPeriod));
				float num22 = Mathf.Sqrt((num21 - num4) * (num21 - num4) + (num20 - num5) * (num20 - num5));
				float num23 = Mathf.Clamp01(1f - num22 / radiusMeters);
				num23 *= num23;
				s_colors.Add(new Color(gridColor.r, gridColor.g, gridColor.b, gridColor.a * num23));
			}
		}
		int num24 = num17 + 1;
		for (int k = 0; k < num17; k++)
		{
			for (int l = 0; l < num17; l++)
			{
				int num25 = count + k * num24 + l;
				int item2 = num25 + 1;
				int num26 = count + (k + 1) * num24 + l;
				int item3 = num26 + 1;
				s_triangles.Add(num25);
				s_triangles.Add(num26);
				s_triangles.Add(item2);
				s_triangles.Add(item2);
				s_triangles.Add(num26);
				s_triangles.Add(item3);
				s_triangles.Add(num25);
				s_triangles.Add(item2);
				s_triangles.Add(num26);
				s_triangles.Add(item2);
				s_triangles.Add(item3);
				s_triangles.Add(num26);
			}
		}
		Vector3 val9 = transform.TransformDirection(val3);
		Vector3 normalized = ((Vector3)(ref val9)).normalized;
		Vector3 val10 = transform.TransformDirection(val4);
		Vector3 normalized2 = ((Vector3)(ref val10)).normalized;
		float size = Mathf.Clamp(gridSize * 0.35f, 0.06f, 0.14f);
		Vector3 center = snappedWorldPoint + val7 * (num10 + 0.003f);
		AddSnapMarker(center, normalized, normalized2, size, activeNodeColor, BuildGridPlugin.IsSnapToCenter);
		return val7;
	}

	private static void BuildTerrainPlane(Vector3 hitPoint, Vector3 snappedWorldPoint, float gridSize, float radiusMeters, Color gridColor, Color activeNodeColor)
	{
		//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_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: 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)
		//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
		Vector3 up = Vector3.up;
		float num = 0.015f;
		float majorPeriod = GetMajorPeriod(gridSize);
		float num2 = Mathf.Round(hitPoint.x / 2f) * 2f;
		float num3 = Mathf.Round(hitPoint.z / 2f) * 2f;
		float num4 = num2 - radiusMeters;
		float num5 = num2 + radiusMeters;
		float num6 = num3 - radiusMeters;
		float num7 = num3 + radiusMeters;
		int num8 = 12;
		float num9 = (num5 - num4) / (float)num8;
		float num10 = (num7 - num6) / (float)num8;
		int count = s_vertices.Count;
		Vector3 item = default(Vector3);
		for (int i = 0; i <= num8; i++)
		{
			float num11 = num6 + (float)i * num10;
			for (int j = 0; j <= num8; j++)
			{
				float num12 = num4 + (float)j * num9;
				float num13 = 0f;
				if ((Object)(object)ZoneSystem.instance != (Object)null)
				{
					num13 = ZoneSystem.instance.GetGroundHeight(new Vector3(num12, 0f, num11));
				}
				((Vector3)(ref item))..ctor(num12, num13 + num, num11);
				s_vertices.Add(item);
				s_uvs.Add(new Vector2(num12 / majorPeriod, num11 / majorPeriod));
				float num14 = Mathf.Sqrt((num12 - hitPoint.x) * (num12 - hitPoint.x) + (num11 - hitPoint.z) * (num11 - hitPoint.z));
				float num15 = Mathf.Clamp01(1f - num14 / radiusMeters);
				num15 *= num15;
				s_colors.Add(new Color(gridColor.r, gridColor.g, gridColor.b, gridColor.a * num15));
			}
		}
		int num16 = num8 + 1;
		for (int k = 0; k < num8; k++)
		{
			for (int l = 0; l < num8; l++)
			{
				int num17 = count + k * num16 + l;
				int item2 = num17 + 1;
				int num18 = count + (k + 1) * num16 + l;
				int item3 = num18 + 1;
				s_triangles.Add(num17);
				s_triangles.Add(num18);
				s_triangles.Add(item2);
				s_triangles.Add(item2);
				s_triangles.Add(num18);
				s_triangles.Add(item3);
				s_triangles.Add(num17);
				s_triangles.Add(item2);
				s_triangles.Add(num18);
				s_triangles.Add(item2);
				s_triangles.Add(item3);
				s_triangles.Add(num18);
			}
		}
		float size = Mathf.Clamp(gridSize * 0.35f, 0.07f, 0.16f);
		Vector3 center = snappedWorldPoint + up * (num + 0.003f);
		AddSnapMarker(center, Vector3.right, Vector3.forward, size, activeNodeColor, BuildGridPlugin.IsSnapToCenter);
	}

	private static void BuildFootprintOnly(GameObject ghost, Vector3 baseSnappedPos, Vector3 worldNormal, float gridSize, Color footprintColor)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_007a: 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_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_008b: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: 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_00c7: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: 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_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_0149: 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_014e: Unknown result type (might be due to invalid IL or missing references)
		Piece component = ghost.GetComponent<Piece>();
		if (!((Object)(object)component == (Object)null))
		{
			GetGhostFootprint(component, out var minXZ, out var maxXZ);
			float num = 0.006f;
			Color fillColor = default(Color);
			((Color)(ref fillColor))..ctor(footprintColor.r, footprintColor.g, footprintColor.b, footprintColor.a * 0.12f);
			float lineWidth = 0.012f;
			Vector3 w = baseSnappedPos + ghost.transform.rotation * new Vector3(minXZ.x, 0f, minXZ.y) + worldNormal * num;
			Vector3 w2 = baseSnappedPos + ghost.transform.rotation * new Vector3(maxXZ.x, 0f, minXZ.y) + worldNormal * num;
			Vector3 w3 = baseSnappedPos + ghost.transform.rotation * new Vector3(maxXZ.x, 0f, maxXZ.y) + worldNormal * num;
			Vector3 w4 = baseSnappedPos + ghost.transform.rotation * new Vector3(minXZ.x, 0f, maxXZ.y) + worldNormal * num;
			AddFootprintQuad(w, w2, w3, w4, worldNormal, lineWidth, footprintColor, fillColor);
		}
	}

	private static void GetGhostFootprint(Piece ghostPiece, out Vector2 minXZ, out Vector2 maxXZ)
	{
		//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_000a: 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_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_002d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		Bounds pieceLocalBounds = GetPieceLocalBounds(ghostPiece);
		minXZ = new Vector2(((Bounds)(ref pieceLocalBounds)).min.x, ((Bounds)(ref pieceLocalBounds)).min.z);
		maxXZ = new Vector2(((Bounds)(ref pieceLocalBounds)).max.x, ((Bounds)(ref pieceLocalBounds)).max.z);
	}

	private static void AddFootprintQuad(Vector3 w0, Vector3 w1, Vector3 w2, Vector3 w3, Vector3 normal, float lineWidth, Color lineColor, Color fillColor)
	{
		//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_0002: 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_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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_0020: 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_0028: 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_002d: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		AddLineQuad(w0, w1, normal, lineWidth, lineColor);
		AddLineQuad(w1, w2, normal, lineWidth, lineColor);
		AddLineQuad(w2, w3, normal, lineWidth, lineColor);
		AddLineQuad(w3, w0, normal, lineWidth, lineColor);
		AddOverlayQuad(w0, w1, w2, w3, fillColor, fillColor, fillColor, fillColor);
	}

	private static void AddOverlayQuad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Color ca, Color cb, Color cc, Color cd)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_003c: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_0090: 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)
		int count = s_vertices.Count;
		s_vertices.Add(a);
		s_vertices.Add(b);
		s_vertices.Add(c);
		s_vertices.Add(d);
		s_uvs.Add(s_overlayUV);
		s_uvs.Add(s_overlayUV);
		s_uvs.Add(s_overlayUV);
		s_uvs.Add(s_overlayUV);
		s_colors.Add(ca);
		s_colors.Add(cb);
		s_colors.Add(cc);
		s_colors.Add(cd);
		s_overlayTriangles.Add(count);
		s_overlayTriangles.Add(count + 1);
		s_overlayTriangles.Add(count + 2);
		s_overlayTriangles.Add(count);
		s_overlayTriangles.Add(count + 2);
		s_overlayTriangles.Add(count + 3);
		s_overlayTriangles.Add(count);
		s_overlayTriangles.Add(count + 2);
		s_overlayTriangles.Add(count + 1);
		s_overlayTriangles.Add(count);
		s_overlayTriangles.Add(count + 3);
		s_overlayTriangles.Add(count + 2);
	}

	public static void AddLineQuad(Vector3 start, Vector3 end, Vector3 normal, float width, Color color)
	{
		//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_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		AddLineQuad(start, end, normal, width, color, color);
	}

	public static void AddLineQuad(Vector3 start, Vector3 end, Vector3 normal, float width, Color startColor, Color endColor)
	{
		//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_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_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0045: 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_004c: 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_0053: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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)
		Vector3 val = end - start;
		float magnitude = ((Vector3)(ref val)).magnitude;
		if (!(magnitude < 0.0001f))
		{
			val /= magnitude;
			Vector3 val2 = Vector3.Cross(normal, val);
			Vector3 val3 = ((Vector3)(ref val2)).normalized * (width * 0.5f);
			AddOverlayQuad(start - val3, start + val3, end + val3, end - val3, startColor, startColor, endColor, endColor);
		}
	}

	public static void AddSnapIndicator(Vector3 center, Vector3 uAxis, Vector3 vAxis, float size, Color color)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: 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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		float num = size * 0.5f;
		AddOverlayQuad(center + vAxis * num, center + uAxis * num, center - vAxis * num, center - uAxis * num, color, color, color, color);
	}

	public static void AddSnapMarker(Vector3 center, Vector3 uAxis, Vector3 vAxis, float size, Color color, bool cellCenter)
	{
		//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_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_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_0044: 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_00dc: 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_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)
		//IL_00eb: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: 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_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: 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_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: 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_0154: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_0081: 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_0091: 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_0098: 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_00ae: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.Cross(uAxis, vAxis);
		Vector3 normalized = ((Vector3)(ref val)).normalized;
		Color color2 = default(Color);
		((Color)(ref color2))..ctor(0f, 0f, 0f, color.a * 0.45f);
		float num = size * 0.16f;
		float num2 = size * 0.07f;
		Vector3 val2 = normalized * 0.001f;
		if (cellCenter)
		{
			float num3 = size * 0.5f;
			AddRing(center, uAxis, vAxis, num3 - num * 0.5f - num2, num3 + num * 0.5f + num2, color2);
			AddRing(center, uAxis, vAxis, 0f, num + num2, color2);
			AddRing(center + val2, uAxis, vAxis, num3 - num * 0.5f, num3 + num * 0.5f, color);
			AddRing(center + val2, uAxis, vAxis, 0f, num, color);
		}
		else
		{
			float num4 = size * 0.75f;
			float num5 = num4 + num2;
			AddLineQuad(center - uAxis * num5, center + uAxis * num5, normalized, num + num2 * 2f, color2);
			AddLineQuad(center - vAxis * num5, center + vAxis * num5, normalized, num + num2 * 2f, color2);
			AddLineQuad(center + val2 - uAxis * num4, center + val2 + uAxis * num4, normalized, num, color);
			AddLineQuad(center + val2 - vAxis * num4, center + val2 + vAxis * num4, normalized, num, color);
		}
	}

	private static void AddRing(Vector3 center, Vector3 uAxis, Vector3 vAxis, float innerRadius, float outerRadius, Color color)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0091: 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)
		float num = (float)Math.PI / 12f;
		for (int i = 0; i < 24; i++)
		{
			Vector3 val = uAxis * Mathf.Cos((float)i * num) + vAxis * Mathf.Sin((float)i * num);
			Vector3 val2 = uAxis * Mathf.Cos((float)(i + 1) * num) + vAxis * Mathf.Sin((float)(i + 1) * num);
			AddOverlayQuad(center + val * innerRadius, center + val * outerRadius, center + val2 * outerRadius, center + val2 * innerRadius, color, color, color, color);
		}
	}

	public static void Hide()
	{
		//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)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		SlopeAlignmentModule.Reset();
		if ((Object)(object)s_visualizerObject != (Object)null && s_isVisible)
		{
			s_visualizerObject.SetActive(false);
			s_isVisible = false;
			s_lastPieceTransform = null;
			s_lastSnappedPoint = Vector3.negativeInfinity;
			s_lastGridCenter = Vector3.negativeInfinity;
			s_lastRailActive = false;
			s_lastRailAxis = GuideRailModule.LockedAxis.None;
			s_currentGhost = null;
			s_boundsCache.Clear();
		}
	}

	public static void Destroy()
	{
		s_boundsCache.Clear();
		if ((Object)(object)s_visualizerObject != (Object)null)
		{
			Object.Destroy((Object)(object)s_visualizerObject);
			s_visualizerObject = null;
		}
		if ((Object)(object)s_gridMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)s_gridMaterial);
			s_gridMaterial = null;
		}
		if ((Object)(object)s_overlayMaterial != (Object)null)
		{
			Object.Destroy((Object)(object)s_overlayMaterial);
			s_overlayMaterial = null;
		}
		if ((Object)(object)s_proceduralGridTexture != (Object)null)
		{
			Object.Destroy((Object)(object)s_proceduralGridTexture);
			s_proceduralGridTexture = null;
			s_texGridSize = -1f;
		}
	}
}
[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
public static class PlayerPlacementPatch
{
	private static Func<Player, GameObject> s_getPlacementGhost;

	private static Func<Player, int> s_getManualSnapPoint;

	private static Func<Player, List<Transform>> s_getTempSnapPoints1;

	private static Func<Player, List<Piece>> s_getTempPieces;

	private static Action<Player, bool> s_setPlacementGhostValid;

	private static MethodInfo s_pieceRayTestMethod;

	private static readonly object[] s_rayArgs = new object[6];

	private static GameObject s_lastGhostInstance = null;

	private static readonly Dictionary<int, bool> s_hasSnapPointsCache = new Dictionary<int, bool>(64);

	private static GameObject s_cachedGhostForColliders = null;

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

	private static GameObject s_lastOffsetGhost = null;

	private static Vector3 s_lastOffsetNormal = Vector3.zero;

	private static Quaternion s_lastOffsetRot = Quaternion.identity;

	private static Vector3 s_lastComputedOffset = Vector3.zero;

	public static float SnapCoordinate(float val, float gridSize, bool snapToCenter)
	{
		if (snapToCenter)
		{
			return (Mathf.Floor(val / gridSize) + 0.5f) * gridSize;
		}
		return Mathf.Round(val / gridSize) * gridSize;
	}

	private static bool InitReflection()
	{
		if (s_getPlacementGhost == null)
		{
			s_getPlacementGhost = FastReflection.CreateGetter<Player, GameObject>("m_placementGhost");
			s_getManualSnapPoint = FastReflection.CreateGetter<Player, int>("m_manualSnapPoint");
			s_getTempSnapPoints1 = FastReflection.CreateGetter<Player, List<Transform>>("m_tempSnapPoints1");
			s_getTempPieces = FastReflection.CreateGetter<Player, List<Piece>>("m_tempPieces");
			MethodInfo methodInfo = AccessTools.Method(typeof(Player), "SetPlacementGhostValid", new Type[1] { typeof(bool) }, (Type[])null);
			if (methodInfo != null)
			{
				try
				{
					s_setPlacementGhostValid = (Action<Player, bool>)Delegate.CreateDelegate(typeof(Action<Player, bool>), methodInfo);
				}
				catch
				{
				}
			}
		}
		if (s_pieceRayTestMethod == null)
		{
			s_pieceRayTestMethod = AccessTools.Method(typeof(Player), "PieceRayTest", new Type[6]
			{
				typeof(Vector3).MakeByRefType(),
				typeof(Vector3).MakeByRefType(),
				typeof(Piece).MakeByRefType(),
				typeof(Heightmap).MakeByRefType(),
				typeof(Collider).MakeByRefType(),
				typeof(bool)
			}, (Type[])null);
		}
		return s_pieceRayTestMethod != null;
	}

	[HarmonyPrefix]
	public static void Prefix(Player __instance)
	{
		if (BuildGridPlugin.ModEnabled.Value)
		{
			InitReflection();
			GameObject placementGhost = ((s_getPlacementGhost != null) ? s_getPlacementGhost(__instance) : null);
			RugPlacementModule.PrePlacement(__instance, placementGhost);
		}
	}

	[HarmonyPostfix]
	public static void Postfix(Player __instance, bool flashGuardStone)
	{
		//IL_00e9: 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_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Expected O, but got Unknown
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Expected O, but got Unknown
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: 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_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_0578: Unknown result type (might be due to invalid IL or missing references)
		//IL_057d: Unknown result type (might be due to invalid IL or missing references)
		//IL_055a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: 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_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0596: Unknown result