Decompiled source of ModSettingsMenu v1.2.0

BepInEx/plugins/ModSettingsMenu/ModSettingsMenu.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GraveyardKeeper2LocalizationAPI.Api;
using HarmonyLib;
using LazyBearTechnology;
using ModSettingsMenu.Api;
using ModSettingsMenu.Configuration;
using ModSettingsMenu.Localization;
using ModSettingsMenu.Patches;
using ModSettingsMenu.Runtime;
using ModSettingsMenu.Update;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.TextCore;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ModSettingsMenu")]
[assembly: AssemblyDescription("Mod Settings Menu mod for Graveyard Keeper 2 by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("ModSettingsMenu")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("d041f388-c515-4768-abca-f1b9cd68a54b")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.2.0.0")]
namespace ModSettingsMenu
{
	[BepInPlugin("IceBoxStudio.GraveyardKeeper2.ModSettingsMenu", "ModSettingsMenu", "1.2.0")]
	[BepInDependency("IceBoxStudio.GraveyardKeeper2.LocalizationAPI", "1.0.1")]
	public sealed class ModSettingsMenu : BaseUnityPlugin
	{
		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			MenuSetup.Init(this);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.GraveyardKeeper2.ModSettingsMenu";

		public const string PLUGIN_NAME = "ModSettingsMenu";

		public const string PLUGIN_VERSION = "1.2.0";

		public const string PLUGIN_AUTHOR = "Ice Box Studio";

		public const string UPDATE_MANIFEST_URL = "https://cdn.jsdelivr.net/gh/ibox233/MyMod_Version@main/GraveyardKeeper2/ModSettingsMenu.json";

		public const int NEXUS_MODS_ID = 245;

		public const string THUNDERSTORE_TEAM = "Ice_Box_Studio_GK2";

		public const string THUNDERSTORE_MOD_NAME = "ModSettingsMenu";
	}
}
namespace ModSettingsMenu.Update
{
	internal static class ModUpdateChecker
	{
		private const int MaxManifestBytes = 16384;

		private const int MaxThunderstoreBytes = 8388608;

		private const string ThunderstorePackagesUrl = "https://thunderstore.io/c/graveyard-keeper-2/api/v1/package/";

		private static readonly SemaphoreSlim ThunderstoreCatalogSlot = new SemaphoreSlim(1, 1);

		private static JArray ThunderstorePackages;

		private static DateTime ThunderstoreCatalogRetryAfter;

		private static readonly TimeSpan Timeout = TimeSpan.FromSeconds(4.0);

		private static readonly Dictionary<string, ModUpdateCheckResult> Results = new Dictionary<string, ModUpdateCheckResult>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, string> CheckKeys = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

		private static readonly Dictionary<string, DateTime> RetryAfter = new Dictionary<string, DateTime>(StringComparer.OrdinalIgnoreCase);

		private static readonly SemaphoreSlim Slots = new SemaphoreSlim(3, 3);

		private static int _revision;

		private static readonly object Sync = new object();

		private static readonly HttpClientHandler ClientHandler = new HttpClientHandler
		{
			AllowAutoRedirect = false
		};

		private static readonly HttpClient Client = new HttpClient((HttpMessageHandler)(object)ClientHandler)
		{
			Timeout = Timeout
		};

		public static int Revision => Volatile.Read(in _revision);

