Decompiled source of LeaderboardManager v1.4.0

UltrakillDifficultyLeaderboard.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UltrakillDifficultyLeaderboard.Data;
using UltrakillDifficultyLeaderboard.HarmonyPatches;
using UltrakillDifficultyLeaderboard.Scripts;
using UltrakillModLib;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
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("UltrakillDifficultyLeaderboard")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltrakillDifficultyLeaderboard")]
[assembly: AssemblyTitle("UltrakillDifficultyLeaderboard")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace UltrakillLayerConfigurator.Patches
{
	[HarmonyPatch(typeof(GearCheckEnabler))]
	public static class GearCheckEnablerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		public static void StartPostfix()
		{
			DifficultyFinder.Create();
			LeaderboardLocalTimeManager.Create();
		}
	}
	[HarmonyPatch(typeof(LayerSelect))]
	public class LayerSelectPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("CheckScore")]
		public static void CheckScorePostfix(ref LayerSelect __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<CustomLayerSelect>() == (Object)null)
			{
				ComponentExtensions.GetOrAddComponent<CustomLayerSelect>((Component)(object)__instance);
			}
		}
	}
	[HarmonyPatch(typeof(LevelSelectPanel))]
	public class LevelSelectPanelPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("CheckScore")]
		public static void CheckScorePostfix(ref LevelSelectPanel __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<CustomLeaderboardPanel>() == (Object)null)
			{
				ComponentExtensions.GetOrAddComponent<CustomLeaderboardPanel>((Component)(object)__instance);
			}
		}
	}
}
namespace UltrakillDifficultyLeaderboard
{
	[BepInPlugin("net.zephyr.ultrakill.DifficultyLeaderboards", "Leaderboard Manager", "1.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LeaderboardPlugin : BaseUnityPlugin
	{
		internal static DebugLog Log = null;

		private PluginConfigurator config;

		public static Dictionary<GameDifficulty, DifficultyOption> DifficultyVisibility = new Dictionary<GameDifficulty, DifficultyOption>();

		private const string ModName = "Zephyr's Leaderboard Manager";

		public const string VisGlobalCategoryName = "--Entry Visibility--";

		public const string TimeManagementGlobalCategoryName = "--Record Management--";

		public const string CosmeticGlobalCategoryName = "--Other--";

		private const string TypeSortingDirectionName = "Default Time Sorting Direction";

		private const string TypeSortingBehaviorName = "Default Time Sorting Behavior";

		private const string PerDifficultySortingName = "Difficulty Sorting Direction";

		private const string PerDifficultyBehaviorName = "Default Difficulty Sorting Behavior";

		private const string ActiveDiffName = "Show Times of Active Difficulty";

		private const string ActiveDiffOnlyName = "Default Hide Other Difficulties";

		private const string HideTimesAboveYourOwnName = "Hide Times Above Your Own";

		private const string HideOthersName = "Hide Other Players";

		private const string BlockAllRecordName = "Prevent New Steam Level Records";

		private const string BlockAllCybergrindRecordName = "Prevent New Cybergrind Records";

		private const string BlockAllLocalTimesName = "Save Records per Difficulty";

		private const string UserPanelName = "Config Friends Visibility";

		private const string TimePanelName = "Config Records";

		private const string DiffPanelName = "Config Difficulties";

		private const string AnyRecordColorName = "ANY% Best time Color";

		private const string PRankRecordColorName = "P-RANK Best time Color";

		private const string EnableBestWaveAnimationName = "Best Time WAVE Animation";

		private const string ColorizeDifficultiesName = "Colorize Difficulties";

		private const string FeedbackButtonName = "Send FEEDBACK / REPORT BUG (discord)";

		private const string DiffCatecoryName1 = "--ACCESSIBLE--";

		private const string DiffCatecoryName2 = "--HARD--";

		private const string DiffCatecoryName3 = "--VERY HARD--";

		private static readonly Color HarmlessColor = new Color(0.43f, 1f, 0.905f);

		private static readonly Color LenientColor = new Color(0.49f, 0.753f, 1f);

		private static readonly Color StandardColor = new Color(0.664f, 0.47f, 1f);

		private static readonly Color ViolentColor = new Color(1f, 0.35f, 0.968f);

		private static readonly Color BrutalColor = new Color(1f, 0.27f, 0.647f);

		private static readonly Color UKMDColor = new Color(1f, 0.248f, 0.285f);

		public BoolField ActiveDiffVis { get; private set; }

		public BoolField DiffVis { get; private set; }

		public BoolField BlockAllRecords { get; private set; }

		public BoolField BlockAllCybergrindRecords { get; private set; }

		public BoolField AllowAllLocalTimes { get; private set; }

		public BoolField HideTimesAboveYourOwn { get; private set; }

		public BoolField HideOthers { get; private set; }

		public ColorField AnyRecordColor { get; private set; }

		public ColorField PRankRecordColor { get; private set; }

		public BoolField EnableBestWaveAnimation { get; private set; }

		public BoolField ColorizeDifficulties { get; private set; }

		public ConfigPanel UserPanel { get; private set; }

		public EnumField<SortingDirection> TypeSortingDirection { get; private set; }

		public EnumField<TimeSortingBehavior> TypeSortingBehavior { get; private set; }

		public EnumField<SortingDirection> PerDifficultySortingDirection { get; private set; }

		public EnumField<DifficultySortingBehavior> PerDifficultySortingBehavior { get; private set; }

		public static Dictionary<SteamId, BoolField> UserVisibilityToggles { get; private set; } = new Dictionary<SteamId, BoolField>();

		public static Dictionary<SteamId, ConfigPanel> UserPanels { get; private set; } = new Dictionary<SteamId, ConfigPanel>();

		public static LeaderboardPlugin Instance { get; private set; } = null;

		public LeaderboardPlugin()
		{
			Instance = this;
			CreateConfig();
		}

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Harmony val = new Harmony("net.zephyr.ultrakill.DifficultyLeaderboards");
			val.PatchAll();
			Log = new DebugLog("Zephyr's Leaderboard Manager", ConsoleColor.DarkYellow, false);
			Log.Log("The goop is in the bag.");
		}

		private void Update()
		{
			SteamControllerPatch.UpdateRealBests();
		}

		private Sprite MakeSpriteFronFileName(string fileName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string path = Path.Combine(directoryName, fileName);
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private void CreateConfig()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Expected O, but got Unknown
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Expected O, but got Unknown
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Expected O, but got Unknown
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Expected O, but got Unknown
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Expected O, but got Unknown
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Expected O, but got Unknown
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Expected O, but got Unknown
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Expected O, but got Unknown
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Expected O, but got Unknown
			config = PluginConfigurator.Create("Zephyr's Leaderboard Manager", "net.zephyr.ultrakill.DifficultyLeaderboards");
			Sprite image = MakeSpriteFronFileName("icon.png");
			config.image = image;
			ConfigHeader val = new ConfigHeader(config.rootPanel, "--Record Management--", 24);
			AllowAllLocalTimes = new BoolField(config.rootPanel, "Save Records per Difficulty", "local_times_lock", true);
			BlockAllRecords = new BoolField(config.rootPanel, "Prevent New Steam Level Records", "records_lock", false);
			BlockAllCybergrindRecords = new BoolField(config.rootPanel, "Prevent New Cybergrind Records", "records_cybergrind_lock", false);
			TypeSortingBehavior = new EnumField<TimeSortingBehavior>(config.rootPanel, "Default Time Sorting Behavior", "time_behavior", TimeSortingBehavior.Time);
			TypeSortingDirection = new EnumField<SortingDirection>(config.rootPanel, "Default Time Sorting Direction", "time_sorting", SortingDirection.Ascending);
			PerDifficultySortingBehavior = new EnumField<DifficultySortingBehavior>(config.rootPanel, "Default Difficulty Sorting Behavior", "difficulty_behavior", DifficultySortingBehavior.NoSorting);
			PerDifficultySortingDirection = new EnumField<SortingDirection>(config.rootPanel, "Difficulty Sorting Direction", "difficulty_sorting", SortingDirection.Descending);
			ConfigPanel timePanel = new ConfigPanel(config.rootPanel, "Config Records", "time_panel", (PanelFieldType)3);
			timePanel.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
			{
				((MonoBehaviour)this).StartCoroutine(CreateConfigTimes(timePanel));
			};
			timePanel.onPannelCloseEvent += (ClosePanelEventDelegate)delegate
			{
				for (int i = 0; i < timePanel.fieldCount; i++)
				{
					timePanel.FieldAt(i).hidden = true;
				}
			};
			ConfigPanel diffPanel = new ConfigPanel(config.rootPanel, "Config Difficulties", "diff_panel", (PanelFieldType)3);
			ConfigHeader val2 = new ConfigHeader(config.rootPanel, "--Entry Visibility--", 24);
			ActiveDiffVis = new BoolField(config.rootPanel, "Show Times of Active Difficulty", "active_diff_vis", true);
			DiffVis = new BoolField(config.rootPanel, "Default Hide Other Difficulties", "diff_vis", false);
			HideTimesAboveYourOwn = new BoolField(config.rootPanel, "Hide Times Above Your Own", "better_times_vis", false);
			HideOthers = new BoolField(config.rootPanel, "Hide Other Players", "others_vis", false);
			CreatePerUserConfig();
			CreateConfigDifficulties(diffPanel);
			ConfigHeader val3 = new ConfigHeader(config.rootPanel, "--Other--", 24);
			AnyRecordColor = new ColorField(config.rootPanel, "ANY% Best time Color", "any_record_color", new Color(0.416f, 0.809f, 0.82f));
			PRankRecordColor = new ColorField(config.rootPanel, "P-RANK Best time Color", "prank_record_color", new Color(0.93f, 0.64f, 0f));
			EnableBestWaveAnimation = new BoolField(config.rootPanel, "Best Time WAVE Animation", "enable_record_wave", true);
			ColorizeDifficulties = new BoolField(config.rootPanel, "Colorize Difficulties", "colorize_difficulties", true);
			ConfigPanel feedbackButton = new ConfigPanel(config.rootPanel, "Send FEEDBACK / REPORT BUG (discord)", "feedback_button", (PanelFieldType)3);
			feedbackButton.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
			{
				Process.Start("https://discord.gg/KcsjvKa6jw");
				feedbackButton.ClosePanel();
			};
		}

		private void CreatePerUserConfig()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			UserPanel = new ConfigPanel(config.rootPanel, "Config Friends Visibility", "user_panel", (PanelFieldType)3);
			((ConfigField)UserPanel).interactable = !HideOthers.value;
			HideOthers.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				((ConfigField)UserPanel).interactable = !e.value;
			};
			UserPanel.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
			{
				RefreshFriends();
			};
		}

