Decompiled source of RomesteadWiki v0.1.0

BepInEx\plugins\RomesteadWiki\RomesteadWiki.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.Json;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using Candide;
using Candide.CandideUI;
using Candide.CandideUI.Components;
using Candide.CandideUI.Components.Buttons;
using Candide.CandideUI.Containers;
using Candide.CandideUI.Input;
using Candide.Database;
using Candide.Graphics;
using Candide.PlayerMode;
using CandideCreator.Shared;
using CandideCreator.Shared.Graphics;
using CandideCreator.Shared.Helpers;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using ModSettingsMenu.Api;
using RomesteadLocalizationAPI.Api;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyCompany("RomesteadWiki")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RomesteadWiki")]
[assembly: AssemblyTitle("RomesteadWiki")]
[assembly: RequiresPreviewFeatures]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace RomesteadWiki;

internal static class I18n
{
	public static readonly RomesteadLocalizer L = RomesteadLocalization.For("wwwshe.romestead.wiki");
}
[BepInPlugin("wwwshe.romestead.wiki", "Romestead Wiki", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BasePlugin
{
	public const string PluginGuid = "wwwshe.romestead.wiki";

	public const string PluginName = "Romestead Wiki";

	public const string PluginVersion = "0.1.0";

	internal static ManualLogSource LogSource = null;

	internal static ConfigEntry<bool> Enabled = null;

	internal static ConfigEntry<string> OpenWikiKey = null;

	internal static string PluginDirectory = string.Empty;

	private Harmony? _harmony;

	private bool _settingsRegistered;

	public override void Load()
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Expected O, but got Unknown
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Expected O, but got Unknown
		LogSource = ((BasePlugin)this).Log;
		PluginDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		I18n.L.RegisterJson(Path.Combine(PluginDirectory, "localization.json"));
		I18n.L.RegisterJson(Path.Combine(PluginDirectory, "localization.wiki.json"));
		WikiLocalization.Initialize(Path.Combine(PluginDirectory, "localization.wiki.json"));
		RegisterSettings();
		RomesteadLocalization.LocalizationApplied += OnLocalizationApplied;
		WikiDataLoader.Reload();
		_harmony = new Harmony("wwwshe.romestead.wiki");
		PatchUiUpdate();
		ManualLogSource logSource = LogSource;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Romestead Wiki");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
		}
		logSource.LogInfo(val);
	}

	public override bool Unload()
	{
		RomesteadLocalization.LocalizationApplied -= OnLocalizationApplied;
		WikiWindowController.Close();
		Harmony? harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		return true;
	}

	private void OnLocalizationApplied(string locale)
	{
		RegisterSettings();
		WikiDataLoader.Reload();
		WikiWindowController.RefreshIfOpen();
	}

	private void RegisterSettings()
	{
		//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_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Expected O, but got Unknown
		if (!_settingsRegistered)
		{
			_settingsRegistered = true;
			Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, BuildDescription("entry.enabled", "entry.enabled.desc", 1));
			OpenWikiKey = ((BasePlugin)this).Config.Bind<string>("General", "OpenWikiKey", "F7", BuildDescription("entry.openWikiKey", "entry.openWikiKey.desc", 2));
			OpenWikiKey.SettingChanged += delegate
			{
				WikiInputController.ResetKeyCache();
			};
		}
		else
		{
			SetDescription((ConfigEntryBase)(object)Enabled, BuildDescription("entry.enabled", "entry.enabled.desc", 1));
			SetDescription((ConfigEntryBase)(object)OpenWikiKey, BuildDescription("entry.openWikiKey", "entry.openWikiKey.desc", 2));
		}
		ModSettingsRegistry.Register("wwwshe.romestead.wiki", I18n.L.Text("mod.name", Array.Empty<object>()), ((BasePlugin)this).Config, new ModSettingsModOptions
		{
			Icon = "cog",
			Version = "0.1.0",
			Author = "wwwshe",
			Description = I18n.L.Text("mod.description", Array.Empty<object>()),
			Order = 80
		});
	}

	private static ConfigDescription BuildDescription(string nameKey, string descKey, int order)
	{
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		return new ConfigDescription(I18n.L.Text(descKey, Array.Empty<object>()), (AcceptableValueBase)null, new object[2]
		{
			ModSettingsTags.Section("General", I18n.L.Text("section.general", Array.Empty<object>()), (int?)10, (bool?)null),
			ModSettingsTags.Entry(I18n.L.Text(nameKey, Array.Empty<object>()), I18n.L.Text(descKey, Array.Empty<object>()), (int?)order, (double?)null, (bool?)null)
		});
	}

	private static void SetDescription(ConfigEntryBase entry, ConfigDescription description)
	{
		typeof(ConfigEntryBase).GetField("<Description>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(entry, description);
	}

	private void PatchUiUpdate()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		MethodInfo methodInfo = FindType("Candide.CandideUI.CandideUiSystem")?.GetMethod("Update", BindingFlags.Static | BindingFlags.Public);
		MethodInfo method = typeof(WikiInputController).GetMethod("OnUiUpdate", BindingFlags.Static | BindingFlags.Public);
		if (methodInfo == null || method == null)
		{
			LogSource.LogWarning((object)"Could not patch CandideUiSystem.Update; wiki hotkey will not work.");
			return;
		}
		_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		LogSource.LogInfo((object)"Patched CandideUiSystem.Update for wiki hotkey.");
	}

	internal static Type? FindType(string fullName)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			Type type = null;
			try
			{
				type = assembly.GetType(fullName, throwOnError: false);
			}
			catch
			{
			}
			if (type != null)
			{
				return type;
			}
		}
		return null;
	}
}
internal static class WikiDataLoader
{
	private static readonly JsonSerializerOptions JsonOptions = new JsonSerializerOptions
	{
		PropertyNameCaseInsensitive = true,
		ReadCommentHandling = JsonCommentHandling.Skip,
		AllowTrailingCommas = true
	};

