Decompiled source of TerrainForge v0.3.8

TerrainForge.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TerrainForge")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.8.0")]
[assembly: AssemblyInformationalVersion("0.3.8+b58818910b641b39ba530e382df693a1239bcafc")]
[assembly: AssemblyProduct("TerrainForge")]
[assembly: AssemblyTitle("TerrainForge")]
[assembly: AssemblyVersion("0.3.8.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TerrainForge
{
	internal static class ColorExtensions
	{
		public static Color WithAlpha(this Color c, float a)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			c.a = a;
			return c;
		}
	}
	internal sealed class TerrainKeybinds : MonoBehaviour
	{
		private struct Entry
		{
			public string Label;

			public ConfigEntry<KeyboardShortcut> Bind;
		}

		private const int WindowId = 9911735;

		private static readonly KeyCode[] AllKeys = (KeyCode[])Enum.GetValues(typeof(KeyCode));

		private readonly List<Entry> _entries = new List<Entry>();

		private bool _open;

		private int _capturing = -1;

		private int _tab;

		private Vector2 _mainScroll;

		private Rect _window = new Rect(40f, 60f, 900f, 720f);

		private bool _cursorWasVisible;

		private CursorLockMode _cursorLock;

		private string _undoDepthText;

		private string _presetName = "";

		private ModLanguage _langBuilt;

		private string _fixedHeightText;

		private string _snapshotName = "";

		private string _stampName = "";

		private string _stampLoadName = "";

		private string _keySearch = "";

		private bool _resizing;

		private GUIStyle _gripStyle;

		private GUIStyle _winStyle;

		private GUIStyle _headerStyle;

		private GUIStyle _titleStyle;

		private GUIStyle _hintStyle;

		private GUIStyle _rowStyle;

		private GUIStyle _btnStyle;

		private GUIStyle _closeStyle;

		private GUIStyle _capturingStyle;

		private GUIStyle _capturingBtnStyle;

		private GUIStyle _tabStyle;

		private GUIStyle _bodyStyle;

		private GUIStyle _topicStyle;

		private GUIStyle _boxStyle;

		private GUIStyle _scrollStyle;

		private GUIStyle _scrollBarStyle;

		private GUIStyle _scrollBarThumbStyle;

		private GUIStyle _iconBtnStyle;

		private GUIStyle _iconBtnSelStyle;

		private GUIStyle _iconCapStyle;

		private GUIStyle _iconCapSelStyle;

		private GUIStyle _iconOnlyStyle;

		private Texture2D _texPanel;

		private Texture2D _texHeader;

		private Texture2D _texPanelBg;

		private Texture2D _texBtn;

		private Texture2D _texBtnHover;

		private Texture2D _texBtnActive;

		private Texture2D _texCapture;

		private Texture2D _texBackdrop;

		private static TerrainKeybinds s_instance;

		public static bool MenuOpen { get; private set; }

		internal static void OpenMenu()
		{
			if ((Object)(object)s_instance != (Object)null)
			{
				s_instance.Toggle(open: true);
			}
		}

		private void Start()
		{
			s_instance = this;
			BuildEntries();
		}

		private void BuildEntries()
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				_entries.Clear();
				_entries.Add(new Entry
				{
					Label = Loc.T("key.apply"),
					Bind = instance.ApplyKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.radiusUp"),
					Bind = instance.RadiusUpKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.radiusDown"),
					Bind = instance.RadiusDownKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.cycleOp"),
					Bind = instance.CycleOperationKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.cycleShape"),
					Bind = instance.CycleShapeKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.cyclePaint"),
					Bind = instance.CyclePaintKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.aimMod"),
					Bind = instance.AimHeightModifierKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.undo"),
					Bind = instance.UndoKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.redo"),
					Bind = instance.RedoKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.eyedrop"),
					Bind = instance.EyedropKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.rampMode"),
					Bind = instance.RampModeKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.radial"),
					Bind = instance.RadialKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.radialTools"),
					Bind = instance.RadialToolsKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.radialConfirm"),
					Bind = instance.RadialConfirmKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.radialCancel"),
					Bind = instance.RadialCancelKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.adjust"),
					Bind = instance.AdjustModeKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.freecam"),
					Bind = instance.FreeCameraKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.give"),
					Bind = instance.GiveToolKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.menu"),
					Bind = instance.RebindMenuKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.flatten"),
					Bind = instance.OpFlattenKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.raise"),
					Bind = instance.OpRaiseKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.lower"),
					Bind = instance.OpLowerKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.smooth"),
					Bind = instance.OpSmoothKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.paint"),
					Bind = instance.OpPaintKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.restore"),
					Bind = instance.OpRestoreKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.ramp"),
					Bind = instance.OpRampKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.shore"),
					Bind = instance.OpShoreKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.op.snow"),
					Bind = instance.OpSnowKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.cycleProfile"),
					Bind = instance.CycleProfileKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.copyStamp"),
					Bind = instance.CopyStampKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.pasteStamp"),
					Bind = instance.PasteStampKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.cycleStamp"),
					Bind = instance.CycleStampKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.cycleStampBack"),
					Bind = instance.CycleStampBackKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.slopeHeatmap"),
					Bind = instance.SlopeHeatmapKey
				});
				_entries.Add(new Entry
				{
					Label = Loc.T("key.heightHeatmap"),
					Bind = instance.HeightHeatmapKey
				});
				_langBuilt = ((instance.Language != null) ? instance.Language.Value : ModLanguage.Español);
			}
		}

		private void Update()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				PauseMenuPatch.Ensure();
				if (_open)
				{
					Cursor.visible = true;
					Cursor.lockState = (CursorLockMode)0;
				}
				if (_capturing >= 0)
				{
					PollCapture();
				}
				else if (ShortcutDown(instance.RebindMenuKey.Value))
				{
					Toggle(!_open);
				}
			}
		}

		private void PollCapture()
		{
			//IL_0047: 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)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Invalid comparison between Unknown and I4
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Invalid comparison between Unknown and I4
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Invalid comparison between Unknown and I4
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Invalid comparison between Unknown and I4
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Invalid comparison between Unknown and I4
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetMouseButtonDown(0))
			{
				Capture((KeyCode)323);
				return;
			}
			if (Input.GetMouseButtonDown(1))
			{
				Capture((KeyCode)324);
				return;
			}
			if (Input.GetMouseButtonDown(2))
			{
				Capture((KeyCode)325);
				return;
			}
			for (int i = 0; i < AllKeys.Length; i++)
			{
				KeyCode val = AllKeys[i];
				if ((int)val == 0 || (int)val == 306 || (int)val == 305 || (int)val == 304 || (int)val == 303 || (int)val == 308 || (int)val == 307 || (int)val == 310 || (int)val == 309)
				{
					continue;
				}
				bool keyDown;
				try
				{
					keyDown = Input.GetKeyDown(val);
				}
				catch
				{
					continue;
				}
				if (keyDown)
				{
					if ((int)val == 27)
					{
						_capturing = -1;
					}
					else
					{
						Capture(val);
					}
					break;
				}
			}
		}

		private void Capture(KeyCode main)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			List<KeyCode> list = new List<KeyCode>();
			if (!IsModifier(main, (KeyCode)306, (KeyCode)305) && (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)))
			{
				list.Add((KeyCode)306);
			}
			if (!IsModifier(main, (KeyCode)304, (KeyCode)303) && (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303)))
			{
				list.Add((KeyCode)304);
			}
			if (!IsModifier(main, (KeyCode)308, (KeyCode)307) && (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)))
			{
				list.Add((KeyCode)308);
			}
			_entries[_capturing].Bind.Value = new KeyboardShortcut(main, list.ToArray());
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Config.Save();
			}
			_capturing = -1;
		}

		private static bool IsModifier(KeyCode main, KeyCode a, KeyCode b)
		{
			//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_0004: 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)
			if (main != a)
			{
				return main == b;
			}
			return true;
		}

		private void Toggle(bool open)
		{
			//IL_00d3: 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_01a3: Unknown result type (might be due to invalid IL or missing references)
			_open = open;
			MenuOpen = open;
			if (open)
			{
				((Rect)(ref _window)).width = Mathf.Min(Mathf.Clamp((float)Screen.width * 0.9f, 720f, 1100f), (float)Screen.width - 24f);
				((Rect)(ref _window)).height = Mathf.Min(Mathf.Clamp((float)Screen.height * 0.9f, 600f, 900f), (float)Screen.height - 24f);
				((Rect)(ref _window)).x = ((float)Screen.width - ((Rect)(ref _window)).width) * 0.5f;
				((Rect)(ref _window)).y = ((float)Screen.height - ((Rect)(ref _window)).height) * 0.5f;
				_cursorWasVisible = Cursor.visible;
				_cursorLock = Cursor.lockState;
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				TerrainForgePlugin instance = TerrainForgePlugin.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					ModLanguage modLanguage = ((instance.Language != null) ? instance.Language.Value : ModLanguage.Español);
					if (_entries.Count == 0 || modLanguage != _langBuilt)
					{
						BuildEntries();
					}
					if (instance.UndoDepth != null)
					{
						_undoDepthText = instance.UndoDepth.Value.ToString();
					}
					if (instance.FixedHeight != null)
					{
						_fixedHeightText = instance.FixedHeight.Value.ToString("0.0");
					}
				}
				return;
			}
			_capturing = -1;
			try
			{
				TerrainForgePlugin instance2 = TerrainForgePlugin.Instance;
				if (instance2 != null)
				{
					((BaseUnityPlugin)instance2).Config.Save();
				}
			}
			catch
			{
			}
			Cursor.visible = _cursorWasVisible;
			Cursor.lockState = _cursorLock;
		}

		private void OnGUI()
		{
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Invalid comparison between Unknown and I4
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			if (_open)
			{
				Cursor.visible = true;
				Cursor.lockState = (CursorLockMode)0;
				((Rect)(ref _window)).width = Mathf.Clamp(((Rect)(ref _window)).width, Mathf.Min(620f, (float)Screen.width - 16f), Mathf.Max(620f, (float)Screen.width - 16f));
				((Rect)(ref _window)).height = Mathf.Clamp(((Rect)(ref _window)).height, Mathf.Min(500f, (float)Screen.height - 16f), Mathf.Max(500f, (float)Screen.height - 16f));
				((Rect)(ref _window)).x = Mathf.Clamp(((Rect)(ref _window)).x, 8f, Mathf.Max(8f, (float)Screen.width - ((Rect)(ref _window)).width - 8f));
				((Rect)(ref _window)).y = Mathf.Clamp(((Rect)(ref _window)).y, 8f, Mathf.Max(8f, (float)Screen.height - ((Rect)(ref _window)).height - 8f));
				EnsureSkin();
				if ((int)Event.current.type == 7)
				{
					GUI.color = new Color(0f, 0f, 0f, 0.58f);
					GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)_texBackdrop);
					GUI.color = Color.white;
				}
				_window = GUILayout.Window(9911735, _window, new WindowFunction(DrawWindow), GUIContent.none, _winStyle, Array.Empty<GUILayoutOption>());
			}
		}

		private void DrawWindow(int id)
		{
			//IL_00a4: 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_019c: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(_headerStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Label("TERRAINFORGE", _titleStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			if (GUILayout.Button("✕", _closeStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(30f),
				GUILayout.Height(24f)
			}))
			{
				Toggle(open: false);
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(8f);
			DrawTabRow(0, 1, 2);
			GUILayout.Space(4f);
			DrawTabRow(3, 4, 5);
			GUILayout.Space(10f);
			_mainScroll = GUILayout.BeginScrollView(_mainScroll, _scrollStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.MinHeight(240f),
				GUILayout.ExpandHeight(true)
			});
			DrawTabIntro();
			if (_tab == 0)
			{
				DrawToolTab();
			}
			else if (_tab == 1)
			{
				DrawKeysTab();
			}
			else if (_tab == 2)
			{
				DrawAdvancedTab();
			}
			else if (_tab == 3)
			{
				DrawSettingsTabContent();
			}
			else if (_tab == 5)
			{
				DrawStampTab();
			}
			else
			{
				DrawHelpTabContent();
			}
			GUILayout.EndScrollView();
			GUILayout.Space(6f);
			if (GUILayout.Button(Loc.T("menu.coffee"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(22f) }))
			{
				try
				{
					Application.OpenURL("https://cafecito.app/byrka");
				}
				catch
				{
				}
			}
			GUILayout.EndVertical();
			DrawResizeGrip();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 34f));
		}

		private void DrawTabIntro()
		{
			GUILayout.Label(Loc.T(_tab switch
			{
				0 => "tabintro.tool", 
				1 => "tabintro.keys", 
				2 => "tabintro.advanced", 
				3 => "tabintro.settings", 
				5 => "tabintro.stamps", 
				_ => "tabintro.help", 
			}), _hintStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(8f);
		}

		private void SelectTab(int tab)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (_tab != tab)
			{
				_tab = tab;
				_mainScroll = Vector2.zero;
			}
		}

		private void DrawTabRow(int first, int second, int third)
		{
			int[] array = new int[3] { first, second, third };
			string[] array2 = new string[6] { "tab.tool", "tab.keys", "tab.advanced", "tab.settings", "tab.help", "tab.stamps" };
			float num = Mathf.Max(80f, (((Rect)(ref _window)).width - 52f) / 3f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (int num2 in array)
			{
				if (GUILayout.Toggle(_tab == num2, Loc.T(array2[num2]), _tabStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(num),
					GUILayout.Height(32f)
				}))
				{
					SelectTab(num2);
				}
			}
			GUILayout.EndHorizontal();
		}

		private void DrawResizeGrip()
		{
			//IL_0033: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Invalid comparison between Unknown and I4
			//IL_0061: 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_013a: Invalid comparison between Unknown and I4
			//IL_00a4: 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)
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref _window)).width - 22f, ((Rect)(ref _window)).height - 22f, 22f, 22f);
			GUI.Label(val, "◢", _gripStyle);
			Event current = Event.current;
			if (current != null)
			{
				if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
				{
					_resizing = true;
					current.Use();
				}
				else if (_resizing && (int)current.type == 3)
				{
					((Rect)(ref _window)).width = Mathf.Clamp(((Rect)(ref _window)).width + current.delta.x, Mathf.Min(620f, (float)Screen.width - 30f), (float)Screen.width - 30f);
					((Rect)(ref _window)).height = Mathf.Clamp(((Rect)(ref _window)).height + current.delta.y, Mathf.Min(500f, (float)Screen.height - 30f), (float)Screen.height - 30f);
					current.Use();
				}
				else if (_resizing && (int)current.type == 1)
				{
					_resizing = false;
					current.Use();
				}
			}
		}

		private void DrawToolTab()
		{
			TerrainForgePlugin p = TerrainForgePlugin.Instance;
			if ((Object)(object)p == (Object)null)
			{
				return;
			}
			SettingHeader(Loc.T("set.operation"));
			DrawOpPicker(p);
			if (p.DefaultOperation.Value == TerrainOperation.Ramp)
			{
				DrawRampToolControls(p);
				return;
			}
			if (p.DefaultOperation.Value == TerrainOperation.CopyPaste)
			{
				DrawCopyPasteToolControls(p);
				return;
			}
			SettingHeader(Loc.T("set.shape"));
			DrawShapePicker(p);
			if (p.DefaultOperation.Value == TerrainOperation.Paint)
			{
				SettingHeader(Loc.T("set.paint"));
				CycleRow(Loc.T("set.paint"), p.Paint.Value.ToString(), delegate
				{
					p.Paint.Value = (TerrainPaint)((int)(p.Paint.Value + 1) % 6);
				});
			}
			else if (p.DefaultOperation.Value == TerrainOperation.Smooth)
			{
				CycleRow(Loc.T("set.smoothmode"), SmoothModeText(p.SmoothMode.Value), delegate
				{
					p.SmoothMode.Value = (SmoothMode)((int)(p.SmoothMode.Value + 1) % 3);
				});
			}
			SettingHeader(Loc.T("set.sizes"));
			FloatSlider(Loc.T("set.radius"), p.Radius, 1f, 100f, "0.#");
			FloatSlider(Loc.T("set.softness"), p.Softness, 0f, 100f, "0");
			if (p.DefaultOperation.Value == TerrainOperation.Flatten)
			{
				DrawFixedHeight(p);
			}
			else if (p.DefaultOperation.Value == TerrainOperation.Raise || p.DefaultOperation.Value == TerrainOperation.Lower)
			{
				CycleRow(Loc.T("set.falloff"), FalloffModeText(p.FalloffMode.Value), delegate
				{
					p.FalloffMode.Value = (FalloffMode)((int)(p.FalloffMode.Value + 1) % 4);
				});
				FloatSlider(Loc.T("set.raisedelta"), p.RaiseDelta, 0.5f, 10f, "0.#");
				FloatSlider(Loc.T("set.falloffpower"), p.FalloffPower, 1f, 5f, "0.#");
			}
			else if (p.DefaultOperation.Value == TerrainOperation.Shore)
			{
				FloatSlider(Loc.T("set.shoreoffset"), p.ShoreOffset, -2f, 5f, "0.#");
				CycleRow(Loc.T("set.shorefalloff"), ShoreFalloffModeText(p.ShoreFalloffMode.Value), delegate
				{
					p.ShoreFalloffMode.Value = (ShoreFalloffMode)((int)(p.ShoreFalloffMode.Value + 1) % 4);
				});
			}
		}

		private void DrawRampToolControls(TerrainForgePlugin p)
		{
			SettingHeader(Loc.T("set.rampmode"));
			RampMode[] array = new RampMode[3]
			{
				RampMode.TwoPoint,
				RampMode.FixedAngle,
				RampMode.Path
			};
			string[] array2 = new string[3]
			{
				Loc.T("rampmode.two"),
				Loc.T("rampmode.fixed"),
				Loc.T("rampmode.path")
			};
			float num = Mathf.Max(100f, (((Rect)(ref _window)).width - 52f) / (float)array.Length);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			for (int i = 0; i < array.Length; i++)
			{
				int num2 = i;
				if (GUILayout.Toggle(p.RampMode.Value == array[i], array2[i], _tabStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(num),
					GUILayout.Height(38f)
				}) && p.RampMode.Value != array[i])
				{
					p.RampMode.Value = array[num2];
					TerrainBrush.RequestClearMarks();
				}
			}
			GUILayout.EndHorizontal();
			SettingHeader(Loc.T("set.ramp.tools"));
			if (p.RampMode.Value == RampMode.FixedAngle)
			{
				FloatSlider(Loc.T("set.angle"), p.SlopeAngle, 5f, 60f, "0");
			}
			FloatSlider(Loc.T("set.ramp.width"), p.Radius, 1f, 100f, "0.#");
			FloatSlider(Loc.T("set.softness"), p.Softness, 0f, 100f, "0");
			GUILayout.Label(Loc.T("set.ramp.hint"), _hintStyle, Array.Empty<GUILayoutOption>());
		}

		private void DrawCopyPasteToolControls(TerrainForgePlugin p)
		{
			SettingHeader(Loc.T("set.shape"));
			DrawShapePicker(p);
			SettingHeader(Loc.T("set.sizes"));
			FloatSlider(Loc.T("set.radius"), p.Radius, 1f, 100f, "0.#");
			FloatSlider(Loc.T("set.softness"), p.Softness, 0f, 100f, "0");
			GUILayout.Label(Loc.T("set.copy.hint"), _hintStyle, Array.Empty<GUILayoutOption>());
		}

		private void DrawOpPicker(TerrainForgePlugin p)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			TerrainOperation value = p.DefaultOperation.Value;
			TerrainOperation[] array = new TerrainOperation[9]
			{
				TerrainOperation.Flatten,
				TerrainOperation.Raise,
				TerrainOperation.Lower,
				TerrainOperation.Smooth,
				TerrainOperation.Paint,
				TerrainOperation.Restore,
				TerrainOperation.Ramp,
				TerrainOperation.Shore,
				TerrainOperation.CopyPaste
			};
			for (int i = 0; i < array.Length; i += 5)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				for (int j = i; j < array.Length && j < i + 5; j++)
				{
					TerrainOperation terrainOperation = array[j];
					bool flag = terrainOperation == value;
					GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(74f) });
					if (GUILayout.Button(new GUIContent((Texture)(object)TerrainUiIcons.Op(terrainOperation), Loc.OpName(terrainOperation)), flag ? _iconBtnSelStyle : _iconBtnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(68f),
						GUILayout.Height(46f)
					}))
					{
						p.DefaultOperation.Value = terrainOperation;
						TerrainBrush.RequestClearMarks();
					}
					GUILayout.Label(Loc.OpName(terrainOperation), flag ? _iconCapSelStyle : _iconCapStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(74f),
						GUILayout.Height(14f)
					});
					GUILayout.EndVertical();
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.Space(2f);
		}

		private void DrawShapePicker(TerrainForgePlugin p)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			TerrainShape value = p.Shape.Value;
			TerrainShape[] obj = (TerrainShape[])Enum.GetValues(typeof(TerrainShape));
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			TerrainShape[] array = obj;
			foreach (TerrainShape terrainShape in array)
			{
				bool flag = terrainShape == value;
				GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(64f) });
				if (GUILayout.Button(new GUIContent((Texture)(object)TerrainUiIcons.Shape(terrainShape), ShapeText(terrainShape)), flag ? _iconBtnSelStyle : _iconBtnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(58f),
					GUILayout.Height(46f)
				}))
				{
					p.Shape.Value = terrainShape;
					TerrainBrush.RequestClearMarks();
				}
				GUILayout.Label(ShapeText(terrainShape), flag ? _iconCapSelStyle : _iconCapStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(64f),
					GUILayout.Height(14f)
				});
				GUILayout.EndVertical();
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(2f);
		}

		private void DrawKeysTab()
		{
			//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_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			GUILayout.Label((_capturing >= 0) ? Loc.T("keys.hint.capture") : Loc.T("keys.hint.idle"), (_capturing >= 0) ? _capturingStyle : _hintStyle, Array.Empty<GUILayoutOption>());
			GUILayout.Space(6f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("set.search"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.Height(26f)
			});
			_keySearch = GUILayout.TextField(_keySearch ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			if (GUILayout.Button("X", _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(44f),
				GUILayout.Height(26f)
			}))
			{
				_keySearch = "";
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(8f);
			string text = (_keySearch ?? "").Trim().ToLowerInvariant();
			for (int i = 0; i < _entries.Count; i++)
			{
				if (text.Length <= 0 || _entries[i].Label.ToLowerInvariant().Contains(text))
				{
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					Color color = GUI.color;
					GUI.color = (Color)((_capturing == i) ? new Color(1f, 0.85f, 0.45f) : Color.white);
					GUILayout.Label(_entries[i].Label, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(250f),
						GUILayout.Height(26f)
					});
					GUI.color = color;
					if (GUILayout.Button((_capturing == i) ? Loc.T("keys.press") : ((object)_entries[i].Bind.Value/*cast due to .constrained prefix*/).ToString(), (_capturing == i) ? _capturingBtnStyle : _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(235f),
						GUILayout.Height(26f)
					}))
					{
						_capturing = i;
					}
					GUILayout.EndHorizontal();
					GUILayout.Space(3f);
				}
			}
			GUILayout.Space(6f);
			if (GUILayout.Button(Loc.T("set.resetkeys"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
			{
				ResetKeybinds();
			}
			GUILayout.Space(10f);
			if (GUILayout.Button(Loc.T("btn.get"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
			{
				TerrainTool.Give(Player.m_localPlayer);
			}
		}

		private void DrawAdvancedTab()
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				DrawQuickActions();
				SettingHeader(Loc.T("set.snapshots"));
				DrawSnapshots();
				SettingHeader(Loc.T("set.profiles"));
				DrawPresets(instance);
				GUILayout.Space(10f);
				DrawHistorySection();
			}
		}

		private void DrawStampTab()
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				SettingHeader(Loc.T("help.stamp.t"));
				GUILayout.Label(Loc.T("stamp.workflow"), _hintStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Space(8f);
				IReadOnlyList<TerrainEngine.TerrainStamp> clipboard = TerrainEngine.GetClipboard();
				TerrainEngine.TerrainStamp stamp = TerrainEngine.GetStamp();
				string text = ((stamp != null && !string.IsNullOrEmpty(stamp.Label)) ? stamp.Label : Loc.T("set.stampnoclip"));
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(Loc.T("act.copystamp"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
				{
					TerrainBrush.RequestCopyStamp();
					Toggle(open: false);
				}
				if (GUILayout.Button(Loc.T("act.pastestamp"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(34f) }))
				{
					TerrainBrush.RequestPasteStamp();
					Toggle(open: false);
				}
				GUILayout.EndHorizontal();
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(Loc.F("stamp.clipboard", clipboard.Count, 10), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
				GUILayout.FlexibleSpace();
				if (GUILayout.Button(Loc.T("key.cycleStampBack"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(145f),
					GUILayout.Height(26f)
				}))
				{
					TerrainBrush.RequestCycleStampBack();
					Toggle(open: false);
				}
				if (GUILayout.Button(Loc.T("key.cycleStamp"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(130f),
					GUILayout.Height(26f)
				}))
				{
					TerrainBrush.RequestCycleStamp();
					Toggle(open: false);
				}
				GUILayout.EndHorizontal();
				GUILayout.Label(text, _hintStyle, Array.Empty<GUILayoutOption>());
				GUILayout.Space(12f);
				SettingHeader(Loc.T("set.stamps"));
				DrawStamps(instance);
			}
		}

		private void DrawQuickActions()
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (!((Object)(object)instance == (Object)null))
			{
				SettingHeader(Loc.T("set.quick"));
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(Loc.T("key.undo"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					TerrainBrush.RequestUndo();
				}
				if (GUILayout.Button(Loc.T("key.redo"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					TerrainBrush.RequestRedo();
				}
				if (GUILayout.Button(Loc.T("act.eyedrop"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					TerrainBrush.RequestEyedrop();
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(3f);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(Loc.T("act.clearmarks"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					TerrainBrush.RequestClearMarks();
				}
				if (GUILayout.Button(Loc.T("set.slopeheatmap"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					instance.ShowSlopeHeatmap.Value = !instance.ShowSlopeHeatmap.Value;
				}
				if (GUILayout.Button(Loc.T("set.heightheatmap"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					instance.ShowHeightHeatmap.Value = !instance.ShowHeightHeatmap.Value;
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(3f);
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (GUILayout.Button(Loc.T("act.diag"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					TerrainBrush.RequestDumpMaterial();
				}
				if (GUILayout.Button(Loc.T("key.freecam"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					TerrainBrush.RequestFreeCamera();
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(3f);
			}
		}

		private void ResetKeybinds()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)TerrainForgePlugin.Instance == (Object)null))
			{
				for (int i = 0; i < _entries.Count; i++)
				{
					_entries[i].Bind.Value = (KeyboardShortcut)((ConfigEntryBase)_entries[i].Bind).DefaultValue;
				}
				_capturing = -1;
				TerrainForgePlugin.Message(Loc.T("keys.resetdone"));
			}
		}

		private static bool TryParseLenient(string t, out float v)
		{
			if (float.TryParse(t, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
			{
				return true;
			}
			return float.TryParse(t, out v);
		}

		private void DrawFixedHeight(TerrainForgePlugin p)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("set.fixedheight"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(140f),
				GUILayout.Height(26f)
			});
			string text = GUILayout.TextField(_fixedHeightText ?? p.FixedHeight.Value.ToString("0.0"), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.Height(26f)
			});
			if (text != _fixedHeightText)
			{
				_fixedHeightText = text;
				if (TryParseLenient(text, out var v))
				{
					p.FixedHeight.Value = Mathf.Clamp(v, -10f, 150f);
				}
			}
			if (GUILayout.Button(Loc.T("set.fix"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(85f),
				GUILayout.Height(26f)
			}))
			{
				if (TryParseLenient(_fixedHeightText ?? "", out var v2))
				{
					p.FixedHeight.Value = Mathf.Clamp(v2, -10f, 150f);
				}
				p.UseFixedHeight.Value = true;
				_fixedHeightText = p.FixedHeight.Value.ToString("0.0");
			}
			if (GUILayout.Button(Loc.T("set.release"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(85f),
				GUILayout.Height(26f)
			}))
			{
				p.UseFixedHeight.Value = false;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
		}

		private void DrawPresets(TerrainForgePlugin p)
		{
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("set.profilename"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.Height(26f)
			});
			_presetName = GUILayout.TextField(_presetName ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			if (GUILayout.Button(Loc.T("set.profilesave"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(130f),
				GUILayout.Height(26f)
			}) && !string.IsNullOrEmpty((_presetName ?? "").Trim()))
			{
				TerrainPresets.SaveCurrent(_presetName.Trim());
				_presetName = "";
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
			List<TerrainPresets.Preset> list = TerrainPresets.Load();
			if (list.Count == 0)
			{
				GUILayout.Label(Loc.T("set.profileempty"), _hintStyle, Array.Empty<GUILayoutOption>());
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				TerrainPresets.Preset preset = list[i];
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(new GUIContent((Texture)(object)TerrainUiIcons.Op(preset.Operation)), _iconOnlyStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(24f),
					GUILayout.Height(24f)
				});
				GUILayout.Label(new GUIContent((Texture)(object)TerrainUiIcons.Shape(preset.Shape)), _iconOnlyStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(24f),
					GUILayout.Height(24f)
				});
				GUILayout.Label(preset.Name, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(120f),
					GUILayout.Height(26f)
				});
				GUILayout.Label(PresetSummary(preset), _hintStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(190f),
					GUILayout.Height(26f)
				});
				if (GUILayout.Button(Loc.T("set.profileload"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(110f),
					GUILayout.Height(26f)
				}))
				{
					TerrainPresets.ApplyPreset(preset);
					TerrainBrush.RequestClearMarks();
				}
				if (GUILayout.Button("X", _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(50f),
					GUILayout.Height(26f)
				}))
				{
					TerrainPresets.Delete(preset.Name);
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(3f);
			}
		}

		private string PresetSummary(TerrainPresets.Preset pr)
		{
			return string.Format("{0} · {1} · r{2}", Loc.OpName(pr.Operation), ShapeText(pr.Shape), pr.Radius.ToString("0.#"));
		}

		private void DrawSnapshots()
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("set.profilename"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.Height(26f)
			});
			_snapshotName = GUILayout.TextField(_snapshotName ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			if (GUILayout.Button(Loc.T("set.profilesave"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(130f),
				GUILayout.Height(26f)
			}))
			{
				string text = (_snapshotName ?? "").Trim();
				if (text.Length == 0)
				{
					text = "Snapshot-" + DateTime.Now.ToString("yyyyMMdd-HHmm");
				}
				if (TerrainEngine.ExportSnapshot(text, out var message))
				{
					_snapshotName = "";
				}
				TerrainForgePlugin.Message(message);
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
			List<string> list = TerrainEngine.SnapshotNames();
			if (list.Count == 0)
			{
				GUILayout.Label(Loc.T("set.snapshotempty"), _hintStyle, Array.Empty<GUILayoutOption>());
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				string text2 = list[i];
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(text2, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(215f),
					GUILayout.Height(26f)
				});
				if (GUILayout.Button(Loc.T("set.profileload"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(120f),
					GUILayout.Height(26f)
				}))
				{
					TerrainEngine.ImportSnapshot(text2, out var message2);
					TerrainForgePlugin.Message(message2);
				}
				if (GUILayout.Button("X", _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(60f),
					GUILayout.Height(26f)
				}))
				{
					TerrainEngine.DeleteSnapshot(text2);
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(3f);
			}
		}

		private void DrawStamps(TerrainForgePlugin p)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("set.stampname"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.Height(26f)
			});
			_stampName = GUILayout.TextField(_stampName ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			if (GUILayout.Button(Loc.T("set.stampsave"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(130f),
				GUILayout.Height(26f)
			}) && !string.IsNullOrEmpty((_stampName ?? "").Trim()))
			{
				TerrainEngine.TerrainStamp stamp = TerrainEngine.GetStamp();
				if (stamp != null)
				{
					TerrainEngine.SaveStamp(_stampName.Trim(), stamp, out var message);
					TerrainForgePlugin.Message(message);
					_stampName = "";
				}
				else
				{
					TerrainForgePlugin.Message(Loc.T("set.stampnoclip"));
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("set.stampload"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(90f),
				GUILayout.Height(26f)
			});
			_stampLoadName = GUILayout.TextField(_stampLoadName ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			if (GUILayout.Button(Loc.T("set.stamploadbtn"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(130f),
				GUILayout.Height(26f)
			}) && !string.IsNullOrEmpty((_stampLoadName ?? "").Trim()))
			{
				TerrainEngine.LoadStampToClipboard(_stampLoadName.Trim(), out var message2);
				TerrainForgePlugin.Message(message2);
				_stampLoadName = "";
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
			List<string> list = TerrainEngine.StampNames();
			if (list.Count == 0)
			{
				GUILayout.Label(Loc.T("set.stampempty"), _hintStyle, Array.Empty<GUILayoutOption>());
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				string text = list[i];
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label(text, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(215f),
					GUILayout.Height(26f)
				});
				if (GUILayout.Button(Loc.T("set.stamploadbtn"), _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(120f),
					GUILayout.Height(26f)
				}))
				{
					TerrainEngine.LoadStampToClipboard(text, out var message3);
					TerrainForgePlugin.Message(message3);
				}
				if (GUILayout.Button("X", _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(60f),
					GUILayout.Height(26f)
				}))
				{
					TerrainEngine.DeleteStamp(text);
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(3f);
			}
		}

		private void DrawHistorySection()
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if ((Object)(object)instance == (Object)null || instance.UndoDepth == null)
			{
				return;
			}
			GUILayout.Label(Loc.T("hist.title"), _hintStyle, Array.Empty<GUILayoutOption>());
			int num = Mathf.Clamp(instance.UndoDepth.Value, 0, 500);
			int num2 = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)num, 0f, 200f, Array.Empty<GUILayoutOption>()));
			if (num2 != num)
			{
				instance.UndoDepth.Value = num2;
				_undoDepthText = num2.ToString();
				if (num2 <= 0)
				{
					TerrainEngine.ClearHistory();
				}
			}
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(Loc.T("hist.exact"), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(250f),
				GUILayout.Height(26f)
			});
			string text = GUILayout.TextField(_undoDepthText ?? num.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(235f),
				GUILayout.Height(26f)
			});
			if (text != _undoDepthText)
			{
				_undoDepthText = text;
				if (int.TryParse(text, out var result))
				{
					result = Mathf.Clamp(result, 0, 500);
					if (result != instance.UndoDepth.Value)
					{
						instance.UndoDepth.Value = result;
						if (result <= 0)
						{
							TerrainEngine.ClearHistory();
						}
					}
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.Label(Loc.F("hist.saved", TerrainEngine.UndoCount, TerrainEngine.RedoCount), _hintStyle, Array.Empty<GUILayoutOption>());
		}

		private void DrawSettingsTabContent()
		{
			TerrainForgePlugin p = TerrainForgePlugin.Instance;
			if (!((Object)(object)p == (Object)null))
			{
				SettingHeader(Loc.T("set.general"));
				CycleRow(Loc.T("set.language"), p.Language.Value.ToString(), delegate
				{
					ModLanguage[] array = new ModLanguage[15]
					{
						ModLanguage.Auto,
						ModLanguage.English,
						ModLanguage.Español,
						ModLanguage.Français,
						ModLanguage.Deutsch,
						ModLanguage.Русский,
						ModLanguage.中文,
						ModLanguage.繁體中文,
						ModLanguage.日本語,
						ModLanguage.한국어,
						ModLanguage.Polski,
						ModLanguage.Português,
						ModLanguage.Türkçe,
						ModLanguage.Українська,
						ModLanguage.Italiano
					};
					int num = Array.IndexOf(array, p.Language.Value);
					p.Language.Value = array[(num + 1) % array.Length];
				});
				SettingHeader(Loc.T("set.tool"));
				BoolToggle(Loc.T("set.tooltint"), p.ToolTint);
				CycleRow(Loc.T("set.toolcolor"), p.ToolTintColor.Value, delegate
				{
					string[] array = new string[6] { "#4FC3F7", "#FFC400", "#8BC34A", "#FF5252", "#AB47BC", "#FFFFFF" };
					int num = Array.IndexOf(array, p.ToolTintColor.Value);
					p.ToolTintColor.Value = array[(num + 1) % array.Length];
				});
				BoolToggle(Loc.T("set.autogive"), p.AutoGiveTool);
				BoolToggle(Loc.T("set.blockvanilla"), p.BlockVanillaTerrainTools);
				CycleRow(Loc.T("set.stamptool"), StampToolModeText(p.StampToolMode.Value), delegate
				{
					p.StampToolMode.Value = (StampToolMode)((int)(p.StampToolMode.Value + 1) % 4);
				});
				SettingHeader(Loc.T("set.view"));
				BoolToggle(Loc.T("set.preview"), p.ShowPreview);
				BoolToggle(Loc.T("set.guides"), p.ShowGuides);
				BoolToggle(Loc.T("set.slopeheatmap"), p.ShowSlopeHeatmap);
				BoolToggle(Loc.T("set.heightheatmap"), p.ShowHeightHeatmap);
				BoolToggle(Loc.T("set.effects"), p.PlayEffects);
				SettingHeader(Loc.T("set.vanilla"));
				BoolToggle(Loc.T("set.nocost"), p.NoBuildCost);
				BoolToggle(Loc.T("set.protected"), p.AllowInProtectedZones);
				SettingHeader(Loc.T("set.server"));
				BoolToggle(Loc.T("set.deltalimit"), p.UnlockDeltaLimit);
				BoolToggle(Loc.T("set.allow"), p.AllowTerrainEdits);
				BoolToggle(Loc.T("set.adminonly"), p.AdminOnlyEdits);
				BoolToggle(Loc.T("set.respectwards"), p.RespectWards);
				FloatSlider(Loc.T("set.radiuscap"), p.RadiusCap, 0f, 100f, "0.#");
				FloatSlider(Loc.T("set.deltacap"), p.DeltaCap, 0f, 64f, "0.#");
				IntSlider(Loc.T("set.chunkcomps"), p.ChunkCompsPerFrame, 1, 32);
			}
		}

		private void SettingHeader(string text)
		{
			GUILayout.Space(6f);
			GUILayout.Label(text, _topicStyle, Array.Empty<GUILayoutOption>());
		}

		private void CycleRow(string label, string value, Action onClick)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(215f),
				GUILayout.Height(26f)
			});
			if (GUILayout.Button(value, _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(205f),
				GUILayout.Height(26f)
			}))
			{
				onClick();
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
		}

		private void SegmentedRow(string label, string[] options, int current, Action<int> onSelect)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(215f),
				GUILayout.Height(26f)
			});
			for (int i = 0; i < options.Length; i++)
			{
				if (GUILayout.Button(options[i], (i == current) ? _capturingBtnStyle : _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) }))
				{
					onSelect(i);
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
		}

		private void FloatSlider(string label, ConfigEntry<float> entry, float min, float max, string fmt)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label + ": " + entry.Value.ToString(fmt), _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(215f),
				GUILayout.Height(26f)
			});
			float num = GUILayout.HorizontalSlider(entry.Value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(205f),
				GUILayout.Height(26f)
			});
			if (!Mathf.Approximately(num, entry.Value))
			{
				entry.Value = num;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
		}

		private void IntSlider(string label, ConfigEntry<int> entry, int min, int max)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label + ": " + entry.Value, _rowStyle, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(215f),
				GUILayout.Height(26f)
			});
			int num = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)entry.Value, (float)min, (float)max, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(205f),
				GUILayout.Height(26f)
			}));
			if (num != entry.Value)
			{
				entry.Value = num;
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
		}

		private void BoolToggle(string label, ConfigEntry<bool> entry)
		{
			bool flag = GUILayout.Toggle(entry.Value, label, _btnStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(26f) });
			if (flag != entry.Value)
			{
				entry.Value = flag;
			}
			GUILayout.Space(3f);
		}

		private static string ShapeText(TerrainShape s)
		{
			return s switch
			{
				TerrainShape.Square => Loc.T("shape.square"), 
				TerrainShape.Line => Loc.T("shape.line"), 
				TerrainShape.Rect => Loc.T("shape.rect"), 
				TerrainShape.Poly => Loc.T("shape.poly"), 
				_ => Loc.T("shape.circle"), 
			};
		}

		private static string RampModeText(RampMode m)
		{
			return m switch
			{
				RampMode.FixedAngle => Loc.T("rampmode.fixed"), 
				RampMode.Path => Loc.T("rampmode.path"), 
				_ => Loc.T("rampmode.two"), 
			};
		}

		private static string SmoothModeText(SmoothMode m)
		{
			return m switch
			{
				SmoothMode.Bumps => Loc.T("smooth.bumps"), 
				SmoothMode.Dips => Loc.T("smooth.dips"), 
				_ => Loc.T("smooth.full"), 
			};
		}

		private static string FalloffModeText(FalloffMode m)
		{
			return m switch
			{
				FalloffMode.Flat => Loc.T("falloff.flat"), 
				FalloffMode.Smooth => Loc.T("falloff.smooth"), 
				FalloffMode.Linear => Loc.T("falloff.linear"), 
				_ => Loc.T("falloff.pointy"), 
			};
		}

		private static string ShoreFalloffModeText(ShoreFalloffMode m)
		{
			return m switch
			{
				ShoreFalloffMode.Linear => Loc.T("shorefalloff.linear"), 
				ShoreFalloffMode.Smooth => Loc.T("shorefalloff.smooth"), 
				ShoreFalloffMode.Flat => Loc.T("shorefalloff.flat"), 
				_ => Loc.T("shorefalloff.pointy"), 
			};
		}

		private static string StampToolModeText(StampToolMode m)
		{
			return m switch
			{
				StampToolMode.Any => Loc.T("stamptool.any"), 
				StampToolMode.Pickaxe => Loc.T("stamptool.pickaxe"), 
				StampToolMode.TerrainForgeTool => Loc.T("stamptool.rod"), 
				_ => Loc.T("stamptool.main"), 
			};
		}

		private void DrawHelpTabContent()
		{
			Topic(Loc.T("help.what.t"));
			Body(Loc.T("help.what.b"));
			Topic(Loc.T("help.tool.t"));
			Body(Loc.T("help.tool.b"));
			Topic(Loc.T("help.ops.t"));
			Body(Loc.T("help.ops.b"));
			Topic(Loc.T("help.controls.t"));
			Body(Loc.T("help.controls.b"));
			Topic(Loc.T("help.preview.t"));
			Body(Loc.T("help.preview.b"));
			Topic(Loc.T("help.stamp.t"));
			Body(Loc.T("help.stamp.b"));
			Topic(Loc.T("help.mp.t"));
			Body(Loc.T("help.mp.b"));
			Topic(Loc.T("help.save.t"));
			Body(Loc.T("help.save.b"));
		}

		private void Topic(string text)
		{
			GUILayout.Space(10f);
			GUILayout.Label(text, _topicStyle, Array.Empty<GUILayoutOption>());
		}

		private void Body(string text)
		{
			GUILayout.Label(text, _bodyStyle, Array.Empty<GUILayoutOption>());
		}

		private void EnsureSkin()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_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_0026: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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: Expected O, but got Unknown
			//IL_012e: 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_0144: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: 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_0181: Expected O, but got Unknown
			//IL_0181: 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_0190: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01c9: Expected O, but got Unknown
			//IL_01d4: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Expected O, but got Unknown
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Expected O, but got Unknown
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Expected O, but got Unknown
			//IL_03ab: 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_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Expected O, but got Unknown
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Expected O, but got Unknown
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Expected O, but got Unknown
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Expected O, but got Unknown
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Expected O, but got Unknown
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Expected O, but got Unknown
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Expected O, but got Unknown
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Expected O, but got Unknown
			//IL_0504: Expected O, but got Unknown
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Expected O, but got Unknown
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: 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_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: 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_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: 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_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: 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_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Expected O, but got Unknown
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_061c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Expected O, but got Unknown
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_065a: Unknown result type (might be due to invalid IL or missing references)
			//IL_065f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			//IL_066e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0688: Expected O, but got Unknown
			//IL_0693: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cb: Expected O, but got Unknown
			//IL_06d0: Expected O, but got Unknown
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0709: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_0720: Expected O, but got Unknown
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_074a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_0773: Unknown result type (might be due to invalid IL or missing references)
			//IL_0782: Unknown result type (might be due to invalid IL or missing references)
			//IL_079c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Expected O, but got Unknown
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07db: Expected O, but got Unknown
			//IL_07e0: Expected O, but got Unknown
			if (_winStyle == null)
			{
				Font font = TerrainBrush.GameFont();
				Color panelDark = TerrainTheme.PanelDark;
				Color panelHeader = TerrainTheme.PanelHeader;
				Color gold = TerrainTheme.Gold;
				Color goldBright = TerrainTheme.GoldBright;
				Color panelBg = TerrainTheme.PanelBg;
				Color button = TerrainTheme.Button;
				Color buttonHover = TerrainTheme.ButtonHover;
				Color buttonActive = TerrainTheme.ButtonActive;
				_ = TerrainTheme.TextGold;
				Color textWhite = TerrainTheme.TextWhite;
				Color textDim = TerrainTheme.TextDim;
				_ = TerrainTheme.TextBright;
				_texPanel = MakeTex(panelDark);
				_texBackdrop = MakeTex(Color.white);
				_texHeader = MakeTex(panelHeader);
				_texPanelBg = MakeTex(panelBg);
				_texBtn = MakeTex(button);
				_texBtnHover = MakeTex(buttonHover);
				_texBtnActive = MakeTex(buttonActive);
				_texCapture = MakeTex(buttonActive);
				GUIStyle val = new GUIStyle(GUI.skin.window);
				val.normal.background = _texPanel;
				val.focused.background = _texPanel;
				val.onNormal.background = _texPanel;
				val.onFocused.background = _texPanel;
				val.padding = new RectOffset(16, 16, 16, 16);
				val.font = font;
				val.border = new RectOffset(4, 4, 4, 4);
				val.stretchWidth = true;
				val.stretchHeight = true;
				_winStyle = val;
				GUIStyle val2 = new GUIStyle();
				val2.normal.background = _texPanelBg;
				val2.padding = new RectOffset(10, 10, 10, 10);
				val2.margin = new RectOffset(4, 4, 4, 4);
				val2.stretchWidth = true;
				_boxStyle = val2;
				GUIStyle val3 = new GUIStyle();
				val3.normal.background = _texHeader;
				val3.padding = new RectOffset(12, 12, 8, 8);
				_headerStyle = val3;
				_titleStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3,
					font = font
				};
				_titleStyle.normal.textColor = goldBright;
				_hintStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12,
					alignment = (TextAnchor)3,
					wordWrap = true,
					font = font
				};
				_hintStyle.normal.textColor = textDim;
				_capturingStyle = new GUIStyle(_hintStyle);
				_capturingStyle.normal.textColor = goldBright;
				_capturingStyle.fontStyle = (FontStyle)1;
				_rowStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 13,
					alignment = (TextAnchor)3,
					padding = new RectOffset(8, 8, 2, 2),
					font = font
				};
				_rowStyle.normal.textColor = textWhite;
				_capturingBtnStyle = MakeButtonStyle(font, _texCapture, _texCapture, _texCapture, goldBright);
				_capturingBtnStyle.fontStyle = (FontStyle)1;
				_capturingBtnStyle.fontSize = 13;
				_btnStyle = MakeButtonStyle(font, _texBtn, _texBtnHover, _texBtnActive, textWhite);
				_closeStyle = MakeButtonStyle(font, _texBtn, _texBtnHover, _texBtnActive, new Color(1f, 0.5f, 0.4f, 1f));
				_closeStyle.fontSize = 14;
				_closeStyle.fontStyle = (FontStyle)1;
				_gripStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 16,
					alignment = (TextAnchor)4,
					font = font
				};
				_gripStyle.normal.textColor = textDim;
				GUIStyle val4 = new GUIStyle(GUI.skin.button)
				{
					padding = new RectOffset(3, 3, 3, 3),
					margin = new RectOffset(2, 2, 2, 2),
					font = font
				};
				val4.normal.background = _texBtn;
				val4.hover.background = _texBtnHover;
				val4.active.background = _texBtnActive;
				_iconBtnStyle = val4;
				GUIStyle val5 = new GUIStyle(_iconBtnStyle);
				val5.normal.background = _texBtnActive;
				val5.hover.background = _texBtnActive;
				val5.active.background = _texBtnActive;
				_iconBtnSelStyle = val5;
				_iconCapStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 10,
					alignment = (TextAnchor)4,
					clipping = (TextClipping)1,
					font = font
				};
				_iconCapStyle.normal.textColor = textDim;
				_iconCapSelStyle = new GUIStyle(_iconCapStyle);
				_iconCapSelStyle.normal.textColor = goldBright;
				_iconOnlyStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					padding = new RectOffset(0, 0, 0, 0),
					margin = new RectOffset(1, 1, 0, 0)
				};
				GUIStyle val6 = new GUIStyle(GUI.skin.button)
				{
					fontSize = 13,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4,
					padding = new RectOffset(12, 12, 6, 6),
					font = font
				};
				val6.normal.background = _texBtn;
				val6.normal.textColor = textDim;
				val6.hover.background = _texBtnHover;
				val6.hover.textColor = gold;
				val6.active.background = _texBtnActive;
				val6.active.textColor = goldBright;
				val6.onNormal.background = _texBtnActive;
				val6.onNormal.textColor = goldBright;
				val6.onHover.background = _texBtnActive;
				val6.onHover.textColor = goldBright;
				val6.onActive.background = _texBtnActive;
				val6.onActive.textColor = goldBright;
				val6.stretchWidth = true;
				val6.fixedHeight = 30f;
				_tabStyle = val6;
				_topicStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3,
					font = font
				};
				_topicStyle.normal.textColor = gold;
				_bodyStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12,
					alignment = (TextAnchor)0,
					wordWrap = true,
					richText = true,
					font = font
				};
				_bodyStyle.normal.textColor = textWhite;
				GUIStyle val7 = new GUIStyle(GUI.skin.scrollView);
				val7.normal.background = _texPanelBg;
				val7.padding = new RectOffset(0, 12, 0, 0);
				_scrollStyle = val7;
				GUIStyle val8 = new GUIStyle(GUI.skin.verticalScrollbar);
				val8.normal.background = MakeTex(new Color(0.1f, 0.1f, 0.12f, 0.5f));
				val8.fixedWidth = 14f;
				val8.stretchWidth = false;
				_scrollBarStyle = val8;
				GUIStyle val9 = new GUIStyle(GUI.skin.verticalScrollbarThumb);
				val9.normal.background = MakeTex(new Color(0.3f, 0.3f, 0.35f, 0.8f));
				val9.hover.background = MakeTex(new Color(0.4f, 0.4f, 0.45f, 0.9f));
				val9.active.background = MakeTex(new Color(0.5f, 0.5f, 0.55f, 1f));
				val9.fixedWidth = 12f;
				val9.stretchWidth = false;
				val9.padding = new RectOffset(1, 1, 4, 4);
				val9.margin = new RectOffset(0, 0, 4, 4);
				_scrollBarThumbStyle = val9;
			}
		}

		private static GUIStyle MakeButtonStyle(Font font, Texture2D normal, Texture2D hover, Texture2D active, Color text)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//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_0040: 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_004d: 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_005f: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button)
			{
				fontSize = 14,
				alignment = (TextAnchor)4,
				padding = new RectOffset(8, 8, 4, 4),
				font = font
			};
			val.normal.background = normal;
			val.normal.textColor = text;
			val.hover.background = hover;
			val.hover.textColor = Color.white;
			val.active.background = active;
			val.active.textColor = Color.white;
			val.focused.background = normal;
			val.focused.textColor = text;
			return val;
		}

		private static Texture2D MakeTex(Color c)
		{
			//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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1)
			{
				hideFlags = (HideFlags)61
			};
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}

		private static bool ShortcutDown(KeyboardShortcut s)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected I4, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			KeyCode mainKey = ((KeyboardShortcut)(ref s)).MainKey;
			if ((int)mainKey == 0)
			{
				return false;
			}
			if ((mainKey - 323) switch
			{
				0 => Input.GetMouseButtonDown(0) ? 1 : 0, 
				1 => Input.GetMouseButtonDown(1) ? 1 : 0, 
				2 => Input.GetMouseButtonDown(2) ? 1 : 0, 
				_ => Input.GetKeyDown(mainKey) ? 1 : 0, 
			} == 0)
			{
				return false;
			}
			IEnumerable<KeyCode> modifiers = ((KeyboardShortcut)(ref s)).Modifiers;
			if (modifiers != null)
			{
				foreach (KeyCode item in modifiers)
				{
					if (!Input.GetKey(item))
					{
						return false;
					}
				}
			}
			return true;
		}

		internal static void CycleNextProfile()
		{
			TerrainForgePlugin p = TerrainForgePlugin.Instance;
			if ((Object)(object)p == (Object)null)
			{
				return;
			}
			List<TerrainPresets.Preset> list = TerrainPresets.Load();
			if (list.Count != 0)
			{
				int index = (list.FindIndex((TerrainPresets.Preset x) => x.Radius == p.Radius.Value && x.Softness == p.Softness.Value && x.Operation == p.DefaultOperation.Value && x.Shape == p.Shape.Value && x.Paint == p.Paint.Value && x.RampMode == p.RampMode.Value && x.SlopeAngle == p.SlopeAngle.Value && x.SmoothMode == p.SmoothMode.Value && x.RaiseDelta == p.RaiseDelta.Value && x.PaintStrength == p.PaintStrength.Value && x.FalloffPower == p.FalloffPower.Value && x.ShoreOffset == p.ShoreOffset.Value) + 1) % list.Count;
				TerrainPresets.ApplyPreset(list[index]);
				TerrainBrush.RequestClearMarks();
				TerrainForgePlugin.Message("Perfil: " + list[index].Name);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	internal static class TerrainMenuPlayerInputPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(Player __instance, ref bool __result)
		{
			if (!TerrainKeybinds.MenuOpen || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	internal static class TerrainMenuCameraPatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return !TerrainKeybinds.MenuOpen;
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	internal static class TerrainToolObjectDbPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ObjectDB __instance)
		{
			TerrainTool.Register(__instance);
			TerrainToolNetworkPrefabPatch.EnsureRegistered();
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	internal static class TerrainToolNetworkPrefabPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ZNetScene __instance)
		{
			TerrainTool.RegisterNetworkPrefab(__instance);
		}

		internal static void EnsureRegistered()
		{
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				TerrainTool.RegisterNetworkPrefab(ZNetScene.instance);
			}
		}
	}
	[HarmonyPatch(typeof(TerrainComp), "ApplyToHeightmap")]
	internal static class ApplyToHeightmapPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(TerrainComp __instance, Texture2D clearedMask, List<float> heights, float[] baseHeights, float[] levelOnlyHeights, Heightmap hm)
		{
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.UnlockDeltaLimit.Value)
			{
				return true;
			}
			if ((Object)(object)clearedMask == (Object)null || heights == null || baseHeights == null)
			{
				return true;
			}
			TerrainEngine.Cache();
			float[] array = TerrainEngine.LevelDelta(__instance);
			float[] array2 = TerrainEngine.SmoothDelta(__instance);
			bool[] array3 = TerrainEngine.ModifiedPaint(__instance);
			Color[] array4 = TerrainEngine.PaintMask(__instance);
			if (array == null || array2 == null || array3 == null || array4 == null)
			{
				return true;
			}
			int num = TerrainEngine.Width(__instance) + 1;
			float num2 = Mathf.Max(8f, instance.MaxUpDelta.Value);
			float num3 = Mathf.Max(8f, instance.MaxDownDelta.Value);
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					int num4 = i * num + j;
					float num5 = array[num4];
					float num6 = array2[num4];
					if (num5 != 0f || num6 != 0f)
					{
						float num7 = heights[num4] + num5 + num6;
						float num8 = baseHeights[num4];
						heights[num4] = Mathf.Clamp(num7, num8 - num3, num8 + num2);
					}
				}
			}
			for (int k = 0; k < num; k++)
			{
				for (int l = 0; l < num; l++)
				{
					int num9 = k * num + l;
					if (array3[num9])
					{
						clearedMask.SetPixel(l, k, array4[num9]);
					}
				}
			}
			return false;
		}
	}
	internal static class NoCostPatch
	{
		[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
		{
			typeof(Piece),
			typeof(RequirementMode)
		})]
		[HarmonyPrefix]
		private static bool HaveRequirementsPrefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result)
		{
			//IL_001e: 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_0023: Invalid comparison between Unknown and I4
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.NoBuildCost.Value)
			{
				return true;
			}
			if ((int)mode == 0 || (int)mode == 2)
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(Player), "ConsumeResources")]
		[HarmonyPrefix]
		private static bool ConsumeResourcesPrefix(Player __instance)
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.NoBuildCost.Value)
			{
				return true;
			}
			return false;
		}
	}
	internal static class NoBuildZonePatch
	{
		private static FieldInfo s_statusField;

		[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
		[HarmonyPostfix]
		private static void Postfix(Player __instance)
		{
			//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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Invalid comparison between Unknown and I4
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.AllowInProtectedZones.Value || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return;
			}
			if (s_statusField == null)
			{
				s_statusField = AccessTools.Field(typeof(Player), "m_placementStatus");
			}
			if (!(s_statusField == null))
			{
				PlacementStatus val = (PlacementStatus)s_statusField.GetValue(__instance);
				if ((int)val == 3 || (int)val == 4)
				{
					s_statusField.SetValue(__instance, (object)(PlacementStatus)0);
				}
			}
		}
	}
	internal static class ToolRadiusPatch
	{
		private static PlacementRadiusScope s_scope;

		[HarmonyPatch(typeof(Player), "TryPlacePiece")]
		[HarmonyPrefix]
		private static void Prefix(Player __instance, Piece piece)
		{
			Restore();
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.ScaleVanillaToolRadius.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && !((Object)(object)piece == (Object)null))
			{
				float target = Mathf.Clamp(instance.VanillaToolRadius.Value, 1f, 100f);
				PlacementRadiusScope placementRadiusScope = new PlacementRadiusScope();
				ScaleTerrainComponents(((Component)piece).gameObject, target, placementRadiusScope);
				if (placementRadiusScope.Count == 0)
				{
					placementRadiusScope.Restore();
				}
				else
				{
					s_scope = placementRadiusScope;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "TryPlacePiece")]
		[HarmonyFinalizer]
		private static Exception Finalizer(Exception __exception)
		{
			Restore();
			return __exception;
		}

		private static void Restore()
		{
			if (s_scope == null)
			{
				return;
			}
			try
			{
				s_scope.Restore();
			}
			finally
			{
				s_scope = null;
			}
		}

		private static void ScaleTerrainComponents(GameObject root, float target, PlacementRadiusScope scope)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			TerrainOp[] componentsInChildren = root.GetComponentsInChildren<TerrainOp>(true);
			foreach (TerrainOp val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || val.m_settings == null)
				{
					continue;
				}
				Settings s = val.m_settings;
				float radius = s.GetRadius();
				if (!(radius <= 0.001f))
				{
					float num = target / radius;
					float l = s.m_levelRadius;
					float r = s.m_raiseRadius;
					float sm = s.m_smoothRadius;
					float p = s.m_paintRadius;
					bool level = s.m_level;
					bool raise = s.m_raise;
					bool smooth = s.m_smooth;
					bool paintCleared = s.m_paintCleared;
					scope.Add(delegate
					{
						s.m_levelRadius = l;
						s.m_raiseRadius = r;
						s.m_smoothRadius = sm;
						s.m_paintRadius = p;
					});
					if (level)
					{
						s.m_levelRadius = Mathf.Clamp(l * num, 0.5f, 200f);
					}
					if (raise)
					{
						s.m_raiseRadius = Mathf.Clamp(r * num, 0.5f, 200f);
					}
					if (smooth)
					{
						s.m_smoothRadius = Mathf.Clamp(sm * num, 0.5f, 200f);
					}
					if (paintCleared)
					{
						s.m_paintRadius = Mathf.Clamp(p * num, 0.5f, 200f);
					}
				}
			}
			TerrainModifier[] componentsInChildren2 = root.GetComponentsInChildren<TerrainModifier>(true);
			foreach (TerrainModifier mod in componentsInChildren2)
			{
				if ((Object)(object)mod == (Object)null)
				{
					continue;
				}
				float radius2 = mod.GetRadius();
				if (!(radius2 <= 0.001f))
				{
					float num2 = target / radius2;
					float l2 = mod.m_levelRadius;
					float sm2 = mod.m_smoothRadius;
					float p2 = mod.m_paintRadius;
					bool level2 = mod.m_level;
					bool smooth2 = mod.m_smooth;
					bool paintCleared2 = mod.m_paintCleared;
					scope.Add(delegate
					{
						mod.m_levelRadius = l2;
						mod.m_smoothRadius = sm2;
						mod.m_paintRadius = p2;
					});
					if (level2)
					{
						mod.m_levelRadius = Mathf.Clamp(l2 * num2, 0.5f, 200f);
					}
					if (smooth2)
					{
						mod.m_smoothRadius = Mathf.Clamp(sm2 * num2, 0.5f, 200f);
					}
					if (paintCleared2)
					{
						mod.m_paintRadius = Mathf.Clamp(p2 * num2, 0.5f, 200f);
					}
				}
			}
		}
	}
	internal static class BlockVanillaTerrainPatch
	{
		[HarmonyPatch(typeof(Player), "TryPlacePiece")]
		[HarmonyPrefix]
		private static bool Prefix(Player __instance, Piece piece, ref bool __result)
		{
			TerrainForgePlugin instance = TerrainForgePlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.BlockVanillaTerrainTools.Value)
			{
				return true;
			}
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || (Object)(object)piece == (Object)null)
			{
				return true;
			}
			ItemData heldItem = TerrainBrush.GetHeldItem(__instance);
			if (!TerrainTool.IsEquipped(__instance, heldItem))
			{
				return true;
			}
			if ((Object)(object)((Component)piece).GetComponentInChildren<TerrainOp>(true) == (Object)null && (Object)(object)((Component)piece).GetComponentInChildren<TerrainModifier>(true) == (Object)null)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal static class PauseMenuPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__5_0;

			internal void <AddButton>b__5_0()
			{
				TerrainKeybinds.OpenMenu();
			}
		}

		private const string ButtonName = "TerrainForgeButton";

		private static MethodInfo s_updateNavigation;

		private static bool s_logged;

		private static bool s_failed;

		internal static void Ensure()
		{
			if (s_failed)
			{
				return;
			}
			try
			{
				Menu instance = Menu.instance;
				if (!((Object)(object)instance == (Object)null))
				{
					AddButton(instance);
				}
			}
			catch (Exception ex)
			{
				s_failed = true;
				ManualLogSource log = TerrainForgePlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("TerrainForge pause menu hook failed: " + ex.Message));
				}
			}
		}

		private static void AddButton(Menu menu)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//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_0145: Expected O, but got Unknown
			if ((Object)(object)menu == (Object)null || (Object)(object)menu.m_settingsButton == (Object)null || (Object)(object)menu.menuEntriesParent == (Object)null)
			{
				ManualLogSource log = TerrainForgePlugin.Log;
				if (log != null)
				{
					log.LogWarning((object)"TerrainForge pause menu: settings button or entries parent missing.");
				}
				return;
			}
			Transform menuEntriesParent = (Transform)(object)menu.menuEntriesParent;
			Transform val = menuEntriesParent.Find("TerrainForgeButton");
			Button val2;
			if ((Object)(object)val != (Object)null)
			{
				val2 = ((Component)val).GetComponent<Button>();
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
			}
			else
			{
				val2 = Object.Instantiate<Button>(menu.m_settingsButton, menuEntriesParent);
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				((Object)val2).name = "TerrainForgeButton";
			}
			((Component)val2).transform.SetSiblingIndex(((Component)menu.m_settingsButton).transform.GetSiblingIndex() + 1);
			((Component)val2).transform.localScale = Vector3.one;
			((Component)val2).gameObject.SetActive(true);
			val2.onClick = new ButtonClickedEvent();
			TMP_Text[] componentsInChildren = ((Component)val2).GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].text = "TerrainForge";
			}
			Text[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<Text>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].text = "TerrainForge";
			}
			ButtonClickedEvent onClick = val2.onClick;
			object obj = <>c.<>9__5_0;
			if (obj == null)
			{
				UnityAction val3 = delegate
				{
					TerrainKeybinds.OpenMenu();
				};
				<>c.<>9__5_0 = val3;
				obj = (object)val3;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			try
			{
				if (s_updateNavigation == null)
				{
					s_updateNavigation = AccessTools.Method(typeof(Menu), "UpdateNavigation", (Type[])null, (Type[])null);
				}
				s_updateNavigation?.Invoke(menu, null);
			}
			catch
			{
			}
			if (!s_logged)
			{
				s_logged = true;
				ManualLogSource log2 = TerrainForgePlugin.Log;
				if (log2 != null)
				{
					log2.LogInfo((object)("TerrainForge pause menu button added (index " + ((Component)val2).transform.GetSiblingIndex() + " of " + menuEntriesParent.childCount + " entries)."));
				}
			}
		}
	}
	internal static class ScrollSuppressPatch
	{
		internal static bool Prefix(ref float __result)
		{
			if (TerrainBrush.AdjustModeActive || TerrainBrush.FreeFlyWheelBusy || TerrainRadial.Open)
			{
				__result = 0f;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "ScreenShot")]
	internal static class FreeFlyScreenshotPatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return !TerrainBrush.SuppressFreeFlyScreenshot;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateFreeFly")]
	internal static class FreeFlyNoLockonPatch
	{
		private static FieldInfo s_lockon;

		private static FieldInfo s_target;

		[HarmonyPostfix]
		private static void Postfix(GameCamera __instance)
		{
			if (TerrainBrush.SuppressFreeFlyLockon)
			{
				KeepFreeCameraAboveTerrain();
				if (s_lockon == null)
				{
					s_lockon = AccessTools.Field(typeof(GameCamera), "m_freeFlyLockon");
				}
				if (s_lockon != null && s_lockon.GetValue(__instance) != null)
				{
					s_lockon.SetValue(__instance, null);
				}
				if (s_target == null)
				{
					s_target = AccessTools.Field(typeof(GameCamera), "m_freeFlyTarget");
				}
				if (s_target != null && s_target.GetValue(__instance) != null)
				{
					s_target.SetValue(__instance, null);
				}
			}
		}

		private static void KeepFreeCameraAboveTerrain()
		{
			//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_002c: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			ZoneSystem instance = ZoneSystem.instance;
			if (!((Object)(object)main == (Object)null) && !((Object)(object)instance == (Object)null))
			{
				Vector3 position = ((Component)main).transform.position;
				float groundHeight = instance.GetGroundHeight(position);
				if (position.y < groundHeight + 1.25f)
				{
					position.y = groundHeight + 1.25f;
					((Component)main).transform.position = position;
				}
			}
		}
	}
	internal static class FreeFlyButtonSuppressPatch
	{
		internal static bool Prefix(string __0, ref bool __result)
		{
			if (!TerrainBrush.SuppressFreeFlyLockon)
			{
				return true;
			}
			switch (__0)
			{
			case "SecondaryAttack":
			case "Block":
			case "Attack":
				__result = false;
				return false;
			default:
				return true;
			}
		}
	}
	internal sealed class PlacementRadiusScope
	{
		private readonly List<Action> _undo = new List<Action>();

		public int Count => _undo.Count;

		public void Add(Action undo)
		{
			_undo.Add(undo);
		}

		public void Restore()
		{
			for (int num = _undo.Count - 1; num >= 0; num--)
			{
				try
				{
					_undo[num]();
				}
				catch
				{
				}
			}
			_undo.Clear();
		}
	}
	[BepInPlugin("com.terrainforge.valheim", "TerrainForge", "0.3.8")]
	public class TerrainForgePlugin : BaseUnityPlugin
	{
		public const string Guid = "com.terrainforge.valheim";

		public ConfigEntry<bool> Enabled;

		public ConfigEntry<bool> PlayEffects;

		public ConfigEntry<ModLanguage> Language;

		public ConfigEntry<bool> ToolTint;

		public ConfigEntry<string> ToolTintColor;

		public ConfigEntry<float> Radius;

		public ConfigEntry<float> RadiusMin;

		public ConfigEntry<float> RadiusMax;

		public ConfigEntry<float> RadiusStep;

		public ConfigEntry<float> Softness;

		public ConfigEntry<float> FalloffPower;

		public ConfigEntry<float> RaiseDelta;

		public ConfigEntry<float> PaintStrength;

		public ConfigEntry<TerrainOperation> DefaultOperation;

		public ConfigEntry<TerrainShape> Shape;

		public ConfigEntry<TerrainPaint> Paint;

		public ConfigEntry<RampMode> RampMode;

		public ConfigEntry<float> SlopeAngle;

		public ConfigEntry<bool> UseFixedHeight;

		public ConfigEntry<float> FixedHeight;

		public ConfigEntry<SmoothMode> SmoothMode;

		public ConfigEntry<FalloffMode> FalloffMode;

		public ConfigEntry<ShoreFalloffMode> ShoreFalloffMode;

		public ConfigEntry<float> ShoreOffset;

		public ConfigEntry<bool> UnlockDeltaLimit;

		public ConfigEntry<float> MaxUpDelta;

		public ConfigEntry<float> MaxDownDelta;

		public ConfigEntry<KeyboardShortcut> ApplyKey;

		public ConfigEntry<KeyboardShortcut> RadiusUpKey;

		public ConfigEntry<KeyboardShortcut> RadiusDownKey;

		public ConfigEntry<KeyboardShortcut> CycleOperationKey;

		public ConfigEntry<KeyboardShortcut> CycleShapeKey;

		public ConfigEntry<KeyboardShortcut> CyclePaintKey;

		public ConfigEntry<KeyboardShortcut> AimHeightModifierKey;

		public ConfigEntry<KeyboardShortcut> RebindMenuKey;

		public ConfigEntry<KeyboardShortcut> GiveToolKey;

		public ConfigEntry<KeyboardShortcut> EyedropKey;

		public ConfigEntry<KeyboardShortcut> RampModeKey;

		public ConfigEntry<KeyboardShortcut> RadialKey;

		public ConfigEntry<KeyboardShortcut> RadialToolsKey;

		public ConfigEntry<KeyboardShortcut> RadialConfirmKey;

		public ConfigEntry<KeyboardShortcut> RadialCancelKey;

		public ConfigEntry<KeyboardShortcut> AdjustModeKey;

		public ConfigEntry<KeyboardShortcut> FreeCameraKey;

		public ConfigEntry<float> FreeCameraAimDistance;

		public ConfigEntry<KeyboardShortcut> OpFlattenKey;

		public ConfigEntry<KeyboardShortcut> OpRaiseKey;

		public ConfigEntry<KeyboardShortcut> OpLowerKey;

		public ConfigEntry<KeyboardShortcut> OpSmoothKey;

		public ConfigEntry<KeyboardShortcut> OpPaintKey;

		public ConfigEntry<KeyboardShortcut> OpRestoreKey;

		public ConfigEntry<KeyboardShortcut> OpRampKey;

		public ConfigEntry<KeyboardShortcut> OpShoreKey;

		public ConfigEntry<KeyboardShortcut> OpSnowKey;

		public ConfigEntry<KeyboardShortcut> CycleProfileKey;

		public ConfigEntry<KeyboardShortcut> CopyStampKey;

		public ConfigEntry<KeyboardShortcut> PasteStampKey;

		public ConfigEntry<KeyboardShortcut> CycleStampKey;

		public ConfigEntry<KeyboardShortcut> CycleStampBackKey;

		public ConfigEntry<bool> SeenTutorial;

		public ConfigEntry<string> PresetSlots;

		public ConfigEntry<ToolRequirement> RequiredTool;

		public ConfigEntry<StampToolMode> StampToolMode;

		public ConfigEntry<bool> AutoGiveTool;

		public ConfigEntry<bool> ScaleVanillaToolRadius;

		public ConfigEntry<float> VanillaToolRadius;