		public static void CheckAll()
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (((value != null) ? value.Metadata : null) != null)
				{
					ModSettingsRegistry.TryGet(value.Metadata.GUID, out var registration);
					ModConfig mod = new ModConfig
					{
						Info = value,
						Registration = registration
					};
					string currentVersion = (string.IsNullOrWhiteSpace(registration?.Version) ? value.Metadata.Version.ToString() : registration.Version);
					GetOrStart(mod, currentVersion);
				}
			}
		}

		public static ModUpdateCheckResult Get(string guid)
		{
			ModSettingsRegistry.TryGet(guid, out var registration);
			if (!IsEnabled(registration?.UpdateManifestUrl))
			{
				return ModUpdateCheckResult.NotConfigured();
			}
			lock (Sync)
			{
				ModUpdateCheckResult value;
				return Results.TryGetValue(guid, out value) ? value : ModUpdateCheckResult.NotConfigured();
			}
		}

		public static int GetUpdateCount()
		{
			return Chainloader.PluginInfos.Keys.Count((string guid) => Get(guid).Status == ModUpdateCheckStatus.UpdateAvailable);
		}

		public static ModUpdateCheckResult GetOrStart(ModConfig mod, string currentVersion)
		{
			object obj;
			if (mod == null)
			{
				obj = null;
			}
			else
			{
				PluginInfo info = mod.Info;
				obj = ((info != null) ? info.Metadata : null);
			}
			if (obj == null || !IsEnabled(mod.Registration?.UpdateManifestUrl))
			{
				return ModUpdateCheckResult.NotConfigured();
			}
			ModSettingsRegistration registration = mod.Registration;
			string gUID = mod.Info.Metadata.GUID;
			string text = currentVersion + "\n" + registration?.UpdateManifestUrl + "\n" + registration?.NexusModsId + "\n" + registration?.ThunderstoreTeam + "\n" + registration?.ThunderstoreModName + "\n" + mod.Info.Metadata.Name + "\n" + registration?.Name;
			ModUpdateCheckResult value2;
			lock (Sync)
			{
				if (CheckKeys.TryGetValue(gUID, out var value) && value == text && Results.TryGetValue(gUID, out value2) && (value2.Status != ModUpdateCheckStatus.Failed || (RetryAfter.TryGetValue(gUID, out var value3) && DateTime.UtcNow < value3)))
				{
					return value2;
				}
				CheckKeys[gUID] = text;
				RetryAfter.Remove(gUID);
				value2 = ModUpdateCheckResult.Checking();
				Results[gUID] = value2;
			}
			CheckAsync(gUID, currentVersion, registration?.UpdateManifestUrl, registration?.NexusModsId, mod.Info.Metadata.Name, registration?.Name, registration?.ThunderstoreTeam, registration?.ThunderstoreModName, text);
			return value2;
		}

		private static bool IsEnabled(string manifestUrl)
		{
			ConfigEntry<bool> checkUpdates = MenuConfig.CheckUpdates;
			if (checkUpdates != null && !checkUpdates.Value)
			{
				return !string.IsNullOrWhiteSpace(manifestUrl);
			}
			return true;
		}

		private static async Task CheckAsync(string pluginGuid, string currentVersion, string manifestUrl, int? nexusModsId, string modName, string registeredName, string thunderstoreTeam, string thunderstoreModName, string key)
		{
			await Slots.WaitAsync().ConfigureAwait(continueOnCapturedContext: false);
			try
			{
				ModUpdateCheckResult modUpdateCheckResult = (string.IsNullOrWhiteSpace(manifestUrl) ? (await SearchThunderstoreAsync(currentVersion, modName, registeredName, thunderstoreTeam, thunderstoreModName).ConfigureAwait(continueOnCapturedContext: false)) : (await CheckCoreAsync(currentVersion, manifestUrl).ConfigureAwait(continueOnCapturedContext: false)));
				ModUpdateCheckResult modUpdateCheckResult2 = modUpdateCheckResult;
				lock (Sync)
				{
					if (CheckKeys[pluginGuid] == key)
					{
						Results[pluginGuid] = modUpdateCheckResult2;
						if (modUpdateCheckResult2.Status == ModUpdateCheckStatus.Failed)
						{
							RetryAfter[pluginGuid] = DateTime.UtcNow.AddMinutes(1.0);
						}
						Interlocked.Increment(ref _revision);
					}
				}
			}
			finally
			{
				Slots.Release();
			}
		}

		private static async Task<ModUpdateCheckResult> SearchThunderstoreAsync(string currentVersion, string modName, string registeredName, string team, string packageName)
		{
			try
			{
				JArray val = await GetPackagesAsync().ConfigureAwait(continueOnCapturedContext: false);
				if (val == null)
				{
					return Failed();
				}
				if (!string.IsNullOrWhiteSpace(team) && !string.IsNullOrWhiteSpace(packageName))
				{
					List<JToken> list = ((IEnumerable<JToken>)val).Where(delegate(JToken package)
					{
						JToken obj4 = package[(object)"owner"];
						if (string.Equals((obj4 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj4) : null, team, StringComparison.OrdinalIgnoreCase))
						{
							JToken obj5 = package[(object)"name"];
							return string.Equals((obj5 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj5) : null, packageName, StringComparison.OrdinalIgnoreCase);
						}
						return false;
					}).ToList();
					return (list.Count == 1) ? CheckPackage(currentVersion, list[0]) : ModUpdateCheckResult.NotConfigured();
				}
				List<string> nameKeys = GetNameKeys(modName, registeredName);
				if (nameKeys.Count == 0)
				{
					return ModUpdateCheckResult.NotConfigured();
				}
				JToken val2 = null;
				int num = 0;
				bool flag = false;
				foreach (JToken item in val)
				{
					JToken obj = item[(object)"owner"];
					string owner = ((obj != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj) : null);
					JToken obj2 = item[(object)"name"];
					string name = ((obj2 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj2) : null);
					JToken obj3 = item[(object)"full_name"];
					string fullName = ((obj3 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj3) : null);
					int num2 = ScorePackage(nameKeys, owner, name, fullName);
					if (num2 >= 70)
					{
						if (num2 > num)
						{
							val2 = item;
							num = num2;
							flag = false;
						}
						else if (num2 == num)
						{
							flag = true;
						}
					}
				}
				return (val2 == null || flag) ? ModUpdateCheckResult.NotConfigured() : CheckPackage(currentVersion, val2);
			}
			catch (OperationCanceledException)
			{
				return Failed();
			}
			catch (Exception ex2)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					log.LogWarning((object)("Thunderstore update search failed: " + ex2.Message));
				}
				return Failed();
			}
		}

		private static async Task<JArray> GetPackagesAsync()
		{
			if (ThunderstorePackages != null)
			{
				return ThunderstorePackages;
			}
			if (ThunderstoreCatalogRetryAfter > DateTime.UtcNow)
			{
				return null;
			}
			await ThunderstoreCatalogSlot.WaitAsync().ConfigureAwait(continueOnCapturedContext: false);
			try
			{
				if (ThunderstorePackages != null)
				{
					return ThunderstorePackages;
				}
				if (ThunderstoreCatalogRetryAfter > DateTime.UtcNow)
				{
					return null;
				}
				using CancellationTokenSource cts = new CancellationTokenSource(Timeout);
				HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "https://thunderstore.io/c/graveyard-keeper-2/api/v1/package/");
				try
				{
					request.Headers.UserAgent.ParseAdd("GK2-ModSettingsMenu/1.2.0");
					HttpResponseMessage response = await Client.SendAsync(request, (HttpCompletionOption)1, cts.Token).ConfigureAwait(continueOnCapturedContext: false);
					try
					{
						if (response.StatusCode != HttpStatusCode.OK || response.Content.Headers.ContentLength > 8388608)
						{
							ThunderstoreCatalogRetryAfter = DateTime.UtcNow.AddMinutes(1.0);
							return null;
						}
						using Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(continueOnCapturedContext: false);
						ThunderstorePackages = JArray.Parse(await ReadLimitedStringAsync(stream, cts.Token, 8388608).ConfigureAwait(continueOnCapturedContext: false));
						return ThunderstorePackages;
					}
					finally
					{
						((IDisposable)response)?.Dispose();
					}
				}
				finally
				{
					((IDisposable)request)?.Dispose();
				}
			}
			catch
			{
				ThunderstoreCatalogRetryAfter = DateTime.UtcNow.AddMinutes(1.0);
				throw;
			}
			finally
			{
				ThunderstoreCatalogSlot.Release();
			}
		}

		private static ModUpdateCheckResult CheckPackage(string currentVersion, JToken package)
		{
			JToken obj = package[(object)"owner"];
			string text = ((obj != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj) : null);
			JToken obj2 = package[(object)"name"];
			string text2 = ((obj2 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj2) : null);
			JToken obj3 = package[(object)"versions"];
			JObject? obj4 = ((IEnumerable)((obj3 is JArray) ? obj3 : null))?.OfType<JObject>().FirstOrDefault((Func<JObject, bool>)delegate(JObject version)
			{
				JToken obj7 = version["is_active"];
				return obj7 != null && Extensions.Value<bool>((IEnumerable<JToken>)obj7);
			});
			object obj5;
			if (obj4 == null)
			{
				obj5 = null;
			}
			else
			{
				JToken obj6 = obj4["version_number"];
				obj5 = ((obj6 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj6) : null);
			}
			string text3 = (string)obj5;
			if (string.IsNullOrWhiteSpace(text) || string.IsNullOrWhiteSpace(text2) || string.IsNullOrWhiteSpace(text3))
			{
				return Failed();
			}
			string thunderstoreUrl = ModSettingsRegistry.GetThunderstoreUrl(text, text2);
			return new ModUpdateCheckResult
			{
				Status = CompareVersion(currentVersion, text3).Status,
				LatestVersion = text3,
				ThunderstoreTeam = text,
				ThunderstoreModName = text2,
				ThunderstoreAuthor = text,
				ThunderstoreUrl = thunderstoreUrl
			};
		}

		private static List<string> GetNameKeys(string modName, string registeredName)
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			string[] array = new string[2] { modName, registeredName };
			foreach (string text in array)
			{
				if (string.IsNullOrWhiteSpace(text))
				{
					continue;
				}
				string text2 = Regex.Replace(text, "(?<=[a-z0-9])(?=[A-Z])", " ");
				string input = Regex.Replace(text2, "^v?\\d+(?:\\.\\d+)+(?:\\s*[-:]\\s*|\\s+)", string.Empty, RegexOptions.IgnoreCase);
				input = Regex.Replace(input, "^(?:Graveyard\\s*Keeper\\s*2|GK2)\\s*[-:]?\\s*", string.Empty, RegexOptions.IgnoreCase);
				input = Regex.Replace(input, "\\s*\\(\\s*v?\\d+(?:\\.\\d+)+\\s*\\)$", string.Empty, RegexOptions.IgnoreCase);
				string[] array2 = new string[3] { text, text2, input };
				for (int j = 0; j < array2.Length; j++)
				{
					string text3 = FoldName(array2[j]);
					if (!string.IsNullOrWhiteSpace(text3))
					{
						hashSet.Add(text3);
					}
				}
			}
			return hashSet.ToList();
		}

		private static int ScorePackage(IEnumerable<string> modKeys, string owner, string name, string fullName)
		{
			string text = FoldName(name);
			string text2 = FoldName(fullName);
			string text3 = FoldName((owner ?? string.Empty) + (name ?? string.Empty));
			int num = 0;
			foreach (string modKey in modKeys)
			{
				if (modKey == text)
				{
					num = Math.Max(num, 100);
				}
				if (modKey == text2)
				{
					num = Math.Max(num, 95);
				}
				if (modKey == text3)
				{
					num = Math.Max(num, 90);
				}
				if (modKey.Length >= 6 && text.Length > 0 && (modKey.EndsWith(text, StringComparison.Ordinal) || text.EndsWith(modKey, StringComparison.Ordinal)))
				{
					num = Math.Max(num, 70);
				}
			}
			return num;
		}

		private static async Task<ModUpdateCheckResult> CheckCoreAsync(string currentVersion, string manifestUrl)
		{
			_ = 2;
			try
			{
				if (!TryValidateHttpsUri(manifestUrl, out var uri))
				{
					return Failed();
				}
				using CancellationTokenSource cts = new CancellationTokenSource(Timeout);
				HttpResponseMessage response = await Client.GetAsync(uri, (HttpCompletionOption)1, cts.Token).ConfigureAwait(continueOnCapturedContext: false);
				try
				{
					if (response.StatusCode != HttpStatusCode.OK)
					{
						return Failed();
					}
					MediaTypeHeaderValue contentType = response.Content.Headers.ContentType;
					string text = ((contentType != null) ? contentType.MediaType : null);
					if (!string.IsNullOrWhiteSpace(text) && !text.Equals("application/json", StringComparison.OrdinalIgnoreCase) && !text.Equals("text/json", StringComparison.OrdinalIgnoreCase) && !text.Equals("text/plain", StringComparison.OrdinalIgnoreCase))
					{
						return Failed();
					}
					long? contentLength = response.Content.Headers.ContentLength;
					if (contentLength.HasValue && contentLength.Value > 16384)
					{
						return Failed();
					}
					using Stream stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(continueOnCapturedContext: false);
					return ParseManifest(await ReadLimitedStringAsync(stream, cts.Token).ConfigureAwait(continueOnCapturedContext: false), currentVersion);
				}
				finally
				{
					((IDisposable)response)?.Dispose();
				}
			}
			catch (OperationCanceledException)
			{
				return Failed();
			}
			catch (Exception ex2)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					log.LogWarning((object)("Update check failed: " + ex2.Message));
				}
				return Failed();
			}
		}

		private static ModUpdateCheckResult ParseManifest(string json, string currentVersion)
		{
			JObject root = JObject.Parse(json);
			string latestVersion = GetString(root, "version") ?? GetString(root, "latestVersion");
			return CompareVersion(currentVersion, latestVersion);
		}

		private static ModUpdateCheckResult CompareVersion(string currentVersion, string latestVersion)
		{
			if (string.IsNullOrWhiteSpace(latestVersion) || latestVersion.Length > 64)
			{
				return Failed();
			}
			bool flag = IsRemoteVersionNewer(currentVersion, latestVersion);
			return new ModUpdateCheckResult
			{
				Status = (flag ? ModUpdateCheckStatus.UpdateAvailable : ModUpdateCheckStatus.UpToDate),
				LatestVersion = latestVersion
			};
		}

		private static string GetString(JObject root, string propertyName)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			JToken val = root[propertyName];
			if (val == null || (int)val.Type != 8)
			{
				return null;
			}
			return Extensions.Value<string>((IEnumerable<JToken>)val);
		}

		private static async Task<string> ReadLimitedStringAsync(Stream stream, CancellationToken cancellationToken, int maxBytes = 16384)
		{
			using MemoryStream memory = new MemoryStream();
			byte[] buffer = new byte[1024];
			while (true)
			{
				int num = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
				if (num == 0)
				{
					break;
				}
				if (memory.Length + num > maxBytes)
				{
					throw new InvalidOperationException("Manifest too large.");
				}
				memory.Write(buffer, 0, num);
			}
			string text = Encoding.UTF8.GetString(memory.ToArray());
			return (text.Length > 0 && text[0] == '\ufeff') ? text.Substring(1) : text;
		}

		private static bool TryValidateHttpsUri(string url, out Uri uri)
		{
			uri = null;
			if (string.IsNullOrWhiteSpace(url) || url.Length > 2048 || !Uri.TryCreate(url, UriKind.Absolute, out uri))
			{
				return false;
			}
			if (!uri.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			if (uri.UserInfo.Length > 0 || uri.IsFile || uri.IsLoopback || uri.HostNameType == UriHostNameType.Unknown)
			{
				return false;
			}
			if ((uri.HostNameType == UriHostNameType.IPv4 || uri.HostNameType == UriHostNameType.IPv6) && IPAddress.TryParse(uri.DnsSafeHost, out IPAddress address) && IsUnsafeAddress(address))
			{
				return false;
			}
			return true;
		}

		private static bool IsUnsafeAddress(IPAddress address)
		{
			if (IPAddress.IsLoopback(address))
			{
				return true;
			}
			if (address.AddressFamily == AddressFamily.InterNetwork)
			{
				byte[] addressBytes = address.GetAddressBytes();
				if (addressBytes[0] != 10 && addressBytes[0] != 127 && addressBytes[0] != 0 && (addressBytes[0] != 169 || addressBytes[1] != 254) && (addressBytes[0] != 172 || addressBytes[1] < 16 || addressBytes[1] > 31))
				{
					if (addressBytes[0] == 192)
					{
						return addressBytes[1] == 168;
					}
					return false;
				}
				return true;
			}
			if (address.AddressFamily == AddressFamily.InterNetworkV6)
			{
				if (!address.IsIPv6LinkLocal && !address.IsIPv6SiteLocal && !address.IsIPv6Multicast && !address.Equals(IPAddress.IPv6None) && !address.Equals(IPAddress.IPv6Any))
				{
					return address.Equals(IPAddress.IPv6Loopback);
				}
				return true;
			}
			return true;
		}

		private static bool IsRemoteVersionNewer(string currentVersion, string latestVersion)
		{
			string suffix;
			int[] array = ReadVersion(currentVersion, out suffix);
			string suffix2;
			int[] array2 = ReadVersion(latestVersion, out suffix2);
			int num = Math.Max(array.Length, array2.Length);
			for (int i = 0; i < num; i++)
			{
				int num2 = ((i < array.Length) ? array[i] : 0);
				int num3 = ((i < array2.Length) ? array2[i] : 0);
				if (num3 > num2)
				{
					return true;
				}
				if (num3 < num2)
				{
					return false;
				}
			}
			if (suffix.Length == 0)
			{
				return false;
			}
			if (suffix2.Length == 0)
			{
				return true;
			}
			return CompareSuffix(suffix2, suffix) > 0;
		}

		private static int[] ReadVersion(string version, out string suffix)
		{
			suffix = string.Empty;
			if (string.IsNullOrWhiteSpace(version))
			{
				return Array.Empty<int>();
			}
			string text = version.Trim().TrimStart('v', 'V');
			int num = text.IndexOf('+');
			if (num >= 0)
			{
				text = text.Substring(0, num);
			}
			int num2 = text.IndexOf('-');
			if (num2 >= 0)
			{
				suffix = text.Substring(num2 + 1);
				text = text.Substring(0, num2);
			}
			int result;
			return (from part in text.Split(new char[2] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries)
				select int.TryParse(new string(part.TakeWhile(char.IsDigit).ToArray()), out result) ? result : 0).ToArray();
		}

		private static int CompareSuffix(string left, string right)
		{
			string[] array = left.Split(new char[1] { '.' });
			string[] array2 = right.Split(new char[1] { '.' });
			for (int i = 0; i < Math.Min(array.Length, array2.Length); i++)
			{
				long result;
				bool flag = long.TryParse(array[i], out result);
				long result2;
				bool flag2 = long.TryParse(array2[i], out result2);
				int num = ((flag && flag2) ? result.CompareTo(result2) : ((flag == flag2) ? string.Compare(array[i], array2[i], StringComparison.Ordinal) : ((!flag) ? 1 : (-1))));
				if (num != 0)
				{
					return num;
				}
			}
			return array.Length.CompareTo(array2.Length);
		}

		private static string FoldName(string name)
		{
			return new string((name ?? string.Empty).Where(char.IsLetterOrDigit).Select(char.ToLowerInvariant).ToArray());
		}

		private static ModUpdateCheckResult Failed()
		{
			return new ModUpdateCheckResult
			{
				Status = ModUpdateCheckStatus.Failed
			};
		}
	}
	internal enum ModUpdateCheckStatus
	{
		NotConfigured,
		Checking,
		UpToDate,
		UpdateAvailable,
		Failed
	}
	internal sealed class ModUpdateCheckResult
	{
		public ModUpdateCheckStatus Status { get; set; }

		public string LatestVersion { get; set; }

		public int? NexusModsId { get; set; }

		public string NexusAuthor { get; set; }

		public string NexusSummary { get; set; }

		public string ThunderstoreTeam { get; set; }

		public string ThunderstoreModName { get; set; }

		public string ThunderstoreAuthor { get; set; }

		public string ThunderstoreUrl { get; set; }

		public static ModUpdateCheckResult NotConfigured()
		{
			return new ModUpdateCheckResult
			{
				Status = ModUpdateCheckStatus.NotConfigured
			};
		}

		public static ModUpdateCheckResult Checking()
		{
			return new ModUpdateCheckResult
			{
				Status = ModUpdateCheckStatus.Checking
			};
		}
	}
}
namespace ModSettingsMenu.Runtime
{
	internal sealed class ConfigRows
	{
		private readonly Transform _content;

