Decompiled source of Leaderboard v1.0.4

plugins/com.cakedevs.leaderboard.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Leaderboard.MonoBehaviours;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.cakedevs.leaderboard")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("com.cakedevs.leaderboard")]
[assembly: AssemblyTitle("Leaderboard")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Leaderboard
{
	[BepInPlugin("com.cakedevs.leaderboard", "Leaderboard", "1.0.4")]
	internal sealed class Entry : BaseUnityPlugin
	{
		internal static ConfigEntry<bool>? displayTimer;

		internal static ConfigEntry<bool>? displayLeaderboard;

		internal static ConfigEntry<bool>? displayHeights;

		internal static ConfigEntry<bool>? extraSpace;

		internal static ConfigEntry<int>? topPlayerCount;

		internal static ConfigEntry<bool>? hideDead;

		internal static ConfigEntry<string>? ignoredPlayers;

		private void Awake()
		{
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Creating config entries");
			displayLeaderboard = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display Leaderboard", true, "Displays the top players leaderboard in the top right corner.");
			displayTimer = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display Run Timer", true, "Displays the run timer in the top right.");
			displayHeights = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Display Heights on the leaderboard", true, "Displays how far the top players are on the leaderboard.");
			extraSpace = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Extra blank space above leaderboard", false, "Adds 1 blank line above the leaderboard, effectively shifting the leaderboard down a bit so it doesn't cover the 'Ascent X' label when playing on ascent difficulty.");
			topPlayerCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Top player count", 6, "How many top X players should be shown on the leaderboard (Has to be 1+ if 'Display Leaderboard' is enabled).");
			hideDead = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Ignore DEAD players", false, "Prevents DEAD players from appearing in the leaderboard.");
			ignoredPlayers = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Ignored player names", "", "Prevents specific players from appearing in the leaderboard (Write the EXACT playernames as appearing on Steam, not case-sensitive and semicolon separated).");
			((BaseUnityPlugin)this).Logger.LogMessage((object)"Hooking GUIManager.Start");
			new Hook((MethodBase)AccessTools.Method(typeof(GUIManager), "Start", (Type[])null, (Type[])null), (Delegate)new Action<Action<GUIManager>, GUIManager>(GUIManagerStartHook));
		}

		private static void GUIManagerStartHook(Action<GUIManager> orig, GUIManager self)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			orig(self);
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "Airport")
			{
				CreateTimerAndHeightStats(self);
			}
		}

		private static void CreateTimerAndHeightStats(GUIManager self)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)((Component)self).GetComponentInChildren<AscentUI>()).transform;
			RectTransform val = (RectTransform)Object.Instantiate<Transform>(transform, transform.parent);
			((Object)val).name = "Timer & Height UI";
			Object.Destroy((Object)(object)((Component)val).GetComponent<AscentUI>());
			((Component)val).gameObject.AddComponent<TimerAndLeaderboardStats>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 1f);
			val.anchorMin = val2;
			val.anchorMax = val2;
			val.pivot = val2;
			val.anchoredPosition = Vector2.zero;
		}
	}
}
namespace Leaderboard.MonoBehaviours
{
	internal sealed class TimerAndLeaderboardStats : MonoBehaviour
	{
		private TMP_Text? leaderboardText;

		private TMP_Text? heightsText;

		private const int MaxNameLength = 14;

		private void Start()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			leaderboardText = GameObject.Find("Timer & Height UI").GetComponent<TMP_Text>();
			leaderboardText.autoSizeTextContainer = false;
			leaderboardText.textWrappingMode = (TextWrappingModes)0;
			leaderboardText.alignment = (TextAlignmentOptions)257;
			leaderboardText.fontSize = 24f;
			leaderboardText.outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
			leaderboardText.outlineWidth = 0.045f;
			GameObject val = new GameObject("heightsText", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(TextMeshProUGUI)
			});
			val.transform.SetParent(leaderboardText.transform.parent, false);
			val.layer = ((Component)leaderboardText).gameObject.layer;
			heightsText = val.GetComponent<TMP_Text>();
			heightsText.font = leaderboardText.font;
			((Graphic)heightsText).color = ((Graphic)leaderboardText).color;
			heightsText.autoSizeTextContainer = false;
			heightsText.textWrappingMode = (TextWrappingModes)0;
			heightsText.alignment = (TextAlignmentOptions)260;
			heightsText.fontSize = 24f;
			heightsText.outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
			heightsText.outlineWidth = 0.045f;
			RectTransform component = ((Component)leaderboardText).GetComponent<RectTransform>();
			component.sizeDelta = new Vector2(300f, 0f);
			component.anchorMin = new Vector2(1f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(1f, 1f);
			component.anchoredPosition = new Vector2(-10f, -10f);
			RectTransform component2 = ((Component)heightsText).GetComponent<RectTransform>();
			component2.sizeDelta = new Vector2(300f, 0f);
			component2.anchorMin = new Vector2(1f, 1f);
			component2.anchorMax = new Vector2(1f, 1f);
			component2.pivot = new Vector2(1f, 1f);
			component2.anchoredPosition = new Vector2(-10f, -10f);
		}

