Decompiled source of DailyQuestTracker v0.2.1

plugins\StonewardsDailyQuestTracker.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace StonewardsDailyQuestTracker
{
	internal sealed class CurrencyHudAnchor
	{
		private const float RetrySeconds = 8f;

		private const int MaxAttemptsPerScene = 2;

		private const int MaxVisitedElements = 3500;

		private readonly ManualLogSource _log;

		private TextElement _currencyLabel;

		private VisualElement _badge;

		private float _nextProbe;

		private int _lastWidth;

		private int _lastHeight;

		private bool _loggedFailure;

		private int _attemptCount;

		public CurrencyHudAnchor(ManualLogSource log)
		{
			_log = log;
		}

		public void Reset()
		{
			_currencyLabel = null;
			_badge = null;
			_nextProbe = 0f;
			_lastWidth = 0;
			_lastHeight = 0;
			_loggedFailure = false;
			_attemptCount = 0;
		}

		public void RefreshIfNeeded()
		{
			if (Screen.width != _lastWidth || Screen.height != _lastHeight)
			{
				_lastWidth = Screen.width;
				_lastHeight = Screen.height;
				if (_currencyLabel == null || ((VisualElement)_currencyLabel).panel == null)
				{
					_nextProbe = 0f;
				}
			}
			if (_currencyLabel == null || ((VisualElement)_currencyLabel).panel == null)
			{
				_currencyLabel = null;
				_badge = null;
				if (_attemptCount < 2 && !(Time.unscaledTime < _nextProbe))
				{
					_nextProbe = Time.unscaledTime + 8f;
					_attemptCount++;
					Discover();
				}
			}
		}

		public bool TryGetPanelRoot(out VisualElement root)
		{
			//IL_003b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			root = null;
			if (_currencyLabel == null || ((VisualElement)_currencyLabel).panel == null)
			{
				return false;
			}
			root = ((VisualElement)_currencyLabel).panel.visualTree;
			if (root != null && root.panel != null)
			{
				Rect worldBound = root.worldBound;
				if (((Rect)(ref worldBound)).width > 1f)
				{
					worldBound = root.worldBound;
					return ((Rect)(ref worldBound)).height > 1f;
				}
			}
			return false;
		}

		public bool TryGetBadgeBounds(out Rect bounds)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			bounds = default(Rect);
			if (_currencyLabel == null || ((VisualElement)_currencyLabel).panel == null)
			{
				return false;
			}
			try
			{
				if (!IsVisible((VisualElement)(object)_currencyLabel))
				{
					return false;
				}
				return TryScreenBounds((VisualElement)((_badge != null && _badge.panel == ((VisualElement)_currencyLabel).panel) ? ((object)_badge) : ((object)_currencyLabel)), out bounds) && ((Rect)(ref bounds)).width > 1f && ((Rect)(ref bounds)).height > 1f;
			}
			catch (Exception)
			{
				_currencyLabel = null;
				_badge = null;
				return false;
			}
		}

		private void Discover()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				UIDocument[] array = Resources.FindObjectsOfTypeAll<UIDocument>();
				int num = 3500;
				float num2 = float.NegativeInfinity;
				TextElement val = null;
				VisualElement val2 = null;
				UIDocument[] array2 = array;
				foreach (UIDocument val3 in array2)
				{
					if (num <= 0)
					{
						break;
					}
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					Scene scene = ((Component)val3).gameObject.scene;
					if (!((Scene)(ref scene)).IsValid() || !((Component)val3).gameObject.activeInHierarchy)
					{
						continue;
					}
					VisualElement rootVisualElement = val3.rootVisualElement;
					if (rootVisualElement == null || rootVisualElement.panel == null)
					{
						continue;
					}
					Stack<VisualElement> stack = new Stack<VisualElement>();
					stack.Push(rootVisualElement);
					while (stack.Count != 0 && num-- > 0)
					{
						VisualElement val4 = stack.Pop();
						TextElement val5 = (TextElement)(object)((val4 is TextElement) ? val4 : null);
						if (val5 != null && HasCurrencyNumber(val5.text) && IsVisible((VisualElement)(object)val5) && TryScreenBounds((VisualElement)(object)val5, out var rect) && ((Rect)(ref rect)).xMin > (float)Screen.width * 0.63f && ((Rect)(ref rect)).yMin >= 0f && ((Rect)(ref rect)).yMax < (float)Screen.height * 0.23f)
						{
							float num3 = ((Rect)(ref rect)).xMax / (float)Screen.width * 2f - ((Rect)(ref rect)).yMin / (float)Screen.height;
							if (CurrencyKeywordNearby((VisualElement)(object)val5))
							{
								num3 += 4f;
							}
							if (val5.text.Trim().Length >= 4)
							{
								num3 += 0.2f;
							}
							if (num3 > num2)
							{
								num2 = num3;
								val = val5;
								val2 = FindCompactBadge((VisualElement)(object)val5, rect);
							}
						}
						for (int num4 = val4.childCount - 1; num4 >= 0; num4--)
						{
							stack.Push(val4.ElementAt(num4));
						}
					}
				}
				if (val != null)
				{
					_currencyLabel = val;
					_badge = (VisualElement)(((object)val2) ?? ((object)val));
					_loggedFailure = false;
					_log.LogInfo((object)"Currency HUD label located. Daily quest panel will follow the badge's live screen position.");
				}
				else if (!_loggedFailure)
				{
					_loggedFailure = true;
					_log.LogWarning((object)"Currency HUD label not located. Using manual top-right offsets until the native currency UI can be identified.");
				}
			}
			catch (Exception ex)
			{
				if (!_loggedFailure)
				{
					_loggedFailure = true;
					_log.LogWarning((object)("Currency HUD anchor discovery failed: " + ex.Message));
				}
			}
		}

		private static bool HasCurrencyNumber(string text)
		{
			if (string.IsNullOrWhiteSpace(text))
			{
				return false;
			}
			int num = 0;
			foreach (char c in text)
			{
				if (c >= '0' && c <= '9')
				{
					num++;
				}
				else if (!char.IsWhiteSpace(c) && c != ',' && c != '.' && c != '\u00a0')
				{
					return false;
				}
			}
			if (num >= 2)
			{
				return num <= 9;
			}
			return false;
		}

		private static bool CurrencyKeywordNearby(VisualElement element)
		{
			int num = 0;
			VisualElement val = element;
			while (val != null && num++ < 4)
			{
				if (HasCurrencyKeyword(val.name))
				{
					return true;
				}
				foreach (string @class in val.GetClasses())
				{
					if (HasCurrencyKeyword(@class))
					{
						return true;
					}
				}
				val = val.parent;
			}
			return false;
		}

		private static bool HasCurrencyKeyword(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return false;
			}
			string text = value.ToLowerInvariant();
			if (!text.Contains("currency") && !text.Contains("money") && !text.Contains("coin") && !text.Contains("gold"))
			{
				return text.Contains("metacurrency");
			}
			return true;
		}

		private static VisualElement FindCompactBadge(VisualElement label, Rect textBounds)
		{
			VisualElement result = label;
			int num = 0;
			VisualElement parent = label.parent;
			Rect rect;
			while (parent != null && num++ < 5 && TryScreenBounds(parent, out rect) && !(((Rect)(ref rect)).width > 390f) && !(((Rect)(ref rect)).height > 110f) && !(((Rect)(ref rect)).width < ((Rect)(ref textBounds)).width) && !(((Rect)(ref rect)).height < ((Rect)(ref textBounds)).height))
			{
				result = parent;
				parent = parent.parent;
			}
			return result;
		}

		private static bool IsVisible(VisualElement element)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			for (VisualElement val = element; val != null; val = val.parent)
			{
				if ((int)val.resolvedStyle.display == 1 || (int)val.resolvedStyle.visibility == 1 || val.resolvedStyle.opacity <= 0.01f)
				{
					return false;
				}
			}
			return element.panel != null;
		}

		private static bool TryScreenBounds(VisualElement element, out Rect rect)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			rect = default(Rect);
			if (element == null || element.panel == null)
			{
				return false;
			}
			Rect worldBound = element.panel.visualTree.worldBound;
			Rect worldBound2 = element.worldBound;
			if (((Rect)(ref worldBound)).width <= 0f || ((Rect)(ref worldBound)).height <= 0f || ((Rect)(ref worldBound2)).width <= 0f || ((Rect)(ref worldBound2)).height <= 0f)
			{
				return false;
			}
			float num = (float)Screen.width / ((Rect)(ref worldBound)).width;
			float num2 = (float)Screen.height / ((Rect)(ref worldBound)).height;
			rect = new Rect((((Rect)(ref worldBound2)).xMin - ((Rect)(ref worldBound)).xMin) * num, (((Rect)(ref worldBound2)).yMin - ((Rect)(ref worldBound)).yMin) * num2, ((Rect)(ref worldBound2)).width * num, ((Rect)(ref worldBound2)).height * num2);
			if (((Rect)(ref rect)).xMin >= -1f && ((Rect)(ref rect)).yMin >= -1f && ((Rect)(ref rect)).xMax <= (float)Screen.width + 1f)
			{
				return ((Rect)(ref rect)).yMax <= (float)Screen.height + 1f;
			}
			return false;
		}
	}
	internal sealed class DailyQuestReader
	{
		private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly Assembly GameAssembly = typeof(FirstPersonController).Assembly;

		private static readonly Type ManagerType = GameAssembly.GetType("QuestManager");

		private static readonly Type MissionType = GameAssembly.GetType("RuntimeMission");

		private static readonly Type QuestType = GameAssembly.GetType("QuestSO");

		private static readonly FieldInfo ManagerInstance = ManagerType?.GetField("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly PropertyInfo SelectedDaily = ManagerType?.GetProperty("CurrentDailyQuests", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo RuntimeMissions = ManagerType?.GetField("runtimeMissions", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo DailyQuestCount = ManagerType?.GetField("DAILY_QUESTS_COUNT", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly MethodInfo IsQuestCompleted = ((ManagerType != null && QuestType != null) ? ManagerType.GetMethod("IsQuestCompleted", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { QuestType }, null) : null);

		private static readonly FieldInfo MissionQuest = MissionType?.GetField("QuestSO", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionTypeField = MissionType?.GetField("missionType", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionCurrent = MissionType?.GetField("currentValue", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionTarget = MissionType?.GetField("target", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionReached = MissionType?.GetField("targetAlreadyReached", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly PropertyInfo MissionDescription = MissionType?.GetProperty("Description", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly PropertyInfo MissionTitle = MissionType?.GetProperty("Title", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo QuestId = QuestType?.GetField("ID", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private readonly ManualLogSource _log;

		private bool _reported;

		private readonly List<QuestView> _empty = new List<QuestView>(0);

		public int TotalDailyQuests { get; private set; }

		public bool HasSeenDailyQuests { get; private set; }

		public DailyQuestReader(ManualLogSource log)
		{
			_log = log;
			if (ManagerInstance == null || SelectedDaily == null || RuntimeMissions == null || MissionQuest == null || MissionTypeField == null || MissionCurrent == null || MissionTarget == null)
			{
				_log.LogError((object)"Stonewards daily quest API fields missing. Please capture F9 diagnostics for the installed game version.");
			}
			else
			{
				_log.LogInfo((object)"Daily quest API bound: QuestManager.CurrentDailyQuests + runtimeMissions (currentValue / target / missionType).");
			}
		}

		public void ResetSession()
		{
			_reported = false;
			TotalDailyQuests = 0;
			HasSeenDailyQuests = false;
		}

		public List<QuestView> ReadDailyQuests()
		{
			if (ManagerInstance == null || SelectedDaily == null || RuntimeMissions == null || MissionQuest == null || MissionTypeField == null || MissionCurrent == null || MissionTarget == null)
			{
				return _empty;
			}
			object obj = Get(ManagerInstance, null);
			if (obj == null)
			{
				return _empty;
			}
			IList list = Get(SelectedDaily, obj) as IList;
			IList list2 = Get(RuntimeMissions, obj) as IList;
			if (list == null || list2 == null)
			{
				WarnOnce("Daily quest selection or runtime missions are not initialized yet.");
				return _empty;
			}
			if (Get(DailyQuestCount, null) is int num && num > 0 && num <= 64)
			{
				TotalDailyQuests = Math.Max(num, list.Count);
			}
			else
			{
				TotalDailyQuests = Math.Max(TotalDailyQuests, list.Count);
			}
			List<QuestView> list3 = new List<QuestView>(list.Count);
			bool flag = default(bool);
			for (int i = 0; i < list.Count; i++)
			{
				object obj2 = list[i];
				if (obj2 == null)
				{
					continue;
				}
				string text = Get(QuestId, obj2) as string;
				object obj3 = null;
				foreach (object item in list2)
				{
					if (item == null)
					{
						continue;
					}
					object obj4 = Get(MissionTypeField, item);
					if (obj4 != null && string.Equals(obj4.ToString(), "DAILY", StringComparison.OrdinalIgnoreCase))
					{
						object obj5 = Get(MissionQuest, item);
						if (obj5 == obj2)
						{
							obj3 = item;
							break;
						}
						if (obj5 != null && !string.IsNullOrEmpty(text) && string.Equals(Get(QuestId, obj5) as string, text, StringComparison.Ordinal))
						{
							obj3 = item;
							break;
						}
					}
				}
				if (obj3 == null)
				{
					continue;
				}
				object obj6 = Get(MissionCurrent, obj3);
				object obj7 = Get(MissionTarget, obj3);
				if (obj6 is float num2 && obj7 is float num3 && !float.IsNaN(num2) && !float.IsNaN(num3) && !(num3 <= 0f))
				{
					object obj8 = Get(MissionReached, obj3);
					int num4;
					if (obj8 is bool)
					{
						flag = (bool)obj8;
						num4 = 1;
					}
					else
					{
						num4 = 0;
					}
					bool flag2 = (byte)((uint)num4 & (flag ? 1u : 0u)) != 0;
					bool flag3 = false;
					if (QuestType != null && QuestType.IsInstanceOfType(obj2) && IsQuestCompleted != null)
					{
						flag3 = GetCompleted(obj, obj2);
					}
					bool completed = flag3 || flag2 || num2 >= num3;
					string text2 = Get(MissionDescription, obj3) as string;
					if (string.IsNullOrWhiteSpace(text2))
					{
						text2 = Get(MissionTitle, obj3) as string;
					}
					if (string.IsNullOrWhiteSpace(text2))
					{
						text2 = text ?? "Daily quest";
					}
					list3.Add(new QuestView
					{
						Id = (text ?? text2),
						Title = text2,
						Progress = Mathf.Max(0, Mathf.RoundToInt(num2)),
						Target = Mathf.Max(1, Mathf.RoundToInt(num3)),
						Completed = completed
					});
				}
			}
			if (list3.Count > 0)
			{
				HasSeenDailyQuests = true;
				_reported = false;
			}
			else if (!HasSeenDailyQuests)
			{
				WarnOnce("No selected daily quests matched live DAILY runtime missions. Try opening Missions / Daily and press F9 if this persists.");
			}
			return list3;
		}

		private bool GetCompleted(object manager, object quest)
		{
			try
			{
				object obj = IsQuestCompleted.Invoke(manager, new object[1] { quest });
				bool flag = default(bool);
				int num;
				if (obj is bool)
				{
					flag = (bool)obj;
					num = 1;
				}
				else
				{
					num = 0;
				}
				return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			}
			catch (Exception)
			{
				return false;
			}
		}

		private void WarnOnce(string message)
		{
			if (!_reported)
			{
				_reported = true;
				_log.LogWarning((object)message);
			}
		}

		private static object Get(FieldInfo field, object instance)
		{
			if (field == null)
			{
				return null;
			}
			try
			{
				return field.GetValue(instance);
			}
			catch (Exception)
			{
				return null;
			}
		}

		private static object Get(PropertyInfo property, object instance)
		{
			if (property == null)
			{
				return null;
			}
			try
			{
				return property.GetValue(instance, null);
			}
			catch (Exception)
			{
				return null;
			}
		}
	}
	[BepInPlugin("community.stonewards.dailyquesttracker", "Stonewards Daily Quest Tracker", "0.2.1")]
	public sealed class DailyQuestTrackerPlugin : BaseUnityPlugin
	{
		public const string Guid = "community.stonewards.dailyquesttracker";

		public const string Name = "Stonewards Daily Quest Tracker";

		public const string Version = "0.2.1";

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<CompletedQuestMode> _completedQuestMode;

		private ConfigEntry<bool> _showMissingDataNotice;

		private ConfigEntry<PanelCorner> _corner;

		private ConfigEntry<int> _xOffset;

		private ConfigEntry<int> _yOffset;

		private ConfigEntry<float> _scale;

		private ConfigEntry<float> _readabilityScale;

		private ConfigEntry<bool> _autoScaleToResolution;

		private ConfigEntry<bool> _anchorToCurrencyHud;

		private ConfigEntry<bool> _renderBehindGameUi;

		private ConfigEntry<int> _currencyGap;

		private ConfigEntry<float> _refresh;

		private ConfigEntry<Key> _toggleKey;

		private ConfigEntry<Key> _diagnosticKey;

		private DailyQuestReader _reader;

		private QuestHud _hud;

		private CurrencyHudAnchor _currencyAnchor;

		private NativeHudLayer _nativeHudLayer;

		private PinnedMissions _pinned;

		private List<QuestView> _pinnedQuests = new List<QuestView>();

		private List<QuestView> _quests = new List<QuestView>();

		private float _nextUpdate;

		private float _nextError;

		private bool _visible = true;

		private bool _wasConnected;

		private float _lastDiagnosticTime = -100f;

		private float _statusUntil;

		private string _diagnosticStatus = "";

		private static readonly FieldInfo InventoryRoot = typeof(InventoryScreen).GetField("inventoryScreen", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo LoadingInstance = typeof(LoadingScreen).GetField("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo LoadingElement = typeof(LoadingScreen).GetField("_loadingScreenElement", BindingFlags.Instance | BindingFlags.NonPublic);

		private void Awake()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Expected O, but got Unknown
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable Daily Quest Tracker.");
			_completedQuestMode = ((BaseUnityPlugin)this).Config.Bind<CompletedQuestMode>("General", "CompletedQuestMode", CompletedQuestMode.Hide, "Hide completed daily quests (Hide), or keep them at the bottom with a green checkmark (Mark). The old HideCompleted setting is ignored.");
			_showMissingDataNotice = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowMissingQuestData", true, "Show a compact warning if the game has not initialized active daily quests.");
			_corner = ((BaseUnityPlugin)this).Config.Bind<PanelCorner>("Appearance", "Anchor", PanelCorner.TopRight, "Panel screen corner.");
			_xOffset = ((BaseUnityPlugin)this).Config.Bind<int>("Appearance", "HorizontalOffset", 18, "Horizontal edge inset in actual pixels.");
			_yOffset = ((BaseUnityPlugin)this).Config.Bind<int>("Appearance", "VerticalOffset", 240, "Vertical edge inset in actual pixels. Top-right default avoids the gold and Bell Control panels.");
			_scale = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "Scale", 1f, new ConfigDescription("Manual HUD size multiplier (0.65 - 1.8).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.65f, 1.8f), Array.Empty<object>()));
			_readabilityScale = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "ReadabilityScale", 1.12f, new ConfigDescription("Extra HUD enlargement, like PartyHUD (1.0 - 1.4).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 1.4f), Array.Empty<object>()));
			_autoScaleToResolution = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "AutoScaleToResolution", true, "Maintain the same HUD-to-screen proportions using 1920x1080 as a reference. Disable for a fixed physical-pixel panel size.");
			_anchorToCurrencyHud = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "AnchorToCurrencyHud", true, "When Anchor is TopRight, place the panel below the live coin HUD position. Falls back to manual offsets if the native currency badge is not found.");
			_currencyGap = ((BaseUnityPlugin)this).Config.Bind<int>("Appearance", "CurrencyGap", 10, new ConfigDescription("Gap below the coin HUD in physical screen pixels.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>()));
			_renderBehindGameUi = ((BaseUnityPlugin)this).Config.Bind<bool>("Appearance", "RenderBehindGameUI", true, "Draw the quest HUD inside the game's native UI Toolkit panel, beneath notifications. Set false to restore the original OnGUI rendering if needed.");
			_refresh = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RefreshSeconds", 1.25f, new ConfigDescription("How often to read actual quest progress (unscaled seconds).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 5f), Array.Empty<object>()));
			_toggleKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Hotkeys", "TogglePanel", (Key)99, "Toggle quest panel.");
			_diagnosticKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Hotkeys", "DumpQuestDiagnostics", (Key)102, "Write quest-system field names to BepInEx/config/StonewardsDailyQuestTracker-diagnostic.txt.");
			_pinned = new PinnedMissions(((BaseUnityPlugin)this).Config.Bind<string>("PinnedMissions", "QuestIds", "", "Persistent quest IDs, separated by |. Pin missions from the Missions menu."), ((BaseUnityPlugin)this).Config.Bind<string>("PinnedMissions", "QuestTitles", "", "Automatically saved localized titles of pinned missions. Used to restore labels when completed quests no longer have active runtime missions."), ((BaseUnityPlugin)this).Logger);
			_reader = new DailyQuestReader(((BaseUnityPlugin)this).Logger);
			_hud = new QuestHud();
			_currencyAnchor = new CurrencyHudAnchor(((BaseUnityPlugin)this).Logger);
			_nativeHudLayer = new NativeHudLayer(((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Daily Quest Tracker v0.2.0 loaded. Active missions: QuestManager runtime state. F6: panel, F9: diagnostic.");
		}

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			if (_nativeHudLayer != null)
			{
				_nativeHudLayer.Detach();
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (_reader != null)
			{
				_reader.ResetSession();
			}
			if (_currencyAnchor != null)
			{
				_currencyAnchor.Reset();
			}
			if (_nativeHudLayer != null)
			{
				_nativeHudLayer.Detach();
			}
			_quests.Clear();
			_pinnedQuests.Clear();
			_nextUpdate = 0f;
		}

		private void TryExportDiagnostics(string trigger)
		{
			if (!(Time.unscaledTime - _lastDiagnosticTime < 0.35f))
			{
				_lastDiagnosticTime = Time.unscaledTime;
				try
				{
					string text = QuestDiagnostics.Export(trigger);
					_diagnosticStatus = "QUEST DIAGNOSTICS SAVED - BepInEx/config";
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Quest diagnostics written to: " + text));
				}
				catch (Exception ex)
				{
					_diagnosticStatus = "QUEST DIAGNOSTICS FAILED - CHECK LOG";
					((BaseUnityPlugin)this).Logger.LogError((object)("Quest diagnostic export failed: " + ex));
				}
				_statusUntil = Time.unscaledTime + 6f;
			}
		}

		private void Update()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_01f8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Keyboard current = Keyboard.current;
				if (current != null)
				{
					if (current[_toggleKey.Value] != null && ((ButtonControl)current[_toggleKey.Value]).wasPressedThisFrame)
					{
						_visible = !_visible;
					}
					if (current[_diagnosticKey.Value] != null && ((ButtonControl)current[_diagnosticKey.Value]).wasPressedThisFrame)
					{
						TryExportDiagnostics("F9 hotkey");
					}
				}
				_pinned.UpdateMenu();
				if (!NetworkClient.active)
				{
					if (_wasConnected)
					{
						_reader.ResetSession();
						_currencyAnchor.Reset();
						_quests.Clear();
						_pinnedQuests.Clear();
					}
					_wasConnected = false;
					_nativeHudLayer.Detach();
					return;
				}
				if (!_wasConnected)
				{
					_reader.ResetSession();
					_currencyAnchor.Reset();
					_wasConnected = true;
					_nextUpdate = 0f;
				}
				if ((_anchorToCurrencyHud.Value && _corner.Value == PanelCorner.TopRight) || _renderBehindGameUi.Value)
				{
					_currencyAnchor.RefreshIfNeeded();
				}
				if (_renderBehindGameUi.Value && _currencyAnchor.TryGetPanelRoot(out var root))
				{
					_nativeHudLayer.Attach(root);
				}
				else
				{
					_nativeHudLayer.Detach();
				}
				if (Time.unscaledTime >= _nextUpdate)
				{
					_nextUpdate = Time.unscaledTime + _refresh.Value;
					_quests = _reader.ReadDailyQuests();
					_pinnedQuests = _pinned.Read();
				}
				if (_nativeHudLayer.Attached)
				{
					Rect bounds;
					Rect? currencyBadge = ((_anchorToCurrencyHud.Value && _corner.Value == PanelCorner.TopRight && _currencyAnchor.TryGetBadgeBounds(out bounds)) ? new Rect?(bounds) : ((Rect?)null));
					_nativeHudLayer.Sync(_quests, _enabled.Value && _visible && !IsBlocked(), _corner.Value, _xOffset.Value, _yOffset.Value, _scale.Value, _readabilityScale.Value, _autoScaleToResolution.Value, _completedQuestMode.Value, _showMissingDataNotice.Value, currencyBadge, _currencyGap.Value, _reader.TotalDailyQuests, _reader.HasSeenDailyQuests, _pinnedQuests);
				}
			}
			catch (Exception ex)
			{
				if (Time.unscaledTime >= _nextError)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Quest update failed (will retry): " + ex));
					_nextError = Time.unscaledTime + 15f;
				}
			}
		}

		private void OnGUI()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (Event.current == null)
			{
				return;
			}
			if ((int)Event.current.type == 4 && (int)_diagnosticKey.Value == 102 && (int)Event.current.keyCode == 290)
			{
				TryExportDiagnostics("F9 IMGUI fallback");
			}
			if ((int)Event.current.type == 7)
			{
				if (Time.unscaledTime < _statusUntil)
				{
					Color color = GUI.color;
					GUI.color = new Color(0.08f, 0.1f, 0.14f, 0.93f);
					GUI.DrawTexture(new Rect(18f, (float)(Screen.height - 72), 448f, 44f), (Texture)(object)Texture2D.whiteTexture);
					GUI.color = Color.white;
					GUI.Label(new Rect(29f, (float)(Screen.height - 67), 423f, 35f), _diagnosticStatus);
					GUI.color = color;
				}
				if (!_nativeHudLayer.IsDrawing)
				{
					DrawHud(1f, 1f);
				}
			}
		}

		private void DrawHud(float unitsPerPixelX, float unitsPerPixelY, float originScreenX = 0f, float originScreenY = 0f)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (_enabled.Value && _visible && NetworkClient.active && !IsBlocked() && (_quests.Count != 0 || _showMissingDataNotice.Value || _reader.HasSeenDailyQuests || _pinnedQuests.Count != 0))
			{
				Rect bounds;
				Rect? currencyBadge = ((_anchorToCurrencyHud.Value && _corner.Value == PanelCorner.TopRight && _currencyAnchor.TryGetBadgeBounds(out bounds)) ? new Rect?(bounds) : ((Rect?)null));
				_hud.Draw(_quests, _corner.Value, _xOffset.Value, _yOffset.Value, _scale.Value, _readabilityScale.Value, _autoScaleToResolution.Value, _completedQuestMode.Value, _showMissingDataNotice.Value, currencyBadge, _currencyGap.Value, _reader.TotalDailyQuests, _reader.HasSeenDailyQuests, _pinnedQuests, unitsPerPixelX, unitsPerPixelY, originScreenX, originScreenY);
			}
		}

		private static bool IsBlocked()
		{
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Invalid comparison between Unknown and I4
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Invalid comparison between Unknown and I4
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Invalid comparison between Unknown and I4
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Invalid comparison between Unknown and I4
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Invalid comparison between Unknown and I4
			try
			{
				if (LoadingInstance != null && LoadingElement != null)
				{
					object value = LoadingInstance.GetValue(null);
					VisualElement val = (VisualElement)((value == null) ? null : /*isinst with value type is only supported in some contexts*/);
					if (val != null && val.panel != null)
					{
						bool flag = true;
						for (VisualElement val2 = val; val2 != null; val2 = val2.parent)
						{
							if ((int)val2.resolvedStyle.display == 1 || (int)val2.resolvedStyle.visibility == 1 || val2.resolvedStyle.opacity <= 0.01f)
							{
								flag = false;
							}
						}
						if (flag)
						{
							return true;
						}
					}
				}
				ShopMenu instance = ShopMenu.Instance;
				if ((Object)(object)instance != (Object)null && ((BaseMenu)instance).IsOpen)
				{
					return true;
				}
				CharacterSelectionScreen instance2 = CharacterSelectionScreen.Instance;
				if ((Object)(object)instance2 != (Object)null && ((BaseMenu)instance2).IsOpen)
				{
					return true;
				}
				GlobalMissionMenu instance3 = GlobalMissionMenu.Instance;
				if ((Object)(object)instance3 != (Object)null && ((BaseMenu)instance3).IsOpen)
				{
					return true;
				}
				RogueLikeUpgradeMenu instance4 = RogueLikeUpgradeMenu.Instance;
				if ((Object)(object)instance4 != (Object)null && ((BaseMenu)instance4).IsOpen)
				{
					return true;
				}
				InventoryScreen instance5 = InventoryScreen.Instance;
				if ((Object)(object)instance5 != (Object)null && InventoryRoot != null)
				{
					object? value2 = InventoryRoot.GetValue(instance5);
					VisualElement val3 = (VisualElement)((value2 is VisualElement) ? value2 : null);
					if (val3 != null && val3.panel != null && (int)val3.resolvedStyle.display != 1)
					{
						return true;
					}
				}
				InputManager instance6 = InputManager.Instance;
				return (Object)(object)instance6 != (Object)null && (int)instance6.CurrentInputState != 2 && (int)instance6.CurrentInputState != 4;
			}
			catch
			{
				return false;
			}
		}
	}
	internal enum PanelCorner
	{
		TopRight,
		TopLeft,
		BottomRight,
		BottomLeft
	}
	internal enum CompletedQuestMode
	{
		Hide,
		Mark
	}
	internal sealed class QuestView
	{
		public string Id;

		public string Title;

		public int? Progress;

		public int? Target;

		public bool Completed;
	}
	internal sealed class NativeHudLayer
	{
		private const float Width = 310f;

		private const float HeaderHeight = 32f;

		private const float ItemHeight = 30f;

		private const float FooterHeight = 18f;

		private const float EdgeMargin = 8f;

		private const int MaxRows = 5;

		private const float PinnedGap = 8f;

		private const float ReferenceWidth = 1920f;

		private const float ReferenceHeight = 1080f;

		private const float PanelSizeBoost = 0.95f;

		private const float RetrySeconds = 5f;

		private static readonly Color GoldFrame = new Color(0.72f, 0.64f, 0.48f, 1f);

		private static readonly Color MainFill = new Color(0.07450981f, 0.09019608f, 0.1254902f, 0.96f);

		private static readonly Color HeaderFill = new Color(0.29803923f, 0.18039216f, 16f / 85f, 1f);

		private static readonly Color GoldText = new Color(0.98f, 0.79f, 0.51f, 1f);

		private static readonly Color PrimaryText = new Color(0.98f, 0.9f, 0.76f, 1f);

		private static readonly Color SuccessText = new Color(0.47f, 0.87f, 0.56f, 1f);

		private static readonly Color RowDivider = new Color(0.71f, 0.63f, 0.48f, 0.27f);

		private readonly ManualLogSource _log;

		private VisualElement _panelRoot;

		private VisualElement _parent;

		private VisualElement _notificationBranch;

		private VisualElement _panel;

		private readonly VisualElement[] _backgroundPieces = (VisualElement[])(object)new VisualElement[2];

		private readonly VisualElement[] _headerPieces = (VisualElement[])(object)new VisualElement[2];

		private readonly VisualElement[] _framePieces = (VisualElement[])(object)new VisualElement[12];

		private VisualElement _headerDivider;

		private VisualElement _headerAccent;

		private Label _heading;

		private Label _count;

		private Label _empty;

		private Label _footer;

		private readonly VisualElement[] _bars = (VisualElement[])(object)new VisualElement[5];

		private readonly Label[] _ticks = (Label[])(object)new Label[5];

		private readonly Label[] _titles = (Label[])(object)new Label[5];

		private readonly Label[] _counters = (Label[])(object)new Label[5];

		private readonly VisualElement[] _dividers = (VisualElement[])(object)new VisualElement[5];

		private readonly bool[] _completedRows = new bool[5];

		private VisualElement _pinnedGroup;

		private readonly VisualElement[] _pinBackground = (VisualElement[])(object)new VisualElement[2];

		private readonly VisualElement[] _pinHeader = (VisualElement[])(object)new VisualElement[2];

		private readonly VisualElement[] _pinFrame = (VisualElement[])(object)new VisualElement[12];

		private VisualElement _pinDivider;

		private Label _pinHeading;

		private Label _pinCount;

		private readonly VisualElement[] _pinBars = (VisualElement[])(object)new VisualElement[5];

		private readonly Label[] _pinTicks = (Label[])(object)new Label[5];

		private readonly Label[] _pinTitles = (Label[])(object)new Label[5];

		private readonly Label[] _pinCounters = (Label[])(object)new Label[5];

		private readonly VisualElement[] _pinDividers = (VisualElement[])(object)new VisualElement[5];

		private List<QuestView> _previousPins;

		private Font _font;

		private Font _checkFont;

		private float _nextSearch;

		private bool _reportedFailure;

		private float _previousX = float.NaN;

		private float _previousY = float.NaN;

		private float _previousSx = float.NaN;

		private float _previousSy = float.NaN;

		private float _previousHeight = float.NaN;

		private List<QuestView> _previousQuests;

		private CompletedQuestMode _previousMode;

		private int _previousTotal = -1;

		private bool _previousHasSeen;

		public bool Attached
		{
			get
			{
				if (_panel != null && _parent != null && _panelRoot != null && _notificationBranch != null && _panel.parent == _parent && _notificationBranch.parent == _parent && _panel.panel != null)
				{
					return _panel.panel == _panelRoot.panel;
				}
				return false;
			}
		}

		public bool IsDrawing
		{
			get
			{
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Invalid comparison between Unknown and I4
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: 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)
				if (Attached && (int)_panel.resolvedStyle.display != 1)
				{
					Rect worldBound = _panel.worldBound;
					if (((Rect)(ref worldBound)).width > 2f)
					{
						worldBound = _panel.worldBound;
						return ((Rect)(ref worldBound)).height > 2f;
					}
				}
				return false;
			}
		}

		public NativeHudLayer(ManualLogSource log)
		{
			_log = log;
		}

		public void Attach(VisualElement root)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if (root == null || root.panel == null)
			{
				Detach();
			}
			else
			{
				if (Attached && _panelRoot == root)
				{
					return;
				}
				if (_panel != null)
				{
					Detach();
				}
				if (Time.unscaledTime < _nextSearch)
				{
					return;
				}
				try
				{
					VisualElement val = UQueryExtensions.Q<VisualElement>(root, "QuestNotificationHolder", (string)null);
					if (val == null || val.panel != root.panel)
					{
						Retry("QuestNotificationHolder unavailable.");
						return;
					}
					VisualElement val2 = val;
					VisualElement parent = val.parent;
					Rect worldBound = root.worldBound;
					while (parent != null && !CoversViewport(parent.worldBound, worldBound))
					{
						val2 = parent;
						parent = parent.parent;
					}
					if (parent == null)
					{
						Retry("No screen-sized ancestor for QuestNotificationHolder.");
						return;
					}
					InitializeStyles();
					BuildPanel();
					parent.Add(_panel);
					val2.BringToFront();
					_panelRoot = root;
					_parent = parent;
					_notificationBranch = val2;
					_previousQuests = null;
					_previousHeight = float.NaN;
					_previousX = float.NaN;
					_reportedFailure = false;
					_log.LogInfo((object)("Native quest HUD inserted before notification branch '" + val2.name + "'. No IMGUIContainer is used."));
				}
				catch (Exception ex)
				{
					Detach();
					Retry("Native quest HUD failed: " + ex.Message);
				}
			}
		}

		private void Retry(string reason)
		{
			_nextSearch = Time.unscaledTime + 5f;
			if (!_reportedFailure)
			{
				_reportedFailure = true;
				_log.LogWarning((object)(reason + " Using legacy OnGUI HUD."));
			}
		}

		private static bool CoversViewport(Rect candidate, Rect viewport)
		{
			if (((Rect)(ref candidate)).width >= ((Rect)(ref viewport)).width * 0.92f && ((Rect)(ref candidate)).height >= ((Rect)(ref viewport)).height * 0.92f && ((Rect)(ref candidate)).xMin <= ((Rect)(ref viewport)).xMin + ((Rect)(ref viewport)).width * 0.04f && ((Rect)(ref candidate)).yMin <= ((Rect)(ref viewport)).yMin + ((Rect)(ref viewport)).height * 0.04f && ((Rect)(ref candidate)).xMax >= ((Rect)(ref viewport)).xMax - ((Rect)(ref viewport)).width * 0.04f)
			{
				return ((Rect)(ref candidate)).yMax >= ((Rect)(ref viewport)).yMax - ((Rect)(ref viewport)).height * 0.04f;
			}
			return false;
		}

		public void Sync(List<QuestView> quests, bool visible, PanelCorner anchor, int horizontalInset, int verticalInset, float requestedScale, float readabilityScale, bool autoScaleToResolution, CompletedQuestMode completedMode, bool showStatus, Rect? currencyBadge, int currencyGap, int totalDailyQuests, bool hasSeenDailyQuests, List<QuestView> pinned)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Invalid comparison between Unknown and I4
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: 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_0393: 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_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: 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_0440: Unknown result type (might be due to invalid IL or missing references)
			if (!Attached)
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < quests.Count; i++)
			{
				if (!quests[i].Completed)
				{
					num++;
				}
			}
			int num2 = ((completedMode == CompletedQuestMode.Hide) ? num : quests.Count);
			bool flag = num2 == 0;
			int num3 = Math.Min(pinned.Count, 5);
			if (!visible || (num3 <= 0 && flag && quests.Count == 0 && !showStatus && !hasSeenDailyQuests))
			{
				_panel.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)1);
				return;
			}
			if ((int)_panel.resolvedStyle.display == 1)
			{
				_panel.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)0);
			}
			int num4 = Math.Min(num2, 5);
			int num5 = Math.Max(0, num2 - num4);
			float num6 = 32f + (flag ? 39f : ((float)num4 * 30f + 5f)) + ((num5 > 0) ? 18f : 0f);
			float num7 = ((num3 > 0) ? (32f + (float)num3 * 30f + 5f) : 0f);
			float num8 = num6 + ((num3 > 0) ? (8f + num7) : 0f);
			float num9 = Mathf.Clamp(requestedScale * Mathf.Clamp(readabilityScale, 1f, 1.4f) * 0.95f, 0.55f, 1.8f);
			float num10 = (autoScaleToResolution ? Mathf.Min((float)Screen.width / 1920f, (float)Screen.height / 1080f) : 1f);
			float num11 = num9 * num10;
			num11 = Mathf.Min(new float[3]
			{
				num11,
				((float)Screen.width - 16f) / 310f,
				((float)Screen.height - 16f) / num8
			});
			Rect value;
			int num12;
			if (anchor == PanelCorner.TopRight && currencyBadge.HasValue)
			{
				value = currencyBadge.Value;
				if (((Rect)(ref value)).yMax >= 0f)
				{
					value = currencyBadge.Value;
					num12 = ((((Rect)(ref value)).yMax < (float)Screen.height - 60f) ? 1 : 0);
					goto IL_020d;
				}
			}
			num12 = 0;
			goto IL_020d;
			IL_020d:
			bool flag2 = (byte)num12 != 0;
			float num13;
			if (!flag2)
			{
				num13 = 0f;
			}
			else
			{
				value = currencyBadge.Value;
				num13 = ((Rect)(ref value)).yMax;
			}
			float num14 = num13;
			float num15 = Mathf.Max(0, currencyGap);
			if (flag2)
			{
				float num16 = (float)Screen.height - 8f - num14 - num15;
				if (num16 >= 48f)
				{
					num11 = Mathf.Min(num11, num16 / num8);
				}
				else
				{
					flag2 = false;
				}
			}
			if (autoScaleToResolution && !flag2)
			{
				float num17 = (float)Screen.height - Mathf.Max(8f, (float)verticalInset) - 8f;
				if (num17 >= 72f)
				{
					num11 = Mathf.Min(num11, num17 / num8);
				}
			}
			if (!(num11 <= 0f))
			{
				float num18 = 310f * num11;
				float num19 = num8 * num11;
				bool num20 = anchor == PanelCorner.TopRight || anchor == PanelCorner.BottomRight;
				bool flag3 = anchor == PanelCorner.BottomRight || anchor == PanelCorner.BottomLeft;
				float num21 = (num20 ? ((float)Screen.width - Mathf.Max(8f, (float)horizontalInset) - num18) : Mathf.Max(8f, (float)horizontalInset));
				float num22 = (flag3 ? ((float)Screen.height - Mathf.Max(8f, (float)verticalInset) - num19) : Mathf.Max(8f, (float)verticalInset));
				if (flag2)
				{
					value = currencyBadge.Value;
					num21 = ((Rect)(ref value)).xMax - num18;
					num22 = num14 + num15;
				}
				num21 = Mathf.Clamp(num21, 8f, (float)Screen.width - num18 - 8f);
				num22 = Mathf.Clamp(num22, 8f, (float)Screen.height - num19 - 8f);
				Rect worldBound = _panelRoot.worldBound;
				Rect worldBound2 = _parent.worldBound;
				float num23 = ((Rect)(ref worldBound)).width / (float)Screen.width;
				float num24 = ((Rect)(ref worldBound)).height / (float)Screen.height;
				float num25 = num21 * num23 - (((Rect)(ref worldBound2)).xMin - ((Rect)(ref worldBound)).xMin);
				float num26 = num22 * num24 - (((Rect)(ref worldBound2)).yMin - ((Rect)(ref worldBound)).yMin);
				float num27 = num11 * num23;
				float num28 = num11 * num24;
				if (Different(num25, _previousX) || Different(num26, _previousY))
				{
					_panel.style.left = StyleLength.op_Implicit(num25);
					_panel.style.top = StyleLength.op_Implicit(num26);
					_previousX = num25;
					_previousY = num26;
				}
				bool flag4 = Different(num27, _previousSx) || Different(num28, _previousSy) || Different(num8, _previousHeight);
				if (flag4)
				{
					Layout(num27, num28, num6, num8, num4, num5, num3);
					_previousSx = num27;
					_previousSy = num28;
					_previousHeight = num8;
				}
				int num29 = Math.Max(quests.Count, totalDailyQuests);
				if (_previousQuests != quests || _previousMode != completedMode || _previousTotal != num29 || _previousHasSeen != hasSeenDailyQuests || flag4)
				{
					Populate(quests, completedMode, num, num29, num4, num5, flag, hasSeenDailyQuests);
					_previousQuests = quests;
					_previousMode = completedMode;
					_previousTotal = num29;
					_previousHasSeen = hasSeenDailyQuests;
				}
				if (_previousPins != pinned || flag4)
				{
					PopulatePins(pinned);
					_previousPins = pinned;
				}
			}
		}

		private static bool Different(float a, float b)
		{
			if (!float.IsNaN(b))
			{
				return Mathf.Abs(a - b) > 0.01f;
			}
			return true;
		}

		private void InitializeStyles()
		{
			if ((Object)(object)_font != (Object)null)
			{
				return;
			}
			Font[] array = Resources.FindObjectsOfTypeAll<Font>();
			foreach (Font val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					if (((Object)val).name == "Jersey10-Regular")
					{
						_font = val;
						break;
					}
					if ((Object)(object)_font == (Object)null && ((Object)val).name == "Jersey10-Regular2")
					{
						_font = val;
					}
				}
			}
			try
			{
				_checkFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
			}
			catch (Exception)
			{
			}
			if ((Object)(object)_font == (Object)null)
			{
				_font = _checkFont;
			}
		}

		private void BuildPanel()
		{
			//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_0016: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: 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_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			_panel = new VisualElement
			{
				name = "StonewardsDailyQuestTracker"
			};
			_panel.pickingMode = (PickingMode)1;
			_panel.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			_panel.style.backgroundColor = StyleColor.op_Implicit(Color.clear);
			_panel.style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			for (int i = 0; i < _backgroundPieces.Length; i++)
			{
				_backgroundPieces[i] = MakeRect(_panel, MainFill);
			}
			for (int j = 0; j < _headerPieces.Length; j++)
			{
				_headerPieces[j] = MakeRect(_panel, HeaderFill);
			}
			for (int k = 0; k < _framePieces.Length; k++)
			{
				_framePieces[k] = MakeRect(_panel, GoldFrame);
			}
			_headerDivider = MakeRect(_panel, GoldFrame);
			_headerAccent = MakeRect(_panel, GoldText);
			_heading = MakeLabel(_panel, GoldText, (TextAnchor)3);
			_count = MakeLabel(_panel, GoldText, (TextAnchor)5);
			_empty = MakeLabel(_panel, PrimaryText, (TextAnchor)4);
			_footer = MakeLabel(_panel, GoldText, (TextAnchor)4);
			((TextElement)_heading).text = "DAILY QUESTS";
			for (int l = 0; l < 5; l++)
			{
				_bars[l] = MakeRect(_panel, GoldText);
				_ticks[l] = MakeLabel(_panel, SuccessText, (TextAnchor)3, _checkFont);
				((TextElement)_ticks[l]).text = "✔";
				_titles[l] = MakeLabel(_panel, PrimaryText, (TextAnchor)3);
				_counters[l] = MakeLabel(_panel, GoldText, (TextAnchor)5);
				_dividers[l] = MakeRect(_panel, RowDivider);
			}
			_pinnedGroup = new VisualElement
			{
				name = "DailyQuestTrackerPinnedMissions",
				pickingMode = (PickingMode)1
			};
			_pinnedGroup.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			_pinnedGroup.style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			_panel.Add(_pinnedGroup);
			for (int m = 0; m < 2; m++)
			{
				_pinBackground[m] = MakeRect(_pinnedGroup, MainFill);
				_pinHeader[m] = MakeRect(_pinnedGroup, HeaderFill);
			}
			for (int n = 0; n < _pinFrame.Length; n++)
			{
				_pinFrame[n] = MakeRect(_pinnedGroup, GoldFrame);
			}
			_pinDivider = MakeRect(_pinnedGroup, GoldFrame);
			_pinHeading = MakeLabel(_pinnedGroup, GoldText, (TextAnchor)3);
			((TextElement)_pinHeading).text = "PINNED QUESTS";
			_pinCount = MakeLabel(_pinnedGroup, GoldText, (TextAnchor)5);
			for (int num = 0; num < 5; num++)
			{
				_pinBars[num] = MakeRect(_pinnedGroup, GoldText);
				_pinTicks[num] = MakeLabel(_pinnedGroup, SuccessText, (TextAnchor)3, _checkFont);
				((TextElement)_pinTicks[num]).text = "✔";
				_pinTitles[num] = MakeLabel(_pinnedGroup, PrimaryText, (TextAnchor)3);
				_pinCounters[num] = MakeLabel(_pinnedGroup, GoldText, (TextAnchor)5);
				_pinDividers[num] = MakeRect(_pinnedGroup, RowDivider);
			}
		}

		private static VisualElement MakeRect(VisualElement parent, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0014: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			VisualElement val = new VisualElement
			{
				pickingMode = (PickingMode)1
			};
			val.style.position = StyleEnum<Position>.op_Implicit((Position)1);
			val.style.backgroundColor = StyleColor.op_Implicit(color);
			parent.Add(val);
			return val;
		}

		private Label MakeLabel(VisualElement parent, Color color, TextAnchor anchor, Font font = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0014: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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)
			Label val = new Label
			{
				pickingMode = (PickingMode)1
			};
			((VisualElement)val).style.position = StyleEnum<Position>.op_Implicit((Position)1);
			((VisualElement)val).style.color = StyleColor.op_Implicit(color);
			((VisualElement)val).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit(anchor);
			((VisualElement)val).style.whiteSpace = StyleEnum<WhiteSpace>.op_Implicit((WhiteSpace)1);
			((VisualElement)val).style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)1);
			if ((Object)(object)font != (Object)null || (Object)(object)_font != (Object)null)
			{
				((VisualElement)val).style.unityFont = StyleFont.op_Implicit(font ?? _font);
			}
			parent.Add((VisualElement)(object)val);
			return val;
		}

		private static void SetRect(VisualElement element, float x, float y, float width, float height, float sx, float sy)
		{
			//IL_000a: 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_003c: 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)
			element.style.left = StyleLength.op_Implicit(x * sx);
			element.style.top = StyleLength.op_Implicit(y * sy);
			element.style.width = StyleLength.op_Implicit(Mathf.Max(0f, width * sx));
			element.style.height = StyleLength.op_Implicit(Mathf.Max(0f, height * sy));
		}

		private static void SetFont(Label label, float points, float sy)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			((VisualElement)label).style.fontSize = StyleLength.op_Implicit(Mathf.Max(9f, points * sy));
		}

		private void Layout(float sx, float sy, float height, float totalHeight, int rows, int overflow, int pinRows)
		{
			//IL_0012: 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)
			_panel.style.width = StyleLength.op_Implicit(310f * sx);
			_panel.style.height = StyleLength.op_Implicit(totalHeight * sy);
			SetRect(_backgroundPieces[0], 7f, 0f, 296f, height, sx, sy);
			SetRect(_backgroundPieces[1], 0f, 7f, 310f, height - 14f, sx, sy);
			SetRect(_headerPieces[0], 7f, 2f, 296f, 30f, sx, sy);
			SetRect(_headerPieces[1], 2f, 7f, 306f, 25f, sx, sy);
			SetRect(_framePieces[0], 8f, 0f, 294f, 2f, sx, sy);
			SetRect(_framePieces[1], 5f, 2f, 3f, 2f, sx, sy);
			SetRect(_framePieces[2], 2f, 5f, 3f, 2f, sx, sy);
			SetRect(_framePieces[3], 302f, 2f, 3f, 2f, sx, sy);
			SetRect(_framePieces[4], 305f, 5f, 3f, 2f, sx, sy);
			SetRect(_framePieces[5], 0f, 7f, 2f, height - 14f, sx, sy);
			SetRect(_framePieces[6], 308f, 7f, 2f, height - 14f, sx, sy);
			SetRect(_framePieces[7], 8f, height - 2f, 294f, 2f, sx, sy);
			SetRect(_framePieces[8], 5f, height - 4f, 3f, 2f, sx, sy);
			SetRect(_framePieces[9], 2f, height - 7f, 3f, 2f, sx, sy);
			SetRect(_framePieces[10], 302f, height - 4f, 3f, 2f, sx, sy);
			SetRect(_framePieces[11], 305f, height - 7f, 3f, 2f, sx, sy);
			SetRect(_headerDivider, 2f, 31f, 306f, 1f, sx, sy);
			SetRect(_headerAccent, 10f, 28f, 46f, 1f, sx, sy);
			SetRect((VisualElement)(object)_heading, 13f, 3f, 178f, 26f, sx, sy);
			SetRect((VisualElement)(object)_count, 190f, 3f, 105f, 26f, sx, sy);
			SetRect((VisualElement)(object)_empty, 13f, 37f, 284f, 30f, sx, sy);
			SetRect((VisualElement)(object)_footer, 13f, 35f + (float)rows * 30f, 284f, 16f, sx, sy);
			SetFont(_heading, 18f, sy);
			SetFont(_count, 16f, sy);
			SetFont(_empty, 15f, sy);
			SetFont(_footer, 13f, sy);
			for (int i = 0; i < 5; i++)
			{
				float num = 35f + (float)i * 30f;
				SetRect(_bars[i], 8f, num + 6f, 2f, 17f, sx, sy);
				SetRect((VisualElement)(object)_ticks[i], 7f, num + 2f, 24f, 24f, sx, sy);
				SetRect((VisualElement)(object)_titles[i], 16f, num + 1f, 219f, 24f, sx, sy);
				SetRect((VisualElement)(object)_counters[i], 240f, num + 1f, 57f, 24f, sx, sy);
				SetRect(_dividers[i], 11f, num + 30f - 2f, 288f, 1f, sx, sy);
				SetFont(_ticks[i], 19f, sy);
				SetFont(_titles[i], 17f, sy);
				SetFont(_counters[i], 16f, sy);
			}
			LayoutPins(sx, sy, height, pinRows);
		}

		private void LayoutPins(float sx, float sy, float dailyHeight, int rows)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			_pinnedGroup.style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(rows <= 0));
			if (rows != 0)
			{
				float num = 32f + (float)rows * 30f + 5f;
				SetRect(_pinnedGroup, 0f, dailyHeight + 8f, 310f, num, sx, sy);
				SetRect(_pinBackground[0], 7f, 0f, 296f, num, sx, sy);
				SetRect(_pinBackground[1], 0f, 7f, 310f, num - 14f, sx, sy);
				SetRect(_pinHeader[0], 7f, 2f, 296f, 30f, sx, sy);
				SetRect(_pinHeader[1], 2f, 7f, 306f, 25f, sx, sy);
				SetRect(_pinFrame[0], 8f, 0f, 294f, 2f, sx, sy);
				SetRect(_pinFrame[1], 5f, 2f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[2], 2f, 5f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[3], 302f, 2f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[4], 305f, 5f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[5], 0f, 7f, 2f, num - 14f, sx, sy);
				SetRect(_pinFrame[6], 308f, 7f, 2f, num - 14f, sx, sy);
				SetRect(_pinFrame[7], 8f, num - 2f, 294f, 2f, sx, sy);
				SetRect(_pinFrame[8], 5f, num - 4f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[9], 2f, num - 7f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[10], 302f, num - 4f, 3f, 2f, sx, sy);
				SetRect(_pinFrame[11], 305f, num - 7f, 3f, 2f, sx, sy);
				SetRect(_pinDivider, 2f, 31f, 306f, 1f, sx, sy);
				SetRect((VisualElement)(object)_pinHeading, 13f, 3f, 178f, 26f, sx, sy);
				SetRect((VisualElement)(object)_pinCount, 190f, 3f, 105f, 26f, sx, sy);
				SetFont(_pinHeading, 18f, sy);
				SetFont(_pinCount, 15f, sy);
				for (int i = 0; i < 5; i++)
				{
					float num2 = 35f + (float)i * 30f;
					SetRect(_pinBars[i], 8f, num2 + 6f, 2f, 17f, sx, sy);
					SetRect((VisualElement)(object)_pinTicks[i], 7f, num2 + 2f, 24f, 24f, sx, sy);
					SetRect((VisualElement)(object)_pinTitles[i], 16f, num2 + 1f, 219f, 24f, sx, sy);
					SetRect((VisualElement)(object)_pinCounters[i], 240f, num2 + 1f, 57f, 24f, sx, sy);
					SetRect(_pinDividers[i], 11f, num2 + 30f - 2f, 288f, 1f, sx, sy);
					SetFont(_pinTicks[i], 19f, sy);
					SetFont(_pinTitles[i], 17f, sy);
					SetFont(_pinCounters[i], 16f, sy);
				}
			}
		}

		private void PopulatePins(List<QuestView> pins)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00ed: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			int num = Math.Min(pins.Count, 5);
			((TextElement)_pinCount).text = num + "/" + 5;
			for (int i = 0; i < 5; i++)
			{
				bool flag = i < num;
				QuestView questView = (flag ? pins[i] : null);
				bool flag2 = flag && questView.Completed;
				_pinBars[i].style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)((!flag || flag2) ? 1 : 0));
				((VisualElement)_pinTicks[i]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag2));
				((VisualElement)_pinTitles[i]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag));
				((VisualElement)_pinCounters[i]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag));
				_pinDividers[i].style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag));
				if (flag)
				{
					((VisualElement)_pinTitles[i]).style.color = StyleColor.op_Implicit(flag2 ? SuccessText : PrimaryText);
					((VisualElement)_pinCounters[i]).style.color = StyleColor.op_Implicit(flag2 ? SuccessText : GoldText);
					((TextElement)_pinTitles[i]).text = questView.Title ?? "Mission";
					((TextElement)_pinCounters[i]).text = ((questView.Progress.HasValue && questView.Target.HasValue) ? (Math.Min(questView.Progress.Value, questView.Target.Value) + "/" + questView.Target.Value) : (flag2 ? "DONE" : "—"));
				}
			}
		}

		private void Populate(List<QuestView> quests, CompletedQuestMode mode, int remaining, int total, int rows, int overflow, bool empty, bool hasSeenDailyQuests)
		{
			//IL_004e: 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_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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)
			((TextElement)_count).text = ((quests.Count == 0 && !hasSeenDailyQuests) ? "—" : (remaining + "/" + total + " LEFT"));
			((VisualElement)_empty).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!empty));
			((TextElement)_empty).text = ((quests.Count == 0 && !hasSeenDailyQuests) ? "QUEST PROGRESS NOT DETECTED" : "ALL QUESTS COMPLETED");
			((VisualElement)_footer).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(overflow <= 0));
			((TextElement)_footer).text = "+ " + overflow + " MORE QUESTS";
			int num = 0;
			for (int i = 0; i < ((mode != CompletedQuestMode.Mark) ? 1 : 2); i++)
			{
				for (int j = 0; j < quests.Count; j++)
				{
					if (num >= 5)
					{
						break;
					}
					QuestView questView = quests[j];
					if (questView.Completed == (i == 1))
					{
						bool completed = questView.Completed;
						_completedRows[num] = completed;
						_bars[num].style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(completed ? 1 : 0));
						((VisualElement)_ticks[num]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!completed));
						((VisualElement)_titles[num]).style.color = StyleColor.op_Implicit(completed ? SuccessText : PrimaryText);
						((VisualElement)_counters[num]).style.color = StyleColor.op_Implicit(completed ? SuccessText : GoldText);
						((TextElement)_titles[num]).text = questView.Title ?? "Daily quest";
						((TextElement)_counters[num]).text = ((questView.Progress.HasValue && questView.Target.HasValue) ? (Math.Min(questView.Progress.Value, questView.Target.Value) + "/" + questView.Target.Value) : (completed ? "DONE" : "—"));
						((VisualElement)_titles[num]).style.left = StyleLength.op_Implicit((completed ? 33f : 16f) * _previousSx);
						((VisualElement)_titles[num]).style.width = StyleLength.op_Implicit((completed ? 202f : 219f) * _previousSx);
						num++;
					}
				}
			}
			for (int k = 0; k < 5; k++)
			{
				bool flag = k < num;
				_bars[k].style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)((!flag || _completedRows[k]) ? 1 : 0));
				((VisualElement)_ticks[k]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)((!flag || !_completedRows[k]) ? 1 : 0));
				((VisualElement)_titles[k]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag));
				((VisualElement)_counters[k]).style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag));
				_dividers[k].style.display = StyleEnum<DisplayStyle>.op_Implicit((DisplayStyle)(!flag));
			}
		}

		public void Detach()
		{
			if (_panel != null)
			{
				try
				{
					_panel.RemoveFromHierarchy();
				}
				catch (Exception)
				{
				}
			}
			_panel = null;
			_panelRoot = null;
			_parent = null;
			_notificationBranch = null;
			_previousQuests = null;
			_previousPins = null;
			_previousX = float.NaN;
			_previousY = float.NaN;
			_previousSx = float.NaN;
			_previousSy = float.NaN;
			_previousHeight = float.NaN;
		}
	}
	internal sealed class PinnedMissions
	{
		private sealed class PinFrame
		{
			internal readonly VisualElement[] Outer = (VisualElement[])(object)new VisualElement[7];

			internal readonly VisualElement[] Inner = (VisualElement[])(object)new VisualElement[7];

			internal float Size = -1f;
		}

		public const int MaxPins = 5;

		private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private const float MenuRefreshSeconds = 0.5f;

		private static readonly Type ManagerType = typeof(FirstPersonController).Assembly.GetType("QuestManager");

		private static readonly Type MissionType = typeof(FirstPersonController).Assembly.GetType("RuntimeMission");

		private static readonly Type QuestType = typeof(FirstPersonController).Assembly.GetType("QuestSO");

		private static readonly FieldInfo ManagerInstance = ManagerType?.GetField("Instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo RuntimeMissions = ManagerType?.GetField("runtimeMissions", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo QuestDatabase = ManagerType?.GetField("QuestDatabaseSO", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo QuestSOId = QuestType?.GetField("ID", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionQuest = MissionType?.GetField("QuestSO", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionKind = MissionType?.GetField("missionType", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionCurrent = MissionType?.GetField("currentValue", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionTarget = MissionType?.GetField("target", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MissionReached = MissionType?.GetField("targetAlreadyReached", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly PropertyInfo MissionDescription = MissionType?.GetProperty("Description", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly PropertyInfo MissionTitle = MissionType?.GetProperty("Title", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly MethodInfo QuestCompleted = ((QuestType == null) ? null : ManagerType?.GetMethod("IsQuestCompleted", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { QuestType }, null));

		private static readonly FieldInfo MenuButtons = typeof(GlobalMissionMenu).GetField("missionButtons", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo MenuDailyRoot = typeof(GlobalMissionMenu).GetField("dailyButtonListParent", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo ButtonQuest = typeof(GlobalMissionButton).GetField("questSO", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo ButtonDescription = typeof(GlobalMissionButton).GetField("missionDescription", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo ButtonValidationIcon = typeof(GlobalMissionButton).GetField("validationIcon", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo ButtonProgressBar = typeof(GlobalMissionButton).GetField("missionProgressBar", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

		private readonly ConfigEntry<string> _saved;

		private readonly ConfigEntry<string> _savedTitles;

		private readonly ManualLogSource _log;

		private readonly List<string> _ids = new List<string>(5);

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

		private float _nextMenuUpdate;

		private readonly Dictionary<VisualElement, Button> _buttons = new Dictionary<VisualElement, Button>();

		private readonly Texture2D _pinIcon;

		private const float PinRightInset = 260f;

		private const float PinSize = 50f;

		private const float PinGlyphSize = 28f;

		private const float PinVisualCenterOffset = 0f;

		private readonly HashSet<Button> _hoveredPins = new HashSet<Button>();

		private static readonly Rect[] FrameOuter = (Rect[])(object)new Rect[7]
		{
			new Rect(18f, 0f, 14f, 3f),
			new Rect(11f, 3f, 28f, 5f),
			new Rect(6f, 8f, 38f, 5f),
			new Rect(1f, 13f, 48f, 24f),
			new Rect(6f, 37f, 38f, 5f),
			new Rect(11f, 42f, 28f, 5f),
			new Rect(18f, 47f, 14f, 3f)
		};

		private static readonly Rect[] FrameInner = (Rect[])(object)new Rect[7]
		{
			new Rect(18f, 3f, 14f, 2f),
			new Rect(13f, 5f, 24f, 5f),
			new Rect(8f, 10f, 34f, 4f),
			new Rect(3f, 14f, 44f, 22f),
			new Rect(8f, 36f, 34f, 4f),
			new Rect(13f, 40f, 24f, 5f),
			new Rect(18f, 45f, 14f, 2f)
		};

		private readonly Dictionary<Button, PinFrame> _frames = new Dictionary<Button, PinFrame>();

		public int Count => _ids.Count;

		public PinnedMissions(ConfigEntry<string> saved, ConfigEntry<string> savedTitles, ManualLogSource log)
		{
			_saved = saved;
			_savedTitles = savedTitles;
			_log = log;
			_pinIcon = LoadPinIcon(log);
			Load();
		}

		private void Load()
		{
			_ids.Clear();
			string[] array = (_saved.Value ?? "").Split('|');
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Length != 0 && text.Length <= 200 && !_ids.Contains(text) && _ids.Count < 5)
				{
					_ids.Add(text);
				}
			}
			LoadTitles();
		}

		private void LoadTitles()
		{
			_titles.Clear();
			string[] array = (_savedTitles.Value ?? "").Split('|');
			foreach (string text in array)
			{
				if (string.IsNullOrEmpty(text))
				{
					continue;
				}
				int num = text.IndexOf(':');
				if (num <= 0 || num == text.Length - 1)
				{
					continue;
				}
				try
				{
					string text2 = Encoding.UTF8.GetString(Convert.FromBase64String(text.Substring(0, num)));
					string value = Encoding.UTF8.GetString(Convert.FromBase64String(text.Substring(num + 1)));
					if (_ids.Contains(text2) && IsDisplayTitle(text2, value))
					{
						_titles[text2] = value;
					}
				}
				catch (FormatException)
				{
				}
				catch (ArgumentException)
				{
				}
			}
		}

		private void SaveTitles()
		{
			List<string> list = new List<string>(_ids.Count);
			foreach (string id in _ids)
			{
				if (_titles.TryGetValue(id, out var value) && IsDisplayTitle(id, value))
				{
					list.Add(Convert.ToBase64String(Encoding.UTF8.GetBytes(id)) + ":" + Convert.ToBase64String(Encoding.UTF8.GetBytes(value)));
				}
			}
			string text = string.Join("|", list.ToArray());
			if (_savedTitles.Value != text)
			{
				_savedTitles.Value = text;
			}
		}

		private void RememberTitle(string id, string title)
		{
			if (!IsDisplayTitle(id, title))
			{
				return;
			}
			title = title.Trim();
			if (!_titles.TryGetValue(id, out var value) || !(value == title))
			{
				_titles[id] = title;
				if (_ids.Contains(id))
				{
					SaveTitles();
				}
			}
		}

		private static bool IsDisplayTitle(string id, string value)
		{
			if (string.IsNullOrWhiteSpace(value) || value.Length > 300)
			{
				return false;
			}
			string text = id ?? "";
			if (text.StartsWith("QUEST_", StringComparison.OrdinalIgnoreCase))
			{
				text = text.Substring(6);
			}
			text = text.Replace("_", " ");
			if (!string.Equals(text, value.Trim(), StringComparison.OrdinalIgnoreCase))
			{
				return !string.Equals(id, value.Trim(), StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}

		public void UpdateMenu()
		{
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Expected O, but got Unknown
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: 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_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: 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_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_0647: Unknown result type (might be due to invalid IL or missing references)
			//IL_0663: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0574: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_059b: Expected O, but got Unknown
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextMenuUpdate)
			{
				return;
			}
			_nextMenuUpdate = Time.unscaledTime + 0.5f;
			GlobalMissionMenu instance = GlobalMissionMenu.Instance;
			bool flag = (Object)(object)instance != (Object)null && ((BaseMenu)instance).IsOpen;
			if (!flag)
			{
				_buttons.Clear();
				_hoveredPins.Clear();
			}
			IList list = (((Object)(object)instance != (Object)null) ? (Get(MenuButtons, instance) as IList) : null);
			VisualElement val = (VisualElement)(((Object)(object)instance != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if (list == null || ButtonQuest == null)
			{
				return;
			}
			GlobalMissionButton row = default(GlobalMissionButton);
			for (int i = 0; i < list.Count; i++)
			{
				ref GlobalMissionButton reference = ref row;
				object? obj = list[i];
				reference = (GlobalMissionButton)((obj is GlobalMissionButton) ? obj : null);
				if (row == null || (val != null && IsInside((VisualElement)(object)row, val)))
				{
					continue;
				}
				object instance2 = Get(ButtonQuest, row);
				string text = Get(QuestSOId, instance2) as string;
				if (string.IsNullOrWhiteSpace(text))
				{
					continue;
				}
				object obj2 = Get(ButtonDescription, row);
				Label val2 = (Label)((obj2 is Label) ? obj2 : null);
				if (val2 != null && _ids.Contains(text))
				{
					RememberTitle(text, ((TextElement)val2).text);
				}
				else if (val2 != null && IsDisplayTitle(text, ((TextElement)val2).text))
				{
					_titles[text] = ((TextElement)val2).text.Trim();
				}
				if (!flag || ((VisualElement)row).panel == null)
				{
					continue;
				}
				if (!_buttons.TryGetValue((VisualElement)(object)row, out var pin) || pin == null || (object)((VisualElement)pin).parent != row)
				{
					pin = UQueryExtensions.Q<Button>((VisualElement)(object)row, "DailyQuestTrackerPin", (string)null);
					if (pin == null)
					{
						string capturedId = text;
						pin = new Button((Action)delegate
						{
							Toggle(capturedId);
						})
						{
							name = "DailyQuestTrackerPin",
							pickingMode = (PickingMode)0,
							focusable = false
						};
						((VisualElement)pin).style.position = StyleEnum<Position>.op_Implicit((Position)1);
						((VisualElement)pin).style.right = StyleLength.op_Implicit(260f);
						((VisualElement)pin).style.top = StyleLength.op_Implicit(10f);
						((VisualElement)pin).style.width = StyleLength.op_Implicit(50f);
						((VisualElement)pin).style.height = StyleLength.op_Implicit(50f);
						((VisualElement)pin).style.borderTopLeftRadius = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.borderTopRightRadius = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.borderBottomLeftRadius = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.borderBottomRightRadius = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.borderLeftWidth = StyleFloat.op_Implicit(0f);
						((VisualElement)pin).style.borderRightWidth = StyleFloat.op_Implicit(0f);
						((VisualElement)pin).style.borderTopWidth = StyleFloat.op_Implicit(0f);
						((VisualElement)pin).style.borderBottomWidth = StyleFloat.op_Implicit(0f);
						((VisualElement)pin).style.backgroundColor = StyleColor.op_Implicit(Color.clear);
						((VisualElement)pin).style.overflow = StyleEnum<Overflow>.op_Implicit((Overflow)0);
						((VisualElement)pin).style.marginLeft = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.marginRight = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.marginTop = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.marginBottom = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.paddingLeft = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.paddingRight = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.paddingTop = StyleLength.op_Implicit(0f);
						((VisualElement)pin).style.paddingBottom = StyleLength.op_Implicit(0f);
						((TextElement)pin).text = "";
						((VisualElement)pin).userData = text;
						BuildPinFrame(pin);
						if ((Object)(object)_pinIcon != (Object)null)
						{
							Image val3 = new Image
							{
								name = "DailyQuestTrackerPinGlyph",
								image = (Texture)(object)_pinIcon,
								scaleMode = (ScaleMode)2,
								pickingMode = (PickingMode)1
							};
							((VisualElement)val3).style.position = StyleEnum<Position>.op_Implicit((Position)1);
							float num = 11f;
							((VisualElement)val3).style.left = StyleLength.op_Implicit(num);
							((VisualElement)val3).style.top = StyleLength.op_Implicit(num);
							((VisualElement)val3).style.width = StyleLength.op_Implicit(28f);
							((VisualElement)val3).style.height = StyleLength.op_Implicit(28f);
							((VisualElement)pin).Add((VisualElement)(object)val3);
						}
						else
						{
							((TextElement)pin).text = "+";
							((VisualElement)pin).style.fontSize = StyleLength.op_Implicit(25f);
							((VisualElement)pin).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
						}
						Button hoveredPin = pin;
						((CallbackEventHandler)pin).RegisterCallback<PointerEnterEvent>((EventCallback<PointerEnterEvent>)delegate
						{
							_hoveredPins.Add(hoveredPin);
							SetPinAppearance(hoveredPin, (string)((VisualElement)hoveredPin).userData, hovering: true);
						}, (TrickleDown)0);
						((CallbackEventHandler)pin).RegisterCallback<PointerLeaveEvent>((EventCallback<PointerLeaveEvent>)delegate
						{
							_hoveredPins.Remove(hoveredPin);
							SetPinAppearance(hoveredPin, (string)((VisualElement)hoveredPin).userData);
						}, (TrickleDown)0);
						((CallbackEventHandler)pin).RegisterCallback<PointerDownEvent>((EventCallback<PointerDownEvent>)delegate(PointerDownEvent evt)
						{
							((EventBase)evt).StopPropagation();
						}, (TrickleDown)0);
						((CallbackEventHandler)pin).RegisterCallback<PointerUpEvent>((EventCallback<PointerUpEvent>)delegate(PointerUpEvent evt)
						{
							((EventBase)evt).StopPropagation();
						}, (TrickleDown)0);
						((CallbackEventHandler)pin).RegisterCallback<ClickEvent>((EventCallback<ClickEvent>)delegate(ClickEvent evt)
						{
							((EventBase)evt).StopPropagation();
						}, (TrickleDown)0);
						((VisualElement)row).Add((VisualElement)(object)pin);
						((CallbackEventHandler)row).RegisterCallback<GeometryChangedEvent>((EventCallback<GeometryChangedEvent>)delegate
						{
							CenterPinVertically((VisualElement)(object)row, pin);
						}, (TrickleDown)0);
					}
					_buttons[(VisualElement)(object)row] = pin;
				}
				CenterPinVertically((VisualElement)(object)row, pin);
				((VisualElement)pin).userData = text;
				SetPinAppearance(pin, text, _hoveredPins.Contains(pin));
			}
		}

		private void BuildPinFrame(Button pin)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			PinFrame pinFrame = new PinFrame();
			for (int i = 0; i < 7; i++)
			{
				VisualElement val = new VisualElement
				{
					pickingMode = (PickingMode)1
				};
				val.style.position = StyleEnum<Position>.op_Implicit((Position)1);
				((VisualElement)pin).Add(val);
				pinFrame.Outer[i] = val;
			}
			for (int j = 0; j < 7; j++)
			{
				VisualElement val2 = new VisualElement
				{
					pickingMode = (PickingMode)1
				};
				val2.style.position = StyleEnum<Position>.op_Implicit((Position)1);
				((VisualElement)pin).Add(val2);
				pinFrame.Inner[j] = val2;
			}
			_frames[pin] = pinFrame;
			ResizePinFrame(pinFrame, 50f);
		}

		private static void ResizePinFrame(PinFrame frame, float size)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (!(Mathf.Abs(frame.Size - size) < 0.1f))
			{
				float factor = size / 50f;
				for (int i = 0; i < 7; i++)
				{
					SetFrameRect(frame.Outer[i], FrameOuter[i], factor);
					SetFrameRect(frame.Inner[i], FrameInner[i], factor);
				}
				frame.Size = size;
			}
		}

		private static void SetFrameRect(VisualElement element, Rect rect, float factor)
		{
			//IL_0014: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			element.style.left = StyleLength.op_Implicit(Mathf.Round(((Rect)(ref rect)).x * factor));
			element.style.top = StyleLength.op_Implicit(Mathf.Round(((Rect)(ref rect)).y * factor));
			element.style.width = StyleLength.op_Implicit(Mathf.Max(1f, Mathf.Round(((Rect)(ref rect)).width * factor)));
			element.style.height = StyleLength.op_Implicit(Mathf.Max(1f, Mathf.Round(((Rect)(ref rect)).height * factor)));
		}

		private void CenterPinVertically(VisualElement row, Button pin)
		{
			//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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00bc: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			if (row == null || pin == null || ((VisualElement)pin).parent != row || row.panel == null)
			{
				return;
			}
			Rect val = row.layout;
			float height = ((Rect)(ref val)).height;
			if (float.IsNaN(height) || height <= 0f)
			{
				return;
			}
			object obj = Get(ButtonValidationIcon, row);
			VisualElement val2 = (VisualElement)((obj is VisualElement) ? obj : null);
			object obj2 = Get(ButtonProgressBar, row);
			VisualElement val3 = (VisualElement)((obj2 is VisualElement) ? obj2 : null);
			VisualElement val4 = (HasVisibleRect(val2) ? val2 : (HasVisibleRect(val3) ? val3 : null));
			float num = height * 0.5f;
			if (val4 != null)
			{
				val = row.worldBound;
				if (((Rect)(ref val)).height > 0f)
				{
					val = val4.worldBound;
					float y = ((Rect)(ref val)).center.y;
					val = row.worldBound;
					float num2 = (y - ((Rect)(ref val)).yMin) * height;
					val = row.worldBound;
					num = num2 / ((Rect)(ref val)).height;
				}
			}
			float num3 = 50f;
			if (HasVisibleRect(val2))
			{
				val = val2.worldBound;
				if (((Rect)(ref val)).height >= 35f)
				{
					val = val2.worldBound;
					if (((Rect)(ref val)).height <= 70f)
					{
						val = val2.worldBound;
						float num4 = ((Rect)(ref val)).height * height;
						val = row.worldBound;
						num3 = Mathf.Round(num4 / ((Rect)(ref val)).height);
					}
				}
			}
			num3 = Mathf.Clamp(num3, 42f, 56f);
			if (_frames.TryGetValue(pin, out var value))
			{
				ResizePinFrame(value, num3);
			}
			((VisualElement)pin).style.width = StyleLength.op_Implicit(num3);
			((VisualElement)pin).style.height = StyleLength.op_Implicit(num3);
			((VisualElement)pin).style.top = StyleLength.op_Implicit(Mathf.Round(Mathf.Max(0f, num - num3 * 0.5f)));
			Image val5 = UQueryExtensions.Q<Image>((VisualElement)(object)pin, "DailyQuestTrackerPinGlyph", (string)null);
			if (val5 != null)
			{
				float num5 = Mathf.Round((num3 - 28f) * 0.5f);
				((VisualElement)val5).style.left = StyleLength.op_Implicit(num5);
				((VisualElement)val5).style.top = StyleLength.op_Implicit(num5);
			}
		}

		private static bool HasVisibleRect(VisualElement element)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_001c: 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)
			if (element == null || element.panel == null || (int)element.resolvedStyle.display == 1)
			{
				return false;
			}
			Rect worldBound = element.worldBound;
			if (!float.IsNaN(((Rect)(ref worldBound)).y) && ((Rect)(ref worldBound)).height > 8f && !float.IsNaN(((Rect)(ref worldBound)).x))
			{
				return ((Rect)(ref worldBound)).width > 8f;
			}
			return false;
		}

		private static bool IsInside(VisualElement child, VisualElement parent)
		{
			for (VisualElement val = child; val != null; val = val.parent)
			{
				if (val == parent)
				{
					return true;
				}
			}
			return false;
		}

		private void Toggle(string id)
		{
			if (_ids.Remove(id))
			{
				_saved.Value = string.Join("|", _ids.ToArray());
				_log.LogInfo((object)("Unpinned global mission: " + id));
			}
			else
			{
				if (_ids.Count >= 5)
				{
					_log.LogWarning((object)("You can pin at most " + 5 + " missions."));
					return;
				}
				_ids.Add(id);
				_saved.Value = string.Join("|", _ids.ToArray());
				_log.LogInfo((object)("Pinned global mission: " + id));
			}
			SaveTitles();
			_nextMenuUpdate = 0f;
			foreach (Button value in _buttons.Values)
			{
				if (value != null && ((VisualElement)value).panel != null && ((VisualElement)value).userData is string id2)
				{
					SetPinAppearance(value, id2, _hoveredPins.Contains(value));
				}
			}
		}

		private void SetPinAppearance(Button pin, string id, bool hovering = false)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00bf: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _ids.Contains(id);
			Color val = (hovering ? new Color(1f, 0.87f, 0.58f, 1f) : (flag ? new Color(0.98f, 0.76f, 0.38f, 1f) : new Color(0.66f, 0.57f, 0.41f, 1f)));
			Color val2 = (hovering ? new Color(0.29f, 0.2f, 0.19f, 1f) : (flag ? new Color(0.3f, 0.21f, 0.16f, 1f) : new Color(0.14f, 0.18f, 0.23f, 1f)));
			((VisualElement)pin).style.backgroundColor = StyleColor.op_Implicit(Color.clear);
			if (_frames.TryGetValue(pin, out var value))
			{
				for (int i = 0; i < 7; i++)
				{
					value.Outer[i].style.backgroundColor = StyleColor.op_Implicit(val);
					value.Inner[i].style.backgroundColor = StyleColor.op_Implicit(val2);
				}
			}
			Image val3 = UQueryExtensions.Q<Image>((VisualElement)(object)pin, "DailyQuestTrackerPinGlyph", (string)null);
			if (val3 != null)
			{
				val3.tintColor = Color.white;
			}
			else
			{
				((VisualElement)pin).style.color = StyleColor.op_Implicit(val);
			}
			((VisualElement)pin).tooltip = (flag ? "Unpin mission" : ((_ids.Count >= 5) ? "Five missions maximum" : "Pin mission"));
		}

		private static Texture2D LoadPinIcon(ManualLogSource log)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Expected O, but got Unknown
			try
			{
				using Stream stream = typeof(PinnedMissions).Assembly.GetManifestResourceStream("StonewardsDailyQuestTracker.pin-icon.png