	private static IReadOnlyList<WikiEntryRaw> _rawEntries = Array.Empty<WikiEntryRaw>();

	private static IReadOnlyList<WikiEntry> _entries = Array.Empty<WikiEntry>();

	public static IReadOnlyList<WikiEntry> Entries => _entries;

	public static void Reload()
	{
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		_rawEntries = LoadRaw(Plugin.PluginDirectory);
		_entries = (from e in _rawEntries.Select(WikiLocalization.Localize)
			orderby CategoryOrder(e.Category), EntryOrder(e)
			select e).ThenBy<WikiEntry, string>((WikiEntry e) => e.Title, StringComparer.CurrentCultureIgnoreCase).ToArray();
		ManualLogSource logSource = Plugin.LogSource;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Loaded ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_entries.Count);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" wiki entries.");
		}
		logSource.LogInfo(val);
	}

	public static IReadOnlyList<WikiEntryRaw> LoadRaw(string pluginDirectory)
	{
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		string text = Path.Combine(pluginDirectory, "WikiData");
		bool flag = default(bool);
		if (!Directory.Exists(text))
		{
			ManualLogSource logSource = Plugin.LogSource;
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(30, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("WikiData directory not found: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
			}
			logSource.LogWarning(val);
			return Array.Empty<WikiEntryRaw>();
		}
		List<WikiEntryRaw> list = new List<WikiEntryRaw>();
		foreach (string item in Directory.EnumerateFiles(text, "*.json", SearchOption.TopDirectoryOnly))
		{
			try
			{
				string json = File.ReadAllText(item);
				WikiEntryRaw[] array = TryDeserializeMany(json);
				if (array != null)
				{
					list.AddRange(array.Where(IsValid));
					continue;
				}
				WikiEntryRaw wikiEntryRaw = JsonSerializer.Deserialize<WikiEntryRaw>(json, JsonOptions);
				if (wikiEntryRaw != null && IsValid(wikiEntryRaw))
				{
					list.Add(wikiEntryRaw);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logSource2 = Plugin.LogSource;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(29, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to load wiki data '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Path.GetFileName(item));
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logSource2.LogWarning(val);
			}
		}
		return list;
	}

	private static WikiEntryRaw[]? TryDeserializeMany(string json)
	{
		if (!json.TrimStart().StartsWith("[", StringComparison.Ordinal))
		{
			return null;
		}
		return JsonSerializer.Deserialize<WikiEntryRaw[]>(json, JsonOptions);
	}

	private static bool IsValid(WikiEntryRaw entry)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Expected O, but got Unknown
		if (string.IsNullOrWhiteSpace(entry.Id) || string.IsNullOrWhiteSpace(entry.Category) || entry.Sections.Length == 0)
		{
			ManualLogSource logSource = Plugin.LogSource;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Skipped invalid wiki entry: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(entry.Id ?? "(unknown)");
			}
			logSource.LogWarning(val);
			return false;
		}
		return true;
	}

	private static int EntryOrder(WikiEntry entry)
	{
		switch (entry.Category)
		{
		case "biomes":
		{
			int result;
			switch (entry.Id)
			{
			case "biome-plains":
				result = 10;
				break;
			case "biome-forest":
				result = 20;
				break;
			case "biome-desert":
				result = 30;
				break;
			case "biome-volcano":
			case "biome-volcano-swamp":
				result = 40;
				break;
			default:
				result = 999;
				break;
			}
			return result;
		}
		case "quests":
			return entry.Id switch
			{
				"quests-overview" => 10, 
				"quests-minerva" => 20, 
				"quests-ceres" => 30, 
				"quests-diana" => 40, 
				"quests-mars" => 50, 
				"quests-mercury" => 60, 
				"quests-venus" => 70, 
				"quests-vulcan" => 80, 
				"quests-minerva-main" => 20, 
				"quests-god-subquests" => 90, 
				"quests-repeatable" => 100, 
				_ => 999, 
			};
		case "towns":
			return entry.Id switch
			{
				"town-overview" => 10, 
				"town-early-setup" => 20, 
				"town-food" => 30, 
				"town-logistics" => 40, 
				_ => 999, 
			};
		case "resources":
			return entry.Id switch
			{
				"resources-overview" => 10, 
				"resources-gathering" => 20, 
				"resources-processed" => 30, 
				"resources-field" => 40, 
				_ => 999, 
			};
		default:
			return 0;
		}
	}

	private static int CategoryOrder(string category)
	{
		return category switch
		{
			"altar" => 10, 
			"quests" => 15, 
			"towns" => 20, 
			"resources" => 30, 
			"npc" => 40, 
			"construction" => 50, 
			"raids" => 60, 
			"biomes" => 70, 
			_ => 999, 
		};
	}
}
internal sealed record WikiEntryRaw(string Id, string Category, string[] Tags, string GameVersion, WikiSectionRaw[] Sections, string[] Sources, string? Icon = null);
internal sealed record WikiSectionRaw(string? Icon = null);
internal sealed record WikiEntry(string Id, string Category, string Title, string[] Tags, string GameVersion, WikiSection[] Sections, string[] Sources, string? Icon = null);
internal sealed record WikiSection(string Heading, string Body, string? Icon = null);
internal static class WikiInputController
{
	private static string? _cachedKeyName;

