Decompiled source of HudLayout v1.0.1

HudLayout.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

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

public static class HudLayoutApi
{
	internal sealed class Entry
	{
		public string Id;

		public string Name;

		public RectTransform Target;

		public bool Wrap;
	}

	public const int ApiVersion = 1;

	internal static readonly Dictionary<string, Entry> Entries = new Dictionary<string, Entry>(StringComparer.OrdinalIgnoreCase);

	public static bool IsEditing
	{
		get
		{
			if ((Object)(object)HudLayoutPlugin.Instance != (Object)null)
			{
				return HudLayoutPlugin.Instance.Editing;
			}
			return false;
		}
	}

	public static void Register(string id, RectTransform target, string displayName)
	{
		Register(id, target, displayName, wrap: false);
	}

	public static void Register(string id, RectTransform target, string displayName, bool wrap)
	{
		if (!string.IsNullOrEmpty(id) && !((Object)(object)target == (Object)null))
		{
			Entry entry = new Entry();
			entry.Id = id.Trim();
			entry.Name = (string.IsNullOrEmpty(displayName) ? entry.Id : displayName);
			entry.Target = target;
			entry.Wrap = wrap;
			Entries[entry.Id] = entry;
		}
	}

	public static void Unregister(string id)
	{
		if (!string.IsNullOrEmpty(id))
		{
			Entries.Remove(id.Trim());
			if ((Object)(object)HudLayoutPlugin.Instance != (Object)null)
			{
				HudLayoutPlugin.Instance.ForgetApiElement(id.Trim());
			}
		}
	}
}
[BepInPlugin("j1ga.hudlayout", "HudLayout", "1.0.1")]
public class HudLayoutPlugin : BaseUnityPlugin
{
	private sealed class ConfigurationManagerAttributes
	{
		public int? Order;

		public bool? IsAdvanced;
	}

	private enum DragKind
	{
		None,
		Move,
		Scale,
		Edge,
		ResizeWindow
	}

	private const string Usage = "hudlayout edit | presets | apply <name> [all|layout|style] | save <name> | delete <name> | export [name] | import | reset | dump";

	private const string CustomStyle = "Custom";

	private const string EditHint = " Easiest to set in the F7 editor.";

	public const string Guid = "j1ga.hudlayout";

	public const string Name = "HudLayout";

	public const string Version = "1.0.1";

	private const int MaxErrors = 25;

	private const float GridStep = 0.005f;

	private const float TitleH = 26f;

	private const int WindowId = 303575;

	private const string ExportPrefix = "HUDLAYOUT1:";

	private const string VanillaPreset = "Vanilla";

	private const string AuthorsChoiceText = "Health.PositionX = 0.5\nHealth.PositionY = 0.11\nHealth.Orientation = Horizontal\nHealth.Anchor = Center\nHealth.Length = 2\nHealth.Thickness = 0.9\nHealth.FixedLength = true\nHealth.Style = Custom\nHealth.Visibility = NotFull\nHealth.Text = CurrentMax\nHealth.TextSize = 1.3\nHealth.TextPosition = Center\nHealth.Segments = true\nHealth.Icon = false\nStamina.PositionX = 0.5\nStamina.PositionY = 0.925\nStamina.Orientation = Horizontal\nStamina.Length = 2.5\nStamina.FixedLength = true\nStamina.Style = Custom\nStamina.Visibility = NotFull\nStamina.Text = CurrentMax\nStamina.TextSize = 1.37\nStamina.TextPosition = Center\nStamina.Segments = true\nEitr.PositionX = 0.5\nEitr.PositionY = 0.08\nEitr.Length = 2.45\nEitr.Thickness = 1.6\nEitr.FixedLength = true\nEitr.Style = Custom\nEitr.Visibility = NotFull\nEitr.Text = CurrentMax\nEitr.TextSize = 1.11\nEitr.TextPosition = Center\nEitr.Segments = true\nAdrenaline.PositionX = 0.565\nAdrenaline.PositionY = 0.5\nAdrenaline.Orientation = Vertical\nAdrenaline.Length = 0.75\nAdrenaline.Thickness = 0.45\nAdrenaline.FixedLength = true\nAdrenaline.Style = Custom\nAdrenaline.Opacity = 0.5\nAdrenaline.Text = CurrentMax\nAdrenaline.TextPosition = Center\nAdrenaline.Segments = true\nFood.PositionX = 0.5\nFood.PositionY = 0.03\nFood.Orientation = Horizontal\nFood.Icon = false\nGuardianPower.PositionX = 0.105\nGuardianPower.PositionY = 0.11\nStagger.PositionX = 0.435\nStagger.PositionY = 0.5\nMount.PositionX = 0.5\nMount.PositionY = 0.16\nShip.PositionX = 0.93\nShip.PositionY = 0.635\nSaveIcon.PositionX = 0.015\nSaveIcon.PositionY = 0.955\nBadConnection.PositionX = 0.015\nBadConnection.PositionY = 0.955\nMod.Compass.PositionX = 0.5\nMod.Compass.PositionY = 0.98\nMod.WeaponArts.PositionX = 0.5\nMod.WeaponArts.PositionY = 0.175\nMod.ExtraSlotsFoodHotBar.PositionX = 0.05\nMod.ExtraSlotsFoodHotBar.PositionY = 0.05\nMod.ExtraSlotsAmmoHotBar.PositionX = 0.05\nMod.ExtraSlotsAmmoHotBar.PositionY = 0.18\nMod.ExtraSlotsQuickSlotsHotBar.PositionX = 0.05\nMod.ExtraSlotsQuickSlotsHotBar.PositionY = 0.115\n";

	private ConfigEntry<bool> _cfgEnabled;

	private ConfigEntry<KeyboardShortcut> _cfgEditKey;

	private ConfigEntry<bool> _cfgBuildShift;

	private ConfigEntry<float> _cfgEditorOpacity;

	private static ConfigEntry<string> _cfgLanguage;

	internal readonly ElementSettings[] Elements = new ElementSettings[5];

	internal readonly List<ElementSettings> Extra = new List<ElementSettings>();

	private int _order;

	private bool _orphansDropped;

	private int _applying;

	public static HudLayoutPlugin Instance;

	private Harmony _harmony;

	private int _errorCount;

	private bool _disabledByErrors;

	private readonly HashSet<string> _loggedErrors = new HashSet<string>();

	private bool _editing;

	private bool _snap = true;

	private ElementSettings _sel;

	private DragKind _drag;

	private Vector2 _grab;

	private float _dragStartScale;

	private float _dragStartDist;

	private ConfigEntry<float> _edgeTarget;

	private bool _edgeAlongX;

	private Rect _win;

	private float _winW = 470f;

	private float _winH = 700f;

	private bool _collapsed;

	private bool _winPlaced;

	private Vector2 _scroll;

	private string _saveName = "";

	private string _colorBuf = "";

	private string _confirmDelete;

	private float _confirmUntil;

	private string _msg = "";

	private float _msgUntil;

	private int _escFrame = -1;

	private bool _savedSaveOnSet = true;

	private GUIStyle _labelStyle;

	private GUIStyle _shadowStyle;

	private GUIStyle _headerStyle;

	private GUIStyle _hintStyle;

	private GUIStyle _smallButton;

	private GUIStyle _wrapLabel;

	private GUIStyle _wrapToggle;

	private GUIStyle _windowStyle;

	private GUIStyle _gridStyle;

	private Texture2D _windowBg;

	private float _windowBgAlpha = -1f;

	private static readonly string[] Swatches = new string[9] { "", "#FF3B3B", "#FF8A1F", "#FFD21F", "#5BE35B", "#3FD5E8", "#4A8BFF", "#B86BFF", "#FFFFFF" };

	private static readonly string[] Languages = new string[3] { "Auto", "English", "Russian" };

	private Hud _hud;

	private RectTransform _root;

	private Canvas _canvas;

	private readonly List<HudElement> _hudElements = new List<HudElement>();

	private static FieldInfo _lastMaxAdrenaline;

	private static readonly int VisibleHash = Animator.StringToHash("Visible");

	private readonly Vector3[] _corners = (Vector3[])(object)new Vector3[4];

	private readonly List<Preset> _builtIn = new List<Preset>();

	private readonly List<Preset> _user = new List<Preset>();

	private ConfigEntry<bool> _cfgModElements;

	private ConfigEntry<string> _cfgIgnore;

	private static readonly HashSet<string> VanillaRootChildren = new HashSet<string>(StringComparer.Ordinal)
	{
		"Inventory tip", "HotKeyBar", "staminapanel", "adrenalinepanel", "eitrpanel", "healthpanel", "staggerpanel", "crosshair", "GuardianPower", "BuildHud",
		"ShipHud", "BuildUIV2", "MountHud", "StatusEffects", "KeyHints", "MiniMap", "Damaged", "LavaWarning", "EventBar", "action_progress",
		"ValheimRadial", "SaveIcon", "BadConnectionIcon"
	};

	private static readonly SimpleDef[] VanillaSimple = new SimpleDef[14]
	{
		Direct(Def("HotKeyBar", "Hotbar", "Панель быстрого доступа", delegate(Hud h, RectTransform r)
		{
			Transform obj = ((Transform)r).Find("HotKeyBar");
			return (RectTransform)(object)((obj is RectTransform) ? obj : null);
		})),
		Def("GuardianPower", "Forsaken power", "Сила Отрёкшегося", (Hud h, RectTransform r) => h.m_gpRoot),
		Def("StatusEffects", "Status effects", "Эффекты", (Hud h, RectTransform r) => h.m_statusEffectListRoot),
		Def("Minimap", "Minimap", "Мини-карта", (Hud h, RectTransform r) => (!((Object)(object)Minimap.instance != (Object)null)) ? null : Rt(Minimap.instance.m_smallRoot)),
		Def("EventBar", "Raid bar", "Полоса рейда", (Hud h, RectTransform r) => Rt(h.m_eventBar)),
		Def("ActionProgress", "Action progress", "Прогресс действия", (Hud h, RectTransform r) => Rt(h.m_actionBarRoot)),
		Def("Stagger", "Stagger bar", "Полоса оглушения", (Hud h, RectTransform r) => Rt((Component)(object)h.m_staggerAnimator)),
		Def("Mount", "Mount panel", "Панель верхового", (Hud h, RectTransform r) => Rt(h.m_mountPanel)),
		Def("Ship", "Ship controls", "Управление кораблём", (Hud h, RectTransform r) => Rt(h.m_shipHudRoot)),
		Def("KeyHints", "Key hints", "Подсказки клавиш", delegate(Hud h, RectTransform r)
		{
			Transform obj = ((Transform)r).Find("KeyHints");
			return (RectTransform)(object)((obj is RectTransform) ? obj : null);
		}),
		Def("CenterMessage", "Centre message", "Сообщение по центру", (Hud h, RectTransform r) => (!((Object)(object)MessageHud.instance != (Object)null)) ? null : Rt((Component)(object)MessageHud.instance.m_messageCenterText)),
		Def("Messages", "Top left messages", "Сообщения слева сверху", (Hud h, RectTransform r) => (!((Object)(object)MessageHud.instance != (Object)null)) ? null : Rt((Component)(object)MessageHud.instance.m_messageText)),
		Def("SaveIcon", "Save icon", "Значок сохранения", (Hud h, RectTransform r) => Rt(h.m_saveIcon)),
		Def("BadConnection", "Bad connection icon", "Значок плохой связи", (Hud h, RectTransform r) => Rt(h.m_badConnectionIcon))
	};