		public async Task RefreshFriends()
		{
			LeaderboardController leaderboardController = MonoSingleton<LeaderboardController>.Instance;
			LeaderboardEntry[] entries = await leaderboardController.GetLevelScores("Level 0-1", false);
			List<Friend> friends = new List<Friend>();
			LeaderboardEntry[] array = entries;
			for (int i = 0; i < array.Length; i++)
			{
				LeaderboardEntry entry = array[i];
				friends.Add(entry.User);
			}
			friends = new List<Friend>(friends.OrderBy((Friend x) => ((Friend)(ref x)).Name));
			if (friends == null)
			{
				return;
			}
			foreach (Friend item in friends)
			{
				Friend friend = item;
				if (!((Friend)(ref friend)).IsMe)
				{
					if (!UserVisibilityToggles.ContainsKey(friend.Id))
					{
						CreateUserEntry(UserPanel, friend);
					}
					else
					{
						SetUserIcon(friend);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)LeaderboardLocalTimeManager.Instance))
			{
				LeaderboardLocalTimeManager.Instance.FriendsList = friends;
			}
		}

		private static void CreateUserEntry(ConfigPanel panel, Friend friend)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			ConfigPanel val = new ConfigPanel(panel, ((Friend)(ref friend)).Name, "friend_" + friend.Id.Value, (PanelFieldType)1);
			val.buttonText = "CONFIG";
			BoolField value = new BoolField(val, "Show Times of " + ((Friend)(ref friend)).Name, "friend_" + friend.Id.Value + "_vis", true);
			UserVisibilityToggles.Add(friend.Id, value);
			UserPanels.Add(friend.Id, val);
			SetUserIcon(friend);
		}

		private static void SetUserIcon(Friend friend)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0035: 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_004c: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			if (UserPanels.ContainsKey(friend.Id))
			{
				ConfigPanel val = UserPanels[friend.Id];
				GameObject val2 = new GameObject();
				RawImage val3 = val2.AddComponent<RawImage>();
				SteamController.FetchAvatar(val3, friend);
				Texture2D val4 = FlipTexture((Texture2D)val3.texture);
				val.icon = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), Vector2.one * 0.5f);
				Object.Destroy((Object)(object)val2);
			}
		}

		private static Texture2D FlipTexture(Texture2D original)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(((Texture)original).width, ((Texture)original).height);
			for (int i = 0; i < ((Texture)original).width; i++)
			{
				for (int j = 0; j < ((Texture)original).height; j++)
				{
					val.SetPixel(i, ((Texture)original).height - j - 1, original.GetPixel(i, j));
				}
			}
			val.Apply();
			return val;
		}

		private IEnumerator CreateConfigTimes(ConfigPanel timePanel)
		{
			LeaderboardLocalTimeManager timeManager = LeaderboardLocalTimeManager.Instance;
			foreach (string level in timeManager.GetAllLevels())
			{
				string id = level.ToLower().Replace(" ", "_");
				string levelName = level.Replace("Level ", "");
				switch (levelName[0])
				{
				case '0':
				{
					string hex = "#fc3d03";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '1':
				{
					string hex = "#81ff70";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '2':
				{
					string hex = "#9746f2";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '3':
				{
					string hex = "#b32a20";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '4':
				{
					string hex = "#edbd39";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '5':
				{
					string hex = "#5ea6f7";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '6':
				{
					string hex = "#ff2119";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '7':
				{
					string hex = "#ffffff";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '8':
				{
					string hex = "#448f42";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case '9':
				{
					string hex = "#448f42";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				case 'P':
				{
					string hex = "#f20039";
					levelName = "<color=" + hex + ">" + levelName + "</color>";
					break;
				}
				}
				ConfigPanel levelPanel = new ConfigPanel(timePanel, "CONFIG " + levelName.ToUpper() + " DATA", id + "_panel", (PanelFieldType)3);
				ConfigPanel anyLevelPanel = new ConfigPanel(levelPanel, "CONFIG " + levelName.ToUpper() + " <color=#" + ColorUtility.ToHtmlStringRGB(AnyRecordColor.value) + ">ANY%</color> TIMES", id + "_any_panel", (PanelFieldType)3);
				ConfigPanel pRankLevelPanel = new ConfigPanel(levelPanel, "CONFIG " + levelName.ToUpper() + " <color=#" + ColorUtility.ToHtmlStringRGB(PRankRecordColor.value) + ">P-RANK</color> TIMES", id + "_p_rank_panel", (PanelFieldType)3);
				anyLevelPanel.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
				{
					((MonoBehaviour)this).StartCoroutine(CreateTimesForLevel(level, id, levelName, " Any%", anyLevelPanel));
				};
				anyLevelPanel.onPannelCloseEvent += (ClosePanelEventDelegate)delegate
				{
					for (int i = 0; i < anyLevelPanel.fieldCount; i++)
					{
						anyLevelPanel.FieldAt(i).hidden = true;
					}
				};
				pRankLevelPanel.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
				{
					((MonoBehaviour)this).StartCoroutine(CreateTimesForLevel(level, id, levelName, " PRank", pRankLevelPanel));
				};
				pRankLevelPanel.onPannelCloseEvent += (ClosePanelEventDelegate)delegate
				{
					for (int i = 0; i < pRankLevelPanel.fieldCount; i++)
					{
						pRankLevelPanel.FieldAt(i).hidden = true;
					}
				};
			}
			yield break;
		}

		private IEnumerator CreateTimesForLevel(string level, string id, string levelName, string key, ConfigPanel levelPanel)
		{
			Task<LeaderboardLocalTime> localTimeDataFetch = LeaderboardLocalTimeManager.Instance.GetTimesForLevel(level);
			while (!localTimeDataFetch.IsCompleted)
			{
				yield return null;
			}
			LeaderboardLocalTime localTimeData = localTimeDataFetch.Result;
			bool isPRank = key.Contains("PRank");
			float[] times = (isPRank ? localTimeData.PRankTime : localTimeData.Time);
			string buttonText = (isPRank ? "prank" : "any");
			string buttonNameText = (isPRank ? ("<color=#" + ColorUtility.ToHtmlStringRGB(PRankRecordColor.value) + ">P-RANK</color>") : ("<color=#" + ColorUtility.ToHtmlStringRGB(AnyRecordColor.value) + ">ANY%</color>"));
			for (int i = 0; i < times.Length; i++)
			{
				string boardKey = level + key;
				Log.LogDebug("Fetching leaderboard for " + boardKey + "...");
				Task<Leaderboard?> leaderboardFetch = SteamController.FetchSteamLeaderboard(boardKey, false, (LeaderboardSort)1, (LeaderboardDisplay)3);
				while (!leaderboardFetch.IsCompleted)
				{
					yield return null;
				}
				if (!leaderboardFetch.Result.HasValue)
				{
					continue;
				}
				Leaderboard leaderboard = leaderboardFetch.Result.Value;
				if (!(times[i] <= 0f))
				{
					string diffName = DifficultyFinder.Instance.DifficultyNames[i];
					Task<LeaderboardEntry[]> leaderboardEntryFetch = ((Leaderboard)(ref leaderboard)).GetScoresForUsersAsync((SteamId[])(object)new SteamId[1] { SteamClient.SteamId });
					while (!leaderboardEntryFetch.IsCompleted)
					{
						yield return null;
					}
					bool isSteamValue = Mathf.Abs(times[i] - (float)leaderboardEntryFetch.Result[0].Score / 1000f) < 0.002f;
					string added = (isSteamValue ? "<color=blue>(ON STEAM)</color>" : "");
					ConfigPanel diffSubMenu = new ConfigPanel(levelPanel, $"[{diffName}] {times[i]:0.000}s {added}", id + "_" + buttonText + "_time_panel_" + i, (PanelFieldType)3);
					int diff = i;
					ConfigPanel steamDisplayButton = new ConfigPanel(diffSubMenu, "Display " + levelName + " " + buttonNameText + " TIME [" + diffName + "] on STEAM", id + "_" + buttonText + "_steam_display_button_" + i, (PanelFieldType)2)
					{
						buttonText = "DISPLAY ON STEAM",
						icon = MakeSpriteFronFileName("steam.png")
					};
					steamDisplayButton.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
					{
						int[] array = new int[leaderboardEntryFetch.Result[0].Details.Length];
						Array.Copy(leaderboardEntryFetch.Result[0].Details, array, array.Length);
						array[0] = diff;
						((Leaderboard)(ref leaderboard)).ReplaceScore((int)(times[diff] * 1000f), array);
						((ConfigField)steamDisplayButton).interactable = false;
						steamDisplayButton.ClosePanel();
					};
					((ConfigField)steamDisplayButton).interactable = !isSteamValue;
					new ConfigHeader(diffSubMenu, "<color=red>--Danger Zone--</color>", 24);
					ConfigPanel eraseButton = new ConfigPanel(diffSubMenu, "Erase " + levelName + " " + buttonNameText + " TIME [" + diffName + "]", id + "_" + buttonText + "_erase_button_" + i)
					{
						buttonText = "ERASE"
					};
					new ConfigHeader(eraseButton, "<color=red>--Are you sure?--</color>", 24);
					ConfigPanel eraseConfirmButton = new ConfigPanel(eraseButton, "PRETTY SURE! - DELETE", id + "_" + buttonText + "_erase_button_" + i, (PanelFieldType)3);
					eraseConfirmButton.onPannelOpenEvent += (OpenPanelEventDelegate)delegate
					{
						LeaderboardLocalTimeManager.Instance.ResetLocalTime(level, diff, isPRank);
						eraseConfirmButton.ClosePanel();
						eraseButton.ClosePanel();
						diffSubMenu.ClosePanel();
					};
				}
			}
		}

		private void CreateConfigDifficulties(ConfigPanel diffPanel)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00ce: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Expected O, but got Unknown
			((ConfigField)diffPanel).interactable = !DiffVis.value || !BlockAllRecords.value || AllowAllLocalTimes.value;
			ActiveDiffVis.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				DiffVis.value = DiffVis.value && e.value;
				((ConfigField)DiffVis).interactable = e.value;
				DiffVis.TriggerValueChangeEvent();
			};
			ConfigHeader val = new ConfigHeader(diffPanel, "--ACCESSIBLE--", 24);
			val.textColor = HarmlessColor;
			DifficultyOption difficultyOption = DifficultyOption.Create((GameDifficulty)0, diffPanel, HarmlessColor);
			DifficultyOption difficultyOption2 = DifficultyOption.Create((GameDifficulty)1, diffPanel, LenientColor);
			ConfigHeader val2 = new ConfigHeader(diffPanel, "", 24);
			ConfigHeader val3 = new ConfigHeader(diffPanel, "--HARD--", 24);
			val3.textColor = StandardColor;
			DifficultyOption difficultyOption3 = DifficultyOption.Create((GameDifficulty)2, diffPanel, StandardColor);
			DifficultyOption difficultyOption4 = DifficultyOption.Create((GameDifficulty)3, diffPanel, ViolentColor);
			ConfigHeader val4 = new ConfigHeader(diffPanel, "", 24);
			ConfigHeader val5 = new ConfigHeader(diffPanel, "--VERY HARD--", 24);
			val5.textColor = BrutalColor;
			DifficultyOption difficultyOption5 = DifficultyOption.Create((GameDifficulty)4, diffPanel, BrutalColor);
			DifficultyOption difficultyOption6 = DifficultyOption.Create((GameDifficulty)5, diffPanel, UKMDColor);
			DiffVis.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				foreach (DifficultyOption value in DifficultyVisibility.Values)
				{
					((ConfigField)value.VisibilityField).interactable = !e.value;
				}
				((ConfigField)diffPanel).interactable = !e.value || !BlockAllRecords.value || AllowAllLocalTimes.value;
			};
			BlockAllRecords.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				foreach (DifficultyOption value2 in DifficultyVisibility.Values)
				{
					((ConfigField)value2.RecordSetField).interactable = !e.value;
				}
				((ConfigField)diffPanel).interactable = !DiffVis.value || !e.value || AllowAllLocalTimes.value;
			};
			AllowAllLocalTimes.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				foreach (DifficultyOption value3 in DifficultyVisibility.Values)
				{
					((ConfigField)value3.LocalTimeSetField).interactable = e.value;
				}
				((ConfigField)diffPanel).interactable = !DiffVis.value || !BlockAllRecords.value || e.value;
			};
		}
	}
}
namespace UltrakillDifficultyLeaderboard.Scripts
{
	public class CustomLayerSelect : MonoBehaviour
	{
		private float cachedSize;

		private static float sizeChange = 30f;

		private GameObject row;

		private async void OnEnable()
		{
			await Task.Delay(60);
			if (Object.op_Implicit((Object)(object)row) && Object.op_Implicit((Object)(object)row.GetComponent<GridLayoutGroup>()))
			{
				if (cachedSize == 0f)
				{
					cachedSize = row.GetComponent<GridLayoutGroup>().cellSize.y;
				}
				row.GetComponent<GridLayoutGroup>().cellSize = new Vector2(row.GetComponent<GridLayoutGroup>().cellSize.x, cachedSize + sizeChange);
			}
			await Task.Delay(10);
			LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)((Component)this).transform).GetComponent<RectTransform>());
			LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)row.transform).GetComponent<RectTransform>());
		}

		private async void Start()
		{
			await Task.Delay(50);
			row = ((Component)((Component)this).transform.Find("Level Row")).gameObject;
		}
	}
	public class CustomLeaderboardPanel : MonoBehaviour
	{
		private float cachedSize;

		private float cachedLeaderboardSize;

		private static float sizeChange = 30f;

		private GameObject sortButtonsHolder;

		private GameObject sortButton;

		private GameObject sortDirectionButton;

		private GameObject difficultyOrderButton;

		private GameObject difficultyFilterButton;

		private Transform leaderboardContainer;

		private LevelSelectLeaderboard leaderboard;

		private GameObject previousHovered = null;

		private GameObject currentHovered = null;

		private Dictionary<GameObject, string> tooltipNames = new Dictionary<GameObject, string>();

		public TimeSortingBehavior behavior = TimeSortingBehavior.Time;

		public SortingDirection direction = SortingDirection.Descending;

		public DifficultySortingBehavior difficulty = DifficultySortingBehavior.NoSorting;

		public bool hideOtherDifficulties = false;

		public static Dictionary<string, CustomLeaderboardPanel> panels = new Dictionary<string, CustomLeaderboardPanel>();

		private async void OnEnable()
		{
			await Task.Delay(60);
			RectTransform rectTransform = ((Component)this).GetComponent<RectTransform>();
			if (cachedSize == 0f)
			{
				cachedSize = rectTransform.offsetMin.y;
			}
			rectTransform.offsetMin = new Vector2(rectTransform.offsetMin.x, cachedSize - sizeChange);
			if ((Object)(object)leaderboard != (Object)null)
			{
				panels.TryAdd("Level " + leaderboard.layerLevelNumber, this);
				if (Object.op_Implicit((Object)(object)sortButtonsHolder))
				{
					sortButtonsHolder.transform.localPosition = new Vector3(0f, -66f, 0f);
					RectTransform sortButtonsHolderRect = sortButtonsHolder.GetComponent<RectTransform>();
					sortButtonsHolderRect.anchorMin = new Vector2(0f, 0f);
					sortButtonsHolderRect.anchorMax = new Vector2(1f, 0f);
					sortButtonsHolderRect.offsetMin = new Vector2(10f, 8f);
					sortButtonsHolderRect.offsetMax = new Vector2(-10f, 35f);
				}
				if ((Object)(object)leaderboardContainer != (Object)null)
				{
					RectTransform containerRect = ((Component)leaderboardContainer).GetComponent<RectTransform>();
					if (cachedLeaderboardSize == 0f)
					{
						cachedLeaderboardSize = containerRect.offsetMin.y;
					}
					containerRect.offsetMin = new Vector2(containerRect.offsetMin.x, cachedLeaderboardSize + sizeChange);
				}
				if (Object.op_Implicit((Object)(object)sortButton))
				{
					RectTransform buttonRect = sortButton.GetComponent<RectTransform>();
					buttonRect.anchorMin = new Vector2(0.5f, 0.5f);
					buttonRect.anchorMax = new Vector2(0.5f, 0.5f);
				}
				if (Object.op_Implicit((Object)(object)difficultyOrderButton))
				{
					RectTransform buttonRect2 = difficultyOrderButton.GetComponent<RectTransform>();
					buttonRect2.anchorMin = new Vector2(0f, 0.5f);
					buttonRect2.anchorMax = new Vector2(0f, 0.5f);
				}
			}
			RefreshAllButtons();
		}

		private async void Start()
		{
			await Task.Delay(50);
			Transform leaderboardTransform = ((Component)this).transform.Find("Level Select Leaderboard");
			leaderboard = ((Component)leaderboardTransform).GetComponent<LevelSelectLeaderboard>();
			if ((Object)(object)leaderboardTransform != (Object)null)
			{
				sortButtonsHolder = new GameObject("Sort Buttons Holder", new Type[2]
				{
					typeof(RectTransform),
					typeof(HorizontalLayoutGroup)
				});
				sortButtonsHolder.transform.SetParent(leaderboardTransform);
				sortButtonsHolder.transform.localScale = new Vector3(1f, 1f, 1f);
				HorizontalLayoutGroup sortButtonsHolderComponent = sortButtonsHolder.GetComponent<HorizontalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)sortButtonsHolderComponent).spacing = 3f;
				((LayoutGroup)sortButtonsHolderComponent).childAlignment = (TextAnchor)4;
				((HorizontalOrVerticalLayoutGroup)sortButtonsHolderComponent).childScaleWidth = true;
				((HorizontalOrVerticalLayoutGroup)sortButtonsHolderComponent).childForceExpandWidth = false;
				leaderboardContainer = leaderboardTransform.Find("ScrollRect Container");
			}
		}

		private void RefreshLeaderboard()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)leaderboard).transform.Find("Mode Buttons");
			if ((Object)(object)val != (Object)null)
			{
				val = val.Find("P Rank Button");
				bool flag = ((Graphic)((Component)val).GetComponentInChildren<TMP_Text>()).color == Color.black;
				leaderboard.SwitchLeaderboardType(flag);
			}
		}

		private void RefreshAllButtons()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			Transform val = ((Component)this).transform.Find("Level Select Leaderboard");
			Transform val2 = val.Find("Mode Buttons");
			if ((Object)(object)val2 != (Object)null)
			{
				val2 = val2.Find("P Rank Button");
				if ((Object)(object)val2 != (Object)null)
				{
					CreateButton(ref sortButton, "Sort Type Button", "Leaderboard Sorting Type", val2, new UnityAction(CycleSortType));
					CreateButton(ref sortDirectionButton, "Sort Direction Button", "Leaderboard Direction", val2, new UnityAction(CycleSortDirection));
					CreateButton(ref difficultyOrderButton, "Difficulty Order Button", "Sort Leaderboard by Difficulty", val2, new UnityAction(CycleSortDifficulty));
					CreateButton(ref difficultyFilterButton, "Difficulty Filter Button", "Hide other difficulties from Leaderboard", val2, new UnityAction(CycleShowOtherDifficulties));
				}
			}
			TimeSortingBehavior value = LeaderboardPlugin.Instance.TypeSortingBehavior.value;
			SortingDirection value2 = LeaderboardPlugin.Instance.TypeSortingDirection.value;
			DifficultySortingBehavior value3 = LeaderboardPlugin.Instance.PerDifficultySortingBehavior.value;
			bool value4 = LeaderboardPlugin.Instance.DiffVis.value;
			UpdateSortType(value);
			UpdateSortDirection(value2);
			UpdateSortDifficulty(value3);
			UpdateShowDifficulty(value4);
		}

		private void CreateButton(ref GameObject buttonRef, string buttonName, string toolTip, Transform prefab, UnityAction action)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)buttonRef))
			{
				buttonRef = Object.Instantiate<GameObject>(((Component)prefab).gameObject, sortButtonsHolder.transform, true);
				((Object)buttonRef).name = buttonName;
				Button component = buttonRef.GetComponent<Button>();
				component.onClick = new ButtonClickedEvent();
				((UnityEvent)component.onClick).AddListener(action);
				tooltipNames.Add(buttonRef, toolTip);
			}
		}

		private void Update()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			currentHovered = null;
			foreach (RaycastResult item in RaycastMouse())
			{
				RaycastResult current = item;
				if ((Object)(object)((RaycastResult)(ref current)).gameObject == (Object)(object)sortButton)
				{
					currentHovered = sortButton;
				}
				if ((Object)(object)((RaycastResult)(ref current)).gameObject == (Object)(object)sortDirectionButton)
				{
					currentHovered = sortDirectionButton;
				}
				if ((Object)(object)((RaycastResult)(ref current)).gameObject == (Object)(object)difficultyOrderButton)
				{
					currentHovered = difficultyOrderButton;
				}
				if ((Object)(object)((RaycastResult)(ref current)).gameObject == (Object)(object)difficultyFilterButton)
				{
					currentHovered = difficultyFilterButton;
				}
			}
			if ((Object)(object)previousHovered != (Object)(object)currentHovered)
			{
				DifficultyFinder.Instance.StopHover();
				previousHovered = currentHovered;
			}
			if (Object.op_Implicit((Object)(object)currentHovered) && tooltipNames.ContainsKey(currentHovered))
			{
				DifficultyFinder.Instance.UpdateTooltip(tooltipNames[currentHovered]);
			}
		}

		private void OnDisable()
		{
			DifficultyFinder.Instance.StopHover();
		}

		public unsafe List<RaycastResult> RaycastMouse()
		{
			//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_0014: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			PointerEventData val = new PointerEventData(EventSystem.current)
			{
				pointerId = -1
			};
			val.position = Unsafe.Read<Vector2>((void*)((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).value);
			List<RaycastResult> list = new List<RaycastResult>();
			EventSystem.current.RaycastAll(val, list);
			Debug.Log((object)list.Count);
			return list;
		}

		private void CycleSortType()
		{
			if (behavior == TimeSortingBehavior.Time)
			{
				UpdateSortType(TimeSortingBehavior.Alphabetical);
			}
			else if (behavior == TimeSortingBehavior.Alphabetical)
			{
				UpdateSortType(TimeSortingBehavior.Time);
			}
			RefreshLeaderboard();
		}

		private void UpdateSortType(TimeSortingBehavior newBehavior)
		{
			string text = ((newBehavior == TimeSortingBehavior.Time) ? "TIME" : "ABC");
			behavior = newBehavior;
			((TMP_Text)sortButton.GetComponentInChildren<TextMeshProUGUI>()).text = text;
		}

		private void CycleSortDirection()
		{
			if (direction == SortingDirection.Ascending)
			{
				UpdateSortDirection(SortingDirection.Descending);
			}
			else if (direction == SortingDirection.Descending)
			{
				UpdateSortDirection(SortingDirection.Ascending);
			}
			RefreshLeaderboard();
		}

		private void UpdateSortDirection(SortingDirection newDirection)
		{
			string text = ((newDirection == SortingDirection.Descending) ? "UP" : "DOWN");
			direction = newDirection;
			((TMP_Text)sortDirectionButton.GetComponentInChildren<TextMeshProUGUI>()).text = text;
		}

		private void CycleSortDifficulty()
		{
			if (difficulty == DifficultySortingBehavior.NoSorting)
			{
				UpdateSortDifficulty(DifficultySortingBehavior.PerDifficulty);
			}
			else if (difficulty == DifficultySortingBehavior.PerDifficulty)
			{
				UpdateSortDifficulty(DifficultySortingBehavior.NoSorting);
			}
			RefreshLeaderboard();
		}

		private void UpdateSortDifficulty(DifficultySortingBehavior newBehavior)
		{
			string text = ((newBehavior == DifficultySortingBehavior.PerDifficulty) ? "DIFF" : "GLOBAL");
			difficulty = newBehavior;
			((TMP_Text)difficultyOrderButton.GetComponentInChildren<TextMeshProUGUI>()).text = text;
		}

		private void CycleShowOtherDifficulties()
		{
			UpdateShowDifficulty(!hideOtherDifficulties);
			RefreshLeaderboard();
		}

		private void UpdateShowDifficulty(bool newBehavior)
		{
			hideOtherDifficulties = newBehavior;
			string text = (hideOtherDifficulties ? "FILTER" : "SHOW");
			((TMP_Text)difficultyFilterButton.GetComponentInChildren<TextMeshProUGUI>()).text = text;
		}
	}
	public class DifficultyFinder : MonoBehaviour
	{
		private GameObject tooltip;

		private GameObject canvas;

		private bool didTooltip = false;

		public Dictionary<int, string> DifficultyNames = new Dictionary<int, string>();

		public int max = 0;

		public static DifficultyFinder Instance { get; private set; }

		public static void Create()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			if (SceneHelper.IsSceneRankless && (!Object.op_Implicit((Object)(object)Instance) || Object.FindObjectsOfType<DifficultyFinder>().Length == 0))
			{
				GameObject val = new GameObject("DifficultyFinder");
				DifficultyFinder instance = val.AddComponent<DifficultyFinder>();
				Instance = instance;
			}
		}

		private void Start()
		{
			CustomLeaderboardPanel.panels.Clear();
			DifficultySelectButton[] source = Object.FindObjectsOfType<DifficultySelectButton>(true);
			List<DifficultySelectButton> source2 = source.ToList();
			source2 = new List<DifficultySelectButton>(source2.OrderBy((DifficultySelectButton x) => x.difficulty));
			foreach (DifficultySelectButton item in source2)
			{
				max = Mathf.Max(max, item.difficulty + 1);
				if (!((Object)(object)((Component)item).transform.Find("Under Construction") != (Object)null))
				{
					TMP_Text component = ((Component)((Component)item).transform.Find("Name")).GetComponent<TMP_Text>();
					string text = component.text;
					text = text.Replace(" <color=orange>*</color>", "");
					text = text.Replace("ULTRAKILL MUST DIE", "UKMD");
					text = text.Replace("Bananas Difficulty", "BANANAS");
					text = text.ToUpper();
					DifficultyNames.TryAdd(item.difficulty, text);
					LeaderboardPlugin.Log.LogDebug($"Difficulty {text} ({item.difficulty}) Added");
				}
			}
			canvas = ((Component)Object.FindAnyObjectByType<ColorBlindActivator>()).gameObject;
		}

		private unsafe void Update()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)tooltip) && tooltip.activeSelf)
			{
				tooltip.transform.position = new Vector3(*(float*)((InputControl<float>)(object)((Pointer)Mouse.current).position.x).value, *(float*)((InputControl<float>)(object)((Pointer)Mouse.current).position.y).value + 30f, 0f);
			}
		}

		private void LateUpdate()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_007f: 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_00f5: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)tooltip) && !didTooltip)
			{
				tooltip = new GameObject("TooltipObject", new Type[1] { typeof(RectTransform) });
				tooltip.transform.SetParent(canvas.transform);
				didTooltip = true;
				RectTransform component = tooltip.GetComponent<RectTransform>();
				component.offsetMin = new Vector2(0f, 0f);
				component.offsetMax = new Vector2(0f, 0f);
				Transform val = canvas.transform.Find("Main Menu (1)").Find("LeftSide").Find("Credits");
				GameObject val2 = new GameObject("TooltipImage", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val2.transform.SetParent(tooltip.transform);
				val2.transform.localPosition = Vector3.zero;
				val2.transform.localScale = Vector3.one;
				RectTransform component2 = val2.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0.5f, 0.5f);
				component2.anchorMax = new Vector2(0.5f, 0.5f);
				component2.offsetMin = new Vector2(-50f, -20f);
				component2.offsetMax = new Vector2(50f, 20f);
				val2.GetComponent<Image>().type = (Type)1;
				val2.GetComponent<Image>().pixelsPerUnitMultiplier = 4.05f;
				val2.GetComponent<Image>().sprite = ((Component)val).GetComponent<Image>().sprite;
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val.Find("Text")).gameObject, val2.transform, true);
				val3.transform.localPosition = Vector3.zero;
				val3.transform.localScale = Vector3.one;
				TMP_Text component3 = (TMP_Text)(object)val3.GetComponent<TextMeshProUGUI>();
				component3.fontStyle = (FontStyles)0;
				component3.fontSize = 18f;
				RectTransform component4 = val3.GetComponent<RectTransform>();
				component4.anchorMin = new Vector2(0.5f, 0.5f);
				component4.anchorMax = new Vector2(0.5f, 0.5f);
				component4.offsetMin = component2.offsetMin;
				component4.offsetMax = component2.offsetMax;
				UpdateTooltip("This is a tooltip");
				StopHover();
			}
		}

		public unsafe void UpdateTooltip(string text)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: 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)
			//IL_013c: 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_01ac: 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_01da: 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)
			if (Object.op_Implicit((Object)(object)tooltip) && !tooltip.activeSelf)
			{
				tooltip.SetActive(true);
				tooltip.transform.position = new Vector3(*(float*)((InputControl<float>)(object)((Pointer)Mouse.current).position.x).value, *(float*)((InputControl<float>)(object)((Pointer)Mouse.current).position.y).value + 30f, 0f);
				LeaderboardPlugin.Log.LogDebug("Updating " + text);
				Transform val = tooltip.transform.Find("TooltipImage");
				Transform val2 = val.Find("Text(Clone)");
				TMP_Text component = (TMP_Text)(object)((Component)val2).GetComponent<TextMeshProUGUI>();
				component.text = text;
				bool flag = *(float*)((InputControl<float>)(object)((Pointer)Mouse.current).position.x).value < (float)Screen.width / 2f;
				float preferredWidth = component.preferredWidth;
				RectTransform component2 = ((Component)val).GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0.5f, 0.5f);
				component2.anchorMax = new Vector2(0.5f, 0.5f);
				if (flag)
				{
					component2.offsetMin = new Vector2(-18f, -18f);
					component2.offsetMax = new Vector2(preferredWidth + 18f, 18f);
				}
				else
				{
					component2.offsetMin = new Vector2(0f - preferredWidth - 18f, -18f);
					component2.offsetMax = new Vector2(18f, 18f);
				}
				RectTransform component3 = ((Component)val2).GetComponent<RectTransform>();
				component3.anchorMin = new Vector2(0.5f, 0.5f);
				component3.anchorMax = new Vector2(0.5f, 0.5f);
				component3.offsetMin = new Vector2(-500f, -18f);
				component3.offsetMax = new Vector2(500f, 18f);
			}
		}

		public void StopHover()
		{
			if (Object.op_Implicit((Object)(object)tooltip))
			{
				tooltip.SetActive(false);
			}
		}
	}
}
namespace UltrakillDifficultyLeaderboard.HarmonyPatches
{
	[HarmonyPatch(typeof(DifficultySelectButton))]
	public class DifficultySelectButtonPatch
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__0_0;

