Decompiled source of PaceReference v1.0.3

PaceRef.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PaceRef")]
[assembly: AssemblyDescription("Enhanced scoreboard and pace reference mod for Distance")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PaceRef")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b8c7f4e2-9a3d-4f1b-8e5c-7d2a1f9e3b6a")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.0.3.0")]
namespace PaceRef
{
	public static class Constants
	{
		public static class Config
		{
			public const string SectionName = "PaceRef - Enhanced Scoreboard";

			public const string SampleSize = "Sample Size";

			public const string SampleSizeDescription = "Set the number of samples to use for calculating the average time.";
		}

		public const string PluginGuid = "F2E8A3C7-9D1B-4F6E-8A5C-3E7D2F9B1A4E";

		public const string PluginName = "PaceRef - Enhanced Scoreboard";

		public const string HarmonyId = "de.kilika.distance.PaceRef";
	}
	[BepInPlugin("F2E8A3C7-9D1B-4F6E-8A5C-3E7D2F9B1A4E", "PaceRef - Enhanced Scoreboard", "1.0.0")]
	public sealed class Mod : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		internal static ConfigEntry<int> SampleSizeConfig { get; set; }

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			Logger = Logger.CreateLogSource("PaceRef - Enhanced Scoreboard");
			ConfigDescription val = new ConfigDescription("Set the number of samples to use for calculating the average time.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 1000), new object[0]);
			SampleSizeConfig = ((BaseUnityPlugin)this).Config.Bind<int>("PaceRef - Enhanced Scoreboard", "Sample Size", 100, val);
			Harmony val2 = new Harmony("de.kilika.distance.PaceRef");
			Logger.LogInfo((object)"Loading PaceRef...");
			val2.PatchAll();
			Logger.LogInfo((object)"PaceRef loaded successfully!");
		}
	}
	internal static class ScoreboardBuilder
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<int, string> <>9__4_0;

			public static Func<int, string> <>9__4_1;

			internal string <GetFormatter>b__4_0(int ms)
			{
				return GUtils.GetFormattedMS((double)ms);
			}

			internal string <GetFormatter>b__4_1(int score)
			{
				return score.ToString("N0", CultureInfo.InvariantCulture) + " eV";
			}
		}

		internal static string Build(int[] scores, int sampleSize, GameModeID gameModeId)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (Math.Min(sampleSize, scores.Length) == 0)
			{
				return NguiLabel("No scores yet!");
			}
			int[] array = scores.Take(sampleSize).ToArray();
			int arg = scores[0];
			int arg2 = (int)array.Average();
			Func<int, string> formatter = GetFormatter(gameModeId);
			return NguiLabel("Global Best:") + " " + NguiValue(formatter(arg)) + "\n" + NguiLabel("Top " + array.Length + " Avg:") + " " + NguiValue(formatter(arg2));
		}

		private static string NguiLabel(string text)
		{
			return "[c][AAAAAA]" + text + "[-][/c]";
		}

		private static string NguiValue(string text)
		{
			return "[c][FFFFFF]" + text + "[-][/c]";
		}

		private static bool IsTimeMode(GameModeID gameModeID)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			return (int)gameModeID != 2;
		}

		private static Func<int, string> GetFormatter(GameModeID gameModeId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			object obj;
			if (!IsTimeMode(gameModeId))
			{
				obj = <>c.<>9__4_1;
				if (obj == null)
				{
					return <>c.<>9__4_1 = (int score) => score.ToString("N0", CultureInfo.InvariantCulture) + " eV";
				}
			}
			else
			{
				obj = (Func<int, string>)((int ms) => GUtils.GetFormattedMS((double)ms));
			}
			return (Func<int, string>)obj;
		}
	}
}
namespace PaceRef.Patches
{
	[HarmonyPatch(typeof(PauseMenuLogic), "SetupPauseMenuLevelInfo")]
	internal class PauseMenuLogic_AddDetailedScoreBoardPanel
	{
		[HarmonyPostfix]
		public static void SetupPauseMenuLevelInfo_Postfix(PauseMenuLogic __instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			string levelPath_ = G.Sys.GameManager_.LevelPath_;
			GameModeID gameModeID = G.Sys.GameManager_.Mode_.GameModeID_;
			G.Sys.SteamworksManager_.Leaderboard_.DownloadLeaderboardInfo(levelPath_, gameModeID, (OnLeaderboardDownloaded)delegate(bool success, Entry[] entries, int count)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				if (entries != null && entries.Length != 0)
				{
					string scoreboardData = ScoreboardBuilder.Build(entries.Select((Entry e) => ((Entry)e).Score_).ToArray(), Mod.SampleSizeConfig.Value, gameModeID);
					AddScoreboardDataToLabel(__instance, scoreboardData);
				}
			}, (RangeRequestType)0, 1, Mod.SampleSizeConfig.Value, false);
		}

		private static void AddScoreboardDataToLabel(PauseMenuLogic pauseMenuLogic, string scoreboardData)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			UILabel levelInfoLabel_ = pauseMenuLogic.levelInfoLabel_;
			Transform val = ((Component)levelInfoLabel_).transform.parent.Find("PaceRef Scoreboard");
			if ((Object)(object)val != (Object)null)
			{
				NGUITools.Destroy((Object)(object)((Component)val).gameObject);
			}
			GameObject obj = NGUITools.AddChild(((Component)((Component)levelInfoLabel_).transform.parent).gameObject);
			((Object)obj).name = "PaceRef Scoreboard";
			UILabel val2 = obj.AddComponent<UILabel>();
			val2.bitmapFont = levelInfoLabel_.bitmapFont;
			val2.trueTypeFont = levelInfoLabel_.trueTypeFont;
			val2.fontSize = levelInfoLabel_.fontSize;
			((UIWidget)val2).color = ((UIWidget)levelInfoLabel_).color;
			((UIWidget)val2).width = ((UIWidget)levelInfoLabel_).width;
			((UIWidget)val2).pivot = ((UIWidget)levelInfoLabel_).pivot;
			((UIWidget)val2).depth = ((UIWidget)levelInfoLabel_).depth;
			val2.overflowMethod = (Overflow)3;
			val2.text = scoreboardData;
			((UIWidget)val2).MakePixelPerfect();
			Vector3 localPosition = ((Component)levelInfoLabel_).transform.localPosition;
			obj.transform.localPosition = new Vector3(localPosition.x, localPosition.y - (float)((UIWidget)levelInfoLabel_).height - 8f, localPosition.z);
			int num = 8 + ((UIWidget)val2).height + 8;
			GrowPanelWidget(((Component)levelInfoLabel_).transform.parent, num);
			ShiftLogoDown(((Component)levelInfoLabel_).transform.parent, "UITexture - Medal", num / 2);
			ShiftLogoDown(((Component)levelInfoLabel_).transform.parent, "Medal Logo", num / 2);
		}

		private static void ShiftLogoDown(Transform parent, string childName, int shift)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find(childName);
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 localPosition = val.localPosition;
				val.localPosition = new Vector3(localPosition.x, localPosition.y - (float)shift, localPosition.z);
			}
		}

		private static void GrowPanelWidget(Transform panelLevelInfo, int extraHeight)
		{
			UIWidget component = ((Component)panelLevelInfo).GetComponent<UIWidget>();
			if (!((Object)(object)component == (Object)null) && (Object)(object)((UIRect)component).bottomAnchor.target != (Object)null)
			{
				AnchorPoint bottomAnchor = ((UIRect)component).bottomAnchor;
				bottomAnchor.absolute -= extraHeight;
			}
		}
	}
}