	private Preset _pendingPreset;

	private PresetPart _pendingPart;

	private float _nextScan;

	private static readonly string[] BarStyleNames = new string[7] { "Vanilla", "Minimal", "Numeric", "Percent", "Faded", "Contrast", "Custom" };

	private static readonly string[] FoodStyleNames = new string[5] { "Vanilla", "IconsOnly", "LargeTimers", "Faded", "Custom" };

	private readonly Dictionary<ElementId, List<StyleDef>> _styles = new Dictionary<ElementId, List<StyleDef>>();

	internal bool Active
	{
		get
		{
			if (!_disabledByErrors && _cfgEnabled != null)
			{
				return _cfgEnabled.Value;
			}
			return false;
		}
	}

	internal bool Editing => _editing;

	private float WinH
	{
		get
		{
			if (!_collapsed)
			{
				return _winH;
			}
			return 26f;
		}
	}

	internal bool BlockMenu
	{
		get
		{
			if (!_editing)
			{
				return Time.frameCount == _escFrame;
			}
			return true;
		}
	}

	private Camera UiCamera
	{
		get
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_canvas == (Object)null)
			{
				return null;
			}
			Canvas rootCanvas = _canvas.rootCanvas;
			if (!((Object)(object)rootCanvas == (Object)null) && (int)rootCanvas.renderMode != 0)
			{
				return rootCanvas.worldCamera;
			}
			return null;
		}
	}

	private static string PresetDir => Path.Combine(Paths.ConfigPath, "j1ga.hudlayout.presets");

	private void RegisterCommands()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_003c: 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_0034: Expected O, but got Unknown
		new ConsoleCommand("hudlayout", "HudLayout: hudlayout edit | presets | apply <name> [all|layout|style] | save <name> | delete <name> | export [name] | import | reset | dump", (ConsoleEvent)delegate(ConsoleEventArgs args)
		{
			RunCommand(args);
		}, false, false, false, false, false, false, (ConsoleOptionsFetcher)(() => new List<string> { "edit", "presets", "apply", "save", "delete", "export", "import", "reset", "dump" }), false, false, false);
	}

	private static void Say(ConsoleEventArgs args, string text)
	{
		if (args != null && (Object)(object)args.Context != (Object)null)
		{
			args.Context.AddString(text);
		}
	}

	private static string Rest(string[] a, int from, int toExclusive)
	{
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = from; i < toExclusive && i < a.Length; i++)
		{
			if (stringBuilder.Length > 0)
			{
				stringBuilder.Append(' ');
			}
			stringBuilder.Append(a[i]);
		}
		return stringBuilder.ToString().Trim();
	}

	private void RunCommand(ConsoleEventArgs args)
	{
		try
		{
			string[] args2 = args.Args;
			switch ((args2.Length > 1) ? args2[1].ToLowerInvariant() : "")
			{
			case "edit":
			{
				string text2 = StartEditing();
				Say(args, text2 ?? L("Edit mode on. Close the console to use it.", "Редактор открыт. Закройте консоль, чтобы им пользоваться."));
				break;
			}
			case "presets":
			{
				StringBuilder stringBuilder = new StringBuilder(L("Presets:", "Пресеты:"));
				foreach (Preset item in AllPresets())
				{
					stringBuilder.Append("\n  ").Append(item.Name).Append(item.BuiltIn ? L("  (built-in)", "  (встроенный)") : "");
				}
				Say(args, stringBuilder.ToString());
				break;
			}
			case "apply":
			{
				PresetPart presetPart = PresetPart.All;
				int num = args2.Length;
				if (args2.Length > 3)
				{
					switch (args2[^1].ToLowerInvariant())
					{
					case "all":
						num--;
						break;
					case "layout":
						presetPart = PresetPart.Layout;
						num--;
						break;
					case "style":
						presetPart = PresetPart.Style;
						num--;
						break;
					}
				}
				string text7 = Rest(args2, 2, num);
				Preset preset4 = FindPreset(text7);
				if (preset4 == null)
				{
					Say(args, L("No preset '", "Нет пресета '") + text7 + "'. hudlayout presets");
					break;
				}
				ApplyPreset(preset4, presetPart);
				Say(args, L("Applied: ", "Применён: ") + preset4.Name + ((presetPart == PresetPart.All) ? "" : string.Concat(" (", presetPart, ")")));
				break;
			}
			case "save":
			{
				Preset preset2 = Capture(Rest(args2, 2, args2.Length));
				string text5 = SaveUserPreset(preset2);
				Say(args, text5 ?? (L("Saved: ", "Сохранён: ") + preset2.Name));
				break;
			}
			case "delete":
			{
				string text3 = Rest(args2, 2, args2.Length);
				string text4 = DeleteUserPreset(text3);
				Say(args, text4 ?? (L("Deleted: ", "Удалён: ") + text3));
				break;
			}
			case "export":
			{
				string text6 = Rest(args2, 2, args2.Length);
				Preset preset3 = ((text6.Length > 0) ? FindPreset(text6) : Capture("Shared layout"));
				if (preset3 == null)
				{
					Say(args, L("No preset '", "Нет пресета '") + text6 + "'");
					break;
				}
				GUIUtility.systemCopyBuffer = Export(preset3);
				Say(args, L("Copied to the clipboard.", "Скопировано в буфер обмена."));
				break;
			}
			case "import":
			{
				Preset preset = Import(GUIUtility.systemCopyBuffer);
				if (preset == null)
				{
					Say(args, L("The clipboard holds no preset.", "В буфере нет пресета."));
					break;
				}
				preset.Name = FreeName(preset.Name);
				string text = SaveUserPreset(preset);
				Say(args, text ?? (L("Imported as: ", "Импортирован как: ") + preset.Name + L(". Apply: hudlayout apply ", ". Применить: hudlayout apply ") + preset.Name));
				break;
			}
			case "reset":
				ApplyPreset(FindPreset("Vanilla"), PresetPart.All);
				Say(args, L("Back to the game's HUD.", "HUD как в игре."));
				break;
			case "dump":
				Say(args, DumpHud());
				break;
			default:
				Say(args, "hudlayout edit | presets | apply <name> [all|layout|style] | save <name> | delete <name> | export [name] | import | reset | dump");
				break;
			}
		}
		catch (Exception ex)
		{
			Say(args, "hudlayout: " + ex.Message);
			Fail("command", ex);
		}
	}

	internal IEnumerable<ElementSettings> AllSettings()
	{
		try
		{
			ElementSettings[] elements = Elements;
			foreach (ElementSettings s in elements)
			{
				if (s != null)
				{
					yield return s;
				}
			}
		}
		finally
		{
		}
		foreach (ElementSettings item in Extra)
		{
			yield return item;
		}
	}

	internal ElementSettings FindSettings(string key)
	{
		foreach (ElementSettings item in AllSettings())
		{
			if (string.Equals(item.Key, key, StringComparison.OrdinalIgnoreCase))
			{
				return item;
			}
		}
		return null;
	}

	internal static string L(string en, string ru)
	{
		string text = ((_cfgLanguage != null) ? _cfgLanguage.Value : "Auto");
		if (text == "Russian")
		{
			return ru;
		}
		if (text == "English")
		{
			return en;
		}
		try
		{
			Localization instance = Localization.instance;
			return (instance != null && instance.GetSelectedLanguage() == "Russian") ? ru : en;
		}
		catch
		{
			return en;
		}
	}

	private ConfigDescription D(string text)
	{
		return D(text, null, advanced: false);
	}

	private ConfigDescription D(string text, AcceptableValueBase values)
	{
		return D(text, values, advanced: false);
	}

	private ConfigDescription D(string text, AcceptableValueBase values, bool advanced)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes();
		configurationManagerAttributes.Order = _order--;
		if (advanced)
		{
			configurationManagerAttributes.IsAdvanced = true;
		}
		return new ConfigDescription(text, values, new object[1] { configurationManagerAttributes });
	}

	private static AcceptableValueRange<float> Range(float min, float max)
	{
		return new AcceptableValueRange<float>(min, max);
	}

	private void BindConfig()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		_order = 1000;
		_cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("00 General", "Enabled", true, D("Off = the HUD exactly as the game draws it. Your settings are kept."));
		_cfgEditKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("00 General", "EditModeKey", new KeyboardShortcut((KeyCode)288, (KeyCode[])(object)new KeyCode[0]), D("Opens the editor: drag the HUD elements with the mouse, resize them, pick styles and presets. Esc or the same key closes it."));
		_cfgLanguage = ((BaseUnityPlugin)this).Config.Bind<string>("00 General", "Language", "Auto", D("Language of the editor. Auto = as the game.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Auto", "English", "Russian" })));
		_cfgBuildShift = ((BaseUnityPlugin)this).Config.Bind<bool>("00 General", "FollowBuildShift", true, D("In build mode and at a ship's helm the game lifts the stamina, eitr and adrenaline bars out of the way. On = moved bars are lifted too.", null, advanced: true));
		_cfgEditorOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("00 General", "EditorOpacity", 0.95f, D("How opaque the editor window's background is.", (AcceptableValueBase)(object)Range(0.3f, 1f), advanced: true));
		BindModOptions("00 General");
		Elements[0] = BindElement(ElementId.Health, "01 Health", "Health", isBar: true, nativeVertical: true, BarAnchor.Start);
		Elements[1] = BindElement(ElementId.Stamina, "02 Stamina", "Stamina", isBar: true, nativeVertical: false, BarAnchor.Center);
		Elements[2] = BindElement(ElementId.Eitr, "03 Eitr", "Eitr", isBar: true, nativeVertical: false, BarAnchor.Center);
		Elements[3] = BindElement(ElementId.Adrenaline, "04 Adrenaline", "Adrenaline", isBar: true, nativeVertical: false, BarAnchor.Center);
		Elements[4] = BindElement(ElementId.Food, "05 Food", "Food", isBar: false, nativeVertical: true, BarAnchor.Center);
		ElementSettings[] elements = Elements;
		foreach (ElementSettings s in elements)
		{
			ParseColor(s);
		}
		BindVanillaSimple();
		DropRetiredOptions();
		((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged;
	}

	private ElementSettings BindElement(ElementId id, string section, string key, bool isBar, bool nativeVertical, BarAnchor anchor)
	{
		ElementSettings elementSettings = new ElementSettings();
		elementSettings.Id = id;
		elementSettings.Key = key;
		elementSettings.Section = section;
		elementSettings.IsBar = isBar;
		elementSettings.NativeVertical = nativeVertical;
		string text = (isBar ? ("the " + key.ToLowerInvariant() + " bar") : "the food icons");
		_order = 1000;
		string[] array = StyleNamesFor(isBar);
		elementSettings.Style = ((BaseUnityPlugin)this).Config.Bind<string>(section, "Style", "Vanilla", D("A ready-made look for " + text + ". Picking one fills in the options below; changing one of them makes it Custom.", (AcceptableValueBase)(object)new AcceptableValueList<string>(array)));
		elementSettings.PosX = ((BaseUnityPlugin)this).Config.Bind<float>(section, "PositionX", -1f, D("Where " + text + " is across the screen: 0 = left edge, 1 = right edge, -1 = where the game puts it. Easiest to set in the F7 editor.", (AcceptableValueBase)(object)Range(-1f, 1f)));
		elementSettings.PosY = ((BaseUnityPlugin)this).Config.Bind<float>(section, "PositionY", -1f, D("Where " + text + " is up the screen: 0 = bottom, 1 = top, -1 = where the game puts it. Easiest to set in the F7 editor.", (AcceptableValueBase)(object)Range(-1f, 1f)));
		elementSettings.Scale = ((BaseUnityPlugin)this).Config.Bind<float>(section, "Scale", 1f, D("Size of " + text + ". 1 = as in the game.", (AcceptableValueBase)(object)Range(0.25f, 4f)));
		elementSettings.Orient = ((BaseUnityPlugin)this).Config.Bind<Orientation>(section, "Orientation", Orientation.Default, D(isBar ? "Horizontal or vertical. Default = as in the game (health vertical, the others horizontal)." : "Vertical = a column (as in the game), Horizontal = a row."));
		elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.PosX);
		elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.PosY);
		elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.Scale);
		elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.Orient);
		if (isBar)
		{
			elementSettings.Length = ((BaseUnityPlugin)this).Config.Bind<float>(section, "Length", 1f, D("How long the bar is. 1 = as in the game.", (AcceptableValueBase)(object)Range(0.25f, 4f)));
			elementSettings.Thickness = ((BaseUnityPlugin)this).Config.Bind<float>(section, "Thickness", 1f, D("How thick the bar is. 1 = as in the game.", (AcceptableValueBase)(object)Range(0.25f, 4f)));
			elementSettings.FixedLength = ((BaseUnityPlugin)this).Config.Bind<bool>(section, "FixedLength", false, D("On = the bar keeps the same length as your maximum grows; only the number changes. Off = it grows, as in the game."));
			elementSettings.Anchor = ((BaseUnityPlugin)this).Config.Bind<BarAnchor>(section, "Anchor", anchor, D("Which end stays in place while the bar grows: Start (left / bottom), Center or End.", null, advanced: true));
			elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.Anchor);
			elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.Length);
			elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.Thickness);
			elementSettings.LayoutEntries.Add((ConfigEntryBase)(object)elementSettings.FixedLength);
			elementSettings.Vis = ((BaseUnityPlugin)this).Config.Bind<Visibility>(section, "Visibility", Visibility.Vanilla, D("When the bar shows. Vanilla = as in the game, Always = never fades out, Hidden = never, NotFull = only when it isn't full."));
		}
		else
		{
			elementSettings.Visible = ((BaseUnityPlugin)this).Config.Bind<bool>(section, "Visible", true, D("Show " + text + "."));
		}
		elementSettings.Opacity = ((BaseUnityPlugin)this).Config.Bind<float>(section, "Opacity", 1f, D("How opaque " + text + " is. 1 = solid.", (AcceptableValueBase)(object)Range(0.05f, 1f)));
		elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.Style);
		elementSettings.StyleEntries.Add((ConfigEntryBase)(isBar ? ((object)elementSettings.Vis) : ((object)elementSettings.Visible)));
		elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.Opacity);
		if (isBar)
		{
			elementSettings.Text = ((BaseUnityPlugin)this).Config.Bind<TextMode>(section, "Text", TextMode.Vanilla, D("The number on the bar: Vanilla (as in the game), Hidden, Current (75), CurrentMax (75/100) or Percent (75%)."));
			elementSettings.TextSize = ((BaseUnityPlugin)this).Config.Bind<float>(section, "TextSize", 1f, D("Size of the number. 1 = as in the game.", (AcceptableValueBase)(object)Range(0.5f, 3f)));
			elementSettings.TextPos = ((BaseUnityPlugin)this).Config.Bind<TextPosition>(section, "TextPosition", TextPosition.Vanilla, D("Where the number sits: Vanilla (as in the game), Center (middle of the bar) or Fill (middle of the filled part)."));
			elementSettings.Segments = ((BaseUnityPlugin)this).Config.Bind<bool>(section, "Segments", false, D("Divide the bar into cells, one per SegmentSize points of your maximum."));
			elementSettings.SegmentSize = ((BaseUnityPlugin)this).Config.Bind<float>(section, "SegmentSize", 10f, D("Points per cell.", (AcceptableValueBase)(object)Range(1f, 100f)));
			elementSettings.BarColor = ((BaseUnityPlugin)this).Config.Bind<string>(section, "BarColor", "", D("Colour of the bar, #RRGGBB. Empty = the game's colour."));
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.Text);
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.TextSize);
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.TextPos);
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.BarColor);
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.Segments);
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.SegmentSize);
		}
		else
		{
			elementSettings.Timers = ((BaseUnityPlugin)this).Config.Bind<bool>(section, "Timers", true, D("Show the time left on each food icon."));
			elementSettings.TextSize = ((BaseUnityPlugin)this).Config.Bind<float>(section, "TextSize", 1f, D("Size of the time left. 1 = as in the game.", (AcceptableValueBase)(object)Range(0.5f, 3f)));
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.Timers);
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.TextSize);
		}
		if (id == ElementId.Health || id == ElementId.Food)
		{
			elementSettings.Icon = ((BaseUnityPlugin)this).Config.Bind<bool>(section, "Icon", true, D((id == ElementId.Health) ? "Show the heart under the health bar." : "Show the food symbol next to the food icons."));
			elementSettings.StyleEntries.Add((ConfigEntryBase)(object)elementSettings.Icon);
		}
		if (elementSettings.Visible != null)
		{
			MigrateVisibility(elementSettings);
		}
		return elementSettings;
	}

	internal static bool IsHidden(ElementSettings s)
	{
		if (s.Vis != null)
		{
			return s.Vis.Value == Visibility.Hidden;
		}
		if (s.Visible != null)
		{
			return !s.Visible.Value;
		}
		return false;
	}

	private Dictionary<ConfigDefinition, string> Orphans()
	{
		try
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			return (propertyInfo != null) ? (propertyInfo.GetValue(((BaseUnityPlugin)this).Config, null) as Dictionary<ConfigDefinition, string>) : null;
		}
		catch
		{
			return null;
		}
	}

	private string TakeOrphan(string section, string key)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		Dictionary<ConfigDefinition, string> dictionary = Orphans();
		if (dictionary == null)
		{
			return null;
		}
		ConfigDefinition key2 = new ConfigDefinition(section, key);
		if (!dictionary.TryGetValue(key2, out var value))
		{
			return null;
		}
		dictionary.Remove(key2);
		_orphansDropped = true;
		return value;
	}

	private void MigrateVisibility(ElementSettings s)
	{
		string text = TakeOrphan(s.Section, "Visibility");
		if (text != null && text.Trim() == "Hidden")
		{
			s.Visible.Value = false;
		}
	}

	private void DropRetiredOptions()
	{
		TakeOrphan("00 General", "SnapToGrid");
		TakeOrphan("00 General", "GridStep");
		TakeOrphan("00 General", "LastPreset");
		if (_orphansDropped)
		{
			_orphansDropped = false;
			((BaseUnityPlugin)this).Config.Save();
		}
	}

	internal ElementSettings Get(ElementId id)
	{
		return Elements[(int)id];
	}

	private ElementSettings OwnerOf(ConfigEntryBase entry, out bool isStyleEntry)
	{
		isStyleEntry = false;
		foreach (ElementSettings item in AllSettings())
		{
			if (item.LayoutEntries.Contains(entry))
			{
				return item;
			}
			if (item.StyleEntries.Contains(entry))
			{
				isStyleEntry = true;
				return item;
			}
		}
		return null;
	}

	private void OnSettingChanged(object sender, SettingChangedEventArgs args)
	{
		try
		{
			ConfigEntryBase changedSetting = args.ChangedSetting;
			bool isStyleEntry;
			ElementSettings elementSettings = OwnerOf(changedSetting, out isStyleEntry);
			if (elementSettings == null)
			{
				return;
			}
			if ((object)changedSetting == elementSettings.BarColor)
			{
				ParseColor(elementSettings);
			}
			if (_applying <= 0 && isStyleEntry)
			{
				if ((object)changedSetting == elementSettings.Style)
				{
					ApplyStyle(elementSettings, elementSettings.Style.Value);
				}
				else
				{
					DetectStyle(elementSettings);
				}
			}
		}
		catch (Exception e)
		{
			Fail("SettingChanged", e);
		}
	}

	private static void ParseColor(ElementSettings s)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		s.HasColor = false;
		if (s.BarColor == null)
		{
			return;
		}
		string text = (s.BarColor.Value ?? "").Trim();
		if (text.Length != 0)
		{
			if (!text.StartsWith("#"))
			{
				text = "#" + text;
			}
			Color color = default(Color);
			if (ColorUtility.TryParseHtmlString(text, ref color))
			{
				s.HasColor = true;
				s.Color = color;
			}
		}
	}

	internal void Batch(Action body)
	{
		bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet;
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
		_applying++;
		try
		{
			body();
		}
		finally
		{
			_applying--;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet;
			if (saveOnConfigSet)
			{
				((BaseUnityPlugin)this).Config.Save();
			}
		}
	}

	internal static string Normalize(ConfigEntryBase entry, string text)
	{
		try
		{
			object obj = TomlTypeConverter.ConvertToValue(text, entry.SettingType);
			if (entry.Description != null && entry.Description.AcceptableValues != null)
			{
				obj = entry.Description.AcceptableValues.Clamp(obj);
			}
			return TomlTypeConverter.ConvertToString(obj, entry.SettingType);
		}
		catch
		{
			return null;
		}
	}

	internal static string DefaultText(ConfigEntryBase entry)
	{
		return TomlTypeConverter.ConvertToString(entry.DefaultValue, entry.SettingType);
	}

	internal static string F(float v)
	{
		return v.ToString("0.###", CultureInfo.InvariantCulture);
	}

	private void Awake()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		try
		{
			Instance = this;
			BindConfig();
			BuildStyles();
			BuildPresets();
			LoadUserPresets();
			RegisterCommands();
			_harmony = new Harmony("j1ga.hudlayout");
			_harmony.PatchAll(typeof(HudLayoutPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"HudLayout 1.0.1 loaded.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Failed to start: " + ex));
			_disabledByErrors = true;
		}
	}

	private void OnDestroy()
	{
		try
		{
			if (_editing)
			{
				StopEditing();
			}
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("OnDestroy: " + ex));
		}
	}

	private void Update()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		if (_disabledByErrors)
		{
			return;
		}
		try
		{
			if (ShortcutPressed(_cfgEditKey.Value) && !TypingSomewhere())
			{
				if (_editing)
				{
					StopEditing();
				}
				else
				{
					string text = StartEditing();
					if (text != null && (Object)(object)Player.m_localPlayer != (Object)null)
					{
						((Character)Player.m_localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false);
					}
				}
			}
			if (_editing && !CanEdit())
			{
				StopEditing();
			}
		}
		catch (Exception e)
		{
			Fail("Update", e);
		}
	}

	private static bool ShortcutPressed(KeyboardShortcut shortcut)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003c: Unknown result type (might be due to invalid IL or missing references)
		if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0)
		{
			return false;
		}
		IInputSystem current = UnityInput.Current;
		if (current == null || !current.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
		{
			return false;
		}
		foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
		{
			if (!current.GetKey(modifier))
			{
				return false;
			}
		}
		return true;
	}

	private static bool TypingSomewhere()
	{
		if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
		{
			return true;
		}
		if (Console.IsVisible())
		{
			return true;
		}
		if (TextInput.IsVisible())
		{
			return true;
		}
		return false;
	}

	internal void Fail(string where, Exception e)
	{
		string text = where + ": " + e.GetType().Name + ": " + e.Message;
		if (_loggedErrors.Add(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)(text + "\n" + e.StackTrace));
		}
		if (++_errorCount >= 25 && !_disabledByErrors)
		{
			_disabledByErrors = true;
			((BaseUnityPlugin)this).Logger.LogError((object)"Too many errors, HudLayout is now inert until the game restarts.");
			if (_editing)
			{
				StopEditing();
			}
		}
	}

	internal void Log(string text)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)text);
	}

	private bool CanEdit()
	{
		if (Active && (Object)(object)_root != (Object)null && _hudElements.Count > 0)
		{
			return (Object)(object)Player.m_localPlayer != (Object)null;
		}
		return false;
	}

	internal string StartEditing()
	{
		if (_editing)
		{
			return null;
		}
		if (!CanEdit())
		{
			if (Active)
			{
				return L("Enter a world first.", "Сначала зайдите в мир.");
			}
			return L("HudLayout is disabled (00 General / Enabled).", "HudLayout выключен (00 General / Enabled).");
		}
		if (Hud.IsUserHidden())
		{
			return L("The HUD is hidden (Ctrl+F3); show it first.", "HUD скрыт (Ctrl+F3); сначала покажите его.");
		}
		_editing = true;
		_drag = DragKind.None;
		_savedSaveOnSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet;
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
		Select(_sel ?? Get(ElementId.Health));
		return null;
	}

	internal void StopEditing()
	{
		if (!_editing)
		{
			return;
		}
		_editing = false;
		_drag = DragKind.None;
		_confirmDelete = null;
		GUIUtility.keyboardControl = 0;
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = _savedSaveOnSet;
		try
		{
			((BaseUnityPlugin)this).Config.Save();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not save the config: " + ex.Message));
		}
	}

	private void Say(string text)
	{
		_msg = text;
		_msgUntil = Time.unscaledTime + 6f;
	}

	private void Select(ElementSettings s)
	{
		_sel = s;
		_colorBuf = ((s.BarColor != null) ? s.BarColor.Value : "");
		GUIUtility.keyboardControl = 0;
	}

	internal static string ElementLabel(ElementSettings s)
	{
		if (s.Id == ElementId.Other)
		{
			if (!s.Key.StartsWith("Mod.", StringComparison.Ordinal) && !s.Key.StartsWith("Api.", StringComparison.Ordinal))
			{
				return L(s.LabelEn, s.LabelRu ?? s.LabelEn);
			}
			return L("Mod: ", "Мод: ") + L(s.LabelEn, s.LabelRu ?? s.LabelEn);
		}
		return ElementLabel(s.Id);
	}

	internal static string ElementLabel(ElementId id)
	{
		return id switch
		{
			ElementId.Health => L("Health", "Здоровье"), 
			ElementId.Stamina => L("Stamina", "Выносливость"), 
			ElementId.Eitr => L("Eitr", "Эйтр"), 
			ElementId.Adrenaline => L("Adrenaline", "Адреналин"), 
			_ => L("Food", "Еда"), 
		};
	}

	private Vector2 ToScreen(HudElement e, Vector2 wrapperPoint)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		return RectTransformUtility.WorldToScreenPoint(UiCamera, e.ToWorld(wrapperPoint));
	}

	private static Vector2 GuiToScreen(Vector2 g)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		return new Vector2(g.x, (float)Screen.height - g.y);
	}

	private static Vector2 ScreenToGui(Vector2 s)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		return new Vector2(s.x, (float)Screen.height - s.y);
	}

	private Rect GuiRect(HudElement e)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_002d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		Vector2 bMin = e.BMin;
		Vector2 bMax = e.BMax;
		Vector2 val = ScreenToGui(ToScreen(e, new Vector2(bMin.x, bMin.y)));
		Vector2 val2 = ScreenToGui(ToScreen(e, new Vector2(bMin.x, bMax.y)));
		Vector2 val3 = ScreenToGui(ToScreen(e, new Vector2(bMax.x, bMax.y)));
		Vector2 val4 = ScreenToGui(ToScreen(e, new Vector2(bMax.x, bMin.y)));
		Vector2 val5 = Vector2.Min(Vector2.Min(val, val2), Vector2.Min(val3, val4));
		Vector2 val6 = Vector2.Max(Vector2.Max(val, val2), Vector2.Max(val3, val4));
		Rect result = Rect.MinMaxRect(val5.x, val5.y, val6.x, val6.y);
		if (((Rect)(ref result)).width < 24f)
		{
			((Rect)(ref result)).x = ((Rect)(ref result)).x - (24f - ((Rect)(ref result)).width) * 0.5f;
			((Rect)(ref result)).width = 24f;
		}
		if (((Rect)(ref result)).height < 24f)
		{
			((Rect)(ref result)).y = ((Rect)(ref result)).y - (24f - ((Rect)(ref result)).height) * 0.5f;
			((Rect)(ref result)).height = 24f;
		}
		return result;
	}

	private Vector2 PivotScreen(HudElement e)
	{
		//IL_0003: 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)
		return ToScreen(e, e.Pivot);
	}

	private bool ScreenToPosition(HudElement e, Vector2 screen, out Vector2 pos)
	{
		//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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		pos = Vector2.zero;
		Vector2 val = default(Vector2);
		if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(_root, screen, UiCamera, ref val))
		{
			return false;
		}
		if (_cfgBuildShift.Value)
		{
			val -= e.Shift;
		}
		Rect rect = _root.rect;
		if (((Rect)(ref rect)).width <= 0f || ((Rect)(ref rect)).height <= 0f)
		{
			return false;
		}
		pos = new Vector2((val.x - ((Rect)(ref rect)).xMin) / ((Rect)(ref rect)).width, (val.y - ((Rect)(ref rect)).yMin) / ((Rect)(ref rect)).height);
		return true;
	}

	private static float AxisDistance(Vector2 a, Vector2 b, bool alongX)
	{
		return Mathf.Abs(alongX ? (a.x - b.x) : (a.y - b.y));
	}

	private HudElement HitTest(Vector2 gui)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		HudElement result = null;
		float num = float.MaxValue;
		foreach (HudElement hudElement in _hudElements)
		{
			Rect val = GuiRect(hudElement);
			if (((Rect)(ref val)).Contains(gui))
			{
				float num2 = ((Rect)(ref val)).width * ((Rect)(ref val)).height;
				if (num2 < num)
				{
					result = hudElement;
					num = num2;
				}
			}
		}
		return result;
	}

	private static Rect[] Handles(Rect r)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		return (Rect[])(object)new Rect[4]
		{
			new Rect(((Rect)(ref r)).xMin - 6f, ((Rect)(ref r)).yMin - 6f, 12f, 12f),
			new Rect(((Rect)(ref r)).xMax - 6f, ((Rect)(ref r)).yMin - 6f, 12f, 12f),
			new Rect(((Rect)(ref r)).xMax - 6f, ((Rect)(ref r)).yMax - 6f, 12f, 12f),
			new Rect(((Rect)(ref r)).xMin - 6f, ((Rect)(ref r)).yMax - 6f, 12f, 12f)
		};
	}

	private static Rect[] EdgeHandles(Rect r)
	{
		//IL_0002: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		float x = ((Rect)(ref r)).center.x;
		float y = ((Rect)(ref r)).center.y;
		return (Rect[])(object)new Rect[4]
		{
			new Rect(((Rect)(ref r)).xMin - 5f, y - 5f, 10f, 10f),
			new Rect(((Rect)(ref r)).xMax - 5f, y - 5f, 10f, 10f),
			new Rect(x - 5f, ((Rect)(ref r)).yMin - 5f, 10f, 10f),
			new Rect(x - 5f, ((Rect)(ref r)).yMax - 5f, 10f, 10f)
		};
	}

	private static bool VerticalOnScreen(ElementSettings s)
	{
		return s.NativeVertical != (AngleFor(s) != 0f);
	}

	private static ConfigEntry<float> EdgeTarget(ElementSettings s, int edge)
	{
		bool flag = edge < 2;
		if (flag == VerticalOnScreen(s))
		{
			return s.Thickness;
		}
		return s.Length;
	}

	private void SetPosition(ElementSettings s, Vector2 p, bool snap)
	{
		if (snap)
		{
			float num = 0.005f;
			p.x = Mathf.Round(p.x / num) * num;
			p.y = Mathf.Round(p.y / num) * num;
			if (Mathf.Abs(p.x - 0.5f) < num * 2f)
			{
				p.x = 0.5f;
			}
		}
		p.x = Mathf.Clamp01(p.x);
		p.y = Mathf.Clamp01(p.y);
		float num2 = (float)Math.Round(p.x, 4);
		float num3 = (float)Math.Round(p.y, 4);
		if (s.PosX.Value != num2)
		{
			s.PosX.Value = num2;
		}
		if (s.PosY.Value != num3)
		{
			s.PosY.Value = num3;
		}
	}

	private static float Snapped(float v, float min, float max, bool snap)
	{
		v = Mathf.Clamp(v, min, max);
		if (!snap)
		{
			return (float)Math.Round(v, 2);
		}
		return Mathf.Round(v * 20f) / 20f;
	}

	private void ResetPosition(ElementSettings s)
	{
		Batch(delegate
		{
			s.PosX.Value = -1f;
			s.PosY.Value = -1f;
		});
	}

	private void ResetLayout(ElementSettings s)
	{
		Batch(delegate
		{
			foreach (ConfigEntryBase layoutEntry in s.LayoutEntries)
			{
				layoutEntry.BoxedValue = layoutEntry.DefaultValue;
			}
		});
	}

	private bool CurrentPosition(HudElement e, out Vector2 pos)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		ElementSettings settings = e.Settings;
		if (settings.HasPosition)
		{
			pos = new Vector2(settings.PosX.Value, settings.PosY.Value);
			return true;
		}
		return ScreenToPosition(e, PivotScreen(e), out pos);
	}

	private void Nudge(HudElement e, Vector2 dir, bool big)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		if (CurrentPosition(e, out var pos))
		{
			float num = 0.005f * (big ? 10f : 1f);
			SetPosition(e.Settings, pos + dir * num, snap: false);
		}
	}

	private void OnGUI()
	{
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Expected O, but got Unknown
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Expected O, but got Unknown
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		if (!_editing)
		{
			return;
		}
		try
		{
			if (CanEdit())
			{
				EnsureGuiStyles();
				float num = UiScale();
				float num2 = (float)Screen.width / num;
				float num3 = (float)Screen.height / num;
				_winW = Mathf.Clamp(_winW, 360f, num2 - 20f);
				_winH = Mathf.Clamp(_winH, 300f, num3 - 20f);
				if (!_winPlaced)
				{
					_winH = Mathf.Min(760f, num3 * 0.75f);
					_win = new Rect(num2 - _winW - 20f, num3 * 0.15f, _winW, _winH);
					_winPlaced = true;
				}
				DrawOverlay();
				HandleInput(Event.current);
				Matrix4x4 matrix = GUI.matrix;
				GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(num, num, 1f));
				string text = L("HudLayout — edit mode", "HudLayout — редактор HUD");
				if (_collapsed)
				{
					_win = GUI.Window(303575, new Rect(((Rect)(ref _win)).x, ((Rect)(ref _win)).y, _winW, 26f), new WindowFunction(DrawWindow), text, WindowStyle());
				}
				else
				{
					_win = GUILayout.Window(303575, new Rect(((Rect)(ref _win)).x, ((Rect)(ref _win)).y, _winW, WinH), new WindowFunction(DrawWindow), text, WindowStyle(), (GUILayoutOption[])(object)new GUILayoutOption[2]
					{
						GUILayout.Width(_winW),
						GUILayout.Height(WinH)
					});
				}
				((Rect)(ref _win)).width = _winW;
				((Rect)(ref _win)).height = WinH;
				((Rect)(ref _win)).x = Mathf.Clamp(((Rect)(ref _win)).x, 0f, num2 - _winW);
				((Rect)(ref _win)).y = Mathf.Clamp(((Rect)(ref _win)).y, 0f, num3 - WinH);
				GUI.matrix = matrix;
			}
		}
		catch (Exception e)
		{
			Fail("editor", e);
		}
	}

	private static float UiScale()
	{
		return Mathf.Clamp((float)Screen.height / 1080f, 1f, 2f);
	}

	private Rect WindowOnScreen()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		float num = UiScale();
		return new Rect(((Rect)(ref _win)).x * num, ((Rect)(ref _win)).y * num, _winW * num, WinH * num);
	}

	private Rect ResizeGrip()
	{
		//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_0027: Unknown result type (might be due to invalid IL or missing references)
		Rect val = WindowOnScreen();
		float num = 20f * UiScale();
		return new Rect(((Rect)(ref val)).xMax - num, ((Rect)(ref val)).yMax - num, num, num);
	}

	private void EnsureGuiStyles()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0035: 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_0050: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Expected O, but got Unknown
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Expected O, but got Unknown
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Expected O, but got Unknown
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Expected O, but got Unknown
		if (_labelStyle == null)
		{
			_labelStyle = new GUIStyle(GUI.skin.label);
			_labelStyle.fontStyle = (FontStyle)1;
			_labelStyle.normal.textColor = Color.white;
			_shadowStyle = new GUIStyle(_labelStyle);
			_shadowStyle.normal.textColor = new Color(0f, 0f, 0f, 0.8f);
			_headerStyle = new GUIStyle(GUI.skin.label);
			_headerStyle.fontStyle = (FontStyle)1;
			_headerStyle.normal.textColor = new Color(1f, 0.85f, 0.45f);
			_hintStyle = new GUIStyle(GUI.skin.label);
			_hintStyle.wordWrap = true;
			_hintStyle.fontSize = Mathf.Max(10, GUI.skin.label.fontSize - 1);
			_hintStyle.normal.textColor = new Color(0.85f, 0.85f, 0.85f);
			_smallButton = new GUIStyle(GUI.skin.button);
			_smallButton.padding = new RectOffset(4, 4, 2, 2);
			_smallButton.wordWrap = true;
			_gridStyle = new GUIStyle(GUI.skin.button);
			_gridStyle.wordWrap = true;
			_wrapLabel = new GUIStyle(GUI.skin.label);
			_wrapLabel.wordWrap = true;
			_wrapToggle = new GUIStyle(GUI.skin.toggle);
			_wrapToggle.wordWrap = true;
		}
	}

	private GUIStyle WindowStyle()
	{
		//IL_0079: 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_0054: Expected O, but got Unknown
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		//IL_00bd: 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)
		float value = _cfgEditorOpacity.Value;
		if (_windowStyle != null && (Object)(object)_windowBg != (Object)null && Mathf.Approximately(value, _windowBgAlpha))
		{
			return _windowStyle;
		}
		if ((Object)(object)_windowBg == (Object)null)
		{
			_windowBg = new Texture2D(1, 1, (TextureFormat)4, false);
			((Object)_windowBg).hideFlags = (HideFlags)61;
		}
		_windowBg.SetPixel(0, 0, new Color(0.08f, 0.07f, 0.06f, value));
		_windowBg.Apply();
		_windowBgAlpha = value;
		if (_windowStyle == null)
		{
			_windowStyle = new GUIStyle(GUI.skin.window);
			_windowStyle.normal.textColor = Color.white;
			_windowStyle.onNormal.textColor = _windowStyle.normal.textColor;
			_windowStyle.fontStyle = (FontStyle)1;
		}
		_windowStyle.normal.background = _windowBg;
		_windowStyle.onNormal.background = _windowBg;
		_windowStyle.focused.background = _windowBg;
		_windowStyle.onFocused.background = _windowBg;
		_windowStyle.hover.background = _windowBg;
		_windowStyle.onHover.background = _windowBg;
		_windowStyle.active.background = _windowBg;
		_windowStyle.onActive.background = _windowBg;
		_windowStyle.border = new RectOffset(0, 0, 0, 0);
		return _windowStyle;
	}

	private static void Fill(Rect r, Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		Color color = GUI.color;
		GUI.color = c;
		GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color;
	}

	private static void Outline(Rect r, Color c, float w)
	{
		//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_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		Fill(new Rect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin, ((Rect)(ref r)).width, w), c);
		Fill(new Rect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMax - w, ((Rect)(ref r)).width, w), c);
		Fill(new Rect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin, w, ((Rect)(ref r)).height), c);
		Fill(new Rect(((Rect)(ref r)).xMax - w, ((Rect)(ref r)).yMin, w, ((Rect)(ref r)).height), c);
	}

	private void Shadowed(Rect r, string text)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		GUI.Label(new Rect(((Rect)(ref r)).x + 1f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, _shadowStyle);
		GUI.Label(r, text, _labelStyle);
	}

	private void DrawOverlay()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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_007d: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		if ((int)Event.current.type != 7)
		{
			return;
		}
		Color val = default(Color);
		((Color)(ref val))..ctor(1f, 0.78f, 0.2f, 1f);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(1f, 1f, 1f, 0.6f);
		foreach (HudElement hudElement in _hudElements)
		{
			bool flag = hudElement.Settings == _sel;
			Rect r = GuiRect(hudElement);
			Color c = (flag ? val : val2);
			Fill(r, new Color(c.r, c.g, c.b, flag ? 0.14f : 0.06f));
			Outline(r, c, flag ? 2f : 1f);
			string text = ElementLabel(hudElement.Settings);
			if (IsHidden(hudElement.Settings))
			{
				text += L(" (hidden)", " (скрыт)");
			}
			Shadowed(new Rect(((Rect)(ref r)).xMin, ((Rect)(ref r)).yMin - 22f, 260f, 22f), text);
			if (!flag)
			{
				continue;
			}
			Rect[] array = Handles(r);
			foreach (Rect r2 in array)
			{
				Fill(r2, val);
				Outline(r2, Color.black, 1f);
			}
			if (hudElement.Settings.IsBar)
			{
				Rect[] array2 = EdgeHandles(r);
				foreach (Rect r3 in array2)
				{
					Fill(r3, new Color(0.3f, 0.9f, 1f, 1f));
					Outline(r3, Color.black, 1f);
				}
			}
			Vector2 val3 = ScreenToGui(PivotScreen(hudElement));
			Fill(new Rect(val3.x - 5f, val3.y - 1f, 10f, 2f), Color.black);
			Fill(new Rect(val3.x - 1f, val3.y - 5f, 2f, 10f), Color.black);
		}
		if (_drag == DragKind.Move)
		{
			ElementSettings sel = _sel;
			if (sel != null && sel.HasPosition && Mathf.Abs(sel.PosX.Value - 0.5f) < 0.0001f)
			{
				Fill(new Rect((float)Screen.width * 0.5f - 0.5f, 0f, 1f, (float)Screen.height), new Color(0.3f, 0.9f, 1f, 0.6f));
			}
		}
	}

	private void HandleInput(Event ev)
	{
		//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_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_001e: 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_0043: Expected I4, but got Unknown
		//IL_04de: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e5: Invalid comparison between Unknown and I4
		//IL_042b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_0508: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Invalid comparison between Unknown and I4
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_053d: Invalid comparison between Unknown and I4
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0394: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b3: Invalid comparison between Unknown and I4
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c9: Invalid comparison between Unknown and I4
		//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: 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_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05df: Invalid comparison between Unknown and I4
		//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0600: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f5: Invalid comparison between Unknown and I4
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0610: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		Vector2 mousePosition = ev.mousePosition;
		Rect val = WindowOnScreen();
		bool flag = ((Rect)(ref val)).Contains(mousePosition);
		EventType type = ev.type;
		switch ((int)type)
		{
		case 0:
			if (ev.button == 0 && !_collapsed)
			{
				Rect val4 = ResizeGrip();
				if (((Rect)(ref val4)).Contains(mousePosition))
				{
					_drag = DragKind.ResizeWindow;
					ev.Use();
					break;
				}
			}
			if (flag)
			{
				break;
			}
			if (ev.button == 0)
			{
				HudElement hudElement4 = HudElementOf(_sel);
				if (hudElement4 != null && hudElement4.Settings.IsBar)
				{
					Rect[] array = EdgeHandles(GuiRect(hudElement4));
					for (int i = 0; i < array.Length; i++)
					{
						if (((Rect)(ref array[i])).Contains(mousePosition))
						{
							_drag = DragKind.Edge;
							_edgeTarget = EdgeTarget(hudElement4.Settings, i);
							_edgeAlongX = i < 2;
							_dragStartScale = _edgeTarget.Value;
							_dragStartDist = Mathf.Max(4f, AxisDistance(GuiToScreen(mousePosition), PivotScreen(hudElement4), _edgeAlongX));
							ev.Use();
							return;
						}
					}
				}
				if (hudElement4 != null)
				{
					Rect[] array2 = Handles(GuiRect(hudElement4));
					for (int j = 0; j < array2.Length; j++)
					{
						Rect val5 = array2[j];
						if (((Rect)(ref val5)).Contains(mousePosition))
						{
							_drag = DragKind.Scale;
							_dragStartScale = hudElement4.Settings.Scale.Value;
							_dragStartDist = Mathf.Max(4f, Vector2.Distance(GuiToScreen(mousePosition), PivotScreen(hudElement4)));
							ev.Use();
							return;
						}
					}
				}
				HudElement hudElement3 = HitTest(mousePosition);
				if (hudElement3 != null)
				{
					Select(hudElement3.Settings);
					_drag = DragKind.Move;
					_grab = PivotScreen(hudElement3) - GuiToScreen(mousePosition);
					ev.Use();
				}
				else
				{
					GUIUtility.keyboardControl = 0;
				}
			}
			else
			{
				if (ev.button != 1)
				{
					break;
				}
				HudElement hudElement3 = HitTest(mousePosition);
				if (hudElement3 != null)
				{
					Select(hudElement3.Settings);
					if (ev.shift)
					{
						ResetLayout(hudElement3.Settings);
					}
					else
					{
						ResetPosition(hudElement3.Settings);
					}
					ev.Use();
				}
			}
			break;
		case 3:
		{
			if (_drag == DragKind.None)
			{
				break;
			}
			if (_drag == DragKind.ResizeWindow)
			{
				float num2 = UiScale();
				_winW += ev.delta.x / num2;
				_winH += ev.delta.y / num2;
				ev.Use();
				break;
			}
			HudElement hudElement2 = HudElementOf(_sel);
			if (hudElement2 == null)
			{
				_drag = DragKind.None;
				break;
			}
			if (_drag == DragKind.Move)
			{
				if (ScreenToPosition(hudElement2, GuiToScreen(mousePosition) + _grab, out var pos))
				{
					SetPosition(hudElement2.Settings, pos, _snap && !ev.control);
				}
			}
			else if (_drag == DragKind.Edge)
			{
				float num3 = AxisDistance(GuiToScreen(mousePosition), PivotScreen(hudElement2), _edgeAlongX);
				float num4 = Snapped(_dragStartScale * num3 / _dragStartDist, 0.25f, 4f, _snap && !ev.control);
				if (_edgeTarget.Value != num4)
				{
					_edgeTarget.Value = num4;
				}
			}
			else
			{
				float num5 = Vector2.Distance(GuiToScreen(mousePosition), PivotScreen(hudElement2));
				float num6 = Snapped(_dragStartScale * num5 / _dragStartDist, 0.25f, 4f, _snap && !ev.control);
				if (hudElement2.Settings.Scale.Value != num6)
				{
					hudElement2.Settings.Scale.Value = num6;
				}
			}
			ev.Use();
			break;
		}
		case 1:
			if (_drag != DragKind.None)
			{
				_drag = DragKind.None;
				ev.Use();
			}
			break;
		case 6:
		{
			if (flag)
			{
				break;
			}
			HudElement hudElement3 = HitTest(mousePosition);
			if (hudElement3 != null)
			{
				Select(hudElement3.Settings);
				float num7 = ((ev.delta.y > 0f) ? (-0.05f) : 0.05f);
				ConfigEntry<float> val3 = hudElement3.Settings.Scale;
				if (ev.control && hudElement3.Settings.Length != null)
				{
					val3 = hudElement3.Settings.Length;
				}
				else if (ev.shift && hudElement3.Settings.Thickness != null)
				{
					val3 = hudElement3.Settings.Thickness;
				}
				val3.Value = Snapped(val3.Value + num7, 0.25f, 4f, snap: false);
				ev.Use();
			}
			break;
		}
		case 4:
			if ((int)ev.keyCode == 27)
			{
				_escFrame = Time.frameCount;
				StopEditing();
				ev.Use();
			}
			else
			{
				if (GUIUtility.keyboardControl != 0)
				{
					break;
				}
				if ((int)ev.keyCode == 104)
				{
					_collapsed = !_collapsed;
					ev.Use();
					break;
				}
				HudElement hudElement = HudElementOf(_sel);
				if ((int)ev.keyCode == 9)
				{
					int count = _hudElements.Count;
					if (count != 0)
					{
						int num = ((hudElement != null) ? _hudElements.IndexOf(hudElement) : (-1));
						Select(_hudElements[((num + ((!ev.shift) ? 1 : (-1))) % count + count) % count].Settings);
						ev.Use();
					}
				}
				else if (hudElement != null)
				{
					Vector2 val2 = Vector2.zero;
					if ((int)ev.keyCode == 276)
					{
						val2 = Vector2.left;
					}
					else if ((int)ev.keyCode == 275)
					{
						val2 = Vector2.right;
					}
					else if ((int)ev.keyCode == 273)
					{
						val2 = Vector2.up;
					}
					else if ((int)ev.keyCode == 274)
					{
						val2 = Vector2.down;
					}
					if (!(val2 == Vector2.zero))
					{
						Nudge(hudElement, val2, ev.shift);
						ev.Use();
					}
				}
			}
			break;
		case 2:
		case 5:
			break;
		}
	}

	private void DrawWindow(int id)
	{
		//IL_001b: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		if (GUI.Button(new Rect(_winW - 30f, 3f, 26f, 18f), _collapsed ? "+" : "–", _smallButton))
		{
			_collapsed = !_collapsed;
			GUIUtility.keyboardControl = 0;
		}
		if (_collapsed)
		{
			GUI.DragWindow(new Rect(0f, 0f, _winW - 34f, 26f));
			return;
		}
		_scroll = GUILayout.BeginScrollView(_scroll, false, true, GUIStyle.none, GUI.skin.verticalScrollbar, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(_winW - 46f) });
		GUILayout.Label(L(string.Concat("Drag an element to move it, a yellow corner to resize it, a blue side to change length or thickness. Wheel: size, Ctrl+wheel: length, Shift+wheel: thickness. Right click: back to the game's place (Shift: whole layout). Arrows: nudge (Shift ×10), Tab: next element. Ctrl while dragging: no snapping. The corner of this window resizes it, – or H folds it. Esc or ", _cfgEditKey.Value, ": done."), string.Concat("Тащите элемент, чтобы передвинуть; жёлтый уголок — размер; синяя середина стороны — длина или толщина. Колесо: размер, Ctrl+колесо: длина, Shift+колесо: толщина. ПКМ: вернуть на место игры (Shift — всю раскладку). Стрелки: сдвиг (Shift ×10), Tab: следующий элемент. Ctrl при перетаскивании: без привязки. Уголок этого окна меняет его размер, – или H сворачивает его. Esc или ", _cfgEditKey.Value, ": готово.")), _hintStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		ElementGroup(L("Bars and food", "Полосы и еда"), 0);
		ElementGroup(L("Rest of the HUD", "Остальной HUD"), 1);
		ElementGroup(L("Other mods", "Другие моды"), 2);
		ElementSettings s = _sel ?? Get(ElementId.Health);
		DrawLayoutSection(s);
		DrawStyleSection(s);
		DrawPresetSection();
		DrawSettingsSection();
		if (_msg.Length > 0 && Time.unscaledTime < _msgUntil)
		{
			GUILayout.Space(4f);
			GUILayout.Label(_msg, _headerStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		}
		GUILayout.Space(6f);
		if (GUILayout.Button(L("Done", "Готово"), (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			StopEditing();
		}
		GUILayout.EndVertical();
		GUILayout.EndScrollView();
		GUI.Label(new Rect(_winW - 18f, _winH - 20f, 18f, 18f), "◢", _hintStyle);
		GUI.DragWindow(new Rect(0f, 0f, _winW - 34f, 22f));
	}

	private static int GroupOf(ElementSettings s)
	{
		if (!s.IsSimple)
		{
			return 0;
		}
		if (!s.Key.StartsWith("Mod.", StringComparison.Ordinal) && !s.Key.StartsWith("Api.", StringComparison.Ordinal))
		{
			return 1;
		}
		return 2;
	}

	private void ElementGroup(string title, int group)
	{
		List<HudElement> list = new List<HudElement>();
		foreach (HudElement hudElement in _hudElements)
		{
			if (GroupOf(hudElement.Settings) == group)
			{
				list.Add(hudElement);
			}
		}
		if (list.Count == 0)
		{
			return;
		}
		GUILayout.Label(title, _hintStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		string[] array = new string[list.Count];
		int num = -1;
		for (int i = 0; i < list.Count; i++)
		{
			array[i] = ((group == 2) ? L(list[i].Settings.LabelEn, list[i].Settings.LabelRu) : ElementLabel(list[i].Settings));
			if (list[i].Settings == _sel)
			{
				num = i;
			}
		}
		int num2 = GUILayout.SelectionGrid(num, array, (group == 2) ? 2 : 3, _gridStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (num2 != num && num2 >= 0)
		{
			Select(list[num2].Settings);
		}
	}

	private void Header(string text)
	{
		GUILayout.Space(8f);
		GUILayout.Label(text, _headerStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
	}

	private void Slider(string label, ConfigEntry<float> e, float min, float max)
	{
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
		float num = GUILayout.HorizontalSlider(e.Value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(e.Value.ToString("0.00", CultureInfo.InvariantCulture), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
		GUILayout.EndHorizontal();
		if (Mathf.Abs(num - e.Value) > 0.0001f)
		{
			e.Value = (float)Math.Round(num, 2);
		}
	}

	private void Choice<T>(string label, ConfigEntry<T> e, T[] values, string[] labels, int columns)
	{
		GUILayout.Label(label, _wrapLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		int num = Array.IndexOf(values, e.Value);
		int num2 = GUILayout.SelectionGrid(num, labels, columns, _gridStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (num2 != num && num2 >= 0 && num2 < values.Length)
		{
			e.Value = values[num2];
		}
	}

	private void DrawLayoutSection(ElementSettings s)
	{
		Header(L("Position and size", "Положение и размер"));
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(s.HasPosition ? ("X " + F(s.PosX.Value) + "   Y " + F(s.PosY.Value)) : L("Where the game puts it", "Там, где его ставит игра"), _wrapLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (s.HasPosition && GUILayout.Button(L("Game's place", "Место игры"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
		{
			ResetPosition(s);
		}
		GUILayout.EndHorizontal();
		Slider(L("Scale", "Размер"), s.Scale, 0.25f, 4f);
		if (s.Length != null)
		{
			Slider(L("Length", "Длина"), s.Length, 0.25f, 4f);
		}
		if (s.Thickness != null)
		{
			Slider(L("Thickness", "Толщина"), s.Thickness, 0.25f, 4f);
		}
		if (s.FixedLength != null)
		{
			bool flag = GUILayout.Toggle(s.FixedLength.Value, L(" Fixed length: the bar does not grow with the maximum, only the number does", " Фиксированная длина: полоса не растёт с максимумом, растёт только число"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (flag != s.FixedLength.Value)
			{
				s.FixedLength.Value = flag;
			}
		}
		if (s.Orient != null)
		{
			Choice(L("Orientation", "Ориентация"), s.Orient, new Orientation[3]
			{
				Orientation.Default,
				Orientation.Horizontal,
				Orientation.Vertical
			}, s.IsBar ? new string[3]
			{
				L("As in game", "Как в игре"),
				L("Horizontal", "Горизонтально"),
				L("Vertical", "Вертикально")
			} : new string[3]
			{
				L("As in game", "Как в игре"),
				L("Row", "Строкой"),
				L("Column", "Столбцом")
			}, 3);
		}
		if (s.Anchor != null)
		{
			Choice(L("Stays in place while growing", "При росте на месте остаётся"), s.Anchor, new BarAnchor[3]
			{
				BarAnchor.Start,
				BarAnchor.Center,
				BarAnchor.End
			}, new string[3]
			{
				L("Start", "Начало"),
				L("Middle", "Середина"),
				L("End", "Конец")
			}, 3);
		}
		if (GUILayout.Button(L("Reset position and size", "Сбросить положение и размер"), (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			ResetLayout(s);
		}
	}

	private void DrawStyleSection(ElementSettings s)
	{
		//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0618: Unknown result type (might be due to invalid IL or missing references)
		Header(L("Look", "Внешний вид"));
		if (s.Style != null)
		{
			List<StyleDef> list = StylesOf(s);
			string[] array = new string[list.Count];
			int num = -1;
			for (int i = 0; i < list.Count; i++)
			{
				array[i] = L(list[i].Name, list[i].NameRu);
				if (list[i].Name == s.Style.Value)
				{
					num = i;
				}
			}
			GUILayout.Label(L("Style: ", "Стиль: ") + StyleLabel(s, s.Style.Value), (GUILayoutOption[])(object)new GUILayoutOption[0]);
			int num2 = GUILayout.SelectionGrid(num, array, 3, _gridStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (num2 != num && num2 >= 0)
			{
				ApplyStyle(s, list[num2].Name);
			}
		}
		if (s.Vis != null)
		{
			Choice(L("Visibility", "Видимость"), s.Vis, new Visibility[4]
			{
				Visibility.Vanilla,
				Visibility.Always,
				Visibility.Hidden,
				Visibility.NotFull
			}, new string[4]
			{
				L("As in game", "Как в игре"),
				L("Always", "Всегда"),
				L("Hidden", "Скрыта"),
				L("When not full", "Когда не полная")
			}, 2);
		}
		else if (s.Visible != null)
		{
			bool flag = GUILayout.Toggle(s.Visible.Value, L(" Shown", " Показывать"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (flag != s.Visible.Value)
			{
				s.Visible.Value = flag;
			}
		}
		Slider(L("Opacity", "Непрозрачность"), s.Opacity, 0.05f, 1f);
		if (s.Icon != null)
		{
			bool flag2 = GUILayout.Toggle(s.Icon.Value, (s.Id == ElementId.Health) ? L(" Heart icon", " Значок сердца") : L(" Food symbol under the icons", " Символ еды под значками"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (flag2 != s.Icon.Value)
			{
				s.Icon.Value = flag2;
			}
		}
		if (s.IsBar)
		{
			Choice(L("Number on the bar", "Число на полосе"), s.Text, new TextMode[5]
			{
				TextMode.Vanilla,
				TextMode.Hidden,
				TextMode.Current,
				TextMode.CurrentMax,
				TextMode.Percent
			}, new string[5]
			{
				L("As in game", "Как в игре"),
				L("None", "Нет"),
				"75",
				"75/100",
				"75%"
			}, 3);
			Slider(L("Number size", "Размер числа"), s.TextSize, 0.5f, 3f);
			bool flag3 = GUILayout.Toggle(s.Segments.Value, L(" Cells: one cell per N points of the maximum", " Ячейки: одна ячейка на N единиц максимума"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (flag3 != s.Segments.Value)
			{
				s.Segments.Value = flag3;
			}
			if (s.Segments.Value)
			{
				GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
				GUILayout.Label(L("Points per cell", "Единиц в ячейке"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
				float num3 = GUILayout.HorizontalSlider(s.SegmentSize.Value, 1f, 50f, (GUILayoutOption[])(object)new GUILayoutOption[0]);
				GUILayout.Label(Mathf.RoundToInt(s.SegmentSize.Value).ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
				GUILayout.EndHorizontal();
				num3 = Mathf.Round(num3);
				if (num3 != s.SegmentSize.Value)
				{
					s.SegmentSize.Value = num3;
				}
			}
			Choice(L("Number position", "Положение числа"), s.TextPos, new TextPosition[3]
			{
				TextPosition.Vanilla,
				TextPosition.Center,
				TextPosition.Fill
			}, new string[3]
			{
				L("As in game", "Как в игре"),
				L("Middle of the bar", "Середина полосы"),
				L("Middle of the fill", "Середина заполнения")
			}, 3);
			GUILayout.Label(L("Bar colour", "Цвет полосы"), _wrapLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			string[] swatches = Swatches;
			Color backgroundColor2 = default(Color);
			foreach (string text in swatches)
			{
				bool flag4 = text.Length == 0;
				Color backgroundColor = GUI.backgroundColor;
				if (!flag4 && ColorUtility.TryParseHtmlString(text, ref backgroundColor2))
				{
					GUI.backgroundColor = backgroundColor2;
				}
				bool flag5 = GUILayout.Button(flag4 ? L("Game", "Игра") : " ", _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(flag4 ? 44f : 26f) });
				GUI.backgroundColor = backgroundColor;
				if (flag5)
				{
					s.BarColor.Value = text;
					_colorBuf = text;
				}
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			_colorBuf = GUILayout.TextField(_colorBuf ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
			if (GUILayout.Button(L("Apply #RRGGBB", "Применить #RRGGBB"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				string text2 = (_colorBuf ?? "").Trim();
				Color val = default(Color);
				if (text2.Length == 0 || ColorUtility.TryParseHtmlString(text2.StartsWith("#") ? text2 : ("#" + text2), ref val))
				{
					s.BarColor.Value = ((text2.Length == 0 || text2.StartsWith("#")) ? text2 : ("#" + text2));
					GUIUtility.keyboardControl = 0;
				}
				else
				{
					Say(L("Not a colour: ", "Это не цвет: ") + text2);
				}
			}
			GUILayout.EndHorizontal();
		}
		else if (s.Timers != null)
		{
			bool flag6 = GUILayout.Toggle(s.Timers.Value, L(" Time left on the icons", " Оставшееся время на значках"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
			if (flag6 != s.Timers.Value)
			{
				s.Timers.Value = flag6;
			}
			Slider(L("Time size", "Размер времени"), s.TextSize, 0.5f, 3f);
		}
		if (!GUILayout.Button(L("Reset look", "Сбросить внешний вид"), (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			return;
		}
		if (s.Style != null)
		{
			ApplyStyle(s, "Vanilla");
			return;
		}
		Batch(delegate
		{
			foreach (ConfigEntryBase styleEntry in s.StyleEntries)
			{
				styleEntry.BoxedValue = styleEntry.DefaultValue;
			}
		});
	}

	private void DrawPresetSection()
	{
		Header(L("Presets (all elements)", "Пресеты (все элементы)"));
		GUILayout.Label(L("Apply: all / only positions and sizes / only looks.", "Применить: всё / только положение и размер / только внешний вид."), _hintStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		Preset preset = null;
		foreach (Preset item in AllPresets())
		{
			GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
			GUILayout.Label(PresetLabel(item) + (item.BuiltIn ? "" : L("  (mine)", "  (мой)")), _wrapLabel, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(Mathf.Max(110f, _winW - 300f)) });
			if (GUILayout.Button(L("All", "Всё"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				ApplyPreset(item, PresetPart.All);
				Say(L("Applied: ", "Применён: ") + PresetLabel(item));
			}
			if (GUILayout.Button(L("Layout", "Место"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				ApplyPreset(item, PresetPart.Layout);
				Say(L("Layout applied: ", "Расположение применено: ") + PresetLabel(item));
			}
			if (GUILayout.Button(L("Look", "Вид"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
			{
				ApplyPreset(item, PresetPart.Style);
				Say(L("Look applied: ", "Вид применён: ") + PresetLabel(item));
			}
			if (!item.BuiltIn)
			{
				bool flag = _confirmDelete == item.Name && Time.unscaledTime < _confirmUntil;
				if (GUILayout.Button(flag ? L("Sure?", "Точно?") : "✕", _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(52f) }))
				{
					if (flag)
					{
						preset = item;
						_confirmDelete = null;
					}
					else
					{
						_confirmDelete = item.Name;
						_confirmUntil = Time.unscaledTime + 3f;
					}
				}
			}
			GUILayout.EndHorizontal();
		}
		if (preset != null)
		{
			string text = DeleteUserPreset(preset.Name);
			Say(text ?? (L("Deleted: ", "Удалён: ") + preset.Name));
		}
		GUILayout.Space(4f);
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		_saveName = GUILayout.TextField(_saveName ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(Mathf.Max(120f, _winW - 250f)) });
		if (GUILayout.Button(L("Save current as", "Сохранить текущее как"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			Preset preset2 = Capture(_saveName);
			string text2 = SaveUserPreset(preset2);
			Say(text2 ?? (L("Saved: ", "Сохранён: ") + preset2.Name));
			if (text2 == null)
			{
				GUIUtility.keyboardControl = 0;
			}
		}
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (GUILayout.Button(L("Copy current to clipboard", "Копировать текущее в буфер"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			string text3 = (_saveName ?? "").Trim();
			GUIUtility.systemCopyBuffer = Export(Capture((text3.Length > 0) ? text3 : "Shared layout"));
			Say(L("Copied. Send it to a friend; they press Import.", "Скопировано. Отправьте другу — он нажмёт «Импорт»."));
		}
		if (GUILayout.Button(L("Import from clipboard", "Импорт из буфера"), _smallButton, (GUILayoutOption[])(object)new GUILayoutOption[0]))
		{
			Preset preset3 = Import(GUIUtility.systemCopyBuffer);
			if (preset3 == null)
			{
				Say(L("The clipboard holds no preset.", "В буфере нет пресета."));
			}
			else
			{
				preset3.Name = FreeName(preset3.Name);
				string text4 = SaveUserPreset(preset3);
				Say(text4 ?? (L("Imported as: ", "Импортирован как: ") + preset3.Name));
			}
		}
		GUILayout.EndHorizontal();
	}

	private void DrawSettingsSection()
	{
		Header(L("Settings", "Настройки"));
		GUILayout.Label(L("Language of this window", "Язык этого окна"), _wrapLabel, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		int num = Mathf.Max(0, Array.IndexOf(Languages, _cfgLanguage.Value));
		int num2 = GUILayout.SelectionGrid(num, new string[3]
		{
			L("As the game", "Как в игре"),
			"English",
			"Русский"
		}, 3, _gridStyle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (num2 != num)
		{
			_cfgLanguage.Value = Languages[num2];
		}
		bool snap = GUILayout.Toggle(_snap, L(" Snap to grid", " Привязка к сетке"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		_snap = snap;
		bool flag = GUILayout.Toggle(_cfgBuildShift.Value, L(" Lift bars in build mode like the game", " Поднимать полосы в режиме строительства, как игра"), _wrapToggle, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		if (flag != _cfgBuildShift.Value)
		{
			_cfgBuildShift.Value = flag;
		}
		GUILayout.BeginHorizontal((GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.Label(L("Window background", "Фон окна"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
		float num3 = GUILayout.HorizontalSlider(_cfgEditorOpacity.Value, 0.3f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[0]);
		GUILayout.EndHorizontal();
		if (Mathf.Abs(num3 - _cfgEditorOpacity.Value) > 0.0001f)
		{
			_cfgEditorOpacity.Value = (float)Math.Round(num3, 2);
		}
	}

	internal HudElement HudElementOf(ElementId id)
	{
		foreach (HudElement hudElement in _hudElements)
		{
			if (hudElement.Settings.Id == id)
			{
				return hudElement;
			}
		}
		return null;
	}

	internal void OnHudAwake(Hud hud)
	{
		if (_disabledByErrors)
		{
			return;
		}
		try
		{
			Attach(hud);
		}
		catch (Exception e)
		{
			Fail("attach", e);
		}
	}

	internal void OnHudDestroy(Hud hud)
	{
		if (!((Object)(object)hud != (Object)(object)_hud))
		{
			if (_editing)
			{
				StopEditing();
			}
			_hud = null;
			_root = null;
			_canvas = null;
			_hudElements.Clear();
		}
	}

	private void Attach(Hud hud)
	{
		if ((Object)(object)hud == (Object)null || (Object)(object)hud == (Object)(object)_hud)
		{
			return;
		}
		_hudElements.Clear();
		_hud = hud;
		_root = (RectTransform)(((Object)(object)hud.m_rootObject != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
		if ((Object)(object)_root == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Hud.m_rootObject not found; the HUD is left as it is.");
			return;
		}
		_canvas = ((Component)_root).GetComponentInParent<Canvas>();
		TryAttach("health", delegate
		{
			AttachHealth(hud);
		});
		TryAttach("food", delegate
		{
			AttachFood(hud);
		});
		TryAttach("stamina", delegate
		{
			AttachBar(hud, ElementId.Stamina, hud.m_staminaBar2Root, hud.m_staminaBar2Fast, hud.m_staminaBar2Slow, hud.m_staminaText, hud.m_staminaAnimator);
		});
		TryAttach("eitr", delegate
		{
			AttachBar(hud, ElementId.Eitr, hud.m_eitrBarRoot, hud.m_eitrBarFast, hud.m_eitrBarSlow, hud.m_eitrText, hud.m_eitrAnimator);
		});
		TryAttach("adrenaline", delegate
		{
			AttachBar(hud, ElementId.Adrenaline, hud.m_adrenalineBarRoot, hud.m_adrenalineBarFast, hud.m_adrenalineBarSlow, hud.m_adrenalineText, hud.m_adrenalineAnimator);
		});
		AttachVanillaSimple();
		_nextScan = 0f;
		((BaseUnityPlugin)this).Logger.LogInfo((object)("HUD found: " + _hudElements.Count + " elements made movable."));
	}

	private void TryAttach(string what, Action body)
	{
		try
		{
			body();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not wrap the " + what + " element, it stays as the game draws it: " + ex.Message));
		}
	}

	private RectTransform MakeWrapper(string name, int siblingIndex)
	{
		return MakeWrapper(name, _root, siblingIndex);
	}

	private RectTransform MakeWrapper(string name, RectTransform parent, int siblingIndex)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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)
		GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
		val.layer = ((Component)parent).gameObject.layer;
		RectTransform val2 = (RectTransform)val.transform;
		((Transform)val2).SetParent((Transform)(object)parent, false);
		val2.anchorMin = Vector2.zero;
		val2.anchorMax = Vector2.one;
		val2.pivot = parent.pivot;
		val2.anchoredPosition = Vector2.zero;
		val2.sizeDelta = Vector2.zero;
		((Transform)val2).localRotation = Quaternion.identity;
		((Transform)val2).localScale = Vector3.one;
		((Transform)val2).SetSiblingIndex(Mathf.Clamp(siblingIndex, 0, ((Transform)parent).childCount - 1));
		return val2;
	}

	private HudElement NewElement(ElementId id, string name, int siblingIndex)
	{
		HudElement hudElement = new HudElement();
		hudElement.Settings = Get(id);
		hudElement.Wrapper = MakeWrapper("HudLayout_" + name, siblingIndex);
		hudElement.Group = ((Component)hudElement.Wrapper).gameObject.AddComponent<CanvasGroup>();
		return hudElement;
	}

	private static void AddUpright(HudElement e, Transform t)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)t == (Object)null) && !e.Upright.Contains(t))
		{
			e.Upright.Add(t);
			e.UprightBase.Add(t.localRotation);
		}
	}

	private static void AddText(HudElement e, TMP_Text t)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)t == (Object)null))
		{
			e.Texts.Add(t);
			e.TextBase.Add(new float[3] { t.fontSize, t.fontSizeMin, t.fontSizeMax });
			e.WrapBase.Add(t.textWrappingMode);
			e.TextSizeBase.Add(t.rectTransform.sizeDelta);
			e.OverflowBase.Add(t.overflowMode);
		}
	}

	private static void SetupTextPlace(HudElement e, RectTransform center, GuiBar fast)
	{
		//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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)e.Text == (Object)null))
		{
			RectTransform rectTransform = e.Text.rectTransform;
			e.TextParent = ((Transform)rectTransform).parent;
			e.TextSibling = ((Transform)rectTransform).GetSiblingIndex();
			e.TextAnchorMin = rectTransform.anchorMin;
			e.TextAnchorMax = rectTransform.anchorMax;
			e.TextPivot = rectTransform.pivot;
			e.TextPos = rectTransform.anchoredPosition;
			e.CenterHolder = center;
			e.FillHolder = (RectTransform)(((Object)(object)fast != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
		}
	}

	privat