			internal void <StartPostfix>b__0_0()
			{
				LeaderboardPlugin.Instance.RefreshFriends();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void StartPostfix(DifficultySelectButton __instance)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ButtonClickedEvent onClick = ((Component)__instance).gameObject.GetComponent<Button>().onClick;
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					LeaderboardPlugin.Instance.RefreshFriends();
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
		}
	}
	[HarmonyPatch(typeof(GameProgressSaver))]
	public class GameProgressSaverPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("SetBestCyber")]
		private static bool SetBestCyberPrefix(ref FinalCyberRank fcr)
		{
			int num = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if ((LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)num) || LeaderboardPlugin.Instance.BlockAllCybergrindRecords.value) && (!LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)num].LocalTimeSetField.value || LeaderboardPlugin.Instance.BlockAllCybergrindRecords.value))
			{
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		[HarmonyPatch("PrepareFs")]
		private static void PrepareFsPostfix()
		{
		}
	}
	[HarmonyPatch(typeof(LeaderboardController))]
	public class LeaderboardControllerPatch
	{
		public static Dictionary<string, LoadedLeaderboardEntry> LeaderboardEntriesMap = new Dictionary<string, LoadedLeaderboardEntry>();

		private static CustomLeaderboardPanel panel;

		[HarmonyPostfix]
		[HarmonyPatch("FetchLeaderboardEntries")]
		private static void FetchLeaderboardEntriesPostfix(string key, LeaderboardType type, int count, bool createIfNotFound, LeaderboardSort defaultSortMode, ref Task<LeaderboardEntry[]> __result)
		{
			if (!key.Contains("Cyber Grind"))
			{
				bool pRankFromKey = GetPRankFromKey(key);
				string levelFromKey = GetLevelFromKey(key);
				Task<LeaderboardEntry[]> task = ModifyLeaderboardEntries(levelFromKey, pRankFromKey, __result);
				__result = task;
			}
		}

		public static string GetLevelFromKey(string key)
		{
			if (key.StartsWith("Level "))
			{
				bool pRankFromKey = GetPRankFromKey(key);
				if (!string.IsNullOrWhiteSpace(key))
				{
					int num = key.IndexOf(pRankFromKey ? " PRank" : " Any%", StringComparison.Ordinal);
					if (num > 0)
					{
						return key.Substring(0, num);
					}
				}
			}
			return "";
		}

		public static bool GetPRankFromKey(string key)
		{
			return key.Contains("PRank");
		}

		[HarmonyPrefix]
		[HarmonyPatch("SubmitCyberGrindScore")]
		private static bool SubmitCyberGrindScorePrefix(ref int difficulty, ref float wave, ref int kills, ref int style, ref float seconds)
		{
			if ((LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)difficulty) || LeaderboardPlugin.Instance.BlockAllCybergrindRecords.value) && (!LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)difficulty].RecordSetField.value || LeaderboardPlugin.Instance.BlockAllCybergrindRecords.value))
			{
				return false;
			}
			return true;
		}

		[HarmonyPrefix]
		[HarmonyPatch("SubmitLevelScore")]
		private static bool SubmitScoreAsyncPrefix(ref string levelName, ref int difficulty, ref float seconds, ref int kills, ref int style, ref int restartCount, ref bool pRank)
		{
			if (LeaderboardPlugin.Instance.BlockAllRecords.value)
			{
				return false;
			}
			if (LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)difficulty) && !LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)difficulty].RecordSetField.value)
			{
				return false;
			}
			if (LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)difficulty) && LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)difficulty].LocalTimeSetField.value && LeaderboardPlugin.Instance.AllowAllLocalTimes.value)
			{
				LeaderboardLocalTimeManager.Instance.SetBestLocalTime(levelName, difficulty, seconds, pRank);
			}
			return true;
		}

		private static async Task<LeaderboardEntry[]> ModifyLeaderboardEntries(string levelName, bool pRank, Task<LeaderboardEntry[]> original)
		{
			LeaderboardEntry[] entries = await original;
			if (CustomLeaderboardPanel.panels.ContainsKey(levelName))
			{
				panel = CustomLeaderboardPanel.panels[levelName];
			}
			if (entries == null)
			{
				return (LeaderboardEntry[])(object)new LeaderboardEntry[0];
			}
			List<LeaderboardEntry> modifiedEntries = new List<LeaderboardEntry>();
			List<LeaderboardEntry> serverEntries = new List<LeaderboardEntry>();
			List<LeaderboardEntry> preEntries = new List<LeaderboardEntry>(entries);
			int difficulty = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			if (!string.IsNullOrEmpty(levelName))
			{
				for (int i = 0; i < DifficultyFinder.Instance.max; i++)
				{
					foreach (Friend f in LeaderboardLocalTimeManager.Instance.FriendsList)
					{
						float localTime = await LeaderboardLocalTimeManager.Instance.GetBestLocalTime(levelName, f.Id, i, pRank);
						if (localTime > 0f)
						{
							LeaderboardEntry localEntry = new LeaderboardEntry
							{
								User = f,
								Score = (int)(localTime * 1000f),
								Details = new int[1] { i }
							};
							Array.Resize(ref entries, entries.Length + 1);
							entries[^1] = localEntry;
							serverEntries.Add(localEntry);
						}
					}
				}
			}
			bool showOnlyActive = (Object.op_Implicit((Object)(object)panel) ? panel.hideOtherDifficulties : LeaderboardPlugin.Instance.DiffVis.value);
			bool showActive = LeaderboardPlugin.Instance.ActiveDiffVis.value || showOnlyActive;
			int personalBestTime = int.MaxValue;
			for (int j = 0; j < entries.Length; j++)
			{
				LeaderboardEntry entry = entries[j];
				bool isOtherAndHidden = (LeaderboardPlugin.Instance.HideOthers.value || (LeaderboardPlugin.UserVisibilityToggles.ContainsKey(entry.User.Id) && !LeaderboardPlugin.UserVisibilityToggles[entry.User.Id].value)) && !((Friend)(ref entry.User)).IsMe;
				if (showActive && entry.Details[0] == difficulty && !isOtherAndHidden)
				{
					modifiedEntries.Add(entry);
				}
				else if (!showOnlyActive && LeaderboardPlugin.DifficultyVisibility.ContainsKey((GameDifficulty)entry.Details[0]) && LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)entry.Details[0]].VisibilityField.value && !isOtherAndHidden)
				{
					modifiedEntries.Add(entry);
				}
				else
				{
					entry = default(LeaderboardEntry);
				}
			}
			personalBestTime = Mathf.Min(personalBestTime, (from e in modifiedEntries
				where ((Friend)(ref e.User)).IsMe
				orderby e.Score
				select e).FirstOrDefault().Score);
			int personalBestTimeOnDifficulty = Mathf.Min(personalBestTime, (from e in modifiedEntries
				where ((Friend)(ref e.User)).IsMe && e.Details[0] == difficulty
				orderby e.Score
				select e).FirstOrDefault().Score);
			foreach (Friend f2 in LeaderboardLocalTimeManager.Instance.FriendsList)
			{
				SteamId currentId = f2.Id;
				for (int i2 = 0; i2 < DifficultyFinder.Instance.max; i2++)
				{
					LeaderboardEntry lowestEntry = (from e in modifiedEntries
						where SteamId.op_Implicit(e.User.Id) == SteamId.op_Implicit(currentId) && e.Details[0] == i2
						orderby e.Score
						select e).FirstOrDefault();
					LeaderboardEntry lowestExistingEntry = (from e in serverEntries
						where SteamId.op_Implicit(e.User.Id) == SteamId.op_Implicit(currentId) && e.Details[0] == i2
						orderby e.Score
						select e).FirstOrDefault();
					LeaderboardEntry lowestSteamEntry = (from e in preEntries
						where SteamId.op_Implicit(e.User.Id) == SteamId.op_Implicit(currentId) && e.Details[0] == i2
						orderby e.Score
						select e).FirstOrDefault();
					if (SteamId.op_Implicit(currentId) == SteamId.op_Implicit(SteamClient.SteamId) && lowestSteamEntry.Score > 0 && (lowestExistingEntry.Score > lowestSteamEntry.Score || lowestExistingEntry.Score == 0))
					{
						LeaderboardPlugin.Log.LogDebug($"{levelName} {i2} Best saved for {currentId.Value}: {lowestExistingEntry.Score}ms");
						LeaderboardPlugin.Log.LogDebug($"{levelName} {i2} Best steam for {currentId.Value}: {lowestSteamEntry.Score}ms");
						await LeaderboardLocalTimeManager.Instance.SetBestLocalTime(levelName, i2, (float)lowestSteamEntry.Score / 1000f, pRank);
					}
					modifiedEntries.RemoveAll((LeaderboardEntry e) => modifiedEntries.IndexOf(e) != modifiedEntries.IndexOf(lowestEntry) && SteamId.op_Implicit(e.User.Id) == SteamId.op_Implicit(currentId) && e.Details[0] == i2 && e.Score >= lowestEntry.Score);
				}
			}
			if (LeaderboardPlugin.Instance.HideTimesAboveYourOwn.value)
			{
				modifiedEntries.RemoveAll((LeaderboardEntry e) => !((Friend)(ref e.User)).IsMe && e.Score < personalBestTime);
			}
			DifficultySortingBehavior difficultySortingBehavior = (Object.op_Implicit((Object)(object)panel) ? panel.difficulty : LeaderboardPlugin.Instance.PerDifficultySortingBehavior.value);
			if (difficultySortingBehavior == DifficultySortingBehavior.PerDifficulty)
			{
				modifiedEntries = SortPerDifficulty(modifiedEntries);
			}
			else
			{
				modifiedEntries = SortEntries(modifiedEntries);
			}
			int best = ((difficultySortingBehavior == DifficultySortingBehavior.PerDifficulty) ? personalBestTimeOnDifficulty : personalBestTime);
			LoadedLeaderboardEntry leaderboard = new LoadedLeaderboardEntry(personalBestIndex: modifiedEntries.FindIndex((LeaderboardEntry e) => e.Score == best), personalBestToHighlightIndex: modifiedEntries.FindIndex((LeaderboardEntry e) => e.Score == personalBestTime), entries: modifiedEntries, isPRank: pRank, isSortedByDifficulty: difficultySortingBehavior == DifficultySortingBehavior.PerDifficulty);
			panel = null;
			LeaderboardEntriesMap[levelName] = leaderboard;
			return modifiedEntries.ToArray();
		}

		private static List<LeaderboardEntry> SortPerDifficulty(List<LeaderboardEntry> entries)
		{
			List<LeaderboardEntry> list = new List<LeaderboardEntry>();
			for (int i = 0; i < DifficultyFinder.Instance.max; i++)
			{
				int index = i;
				if (LeaderboardPlugin.Instance.PerDifficultySortingDirection.value == SortingDirection.Descending)
				{
					index = DifficultyFinder.Instance.max - i - 1;
				}
				List<LeaderboardEntry> entries2 = entries.Where((LeaderboardEntry e) => e.Details[0] == index).ToList();
				entries2 = SortEntries(entries2);
				list.AddRange(entries2);
			}
			return list;
		}

		private static List<LeaderboardEntry> SortEntries(List<LeaderboardEntry> entries)
		{
			TimeSortingBehavior timeSortingBehavior = (Object.op_Implicit((Object)(object)panel) ? panel.behavior : LeaderboardPlugin.Instance.TypeSortingBehavior.value);
			SortingDirection sortingDirection = (Object.op_Implicit((Object)(object)panel) ? panel.direction : LeaderboardPlugin.Instance.TypeSortingDirection.value);
			switch (timeSortingBehavior)
			{
			case TimeSortingBehavior.Time:
				entries = new List<LeaderboardEntry>(entries.OrderByDescending((LeaderboardEntry e) => e.Score));
				if (sortingDirection == SortingDirection.Ascending)
				{
					entries.Reverse();
				}
				break;
			case TimeSortingBehavior.Alphabetical:
				entries = new List<LeaderboardEntry>(entries.OrderBy((LeaderboardEntry x) => ((Friend)(ref x.User)).Name));
				if (sortingDirection == SortingDirection.Descending)
				{
					entries.Reverse();
				}
				break;
			}
			return entries;
		}
	}
	[HarmonyPatch(typeof(SteamController))]
	public class SteamControllerPatch
	{
		private static readonly FieldInfo ContainerField = AccessTools.Field(typeof(LevelSelectLeaderboard), "container");

		private static readonly FieldInfo IsPRankSelectedField = AccessTools.Field(typeof(LevelSelectLeaderboard), "pRankSelected");

		private static readonly FieldInfo OwnEntryIndexField = AccessTools.Field(typeof(LevelSelectLeaderboard), "ownEntryIndex");

		private static readonly Color HighlightOutlineColor = new Color(1f, 1f, 1f, 1f);

		private static readonly Color HighlightBackgroundColor = new Color(0.745f, 0.745f, 0.745f, 0.349f);

		private static readonly Color BackgroundColor = new Color(0.5f, 0.5f, 0.5f, 0.239f);

		private static Dictionary<TMP_Text, string> pRankBests = new Dictionary<TMP_Text, string>();

		private static Dictionary<TMP_Text, string> anyBests = new Dictionary<TMP_Text, string>();

		[HarmonyPostfix]
		[HarmonyPatch("FetchAvatar")]
		private static void FetchAvatarPostfix(RawImage target, Friend user)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null))
			{
				LevelSelectLeaderboard componentInParent = ((Component)target).GetComponentInParent<LevelSelectLeaderboard>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					ChangeLevelSelectLeaderboards(((Component)target).gameObject, componentInParent, user);
				}
			}
		}

		private static void ChangeLevelSelectLeaderboards(GameObject avatarObject, LevelSelectLeaderboard leaderboard, Friend user)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: 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_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: 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_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: 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_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: 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_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0518: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (Transform)ContainerField.GetValue(leaderboard);
			string key = "Level " + leaderboard.layerLevelNumber;
			bool flag = (bool)IsPRankSelectedField.GetValue(leaderboard);
			int num = (int)OwnEntryIndexField.GetValue(leaderboard);
			LoadedLeaderboardEntry loadedLeaderboardEntry = LeaderboardControllerPatch.LeaderboardEntriesMap[key];
			Transform val2 = avatarObject.transform;
			while ((Object)(object)val2 != (Object)null && (Object)(object)val2.parent != (Object)(object)val)
			{
				val2 = val2.parent;
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			int num2 = val2.GetSiblingIndex() - 1;
			LeaderboardEntry val3 = loadedLeaderboardEntry.entries[num2];
			int num3 = val3.Details[0];
			bool flag2 = num2 == loadedLeaderboardEntry.personalBestIndex || (((Friend)(ref val3.User)).IsMe && loadedLeaderboardEntry.isSortedByDifficulty);
			bool flag3 = num2 == loadedLeaderboardEntry.personalBestToHighlightIndex || (((Friend)(ref val3.User)).IsMe && loadedLeaderboardEntry.isSortedByDifficulty);
			Color val4 = LeaderboardPlugin.DifficultyVisibility[(GameDifficulty)num3].DifficultyColor.value;
			if (!LeaderboardPlugin.Instance.ColorizeDifficulties.value)
			{
				val4 = Color.white;
			}
			int currentDifficulty = MonoSingleton<PrefsManager>.Instance.GetInt("difficulty", 0);
			int num4 = ((loadedLeaderboardEntry.isSortedByDifficulty && loadedLeaderboardEntry.entries.Any((LeaderboardEntry e) => ((Friend)(ref e.User)).IsMe && e.Details[0] == currentDifficulty)) ? loadedLeaderboardEntry.entries.FindIndex((LeaderboardEntry e) => ((Friend)(ref e.User)).IsMe && e.Details[0] == currentDifficulty) : loadedLeaderboardEntry.personalBestIndex);
			OwnEntryIndexField.SetValue(leaderboard, num4);
			Image[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Image>(true);
			foreach (Image val5 in componentsInChildren)
			{
				if (((Object)((Component)val5).gameObject).name.Contains("Highlight"))
				{
					if (((Object)((Component)val5).gameObject).name.Contains("Background"))
					{
						((Graphic)val5).color = HighlightBackgroundColor;
						if (LeaderboardPlugin.Instance.ColorizeDifficulties.value)
						{
							((Graphic)val5).color = ((Graphic)val5).color * val4;
							((Graphic)val5).color = ((Graphic)val5).color * ((Graphic)val5).color.a;
							((Graphic)val5).color = new Color(((Graphic)val5).color.r, ((Graphic)val5).color.g, ((Graphic)val5).color.b, 0.75f);
						}
						if (!flag2)
						{
							((Graphic)val5).color = new Color(((Graphic)val5).color.r, ((Graphic)val5).color.g, ((Graphic)val5).color.b, ((Graphic)val5).color.a / 2f);
						}
					}
					else
					{
						((Graphic)val5).color = HighlightOutlineColor;
						((Graphic)val5).color = ((Graphic)val5).color * val4;
						if (!flag2)
						{
							((Graphic)val5).color = new Color(((Graphic)val5).color.r, ((Graphic)val5).color.g, ((Graphic)val5).color.b, 0.25f);
						}
					}
				}
				else if (LeaderboardPlugin.Instance.ColorizeDifficulties.value)
				{
					((Graphic)val5).color = BackgroundColor;
					((Graphic)val5).color = ((Graphic)val5).color * val4;
					((Graphic)val5).color = ((Graphic)val5).color * ((Graphic)val5).color.a;
					((Graphic)val5).color = new Color(((Graphic)val5).color.r, ((Graphic)val5).color.g, ((Graphic)val5).color.b, 0.6f);
				}
			}
			TMP_Text[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<TMP_Text>(true);
			foreach (TMP_Text val6 in componentsInChildren2)
			{
				if (((Object)val6).name.Contains("Username"))
				{
					((Graphic)val6).color = Color.white;
					if (((Friend)(ref val3.User)).IsMe)
					{
						((Graphic)val6).color = Color.white;
						if (flag2)
						{
							val6.text = "<b>" + val6.text + "</b>";
						}
					}
				}
				else if (((Object)val6).name.Contains("Difficulty"))
				{
					((Graphic)val6).color = val4;
					if (((Friend)(ref val3.User)).IsMe && flag2)
					{
						((Graphic)val6).color = Color.white;
						val6.text = "<b>" + val6.text + "</b>";
					}
				}
				else
				{
					if (!((Object)val6).name.Contains("Time"))
					{
						continue;
					}
					((Graphic)val6).color = Color.white;
					if (flag3 && !pRankBests.ContainsKey(val6))
					{
						if (flag)
						{
							pRankBests.Add(val6, val6.text);
						}
						else
						{
							anyBests.Add(val6, val6.text);
						}
					}
				}
			}
		}

		public static void UpdateRealBests()
		{
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			List<TMP_Text> list = new List<TMP_Text>();
			foreach (KeyValuePair<TMP_Text, string> item in pRankBests.Where<KeyValuePair<TMP_Text, string>>((KeyValuePair<TMP_Text, string> e) => ((UIBehaviour)e.Key).IsDestroyed()))
			{
				list.Add(item.Key);
			}
			foreach (TMP_Text item2 in list)
			{
				pRankBests.Remove(item2);
			}
			list.Clear();
			foreach (KeyValuePair<TMP_Text, string> item3 in anyBests.Where<KeyValuePair<TMP_Text, string>>((KeyValuePair<TMP_Text, string> e) => ((UIBehaviour)e.Key).IsDestroyed()))
			{
				list.Add(item3.Key);
			}
			foreach (TMP_Text item4 in list)
			{
				anyBests.Remove(item4);
			}
			for (int num = 0; num < pRankBests.Count; num++)
			{
				TMP_Text val = pRankBests.Keys.ToList()[num];
				string text = pRankBests[val];
				if (((UIBehaviour)val).IsDestroyed())
				{
					continue;
				}
				string text2 = "";
				for (int num2 = 0; num2 < text.Length; num2++)
				{
					char c = text[num2];
					string text3 = (LeaderboardPlugin.Instance.EnableBestWaveAnimation.value ? (Mathf.Sin(Time.time * 3f + (float)num2) / 25f) : 0f).ToString("0.00");
					float num3 = Mathf.Clamp01(Mathf.Sin(Time.time * 3f + (float)num2 / 3f) + 1f) * 5f;
					Color val2 = Color.Lerp(Color.white, LeaderboardPlugin.Instance.PRankRecordColor.value, num3);
					if (!LeaderboardPlugin.Instance.ColorizeDifficulties.value)
					{
						val2 = Color.white;
					}
					string text4 = "#" + ColorUtility.ToHtmlStringRGBA(val2);
					text2 = text2 + "<voffset=" + text3 + "em>";
					text2 += "<b>";
					text2 = text2 + "<color=" + text4.ToUpper() + ">";
					text2 += c;
					text2 += "</color>";
					text2 += "</b>";
					text2 += "</voffset>";
				}
				val.text = text2;
			}
			for (int num4 = 0; num4 < anyBests.Count; num4++)
			{
				TMP_Text val3 = anyBests.Keys.ToList()[num4];
				string text5 = anyBests[val3];
				if (((UIBehaviour)val3).IsDestroyed())
				{
					continue;
				}
				string text6 = "";
				for (int num5 = 0; num5 < text5.Length; num5++)
				{
					char c2 = text5[num5];
					string text7 = (LeaderboardPlugin.Instance.EnableBestWaveAnimation.value ? (Mathf.Sin(Time.time * 3f + (float)num5) / 25f) : 0f).ToString("0.00");
					float num6 = Mathf.Clamp01(Mathf.Sin(Time.time * 3f + (float)num5 / 3f) + 1f) * 5f;
					Color val4 = Color.Lerp(Color.white, LeaderboardPlugin.Instance.AnyRecordColor.value, num6);
					if (!LeaderboardPlugin.Instance.ColorizeDifficulties.value)
					{
						val4 = Color.white;
					}
					string text8 = "#" + ColorUtility.ToHtmlStringRGBA(val4);
					text6 = text6 + "<voffset=" + text7 + "em>";
					text6 += "<b>";
					text6 = text6 + "<color=" + text8.ToUpper() + ">";
					text6 += c2;
					text6 += "</color>";
					text6 += "</b>";
					text6 += "</voffset>";
				}
				val3.text = text6;
			}
		}
	}
}
namespace UltrakillDifficultyLeaderboard.Data
{
	public class DifficultyOption
	{
		public GameDifficulty Difficulty { get; }

