Decompiled source of FriendBPSort v2.0.0

FriendBPSort.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading;
using FriendBPSort;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppRUMBLE.Interactions.InteractionBase;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Social;
using Il2CppRUMBLE.Social.Phone;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Mod), "FriendBPSort", "0.3.3", "Colli", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : System.Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableAttribute : System.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]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableContextAttribute : System.Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : System.Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FriendBPSort
{
	public sealed class Mod : MelonMod
	{
		private sealed class SideButton
		{
			internal GameObject Object;

			internal TMP_Text Label;

			internal SortMode Mode;

			internal string Caption;
		}

		private sealed class RowValue
		{
			internal PlayerTag Tag;

			internal GameObject Box;

			internal TMP_Text Text;

			internal string Master;

			internal string Title;

			internal string Key;
		}

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

			public static Func<MelonMod, bool> <>9__12_0;

			public static FileSystemEventHandler <>9__19_0;

			public static FileSystemEventHandler <>9__19_1;

			public static FileSystemEventHandler <>9__19_2;

			public static RenamedEventHandler <>9__19_3;

			public static ErrorEventHandler <>9__19_4;

			public static Func<ScrollableItem, bool> <>9__45_0;

			public static Action<bool> <>9__45_1;

			public static Func<SideButton, bool> <>9__50_0;

			public static Func<KeyValuePair<int, FriendList>, bool> <>9__50_1;

			public static Func<KeyValuePair<int, FriendList>, int> <>9__50_2;

			public static Func<ScrollableItem, bool> <>9__50_3;

			public static Predicate<SideButton> <>9__50_4;

			public static Func<ScrollableItem, PlayerTag> <>9__50_5;

			public static Func<PlayerTag, bool> <>9__50_6;

			public static Func<MeshFilter, bool> <>9__53_0;

			internal bool <get_MatchInfoPresent>b__12_0(MelonMod m)
			{
				MelonInfoAttribute info = ((MelonBase)m).Info;
				return string.Equals((info != null) ? info.Name : null, "MatchInfo", (StringComparison)5);
			}

			internal void <WatchMatches>b__19_0(object _, FileSystemEventArgs __)
			{
				Interlocked.Exchange(ref matchFileChanged, 1);
			}

			internal void <WatchMatches>b__19_1(object _, FileSystemEventArgs __)
			{
				Interlocked.Exchange(ref matchFileChanged, 1);
			}

			internal void <WatchMatches>b__19_2(object _, FileSystemEventArgs __)
			{
				Interlocked.Exchange(ref matchFileChanged, 1);
			}

			internal void <WatchMatches>b__19_3(object _, RenamedEventArgs __)
			{
				Interlocked.Exchange(ref matchFileChanged, 1);
			}

			internal void <WatchMatches>b__19_4(object _, ErrorEventArgs __)
			{
				Interlocked.Exchange(ref matchFileChanged, 1);
			}

			internal bool <RefreshUnified>b__45_0(ScrollableItem item)
			{
				if (item == null)
				{
					return false;
				}
				PlayerTag obj = ((Il2CppObjectBase)item).TryCast<PlayerTag>();
				return ((obj != null) ? new bool?(obj.isInitializing) : ((bool?)null)) == true;
			}

			internal void <RefreshUnified>b__45_1(bool _)
			{
			}

			internal bool <OnUpdate>b__50_0(SideButton b)
			{
				return IsMatch(b.Mode);
			}

			internal bool <OnUpdate>b__50_1(KeyValuePair<int, FriendList> p)
			{
				return !Object.op_Implicit((Object)(object)p.Value);
			}

			internal int <OnUpdate>b__50_2(KeyValuePair<int, FriendList> p)
			{
				return p.Key;
			}

			internal bool <OnUpdate>b__50_3(ScrollableItem item)
			{
				if (item == null)
				{
					return false;
				}
				PlayerTag obj = ((Il2CppObjectBase)item).TryCast<PlayerTag>();
				return ((obj != null) ? new bool?(obj.isInitializing) : ((bool?)null)) == true;
			}

			internal bool <OnUpdate>b__50_4(SideButton b)
			{
				return !Object.op_Implicit((Object)(object)b.Object);
			}

			internal PlayerTag <OnUpdate>b__50_5(ScrollableItem i)
			{
				if (i == null)
				{
					return null;
				}
				return ((Il2CppObjectBase)i).TryCast<PlayerTag>();
			}

			internal bool <OnUpdate>b__50_6(PlayerTag t)
			{
				if (Object.op_Implicit((Object)(object)t) && Object.op_Implicit((Object)(object)t.username))
				{
					return Object.op_Implicit((Object)(object)t.moreInfoButton);
				}
				return false;
			}

			internal bool <CreateRowBox>b__53_0(MeshFilter m)
			{
				//IL_0040: 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_0048: 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)
				if (Object.op_Implicit((Object)(object)m.sharedMesh) && Object.op_Implicit((Object)(object)((Component)m).GetComponent<MeshRenderer>()) && !Object.op_Implicit((Object)(object)((Component)m).GetComponent<TMP_Text>()) && !((Object)m).name.StartsWith("FriendBPSort", (StringComparison)4))
				{
					Bounds bounds = ((Component)m).GetComponent<Renderer>().bounds;
					Vector3 size = ((Bounds)(ref bounds)).size;
					return ((Vector3)(ref size)).magnitude < 0.65f;
				}
				return false;
			}
		}

		private static readonly Dictionary<int, FriendList> lists = new Dictionary<int, FriendList>();

		private static readonly Dictionary<int, List<SideButton>> controls = new Dictionary<int, List<SideButton>>();

		private static readonly Dictionary<string, int> points = new Dictionary<string, int>((IEqualityComparer<string>)(object)StringComparer.Ordinal);

		private static readonly Dictionary<int, RowValue> rowValues = new Dictionary<int, RowValue>();

		private static readonly string[] captions = new string[6] { "SORT A–Z", "SORT BY BP", "FRIEND ADDED", "RECENTLY PLAYED", "WLR", "TOTAL MATCHES" };

		private static readonly MatchStats matches = new MatchStats();

		private static readonly Dictionary<int, string> summaries = new Dictionary<int, string>();

		private static bool inverse;

		private static bool matchWarning;

		private static float nextMatchRead;

		private static FileSystemWatcher matchWatcher;

		private static int matchFileChanged = 1;

		private static int matchReadRetries;

		private static MelonPreferences_Entry<bool> savedInverse;

		private static SortHistory history = new SortHistory();

		private static SortMode mode;

		private static MelonPreferences_Category preferences;

		private static MelonPreferences_Entry<int> savedMode;

		private static MelonPreferences_Entry<string> savedHistory;

		private static bool dirty;

		private static bool historyDirty;

		private static bool stopped;

		private static bool warnedMissingAsset;

		private static bool resetPage;

		private static float nextTick;

		private static float nextAssetSearch;

		private static float nextSave;

		private static GameObject staging;

		private static Material backboardMaterial;

		private static InteractionButton stoneButton;

		private static bool rendering;

		private static bool MatchInfoPresent => Enumerable.Any<MelonMod>((System.Collections.Generic.IEnumerable<MelonMod>)MelonTypeBase<MelonMod>.RegisteredMelons, (Func<MelonMod, bool>)delegate(MelonMod m)
		{
			MelonInfoAttribute info = ((MelonBase)m).Info;
			return string.Equals((info != null) ? info.Name : null, "MatchInfo", (StringComparison)5);
		});

		private static string MatchPath => Path.Combine(MelonEnvironment.UserDataDirectory, "MatchInfo", "MatchInfo.txt");

		private static void WatchMatches(bool present)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00bd: 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_00c8: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			if (!present)
			{
				FileSystemWatcher obj = matchWatcher;
				if (obj != null)
				{
					((Component)obj).Dispose();
				}
				matchWatcher = null;
			}
			else
			{
				if (matchWatcher != null)
				{
					return;
				}
				string directoryName = Path.GetDirectoryName(MatchPath);
				if (!Directory.Exists(directoryName))
				{
					return;
				}
				matchWatcher = new FileSystemWatcher(directoryName, "MatchInfo.txt");
				matchWatcher.NotifyFilter = (NotifyFilters)25;
				FileSystemWatcher obj2 = matchWatcher;
				object obj3 = <>c.<>9__19_0;
				if (obj3 == null)
				{
					FileSystemEventHandler val = delegate
					{
						Interlocked.Exchange(ref matchFileChanged, 1);
					};
					<>c.<>9__19_0 = val;
					obj3 = (object)val;
				}
				obj2.Changed += (FileSystemEventHandler)obj3;
				FileSystemWatcher obj4 = matchWatcher;
				object obj5 = <>c.<>9__19_1;
				if (obj5 == null)
				{
					FileSystemEventHandler val2 = delegate
					{
						Interlocked.Exchange(ref matchFileChanged, 1);
					};
					<>c.<>9__19_1 = val2;
					obj5 = (object)val2;
				}
				obj4.Created += (FileSystemEventHandler)obj5;
				FileSystemWatcher obj6 = matchWatcher;
				object obj7 = <>c.<>9__19_2;
				if (obj7 == null)
				{
					FileSystemEventHandler val3 = delegate
					{
						Interlocked.Exchange(ref matchFileChanged, 1);
					};
					<>c.<>9__19_2 = val3;
					obj7 = (object)val3;
				}
				obj6.Deleted += (FileSystemEventHandler)obj7;
				FileSystemWatcher obj8 = matchWatcher;
				object obj9 = <>c.<>9__19_3;
				if (obj9 == null)
				{
					RenamedEventHandler val4 = delegate
					{
						Interlocked.Exchange(ref matchFileChanged, 1);
					};
					<>c.<>9__19_3 = val4;
					obj9 = (object)val4;
				}
				obj8.Renamed += (RenamedEventHandler)obj9;
				FileSystemWatcher obj10 = matchWatcher;
				object obj11 = <>c.<>9__19_4;
				if (obj11 == null)
				{
					ErrorEventHandler val5 = delegate
					{
						Interlocked.Exchange(ref matchFileChanged, 1);
					};
					<>c.<>9__19_4 = val5;
					obj11 = (object)val5;
				}
				obj10.Error += (ErrorEventHandler)obj11;
				matchWatcher.EnableRaisingEvents = true;
				Interlocked.Exchange(ref matchFileChanged, 1);
			}
		}

		private static bool IsMatch(SortMode value)
		{
			if (value != SortMode.Wins && value != SortMode.Losses)
			{
				return value == SortMode.TotalMatches;
			}
			return true;
		}

		private static string Key(UserSearchResult f)
		{
			object obj;
			if (string.IsNullOrWhiteSpace((f != null) ? f.PlayFabMasterId : null))
			{
				obj = ((f != null) ? f.PlayFabTitleId : null);
				if (obj == null)
				{
					return "";
				}
			}
			else
			{
				obj = f.PlayFabMasterId;
			}
			return (string)obj;
		}

		private static string Key(UserData u)
		{
			object obj;
			if (string.IsNullOrWhiteSpace((u != null) ? u.playFabMasterId : null))
			{
				obj = ((u != null) ? u.playFabTitleId : null);
				if (obj == null)
				{
					return "";
				}
			}
			else
			{
				obj = u.playFabMasterId;
			}
			return (string)obj;
		}

		private static int BP(UserSearchResult f)
		{
			int result = default(int);
			if (!points.TryGetValue(Key(f), ref result))
			{
				return -1;
			}
			return result;
		}

		public override void OnInitializeMelon()
		{
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Expected O, but got Unknown
			preferences = MelonPreferences.CreateCategory("FriendBPSort");
			savedMode = preferences.CreateEntry<int>("SortMode", 0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			savedInverse = preferences.CreateEntry<bool>("Inverse", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			inverse = savedInverse.Value;
			savedHistory = preferences.CreateEntry<string>("SortHistory", "", (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			mode = (System.Enum.IsDefined(typeof(SortMode), (object)savedMode.Value) ? ((SortMode)savedMode.Value) : SortMode.Alphabetical);
			if (!string.IsNullOrWhiteSpace(savedHistory.Value))
			{
				try
				{
					history = JsonSerializer.Deserialize<SortHistory>(savedHistory.Value, (JsonSerializerOptions)null) ?? new SortHistory();
					SortHistory sortHistory = history;
					if (sortHistory.KnownFriends == null)
					{
						HashSet<string> val = (sortHistory.KnownFriends = new HashSet<string>());
					}
					sortHistory = history;
					if (sortHistory.Added == null)
					{
						Dictionary<string, long> val3 = (sortHistory.Added = new Dictionary<string, long>());
					}
					sortHistory = history;
					if (sortHistory.Played == null)
					{
						Dictionary<string, long> val3 = (sortHistory.Played = new Dictionary<string, long>());
					}
				}
				catch (System.Exception ex)
				{
					MelonLogger.Warning("\ud83d\udc31 Sort history could not be read: " + ex.Message);
					history = new SortHistory();
				}
			}
			BindingFlags val6 = (BindingFlags)40;
			((MelonBase)this).HarmonyInstance.Patch((MethodBase)(object)typeof(FriendList).GetMethod("Refresh"), new HarmonyMethod(typeof(Mod).GetMethod("RefreshUnified", val6)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			((MelonBase)this).HarmonyInstance.Patch((MethodBase)(object)typeof(FriendHandler).GetMethod("AddRecentlyMetPlayer"), (HarmonyMethod)null, new HarmonyMethod(typeof(Mod).GetMethod("MetPlayer", val6)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MelonLogger.Msg("FriendBPSort: four sort buttons ready; two additional match-stat buttons require MatchInfo. Historical friend dates are unknown; new additions and encounters are tracked locally.");
		}

		private static bool Snapshot()
		{
			bool result = false;
			List<UserData> userDataList = UserDataManager.userDataList;
			if (userDataList != null)
			{
				Enumerator<UserData> enumerator = userDataList.GetEnumerator();
				int num = default(int);
				while (enumerator.MoveNext())
				{
					UserData current = enumerator.Current;
					if (current != null && current.battlePoints >= 0)
					{
						string text = Key(current);
						if (text.Length != 0 && (!points.TryGetValue(text, ref num) || num != current.battlePoints))
						{
							points[text] = current.battlePoints;
							result = true;
						}
					}
				}
			}
			return result;
		}

		private static int CompareFriends(GetFriendsResult a, GetFriendsResult b)
		{
			return Ranking.Compare(mode, BP((UserSearchResult)(object)a), (a != null) ? ((UserSearchResult)a).PublicName : null, Key((UserSearchResult)(object)a), IsMatch(mode) ? matches.Value(mode, (a != null) ? ((UserSearchResult)a).PlayFabMasterId : null) : history.Date(mode, (a != null) ? ((UserSearchResult)a).PlayFabMasterId : null, (a != null) ? ((UserSearchResult)a).PlayFabTitleId : null), BP((UserSearchResult)(object)b), (b != null) ? ((UserSearchResult)b).PublicName : null, Key((UserSearchResult)(object)b), IsMatch(mode) ? matches.Value(mode, (b != null) ? ((UserSearchResult)b).PlayFabMasterId : null) : history.Date(mode, (b != null) ? ((UserSearchResult)b).PlayFabMasterId : null, (b != null) ? ((UserSearchResult)b).PlayFabTitleId : null), inverse);
		}

		private static bool RefreshUnified(FriendList __instance)
		{
			if (rendering)
			{
				return false;
			}
			EnsureAvailableSort();
			lists[((Object)__instance).GetInstanceID()] = __instance;
			Il2CppReferenceArray<ScrollableItem> scrollableItems = ((ScrollableList)__instance).ScrollableItems;
			if (scrollableItems == null)
			{
				return true;
			}
			if (Enumerable.Any<ScrollableItem>((System.Collections.Generic.IEnumerable<ScrollableItem>)scrollableItems, (Func<ScrollableItem, bool>)delegate(ScrollableItem item)
			{
				if (item == null)
				{
					return false;
				}
				PlayerTag obj2 = ((Il2CppObjectBase)item).TryCast<PlayerTag>();
				return ((obj2 != null) ? new bool?(obj2.isInitializing) : ((bool?)null)) == true;
			}))
			{
				dirty = true;
				return false;
			}
			rendering = true;
			try
			{
				Snapshot();
				List<GetFriendsResult> friendsWithTag = FriendHandler.GetFriendsWithTag(__instance.listeningToTags);
				if (friendsWithTag == null)
				{
					return true;
				}
				List<GetFriendsResult> val = new List<GetFriendsResult>();
				Enumerator<GetFriendsResult> enumerator = friendsWithTag.GetEnumerator();
				while (enumerator.MoveNext())
				{
					GetFriendsResult current = enumerator.Current;
					if (current != null)
					{
						val.Add(current);
					}
				}
				val.Sort((Comparison<GetFriendsResult>)CompareFriends);
				string text = "NO MATCH DATA";
				if (IsMatch(mode) && val.Count > 0)
				{
					GetFriendsResult val2 = val[0];
					MatchRecord matchRecord = matches.Find(((UserSearchResult)val2).PlayFabMasterId);
					if (matchRecord != null)
					{
						string text2 = Ranking.PlainName(((UserSearchResult)val2).PublicName).Replace("\n", " ").Replace("\r", " ");
						if (text2.Length > 12)
						{
							text2 = text2.Substring(0, 12) + "…";
						}
						text = string.Concat(new string[6]
						{
							text2,
							": ",
							matchRecord.Wins.ToString(),
							"W / ",
							matchRecord.Losses.ToString(),
							"L"
						});
						if (mode == SortMode.TotalMatches)
						{
							text = text2 + ": " + matchRecord.Total + " MATCHES";
						}
					}
				}
				summaries[((Object)__instance).GetInstanceID()] = text;
				((ScrollableList)__instance).SetListSize(val.Count);
				((ScrollableList)__instance).topItemNo = Math.Max(0, Math.Min(((ScrollableList)__instance).topItemNo, Math.Max(0, val.Count - ((Il2CppArrayBase<ScrollableItem>)(object)scrollableItems).Length)));
				for (int num = 0; num < ((Il2CppArrayBase<ScrollableItem>)(object)scrollableItems).Length; num++)
				{
					ScrollableItem obj = ((Il2CppArrayBase<ScrollableItem>)(object)scrollableItems)[num];
					PlayerTag val3 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<PlayerTag>() : null);
					if (Object.op_Implicit((Object)(object)val3))
					{
						int num2 = ((ScrollableList)__instance).topItemNo + num;
						bool flag = num2 < val.Count;
						if (((Component)val3).gameObject.activeSelf != flag)
						{
							((Component)val3).gameObject.SetActive(flag);
						}
						if (flag)
						{
							val3.Initialize((UserSearchResult)(object)val[num2], Action<bool>.op_Implicit((Action<bool>)delegate
							{
							}));
							BindRow(val3, val[num2]);
						}
					}
				}
				return false;
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("\ud83d\udc31 Unified friend sort failed: " + ex.GetBaseException().Message);
				return true;
			}
			finally
			{
				rendering = false;
			}
		}

		private static void MetPlayer(string __0)
		{
			if (!string.IsNullOrWhiteSpace(__0))
			{
				history.RecordPlayed(__0, System.DateTime.UtcNow.Ticks);
				historyDirty = true;
				if (mode == SortMode.RecentlyPlayed)
				{
					dirty = true;
				}
			}
		}

		private static void EnsureAvailableSort()
		{
			if (IsMatch(mode) && !MatchInfoPresent)
			{
				mode = SortMode.Alphabetical;
				inverse = false;
				savedMode.Value = (int)mode;
				savedInverse.Value = false;
				dirty = true;
				historyDirty = true;
				resetPage = true;
			}
		}

		private static void Choose(SortMode chosen)
		{
			if (IsMatch(chosen) && !MatchInfoPresent)
			{
				return;
			}
			if (chosen == SortMode.Wins && (mode == SortMode.Wins || mode == SortMode.Losses))
			{
				if (!inverse)
				{
					inverse = true;
				}
				else
				{
					inverse = false;
					mode = ((mode == SortMode.Wins) ? SortMode.Losses : SortMode.Wins);
				}
			}
			else if (mode == chosen)
			{
				inverse = !inverse;
			}
			else
			{
				mode = chosen;
				inverse = false;
			}
			savedMode.Value = (int)mode;
			savedInverse.Value = inverse;
			dirty = true;
			historyDirty = true;
			resetPage = true;
		}

		private static void Save()
		{
			try
			{
				savedHistory.Value = JsonSerializer.Serialize<SortHistory>(history, (JsonSerializerOptions)null);
				preferences.SaveToFile(false);
				historyDirty = false;
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("\ud83d\udc31 Could not save sorting preferences: " + ex.Message);
			}
		}

		public override void OnUpdate()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: Unknown result type (might be due to invalid IL or missing references)
			if (stopped || Time.unscaledTime < nextTick)
			{
				return;
			}
			nextTick = Time.unscaledTime + 0.5f;
			try
			{
				EnsureAvailableSort();
				bool matchInfoPresent = MatchInfoPresent;
				WatchMatches(matchInfoPresent);
				if (!matchInfoPresent)
				{
					Enumerator<int, List<SideButton>> enumerator = controls.Values.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							List<SideButton> current = enumerator.Current;
							SideButton[] array = Enumerable.ToArray<SideButton>(Enumerable.Where<SideButton>((System.Collections.Generic.IEnumerable<SideButton>)current, (Func<SideButton, bool>)((SideButton b) => IsMatch(b.Mode))));
							foreach (SideButton sideButton in array)
							{
								if (Object.op_Implicit((Object)(object)sideButton.Object))
								{
									sideButton.Object.SetActive(false);
									Object.Destroy((Object)(object)sideButton.Object);
								}
								current.Remove(sideButton);
							}
						}
					}
					finally
					{
						((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
					}
				}
				if (Snapshot() && mode == SortMode.BattlePoints)
				{
					dirty = true;
				}
				if (Interlocked.Exchange(ref matchFileChanged, 0) != 0)
				{
					matchReadRetries = 3;
					nextMatchRead = Time.unscaledTime + 0.5f;
				}
				if (matchInfoPresent && matchReadRetries > 0 && Time.unscaledTime >= nextMatchRead)
				{
					nextMatchRead = Time.unscaledTime + 1f;
					matchReadRetries--;
					try
					{
						if (matches.Reload(MatchPath) && IsMatch(mode))
						{
							dirty = true;
						}
						matchWarning = false;
					}
					catch (System.Exception ex)
					{
						if (!matchWarning)
						{
							MelonLogger.Warning("\ud83d\udc31 MatchInfo data unavailable: " + ex.Message);
						}
						matchWarning = true;
					}
				}
				List<GetFriendsResult> confirmedFriends = FriendHandler.ConfirmedFriends;
				if (confirmedFriends != null)
				{
					List<string> val = new List<string>();
					Enumerator<GetFriendsResult> enumerator2 = confirmedFriends.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						GetFriendsResult current2 = enumerator2.Current;
						val.Add(Key((UserSearchResult)(object)current2));
					}
					if (history.ObserveFriends((System.Collections.Generic.IEnumerable<string>)val, System.DateTime.UtcNow.Ticks))
					{
						historyDirty = true;
						if (mode == SortMode.FriendAdded)
						{
							dirty = true;
						}
					}
				}
				if (historyDirty && Time.unscaledTime >= nextSave)
				{
					nextSave = Time.unscaledTime + 5f;
					Save();
				}
				int[] array2 = Enumerable.ToArray<int>(Enumerable.Select<KeyValuePair<int, FriendList>, int>(Enumerable.Where<KeyValuePair<int, FriendList>>((System.Collections.Generic.IEnumerable<KeyValuePair<int, FriendList>>)lists, (Func<KeyValuePair<int, FriendList>, bool>)((KeyValuePair<int, FriendList> p) => !Object.op_Implicit((Object)(object)p.Value))), (Func<KeyValuePair<int, FriendList>, int>)((KeyValuePair<int, FriendList> p) => p.Key)));
				List<SideButton> val2 = default(List<SideButton>);
				foreach (int num2 in array2)
				{
					if (controls.TryGetValue(num2, ref val2))
					{
						Enumerator<SideButton> enumerator3 = val2.GetEnumerator();
						try
						{
							while (enumerator3.MoveNext())
							{
								SideButton current3 = enumerator3.Current;
								if (Object.op_Implicit((Object)(object)current3.Object))
								{
									Object.Destroy((Object)(object)current3.Object);
								}
							}
						}
						finally
						{
							((System.IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
						}
					}
					controls.Remove(num2);
					lists.Remove(num2);
					summaries.Remove(num2);
				}
				bool flag = false;
				KeyValuePair<int, FriendList>[] array3 = Enumerable.ToArray<KeyValuePair<int, FriendList>>((System.Collections.Generic.IEnumerable<KeyValuePair<int, FriendList>>)lists);
				List<SideButton> val4 = default(List<SideButton>);
				string text2 = default(string);
				for (int num = 0; num < array3.Length; num++)
				{
					KeyValuePair<int, FriendList> val3 = array3[num];
					FriendList value = val3.Value;
					if (!((Component)value).gameObject.activeInHierarchy)
					{
						flag |= dirty;
						continue;
					}
					Il2CppReferenceArray<ScrollableItem> scrollableItems = ((ScrollableList)value).ScrollableItems;
					if (scrollableItems == null)
					{
						flag |= dirty;
						continue;
					}
					if (dirty)
					{
						if (Enumerable.Any<ScrollableItem>((System.Collections.Generic.IEnumerable<ScrollableItem>)scrollableItems, (Func<ScrollableItem, bool>)delegate(ScrollableItem item)
						{
							if (item == null)
							{
								return false;
							}
							PlayerTag obj = ((Il2CppObjectBase)item).TryCast<PlayerTag>();
							return ((obj != null) ? new bool?(obj.isInitializing) : ((bool?)null)) == true;
						}))
						{
							flag = true;
						}
						else
						{
							if (resetPage)
							{
								((ScrollableList)value).topItemNo = 0;
							}
							((ScrollableList)value).Refresh();
						}
					}
					if (!controls.TryGetValue(val3.Key, ref val4))
					{
						val4 = (controls[val3.Key] = new List<SideButton>());
					}
					val4.RemoveAll((Predicate<SideButton>)((SideButton b) => !Object.op_Implicit((Object)(object)b.Object)));
					PlayerTag val6 = Enumerable.FirstOrDefault<PlayerTag>(Enumerable.Select<ScrollableItem, PlayerTag>((System.Collections.Generic.IEnumerable<ScrollableItem>)scrollableItems, (Func<ScrollableItem, PlayerTag>)((ScrollableItem i) => (i == null) ? null : ((Il2CppObjectBase)i).TryCast<PlayerTag>())), (Func<PlayerTag, bool>)((PlayerTag t) => Object.op_Implicit((Object)(object)t) && Object.op_Implicit((Object)(object)t.username) && Object.op_Implicit((Object)(object)t.moreInfoButton)));
					if (!Object.op_Implicit((Object)(object)val6))
					{
						continue;
					}
					SortMode[] array4 = new SortMode[6];
					RuntimeHelpers.InitializeArray((System.Array)array4, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
					SortMode[] array5 = array4;
					foreach (SortMode choice in array5)
					{
						if ((matchInfoPresent || !IsMatch(choice)) && !Enumerable.Any<SideButton>((System.Collections.Generic.IEnumerable<SideButton>)val4, (Func<SideButton, bool>)((SideButton b) => b.Mode == choice)))
						{
							SideButton sideButton2 = MakeButton(val6, value, choice);
							if (sideButton2 != null)
							{
								val4.Add(sideButton2);
							}
						}
					}
					Enumerator<SideButton> enumerator3 = val4.GetEnumerator();
					try
					{
						while (enumerator3.MoveNext())
						{
							SideButton current4 = enumerator3.Current;
							bool flag2 = current4.Mode == mode || (current4.Mode == SortMode.Wins && mode == SortMode.Losses);
							string text = captions[(int)current4.Mode];
							if (flag2)
							{
								text = ((mode != SortMode.Alphabetical) ? ((mode == SortMode.Wins) ? "WLR WINS" : ((mode == SortMode.Losses) ? "WLR LOSSES" : text)) : (inverse ? "SORT Z–A" : "SORT A–Z"));
								if (mode != SortMode.Alphabetical)
								{
									text += (inverse ? " ↑" : " ↓");
								}
								text += " ✓";
								if (IsMatch(mode))
								{
									text = text + "\n<size=70%>" + (summaries.TryGetValue(val3.Key, ref text2) ? text2 : "NO MATCH DATA") + "</size>";
								}
							}
							if (!(current4.Caption == text))
							{
								current4.Label.text = text;
								((Graphic)current4.Label).color = (Color)(flag2 ? new Color(1f, 0.8f, 0.15f) : Color.white);
								current4.Caption = text;
							}
						}
					}
					finally
					{
						((System.IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
					}
				}
				dirty = flag;
				if (!flag)
				{
					resetPage = false;
				}
				UpdateRowValues();
			}
			catch (System.Exception ex2)
			{
				MelonLogger.Warning("\ud83d\udc31 FriendBPSort: " + ex2.GetBaseException().Message);
				nextTick = Time.unscaledTime + 5f;
			}
		}

		private static void BindRow(PlayerTag tag, GetFriendsResult friend)
		{
			int instanceID = ((Object)tag).GetInstanceID();
			RowValue rowValue = default(RowValue);
			if (!rowValues.TryGetValue(instanceID, ref rowValue))
			{
				Dictionary<int, RowValue> obj = rowValues;
				RowValue obj2 = new RowValue
				{
					Tag = tag
				};
				rowValue = obj2;
				obj[instanceID] = obj2;
			}
			rowValue.Master = ((UserSearchResult)friend).PlayFabMasterId;
			rowValue.Title = ((UserSearchResult)friend).PlayFabTitleId;
			rowValue.Key = Key((UserSearchResult)(object)friend);
			if (Object.op_Implicit((Object)(object)rowValue.Box))
			{
				rowValue.Box.SetActive(false);
			}
		}

		private static void UpdateRowValues()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: 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)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: 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_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			KeyValuePair<int, RowValue>[] array = Enumerable.ToArray<KeyValuePair<int, RowValue>>((System.Collections.Generic.IEnumerable<KeyValuePair<int, RowValue>>)rowValues);
			int num = default(int);
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<int, RowValue> val = array[i];
				RowValue value = val.Value;
				PlayerTag tag = value.Tag;
				if (!Object.op_Implicit((Object)(object)tag))
				{
					if (Object.op_Implicit((Object)(object)value.Box))
					{
						Object.Destroy((Object)(object)value.Box);
					}
					rowValues.Remove(val.Key);
				}
				else if (!((Component)tag).gameObject.activeInHierarchy || tag.isInitializing || (mode != SortMode.BattlePoints && (!IsMatch(mode) || !MatchInfoPresent)))
				{
					if (Object.op_Implicit((Object)(object)value.Box))
					{
						value.Box.SetActive(false);
					}
				}
				else if (Object.op_Implicit((Object)(object)tag.battlePoints))
				{
					if (!Object.op_Implicit((Object)(object)value.Box))
					{
						CreateRowBox(value);
					}
					long value2 = ((mode == SortMode.BattlePoints) ? (points.TryGetValue(value.Key, ref num) ? num : (-1)) : matches.Value(mode, value.Master));
					MatchRecord matchRecord = matches.Find(value.Master);
					string text = ((mode == SortMode.Wins || mode == SortMode.Losses) ? ValueDisplay.Pair(matchRecord?.Wins ?? (-1), matchRecord?.Losses ?? (-1), mode == SortMode.Losses != inverse) : ValueDisplay.Format(mode, value2));
					if (value.Text.text != text)
					{
						value.Text.text = text;
					}
					((Graphic)value.Text).color = ((mode == SortMode.Wins || mode == SortMode.Losses) ? Color.white : ((Graphic)tag.battlePoints).color);
					TMP_Text battlePoints = tag.battlePoints;
					Vector3 lossyScale = battlePoints.transform.lossyScale;
					Vector3 right = battlePoints.transform.right;
					Rect rect = battlePoints.rectTransform.rect;
					float num2 = ((Rect)(ref rect)).width * Mathf.Abs(lossyScale.x) * 0.5f;
					Transform transform = battlePoints.transform;
					rect = battlePoints.rectTransform.rect;
					Vector3 val2 = transform.TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center));
					value.Box.transform.position = val2 + right * (num2 + 0.085f) - battlePoints.transform.forward * 0.008f;
					value.Box.transform.rotation = battlePoints.transform.rotation;
					value.Box.SetActive(true);
				}
			}
		}

		private static void CreateRowBox(RowValue row)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: 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_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: 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)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text battlePoints = row.Tag.battlePoints;
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			val.SetActive(false);
			try
			{
				((Object)val).name = "FriendBPSort.SortedValue";
				val.transform.SetParent(((Component)row.Tag).transform, false);
				val.transform.rotation = battlePoints.transform.rotation;
				val.transform.localScale = Vector3.one;
				Vector3 lossyScale = val.transform.lossyScale;
				if (Mathf.Min(Mathf.Abs(lossyScale.x), Mathf.Min(Mathf.Abs(lossyScale.y), Mathf.Abs(lossyScale.z))) < 0.0001f)
				{
					throw new InvalidOperationException("\ud83d\udc31 Cannot place value box on a zero-scale row.");
				}
				val.transform.localScale = new Vector3(0.15f / Mathf.Abs(lossyScale.x), 0.075f / Mathf.Abs(lossyScale.y), 0.008f / Mathf.Abs(lossyScale.z));
				Collider component = val.GetComponent<Collider>();
				component.enabled = false;
				Object.Destroy((Object)(object)component);
				Transform transform = battlePoints.transform;
				Rect rect = battlePoints.rectTransform.rect;
				Vector3 center = transform.TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center));
				MeshFilter val2 = Enumerable.FirstOrDefault<MeshFilter>((System.Collections.Generic.IEnumerable<MeshFilter>)Enumerable.OrderBy<MeshFilter, float>(Enumerable.Where<MeshFilter>((System.Collections.Generic.IEnumerable<MeshFilter>)((Component)row.Tag).GetComponentsInChildren<MeshFilter>(true), (Func<MeshFilter, bool>)delegate(MeshFilter m)
				{
					//IL_0040: 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_0048: 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)
					if (Object.op_Implicit((Object)(object)m.sharedMesh) && Object.op_Implicit((Object)(object)((Component)m).GetComponent<MeshRenderer>()) && !Object.op_Implicit((Object)(object)((Component)m).GetComponent<TMP_Text>()) && !((Object)m).name.StartsWith("FriendBPSort", (StringComparison)4))
					{
						Bounds bounds2 = ((Component)m).GetComponent<Renderer>().bounds;
						Vector3 size = ((Bounds)(ref bounds2)).size;
						return ((Vector3)(ref size)).magnitude < 0.65f;
					}
					return false;
				}), (Func<MeshFilter, float>)delegate(MeshFilter m)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0014: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					Bounds bounds2 = ((Component)m).GetComponent<Renderer>().bounds;
					Vector3 val3 = ((Bounds)(ref bounds2)).center - center;
					return ((Vector3)(ref val3)).sqrMagnitude;
				}));
				if (Object.op_Implicit((Object)(object)val2))
				{
					val.GetComponent<MeshFilter>().sharedMesh = val2.sharedMesh;
					val.GetComponent<Renderer>().sharedMaterials = ((Component)val2).GetComponent<Renderer>().sharedMaterials;
					Bounds bounds = val2.sharedMesh.bounds;
					Vector3 lossyScale2 = ((Component)row.Tag).transform.lossyScale;
					val.transform.localScale = new Vector3(0.15f / Mathf.Max(0.0001f, ((Bounds)(ref bounds)).size.x * Mathf.Abs(lossyScale2.x)), 0.075f / Mathf.Max(0.0001f, ((Bounds)(ref bounds)).size.y * Mathf.Abs(lossyScale2.y)), 0.008f / Mathf.Max(0.0001f, ((Bounds)(ref bounds)).size.z * Mathf.Abs(lossyScale2.z)));
				}
				else
				{
					val.GetComponent<Renderer>().sharedMaterial = SolidBrown();
				}
				TMP_Text component2 = Object.Instantiate<GameObject>(((Component)battlePoints).gameObject, val.transform).GetComponent<TMP_Text>();
				((Object)component2).name = "SortedValueText";
				component2.transform.position = val.transform.position - battlePoints.transform.forward * 0.006f;
				component2.transform.localRotation = Quaternion.identity;
				Vector3 lossyScale3 = val.transform.lossyScale;
				Vector3 lossyScale4 = battlePoints.transform.lossyScale;
				component2.transform.localScale = new Vector3(lossyScale4.x / lossyScale3.x, lossyScale4.y / lossyScale3.y, lossyScale4.z / lossyScale3.z);
				component2.rectTransform.pivot = new Vector2(0.5f, 0.5f);
				component2.rectTransform.sizeDelta = new Vector2(0.14f / Mathf.Abs(lossyScale4.x), 0.065f / Mathf.Abs(lossyScale4.y));
				component2.alignment = (TextAlignmentOptions)514;
				((Graphic)component2).raycastTarget = false;
				component2.richText = true;
				component2.enableWordWrapping = false;
				component2.enableAutoSizing = true;
				component2.fontSizeMax = battlePoints.fontSize;
				component2.fontSizeMin = battlePoints.fontSize * 0.3f;
				((Graphic)component2).color = ((Graphic)battlePoints).color;
				((Component)component2).gameObject.SetActive(true);
				row.Box = val;
				row.Text = component2;
			}
			catch
			{
				val.SetActive(false);
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		private static Material SolidBrown()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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)
			if (Object.op_Implicit((Object)(object)backboardMaterial))
			{
				return backboardMaterial;
			}
			Shader val = Shader.Find("Universal Render Pipeline/Unlit");
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = Shader.Find("Unlit/Color");
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("\ud83d\udc31 Solid-color backboard shader unavailable.");
			}
			backboardMaterial = new Material(val);
			((Object)backboardMaterial).name = "FriendBPSort.SolidBrown";
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.32f, 0.16f, 0.07f, 1f);
			if (backboardMaterial.HasProperty("_BaseColor"))
			{
				backboardMaterial.SetColor("_BaseColor", val2);
			}
			if (backboardMaterial.HasProperty("_Color"))
			{
				backboardMaterial.SetColor("_Color", val2);
			}
			return backboardMaterial;
		}

		private static void ClearEvents(InteractionButton button)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			button.onPressed = new UnityEvent();
			button.onPressedByPlayer = new UnityEvent<Player>();
			button.onToggledByPlayerController = new UnityEvent<bool, PlayerController>();
			button.onToggleStateChanged = new UnityEventBool();
			button.isToggleButton = false;
			button.useLongPress = false;
			button.disableButtonAfterInit = false;
			button.pressInterval = 0.5f;
		}

		private static SideButton MakeButton(PlayerTag tag, FriendList list, SortMode choice)
		{
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0480: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_061e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0628: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_063d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0647: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_065c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0687: Unknown result type (might be due to invalid IL or missing references)
			//IL_06af: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0706: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_071a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0722: Unknown result type (might be due to invalid IL or missing references)
			//IL_0729: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			//IL_0738: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Unknown result type (might be due to invalid IL or missing references)
			//IL_0756: Unknown result type (might be due to invalid IL or missing references)
			//IL_0772: Unknown result type (might be due to invalid IL or missing references)
			//IL_0789: Unknown result type (might be due to invalid IL or missing references)
			//IL_07aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07da: Unknown result type (might be due to invalid IL or missing references)
			//IL_07de: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0828: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_084e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0858: Unknown result type (might be due to invalid IL or missing references)
			//IL_085d: Unknown result type (might be due to invalid IL or missing references)
			//IL_086d: Unknown result type (might be due to invalid IL or missing references)
			//IL_087d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0882: Unknown result type (might be due to invalid IL or missing references)
			//IL_088f: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_090e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0918: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)tag.moreInfoButton) || !Object.op_Implicit((Object)(object)tag.username))
			{
				return null;
			}
			if (!Object.op_Implicit((Object)(object)stoneButton) && Time.unscaledTime >= nextAssetSearch)
			{
				nextAssetSearch = Time.unscaledTime + 5f;
				System.Collections.Generic.IEnumerator<InteractionButton> enumerator = Object.FindObjectsOfType<InteractionButton>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						InteractionButton current = enumerator.Current;
						Transform parent = ((Component)current).transform.parent;
						while (Object.op_Implicit((Object)(object)parent))
						{
							if (((Object)parent).name.IndexOf("ShiftstoneQuickswapper", (StringComparison)5) >= 0)
							{
								stoneButton = current;
								break;
							}
							parent = parent.parent;
						}
						if (Object.op_Implicit((Object)(object)stoneButton))
						{
							break;
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
				if (!Object.op_Implicit((Object)(object)stoneButton) && !warnedMissingAsset)
				{
					warnedMissingAsset = true;
					MelonLogger.Warning("\ud83d\udc31 Shiftstone quickswap button not found; favorites will appear when the asset is available.");
				}
				if (Object.op_Implicit((Object)(object)stoneButton))
				{
					warnedMissingAsset = false;
				}
			}
			if (!Object.op_Implicit((Object)(object)stoneButton))
			{
				return null;
			}
			if (!Object.op_Implicit((Object)(object)staging))
			{
				staging = new GameObject("FriendBPSort.Staging");
				staging.SetActive(false);
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)stoneButton).gameObject, staging.transform);
			((Object)val).name = "FriendBPSort.Sort." + ((object)choice/*cast due to .constrained prefix*/).ToString();
			try
			{
				val.SetActive(false);
				val.transform.SetParent(((Component)list).transform, false);
				val.transform.rotation = ((Component)tag.moreInfoButton).transform.rotation;
				Vector3 lossyScale = ((Component)list).transform.lossyScale;
				Vector3 lossyScale2 = ((Component)stoneButton).transform.lossyScale;
				if (Mathf.Abs(lossyScale.x) < 0.0001f || Mathf.Abs(lossyScale.y) < 0.0001f || Mathf.Abs(lossyScale.z) < 0.0001f)
				{
					throw new InvalidOperationException("\ud83d\udc31 Cannot place favorite button on a board with zero scale.");
				}
				val.transform.localScale = new Vector3(lossyScale2.x / lossyScale.x, lossyScale2.y / lossyScale.y, lossyScale2.z / lossyScale.z);
				Il2CppArrayBase<Renderer> componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
				if (componentsInChildren.Length > 0)
				{
					Bounds bounds = componentsInChildren[0].bounds;
					System.Collections.Generic.IEnumerator<Renderer> enumerator2 = componentsInChildren.GetEnumerator();
					try
					{
						while (((System.Collections.IEnumerator)enumerator2).MoveNext())
						{
							Renderer current2 = enumerator2.Current;
							((Bounds)(ref bounds)).Encapsulate(current2.bounds);
						}
					}
					finally
					{
						((System.IDisposable)enumerator2)?.Dispose();
					}
					float num = Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z));
					if (num > 0.001f)
					{
						Transform transform = val.transform;
						transform.localScale *= 0.09f / num;
					}
				}
				Vector3 val2 = ((Component)tag).transform.InverseTransformPoint(((Component)tag.moreInfoButton).transform.position);
				float x = ((Component)tag).transform.InverseTransformPoint(tag.username.transform.position).x;
				val2.x = x - Mathf.Max(Mathf.Abs(val2.x - x), 0.06f);
				val.transform.position = ((Component)tag).transform.TransformPoint(val2) - tag.username.transform.up * (0.12f * (float)choice);
				Vector3 right = tag.username.transform.right;
				float num2 = Vector3.Dot(val.transform.position, right) - 0.18f;
				InteractionButton[] array = (InteractionButton[])(object)new InteractionButton[4]
				{
					((ScrollableList)list).pageUpButton,
					((ScrollableList)list).pageDownButton,
					((ScrollableList)list).scrollUpButton,
					((ScrollableList)list).scrollDownButton
				};
				foreach (InteractionButton val3 in array)
				{
					if (Object.op_Implicit((Object)(object)val3))
					{
						num2 = Mathf.Min(num2, Vector3.Dot(((Component)val3).transform.position, right) - 0.16f);
					}
				}
				Transform transform2 = val.transform;
				transform2.position += right * (num2 - Vector3.Dot(val.transform.position, right));
				Transform transform3 = val.transform;
				transform3.position -= right * 0.18f;
				Transform transform4 = val.transform;
				transform4.position -= tag.username.transform.forward * 0.12f;
				InteractionButton component = val.GetComponent<InteractionButton>();
				ClearEvents(component);
				component.isPressed = false;
				component.waitingForRelease = false;
				component.canBeToggledAgain = true;
				component.closestCollider = null;
				component.lastTimePressed = -100f;
				System.Collections.Generic.IEnumerator<Collider> enumerator3 = val.GetComponentsInChildren<Collider>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator3).MoveNext())
					{
						enumerator3.Current.enabled = true;
					}
				}
				finally
				{
					((System.IDisposable)enumerator3)?.Dispose();
				}
				System.Collections.Generic.IEnumerator<Rigidbody> enumerator4 = val.GetComponentsInChildren<Rigidbody>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator4).MoveNext())
					{
						Rigidbody current3 = enumerator4.Current;
						current3.isKinematic = true;
						current3.useGravity = false;
						current3.detectCollisions = true;
					}
				}
				finally
				{
					((System.IDisposable)enumerator4)?.Dispose();
				}
				System.Collections.Generic.IEnumerator<TMP_Text> enumerator5 = val.GetComponentsInChildren<TMP_Text>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator5).MoveNext())
					{
						((Component)enumerator5.Current).gameObject.SetActive(false);
					}
				}
				finally
				{
					((System.IDisposable)enumerator5)?.Dispose();
				}
				TMP_Text component2 = Object.Instantiate<GameObject>(((Component)tag.username).gameObject, val.transform).GetComponent<TMP_Text>();
				((Object)component2).name = "SortLabel";
				component2.text = captions[(int)choice];
				component2.alignment = (TextAlignmentOptions)514;
				((Graphic)component2).raycastTarget = false;
				((Component)component2).gameObject.SetActive(true);
				component2.transform.position = val.transform.position - tag.username.transform.right * 0.22f - tag.username.transform.up * 0.025f - tag.username.transform.forward * 0.055f;
				component2.transform.rotation = tag.username.transform.rotation;
				component2.fontSize = tag.username.fontSize * 0.85f;
				Vector3 lossyScale3 = val.transform.lossyScale;
				Vector3 lossyScale4 = tag.username.transform.lossyScale;
				if (Mathf.Abs(lossyScale3.x) < 0.0001f || Mathf.Abs(lossyScale3.y) < 0.0001f || Mathf.Abs(lossyScale3.z) < 0.0001f)
				{
					throw new InvalidOperationException("\ud83d\udc31 Favorite button asset has zero scale.");
				}
				component2.transform.localScale = new Vector3(lossyScale4.x / lossyScale3.x, lossyScale4.y / lossyScale3.y, lossyScale4.z / lossyScale3.z);
				component2.rectTransform.sizeDelta = new Vector2(0.32f / Mathf.Max(Mathf.Abs(lossyScale4.x), 0.0001f), 0.065f / Mathf.Max(Mathf.Abs(lossyScale4.y), 0.0001f));
				component2.enableAutoSizing = false;
				component2.enableWordWrapping = false;
				float num3 = component2.GetPreferredValues("ABCDEFG").x * Mathf.Abs(component2.transform.lossyScale.x);
				Transform transform5 = component2.transform;
				transform5.position -= right * num3;
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
				obj.SetActive(false);
				((Object)obj).name = "SortButtonBackboard";
				obj.transform.SetParent(val.transform, false);
				obj.transform.rotation = tag.username.transform.rotation;
				obj.transform.position = val.transform.position + tag.username.transform.forward * 0.0396f;
				obj.transform.localScale = Vector3.one;
				Vector3 lossyScale5 = obj.transform.lossyScale;
				obj.transform.localScale = new Vector3(0.13f / Mathf.Abs(lossyScale5.x), 0.11f / Mathf.Abs(lossyScale5.y), 0.015f / Mathf.Abs(lossyScale5.z));
				Collider component3 = obj.GetComponent<Collider>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					component3.enabled = false;
					Object.Destroy((Object)(object)component3);
				}
				obj.GetComponent<Renderer>().sharedMaterial = SolidBrown();
				obj.SetActive(true);
				component.onPressed.AddListener(UnityAction.op_Implicit((Action)delegate
				{
					Choose(choice);
				}));
				((Behaviour)component).enabled = true;
				val.SetActive(true);
				return new SideButton
				{
					Object = val,
					Label = component2,
					Mode = choice
				};
			}
			catch
			{
				val.SetActive(false);
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		public override void OnDeinitializeMelon()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			stopped = true;
			if (historyDirty)
			{
				Save();
			}
			((MelonBase)this).HarmonyInstance.UnpatchSelf();
			FileSystemWatcher obj = matchWatcher;
			if (obj != null)
			{
				((Component)obj).Dispose();
			}
			matchWatcher = null;
			Enumerator<int, RowValue> enumerator = rowValues.Values.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					RowValue current = enumerator.Current;
					if (Object.op_Implicit((Object)(object)current.Box))
					{
						Object.Destroy((Object)(object)current.Box);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			rowValues.Clear();
			Enumerator<int, List<SideButton>> enumerator2 = controls.Values.GetEnumerator();
			try
			{
				while (enumerator2.MoveNext())
				{
					Enumerator<SideButton> enumerator3 = enumerator2.Current.GetEnumerator();
					try
					{
						while (enumerator3.MoveNext())
						{
							SideButton current2 = enumerator3.Current;
							if (Object.op_Implicit((Object)(object)current2.Object))
							{
								Object.Destroy((Object)(object)current2.Object);
							}
						}
					}
					finally
					{
						((System.IDisposable)enumerator3/*cast due to .constrained prefix*/).Dispose();
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
			}
			controls.Clear();
			if (Object.op_Implicit((Object)(object)staging))
			{
				Object.Destroy((Object)(object)staging);
			}
			if (Object.op_Implicit((Object)(object)backboardMaterial))
			{
				Object.Destroy((Object)(object)backboardMaterial);
			}
			FriendList[] array = Enumerable.ToArray<FriendList>((System.Collections.Generic.IEnumerable<FriendList>)lists.Values);
			foreach (FriendList val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeInHierarchy)
				{
					((ScrollableList)val).Refresh();
				}
			}
		}
	}
	public enum SortMode
	{
		Alphabetical,
		BattlePoints,
		FriendAdded,
		RecentlyPlayed,
		Wins,
		TotalMatches,
		Losses
	}
	public static class Ranking
	{
		public static string PlainName(string name)
		{
			return Regex.Replace(name ?? "", "<[^>]*>", "");
		}

		public static int Compare(SortMode mode, int bpA, string nameA, string idA, long dateA, int bpB, string nameB, string idB, long dateB, bool inverse = false)
		{
			bool flag = mode != SortMode.Alphabetical;
			long num = ((mode == SortMode.BattlePoints) ? Math.Max(-1, bpA) : dateA);
			long num2 = ((mode == SortMode.BattlePoints) ? Math.Max(-1, bpB) : dateB);
			int num3;
			bool num4;
			if (mode != SortMode.FriendAdded)
			{
				num3 = ((mode == SortMode.RecentlyPlayed) ? 1 : 0);
				if (num3 == 0)
				{
					num4 = num < 0;
					goto IL_0045;
				}
			}
			else
			{
				num3 = 1;
			}
			num4 = num <= 0;
			goto IL_0045;
			IL_0045:
			bool flag2 = num4;
			bool flag3 = ((num3 != 0) ? (num2 <= 0) : (num2 < 0));
			if (flag && flag2 != flag3)
			{
				if (!flag2)
				{
					return -1;
				}
				return 1;
			}
			int num5 = (flag ? (inverse ? num.CompareTo(num2) : num2.CompareTo(num)) : 0);
			if (num5 != 0)
			{
				return num5;
			}
			num5 = StringComparer.OrdinalIgnoreCase.Compare(PlainName(nameA), PlainName(nameB));
			if (mode == SortMode.Alphabetical && inverse)
			{
				num5 = -num5;
			}
			if (num5 == 0)
			{
				return StringComparer.Ordinal.Compare(idA ?? "", idB ?? "");
			}
			return num5;
		}
	}
	public sealed class SortHistory
	{
		[field: CompilerGenerated]
		public HashSet<string> KnownFriends
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		} = new HashSet<string>();

		[field: CompilerGenerated]
		public Dictionary<string, long> Added
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		} = new Dictionary<string, long>();

		[field: CompilerGenerated]
		public Dictionary<string, long> Played
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		} = new Dictionary<string, long>();

		[field: CompilerGenerated]
		public bool HasBaseline
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			set;
		}

		public bool ObserveFriends(System.Collections.Generic.IEnumerable<string> ids, long now)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> val = new HashSet<string>(Enumerable.Where<string>(ids, (Func<string, bool>)((string id) => !string.IsNullOrEmpty(id))));
			if (val.Count == 0)
			{
				return false;
			}
			if (!HasBaseline)
			{
				KnownFriends = val;
				HasBaseline = true;
				return true;
			}
			bool result = false;
			Enumerator<string> enumerator = val.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.Current;
					if (KnownFriends.Add(current))
					{
						Added[current] = now;
						result = true;
					}
				}
				return result;
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
		}

		public void RecordPlayed(string id, long now)
		{
			if (!string.IsNullOrEmpty(id))
			{
				Played[id] = now;
			}
		}

		public long Date(SortMode mode, string master, string title)
		{
			Dictionary<string, long> val = ((mode == SortMode.FriendAdded) ? Added : Played);
			long num = 0L;
			long num2 = 0L;
			if (master != null)
			{
				val.TryGetValue(master, ref num);
			}
			if (title != null)
			{
				val.TryGetValue(title, ref num2);
			}
			return Math.Max(num, num2);
		}
	}
	public sealed class MatchRecord
	{
		[field: CompilerGenerated]
		public long Wins
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			init;
		}

		[field: CompilerGenerated]
		public long Losses
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			init;
		}

		public long Total => Wins + Losses;
	}
	public sealed class MatchStats
	{
		private System.DateTime stamp;

		private long length = -1L;

		[field: CompilerGenerated]
		public Dictionary<string, MatchRecord> Records
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		} = new Dictionary<string, MatchRecord>((IEqualityComparer<string>)(object)StringComparer.OrdinalIgnoreCase);

		public static Dictionary<string, MatchRecord> Parse(string[] lines)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, MatchRecord> val = new Dictionary<string, MatchRecord>((IEqualityComparer<string>)(object)StringComparer.OrdinalIgnoreCase);
			int num = lines.Length;
			while (num > 0 && string.IsNullOrWhiteSpace(lines[num - 1]))
			{
				num--;
			}
			if (num % 3 != 0)
			{
				throw new FormatException("Incomplete MatchInfo record.");
			}
			long num3 = default(long);
			long num4 = default(long);
			for (int i = 0; i < num; i += 3)
			{
				string text = lines[i].Trim().TrimStart('\ufeff');
				int num2 = text.IndexOf(" - ", (StringComparison)4);
				string text2 = ((num2 < 0) ? text : text.Substring(0, num2)).Trim();
				if (text2.Length == 0 || !long.TryParse(lines[i + 1], (NumberStyles)7, (IFormatProvider)(object)CultureInfo.InvariantCulture, ref num3) || !long.TryParse(lines[i + 2], (NumberStyles)7, (IFormatProvider)(object)CultureInfo.InvariantCulture, ref num4) || num3 < 0 || num4 < 0 || num3 > 9223372036854775807L - num4 || val.ContainsKey(text2))
				{
					throw new FormatException("Invalid or duplicate MatchInfo record.");
				}
				val.Add(text2, new MatchRecord
				{
					Wins = num3,
					Losses = num4
				});
			}
			return val;
		}

		public bool Reload(string path)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				bool result = Records.Count > 0;
				Records.Clear();
				length = -1L;
				return result;
			}
			FileInfo val = new FileInfo(path);
			if (((FileSystemInfo)val).LastWriteTimeUtc == stamp && val.Length == length)
			{
				return false;
			}
			FileStream val2 = new FileStream(path, (FileMode)3, (FileAccess)1, (FileShare)1);
			try
			{
				StreamReader val3 = new StreamReader((Stream)(object)val2);
				try
				{
					List<string> val4 = new List<string>();
					string text;
					while ((text = ((TextReader)val3).ReadLine()) != null)
					{
						val4.Add(text);
					}
					Dictionary<string, MatchRecord> records = Parse(val4.ToArray());
					Records = records;
					stamp = ((FileSystemInfo)val).LastWriteTimeUtc;
					length = val.Length;
					return true;
				}
				finally
				{
					((System.IDisposable)val3)?.Dispose();
				}
			}
			finally
			{
				((System.IDisposable)val2)?.Dispose();
			}
		}

		public MatchRecord Find(string master)
		{
			MatchRecord result = default(MatchRecord);
			if (master == null || !Records.TryGetValue(master, ref result))
			{
				return null;
			}
			return result;
		}

		public long Value(SortMode mode, string master)
		{
			MatchRecord matchRecord = Find(master);
			if (matchRecord != null)
			{
				return mode switch
				{
					SortMode.Losses => matchRecord.Losses, 
					SortMode.Wins => matchRecord.Wins, 
					_ => matchRecord.Total, 
				};
			}
			return -1L;
		}
	}
	public static class ValueDisplay
	{
		public static string Pair(long wins, long losses, bool lossesFirst)
		{
			if (wins < 0 || losses < 0)
			{
				return "—";
			}
			string text = "<color=#FFD700>" + wins.ToString((IFormatProvider)(object)CultureInfo.InvariantCulture) + "</color>";
			string text2 = "<color=#FF3030>" + losses.ToString((IFormatProvider)(object)CultureInfo.InvariantCulture) + "</color>";
			if (!lossesFirst)
			{
				return text + "/" + text2;
			}
			return text2 + "/" + text;
		}

		public static string Format(SortMode mode, long value)
		{
			if (mode != SortMode.BattlePoints && mode != SortMode.Wins && mode != SortMode.Losses && mode != SortMode.TotalMatches)
			{
				return "";
			}
			if (value < 0)
			{
				return "—";
			}
			return value.ToString((IFormatProvider)(object)CultureInfo.InvariantCulture);
		}
	}
}