	private static Keys? _cachedKey;

	private static bool _wasDown;

	public static void ResetKeyCache()
	{
		_cachedKeyName = null;
		_cachedKey = null;
		_wasDown = false;
	}

	public static void OnUiUpdate(GameTime gameTime)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Enabled.Value)
		{
			return;
		}
		Keys? configuredKey = GetConfiguredKey();
		if (configuredKey.HasValue)
		{
			KeyboardState state = Keyboard.GetState();
			bool num = ((KeyboardState)(ref state)).IsKeyDown(configuredKey.Value);
			if (num && !_wasDown)
			{
				WikiWindowController.Toggle();
			}
			_wasDown = num;
		}
	}

	private static Keys? GetConfiguredKey()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		string text = (Plugin.OpenWikiKey.Value ?? "F7").Trim();
		if (string.Equals(_cachedKeyName, text, StringComparison.OrdinalIgnoreCase))
		{
			return _cachedKey;
		}
		_cachedKeyName = text;
		if (Enum.TryParse<Keys>(text, ignoreCase: true, out Keys result))
		{
			_cachedKey = result;
			return result;
		}
		ManualLogSource logSource = Plugin.LogSource;
		bool flag = default(bool);
		BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(79, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalid wiki hotkey '");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'. Use a Microsoft.Xna.Framework.Input.Keys name, e.g. F7.");
		}
		logSource.LogWarning(val);
		_cachedKey = null;
		return null;
	}
}
internal static class WikiLocalization
{
	private static readonly Dictionary<string, string> EnglishFallback = new Dictionary<string, string>(StringComparer.Ordinal);

