Decompiled source of DiscoveryJournal v1.1.0

BepInEx/plugins/DiscoveryJournal.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DiscoveryJournal.Core;
using DiscoveryJournal.Models;
using DiscoveryJournal.UI;
using HarmonyLib;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ADERiGMS")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2026 ADERiGMS")]
[assembly: AssemblyDescription("A vanilla-friendly discovery journal for Valheim.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("Discovery Journal")]
[assembly: AssemblyTitle("Discovery Journal")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace DiscoveryJournal
{
	[BepInPlugin("com.andrii.discoveryjournal", "Discovery Journal", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.andrii.discoveryjournal";

		public const string PluginName = "Discovery Journal";

		public const string PluginVersion = "1.1.0";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Discovery Journal loaded successfully!");
			DiscoveryManager.ResetSession();
			((Component)this).gameObject.AddComponent<DiscoveryHud>();
			_harmony = new Harmony("com.andrii.discoveryjournal");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Harmony patches initialized.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace DiscoveryJournal.UI
{
	internal sealed class DiscoveryHud : MonoBehaviour
	{
		private enum DiscoveryFilter
		{
			All,
			Unread
		}

		private enum DiscoverySortMode
		{
			Default,
			Ascending,
			Descending
		}

		private const float ContentLeftInset = 25f;

		private const float ContentRightInset = 25f;

		private const float ContentHeaderY = 170f;

		private const float ContentHeaderHeight = 28f;

		private const float ContentListY = 205f;

		private const float ContentBottomInset = 25f;

		private const float ContentControlGap = 5f;

		private const float SortButtonWidth = 120f;

		private const float RecentListGap = 3f;

		private const float RecentListBottomInset = 5f;

		private bool _isRecentlyDiscoveredExpanded;

		private Vector2 _recentScrollPosition = Vector2.zero;

		private static DiscoveryHud _instance;

		private const float LauncherWidth = 190f;

		private const float LauncherHeight = 32f;

		private const float DefaultHudLeftOffset = 128f;

		private const float DefaultHudBottomOffset = 18f;

		private const float LauncherDragThreshold = 5f;

		private const int LauncherCornerRadius = 5;

		private const int LauncherBorderThickness = 1;

		private const float WindowWidth = 620f;

		private const float WindowHeight = 430f;

		private const float RowHeight = 56f;

		private const string JournalTitle = "DISCOVERY JOURNAL";

		private const string ModDisplayName = "Discovery Journal";

		private const string ModVersion = "1.1.0";

		private const string ModAuthor = "ADERiGMS";

		private GUIStyle _searchFieldStyle;

		private static readonly string ModFramework = $"BepInEx v{typeof(BaseUnityPlugin).Assembly.GetName().Version}";

		private const float ReferenceScreenWidth = 1920f;

		private const float ReferenceScreenHeight = 1080f;

		private const float MinimumUiScale = 0.75f;

		private const float MaximumUiScale = 2f;

		private float _uiScale = 1f;

		private float _manualUiScale = 1f;

		private int _lastScreenWidth = -1;

		private int _lastScreenHeight = -1;

		private GUIStyle _launcherStyle;

		private GUIStyle _newBadgeStyle;

		private GUIStyle _windowTitleStyle;

		private GUIStyle _sectionStyle;

		private GUIStyle _categoryHeaderStyle;

		private GUIStyle _entryNameStyle;

		private GUIStyle _entryTypeStyle;

		private GUIStyle _selectedTabStyle;

		private GUIStyle _normalButtonStyle;

		private GUIStyle _scrollbarStyle;

		private GUIStyle _scrollbarThumbStyle;

		private GUIStyle _horizontalSliderStyle;

		private GUIStyle _horizontalSliderThumbStyle;

		private GUIStyle _launcherMoveHintStyle;

		private GUIStyle _rightAlignedEntryTypeStyle;

		private GUIStyle _aboutTitleStyle;

		private GUIStyle _aboutNameStyle;

		private GUIStyle _aboutDetailsStyle;

		private Texture2D _launcherNormalTexture;

		private Texture2D _launcherHoverTexture;

		private Texture2D _launcherPressedTexture;

		private Texture2D _journalBackgroundTexture;

		private Texture2D _buttonNormalTexture;

		private Texture2D _buttonHoverTexture;

		private Texture2D _buttonPressedTexture;

		private Texture2D _buttonSelectedTexture;

		private Texture2D _entryNormalTexture;

		private Texture2D _entryUnreadTexture;

		private Texture2D _entryHoverTexture;

		private Texture2D _entryUnreadHoverTexture;

		private Texture2D _newBadgeTexture;

		private Texture2D _scrollbarTrackTexture;

		private Texture2D _scrollbarThumbTexture;

		private Texture2D _scrollbarThumbHoverTexture;

		private Texture2D _sliderTrackTexture;

		private Texture2D _sliderThumbTexture;

		private Texture2D _sliderThumbHoverTexture;

		private Texture2D _sliderThumbPressedTexture;

		private Texture2D _separatorTexture;

		private Texture2D _settingsPanelTexture;

		private Texture2D _launcherMoveHintTexture;

		private ConfigFile _uiConfig;

		private ConfigEntry<float> _launcherXConfig;

		private ConfigEntry<float> _launcherYConfig;

		private ConfigEntry<float> _uiScaleConfig;

		private ConfigEntry<float> _windowXConfig;

		private ConfigEntry<float> _windowYConfig;

		private readonly KeyboardShortcut _journalShortcut = new KeyboardShortcut((KeyCode)106, Array.Empty<KeyCode>());

		private CursorLockMode _cursorLockBeforeJournal;

		private bool _cursorVisibleBeforeJournal;

		private bool _cursorStateCaptured;

		private bool _hudButtonPressed;

		private Rect _launcherRect;

		private Vector2 _preferredLauncherPosition;

		private bool _launcherPositionInitialized;

		private bool _launcherMouseDown;

		private bool _isLauncherDragging;

		private bool _launcherDragMoved;

		private Vector2 _launcherDragOffset;

		private Vector2 _launcherDragStartMouse;

		private bool _launcherMoveMode;

		private int _journalHotControl;

		private bool _windowOpen;

		private bool _uiSettingsOpen;

		private Rect _windowRect;

		private Vector2 _preferredWindowPosition;

		private bool _windowPositionInitialized;

		private bool _isDragging;

		private Vector2 _dragOffset;

		private DiscoveryType _selectedType = DiscoveryType.Material;

		private DiscoveryFilter _selectedFilter;

		private DiscoverySortMode _selectedSortMode;

		private Vector2 _scrollPosition = Vector2.zero;

		private string _searchText = string.Empty;

		private bool _isSearching;

		internal static bool BlocksGameplayInput { get; private set; }

		internal static bool IsSearchFocused
		{
			get
			{
				if ((Object)(object)_instance != (Object)null)
				{
					return _instance._isSearching;
				}
				return false;
			}
		}

		internal static bool OwnsUiFocus
		{
			get
			{
				if (BlocksGameplayInput && (Object)(object)Player.m_localPlayer != (Object)null)
				{
					return !IsHigherPriorityUiActive();
				}
				return false;
			}
		}

		private void InitializeConfiguration()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "com.ADERiGMS.discoveryjournal.ui.cfg");
			_uiConfig = new ConfigFile(text, true);
			_launcherXConfig = _uiConfig.Bind<float>("HUD", "LauncherX", -1f, "Horizontal position of the Discovery Journal launcher in pixels.");
			_launcherYConfig = _uiConfig.Bind<float>("HUD", "LauncherY", -1f, "Vertical position of the Discovery Journal launcher in pixels.");
			_uiScaleConfig = _uiConfig.Bind<float>("UI", "Scale", 1f, "Manual Discovery Journal UI scale multiplier. Range: 0.75 - 1.50.");
			_manualUiScale = Mathf.Clamp(_uiScaleConfig.Value, 0.75f, 1.5f);
			_windowXConfig = _uiConfig.Bind<float>("Journal Window", "PositionX", -1f, "Horizontal position of the Discovery Journal window.");
			_windowYConfig = _uiConfig.Bind<float>("Journal Window", "PositionY", -1f, "Vertical position of the Discovery Journal window.");
		}

		private void EnsureLauncherPosition()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			if (!_launcherPositionInitialized)
			{
				if (_uiConfig == null)
				{
					InitializeConfiguration();
				}
				float num = ((_launcherXConfig != null) ? _launcherXConfig.Value : (-1f));
				float num2 = ((_launcherYConfig != null) ? _launcherYConfig.Value : (-1f));
				if (num < 0f || num2 < 0f)
				{
					num = 128f;
					num2 = (float)Screen.height - 18f - 32f;
				}
				_launcherRect = new Rect(num, num2, 190f, 32f);
				_preferredLauncherPosition = new Vector2(Mathf.Max(0f, ((Rect)(ref _launcherRect)).x), Mathf.Max(0f, ((Rect)(ref _launcherRect)).y));
				_launcherPositionInitialized = true;
				ClampLauncherToScreen();
			}
		}

		private void ClampLauncherToScreen()
		{
			if (_launcherPositionInitialized)
			{
				float num = Mathf.Max(0f, (float)Screen.width - ((Rect)(ref _launcherRect)).width);
				float num2 = Mathf.Max(0f, (float)Screen.height - ((Rect)(ref _launcherRect)).height);
				((Rect)(ref _launcherRect)).x = Mathf.Clamp(((Rect)(ref _launcherRect)).x, 0f, num);
				((Rect)(ref _launcherRect)).y = Mathf.Clamp(((Rect)(ref _launcherRect)).y, 0f, num2);
			}
		}

		private void SaveLauncherPosition()
		{
			if (_launcherPositionInitialized)
			{
				if (_uiConfig == null)
				{
					InitializeConfiguration();
				}
				if (_launcherXConfig != null)
				{
					_launcherXConfig.Value = _preferredLauncherPosition.x;
				}
				if (_launcherYConfig != null)
				{
					_launcherYConfig.Value = _preferredLauncherPosition.y;
				}
				ConfigFile uiConfig = _uiConfig;
				if (uiConfig != null)
				{
					uiConfig.Save();
				}
			}
		}

		private void SaveWindowPosition()
		{
			if (_windowPositionInitialized)
			{
				if (_uiConfig == null)
				{
					InitializeConfiguration();
				}
				if (_windowXConfig != null)
				{
					_windowXConfig.Value = _preferredWindowPosition.x;
				}
				if (_windowYConfig != null)
				{
					_windowYConfig.Value = _preferredWindowPosition.y;
				}
				ConfigFile uiConfig = _uiConfig;
				if (uiConfig != null)
				{
					uiConfig.Save();
				}
			}
		}

		private void DrawRecentlyDiscoveredPanel(float windowX, float windowY)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			List<DiscoveryEntry> recentEntries = DiscoveryManager.GetRecentEntries();
			float num = Scale(570f);
			float num2 = (_isRecentlyDiscoveredExpanded ? num : (num - Scale(125f)));
			if (GUI.Button(new Rect(windowX + Scale(25f), windowY + Scale(170f), num2, Scale(28f)), $"Recently Discovered ({recentEntries.Count})", _normalButtonStyle))
			{
				_isRecentlyDiscoveredExpanded = !_isRecentlyDiscoveredExpanded;
			}
			if (!_isRecentlyDiscoveredExpanded)
			{
				return;
			}
			float num3 = 201f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(windowX + Scale(25f), windowY + Scale(num3), num, Scale(430f - num3 - 5f));
			float num4 = Scale(56f);
			float num5 = Mathf.Max(((Rect)(ref val)).height, (float)recentEntries.Count * num4);
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(0f, 0f, ((Rect)(ref val)).width - Scale(20f), num5);
			UpdateScrollbarThumbHeight(((Rect)(ref val)).height, ((Rect)(ref val2)).height);
			_recentScrollPosition = GUI.BeginScrollView(val, _recentScrollPosition, val2, false, false, GUIStyle.none, GUIStyle.none);
			try
			{
				float num6 = 0f;
				foreach (DiscoveryEntry item in recentEntries)
				{
					DrawEntryRow(item, num6, ((Rect)(ref val2)).width);
					num6 += num4;
				}
			}
			finally
			{
				GUI.EndScrollView();
			}
			DrawVerticalScrollbar(val, ((Rect)(ref val2)).height, ref _recentScrollPosition);
		}

		private void DrawTab(Rect rect, string label, DiscoveryType type)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			int num = CountEntries(type);
			string text = $"{label} ({num})";
			GUIStyle val = ((_selectedType == type) ? _selectedTabStyle : _normalButtonStyle);
			if (GUI.Button(rect, text, val) && _selectedType != type)
			{
				MarkSelectedTabRead();
				_selectedType = type;
				_scrollPosition = Vector2.zero;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)$"Discovery Journal tab: {type}");
				}
			}
		}

		private void DrawFilter(Rect rect, string label, DiscoveryFilter filter)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = ((_selectedFilter == filter) ? _selectedTabStyle : _normalButtonStyle);
			if (GUI.Button(rect, label, val) && _selectedFilter != filter)
			{
				_selectedFilter = filter;
				_scrollPosition = Vector2.zero;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)$"Discovery Journal filter: {filter}");
				}
			}
		}

		private void DrawSelectedEntries(float windowX, float windowY)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_0317: Unknown result type (might be due to invalid IL or missing references)
			string text = ((_selectedFilter == DiscoveryFilter.Unread) ? "No unread discoveries in this category." : "No discoveries in this category.");
			int num = CountVisibleEntries(_selectedType);
			float num2 = Scale(620f);
			float num3 = Scale(430f);
			float num4 = Scale(56f);
			if (GUI.Button(new Rect(windowX + Scale(475f), windowY + Scale(170f), Scale(120f), Scale(28f)), $"Sort: {_selectedSortMode}", _normalButtonStyle))
			{
				if (_selectedSortMode == DiscoverySortMode.Default)
				{
					_selectedSortMode = DiscoverySortMode.Ascending;
				}
				else if (_selectedSortMode == DiscoverySortMode.Ascending)
				{
					_selectedSortMode = DiscoverySortMode.Descending;
				}
				else
				{
					_selectedSortMode = DiscoverySortMode.Default;
				}
				_scrollPosition = Vector2.zero;
			}
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(windowX + Scale(25f), windowY + Scale(205f), num2 - Scale(50f), num3 - Scale(230f));
			if (num == 0)
			{
				if (_selectedFilter == DiscoveryFilter.All && !string.IsNullOrEmpty(_searchText))
				{
					text = "No search results found.";
				}
				GUI.Label(new Rect(((Rect)(ref val)).x + Scale(10f), ((Rect)(ref val)).y + Scale(10f), ((Rect)(ref val)).width - Scale(20f), Scale(40f)), text, _sectionStyle);
				return;
			}
			float num5 = Mathf.Max(((Rect)(ref val)).height - Scale(5f), (float)num * num4 + Scale(10f));
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(0f, 0f, ((Rect)(ref val)).width - Scale(20f), num5);
			UpdateScrollbarThumbHeight(((Rect)(ref val)).height, ((Rect)(ref val2)).height);
			_scrollPosition = GUI.BeginScrollView(val, _scrollPosition, val2, false, false, GUIStyle.none, GUIStyle.none);
			try
			{
				float num6 = Scale(5f);
				List<DiscoveryEntry> list = new List<DiscoveryEntry>(DiscoveryManager.Entries);
				if (_selectedSortMode == DiscoverySortMode.Ascending)
				{
					list.Sort((DiscoveryEntry a, DiscoveryEntry b) => string.Compare(GetLocalizedName(a.LocalizationKey), GetLocalizedName(b.LocalizationKey)));
				}
				else if (_selectedSortMode == DiscoverySortMode.Descending)
				{
					list.Sort((DiscoveryEntry a, DiscoveryEntry b) => string.Compare(GetLocalizedName(b.LocalizationKey), GetLocalizedName(a.LocalizationKey)));
				}
				foreach (DiscoveryEntry item in list)
				{
					if (item.Type == _selectedType && (_selectedFilter != DiscoveryFilter.Unread || !item.IsRead) && (string.IsNullOrEmpty(_searchText) || GetLocalizedName(item.LocalizationKey).IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) != -1))
					{
						DrawEntryRow(item, num6, ((Rect)(ref val2)).width);
						num6 += num4;
					}
				}
			}
			finally
			{
				GUI.EndScrollView();
			}
			DrawVerticalScrollbar(val, ((Rect)(ref val2)).height, ref _scrollPosition);
		}

		private void DrawVerticalScrollbar(Rect viewportRect, float contentHeight, ref Vector2 scrollPosition)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (contentHeight <= ((Rect)(ref viewportRect)).height)
			{
				scrollPosition.y = 0f;
				return;
			}
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref viewportRect)).xMax - _scrollbarStyle.fixedWidth, ((Rect)(ref viewportRect)).y, _scrollbarStyle.fixedWidth, ((Rect)(ref viewportRect)).height);
			float num = Mathf.Max(0f, contentHeight - ((Rect)(ref viewportRect)).height);
			scrollPosition.y = GUI.VerticalSlider(val, scrollPosition.y, 0f, num, _scrollbarStyle, _scrollbarThumbStyle);
		}

		private void DrawEntryRow(DiscoveryEntry entry, float y, float width)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			float num = Scale(56f);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(Scale(5f), y, width - Scale(10f), num - Scale(4f));
			Event current = Event.current;
			Texture2D val2 = ((current == null || !((Rect)(ref val)).Contains(current.mousePosition)) ? (entry.IsRead ? _entryNormalTexture : _entryUnreadTexture) : (entry.IsRead ? _entryHoverTexture : _entryUnreadHoverTexture));
			GUI.DrawTexture(val, (Texture)(object)val2, (ScaleMode)0, true);
			DrawSprite(new Rect(((Rect)(ref val)).x + Scale(7f), ((Rect)(ref val)).y + Scale(6f), Scale(40f), Scale(40f)), entry.Icon);
			string localizedName = GetLocalizedName(entry.LocalizationKey);
			float num2 = (entry.IsRead ? Scale(12f) : Scale(78f));
			GUI.Label(new Rect(((Rect)(ref val)).x + Scale(58f), ((Rect)(ref val)).y + Scale(4f), ((Rect)(ref val)).width - Scale(58f) - num2, Scale(26f)), localizedName, _entryNameStyle);
			GUI.Label(new Rect(((Rect)(ref val)).x + Scale(58f), ((Rect)(ref val)).y + Scale(27f), ((Rect)(ref val)).width - Scale(70f), Scale(20f)), GetTypeDisplayName(entry.Type), _entryTypeStyle);
			if (!entry.IsRead)
			{
				Rect val3 = new Rect(((Rect)(ref val)).x + ((Rect)(ref val)).width - Scale(65f), ((Rect)(ref val)).y + Scale(15f), Scale(55f), Scale(22f));
				GUI.DrawTexture(val3, (Texture)(object)_newBadgeTexture, (ScaleMode)0, true);
				GUI.Label(val3, "NEW", _newBadgeStyle);
			}
		}

		private void MarkSelectedTabRead()
		{
			if (DiscoveryManager.MarkTypeRead(_selectedType) > 0 && (Object)(object)Player.m_localPlayer != (Object)null)
			{
				DiscoveryPersistence.SaveToPlayer(Player.m_localPlayer);
			}
		}

		private int CountVisibleEntries(DiscoveryType type)
		{
			int num = 0;
			foreach (DiscoveryEntry entry in DiscoveryManager.Entries)
			{
				if (_selectedFilter != DiscoveryFilter.Unread || !entry.IsRead)
				{
					string localizedName = GetLocalizedName(entry.LocalizationKey);
					if ((string.IsNullOrEmpty(_searchText) || localizedName.IndexOf(_searchText, StringComparison.OrdinalIgnoreCase) != -1) && type == entry.Type)
					{
						num++;
					}
				}
			}
			return num;
		}

		private static int CountUnreadEntries(DiscoveryType type)
		{
			int num = 0;
			foreach (DiscoveryEntry entry in DiscoveryManager.Entries)
			{
				if (entry.Type == type && !entry.IsRead)
				{
					num++;
				}
			}
			return num;
		}

		private static int CountEntries(DiscoveryType type)
		{
			int num = 0;
			foreach (DiscoveryEntry entry in DiscoveryManager.Entries)
			{
				if (entry.Type == type)
				{
					num++;
				}
			}
			return num;
		}

		private static string GetLocalizedName(string localizationKey)
		{
			if (Localization.instance == null)
			{
				return localizationKey;
			}
			string text = Localization.instance.Localize(localizationKey);
			if (string.IsNullOrWhiteSpace(text))
			{
				return localizationKey;
			}
			return text;
		}

		private static string GetTypeDisplayName(DiscoveryType type)
		{
			return type switch
			{
				DiscoveryType.Recipe => "Recipes", 
				DiscoveryType.BuildPiece => "Build Pieces", 
				DiscoveryType.Item => "Items", 
				DiscoveryType.Material => "Materials", 
				_ => type.ToString(), 
			};
		}

		private static void DrawSprite(Rect rect, Sprite sprite)
		{
			//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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)sprite == (Object)null) && !((Object)(object)sprite.texture == (Object)null))
			{
				Rect textureRect = sprite.textureRect;
				Texture texture = (Texture)(object)sprite.texture;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((Rect)(ref textureRect)).x / (float)texture.width, ((Rect)(ref textureRect)).y / (float)texture.height, ((Rect)(ref textureRect)).width / (float)texture.width, ((Rect)(ref textureRect)).height / (float)texture.height);
				GUI.DrawTextureWithTexCoords(rect, texture, val, true);
			}
		}

		private void Awake()
		{
			InitializeConfiguration();
			_instance = this;
		}

		private void Update()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				ReleaseJournalFocus();
			}
			else
			{
				if (!CanProcessJournalHotkeys())
				{
					return;
				}
				bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
				if (Input.GetKeyDown((KeyCode)106) && flag)
				{
					ToggleLauncherMoveMode();
					return;
				}
				KeyboardShortcut journalShortcut = _journalShortcut;
				if (((KeyboardShortcut)(ref journalShortcut)).IsDown() && !flag)
				{
					ToggleJournalWindow();
				}
				if (OwnsUiFocus)
				{
					ApplyJournalCursor();
				}
			}
		}

		private void LateUpdate()
		{
			if (OwnsUiFocus)
			{
				ApplyJournalCursor();
			}
		}

		private void OnDisable()
		{
			try
			{
				SaveLauncherPosition();
				SaveWindowPosition();
			}
			catch (Exception arg)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"Failed to save journal UI state during disable: {arg}");
				}
			}
			finally
			{
				ReleaseJournalFocus();
			}
		}

		private void OnDestroy()
		{
			try
			{
				SaveLauncherPosition();
				SaveWindowPosition();
			}
			catch (Exception arg)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"Failed to save journal UI state during destruction: {arg}");
				}
			}
			finally
			{
				if ((Object)(object)_instance == (Object)(object)this)
				{
					_instance = null;
				}
				ReleaseJournalFocus();
				DestroyGeneratedTextures();
			}
		}

		private void OnGUI()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || IsHigherPriorityUiActive())
			{
				CancelJournalPointerInteraction();
				return;
			}
			if (!_windowOpen && _journalHotControl != 0)
			{
				CancelJournalPointerInteraction();
			}
			UpdateResponsiveScale();
			EnsureStyles();
			UpdateResponsiveFontSizes();
			int hotControl = GUIUtility.hotControl;
			DrawLauncher();
			if (_windowOpen)
			{
				DrawJournalWindow();
			}
			int hotControl2 = GUIUtility.hotControl;
			if (hotControl2 == 0)
			{
				_journalHotControl = 0;
			}
			else if (hotControl2 != hotControl)
			{
				_journalHotControl = hotControl2;
			}
		}

		private void ToggleJournalWindow()
		{
			if (_windowOpen)
			{
				CloseJournalWindow();
			}
			else
			{
				OpenJournalWindow();
			}
		}

		private static bool IsAnyTextInputActive()
		{
			if (((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) || Console.IsVisible() || TextInput.IsVisible() || Minimap.InTextInput())
			{
				return true;
			}
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.m_buildUi != (Object)null)
			{
				return instance.m_buildUi.SearchFieldFocused;
			}
			return false;
		}

		private static bool IsHigherPriorityUiActive()
		{
			if (!Minimap.IsOpen() && !Menu.IsVisible() && !((Object)(object)Settings.instance != (Object)null) && !UnifiedPopup.IsVisible() && !Feedback.IsVisible() && !ConnectPanel.IsVisible())
			{
				return IsAnyTextInputActive();
			}
			return true;
		}

		private static bool CanProcessJournalHotkeys()
		{
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				return !IsHigherPriorityUiActive();
			}
			return false;
		}

		private void OpenJournalWindow()
		{
			if (!_windowOpen)
			{
				CaptureCursorState();
				_windowOpen = true;
				BlocksGameplayInput = true;
				_isDragging = false;
				ResetLauncherMouseState();
				ApplyJournalCursor();
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"Discovery Journal window: OPENED");
				}
			}
		}

		private void CloseJournalWindow()
		{
			if (!_windowOpen)
			{
				ReleaseJournalFocus();
				return;
			}
			try
			{
				MarkSelectedTabRead();
				if (_launcherMoveMode)
				{
					_launcherMoveMode = false;
					ClampLauncherToScreen();
					SaveLauncherPosition();
				}
				SaveWindowPosition();
			}
			catch (Exception arg)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"Failed to persist journal state while closing: {arg}");
				}
			}
			finally
			{
				ReleaseJournalFocus();
			}
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)"Discovery Journal window: CLOSED");
			}
		}

		private void ReleaseJournalFocus()
		{
			BlocksGameplayInput = false;
			_windowOpen = false;
			_uiSettingsOpen = false;
			_launcherMoveMode = false;
			_isDragging = false;
			_isSearching = false;
			ResetLauncherMouseState();
			if ((Object)(object)Player.m_localPlayer == (Object)null || IsHigherPriorityUiActive())
			{
				_cursorStateCaptured = false;
			}
			else
			{
				RestoreCursorState();
			}
		}

		private void ToggleLauncherMoveMode()
		{
			if (_launcherMoveMode)
			{
				ExitLauncherMoveMode();
				CloseJournalWindow();
			}
			else
			{
				EnterLauncherMoveMode();
			}
		}

		private void EnterLauncherMoveMode()
		{
			if (!_windowOpen)
			{
				OpenJournalWindow();
			}
			_launcherMoveMode = true;
			ResetLauncherMouseState();
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"Discovery Journal launcher move mode: ON");
			}
		}

		private void ExitLauncherMoveMode()
		{
			if (!_launcherMoveMode)
			{
				return;
			}
			_launcherMoveMode = false;
			ResetLauncherMouseState();
			try
			{
				ClampLauncherToScreen();
				SaveLauncherPosition();
			}
			catch (Exception arg)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogError((object)$"Failed to save launcher position while leaving move mode: {arg}");
				}
			}
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)"Discovery Journal launcher move mode: OFF");
			}
		}

		private void ResetLauncherMouseState()
		{
			_hudButtonPressed = false;
			_launcherMouseDown = false;
			_isLauncherDragging = false;
			_launcherDragMoved = false;
		}

		private void CancelJournalPointerInteraction()
		{
			_isDragging = false;
			ResetLauncherMouseState();
			if (_journalHotControl != 0 && GUIUtility.hotControl == _journalHotControl)
			{
				GUIUtility.hotControl = 0;
			}
			_journalHotControl = 0;
		}

		private void CaptureCursorState()
		{
			//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)
			if (!_cursorStateCaptured)
			{
				_cursorLockBeforeJournal = Cursor.lockState;
				_cursorVisibleBeforeJournal = Cursor.visible;
				_cursorStateCaptured = true;
			}
		}

		private static void ApplyJournalCursor()
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}

		private void RestoreCursorState()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (_cursorStateCaptured)
			{
				Cursor.lockState = _cursorLockBeforeJournal;
				Cursor.visible = _cursorVisibleBeforeJournal;
				_cursorStateCaptured = false;
			}
		}

		private void DrawLauncher()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Invalid comparison between Unknown and I4
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Invalid comparison between Unknown and I4
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: 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_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			if (_windowOpen && !_launcherMoveMode)
			{
				ResetLauncherMouseState();
				return;
			}
			UpdateLauncherRect();
			int unreadCount = DiscoveryManager.UnreadCount;
			string text = (_launcherMoveMode ? "MOVE DISCOVERIES" : ((unreadCount > 0) ? $"NEW DISCOVERIES +{unreadCount}" : "DISCOVERIES"));
			Rect launcherRect = _launcherRect;
			Event current = Event.current;
			bool flag = current != null && ((Rect)(ref launcherRect)).Contains(current.mousePosition);
			bool visible = Cursor.visible;
			if (!visible)
			{
				ResetLauncherMouseState();
			}
			if (current != null && (int)current.type == 0 && current.button == 0 && flag && visible)
			{
				_hudButtonPressed = true;
				_launcherMouseDown = true;
				_isLauncherDragging = false;
				_launcherDragMoved = false;
				_launcherDragStartMouse = current.mousePosition;
				_launcherDragOffset = current.mousePosition - new Vector2(((Rect)(ref _launcherRect)).x, ((Rect)(ref _launcherRect)).y);
				current.Use();
			}
			if (current != null && (int)current.type == 3 && current.button == 0 && _launcherMouseDown && visible)
			{
				float num = Vector2.Distance(_launcherDragStartMouse, current.mousePosition);
				if (!_isLauncherDragging && num >= Scale(5f))
				{
					_isLauncherDragging = true;
				}
				if (_isLauncherDragging)
				{
					((Rect)(ref _launcherRect)).x = current.mousePosition.x - _launcherDragOffset.x;
					((Rect)(ref _launcherRect)).y = current.mousePosition.y - _launcherDragOffset.y;
					ClampLauncherToScreen();
					_preferredLauncherPosition = ((Rect)(ref _launcherRect)).position;
					_launcherDragMoved = true;
					_hudButtonPressed = false;
					current.Use();
				}
			}
			if (current != null && (int)current.type == 1 && current.button == 0 && _launcherMouseDown)
			{
				bool num2 = _isLauncherDragging || _launcherDragMoved;
				bool flag2 = !num2 && flag && !_launcherMoveMode;
				ResetLauncherMouseState();
				if (num2)
				{
					ClampLauncherToScreen();
					SaveLauncherPosition();
				}
				else if (flag2)
				{
					ToggleJournalWindow();
				}
				current.Use();
			}
			Rect launcherRect2 = _launcherRect;
			if (_hudButtonPressed && flag && !_isLauncherDragging)
			{
				((Rect)(ref launcherRect2)).x = ((Rect)(ref launcherRect2)).x + Scale(1f);
				((Rect)(ref launcherRect2)).y = ((Rect)(ref launcherRect2)).y + Scale(2f);
				((Rect)(ref launcherRect2)).width = ((Rect)(ref launcherRect2)).width - Scale(2f);
				((Rect)(ref launcherRect2)).height = ((Rect)(ref launcherRect2)).height - Scale(2f);
			}
			Texture2D val = (_launcherMoveMode ? _launcherHoverTexture : ((_hudButtonPressed && flag) ? _launcherPressedTexture : ((!(flag && visible)) ? _launcherNormalTexture : _launcherHoverTexture)));
			GUI.DrawTexture(launcherRect2, (Texture)(object)val, (ScaleMode)0, true);
			Color contentColor = GUI.contentColor;
			GUI.contentColor = ((unreadCount > 0 || _launcherMoveMode) ? new Color(1f, 0.76f, 0.28f, 1f) : ((flag && visible) ? new Color(1f, 0.84f, 0.48f, 1f) : new Color(0.92f, 0.88f, 0.8f, 1f)));
			GUI.Label(launcherRect2, text, _launcherStyle);
			GUI.contentColor = contentColor;
			if (_launcherMoveMode)
			{
				DrawLauncherMoveHint();
			}
		}

		private void UpdateLauncherRect()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			EnsureLauncherPosition();
			((Rect)(ref _launcherRect)).width = Scale(190f);
			((Rect)(ref _launcherRect)).height = Scale(32f);
			((Rect)(ref _launcherRect)).position = _preferredLauncherPosition;
			ClampLauncherToScreen();
		}

		internal static bool ShouldBlockVanillaUiPointer(Vector2 screenPosition)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (OwnsUiFocus)
			{
				return true;
			}
			DiscoveryHud instance = _instance;
			if ((Object)(object)instance == (Object)null || !((Behaviour)instance).isActiveAndEnabled || instance._windowOpen || (Object)(object)Player.m_localPlayer == (Object)null || IsHigherPriorityUiActive() || !Cursor.visible)
			{
				return false;
			}
			instance.UpdateResponsiveScale();
			instance.UpdateLauncherRect();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(screenPosition.x, (float)Screen.height - screenPosition.y);
			if (!instance._launcherMouseDown)
			{
				return ((Rect)(ref instance._launcherRect)).Contains(val);
			}
			return true;
		}

		private void DrawLauncherMoveHint()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_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)
			Vector2 val = _launcherMoveHintStyle.CalcSize(new GUIContent("Drag with LMB  |  Shift + J: finish"));
			Rect val2 = new Rect(((float)Screen.width - val.x - Scale(28f)) / 2f, Scale(18f), val.x + Scale(28f), Scale(30f));
			GUI.DrawTexture(val2, (Texture)(object)_launcherMoveHintTexture, (ScaleMode)0, true);
			GUI.Label(val2, "Drag with LMB  |  Shift + J: finish", _launcherMoveHintStyle);
		}

		private void UpdateResponsiveScale()
		{
			if (_lastScreenWidth != Screen.width || _lastScreenHeight != Screen.height)
			{
				_lastScreenWidth = Screen.width;
				_lastScreenHeight = Screen.height;
				float num = (float)Screen.width / 1920f;
				float num2 = (float)Screen.height / 1080f;
				_uiScale = Mathf.Clamp(Mathf.Min(num, num2), 0.75f, 2f);
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)$"UI SCALE | {Screen.width}x{Screen.height} | Scale: {_uiScale:0.00}");
				}
			}
		}

		private float Scale(float value)
		{
			return value * _uiScale * _manualUiScale;
		}

		private void UpdateResponsiveFontSizes()
		{
			_launcherStyle.fontSize = Mathf.RoundToInt(Scale(14f));
			_windowTitleStyle.fontSize = Mathf.RoundToInt(Scale(24f));
			_sectionStyle.fontSize = Mathf.RoundToInt(Scale(16f));
			_categoryHeaderStyle.fontSize = Mathf.RoundToInt(Scale(16f));
			_entryNameStyle.fontSize = Mathf.RoundToInt(Scale(16f));
			_entryTypeStyle.fontSize = Mathf.RoundToInt(Scale(13f));
			_rightAlignedEntryTypeStyle.fontSize = Mathf.RoundToInt(Scale(13f));
			_launcherMoveHintStyle.fontSize = Mathf.RoundToInt(Scale(13f));
			_newBadgeStyle.fontSize = Mathf.RoundToInt(Scale(13f));
			_selectedTabStyle.fontSize = Mathf.RoundToInt(Scale(12f));
			_normalButtonStyle.fontSize = Mathf.RoundToInt(Scale(12f));
			int num = Mathf.Max(1, Mathf.RoundToInt(Scale(1f)));
			_scrollbarStyle.fixedWidth = Scale(14f);
			_scrollbarStyle.padding.left = num;
			_scrollbarStyle.padding.right = num;
			_scrollbarStyle.padding.top = num;
			_scrollbarStyle.padding.bottom = num;
			_scrollbarThumbStyle.fixedWidth = Mathf.Max(1f, _scrollbarStyle.fixedWidth - (float)num * 2f);
			_scrollbarThumbStyle.fixedHeight = Scale(24f);
			_horizontalSliderStyle.fixedHeight = Scale(22f);
			_horizontalSliderThumbStyle.fixedWidth = Scale(18f);
			_horizontalSliderThumbStyle.fixedHeight = Scale(22f);
		}

		private void UpdateScrollbarThumbHeight(float viewportHeight, float contentHeight)
		{
			float num = Scale(1f);
			float num2 = Mathf.Max(num, viewportHeight - num * 2f);
			float num3 = ((contentHeight > 0f) ? Mathf.Clamp01(viewportHeight / contentHeight) : 1f);
			_scrollbarThumbStyle.fixedHeight = Mathf.Clamp(num2 * num3, Scale(24f), num2);
		}

		private void EnsureStyles()
		{
			if (_launcherStyle == null)
			{
				CreateTextures();
				CreateTextStyles();
				CreateButtonStyles();
				CreateScrollbarStyles();
				CreateSliderStyles();
			}
		}

		private void CreateTextures()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: 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)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: 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_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_0585: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0611: Unknown result type (might be due to invalid IL or missing references)
			//IL_062a: Unknown result type (might be due to invalid IL or missing references)
			_scrollbarTrackTexture = CreateRoundedButtonTexture(14, 120, 5, 1, new Color(0.045f, 0.035f, 0.025f, 0.95f), new Color(0.22f, 0.15f, 0.08f, 1f));
			_scrollbarThumbTexture = CreateRoundedButtonTexture(12, 48, 5, 1, new Color(0.28f, 0.18f, 0.07f, 1f), new Color(0.72f, 0.46f, 0.16f, 1f));
			_scrollbarThumbHoverTexture = CreateRoundedButtonTexture(12, 48, 5, 1, new Color(0.38f, 0.24f, 0.08f, 1f), new Color(0.95f, 0.64f, 0.24f, 1f));
			_sliderTrackTexture = CreateRoundedButtonTexture(320, 8, 4, 1, new Color(0.045f, 0.035f, 0.025f, 0.98f), new Color(0.42f, 0.28f, 0.12f, 1f));
			_sliderThumbTexture = CreateRoundedButtonTexture(18, 22, 5, 1, new Color(0.22f, 0.14f, 0.055f, 1f), new Color(0.78f, 0.5f, 0.18f, 1f));
			_sliderThumbHoverTexture = CreateRoundedButtonTexture(18, 22, 5, 1, new Color(0.34f, 0.21f, 0.07f, 1f), new Color(0.95f, 0.64f, 0.24f, 1f));
			_sliderThumbPressedTexture = CreateRoundedButtonTexture(18, 22, 5, 1, new Color(0.16f, 0.095f, 0.035f, 1f), new Color(1f, 0.74f, 0.3f, 1f));
			_settingsPanelTexture = CreateRoundedButtonTexture(540, 260, 6, 1, new Color(0.065f, 0.05f, 0.035f, 0.96f), new Color(0.34f, 0.23f, 0.11f, 1f));
			_launcherMoveHintTexture = CreateRoundedButtonTexture(360, 30, 5, 1, new Color(0.075f, 0.055f, 0.035f, 0.94f), new Color(0.62f, 0.4f, 0.15f, 1f));
			_separatorTexture = CreateRoundedButtonTexture(580, 4, 2, 1, new Color(0.16f, 0.1f, 0.045f, 0.95f), new Color(0.55f, 0.34f, 0.12f, 1f));
			_entryNormalTexture = CreateRoundedButtonTexture(540, 52, 5, 1, new Color(0.055f, 0.045f, 0.035f, 0.94f), new Color(0.25f, 0.18f, 0.1f, 1f));
			_entryUnreadTexture = CreateRoundedButtonTexture(540, 52, 5, 1, new Color(0.1f, 0.07f, 0.035f, 0.97f), new Color(0.72f, 0.46f, 0.16f, 1f));
			_entryHoverTexture = CreateRoundedButtonTexture(540, 52, 5, 1, new Color(0.13f, 0.085f, 0.04f, 0.98f), new Color(0.82f, 0.52f, 0.18f, 1f));
			_entryUnreadHoverTexture = CreateRoundedButtonTexture(540, 52, 5, 1, new Color(0.16f, 0.095f, 0.035f, 0.99f), new Color(0.98f, 0.66f, 0.24f, 1f));
			_newBadgeTexture = CreateRoundedButtonTexture(64, 24, 4, 1, new Color(0.18f, 0.1f, 0.03f, 0.98f), new Color(0.95f, 0.64f, 0.24f, 1f));
			_buttonNormalTexture = CreateRoundedButtonTexture(160, 36, 4, 1, new Color(0.12f, 0.09f, 0.06f, 0.98f), new Color(0.38f, 0.27f, 0.15f, 1f));
			_buttonHoverTexture = CreateRoundedButtonTexture(160, 36, 4, 1, new Color(0.2f, 0.14f, 0.08f, 0.98f), new Color(0.72f, 0.48f, 0.2f, 1f));
			_buttonPressedTexture = CreateRoundedButtonTexture(160, 36, 4, 1, new Color(0.08f, 0.055f, 0.035f, 1f), new Color(0.86f, 0.58f, 0.22f, 1f));
			_buttonSelectedTexture = CreateRoundedButtonTexture(160, 36, 4, 1, new Color(0.24f, 0.16f, 0.07f, 0.98f), new Color(0.95f, 0.64f, 0.24f, 1f));
			_journalBackgroundTexture = CreateRoundedButtonTexture(620, 430, 8, 2, new Color(0.075f, 0.06f, 0.045f, 0.97f), new Color(0.42f, 0.3f, 0.16f, 1f));
			_launcherNormalTexture = CreateRoundedButtonTexture(190, 32, 5, 1, new Color(0.075f, 0.055f, 0.035f, 0.92f), new Color(0.42f, 0.3f, 0.16f, 1f));
			_launcherHoverTexture = CreateRoundedButtonTexture(190, 32, 5, 1, new Color(0.16f, 0.1f, 0.045f, 0.97f), new Color(0.85f, 0.54f, 0.18f, 1f));
			_launcherPressedTexture = CreateRoundedButtonTexture(190, 32, 5, 1, new Color(0.09f, 0.055f, 0.025f, 0.99f), new Color(0.95f, 0.64f, 0.24f, 1f));
		}

		private void CreateTextStyles()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_002b: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00bf: Expected O, but got Unknown
			//IL_00de: 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_0105: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			//IL_01dc: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: 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_0229: Expected O, but got Unknown
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Expected O, but got Unknown
			_launcherStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 14,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			_launcherStyle.normal.textColor = Color.white;
			_newBadgeStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 17,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			_newBadgeStyle.normal.textColor = new Color(1f, 0.76f, 0.28f, 1f);
			_windowTitleStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 24,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			_windowTitleStyle.normal.textColor = new Color(0.95f, 0.64f, 0.24f, 1f);
			_sectionStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16
			};
			_sectionStyle.normal.textColor = Color.white;
			_categoryHeaderStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				fontStyle = (FontStyle)1
			};
			_categoryHeaderStyle.normal.textColor = new Color(0.92f, 0.72f, 0.38f, 1f);
			_entryNameStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 16,
				fontStyle = (FontStyle)1
			};
			_entryNameStyle.normal.textColor = Color.white;
			_entryTypeStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 13
			};
			_entryTypeStyle.normal.textColor = new Color(0.72f, 0.67f, 0.58f, 1f);
			_rightAlignedEntryTypeStyle = new GUIStyle(_entryTypeStyle)
			{
				alignment = (TextAnchor)2
			};
			_launcherMoveHintStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 13,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			_launcherMoveHintStyle.normal.textColor = new Color(0.94f, 0.87f, 0.74f, 1f);
			_searchFieldStyle = new GUIStyle(GUI.skin.textField)
			{
				alignment = (TextAnchor)3
			};
		}

		private void CreateButtonStyles()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0093: 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_00e5: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Expected O, but got Unknown
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			_selectedTabStyle = new GUIStyle(GUI.skin.button)
			{
				fontStyle = (FontStyle)1
			};
			_selectedTabStyle.normal.background = _buttonSelectedTexture;
			_selectedTabStyle.hover.background = _buttonSelectedTexture;
			_selectedTabStyle.active.background = _buttonPressedTexture;
			_selectedTabStyle.focused.background = _buttonSelectedTexture;
			_selectedTabStyle.normal.textColor = new Color(1f, 0.72f, 0.3f, 1f);
			_selectedTabStyle.hover.textColor = new Color(1f, 0.82f, 0.42f, 1f);
			_selectedTabStyle.active.textColor = new Color(1f, 0.82f, 0.42f, 1f);
			_selectedTabStyle.focused.textColor = new Color(1f, 0.72f, 0.3f, 1f);
			_normalButtonStyle = new GUIStyle(GUI.skin.button);
			_normalButtonStyle.normal.background = _buttonNormalTexture;
			_normalButtonStyle.hover.background = _buttonHoverTexture;
			_normalButtonStyle.active.background = _buttonPressedTexture;
			_normalButtonStyle.focused.background = _buttonNormalTexture;
			_normalButtonStyle.normal.textColor = new Color(0.88f, 0.84f, 0.76f, 1f);
			_normalButtonStyle.hover.textColor = new Color(1f, 0.76f, 0.32f, 1f);
			_normalButtonStyle.active.textColor = new Color(1f, 0.82f, 0.42f, 1f);
			_normalButtonStyle.focused.textColor = new Color(0.88f, 0.84f, 0.76f, 1f);
		}

		private void CreateScrollbarStyles()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//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_0040: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00dd: 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_00e8: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0103: Expected O, but got Unknown
			_scrollbarStyle = new GUIStyle(GUI.skin.verticalScrollbar)
			{
				name = "verticalScrollbar",
				border = new RectOffset(1, 1, 5, 5),
				margin = new RectOffset(),
				padding = new RectOffset(),
				overflow = new RectOffset(),
				fixedHeight = 0f
			};
			_scrollbarStyle.normal.background = _scrollbarTrackTexture;
			_scrollbarStyle.hover.background = _scrollbarTrackTexture;
			_scrollbarStyle.active.background = _scrollbarTrackTexture;
			_scrollbarStyle.focused.background = _scrollbarTrackTexture;
			_scrollbarThumbStyle = new GUIStyle(GUI.skin.verticalScrollbarThumb)
			{
				name = "verticalScrollbarThumb",
				border = new RectOffset(1, 1, 5, 5),
				margin = new RectOffset(),
				padding = new RectOffset(),
				overflow = new RectOffset()
			};
			_scrollbarThumbStyle.normal.background = _scrollbarThumbTexture;
			_scrollbarThumbStyle.hover.background = _scrollbarThumbHoverTexture;
			_scrollbarThumbStyle.active.background = _scrollbarThumbHoverTexture;
			_scrollbarThumbStyle.focused.background = _scrollbarThumbTexture;
		}

		private void CreateSliderStyles()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0042: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006c: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_0092: Expected O, but got Unknown
			_horizontalSliderStyle = new GUIStyle
			{
				name = "horizontalSlider",
				border = new RectOffset(),
				margin = new RectOffset(),
				padding = new RectOffset(),
				overflow = new RectOffset()
			};
			_horizontalSliderThumbStyle = new GUIStyle(GUI.skin.horizontalSliderThumb)
			{
				name = "horizontalSliderThumb",
				border = new RectOffset(1, 1, 5, 5),
				margin = new RectOffset(),
				padding = new RectOffset(),
				overflow = new RectOffset()
			};
			_horizontalSliderThumbStyle.normal.background = _sliderThumbTexture;
			_horizontalSliderThumbStyle.hover.background = _sliderThumbHoverTexture;
			_horizontalSliderThumbStyle.active.background = _sliderThumbPressedTexture;
			_horizontalSliderThumbStyle.focused.background = _sliderThumbTexture;
		}

		private void DestroyGeneratedTextures()
		{
			DestroyTexture(ref _launcherNormalTexture);
			DestroyTexture(ref _launcherHoverTexture);
			DestroyTexture(ref _launcherPressedTexture);
			DestroyTexture(ref _journalBackgroundTexture);
			DestroyTexture(ref _buttonNormalTexture);
			DestroyTexture(ref _buttonHoverTexture);
			DestroyTexture(ref _buttonPressedTexture);
			DestroyTexture(ref _buttonSelectedTexture);
			DestroyTexture(ref _entryNormalTexture);
			DestroyTexture(ref _entryUnreadTexture);
			DestroyTexture(ref _entryHoverTexture);
			DestroyTexture(ref _entryUnreadHoverTexture);
			DestroyTexture(ref _newBadgeTexture);
			DestroyTexture(ref _scrollbarTrackTexture);
			DestroyTexture(ref _scrollbarThumbTexture);
			DestroyTexture(ref _scrollbarThumbHoverTexture);
			DestroyTexture(ref _sliderTrackTexture);
			DestroyTexture(ref _sliderThumbTexture);
			DestroyTexture(ref _sliderThumbHoverTexture);
			DestroyTexture(ref _sliderThumbPressedTexture);
			DestroyTexture(ref _separatorTexture);
			DestroyTexture(ref _settingsPanelTexture);
			DestroyTexture(ref _launcherMoveHintTexture);
		}

		private static void DestroyTexture(ref Texture2D texture)
		{
			if (!((Object)(object)texture == (Object)null))
			{
				Object.Destroy((Object)(object)texture);
				texture = null;
			}
		}

		private static Texture2D CreateRoundedButtonTexture(int width, int height, int radius, int borderThickness, Color fillColor, Color borderColor)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array = (Color[])(object)new Color[width * height];
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					float num = (float)j + 0.5f;
					float num2 = (float)i + 0.5f;
					bool num3 = IsInsideRoundedRect(num, num2, width, height, radius);
					Color val3 = val2;
					if (num3)
					{
						val3 = (IsInsideRoundedRect(num - (float)borderThickness, num2 - (float)borderThickness, (float)width - (float)borderThickness * 2f, (float)height - (float)borderThickness * 2f, Mathf.Max(0f, (float)(radius - borderThickness))) ? fillColor : borderColor);
					}
					array[i * width + j] = val3;
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		private static bool IsInsideRoundedRect(float x, float y, float width, float height, float radius)
		{
			if (width <= 0f || height <= 0f)
			{
				return false;
			}
			if (x < 0f || y < 0f || x >= width || y >= height)
			{
				return false;
			}
			radius = Mathf.Clamp(radius, 0f, Mathf.Min(width, height) * 0.5f);
			if (radius <= 0f)
			{
				return true;
			}
			if (x >= radius && x < width - radius)
			{
				return true;
			}
			if (y >= radius && y < height - radius)
			{
				return true;
			}
			float num = ((x < radius) ? radius : (width - radius));
			float num2 = ((y < radius) ? radius : (height - radius));
			float num3 = x - num;
			float num4 = y - num2;
			return num3 * num3 + num4 * num4 <= radius * radius;
		}

		private void DrawAboutSection(float x, float y, float width)
		{
			if (_aboutTitleStyle == null)
			{
				_aboutTitleStyle = CreateAboutLabelStyle(_categoryHeaderStyle);
				_aboutNameStyle = CreateAboutLabelStyle(_sectionStyle);
				_aboutDetailsStyle = CreateAboutLabelStyle(_entryTypeStyle);
			}
			_aboutTitleStyle.fontSize = _categoryHeaderStyle.fontSize;
			_aboutNameStyle.fontSize = _sectionStyle.fontSize;
			_aboutDetailsStyle.fontSize = _entryTypeStyle.fontSize;
			DrawAboutLabel("ABOUT", _aboutTitleStyle, x, ref y, width, 24f);
			DrawAboutLabel("Discovery Journal", _aboutNameStyle, x, ref y, width, 22f);
			DrawAboutLabel("Version 1.1.0", _aboutDetailsStyle, x, ref y, width, 18f);
			DrawAboutLabel("Author: ADERiGMS", _aboutDetailsStyle, x, ref y, width, 18f);
			DrawAboutLabel("Framework: " + ModFramework, _aboutDetailsStyle, x, ref y, width, 18f);
		}

		private static GUIStyle CreateAboutLabelStyle(GUIStyle source)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			return new GUIStyle(source)
			{
				padding = new RectOffset(),
				margin = new RectOffset(),
				contentOffset = Vector2.zero,
				fixedWidth = 0f,
				fixedHeight = 0f,
				wordWrap = false,
				clipping = (TextClipping)1
			};
		}

		private void DrawAboutLabel(string text, GUIStyle style, float x, ref float y, float width, float minimumHeight)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			GUIContent val = new GUIContent(text);
			float num = Mathf.Ceil(Mathf.Max(Scale(minimumHeight), style.CalcHeight(val, width)));
			GUI.Label(new Rect(x, y, width, num), val, style);
			y += num + Scale(2f);
		}

		private void DrawJournalWindow()
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: 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_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			float num = Scale(620f);
			float num2 = Scale(430f);
			if (!_windowPositionInitialized)
			{
				float num3 = ((_windowXConfig != null) ? _windowXConfig.Value : (-1f));
				float num4 = ((_windowYConfig != null) ? _windowYConfig.Value : (-1f));
				if (num3 >= 0f && num4 >= 0f)
				{
					_windowRect = new Rect(num3, num4, num, num2);
				}
				else
				{
					_windowRect = new Rect(((float)Screen.width - num) / 2f, ((float)Screen.height - num2) / 2f, num, num2);
				}
				_preferredWindowPosition = new Vector2(Mathf.Max(0f, ((Rect)(ref _windowRect)).x), Mathf.Max(0f, ((Rect)(ref _windowRect)).y));
				_windowPositionInitialized = true;
				ClampWindowToScreen();
			}
			((Rect)(ref _windowRect)).width = num;
			((Rect)(ref _windowRect)).height = num2;
			((Rect)(ref _windowRect)).position = _preferredWindowPosition;
			ClampWindowToScreen();
			HandleWindowDrag();
			float x = ((Rect)(ref _windowRect)).x;
			float y = ((Rect)(ref _windowRect)).y;
			GUI.DrawTexture(_windowRect, (Texture)(object)_journalBackgroundTexture, (ScaleMode)0, true);
			GUI.Label(new Rect(x + Scale(20f), y + Scale(15f), num - Scale(80f), Scale(40f)), "DISCOVERY JOURNAL", _windowTitleStyle);
			Rect val = new Rect(x + num - Scale(50f), y + Scale(12f), Scale(35f), Scale(30f));
			if (GUI.Button(new Rect(x + num - Scale(92f), y + Scale(12f), Scale(35f), Scale(30f)), "UI", _normalButtonStyle))
			{
				_uiSettingsOpen = !_uiSettingsOpen;
			}
			if (GUI.Button(val, "X", _normalButtonStyle))
			{
				CloseJournalWindow();
				return;
			}
			if (_uiSettingsOpen)
			{
				DrawUiScaleSettings(x, y, num);
				return;
			}
			float num5 = y + Scale(70f);
			float num6 = Scale(5f);
			float num7 = (num - Scale(40f) - num6 * 3f) / 4f;
			float num8 = x + Scale(20f);
			DrawTab(new Rect(num8, num5, num7, Scale(32f)), "Recipes", DiscoveryType.Recipe);
			num8 += num7 + num6;
			DrawTab(new Rect(num8, num5, num7, Scale(32f)), "Build Pieces", DiscoveryType.BuildPiece);
			num8 += num7 + num6;
			DrawTab(new Rect(num8, num5, num7, Scale(32f)), "Items", DiscoveryType.Item);
			num8 += num7 + num6;
			DrawTab(new Rect(num8, num5, num7, Scale(32f)), "Materials", DiscoveryType.Material);
			GUI.DrawTexture(new Rect(x + Scale(20f), y + Scale(120f), num - Scale(40f), Scale(3f)), (Texture)(object)_separatorTexture, (ScaleMode)0, true);
			float num9 = y + Scale(132f);
			DrawFilter(new Rect(x + Scale(20f), num9, Scale(100f), Scale(28f)), $"All ({CountEntries(_selectedType)})", DiscoveryFilter.All);
			DrawFilter(new Rect(x + Scale(125f), num9, Scale(120f), Scale(28f)), $"Unread ({CountUnreadEntries(_selectedType)})", DiscoveryFilter.Unread);
			GUI.SetNextControlName("journalsearch");
			_searchFieldStyle.fontSize = Mathf.RoundToInt(Scale(14f));
			_searchText = GUI.TextField(new Rect(x + Scale(250f), num9, Scale(285f), Scale(28f)), _searchText, _searchFieldStyle);
			if (GUI.Button(new Rect(x + Scale(540f), num9, Scale(60f), Scale(28f)), "Clear", _normalButtonStyle))
			{
				_scrollPosition = Vector2.zero;
				_searchText = string.Empty;
			}
			_isSearching = GUI.GetNameOfFocusedControl() == "journalsearch";
			DrawRecentlyDiscoveredPanel(x, y);
			if (!_isRecentlyDiscoveredExpanded)
			{
				DrawSelectedEntries(x, y);
			}
		}

		private void DrawUiScaleSettings(float windowX, float windowY, float scaledWindowWidth)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			GUI.DrawTexture(new Rect(windowX + Scale(20f), windowY + Scale(70f), scaledWindowWidth - Scale(40f), Scale(345f)), (Texture)(object)_settingsPanelTexture, (ScaleMode)0, true);
			GUI.Label(new Rect(windowX + Scale(30f), windowY + Scale(85f), scaledWindowWidth - Scale(60f), Scale(30f)), "UI SCALE", _categoryHeaderStyle);
			GUI.Label(new Rect(windowX + Scale(30f), windowY + Scale(108f), scaledWindowWidth - Scale(60f), Scale(24f)), "Adjust the size of the Discovery Journal interface.", _entryTypeStyle);
			GUI.Label(new Rect(windowX + Scale(30f), windowY + Scale(125f), scaledWindowWidth - Scale(60f), Scale(30f)), $"{_manualUiScale:0.00}x", _sectionStyle);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(windowX + Scale(30f), windowY + Scale(170f), scaledWindowWidth - Scale(60f), Scale(22f));
			float num = Scale(8f);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y + (((Rect)(ref val)).height - num) * 0.5f, ((Rect)(ref val)).width, num), (Texture)(object)_sliderTrackTexture, (ScaleMode)0, true);
			float num2 = GUI.HorizontalSlider(val, _manualUiScale, 0.75f, 1.5f, _horizontalSliderStyle, _horizontalSliderThumbStyle);
			num2 = Mathf.Round(num2 * 20f) / 20f;
			GUI.Label(new Rect(windowX + Scale(30f), windowY + Scale(198f), Scale(80f), Scale(25f)), "0.75x", _entryTypeStyle);
			GUI.Label(new Rect(windowX + scaledWindowWidth - Scale(110f), windowY + Scale(198f), Scale(80f), Scale(25f)), "1.50x", _rightAlignedEntryTypeStyle);
			if (GUI.Button(new Rect(windowX + Scale(30f), windowY + Scale(245f), Scale(120f), Scale(32f)), "RESET", _normalButtonStyle))
			{
				num2 = 1f;
			}
			GUI.DrawTexture(new Rect(windowX + Scale(30f), windowY + Scale(282f), scaledWindowWidth - Scale(60f), Scale(2f)), (Texture)(object)_separatorTexture, (ScaleMode)0, true);
			DrawAboutSection(windowX + Scale(30f), windowY + Scale(292f), scaledWindowWidth - Scale(60f));
			if (!Mathf.Approximately(num2, _manualUiScale))
			{
				_manualUiScale = num2;
				if (_uiScaleConfig != null)
				{
					_uiScaleConfig.Value = _manualUiScale;
				}
			}
		}

		private void HandleWindowDrag()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Invalid comparison between Unknown and I4
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Invalid comparison between Unknown and I4
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			Event current = Event.current;
			if (current != null)
			{
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((Rect)(ref _windowRect)).x, ((Rect)(ref _windowRect)).y, ((Rect)(ref _windowRect)).width - Scale(105f), Scale(55f));
				if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
				{
					_isDragging = true;
					_dragOffset = current.mousePosition - new Vector2(((Rect)(ref _windowRect)).x, ((Rect)(ref _windowRect)).y);
					current.Use();
				}
				if ((int)current.type == 3 && current.button == 0 && _isDragging)
				{
					((Rect)(ref _windowRect)).x = current.mousePosition.x - _dragOffset.x;
					((Rect)(ref _windowRect)).y = current.mousePosition.y - _dragOffset.y;
					ClampWindowToScreen();
					_preferredWindowPosition = ((Rect)(ref _windowRect)).position;
					current.Use();
				}
				if ((int)current.type == 1 && current.button == 0 && _isDragging)
				{
					_isDragging = false;
					ClampWindowToScreen();
					SaveWindowPosition();
					current.Use();
				}
			}
		}

		private void ClampWindowToScreen()
		{
			float num = Mathf.Max(0f, (float)Screen.width - Scale(620f));
			float num2 = Mathf.Max(0f, (float)Screen.height - Scale(430f));
			((Rect)(ref _windowRect)).x = Mathf.Clamp(((Rect)(ref _windowRect)).x, 0f, num);
			((Rect)(ref _windowRect)).y = Mathf.Clamp(((Rect)(ref _windowRect)).y, 0f, num2);
		}
	}
}
namespace DiscoveryJournal.Patches
{
	[HarmonyPatch]
	internal static class InventoryInputPatch
	{
		private static readonly string[] InputMethodNames = new string[14]
		{
			"OnSelectedItem", "OnReleasedItem", "OnRightClickItem", "OnTakeAll", "OnStackAll", "OnDropOutside", "OnSelectedRecipe", "OnCraftPressed", "OnCraftCancelPressed", "OnCraftPointerDown",
			"OnRepairPressed", "OnSplitOk", "UpdateGamepad", "UpdateSplitDialog"
		};

