using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
[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.0.0")]
[assembly: AssemblyVersion("1.0.0.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!");
}
}
}
namespace PaceRef.Patches
{
[HarmonyPatch(typeof(PauseMenuLogic), "SetupPauseMenuLevelInfo")]
internal class PauseMenuLogic_AddDetailedScoreBoardPanel
{
private static ManualLogSource Log => Mod.Logger;
[HarmonyPostfix]
public static void SetupPauseMenuLevelInfo_Postfix(PauseMenuLogic __instance)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: 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_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: 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)
{
if (entries != null && entries.Length != 0)
{
AddScoreboardDataToLabel(__instance, entries);
}
}, (RangeRequestType)0, 1, Mod.SampleSizeConfig.Value, false);
}
private static void AddScoreboardDataToLabel(PauseMenuLogic pauseMenuLogic, Entry[] entries)
{
Log.LogInfo((object)"=== Adding scoreboard data to existing label ===");
string text = BuildScoreboardText(entries);
UILabel levelInfoLabel_ = pauseMenuLogic.levelInfoLabel_;
levelInfoLabel_.text = levelInfoLabel_.text + "\n\n" + text;
pauseMenuLogic.levelInfoLabel_.overflowMethod = (Overflow)3;
((UIWidget)pauseMenuLogic.levelInfoLabel_).MakePixelPerfect();
Log.LogInfo((object)"=== Scoreboard data added successfully ===");
}
private static string BuildScoreboardText(Entry[] entries)
{
if (entries == null || entries.Length == 0)
{
return "No leaderboard data";
}
int value = Mod.SampleSizeConfig.Value;
int num = ((entries.Length < value) ? entries.Length : value);
Log.LogInfo((object)$"Using sample size: {num} out of {entries.Length} total entries.");
string formattedMS = GUtils.GetFormattedMS((double)((Entry)entries[0]).Score_);
string formattedMS2 = GUtils.GetFormattedMS((double)(entries.Take(num).Sum((Entry x) => ((Entry)x).Score_) / num));
return "[c][AAAAAA]Global Best:[-][/c] [c][FFFFFF]" + formattedMS + "[-][/c]\n" + $"[c][AAAAAA]Top {num} Avg:[-][/c] [c][FFFFFF]{formattedMS2}[-][/c]";
}
}
}