	public static void Initialize(string wikiLocalizationPath)
	{
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		EnglishFallback.Clear();
		bool flag = default(bool);
		if (!File.Exists(wikiLocalizationPath))
		{
			ManualLogSource logSource = Plugin.LogSource;
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Wiki localization file not found: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(wikiLocalizationPath);
			}
			logSource.LogWarning(val);
			return;
		}
		try
		{
			using FileStream utf8Json = File.OpenRead(wikiLocalizationPath);
			using JsonDocument jsonDocument = JsonDocument.Parse((Stream)utf8Json, default(JsonDocumentOptions));
			if (!jsonDocument.RootElement.TryGetProperty("en", out var value))
			{
				return;
			}
			foreach (JsonProperty item in value.EnumerateObject())
			{
				if (item.Value.ValueKind == JsonValueKind.String)
				{
					EnglishFallback[item.Name] = item.Value.GetString() ?? string.Empty;
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource logSource2 = Plugin.LogSource;
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(38, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to load wiki English fallback: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			logSource2.LogWarning(val);
		}
	}

	public static string TitleKey(string entryId)
	{
		return "wiki.entry." + entryId + ".title";
	}

	public static string SectionHeadingKey(string entryId, int sectionIndex)
	{
		return $"wiki.entry.{entryId}.s{sectionIndex}.h";
	}

	public static string SectionBodyKey(string entryId, int sectionIndex)
	{
		return $"wiki.entry.{entryId}.s{sectionIndex}.b";
	}

	public static string Text(string key)
	{
		string text = I18n.L.Text(key, Array.Empty<object>());
		if (!IsMissing(key, text))
		{
			return text;
		}
		if (EnglishFallback.TryGetValue(key, out string value) && !string.IsNullOrEmpty(value))
		{
			return value;
		}
		return text;
	}

	public static WikiEntry Localize(WikiEntryRaw raw)
	{
		WikiSection[] array = new WikiSection[raw.Sections.Length];
		for (int i = 0; i < raw.Sections.Length; i++)
		{
			WikiSectionRaw wikiSectionRaw = raw.Sections[i];
			string key = SectionHeadingKey(raw.Id, i);
			string key2 = SectionBodyKey(raw.Id, i);
			string text = Text(key);
			if (IsMissing(key, text))
			{
				text = string.Empty;
			}
			string text2 = Text(key2);
			if (IsMissing(key2, text2))
			{
				text2 = string.Empty;
			}
			array[i] = new WikiSection(text, text2, wikiSectionRaw.Icon);
		}
		string key3 = TitleKey(raw.Id);
		string text3 = Text(key3);
		if (IsMissing(key3, text3))
		{
			text3 = raw.Id;
		}
		return new WikiEntry(raw.Id, raw.Category, text3, raw.Tags, raw.GameVersion, array, raw.Sources, raw.Icon);
	}

	private static bool IsMissing(string key, string value)
	{
		if (!string.IsNullOrEmpty(value))
		{
			return string.Equals(key, value, StringComparison.Ordinal);
		}
		return true;
	}
}
internal static class WikiWindowController
{
	private sealed class WikiWindow : CandideExtendedWindow
	{
		private const int ContentWidth = 500;

		private const int ListWidth = 200;

		private const int ContentLeftPadding = 12;

		private const int ScrollBarGutter = 40;

		private const int ContentTextWidth = 448;

		private const int ListScrollGutter = 28;

		private const int ListItemWidth = 172;

		private readonly CandideTextInputBox _searchInput = new CandideTextInputBox
		{
			Padding = new CandideThickness(6, 4, 0, 4),
			Margin = new CandideThickness(0, 0, 2, 0),
			HorizontalAlignment = (HorizontalAlignment)3,
			VerticalAlignment = (VerticalAlignment)1,
			Background = ColorPaletteHelper.BlackBlue,
			SelectAllWhenSelected = true,
			GridColumn = 0
		};

		private readonly CandideListView _entryList = new CandideListView
		{
			Width = 200,
			Height = 365,
			GridColumn = 0,
			GridRow = 2,
			ShowVerticalScrollBar = true,
			ControllerAutoSelectHovered = false
		};

		private readonly CandideListView _contentList = new CandideListView
		{
			Width = 500,
			Height = 400,
			GridColumn = 1,
			GridRow = 1,
			GridRowSpan = 2,
			ShowVerticalScrollBar = true,
			ControllerAutoSelectHovered = false,
			Padding = new CandideThickness(12, 0, 0, 0)
		};

		private readonly CandideLabelButton _sourceButton;

		private string _currentSourceUrl = string.Empty;

		private string? _currentEntryId;

		private const string HighlightColorHex = "#ffe25a";

		private static readonly Dictionary<string, (string Path, int Frame)> TileIcons = new Dictionary<string, (string, int)>
		{
			["tile:grass"] = ("media/autotiles/grass/short_grass", 40),
			["tile:tall_grass"] = ("media/autotiles/grass/tall_grass", 40),
			["tile:sand"] = ("media/autotiles/sandtile", 16),
			["tile:ash"] = ("media/autotiles/ash_tileset", 24)
		};

		private static readonly IconFlag[] PreferredIconFlags;

		private IReadOnlyList<WikiEntry> Entries => WikiDataLoader.Entries;

		private string SearchQuery => _searchInput.Text.Trim();

		public WikiWindow()
			: base((WindowGraphics)1)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_009d: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Expected O, but got Unknown
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Expected O, but got Unknown
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			((CandideWindow)this).MouseSettingsId = "RomesteadWiki";
			CandideGrid val = new CandideGrid
			{
				ColumnsProportions = { Proportion.Auto },
				ColumnsProportions = { Proportion.Fill },
				RowsProportions = { Proportion.Auto },
				RowsProportions = { Proportion.Auto },
				RowsProportions = { Proportion.Fill },
				RowsProportions = { Proportion.Auto },
				HorizontalAlignment = (HorizontalAlignment)3,
				VerticalAlignment = (VerticalAlignment)3,
				Padding = new CandideThickness(14)
			};
			((CandideUiContainerMultipleItems)val).AddChild((CandideUiElement)new CandideTextLabel
			{
				Text = I18n.L.Text("wiki.window.title", Array.Empty<object>()),
				TextStyle = (CandideTextStyle)4,
				TextColor = StyleHelper.YellowText,
				GridColumn = 0,
				GridColumnSpan = 2,
				GridRow = 0,
				Margin = new CandideThickness(0, 0, 0, 10)
			}, false);
			CandideGrid val2 = new CandideGrid
			{
				ColumnsProportions = { Proportion.Fill },
				ColumnsProportions = { Proportion.Auto },
				Width = 200,
				GridColumn = 0,
				GridRow = 1,
				HorizontalAlignment = (HorizontalAlignment)3,
				Margin = new CandideThickness(0, 0, 28, 8)
			};
			((CandideUiContainerMultipleItems)val2).AddChild((CandideUiElement)(object)_searchInput, false);
			((CandideUiContainerMultipleItems)val2).AddChild((CandideUiElement)new CandideIcon((IconFlag)1)
			{
				Icon = "magnifying_glass",
				GridColumn = 1,
				VerticalAlignment = (VerticalAlignment)1,
				HorizontalAlignment = (HorizontalAlignment)2,
				Margin = new CandideThickness(4, 0, 2, 0)
			}, false);
			_searchInput.TextChanged += delegate
			{
				BuildEntryList();
			};
			((CandideUiContainerMultipleItems)val).AddChild((CandideUiElement)(object)val2, false);
			((CandideUiContainerMultipleItems)val).AddChild((CandideUiElement)(object)_entryList, false);
			((CandideUiContainerMultipleItems)val).AddChild((CandideUiElement)(object)_contentList, false);
			_sourceButton = new CandideLabelButton(500, (int?)26)
			{
				Text = I18n.L.Text("wiki.openSource", Array.Empty<object>()),
				GridColumn = 1,
				GridRow = 3,
				HorizontalAlignment = (HorizontalAlignment)0,
				Margin = new CandideThickness(12, 10, 0, 0),
				OnClickAction = delegate
				{
					OpenUrl(_currentSourceUrl);
				}
			};
			((CandideTextLabel)_sourceButton.Label).TextColor = StyleHelper.TextLightBlue;
			((CandideUiContainerMultipleItems)val).AddChild((CandideUiElement)(object)_sourceButton, false);
			((CandideUiContainerSingleItem)this).SetChild((CandideUiElement)(object)val);
			BuildEntryList();
		}

		public void Refresh()
		{
			BuildEntryList();
			_sourceButton.Text = (string.IsNullOrEmpty(_currentSourceUrl) ? I18n.L.Text("wiki.openSource.none", Array.Empty<object>()) : I18n.L.Text("wiki.openSource", Array.Empty<object>()));
		}

		private void BuildEntryList()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//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)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Expected O, but got Unknown
			_entryList.ClearAllItems();
			if (Entries.Count == 0)
			{
				_entryList.AddNonItem((CandideUiElement)new CandideTextLabel
				{
					Text = I18n.L.Text("wiki.empty", Array.Empty<object>()),
					TextColor = StyleHelper.ColorItemGray,
					Wrap = true,
					Width = 172
				});
				((CandideUiElement)_sourceButton).Enabled = false;
				return;
			}
			string query = SearchQuery;
			WikiEntry[] array = Entries.Where((WikiEntry entry3) => MatchesSearch(entry3, query)).ToArray();
			if (array.Length == 0)
			{
				_entryList.AddNonItem((CandideUiElement)new CandideTextLabel
				{
					Text = I18n.L.Text("wiki.search.empty", Array.Empty<object>()),
					TextColor = StyleHelper.ColorItemGray,
					Wrap = true,
					Width = 172
				});
				_contentList.ClearAllItems();
				_contentList.AddNonItem((CandideUiElement)new CandideTextLabel
				{
					Text = I18n.L.Text("wiki.search.empty", Array.Empty<object>()),
					TextColor = StyleHelper.ColorItemGray,
					Wrap = true,
					Width = 448
				});
				((CandideUiElement)_sourceButton).Enabled = false;
				_sourceButton.Text = I18n.L.Text("wiki.openSource.none", Array.Empty<object>());
				return;
			}
			string text = null;
			WikiEntry[] array2 = array;
			foreach (WikiEntry entry in array2)
			{
				if (!string.Equals(text, entry.Category, StringComparison.OrdinalIgnoreCase))
				{
					text = entry.Category;
					_entryList.AddNonItem((CandideUiElement)new CandideTextLabel
					{
						Text = GetCategoryTitle(text),
						TextStyle = (CandideTextStyle)2,
						TextColor = StyleHelper.TextYellowColor,
						Width = 172,
						Margin = new CandideThickness(0, 10, 0, 3)
					});
				}
				CandideLabelButton val = new CandideLabelButton(172, (int?)24)
				{
					Text = entry.Title,
					HorizontalAlignment = (HorizontalAlignment)3,
					Margin = new CandideThickness(0, 0, 28, 3),
					OnClickAction = delegate
					{
						ShowEntry(entry);
					}
				};
				_entryList.AddNonItem((CandideUiElement)(object)val);
			}
			WikiEntry entry2 = array.FirstOrDefault((WikiEntry wikiEntry) => wikiEntry.Id == _currentEntryId) ?? array[0];
			ShowEntry(entry2);
		}

		private void ShowEntry(WikiEntry entry)
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_005c: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00b1: Expected O, but got Unknown
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: 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_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Expected O, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Expected O, but got Unknown
			//IL_016b: 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_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Expected O, but got Unknown
			_contentList.ClearAllItems();
			_currentEntryId = entry.Id;
			string searchQuery = SearchQuery;
			CandideUiElement val = TryBuildTileHeader(entry.Icon, entry.Title, searchQuery);
			if (val != null)
			{
				_contentList.AddNonItem(val);
			}
			else
			{
				IconFlag? val2 = ResolveBestIconFlag(entry.Icon);
				if (val2.HasValue)
				{
					CandideIconLabel val3 = new CandideIconLabel(val2.Value, false)
					{
						Icon = entry.Icon,
						Text = BuildDisplayText(entry.Title, searchQuery),
						TextColor = StyleHelper.YellowText,
						Width = 448,
						Margin = new CandideThickness(0, 0, 0, 10)
					};
					val3.Label.TextStyle = (CandideTextStyle)4;
					_contentList.AddNonItem((CandideUiElement)(object)val3);
				}
				else
				{
					CandideTextLabel val4 = new CandideTextLabel
					{
						Text = BuildDisplayText(entry.Title, searchQuery),
						TextStyle = (CandideTextStyle)4,
						TextColor = StyleHelper.YellowText,
						Wrap = true,
						Width = 448,
						Margin = new CandideThickness(0, 0, 0, 10)
					};
					_contentList.AddNonItem((CandideUiElement)(object)val4);
				}
			}
			WikiSection[] sections = entry.Sections;
			foreach (WikiSection wikiSection in sections)
			{
				if (!string.IsNullOrWhiteSpace(wikiSection.Heading))
				{
					IconFlag? val5 = ResolveBestIconFlag(wikiSection.Icon);
					if (val5.HasValue)
					{
						CandideIconLabel val6 = new CandideIconLabel(val5.Value, false)
						{
							Icon = wikiSection.Icon,
							Text = BuildDisplayText(wikiSection.Heading, searchQuery),
							TextColor = StyleHelper.ColorItemOrange,
							Width = 448,
							Margin = new CandideThickness(0, 10, 0, 3)
						};
						val6.Label.TextStyle = (CandideTextStyle)2;
						_contentList.AddNonItem((CandideUiElement)(object)val6);
					}
					else
					{
						CandideTextLabel val7 = new CandideTextLabel
						{
							Text = BuildDisplayText(wikiSection.Heading, searchQuery),
							TextStyle = (CandideTextStyle)2,
							TextColor = StyleHelper.ColorItemOrange,
							Wrap = true,
							Width = 448,
							Margin = new CandideThickness(0, 10, 0, 3)
						};
						_contentList.AddNonItem((CandideUiElement)(object)val7);
					}
				}
				CandideTextLabel val8 = new CandideTextLabel
				{
					Text = BuildDisplayText(wikiSection.Body, searchQuery),
					TextColor = StyleHelper.ColorItemGray,
					Wrap = true,
					Width = 448,
					Margin = new CandideThickness(0, 0, 0, 6)
				};
				_contentList.AddNonItem((CandideUiElement)(object)val8);
			}
			_currentSourceUrl = GetFirstUrl(entry);
			if (string.IsNullOrEmpty(_currentSourceUrl))
			{
				((CandideUiElement)_sourceButton).Enabled = false;
				_sourceButton.Text = I18n.L.Text("wiki.openSource.none", Array.Empty<object>());
			}
			else
			{
				((CandideUiElement)_sourceButton).Enabled = true;
				_sourceButton.Text = I18n.L.Text("wiki.openSource", Array.Empty<object>());
			}
		}