		private static string FormattedTime(float totalSeconds)
		{
			return TimeSpan.FromSeconds(totalSeconds).ToString("hh\\:mm\\:ss");
		}

		public void Update()
		{
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)leaderboardText == (Object)null || (Object)(object)heightsText == (Object)null)
			{
				return;
			}
			ConfigEntry<bool>? displayLeaderboard = Entry.displayLeaderboard;
			if (displayLeaderboard == null)
			{
				return;
			}
			_ = displayLeaderboard.Value;
			if (false)
			{
				return;
			}
			ConfigEntry<bool>? displayTimer = Entry.displayTimer;
			if (displayTimer == null)
			{
				return;
			}
			_ = displayTimer.Value;
			if (false)
			{
				return;
			}
			ConfigEntry<bool>? displayHeights = Entry.displayHeights;
			if (displayHeights == null)
			{
				return;
			}
			_ = displayHeights.Value;
			if (false)
			{
				return;
			}
			ConfigEntry<bool>? extraSpace = Entry.extraSpace;
			if (extraSpace == null)
			{
				return;
			}
			_ = extraSpace.Value;
			if (false)
			{
				return;
			}
			ConfigEntry<int>? topPlayerCount = Entry.topPlayerCount;
			if (topPlayerCount == null)
			{
				return;
			}
			_ = topPlayerCount.Value;
			if (false || (Entry.displayLeaderboard.Value && Entry.topPlayerCount.Value <= 0))
			{
				return;
			}
			ConfigEntry<bool>? hideDead = Entry.hideDead;
			if (hideDead == null)
			{
				return;
			}
			_ = hideDead.Value;
			if (false || Entry.ignoredPlayers?.Value == null)
			{
				return;
			}
			CharacterStats stats = Character.localCharacter.refs.stats;
			string[] ignored = Entry.ignoredPlayers.Value.Split(';');
			List<Character> list = (from c in Character.AllCharacters
				where (Object)(object)c.refs?.stats != (Object)null && (Object)(object)c.refs.view != (Object)null && !ignored.Any((string p) => p.Equals(c.characterName, StringComparison.OrdinalIgnoreCase))
				orderby c.refs.stats.heightInMeters > 2000f, (!(c.refs.stats.heightInMeters > 2000f)) ? "" : ColorUtility.ToHtmlStringRGB(c.refs.customization.PlayerColor), (!(c.refs.stats.heightInMeters <= 2000f)) ? 0f : c.refs.stats.heightInMeters descending
				select c).ToList();
			string text = "";
			string text2 = "";
			if (Entry.extraSpace.Value)
			{
				text = "\n";
				text2 = "\n";
			}
			if (Entry.displayLeaderboard.Value && Entry.displayTimer.Value)
			{
				text += "Leaderboard\n";
				text2 = text2 + FormattedTime(Time.time - stats.GetFirstTimelineInfo().time) + "\n";
			}
			else if (Entry.displayLeaderboard.Value && !Entry.displayTimer.Value)
			{
				text += "Leaderboard\n";
				text2 += "\n";
			}
			else if (!Entry.displayLeaderboard.Value && Entry.displayTimer.Value)
			{
				text2 += FormattedTime(Time.time - stats.GetFirstTimelineInfo().time);
				heightsText.text = text2;
				return;
			}
			string[] array = Entry.ignoredPlayers.Value.Split(';');
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				if (num == Entry.topPlayerCount.Value)
				{
					break;
				}
				Character val = list[i];
				if (!IsDead(val) || !Entry.hideDead.Value)
				{
					string arg = ((val.characterName.Length > 14) ? (val.characterName.Substring(0, 14) + "…") : val.characterName);
					Color playerColor = val.refs.customization.PlayerColor;
					string arg2 = ColorUtility.ToHtmlStringRGB(playerColor);
					int num2 = Mathf.FloorToInt(val.refs.stats.heightInMeters);
					num++;
					string text3 = $"#{num} <color=#{arg2}>{arg}</color>";
					string text4 = (IsDead(val) ? "DEAD" : (Entry.displayHeights.Value ? $"{num2}m" : ""));
					text = text + text3 + "\n";
					text2 = text2 + text4 + "\n";
				}
			}
			leaderboardText.text = text;
			heightsText.text = text2;
			static bool IsDead(Character c)
			{
				return Mathf.FloorToInt(c.refs.stats.heightInMeters) > 2000;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}