Decompiled source of Worldhalla v1.0.0

BepInEx/plugins/Worldhalla/Worldhalla.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GUIFramework;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SoftReferenceableAssets;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
using Worldhalla.API;
using Worldhalla.API.Attributes;
using Worldhalla.API.Settings;
using Worldhalla.API.Settings.Controls;
using Worldhalla.API.World;
using Worldhalla.Plugin.Compat;
using Worldhalla.Plugin.Core;
using Worldhalla.Plugin.Core.Extensions;
using Worldhalla.Plugin.Core.Patches;
using Worldhalla.Plugin.Localization;
using Worldhalla.Plugin.UI.Patches;
using Worldhalla.Plugin.UI.Preview;
using Worldhalla.Plugin.UI.Preview.Locations;
using Worldhalla.Plugin.UI.Preview.Vanilla;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Gurebu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("API for Worldhalla, a Valheim world generation framework. Compile-time reference only; the runtime comes from the Worldhalla plugin.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f33f747d497b6b5dac94c2f1516f22ee4e48f1cc")]
[assembly: AssemblyProduct("Worldhalla")]
[assembly: AssemblyTitle("Worldhalla")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Gurebu/worldhalla")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 Worldhalla.API
{
	public interface IWorldGenerator
	{
		public enum Feature
		{
			BiomeBlending
		}

		string Name { get; }

		string Moniker { get; }

		string Description { get; }

		string Version { get; }

		Feature[] Features { get; }

		IWorldState Generate(int seed, ISettings? settings, IProgress<float> progress, CancellationToken cancellation);
	}
}
namespace Worldhalla.API.World
{
	public enum Biome
	{
		None = 0,
		Meadows = 1,
		Swamp = 2,
		Mountain = 4,
		BlackForest = 8,
		Plains = 0x10,
		AshLands = 0x20,
		DeepNorth = 0x40,
		Ocean = 0x100,
		Mistlands = 0x200
	}
	public interface IWorldGeography
	{
		float WorldSize { get; }

		bool IsAshlands(float x, float y);

		bool IsDeepNorth(float x, float y);

		float GetAshlandsOceanGradient(float x, float y);

		float GetDeepNorthWaveFade(float x, float y);
	}
	public interface IWorldState
	{
		public struct PointData
		{
			public Biome biome;

			public float height;

			public float fertility;

			public float lava;

			public float snow;

			public float dirt;

			public float pave;
		}

		Biome GetBiome(float x, float y);

		float GetForestation(float x, float y);

		PointData RenderPoint(float x, float y, Biome biome);
	}
}
namespace Worldhalla.API.Settings
{
	public interface ISettings
	{
		byte[] SaveToBinaryBlob();

		string Summary();
	}
	public interface ISettingsForm
	{
		IReadOnlyList<Control> Controls { get; }

		ISettings Build();
	}
	public interface ISettingsHandler
	{
		ISettings DefaultSettings { get; }

		string CommandLineUsage { get; }

		ISettings BuildSettingsFromBinaryBlob(byte[] data);

		ISettings BuildSettingsFromCommandLine(string settings);

		ISettingsForm CreateForm(ISettings current);
	}
	public class SettingsException : Exception
	{
		public SettingsException(string message)
			: base(message)
		{
		}
	}
}
namespace Worldhalla.API.Settings.Controls
{
	public abstract class Control
	{
		public string Label { get; }

		public string? Tooltip { get; }

		public event Action? Changed;

		private protected Control(string label, string? tooltip)
		{
			Label = label;
			Tooltip = tooltip;
		}

		private protected void OnChanged()
		{
			this.Changed?.Invoke();
		}
	}
	public sealed class Select : Control
	{
		private int selected;

		public IReadOnlyList<string> Options { get; }

		public int Selected
		{
			get
			{
				return selected;
			}
			set
			{
				if (CheckIndex(value) != selected)
				{
					selected = value;
					OnChanged();
				}
			}
		}

		public Select(string label, IReadOnlyList<string> options, int selected = 0, string? tooltip = null)
			: base(label, tooltip)
		{
			if (options.Count == 0)
			{
				throw new ArgumentException("A select needs at least one option", "options");
			}
			Options = options;
			this.selected = CheckIndex(selected);
		}

		private int CheckIndex(int index)
		{
			if (index < 0 || index >= Options.Count)
			{
				throw new ArgumentOutOfRangeException("index", index, $"Select has {Options.Count} options");
			}
			return index;
		}
	}
	public sealed class TextField : Control
	{
		private string text;

		public string Text
		{
			get
			{
				return text;
			}
			set
			{
				if (!(value == text))
				{
					text = value;
					OnChanged();
				}
			}
		}

		public TextField(string label, string text = "", string? tooltip = null)
			: base(label, tooltip)
		{
			this.text = text;
		}
	}
}
namespace Worldhalla.API.Attributes
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false)]
	public sealed class WorldhallaWorldGeneratorAttribute(string guid) : Attribute()
	{
		public string Guid { get; } = guid;
	}
}
internal static class PluginInfo
{
	public const string PLUGIN_GUID = "Worldhalla.Plugin";

	public const string PLUGIN_NAME = "Worldhalla.Plugin";

	public const string PLUGIN_VERSION = "1.0.0";
}
namespace Worldhalla.Plugin
{
	public sealed class CommandLineOptions
	{
		public string? worldgenGuid;

		public string? settings;
	}
	public static class CommandLine
	{
		public const string PREFIX = "-wh";

		private static readonly Dictionary<string, Action<CommandLineOptions, string>> Commands = new Dictionary<string, Action<CommandLineOptions, string>>(StringComparer.OrdinalIgnoreCase)
		{
			["guid"] = delegate(CommandLineOptions options, string value)
			{
				SetOnce(ref options.worldgenGuid, value, "worldgen guids");
			},
			["settings"] = delegate(CommandLineOptions options, string value)
			{
				SetOnce(ref options.settings, value, "worldgen settings");
			}
		};

		public static CommandLineOptions Parse(IReadOnlyList<string> args)
		{
			CommandLineOptions commandLineOptions = new CommandLineOptions();
			for (int i = 0; i < args.Count; i++)
			{
				if (string.Equals(args[i], "-wh", StringComparison.OrdinalIgnoreCase))
				{
					if (i + 1 >= args.Count)
					{
						throw new ServerStartupException("'-wh' is missing a command, expected one of: " + string.Join(", ", Commands.Keys));
					}
					string text = args[++i];
					if (!Commands.TryGetValue(text, out Action<CommandLineOptions, string> value))
					{
						throw new ServerStartupException("Unknown command '-wh " + text + "', expected one of: " + string.Join(", ", Commands.Keys));
					}
					if (i + 1 >= args.Count)
					{
						throw new ServerStartupException("'-wh " + text + "' is missing a value");
					}
					value(commandLineOptions, args[++i]);
				}
			}
			if (commandLineOptions == null || commandLineOptions.settings == null || commandLineOptions.worldgenGuid != null)
			{
				return commandLineOptions;
			}
			throw new ServerStartupException("'-wh settings' needs a worldgen to apply to, pass one with '-wh guid'");
		}

		private static void SetOnce(ref string? field, string value, string what)
		{
			if (field != null && field != value)
			{
				throw new ServerStartupException("Conflicting " + what + " '" + field + "' and '" + value + "'");
			}
			field = value;
		}
	}
	public static class Logger
	{
		public enum LogLevel
		{
			Info,
			Warning,
			Error
		}

		private static Action<LogLevel, string>? impl;

		public static void SetLogger(Action<LogLevel, string> logger)
		{
			impl = logger;
		}

		public static void LogInfo(string message)
		{
			impl?.Invoke(LogLevel.Info, message);
		}

		public static void LogWarning(string message)
		{
			impl?.Invoke(LogLevel.Warning, message);
		}

		public static void LogError(string message)
		{
			impl?.Invoke(LogLevel.Error, message);
		}
	}
	[BepInPlugin("dev.gurebu.worldhalla", "Worldhalla.Plugin", "1.0.0")]
	[BepInIncompatibility("BetterContinents")]
	public class WorldhallaPlugin : BaseUnityPlugin
	{
		private const string GUID = "dev.gurebu.worldhalla";

		private bool disabled;

		public void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Logger.SetLogger(delegate(Logger.LogLevel level, string message)
			{
				switch (level)
				{
				case Logger.LogLevel.Info:
					((BaseUnityPlugin)this).Logger.LogInfo((object)message);
					break;
				case Logger.LogLevel.Warning:
					((BaseUnityPlugin)this).Logger.LogWarning((object)message);
					break;
				case Logger.LogLevel.Error:
					((BaseUnityPlugin)this).Logger.LogError((object)message);
					break;
				default:
					throw new ArgumentOutOfRangeException("level", level, null);
				}
			});
			if (StandDownForOutdatedRiverheim())
			{
				return;
			}
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Compatibility", "WorldListPatch", true, "Shows the world generator in the world list and its tooltip. Disable to improve compatibility with mods that change the world list.");
			Harmony val2 = new Harmony("dev.gurebu.worldhalla");
			Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(typeof(WorldhallaPlugin).Assembly);
			foreach (Type type in typesFromAssembly)
			{
				if (!(type == typeof(WorldListPatch)) || val.Value)
				{
					val2.CreateClassProcessor(type).Patch();
				}
			}
			Localization value = Traverse.Create<Localization>().Field<Localization>("m_instance").Value;
			if (value != null)
			{
				Translations.Load(value, value.GetSelectedLanguage());
			}
		}

		public void Start()
		{
			if (!disabled)
			{
				if (StandDownForOutdatedRiverheim())
				{
					Harmony.UnpatchID("dev.gurebu.worldhalla");
				}
				else
				{
					Registry.DiscoverGenerators();
				}
			}
		}

		private bool StandDownForOutdatedRiverheim()
		{
			PluginInfo val = ModCompat.FindOutdatedRiverheim();
			if (val == null)
			{
				return false;
			}
			((BaseUnityPlugin)this).Logger.LogError((object)($"{val.Metadata.Name} {val.Metadata.Version} ({val.Metadata.GUID}) is incompatible with " + "Worldhalla. Update it to 1.3 or newer; until then Worldhalla stays inactive."));
			disabled = true;
			return true;
		}