		private readonly GameObject _row;

		private readonly GameObject _heading;

		private readonly GameObject _divider;

		private readonly GameObject _dropdown;

		private readonly LazyButton _button;

		private readonly TMP_InputField _input;

		private VirtualKeyboard _keyboard;

		private OptionPicker _picker;

		private readonly KeybindEditor _keybindCapture;

		private readonly ModInfoRow _info;

		private bool _cancelInput;

		private readonly List<GameObject> _createdRows = new List<GameObject>();

		private readonly List<TMP_InputField> _inputs = new List<TMP_InputField>();

		private readonly Dictionary<TMP_InputField, UnityAction<string>> _commits = new Dictionary<TMP_InputField, UnityAction<string>>();

		private readonly Dictionary<GamepadNavigationItem, Action<int>> _changes = new Dictionary<GamepadNavigationItem, Action<int>>();

		private ConfigTextLocalization _localization;

		private static Sprite _searchIcon;

		public TMP_InputField Editing => ((IEnumerable<TMP_InputField>)_inputs).FirstOrDefault((Func<TMP_InputField, bool>)((TMP_InputField input) => (Object)(object)input != (Object)null && input.isFocused));

		public string Search { get; set; } = string.Empty;

		private float Width
		{
			get
			{
				//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_0015: Unknown result type (might be due to invalid IL or missing references)
				Rect rect = ((RectTransform)_content).rect;
				return Mathf.Max(1f, ((Rect)(ref rect)).width - 8f);
			}
		}

		public ConfigRows(Transform content, GameObject row, GameObject heading, GameObject divider, GameObject dropdown, KeybindEditor keybindCapture, ModInfoRow info, LazyButton button, TMP_InputField input)
		{
			_content = content;
			_row = row;
			_heading = heading;
			_divider = divider;
			_dropdown = dropdown;
			_keybindCapture = keybindCapture;
			_info = info;
			_button = button;
			_input = input;
		}

		public void SetKeyboard(VirtualKeyboard keyboard)
		{
			_keyboard = keyboard;
		}

		public void SetPicker(OptionPicker picker)
		{
			_picker = picker;
		}

