Decompiled source of HUDEditor v0.2.3

HUDEditor.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HUDEditor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.3.0")]
[assembly: AssemblyInformationalVersion("0.2.3+fc63075db3f38b6ac314e14f87dfc2688287becc")]
[assembly: AssemblyProduct("HUDEditor")]
[assembly: AssemblyTitle("HUDEditor")]
[assembly: AssemblyVersion("0.2.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HUDEditor
{
	[DefaultExecutionOrder(32000)]
	internal sealed class HudEditorController : MonoBehaviour
	{
		private readonly struct CursorRendererState
		{
			internal Renderer Renderer { get; }

			internal bool ForceRenderingOff { get; }

			internal CursorRendererState(Renderer renderer, bool forceRenderingOff)
			{
				Renderer = renderer;
				ForceRenderingOff = forceRenderingOff;
			}
		}

		private const float ScanInterval = 1f;

		private const float ControlLockDuration = 0.25f;

		private const int StartupScanCount = 6;

		private static readonly FieldInfo MapDebugActiveField = typeof(Map).GetField("debugActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MapToolActiveField = typeof(MapToolController).GetField("Active", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly List<InputKey> NoAllowedGameControls = new List<InputKey>();

		private static readonly ExternalHudRule[] ExternalHudRules = new ExternalHudRule[16]
		{
			new ExternalHudRule("headclef.UI", "HeadclefUI.HeadclefUI", "Headclef Tab Overlay", "Info", "Info Panel"),
			new ExternalHudRule("headclef.UI", "HeadclefUI.HeadclefUI", "Headclef Tab Overlay", "Players", "Player List"),
			new ExternalHudRule("denis.repo.denisui", "DenisUI.DenisUIPlugin", "Denis UI Overlay", "Denis UI Overlay", "Denis UI Overlay"),
			new ExternalHudRule("MapValueTracker", "MapValueTracker.MapValueTracker", "Value HUD", "Value HUD", "Map Value Tracker"),
			new ExternalHudRule("MapValueTrackerPlus", "MapValueTracker.MapValueTracker", "Value HUD", "Value HUD", "Map Value Tracker Plus"),
			new ExternalHudRule("fangjx114514.monsterrespawntimer", "MonsterRespawnTimer.Plugin", "MonsterRespawnTimer HUD", "MonsterRespawnTimer HUD", "Monster Respawn Timers"),
			new ExternalHudRule("ThatRobin3001.RobinsDynamicCompass", "RobinsDynamicCompass.RobinsDynamicCompass", "Compass", "Compass", "Dynamic Compass"),
			new ExternalHudRule("zichen.moreui", "Plugin", "moreui.NativeOverlay", "moreui.NativeOverlay", "Info Panel (Native)"),
			new ExternalHudRule("com.binaryn3xus.repo.omniextraction", "OmniExtractionToolkit.OmniExtractionToolkitPlugin", "EnhancedMapTracker", "EnhancedMapTracker", "Map Tracker"),
			new ExternalHudRule("com.binaryn3xus.repo.omniextraction", "OmniExtractionToolkit.OmniExtractionToolkitPlugin", "EnhancedHeldItem", "EnhancedHeldItem", "Held Item"),
			new ExternalHudRule("com.binaryn3xus.repo.omniextraction", "OmniExtractionToolkit.OmniExtractionToolkitPlugin", "EnhancedCooldownBar", "EnhancedCooldownBar", "Scanner Cooldown"),
			new ExternalHudRule("MoonPhaseUtils", "MoonPhaseUtils.Plugin", "ListDeadPlayers", "ListDeadPlayers", "Moon Details"),
			new ExternalHudRule("MoonPhaseUtils", "MoonPhaseUtils.Plugin", "MoonImage", "MoonImage", "Moon Icon"),
			new ExternalHudRule("MoonPhaseUtils", "MoonPhaseUtils.Plugin", "ModUIBanner", "TopPanel", "Moon Banner", searchSceneCanvases: true),
			new ExternalHudRule("cosmetic.scanner", "Cosmetics_Box_Scanner.Plugin", "CosmeticScannerCanvas", "Panel", "Cosmetic Box Counts", searchSceneCanvases: true),
			new ExternalHudRule("cosmetic.scanner", "Cosmetics_Box_Scanner.Plugin", "CosmeticScannerCanvas", "StatusText", "Scanner Status", searchSceneCanvases: true)
		};

		private readonly Dictionary<int, HudElement> _elementsByTarget = new Dictionary<int, HudElement>();

		private readonly Dictionary<string, HudElement> _elementsByStableId = new Dictionary<string, HudElement>(StringComparer.Ordinal);

		private readonly Dictionary<string, ConfigEntry<string>> _positionEntries = new Dictionary<string, ConfigEntry<string>>(StringComparer.Ordinal);

		private readonly Dictionary<string, ConfigEntry<bool>> _visibilityEntries = new Dictionary<string, ConfigEntry<bool>>(StringComparer.Ordinal);

		private readonly Dictionary<string, ConfigEntry<float>> _scaleEntries = new Dictionary<string, ConfigEntry<float>>(StringComparer.Ordinal);

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

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

		private readonly List<string> _presetFiles = new List<string>();

		private readonly Dictionary<int, Rect> _cursorMeshUvs = new Dictionary<int, Rect>();

		private readonly HashSet<MethodBase> _patchedImmediateModeMethods = new HashSet<MethodBase>();

		private Plugin _plugin;

		private Harmony _immediateModeHarmony;

		private HudOffsetRestorer _restorer;

		private GameObject _hudRoot;

		private int _hudRootInstanceId;

		private float _nextScanTime;

		private int _startupScansRemaining;

		private bool _initialized;

		private bool _editorActive;

		private bool _closeConfirmationOpen;

		private HudElement _selected;

		private HudElement _dragging;

		private HudElement _resizing;

		private HudElement _bringCandidate;

		private HudElement _previewedElement;

		private Vector2 _dragPointerScreenPrevious;

		private ResizeCorner _resizeCorner;

		private Vector2 _resizeFixedScreenPoint;

		private Vector2 _resizeMovingStartScreenPoint;

		private Vector2 _resizePointerStartScreenPoint;

		private float _resizeStartScale;

		private Rect _previewInteractionScreenRect;

		private bool _hasPreviewInteractionScreenRect;

		private Rect _panelGuiRect;

		private Rect _bringDropdownGuiRect;

		private Rect _presetDialogGuiRect;

		private bool _panelPositionInitialized;

		private bool _panelDragging;

		private bool _bringMenuOpen;

		private bool _mapPreviewActive;

		private bool _mapStateCaptured;

		private bool _mapActiveBeforePreview;

		private bool _mapDebugBeforePreview;

		private bool _mapToolActiveBeforePreview;

		private bool _presetDialogOpen;

		private bool _drawingModalControls;

		private Vector2 _panelDragScreenOffset;

		private Vector2 _bringScrollPosition;

		private Vector2 _presetScrollPosition;

		private string _presetName = "My HUD Layout";

		private string _selectedPresetPath;

		private string _presetStatus = string.Empty;

		private Texture2D _fallbackCursorTexture;

		private int _cachedCursorInstanceId;

		private Graphic[] _cachedCursorGraphics = Array.Empty<Graphic>();

		private Renderer[] _cachedCursorRenderers = Array.Empty<Renderer>();

		private MenuCursor _suppressedSoftwareCursor;

		private CanvasGroup _cursorSuppressionGroup;

		private bool _cursorSuppressionGroupWasAdded;

		private float _cursorSuppressionAlphaBefore;

		private readonly List<CursorRendererState> _cursorRendererStates = new List<CursorRendererState>();

		private GUIStyle _panelTitleStyle;

		private GUIStyle _panelSelectionStyle;

		private GUIStyle _panelButtonStyle;

		private GUIStyle _panelBadgeStyle;

		private GUIStyle _dialogBodyStyle;

		private GUIStyle _groupHeaderStyle;

		private GUIStyle _presetTextFieldStyle;

		internal bool EditorActive => _editorActive;

		private bool HasUnsavedChanges => _elements.Any((HudElement element) => element.HasUnsavedChanges);

		private static string PresetDirectory => Path.Combine(Paths.ConfigPath, "HUDEditorPresets");

		internal void Initialize(Plugin plugin, HudOffsetRestorer restorer)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			_plugin = plugin;
			_immediateModeHarmony = new Harmony("mathe.hudeditor.immediate-mode");
			_restorer = restorer;
			_restorer.Owner = this;
			_initialized = true;
		}

		internal void Shutdown()
		{
			if (_initialized)
			{
				EndMapPreview();
				DiscardAllChanges();
				RestoreAllOffsets();
				DisposeAllElements();
				if ((Object)(object)_fallbackCursorTexture != (Object)null)
				{
					Object.Destroy((Object)(object)_fallbackCursorTexture);
					_fallbackCursorTexture = null;
				}
				_cursorMeshUvs.Clear();
				_cachedCursorGraphics = Array.Empty<Graphic>();
				_cachedCursorRenderers = Array.Empty<Renderer>();
				_cachedCursorInstanceId = 0;
				RestoreSoftwareCursor();
				Harmony immediateModeHarmony = _immediateModeHarmony;
				if (immediateModeHarmony != null)
				{
					immediateModeHarmony.UnpatchSelf();
				}
				ImmediateModeHudBridge.Clear();
				_patchedImmediateModeMethods.Clear();
				_editorActive = false;
				_initialized = false;
			}
		}

		private void Update()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				return;
			}
			RefreshHudRoot();
			KeyboardShortcut value = _plugin.EditModeKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				if (_editorActive)
				{
					RequestCloseEditor();
				}
				else
				{
					TryEnterEditor();
				}
			}
			if ((Object)(object)_hudRoot != (Object)null && Time.unscaledTime >= _nextScanTime && (_editorActive || _startupScansRemaining > 0))
			{
				ScanHudElements();
				if (!_editorActive && _startupScansRemaining > 0)
				{
					_startupScansRemaining--;
				}
				_nextScanTime = Time.unscaledTime + 1f;
			}
			ApplyAllOffsets();
			if (!_editorActive)
			{
				_selected = null;
			}
			else if ((Object)(object)_hudRoot == (Object)null)
			{
				DiscardAllChanges();
				ExitEditorImmediately();
			}
			else
			{
				MaintainEditorInputState();
				UpdatePointerInteraction();
			}
		}

		private void LateUpdate()
		{
			if (_initialized)
			{
				ApplyAllOffsets();
				_previewedElement?.ApplyPreview();
				RefreshPreviewInteractionRect();
				MaintainMapPreview();
			}
		}

		private void OnGUI()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: 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_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_0662: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_067d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0732: Unknown result type (might be due to invalid IL or missing references)
			//IL_0782: Unknown result type (might be due to invalid IL or missing references)
			//IL_0767: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_080b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0837: Unknown result type (might be due to invalid IL or missing references)
			//IL_0839: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_085b: Unknown result type (might be due to invalid IL or missing references)
			//IL_085d: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_088d: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0930: Unknown result type (might be due to invalid IL or missing references)
			//IL_093c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0969: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b5: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized || !_editorActive)
			{
				return;
			}
			int depth = GUI.depth;
			Color color = GUI.color;
			bool enabled = GUI.enabled;
			GUI.depth = -32000;
			Rect panelGuiRect = GetPanelGuiRect();
			float editorUiScale = GetEditorUiScale();
			EnsureGuiStyles(editorUiScale);
			bool hasUnsavedChanges = HasUnsavedChanges;
			DrawSolidRect(new Rect(((Rect)(ref panelGuiRect)).x + 5f * editorUiScale, ((Rect)(ref panelGuiRect)).y + 7f * editorUiScale, ((Rect)(ref panelGuiRect)).width, ((Rect)(ref panelGuiRect)).height), new Color(0f, 0f, 0f, 0.42f));
			DrawSolidRect(panelGuiRect, new Color(0.025f, 0.035f, 0.05f, 0.97f));
			DrawBorder(panelGuiRect, new Color(0.22f, 0.32f, 0.39f, 1f), Mathf.Max(1f, editorUiScale));
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(((Rect)(ref panelGuiRect)).x, ((Rect)(ref panelGuiRect)).y, ((Rect)(ref panelGuiRect)).width, 48f * editorUiScale);
			DrawSolidRect(rect, new Color(0.045f, 0.075f, 0.1f, 1f));
			DrawSolidRect(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, 5f * editorUiScale, ((Rect)(ref rect)).height), new Color(0.16f, 0.82f, 1f, 1f));
			GUI.color = Color.white;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 20f * editorUiScale, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 150f * editorUiScale, ((Rect)(ref rect)).height), "HUD EDITOR", _panelTitleStyle);
			if (hasUnsavedChanges)
			{
				Rect val = new Rect(((Rect)(ref rect)).xMax - 116f * editorUiScale, ((Rect)(ref rect)).y + 10f * editorUiScale, 94f * editorUiScale, 28f * editorUiScale);
				DrawSolidRect(val, new Color(0.72f, 0.35f, 0.06f, 0.92f));
				GUI.Label(val, "UNSAVED", _panelBadgeStyle);
			}
			Rect rect2 = default(Rect);
			((Rect)(ref rect2))..ctor(((Rect)(ref panelGuiRect)).x + 18f * editorUiScale, ((Rect)(ref panelGuiRect)).y + 59f * editorUiScale, ((Rect)(ref panelGuiRect)).width - 36f * editorUiScale, 38f * editorUiScale);
			DrawSolidRect(rect2, new Color(0.055f, 0.075f, 0.095f, 1f));
			DrawBorder(rect2, new Color(0.11f, 0.2f, 0.25f, 1f), Mathf.Max(1f, editorUiScale));
			GUI.Label(new Rect(((Rect)(ref rect2)).x + 12f * editorUiScale, ((Rect)(ref rect2)).y, ((Rect)(ref rect2)).width - 24f * editorUiScale, ((Rect)(ref rect2)).height), "Selected: " + ((_selected != null) ? _selected.DisplayName : "None"), _panelSelectionStyle);
			Rect rect3 = default(Rect);
			((Rect)(ref rect3))..ctor(((Rect)(ref panelGuiRect)).x + 18f * editorUiScale, ((Rect)(ref panelGuiRect)).y + 108f * editorUiScale, 414f * editorUiScale, 38f * editorUiScale);
			if (DrawPanelButton(label: (_bringCandidate != null && _bringCandidate.IsAlive) ? _bringCandidate.DisplayName : "Select HUD element...", rect: rect3, baseColor: new Color(0.07f, 0.1f, 0.13f, 1f), enabled: _bringOptions.Count > 0))
			{
				_bringMenuOpen = !_bringMenuOpen;
			}
			if (DrawPanelButton(new Rect(((Rect)(ref rect3)).xMax + 10f * editorUiScale, ((Rect)(ref rect3)).y, 140f * editorUiScale, ((Rect)(ref rect3)).height), "BRING", new Color(0.03f, 0.53f, 0.68f, 1f), _bringCandidate != null && _bringCandidate.IsAlive))
			{
				BringCandidate();
			}
			float num = ((Rect)(ref panelGuiRect)).y + 160f * editorUiScale;
			float num2 = ((Rect)(ref panelGuiRect)).y + 205f * editorUiScale;
			float num3 = 34f * editorUiScale;
			float num4 = 10f * editorUiScale;
			float num5 = ((Rect)(ref panelGuiRect)).x + 18f * editorUiScale;
			if (DrawPanelButton(new Rect(num5, num, 116f * editorUiScale, num3), "SAVE", new Color(0.03f, 0.53f, 0.68f, 1f), hasUnsavedChanges))
			{
				SaveAllChanges();
			}
			num5 += 116f * editorUiScale + num4;
			if (DrawPanelButton(new Rect(num5, num, 116f * editorUiScale, num3), "CLOSE", new Color(0.14f, 0.18f, 0.22f, 1f), enabled: true))
			{
				RequestCloseEditor();
			}
			num5 += 116f * editorUiScale + num4;
			if (DrawPanelButton(new Rect(num5, num, 140f * editorUiScale, num3), "RESET ALL", new Color(0.14f, 0.18f, 0.22f, 1f), enabled: true))
			{
				ResetAllElements();
			}
			num5 += 140f * editorUiScale + num4;
			if (DrawPanelButton(enabled: _elements.Any((HudElement element) => !element.Visible), rect: new Rect(num5, num, 162f * editorUiScale, num3), label: "SHOW HIDDEN", baseColor: new Color(0.14f, 0.18f, 0.22f, 1f)))
			{
				ShowAllHiddenElements();
			}
			num5 = ((Rect)(ref panelGuiRect)).x + 18f * editorUiScale;
			if (DrawPanelButton(label: (_selected != null && !_selected.Visible) ? "SHOW" : "HIDE", rect: new Rect(num5, num2, 116f * editorUiScale, num3), baseColor: new Color(0.68f, 0.31f, 0.08f, 1f), enabled: _selected != null))
			{
				ClearPreview();
				_selected.SetVisible(!_selected.Visible);
			}
			num5 += 116f * editorUiScale + num4;
			if (DrawPanelButton(new Rect(num5, num2, 166f * editorUiScale, num3), "RESET ITEM", new Color(0.14f, 0.18f, 0.22f, 1f), _selected != null))
			{
				_selected.SetOffset(Vector2.zero);
				_selected.SetScale(1f);
			}
			num5 += 166f * editorUiScale + num4;
			if (DrawPanelButton(new Rect(num5, num2, 126f * editorUiScale, num3), "DESELECT", new Color(0.14f, 0.18f, 0.22f, 1f), _selected != null))
			{
				ClearPreview();
				_resizing = null;
				_selected = null;
				_dragging = null;
			}
			float num6 = ((Rect)(ref panelGuiRect)).y + 250f * editorUiScale;
			num5 = ((Rect)(ref panelGuiRect)).x + 18f * editorUiScale;
			if (DrawPanelButton(new Rect(num5, num6, 140f * editorUiScale, num3), _mapPreviewActive ? "MAP: ON" : "MAP: OFF", _mapPreviewActive ? new Color(0.03f, 0.53f, 0.68f, 1f) : new Color(0.14f, 0.18f, 0.22f, 1f), (Object)(object)Map.Instance != (Object)null && (Object)(object)MapToolController.instance != (Object)null))
			{
				ToggleMapPreview();
			}
			num5 += 140f * editorUiScale + num4;
			if (DrawPanelButton(new Rect(num5, num6, 166f * editorUiScale, num3), "PRESETS", new Color(0.14f, 0.18f, 0.22f, 1f), enabled: true))
			{
				_presetDialogOpen = true;
				_bringMenuOpen = false;
				_bringDropdownGuiRect = default(Rect);
				RefreshPresetFiles();
			}
			if (_selected != null && _selected.TryGetScreenRect(includeHidden: true, out var result, out var _))
			{
				Rect rect4 = ScreenToGuiRect(result);
				Color color2 = default(Color);
				((Color)(ref color2))..ctor(1f, 0.72f, 0.12f, 1f);
				DrawBorder(rect4, color2, (_dragging == _selected || _resizing == _selected) ? 3f : 2f);
				DrawResizeHandles(rect4, _resizing == _selected);
				if (_plugin.ShowElementLabels.Value)
				{
					GUI.color = new Color(0f, 0f, 0f, 0.88f);
					Rect val2 = default(Rect);
					((Rect)(ref val2))..ctor(((Rect)(ref rect4)).x, Mathf.Max(0f, ((Rect)(ref rect4)).y - 20f), Mathf.Max(90f, Mathf.Min(260f, (float)_selected.DisplayName.Length * 7.2f + 12f)), 19f);
					GUI.DrawTexture(val2, (Texture)(object)Texture2D.whiteTexture);
					GUI.color = color2;
					GUI.Label(new Rect(((Rect)(ref val2)).x + 4f, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width - 8f, 19f), _selected.DisplayName);
				}
			}
			if (_closeConfirmationOpen)
			{
				DrawUnsavedChangesDialog();
			}
			else if (_presetDialogOpen)
			{
				DrawPresetDialog();
			}
			if (_bringMenuOpen && !_closeConfirmationOpen && !_presetDialogOpen)
			{
				DrawBringDropdown(panelGuiRect, editorUiScale);
			}
			else
			{
				_bringDropdownGuiRect = default(Rect);
			}
			DrawCursorOnTop();
			GUI.enabled = enabled;
			GUI.color = color;
			GUI.depth = depth;
		}

		private void RefreshHudRoot()
		{
			//IL_009e: 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)
			GameObject val = null;
			if ((Object)(object)HUDCanvas.instance != (Object)null)
			{
				val = ((Component)HUDCanvas.instance).gameObject;
			}
			int num = (((Object)(object)val != (Object)null) ? ((Object)val).GetInstanceID() : 0);
			if (num != _hudRootInstanceId)
			{
				RestoreAllOffsets();
				ClearPreview();
				DisposeAllElements();
				_elements.Clear();
				_elementsByTarget.Clear();
				_elementsByStableId.Clear();
				_bringOptions.Clear();
				_selected = null;
				_dragging = null;
				_resizing = null;
				_bringCandidate = null;
				_bringMenuOpen = false;
				_bringDropdownGuiRect = default(Rect);
				EndMapPreview();
				_presetDialogOpen = false;
				_presetDialogGuiRect = default(Rect);
				_closeConfirmationOpen = false;
				_hudRoot = val;
				_hudRootInstanceId = num;
				_nextScanTime = (((Object)(object)val != (Object)null) ? (Time.unscaledTime + 0.5f) : 0f);
				_startupScansRemaining = (((Object)(object)val != (Object)null) ? 6 : 0);
				if (_editorActive && (Object)(object)_hudRoot == (Object)null)
				{
					DiscardAllChanges();
					ExitEditorImmediately();
				}
			}
		}

		private void TryEnterEditor()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hudRoot == (Object)null || !_hudRoot.activeInHierarchy)
			{
				Plugin.Log.LogWarning((object)"HUD edit mode is only available when the in-game HUD exists.");
				return;
			}
			if ((int)Cursor.lockState != 1)
			{
				Plugin.Log.LogWarning((object)"HUD edit mode was not opened because another game menu already owns the cursor.");
				return;
			}
			ScanHudElements();
			_selected = null;
			_dragging = null;
			_resizing = null;
			_bringCandidate = null;
			_bringMenuOpen = false;
			_bringScrollPosition = Vector2.zero;
			_bringDropdownGuiRect = default(Rect);
			_mapPreviewActive = false;
			_mapStateCaptured = false;
			_presetDialogOpen = false;
			_presetStatus = string.Empty;
			_closeConfirmationOpen = false;
			_panelDragging = false;
			_panelPositionInitialized = false;
			_editorActive = true;
			_nextScanTime = Time.unscaledTime + 1f;
			Plugin.Log.LogInfo((object)"HUD edit mode opened. Gameplay controls are suppressed until it closes.");
		}

		private void RequestCloseEditor()
		{
			if (_editorActive)
			{
				if (HasUnsavedChanges)
				{
					_dragging = null;
					_resizing = null;
					_closeConfirmationOpen = true;
				}
				else
				{
					ExitEditorImmediately();
				}
			}
		}

		private void ExitEditorImmediately()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			ClearPreview();
			EndMapPreview();
			RestoreSoftwareCursor();
			_dragging = null;
			_resizing = null;
			_selected = null;
			_bringCandidate = null;
			_bringMenuOpen = false;
			_bringDropdownGuiRect = default(Rect);
			_presetDialogOpen = false;
			_presetDialogGuiRect = default(Rect);
			_closeConfirmationOpen = false;
			_panelDragging = false;
			_editorActive = false;
			Plugin.Log.LogInfo((object)"HUD edit mode closed.");
		}

		private void DrawUnsavedChangesDialog()
		{
			//IL_004f: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			_drawingModalControls = true;
			float editorUiScale = GetEditorUiScale();
			EnsureGuiStyles(editorUiScale);
			float num = 500f * editorUiScale;
			float num2 = 176f * editorUiScale;
			Rect rect = default(Rect);
			((Rect)(ref rect))..ctor(((float)Screen.width - num) * 0.5f, ((float)Screen.height - num2) * 0.5f, num, num2);
			GUI.enabled = true;
			DrawSolidRect(rect, new Color(0.025f, 0.035f, 0.05f, 0.99f));
			DrawBorder(rect, new Color(0.25f, 0.42f, 0.5f, 1f), Mathf.Max(1f, editorUiScale));
			DrawSolidRect(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 48f * editorUiScale), new Color(0.045f, 0.075f, 0.1f, 1f));
			GUI.color = Color.white;
			GUI.Label(new Rect(((Rect)(ref rect)).x + 18f * editorUiScale, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 36f * editorUiScale, 48f * editorUiScale), "UNSAVED HUD CHANGES", _panelTitleStyle);
			GUI.Label(new Rect(((Rect)(ref rect)).x + 18f * editorUiScale, ((Rect)(ref rect)).y + 59f * editorUiScale, ((Rect)(ref rect)).width - 36f * editorUiScale, 38f * editorUiScale), "Save the HUD changes before closing the editor?", _dialogBodyStyle);
			float num3 = ((Rect)(ref rect)).y + 116f * editorUiScale;
			float num4 = 144f * editorUiScale;
			float num5 = 38f * editorUiScale;
			float num6 = 16f * editorUiScale;
			float num7 = ((Rect)(ref rect)).x + 18f * editorUiScale;
			if (DrawPanelButton(new Rect(num7, num3, num4, num5), "SAVE & CLOSE", new Color(0.03f, 0.53f, 0.68f, 1f), enabled: true))
			{
				SaveAllChanges();
				ExitEditorImmediately();
			}
			num7 += num4 + num6;
			if (DrawPanelButton(new Rect(num7, num3, num4, num5), "DON'T SAVE", new Color(0.63f, 0.22f, 0.14f, 1f), enabled: true))
			{
				DiscardAllChanges();
				ExitEditorImmediately();
			}
			num7 += num4 + num6;
			if (DrawPanelButton(new Rect(num7, num3, num4, num5), "CANCEL", new Color(0.14f, 0.18f, 0.22f, 1f), enabled: true))
			{
				_closeConfirmationOpen = false;
			}
			_drawingModalControls = false;
		}

		private void MaintainEditorInputState()
		{
			if ((Object)(object)InputManager.instance != (Object)null)
			{
				InputManager.instance.DisableControlsExcept(0.25f, NoAllowedGameControls);
				InputManager.instance.DisableMovement(0.25f);
				InputManager.instance.DisableAiming(0.25f);
			}
			if ((Object)(object)PlayerController.instance != (Object)null)
			{
				PlayerController.instance.InputDisable(0.25f);
			}
			if ((Object)(object)CursorManager.instance != (Object)null && (Object)(object)MenuCursor.instance != (Object)null)
			{
				CursorManager.instance.Unlock(0.25f);
				Cursor.visible = false;
				SuppressSoftwareCursor(MenuCursor.instance);
			}
			else
			{
				RestoreSoftwareCursor();
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
		}

		private void SuppressSoftwareCursor(MenuCursor cursor)
		{
			if ((Object)(object)cursor == (Object)null)
			{
				RestoreSoftwareCursor();
				return;
			}
			if ((Object)(object)_suppressedSoftwareCursor != (Object)(object)cursor)
			{
				RestoreSoftwareCursor();
				_suppressedSoftwareCursor = cursor;
				_cursorSuppressionGroup = ((Component)cursor).GetComponent<CanvasGroup>();
				if ((Object)(object)_cursorSuppressionGroup == (Object)null)
				{
					_cursorSuppressionGroup = ((Component)cursor).gameObject.AddComponent<CanvasGroup>();
					_cursorSuppressionGroupWasAdded = true;
					_cursorSuppressionAlphaBefore = 1f;
				}
				else
				{
					_cursorSuppressionGroupWasAdded = false;
					_cursorSuppressionAlphaBefore = _cursorSuppressionGroup.alpha;
				}
				Renderer[] componentsInChildren = ((Component)cursor).GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					if ((Object)(object)val != (Object)null)
					{
						_cursorRendererStates.Add(new CursorRendererState(val, val.forceRenderingOff));
					}
				}
			}
			if ((Object)(object)_cursorSuppressionGroup != (Object)null)
			{
				_cursorSuppressionGroup.alpha = 0f;
			}
			for (int j = 0; j < _cursorRendererStates.Count; j++)
			{
				Renderer renderer = _cursorRendererStates[j].Renderer;
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.forceRenderingOff = true;
				}
			}
		}

		private void RestoreSoftwareCursor()
		{
			if ((Object)(object)_cursorSuppressionGroup != (Object)null)
			{
				_cursorSuppressionGroup.alpha = _cursorSuppressionAlphaBefore;
				if (_cursorSuppressionGroupWasAdded)
				{
					Object.Destroy((Object)(object)_cursorSuppressionGroup);
				}
			}
			for (int i = 0; i < _cursorRendererStates.Count; i++)
			{
				CursorRendererState cursorRendererState = _cursorRendererStates[i];
				if ((Object)(object)cursorRendererState.Renderer != (Object)null)
				{
					cursorRendererState.Renderer.forceRenderingOff = cursorRendererState.ForceRenderingOff;
				}
			}
			_cursorRendererStates.Clear();
			_suppressedSoftwareCursor = null;
			_cursorSuppressionGroup = null;
			_cursorSuppressionGroupWasAdded = false;
			_cursorSuppressionAlphaBefore = 1f;
		}

		private void ToggleMapPreview()
		{
			if (_mapPreviewActive)
			{
				EndMapPreview();
				return;
			}
			Map instance = Map.Instance;
			MapToolController instance2 = MapToolController.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null)
			{
				Plugin.Log.LogInfo((object)"Map preview is unavailable in the current scene.");
				return;
			}
			_mapActiveBeforePreview = instance.Active;
			_mapDebugBeforePreview = ReadBooleanField(MapDebugActiveField, instance);
			_mapToolActiveBeforePreview = ReadBooleanField(MapToolActiveField, instance2);
			_mapStateCaptured = true;
			_mapPreviewActive = true;
			MaintainMapPreview();
			_nextScanTime = 0f;
			Plugin.Log.LogInfo((object)"Map preview enabled for HUD editing.");
		}

		private void MaintainMapPreview()
		{
			if (!_mapPreviewActive)
			{
				return;
			}
			Map instance = Map.Instance;
			MapToolController instance2 = MapToolController.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null)
			{
				EndMapPreview();
				return;
			}
			WriteBooleanField(MapDebugActiveField, instance, value: true);
			WriteBooleanField(MapToolActiveField, instance2, value: true);
			if (!instance.Active || (Object)(object)instance.ActiveParent == (Object)null || !instance.ActiveParent.activeSelf)
			{
				instance.ActiveSet(true);
			}
			StatsUI instance3 = StatsUI.instance;
			if (instance3 != null)
			{
				((SemiUI)instance3).Show();
			}
			LevelUI instance4 = LevelUI.instance;
			if (instance4 != null)
			{
				((SemiUI)instance4).Show();
			}
			MissionUI instance5 = MissionUI.instance;
			if (instance5 != null)
			{
				((SemiUI)instance5).Show();
			}
		}

		private void EndMapPreview()
		{
			if (!_mapStateCaptured)
			{
				_mapPreviewActive = false;
				return;
			}
			_mapPreviewActive = false;
			Map instance = Map.Instance;
			MapToolController instance2 = MapToolController.instance;
			if ((Object)(object)instance != (Object)null)
			{
				WriteBooleanField(MapDebugActiveField, instance, _mapDebugBeforePreview);
				instance.ActiveSet(_mapActiveBeforePreview);
			}
			if ((Object)(object)instance2 != (Object)null)
			{
				WriteBooleanField(MapToolActiveField, instance2, _mapToolActiveBeforePreview);
			}
			_mapStateCaptured = false;
			Plugin.Log.LogInfo((object)"Map preview restored to its previous state.");
		}

		private static bool ReadBooleanField(FieldInfo field, object instance)
		{
			bool flag = default(bool);
			int num;
			if (field != null && instance != null)
			{
				object value = field.GetValue(instance);
				if (value is bool)
				{
					flag = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		private static void WriteBooleanField(FieldInfo field, object instance, bool value)
		{
			if (field != null && instance != null)
			{
				field.SetValue(instance, value);
			}
		}

		private void ScanHudElements()
		{
			if ((Object)(object)_hudRoot == (Object)null)
			{
				return;
			}
			RemoveDestroyedElements();
			List<Transform> list = RegisterCompatibilityHuds();
			SemiUI[] componentsInChildren = _hudRoot.GetComponentsInChildren<SemiUI>(true);
			List<Transform> list2 = new List<Transform>(list);
			SemiUI[] array = componentsInChildren;
			foreach (SemiUI val in array)
			{
				if (IsSceneComponent((Component)(object)val) && IsEditableHudTransform(((Component)val).transform) && !IsExcludedUiTransform(((Component)val).transform) && !ShouldSkipSemiUi(val) && !IsRepresentedByGroup(((Component)val).transform, list))
				{
					object obj = (val.animateTheEntireObject ? ((Component)val).transform : (((Object)(object)val.textRectTransform != (Object)null) ? ((object)val.textRectTransform) : ((object)((Component)val).GetComponent<RectTransform>())));
					RectTransform val2 = (RectTransform)((obj is RectTransform) ? obj : null);
					if (!((Object)(object)val2 == (Object)null))
					{
						list2.Add(((Component)val).transform);
						Transform transform = ((Component)val).transform;
						RectTransform boundsRoot = (RectTransform)(((object)((transform is RectTransform) ? transform : null)) ?? ((object)val2));
						RegisterAfterOneFrame(val2, boundsRoot, ((Component)val).transform, ((object)val).GetType().Assembly.GetName().Name + "|" + ((object)val).GetType().FullName, MakeFriendlyName(((object)val).GetType().Name), (Component)(object)val, val);
					}
				}
			}
			Graphic[] componentsInChildren2 = _hudRoot.GetComponentsInChildren<Graphic>(true);
			foreach (Graphic graphic in componentsInChildren2)
			{
				if (IsActiveSceneComponent((Component)(object)graphic) && IsEditableHudTransform(((Component)graphic).transform) && IsGraphicEffectivelyVisible(graphic) && !IsExcludedUiTransform(((Component)graphic).transform) && !list2.Any((Transform group) => (Object)(object)((Component)graphic).transform == (Object)(object)group || ((Component)graphic).transform.IsChildOf(group)))
				{
					RectTransform rectTransform = graphic.rectTransform;
					RegisterAfterOneFrame(rectTransform, rectTransform, ((Component)graphic).transform, ((object)graphic).GetType().Assembly.GetName().Name + "|" + ((object)graphic).GetType().FullName, MakeFriendlyName(((Object)((Component)graphic).gameObject).name), (Component)(object)graphic, null);
				}
			}
			RegisterImmediateModeHuds();
			RefreshBringOptions();
		}

		private List<Transform> RegisterCompatibilityHuds()
		{
			List<Transform> list = new List<Transform>();
			Canvas[] array = null;
			RectTransform[] array2 = null;
			ExternalHudRule[] externalHudRules = ExternalHudRules;
			foreach (ExternalHudRule rule in externalHudRules)
			{
				if (!TryResolvePluginType(rule.PluginGuid, rule.SourceTypeName, out var pluginInfo, out var componentType))
				{
					continue;
				}
				IEnumerable<RectTransform> enumerable;
				if (rule.SearchSceneCanvases)
				{
					if (array == null)
					{
						array = Resources.FindObjectsOfTypeAll<Canvas>().Where(delegate(Canvas canvas)
						{
							//IL_000f: Unknown result type (might be due to invalid IL or missing references)
							//IL_0014: Unknown result type (might be due to invalid IL or missing references)
							if ((Object)(object)canvas != (Object)null)
							{
								Scene scene = ((Component)canvas).gameObject.scene;
								return ((Scene)(ref scene)).IsValid();
							}
							return false;
						}).ToArray();
					}
					enumerable = array.Where((Canvas canvas) => (Object)(object)FindNamedAncestor(((Component)canvas).transform, rule.RootObjectName) != (Object)null).SelectMany((Canvas canvas) => ((Component)canvas).GetComponentsInChildren<RectTransform>(true));
				}
				else
				{
					if (array2 == null)
					{
						array2 = _hudRoot.GetComponentsInChildren<RectTransform>(true);
					}
					enumerable = array2;
				}
				string pluginDisplayName = GetPluginDisplayName(pluginInfo, componentType.Assembly);
				foreach (RectTransform item in enumerable)
				{
					if (!((Object)(object)item == (Object)null) && string.Equals(NormalizeObjectName(((Object)item).name), rule.TargetObjectName, StringComparison.OrdinalIgnoreCase) && !((Object)(object)FindNamedAncestor((Transform)(object)item, rule.RootObjectName) == (Object)null))
					{
						RegisterAfterOneFrame(item, item, (Transform)(object)item, "Compatibility|" + rule.PluginGuid + "|" + componentType.FullName, rule.DisplayName, (Component)(object)((pluginInfo != null) ? pluginInfo.Instance : null), ((Component)item).GetComponent<SemiUI>(), pluginDisplayName);
						if (!list.Contains((Transform)(object)item))
						{
							list.Add((Transform)(object)item);
						}
					}
				}
			}
			RegisterShoppingListHud(list);
			RegisterStaticComponentHud("ItsAGeBa.ShowTotalLoot", "ShowTotalLoot.ShowTotalLoot", "ShowTotalLoot.Patches.ShowMaxHaulPatch", "_maxHaulGoalLabel", "Total Loot Value", list);
			return list;
		}

		private void RegisterShoppingListHud(List<Transform> representedGroups)
		{
			if (!TryResolvePluginType("khalliv.ShoppingListHUD", "ShoppingListHUD.ShoppingListHUD", out var pluginInfo, out var componentType) || (Object)(object)StatsUI.instance == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)StatsUI.instance).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (val != null)
			{
				RegisterAfterOneFrame(val, val, (Transform)(object)val, "Compatibility|khalliv.ShoppingListHUD|ShoppingListHUD.ShoppingListHUD", "Shopping List", (Component)(object)((pluginInfo != null) ? pluginInfo.Instance : null), (SemiUI)(object)StatsUI.instance, GetPluginDisplayName(pluginInfo, componentType.Assembly));
				if (!representedGroups.Contains((Transform)(object)val))
				{
					representedGroups.Add((Transform)(object)val);
				}
			}
		}

		private void RegisterStaticComponentHud(string pluginGuid, string sourceTypeName, string ownerTypeName, string fieldName, string displayName, List<Transform> representedGroups)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			if (!TryResolvePluginType(pluginGuid, sourceTypeName, out var pluginInfo, out var componentType))
			{
				return;
			}
			object obj = (componentType.Assembly.GetType(ownerTypeName, throwOnError: false)?.GetField(fieldName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))?.GetValue(null);
			Component val = (Component)((obj is Component) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				object? obj2 = (obj?.GetType().GetProperty("labelTMP", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))?.GetValue(obj, null);
				val = (Component)((obj2 is Component) ? obj2 : null);
			}
			Transform obj3 = ((val != null) ? val.transform : null);
			RectTransform val2 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			Scene scene = ((Component)val2).gameObject.scene;
			if (((Scene)(ref scene)).IsValid())
			{
				RegisterAfterOneFrame(val2, val2, (Transform)(object)val2, "Compatibility|" + pluginGuid + "|" + ownerTypeName + "." + fieldName, displayName, (Component)(object)((pluginInfo != null) ? pluginInfo.Instance : null), ((Component)val2).GetComponent<SemiUI>(), GetPluginDisplayName(pluginInfo, componentType.Assembly));
				if (!representedGroups.Contains((Transform)(object)val2))
				{
					representedGroups.Add((Transform)(object)val2);
				}
			}
		}

		private static bool IsRepresentedByGroup(Transform transform, List<Transform> groups)
		{
			if ((Object)(object)transform == (Object)null || groups == null)
			{
				return false;
			}
			for (int i = 0; i < groups.Count; i++)
			{
				Transform val = groups[i];
				if ((Object)(object)val != (Object)null && ((Object)(object)transform == (Object)(object)val || transform.IsChildOf(val)))
				{
					return true;
				}
			}
			return false;
		}

		private static Transform FindNamedAncestor(Transform transform, string objectName)
		{
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				if (string.Equals(NormalizeObjectName(((Object)val).name), objectName, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
				val = val.parent;
			}
			return null;
		}

		private void RegisterImmediateModeHuds()
		{
			RegisterImmediateModeHud("com.theohay.nuageroles", "NuageRoles.Roles.Patches.guiManager", "Role & Ability HUD", "RoleAndAbilityHud", (Type _) => new Rect((float)Screen.width * 0.5f - 360f, (float)Screen.height * 0.5f - 90f, 720f, 205f), "OnGUI", "showGUI");
			RegisterImmediateModeHud("Vippy.SharedUpgradesPlus", "SharedUpgradesPlus.Services.WatermarkService", "Compatibility Watermark", "SharedUpgradesWatermark", (Type _) => new Rect(6f, (float)Screen.height - 72f, 160f, 56f), "OnGUI", "show");
			RegisterImmediateModeHud("jonathan.portalrenderspike", "PortalRenderSpike.Plugin", "Portal Crosshair", "PortalCrosshair", (Type _) => new Rect((float)Screen.width * 0.5f - 16f, (float)Screen.height * 0.5f - 16f, 32f, 32f), "OnGUI", "portalMode", "holdingPortalGun");
			RegisterImmediateModeHud("dev.saturnkai.deadmapaccess", "DeadMapAccess.DeadMap", "Spectator Map", "DeadMap", GetDeadMapRect, "OnGUI", "spectating", "active");
			RegisterImmediateModeHud("Minimap", "Minimap.Plugin", "Minimap", "DigMinimap", GetMinimapRect, "OnGUI");
			RegisterImmediateModeHud("Nubez.TheEverythingMap", "TheEverythingMap.Mod.TheEverythingMap", "Minimap", "EverythingMap", GetEverythingMapRect, "OnGUI");
			RegisterImmediateModeHud("com.github.qert2002.REPO_FPSCounter", "REPO_FPSCounter.FpsCounter", "FPS Counter", "FpsCounter", (Type _) => new Rect(5f, 5f, 200f, 50f), "OnGUI");
			RegisterImmediateModeHud("zichen.moreui", "Plugin", "Info Panel (Text)", "MoreUiTextOverlay", GetMoreUiTextRect, "DrawMainTextOverlay");
		}

		private void RegisterImmediateModeHud(string pluginGuid, string componentTypeName, string displayName, string stableName, Func<Type, Rect> guiRectProvider, string methodName, params string[] previewVisibilityFieldNames)
		{
			//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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Expected O, but got Unknown
			//IL_03a4: Expected O, but got Unknown
			//IL_03a4: Expected O, but got Unknown
			if (!TryResolvePluginType(pluginGuid, componentTypeName, out var pluginInfo, out var componentType) || !typeof(MonoBehaviour).IsAssignableFrom(componentType))
			{
				return;
			}
			MethodInfo method = componentType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
			if (method == null)
			{
				return;
			}
			Func<Rect> immediateGuiRectProvider = () => guiRectProvider(componentType);
			string text = "IMGUI|" + componentType.Assembly.GetName().Name + "|" + componentType.FullName + "|" + stableName;
			if (!_elementsByStableId.TryGetValue(text, out var value) || !value.IsAlive)
			{
				string text2 = MakeConfigKey(displayName, text);
				if (!_positionEntries.TryGetValue(text, out var value2))
				{
					value2 = ((BaseUnityPlugin)_plugin).Config.Bind<string>("Positions", text2, "0, 0", "Saved screen offset for the " + displayName + " immediate-mode HUD.");
					_positionEntries.Add(text, value2);
				}
				if (!_visibilityEntries.TryGetValue(text, out var value3))
				{
					value3 = ((BaseUnityPlugin)_plugin).Config.Bind<bool>("Visibility", text2, true, "Whether the " + displayName + " immediate-mode HUD is shown.");
					_visibilityEntries.Add(text, value3);
				}
				if (!_scaleEntries.TryGetValue(text, out var value4))
				{
					value4 = ((BaseUnityPlugin)_plugin).Config.Bind<float>("Scales", text2, 1f, "Saved size multiplier for the " + displayName + " immediate-mode HUD.");
					_scaleEntries.Add(text, value4);
				}
				GameObject val = new GameObject("HUDEditor Immediate HUD - " + displayName, new Type[1] { typeof(RectTransform) })
				{
					hideFlags = (HideFlags)61
				};
				val.transform.SetParent(_hudRoot.transform, false);
				val.SetActive(false);
				RectTransform component = val.GetComponent<RectTransform>();
				value = new HudElement(component, component, displayName, text, GetPluginDisplayName(pluginInfo, componentType.Assembly), _hudRoot.transform, null, value2, value3, value4, ParseOffset(value2.Value), value3.Value, ClampScale(value4.Value), immediateGuiRectProvider, ownsTracker: true);
				_elementsByTarget[((Object)component).GetInstanceID()] = value;
				_elementsByStableId[text] = value;
				_elements.Add(value);
				Plugin.Log.LogInfo((object)("Detected immediate-mode HUD: " + displayName + " (" + componentType.FullName + ")."));
			}
			FieldInfo[] previewVisibilityFields = (from fieldName in previewVisibilityFieldNames ?? Array.Empty<string>()
				where !string.IsNullOrWhiteSpace(fieldName)
				select componentType.GetField(fieldName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) into field
				where field != null && field.FieldType == typeof(bool)
				select field).ToArray();
			ImmediateModeHudBridge.Register(method, value, previewVisibilityFields);
			if (_patchedImmediateModeMethods.Add(method))
			{
				_immediateModeHarmony.Patch((MethodBase)method, new HarmonyMethod(typeof(ImmediateModeHudBridge), "Prefix", (Type[])null), new HarmonyMethod(typeof(ImmediateModeHudBridge), "Postfix", (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(ImmediateModeHudBridge), "Finalizer", (Type[])null), (HarmonyMethod)null);
				Plugin.Log.LogInfo((object)("Enabled movable immediate-mode HUD bridge for " + componentType.FullName + "." + methodName + "()."));
			}
		}

		private static bool TryResolvePluginType(string pluginGuid, string componentTypeName, out PluginInfo pluginInfo, out Type componentType)
		{
			pluginInfo = null;
			componentType = null;
			if (!string.IsNullOrWhiteSpace(pluginGuid))
			{
				if (!Chainloader.PluginInfos.TryGetValue(pluginGuid, out pluginInfo))
				{
					pluginInfo = ((IEnumerable<PluginInfo>)Chainloader.PluginInfos.Values).FirstOrDefault((Func<PluginInfo, bool>)delegate(PluginInfo info)
					{
						object a;
						if (info == null)
						{
							a = null;
						}
						else
						{
							BepInPlugin metadata = info.Metadata;
							a = ((metadata != null) ? metadata.GUID : null);
						}
						return string.Equals((string?)a, pluginGuid, StringComparison.OrdinalIgnoreCase);
					});
				}
				PluginInfo obj = pluginInfo;
				componentType = ((obj == null) ? null : ((object)obj.Instance)?.GetType().Assembly)?.GetType(componentTypeName, throwOnError: false);
				if (componentType != null)
				{
					return true;
				}
			}
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				Type type = ((value == null) ? null : ((object)value.Instance)?.GetType().Assembly)?.GetType(componentTypeName, throwOnError: false);
				if (!(type == null))
				{
					pluginInfo = value;
					componentType = type;
					return true;
				}
			}
			return false;
		}

		private static string GetPluginDisplayName(PluginInfo pluginInfo, Assembly sourceAssembly)
		{
			object value;
			if (pluginInfo == null)
			{
				value = null;
			}
			else
			{
				BepInPlugin metadata = pluginInfo.Metadata;
				value = ((metadata != null) ? metadata.Name : null);
			}
			if (string.IsNullOrWhiteSpace((string?)value))
			{
				return GetModDisplayName(sourceAssembly);
			}
			return pluginInfo.Metadata.Name;
		}

		private static Rect GetDeadMapRect(Type componentType)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			Type? type = componentType.Assembly.GetType("DeadMapAccess.Configuration", throwOnError: false);
			float num = ReadInstanceField(componentType, "scale", 1f);
			float num2 = ReadConfigValue(type, "width", 600f) * Mathf.Max(0.01f, num);
			float num3 = ReadConfigValue(type, "height", 600f) * Mathf.Max(0.01f, num);
			float num4 = ReadConfigValue(type, "borderSize", 6);
			float num5 = ((float)Screen.width - num2) * 0.5f;
			float num6 = ((float)Screen.height - num3) * 0.5f;
			return new Rect(num5 - num4, num6 - num4, num2 + num4 * 2f, num3 + num4 * 2f);
		}

		private static Rect GetMinimapRect(Type componentType)
		{
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			Type type = componentType.Assembly.GetType("Minimap.ConfigValues", throwOnError: false);
			float num = ReadConfigValue(type, "Width", 375f);
			float num2 = ReadConfigValue(type, "Height", 375f);
			float num3 = ReadConfigValue(type, "Buffer", 12f);
			float num4;
			float num5;
			switch (ReadConfigObject(type, "Preset")?.ToString() ?? "TopRight")
			{
			case "TopLeft":
				num4 = num3;
				num5 = num3 * 2f;
				break;
			case "MiddleLeft":
				num4 = num3;
				num5 = ((float)Screen.height - num2) * 0.5f;
				break;
			case "MiddleRight":
				num4 = (float)Screen.width - num - num3;
				num5 = ((float)Screen.height - num2) * 0.5f;
				break;
			case "Manual":
			{
				Vector2 val = ReadConfigValue<Vector2>(type, "ManualPosition", Vector2.zero);
				num4 = val.x;
				num5 = val.y;
				break;
			}
			default:
				num4 = (float)Screen.width - num - num3;
				num5 = num3 * 2f;
				break;
			}
			bool flag = ReadConfigValue(type, "EnabledHintText", fallback: true);
			return new Rect(num4, num5, num, num2 + (flag ? (24f + num3 * 0.5f) : 0f));
		}

		private static Rect GetEverythingMapRect(Type componentType)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			Type? type = componentType.Assembly.GetType("TheEverythingMap.Settings.ConfigValues", throwOnError: false);
			float num = ReadConfigValue(type, "WidthHeight", 500);
			float num2 = ReadConfigValue(type, "Buffer", 12);
			float num3;
			float num4;
			switch (ReadConfigObject(type, "Preset")?.ToString() ?? "BottomLeft")
			{
			case "TopLeft":
				num3 = num2;
				num4 = num2 * 2f;
				break;
			case "MiddleRight":
				num3 = (float)Screen.width - num - num2;
				num4 = ((float)Screen.height - num) * 0.5f;
				break;
			case "TopRight":
				num3 = (float)Screen.width - num - num2;
				num4 = num2 * 2f;
				break;
			case "BottomRight":
				num3 = (float)Screen.width - num - num2;
				num4 = (float)Screen.height - num - num2;
				break;
			case "MiddleLeft":
				num3 = num2;
				num4 = ((float)Screen.height - num) * 0.5f;
				break;
			default:
				num3 = num2;
				num4 = (float)Screen.height - num - num2;
				break;
			}
			return new Rect(num3, num4, num, num);
		}

		private static Rect GetMoreUiTextRect(Type componentType)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			object pluginComponentInstance = GetPluginComponentInstance(componentType);
			FieldInfo field = componentType.GetField("cachedTextOverlayRect", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (pluginComponentInstance != null && field?.GetValue(pluginComponentInstance) is Rect result && ((Rect)(ref result)).width >= 2f && ((Rect)(ref result)).height >= 2f)
			{
				return result;
			}
			return new Rect((float)Screen.width - 332f, (float)Screen.height - 206f, 320f, 180f);
		}

		private static T ReadConfigValue<T>(Type configType, string fieldName, T fallback)
		{
			object obj = ReadConfigObject(configType, fieldName);
			if (obj is T)
			{
				return (T)obj;
			}
			try
			{
				if (obj != null)
				{
					return (T)Convert.ChangeType(obj, typeof(T), CultureInfo.InvariantCulture);
				}
			}
			catch
			{
			}
			return fallback;
		}

		private static object ReadConfigObject(Type configType, string fieldName)
		{
			object obj = (configType?.GetField(fieldName, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))?.GetValue(null);
			return obj?.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public)?.GetValue(obj, null);
		}

		private static T ReadInstanceField<T>(Type componentType, string fieldName, T fallback)
		{
			object pluginComponentInstance = GetPluginComponentInstance(componentType);
			FieldInfo fieldInfo = componentType?.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (pluginComponentInstance != null)
			{
				object obj = fieldInfo?.GetValue(pluginComponentInstance);
				if (obj is T)
				{
					return (T)obj;
				}
			}
			return fallback;
		}

		private static object GetPluginComponentInstance(Type componentType)
		{
			PluginInfo val = ((IEnumerable<PluginInfo>)Chainloader.PluginInfos.Values).FirstOrDefault((Func<PluginInfo, bool>)((PluginInfo info) => (Object)(object)((info != null) ? info.Instance : null) != (Object)null && componentType.IsInstanceOfType(info.Instance)));
			if ((Object)(object)((val != null) ? val.Instance : null) != (Object)null)
			{
				return val.Instance;
			}
			return (componentType?.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))?.GetValue(null, null);
		}

		private void RegisterAfterOneFrame(RectTransform target, RectTransform boundsRoot, Transform identityTransform, string sourceIdentity, string friendlyName, Component sourceComponent, SemiUI semiUi, string sourceModOverride = null)
		{
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)target).GetInstanceID();
			if (_elementsByTarget.ContainsKey(instanceID))
			{
				return;
			}
			Transform identityRoot = GetIdentityRoot(identityTransform);
			string hierarchyPath = GetHierarchyPath(identityRoot, identityTransform);
			string text = NormalizeObjectName(((Object)identityRoot).name) + (string.IsNullOrEmpty(hierarchyPath) ? string.Empty : ("/" + hierarchyPath));
			string text2 = sourceIdentity + "|" + text;
			if (!_elementsByStableId.TryGetValue(text2, out var value) || !value.IsAlive)
			{
				string text3 = MakeConfigKey(friendlyName, text2);
				if (!_positionEntries.TryGetValue(text2, out var value2))
				{
					value2 = ((BaseUnityPlugin)_plugin).Config.Bind<string>("Positions", text3, "0, 0", "Saved local HUD offset for " + text + ". Use RESET ALL in the editor or delete this config file to restore defaults.");
					_positionEntries.Add(text2, value2);
				}
				if (!_visibilityEntries.TryGetValue(text2, out var value3))
				{
					value3 = ((BaseUnityPlugin)_plugin).Config.Bind<bool>("Visibility", text3, true, "Whether this HUD element is shown. Use the HUD editor to change it.");
					_visibilityEntries.Add(text2, value3);
				}
				if (!_scaleEntries.TryGetValue(text2, out var value4))
				{
					value4 = ((BaseUnityPlugin)_plugin).Config.Bind<float>("Scales", text3, 1f, "Saved size multiplier for " + text + ".");
					_scaleEntries.Add(text2, value4);
				}
				Vector2 offset = ParseOffset(value2.Value);
				string text4 = (string.IsNullOrWhiteSpace(friendlyName) ? ((Object)identityTransform).name : friendlyName);
				string sourceMod = ((!string.IsNullOrWhiteSpace(sourceModOverride)) ? sourceModOverride : DetermineSourceMod(identityTransform, sourceComponent));
				HudElement hudElement = new HudElement(target, boundsRoot, text4, text2, sourceMod, _hudRoot.transform, semiUi, value2, value3, value4, offset, value3.Value, ClampScale(value4.Value));
				_elementsByTarget.Add(instanceID, hudElement);
				_elementsByStableId[text2] = hudElement;
				_elements.Add(hudElement);
				Plugin.Log.LogDebug((object)("Detected draggable HUD element: " + text4 + " (" + text + ")"));
			}
		}

		private string DetermineSourceMod(Transform identityTransform, Component sourceComponent)
		{
			Assembly assembly = (((Object)(object)sourceComponent != (Object)null) ? ((object)sourceComponent).GetType().Assembly : null);
			if (!IsExternalModAssembly(assembly))
			{
				Transform val = identityTransform;
				while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_hudRoot.transform)
				{
					Component[] components = ((Component)val).GetComponents<Component>();
					foreach (Component val2 in components)
					{
						Assembly assembly2 = (((Object)(object)val2 != (Object)null) ? ((object)val2).GetType().Assembly : null);
						if (IsExternalModAssembly(assembly2))
						{
							assembly = assembly2;
							break;
						}
					}
					if (IsExternalModAssembly(assembly))
					{
						break;
					}
					val = val.parent;
				}
			}
			if (!IsExternalModAssembly(assembly))
			{
				return "R.E.P.O.";
			}
			return GetModDisplayName(assembly);
		}

		private static string GetModDisplayName(Assembly sourceAssembly)
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if ((Object)(object)((value != null) ? value.Instance : null) != (Object)null && ((object)value.Instance).GetType().Assembly == sourceAssembly)
				{
					BepInPlugin metadata = value.Metadata;
					if (!string.IsNullOrWhiteSpace((metadata != null) ? metadata.Name : null))
					{
						return value.Metadata.Name;
					}
				}
			}
			return sourceAssembly.GetName().Name;
		}

		private static bool IsExternalModAssembly(Assembly assembly)
		{
			if (assembly == null)
			{
				return false;
			}
			string text = assembly.GetName().Name ?? string.Empty;
			if (!string.Equals(text, "Assembly-CSharp", StringComparison.OrdinalIgnoreCase) && !string.Equals(text, "HUDEditor", StringComparison.OrdinalIgnoreCase) && !string.Equals(text, "mscorlib", StringComparison.OrdinalIgnoreCase) && !string.Equals(text, "netstandard", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("System", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("Unity", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("BepInEx", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("Mono.", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("Photon", StringComparison.OrdinalIgnoreCase) && !text.StartsWith("Harmony", StringComparison.OrdinalIgnoreCase))
			{
				return !text.StartsWith("0Harmony", StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}

		private void RemoveDestroyedElements()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			for (int num = _elements.Count - 1; num >= 0; num--)
			{
				HudElement hudElement = _elements[num];
				if (!hudElement.IsAlive)
				{
					_elements.RemoveAt(num);
					_elementsByTarget.Remove(hudElement.TargetInstanceId);
					_elementsByStableId.Remove(hudElement.StableId);
					if (_selected == hudElement)
					{
						_selected = null;
					}
					if (_dragging == hudElement)
					{
						_dragging = null;
					}
					if (_resizing == hudElement)
					{
						_resizing = null;
					}
					if (_bringCandidate == hudElement)
					{
						_bringCandidate = null;
					}
					if (_previewedElement == hudElement)
					{
						_previewedElement = null;
						_previewInteractionScreenRect = default(Rect);
						_hasPreviewInteractionScreenRect = false;
					}
				}
			}
			RefreshBringOptions();
		}

		private void RefreshBringOptions()
		{
			_bringOptions.Clear();
			_bringOptions.AddRange(_elements.Where((HudElement element) => element.IsAlive).OrderBy<HudElement, string>((HudElement element) => element.SourceMod, StringComparer.OrdinalIgnoreCase).ThenBy<HudElement, string>((HudElement element) => element.DisplayName, StringComparer.OrdinalIgnoreCase)
				.ThenBy<HudElement, string>((HudElement element) => element.StableId, StringComparer.Ordinal));
			if (_bringCandidate != null && !_bringCandidate.IsAlive)
			{
				_bringCandidate = null;
			}
		}

		private void BringCandidate()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (_bringCandidate != null && _bringCandidate.IsAlive)
			{
				ClearPreview();
				_selected = _bringCandidate;
				_dragging = null;
				_previewedElement = _bringCandidate;
				_previewedElement.BeginPreview();
				RefreshPreviewInteractionRect();
				_bringMenuOpen = false;
				_bringDropdownGuiRect = default(Rect);
				Plugin.Log.LogInfo((object)("Brought HUD element '" + _previewedElement.DisplayName + "' into temporary preview."));
			}
		}

		private void ClearPreview()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (_previewedElement != null)
			{
				_previewedElement.EndPreview();
				_previewedElement = null;
				_previewInteractionScreenRect = default(Rect);
				_hasPreviewInteractionScreenRect = false;
			}
		}

		private void RefreshPreviewInteractionRect()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (_previewedElement != null && _previewedElement.TryGetScreenRect(includeHidden: true, out var result, out var _))
			{
				_previewInteractionScreenRect = result;
				_hasPreviewInteractionScreenRect = true;
			}
		}

		private void UpdatePointerInteraction()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			if (_closeConfirmationOpen || _presetDialogOpen)
			{
				return;
			}
			Vector2 val = Vector2.op_Implicit(Input.mousePosition);
			if (UpdatePanelDragging(val))
			{
				return;
			}
			bool flag = PointerIsOverPanel(val);
			if (_resizing != null)
			{
				if (Input.GetMouseButton(0))
				{
					UpdateResize(val);
				}
				if (Input.GetMouseButtonUp(0) || !Input.GetMouseButton(0))
				{
					_resizing = null;
				}
				return;
			}
			if (_bringMenuOpen && Input.GetMouseButtonDown(0) && !flag)
			{
				_bringMenuOpen = false;
				_bringDropdownGuiRect = default(Rect);
			}
			if (_dragging == null && !flag && Input.GetMouseButtonDown(0))
			{
				if (_selected != null && _selected.CanInteract && TryGetResizeCorner(_selected, val, out var corner))
				{
					BeginResize(_selected, corner);
					return;
				}
				HudElement hudElement = FindTopElementAt(val);
				if (_selected != null && _selected.ContainsScreenPoint(val))
				{
					hudElement = _selected;
				}
				if (_previewedElement != null && (_previewedElement.ContainsScreenPoint(val) || (_hasPreviewInteractionScreenRect && ((Rect)(ref _previewInteractionScreenRect)).Contains(val)) || _previewedElement.IsInSameHierarchyBranch(hudElement)))
				{
					hudElement = _previewedElement;
				}
				if (hudElement != _previewedElement)
				{
					ClearPreview();
				}
				_selected = hudElement;
				if (_selected != null)
				{
					_bringCandidate = _selected;
					Plugin.Log.LogInfo((object)("Selected HUD element '" + _selected.DisplayName + "'."));
				}
				if (_selected != null && _selected.CanInteract)
				{
					_dragging = _selected;
					_dragPointerScreenPrevious = val;
				}
			}
			if (_dragging != null && Input.GetMouseButton(0))
			{
				if (_dragging.TryScreenDeltaToParentLocal(_dragPointerScreenPrevious, val, out var parentLocalDelta) && ((Vector2)(ref parentLocalDelta)).sqrMagnitude > 0.0001f)
				{
					_dragging.SetOffset(_dragging.Offset + parentLocalDelta);
				}
				_dragPointerScreenPrevious = val;
			}
			if (_dragging != null && Input.GetMouseButtonUp(0))
			{
				_dragging = null;
			}
		}

		private bool TryGetResizeCorner(HudElement element, Vector2 pointer, out ResizeCorner corner)
		{
			//IL_0083: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			corner = ResizeCorner.None;
			if (element == null || !element.TryGetScreenRect(includeHidden: true, out var result, out var _))
			{
				return false;
			}
			float editorUiScale = GetEditorUiScale();
			float armLength = Mathf.Clamp(23f * editorUiScale, 20f, 32f);
			float thickness = Mathf.Clamp(7f * editorUiScale, 6f, 10f);
			float amount = Mathf.Clamp(5f * editorUiScale, 4f, 7f);
			ResizeCorner[] array = new ResizeCorner[4]
			{
				ResizeCorner.BottomLeft,
				ResizeCorner.BottomRight,
				ResizeCorner.TopLeft,
				ResizeCorner.TopRight
			};
			int num = 0;
			while (num < array.Length)
			{
				ResizeCorner resizeCorner = array[num];
				Vector2 cornerPoint = GetCornerPoint(result, resizeCorner);
				float horizontalDirection = ((resizeCorner == ResizeCorner.BottomLeft || resizeCorner == ResizeCorner.TopLeft) ? 1f : (-1f));
				float verticalDirection = ((resizeCorner == ResizeCorner.BottomLeft || resizeCorner == ResizeCorner.BottomRight) ? 1f : (-1f));
				CreateHandleArmRects(cornerPoint, horizontalDirection, verticalDirection, armLength, thickness, out var horizontal, out var vertical);
				Rect val = ExpandRect(horizontal, amount);
				if (!((Rect)(ref val)).Contains(pointer))
				{
					val = ExpandRect(vertical, amount);
					if (!((Rect)(ref val)).Contains(pointer))
					{
						num++;
						continue;
					}
				}
				corner = resizeCorner;
				return true;
			}
			return false;
		}

		private void BeginResize(HudElement element, ResizeCorner corner)
		{
			//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)
			//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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (element != null && corner != ResizeCorner.None && element.TryGetScreenRect(includeHidden: true, out var result, out var _))
			{
				_dragging = null;
				_resizing = element;
				_resizeCorner = corner;
				_resizeMovingStartScreenPoint = GetCornerPoint(result, corner);
				_resizePointerStartScreenPoint = Vector2.op_Implicit(Input.mousePosition);
				_resizeFixedScreenPoint = GetCornerPoint(result, GetOppositeCorner(corner));
				_resizeStartScale = element.Scale;
				Plugin.Log.LogInfo((object)("Resizing HUD element '" + element.DisplayName + "'."));
			}
		}

		private void UpdateResize(Vector2 pointer)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			if (_resizing == null)
			{
				return;
			}
			Vector2 val = _resizeMovingStartScreenPoint - _resizeFixedScreenPoint;
			float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude;
			if (sqrMagnitude < 4f)
			{
				return;
			}
			float num = 1f + Vector2.Dot(pointer - _resizePointerStartScreenPoint, val) / sqrMagnitude;
			float scale = Mathf.Clamp(_resizeStartScale * num, 0.25f, 4f);
			_resizing.SetScale(scale);
			if (_resizing.TryGetScreenRect(includeHidden: true, out var result, out var _))
			{
				Vector2 cornerPoint = GetCornerPoint(result, GetOppositeCorner(_resizeCorner));
				if (_resizing.TryScreenDeltaToParentLocal(cornerPoint, _resizeFixedScreenPoint, out var parentLocalDelta))
				{
					_resizing.SetOffset(_resizing.Offset + parentLocalDelta);
				}
			}
			RefreshPreviewInteractionRect();
		}

		private static Vector2 GetCornerPoint(Rect rect, ResizeCorner corner)
		{
			//IL_0028: 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_0050: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			return (Vector2)(corner switch
			{
				ResizeCorner.BottomLeft => new Vector2(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMin), 
				ResizeCorner.BottomRight => new Vector2(((Rect)(ref rect)).xMax, ((Rect)(ref rect)).yMin), 
				ResizeCorner.TopLeft => new Vector2(((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMax), 
				ResizeCorner.TopRight => new Vector2(((Rect)(ref rect)).xMax, ((Rect)(ref rect)).yMax), 
				_ => ((Rect)(ref rect)).center, 
			});
		}

		private static ResizeCorner GetOppositeCorner(ResizeCorner corner)
		{
			return corner switch
			{
				ResizeCorner.BottomLeft => ResizeCorner.TopRight, 
				ResizeCorner.BottomRight => ResizeCorner.TopLeft, 
				ResizeCorner.TopLeft => ResizeCorner.BottomRight, 
				ResizeCorner.TopRight => ResizeCorner.BottomLeft, 
				_ => ResizeCorner.None, 
			};
		}

		private HudElement FindTopElementAt(Vector2 pointer)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			HudElement result = null;
			int num = int.MinValue;
			float num2 = float.MaxValue;
			foreach (HudElement element in _elements)
			{
				if (element.CanInteract && element.TryGetScreenRect(includeHidden: false, out var result2, out var depth) && ((Rect)(ref result2)).Contains(pointer))
				{
					float num3 = ((Rect)(ref result2)).width * ((Rect)(ref result2)).height;
					if (num3 < num2 || (Mathf.Approximately(num3, num2) && depth > num))
					{
						result = element;
						num = depth;
						num2 = num3;
					}
				}
			}
			return result;
		}

		internal void RestoreAllOffsets()
		{
			foreach (HudElement element in _elements)
			{
				if (element.HasAppliedOffset)
				{
					element.RestoreBasePosition();
				}
			}
		}

		private void ApplyAllOffsets()
		{
			foreach (HudElement element in _elements)
			{
				if (element.NeedsOffsetApplication)
				{
					element.ApplyOffset();
				}
			}
		}

		private void SaveAllChanges()
		{
			foreach (HudElement element in _elements)
			{
				element.Save();
			}
			Plugin plugin = _plugin;
			if (plugin != null)
			{
				((BaseUnityPlugin)plugin).Config.Save();
			}
			_closeConfirmationOpen = false;
			Plugin.Log.LogInfo((object)$"Saved {_elements.Count} HUD element settings.");
		}

		private void DiscardAllChanges()
		{
			foreach (HudElement element in _elements)
			{
				element.RestoreSavedState();
			}
		}

		private void ResetAllElements()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			ClearPreview();
			foreach (HudElement element in _elements)
			{
				element.SetOffset(Vector2.zero);
				element.SetScale(1f);
				element.SetVisible(visible: true);
			}
			Plugin.Log.LogInfo((object)$"Reset {_elements.Count} HUD elements. Press SAVE to keep the reset.");
		}

		private void ShowAllHiddenElements()
		{
			ClearPreview();
			foreach (HudElement element in _elements)
			{
				element.SetVisible(visible: true);
			}
			Plugin.Log.LogInfo((object)"Revealed all hidden HUD elements. Press SAVE to keep this change.");
		}

		private void DisposeAllElements()
		{
			foreach (HudElement element in _elements)
			{
				element.Dispose();
			}
		}

		private static bool ShouldSkipSemiUi(SemiUI semiUi)
		{
			if (semiUi is InventorySpot && (Object)(object)((Component)semiUi).GetComponentInParent<InventoryUI>() != (Object)null)
			{
				return true;
			}
			if (((object)semiUi).GetType() == typeof(SemiUI))
			{
				SemiUI[] componentsInChildren = ((Component)semiUi).GetComponentsInChildren<SemiUI>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)(object)semiUi && ((object)componentsInChildren[i]).GetType() != typeof(SemiUI))
					{
						return true;
					}
				}
			}
			return false;
		}

		private bool IsEditableHudTransform(Transform transform)
		{
			if ((Object)(object)transform == (Object)null || (Object)(object)_hudRoot == (Object)null || ((Object)(object)transform != (Object)(object)_hudRoot.transform && !transform.IsChildOf(_hudRoot.transform)))
			{
				return false;
			}
			bool result = false;
			Transform val = transform;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)_hudRoot.transform)
			{
				string text = NormalizeObjectName(((Object)val).name);
				if (IsBackgroundName(text) || text.IndexOf("Menu Selection Outline", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return false;
				}
				if ((Object)(object)val.parent == (Object)(object)_hudRoot.transform && (string.Equals(text, "HUD", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "Hide Parent", StringComparison.OrdinalIgnoreCase)))
				{
					result = true;
				}
				val = val.parent;
			}
			return result;
		}

		private static bool IsBackgroundName(string objectName)
		{
			if (!string.Equals(objectName, "Background", StringComparison.OrdinalIgnoreCase) && !objectName.StartsWith("Background ", StringComparison.OrdinalIgnoreCase) && !string.Equals(objectName, "Bg", StringComparison.OrdinalIgnoreCase))
			{
				return objectName.StartsWith("Bg (", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool IsActiveSceneComponent(Component component)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)component != (Object)null)
			{
				Scene scene = component.gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					return component.gameObject.activeInHierarchy;
				}
			}
			return false;
		}

		private static bool IsSceneComponent(Component component)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)component != (Object)null)
			{
				Scene scene = component.gameObject.scene;
				return ((Scene)(ref scene)).IsValid();
			}
			return false;
		}

		private static bool IsExcludedUiTransform(Transform transform)
		{
			if ((Object)(object)transform == (Object)null || (Object)(object)((Component)transform).GetComponentInParent<WorldSpaceUIParent>() != (Object)null || (Object)(object)((Component)transform).GetComponentInParent<MenuCursor>() != (Object)null || (Object)(object)((Component)transform).GetComponentInParent<MenuPage>() != (Object)null || (Object)(object)((Component)transform).GetComponentInParent<MenuHolder>() != (Object)null)
			{
				return true;
			}
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				string text = ((Object)val).name ?? string.Empty;
				if (text.IndexOf("Debug Console", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("DebugConsole", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Render Texture Overlay", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
				Component[] components = ((Component)val).GetComponents<Component>();
				foreach (Component val2 in components)
				{
					if ((Object)(object)val2 != (Object)null && ((object)val2).GetType().Name.IndexOf("DebugConsole", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return true;
					}
				}
				val = val.parent;
			}
			return false;
		}

		private static bool IsGraphicEffectivelyVisible(Graphic graphic)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)graphic == (Object)null || !((Behaviour)graphic).enabled || graphic.color.a <= 0.01f)
			{
				return false;
			}
			RawImage val = (RawImage)(object)((graphic is RawImage) ? graphic : null);
			if (val != null && val.texture is RenderTexture)
			{
				return false;
			}
			TMP_Text val2 = (TMP_Text)(object)((graphic is TMP_Text) ? graphic : null);
			if (val2 != null && string.IsNullOrWhiteSpace(val2.text))
			{
				return false;
			}
			Text val3 = (Text)(object)((graphic is Text) ? graphic : null);
			if (val3 != null && string.IsNullOrWhiteSpace(val3.text))
			{
				return false;
			}
			CanvasGroup[] componentsInParent = ((Component)graphic).GetComponentsInParent<CanvasGroup>(true);
			for (int i = 0; i < componentsInParent.Length; i++)
			{
				if (componentsInParent[i].alpha <= 0.01f)
				{
					return false;
				}
			}
			return true;
		}

		private static Transform GetIdentityRoot(Transform transform)
		{
			Canvas componentInParent = ((Component)transform).GetComponentInParent<Canvas>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return transform.root;
			}
			return ((Component)componentInParent).transform;
		}

		private static string GetHierarchyPath(Transform root, Transform target)
		{
			Stack<string> stack = new Stack<string>();
			Transform val = target;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				string text = NormalizeObjectName(((Object)val).name);
				int num = 0;
				if ((Object)(object)val.parent != (Object)null)
				{
					for (int i = 0; i < val.GetSiblingIndex(); i++)
					{
						if (NormalizeObjectName(((Object)val.parent.GetChild(i)).name) == text)
						{
							num++;
						}
					}
				}
				stack.Push((num == 0) ? text : (text + "[" + num + "]"));
				val = val.parent;
			}
			return string.Join("/", stack);
		}

		private static string NormalizeObjectName(string name)
		{
			if (!string.IsNullOrEmpty(name))
			{
				return name.Replace("(Clone)", string.Empty).Trim();
			}
			return "Unnamed";
		}

		private static string MakeFriendlyName(string rawName)
		{
			if (string.IsNullOrWhiteSpace(rawName))
			{
				return "HUD Element";
			}
			string text = NormalizeObjectName(rawName);
			if (text.EndsWith("UI", StringComparison.Ordinal) && text.Length > 2)
			{
				text = text.Substring(0, text.Length - 2);
			}
			StringBuilder stringBuilder = new StringBuilder(text.Length + 8);
			for (int i = 0; i < text.Length; i++)
			{
				char c = text[i];
				if (i > 0 && char.IsUpper(c) && (char.IsLower(text[i - 1]) || char.IsDigit(text[i - 1])))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append((c == '_') ? ' ' : c);
			}
			return stringBuilder.ToString().Trim();
		}

		private static string MakeConfigKey(string friendlyName, string stableId)
		{
			string text = new string(friendlyName.Where((char character) => char.IsLetterOrDigit(character) || character == ' ' || character == '-').ToArray()).Trim().Replace(' ', '_');
			if (string.IsNullOrEmpty(text))
			{
				text = "HUD_Element";
			}
			uint num = 2166136261u;
			foreach (char c in stableId)
			{
				num ^= c;
				num *= 16777619;
			}
			return text + "_" + num.ToString("X8", CultureInfo.InvariantCulture);
		}

		private static Vector2 ParseOffset(string value)
		{
			//IL_0008: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(value))
			{
				return Vector2.zero;
			}
			string[] array = value.Split(',');
			if (array.Length == 2 && float.TryParse(array[0].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result) && float.TryParse(array[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result2) && !float.IsNaN(result) && !float.IsInfinity(result) && !float.IsNaN(result2) && !float.IsInfinity(result2))
			{
				return new Vector2(result, result2);
			}
			return Vector2.zero;
		}

		internal static float ClampScale(float value)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return Mathf.Clamp(value, 0.25f, 4f);
			}
			return 1f;
		}

		private Rect GetPanelGuiRect()
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			float editorUiScale = GetEditorUiScale();
			float num = 600f * editorUiScale;
			float num2 = 301f * editorUiScale;
			if (!_panelPositionInitialized)
			{
				_panelGuiRect = new Rect(Mathf.Max(0f, ((float)Screen.width - num) * 0.5f), Mathf.Max(0f, ((float)Screen.height - num2) * 0.5f), num, num2);
				_panelPositionInitialized = true;
			}
			((Rect)(ref _panelGuiRect)).x = Mathf.Clamp(((Rect)(ref _panelGuiRect)).x, 0f, Mathf.Max(0f, (float)Screen.width - num));
			((Rect)(ref _panelGuiRect)).y = Mathf.Clamp(((Rect)(ref _panelGuiRect)).y, 0f, Mathf.Max(0f, (float)Screen.height - num2));
			((Rect)(ref _panelGuiRect)).width = num;
			((Rect)(ref _panelGuiRect)).height = num2;
			return _panelGuiRect;
		}

		private bool PointerIsOverPanel(Vector2 screenPointer)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			Rect val = GuiToScreenRect(GetPanelGuiRect());
			if (((Rect)(ref val)).Contains(screenPointer))
			{
				return true;
			}
			if (_bringMenuOpen && ((Rect)(ref _bringDropdownGuiRect)).width > 0f)
			{
				Rect val2 = GuiToScreenRect(_bringDropdownGuiRect);
				return ((Rect)(ref val2)).Contains(screenPointer);
			}
			return false;
		}

		private bool UpdatePanelDragging(Vector2 screenPointer)
		{
			//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_013a: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			Rect panelGuiRect = GetPanelGuiRect();
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref panelGuiRect)).x, (float)Screen.height - ((Rect)(ref panelGuiRect)).y - ((Rect)(ref panelGuiRect)).height, ((Rect)(ref panelGuiRect)).width, ((Rect)(ref panelGuiRect)).height);
			if (_panelDragging)
			{
				if (!Input.GetMouseButton(0))
				{
					_panelDragging = false;
					return true;
				}
				float x = Mathf.Clamp(screenPointer.x - _panelDragScreenOffset.x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref panelGuiRect)).width));
				float num = Mathf.Clamp(screenPointer.y - _panelDragScreenOffset.y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref panelGuiRect)).height));
				((Rect)(ref _panelGuiRect)).x = x;
				((Rect)(ref _panelGuiRect)).y = (float)Screen.height - num - ((Rect)(ref panelGuiRect)).height;
				_bringMenuOpen = false;
				_bringDropdownGuiRect = default(Rect);
				return true;
			}
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(((Rect)(ref val)).x, ((Rect)(ref val)).yMax - 48f * GetEditorUiScale(), ((Rect)(ref val)).width, 48f * GetEditorUiScale());
			if (Input.GetMouseButtonDown(0) && ((Rect)(ref val2)).Contains(screenPointer))
			{
				_panelDragging = true;
				_panelDragScreenOffset = screenPointer - ((Rect)(ref val)).position;
				return true;
			}
			return false;
		}

		private static Rect ScreenToGuiRect(Rect screenRect)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(((Rect)(ref screenRect)).x, (float)Screen.height - ((Rect)(ref screenRect)).yMax, ((Rect)(ref screenRect)).width, ((Rect)(ref screenRect)).height);
		}

		private static Rect GuiToScreenRect(Rect guiRect)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(((Rect)(ref guiRect)).x, (float)Screen.height - ((Rect)(ref guiRect)).y - ((Rect)(ref guiRect)).height, ((Rect)(ref guiRect)).width, ((Rect)(ref guiRect)).height);
		}

		private static float GetEditorUiScale()
		{
			return Mathf.Clamp((float)Screen.height / 1080f, 0.85f, 1.35f);
		}

		private void EnsureGuiStyles(float scale)
		{
			//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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0040: 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_0061: 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_0074: Expected O, but got Unknown
			//IL_0093: 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_00ad: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: 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_021c: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			if (_panelTitleStyle == null)
			{
				_panelTitleStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					clipping = (TextClipping)1,
					fontStyle = (FontStyle)1
				};
				_panelTitleStyle.normal.textColor = Color.white;
				_panelSelectionStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					clipping = (TextClipping)1,
					fontStyle = (FontStyle)1
				};
				_panelSelectionStyle.normal.textColor = new Color(0.86f, 0.94f, 0.98f, 1f);
				_panelButtonStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					clipping = (TextClipping)1,
					fontStyle = (FontStyle)1
				};
				_panelButtonStyle.normal.textColor = Color.white;
				_panelButtonStyle.hover.textColor = Color.white;
				_panelButtonStyle.active.textColor = Color.white;
				_panelButtonStyle.focused.textColor = Color.white;
				_panelBadgeStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					clipping = (TextClipping)1,
					fontStyle = (FontStyle)1
				};
				_panelBadgeStyle.normal.textColor = Color.white;
				_dialogBodyStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					clipping = (TextClipping)1
				};
				_dialogBodyStyle.normal.textColor = new Color(0.85f, 0.9f, 0.93f, 1f);
				_groupHeaderStyle = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)3,
					clipping = (TextClipping)1,
					fontStyle = (FontStyle)1
				};
				_groupHeaderStyle.normal.textColor = new Color(0.27f, 0.8f, 1f, 1f);
				_presetTextFieldStyle = new GUIStyle(GUI.skin.textField)
				{
					alignment = (TextAnchor)3,
					clipping = (TextClipping)1
				};
				_presetTextFieldStyle.normal.textColor = Color.white;
			}
			_panelTitleStyle.fontSize = Mathf.RoundToInt(22f * scale);
			_panelSelectionStyle.fontSize = Mathf.RoundToInt(16f * scale);
			_panelButtonStyle.fontSize = Mathf.RoundToInt(13f * scale);
			_panelBadgeStyle.fontSize = Mathf.RoundToInt(12f * scale);
			_dialogBodyStyle.fontSize = Mathf.RoundToInt(16f * scale);
			_groupHeaderStyle.fontSize = Mathf.RoundToInt(12f * scale);
			_presetTextFieldStyle.fontSize = Mathf.RoundToInt(15f * scale);
		}

		private bool DrawPanelButton(Rect rect, string label, Color baseColor, bool enabled)
		{
			//IL_002f: 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_0083: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _closeConfirmationOpen || _presetDialogOpen;
			int num;
			int num2;
			if (enabled)
			{
				if (flag)
				{
					num = (_drawingModalControls ? 1 : 0);
					if (num == 0)
					{
						goto IL_003b;
					}
				}
				else
				{
					num = 1;
				}
				num2 = (((Rect)(ref rect)).Contains(Event.current.mousePosition) ? 1 : 0);
				goto IL_003c;
			}
			num = 0;
			goto IL_003b;
			IL_003c:
			bool flag2 = (byte)num2 != 0;
			bool flag3 = flag2 && Input.GetMouseButton(0);
			Color val = (Color)((num == 0) ? new Color(0.075f, 0.09f, 0.105f, 0.9f) : (flag3 ? Color.Lerp(baseColor, Color.black, 0.16f) : (flag2 ? Color.Lerp(baseColor, Color.white, 0.13f) : baseColor)));
			Color color = (Color)((num != 0) ? Col