		public BoolField VisibilityField { get; set; }

		public BoolField RecordSetField { get; set; }

		public BoolField LocalTimeSetField { get; set; }

		public ColorField DifficultyColor { get; set; }

		public unsafe DifficultyOption(GameDifficulty difficulty, ConfigPanel panel, Color defaultColor)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_0048: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Expected O, but got Unknown
			Difficulty = difficulty;
			string text = ((object)(*(GameDifficulty*)(&difficulty))/*cast due to .constrained prefix*/).ToString().ToUpper();
			string text2 = ((object)(*(GameDifficulty*)(&difficulty))/*cast due to .constrained prefix*/).ToString().ToLower();
			ConfigPanel val = new ConfigPanel(panel, text, text2 + "_panel");
			val.buttonText = "CONFIG";
			ConfigHeader val2 = new ConfigHeader(val, "--Entry Visibility--", 24);
			DifficultyColor = new ColorField(val, "Color", text2 + "_color", defaultColor);
			VisibilityField = new BoolField(val, "Show " + text + " Times\non Leaderboards", text2 + "_vis_toggle", true);
			ConfigHeader val3 = new ConfigHeader(val, "--Record Management--", 24);
			RecordSetField = new BoolField(val, "Allow new " + text + "\nRecords", text2 + "_time_toggle", true);
			LocalTimeSetField = new BoolField(val, "Save " + text + " Times\nLocally", text2 + "_time_local_toggle", true);
			((ConfigField)VisibilityField).interactable = !LeaderboardPlugin.Instance.DiffVis.value;
			((ConfigField)RecordSetField).interactable = !LeaderboardPlugin.Instance.BlockAllRecords.value;
			((ConfigField)LocalTimeSetField).interactable = LeaderboardPlugin.Instance.AllowAllLocalTimes.value;
		}