		public void OnDestroy()
		{
			Registry.PurgeAll();
			Harmony.UnpatchID("dev.gurebu.worldhalla");
		}
	}
}
namespace Worldhalla.Plugin.UI
{
	public sealed class GuiElementPalette
	{
		public const float SMALL_FONT_SCALE = 0.75f;

		private const string ICON_CHILD = "Image";

		private const string LABEL_SOURCE = "seed";

		private const string BACKGROUND = "bkg";

		private readonly TMP_Text label;

		private readonly Button button;

		private readonly Button iconButton;

		private readonly TMP_Dropdown dropdown;

		private readonly GuiInputField textField;

		private readonly GameObject textBox;

		private readonly Scrollbar scrollbar;

		private readonly GameObject? background;

		public GuiElementPalette(FejdStartup startup)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Expected O, but got Unknown
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			Transform shelf = NewShelf(startup, "WorldhallaPalette");
			Transform parent = ((Component)startup.m_newWorldName).transform.parent;
			label = Copy(((Component)parent.Find("seed")).gameObject, shelf, "Label").GetComponent<TMP_Text>();
			label.text = "";
			Transform val = parent.Find("bkg");
			if (val != null)
			{
				background = Copy(((Component)val).gameObject, shelf, "bkg");
			}
			button = Copy(((Component)startup.m_newWorldDone).gameObject, shelf, "Button").GetComponent<Button>();
			((Selectable)button).interactable = true;
			iconButton = Copy(((Component)startup.m_serverListPanel.GetComponentInChildren<ServerListGui>(true).m_serverRefreshButton).gameObject, shelf, "IconButton").GetComponent<Button>();
			Button[] array = (Button[])(object)new Button[2] { button, iconButton };
			foreach (Button obj in array)
			{
				obj.onClick = new ButtonClickedEvent();
				UITooltip[] componentsInChildren = ((Component)obj).GetComponentsInChildren<UITooltip>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[j]);
				}
			}
			dropdown = Copy(((Component)startup.m_settingsPrefab.GetComponentInChildren<TMP_Dropdown>(true)).gameObject, shelf, "Dropdown").GetComponent<TMP_Dropdown>();
			RemoveExternalCaption(dropdown);
			dropdown.captionText.overflowMode = (TextOverflowModes)1;
			dropdown.itemText.overflowMode = (TextOverflowModes)1;
			dropdown.captionText.richText = true;
			dropdown.itemText.richText = true;
			dropdown.onValueChanged = new DropdownEvent();
			textField = Copy(((Component)startup.m_newWorldSeed).gameObject, shelf, "TextField").GetComponent<GuiInputField>();
			ClearTextField(textField);
			textBox = Copy(((Component)startup.m_newWorldName).gameObject, shelf, "TextBox");
			ClearTextBox(textBox);
			scrollbar = Copy(((Component)startup.m_patchLogScroll).gameObject, shelf, "Scrollbar").GetComponent<Scrollbar>();
			scrollbar.onValueChanged = new ScrollEvent();
			Scrollbar obj2 = scrollbar;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj2).navigation = navigation;
			scrollbar.direction = (Direction)2;
		}

		public TMP_Text Label(Transform parent, string name, string text)
		{
			TMP_Text result = Instantiate<TMP_Text>(label, parent, name);
			SetText(result, text);
			return result;
		}

		public Button Button(Transform parent, string name, string text, string? gamepadButton = null)
		{
			Button obj = Instantiate<Button>(button, parent, name);
			SetGamepadButton(obj, gamepadButton);
			SetText(((Component)obj).GetComponentInChildren<TMP_Text>(true), text);
			return obj;
		}

		public Button IconButton(Transform parent, string name, Sprite? icon = null)
		{
			Button val = Instantiate<Button>(iconButton, parent, name);
			SetGamepadButton(val, null);
			if ((Object)(object)icon != (Object)null)
			{
				((Component)((Component)val).transform.Find("Image")).GetComponent<Image>().sprite = icon;
			}
			return val;
		}

		public TMP_Dropdown Dropdown(Transform parent, string name)
		{
			return Instantiate<TMP_Dropdown>(dropdown, parent, name);
		}

		public GuiInputField TextField(Transform parent, string name)
		{
			return Instantiate<GuiInputField>(textField, parent, name);
		}

		public TMP_Text TextBox(Transform parent, string name)
		{
			GameObject obj = Object.Instantiate<GameObject>(textBox, parent);
			((Object)obj).name = name;
			return obj.GetComponentInChildren<TMP_Text>(true);
		}

		public ScrollRect ScrollingTextBox(Transform parent, string name)
		{
			//IL_0022: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = TextBox(parent, name);
			val.overflowMode = (TextOverflowModes)0;
			RectTransform rectTransform = val.rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = Vector2.one;
			rectTransform.pivot = new Vector2(0.5f, 1f);
			Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero);
			rectTransform.offsetMin = offsetMin;
			((Component)val).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			RectTransform val2 = (RectTransform)((Transform)rectTransform).parent;
			if ((Object)(object)((Component)val2).GetComponent<RectMask2D>() == (Object)null)
			{
				((Component)val2).gameObject.AddComponent<RectMask2D>();
			}
			Transform parent2 = ((Transform)val2).parent;
			Scrollbar val3 = Instantiate<Scrollbar>(scrollbar, parent2, "Scrollbar");
			RectTransform val4 = (RectTransform)((Component)val3).transform;
			Rect rect = val4.rect;
			float width = ((Rect)(ref rect)).width;
			val4.anchorMin = new Vector2(1f, 0f);
			val4.anchorMax = Vector2.one;
			val4.pivot = new Vector2(1f, 0.5f);
			val4.sizeDelta = new Vector2(width, 0f);
			val4.anchoredPosition = Vector2.zero;
			val.margin += new Vector4(0f, 0f, width, 0f);
			ScrollRect obj = ((Component)parent2).gameObject.AddComponent<ScrollRect>();
			obj.viewport = val2;
			obj.content = rectTransform;
			obj.horizontal = false;
			obj.vertical = true;
			obj.movementType = (MovementType)2;
			obj.inertia = false;
			obj.scrollSensitivity = val.fontSize;
			obj.verticalScrollbar = val3;
			obj.verticalScrollbarVisibility = (ScrollbarVisibility)1;
			return obj;
		}

		public void Background(Transform parent)
		{
			if ((Object)(object)background != (Object)null)
			{
				((Object)Object.Instantiate<GameObject>(background, parent)).name = "bkg";
			}
		}

		internal static Transform NewShelf(FejdStartup startup, string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.SetActive(false);
			val.transform.SetParent(((Component)startup).transform, false);
			return val.transform;
		}

		private static T Instantiate<T>(T template, Transform parent, string name) where T : Component
		{
			T val = Object.Instantiate<T>(template, parent);
			((Object)(object)val).name = name;
			return val;
		}

		internal static GameObject Copy(GameObject original, Transform shelf, string name)
		{
			GameObject val = Object.Instantiate<GameObject>(original, shelf);
			((Object)val).name = name;
			Localize[] componentsInChildren = val.GetComponentsInChildren<Localize>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			return val;
		}

		private static void ClearTextField(GuiInputField field)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if ((Object)(object)((TMP_InputField)field).placeholder != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)((TMP_InputField)field).placeholder).gameObject);
			}
			((TMP_InputField)field).onValueChanged = new OnChangeEvent();
			((TMP_InputField)field).onEndEdit = new SubmitEvent();
			((TMP_InputField)field).onSubmit = new SubmitEvent();
			field.OnInputSubmit = new OnInputSubmitEvent();
			((TMP_InputField)field).contentType = (ContentType)0;
			((TMP_InputField)field).lineType = (LineType)0;
			((TMP_InputField)field).characterLimit = 0;
			((TMP_InputField)field).text = "";
		}

		private static void ClearTextBox(GameObject copy)
		{
			TMP_InputField component = copy.GetComponent<TMP_InputField>();
			TMP_Text textComponent = component.textComponent;
			if ((Object)(object)component.placeholder != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)component.placeholder).gameObject);
			}
			Object.DestroyImmediate((Object)(object)component);
			textComponent.text = "";
			textComponent.textWrappingMode = (TextWrappingModes)1;
			textComponent.overflowMode = (TextOverflowModes)1;
			textComponent.horizontalAlignment = (HorizontalAlignmentOptions)1;
			textComponent.verticalAlignment = (VerticalAlignmentOptions)256;
			textComponent.enableAutoSizing = false;
			textComponent.fontSize *= 0.75f;
		}

		private static void SetGamepadButton(Button copy, string? gamepadButton)
		{
			UIGamePad[] componentsInChildren = ((Component)copy).GetComponentsInChildren<UIGamePad>(true);
			foreach (UIGamePad val in componentsInChildren)
			{
				if (gamepadButton != null)
				{
					SetGamepadButton(val, gamepadButton);
					continue;
				}
				if ((Object)(object)val.m_hint != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)val.m_hint);
				}
				Object.DestroyImmediate((Object)(object)val);
			}
		}

		private static void SetGamepadButton(UIGamePad gamePad, string button)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			gamePad.m_zinputKey = "Joy" + button;
			gamePad.m_keyCode = (KeyCode)0;
			if (!((Object)(object)gamePad.m_hint == (Object)null))
			{
				TMP_Text[] componentsInChildren = gamePad.m_hint.GetComponentsInChildren<TMP_Text>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].text = "$KEY_" + button;
				}
				Text[] componentsInChildren2 = gamePad.m_hint.GetComponentsInChildren<Text>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					componentsInChildren2[i].text = "$KEY_" + button;
				}
				gamePad.m_hint.AddComponent<Localize>();
			}
		}

		private static void RemoveExternalCaption(TMP_Dropdown dropdown)
		{
			foreach (Transform item in ((IEnumerable)((Component)dropdown).transform).Cast<Transform>().ToList())
			{
				if ((Object)(object)((Component)item).GetComponent<TMP_Text>() != (Object)null && (Object)(object)item != (Object)(object)dropdown.captionText.transform)
				{
					Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
				}
			}
		}

		private static void SetText(TMP_Text label, string text)
		{
			label.text = text;
			if (text.StartsWith("$"))
			{
				((Component)label).gameObject.AddComponent<Localize>();
			}
		}
	}
	public static class Icons
	{
		private const int SIZE = 20;

		private const int SUBSAMPLES = 6;

		private const float LENS_X = 8f;

		private const float LENS_Y = 8f;

		private const float LENS_RADIUS = 5.6f;

		private const float LENS_WIDTH = 2.9f;

		private const float HANDLE_HALF_WIDTH = 2.05f;

		private const float HANDLE_END = 17.3f;

		private const float EYE_CENTER = 10f;

		private const float EYE_HALF_WIDTH = 9.2f;

		private const float EYE_HALF_HEIGHT = 5.4f;

		private const float EYE_OUTLINE_WIDTH = 2.3f;

		private const float PUPIL_RADIUS = 4f;

		private const float SLASH_WIDTH = 2.4f;

		private const float SLASH_GAP = 1.2f;

		private static readonly Vector2 SlashStart = new Vector2(3f, 3f);

		private static readonly Vector2 SlashEnd = new Vector2(17f, 17f);

		private static Sprite? magnifier;

		private static Sprite? crossedEye;

		public static Sprite Magnifier => magnifier ?? (magnifier = Draw(MagnifierCovers));

		public static Sprite CrossedEye => crossedEye ?? (crossedEye = Draw(CrossedEyeCovers));

		private static bool MagnifierCovers(float x, float y)
		{
			//IL_000e: 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_0040: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = new Vector2(x - 8f, y - 8f);
			if (Mathf.Abs(((Vector2)(ref val)).magnitude - 5.6f) <= 1.45f)
			{
				return true;
			}
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(17.3f, 17.3f);
			val = val2 - new Vector2(8f, 8f);
			Vector2 normalized = ((Vector2)(ref val)).normalized;
			Vector2 start = new Vector2(8f, 8f) + normalized * 6.75f;
			return DistanceToSegment(new Vector2(x, y), start, val2) <= 2.05f;
		}

		private static bool CrossedEyeCovers(float x, float y)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(x, y);
			float num = DistanceToSegment(val, SlashStart, SlashEnd);
			if (num <= 1.2f)
			{
				return true;
			}
			Vector2 val2 = SlashEnd - SlashStart;
			float num2 = val2.x * (y - SlashStart.y) - val2.y * (x - SlashStart.x);
			if (num <= 2.4f && num2 < 0f)
			{
				return false;
			}
			if (!InsideEye(val, 1.15f) || InsideEye(val, -1.15f))
			{
				Vector2 val3 = val - new Vector2(10f, 10f);
				return ((Vector2)(ref val3)).magnitude <= 4f;
			}
			return true;
		}

		private static bool InsideEye(Vector2 point, float margin)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			float num = 5.1370363f;
			float num2 = num + 5.4f + margin;
			Vector2 val = point - new Vector2(10f, 10f + num);
			if (((Vector2)(ref val)).magnitude <= num2)
			{
				val = point - new Vector2(10f, 10f - num);
				return ((Vector2)(ref val)).magnitude <= num2;
			}
			return false;
		}

		private static float DistanceToSegment(Vector2 point, Vector2 start, Vector2 end)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = end - start;
			float num = Mathf.Clamp01(Vector2.Dot(point - start, val) / ((Vector2)(ref val)).sqrMagnitude);
			Vector2 val2 = point - (start + num * val);
			return ((Vector2)(ref val2)).magnitude;
		}

		private static Sprite Draw(Func<float, float, bool> covers)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(20, 20, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[400];
			for (int i = 0; i < 20; i++)
			{
				for (int j = 0; j < 20; j++)
				{
					int num = 0;
					for (int k = 0; k < 6; k++)
					{
						for (int l = 0; l < 6; l++)
						{
							float arg = (float)j + ((float)l + 0.5f) / 6f;
							float arg2 = (float)(20 - i - 1) + ((float)k + 0.5f) / 6f;
							if (covers(arg, arg2))
							{
								num++;
							}
						}
					}
					array[i * 20 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(255 * num / 36));
				}
			}
			val.SetPixels32(array);
			val.Apply(false);
			return Sprite.Create(val, new Rect(0f, 0f, 20f, 20f), new Vector2(0.5f, 0.5f));
		}
	}
	public sealed class NavigationGrid(params Selectable[][][] columns)
	{
		public void Apply()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < columns.Length; i++)
			{
				for (int j = 0; j < columns[i].Length; j++)
				{
					for (int k = 0; k < columns[i][j].Length; k++)
					{
						Selectable val = columns[i][j][k];
						if (!((Object)(object)val == (Object)null))
						{
							Navigation navigation = default(Navigation);
							((Navigation)(ref navigation)).mode = (Mode)4;
							((Navigation)(ref navigation)).selectOnLeft = Sideways(i, j, k, -1);
							((Navigation)(ref navigation)).selectOnRight = Sideways(i, j, k, 1);
							((Navigation)(ref navigation)).selectOnUp = Vertical(i, j, k, -1);
							((Navigation)(ref navigation)).selectOnDown = Vertical(i, j, k, 1);
							val.navigation = navigation;
						}
					}
				}
			}
		}

		private Selectable? Sideways(int column, int row, int index, int step)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Selectable[] array = columns[column][row];
			for (int i = index + step; i >= 0 && i < array.Length; i += step)
			{
				if (IsUsable(array[i]))
				{
					return array[i];
				}
			}
			int num = column + step;
			if (num < 0 || num >= columns.Length)
			{
				return null;
			}
			float height = ((Component)array[index]).transform.position.y;
			return (from cell in columns[num].SelectMany((Selectable[] cell) => cell).Where(IsUsable)
				orderby Mathf.Abs(((Component)cell).transform.position.y - height)
				select cell).FirstOrDefault();
		}

		private Selectable? Vertical(int column, int row, int index, int step)
		{
			Selectable[][] array = columns[column];
			for (int i = row + step; i >= 0 && i < array.Length; i += step)
			{
				Selectable[] array2 = array[i];
				int num = Mathf.Min(index, array2.Length - 1);
				if (IsUsable(array2[num]))
				{
					return array2[num];
				}
				Selectable val = ((IEnumerable<Selectable>)array2).FirstOrDefault((Func<Selectable, bool>)IsUsable);
				if (val != null)
				{
					return val;
				}
			}
			return null;
		}

		private static bool IsUsable(Selectable? selectable)
		{
			if ((Object)(object)selectable != (Object)null && ((Component)selectable).gameObject.activeInHierarchy)
			{
				return selectable.IsInteractable();
			}
			return false;
		}
	}
	public class SettingsDialog : MonoBehaviour
	{
		private const float WIDTH = 560f;

		private const float PADDING = 16f;

		private const float TITLE_HEIGHT = 30f;

		private const float LABEL_HEIGHT = 26f;

		private const float FIELD_HEIGHT = 35f;

		private const float ROW_GAP = 10f;

		private const float ERROR_HEIGHT = 40f;

		private const float BUTTON_WIDTH = 136f;

		private const float BUTTON_HEIGHT = 45f;

		private const float BUTTON_GAP = 8f;

		private const float SCREEN_FRACTION = 0.95f;

		private const string BUILD_FAILED = "$wh_settings_build_failed";

		public RectTransform frame;

		public TMP_Text title;

		public RectTransform rows;

		public TMP_Text error;

		public Button okButton;

		public Button cancelButton;

		public TMP_Text labelTemplate;

		public TMP_Dropdown dropdownTemplate;

		public GuiInputField textFieldTemplate;

		public UIGroupHandler group;

		private readonly List<Action> unbind = new List<Action>();

		private Func<Action>? build;

		private GameObject? firstField;

		public bool IsOpen => build != null;

		public void Initialize()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			((UnityEvent)okButton.onClick).AddListener(new UnityAction(Accept));
			((UnityEvent)cancelButton.onClick).AddListener(new UnityAction(Close));
			((Component)this).gameObject.SetActive(false);
		}

		public void Open<T>(string heading, IReadOnlyList<Control> controls, Func<T> buildSettings, Action<T> onAccepted)
		{
			Close();
			try
			{
				float y = -56f;
				foreach (Control control in controls)
				{
					y = AddRow(control, y);
				}
				build = delegate
				{
					T settings = buildSettings();
					return delegate
					{
						onAccepted(settings);
					};
				};
			}
			catch (Exception arg)
			{
				Logger.LogError($"Can't show settings form: {arg}");
				Clear();
				return;
			}
			title.text = heading;
			Layout(controls.Count);
			group.m_defaultElement = (GameObject)(((Object)(object)firstField != (Object)null) ? ((object)firstField) : ((object)((Component)cancelButton).gameObject));
			((Component)this).gameObject.SetActive(true);
			Validate();
		}

		public void Close()
		{
			Clear();
			((Component)this).gameObject.SetActive(false);
		}

		private void Clear()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			foreach (Action item in unbind)
			{
				item();
			}
			unbind.Clear();
			foreach (Transform item2 in (Transform)rows)
			{
				Object.Destroy((Object)(object)((Component)item2).gameObject);
			}
			build = null;
			firstField = null;
		}

		private float AddRow(Control control, float y)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			TMP_Text component = Object.Instantiate<GameObject>(((Component)labelTemplate).gameObject, (Transform)(object)rows).GetComponent<TMP_Text>();
			((Component)component).gameObject.SetActive(true);
			component.text = control.Label;
			Place(component.rectTransform, y, 26f);
			y -= 26f;
			GameObject val;
			if (!(control is Select obj))
			{
				if (!(control is TextField textField))
				{
					throw new NotSupportedException("Control " + control.GetType().Name + " isn't supported by this Worldhalla version");
				}
				val = BindTextField(textField);
			}
			else
			{
				val = BindSelect(obj);
			}
			GameObject val2 = val;
			Place((RectTransform)val2.transform, y, 35f);
			if ((Object)(object)firstField == (Object)null)
			{
				firstField = val2;
			}
			return y - 35f - 10f;
		}

		private GameObject BindSelect(Select select)
		{
			TMP_Dropdown dropdown = Object.Instantiate<GameObject>(((Component)dropdownTemplate).gameObject, (Transform)(object)rows).GetComponent<TMP_Dropdown>();
			((Component)dropdown).gameObject.SetActive(true);
			dropdown.ClearOptions();
			dropdown.AddOptions(select.Options.ToList());
			dropdown.SetValueWithoutNotify(select.Selected);
			dropdown.RefreshShownValue();
			((UnityEvent<int>)(object)dropdown.onValueChanged).AddListener((UnityAction<int>)delegate(int index)
			{
				select.Selected = index;
			});
			select.Changed += Show;
			unbind.Add(delegate
			{
				select.Changed -= Show;
			});
			return ((Component)dropdown).gameObject;
			void Show()
			{
				dropdown.SetValueWithoutNotify(select.Selected);
				dropdown.RefreshShownValue();
				Validate();
			}
		}

		private GameObject BindTextField(TextField textField)
		{
			GuiInputField input = Object.Instantiate<GameObject>(((Component)textFieldTemplate).gameObject, (Transform)(object)rows).GetComponent<GuiInputField>();
			((Component)input).gameObject.SetActive(true);
			input.VirtualKeyboardTitle = textField.Label;
			((TMP_InputField)input).SetTextWithoutNotify(textField.Text);
			((UnityEvent<string>)(object)((TMP_InputField)input).onValueChanged).AddListener((UnityAction<string>)delegate(string text)
			{
				textField.Text = text;
			});
			textField.Changed += Show;
			unbind.Add(delegate
			{
				textField.Changed -= Show;
			});
			return ((Component)input).gameObject;
			void Show()
			{
				if (((TMP_InputField)input).text != textField.Text)
				{
					((TMP_InputField)input).SetTextWithoutNotify(textField.Text);
				}
				Validate();
			}
		}

		private void Validate()
		{
			Action handOver;
			string text = TryBuild(out handOver);
			error.text = text ?? "";
			((Selectable)okButton).interactable = text == null;
		}

		private void Accept()
		{
			if (TryBuild(out Action handOver) == null)
			{
				Close();
				handOver();
			}
		}

		private string? TryBuild(out Action? handOver)
		{
			handOver = null;
			if (build == null)
			{
				return Translations.Get("$wh_settings_build_failed");
			}
			try
			{
				handOver = build();
				return null;
			}
			catch (SettingsException ex)
			{
				return ex.Message;
			}
			catch (Exception arg)
			{
				Logger.LogError($"Settings form failed to build settings: {arg}");
				return Translations.Get("$wh_settings_build_failed");
			}
		}

		private void Layout(int rowCount)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)rowCount * 71f;
			float num2 = 56f + num + 40f + 45f + 16f;
			frame.sizeDelta = new Vector2(560f, num2);
			Rect rect = ((RectTransform)((Component)this).transform).rect;
			Vector2 val = ((Rect)(ref rect)).size * 0.95f;
			float num3 = Mathf.Min(new float[3]
			{
				1f,
				val.x / 560f,
				val.y / num2
			});
			((Transform)frame).localScale = new Vector3(num3, num3, 1f);
			Place(title.rectTransform, -16f, 30f);
			Place(error.rectTransform, 0f - (56f + num), 40f);
			float top = 0f - (num2 - 16f - 45f);
			float num4 = 72f;
			PlaceButton(okButton, 0f - num4, top);
			PlaceButton(cancelButton, num4, top);
		}

		private static void Place(RectTransform rect, float top, float height)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 1f);
			rect.anchorMax = val;
			rect.anchorMin = val;
			rect.pivot = new Vector2(0.5f, 1f);
			rect.sizeDelta = new Vector2(528f, height);
			rect.anchoredPosition = new Vector2(0f, top);
		}

		private static void PlaceButton(Button button, float x, float top)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0024: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			RectTransform val = (RectTransform)((Component)button).transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 1f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0.5f, 1f);
			val.sizeDelta = new Vector2(136f, 45f);
			val.anchoredPosition = new Vector2(x, top);
		}

		private void OnDestroy()
		{
			foreach (Action item in unbind)
			{
				item();
			}
		}
	}
	public sealed class VanillaCreateWorldPanel
	{
		private const string CANCEL = "Cancel";

		private const string GENERATE_SEED = "GenerateSeed";

		private const string NAME_LABEL = "name";

		private const string NAME_TIP = "name_tip";

		private const string SEED_LABEL = "seed";

		private readonly Transform original;

		private readonly GameObject frame;

		private readonly GameObject? nameTip;

		public Button Cancel { get; }

		public string NameLabelKey { get; }

		public string SeedLabelKey { get; }

		public VanillaCreateWorldPanel(FejdStartup startup)
		{
			Transform val = GuiElementPalette.NewShelf(startup, "WorldhallaCreateWorldPanel");
			original = ((Component)startup.m_newWorldName).transform.parent;
			Cancel = ((Component)original.Find("Cancel")).GetComponent<Button>();
			NameLabelKey = ((Component)original.Find("name")).GetComponent<TMP_Text>().text;
			SeedLabelKey = ((Component)original.Find("seed")).GetComponent<TMP_Text>().text;
			Transform val2 = original.Find("name_tip");
			if (val2 != null)
			{
				nameTip = Object.Instantiate<GameObject>(((Component)val2).gameObject, val);
			}
			frame = Object.Instantiate<GameObject>(((Component)original).gameObject, val);
			string[] array = new string[8]
			{
				((Object)startup.m_newWorldName).name,
				((Object)startup.m_newWorldSeed).name,
				((Object)startup.m_newWorldDone).name,
				"Cancel",
				"GenerateSeed",
				"name",
				"name_tip",
				"seed"
			};
			foreach (string text in array)
			{
				Transform val3 = frame.transform.Find(text);
				if (val3 != null)
				{
					Object.DestroyImmediate((Object)(object)((Component)val3).gameObject);
				}
			}
		}

		public RectTransform Frame(Transform parent, string name)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			RectTransform val = (RectTransform)Object.Instantiate<GameObject>(frame, parent).transform;
			((Object)val).name = name;
			return val;
		}

		public TMP_Text? NameTip(Transform parent)
		{
			if (!((Object)(object)nameTip != (Object)null))
			{
				return null;
			}
			return Object.Instantiate<GameObject>(nameTip, parent).GetComponent<TMP_Text>();
		}

		public void HideOriginal()
		{
			((Component)original).gameObject.SetActive(false);
		}
	}
	public class WorldCreationDialog : MonoBehaviour
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static PopupButtonCallback <0>__Pop;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__86_4;

			public static Func<RegisteredGenerator, string> <>9__87_0;

			public static Func<RegisteredGenerator, string> <>9__87_1;

			public static Func<RegisteredGenerator, string> <>9__87_2;

			internal void <Initialize>b__86_4()
			{
				Logger.LogInfo("World settings screen is not implemented yet");
			}

			internal string <Open>b__87_0(RegisteredGenerator generator)
			{
				return generator.Name;
			}

			internal string <Open>b__87_1(RegisteredGenerator generator)
			{
				return generator.Guid;
			}

			internal string <Open>b__87_2(RegisteredGenerator generator)
			{
				return "<noparse>" + generator.Name + "</noparse> <color=#8a8a8a>(<noparse>" + generator.Guid + "</noparse>)</color>";
			}
		}

		private const string VANILLA_OPTION = "Valheim";

		private const string GUID_COLOR = "#8a8a8a";

		private const float SEED_DEBOUNCE_SECONDS = 0.5f;

		private const float SPINNER_DEGREES_PER_SECOND = -270f;

		private const float DETAILS_SCREEN_FRACTION = 0.95f;

		private const float LOCATION_ICON_SIZE = 32f;

		private const float CAPTION_FONT_SIZE = 16f;

		private const float CAPTION_WIDTH = 240f;

		private const float CAPTION_OUTLINE_WIDTH = 0.35f;

		private const float GAMEPAD_PAN_PIXELS_PER_SECOND = 600f;

		private const float GAMEPAD_DEAD_ZONE = 0.2f;

		private const float GAMEPAD_SCROLL_PIXELS_PER_SECOND = 150f;

		private const string SPOILER_HEADER = "$wh_spoiler_header";

		private const string SPOILER_TEXT = "$wh_spoiler_text";

		private const string CLICK_TO_REVEAL = "$wh_preview_click_to_reveal";

		private const string GENERATING = "$wh_preview_generating";

		private const string FAILED = "$wh_preview_failed";

		private const string LOCATIONS = "$wh_preview_locations";

		private const string LOCATIONS_PROGRESS = "$wh_preview_locations_progress";

		private const string VANILLA_DESCRIPTION = "$wh_vanilla_description";

		public FejdStartup startup;

		public GuiElementPalette palette;

		public GuiInputField nameField;

		public GuiInputField seedField;

		public TMP_Dropdown generatorDropdown;

		public ScrollRect generatorDescription;

		public TMP_Text worldSettingsSummary;

		public TMP_Text generatorSettingsSummary;

		public RawImage previewImage;

		public Button previewButton;

		public TMP_Text previewLabel;

		public RectTransform spinner;

		public GameObject progress;

		public Image progressFill;

		public TMP_Text progressPercent;

		public Texture2D discTexture;

		public int previewSize;

		public Button hideButton;

		public Button detailsButton;

		public Button worldSettingsButton;

		public Button generatorSettingsButton;

		public Button newSeedButton;

		public Button doneButton;

		public Button cancelButton;

		public GameObject detailsOverlay;

		public RectTransform detailsFrame;

		public RawImage detailsImage;

		public RawImage detailsWholeImage;

		public DragAndScroll detailsInput;

		public UIGroupHandler detailsGroup;

		public GameObject detailsRing;

		public Button detailsCloseButton;

		public Button locationsButton;

		public GameObject locationsNote;

		public SettingsDialog settingsDialog;

		private NavigationGrid navigation;

		private UIGroupHandler? group;

		private WorldPreview preview;

		private PreviewTexture? previewTexture;

		private PreviewTexture? detailsTexture;

		private PreviewTexture? detailsWholeTexture;

		private Texture? detailsPlaceholder;

		private PreviewView detailsView = PreviewView.Whole;

		private PreviewView detailsDragStart;

		private Vector2 gamepadPan;

		private List<RegisteredGenerator> generators = new List<RegisteredGenerator>();

		private ISettings? settings;

		private WorldhallaSettings worldhallaSettings = Worldhalla.Plugin.Core.WorldhallaSettings.Default;

		private bool revealed;

		private bool spoilerAccepted;

		private float? seedChangedAt;

		private Exception? reportedFailure;

		private WorldGenerator? simulatedGenerator;

		private CancellationTokenSource? simulation;

		private LocationSimulation.Progress? simulationProgress;

		private TMP_Text locationsLabel;

		private readonly List<(RectTransform icon, Vector3 position)> locationIcons = new List<(RectTransform, Vector3)>();

		private Material? captionMaterial;

		private static bool LocationsSimulable => LocationPlacementAccelerator.PlacesLikeVanilla;

		public RegisteredGenerator? SelectedWorldgen
		{
			get
			{
				int num = generatorDropdown.value - 1;
				if (num < 0 || num >= generators.Count)
				{
					return null;
				}
				return generators[num];
			}
		}

		public ISettings? Settings => settings;

		public WorldhallaSettings WorldhallaSettings => worldhallaSettings;

		public void Initialize()
		{
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Expected O, but got Unknown
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Expected O, but got Unknown
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Expected O, but got Unknown
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Expected O, but got Unknown
			navigation = new NavigationGrid(new Selectable[5][]
			{
				(Selectable[])(object)new Selectable[1] { (Selectable)nameField },
				(Selectable[])(object)new Selectable[2]
				{
					(Selectable)seedField,
					(Selectable)newSeedButton
				},
				(Selectable[])(object)new Selectable[1] { (Selectable)generatorDropdown },
				(Selectable[])(object)new Selectable[1] { (Selectable)worldSettingsButton },
				(Selectable[])(object)new Selectable[1] { (Selectable)generatorSettingsButton }
			}, new Selectable[3][]
			{
				(Selectable[])(object)new Selectable[1] { (Selectable)previewButton },
				(Selectable[])(object)new Selectable[2]
				{
					(Selectable)hideButton,
					(Selectable)detailsButton
				},
				(Selectable[])(object)new Selectable[2]
				{
					(Selectable)doneButton,
					(Selectable)cancelButton
				}
			});
			group = ((Component)this).GetComponent<UIGroupHandler>();
			preview = new WorldPreview(previewSize);
			previewTexture = new PreviewTexture(previewSize);
			detailsTexture = new PreviewTexture(1024);
			detailsWholeTexture = new PreviewTexture(1024);
			detailsPlaceholder = detailsImage.texture;
			((UnityEvent<string>)(object)((TMP_InputField)seedField).onValueChanged).AddListener((UnityAction<string>)delegate
			{
				OnSeedChanged();
			});
			((UnityEvent<int>)(object)generatorDropdown.onValueChanged).AddListener((UnityAction<int>)delegate
			{
				OnGeneratorChanged();
			});
			((Selectable)newSeedButton).interactable = true;
			((UnityEvent)newSeedButton.onClick).AddListener((UnityAction)delegate
			{
				((TMP_InputField)seedField).text = World.GenerateSeed();
			});
			((UnityEvent)previewButton.onClick).AddListener(new UnityAction(OnPreviewClicked));
			((UnityEvent)hideButton.onClick).AddListener(new UnityAction(Hide));
			((UnityEvent)detailsButton.onClick).AddListener(new UnityAction(OpenDetails));
			((UnityEvent)detailsCloseButton.onClick).AddListener(new UnityAction(CloseDetails));
			((UnityEvent)locationsButton.onClick).AddListener(new UnityAction(SimulateLocations));
			locationsLabel = ((Component)locationsButton).GetComponentInChildren<TMP_Text>(true);
			detailsInput.DragStarted += delegate
			{
				detailsDragStart = detailsView;
			};
			detailsInput.Dragged += PanDetails;
			detailsInput.Scrolled += ZoomDetails;
			ButtonClickedEvent onClick = worldSettingsButton.onClick;
			object obj = <>c.<>9__86_4;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					Logger.LogInfo("World settings screen is not implemented yet");
				};
				<>c.<>9__86_4 = val;
				obj = (object)val;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			((UnityEvent)generatorSettingsButton.onClick).AddListener(new UnityAction(OpenGeneratorSettings));
		}

		public void Open()
		{
			generators = (from generator in Registry.Generators.Values
				orderby generator.Name, generator.Guid
				select generator).ToList();
			generatorDropdown.ClearOptions();
			generatorDropdown.AddOptions(new string[1] { "Valheim" }.Concat(generators.Select((RegisteredGenerator generator) => "<noparse>" + generator.Name + "</noparse> <color=#8a8a8a>(<noparse>" + generator.Guid + "</noparse>)</color>")).ToList());
			generatorDropdown.SetValueWithoutNotify(0);
			generatorDropdown.RefreshShownValue();
			ResetSession();
			worldhallaSettings = Worldhalla.Plugin.Core.WorldhallaSettings.Default;
			OnGeneratorChanged();
		}

		private void OnDisable()
		{
			ResetSession();
		}

		private void OnDestroy()
		{
			if ((Object)(object)captionMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)captionMaterial);
			}
		}

		private void ResetSession()
		{
			revealed = false;
			spoilerAccepted = false;
			seedChangedAt = null;
			preview.Clear();
			CloseDetails();
			settingsDialog.Close();
			simulation?.Cancel();
			simulatedGenerator = null;
			simulationProgress = null;
			ClearLocationIcons();
		}

		private void Update()
		{
			float? num = seedChangedAt;
			if (num.HasValue)
			{
				float valueOrDefault = num.GetValueOrDefault();
				if (Time.unscaledTime - valueOrDefault >= 0.5f)
				{
					seedChangedAt = null;
					RequestPreview();
				}
			}
			preview.Tick();
			ReportFailure();
			NavigateDetails();
			ScrollDescription();
			RefreshPreview();
			RefreshDetails();
			RefreshButtons();
			navigation.Apply();
		}

		private void OnSeedChanged()
		{
			if (revealed)
			{
				preview.Clear();
				seedChangedAt = Time.unscaledTime;
			}
		}

		private void OnGeneratorChanged()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			RegisteredGenerator selectedWorldgen = SelectedWorldgen;
			settings = selectedWorldgen?.DefaultSettings;
			((Component)generatorDescription.content).GetComponent<TMP_Text>().text = ((selectedWorldgen != null) ? selectedWorldgen.Description : Translations.Get("$wh_vanilla_description"));
			generatorDescription.content.anchoredPosition = Vector2.zero;
			worldSettingsSummary.text = "";
			generatorSettingsSummary.text = settings?.Summary() ?? "";
			if (revealed)
			{
				seedChangedAt = null;
				RequestPreview();
			}
		}

		private void OpenGeneratorSettings()
		{
			RegisteredGenerator selectedWorldgen = SelectedWorldgen;
			if (selectedWorldgen == null)
			{
				return;
			}
			ISettingsHandler settingsHandler = selectedWorldgen.SettingsHandler;
			if (settingsHandler != null && settings != null)
			{
				ISettingsForm form;
				try
				{
					form = settingsHandler.CreateForm(settings);
				}
				catch (Exception arg)
				{
					Logger.LogError($"{SelectedWorldgen.Guid} failed to create its settings form: {arg}");
					return;
				}
				settingsDialog.Open(Translations.Get("$wh_settings_title", SelectedWorldgen.Name), form.Controls, delegate
				{
					ISettings result = form.Build();
					WorldPayload.CheckSettings(result);
					return result;
				}, OnGeneratorSettingsAccepted);
			}
		}

		private void OnGeneratorSettingsAccepted(ISettings accepted)
		{
			settings = accepted;
			generatorSettingsSummary.text = accepted.Summary();
			if (revealed)
			{
				seedChangedAt = null;
				RequestPreview();
			}
		}

		private void OnPreviewClicked()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (revealed)
			{
				return;
			}
			if (spoilerAccepted)
			{
				Reveal();
				return;
			}
			string text = Translations.Get("$wh_spoiler_header");
			string text2 = Translations.Get("$wh_spoiler_text");
			PopupButtonCallback val = delegate
			{
				UnifiedPopup.Pop();
				spoilerAccepted = true;
				Reveal();
			};
			object obj = <>O.<0>__Pop;
			if (obj == null)
			{
				PopupButtonCallback val2 = UnifiedPopup.Pop;
				<>O.<0>__Pop = val2;
				obj = (object)val2;
			}
			UnifiedPopup.Push((PopupBase)new YesNoPopup(text, text2, val, (PopupButtonCallback)obj, false, false));
		}

		private void Reveal()
		{
			revealed = true;
			RequestPreview();
		}

		private void Hide()
		{
			revealed = false;
			seedChangedAt = null;
			preview.Clear();
			CloseDetails();
			settingsDialog.Close();
		}

		private void RequestPreview()
		{
			string seed = ((TMP_InputField)seedField).text;
			RegisteredGenerator worldgen = SelectedWorldgen;
			ISettings worldSettings = settings;
			preview.Request(() => PreviewGeneration.Start(worldgen, seed, worldSettings));
		}

		private void OpenDetails()
		{
			//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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			locationsNote.SetActive(!LocationsSimulable);
			Rect rect = ((RectTransform)detailsOverlay.transform).rect;
			Vector2 val = ((Rect)(ref rect)).size * 0.95f;
			Vector2 sizeDelta = detailsFrame.sizeDelta;
			float num = Mathf.Min(new float[3]
			{
				1f,
				val.x / sizeDelta.x,
				val.y / sizeDelta.y
			});
			((Transform)detailsFrame).localScale = new Vector3(num, num, 1f);
			detailsView = PreviewView.Whole;
			gamepadPan = Vector2.zero;
			detailsOverlay.SetActive(true);
		}

		private void SimulateLocations()
		{
			if (LocationsSimulable)
			{
				WorldGenerator generator = preview.Generator;
				if (generator != null && generator != simulatedGenerator)
				{
					simulatedGenerator = generator;
					simulation?.Cancel();
					simulation = new CancellationTokenSource();
					ClearLocationIcons();
					((MonoBehaviour)this).StartCoroutine(RunSimulation(generator, simulation.Token));
				}
			}
		}

		private IEnumerator RunSimulation(WorldGenerator generator, CancellationToken token)
		{
			LocationSimulation.Progress progress = (simulationProgress = new LocationSimulation.Progress());
			yield return LocationSimulation.Run(generator, progress, ShowLocations, token);
			if (simulationProgress == progress)
			{
				simulationProgress = null;
				if (locationIcons.Count == 0 && simulatedGenerator == generator)
				{
					simulatedGenerator = null;
				}
			}
		}

		private void ShowLocations(List<LocationSimulation.Placed> placed)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			if (preview.Generator != simulatedGenerator)
			{
				return;
			}
			foreach (LocationSimulation.Placed item in placed)
			{
				GameObject val = new GameObject(item.name, new Type[2]
				{
					typeof(RectTransform),
					typeof(RawImage)
				});
				val.transform.SetParent(((Component)detailsInput).transform, false);
				RawImage component = val.GetComponent<RawImage>();
				component.texture = (Texture)(object)item.icon;
				((Graphic)component).raycastTarget = false;
				RectTransform rectTransform = ((Graphic)component).rectTransform;
				rectTransform.sizeDelta = 40.32f * Vector2.one;
				rectTransform.anchoredPosition = Vector2.zero;
				locationIcons.Add((rectTransform, item.position));
				if (item.caption != null)
				{
					AddCaption(rectTransform, item.caption);
				}
			}
		}

		private void AddCaption(RectTransform icon, string text)
		{
			//IL_006f: 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_0086: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = palette.Label((Transform)(object)icon, "Caption", "");
			val.fontSharedMaterial = CaptionMaterial(val);
			val.text = text;
			val.fontSize = 16f;
			val.horizontalAlignment = (HorizontalAlignmentOptions)2;
			val.verticalAlignment = (VerticalAlignmentOptions)256;
			val.textWrappingMode = (TextWrappingModes)0;
			((Graphic)val).raycastTarget = false;
			RectTransform rectTransform = val.rectTransform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0f);
			rectTransform.anchorMax = val2;
			rectTransform.anchorMin = val2;
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.sizeDelta = new Vector2(240f, 24f);
			rectTransform.anchoredPosition = Vector2.zero;
		}

		private Material CaptionMaterial(TMP_Text caption)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)captionMaterial != (Object)null)
			{
				return captionMaterial;
			}
			captionMaterial = new Material(caption.fontSharedMaterial);
			captionMaterial.SetFloat(ShaderUtilities.ID_FaceDilate, 0.35f);
			captionMaterial.SetFloat(ShaderUtilities.ID_OutlineWidth, 0.35f);
			captionMaterial.SetColor(ShaderUtilities.ID_OutlineColor, IconOutline.Ink);
			return captionMaterial;
		}

		private void ClearLocationIcons()
		{
			foreach (var locationIcon in locationIcons)
			{
				Object.Destroy((Object)(object)((Component)locationIcon.icon).gameObject);
			}
			locationIcons.Clear();
		}

		private void PlaceLocationIcons()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (preview.Generator == simulatedGenerator)
			{
				float? worldRadius = preview.WorldRadius;
				if (worldRadius.HasValue)
				{
					float valueOrDefault = worldRadius.GetValueOrDefault();
					{
						foreach (var locationIcon in locationIcons)
						{
							RectTransform item = locationIcon.icon;
							Vector3 item2 = locationIcon.position;
							Vector2 val = detailsView.Normalized(new Vector2(item2.x, item2.z), valueOrDefault);
							Vector2 anchorMin = (item.anchorMax = val);
							item.anchorMin = anchorMin;
						}
						return;
					}
				}
			}
			ClearLocationIcons();
		}

		private void PanDetails(Vector2 offset)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			detailsView = detailsDragStart.Panned(ToDetailsPixels(offset));
		}

		private void ZoomDetails(Vector2 at, float scroll)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0025: Unknown result type (might be due to invalid IL or missing references)
			if (scroll != 0f)
			{
				detailsView = detailsView.Zoomed(ToDetailsPixels(at) + 512f * Vector2.one, scroll > 0f);
			}
		}

		private void NavigateDetails()
		{
			//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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			if (detailsOverlay.activeSelf && detailsGroup.IsActive)
			{
				Vector2 joyLeftStick = ZInput.GetJoyLeftStick();
				if (((Vector2)(ref joyLeftStick)).magnitude > 0.2f)
				{
					gamepadPan -= joyLeftStick * (600f * Time.unscaledDeltaTime);
					Vector2 val = default(Vector2);
					((Vector2)(ref val))..ctor(Mathf.Round(gamepadPan.x), Mathf.Round(gamepadPan.y));
					gamepadPan -= val;
					detailsView = detailsView.Panned(val);
				}
				bool buttonDown = ZInput.GetButtonDown("JoyMapZoomIn");
				if (buttonDown || ZInput.GetButtonDown("JoyMapZoomOut"))
				{
					detailsView = detailsView.Zoomed(512f * Vector2.one, buttonDown);
				}
			}
		}

		private void ScrollDescription()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			UIGroupHandler val = group;
			if (val == null || val.IsActive)
			{
				float joyRightStickY = ZInput.GetJoyRightStickY();
				Rect rect = generatorDescription.content.rect;
				float height = ((Rect)(ref rect)).height;
				rect = generatorDescription.viewport.rect;
				float num = height - ((Rect)(ref rect)).height;
				if (!(Mathf.Abs(joyRightStickY) <= 0.2f) && !(num <= 0f))
				{
					float num2 = joyRightStickY * 150f * Time.unscaledDeltaTime / num;
					generatorDescription.verticalNormalizedPosition = Mathf.Clamp01(generatorDescription.verticalNormalizedPosition - num2);
				}
			}
		}

		private Vector2 ToDetailsPixels(Vector2 local)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = ((RectTransform)((Component)detailsInput).transform).rect;
			return local * (1024f / ((Rect)(ref rect)).width);
		}

		private void CloseDetails()
		{
			detailsOverlay.SetActive(false);
		}

		private void ReportFailure()
		{
			Exception failure = preview.GetFailure();
			if (failure != null && failure != reportedFailure)
			{
				reportedFailure = failure;
				Logger.LogError($"World preview failed: {failure}");
			}
		}

		private void RefreshPreview()
		{
			WorldPreview.Phase currentPhase = preview.CurrentPhase;
			bool flag = revealed && (currentPhase == WorldPreview.Phase.Generating || seedChangedAt.HasValue);
			PreviewRender main = preview.Main;
			bool flag2 = main != null;
			if (flag2)
			{
				bool flag3 = (uint)(currentPhase - 2) <= 1u;
				flag2 = flag3;
			}
			if (flag2)
			{
				previewTexture.Show(main);
				previewImage.texture = (Texture)(object)previewTexture.texture;
			}
			else
			{
				previewImage.texture = (Texture)(object)discTexture;
			}
			previewLabel.text = Translations.Get((!revealed) ? "$wh_preview_click_to_reveal" : (flag ? "$wh_preview_generating" : ((currentPhase == WorldPreview.Phase.Failed) ? "$wh_preview_failed" : "")));
			float? num = (flag ? preview.GenerationProgress : ((float?)null));
			progress.SetActive(num.HasValue);
			if (num.HasValue)
			{
				float valueOrDefault = num.GetValueOrDefault();
				progressFill.fillAmount = valueOrDefault;
				progressPercent.text = $"{Mathf.FloorToInt(valueOrDefault * 100f)}%";
			}
			((Component)spinner).gameObject.SetActive(flag && !num.HasValue);
			if (flag && !num.HasValue)
			{
				((Transform)spinner).Rotate(0f, 0f, -270f * Time.unscaledDeltaTime);
			}
		}

		private void RefreshDetails()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			if (detailsOverlay.activeSelf)
			{
				detailsRing.SetActive(detailsView.IsWhole);
				PlaceLocationIcons();
				DetailsRender detailsRender = preview.EnsureDetails(detailsView);
				DetailsRender wholeDetails = preview.WholeDetails;
				((Behaviour)detailsWholeImage).enabled = wholeDetails != null;
				if (wholeDetails != null)
				{
					detailsWholeTexture.Show(wholeDetails);
					detailsWholeImage.texture = (Texture)(object)detailsWholeTexture.texture;
					Place(detailsWholeImage, wholeDetails.view.PlacementIn(detailsView));
				}
				((Behaviour)detailsImage).enabled = detailsRender == null || detailsRender != wholeDetails;
				if (detailsRender != null)
				{
					detailsTexture.Show(detailsRender);
					detailsImage.texture = (Texture)(object)detailsTexture.texture;
					Place(detailsImage, detailsRender.view.PlacementIn(detailsView));
				}
				else
				{
					detailsImage.texture = detailsPlaceholder;
					Place(detailsImage, new Rect(0f, 0f, 1f, 1f));
				}
			}
		}

		private static void Place(RawImage image, Rect placement)
		{
			//IL_0008: 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)
			((Graphic)image).rectTransform.anchorMin = ((Rect)(ref placement)).min;
			((Graphic)image).rectTransform.anchorMax = ((Rect)(ref placement)).max;
		}

		private void RefreshButtons()
		{
			RegisteredGenerator selectedWorldgen = SelectedWorldgen;
			((Selectable)hideButton).interactable = revealed;
			((Selectable)detailsButton).interactable = revealed && preview.CanShowDetails;
			((Selectable)locationsButton).interactable = LocationsSimulable && preview.Generator != null && preview.Generator != simulatedGenerator;
			TMP_Text obj = locationsLabel;
			LocationSimulation.Progress progress = simulationProgress;
			obj.text = ((progress != null) ? Translations.Get("$wh_preview_locations_progress", Mathf.FloorToInt(progress.Fraction * 100f).ToString()) : Translations.Get("$wh_preview_locations"));
			((Selectable)worldSettingsButton).interactable = selectedWorldgen != null;
			((Selectable)generatorSettingsButton).interactable = selectedWorldgen?.SettingsHandler != null;
		}
	}
	public static class WorldCreationDialogBuilder
	{
		private const string PANEL_NAME = "WorldhallaPanel";

		private const string DETAILS_NAME = "WorldhallaPreviewDetails";

		private const string SETTINGS_NAME = "WorldhallaSettings";

		private const float DESCRIPTION_HEIGHT = 56f;

		private const float DESCRIPTION_ROW = 66f;

		private const float PANEL_WIDTH = 926f;

		private const float PANEL_HEIGHT = 606f;

		private const float CONTENT_TOP = 248f;

		private const float COLUMN1_X = -253f;

		private const float COLUMN1_WIDTH = 360f;

		private const float COLUMN2_RIGHT = 428f;

		private const float LABEL_HEIGHT = 26f;

		private const float FIELD_HEIGHT = 35f;

		private const float SUMMARY_HEIGHT = 85f;

		private const float MAIN_BUTTON_HEIGHT = 45f;

		private const float ROW_GAP = 10f;

		private const float BUTTON_GAP = 8f;

		private const float CLOSE_BUTTON_WIDTH = 136f;

		private const float LOCATIONS_BUTTON_WIDTH = 200f;

		private const float EDIT_BUTTON_WIDTH = 80f;

		private const float ICON_BUTTON_SIZE = 35f;

		private const int OVERLAY_GROUP_PRIORITY = 2;

		private const float SELECTION_RING_WIDTH = 9f;

		private const string GAMEPAD_BACK = "ButtonB";

		private const string GAMEPAD_CONFIRM = "ButtonX";

		private const string GAMEPAD_ACTION = "ButtonY";

		private const float DETAILS_MAP_SIZE = 1024f;

		private const float DETAILS_PADDING = 12f;

		private const float DETAILS_TITLE_HEIGHT = 30f;

		private const float DETAILS_WIDTH = 1048f;

		private const float DETAILS_HEIGHT = 1139f;

		private const int SPINNER_SIZE = 64;

		private const float SPINNER_DISPLAY_SIZE = 32f;

		private const int PROGRESS_SIZE = 96;

		private const float PROGRESS_DISPLAY_SIZE = 48f;

		private const float PROGRESS_FONT_SCALE = 0.6f;

		private const float RING_WIDTH = 3f;

		private static readonly Color DiscColor = new Color(0.05f, 0.07f, 0.08f, 0.92f);

		private static readonly Color RingColor = new Color(0.64f, 0.48f, 0.21f, 1f);

		private static readonly Color SelectionColor = new Color(0.94f, 0.7f, 0.29f, 1f);

		private static readonly Color SpinnerColor = new Color(0.94f, 0.7f, 0.29f, 1f);

		private static readonly Color ProgressTrackColor = new Color(0.94f, 0.7f, 0.29f, 0.2f);

		private static readonly Color OverlayColor = new Color(0f, 0f, 0f, 0.6f);

		private static readonly Color ErrorColor = new Color(0.93f, 0.45f, 0.35f, 1f);

		private const float ERROR_FONT_SCALE = 0.8f;

		public static WorldCreationDialog Build(FejdStartup startup, VanillaCreateWorldPanel vanilla, GuiElementPalette palette)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = startup.m_createWorldPanel.transform;
			GuiInputField newWorldName = startup.m_newWorldName;
			GuiInputField newWorldSeed = startup.m_newWorldSeed;
			Button newWorldDone = startup.m_newWorldDone;
			Button cancel = vanilla.Cancel;
			RectTransform val = vanilla.Frame(transform, "WorldhallaPanel");
			val.sizeDelta = new Vector2(926f, 606f);
			vanilla.HideOriginal();
			WorldCreationDialog worldCreationDialog = ((Component)val).gameObject.AddComponent<WorldCreationDialog>();
			worldCreationDialog.startup = startup;
			worldCreationDialog.palette = palette;
			worldCreationDialog.nameField = newWorldName;
			worldCreationDialog.seedField = newWorldSeed;
			worldCreationDialog.doneButton = newWorldDone;
			worldCreationDialog.cancelButton = cancel;
			float y = 248f;
			PlaceLabel(palette.Label((Transform)(object)val, "name", vanilla.NameLabelKey).transform, ref y);
			TMP_Text val2 = vanilla.NameTip((Transform)(object)val);
			if (val2 != null)
			{
				Place(val2.transform, -253f, y + 26f, 360f, 26f);
				val2.horizontalAlignment = (HorizontalAlignmentOptions)4;
			}
			PlaceField(((Component)newWorldName).transform, val, 35f, ref y);
			PlaceLabel(palette.Label((Transform)(object)val, "seed", vanilla.SeedLabelKey).transform, ref y);
			((Component)newWorldSeed).transform.SetParent((Transform)(object)val, false);
			float num = 317f;
			Place(((Component)newWorldSeed).transform, -253f - (360f - num) / 2f, y, num, 35f);
			worldCreationDialog.newSeedButton = palette.IconButton((Transform)(object)val, "NewSeed");
			Place(((Component)worldCreationDialog.newSeedButton).transform, -90.5f, y, 35f, 35f);
			y -= 45f;
			PlaceLabel(palette.Label((Transform)(object)val, "generator", "$wh_generator").transform, ref y);
			worldCreationDialog.generatorDropdown = palette.Dropdown((Transform)(object)val, "GeneratorDropdown");
			RectTransform val3 = (RectTransform)((Component)worldCreationDialog.generatorDropdown).transform;
			PlaceField((Transform)(object)val3, val, val3.sizeDelta.y, ref y);
			worldCreationDialog.generatorDescription = NewDescription(palette, val, ref y);
			worldCreationDialog.worldSettingsButton = NewEditableLabel(palette, val, "worldSettings", "$wh_world_settings", ref y);
			worldCreationDialog.worldSettingsSummary = NewSummary(palette, val, "WorldSettingsSummary", ref y);
			worldCreationDialog.generatorSettingsButton = NewEditableLabel(palette, val, "generatorSettings", "$wh_generator_settings", ref y);
			worldCreationDialog.generatorSettingsSummary = NewSummary(palette, val, "GeneratorSettingsSummary", ref y);
			float num2 = y + 10f;
			int num3 = Mathf.FloorToInt(248f - num2 - 55f);
			float num4 = num3;
			float num5 = 428f - num4 / 2f;
			y = 248f;
			BuildPreview(worldCreationDialog, val, palette, num5, num3, ref y);
			float num6 = y + 10f;
			worldCreationDialog.hideButton = palette.IconButton((Transform)(object)val, "HidePreview", Icons.CrossedEye);
			Place(((Component)worldCreationDialog.hideButton).transform, num5 - (num4 - 35f) / 2f, num6 + 35f, 35f, 35f);
			worldCreationDialog.detailsButton = palette.IconButton((Transform)(object)val, "PreviewDetails", Icons.Magnifier);
			Place(((Component)worldCreationDialog.detailsButton).transform, num5 + (num4 - 35f) / 2f, num6 + 35f, 35f, 35f);
			float num7 = (num4 - 8f) / 2f;
			float num8 = (num7 + 8f) / 2f;
			((Component)newWorldDone).transform.SetParent((Transform)(object)val, false);
			((Component)cancel).transform.SetParent((Transform)(object)val, false);
			Place(((Component)newWorldDone).transform, num5 - num8, y, num7, 45f);
			Place(((Component)cancel).transform, num5 + num8, y, num7, 45f);
			UIGroupHandler component = ((Component)val).GetComponent<UIGroupHandler>();
			if (component != null)
			{
				component.m_defaultElement = ((Component)newWorldName).gameObject;
			}
			BuildDetails(worldCreationDialog, transform, palette);
			worldCreationDialog.settingsDialog = BuildSettingsDialog(transform, palette);
			worldCreationDialog.Initialize();
			return worldCreationDialog;
		}

		private static void BuildPreview(WorldCreationDialog dialog, RectTransform panel, GuiElementPalette palette, float x, int size, ref float y)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			dialog.previewSize = size;
			dialog.discTexture = Shapes.Disc(size, DiscColor);
			RawImage val = NewRawImage((Transform)(object)panel, "Preview", (Texture)(object)dialog.discTexture, raycastTarget: true);
			Place(((Component)val).transform, x, y, size, size);
			y -= (float)size + 10f;
			dialog.previewImage = val;
			dialog.previewButton = ((Component)val).gameObject.AddComponent<Button>();
			Stretch(((Graphic)NewRawImage(((Component)val).transform, "Ring", (Texture)(object)Shapes.Ring(size, 3f, RingColor), raycastTarget: false)).rectTransform);
			RawImage val2 = NewRawImage(((Component)val).transform, "Selection", (Texture)(object)Shapes.Ring(size, 9f, SelectionColor), raycastTarget: false);
			Stretch(((Graphic)val2).rectTransform);
			((Selectable)dialog.previewButton).targetGraphic = (Graphic)(object)val2;
			((Selectable)dialog.previewButton).colors = ShownWhenSelected(((Selectable)dialog.previewButton).colors);
			RawImage val3 = NewRawImage(((Component)val).transform, "Spinner", (Texture)(object)Shapes.Arc(64, 4f, 270f, SpinnerColor), raycastTarget: false);
			((Graphic)val3).rectTransform.sizeDelta = new Vector2(32f, 32f);
			((Graphic)val3).rectTransform.anchoredPosition = new Vector2(0f, 32f);
			dialog.spinner = ((Graphic)val3).rectTransform;
			BuildProgress(dialog, ((Component)val).transform, palette);
			TMP_Text val4 = palette.Label(((Component)val).transform, "Label", "");
			val4.horizontalAlignment = (HorizontalAlignmentOptions)2;
			val4.verticalAlignment = (VerticalAlignmentOptions)512;
			((Graphic)val4).raycastTarget = false;
			Stretch(val4.rectTransform);
			dialog.previewLabel = val4;
		}

		private static void BuildProgress(WorldCreationDialog dialog, Transform parent, GuiElementPalette palette)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Progress", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform val2 = (RectTransform)val.transform;
			val2.sizeDelta = new Vector2(48f, 48f);
			val2.anchoredPosition = new Vector2(0f, 48f);
			val.SetActive(false);
			dialog.progress = val;
			Stretch(((Graphic)NewRawImage((Transform)(object)val2, "Track", (Texture)(object)Shapes.Ring(96, 6f, ProgressTrackColor), raycastTarget: false)).rectTransform);
			Texture2D val3 = Shapes.Ring(96, 6f, SpinnerColor);
			Image component = new GameObject("Fill", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).GetComponent<Image>();
			((Component)component).transform.SetParent((Transform)(object)val2, false);
			component.sprite = Sprite.Create(val3, new Rect(0f, 0f, 96f, 96f), new Vector2(0.5f, 0.5f));
			component.type = (Type)3;
			component.fillMethod = (FillMethod)4;
			component.fillOrigin = 2;
			component.fillClockwise = true;
			component.fillAmount = 0f;
			((Graphic)component).raycastTarget = false;
			Stretch(((Graphic)component).rectTransform);
			dialog.progressFill = component;
			TMP_Text val4 = palette.Label((Transform)(object)val2, "Percent", "");
			val4.enableAutoSizing = false;
			val4.fontSize *= 0.6f;
			val4.horizontalAlignment = (HorizontalAlignmentOptions)2;
			val4.verticalAlignment = (VerticalAlignmentOptions)512;
			((Graphic)val4).raycastTarget = false;
			Stretch(val4.rectTransform);
			dialog.progressPercent = val4;
		}

		private static void BuildDetails(WorldCreationDialog dialog, Transform root, GuiElementPalette palette)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_004e: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: 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_021e: 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_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("WorldhallaPreviewDetails", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(root, false);
			Stretch((RectTransform)val.transform);
			((Graphic)val.GetComponent<Image>()).color = OverlayColor;
			RectTransform val2 = (RectTransform)new GameObject("Frame", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val2).SetParent(val.transform, false);
			val2.sizeDelta = new Vector2(1048f, 1139f);
			palette.Background((Transform)(object)val2);
			float num = 557.5f;
			TMP_Text obj = palette.Label((Transform)(object)val2, "topic", "$wh_preview_title");
			obj.horizontalAlignment = (HorizontalAlignmentOptions)2;
			Place(obj.transform, 0f, num, 1024f, 30f);
			num -= 38f;
			GameObject val3 = new GameObject("Map", new Type[3]
			{
				typeof(RectTransform),
				typeof(RectMask2D),
				typeof(Image)
			});
			val3.transform.SetParent((Transform)(object)val2, false);
			((Graphic)val3.GetComponent<Image>()).color = Color.clear;
			Place(val3.transform, 0f, num, 1024f, 1024f);
			RawImage val4 = NewRawImage(val3.transform, "Whole", (Texture)(object)Texture2D.blackTexture, raycastTarget: false);
			Stretch(((Graphic)val4).rectTransform);
			RawImage val5 = NewRawImage(val3.transform, "View", (Texture)(object)Shapes.Disc(1024, DiscColor), raycastTarget: false);
			Stretch(((Graphic)val5).rectTransform);
			RawImage val6 = NewRawImage(val3.transform, "Ring", (Texture)(object)Shapes.Ring(1024, 6f, RingColor), raycastTarget: false);
			Stretch(((Graphic)val6).rectTransform);
			num -= 1032f;
			Button val7 = palette.Button((Transform)(object)val2, "Close", "$wh_preview_close", "ButtonB");
			Button val8 = palette.Button((Transform)(object)val2, "Locations", "$wh_preview_locations", "ButtonY");
			Navigation val9 = default(Navigation);
			((Navigation)(ref val9)).mode = (Mode)0;
			Navigation navigation = (((Selectable)val8).navigation = val9);
			((Selectable)val7).navigation = navigation;
			dialog.detailsGroup = NewOverlayGroup(val);
			Place(((Component)val8).transform, -104f, num, 200f, 45f);
			Place(((Component)val7).transform, 72f, num, 136f, 45f);
			TMP_Text val11 = palette.Label((Transform)(object)val2, "LocationsNote", "$wh_preview_locations_lpa");
			val11.horizontalAlignment = (HorizontalAlignmentOptions)4;
			val11.verticalAlignment = (VerticalAlignmentOptions)512;
			val11.textWrappingMode = (TextWrappingModes)1;
			val11.enableAutoSizing = false;
			val11.fontSize *= 0.75f;
			((Graphic)val11).raycastTarget = false;
			float num2 = -212f;
			float num3 = 512f + num2;
			Place(val11.transform, num2 - num3 / 2f, num, num3, 45f);
			dialog.detailsOverlay = val;
			dialog.detailsFrame = val2;
			dialog.detailsImage = val5;
			dialog.detailsWholeImage = val4;
			dialog.detailsInput = val3.AddComponent<DragAndScroll>();
			dialog.detailsRing = ((Component)val6).gameObject;
			dialog.detailsCloseButton = val7;
			dialog.locationsButton = val8;
			dialog.locationsNote = ((Component)val11).gameObject;
			val.SetActive(false);
		}

		private static SettingsDialog BuildSettingsDialog(Transform root, GuiElementPalette palette)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_004e: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("WorldhallaSettings", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(root, false);
			Stretch((RectTransform)val.transform);
			((Graphic)val.GetComponent<Image>()).color = OverlayColor;
			RectTransform val2 = (RectTransform)new GameObject("Frame", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val2).SetParent(val.transform, false);
			palette.Background((Transform)(object)val2);
			RectTransform val3 = (RectTransform)new GameObject("Rows", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val3).SetParent((Transform)(object)val2, false);
			Stretch(val3);
			TMP_Text val4 = palette.Label((Transform)(object)val2, "topic", "");
			val4.horizontalAlignment = (HorizontalAlignmentOptions)2;
			TMP_Text val5 = palette.Label((Transform)(object)val2, "error", "");
			val5.horizontalAlignment = (HorizontalAlignmentOptions)2;
			val5.verticalAlignment = (VerticalAlignmentOptions)512;
			val5.textWrappingMode = (TextWrappingModes)1;
			((Graphic)val5).color = ErrorColor;
			val5.fontSize *= 0.8f;
			TMP_Text val6 = palette.Label((Transform)(object)val2, "LabelTemplate", "");
			val6.horizontalAlignment = (HorizontalAlignmentOptions)1;
			((Component)val6).gameObject.SetActive(false);
			TMP_Dropdown val7 = palette.Dropdown((Transform)(object)val2, "DropdownTemplate");
			((Component)val7).gameObject.SetActive(false);
			GuiInputField val8 = palette.TextField((Transform)(object)val2, "TextField");
			((Component)val8).gameObject.SetActive(false);
			SettingsDialog settingsDialog = val.AddComponent<SettingsDialog>();
			settingsDialog.frame = val2;
			settingsDialog.title = val4;
			settingsDialog.rows = val3;
			settingsDialog.error = val5;
			settingsDialog.okButton = palette.Button((Transform)(object)val2, "Ok", "$wh_settings_ok", "ButtonX");
			settingsDialog.cancelButton = palette.Button((Transform)(object)val2, "Cancel", "$wh_settings_cancel", "ButtonB");
			settingsDialog.group = NewOverlayGroup(val);
			settingsDialog.labelTemplate = val6;
			settingsDialog.dropdownTemplate = val7;
			settingsDialog.textFieldTemplate = val8;
			settingsDialog.Initialize();
			return settingsDialog;
		}

		private static void PlaceLabel(Transform label, ref float y)
		{
			Place(label, -253f, y, 360f, 26f);
			((Component)label).GetComponent<TMP_Text>().horizontalAlignment = (HorizontalAlignmentOptions)1;
			y -= 26f;
		}

		private static Button NewEditableLabel(GuiElementPalette palette, RectTransform panel, string name, string text, ref float y)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			float top = y;
			TMP_Text val = palette.Label((Transform)(object)panel, name, text);
			PlaceLabel(val.transform, ref y);
			Button obj = palette.Button((Transform)(object)panel, name + "Edit", "$wh_edit");
			Place(((Component)obj).transform, -113f, top, 80f, 26f);
			TMP_Text componentInChildren = ((Component)obj).GetComponentInChildren<TMP_Text>(true);
			Stretch(componentInChildren.rectTransform);
			componentInChildren.margin = Vector4.zero;
			componentInChildren.enableAutoSizing = false;
			componentInChildren.fontSize = val.fontSize;
			componentInChildren.textWrappingMode = (TextWrappingModes)0;
			componentInChildren.overflowMode = (TextOverflowModes)0;
			componentInChildren.verticalAlignment = (VerticalAlignmentOptions)512;
			return obj;
		}

		private static void PlaceField(Transform field, RectTransform panel, float height, ref float y)
		{
			field.SetParent((Transform)(object)panel, false);
			Place(field, -253f, y, 360f, height);
			y -= height + 10f;
		}

		private static RectTransform Place(Transform transform, float x, float top, float width, float height)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0056: Expected O, but got Unknown
			RectTransform val = (RectTransform)transform;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val.anchorMax = val2;
			val