		private static bool MatchesSearch(WikiEntry entry, string query)
		{
			if (string.IsNullOrWhiteSpace(query))
			{
				return true;
			}
			if (ContainsSearchText(entry.Title, query) || ContainsSearchText(GetCategoryTitle(entry.Category), query) || entry.Tags.Any((string tag) => ContainsSearchText(tag, query)))
			{
				return true;
			}
			return entry.Sections.Any((WikiSection section) => ContainsSearchText(section.Heading, query) || ContainsSearchText(section.Body, query));
		}

		private static bool ContainsSearchText(string? text, string query)
		{
			if (!string.IsNullOrWhiteSpace(text) && !string.IsNullOrWhiteSpace(query))
			{
				return text.Contains(query, StringComparison.CurrentCultureIgnoreCase);
			}
			return false;
		}

		private static string EscapeRich(string text)
		{
			return text.Replace("/", "//");
		}

		private static string BuildDisplayText(string? text, string query)
		{
			if (string.IsNullOrEmpty(text))
			{
				return string.Empty;
			}
			if (string.IsNullOrWhiteSpace(query))
			{
				return EscapeRich(text);
			}
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			while (num < text.Length)
			{
				int num2 = text.IndexOf(query, num, StringComparison.CurrentCultureIgnoreCase);
				if (num2 < 0)
				{
					stringBuilder.Append(EscapeRich(text.Substring(num)));
					break;
				}
				stringBuilder.Append(EscapeRich(text.Substring(num, num2 - num)));
				stringBuilder.Append("/c[").Append("#ffe25a").Append(']');
				stringBuilder.Append(EscapeRich(text.Substring(num2, query.Length)));
				stringBuilder.Append("/cd");
				num = num2 + query.Length;
			}
			return stringBuilder.ToString();
		}