		public TMP_InputField CreateSearch(Transform parent, UnityAction<string> changed)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009c: 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_0120: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Expected O, but got Unknown
			//IL_024c: 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_0270: 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)
			GameObject val = NativeUi.Clone(((Component)_input).gameObject, parent, "Search Settings");
			RectTransform obj = NativeUi.Rect("Search Icon", val.transform);
			obj.anchorMin = new Vector2(0f, 0.5f);
			obj.anchorMax = new Vector2(0f, 0.5f);
			obj.anchoredPosition = new Vector2(13f, 0f);
			obj.sizeDelta = new Vector2(14f, 14f);
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = GetSearchIcon();
			((Graphic)obj2).color = ((Graphic)_heading.GetComponent<TMP_Text>()).color;
			((Graphic)obj2).raycastTarget = false;
			TMP_InputField component = val.GetComponent<TMP_InputField>();
			TMP_Text textComponent = component.textComponent;
			TMP_Text component2 = _heading.GetComponent<TMP_Text>();
			component.textComponent = NativeUi.Label(component2, (Transform)(object)component.textViewport, "Text", string.Empty);
			Object.DestroyImmediate((Object)(object)((Component)textComponent).gameObject);
			NativeUi.Stretch(component.textViewport);
			component.textViewport.offsetMin = new Vector2(26f, 2f);
			component.textViewport.offsetMax = new Vector2(-8f, -2f);
			((Component)component.textViewport).GetComponent<RectMask2D>().padding = Vector4.zero;
			NativeUi.Stretch(component.textComponent.rectTransform);
			NativeUi.Align(component.textComponent, (TextAlignmentOptions)4097);
			component.textComponent.textWrappingMode = (TextWrappingModes)0;
			component.textComponent.margin = Vector4.zero;
			component.richText = false;
			component.fontAsset = component.textComponent.font;
			component.pointSize = component.textComponent.fontSize;
			component.contentType = (ContentType)0;
			component.lineType = (LineType)0;
			component.characterLimit = 0;
			component.onFocusSelectAll = false;
			component.customCaretColor = true;
			component.caretColor = ((Graphic)component2).color;
			component.onValidateInput = null;
			component.onValueChanged = new OnChangeEvent();
			component.onEndEdit = new SubmitEvent();
			component.onSubmit = new SubmitEvent();
			component.onSelect = new SelectionEvent();
			component.onDeselect = new SelectionEvent();
			((UnityEvent<string>)(object)component.onValueChanged).AddListener(changed);
			Image component3 = val.GetComponent<Image>();
			Image component4 = ((Component)_dropdown.transform.Find("Back")).GetComponent<Image>();
			component3.sprite = component4.sprite;
			((Graphic)component3).color = ((Graphic)component4).color;
			component3.type = component4.type;
			((Graphic)component3).material = ((Graphic)component4).material;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)component).navigation = navigation;
			if ((Object)(object)component.placeholder != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)component.placeholder).gameObject);
			}
			TMP_Text val2 = NativeUi.Label(component2, (Transform)(object)component.textViewport, "Placeholder", string.Empty);
			NativeUi.Stretch(val2.rectTransform);
			NativeUi.Align(val2, (TextAlignmentOptions)4097);
			val2.textWrappingMode = (TextWrappingModes)0;
			val2.overflowMode = (TextOverflowModes)1;
			component.placeholder = (Graphic)(object)val2;
			component.SetTextWithoutNotify(string.Empty);
			val.SetActive(true);
			return component;
		}

		private static Sprite GetSearchIcon()
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_00eb: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_searchIcon != (Object)null)
			{
				return _searchIcon;
			}
			string[] array = new string[16]
			{
				"................", "....#####.......", "..##.....##.....", "..#.......#.....", ".#.........#....", ".#.........#....", ".#.........#....", ".#.........#....", "..#.......#.....", "..##.....##.....",
				"....#####.##....", "..........###...", "...........###..", "............###.", ".............##.", "................"
			};
			Color32[] array2 = (Color32[])(object)new Color32[256];
			for (int i = 0; i < 16; i++)
			{
				for (int j = 0; j < 16; j++)
				{
					array2[(15 - i) * 16 + j] = ((array[i][j] == '#') ? new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue) : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
				}
			}
			Texture2D val = new Texture2D(16, 16, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1
			};
			val.SetPixels32(array2);
			val.Apply(false, true);
			_searchIcon = Sprite.Create(val, new Rect(0f, 0f, 16f, 16f), new Vector2(0.5f, 0.5f));
			return _searchIcon;
		}

		public void Update()
		{
			_info?.Update();
		}

		public void Build(ModConfig mod)
		{
			ClearRows();
			_localization = null;
			try
			{
				_localization = ConfigTextLocalizations.Get(mod);
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					object obj;
					if (mod == null)
					{
						obj = null;
					}
					else
					{
						PluginInfo info = mod.Info;
						if (info == null)
						{
							obj = null;
						}
						else
						{
							BepInPlugin metadata = info.Metadata;
							obj = ((metadata != null) ? metadata.GUID : null);
						}
					}
					log.LogWarning((object)("Settings localization unavailable for " + (string?)obj + ": " + ex.Message));
				}
			}
			if (mod == null)
			{
				TryCreateHeading(I18n.Text("menu.no_configurable_mods"));
			}
			else
			{
				try
				{
					GameObject val = _info?.Create(mod);
					if ((Object)(object)val != (Object)null)
					{
						CompleteRow(val);
					}
				}
				catch (Exception ex2)
				{
					ManualLogSource log2 = ModSettingsMenu.Log;
					if (log2 != null)
					{
						log2.LogWarning((object)("Settings metadata unavailable for " + mod.Info.Metadata.GUID + ": " + ex2.Message));
					}
				}
				List<ConfigEntryBase> entries = GetEntries(mod);
				List<ConfigEntryBase> list = new List<ConfigEntryBase>();
				foreach (ConfigEntryBase item in entries)
				{
					try
					{
						if (Matches(mod, item))
						{
							list.Add(item);
						}
					}
					catch (Exception ex3)
					{
						ManualLogSource log3 = ModSettingsMenu.Log;
						if (log3 != null)
						{
							log3.LogWarning((object)$"Settings search skipped {mod.Info.Metadata.GUID}:{item.Definition}: {ex3.Message}");
						}
					}
				}
				if (list.Count == 0 && !string.IsNullOrWhiteSpace(Search))
				{
					TryCreateHeading(I18n.Text("menu.no_search_results"));
				}
				string a = null;
				foreach (ConfigEntryBase item2 in list)
				{
					try
					{
						if (!string.Equals(a, item2.Definition.Section, StringComparison.OrdinalIgnoreCase))
						{
							string section = item2.Definition.Section;
							CreateHeading(SplitName(_localization?.GetSection(section) ?? LocalizationApi.GetConfigSection(section, mod.ConfigFile)));
							a = section;
						}
						CreateEntryRow(mod, item2);
					}
					catch (Exception ex4)
					{
						ManualLogSource log4 = ModSettingsMenu.Log;
						if (log4 != null)
						{
							log4.LogWarning((object)$"Settings row skipped {mod.Info.Metadata.GUID}:{item2.Definition}: {ex4.Message}");
						}
					}
				}
			}
			try
			{
				LayoutRebuild();
			}
			catch (Exception arg)
			{
				ManualLogSource log5 = ModSettingsMenu.Log;
				if (log5 != null)
				{
					log5.LogError((object)$"Failed to lay out settings: {arg}");
				}
			}
		}

		private static List<ConfigEntryBase> GetEntries(ModConfig mod)
		{
			try
			{
				return (from entry in mod.ConfigFile.GetConfigEntries()
					orderby ModSettingsOrder.GetSectionOrder(mod, entry.Definition.Section)
					select entry).ThenBy<ConfigEntryBase, string>((ConfigEntryBase entry) => entry.Definition.Section, StringComparer.OrdinalIgnoreCase).ThenBy((ConfigEntryBase entry) => ModSettingsOrder.GetEntryOrder(mod, entry)).ThenBy<ConfigEntryBase, string>((ConfigEntryBase entry) => entry.Definition.Key, StringComparer.OrdinalIgnoreCase)
					.ToList();
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					log.LogWarning((object)("Settings order unavailable for " + mod.Info.Metadata.GUID + "; using config order: " + ex.Message));
				}
				try
				{
					return mod.ConfigFile.GetConfigEntries().ToList();
				}
				catch (Exception arg)
				{
					ManualLogSource log2 = ModSettingsMenu.Log;
					if (log2 != null)
					{
						log2.LogError((object)$"Failed to read settings for {mod.Info.Metadata.GUID}: {arg}");
					}
					return new List<ConfigEntryBase>();
				}
			}
		}

		private void TryCreateHeading(string text)
		{
			try
			{
				CreateHeading(text);
			}
			catch (Exception ex)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					log.LogWarning((object)("Settings heading skipped: " + ex.Message));
				}
			}
		}

		private bool Matches(ModConfig mod, ConfigEntryBase entry)
		{
			string query = Search.Trim().Normalize(NormalizationForm.FormKC);
			if (query.Length == 0)
			{
				return true;
			}
			List<string> list = new List<string>
			{
				entry.Definition.Key,
				SplitName(entry.Definition.Key),
				entry.Definition.Section,
				entry.Description.Description,
				GetSettingText(entry),
				LocalizationApi.GetConfigDisplayName(entry),
				LocalizationApi.GetConfigDescription(entry),
				LocalizationApi.GetConfigSection(entry.Definition.Section, mod.ConfigFile)
			};
			if (_localization != null)
			{
				list.AddRange(_localization.GetSearchText(entry));
			}
			return list.Any((string text) => !string.IsNullOrWhiteSpace(text) && CultureInfo.InvariantCulture.CompareInfo.IndexOf(text.Normalize(NormalizationForm.FormKC), query, CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0);
		}

		public void Reset(ModConfig mod)
		{
			if (mod == null)
			{
				return;
			}
			TMP_InputField editing = Editing;
			if ((Object)(object)editing != (Object)null)
			{
				_cancelInput = true;
				try
				{
					editing.DeactivateInputField(false);
				}
				finally
				{
					_cancelInput = false;
				}
			}
			ConfigEntryBase[] configEntries = mod.ConfigFile.GetConfigEntries();
			foreach (ConfigEntryBase obj in configEntries)
			{
				ConfigValues.TrySetValue(obj, obj.DefaultValue);
			}
			Build(mod);
		}

		public bool Adjust(GamepadNavigationItem item, int direction)
		{
			if ((Object)(object)item == (Object)null || !_changes.TryGetValue(item, out var value))
			{
				return false;
			}
			value(direction);
			return true;
		}

		private void ClearRows()
		{
			_keybindCapture.Cancel();
			foreach (GameObject createdRow in _createdRows)
			{
				if ((Object)(object)createdRow != (Object)null)
				{
					createdRow.SetActive(false);
					Object.Destroy((Object)(object)createdRow);
				}
			}
			_createdRows.Clear();
			_changes.Clear();
			_inputs.Clear();
			_commits.Clear();
		}

		private void CreateHeading(string text)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = NativeUi.Clone(_heading, _content, "Mod Settings Section - " + text);
			TMP_Text component = val.GetComponent<TMP_Text>();
			component.text = text;
			component.textWrappingMode = (TextWrappingModes)1;
			NativeUi.Align(component, (TextAlignmentOptions)257);
			float y = component.GetPreferredValues(text, Width - 8f, 0f).y;
			component.margin = new Vector4(4f, 10f, 0f, 10f);
			NativeUi.Height(val, y + 24f);
			GameObject obj = NativeUi.CloneDivider(_divider, val.transform, "Section Divider");
			RectTransform val2 = (RectTransform)obj.transform;
			val2.anchorMin = new Vector2(0f, 0f);
			val2.anchorMax = new Vector2(1f, 0f);
			val2.offsetMin = new Vector2(4f, 1f);
			val2.offsetMax = new Vector2(-4f, 2.5f);
			Image component2 = obj.GetComponent<Image>();
			component2.sprite = null;
			((Graphic)component2).material = null;
			component2.type = (Type)0;
			Color color = ((Graphic)component).color;
			color.a = 0.55f;
			((Graphic)component2).color = color;
			CompleteRow(val);
		}

		private void CreateEntryRow(ModConfig mod, ConfigEntryBase entry)
		{
			Type settingType = entry.SettingType;
			ConfigDescription description = entry.Description;
			AcceptableValueBase acceptable = ((description != null) ? description.AcceptableValues : null);
			IReadOnlyList<object> values;
			float min;
			float max;
			if (settingType == typeof(bool))
			{
				CreateBoolRow(entry);
			}
			else if (settingType == typeof(KeyCode) || settingType == typeof(KeyboardShortcut))
			{
				CreateKeybindRow(entry);
			}
			else if (settingType.IsEnum)
			{
				CreateDropdownRow(entry, Enum.GetValues(settingType).Cast<object>().ToList());
			}
			else if (ConfigValues.TryGetAcceptableValues(acceptable, out values))
			{
				CreateDropdownRow(entry, values);
			}
			else if (ConfigValues.IsSliderType(settingType) && TryGetSliderRange(acceptable, entry.DefaultValue, settingType, out min, out max))
			{
				CreateSliderRow(mod, entry, min, max);
			}
			else
			{
				CreateInputRow(entry);
			}
		}

		private static bool TryGetSliderRange(AcceptableValueBase acceptable, object defaultValue, Type type, out float min, out float max)
		{
			if (ConfigValues.TryGetNumericRange(acceptable, out min, out max))
			{
				return true;
			}
			double num = Convert.ToDouble(defaultValue, CultureInfo.InvariantCulture);
			if (double.IsNaN(num) || double.IsInfinity(num))
			{
				return false;
			}
			double num2 = Math.Max(1.0, Math.Abs(num) * 1000.0);
			if (ConfigValues.IsIntegralType(type))
			{
				num2 = Math.Max(1.0, Math.Floor(num2));
			}
			num2 = Math.Min(3.4028234663852886E+38, num2);
			if (type == typeof(byte))
			{
				num2 = Math.Min(255.0, num2);
			}
			else if (type == typeof(sbyte))
			{
				num2 = Math.Min(127.0, num2);
			}
			else if (type == typeof(short))
			{
				num2 = Math.Min(32767.0, num2);
			}
			else if (type == typeof(ushort))
			{
				num2 = Math.Min(65535.0, num2);
			}
			else if (type == typeof(int))
			{
				num2 = Math.Min(2147483647.0, num2);
			}
			else if (type == typeof(uint))
			{
				num2 = Math.Min(4294967295.0, num2);
			}
			else if (type == typeof(long))
			{
				num2 = Math.Min(9.223372036854776E+18, num2);
			}
			else if (type == typeof(ulong))
			{
				num2 = Math.Min(1.8446744073709552E+19, num2);
			}
			min = 0f;
			max = (float)num2;
			if (!float.IsInfinity(max))
			{
				return min < max;
			}
			return false;
		}

		private void CreateBoolRow(ConfigEntryBase entry)
		{
			CreateSwitchRow(entry, _dropdown, new object[2] { false, true }, (object value) => _localization?.GetValue(entry, value) ?? I18n.Text(((bool)value) ? "menu.on" : "menu.off"));
		}

		private void CreateDropdownRow(ConfigEntryBase entry, IReadOnlyList<object> values)
		{
			//IL_007e: 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_00a3: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Expected O, but got Unknown
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: 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_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Expected O, but got Unknown
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Expected O, but got Unknown
			if (values.Count <= 5)
			{
				CreateSwitchRow(entry, _dropdown, values, (object value) => GetConfigValueText(entry, value));
				return;
			}
			GameObject val = NewRow(_dropdown, entry);
			Transform obj = val.transform.Find("Control");
			Transform val2 = obj.Find("Back");
			NativeUi.Bottom((RectTransform)val2, 0f, 1f, 1f, 24f);
			RectTransform val3 = (RectTransform)val2;
			val3.offsetMax -= new Vector2(8f, 0f);
			Image component = ((Component)val2).GetComponent<Image>();
			((Graphic)component).raycastTarget = true;
			Button button = ((Component)val2).gameObject.AddComponent<Button>();
			((Selectable)button).targetGraphic = (Graphic)(object)component;
			ColorBlock defaultColorBlock = ColorBlock.defaultColorBlock;
			((ColorBlock)(ref defaultColorBlock)).highlightedColor = new Color(1.15f, 1.15f, 1.15f, 1f);
			((ColorBlock)(ref defaultColorBlock)).fadeDuration = 0f;
			((Selectable)button).colors = defaultColorBlock;
			TMP_Text label = ((Component)val2.Find("Value")).GetComponent<TMP_Text>();
			label.text = GetConfigValueText(entry, entry.BoxedValue);
			label.textWrappingMode = (TextWrappingModes)0;
			label.overflowMode = (TextOverflowModes)1;
			NativeUi.Align(label, (TextAlignmentOptions)4098);
			NativeUi.Stretch(label.rectTransform);
			label.rectTransform.offsetMin = new Vector2(28f, 2f);
			label.rectTransform.offsetMax = new Vector2(-28f, -2f);
			((Component)obj.Find("ToRight")).gameObject.SetActive(false);
			Transform val4 = obj.Find("ToLeft");
			RectTransform val5 = (RectTransform)val4.Find("BtnBack/Icon");
			GameObject obj2 = NativeUi.CloneDivider(((Component)val5).gameObject, val2, "Dropdown Arrow");
			((Component)val4).gameObject.SetActive(false);
			RectTransform val6 = (RectTransform)obj2.transform;
			val6.anchorMin = new Vector2(1f, 0.5f);
			val6.anchorMax = new Vector2(1f, 0.5f);
			val6.pivot = new Vector2(0.5f, 0.5f);
			val6.anchoredPosition = new Vector2(-14f, 0f);
			val6.sizeDelta = val5.sizeDelta;
			((Transform)val6).localRotation = Quaternion.Euler(0f, 0f, 90f);
			obj2.SetActive(true);
			NativeUi.Bind(button, (UnityAction)delegate
			{
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Expected O, but got Unknown
				int selected = values.ToList().FindIndex((object value) => object.Equals(value, entry.BoxedValue));
				_picker.Show((RectTransform)((Component)button).transform, values.Select((object value) => GetConfigValueText(entry, value)).ToList(), selected, delegate(int index)
				{
					ConfigValues.TrySetValue(entry, values[index]);
					label.text = GetConfigValueText(entry, entry.BoxedValue);
				});
			});
			((Component)button).gameObject.SetActive(true);
			SetupItem(val, entry, (UnityAction)delegate
			{
				((UnityEvent)button.onClick).Invoke();
			});
		}

		private void CreateSwitchRow(ConfigEntryBase entry, GameObject source, IReadOnlyList<object> values, Func<object, string> format)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_009c: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00b7: 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_00c2: 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_00d6: 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_00f1: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			GameObject val = NewRow(source, entry);
			Transform obj = val.transform.Find("Control");
			Transform val2 = obj.Find("Back");
			TMP_Text label = ((Component)val2.Find("Value")).GetComponent<TMP_Text>();
			Button component = ((Component)obj.Find("ToLeft")).GetComponent<Button>();
			Button component2 = ((Component)obj.Find("ToRight")).GetComponent<Button>();
			NativeUi.Bottom((RectTransform)val2, 0f, 1f, 1f, 24f);
			RectTransform val3 = (RectTransform)val2;
			val3.offsetMin += new Vector2(28f, 0f);
			val3.offsetMax -= new Vector2(28f, 0f);
			PlaceEdge((RectTransform)((Component)component).transform, right: false);
			PlaceEdge((RectTransform)((Component)component2).transform, right: true);
			label.textWrappingMode = (TextWrappingModes)0;
			label.overflowMode = (TextOverflowModes)1;
			Action<int> change = delegate(int direction)
			{
				int num = 0;
				for (int i = 0; i < values.Count; i++)
				{
					if (object.Equals(values[i], entry.BoxedValue))
					{
						num = i;
						break;
					}
				}
				if (values.Count > 0)
				{
					num = (num + direction + values.Count) % values.Count;
					ConfigValues.TrySetValue(entry, values[num]);
				}
				label.text = format(entry.BoxedValue);
			};
			label.text = format(entry.BoxedValue);
			((Selectable)component).interactable = values.Count > 1;
			((Selectable)component2).interactable = values.Count > 1;
			NativeUi.Bind(component, (UnityAction)delegate
			{
				change(-1);
			});
			NativeUi.Bind(component2, (UnityAction)delegate
			{
				change(1);
			});
			GamepadNavigationItem key = SetupItem(val, entry, null);
			_changes[key] = change;
		}

		private void CreateKeybindRow(ConfigEntryBase entry)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			GameObject val = NewRow(_row, entry);
			HideValues(val);
			LazyButton button = NativeUi.CloneButton(_button, val.transform.Find("Control"), "Keybind");
			NativeUi.Bottom((RectTransform)((Component)button).transform, 0f, 1f, 0f, 26f);
			TMP_Text text = NativeUi.FitButton(button);
			MenuFonts.Attach(text).Limit(14f);
			text.textWrappingMode = (TextWrappingModes)0;
			text.overflowMode = (TextOverflowModes)1;
			NativeUi.SetText(((Component)button).gameObject, KeybindCapture.FormatKeyCode(entry.BoxedValue));
			((Component)button).gameObject.SetActive(true);
			NativeUi.Bind((Button)(object)button, (UnityAction)delegate
			{
				_keybindCapture.Begin(entry, (Button)(object)button, text);
			});
			SetupItem(val, entry, (UnityAction)delegate
			{
				((UnityEvent)((Button)button).onClick).Invoke();
			});
		}

		private void CreateSliderRow(ModConfig mod, ConfigEntryBase entry, float min, float max)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_0240: 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_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Expected O, but got Unknown
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Expected O, but got Unknown
			GameObject val = NewRow(_row, entry);
			Transform val2 = val.transform.Find("Control");
			Slider slider = val.GetComponentInChildren<Slider>(true);
			Button component = ((Component)val2.Find("Minus")).GetComponent<Button>();
			Button component2 = ((Component)val2.Find("Plus")).GetComponent<Button>();
			NativeUi.Bottom((RectTransform)((Component)slider).transform, 0f, 1f, 4f, 18f);
			RectTransform val3 = (RectTransform)((Component)slider).transform;
			val3.offsetMin += new Vector2(28f, 0f);
			RectTransform val4 = (RectTransform)((Component)slider).transform;
			val4.offsetMax -= new Vector2(108f, 0f);
			((Component)val2.Find("Value")).gameObject.SetActive(false);
			PlaceEdge((RectTransform)((Component)component).transform, right: false);
			PlaceEdge((RectTransform)((Component)component2).transform, right: true);
			double step = ConfigValues.GetSliderStep(configuredStep: ModSettingsMetadata.GetSliderStep(mod, entry), min: min, max: max, targetType: entry.SettingType);
			TMP_InputField valueInput = CreateInput(val2, ((Component)val2.Find("Value")).GetComponent<TMP_Text>(), entry, numeric: true, delegate(string value)
			{
				ConfigValues.TrySetNumber(entry, value, min, max);
			}, (UnityAction)delegate
			{
				float valueWithoutNotify2 = ConfigValues.SnapSliderValue(Convert.ToSingle(entry.BoxedValue, CultureInfo.InvariantCulture), min, max, entry.SettingType, step);
				slider.SetValueWithoutNotify(valueWithoutNotify2);
			});
			float valueWithoutNotify = ConfigValues.SnapSliderValue(Convert.ToSingle(entry.BoxedValue, CultureInfo.InvariantCulture), min, max, entry.SettingType, step);
			slider.onValueChanged = new SliderEvent();
			slider.minValue = min;
			slider.maxValue = max;
			slider.wholeNumbers = ConfigValues.IsIntegralType(entry.SettingType);
			slider.SetValueWithoutNotify(valueWithoutNotify);
			Navigation navigation = ((Selectable)slider).navigation;
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)slider).navigation = navigation;
			((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate(float sliderValue)
			{
				object value = ConfigValues.ConvertSliderValue(ConfigValues.SnapSliderValue(sliderValue, min, max, entry.SettingType, step), entry.SettingType);
				ConfigValues.TrySetValue(entry, value);
				slider.SetValueWithoutNotify(Convert.ToSingle(entry.BoxedValue, CultureInfo.InvariantCulture));
				valueInput.SetTextWithoutNotify(ConfigValues.FormatValue(entry.BoxedValue));
				UISliderClickSound.Play();
			});
			valueInput.SetTextWithoutNotify(ConfigValues.FormatValue(entry.BoxedValue));
			Action<int> change = delegate(int direction)
			{
				if (ConfigValues.StepNumber(entry, direction, min, max, step))
				{
					slider.SetValueWithoutNotify(Convert.ToSingle(entry.BoxedValue, CultureInfo.InvariantCulture));
					valueInput.SetTextWithoutNotify(ConfigValues.FormatValue(entry.BoxedValue));
					UISliderClickSound.Play();
				}
			};
			NativeUi.Bind(component, (UnityAction)delegate
			{
				change(-1);
			});
			NativeUi.Bind(component2, (UnityAction)delegate
			{
				change(1);
			});
			GamepadNavigationItem key = SetupItem(val, entry, (UnityAction)delegate
			{
				if (LazyInput.IsGamepadActive && _keyboard != null)
				{
					_keyboard.Show(valueInput.text, numeric: true, delegate(string value)
					{
						_commits[valueInput].Invoke(value);
						_keyboard.Hide();
					}, _keyboard.Hide);
				}
				else
				{
					((Selectable)valueInput).Select();
					valueInput.ActivateInputField();
				}
			});
			_changes[key] = change;
		}

		private TMP_InputField CreateInput(Transform parent, TMP_Text source, ConfigEntryBase entry, bool numeric, UnityAction<string> apply = null, UnityAction refresh = null)
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Expected O, but got Unknown
			//IL_009a: 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_00b9: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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_01f6: 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_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: 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)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Expected O, but got Unknown
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Expected O, but got Unknown
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Expected O, but got Unknown
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Expected O, but got Unknown
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Expected O, but got Unknown
			GameObject val = NativeUi.Clone(((Component)_input).gameObject, parent, "Value Input");
			val.SetActive(false);
			TMP_InputField input = val.GetComponent<TMP_InputField>();
			TMP_Text textComponent = input.textComponent;
			TMP_Text textComponent2 = NativeUi.Label(source, (Transform)(object)input.textViewport, "Text", string.Empty);
			input.textComponent = textComponent2;
			Object.DestroyImmediate((Object)(object)((Component)textComponent).gameObject);
			if (numeric)
			{
				RectTransform val2 = (RectTransform)((Component)input).transform;
				NativeUi.Bottom(val2, 1f, 1f, 1f, 24f);
				val2.pivot = new Vector2(1f, 0f);
				val2.offsetMin = new Vector2(-92f, 1f);
				val2.offsetMax = new Vector2(-28f, 25f);
			}
			else
			{
				NativeUi.Bottom((RectTransform)((Component)input).transform, 0f, 1f, 0f, 26f);
			}
			float num = (numeric ? 2f : 8f);
			NativeUi.Stretch(input.textViewport);
			input.textViewport.offsetMin = new Vector2(num, 2f);
			input.textViewport.offsetMax = new Vector2(0f - num, -2f);
			((Component)input.textViewport).GetComponent<RectMask2D>().padding = Vector4.zero;
			NativeUi.Stretch(input.textComponent.rectTransform);
			NativeUi.Align(input.textComponent, (TextAlignmentOptions)(numeric ? 4098 : 4097));
			input.textComponent.textWrappingMode = (TextWrappingModes)0;
			input.textComponent.enableAutoSizing = false;
			input.textComponent.margin = Vector4.zero;
			input.richText = false;
			Image component = val.GetComponent<Image>();
			Image component2 = ((Component)_dropdown.transform.Find("Back")).GetComponent<Image>();
			component.sprite = component2.sprite;
			component.type = component2.type;
			((Graphic)component).color = ((Graphic)component2).color;
			((Graphic)component).material = ((Graphic)component2).material;
			input.fontAsset = input.textComponent.font;
			input.pointSize = input.textComponent.fontSize;
			input.customCaretColor = true;
			input.caretColor = ((Graphic)input.textComponent).color;
			input.contentType = (ContentType)0;
			input.characterValidation = (CharacterValidation)0;
			input.lineType = (LineType)0;
			input.characterLimit = 0;
			input.onFocusSelectAll = false;
			Graphic placeholder = input.placeholder;
			TMP_Text val3 = (TMP_Text)(object)((placeholder is TMP_Text) ? placeholder : null);
			if (val3 != null)
			{
				val3.text = string.Empty;
			}
			Navigation navigation = ((Selectable)input).navigation;
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)input).navigation = navigation;
			input.onValidateInput = null;
			input.onValueChanged = new OnChangeEvent();
			input.onEndEdit = new SubmitEvent();
			input.onSubmit = new SubmitEvent();
			input.onSelect = new SelectionEvent();
			input.onDeselect = new SelectionEvent();
			UnityAction<string> commit = delegate(string value)
			{
				if (apply != null)
				{
					apply.Invoke(value);
				}
				else if (entry.SettingType == typeof(string))
				{
					ConfigValues.TrySetValue(entry, value);
				}
				else
				{
					ConfigValues.TrySetSerializedValue(entry, value);
				}
				input.SetTextWithoutNotify(GetInputText(entry));
				UnityAction obj = refresh;
				if (obj != null)
				{
					obj.Invoke();
				}
			};
			_commits[input] = commit;
			((UnityEvent<string>)(object)input.onEndEdit).AddListener((UnityAction<string>)delegate(string value)
			{
				if (!_cancelInput && !input.wasCanceled)
				{
					commit.Invoke(value);
				}
				else
				{
					input.SetTextWithoutNotify(GetInputText(entry));
				}
			});
			input.text = GetInputText(entry);
			val.SetActive(true);
			_inputs.Add(input);
			return input;
		}

		private void CreateInputRow(ConfigEntryBase entry)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			GameObject val = NewRow(_row, entry);
			HideValues(val);
			TMP_InputField input = CreateInput(val.transform.Find("Control"), _heading.GetComponent<TMP_Text>(), entry, numeric: false);
			SetupItem(val, entry, (UnityAction)delegate
			{
				if (LazyInput.IsGamepadActive && _keyboard != null)
				{
					_keyboard.Show(input.text, numeric: false, delegate(string value)
					{
						_commits[input].Invoke(value);
						_keyboard.Hide();
					}, _keyboard.Hide);
				}
				else
				{
					((Selectable)input).Select();
					input.ActivateInputField();
				}
			});
		}

		private static string GetInputText(ConfigEntryBase entry)
		{
			if (!(entry.SettingType == typeof(string)))
			{
				return entry.GetSerializedValue();
			}
			return (string)entry.BoxedValue;
		}

		private GameObject NewRow(GameObject source, ConfigEntryBase entry)
		{
			//IL_0128: 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_01bf: 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_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = NativeUi.Clone(source, _content, "Mod Setting - " + entry.Definition.Key);
			CompleteRow(val);
			UIMouseTooltip[] componentsInChildren = val.GetComponentsInChildren<UIMouseTooltip>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			TMP_Text title = NativeUi.SetRowTitle(val, GetSettingText(entry));
			RectTransform val2 = NativeUi.Rect("Control", val.transform);
			for (int num = val.transform.childCount - 1; num >= 0; num--)
			{
				Transform child = val.transform.GetChild(num);
				if ((Object)(object)child != (Object)(object)val2 && (Object)(object)child != (Object)(object)title.transform && ((Object)child).name != "GamepadRect")
				{
					child.SetParent((Transform)(object)val2, false);
				}
			}
			bool flag = Width < 340f;
			float num2 = (flag ? Width : (Width * 0.42f - 8f));
			float num3 = Mathf.Max(18f, title.GetPreferredValues(title.text, num2, 0f).y);
			float num4 = (flag ? (num3 + 32f) : Mathf.Max(30f, num3 + 4f));
			NativeUi.Height(val, num4);
			NativeUi.Place(title.rectTransform, 0f, flag ? 1f : 0.42f, flag ? 30f : 0f, 0f);
			RectTransform rectTransform = title.rectTransform;
			rectTransform.offsetMax += new Vector2(flag ? 0f : (-8f), 0f);
			NativeUi.Align(title, (TextAlignmentOptions)(flag ? 257 : 4097));
			NativeUi.Bottom(val2, flag ? 0f : 0.44f, 1f, flag ? 0f : ((num4 - 26f) * 0.5f), 26f);
			string description = _localization?.GetDescription(entry) ?? LocalizationApi.GetConfigDescription(entry);
			if (!string.IsNullOrWhiteSpace(description))
			{
				UIMouseTooltip.AttachCustom(((Component)title).gameObject, (Action)delegate
				{
					MenuFonts.ShowTooltip((Transform)(object)title.rectTransform, description, title.text);
				}, true, false, default(UIMouseTooltipEdges), default(Vector2));
			}
			return val;
		}

		private static void HideValues(GameObject row)
		{
			Transform obj = row.transform.Find("Control");
			((Component)obj.Find("Slider")).gameObject.SetActive(false);
			((Component)obj.Find("Value")).gameObject.SetActive(false);
			((Component)obj.Find("Minus")).gameObject.SetActive(false);
			((Component)obj.Find("Plus")).gameObject.SetActive(false);
		}

		private static void PlaceEdge(RectTransform rect, bool right)
		{
			//IL_0017: 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_003d: 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: Unknown result type (might be due to invalid IL or missing references)
			float num = (right ? 1f : 0f);
			rect.anchorMin = new Vector2(num, 0f);
			rect.anchorMax = new Vector2(num, 0f);
			rect.pivot = new Vector2(0.5f, 0.5f);
			rect.anchoredPosition = new Vector2(right ? (-12.5f) : 12.5f, 13f);
			rect.sizeDelta = new Vector2(25f, 26f);
		}

		private GamepadNavigationItem SetupItem(GameObject row, ConfigEntryBase entry, UnityAction select)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00c5: Expected O, but got Unknown
			//IL_00c5: Expected O, but got Unknown
			GamepadNavigationItem component = row.GetComponent<GamepadNavigationItem>();
			GamepadNavigationItem[] componentsInChildren = row.GetComponentsInChildren<GamepadNavigationItem>(true);
			foreach (GamepadNavigationItem obj in componentsInChildren)
			{
				obj.Active = (Object)(object)obj == (Object)(object)component;
			}
			component.group = 2;
			component.ignoreScroll = true;
			component.FocusRectTransform = (RectTransform)row.transform;
			component.ResetCustomDirections();
			TMP_Text title = ((Component)row.transform.Find("LeftName")).GetComponent<TMP_Text>();
			FontStyles style = title.fontStyle;
			string description = _localization?.GetDescription(entry) ?? LocalizationApi.GetConfigDescription(entry);
			component.SetCallbacks((UnityAction)delegate
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (!LazyInput.IsGamepadActive)
				{
					title.fontStyle = (FontStyles)(style | 4);
				}
				else if (!string.IsNullOrWhiteSpace(description))
				{
					MenuFonts.ShowTooltip((Transform)(object)title.rectTransform, description, title.text);
				}
			}, (UnityAction)delegate
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				title.fontStyle = style;
				UIMouseTooltip.HideIfShowingAt(title.rectTransform, false);
			}, select);
			return component;
		}

		private void CompleteRow(GameObject row)
		{
			row.SetActive(true);
			_createdRows.Add(row);
		}

		private void LayoutRebuild()
		{
			RectTransform component = ((Component)_content).GetComponent<RectTransform>();
			LayoutRebuilder.ForceRebuildLayoutImmediate(component);
			_info?.Repair();
			LayoutRebuilder.ForceRebuildLayoutImmediate(component);
			ScrollRect componentInParent = ((Component)_content).GetComponentInParent<ScrollRect>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.verticalNormalizedPosition = 1f;
			}
		}

		private string GetSettingText(ConfigEntryBase entry)
		{
			return SplitName(_localization?.GetName(entry) ?? LocalizationApi.GetConfigDisplayName(entry));
		}

		private string GetConfigValueText(ConfigEntryBase entry, object value)
		{
			string text = _localization?.GetValue(entry, value);
			if (!string.IsNullOrWhiteSpace(text))
			{
				return text;
			}
			string result = default(string);
			if (!LocalizationApi.TryGetConfigDisplayValue(entry, value, ref result))
			{
				return ConfigValues.FormatValue(value);
			}
			return result;
		}

		private static string SplitName(string text)
		{
			if (string.IsNullOrWhiteSpace(text))
			{
				return text;
			}
			StringBuilder stringBuilder = new StringBuilder(text.Length + 8);
			for (int i = 0; i < text.Length; i++)
			{
				char c = text[i];
				if (c == '_')
				{
					if (stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] != ' ')
					{
						stringBuilder.Append(' ');
					}
					continue;
				}
				bool flag = i > 0 && !char.IsWhiteSpace(text[i - 1]);
				if (char.IsUpper(c) && flag && (char.IsLower(text[i - 1]) || (i + 1 < text.Length && char.IsLower(text[i + 1]))) && stringBuilder.Length > 0 && stringBuilder[stringBuilder.Length - 1] != ' ')
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append(c);
			}
			return stringBuilder.ToString().Trim();
		}
	}
	internal sealed class KeybindCapture
	{
		private ConfigEntryBase _entry;

		private TMP_Text _buttonText;

		private int _startFrame;

		public bool IsActive => _entry != null;

		public void Begin(ConfigEntryBase entry, Button button, TMP_Text buttonText)
		{
			_entry = entry;
			_buttonText = buttonText;
			_startFrame = Time.frameCount;
			_buttonText.text = I18n.Text("menu.press_a_key");
			NativeUi.SelectObject(((Component)button).gameObject);
		}

		public void CaptureInput()
		{
			//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_0031: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (Time.frameCount <= _startFrame)
			{
				return;
			}
			foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
			{
				if ((int)value != 0 && Input.GetKeyDown(value))
				{
					if ((int)value == 27)
					{
						Finish(save: false, (KeyCode)0);
					}
					else
					{
						Finish(save: true, value);
					}
					break;
				}
			}
		}

		public void Cancel()
		{
			if (IsActive)
			{
				Finish(save: false, (KeyCode)0);
			}
		}

		public unsafe static string FormatKeyCode(object value)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!(value is KeyCode val))
			{
				return ConfigValues.FormatValue(value);
			}
			return ((object)(*(KeyCode*)(&val))/*cast due to .constrained prefix*/).ToString();
		}

		private void Finish(bool save, KeyCode keyCode)
		{
			//IL_0045: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (save && _entry != null && !ConfigValues.TrySetValue(_entry, keyCode))
			{
				keyCode = (KeyCode)_entry.BoxedValue;
			}
			else if (_entry != null)
			{
				keyCode = (KeyCode)_entry.BoxedValue;
			}
			if ((Object)(object)_buttonText != (Object)null)
			{
				_buttonText.text = FormatKeyCode(keyCode);
			}
			_entry = null;
			_buttonText = null;
		}
	}
	internal sealed class KeybindEditor
	{
		private static readonly KeyCode[] Keys = ((KeyCode[])Enum.GetValues(typeof(KeyCode))).Distinct().ToArray();

		private readonly KeybindCapture _capture = new KeybindCapture();

		private readonly List<KeyCode> _held = new List<KeyCode>();

		private readonly Action<bool> _changed;

		private ConfigEntryBase _entry;

		private TMP_Text _text;

		private KeyCode _modifier;

		private bool _ready;

		private int _startFrame;

		private int _finishFrame = -1;

		public bool IsActive => _entry != null;

		public KeybindEditor(Action<bool> changed)
		{
			_changed = changed;
		}

		public void Update()
		{
			if (!IsActive && Time.frameCount > _finishFrame && !Input.GetMouseButton(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2))
			{
				_changed(obj: false);
			}
		}

		public void Begin(ConfigEntryBase entry, Button button, TMP_Text text)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!IsActive && Time.frameCount > _finishFrame + 1)
			{
				_entry = entry;
				_text = text;
				_modifier = (KeyCode)0;
				_ready = false;
				_startFrame = Time.frameCount;
				_held.Clear();
				_held.AddRange(Keys.Where((KeyCode key) => (int)key != 0 && Input.GetKey(key)));
				if (entry.SettingType == typeof(KeyCode))
				{
					_capture.Begin(entry, button, text);
				}
				else
				{
					text.text = I18n.Text("menu.press_a_key");
					NativeUi.SelectObject(((Component)button).gameObject);
				}
				_changed(obj: true);
			}
		}

		public void CaptureInput()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_013c: 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_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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			if (!IsActive || Time.frameCount <= _startFrame)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)27))
			{
				Cancel();
				return;
			}
			if (!_ready)
			{
				_held.RemoveAll((KeyCode key) => !Input.GetKey(key));
				_ready = _held.Count == 0;
				if (!_ready)
				{
					return;
				}
			}
			if (_entry.SettingType == typeof(KeyCode))
			{
				_capture.CaptureInput();
				if (!_capture.IsActive)
				{
					Finish();
				}
				return;
			}
			KeyCode[] keys = Keys;
			foreach (KeyCode val in keys)
			{
				if ((int)val == 0 || !Input.GetKeyDown(val))
				{
					continue;
				}
				if (IsModifier(val))
				{
					_modifier = val;
					continue;
				}
				KeyCode[] array = Keys.Where((KeyCode value) => IsModifier(value) && Input.GetKey(value)).ToArray();
				ConfigValues.TrySetValue(_entry, (object)new KeyboardShortcut(val, array));
				Finish();
				return;
			}
			if ((int)_modifier != 0 && Input.GetKeyUp(_modifier) && !Keys.Any((KeyCode key) => IsModifier(key) && Input.GetKey(key)))
			{
				ConfigValues.TrySetValue(_entry, (object)new KeyboardShortcut(_modifier, Array.Empty<KeyCode>()));
				Finish();
			}
		}

		public void Cancel()
		{
			if (IsActive)
			{
				_capture.Cancel();
				Finish();
			}
		}

		private void Finish()
		{
			if ((Object)(object)_text != (Object)null)
			{
				_text.text = KeybindCapture.FormatKeyCode(_entry.BoxedValue);
			}
			_entry = null;
			_text = null;
			_held.Clear();
			_finishFrame = Time.frameCount;
		}

		private static bool IsModifier(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Invalid comparison between Unknown and I4
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Invalid comparison between Unknown and I4
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Invalid comparison between Unknown and I4
			if ((int)key != 306 && (int)key != 305 && (int)key != 304 && (int)key != 303 && (int)key != 308 && (int)key != 307 && (int)key != 310 && (int)key != 309 && (int)key != 311 && (int)key != 312)
			{
				return (int)key == 313;
			}
			return true;
		}
	}
	internal sealed class MenuFont : MonoBehaviour
	{
		private const float SystemFontScale = 0.8f;

		[SerializeField]
		private TMP_FontAsset nativeFont;

		[SerializeField]
		private Material nativeMaterial;

		[SerializeField]
		private float nativeFontSize;

		private TMP_Text _label;

		public bool Temporary { get; set; }

		private void Awake()
		{
			_label = ((Component)this).GetComponent<TMP_Text>();
			MenuFonts.Add(this);
			if ((Object)(object)nativeFont == (Object)null)
			{
				Capture();
			}
			else
			{
				Apply();
			}
		}

		private void OnEnable()
		{
			Apply();
		}

		private void OnDestroy()
		{
			MenuFonts.Remove(this);
		}

		public void Capture()
		{
			if ((Object)(object)_label == (Object)null)
			{
				_label = ((Component)this).GetComponent<TMP_Text>();
			}
			if (nativeFontSize <= 0f)
			{
				nativeFontSize = _label.fontSize;
			}
			nativeFont = _label.font;
			nativeMaterial = _label.fontSharedMaterial;
			Apply();
		}

		public void Limit(float size)
		{
			nativeFontSize = Mathf.Min(nativeFontSize, size);
			Apply();
		}

		public void Apply()
		{
			if ((Object)(object)_label == (Object)null)
			{
				_label = ((Component)this).GetComponent<TMP_Text>();
			}
			if ((Object)(object)nativeFont == (Object)null)
			{
				nativeFont = _label.font;
				nativeMaterial = _label.fontSharedMaterial;
				nativeFontSize = _label.fontSize;
			}
			if (!((Object)(object)nativeFont == (Object)null))
			{
				if (nativeFontSize <= 0f)
				{
					nativeFontSize = _label.fontSize;
				}
				TMP_FontAsset val = MenuFonts.Get(_label, nativeFont);
				_label.font = val;
				if (MenuFonts.IsSystemFont(val))
				{
					_label.fontSharedMaterial = ((TMP_Asset)val).material;
					_label.fontSize = nativeFontSize * 0.8f;
				}
				else
				{
					_label.fontSharedMaterial = nativeMaterial;
					_label.fontSize = nativeFontSize;
				}
				TMP_InputField componentInParent = ((Component)_label).GetComponentInParent<TMP_InputField>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.textComponent == (Object)(object)_label)
				{
					componentInParent.fontAsset = val;
					componentInParent.pointSize = _label.fontSize;
				}
			}
		}

		public void Restore()
		{
			_label.font = nativeFont;
			_label.fontSharedMaterial = nativeMaterial;
			_label.fontSize = nativeFontSize;
			Object.DestroyImmediate((Object)(object)this);
		}
	}
	internal static class MenuFonts
	{
		private sealed class FontFile
		{
			public string Path;

			public int FaceIndex;
		}

		public const string DefaultFont = "Default";

		private static readonly string[] Languages = new string[11]
		{
			"en", "de", "fr", "pt-br", "es", "ru", "pl", "ja", "zh_cn", "ko",
			"tr"
		};

		private static readonly Dictionary<TMP_FontAsset, TMP_FontAsset> GameFonts = new Dictionary<TMP_FontAsset, TMP_FontAsset>();

		private static readonly HashSet<MenuFont> Labels = new HashSet<MenuFont>();

		private static readonly Dictionary<string, FontFile> SystemFonts = new Dictionary<string, FontFile>(StringComparer.OrdinalIgnoreCase);

		private static string _fontName;

		private static TMP_FontAsset _systemFont;

		public static bool InTooltip { get; private set; }

		public static string[] GetChoices()
		{
			SystemFonts.Clear();
			foreach (object item in (Array)AccessTools.Method(typeof(FontEngine), "GetSystemFontReferences", (Type[])null, (Type[])null).Invoke(null, null))
			{
				Type type = item.GetType();
				string text = (string)AccessTools.Field(type, "familyName").GetValue(item);
				string text2 = (string)AccessTools.Field(type, "styleName").GetValue(item);
				string key = (string.Equals(text2, "Regular", StringComparison.OrdinalIgnoreCase) ? text : (text + " " + text2));
				SystemFonts[key] = new FontFile
				{
					Path = (string)AccessTools.Field(type, "filePath").GetValue(item),
					FaceIndex = (int)AccessTools.Field(type, "faceIndex").GetValue(item)
				};
			}
			return new string[1] { "Default" }.Concat(SystemFonts.Keys.OrderBy<string, string>((string name) => name, StringComparer.OrdinalIgnoreCase)).ToArray();
		}

		public static void Attach(GameObject root)
		{
			TMP_Text[] componentsInChildren = root.GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Attach(componentsInChildren[i]);
			}
		}

		public static MenuFont Attach(TMP_Text label)
		{
			MenuFont obj = ((Component)label).GetComponent<MenuFont>() ?? ((Component)label).gameObject.AddComponent<MenuFont>();
			obj.Apply();
			return obj;
		}

		public static void Add(MenuFont label)
		{
			Labels.Add(label);
		}

		public static void Remove(MenuFont label)
		{
			Labels.Remove(label);
		}

		public static void Refresh()
		{
			TMP_FontAsset systemFont = _systemFont;
			_systemFont = null;
			_fontName = null;
			foreach (MenuFont label in Labels)
			{
				if ((Object)(object)label != (Object)null)
				{
					label.Apply();
				}
			}
			if ((Object)(object)systemFont != (Object)null)
			{
				Texture2D[] atlasTextures = systemFont.atlasTextures;
				for (int i = 0; i < atlasTextures.Length; i++)
				{
					Object.Destroy((Object)(object)atlasTextures[i]);
				}
				Object.Destroy((Object)(object)((TMP_Asset)systemFont).material);
				Object.Destroy((Object)(object)systemFont);
			}
		}

		public static TMP_FontAsset Get(TMP_Text label, TMP_FontAsset native)
		{
			string text = MenuConfig.MenuFont?.Value ?? "Default";
			TMP_FontAsset value = ((text == "Default") ? null : GetSystemFont(text));
			if ((Object)(object)value == (Object)null)
			{
				if (!GameFonts.TryGetValue(native, out value))
				{
					value = Object.Instantiate<TMP_FontAsset>(native);
					((Object)value).name = "ModSettingsMenu " + ((Object)native).name + " " + ((Object)native).GetInstanceID();
					((TMP_Asset)value).hashCode = TMP_TextUtilities.GetHashCode(((Object)value).name);
					((Object)value).hideFlags = (HideFlags)61;
					value.fallbackFontAssetTable = ((native.fallbackFontAssetTable == null) ? new List<TMP_FontAsset>() : new List<TMP_FontAsset>(native.fallbackFontAssetTable));
					GameFonts[native] = value;
				}
				AddFallbacks(value, TMP_Settings.defaultFontAsset);
				List<TMP_FontAsset> fallbackFontAssets = TMP_Settings.fallbackFontAssets;
				if (fallbackFontAssets != null)
				{
					foreach (TMP_FontAsset item in fallbackFontAssets)
					{
						AddFallback(value, item);
					}
				}
			}
			else
			{
				AddFallback(value, native);
			}
			TextStyleComponent component = ((Component)label).GetComponent<TextStyleComponent>();
			object obj;
			if (component == null)
			{
				obj = null;
			}
			else
			{
				TextStyle currentTextStyle = component.CurrentTextStyle;
				obj = ((currentTextStyle != null) ? currentTextStyle.Font : null);
			}
			LazyFontData val = (LazyFontData)obj;
			if ((Object)(object)val != (Object)null)
			{
				string[] languages = Languages;
				foreach (string text2 in languages)
				{
					TMP_FontAsset fontAssetFor = val.GetFontAssetFor(text2, false, false);
					if ((Object)(object)fontAssetFor != (Object)(object)native)
					{
						AddFallback(value, fontAssetFor);
					}
				}
			}
			return value;
		}

		public static bool IsSystemFont(TMP_FontAsset font)
		{
			if ((Object)(object)_systemFont != (Object)null)
			{
				return (Object)(object)font == (Object)(object)_systemFont;
			}
			return false;
		}

		public static void ShowTooltip(Transform target, string text, string header)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			bool inTooltip = InTooltip;
			try
			{
				InTooltip = true;
				UITooltip.ShowSimpleInfo(target, text, default(Vector2), header);
			}
			finally
			{
				InTooltip = inTooltip;
			}
		}

		private static TMP_FontAsset GetSystemFont(string name)
		{
			//IL_007f: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			if (_fontName == name)
			{
				return _systemFont;
			}
			_fontName = name;
			if (SystemFonts.TryGetValue(name, out var value))
			{
				_systemFont = TMP_FontAsset.CreateFontAsset(value.Path, value.FaceIndex, 64, 8, (GlyphRenderMode)4122, 2048, 2048);
			}
			if ((Object)(object)_systemFont == (Object)null)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					log.LogError((object)("Failed to load system font: " + name));
				}
				return null;
			}
			FaceInfo faceInfo = ((TMP_Asset)_systemFont).faceInfo;
			((FaceInfo)(ref faceInfo)).scale = 1f;
			((TMP_Asset)_systemFont).faceInfo = faceInfo;
			_systemFont.ReadFontAssetDefinition();
			((Object)_systemFont).name = "ModSettingsMenu " + name;
			((TMP_Asset)_systemFont).hashCode = TMP_TextUtilities.GetHashCode(((Object)_systemFont).name);
			((Object)_systemFont).hideFlags = (HideFlags)61;
			((Object)((TMP_Asset)_systemFont).material).hideFlags = (HideFlags)61;
			_systemFont.fallbackFontAssetTable = new List<TMP_FontAsset>();
			AddFallbacks(_systemFont, TMP_Settings.defaultFontAsset);
			List<TMP_FontAsset> fallbackFontAssets = TMP_Settings.fallbackFontAssets;
			if (fallbackFontAssets != null)
			{
				foreach (TMP_FontAsset item in fallbackFontAssets)
				{
					AddFallback(_systemFont, item);
				}
			}
			ManualLogSource log2 = ModSettingsMenu.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)("Font: " + name));
			}
			return _systemFont;
		}

		private static void AddFallback(TMP_FontAsset font, TMP_FontAsset fallback)
		{
			if ((Object)(object)fallback != (Object)null && (Object)(object)fallback != (Object)(object)font && !font.fallbackFontAssetTable.Contains(fallback))
			{
				font.fallbackFontAssetTable.Add(fallback);
			}
		}

		private static void AddFallbacks(TMP_FontAsset font, TMP_FontAsset fallback)
		{
			AddFallback(font, fallback);
			if (((fallback != null) ? fallback.fallbackFontAssetTable : null) == null)
			{
				return;
			}
			foreach (TMP_FontAsset item in fallback.fallbackFontAssetTable)
			{
				AddFallback(font, item);
			}
		}
	}
	internal static class MenuRegistration
	{
		internal static void Subscribe()
		{
			ModSettingsRegistry.RefreshRequested += Refresh;
			LocalizationApi.LanguageChanged += OnLanguageChanged;
		}

		internal static void Register()
		{
			try
			{
				ModSettingsRegistry.Register("IceBoxStudio.GraveyardKeeper2.ModSettingsMenu", new ModSettingsModOptions
				{
					Name = "ModSettingsMenu",
					LocalizedName = () => I18n.Text("mod.name"),
					Description = I18n.Text("mod.description"),
					Author = "Ice Box Studio",
					Version = "1.2.0",
					UpdateManifestUrl = "https://cdn.jsdelivr.net/gh/ibox233/MyMod_Version@main/GraveyardKeeper2/ModSettingsMenu.json",
					NexusModsId = 245,
					ThunderstoreModName = "ModSettingsMenu",
					ThunderstoreTeam = "Ice_Box_Studio_GK2"
				});
			}
			catch (Exception arg)
			{
				ModSettingsMenu.Log.LogError((object)$"Failed to register Mod Settings Menu: {arg}");
			}
		}

		internal static void Refresh()
		{
			UpdateNotice.Request();
			ModSettingsMenuController.Refresh();
		}

		private static void OnLanguageChanged(string language)
		{
			Register();
			try
			{
				ModSettingsMenuController.RefreshLocalizedText();
			}
			catch (Exception arg)
			{
				ManualLogSource log = ModSettingsMenu.Log;
				if (log != null)
				{
					log.LogError((object)$"Could not refresh localized menu text: {arg}");
				}
			}
		}
	}
	internal static class MenuSetup
	{
		internal static void Init(ModSettingsMenu plugin)
		{
			MenuRegistration.Subscribe();
			MenuConfig.Init(((BaseUnityPlugin)plugin).Config);
			MenuRegistration.Register();
			MenuPatchInstaller.Init();
		}
	}
	internal sealed class ModInfoRow
	{
		private sealed class MetadataPart
		{
			public string Text { get; }

			public string Name { get; }

			public string Url { get; }

			public MetadataPart(string text, string name = null, string url = null)
			{
				Text = text;
				Name = name;
				Url = url;
			}
		}

		private sealed class ModLink
		{
			public string Name { get; }

			public string Url { get; }

			public int Start { get; }

			public int Length { get; }

			public ModLink(string name, string url, int start, int length)
			{
				Name = name;
				Url = url;
				Start = start;
				Length = length;
			}
		}

		private readonly Transform _content;

		private readonly GameObject _slider;

		private readonly GameObject _divider;

		private readonly GameObject _linkButton;

		private readonly GameObject _description;

		private readonly TMP_Text _descriptionFont;

		private readonly Action _refresh;

		private GameObject _row;

		private IReadOnlyList<ModLink> _links = Array.Empty<ModLink>();

		private bool _linksCreated;

		private ModConfig _mod;

		private string _currentVersion;

		private TMP_Text _statusLabel;

		private ModUpdateCheckStatus _lastStatus;

		private string _lastVersion;

		private int? _shownNexusId;

		private bool _shownThunderstoreMatch;

		public ModInfoRow(Transform content, GameObject slider, GameObject divider, GameObject linkButton, GameObject description, TMP_Text descriptionFont, Action refresh)
		{
			_content = content;
			_slider = slider;
			_divider = divider;
			_linkButton = linkButton;
			_description = description;
			_descriptionFont = descriptionFont;
			_refresh = refresh;
		}

		public GameObject Create(ModConfig mod)
		{
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: 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_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: 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_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: 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_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Unknown result type (might be due to invalid IL or missing references)
			_row = null;
			_links = Array.Empty<ModLink>();
			_linksCreated = false;
			_mod = null;
			_currentVersion = null;
			_statusLabel = null;
			_lastStatus = ModUpdateCheckStatus.NotConfigured;
			_lastVersion = null;
			_shownNexusId = null;
			_shownThunderstoreMatch = false;
			ModSettingsRegistration modSettingsRegistration = mod?.Registration;
			if (mod == null)
			{
				return null;
			}
			string currentVersion = (string.IsNullOrWhiteSpace(modSettingsRegistration?.Version) ? mod.Info.Metadata.Version.ToString() : modSettingsRegistration.Version);
			ModUpdateCheckResult orStart = ModUpdateChecker.GetOrStart(mod, currentVersion);
			List<ModLink> links;
			string text = BuildText(mod, orStart, out links);
			_shownNexusId = orStart.NexusModsId;
			_shownThunderstoreMatch = !string.IsNullOrWhiteSpace(orStart.ThunderstoreTeam);
			string text2 = ((!string.IsNullOrWhiteSpace(modSettingsRegistration?.Description)) ? modSettingsRegistration.Description.Trim() : orStart.NexusSummary?.Trim());
			GameObject val = NewRow();
			HideRowContents(val);
			RectTransform component = val.GetComponent<RectTransform>();
			RectTransform component2 = _slider.GetComponent<RectTransform>();
			RectTransform component3 = _description.GetComponent<RectTransform>();
			RectTransform component4 = _divider.GetComponent<RectTransform>();
			if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null || (Object)(object)component3 == (Object)null || (Object)(object)component4 == (Object)null)
			{
				Object.Destroy((Object)(object)val);
				return null;
			}
			Rect rect = ((RectTransform)_content).rect;
			float width = ((Rect)(ref rect)).width;
			float num = Mathf.Max(1f, width);
			float num2 = Mathf.Max(1f, num);
			float num3 = Mathf.Clamp(num2 * 0.3f, 60f, 120f);
			float width2 = Mathf.Max(1f, num2 - num3 - 8f);
			RectTransform infoRect;
			TMP_Text infoLabel;
			float height;
			GameObject val2 = CreateText(val, text, width2, out infoRect, out infoLabel, out height);
			if ((Object)(object)val2 == (Object)null)
			{
				Object.Destroy((Object)(object)val);
				return null;
			}
			GameObject val3 = null;
			RectTransform infoRect2 = null;
			float height2 = 0f;
			if (!string.IsNullOrWhiteSpace(text2))
			{
				val3 = CreateText(val, text2, num2, out infoRect2, out var _, out height2);
				if ((Object)(object)val3 == (Object)null)
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				((Object)val3).name = "Information Description";
			}
			RectTransform infoRect3;
			TMP_Text infoLabel3;
			float height3;
			GameObject val4 = CreateText(val, string.Empty, num3, out infoRect3, out infoLabel3, out height3);
			if ((Object)(object)val4 == (Object)null)
			{
				Object.Destroy((Object)(object)val);
				return null;
			}
			((Object)val4).name = "Update Status";
			infoLabel3.textWrappingMode = (TextWrappingModes)0;
			infoLabel3.overflowMode = (TextOverflowModes)1;
			NativeUi.Align(infoLabel3, (TextAlignmentOptions)260);
			float fontSize = _descriptionFont.fontSize;
			float num4 = height + 2f + 12f + 6f;
			if ((Object)(object)val3 != (Object)null)
			{
				num4 += height2 + fontSize;
			}
			component.sizeDelta = new Vector2(num, nu