Decompiled source of RecentPlayers v1.0.6

plugins/mod_zacharyacoon_recent-players_v1.0.6_4641e6b1edd47eab521cf4668dcdd302ace2b8e4d89061450f59db2488f879e1.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RecentPlayers
{
	internal static class LobbyTag
	{
		internal const string Key = "dmods";

		internal const string Vanilla = "f";
	}
	[HarmonyPatch(typeof(Lobby), "SetData")]
	internal static class LobbySetDataPatch
	{
		private static void Prefix(string key, ref string value)
		{
			if (key == "dmods")
			{
				value = "f";
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "SteamMatchmaking_OnLobbyCreated")]
	internal static class LobbyCreatedPatch
	{
		[HarmonyPriority(0)]
		private static void Postfix(Result result, Lobby lobby)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			try
			{
				if ((int)result == 1 && ((Lobby)(ref lobby)).GetData("dmods") != "f")
				{
					((Lobby)(ref lobby)).SetData("dmods", "f");
				}
			}
			catch (Exception arg)
			{
				Mod.Log.LogError($"LobbyCreatedPatch: {arg}");
			}
		}
	}
	internal class ModLogger
	{
		private readonly Action<string, string> write;

		public ModLogger(Action<string, string> write)
		{
			this.write = write;
		}

		public void LogInfo(string message)
		{
			Write("Info", message);
		}

		public void LogWarning(string message)
		{
			Write("Warning", message);
		}

		public void LogError(string message)
		{
			Write("Error", message);
		}

		private void Write(string level, string message)
		{
			try
			{
				write(level, message);
			}
			catch
			{
			}
		}
	}
	internal static class Mod
	{
		public const string Guid = "recentplayers";

		public const string Name = "Recent Players";

		public const string ModName = "zacharyacoon_recent-players";

		public const string Version = "1.0.6";

		public const int MaxPlayers = 10;

		public const string DataFileName = "mod_zacharyacoon_recent-players.json";

		internal static ModLogger Log = new ModLogger(delegate
		{
		});

		internal static RecentPlayersStore Store;

		private const string RunningKey = "zacharyacoon_recent-players.running";

		public static bool TryClaim(string loader)
		{
			AppDomain currentDomain = AppDomain.CurrentDomain;
			lock (currentDomain)
			{
				if (currentDomain.GetData("zacharyacoon_recent-players.running") is string text)
				{
					Log.LogInfo("Already running from the " + text + " build; this " + loader + " copy is not starting.");
					return false;
				}
				currentDomain.SetData("zacharyacoon_recent-players.running", loader);
				return true;
			}
		}

		public static void Init(string dataDir, params string[] importDirs)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			Directory.CreateDirectory(dataDir);
			string text = Path.Combine(dataDir, "mod_zacharyacoon_recent-players.json");
			Store = new RecentPlayersStore(text, 10);
			if (!File.Exists(text))
			{
				string[] array = new string[importDirs.Length + 1];
				array[0] = dataDir;
				importDirs.CopyTo(array, 1);
				ImportOldHistory(array);
			}
			Store.Load();
			Harmony val = new Harmony("recentplayers");
			Type[] types = typeof(Mod).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0)
				{
					try
					{
						val.CreateClassProcessor(type).Patch();
					}
					catch (Exception ex)
					{
						Log.LogError("Failed to apply " + type.Name + ": " + ex.Message);
					}
				}
			}
			Log.LogInfo("Loaded zacharyacoon_recent-players v1.0.6. Recent players file: " + text);
		}

		private static void ImportOldHistory(string[] dirs)
		{
			try
			{
				foreach (string text in dirs)
				{
					if (string.IsNullOrEmpty(text) || !Directory.Exists(text))
					{
						continue;
					}
					string text2 = Path.Combine(text, "mod_zacharyacoon_recent-players.json");
					string text3 = Path.Combine(text, "zacharyacoon_recent-players.json");
					string[] array = ((!File.Exists(text2)) ? ((!File.Exists(text3)) ? Directory.GetFiles(text, "mod_recent-players_v*.json") : new string[1] { text3 }) : new string[1] { text2 });
					if (array.Length != 0)
					{
						Array.Sort(array, (string a, string b) => File.GetLastWriteTimeUtc(b).CompareTo(File.GetLastWriteTimeUtc(a)));
						Store.ImportFrom(array[0]);
						Log.LogInfo("Imported recent players from " + array[0]);
						break;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning("Could not import an earlier recent players file: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "AddUserToPlayerList")]
	internal static class RecordPlayerPatch
	{
		private static void Postfix(object[] __args)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			try
			{
				if (__args.Length < 2)
				{
					return;
				}
				object obj = __args[0];
				ulong num = default(ulong);
				int num2;
				if (obj is ulong)
				{
					num = (ulong)obj;
					num2 = 1;
				}
				else
				{
					num2 = 0;
				}
				if (num2 == 0)
				{
					return;
				}
				string username = __args[1] as string;
				if (!SteamClient.IsValid || num != SteamClient.SteamId.Value)
				{
					GameNetworkManager instance = GameNetworkManager.Instance;
					long num3;
					if (!((Object)(object)instance != (Object)null) || !instance.currentLobby.HasValue)
					{
						num3 = 0L;
					}
					else
					{
						Lobby value = instance.currentLobby.Value;
						num3 = (long)((Lobby)(ref value)).Id.Value;
					}
					ulong session = (ulong)num3;
					Presence.Joined(num);
					Mod.Store.Encounter(num, username, session);
					RecentPlayersMenu.RefreshIfOpen();
				}
			}
			catch (Exception arg)
			{
				Mod.Log.LogError($"RecordPlayerPatch: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "Start")]
	internal static class QuickMenuStartPatch
	{
		private static void Postfix(QuickMenuManager __instance)
		{
			SafeAttach(__instance);
		}

		internal static void SafeAttach(QuickMenuManager qm)
		{
			try
			{
				RecentPlayersMenu.Attach(qm);
			}
			catch (Exception arg)
			{
				Mod.Log.LogError($"Menu attach failed: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")]
	internal static class QuickMenuOpenPatch
	{
		private static void Postfix(QuickMenuManager __instance)
		{
			QuickMenuStartPatch.SafeAttach(__instance);
			RecentPlayersMenu.Hide();
		}
	}
	[HarmonyPatch(typeof(QuickMenuManager), "CloseQuickMenu")]
	internal static class QuickMenuClosePatch
	{
		private static void Postfix()
		{
			RecentPlayersMenu.Hide();
		}
	}
	[BepInPlugin("recentplayers", "Recent Players", "1.0.6")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			ManualLogSource log = ((BaseUnityPlugin)this).Logger;
			Mod.Log = new ModLogger(delegate(string level, string message)
			{
				if (!(level == "Error"))
				{
					if (level == "Warning")
					{
						log.LogWarning((object)message);
					}
					else
					{
						log.LogInfo((object)message);
					}
				}
				else
				{
					log.LogError((object)message);
				}
			});
			string gameRootPath = Paths.GameRootPath;
			if (File.Exists(Path.Combine(gameRootPath, "version.dll")) && Directory.GetFiles(gameRootPath, "mod_zacharyacoon_recent-players_v*.dll").Length != 0)
			{
				Mod.Log.LogInfo("Standalone build found in " + gameRootPath + "; this BepInEx copy is not starting.");
			}
			else if (Mod.TryClaim("BepInEx"))
			{
				Mod.Init(Paths.ConfigPath, Paths.ConfigPath);
			}
		}
	}
	internal static class Presence
	{
		private static readonly HashSet<ulong> left = new HashSet<ulong>();

		public static HashSet<ulong> Current()
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			HashSet<ulong> hashSet = new HashSet<ulong>();
			try
			{
				StartOfRound instance = StartOfRound.Instance;
				if ((Object)(object)instance != (Object)null && instance.allPlayerScripts != null)
				{
					PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
					foreach (PlayerControllerB val in allPlayerScripts)
					{
						if ((Object)(object)val != (Object)null && val.playerSteamId != 0L && (val.isPlayerControlled || val.isPlayerDead) && !val.disconnectedMidGame)
						{
							hashSet.Add(val.playerSteamId);
						}
					}
				}
				GameNetworkManager instance2 = GameNetworkManager.Instance;
				if ((Object)(object)instance2 != (Object)null && instance2.currentLobby.HasValue)
				{
					Lobby value = instance2.currentLobby.Value;
					foreach (Friend member in ((Lobby)(ref value)).Members)
					{
						hashSet.Add(member.Id.Value);
					}
				}
			}
			catch (Exception ex)
			{
				Mod.Log.LogWarning("Could not read who is in the lobby: " + ex.Message);
			}
			hashSet.ExceptWith(left);
			return hashSet;
		}

		public static void Joined(ulong steamId)
		{
			left.Remove(steamId);
		}

		public static void PlayerLeft(ulong steamId)
		{
			if (steamId != 0)
			{
				left.Add(steamId);
				Mod.Store.Left(new ulong[1] { steamId });
				RecentPlayersMenu.RefreshIfOpen();
			}
		}

		public static void YouLeft()
		{
			HashSet<ulong> steamIds = Current();
			left.Clear();
			Mod.Store.Left(steamIds);
			RecentPlayersMenu.RefreshIfOpen();
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "OnPlayerDC")]
	internal static class PlayerLeftPatch
	{
		private static void Prefix(StartOfRound __instance, int playerObjectNumber, out ulong __state)
		{
			__state = 0uL;
			try
			{
				PlayerControllerB[] allPlayerScripts = __instance.allPlayerScripts;
				if (allPlayerScripts != null && playerObjectNumber >= 0 && playerObjectNumber < allPlayerScripts.Length && (Object)(object)allPlayerScripts[playerObjectNumber] != (Object)null)
				{
					__state = allPlayerScripts[playerObjectNumber].playerSteamId;
				}
			}
			catch (Exception arg)
			{
				Mod.Log.LogError($"PlayerLeftPatch: {arg}");
			}
		}

		private static void Postfix(ulong __state)
		{
			try
			{
				if (!SteamIsMe(__state))
				{
					Presence.PlayerLeft(__state);
				}
			}
			catch (Exception arg)
			{
				Mod.Log.LogError($"PlayerLeftPatch: {arg}");
			}
		}

		private static bool SteamIsMe(ulong id)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return SteamClient.IsValid && id == SteamClient.SteamId.Value;
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	internal static class YouLeftPatch
	{
		private static void Prefix()
		{
			try
			{
				Presence.YouLeft();
			}
			catch (Exception arg)
			{
				Mod.Log.LogError($"YouLeftPatch: {arg}");
			}
		}
	}
	internal static class RecentPlayersMenu
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__Show;

			public static UnityAction <1>__Hide;
		}

		private const string Prefix = "RecentPlayers_";

		private const float TitleScale = 1f;

		private const float RowScale = 0.75f;

		private const float ScreenMargin = 24f;

		private static QuickMenuManager owner;

		private static Button template;

		private static GameObject mainButtons;

		private static RectTransform canvasRect;

		private static GameObject panel;

		private static TMP_FontAsset font;

		private static float baseFontSize = 24f;

		private static Color textColor = Color.white;

		private static TMP_Text menuLabel;

		private static float menuTextScale = 1f;

		private static bool loggedStyle;

		private static GameObject backButton;

		private static GameObject versionLabel;

		private const float VersionScale = 0.375f;

		private const string VersionAlpha = "#80";

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

		public static void Attach(QuickMenuManager qm)
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_01cd: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Expected O, but got Unknown
			if ((Object)(object)qm == (Object)null || ((Object)(object)owner == (Object)(object)qm && (Object)(object)panel != (Object)null))
			{
				return;
			}
			owner = qm;
			panel = null;
			template = FindInviteButton(qm);
			if ((Object)(object)template == (Object)null)
			{
				Mod.Log.LogWarning("Could not find the \"Invite Friends\" button; menu entry not added.");
				return;
			}
			mainButtons = ((Component)((Component)template).transform.parent).gameObject;
			TMP_Text componentInChildren = ((Component)template).GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				font = componentInChildren.font;
				baseFontSize = componentInChildren.fontSize;
				textColor = ((Graphic)componentInChildren).color;
			}
			Canvas[] componentsInParent = ((Component)template).GetComponentsInParent<Canvas>(true);
			canvasRect = ((componentsInParent.Length != 0) ? ((RectTransform)((Component)componentsInParent[^1]).transform) : ((RectTransform)mainButtons.transform.parent));
			GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, ((Component)template).transform.parent);
			((Object)val).name = "RecentPlayers_MenuEntry";
			val.transform.SetSiblingIndex(((Component)template).transform.GetSiblingIndex() + 1);
			SetLabel(val, EntryLabel(GetLabel(((Component)template).gameObject)));
			TMP_Text componentInChildren2 = val.GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren2 != (Object)null)
			{
				componentInChildren2.enableWordWrapping = false;
				componentInChildren2.overflowMode = (TextOverflowModes)0;
			}
			object obj = <>O.<0>__Show;
			if (obj == null)
			{
				UnityAction val2 = Show;
				<>O.<0>__Show = val2;
				obj = (object)val2;
			}
			SetClick(val, (UnityAction)obj);
			MakeRoomBelow((RectTransform)((Component)template).transform, (RectTransform)val.transform);
			panel = BuildPanel();
		}

		public static void Show()
		{
			if (!((Object)(object)panel == (Object)null))
			{
				MatchMenuStyle();
				Rebuild();
				panel.transform.SetAsLastSibling();
				panel.SetActive(true);
				PlacePanel();
				SetMainButtonsVisible(visible: false);
				AddBackButton();
				AddVersionLabel();
				if ((Object)(object)EventSystem.current != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
			}
		}

		public static void Hide()
		{
			if (!((Object)(object)panel == (Object)null) && panel.activeSelf)
			{
				panel.SetActive(false);
				if ((Object)(object)backButton != (Object)null)
				{
					Object.Destroy((Object)(object)backButton);
				}
				backButton = null;
				if ((Object)(object)versionLabel != (Object)null)
				{
					Object.Destroy((Object)(object)versionLabel);
				}
				versionLabel = null;
				SetMainButtonsVisible(visible: true);
			}
		}

		private static void AddBackButton()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = null;
			float num = float.MaxValue;
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			foreach (GameObject hiddenButton in hiddenButtons)
			{
				Button componentInChildren = hiddenButton.GetComponentInChildren<Button>(true);
				if (!((Object)(object)componentInChildren == (Object)null))
				{
					((RectTransform)((Component)componentInChildren).transform).GetWorldCorners(array);
					if (array[0].y < num)
					{
						num = array[0].y;
						val = (RectTransform)((Component)componentInChildren).transform;
					}
				}
			}
			object obj = <>O.<1>__Hide;
			if (obj == null)
			{
				UnityAction val2 = Hide;
				<>O.<1>__Hide = val2;
				obj = (object)val2;
			}
			backButton = AddMenuButton("> Back", 0.75f, (UnityAction)obj, mainButtons.transform);
			RectTransform val3 = (RectTransform)backButton.transform;
			LayoutElement component = backButton.GetComponent<LayoutElement>();
			if ((Object)(object)component != (Object)null)
			{
				component.ignoreLayout = true;
			}
			((Transform)val3).SetAsLastSibling();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			val.GetWorldCorners(array);
			val3.anchorMin = val.anchorMin;
			val3.anchorMax = val.anchorMax;
			val3.pivot = new Vector2(0f, 0.5f);
			Vector3 position = (array[0] + array[1]) * 0.5f;
			if (TryGetBorderBounds(out var bottom, out var top) && panel.transform.childCount > 0)
			{
				RectTransform val4 = (RectTransform)panel.transform.GetChild(0);
				val4.GetWorldCorners(array);
				float num2 = top - array[1].y;
				Rect rect = val3.rect;
				float num3 = ((Rect)(ref rect)).height * ((Transform)val3).lossyScale.y * 0.5f;
				if (num2 > 0f)
				{
					position.y = bottom + num2 + num3;
				}
			}
			((Transform)val3).position = position;
		}

		private static void AddVersionLabel()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = AddText(mainButtons.transform, "", 0.375f);
			versionLabel = ((Component)val).gameObject;
			((Object)versionLabel).name = "RecentPlayers_Version";
			versionLabel.AddComponent<LayoutElement>().ignoreLayout = true;
			((TMP_Text)val).horizontalAlignment = (HorizontalAlignmentOptions)4;
			((TMP_Text)val).text = "<alpha=#80>mod=ZacharyACoon_RecentPlayers_v1.0.6";
			RectTransform val2 = (RectTransform)versionLabel.transform;
			((Transform)val2).SetAsLastSibling();
			val2.pivot = new Vector2(1f, 0f);
			val2.sizeDelta = new Vector2(((TMP_Text)val).preferredWidth, ((TMP_Text)val).preferredHeight);
			if (TryGetBorderRect(out var min, out var max))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				float num = 0f;
				if (panel.transform.childCount > 0)
				{
					((RectTransform)panel.transform.GetChild(0)).GetWorldCorners(array);
					num = max.y - array[1].y;
				}
				if (num <= 0f)
				{
					Rect rect = val2.rect;
					num = ((Rect)(ref rect)).height * ((Transform)val2).lossyScale.y;
				}
				((Transform)val2).position = new Vector3(max.x - num, min.y + num, ((Transform)val2).position.z);
			}
		}

		private static bool TryGetBorderBounds(out float bottom, out float top)
		{
			//IL_000c: 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)
			Vector3 min;
			Vector3 max;
			bool result = TryGetBorderRect(out min, out max);
			bottom = min.y;
			top = max.y;
			return result;
		}

		private static bool TryGetBorderRect(out Vector3 min, out Vector3 max)
		{
			//IL_0011: 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)
			//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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			min = new Vector3(float.MaxValue, float.MaxValue, 0f);
			max = new Vector3(float.MinValue, float.MinValue, 0f);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			Graphic[] componentsInChildren = mainButtons.GetComponentsInChildren<Graphic>(false);
			foreach (Graphic val in componentsInChildren)
			{
				if (((Behaviour)val).enabled && !((Object)(object)((Component)val).gameObject == (Object)(object)versionLabel) && !((Object)(object)((Component)val).GetComponentInParent<Button>() != (Object)null))
				{
					((RectTransform)((Component)val).transform).GetWorldCorners(array);
					Vector3[] array2 = array;
					foreach (Vector3 val2 in array2)
					{
						min = Vector3.Min(min, val2);
						max = Vector3.Max(max, val2);
					}
				}
			}
			return max.y > min.y && max.x > min.x;
		}

		private static void SetMainButtonsVisible(bool visible)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			if ((Object)(object)mainButtons == (Object)null)
			{
				return;
			}
			if (visible)
			{
				foreach (GameObject hiddenButton in hiddenButtons)
				{
					if ((Object)(object)hiddenButton != (Object)null)
					{
						hiddenButton.SetActive(true);
					}
				}
				hiddenButtons.Clear();
				return;
			}
			foreach (Transform item in mainButtons.transform)
			{
				Transform val = item;
				if (((Component)val).gameObject.activeSelf && !((Object)(object)((Component)val).GetComponentInChildren<Button>(true) == (Object)null))
				{
					((Component)val).gameObject.SetActive(false);
					hiddenButtons.Add(((Component)val).gameObject);
				}
			}
		}

		public static void RefreshIfOpen()
		{
			if ((Object)(object)panel != (Object)null && panel.activeSelf)
			{
				Rebuild();
			}
		}

		private static GameObject BuildPanel()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("RecentPlayers_Panel", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)canvasRect, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 1f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(0f, 1f);
			VerticalLayoutGroup val4 = val.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)val4).childAlignment = (TextAnchor)0;
			((HorizontalOrVerticalLayoutGroup)val4).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val4).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val4).childScaleWidth = true;
			((HorizontalOrVerticalLayoutGroup)val4).childScaleHeight = true;
			((HorizontalOrVerticalLayoutGroup)val4).spacing = 4f;
			ContentSizeFitter val5 = val.AddComponent<ContentSizeFitter>();
			val5.horizontalFit = (FitMode)2;
			val5.verticalFit = (FitMode)2;
			val.SetActive(false);
			return val;
		}

		private static void MatchMenuStyle()
		{
			//IL_00aa: 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_00f6: 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_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_007f: 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)
			//IL_012f: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Expected O, but got Unknown
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_0248: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = (menuLabel = ((Component)template).GetComponentInChildren<TMP_Text>(true));
			if ((Object)(object)val != (Object)null)
			{
				if (((Component)val).gameObject.activeInHierarchy)
				{
					val.ForceMeshUpdate(false, false);
				}
				if (val.fontSize > 0f)
				{
					baseFontSize = val.fontSize;
				}
				if (val.transform.lossyScale.y > 0f)
				{
					menuTextScale = val.transform.lossyScale.y;
				}
				font = val.font;
				textColor = ((Graphic)val).color;
			}
			float y = ((Transform)canvasRect).lossyScale.y;
			float y2 = mainButtons.transform.lossyScale.y;
			float num = ((y > 0f && y2 > 0f) ? (y2 / y) : 1f);
			panel.transform.localScale = new Vector3(num, num, 1f);
			if (!loggedStyle && (Object)(object)val != (Object)null)
			{
				loggedStyle = true;
				RectTransform val2 = (RectTransform)val.transform;
				RectTransform val3 = (RectTransform)((Component)template).transform;
				Mod.Log.LogInfo($"Esc menu text: \"{val.text}\" size={val.fontSize} auto={val.enableAutoSizing} " + "style=" + ((val.textStyle != null) ? (val.textStyle.name + " " + val.textStyle.styleOpeningDefinition) : "none") + " " + $"rich={val.richText} align={val.alignment} labelScale={((Transform)val2).lossyScale.y} buttonScale={((Transform)val3).lossyScale.y} " + $"canvasScale={y} labelRect={val2.rect} buttonRect={val3.rect} transition={((Selectable)template).transition}");
			}
		}

		private static void ApplyMenuLook(TMP_Text tmp, float scale)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)menuLabel != (Object)null && (Object)(object)tmp != (Object)(object)menuLabel)
			{
				tmp.font = menuLabel.font;
				tmp.fontSharedMaterial = menuLabel.fontSharedMaterial;
				tmp.fontStyle = menuLabel.fontStyle;
				tmp.characterSpacing = menuLabel.characterSpacing;
				((Graphic)tmp).color = ((Graphic)menuLabel).color;
				tmp.styleSheet = menuLabel.styleSheet;
				tmp.textStyle = menuLabel.textStyle;
			}
			else if ((Object)(object)font != (Object)null)
			{
				tmp.font = font;
			}
			tmp.richText = true;
			tmp.enableAutoSizing = false;
			tmp.enableWordWrapping = false;
			tmp.overflowMode = (TextOverflowModes)0;
			tmp.horizontalAlignment = (HorizontalAlignmentOptions)1;
			float y = tmp.transform.lossyScale.y;
			tmp.fontSize = baseFontSize * scale * ((y > 0f) ? (menuTextScale / y) : 1f);
		}

		private static string Literal(string s)
		{
			return "<noparse>" + Regex.Replace(s ?? "", "</?noparse>", "", RegexOptions.IgnoreCase) + "</noparse>";
		}

		private static void PlacePanel()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			float num = float.MinValue;
			float num2 = float.MaxValue;
			foreach (Transform item in mainButtons.transform)
			{
				Transform val = item;
				if (((Component)val).gameObject.activeInHierarchy && !((Object)(object)((Component)val).GetComponent<Button>() == (Object)null))
				{
					((RectTransform)val).GetWorldCorners(array);
					Vector3 val2 = ((Transform)canvasRect).InverseTransformPoint(array[1]);
					num = Mathf.Max(num, val2.y);
					num2 = Mathf.Min(num2, val2.x);
				}
			}
			Rect rect = canvasRect.rect;
			if (num == float.MinValue)
			{
				num = ((Rect)(ref rect)).yMax - 96f;
				num2 = ((Rect)(ref rect)).xMin + 48f;
			}
			RectTransform val3 = (RectTransform)panel.transform;
			float num3 = Mathf.Max(num2 - ((Rect)(ref rect)).xMin, 24f);
			float num4 = -48f;
			val3.anchoredPosition = new Vector2(num3, num4);
			LayoutRebuilder.ForceRebuildLayoutImmediate(val3);
			float num5 = ((Rect)(ref rect)).height - 96f;
			Rect rect2 = val3.rect;
			float num6 = ((Rect)(ref rect2)).height * ((Transform)val3).localScale.y;
			if (num6 > num5 && num6 > 0f)
			{
				((Transform)val3).localScale = ((Transform)val3).localScale * (num5 / num6);
			}
		}

		private static void Rebuild()
		{
			for (int num = panel.transform.childCount - 1; num >= 0; num--)
			{
				GameObject gameObject = ((Component)panel.transform.GetChild(num)).gameObject;
				gameObject.SetActive(false);
				Object.Destroy((Object)(object)gameObject);
			}
			AddText(panel.transform, "Recent players", 1f);
			IReadOnlyList<RecentPlayer> players = Mod.Store.Players;
			if (players.Count == 0)
			{
				AddText(panel.transform, "> No recent players yet", 0.75f);
			}
			HashSet<ulong> hashSet = Presence.Current();
			List<RecentPlayer> list = new List<RecentPlayer>();
			List<RecentPlayer> list2 = new List<RecentPlayer>();
			foreach (RecentPlayer item in players)
			{
				((ulong.TryParse(item.steamId, out var result) && hashSet.Contains(result)) ? list : list2).Add(item);
			}
			foreach (RecentPlayer item2 in list)
			{
				AddPlayerRow(item2, inLobby: true);
			}
			foreach (RecentPlayer item3 in list2)
			{
				AddPlayerRow(item3, inLobby: false);
			}
		}

		private static void AddPlayerRow(RecentPlayer player, bool inLobby)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			string text = (inLobby ? "now" : TimeAgo(player.lastSeenUtc));
			string text2 = Literal(player.username);
			string text3 = ((text == null) ? "" : (" <size=0.8775em>(" + text + ")</size>"));
			AddMenuButton("> " + text2 + text3, 0.75f, (UnityAction)delegate
			{
				OpenProfile(player);
			});
		}

		private static GameObject AddMenuButton(string text, float scale, UnityAction onClick, Transform parent = null)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0053: 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_0111: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)((Component)template).transform;
			GameObject val2 = Object.Instantiate<GameObject>(((Component)template).gameObject, ((Object)(object)parent != (Object)null) ? parent : panel.transform, false);
			((Object)val2).name = "RecentPlayers_Button";
			val2.SetActive(true);
			val2.transform.localScale = ((Transform)val).localScale * scale;
			CanvasGroup[] componentsInChildren = val2.GetComponentsInChildren<CanvasGroup>(true);
			foreach (CanvasGroup val3 in componentsInChildren)
			{
				val3.alpha = 1f;
				val3.interactable = true;
				val3.blocksRaycasts = true;
			}
			Button component = val2.GetComponent<Button>();
			((Selectable)component).interactable = true;
			SetClick(val2, onClick);
			TMP_Text componentInChildren = val2.GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				ApplyMenuLook(componentInChildren, scale);
				componentInChildren.text = text;
			}
			LayoutElement val4 = val2.GetComponent<LayoutElement>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = val2.AddComponent<LayoutElement>();
			}
			val4.ignoreLayout = false;
			LayoutElement obj = val4;
			Rect rect = val.rect;
			obj.minWidth = ((Rect)(ref rect)).width;
			LayoutElement obj2 = val4;
			rect = val.rect;
			obj2.preferredWidth = ((Rect)(ref rect)).width;
			LayoutElement obj3 = val4;
			LayoutElement obj4 = val4;
			rect = val.rect;
			float minHeight = (obj4.preferredHeight = ((Rect)(ref rect)).height);
			obj3.minHeight = minHeight;
			LayoutElement obj5 = val4;
			minHeight = (val4.flexibleHeight = -1f);
			obj5.flexibleWidth = minHeight;
			return val2;
		}

		private static TextMeshProUGUI AddText(Transform parent, string text, float scale)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("RecentPlayers_Text", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((Graphic)val2).color = textColor;
			ApplyMenuLook((TMP_Text)(object)val2, scale);
			((Graphic)val2).raycastTarget = false;
			((TMP_Text)val2).text = text;
			return val2;
		}

		private static void OpenProfile(RecentPlayer player)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (!ulong.TryParse(player.steamId, out var result))
			{
				return;
			}
			try
			{
				if (SteamClient.IsValid && SteamUtils.IsOverlayEnabled)
				{
					SteamFriends.OpenUserOverlay(SteamId.op_Implicit(result), "steamid");
					return;
				}
			}
			catch (Exception ex)
			{
				Mod.Log.LogWarning("Steam overlay unavailable: " + ex.Message);
			}
			Application.OpenURL("https://steamcommunity.com/profiles/" + result);
		}

		private static string TimeAgo(string isoUtc)
		{
			if (!DateTime.TryParse(isoUtc, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var result))
			{
				return null;
			}
			TimeSpan timeSpan = DateTime.UtcNow - result.ToUniversalTime();
			if (timeSpan.TotalMinutes < 1.0)
			{
				return Plural(Math.Max(0, (int)timeSpan.TotalSeconds), "second");
			}
			if (timeSpan.TotalHours < 1.0)
			{
				return Plural((int)timeSpan.TotalMinutes, "minute");
			}
			if (timeSpan.TotalDays < 1.0)
			{
				return Plural((int)timeSpan.TotalHours, "hour");
			}
			return Plural((int)timeSpan.TotalDays, "day");
		}

		private static string Plural(int n, string unit)
		{
			return string.Format("{0} {1}{2}", n, unit, (n == 1) ? "" : "s");
		}

		private static Button FindInviteButton(QuickMenuManager qm)
		{
			GameObject value = Traverse.Create((object)qm).Field("menuContainer").GetValue<GameObject>();
			Transform val = (((Object)(object)value != (Object)null) ? value.transform : ((Component)qm).transform);
			return Search(((Component)val).GetComponentsInChildren<Button>(true)) ?? Search(Object.FindObjectsOfType<Button>(true));
		}

		private static Button Search(IEnumerable<Button> buttons)
		{
			foreach (Button button in buttons)
			{
				if (!((Object)(object)button == (Object)null) && !((Object)button).name.StartsWith("RecentPlayers_"))
				{
					string label = GetLabel(((Component)button).gameObject);
					if (label != null && label.IndexOf("invite", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return button;
					}
				}
			}
			return null;
		}

		private static string EntryLabel(string original)
		{
			if (original == null || !Regex.IsMatch(original, "invite\\s+friends", RegexOptions.IgnoreCase))
			{
				return "Recent players";
			}
			return Regex.Replace(original, "invite\\s+friends", "Recent players", RegexOptions.IgnoreCase);
		}

		private static void MakeRoomBelow(RectTransform anchor, RectTransform inserted)
		{
			//IL_0020: 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_0053: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_008b: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Transform)anchor).parent;
			if ((Object)(object)((Component)parent).GetComponent<LayoutGroup>() != (Object)null)
			{
				return;
			}
			float y = anchor.anchoredPosition.y;
			float num = 0f;
			List<RectTransform> list = new List<RectTransform>();
			foreach (Transform item in parent)
			{
				Transform val = item;
				if ((Object)(object)val == (Object)(object)anchor || (Object)(object)val == (Object)(object)inserted || (Object)(object)((Component)val).GetComponent<Button>() == (Object)null)
				{
					continue;
				}
				RectTransform val2 = (RectTransform)val;
				if (!(val2.anchoredPosition.y >= y))
				{
					list.Add(val2);
					float num2 = y - val2.anchoredPosition.y;
					if (num == 0f || num2 < num)
					{
						num = num2;
					}
				}
			}
			if (num == 0f)
			{
				Rect rect = anchor.rect;
				num = ((Rect)(ref rect)).height * 1.2f;
			}
			inserted.anchoredPosition = anchor.anchoredPosition - new Vector2(0f, num);
			foreach (RectTransform item2 in list)
			{
				item2.anchoredPosition -= new Vector2(0f, num);
			}
		}

		private static string GetLabel(GameObject go)
		{
			TMP_Text componentInChildren = go.GetComponentInChildren<TMP_Text>(true);
			return (componentInChildren != null) ? componentInChildren.text : null;
		}

		private static void SetLabel(GameObject go, string text)
		{
			TMP_Text componentInChildren = go.GetComponentInChildren<TMP_Text>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				componentInChildren.text = text;
			}
		}

		private static void SetClick(GameObject go, UnityAction onClick)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			Button component = go.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			if (onClick != null)
			{
				((UnityEvent)component.onClick).AddListener(onClick);
			}
			else
			{
				((Selectable)component).interactable = false;
			}
		}
	}
	public class RecentPlayer
	{
		public string steamId;

		public string username;

		public string lastSeenUtc;
	}
	public class ModInfo
	{
		public string name = "zacharyacoon_recent-players";

		public string version = "1.0.6";
	}
	public class RecentPlayersFile
	{
		public ModInfo mod = new ModInfo();

		public List<RecentPlayer> players = new List<RecentPlayer>();
	}
	internal class RecentPlayersStore
	{
		private readonly string path;

		private readonly int capacity;

		private readonly List<RecentPlayer> players = new List<RecentPlayer>();

		private readonly HashSet<ulong> seenThisSession = new HashSet<ulong>();

		private ulong sessionKey;

		public IReadOnlyList<RecentPlayer> Players => players;

		public RecentPlayersStore(string path, int capacity)
		{
			this.path = path;
			this.capacity = capacity;
		}

		public void Load()
		{
			LoadFile(path);
		}

		public void ImportFrom(string otherPath)
		{
			LoadFile(otherPath);
			if (players.Count > 0)
			{
				Save();
			}
		}

		private void LoadFile(string path)
		{
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				RecentPlayersFile recentPlayersFile = JsonConvert.DeserializeObject<RecentPlayersFile>(File.ReadAllText(path));
				players.Clear();
				if (recentPlayersFile?.players == null)
				{
					return;
				}
				foreach (RecentPlayer p in recentPlayersFile.players)
				{
					if (p != null && ulong.TryParse(p.steamId, out var _) && !players.Exists((RecentPlayer x) => x.steamId == p.steamId))
					{
						players.Add(p);
						if (players.Count == capacity)
						{
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Mod.Log.LogError("Could not read " + path + ": " + ex.Message);
			}
		}

		public bool Encounter(ulong steamId, string username, ulong session)
		{
			if (steamId == 0)
			{
				return false;
			}
			if (session != sessionKey)
			{
				sessionKey = session;
				seenThisSession.Clear();
			}
			if (!seenThisSession.Add(steamId))
			{
				return false;
			}
			string id = steamId.ToString();
			players.RemoveAll((RecentPlayer p) => p.steamId == id);
			players.Insert(0, new RecentPlayer
			{
				steamId = id,
				username = (string.IsNullOrEmpty(username) ? "Unknown" : username),
				lastSeenUtc = DateTime.UtcNow.ToString("o")
			});
			if (players.Count > capacity)
			{
				players.RemoveRange(capacity, players.Count - capacity);
			}
			Save();
			return true;
		}

		public bool Left(ICollection<ulong> steamIds)
		{
			List<RecentPlayer> list = new List<RecentPlayer>();
			string lastSeenUtc = DateTime.UtcNow.ToString("o");
			foreach (RecentPlayer player in players)
			{
				if (ulong.TryParse(player.steamId, out var result) && steamIds.Contains(result))
				{
					player.lastSeenUtc = lastSeenUtc;
					list.Add(player);
				}
			}
			foreach (ulong steamId in steamIds)
			{
				seenThisSession.Remove(steamId);
			}
			if (list.Count == 0)
			{
				return false;
			}
			players.RemoveAll(list.Contains);
			players.InsertRange(0, list);
			Save();
			return true;
		}

		private void Save()
		{
			try
			{
				string sourceFileName = path + ".tmp";
				File.WriteAllText(sourceFileName, JsonConvert.SerializeObject((object)new RecentPlayersFile
				{
					mod = new ModInfo(),
					players = players
				}, (Formatting)1));
				if (File.Exists(path))
				{
					File.Delete(path);
				}
				File.Move(sourceFileName, path);
			}
			catch (Exception ex)
			{
				Mod.Log.LogError("Could not write " + path + ": " + ex.Message);
			}
		}
	}
	internal static class ModVersion
	{
		public const string Value = "1.0.6";

		public const string Numeric = "1.0.6";
	}
}