		public static DifficultyOption Create(GameDifficulty difficulty, ConfigPanel panel, Color defaultColor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			DifficultyOption difficultyOption = new DifficultyOption(difficulty, panel, defaultColor);
			LeaderboardPlugin.DifficultyVisibility.Add(difficulty, difficultyOption);
			return difficultyOption;
		}
	}
	[Serializable]
	public class LeaderboardLocalTime
	{
		public float[] Time;

		public float[] PRankTime;

		public LeaderboardLocalTime()
		{
			Time = new float[DifficultyFinder.Instance.max];
			PRankTime = new float[DifficultyFinder.Instance.max];
		}
	}
	[Serializable]
	public class LeaderboardServerDeleteRequest
	{
		public ulong steamID;

		public string levelName;

		public int difficulty;

		public bool isPRank;
	}
	[Serializable]
	public class LeaderboardServerEntry
	{
		public ulong steamid;

		public string levelname;

		public int difficulty;

		public float any;

		public float prank;
	}
	[Serializable]
	public class LeaderboardServerEntryList
	{
		public LeaderboardServerEntry[] array;
	}
	[Serializable]
	public class LeaderboardServerGetRequest
	{
		public ulong[] steamID;
	}
	[Serializable]
	public class LeaderboardServerPostRequest
	{
		public ulong steamID;

		public string levelName;

		public int difficulty;

		public float time;

		public bool isPRank;
	}
	[Serializable]
	public class LeaderboardServerSplitEntry
	{
		public ulong steamID;

		public int difficulty;

		public float time;
	}
	[Serializable]
	public class LeaderboardServerTime
	{
		public string levelName;

		public ulong steamID;

		public float[] Time;

		public float[] PRankTime;
	}
	[Serializable]
	public class LeaderboardServerTimeList
	{
		public LeaderboardServerTime[] array;
	}
	public class LoadedLeaderboardEntry
	{
		public List<LeaderboardEntry> entries;

		public int personalBestIndex;

		public int personalBestToHighlightIndex;

		public bool isPRank;

		public bool isSortedByDifficulty;

		public LoadedLeaderboardEntry(List<LeaderboardEntry> entries, int personalBestIndex, bool isPRank, int personalBestToHighlightIndex, bool isSortedByDifficulty = false)
		{
			this.entries = entries;
			this.personalBestIndex = personalBestIndex;
			this.isPRank = isPRank;
			this.isSortedByDifficulty = isSortedByDifficulty;
			this.personalBestToHighlightIndex = personalBestToHighlightIndex;
		}
	}
	public class LeaderboardLocalTimeManager : MonoBehaviour
	{
		public static LeaderboardLocalTimeManager Instance;

		public List<Friend> FriendsList = new List<Friend>();

		private Dictionary<string, Dictionary<ulong, LeaderboardLocalTime>> cachedLeaderboards = new Dictionary<string, Dictionary<ulong, LeaderboardLocalTime>>();

		private int maxCachedDifficulty = 0;

		private string url => "https://ferryman.hctel.net";

		private string customSavesDir => Path.Combine(GameProgressSaver.SavePath, "Custom");

		public string localTimesSavesDir => Path.Combine(GameProgressSaver.SavePath, "LeaderboardManager");

		public static async Task Create()
		{
			if (SceneHelper.IsSceneRankless)
			{
				if (!Object.op_Implicit((Object)(object)Instance) || Object.FindObjectsOfType<LeaderboardLocalTimeManager>().Length == 0)
				{
					GameObject go = new GameObject("LeaderboardLocalTimeManager");
					Object.DontDestroyOnLoad((Object)(object)go);
					LeaderboardLocalTimeManager finder = go.AddComponent<LeaderboardLocalTimeManager>();
					Instance = finder;
				}
				await Instance.GetServerTimesData();
			}
		}

		private string localBestTimesPath(string levelName)
		{
			return Path.Combine(localTimesSavesDir, levelName + "_localtimes.bepis");
		}

		private async Task GetServerTimesData()
		{
			cachedLeaderboards.Clear();
			await LeaderboardPlugin.Instance.RefreshFriends();
			((MonoBehaviour)this).StartCoroutine(TryUploadSaveData(SteamClient.SteamId));
			SteamId[] ids = (SteamId[])(object)new SteamId[FriendsList.Count + 1];
			for (int i = 0; i < FriendsList.Count; i++)
			{
				ids[i] = FriendsList[i].Id;
			}
			ids[FriendsList.Count] = SteamClient.SteamId;
			((MonoBehaviour)this).StartCoroutine(GetLeaderboard(ids));
		}

		private async Task<LeaderboardLocalTime> GetLocalTimesData(string levelName, SteamId id)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			LeaderboardLocalTime localTime = new LeaderboardLocalTime();
			if (cachedLeaderboards.ContainsKey(levelName) && cachedLeaderboards[levelName].ContainsKey(id.Value))
			{
				localTime = cachedLeaderboards[levelName][id.Value];
			}
			if (localTime.Time.Length == 0)
			{
				localTime.Time = new float[DifficultyFinder.Instance.max];
			}
			else if (localTime.Time.Length < DifficultyFinder.Instance.max)
			{
				float[] temp = new float[DifficultyFinder.Instance.max];
				for (int i = 0; i < localTime.Time.Length; i++)
				{
					temp[i] = localTime.Time[i];
				}
				localTime.Time = temp;
			}
			if (localTime.PRankTime.Length == 0)
			{
				localTime.PRankTime = new float[DifficultyFinder.Instance.max];
			}
			else if (localTime.PRankTime.Length < DifficultyFinder.Instance.max)
			{
				float[] temp2 = new float[DifficultyFinder.Instance.max];
				for (int j = 0; j < localTime.PRankTime.Length; j++)
				{
					temp2[j] = localTime.PRankTime[j];
				}
				localTime.PRankTime = temp2;
			}
			return localTime;
		}

		public List<string> GetAllLevels()
		{
			return new List<string>(cachedLeaderboards.Keys).OrderBy((string e) => e).ToList();
		}

		public async Task<LeaderboardLocalTime> GetTimesForLevel(string levelName)
		{
			return await GetLocalTimesData(levelName, SteamClient.SteamId);
		}

		public async Task<float> GetBestLocalTime(string levelName, SteamId id, int difficulty, bool pRank)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (SceneHelper.IsPlayingCustom)
			{
				return 0f;
			}
			LeaderboardLocalTime localTimeData = await GetLocalTimesData(levelName, id);
			float[] time = (pRank ? localTimeData.PRankTime : localTimeData.Time);
			return time[difficulty];
		}

		public async Task SetBestLocalTime(string levelName, int difficulty, float time, bool pRank)
		{
			if (SceneHelper.IsPlayingCustom)
			{
				return;
			}
			SteamId id = SteamClient.SteamId;
			float previousTime = await GetBestLocalTime(levelName, id, difficulty, pRank);
			if (previousTime > time || previousTime == 0f)
			{
				if (!cachedLeaderboards.ContainsKey(levelName))
				{
					cachedLeaderboards.TryAdd(levelName, new Dictionary<ulong, LeaderboardLocalTime>());
				}
				if (!cachedLeaderboards[levelName].ContainsKey(id.Value))
				{
					cachedLeaderboards[levelName].TryAdd(id.Value, new LeaderboardLocalTime());
				}
				if (!pRank)
				{
					cachedLeaderboards[levelName][id.Value].Time[difficulty] = time;
				}
				else
				{
					cachedLeaderboards[levelName][id.Value].PRankTime[difficulty] = time;
				}
				LeaderboardPlugin.Log.WriteLine($"Uploading time for {levelName} difficulty {difficulty} time {time} pRank {pRank}", ConsoleColor.Green);
				((MonoBehaviour)this).StartCoroutine(UploadTime(id, time, difficulty, levelName, pRank));
			}
		}

		public void ResetLocalTime(string levelName, int difficulty, bool pRank)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0090: 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)
			if (!SceneHelper.IsPlayingCustom)
			{
				if (!cachedLeaderboards.ContainsKey(levelName))
				{
					cachedLeaderboards.TryAdd(levelName, new Dictionary<ulong, LeaderboardLocalTime>());
				}
				if (!cachedLeaderboards[levelName].ContainsKey(SteamClient.SteamId.Value))
				{
					cachedLeaderboards[levelName].TryAdd(SteamClient.SteamId.Value, new LeaderboardLocalTime());
				}
				if (!pRank)
				{
					cachedLeaderboards[levelName][SteamClient.SteamId.Value].Time[difficulty] = 0f;
				}
				else
				{
					cachedLeaderboards[levelName][SteamClient.SteamId.Value].PRankTime[difficulty] = 0f;
				}
				LeaderboardPlugin.Log.WriteLine($"Deleting time for {levelName} difficulty {difficulty} pRank {pRank}", ConsoleColor.Red);
				((MonoBehaviour)this).StartCoroutine(DeleteTime(SteamClient.SteamId, difficulty, levelName, pRank));
			}
		}

		private void WriteFile(string path, object data)
		{
			Debug.Log((object)("[FS] Writing To " + path));
			Directory.CreateDirectory(Path.GetDirectoryName(path));
			using FileStream fileStream = new FileStream(path, FileMode.OpenOrCreate);
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			try
			{
				binaryFormatter.Serialize(fileStream, data);
				fileStream.Close();
			}
			catch (Exception ex)
			{
				Debug.LogException(ex);
			}
		}

		private object ReadFile(string path)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			using FileStream fileStream = new FileStream(path, FileMode.Open);
			if (fileStream.Length == 0L)
			{
				throw new Exception("Stream Length 0");
			}
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			RestrictedSerializationBinder val = new RestrictedSerializationBinder();
			val.AllowedTypes.Add(typeof(RankData));
			val.AllowedTypes.Add(typeof(CyberRankData));
			val.AllowedTypes.Add(typeof(RankScoreData));
			val.AllowedTypes.Add(typeof(GameProgressData));
			val.AllowedTypes.Add(typeof(GameProgressMoneyAndGear));
			val.AllowedTypes.Add(typeof(LeaderboardLocalTime));
			binaryFormatter.Binder = (SerializationBinder?)(object)val;
			return binaryFormatter.Deserialize(fileStream);
		}

		private IEnumerator TryUploadSaveData(SteamId id)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			string[] files = Directory.GetFiles(localTimesSavesDir);
			if (files.Length == 0)
			{
				yield break;
			}
			List<LeaderboardServerTime> list = new List<LeaderboardServerTime>();
			string[] array = files;
			foreach (string file in array)
			{
				object obj = ReadFile(file);
				if (obj is LeaderboardLocalTime localTime)
				{
					string cleanedUpName = file.Replace(localTimesSavesDir, "");
					cleanedUpName = cleanedUpName.Replace("_localtimes.bepis", "");
					cleanedUpName = cleanedUpName.Replace("\\", "");
					LeaderboardServerTime time = new LeaderboardServerTime
					{
						levelName = cleanedUpName,
						steamID = id.Value,
						Time = localTime.Time,
						PRankTime = localTime.PRankTime
					};
					list.Add(time);
					File.Delete(file);
				}
			}
			LeaderboardServerTimeList l = new LeaderboardServerTimeList
			{
				array = list.ToArray()
			};
			string body = TimeListToJson(l);
			UnityWebRequest www = UnityWebRequest.Post(url + "/savelocalfile", body, "application/json");
			www.SetRequestHeader("Content-Type", "application/json");
			yield return www.SendWebRequest();
			if ((int)www.result != 1)
			{
				LeaderboardPlugin.Log.Error($"{id}: {www.error}");
			}
			else
			{
				LeaderboardPlugin.Log.LogDebug(www.downloadHandler.text);
			}
		}

		private IEnumerator UploadTime(SteamId id, float time, int difficulty, string levelName, bool isPRank)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			LeaderboardServerPostRequest request = new LeaderboardServerPostRequest
			{
				steamID = id.Value,
				time = time,
				difficulty = difficulty,
				levelName = levelName,
				isPRank = isPRank
			};
			string body = PostRequestToJson(request);
			UnityWebRequest www = UnityWebRequest.Post(url + "/registertime", body, "application/json");
			www.SetRequestHeader("Content-Type", "application/json");
			yield return www.SendWebRequest();
			if ((int)www.result != 1)
			{
				LeaderboardPlugin.Log.Error($"{id}: {www.error}");
			}
			else
			{
				LeaderboardPlugin.Log.LogDebug(www.downloadHandler.text);
			}
		}

		private IEnumerator GetLeaderboard(SteamId[] ids)
		{
			ulong[] longIds = new ulong[ids.Length];
			for (int i = 0; i < ids.Length; i++)
			{
				longIds[i] = ids[i].Value;
			}
			LeaderboardServerGetRequest request = new LeaderboardServerGetRequest
			{
				steamID = longIds
			};
			string body = GetRequestToJson(request);
			UnityWebRequest www = UnityWebRequest.Post(url + "/leaderboard", body, "application/json");
			www.SetRequestHeader("Content-Type", "application/json");
			yield return www.SendWebRequest();
			if ((int)www.result != 1)
			{
				LeaderboardPlugin.Log.Error(www.error ?? "");
				yield break;
			}
			LeaderboardServerEntryList list = JsonToEntryList(www.downloadHandler.text);
			LeaderboardServerEntry[] array = list.array;
			foreach (LeaderboardServerEntry entry in array)
			{
				if (entry.difficulty < DifficultyFinder.Instance.max)
				{
					if (!cachedLeaderboards.ContainsKey(entry.levelname))
					{
						cachedLeaderboards.TryAdd(entry.levelname, new Dictionary<ulong, LeaderboardLocalTime>());
					}
					if (!cachedLeaderboards[entry.levelname].ContainsKey(entry.steamid))
					{
						cachedLeaderboards[entry.levelname].TryAdd(entry.steamid, new LeaderboardLocalTime());
					}
					if (entry.any != 0f)
					{
						cachedLeaderboards[entry.levelname][entry.steamid].Time[entry.difficulty] = entry.any;
					}
					if (entry.prank != 0f)
					{
						cachedLeaderboards[entry.levelname][entry.steamid].PRankTime[entry.difficulty] = entry.prank;
					}
				}
			}
		}

		private IEnumerator DeleteTime(SteamId id, int difficulty, string levelName, bool isPRank)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			LeaderboardServerDeleteRequest request = new LeaderboardServerDeleteRequest
			{
				steamID = id.Value,
				difficulty = difficulty,
				levelName = levelName,
				isPRank = isPRank
			};
			string body = DeleteRequestToJson(request);
			UnityWebRequest www = UnityWebRequest.Post(url + "/deleteentry", body, "application/json");
			www.SetRequestHeader("Content-Type", "application/json");
			yield return www.SendWebRequest();
			if ((int)www.result != 1)
			{
				LeaderboardPlugin.Log.Error($"{id}: {www.error}");
			}
			else
			{
				LeaderboardPlugin.Log.LogDebug(www.downloadHandler.text);
			}
		}

		private LeaderboardServerEntryList JsonToEntryList(string url)
		{
			url = "{\"array\":" + url + "}";
			LeaderboardServerEntryList leaderboardServerEntryList = JsonUtility.FromJson<LeaderboardServerEntryList>(url);
			LeaderboardPlugin.Log.LogDebug($"Got {leaderboardServerEntryList.array.Length} leaderboard entries");
			return leaderboardServerEntryList;
		}

		private string EntryListToJson(LeaderboardServerEntryList time)
		{
			return JsonUtility.ToJson((object)time);
		}

		private LeaderboardServerTime JsonToEntry(string url)
		{
			LeaderboardServerTime leaderboardServerTime = JsonUtility.FromJson<LeaderboardServerTime>(url);
			LeaderboardPlugin.Log.LogDebug($"Got {leaderboardServerTime.steamID} entries");
			return leaderboardServerTime;
		}

		private string EntryToJson(LeaderboardServerTime time)
		{
			return JsonUtility.ToJson((object)time);
		}

		private string TimeListToJson(LeaderboardServerTimeList time)
		{
			return JsonUtility.ToJson((object)time);
		}

		private string GetRequestToJson(LeaderboardServerGetRequest get)
		{
			return JsonUtility.ToJson((object)get);
		}

		private string PostRequestToJson(LeaderboardServerPostRequest post)
		{
			return JsonUtility.ToJson((object)post);
		}

		private string DeleteRequestToJson(LeaderboardServerDeleteRequest delete)
		{
			return JsonUtility.ToJson((object)delete);
		}
	}
	public enum DifficultySortingBehavior
	{
		NoSorting,
		PerDifficulty
	}
	public enum SortingDirection
	{
		Ascending,
		Descending
	}
	public enum TimeSortingBehavior
	{
		Time,
		Alphabetical
	}
}