		private static IEnumerable<MethodBase> TargetMethods()
		{
			string[] inputMethodNames = InputMethodNames;
			foreach (string text in inputMethodNames)
			{
				MethodInfo methodInfo = AccessTools.Method(typeof(InventoryGui), text, (Type[])null, (Type[])null);
				if (methodInfo == null)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)("Inventory input patch: InventoryGui." + text + " was not found."));
					}
				}
				else
				{
					yield return methodInfo;
				}
			}
		}

		[HarmonyPrefix]
		private static bool Prefix()
		{
			return !DiscoveryHud.OwnsUiFocus;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateItemDrag")]
	internal static class InventoryItemDragPatch
	{
		private static readonly Action<InventoryGui, ItemData, Inventory, int> SetupDragItem = CreateSetupDragItemDelegate();

		[HarmonyPrefix]
		private static bool Prefix(InventoryGui __instance)
		{
			if (!DiscoveryHud.OwnsUiFocus)
			{
				return true;
			}
			SetupDragItem?.Invoke(__instance, null, null, 1);
			__instance.OnCraftPointerExit();
			return false;
		}

		private static Action<InventoryGui, ItemData, Inventory, int> CreateSetupDragItemDelegate()
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", new Type[3]
			{
				typeof(ItemData),
				typeof(Inventory),
				typeof(int)
			}, (Type[])null);
			if (methodInfo == null)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)"Inventory drag patch: InventoryGui.SetupDragItem was not found.");
				}
				return null;
			}
			try
			{
				return AccessTools.MethodDelegate<Action<InventoryGui, ItemData, Inventory, int>>(methodInfo, (object)null, false);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("Inventory drag patch initialization failed: " + ex.Message));
				}
				return null;
			}
		}
	}
	[HarmonyPatch(typeof(Minimap), "SetMapMode", new Type[] { typeof(MapMode) })]
	internal static class MinimapSetMapModePatch
	{
		[HarmonyPrefix]
		private static bool Prefix(MapMode mode)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between I4 and Unknown
			if (DiscoveryHud.IsSearchFocused && 2 == (int)mode)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class PlayerPersistencePatch
	{
		[HarmonyPatch(typeof(Player), "Load")]
		[HarmonyPostfix]
		private static void PlayerLoadPostfix(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				DiscoveryPersistence.LoadFromPlayer(__instance);
			}
		}

		[HarmonyPatch(typeof(Player), "Save")]
		[HarmonyPrefix]
		private static void PlayerSavePrefix(Player __instance)
		{
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				DiscoveryPersistence.SaveToPlayer(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "TakeInput")]
	internal static class PlayerTakeInputPatch
	{
		[HarmonyPostfix]
		private static void Postfix(ref bool __result)
		{
			if (DiscoveryHud.BlocksGameplayInput)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerController), "TakeInput", new Type[] { typeof(bool) })]
	internal static class PlayerControllerTakeInputPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ref bool __result)
		{
			if (!DiscoveryHud.BlocksGameplayInput)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	internal static class GameCameraMouseCapturePatch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			if (!DiscoveryHud.OwnsUiFocus)
			{
				return true;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			return false;
		}
	}
	[HarmonyPatch]
	internal static class MouseScrollWheelPatch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(AccessTools.TypeByName("ZInput"), "GetMouseScrollWheel", Type.EmptyTypes, (Type[])null);
		}

		[HarmonyPostfix]
		private static void Postfix(ref float __result)
		{
			if (DiscoveryHud.OwnsUiFocus)
			{
				__result = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
	internal static class HudCrosshairPatch
	{
		private static readonly FieldInfo CrosshairField = AccessTools.Field(typeof(Hud), "m_crosshair");

		private static readonly FieldInfo CrosshairBowField = AccessTools.Field(typeof(Hud), "m_crosshairBow");

		private static readonly FieldInfo PieceHealthRootField = AccessTools.Field(typeof(Hud), "m_pieceHealthRoot");

		private static readonly FieldInfo HoverNameField = AccessTools.Field(typeof(Hud), "m_hoverName");

		private static readonly PropertyInfo HoverNameTextProperty = ((HoverNameField != null) ? AccessTools.Property(HoverNameField.FieldType, "text") : null);

		[HarmonyPrefix]
		private static bool Prefix(Hud __instance)
		{
			if (!DiscoveryHud.OwnsUiFocus)
			{
				return true;
			}
			SetInactive(CrosshairField?.GetValue(__instance));
			SetInactive(CrosshairBowField?.GetValue(__instance));
			SetInactive(PieceHealthRootField?.GetValue(__instance));
			object obj = HoverNameField?.GetValue(__instance);
			if (obj != null)
			{
				HoverNameTextProperty?.SetValue(obj, string.Empty);
			}
			return false;
		}

		private static void SetInactive(object value)
		{
			Component val = (Component)((value is Component) ? value : null);
			if (val != null)
			{
				val.gameObject.SetActive(false);
				return;
			}
			GameObject val2 = (GameObject)((value is GameObject) ? value : null);
			if (val2 != null)
			{
				val2.SetActive(false);
			}
		}
	}
	[HarmonyPatch(typeof(MessageHud), "QueueUnlockMsg", new Type[]
	{
		typeof(Sprite),
		typeof(string),
		typeof(string)
	})]
	internal static class UnlockMessagePatch
	{
		[HarmonyPostfix]
		private static void Postfix(Sprite icon, string topic, string description)
		{
			DiscoveryType type;
			switch (topic)
			{
			default:
				return;
			case "$msg_newmaterial":
				type = DiscoveryType.Material;
				break;
			case "$msg_newitem":
			case "$msg_newtrophy":
				type = DiscoveryType.Item;
				break;
			case "$msg_newrecipe":
				type = DiscoveryType.Recipe;
				break;
			case "$msg_newdish":
			case "$msg_newpiece":
				type = DiscoveryType.BuildPiece;
				break;
			}
			DiscoveryManager.Add(type, description, icon);
		}
	}
	[HarmonyPatch(typeof(EventSystem), "RaycastAll")]
	internal static class VanillaUiRaycastPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(PointerEventData __0, List<RaycastResult> __1)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if (!DiscoveryHud.ShouldBlockVanillaUiPointer(__0.position))
			{
				return true;
			}
			__1?.Clear();
			return false;
		}
	}
	[HarmonyPatch]
	internal static class VanillaUiControlInputPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo[] array = new MethodInfo[9]
			{
				FindMethod(typeof(ScrollRect), "OnDrag", typeof(PointerEventData)),
				FindMethod(typeof(ScrollRect), "OnScroll", typeof(PointerEventData)),
				FindMethod(typeof(Scrollbar), "UpdateDrag", typeof(PointerEventData)),
				FindMethod(typeof(Scrollbar), "UpdateDrag", typeof(RectTransform), typeof(Vector2), typeof(Camera)),
				FindMethod(typeof(Slider), "UpdateDrag", typeof(PointerEventData), typeof(Camera)),
				FindMethod(typeof(Scrollbar), "OnMove", typeof(AxisEventData)),
				FindMethod(typeof(Slider), "OnMove", typeof(AxisEventData)),
				FindMethod(typeof(Button), "OnSubmit", typeof(BaseEventData)),
				FindMethod(typeof(Toggle), "OnSubmit", typeof(BaseEventData))
			};
			MethodInfo[] array2 = array;
			foreach (MethodInfo methodInfo in array2)
			{
				if (methodInfo != null)
				{
					yield return methodInfo;
				}
			}
		}

		private static MethodInfo FindMethod(Type type, string methodName, params Type[] parameterTypes)
		{
			MethodInfo methodInfo = AccessTools.Method(type, methodName, parameterTypes, (Type[])null);
			if (methodInfo == null)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("Vanilla UI input patch: " + type.FullName + "." + methodName + " was not found."));
				}
			}
			return methodInfo;
		}

		[HarmonyPrefix]
		private static bool Prefix()
		{
			return !DiscoveryHud.OwnsUiFocus;
		}
	}
	[HarmonyPatch]
	internal static class ZInputChatButtonPatch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(AccessTools.TypeByName("ZInput"), "GetButtonDown", new Type[1] { typeof(string) }, (Type[])null);
		}

		[HarmonyPostfix]
		private static void Postfix(ref bool __result, string name)
		{
			if ((name == "Chat" || name == "JoyChat") && DiscoveryHud.OwnsUiFocus)
			{
				__result = false;
			}
		}
	}
}
namespace DiscoveryJournal.Models
{
	internal sealed class DiscoveryEntry
	{
		public DiscoveryType Type { get; }

