Decompiled source of OssieCustomColors v1.2.0

BepInEx/plugins/OssieCustomColors/OssieCustomColors.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cinnamon;
using GameEvent;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AutoUpdate("Osqat/OssieCustomColors")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
namespace OssieCustomColors;

public class ColorPickerUI : MonoBehaviour, InputReceiver, IGameEventListener
{
	private class CanvasSwatch
	{
		public RectTransform Root;

		public Image Fill;

		public Image Border;

		public RectTransform DeleteRoot;

		public Image DeleteBg;

		public Text DeleteText;
	}

	private int _maxColors;

	private bool _customMode;

	private List<Color> _savedColors;

	private int _selectedIdx = -1;

	private PickableCustomizationButton[] _allColorBtns;

	private PickableCustomizationButton[] _allBlockColorBtns;

	private SpriteRenderer[] _colorBtnRenderers;

	private int _rightmostBtnIdx;

	private float _btnW;

	private float _btnH;

	private bool _layoutReady;

	private bool _nativeButtonsHidden;

	private bool _nativeVisibilityDirty = true;

	private bool _open;

	private bool _bookOpen;

	private bool _deleteMode;

	private int _editingSavedColorIndex = -1;

	private InventoryBook _inventoryBookCache;

	private float _r;

	private float _g;

	private float _b;

	private float _h;

	private float _s;

	private float _v;

	private string _hexInput = "FFFFFF";

	private bool _loggedColorSpace;

	private Texture2D _svTex;

	private Texture2D _hueTex;

	private Color[] _svPixels;

	private float _lastHueForSvTex = -1f;

	private bool _svDragging;

	private bool _hueDragging;

	private readonly Dictionary<string, Color> _calibratedBackendColors = new Dictionary<string, Color>();

	private Color _lastDisplayColor = Color.white;

	private Color _lastBackendColor = Color.white;

	private string _lastDisplayHex = "";

	private string _lastBackendHex = "";

	private readonly Color[] _nearestBackendColors = (Color[])(object)new Color[8];

	private readonly Color[] _nearestDisplayColors = (Color[])(object)new Color[8];

	private readonly float[] _nearestDistances = new float[8];

	private bool _eyedropperActive;

	private bool _pendingReopenPicker;

	private bool _reopenGotoRequested;

	private bool _eyedropperCancelQueued;

	private int _eyedropperPlayerNumber;

	private int _pendingColorPageNumber = -1;

	private Controller _eyedropperController;

	private bool _stylesReady;

	private Font _font;

	private GUIStyle _titleStyle;

	private GUIStyle _labelStyle;

	private GUIStyle _btnStyle;

	private GUIStyle _actionBtnStyle;

	private GUIStyle _fieldStyle;

	private GUIStyle _toggleStyle;

	private GUIStyle _plusStyle;

	private GUIStyle _xStyle;

	private Texture2D _texPanel;

	private Texture2D _texBtn;

	private Texture2D _texBtnHov;

	private Texture2D _texSwatch;

	private Texture2D _texWhite;

	private Texture2D _texDark;

	private Texture2D _texAccent;

	private Canvas _uiCanvas;

	private RectTransform _canvasRect;

	private RectTransform _uiRoot;

	private InventoryPage _uiPage;

	private bool _uiBuilt;

	private bool _ownsUiCanvas;

	private Sprite _uiSprite;

	private bool _uiUsesInventoryCamera;

	private bool _loggedCanvasConfig;

	private bool _syncingHexField;

	private RectTransform _toggleRt;

	private Image _toggleBg;

	private Text _toggleText;

	private Rect _toggleGuiRect;

	private Image _trashBg;

	private Image _trashCanBody;

	private Image _trashCanLid;

	private RectTransform _trashRt;

	private Rect _trashGuiRect;

	private Image _plusBg;

	private Text _plusText;

	private RectTransform _plusRt;

	private Rect _plusGuiRect;

	private readonly List<CanvasSwatch> _swatchViews = new List<CanvasSwatch>();

	private readonly List<Rect> _swatchGuiRects = new List<Rect>();

	private readonly List<Rect> _editGuiRects = new List<Rect>();

	private readonly List<Graphic> _pickerGraphics = new List<Graphic>();

	private readonly List<PickableCustomizationButton> _buttonBuildBuffer = new List<PickableCustomizationButton>();

	private readonly List<PickableCustomizationButton> _blockColorBuildBuffer = new List<PickableCustomizationButton>();

	private readonly List<PickCursor> _cachedCursorRendererCursors = new List<PickCursor>();

	private readonly List<SpriteRenderer> _cachedCursorRenderers = new List<SpriteRenderer>();

	private RectTransform _pickerRoot;

	private Image _pickerPanelBg;

	private Text _pickerTitle;

	private RawImage _svRaw;

	private RawImage _hueRaw;

	private Image _svCursorOuter;

	private Image _svCursorInner;

	private Image _hueMarkerOuter;

	private Image _hueMarkerInner;

	private Text _hexLabel;

	private InputField _hexField;

	private Image _hexBg;

	private Image _previewImage;

	private Image _useBg;

	private Image _saveBg;

	private Image _pickBg;

	private Image _pickIconHandle;

	private Image _pickIconTip;

	private Image _cancelBg;

	private Text _useText;

	private Text _saveText;

	private Text _cancelText;

	private RectTransform _useRt;

	private RectTransform _saveRt;

	private RectTransform _pickRt;

	private RectTransform _cancelRt;

	private Rect _panelGuiRect;

	private Rect _svGuiRect;

	private Rect _hueGuiRect;

	private Rect _hexGuiRect;

	private Rect _useGuiRect;

	private Rect _saveGuiRect;

	private Rect _pickGuiRect;

	private Rect _cancelGuiRect;

	private int _acceptPressedFrame = -999;

	private int _acceptConsumedFrame = -999;

	private int _acceptReleasedFrame = -999;

	private bool _acceptHeld;

	private Controller _acceptSender;

	private static readonly Color ColPanel = new Color(0.06f, 0.06f, 0.08f, 0.97f);

	private static readonly Color ColTitle = Color.white;

	private static readonly Color ColBody = new Color(0.78f, 0.8f, 0.84f, 1f);

	private static readonly Color ColBtn = new Color(1f, 0.82f, 0.3f, 1f);

	private static readonly Color ColBtnHov = new Color(1f, 0.9f, 0.5f, 1f);

	private static readonly Color ColBtnText = new Color(0.1f, 0.09f, 0.06f, 1f);

	private static readonly Color ColDark = new Color(0.1f, 0.1f, 0.12f, 0.95f);

	private static readonly Color ColAccent = new Color(0.3f, 0.65f, 1f, 0.95f);

	private static readonly Color ColDanger = new Color(1f, 0.18f, 0.14f, 0.95f);

	public static ColorPickerUI Instance { get; private set; }

	private void Awake()
	{
		Instance = this;
		Controller.AddGlobalReceiver((InputReceiver)(object)this);
		GameEventManager.ChangeListener<PauseEvent>((IGameEventListener)(object)this, true);
		GameEventManager.ChangeListener<SoftPauseEvent>((IGameEventListener)(object)this, true);
		LoadColors();
	}

	private void OnDestroy()
	{
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
		Controller.RemoveGlobalReceiver((InputReceiver)(object)this);
		GameEventManager.ChangeListener<PauseEvent>((IGameEventListener)(object)this, false);
		GameEventManager.ChangeListener<SoftPauseEvent>((IGameEventListener)(object)this, false);
		DestroyCanvasUi();
		if ((Object)(object)_uiSprite != (Object)null)
		{
			Object.Destroy((Object)(object)_uiSprite);
		}
		if ((Object)(object)_svTex != (Object)null)
		{
			Object.Destroy((Object)(object)_svTex);
		}
		if ((Object)(object)_hueTex != (Object)null)
		{
			Object.Destroy((Object)(object)_hueTex);
		}
	}