		private static CandideUiElement? TryBuildTileHeader(string? iconId, string title, string query)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00f5: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_015c: Expected O, but got Unknown
			if (string.IsNullOrWhiteSpace(iconId) || !TileIcons.TryGetValue(iconId, out (string, int) value))
			{
				return null;
			}
			SpriteSheet val;
			try
			{
				val = Content.SpriteSheet(value.Item1, 16, 16, default(Vector2));
			}
			catch (Exception ex)
			{
				ManualLogSource logSource = Plugin.LogSource;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Could not load tile icon '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(iconId);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("': ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				logSource.LogWarning(val2);
				return null;
			}
			if (val == null)
			{
				return null;
			}
			CandideGrid val3 = new CandideGrid
			{
				ColumnsProportions = { Proportion.Auto },
				ColumnsProportions = { Proportion.Fill },
				Width = 448,
				Margin = new CandideThickness(0, 0, 0, 10)
			};
			((CandideUiContainerMultipleItems)val3).AddChild((CandideUiElement)new CandideImage
			{
				SpriteSheet = val,
				Frame = value.Item2,
				Scale = new Vector2(2f, 2f),
				GridColumn = 0,
				VerticalAlignment = (VerticalAlignment)1
			}, false);
			((CandideUiContainerMultipleItems)val3).AddChild((CandideUiElement)new CandideTextLabel
			{
				Text = BuildDisplayText(title, query),
				TextStyle = (CandideTextStyle)4,
				TextColor = StyleHelper.YellowText,
				VerticalAlignment = (VerticalAlignment)1,
				GridColumn = 1,
				Margin = new CandideThickness(8, 0, 0, 0)
			}, false);
			return (CandideUiElement?)val3;
		}

		private static IconFlag? ResolveBestIconFlag(string? iconId)
		{
			//IL_0039: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(iconId))
			{
				return null;
			}
			IconData? iconOrNull = IconDataBase.GetIconOrNull(iconId);
			if (!iconOrNull.HasValue)
			{
				return null;
			}
			IconFlag[] preferredIconFlags = PreferredIconFlags;
			foreach (IconFlag val in preferredIconFlags)
			{
				IconData value = iconOrNull.Value;
				if (((IconData)(ref value)).GetIconOrNull(val).HasValue)
				{
					return val;
				}
			}
			return null;
		}

		private static string GetFirstUrl(WikiEntry entry)
		{
			string[] sources = entry.Sources;
			foreach (string text in sources)
			{
				if (text.StartsWith("http://", StringComparison.OrdinalIgnoreCase) || text.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
				{
					return text;
				}
			}
			return string.Empty;
		}

		private static string GetCategoryTitle(string category)
		{
			string text = "category." + category;
			string text2 = I18n.L.Text(text, Array.Empty<object>());
			if (!string.IsNullOrWhiteSpace(text2) && !(text2 == text))
			{
				return text2;
			}
			return category;
		}

		static WikiWindow()
		{
			IconFlag[] array = new IconFlag[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			PreferredIconFlags = (IconFlag[])(object)array;
		}
	}

	private static WikiWindow? _window;

	public static void Toggle()
	{
		if (_window != null)
		{
			Close();
		}
		else
		{
			Show();
		}
	}

	public static void Close()
	{
		WikiWindow? window = _window;
		if (window != null)
		{
			((CandideWindow)window).Close();
		}
		_window = null;
	}

	public static void RefreshIfOpen()
	{
		_window?.Refresh();
	}

	private static void Show()
	{
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		try
		{
			CandideEngine game = Globals.Game;
			object obj;
			if (game == null)
			{
				obj = null;
			}
			else
			{
				AbstractModeManager modeManager = game.ModeManager;
				obj = ((modeManager != null) ? modeManager.CandideDesktop : null);
			}
			CandideDesktop val = (CandideDesktop)obj;
			if (val == null)
			{
				Plugin.LogSource.LogWarning((object)"Could not open wiki: CandideDesktop is not available.");
				return;
			}
			WikiWindow wikiWindow = new WikiWindow();
			((CandideUiElement)wikiWindow).Width = 760;
			((CandideUiElement)wikiWindow).Height = 500;
			((CandideUiElement)wikiWindow).HorizontalAlignment = (HorizontalAlignment)1;
			((CandideUiElement)wikiWindow).VerticalAlignment = (VerticalAlignment)1;
			((CandideExtendedWindow)wikiWindow).CloseOnUiClosedPress = true;
			_window = wikiWindow;
			((CandideWindow)_window).Closed += delegate
			{
				_window = null;
			};
			((CandideWindow)_window).Show(val, (int?)null, (int?)null);
		}
		catch (Exception ex)
		{
			ManualLogSource logSource = Plugin.LogSource;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(28, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Could not open wiki window: ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
			}
			logSource.LogWarning(val2);
			_window = null;
		}
	}

	private static void OpenUrl(string url)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		if (string.IsNullOrWhiteSpace(url))
		{
			return;
		}
		try
		{
			Process.Start(new ProcessStartInfo
			{
				FileName = url,
				UseShellExecute = true
			});
		}
		catch (Exception ex)
		{
			ManualLogSource logSource = Plugin.LogSource;
			bool flag = default(bool);
			BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(23, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Could not open URL '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(url);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("': ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			logSource.LogWarning(val);
		}
	}
}