		public string LocalizationKey { get; }

		public Sprite Icon { get; private set; }

		public int SessionIndex { get; }

		public bool IsRead { get; set; }

		public DiscoveryEntry(DiscoveryType type, string localizationKey, Sprite icon, int sessionIndex)
		{
			Type = type;
			LocalizationKey = localizationKey;
			Icon = icon;
			SessionIndex = sessionIndex;
			IsRead = false;
		}

		public void SetIcon(Sprite icon)
		{
			if ((Object)(object)icon != (Object)null)
			{
				Icon = icon;
			}
		}
	}
	internal enum DiscoveryType
	{
		Item,
		Material,
		Recipe,
		BuildPiece
	}
}
namespace DiscoveryJournal.Core
{
	internal static class DiscoveryIconResolver
	{
		public static void ResolveAll()
		{
			int num = 0;
			int num2 = 0;
			foreach (DiscoveryEntry entry in DiscoveryManager.Entries)
			{
				Sprite val = ResolveIcon(entry.Type, entry.LocalizationKey);
				if ((Object)(object)val != (Object)null)
				{
					entry.SetIcon(val);
					num++;
					continue;
				}
				num2++;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)$"JOURNAL ICON MISSING [{entry.Type}] {entry.LocalizationKey}");
				}
			}
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)$"JOURNAL ICONS | Resolved: {num} | Missing: {num2}");
			}
		}

		private static Sprite ResolveIcon(DiscoveryType type, string localizationKey)
		{
			switch (type)
			{
			case DiscoveryType.Item:
			case DiscoveryType.Material:
			case DiscoveryType.Recipe:
				return ResolveItemIcon(localizationKey);
			case DiscoveryType.BuildPiece:
				return ResolvePieceIcon(localizationKey);
			default:
				return null;
			}
		}

		private static Sprite ResolveItemIcon(string localizationKey)
		{
			if ((Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			foreach (GameObject item in ObjectDB.instance.m_items)
			{
				if (!((Object)(object)item == (Object)null))
				{
					ItemDrop component = item.GetComponent<ItemDrop>();
					if (!((Object)(object)component == (Object)null) && component.m_itemData != null && !(component.m_itemData.m_shared.m_name != localizationKey))
					{
						return component.m_itemData.GetIcon();
					}
				}
			}
			return null;
		}

		private static Sprite ResolvePieceIcon(string localizationKey)
		{
			Piece[] array = Resources.FindObjectsOfTypeAll<Piece>();
			foreach (Piece val in array)
			{
				if (!((Object)(object)val == (Object)null) && !(val.m_name != localizationKey))
				{
					return val.m_icon;
				}
			}
			return null;
		}
	}
	internal static class DiscoveryManager
	{
		private static readonly List<DiscoveryEntry> EntriesInternal = new List<DiscoveryEntry>();

		private static readonly HashSet<string> SeenEntries = new HashSet<string>(StringComparer.Ordinal);

		private static int _nextSessionIndex = 1;

		public static IReadOnlyList<DiscoveryEntry> Entries => EntriesInternal;

		public static int UnreadCount
		{
			get
			{
				int num = 0;
				foreach (DiscoveryEntry item in EntriesInternal)
				{
					if (!item.IsRead)
					{
						num++;
					}
				}
				return num;
			}
		}

		public static List<DiscoveryEntry> GetRecentEntries()
		{
			int count = EntriesInternal.Count;
			List<DiscoveryEntry> list = new List<DiscoveryEntry>();
			for (int num = count - 1; num >= 0; num--)
			{
				list.Add(EntriesInternal[num]);
				if (list.Count == 10)
				{
					break;
				}
			}
			return list;
		}

		public static bool Add(DiscoveryType type, string localizationKey, Sprite icon)
		{
			if (string.IsNullOrWhiteSpace(localizationKey))
			{
				return false;
			}
			string text = $"{type}:{localizationKey}";
			if (!SeenEntries.Add(text))
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogDebug((object)("Duplicate discovery ignored: " + text));
				}
				return false;
			}
			DiscoveryEntry item = new DiscoveryEntry(type, localizationKey, icon, _nextSessionIndex);
			_nextSessionIndex++;
			EntriesInternal.Add(item);
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)$"JOURNAL +1 [{type}] {localizationKey} | Total: {EntriesInternal.Count} | Unread: {UnreadCount}");
			}
			return true;
		}

		public static void Restore(IEnumerable<DiscoveryEntry> entries)
		{
			EntriesInternal.Clear();
			SeenEntries.Clear();
			_nextSessionIndex = 1;
			if (entries == null)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"JOURNAL LOAD | Total: 0 | Unread: 0");
				}
				return;
			}
			foreach (DiscoveryEntry entry in entries)
			{
				if (entry == null || string.IsNullOrWhiteSpace(entry.LocalizationKey))
				{
					continue;
				}
				string text = $"{entry.Type}:{entry.LocalizationKey}";
				if (!SeenEntries.Add(text))
				{
					ManualLogSource log2 = Plugin.Log;
					if (log2 != null)
					{
						log2.LogDebug((object)("Duplicate restored discovery ignored: " + text));
					}
				}
				else
				{
					EntriesInternal.Add(entry);
				}
			}
			ManualLogSource log3 = Plugin.Log;
			if (log3 != null)
			{
				log3.LogInfo((object)$"JOURNAL LOAD | Total: {EntriesInternal.Count} | Unread: {UnreadCount}");
			}
		}

		public static int MarkTypeRead(DiscoveryType type)
		{
			int num = 0;
			foreach (DiscoveryEntry item in EntriesInternal)
			{
				if (item.Type == type && !item.IsRead)
				{
					item.IsRead = true;
					num++;
				}
			}
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)$"JOURNAL READ [{type}] | Marked: {num} | Unread remaining: {UnreadCount}");
			}
			return num;
		}

		public static int MarkAllRead()
		{
			int num = 0;
			foreach (DiscoveryEntry item in EntriesInternal)
			{
				if (!item.IsRead)
				{
					item.IsRead = true;
					num++;
				}
			}
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)$"JOURNAL READ ALL | Marked: {num} | Unread remaining: {UnreadCount}");
			}
			return num;
		}

		public static void ResetSession()
		{
			EntriesInternal.Clear();
			SeenEntries.Clear();
			_nextSessionIndex = 1;
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"Discovery session reset.");
			}
		}
	}
	internal static class DiscoveryPersistence
	{
		private const string SaveKey = "com.andrii.discoveryjournal.journal.v1";

		private const string Header = "DJ1";

		public static void SaveToPlayer(Player player)
		{
			if ((Object)(object)player == (Object)null || player.m_customData == null)
			{
				return;
			}
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("DJ1");
				foreach (DiscoveryEntry entry in DiscoveryManager.Entries)
				{
					string value = Convert.ToBase64String(Encoding.UTF8.GetBytes(entry.LocalizationKey));
					stringBuilder.Append((int)entry.Type).Append('|').Append(entry.IsRead ? '1' : '0')
						.Append('|')
						.Append(value)
						.Append('\n');
				}
				player.m_customData["com.andrii.discoveryjournal.journal.v1"] = stringBuilder.ToString();
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)($"JOURNAL SAVE | Total: {DiscoveryManager.Entries.Count} | " + $"Unread: {DiscoveryManager.UnreadCount}"));
				}
			}
			catch (Exception arg)
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)$"Failed to save Discovery Journal data: {arg}");
				}
			}
		}

		public static void LoadFromPlayer(Player player)
		{
			if ((Object)(object)player == (Object)null || player.m_customData == null)
			{
				DiscoveryManager.ResetSession();
				return;
			}
			if (!player.m_customData.TryGetValue("com.andrii.discoveryjournal.journal.v1", out var value))
			{
				DiscoveryManager.ResetSession();
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"JOURNAL LOAD | No saved journal data for this character.");
				}
				return;
			}
			try
			{
				string[] array = value.Split(new char[1] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
				if (array.Length == 0 || array[0].TrimEnd('\r') != "DJ1")
				{
					ManualLogSource log2 = Plugin.Log;
					if (log2 != null)
					{
						log2.LogWarning((object)"Discovery Journal save data has an unsupported format.");
					}
					DiscoveryManager.ResetSession();
					return;
				}
				List<DiscoveryEntry> list = new List<DiscoveryEntry>();
				for (int i = 1; i < array.Length; i++)
				{
					string[] array2 = array[i].TrimEnd('\r').Split(new char[1] { '|' }, 3);
					if (array2.Length == 3 && int.TryParse(array2[0], out var result) && Enum.IsDefined(typeof(DiscoveryType), result))
					{
						bool isRead = array2[1] == "1";
						string text;
						try
						{
							text = Encoding.UTF8.GetString(Convert.FromBase64String(array2[2]));
						}
						catch
						{
							continue;
						}
						if (!string.IsNullOrWhiteSpace(text))
						{
							DiscoveryEntry discoveryEntry = new DiscoveryEntry((DiscoveryType)result, text, null, 0);
							discoveryEntry.IsRead = isRead;
							list.Add(discoveryEntry);
						}
					}
				}
				DiscoveryManager.Restore(list);
				DiscoveryIconResolver.ResolveAll();
			}
			catch (Exception arg)
			{
				ManualLogSource log3 = Plugin.Log;
				if (log3 != null)
				{
					log3.LogError((object)$"Failed to load Discovery Journal data: {arg}");
				}
				DiscoveryManager.ResetSession();
			}
		}
	}
}