	private static bool IsFreeplay()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Invalid comparison between Unknown and I4
		GameSettings instance = GameSettings.GetInstance();
		if ((Object)(object)instance != (Object)null)
		{
			return (int)instance.GameMode == 0;
		}
		return false;
	}

	private void Update()
	{
		bool flag = IsFreeplay();
		if ((Object)(object)_inventoryBookCache == (Object)null)
		{
			_inventoryBookCache = Object.FindObjectOfType<InventoryBook>();
		}
		bool flag2 = (Object)(object)_inventoryBookCache != (Object)null && ((Component)_inventoryBookCache).gameObject.activeInHierarchy && _inventoryBookCache.Visible;
		if (flag2 && !_bookOpen)
		{
			_bookOpen = true;
			_open = false;
			InvalidateButtonCache(restoreNatives: true);
		}
		else if (!flag2 && _bookOpen)
		{
			_bookOpen = false;
			_open = false;
			InvalidateButtonCache(restoreNatives: true);
		}
		if (!flag || !_bookOpen)
		{
			_open = false;
			SetCanvasVisible(visible: false);
			SetPickerGraphicsVisible(visible: false);
			if (!flag && _customMode)
			{
				_customMode = false;
				_open = false;
				CancelEyedropperMode(reopenPicker: false);
				_nativeVisibilityDirty = true;
				SyncNativesToMode();
			}
			return;
		}
		HandlePendingPickerReopen();
		if (_open && Input.GetKeyDown((KeyCode)27))
		{
			_open = false;
		}
		RefreshButtons();
		bool flag3 = _layoutReady && IsColorPageActive();
		if (!flag3)
		{
			_open = false;
		}
		else
		{
			HandlePendingPickerReopen();
		}
		SyncNativesToMode();
		UpdateCanvasUi(flag3);
	}

	public void OnBookShown()
	{
		_bookOpen = true;
		_open = false;
		_inventoryBookCache = null;
		InvalidateButtonCache(restoreNatives: true);
	}

	public void OnBookHidden()
	{
		_bookOpen = false;
		_open = false;
		InvalidateButtonCache(restoreNatives: true);
		SetCanvasVisible(visible: false);
	}

	public void Open(Color current)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		_r = current.r;
		_g = current.g;
		_b = current.b;
		Color.RGBToHSV(current, ref _h, ref _s, ref _v);
		_lastHueForSvTex = -1f;
		_hexInput = ToHex(_r, _g, _b);
		_open = true;
	}

	private void OnGUI()
	{
		if (_eyedropperActive)
		{
			DrawEyedropperOverlay();
		}
		if (IsFreeplay())
		{
			_ = _bookOpen;
		}
	}

	void IGameEventListener.handleEvent(GameEvent e)
	{
		if (!_eyedropperActive || e == null)
		{
			return;
		}
		PauseEvent val = (PauseEvent)(object)((e is PauseEvent) ? e : null);
		if (val != null && val.Paused)
		{
			ClearEyedropperStateOnly();
			return;
		}
		SoftPauseEvent val2 = (SoftPauseEvent)(object)((e is SoftPauseEvent) ? e : null);
		if (val2 != null && val2.SoftPaused)
		{
			ClearEyedropperStateOnly();
		}
	}

	private void DrawEyedropperOverlay()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: 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_007a: Expected O, but got Unknown
		//IL_00a6: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		EnsureStyles();
		if (_stylesReady)
		{
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((float)Screen.width - 760f) * 0.5f, 20f, 760f, 250f);
			GUI.DrawTexture(val, (Texture)(object)(((Object)(object)_texPanel != (Object)null) ? _texPanel : Texture2D.whiteTexture));
			GUIStyle val2 = new GUIStyle(_labelStyle)
			{
				fontSize = 16,
				wordWrap = true,
				alignment = (TextAnchor)0
			};
			GUI.Label(new Rect(((Rect)(ref val)).x + 20f, ((Rect)(ref val)).y + 14f, ((Rect)(ref val)).width - 40f, 34f), "OCC EYEDROPPER MODE", _titleStyle);
			GUI.Label(new Rect(((Rect)(ref val)).x + 30f, ((Rect)(ref val)).y + 62f, ((Rect)(ref val)).width - 60f, 44f), "Hover a placed colorable block and click / press Accept to copy its color.", val2);
			GUI.Label(new Rect(((Rect)(ref val)).x + 30f, ((Rect)(ref val)).y + 116f, ((Rect)(ref val)).width - 60f, 44f), "Click empty space to cancel and return to OCC without changing color.", val2);
			GUI.Label(new Rect(((Rect)(ref val)).x + 30f, ((Rect)(ref val)).y + 170f, ((Rect)(ref val)).width - 60f, 52f), "Back / B cancels and returns to the OCC color picker. Escape is disabled in this mode.", val2);
		}
	}

	private void InvalidateButtonCache(bool restoreNatives)
	{
		if (restoreNatives)
		{
			SetNativeButtonsVisible(visible: true);
		}
		_allColorBtns = null;
		_allBlockColorBtns = null;
		_colorBtnRenderers = null;
		_layoutReady = false;
		_btnW = (_btnH = 0f);
		_nativeVisibilityDirty = true;
		ClearCursorRendererCache();
	}

	private void RefreshButtons()
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		if (_layoutReady && _allColorBtns != null && _allColorBtns.Length != 0 && (Object)(object)_allColorBtns[0] != (Object)null && IsCurrentColorPageButton(_allColorBtns[0]))
		{
			return;
		}
		InvalidateButtonCache(restoreNatives: true);
		_buttonBuildBuffer.Clear();
		_blockColorBuildBuffer.Clear();
		PickableCustomizationButton[] array = Object.FindObjectsOfType<PickableCustomizationButton>(true);
		foreach (PickableCustomizationButton val in array)
		{
			if (!((Object)(object)val == (Object)null) && (int)val.customizationType == 0)
			{
				_blockColorBuildBuffer.Add(val);
				if (IsCurrentColorPageButton(val))
				{
					_buttonBuildBuffer.Add(val);
				}
			}
		}
		if (_blockColorBuildBuffer.Count > 0)
		{
			_allBlockColorBtns = _blockColorBuildBuffer.ToArray();
		}
		_buttonBuildBuffer.Sort(CompareColorButtonsForLayout);
		PickableCustomizationButton[] array2 = _buttonBuildBuffer.ToArray();
		if (array2.Length == 0)
		{
			return;
		}
		Plugin.Log.LogInfo((object)$"[OssieCustomColors] RefreshButtons: {array2.Length} current-page BlockColors buttons found");
		_allColorBtns = array2;
		_colorBtnRenderers = (SpriteRenderer[])(object)new SpriteRenderer[_allColorBtns.Length];
		Camera val2 = InventoryLayoutCamera();
		if ((Object)(object)val2 == (Object)null)
		{
			InvalidateButtonCache(restoreNatives: false);
			return;
		}
		if (!TryUpdateButtonSize(val2, keepLargest: false))
		{
			InvalidateButtonCache(restoreNatives: false);
			_btnW = (_btnH = 0f);
			return;
		}
		_rightmostBtnIdx = 0;
		float num = float.MinValue;
		for (int j = 0; j < _allColorBtns.Length; j++)
		{
			float x = val2.WorldToScreenPoint(((Component)_allColorBtns[j]).transform.position).x;
			if (x > num)
			{
				num = x;
				_rightmostBtnIdx = j;
			}
		}
		_maxColors = Mathf.Max(1, _allColorBtns.Length - 1);
		_layoutReady = true;
		_nativeVisibilityDirty = true;
		Plugin.Log.LogInfo((object)$"[OssieCustomColors] Layout ready: {_allColorBtns.Length} buttons, max={_maxColors}, size={_btnW:F1}x{_btnH:F1}px, rightmost={_rightmostBtnIdx}");
	}

	private static int CompareColorButtonsForLayout(PickableCustomizationButton a, PickableCustomizationButton b)
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0040: 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)
		if ((Object)(object)a == (Object)(object)b)
		{
			return 0;
		}
		if ((Object)(object)a == (Object)null)
		{
			return 1;
		}
		if ((Object)(object)b == (Object)null)
		{
			return -1;
		}
		Vector3 position = ((Component)a).transform.position;
		Vector3 position2 = ((Component)b).transform.position;
		int num = position2.y.CompareTo(position.y);
		if (num == 0)
		{
			return position.x.CompareTo(position2.x);
		}
		return num;
	}

	private bool IsCurrentColorPageButton(PickableCustomizationButton button)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)button == (Object)null || (int)button.customizationType != 0)
		{
			return false;
		}
		InventoryBook val = ((PickableButton)button).InventoryBook ?? _inventoryBookCache;
		if ((Object)(object)val == (Object)null || !val.Visible || val.ScreenMode || !val.inInventory)
		{
			return false;
		}
		if ((Object)(object)_inventoryBookCache != (Object)null && (Object)(object)val != (Object)(object)_inventoryBookCache)
		{
			return false;
		}
		return val.currentPage == ((PickableButton)button).PageNumber;
	}

	private bool TryUpdateButtonSize(Camera cam, bool keepLargest)
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)cam == (Object)null || _allColorBtns == null || _allColorBtns.Length == 0)
		{
			return false;
		}
		SpriteRenderer val = null;
		for (int i = 0; i < _allColorBtns.Length; i++)
		{
			SpriteRenderer colorButtonRenderer = GetColorButtonRenderer(i);
			if (!((Object)(object)colorButtonRenderer == (Object)null) && ((Renderer)colorButtonRenderer).enabled && ((Component)colorButtonRenderer).gameObject.activeInHierarchy)
			{
				Bounds bounds = ((Renderer)colorButtonRenderer).bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				if (!(((Vector3)(ref size)).sqrMagnitude <= 0.0001f))
				{
					val = colorButtonRenderer;
					break;
				}
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		if (!TryGetProjectedBounds(cam, ((Renderer)val).bounds, out var w, out var h))
		{
			return false;
		}
		if (w <= 5f || h <= 5f)
		{
			return false;
		}
		float num = Mathf.Max(w, h);
		if (keepLargest)
		{
			num = Mathf.Max(new float[3] { num, _btnW, _btnH });
		}
		_btnW = (_btnH = num);
		return true;
	}

	private SpriteRenderer GetColorButtonRenderer(int index)
	{
		if (_allColorBtns == null || index < 0 || index >= _allColorBtns.Length)
		{
			return null;
		}
		if (_colorBtnRenderers == null || _colorBtnRenderers.Length != _allColorBtns.Length)
		{
			_colorBtnRenderers = (SpriteRenderer[])(object)new SpriteRenderer[_allColorBtns.Length];
		}
		SpriteRenderer val = _colorBtnRenderers[index];
		if ((Object)(object)val != (Object)null)
		{
			return val;
		}
		PickableCustomizationButton val2 = _allColorBtns[index];
		val = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentInChildren<SpriteRenderer>(true) : null);
		_colorBtnRenderers[index] = val;
		return val;
	}

	private bool TryGetProjectedBounds(Camera cam, Bounds bounds, out float w, out float h)
	{
		//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_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: 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)
		w = (h = 0f);
		Vector3 min = ((Bounds)(ref bounds)).min;
		Vector3 max = ((Bounds)(ref bounds)).max;
		float num = float.PositiveInfinity;
		float num2 = float.NegativeInfinity;
		float num3 = float.PositiveInfinity;
		float num4 = float.NegativeInfinity;
		Vector3 val = default(Vector3);
		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				for (int k = 0; k < 2; k++)
				{
					((Vector3)(ref val))..ctor((i == 0) ? min.x : max.x, (j == 0) ? min.y : max.y, (k == 0) ? min.z : max.z);
					Vector3 val2 = cam.WorldToScreenPoint(val);
					if (!(val2.z < 0f))
					{
						num = Mathf.Min(num, val2.x);
						num2 = Mathf.Max(num2, val2.x);
						num3 = Mathf.Min(num3, val2.y);
						num4 = Mathf.Max(num4, val2.y);
					}
				}
			}
		}
		if (float.IsInfinity(num) || float.IsInfinity(num2) || float.IsInfinity(num3) || float.IsInfinity(num4) || float.IsNaN(num) || float.IsNaN(num2) || float.IsNaN(num3) || float.IsNaN(num4))
		{
			return false;
		}
		w = num2 - num;
		h = num4 - num3;
		if (w > 0f)
		{
			return h > 0f;
		}
		return false;
	}

	private bool IsColorPageActive()
	{
		if (_allColorBtns == null || _allColorBtns.Length == 0)
		{
			return false;
		}
		PickableCustomizationButton val = _allColorBtns[0];
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		InventoryBook val2 = ((PickableButton)val).InventoryBook ?? _inventoryBookCache;
		if ((Object)(object)val2 == (Object)null || !val2.Visible || val2.ScreenMode)
		{
			return false;
		}
		if (!val2.inInventory)
		{
			return false;
		}
		return val2.currentPage == ((PickableButton)val).PageNumber;
	}

	private void SyncNativesToMode()
	{
		bool flag = _customMode && _layoutReady;
		if (_nativeVisibilityDirty || _nativeButtonsHidden != flag)
		{
			SetNativeButtonsVisible(!flag);
			_nativeButtonsHidden = flag;
			_nativeVisibilityDirty = false;
		}
	}

	private void ShowNativeButtons()
	{
		_nativeVisibilityDirty = true;
		SyncNativesToMode();
	}

	private void HideNativeButtons()
	{
		_nativeVisibilityDirty = true;
		SyncNativesToMode();
	}

	private void SetNativeButtonsVisible(bool visible)
	{
		PickableCustomizationButton[] array = _allBlockColorBtns ?? _allColorBtns;
		if (array == null)
		{
			return;
		}
		foreach (PickableCustomizationButton val in array)
		{
			if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf != visible)
			{
				((Component)val).gameObject.SetActive(visible);
			}
		}
	}

	private Rect ToggleRect(Camera cam)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = cam.WorldToScreenPoint(((Component)_allColorBtns[_rightmostBtnIdx]).transform.position);
		float num = val.x + _btnW * 0.45f;
		float num2 = (float)Screen.height - val.y - _btnH;
		return new Rect(num - _btnW * 0.5f, num2 - _btnH * 0.5f, _btnW, _btnH);
	}

	private Rect TrashRect(Camera cam)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		Rect val = ToggleRect(cam);
		return new Rect(((Rect)(ref val)).x - ((Rect)(ref val)).width - _btnW * 0.15f, ((Rect)(ref val)).y, ((Rect)(ref val)).width, ((Rect)(ref val)).height);
	}

	private Rect PlusRect(Camera cam)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = cam.WorldToScreenPoint(((Component)_allColorBtns[0]).transform.position);
		return new Rect(val.x - _btnW * 0.5f, (float)Screen.height - val.y - _btnH * 0.5f, _btnW, _btnH);
	}

	private Rect SwatchRect(Camera cam, int index)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = cam.WorldToScreenPoint(((Component)_allColorBtns[index]).transform.position);
		return new Rect(val.x - _btnW * 0.5f, (float)Screen.height - val.y - _btnH * 0.5f, _btnW, _btnH);
	}

	private void DrawToggleButton()
	{
		//IL_0049: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Invalid comparison between Unknown and I4
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		if (_allColorBtns == null || _allColorBtns.Length == 0 || (Object)(object)_allColorBtns[_rightmostBtnIdx] == (Object)null)
		{
			return;
		}
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			return;
		}
		EnsureStyles();
		if (!_stylesReady)
		{
			return;
		}
		Rect val = ToggleRect(main);
		Event current = Event.current;
		if ((int)current.type == 7)
		{
			GUI.DrawTexture(val, (Texture)(object)(_customMode ? _texAccent : _texDark));
			GUI.Label(val, _customMode ? "S" : "C", _toggleStyle);
		}
		if (((int)current.type == 0 && PointerIn(val, current)) || ControllerClick(val))
		{
			_customMode = !_customMode;
			if (_customMode)
			{
				HideNativeButtons();
			}
			else
			{
				_open = false;
				HideCustomPaletteVisuals();
				ShowNativeButtons();
			}
			if (current.isMouse)
			{
				current.Use();
			}
		}
		if (current.isMouse && PointerIn(val, current))
		{
			current.Use();
		}
	}

	private void DrawCustomPalette()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Invalid comparison between Unknown and I4
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Invalid comparison between Unknown and I4
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Invalid comparison between Unknown and I4
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: 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_0270: 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_00bf: Invalid comparison between Unknown and I4
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: 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)
		if (_savedColors == null || _allColorBtns == null || _allColorBtns.Length == 0)
		{
			return;
		}
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			return;
		}
		EnsureStyles();
		if (!_stylesReady)
		{
			return;
		}
		Event current = Event.current;
		bool flag = (int)current.type == 7;
		Rect val2 = default(Rect);
		for (int num = 0; num < _savedColors.Count; num++)
		{
			Rect val = SwatchRect(main, num + 1);
			bool flag2 = PointerIn(val, current);
			((Rect)(ref val2))..ctor(((Rect)(ref val)).xMax - 14f, ((Rect)(ref val)).yMin, 14f, 14f);
			bool flag3 = flag2 && PointerIn(val2, current);
			int num2;
			int num3;
			if (!((int)current.type == 0 && flag3))
			{
				num2 = (ControllerClick(val2) ? 1 : 0);
				if (num2 == 0)
				{
					num3 = ((((int)current.type == 0 && flag2) || ControllerClick(val)) ? 1 : 0);
					goto IL_00d3;
				}
			}
			else
			{
				num2 = 1;
			}
			num3 = 0;
			goto IL_00d3;
			IL_00d3:
			bool flag4 = (byte)num3 != 0;
			if (num2 != 0)
			{
				_savedColors.RemoveAt(num);
				if (_selectedIdx == num)
				{
					_selectedIdx = -1;
				}
				else if (_selectedIdx > num)
				{
					_selectedIdx--;
				}
				SaveColors();
				if (current.isMouse)
				{
					current.Use();
				}
				return;
			}
			if (flag4)
			{
				SendColorChange(_savedColors[num]);
				_selectedIdx = num;
				if (current.isMouse)
				{
					current.Use();
				}
			}
			if (flag)
			{
				if (num == _selectedIdx)
				{
					GUI.DrawTexture(new Rect(((Rect)(ref val)).x - 2f, ((Rect)(ref val)).y - 2f, ((Rect)(ref val)).width + 4f, ((Rect)(ref val)).height + 4f), (Texture)(object)_texWhite);
				}
				Color color = GUI.color;
				GUI.color = _savedColors[num];
				GUI.DrawTexture(val, (Texture)(object)_texWhite);
				GUI.color = color;
				if (flag2)
				{
					GUI.DrawTexture(val2, (Texture)(object)_texDark);
					GUI.Label(val2, "x", _xStyle);
				}
			}
			if (current.isMouse && PointerIn(val, current))
			{
				current.Use();
			}
		}
		if (_savedColors.Count >= _maxColors)
		{
			return;
		}
		Rect val3 = PlusRect(main);
		bool flag5 = PointerIn(val3, current);
		if (flag)
		{
			GUI.DrawTexture(val3, (Texture)(object)_texDark);
			GUI.Label(val3, "+", _plusStyle);
		}
		if (((int)current.type == 0 && flag5) || ControllerClick(val3))
		{
			Open(_lastDisplayColor);
			if (current.isMouse)
			{
				current.Use();
			}
		}
		if (current.isMouse && PointerIn(val3, current))
		{
			current.Use();
		}
	}

	private void DrawPickerPanel()
	{
		//IL_0063: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Invalid comparison between Unknown and I4
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: 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_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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)
		//IL_01b0: Invalid comparison between Unknown and I4
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Invalid comparison between Unknown and I4
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Invalid comparison between Unknown and I4
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0293: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Invalid comparison between Unknown and I4
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Invalid comparison between Unknown and I4
		//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0522: Unknown result type (might be due to invalid IL or missing references)
		//IL_0370: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: 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_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_0443: Unknown result type (might be due to invalid IL or missing references)
		//IL_0450: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0469: Unknown result type (might be due to invalid IL or missing references)
		//IL_0542: Unknown result type (might be due to invalid IL or missing references)
		//IL_0556: Unknown result type (might be due to invalid IL or missing references)
		//IL_0562: Unknown result type (might be due to invalid IL or missing references)
		//IL_0576: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05af: Invalid comparison between Unknown and I4
		EnsureStyles();
		if (!_stylesReady)
		{
			return;
		}
		float num = 324f;
		float num2 = (num - 260f) / 2f;
		float num3 = 490f;
		float num4 = ((float)Screen.width - 360f) * 0.5f;
		float num5 = ((float)Screen.height - num3) * 0.5f;
		float num6 = num4 + 18f;
		float num7 = num5 + 18f;
		GUI.DrawTexture(new Rect(num4, num5, 360f, num3), (Texture)(object)_texPanel);
		Event current = Event.current;
		GUI.Label(new Rect(num6, num7, num, 28f), "CUSTOM COLOR", _titleStyle);
		num7 += 40f;
		RebuildSvTexIfNeeded();
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(num6 + num2, num7, 260f, 260f);
		GUI.DrawTexture(val, (Texture)(object)_svTex);
		if ((int)current.type == 7)
		{
			float num8 = ((Rect)(ref val)).x + _s * ((Rect)(ref val)).width;
			float num9 = ((Rect)(ref val)).y + (1f - _v) * ((Rect)(ref val)).height;
			Color color = GUI.color;
			GUI.color = Color.black;
			GUI.DrawTexture(new Rect(num8 - 6f, num9 - 6f, 12f, 12f), (Texture)(object)_texWhite);
			GUI.color = Color.white;
			GUI.DrawTexture(new Rect(num8 - 4f, num9 - 4f, 8f, 8f), (Texture)(object)_texWhite);
			GUI.color = color;
		}
		if (((int)current.type == 0 && PointerIn(val, current)) || ControllerClick(val))
		{
			_svDragging = true;
		}
		if ((int)current.type == 1)
		{
			_svDragging = false;
		}
		if (_svDragging && ((int)current.type == 3 || (int)current.type == 0))
		{
			Vector2 val2 = PointerPos(current);
			_s = Mathf.Clamp01((val2.x - ((Rect)(ref val)).x) / ((Rect)(ref val)).width);
			_v = Mathf.Clamp01(1f - (val2.y - ((Rect)(ref val)).y) / ((Rect)(ref val)).height);
			UpdateRgbFromHsv();
			if (current.isMouse)
			{
				current.Use();
			}
		}
		num7 += 268f;
		Rect val3 = default(Rect);
		((Rect)(ref val3))..ctor(num6 + num2, num7, 260f, 18f);
		GUI.DrawTexture(val3, (Texture)(object)EnsureHueTex());
		if ((int)current.type == 7)
		{
			float num10 = ((Rect)(ref val3)).x + _h * ((Rect)(ref val3)).width;
			Color color2 = GUI.color;
			GUI.color = Color.black;
			GUI.DrawTexture(new Rect(num10 - 2f, ((Rect)(ref val3)).y - 1f, 4f, ((Rect)(ref val3)).height + 2f), (Texture)(object)_texWhite);
			GUI.color = Color.white;
			GUI.DrawTexture(new Rect(num10 - 1f, ((Rect)(ref val3)).y - 1f, 2f, ((Rect)(ref val3)).height + 2f), (Texture)(object)_texWhite);
			GUI.color = color2;
		}
		if (((int)current.type == 0 && PointerIn(val3, current)) || ControllerClick(val3))
		{
			_hueDragging = true;
		}
		if ((int)current.type == 1)
		{
			_hueDragging = false;
		}
		if (_hueDragging && ((int)current.type == 3 || (int)current.type == 0))
		{
			Vector2 val4 = PointerPos(current);
			_h = Mathf.Clamp01((val4.x - ((Rect)(ref val3)).x) / ((Rect)(ref val3)).width);
			_lastHueForSvTex = -1f;
			UpdateRgbFromHsv();
			if (current.isMouse)
			{
				current.Use();
			}
		}
		num7 += 28f;
		GUI.Label(new Rect(num6, num7, 20f, 28f), "#", _labelStyle);
		string text = GUI.TextField(new Rect(num6 + 24f, num7, num - 24f, 28f), _hexInput, 6, _fieldStyle);
		if (text != _hexInput)
		{
			_hexInput = text;
			Color val5 = default(Color);
			if (ColorUtility.TryParseHtmlString("#" + text, ref val5))
			{
				_r = val5.r;
				_g = val5.g;
				_b = val5.b;
				Color.RGBToHSV(val5, ref _h, ref _s, ref _v);
				_lastHueForSvTex = -1f;
			}
		}
		num7 += 36f;
		RefreshSwatch();
		GUI.DrawTexture(new Rect(num6, num7, num, 28f), (Texture)(object)_texSwatch);
		num7 += 40f;
		float num11 = 292f;
		float num12 = num6 + (num - num11) / 2f;
		Rect val6 = default(Rect);
		((Rect)(ref val6))..ctor(num12, num7, 100f, 42f);
		Rect val7 = default(Rect);
		((Rect)(ref val7))..ctor(num12 + 106f, num7, 100f, 42f);
		Rect val8 = default(Rect);
		((Rect)(ref val8))..ctor(num12 + 212f, num7, 80f, 42f);
		bool flag = GUI.Button(val6, "Use Color", _actionBtnStyle) || ControllerClick(val6);
		bool flag2 = GUI.Button(val7, "Save Color", _actionBtnStyle) || ControllerClick(val7);
		bool num13 = GUI.Button(val8, "Cancel", _actionBtnStyle) || ControllerClick(val8);
		if (flag)
		{
			UseColor();
		}
		if (flag2)
		{
			SaveColor();
		}
		if (num13)
		{
			_open = false;
		}
		if (current.isMouse && (int)current.type != 12)
		{
			current.Use();
		}
	}

	private void UpdateCanvasUi(bool colorsTabActive)
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Invalid comparison between Unknown and I4
		if (!colorsTabActive)
		{
			_open = false;
			SetPickerGraphicsVisible(visible: false);
			SetCanvasVisible(visible: false);
			return;
		}
		EnsureCanvasUi();
		if (_uiBuilt)
		{
			if ((Object)(object)_uiCanvas != (Object)null && (int)_uiCanvas.renderMode == 1)
			{
				ConfigureCanvasSortingBelowCursor(_uiCanvas);
			}
			SetCanvasVisible(visible: true);
			LayoutCanvasUi();
			SyncCanvasUi();
			HandleCanvasInput();
		}
	}

	private void EnsureCanvasUi()
	{
		//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_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Expected O, but got Unknown
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		InventoryPage colorPage = GetColorPage();
		Camera val = (((Object)(object)_inventoryBookCache != (Object)null) ? _inventoryBookCache.UiCamera : null);
		bool flag = (Object)(object)val != (Object)null;
		Canvas val2 = (_ownsUiCanvas ? _uiCanvas : null);
		if (_uiBuilt && (Object)(object)_uiCanvas != (Object)null && _ownsUiCanvas && (Object)(object)_uiPage == (Object)(object)colorPage && _uiUsesInventoryCamera == flag && (!flag || (Object)(object)_uiCanvas.worldCamera == (Object)(object)val))
		{
			return;
		}
		if (_uiBuilt || (Object)(object)_uiRoot != (Object)null)
		{
			DestroyCanvasUi();
		}
		if ((Object)(object)val2 == (Object)null)
		{
			GameObject val3 = new GameObject("OssieCustomColors.Canvas");
			val3.transform.SetParent(((Component)this).transform, false);
			val3.layer = (flag ? 5 : 0);
			val2 = val3.AddComponent<Canvas>();
			_ownsUiCanvas = true;
		}
		_uiCanvas = val2;
		_uiPage = colorPage;
		_uiUsesInventoryCamera = flag;
		ConfigureCanvas(val2, val);
		_canvasRect = ((Component)val2).GetComponent<RectTransform>();
		if (!((Object)(object)_canvasRect == (Object)null))
		{
			if ((Object)(object)((Component)val2).GetComponent<GraphicRaycaster>() == (Object)null)
			{
				((Component)val2).gameObject.AddComponent<GraphicRaycaster>();
			}
			GameObject val4 = new GameObject("OssieCustomColors.CustomColorsCanvas");
			val4.transform.SetParent(((Component)val2).transform, false);
			_uiRoot = val4.AddComponent<RectTransform>();
			_uiRoot.anchorMin = Vector2.zero;
			_uiRoot.anchorMax = Vector2.one;
			_uiRoot.offsetMin = Vector2.zero;
			_uiRoot.offsetMax = Vector2.zero;
			_uiRoot.pivot = new Vector2(0.5f, 0.5f);
			((Transform)_uiRoot).SetAsLastSibling();
			BuildCanvasUi();
			if (flag)
			{
				SetLayerRecursive(((Component)_uiRoot).gameObject, 5);
			}
			_uiBuilt = true;
		}
	}

	private void ConfigureCanvas(Canvas canvas, Camera inventoryCamera)
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)inventoryCamera != (Object)null)
		{
			canvas.renderMode = (RenderMode)1;
			canvas.worldCamera = inventoryCamera;
			canvas.planeDistance = Mathf.Clamp(250f, inventoryCamera.nearClipPlane + 0.01f, inventoryCamera.farClipPlane - 0.01f);
			canvas.overrideSorting = true;
			((Component)canvas).gameObject.layer = 5;
			ConfigureCanvasSortingBelowCursor(canvas);
		}
		else
		{
			canvas.renderMode = (RenderMode)0;
			canvas.worldCamera = null;
			canvas.overrideSorting = true;
			((Component)canvas).gameObject.layer = 0;
			canvas.sortingOrder = 32760;
		}
		if (!_loggedCanvasConfig)
		{
			_loggedCanvasConfig = true;
			string text = (((Object)(object)inventoryCamera != (Object)null) ? ((Object)inventoryCamera).name : "<overlay>");
			Plugin.Log.LogInfo((object)$"[OssieCustomColors] Canvas config: mode={canvas.renderMode}, camera={text}, plane={canvas.planeDistance:F2}, layer={canvas.sortingLayerName}, order={canvas.sortingOrder}");
		}
	}

	private void ConfigureCanvasSortingBelowCursor(Canvas canvas)
	{
		if (TryGetInventoryCursorRenderer(out var cursorRenderer))
		{
			int num = Mathf.Max(-32768, ((Renderer)cursorRenderer).sortingOrder - 100);
			if (canvas.sortingLayerID != ((Renderer)cursorRenderer).sortingLayerID)
			{
				canvas.sortingLayerID = ((Renderer)cursorRenderer).sortingLayerID;
			}
			if (canvas.sortingOrder != num)
			{
				canvas.sortingOrder = num;
			}
		}
		else if ((Object)(object)_uiPage != (Object)null && (Object)(object)_uiPage.textCanvas != (Object)null)
		{
			int num2 = _uiPage.textCanvas.sortingOrder + 1000;
			if (canvas.sortingLayerID != _uiPage.textCanvas.sortingLayerID)
			{
				canvas.sortingLayerID = _uiPage.textCanvas.sortingLayerID;
			}
			if (canvas.sortingOrder != num2)
			{
				canvas.sortingOrder = num2;
			}
		}
		else
		{
			canvas.sortingLayerName = "UI 1";
			canvas.sortingOrder = 29000;
		}
	}

	private void SetLayerRecursive(GameObject go, int layer)
	{
		if (!((Object)(object)go == (Object)null))
		{
			Transform[] componentsInChildren = go.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = layer;
			}
		}
	}

	private bool TryGetInventoryCursorRenderer(out SpriteRenderer cursorRenderer)
	{
		cursorRenderer = null;
		if ((Object)(object)_inventoryBookCache == (Object)null || _inventoryBookCache.cursors == null)
		{
			return false;
		}
		if (!CursorRendererCacheMatches())
		{
			RebuildCursorRendererCache();
		}
		for (int i = 0; i < _inventoryBookCache.cursors.Count; i++)
		{
			PickCursor val = _inventoryBookCache.cursors[i];
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			SpriteRenderer val2 = ((i < _cachedCursorRenderers.Count) ? _cachedCursorRenderers[i] : null);
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = ((Component)val).GetComponentInChildren<SpriteRenderer>(true);
				while (_cachedCursorRenderers.Count <= i)
				{
					_cachedCursorRenderers.Add(null);
				}
				_cachedCursorRenderers[i] = val2;
			}
			if (!((Object)(object)val2 == (Object)null))
			{
				cursorRenderer = val2;
				return true;
			}
		}
		return false;
	}

	private void RebuildCursorRendererCache()
	{
		ClearCursorRendererCache();
		if (!((Object)(object)_inventoryBookCache == (Object)null) && _inventoryBookCache.cursors != null)
		{
			for (int i = 0; i < _inventoryBookCache.cursors.Count; i++)
			{
				PickCursor val = _inventoryBookCache.cursors[i];
				_cachedCursorRendererCursors.Add(val);
				_cachedCursorRenderers.Add(((Object)(object)val != (Object)null) ? ((Component)val).GetComponentInChildren<SpriteRenderer>(true) : null);
			}
		}
	}

	private bool CursorRendererCacheMatches()
	{
		if ((Object)(object)_inventoryBookCache == (Object)null || _inventoryBookCache.cursors == null)
		{
			return _cachedCursorRendererCursors.Count == 0;
		}
		if (_cachedCursorRendererCursors.Count != _inventoryBookCache.cursors.Count)
		{
			return false;
		}
		for (int i = 0; i < _cachedCursorRendererCursors.Count; i++)
		{
			if ((Object)(object)_cachedCursorRendererCursors[i] != (Object)(object)_inventoryBookCache.cursors[i])
			{
				return false;
			}
		}
		return true;
	}

	private void ClearCursorRendererCache()
	{
		_cachedCursorRendererCursors.Clear();
		_cachedCursorRenderers.Clear();
	}

	private InventoryPage GetColorPage()
	{
		if (_allColorBtns == null || _allColorBtns.Length == 0 || (Object)(object)_allColorBtns[0] == (Object)null)
		{
			return null;
		}
		InventoryBook val = ((PickableButton)_allColorBtns[0]).InventoryBook ?? _inventoryBookCache;
		if ((Object)(object)val == (Object)null || val.InventoryPages == null)
		{
			return null;
		}
		int pageNumber = ((PickableButton)_allColorBtns[0]).PageNumber;
		if (pageNumber < 0 || pageNumber >= val.InventoryPages.Length)
		{
			return null;
		}
		return val.InventoryPages[pageNumber];
	}

	private void BuildCanvasUi()
	{
		//IL_000d: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Expected O, but got Unknown
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: 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)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: 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_04c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_053c: Unknown result type (might be due to invalid IL or missing references)
		//IL_057a: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_061c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0662: Unknown result type (might be due to invalid IL or missing references)
		EnsureCanvasResources();
		_toggleBg = NewImage("ToggleBackground", ColDark);
		_toggleRt = ((Graphic)_toggleBg).rectTransform;
		_toggleText = NewText("ToggleText", "C", 16, (TextAnchor)4, Color.white, (Transform)(object)_toggleRt);
		_trashBg = NewImage("TrashBackground", ColDark);
		_trashRt = ((Graphic)_trashBg).rectTransform;
		_trashCanBody = NewImage("TrashCanBody", ColBody);
		_trashCanLid = NewImage("TrashCanLid", ColBody);
		_plusBg = NewImage("PlusBackground", ColDark);
		_plusRt = ((Graphic)_plusBg).rectTransform;
		_plusText = NewText("PlusText", "+", 24, (TextAnchor)4, Color.white, (Transform)(object)_plusRt);
		GameObject val = new GameObject("PickerRoot");
		val.transform.SetParent((Transform)(object)_uiRoot, false);
		_pickerRoot = val.AddComponent<RectTransform>();
		_pickerRoot.anchorMin = Vector2.zero;
		_pickerRoot.anchorMax = Vector2.one;
		_pickerRoot.offsetMin = Vector2.zero;
		_pickerRoot.offsetMax = Vector2.zero;
		((Component)_pickerRoot).gameObject.SetActive(false);
		_pickerPanelBg = NewImage("PickerPanel", ColPanel, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_pickerPanelBg);
		_pickerTitle = NewText("PickerTitle", "CUSTOM COLOR", 20, (TextAnchor)4, ColTitle, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_pickerTitle);
		_svRaw = NewRawImage("SvTexture", (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_svRaw);
		_svCursorOuter = NewImage("SvCursorOuter", Color.black, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_svCursorOuter);
		_svCursorInner = NewImage("SvCursorInner", Color.white, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_svCursorInner);
		_hueRaw = NewRawImage("HueTexture", (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_hueRaw);
		_hueMarkerOuter = NewImage("HueMarkerOuter", Color.black, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_hueMarkerOuter);
		_hueMarkerInner = NewImage("HueMarkerInner", Color.white, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_hueMarkerInner);
		_hexLabel = NewText("HexLabel", "#", 18, (TextAnchor)3, ColBody, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_hexLabel);
		_hexBg = NewImage("HexBackground", ColDark, (Transform)(object)_pickerRoot);
		((Graphic)_hexBg).raycastTarget = true;
		_pickerGraphics.Add((Graphic)(object)_hexBg);
		_hexField = ((Component)_hexBg).gameObject.AddComponent<InputField>();
		_hexField.characterLimit = 6;
		_hexField.lineType = (LineType)0;
		((UnityEvent<string>)(object)_hexField.onValueChanged).AddListener((UnityAction<string>)OnHexFieldChanged);
		Text val2 = NewText("HexInputText", _hexInput, 18, (TextAnchor)3, ColBody, (Transform)(object)((Graphic)_hexBg).rectTransform);
		((Graphic)val2).rectTransform.anchorMin = Vector2.zero;
		((Graphic)val2).rectTransform.anchorMax = Vector2.one;
		((Graphic)val2).rectTransform.offsetMin = new Vector2(8f, 2f);
		((Graphic)val2).rectTransform.offsetMax = new Vector2(-8f, -2f);
		_hexField.textComponent = val2;
		_hexField.text = _hexInput;
		_previewImage = NewImage("PreviewSwatch", Color.white, (Transform)(object)_pickerRoot);
		_pickerGraphics.Add((Graphic)(object)_previewImage);
		_useBg = NewImage("UseButton", ColBtn, (Transform)(object)_pickerRoot);
		_useRt = ((Graphic)_useBg).rectTransform;
		_pickerGraphics.Add((Graphic)(object)_useBg);
		_useText = NewText("UseText", "Use Color", 14, (TextAnchor)4, ColBtnText, (Transform)(object)_useRt);
		_pickerGraphics.Add((Graphic)(object)_useText);
		_saveBg = NewImage("SaveButton", ColBtn, (Transform)(object)_pickerRoot);
		_saveRt = ((Graphic)_saveBg).rectTransform;
		_pickerGraphics.Add((Graphic)(object)_saveBg);
		_saveText = NewText("SaveText", "Save Color", 14, (TextAnchor)4, ColBtnText, (Transform)(object)_saveRt);
		_pickerGraphics.Add((Graphic)(object)_saveText);
		_pickBg = NewImage("EyedropperButton", ColDark, (Transform)(object)_pickerRoot);
		_pickRt = ((Graphic)_pickBg).rectTransform;
		_pickerGraphics.Add((Graphic)(object)_pickBg);
		_pickIconHandle = NewImage("EyedropperHandle", Color.white, (Transform)(object)_pickerRoot);
		((Transform)((Graphic)_pickIconHandle).rectTransform).localRotation = Quaternion.Euler(0f, 0f, -45f);
		_pickerGraphics.Add((Graphic)(object)_pickIconHandle);
		_pickIconTip = NewImage("EyedropperTip", Color.white, (Transform)(object)_pickerRoot);
		((Transform)((Graphic)_pickIconTip).rectTransform).localRotation = Quaternion.Euler(0f, 0f, -45f);
		_pickerGraphics.Add((Graphic)(object)_pickIconTip);
		_cancelBg = NewImage("CancelButton", ColBtn, (Transform)(object)_pickerRoot);
		_cancelRt = ((Graphic)_cancelBg).rectTransform;
		_pickerGraphics.Add((Graphic)(object)_cancelBg);
		_cancelText = NewText("CancelText", "Cancel", 14, (TextAnchor)4, ColBtnText, (Transform)(object)_cancelRt);
		_pickerGraphics.Add((Graphic)(object)_cancelText);
		SetPickerGraphicsVisible(visible: false);
		Plugin.Log.LogInfo((object)"[OssieCustomColors] Canvas UI built.");
	}

	private void SetPickerGraphicsVisible(bool visible)
	{
		if ((Object)(object)_pickerRoot != (Object)null && ((Component)_pickerRoot).gameObject.activeSelf != visible)
		{
			((Component)_pickerRoot).gameObject.SetActive(visible);
		}
		for (int i = 0; i < _pickerGraphics.Count; i++)
		{
			if ((Object)(object)_pickerGraphics[i] != (Object)null)
			{
				((Component)_pickerGraphics[i]).gameObject.SetActive(visible);
			}
		}
	}

	private void EnsureCanvasResources()
	{
		if ((Object)(object)_font == (Object)null)
		{
			_font = ResolveFont();
		}
		EnsureUiSprite();
	}

	private Image NewImage(string name, Color color, Transform parent = null)
	{
		//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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent((Transform)(((Object)(object)parent != (Object)null) ? ((object)parent) : ((object)_uiRoot)), false);
		Image val2 = val.AddComponent<Image>();
		val2.sprite = EnsureUiSprite();
		val2.type = (Type)0;
		val2.preserveAspect = false;
		((Graphic)val2).color = color;
		((Graphic)val2).raycastTarget = false;
		RectTransform rectTransform = ((Graphic)val2).rectTransform;
		RectTransform rectTransform2 = ((Graphic)val2).rectTransform;
		Vector2 val3 = default(Vector2);
		((Vector2)(ref val3))..ctor(0.5f, 0.5f);
		rectTransform2.anchorMax = val3;
		rectTransform.anchorMin = val3;
		((Graphic)val2).rectTransform.pivot = new Vector2(0.5f, 0.5f);
		return val2;
	}

	private Sprite EnsureUiSprite()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_uiSprite != (Object)null)
		{
			return _uiSprite;
		}
		_uiSprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 100f);
		((Object)_uiSprite).hideFlags = (HideFlags)61;
		return _uiSprite;
	}

	private RawImage NewRawImage(string name, Transform parent = null)
	{
		//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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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)
		GameObject val = new GameObject(name);
		val.transform.SetParent((Transform)(((Object)(object)parent != (Object)null) ? ((object)parent) : ((object)_uiRoot)), false);
		RawImage val2 = val.AddComponent<RawImage>();
		((Graphic)val2).color = Color.white;
		((Graphic)val2).raycastTarget = false;
		val2.texture = null;
		RectTransform rectTransform = ((Graphic)val2).rectTransform;
		RectTransform rectTransform2 = ((Graphic)val2).rectTransform;
		Vector2 val3 = default(Vector2);
		((Vector2)(ref val3))..ctor(0.5f, 0.5f);
		rectTransform2.anchorMax = val3;
		rectTransform.anchorMin = val3;
		((Graphic)val2).rectTransform.pivot = new Vector2(0.5f, 0.5f);
		return val2;
	}

	private Text NewText(string name, string text, int fontSize, TextAnchor alignment, Color color, Transform parent = null)
	{
		//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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent((Transform)(((Object)(object)parent != (Object)null) ? ((object)parent) : ((object)_uiRoot)), false);
		Text val2 = val.AddComponent<Text>();
		val2.font = (((Object)(object)_font != (Object)null) ? _font : ResolveFont());
		val2.text = text;
		val2.fontSize = fontSize;
		val2.alignment = alignment;
		((Graphic)val2).color = color;
		((Graphic)val2).raycastTarget = false;
		val2.horizontalOverflow = (HorizontalWrapMode)1;
		val2.verticalOverflow = (VerticalWrapMode)1;
		if ((Object)(object)parent != (Object)null)
		{
			((Graphic)val2).rectTransform.anchorMin = Vector2.zero;
			((Graphic)val2).rectTransform.anchorMax = Vector2.one;
			((Graphic)val2).rectTransform.offsetMin = Vector2.zero;
			((Graphic)val2).rectTransform.offsetMax = Vector2.zero;
		}
		else
		{
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			RectTransform rectTransform2 = ((Graphic)val2).rectTransform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			rectTransform2.anchorMax = val3;
			rectTransform.anchorMin = val3;
			((Graphic)val2).rectTransform.pivot = new Vector2(0.5f, 0.5f);
		}
		return val2;
	}

	private void DestroyCanvasUi()
	{
		_pickerGraphics.Clear();
		_swatchViews.Clear();
		_swatchGuiRects.Clear();
		_editGuiRects.Clear();
		if ((Object)(object)_uiRoot != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_uiRoot).gameObject);
		}
		if (_ownsUiCanvas && (Object)(object)_uiCanvas != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)_uiCanvas).gameObject);
		}
		_uiCanvas = null;
		_canvasRect = null;
		_uiRoot = null;
		_uiPage = null;
		_pickerRoot = null;
		_uiBuilt = false;
		_ownsUiCanvas = false;
		_uiUsesInventoryCamera = false;
		_loggedCanvasConfig = false;
	}

	private void SetCanvasVisible(bool visible)
	{
		if ((Object)(object)_uiRoot != (Object)null && ((Component)_uiRoot).gameObject.activeSelf != visible)
		{
			((Component)_uiRoot).gameObject.SetActive(visible);
		}
	}

	private void SetTrashVisible(bool visible)
	{
		if ((Object)(object)_trashRt != (Object)null && ((Component)_trashRt).gameObject.activeSelf != visible)
		{
			((Component)_trashRt).gameObject.SetActive(visible);
		}
		if ((Object)(object)_trashCanBody != (Object)null && ((Component)_trashCanBody).gameObject.activeSelf != visible)
		{
			((Component)_trashCanBody).gameObject.SetActive(visible);
		}
		if ((Object)(object)_trashCanLid != (Object)null && ((Component)_trashCanLid).gameObject.activeSelf != visible)
		{
			((Component)_trashCanLid).gameObject.SetActive(visible);
		}
	}

	private void HideCustomPaletteVisuals()
	{
		if ((Object)(object)_plusRt != (Object)null)
		{
			((Component)_plusRt).gameObject.SetActive(false);
		}
		SetTrashVisible(visible: false);
		for (int i = 0; i < _swatchViews.Count; i++)
		{
			((Component)_swatchViews[i].Root).gameObject.SetActive(false);
			((Component)_swatchViews[i].Border).gameObject.SetActive(false);
			((Component)_swatchViews[i].DeleteRoot).gameObject.SetActive(false);
		}
	}

	private void LayoutCanvasUi()
	{
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_0343: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0437: Unknown result type (might be due to invalid IL or missing references)
		//IL_043c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		Camera val = InventoryLayoutCamera();
		if (_allColorBtns == null || _allColorBtns.Length == 0 || (Object)(object)val == (Object)null)
		{
			((Component)_toggleRt).gameObject.SetActive(false);
			SetTrashVisible(visible: false);
			((Component)_plusRt).gameObject.SetActive(false);
			for (int i = 0; i < _swatchViews.Count; i++)
			{
				((Component)_swatchViews[i].Root).gameObject.SetActive(false);
				((Component)_swatchViews[i].Border).gameObject.SetActive(false);
				((Component)_swatchViews[i].DeleteRoot).gameObject.SetActive(false);
			}
			_swatchGuiRects.Clear();
			_editGuiRects.Clear();
			SetPickerGraphicsVisible(visible: false);
			return;
		}
		TryUpdateButtonSize(val, keepLargest: true);
		((Component)_toggleRt).gameObject.SetActive(true);
		_toggleGuiRect = ToggleRect(val);
		if (!_loggedCanvasConfig)
		{
			Plugin.Log.LogInfo((object)$"[OssieCustomColors] Toggle rect: {_toggleGuiRect}");
		}
		SetRectFromGui(_toggleRt, _toggleGuiRect);
		bool customMode = _customMode;
		SetTrashVisible(customMode);
		if (customMode)
		{
			_trashGuiRect = TrashRect(val);
			SetRectFromGui(_trashRt, _trashGuiRect);
			SetRectFromGui(((Graphic)_trashCanBody).rectTransform, new Rect(((Rect)(ref _trashGuiRect)).x + ((Rect)(ref _trashGuiRect)).width * 0.32f, ((Rect)(ref _trashGuiRect)).y + ((Rect)(ref _trashGuiRect)).height * 0.4f, ((Rect)(ref _trashGuiRect)).width * 0.36f, ((Rect)(ref _trashGuiRect)).height * 0.34f));
			SetRectFromGui(((Graphic)_trashCanLid).rectTransform, new Rect(((Rect)(ref _trashGuiRect)).x + ((Rect)(ref _trashGuiRect)).width * 0.27f, ((Rect)(ref _trashGuiRect)).y + ((Rect)(ref _trashGuiRect)).height * 0.28f, ((Rect)(ref _trashGuiRect)).width * 0.46f, ((Rect)(ref _trashGuiRect)).height * 0.08f));
		}
		EnsureSwatchViews();
		_swatchGuiRects.Clear();
		_editGuiRects.Clear();
		int num = Mathf.Min((_savedColors != null) ? _savedColors.Count : 0, _maxColors);
		Rect val3 = default(Rect);
		for (int j = 0; j < _swatchViews.Count; j++)
		{
			bool flag = _customMode && j < num;
			((Component)_swatchViews[j].Root).gameObject.SetActive(flag);
			((Component)_swatchViews[j].Border).gameObject.SetActive(false);
			((Component)_swatchViews[j].DeleteRoot).gameObject.SetActive(flag);
			if (flag)
			{
				Rect val2 = SwatchRect(val, j + 1);
				((Rect)(ref val3))..ctor(((Rect)(ref val2)).xMax - 16f, ((Rect)(ref val2)).yMin, 16f, 16f);
				_swatchGuiRects.Add(val2);
				_editGuiRects.Add(val3);
				SetRectFromGui(_swatchViews[j].Root, val2);
				SetRectFromGui(((Graphic)_swatchViews[j].Border).rectTransform, new Rect(((Rect)(ref val2)).x - 2f, ((Rect)(ref val2)).y - 2f, ((Rect)(ref val2)).width + 4f, ((Rect)(ref val2)).height + 4f));
				SetRectFromGui(_swatchViews[j].DeleteRoot, val3);
			}
		}
		bool flag2 = _customMode && _savedColors != null && _savedColors.Count < _maxColors;
		((Component)_plusRt).gameObject.SetActive(flag2);
		if (flag2)
		{
			_plusGuiRect = PlusRect(val);
			SetRectFromGui(_plusRt, _plusGuiRect);
		}
		if (_open)
		{
			LayoutPickerCanvas();
		}
	}

	private void LayoutPickerCanvas()
	{
		//IL_0049: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_0429: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		float num = 394f;
		float num2 = 492f;
		float num3 = ((float)Screen.width - 430f) * 0.5f;
		float num4 = ((float)Screen.height - num2) * 0.5f;
		float num5 = num3 + 18f;
		float num6 = num4 + 18f;
		_panelGuiRect = new Rect(num3, num4, 430f, num2);
		SetRectFromGui(((Graphic)_pickerPanelBg).rectTransform, _panelGuiRect);
		SetRectFromGui(((Graphic)_pickerTitle).rectTransform, new Rect(num5, num6, num, 28f));
		num6 += 40f;
		_svGuiRect = new Rect(num5, num6, num, 260f);
		SetRectFromGui(((Graphic)_svRaw).rectTransform, _svGuiRect);
		float num7 = ((Rect)(ref _svGuiRect)).x + _s * ((Rect)(ref _svGuiRect)).width;
		float num8 = ((Rect)(ref _svGuiRect)).y + (1f - _v) * ((Rect)(ref _svGuiRect)).height;
		SetRectFromGui(((Graphic)_svCursorOuter).rectTransform, new Rect(num7 - 6f, num8 - 6f, 12f, 12f));
		SetRectFromGui(((Graphic)_svCursorInner).rectTransform, new Rect(num7 - 4f, num8 - 4f, 8f, 8f));
		num6 += 268f;
		_hueGuiRect = new Rect(num5, num6, num, 18f);
		SetRectFromGui(((Graphic)_hueRaw).rectTransform, _hueGuiRect);
		float num9 = ((Rect)(ref _hueGuiRect)).x + _h * ((Rect)(ref _hueGuiRect)).width;
		SetRectFromGui(((Graphic)_hueMarkerOuter).rectTransform, new Rect(num9 - 2f, ((Rect)(ref _hueGuiRect)).y - 1f, 4f, ((Rect)(ref _hueGuiRect)).height + 2f));
		SetRectFromGui(((Graphic)_hueMarkerInner).rectTransform, new Rect(num9 - 1f, ((Rect)(ref _hueGuiRect)).y - 1f, 2f, ((Rect)(ref _hueGuiRect)).height + 2f));
		num6 += 28f;
		SetRectFromGui(((Graphic)_hexLabel).rectTransform, new Rect(num5, num6, 20f, 28f));
		_hexGuiRect = new Rect(num5 + 24f, num6, num - 24f, 28f);
		SetRectFromGui(((Graphic)_hexBg).rectTransform, _hexGuiRect);
		num6 += 36f;
		float num10 = 28f;
		float num11 = 8f;
		SetRectFromGui(((Graphic)_previewImage).rectTransform, new Rect(num5, num6, num - num10 - num11, 28f));
		_pickGuiRect = new Rect(num5 + num - num10, num6, num10, num10);
		SetRectFromGui(_pickRt, _pickGuiRect);
		SetRectFromGui(((Graphic)_pickIconHandle).rectTransform, new Rect(((Rect)(ref _pickGuiRect)).x + 11f, ((Rect)(ref _pickGuiRect)).y + 6f, 5f, 18f));
		SetRectFromGui(((Graphic)_pickIconTip).rectTransform, new Rect(((Rect)(ref _pickGuiRect)).x + 17f, ((Rect)(ref _pickGuiRect)).y + 17f, 6f, 6f));
		num6 += 40f;
		float num12 = 344f;
		float num13 = num5 + (num - num12) / 2f;
		_useGuiRect = new Rect(num13, num6, 118f, 44f);
		_saveGuiRect = new Rect(num13 + 126f, num6, 118f, 44f);
		_cancelGuiRect = new Rect(num13 + 252f, num6, 92f, 44f);
		SetRectFromGui(_useRt, _useGuiRect);
		SetRectFromGui(_saveRt, _saveGuiRect);
		SetRectFromGui(_cancelRt, _cancelGuiRect);
	}

	private void SyncCanvasUi()
	{
		//IL_0015: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: 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_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		((Graphic)_toggleBg).color = (_customMode ? ColAccent : ColDark);
		_toggleText.text = (_customMode ? "S" : "C");
		if (!_customMode)
		{
			HideCustomPaletteVisuals();
			SetPickerGraphicsVisible(visible: false);
			return;
		}
		Vector2 guiPos;
		bool flag = TryGetCurrentGuiPointer(out guiPos);
		((Graphic)_plusBg).color = ((flag && ((Rect)(ref _plusGuiRect)).Contains(guiPos)) ? ColAccent : ColDark);
		SetTrashVisual(flag, guiPos);
		int num = Mathf.Min((_savedColors != null) ? _savedColors.Count : 0, _swatchViews.Count);
		for (int i = 0; i < num; i++)
		{
			CanvasSwatch canvasSwatch = _swatchViews[i];
			((Graphic)canvasSwatch.Fill).color = _savedColors[i];
			Rect val;
			int num2;
			if (_deleteMode && flag && i < _swatchGuiRects.Count)
			{
				val = _swatchGuiRects[i];
				num2 = (((Rect)(ref val)).Contains(guiPos) ? 1 : 0);
			}
			else
			{
				num2 = 0;
			}
			bool flag2 = (byte)num2 != 0;
			((Graphic)canvasSwatch.Border).color = (flag2 ? ColDanger : Color.white);
			((Component)canvasSwatch.Border).gameObject.SetActive(i == _selectedIdx || flag2);
			int num3;
			if (flag && i < _swatchGuiRects.Count)
			{
				val = _swatchGuiRects[i];
				num3 = (((Rect)(ref val)).Contains(guiPos) ? 1 : 0);
			}
			else
			{
				num3 = 0;
			}
			bool flag3 = (byte)num3 != 0;
			((Component)canvasSwatch.DeleteRoot).gameObject.SetActive(_customMode && !_deleteMode && flag3);
		}
		if (!_open)
		{
			SetPickerGraphicsVisible(visible: false);
			return;
		}
		RebuildSvTexIfNeeded();
		_svRaw.texture = (Texture)(object)_svTex;
		_hueRaw.texture = (Texture)(object)EnsureHueTex();
		((Graphic)_previewImage).color = new Color(_r, _g, _b, 1f);
		SetPickerGraphicsVisible(visible: true);
		if ((Object)(object)_hexField != (Object)null && !_hexField.isFocused && _hexField.text != _hexInput)
		{
			_syncingHexField = true;
			_hexField.text = _hexInput;
			_syncingHexField = false;
		}
		SetActionVisual(_useBg, _useText, _useGuiRect, flag, guiPos);
		if ((Object)(object)_saveText != (Object)null)
		{
			_saveText.text = ((_editingSavedColorIndex >= 0) ? "Update Color" : "Save Color");
		}
		SetActionVisual(_saveBg, _saveText, _saveGuiRect, flag, guiPos);
		SetEyedropperVisual(flag, guiPos);
		SetActionVisual(_cancelBg, _cancelText, _cancelGuiRect, flag, guiPos);
	}

	private void SetEyedropperVisual(bool havePointer, Vector2 pointer)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		bool flag = havePointer && ((Rect)(ref _pickGuiRect)).Contains(pointer);
		((Graphic)_pickBg).color = (flag ? ColAccent : ColDark);
		((Graphic)_pickIconHandle).color = (flag ? Color.white : ColBody);
		((Graphic)_pickIconTip).color = (flag ? Color.white : ColBody);
	}

	private void SetTrashVisual(bool havePointer, Vector2 pointer)
	{
		//IL_0018: 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_002c: 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_0058: 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: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_trashBg == (Object)null))
		{
			bool flag = havePointer && ((Rect)(ref _trashGuiRect)).Contains(pointer);
			Color color = ((_deleteMode || flag) ? Color.white : ColBody);
			((Graphic)_trashBg).color = (_deleteMode ? ColDanger : (flag ? ColBtnHov : ColDark));
			((Graphic)_trashCanBody).color = color;
			((Graphic)_trashCanLid).color = color;
		}
	}

	private void SetActionVisual(Image bg, Text text, Rect rect, bool havePointer, Vector2 pointer)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		((Graphic)bg).color = ((havePointer && ((Rect)(ref rect)).Contains(pointer)) ? ColBtnHov : ColBtn);
		((Graphic)text).color = ColBtnText;
	}

	private void EnsureSwatchViews()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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)
		int num = Mathf.Max(0, _maxColors);
		while (_swatchViews.Count < num)
		{
			Image val = NewImage("SavedColor", Color.white);
			Image val2 = NewImage("SavedColorBorder", Color.white);
			Image val3 = NewImage("SavedColorEdit", ColDark);
			Text deleteText = NewText("SavedColorEditText", "E", 11, (TextAnchor)4, Color.white, (Transform)(object)((Graphic)val3).rectTransform);
			((Component)val2).transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex());
			((Component)val3).transform.SetAsLastSibling();
			((Component)val).gameObject.SetActive(false);
			((Component)val2).gameObject.SetActive(false);
			((Component)val3).gameObject.SetActive(false);
			_swatchViews.Add(new CanvasSwatch
			{
				Root = ((Graphic)val).rectTransform,
				Fill = val,
				Border = val2,
				DeleteRoot = ((Graphic)val3).rectTransform,
				DeleteBg = val3,
				DeleteText = deleteText
			});
		}
	}

	private void SetRectFromGui(RectTransform rt, Rect guiRect)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)rt == (Object)null) && !((Object)(object)_canvasRect == (Object)null))
		{
			Camera val = CanvasCamera();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(((Rect)(ref guiRect)).x + ((Rect)(ref guiRect)).width * 0.5f, (float)Screen.height - (((Rect)(ref guiRect)).y + ((Rect)(ref guiRect)).height * 0.5f));
			Vector2 anchoredPosition = default(Vector2);
			if (RectTransformUtility.ScreenPointToLocalPointInRectangle(_canvasRect, val2, val, ref anchoredPosition))
			{
				Vector2 val3 = default(Vector2);
				RectTransformUtility.ScreenPointToLocalPointInRectangle(_canvasRect, val2 + Vector2.left * ((Rect)(ref guiRect)).width * 0.5f, val, ref val3);
				Vector2 val4 = default(Vector2);
				RectTransformUtility.ScreenPointToLocalPointInRectangle(_canvasRect, val2 + Vector2.right * ((Rect)(ref guiRect)).width * 0.5f, val, ref val4);
				Vector2 val5 = default(Vector2);
				RectTransformUtility.ScreenPointToLocalPointInRectangle(_canvasRect, val2 + Vector2.up * ((Rect)(ref guiRect)).height * 0.5f, val, ref val5);
				Vector2 val6 = default(Vector2);
				RectTransformUtility.ScreenPointToLocalPointInRectangle(_canvasRect, val2 + Vector2.down * ((Rect)(ref guiRect)).height * 0.5f, val, ref val6);
				Vector2 val7 = default(Vector2);
				((Vector2)(ref val7))..ctor(0.5f, 0.5f);
				rt.anchorMax = val7;
				rt.anchorMin = val7;
				rt.pivot = new Vector2(0.5f, 0.5f);
				rt.anchoredPosition = anchoredPosition;
				rt.sizeDelta = new Vector2(Mathf.Abs(val4.x - val3.x), Mathf.Abs(val5.y - val6.y));
			}
		}
	}

	private Camera CanvasCamera()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_uiCanvas == (Object)null || (int)_uiCanvas.renderMode == 0)
		{
			return null;
		}
		if ((Object)(object)_uiCanvas.worldCamera != (Object)null)
		{
			return _uiCanvas.worldCamera;
		}
		if ((Object)(object)_inventoryBookCache != (Object)null && (Object)(object)_inventoryBookCache.UiCamera != (Object)null)
		{
			return _inventoryBookCache.UiCamera;
		}
		return Camera.main;
	}

	private Camera InventoryLayoutCamera()
	{
		if ((Object)(object)_inventoryBookCache != (Object)null && (Object)(object)_inventoryBookCache.UiCamera != (Object)null)
		{
			return _inventoryBookCache.UiCamera;
		}
		return Camera.main;
	}

	private void HandleCanvasInput()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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)
		if (Input.GetMouseButtonDown(0))
		{
			HandlePointerPress(new Vector2(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y), isMouse: true);
		}
		if (Input.GetMouseButton(0) && (_svDragging || _hueDragging))
		{
			UpdatePickerDrag(new Vector2(Input.mousePosition.x, (float)Screen.height - Input.mousePosition.y));
		}
		if (Input.GetMouseButtonUp(0))
		{
			_svDragging = false;
			_hueDragging = false;
		}
		if (_acceptPressedFrame >= Time.frameCount - 1 && _acceptConsumedFrame != _acceptPressedFrame && TryGetControllerGuiPointer(out var guiPos) && HandlePointerPress(guiPos, isMouse: false))
		{
			_acceptConsumedFrame = _acceptPressedFrame;
		}
		if (_acceptHeld && (_svDragging || _hueDragging) && TryGetControllerGuiPointer(out guiPos))
		{
			UpdatePickerDrag(guiPos);
		}
		if (_acceptReleasedFrame >= Time.frameCount - 1)
		{
			_svDragging = false;
			_hueDragging = false;
		}
	}

	private bool HandlePointerPress(Vector2 guiPos, bool isMouse)
	{
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		if (_open)
		{
			if (((Rect)(ref _svGuiRect)).Contains(guiPos))
			{
				_svDragging = true;
				UpdatePickerDrag(guiPos);
				return true;
			}
			if (((Rect)(ref _hueGuiRect)).Contains(guiPos))
			{
				_hueDragging = true;
				UpdatePickerDrag(guiPos);
				return true;
			}
			if (((Rect)(ref _hexGuiRect)).Contains(guiPos))
			{
				if ((Object)(object)_hexField != (Object)null)
				{
					_hexField.ActivateInputField();
				}
				return true;
			}
			if (((Rect)(ref _useGuiRect)).Contains(guiPos))
			{
				UseColor();
				return true;
			}
			if (((Rect)(ref _saveGuiRect)).Contains(guiPos))
			{
				SaveColor();
				return true;
			}
			if (((Rect)(ref _pickGuiRect)).Contains(guiPos))
			{
				StartEyedropperMode();
				return true;
			}
			if (((Rect)(ref _cancelGuiRect)).Contains(guiPos))
			{
				_editingSavedColorIndex = -1;
				_open = false;
				return true;
			}
			if (((Rect)(ref _panelGuiRect)).Contains(guiPos))
			{
				return true;
			}
		}
		if (((Rect)(ref _toggleGuiRect)).Contains(guiPos))
		{
			_customMode = !_customMode;
			if (_customMode)
			{
				HideNativeButtons();
			}
			else
			{
				_open = false;
				_deleteMode = false;
				_editingSavedColorIndex = -1;
				HideCustomPaletteVisuals();
				ShowNativeButtons();
			}
			return true;
		}
		if (!_customMode)
		{
			return false;
		}
		if ((Object)(object)_trashRt != (Object)null && ((Component)_trashRt).gameObject.activeSelf && ((Rect)(ref _trashGuiRect)).Contains(guiPos))
		{
			_deleteMode = !_deleteMode;
			_editingSavedColorIndex = -1;
			if (_deleteMode)
			{
				ShowUserMessage("OCC: delete mode. Click one saved color to remove it.");
			}
			return true;
		}
		int num = 0;
		Rect val;
		while (!_deleteMode && num < _editGuiRects.Count)
		{
			val = _editGuiRects[num];
			if (((Rect)(ref val)).Contains(guiPos))
			{
				BeginEditSavedColor(num);
				return true;
			}
			num++;
		}
		for (int i = 0; i < _swatchGuiRects.Count; i++)
		{
			val = _swatchGuiRects[i];
			if (((Rect)(ref val)).Contains(guiPos))
			{
				if (_deleteMode)
				{
					DeleteSavedColor(i);
					return true;
				}
				SendColorChange(_savedColors[i]);
				_selectedIdx = i;
				return true;
			}
		}
		if ((Object)(object)_plusRt != (Object)null && ((Component)_plusRt).gameObject.activeSelf && ((Rect)(ref _plusGuiRect)).Contains(guiPos))
		{
			_deleteMode = false;
			_editingSavedColorIndex = -1;
			Open(_lastDisplayColor);
			return true;
		}
		return false;
	}

	private void StartEyedropperMode()
	{
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		if (!TryGetInventoryCursorForRequest(out var cursor) || (Object)(object)cursor == (Object)null)
		{
			ShowUserMessage("OCC: no inventory cursor found for color pick.");
			return;
		}
		_eyedropperController = ((((Cursor)cursor).LocalPlayer != null) ? ((Cursor)cursor).LocalPlayer.UseController : _acceptSender);
		_eyedropperPlayerNumber = ((Cursor)cursor).networkNumber;
		_pendingColorPageNumber = ((_allColorBtns != null && _allColorBtns.Length != 0 && (Object)(object)_allColorBtns[0] != (Object)null) ? ((PickableButton)_allColorBtns[0]).PageNumber : (((Object)(object)_inventoryBookCache != (Object)null) ? _inventoryBookCache.currentPage : (-1)));
		_eyedropperActive = true;
		_eyedropperCancelQueued = false;
		_pendingReopenPicker = false;
		_reopenGotoRequested = false;
		_open = false;
		SetPickerGraphicsVisible(visible: false);
		SetCanvasVisible(visible: false);
		GameEventManager.SendEvent((GameEvent)new PlayerInventoryEvent(false, _eyedropperPlayerNumber, false));
		HideInventoryCursorForEyedropper(cursor);
		ShowUserMessage("OCC eyedropper: hover a block and click to copy. Empty click or Back cancels. Escape is disabled in this mode.");
	}

	private void BeginEditSavedColor(int index)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		if (_savedColors != null && index >= 0 && index < _savedColors.Count)
		{
			_deleteMode = false;
			_editingSavedColorIndex = index;
			_selectedIdx = index;
			Open(_savedColors[index]);
			ShowUserMessage("OCC: editing saved color. Update Color replaces this slot.");
		}
	}

	private void DeleteSavedColor(int index)
	{
		if (_savedColors != null && index >= 0 && index < _savedColors.Count)
		{
			_savedColors.RemoveAt(index);
			if (_selectedIdx == index)
			{
				_selectedIdx = -1;
			}
			else if (_selectedIdx > index)
			{
				_selectedIdx--;
			}
			if (_editingSavedColorIndex == index)
			{
				_editingSavedColorIndex = -1;
			}
			else if (_editingSavedColorIndex > index)
			{
				_editingSavedColorIndex--;
			}
			SaveColors();
			_deleteMode = false;
			ShowUserMessage("OCC: deleted saved color.");
		}
	}

	private void HideInventoryCursorForEyedropper(PickCursor cursor)
	{
		if (!((Object)(object)cursor == (Object)null))
		{
			if (((Cursor)cursor).hoveredPick != null)
			{
				((Cursor)cursor).hoveredPick.IHoveredCursors.Remove((Cursor)(object)cursor);
				((Cursor)cursor).hoveredPick = null;
			}
			((Cursor)cursor).Disable(false, false);
		}
	}

	private bool TryGetInventoryCursorForRequest(out PickCursor cursor)
	{
		cursor = null;
		if ((Object)(object)_inventoryBookCache == (Object)null || _inventoryBookCache.cursors == null)
		{
			return false;
		}
		for (int i = 0; i < _inventoryBookCache.cursors.Count; i++)
		{
			PickCursor val = _inventoryBookCache.cursors[i];
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)_acceptSender != (Object)null && ((Cursor)val).LocalPlayer != null && (Object)(object)((Cursor)val).LocalPlayer.UseController == (Object)(object)_acceptSender)
				{
					cursor = val;
					return true;
				}
				if ((Object)(object)cursor == (Object)null)
				{
					cursor = val;
				}
			}
		}
		return (Object)(object)cursor != (Object)null;
	}

	private void HandlePendingPickerReopen()
	{
		if (!_pendingReopenPicker || (Object)(object)_inventoryBookCache == (Object)null || !_inventoryBookCache.Visible)
		{
			return;
		}
		if (_pendingColorPageNumber >= 0 && !_inventoryBookCache.ScreenMode && _inventoryBookCache.currentPage != _pendingColorPageNumber)
		{
			if (!_reopenGotoRequested)
			{
				_inventoryBookCache.GotoPage(_pendingColorPageNumber, false, false);
				_reopenGotoRequested = true;
			}
		}
		else if (_layoutReady && IsColorPageActive())
		{
			_customMode = true;
			_open = true;
			_pendingReopenPicker = false;
			_reopenGotoRequested = false;
		}
	}

	public bool HandleEyedropperWorldAccept(PiecePlacementCursor cursor)
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Expected O, but got Unknown
		if (!_eyedropperActive || (Object)(object)cursor == (Object)null || !EyedropperMatchesCursor(cursor))
		{
			return false;
		}
		if ((Object)(object)cursor.Piece != (Object)null)
		{
			ShowUserMessage("OCC: place or drop the held block before picking a color.");
			return true;
		}
		Placeable hoveredPiece = ((Cursor)cursor).hoveredPiece;
		if ((Object)(object)hoveredPiece == (Object)null || !hoveredPiece.canSetCustomColor || hoveredPiece.MarkedForDestruction || hoveredPiece.PickedUp)
		{
			CancelEyedropperMode(reopenPicker: true, ((Object)(object)hoveredPiece == (Object)null) ? "OCC: no block selected; color pick cancelled." : "OCC: that block has no custom color; color pick cancelled.");
			return true;
		}
		Color val = default(Color);
		((Color)(ref val))..ctor(hoveredPiece.CustomColor.r, hoveredPiece.CustomColor.g, hoveredPiece.CustomColor.b, 1f);
		Color currentDisplayColor = ToDisplayColor(val);
		SetCurrentDisplayColor(currentDisplayColor);
		_lastBackendColor = val;
		_lastBackendHex = ToHex(val.r, val.g, val.b);
		_eyedropperActive = false;
		_eyedropperController = null;
		_pendingReopenPicker = true;
		_reopenGotoRequested = false;
		_customMode = true;
		_open = true;
		GameEventManager.SendEvent((GameEvent)new PlayerInventoryEvent(true, _eyedropperPlayerNumber, false));
		ShowUserMessage("OCC: picked #" + _lastDisplayHex + ".");
		return true;
	}

	private bool EyedropperMatchesCursor(PiecePlacementCursor cursor)
	{
		if (_eyedropperPlayerNumber > 0)
		{
			return ((Cursor)cursor).networkNumber == _eyedropperPlayerNumber;
		}
		if ((Object)(object)_eyedropperController != (Obje