Decompiled source of HowManyTimesWeClimbedTogether v0.1.6

plugins/com.github.d5v.HowManyTimesWeClimbedTogether.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using PEAKLib.UI;
using PEAKLib.UI.Elements;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;
using Zorro.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.d5v.HowManyTimesWeClimbedTogether")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.6.0")]
[assembly: AssemblyInformationalVersion("0.1.6+6648f9afaea726d372c7dabbba2883612de9cea6")]
[assembly: AssemblyProduct("com.github.d5v.HowManyTimesWeClimbedTogether")]
[assembly: AssemblyTitle("How Many Times We Climbed Together")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.6.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace HowManyTimesWeClimbedTogether
{
	internal static class HmtcLocalization
	{
		internal static Language CurrentLanguage => LocalizedText.CURRENT_LANGUAGE;

		internal static bool IsCjkLanguage(Language language)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Invalid comparison between Unknown and I4
			if (language - 9 <= 3)
			{
				return true;
			}
			return false;
		}

		internal static bool IsCjkLanguage()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return IsCjkLanguage(CurrentLanguage);
		}

		internal static string GetStatsButtonLabel()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => "STATS D'ASCENSION", 
				1 => "STATISTICHE SCALATA", 
				2 => "KLETTERSTATISTIK", 
				3 => "ESTADISTICAS DE ESCALADA", 
				4 => "ESTADISTICAS DE ESCALADA", 
				5 => "ESTATISTICAS DE ESCALADA", 
				6 => "STATISTIKA VOSKHOZHDENIY", 
				7 => "STATYSTYKA SKHODZHEN", 
				8 => "攀登统计", 
				9 => "攀登統計", 
				10 => "登頂統計", 
				11 => "등반 통계", 
				12 => "STATYSTYKI WSPINACZKI", 
				13 => "TIRMANIS ISTATISTIKLERI", 
				_ => "CLIMB STATS", 
			};
		}

		internal static string GetStatsTitle()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => "Avec qui ai-je deja grimpe ?", 
				1 => "Con chi ho gia scalato?", 
				2 => "Mit wem bin ich schon geklettert?", 
				3 => "Con quien ya he escalado?", 
				4 => "Con quien ya he escalado?", 
				5 => "Com quem eu ja escalei?", 
				6 => "S kem ya uzhe podnimalsya?", 
				7 => "Z kym ya vzhe pidimavsya?", 
				8 => "我和谁一起爬过?", 
				9 => "我和誰一起爬過?", 
				10 => "誰と一緒に登った?", 
				11 => "누구와 함께 올랐을까?", 
				12 => "Z kim juz sie wspinalem?", 
				13 => "Kimlerle birlikte tirmandim?", 
				_ => "Who have I climbed with?", 
			};
		}

		internal static string GetPlayerColumnLabel()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => "Joueur", 
				1 => "Giocatore", 
				2 => "Spieler", 
				3 => "Jugador", 
				4 => "Jugador", 
				5 => "Jogador", 
				6 => "Igrok", 
				7 => "Hravec", 
				8 => "玩家", 
				9 => "玩家", 
				10 => "プレイヤー", 
				11 => "플레이어", 
				12 => "Gracz", 
				13 => "Oyuncu", 
				_ => "Player", 
			};
		}

		internal static string GetClimbCountColumnLabel()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => "Fois", 
				1 => "Volte", 
				2 => "Male", 
				3 => "Veces", 
				4 => "Veces", 
				5 => "Vezes", 
				6 => "Raz", 
				7 => "Raziv", 
				8 => "次数", 
				9 => "次數", 
				10 => "回数", 
				11 => "횟수", 
				12 => "Razy", 
				13 => "Kez", 
				_ => "Times", 
			};
		}

		internal static string FormatClimbCount(int count)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => $"Grimpe ensemble {count} fois", 
				1 => $"Scalato insieme {count} volte", 
				2 => $"{count} Mal zusammen geklettert", 
				3 => $"Escalamos juntos {count} veces", 
				4 => $"Escalamos juntos {count} veces", 
				5 => $"Escalamos juntos {count} vez(es)", 
				6 => $"Vmeste podnimalis {count} raz", 
				7 => $"Razom pidiimalys {count} raziv", 
				8 => $"一起爬了 {count} 次", 
				9 => $"一起爬了 {count} 次", 
				10 => $"一緒に登ったのは {count} 回", 
				11 => $"함께 올란 횟수 {count}회", 
				12 => $"Wspinaliscie sie razem {count} razy", 
				13 => $"Birlikte {count} kez tirmandiniz", 
				_ => string.Format("Climbed together {0} time{1}", count, (count == 1) ? string.Empty : "s"), 
			};
		}

		internal static string FormatTrackedPlayers(int count)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => $"Joueurs suivis: {count}", 
				1 => $"Giocatori registrati: {count}", 
				2 => $"Erfasste Spieler: {count}", 
				3 => $"Jugadores registrados: {count}", 
				4 => $"Jugadores registrados: {count}", 
				5 => $"Jogadores rastreados: {count}", 
				6 => $"Otslezhivaemye igroki: {count}", 
				7 => $"Vidstezhuvani hravtsi: {count}", 
				8 => $"已记录玩家: {count}", 
				9 => $"已記錄玩家: {count}", 
				10 => $"記録済みプレイヤー: {count}", 
				11 => $"기록된 플레이어: {count}", 
				12 => $"Sledzeni gracze: {count}", 
				13 => $"Kayitli oyuncular: {count}", 
				_ => $"Tracked players: {count}", 
			};
		}

		internal static string GetStatsHint()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => "Consultez l'historique des joueurs avec qui vous avez grimpe", 
				1 => "Controlla lo storico dei giocatori con cui hai scalato", 
				2 => "Hier siehst du die Spieler, mit denen du bereits geklettert bist", 
				3 => "Consulta el historial de jugadores con los que ya escalaste", 
				4 => "Consulta el historial de jugadores con los que ya escalaste", 
				5 => "Veja o historico de jogadores com quem voce ja escalou", 
				6 => "Zdes pokazana istoriya igrokov, s kotorymi vy uzhe podnimalis", 
				7 => "Tut pokazano istoriyu hravtsiv, z yakymy vy vzhe pidimalys", 
				8 => "这里会显示你一起爬过山的玩家", 
				9 => "這裡會顯示你一起爬過山的玩家", 
				10 => "ここで一緒に登ったプレイヤーを確認できます", 
				11 => "여기서 함께 올랐던 플레이어 기록을 볼 수 있습니다", 
				12 => "Tutaj zobaczysz graczy, z ktorymi juz sie wspinales", 
				13 => "Burada birlikte tirmandigin oyuncularin kaydini gorebilirsin", 
				_ => "See the players you have already climbed with", 
			};
		}

		internal static string GetNoRecordsText()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => "Aucun historique pour le moment", 
				1 => "Nessun dato registrato per ora", 
				2 => "Noch keine Eintraege vorhanden", 
				3 => "Todavia no hay registros", 
				4 => "Todavia no hay registros", 
				5 => "Ainda nao ha registros", 
				6 => "Poka net zapisey", 
				7 => "Poki shcho nemaie zapysiv", 
				8 => "还没有统计记录", 
				9 => "還沒有統計記錄", 
				10 => "まだ記録がありません", 
				11 => "아직 기록이 없습니다", 
				12 => "Nie ma jeszcze zadnych wpisow", 
				13 => "Henuz kayit yok", 
				_ => "No climbing records yet", 
			};
		}

		internal static string FormatClimbedWithMessage(string playerName, int count)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			Language currentLanguage = CurrentLanguage;
			return (currentLanguage - 1) switch
			{
				0 => $"Vous avez gravi avec {playerName} {count} fois", 
				1 => $"Hai scalato con {playerName} {count} volte", 
				2 => $"Du bist mit {playerName} {count} Mal geklettert", 
				3 => $"Has escalado con {playerName} {count} veces", 
				4 => $"Has escalado con {playerName} {count} veces", 
				5 => $"Voce escalou com {playerName} {count} vez(es)", 
				6 => $"Vy podnimalis s {playerName} {count} raz", 
				7 => $"Vy pidiimalys z {playerName} {count} raziv", 
				8 => $"你和 {playerName} 一起爬了 {count} 次山", 
				9 => $"你和 {playerName} 一起爬了 {count} 次山", 
				10 => $"{playerName} と一緒に登った回数: {count}", 
				11 => $"{playerName} 님과 함께 등반한 횟수: {count}", 
				12 => $"Wspinaliscie sie z {playerName} {count} razy", 
				13 => $"{playerName} ile {count} kez tirmandin", 
				_ => string.Format("You've climbed with {0} {1} time{2}", playerName, count, (count == 1) ? string.Empty : "s"), 
			};
		}
	}
	internal static class MessageFormatter
	{
		internal static string BuildClimbedWithMessage(string playerName, int count)
		{
			string text = HmtcLocalization.FormatClimbedWithMessage(playerName, count);
			return "<color=#AAAAAA>" + text + "</color>";
		}
	}
	internal static class PlayerConnectionLogPatches
	{
		[HarmonyPatch(typeof(PlayerConnectionLog), "OnPlayerEnteredRoom")]
		[HarmonyPostfix]
		private static void OnPlayerEnteredRoom_Postfix(PlayerConnectionLog __instance, Player newPlayer)
		{
			if (!newPlayer.IsLocal)
			{
				SessionDetector.OnPlayerJoinedDuringExpedition(newPlayer);
				string stablePlayerId = SessionDetector.GetStablePlayerId(newPlayer);
				int sessionCount = Plugin.Tracker.GetSessionCount(stablePlayerId);
				if (sessionCount > 0)
				{
					string bestDisplayName = SessionDetector.GetBestDisplayName(newPlayer);
					string text = MessageFormatter.BuildClimbedWithMessage(bestDisplayName, sessionCount);
					__instance.AddMessage(text);
				}
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.d5v.HowManyTimesWeClimbedTogether", "How Many Times We Climbed Together", "0.1.6")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log { get; private set; }

		internal static SessionTracker Tracker { get; private set; }

		private void Awake()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				Tracker = new SessionTracker();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"[HMTC] Failed to initialize SessionTracker: {arg}");
				return;
			}
			try
			{
				Harmony val = new Harmony("com.github.d5v.HowManyTimesWeClimbedTogether");
				MethodInfo method = typeof(PlayerConnectionLog).GetMethod("OnPlayerEnteredRoom", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method == null)
				{
					Log.LogError((object)"[HMTC] Could not find PlayerConnectionLog.OnPlayerEnteredRoom method!");
					MethodInfo[] methods = typeof(PlayerConnectionLog).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						Log.LogWarning((object)("[HMTC] Method: " + methodInfo.Name));
					}
					return;
				}
				Log.LogInfo((object)("[HMTC] Found target method: " + method.Name));
				MethodInfo method2 = typeof(PlayerConnectionLogPatches).GetMethod("OnPlayerEnteredRoom_Postfix", BindingFlags.Static | BindingFlags.NonPublic);
				val.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception arg2)
			{
				Log.LogError((object)$"[HMTC] Failed to apply Harmony patch: {arg2}");
				return;
			}
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void Start()
		{
			StatsMenuUi.Register();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			SessionDetector.OnSceneLoaded(((Scene)(ref scene)).name);
		}

		private void Update()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			SessionDetector.Update(((Scene)(ref activeScene)).name);
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			StatsMenuUi.Dispose();
		}
	}
	internal static class SessionDetector
	{
		private const string LobbyScene = "Airport";

		private static bool _inExpedition;

		private static readonly HashSet<string> _countedPlayersThisSession = new HashSet<string>();

		internal static void Update(string sceneName)
		{
			if (sceneName == "Airport")
			{
				_inExpedition = false;
				_countedPlayersThisSession.Clear();
			}
			else if (PhotonNetwork.InRoom)
			{
				if (!_inExpedition)
				{
					_inExpedition = true;
					RecordAllCurrentPlayers();
				}
				else if (HasUncountedRemotePlayers())
				{
					RecordAllCurrentPlayers();
				}
			}
		}

		internal static void OnSceneLoaded(string sceneName)
		{
			Update(sceneName);
		}

		private static void RecordAllCurrentPlayers()
		{
			Player[] playerList = PhotonNetwork.PlayerList;
			bool flag = false;
			Player[] array = playerList;
			foreach (Player player in array)
			{
				if (TryCountPlayer(player))
				{
					flag = true;
				}
			}
			if (flag)
			{
				Plugin.Tracker.Save();
			}
		}

		internal static void OnPlayerJoinedDuringExpedition(Player newPlayer)
		{
			if (_inExpedition && TryCountPlayer(newPlayer))
			{
				Plugin.Tracker.Save();
			}
		}

		private static bool TryCountPlayer(Player player)
		{
			if (player.ActorNumber == PhotonNetwork.LocalPlayer.ActorNumber)
			{
				return false;
			}
			string stablePlayerId = GetStablePlayerId(player);
			string bestDisplayName = GetBestDisplayName(player);
			if (!_countedPlayersThisSession.Add(stablePlayerId))
			{
				return false;
			}
			Plugin.Tracker.IncrementSession(stablePlayerId, bestDisplayName);
			return true;
		}

		private static bool HasUncountedRemotePlayers()
		{
			Player[] playerList = PhotonNetwork.PlayerList;
			foreach (Player val in playerList)
			{
				if (val.ActorNumber != PhotonNetwork.LocalPlayer.ActorNumber)
				{
					string stablePlayerId = GetStablePlayerId(val);
					if (!_countedPlayersThisSession.Contains(stablePlayerId))
					{
						return true;
					}
				}
			}
			return false;
		}

		internal static string GetStablePlayerId(Player player)
		{
			if (!string.IsNullOrEmpty(player.UserId))
			{
				return player.UserId;
			}
			return "nick:" + (player.NickName ?? player.ActorNumber.ToString());
		}

		internal static string GetBestDisplayName(Player player)
		{
			string stablePlayerId = GetStablePlayerId(player);
			string lastKnownName = Plugin.Tracker.GetLastKnownName(stablePlayerId);
			if (!string.IsNullOrWhiteSpace(lastKnownName))
			{
				return lastKnownName;
			}
			if (!string.IsNullOrWhiteSpace(player.NickName))
			{
				return player.NickName;
			}
			if (!string.IsNullOrWhiteSpace(player.UserId))
			{
				return player.UserId;
			}
			return $"Player {player.ActorNumber}";
		}
	}
	internal class SessionTracker
	{
		private readonly string _dataFilePath;

		private Dictionary<string, PlayerRecord> _records;

		internal SessionTracker()
		{
			_dataFilePath = Path.Combine(Paths.ConfigPath, "HowManyTimesWeClimbedTogether.json");
			_records = Load();
			EnsureDataFileExists();
		}

		internal void IncrementSession(string playerId, string playerName)
		{
			EnsureDataFileExists();
			if (_records.TryGetValue(playerId, out PlayerRecord value))
			{
				value.SessionCount++;
				value.LastKnownName = playerName;
				return;
			}
			_records[playerId] = new PlayerRecord
			{
				PlayerId = playerId,
				LastKnownName = playerName,
				SessionCount = 1
			};
		}

		internal int GetSessionCount(string playerId)
		{
			EnsureDataFileExists();
			if (!_records.TryGetValue(playerId, out PlayerRecord value))
			{
				return 0;
			}
			return value.SessionCount;
		}

		internal string GetLastKnownName(string playerId)
		{
			EnsureDataFileExists();
			if (!_records.TryGetValue(playerId, out PlayerRecord value) || string.IsNullOrWhiteSpace(value.LastKnownName))
			{
				return "";
			}
			return value.LastKnownName;
		}

		internal IReadOnlyDictionary<string, PlayerRecord> GetAllRecords()
		{
			EnsureDataFileExists();
			return _records;
		}

		internal void Save()
		{
			try
			{
				string directoryName = Path.GetDirectoryName(_dataFilePath);
				if (!string.IsNullOrWhiteSpace(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				string contents = JsonConvert.SerializeObject((object)_records, (Formatting)1);
				File.WriteAllText(_dataFilePath, contents);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Failed to save session data: " + ex.Message));
			}
		}

		private Dictionary<string, PlayerRecord> Load()
		{
			try
			{
				if (File.Exists(_dataFilePath))
				{
					string text = File.ReadAllText(_dataFilePath);
					return JsonConvert.DeserializeObject<Dictionary<string, PlayerRecord>>(text) ?? new Dictionary<string, PlayerRecord>();
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Failed to load session data: " + ex.Message));
			}
			return new Dictionary<string, PlayerRecord>();
		}

		private void EnsureDataFileExists()
		{
			if (!File.Exists(_dataFilePath))
			{
				Save();
			}
		}
	}
	internal class PlayerRecord
	{
		public string PlayerId { get; set; } = "";


		public string LastKnownName { get; set; } = "";


		public int SessionCount { get; set; }
	}
	internal static class StatsMenuUi
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static BuilderDelegate <0>__BuildPauseMenu;

			public static Action <1>__OnLanguageChanged;

			public static UnityAction <2>__RefreshPage;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__20_0;

			public static UnityAction <>9__20_1;

			public static Func<PlayerRecord, int> <>9__24_0;

			public static Func<PlayerRecord, string> <>9__24_1;

			public static Func<TextMeshProUGUI, TMP_FontAsset> <>9__29_0;

			public static Func<TMP_FontAsset, bool> <>9__29_1;

			public static Func<char, bool> <>9__34_0;

			internal void <BuildButtons>b__20_0()
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Expected O, but got Unknown
				((UIPageHandler)_pauseMenuHandler).TransistionToPage((UIPage)(object)_parentPage, (PageTransistion)new SetActivePageTransistion());
			}

			internal void <BuildButtons>b__20_1()
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Expected O, but got Unknown
				RefreshPage();
				((UIPageHandler)_pauseMenuHandler).TransistionToPage((UIPage)(object)_statsPage, (PageTransistion)new SetActivePageTransistion());
			}

			internal int <RefreshRows>b__24_0(PlayerRecord record)
			{
				return record.SessionCount;
			}

			internal string <RefreshRows>b__24_1(PlayerRecord record)
			{
				return record.LastKnownName;
			}

			internal TMP_FontAsset <EnsureFonts>b__29_0(TextMeshProUGUI text)
			{
				return ((TMP_Text)text).font;
			}

			internal bool <EnsureFonts>b__29_1(TMP_FontAsset font)
			{
				return (Object)(object)font != (Object)null;
			}

			internal bool <ContainsCjk>b__34_0(char character)
			{
				return character >= '⺀';
			}
		}

		private static readonly List<GameObject> Rows = new List<GameObject>();

		private static bool _registered;

		private static bool _subscribedToLanguageChanged;

		private static PauseMenuHandler? _pauseMenuHandler;

		private static PauseMenuMainPage? _parentPage;

		private static PeakChildPage? _statsPage;

		private static PeakMenuButton? _openButton;

		private static PeakMenuButton? _backButton;

		private static RectTransform? _rowsContent;

		private static TextMeshProUGUI? _titleText;

		private static TextMeshProUGUI? _summaryText;

		private static TextMeshProUGUI? _hintText;

		private static TextMeshProUGUI? _emptyText;

		private static TMP_FontAsset? _vanillaFont;

		private static TMP_FontAsset? _cjkFont;

		internal static void Register()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if (!_registered)
			{
				_registered = true;
				object obj = <>O.<0>__BuildPauseMenu;
				if (obj == null)
				{
					BuilderDelegate val = BuildPauseMenu;
					<>O.<0>__BuildPauseMenu = val;
					obj = (object)val;
				}
				MenuAPI.AddToPauseMenu((BuilderDelegate)obj);
				if (!_subscribedToLanguageChanged)
				{
					LocalizedText.OnLangugageChanged = (Action)Delegate.Combine(LocalizedText.OnLangugageChanged, new Action(OnLanguageChanged));
					_subscribedToLanguageChanged = true;
				}
			}
		}

		internal static void Dispose()
		{
			if (_subscribedToLanguageChanged)
			{
				LocalizedText.OnLangugageChanged = (Action)Delegate.Remove(LocalizedText.OnLangugageChanged, new Action(OnLanguageChanged));
				_subscribedToLanguageChanged = false;
			}
		}

		private static void BuildPauseMenu(Transform parent)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			if ((Object)(object)_statsPage != (Object)null && Object.op_Implicit((Object)(object)_statsPage))
			{
				return;
			}
			_pauseMenuHandler = ((Component)parent).GetComponentInParent<PauseMenuHandler>();
			_parentPage = ((Component)parent).GetComponent<PauseMenuMainPage>();
			if ((Object)(object)_pauseMenuHandler == (Object)null || (Object)(object)_parentPage == (Object)null)
			{
				Plugin.Log.LogError((object)"[HMTC] Failed to build stats page because pause menu references were missing.");
				return;
			}
			EnsureFonts();
			_statsPage = MenuAPI.CreateChildPage("HMTC_StatsPage", (UIPage)(object)_parentPage).CreateBackground((Color?)new Color(0f, 0f, 0f, 0.8667f));
			PeakChildPage? statsPage = _statsPage;
			object obj = <>O.<2>__RefreshPage;
			if (obj == null)
			{
				UnityAction val = RefreshPage;
				<>O.<2>__RefreshPage = val;
				obj = (object)val;
			}
			statsPage.SetOnOpen((UnityAction)obj);
			BuildHeader();
			BuildContent();
			BuildButtons(parent);
			((Component)_statsPage).gameObject.SetActive(false);
			RefreshStaticText();
		}

		private static void BuildHeader()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_statsPage == (Object)null))
			{
				PeakElement val = ElementExtensions.SetSize<PeakElement>(ElementExtensions.SetPivot<PeakElement>(ElementExtensions.SetPosition<PeakElement>(ElementExtensions.SetAnchorMinMax<PeakElement>(ElementExtensions.ParentTo(new GameObject("Header"), (Component)(object)_statsPage).AddComponent<PeakElement>(), new Vector2(0.5f, 1f)), new Vector2(0f, -42f)), new Vector2(0.5f, 1f)), new Vector2(900f, 120f));
				_titleText = CreateText(((Component)val).transform, "Title", 54f, (FontStyles)0, (TextAlignmentOptions)514);
				StretchToParent(((TMP_Text)_titleText).rectTransform);
				((TMP_Text)_titleText).fontSizeMax = 54f;
				((TMP_Text)_titleText).fontSizeMin = 30f;
				((TMP_Text)_titleText).enableAutoSizing = true;
			}
		}

		private static void BuildContent()
		{
			//IL_0013: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_statsPage == (Object)null))
			{
				PeakElement val = ElementExtensions.SetSize<PeakElement>(ElementExtensions.SetPosition<PeakElement>(ElementExtensions.SetAnchorMinMax<PeakElement>(ElementExtensions.SetPivot<PeakElement>(ElementExtensions.ParentTo<PeakElement>(new GameObject("Content").AddComponent<PeakElement>(), (Component)(object)_statsPage), new Vector2(0.5f, 1f)), new Vector2(0.5f, 1f)), new Vector2(0f, -150f)), new Vector2(1420f, 840f));
				PeakElement val2 = ElementExtensions.ExpandToParent<PeakElement>(ElementExtensions.ParentTo<PeakElement>(new GameObject("StatsPanel").AddComponent<PeakElement>(), (Component)(object)val));
				((Graphic)((Component)val2).gameObject.AddComponent<Image>()).color = new Color(0.11f, 0.09f, 0.08f, 0.76f);
				_summaryText = CreateText(((Component)val2).transform, "Summary", 32f, (FontStyles)0, (TextAlignmentOptions)514);
				ConfigureTopText(((TMP_Text)_summaryText).rectTransform, new Vector2(90f, -18f), new Vector2(-90f, -62f));
				_hintText = CreateText(((Component)val2).transform, "Hint", 22f, (FontStyles)0, (TextAlignmentOptions)514);
				((Graphic)_hintText).color = new Color(0.88f, 0.84f, 0.76f, 0.92f);
				ConfigureTopText(((TMP_Text)_hintText).rectTransform, new Vector2(90f, -68f), new Vector2(-90f, -104f));
				PeakElement val3 = ElementExtensions.SetSize<PeakElement>(ElementExtensions.SetPosition<PeakElement>(ElementExtensions.SetPivot<PeakElement>(ElementExtensions.SetAnchorMax<PeakElement>(ElementExtensions.SetAnchorMin<PeakElement>(ElementExtensions.ParentTo<PeakElement>(new GameObject("Divider").AddComponent<PeakElement>(), (Component)(object)val2), new Vector2(0f, 1f)), new Vector2(1f, 1f)), new Vector2(0.5f, 1f)), new Vector2(0f, -122f)), new Vector2(-120f, 2f));
				((Graphic)((Component)val3).gameObject.AddComponent<Image>()).color = new Color(0.78f, 0.63f, 0.35f, 0.9f);
				PeakScrollableContent val4 = ElementExtensions.SetOffsetMax<PeakScrollableContent>(ElementExtensions.SetOffsetMin<PeakScrollableContent>(ElementExtensions.SetAnchorMax<PeakScrollableContent>(ElementExtensions.SetAnchorMin<PeakScrollableContent>(ElementExtensions.ParentTo<PeakScrollableContent>(MenuAPI.CreateScrollableContent("StatsRows"), (Component)(object)val2), new Vector2(0f, 0f)), new Vector2(1f, 1f)), new Vector2(56f, 110f)), new Vector2(-56f, -146f));
				_rowsContent = val4.Content;
				_emptyText = CreateText(((Component)val2).transform, "Empty", 30f, (FontStyles)0, (TextAlignmentOptions)514);
				((Graphic)_emptyText).color = new Color(0.94f, 0.9f, 0.82f, 0.95f);
				((TMP_Text)_emptyText).rectTransform.anchorMin = new Vector2(0f, 0f);
				((TMP_Text)_emptyText).rectTransform.anchorMax = new Vector2(1f, 1f);
				((TMP_Text)_emptyText).rectTransform.offsetMin = new Vector2(120f, 160f);
				((TMP_Text)_emptyText).rectTransform.offsetMax = new Vector2(-120f, -170f);
			}
		}

		private static void BuildButtons(Transform parent)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0092: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			if ((Object)(object)_statsPage == (Object)null || (Object)(object)_pauseMenuHandler == (Object)null || (Object)(object)_parentPage == (Object)null)
			{
				return;
			}
			PeakMenuButton obj = ElementExtensions.SetPosition<PeakMenuButton>(ElementExtensions.SetPivot<PeakMenuButton>(ElementExtensions.SetAnchorMinMax<PeakMenuButton>(ElementExtensions.ParentTo<PeakMenuButton>(ElementExtensions.SetLocalizationIndex<PeakMenuButton>(MenuAPI.CreateMenuButton("Back"), "BACK").SetColor(new Color(0.5189f, 0.1297f, 0.1718f), true), (Component)(object)_statsPage), new Vector2(0.5f, 0f)), new Vector2(0.5f, 0f)), new Vector2(0f, 36f)).SetWidth(220f);
			object obj2 = <>c.<>9__20_0;
			if (obj2 == null)
			{
				UnityAction val = delegate
				{
					//IL_000a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: Expected O, but got Unknown
					((UIPageHandler)_pauseMenuHandler).TransistionToPage((UIPage)(object)_parentPage, (PageTransistion)new SetActivePageTransistion());
				};
				<>c.<>9__20_0 = val;
				obj2 = (object)val;
			}
			_backButton = obj.OnClick((UnityAction)obj2);
			_statsPage.SetBackButton(_backButton.Button);
			PeakMenuButton obj3 = ElementExtensions.ParentTo<PeakMenuButton>(MenuAPI.CreatePauseMenuButton("CLIMB STATS"), parent);
			object obj4 = <>c.<>9__20_1;
			if (obj4 == null)
			{
				UnityAction val2 = delegate
				{
					//IL_000f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Expected O, but got Unknown
					RefreshPage();
					((UIPageHandler)_pauseMenuHandler).TransistionToPage((UIPage)(object)_statsPage, (PageTransistion)new SetActivePageTransistion());
				};
				<>c.<>9__20_1 = val2;
				obj4 = (object)val2;
			}
			_openButton = obj3.OnClick((UnityAction)obj4);
			PositionOpenButton(_openButton);
		}

		private static void PositionOpenButton(PeakMenuButton button)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform rectTransform = ((PeakElement)button).RectTransform;
			rectTransform.anchorMin = new Vector2(0.5f, 0f);
			rectTransform.anchorMax = new Vector2(0.5f, 0f);
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.sizeDelta = new Vector2(277f, rectTransform.sizeDelta.y);
			rectTransform.anchoredPosition = new Vector2(0f, 36f);
		}

		private static void RefreshPage()
		{
			RefreshStaticText();
			RefreshRows();
		}

		private static void RefreshStaticText()
		{
			EnsureFonts();
			if ((Object)(object)_titleText != (Object)null)
			{
				((TMP_Text)_titleText).text = HmtcLocalization.GetStatsTitle();
				ApplyFont((TMP_Text)(object)_titleText, HmtcLocalization.IsCjkLanguage());
			}
			if ((Object)(object)_summaryText != (Object)null)
			{
				((TMP_Text)_summaryText).text = HmtcLocalization.FormatTrackedPlayers(Plugin.Tracker.GetAllRecords().Count);
				ApplyFont((TMP_Text)(object)_summaryText, HmtcLocalization.IsCjkLanguage());
			}
			if ((Object)(object)_hintText != (Object)null)
			{
				((TMP_Text)_hintText).text = HmtcLocalization.GetStatsHint();
				ApplyFont((TMP_Text)(object)_hintText, HmtcLocalization.IsCjkLanguage());
			}
			if ((Object)(object)_emptyText != (Object)null)
			{
				((TMP_Text)_emptyText).text = HmtcLocalization.GetNoRecordsText();
				ApplyFont((TMP_Text)(object)_emptyText, HmtcLocalization.IsCjkLanguage());
			}
			RefreshButtonText();
		}

		private static void RefreshRows()
		{
			if ((Object)(object)_rowsContent == (Object)null)
			{
				return;
			}
			foreach (GameObject row in Rows)
			{
				Object.Destroy((Object)(object)row);
			}
			Rows.Clear();
			List<PlayerRecord> list = (from record in Plugin.Tracker.GetAllRecords().Values
				orderby record.SessionCount descending, record.LastKnownName
				select record).ToList();
			bool flag = list.Count > 0;
			if ((Object)(object)_emptyText != (Object)null)
			{
				((Component)_emptyText).gameObject.SetActive(!flag);
			}
			foreach (PlayerRecord item in list)
			{
				string playerName = (string.IsNullOrWhiteSpace(item.LastKnownName) ? item.PlayerId : item.LastKnownName);
				GameObject val = CreateRow(playerName, item.SessionCount, Rows.Count);
				val.transform.SetParent((Transform)(object)_rowsContent, false);
				Rows.Add(val);
			}
		}

		private static GameObject CreateRow(string playerName, int count, int index)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Row", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(LayoutElement)
			});
			((Graphic)val.GetComponent<Image>()).color = ((index % 2 == 0) ? new Color(0.2f, 0.15f, 0.11f, 0.72f) : new Color(0.16f, 0.12f, 0.09f, 0.72f));
			LayoutElement component = val.GetComponent<LayoutElement>();
			component.preferredHeight = 72f;
			component.minHeight = 72f;
			TextMeshProUGUI val2 = CreateText(val.transform, "PlayerName", 30f, (FontStyles)0, (TextAlignmentOptions)513);
			ConfigureTopText(((TMP_Text)val2).rectTransform, new Vector2(24f, -10f), new Vector2(-240f, -58f));
			((TMP_Text)val2).text = playerName;
			ApplyFont((TMP_Text)(object)val2, ContainsCjk(playerName));
			TextMeshProUGUI val3 = CreateText(val.transform, "Count", 24f, (FontStyles)0, (TextAlignmentOptions)516);
			ConfigureTopText(((TMP_Text)val3).rectTransform, new Vector2(820f, -12f), new Vector2(-24f, -58f));
			((TMP_Text)val3).text = HmtcLocalization.FormatClimbCount(count);
			((TMP_Text)val3).enableAutoSizing = true;
			((TMP_Text)val3).fontSizeMin = 18f;
			((TMP_Text)val3).fontSizeMax = 24f;
			ApplyFont((TMP_Text)(object)val3, HmtcLocalization.IsCjkLanguage());
			return val;
		}

		private static void RefreshButtonText()
		{
			if ((Object)(object)_openButton != (Object)null)
			{
				_openButton.SetText(HmtcLocalization.GetStatsButtonLabel());
				ApplyFont(((PeakLocalizableElement)_openButton).Text, HmtcLocalization.IsCjkLanguage());
			}
			if ((Object)(object)_backButton != (Object)null)
			{
				ApplyFont(((PeakLocalizableElement)_backButton).Text, HmtcLocalization.IsCjkLanguage());
			}
		}

		private static void OnLanguageChanged()
		{
			RefreshStaticText();
			RefreshRows();
		}

		private static TextMeshProUGUI CreateText(Transform parent, string objectName, float fontSize, FontStyles fontStyle, TextAlignmentOptions alignment)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(objectName, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(TextMeshProUGUI)
			});
			val.transform.SetParent(parent, false);
			TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).font = _vanillaFont;
			((TMP_Text)component).fontSize = fontSize;
			((TMP_Text)component).fontStyle = fontStyle;
			((TMP_Text)component).alignment = alignment;
			((Graphic)component).color = Color.white;
			((TMP_Text)component).overflowMode = (TextOverflowModes)1;
			((TMP_Text)component).textWrappingMode = (TextWrappingModes)0;
			return component;
		}

		private static void EnsureFonts()
		{
			if ((Object)(object)_vanillaFont == (Object)null)
			{
				GameObject buttonTemplate = Templates.ButtonTemplate;
				object vanillaFont;
				if (buttonTemplate == null)
				{
					vanillaFont = null;
				}
				else
				{
					TextMeshProUGUI componentInChildren = buttonTemplate.GetComponentInChildren<TextMeshProUGUI>(true);
					vanillaFont = ((componentInChildren != null) ? ((TMP_Text)componentInChildren).font : null);
				}
				_vanillaFont = (TMP_FontAsset?)vanillaFont;
				if (_vanillaFont == null)
				{
					_vanillaFont = (from text in Resources.FindObjectsOfTypeAll<TextMeshProUGUI>()
						select ((TMP_Text)text).font).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset font) => (Object)(object)font != (Object)null));
				}
			}
			if (_cjkFont == null)
			{
				_cjkFont = CreateCjkFontAsset();
			}
		}

		private static TMP_FontAsset? CreateCjkFontAsset()
		{
			string[] array = new string[7] { "Microsoft YaHei UI", "Microsoft YaHei", "SimHei", "Microsoft JhengHei UI", "Microsoft JhengHei", "Malgun Gothic", "Yu Gothic UI" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				try
				{
					Font val = Font.CreateDynamicFontFromOSFont(text, 20);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					return TMP_FontAsset.CreateFontAsset(val, 20, 4, (GlyphRenderMode)4165, 1024, 1024, (AtlasPopulationMode)1, true);
				}
				catch
				{
				}
			}
			return null;
		}

		private static void ApplyFont(TMP_Text text, bool preferCjk)
		{
			if (preferCjk && (Object)(object)_cjkFont != (Object)null)
			{
				text.font = _cjkFont;
			}
			else if ((Object)(object)_vanillaFont != (Object)null)
			{
				text.font = _vanillaFont;
			}
		}

		private static void StretchToParent(RectTransform rectTransform)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.offsetMin = Vector2.zero;
			rectTransform.offsetMax = Vector2.zero;
		}

		private static void ConfigureTopText(RectTransform rectTransform, Vector2 offsetMin, Vector2 offsetMax)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.offsetMin = new Vector2(offsetMin.x, offsetMax.y);
			rectTransform.offsetMax = new Vector2(offsetMax.x, offsetMin.y);
		}

		private static bool ContainsCjk(string text)
		{
			return text.Any((char character) => character >= '⺀');
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}