Decompiled source of RaceTimeStats v1.2.0

RaceTimeStats.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.Core.Logging.Interpolation;
using BepInEx.IL2CPP;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("RaceTimeStats")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Create a server on Awake")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RaceTimeStats")]
[assembly: AssemblyTitle("RaceTimeStats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RaceTimeStats
{
	[BepInPlugin("Serein.RaceTimeStats", "Race Time Stats", "1.2.0")]
	public class RaceTimeStatsPlugin : BasePlugin
	{
		public static Dictionary<ulong, float> FinishTimes = new Dictionary<ulong, float>();

		public static bool _hasSentThisRound = false;

		public static float _startTime = 0f;

		public static ManualLogSource Logger;

		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			Harmony val = new Harmony("Serein.RaceTimeStats");
			MethodInfo methodInfo = AccessTools.Method(typeof(GameModePublicInquUnique), "OnFreezeOver", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(RaceTimeStatsPlugin).GetMethod("OnGameStart_Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo methodInfo2 = AccessTools.Method(typeof(MonoBehaviourPublicInInUnique), "GameOver", (Type[])null, (Type[])null);
			if (methodInfo2 != null)
			{
				val.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(RaceTimeStatsPlugin).GetMethod("OnGameOver_Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			MethodInfo methodInfo3 = AccessTools.Method(typeof(MonoBehaviourPublicLi1ObsaInObUnique), "OnTriggerEnter", (Type[])null, (Type[])null);
			if (methodInfo3 != null)
			{
				val.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(RaceTimeStatsPlugin).GetMethod("OnZoneEnter_Postfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		public static void OnGameStart_Prefix()
		{
			FinishTimes.Clear();
			_hasSentThisRound = false;
			_startTime = Time.time;
			Logger.LogInfo((object)"Race Started!");
		}

		public static void OnGameOver_Prefix()
		{
			if (!_hasSentThisRound)
			{
				_hasSentThisRound = true;
				SendLeaderboard();
			}
		}

		public static void OnZoneEnter_Postfix(Collider __0)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			if (_hasSentThisRound || (Object)(object)MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance == (Object)null || (Object)(object)__0 == (Object)null || (Object)(object)((Component)__0).transform.root == (Object)null)
			{
				return;
			}
			MonoBehaviourPublicCSstReshTrheObplBojuUnique component = ((Component)((Component)__0).transform.root).GetComponent<MonoBehaviourPublicCSstReshTrheObplBojuUnique>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			ulong steamID = component.steamProfile.m_SteamID;
			if (!FinishTimes.ContainsKey(steamID))
			{
				float num = Time.time - _startTime;
				FinishTimes[steamID] = num;
				ManualLogSource logger = Logger;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(19, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Player ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(steamID);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" finished: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num, "F2");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s");
				}
				logger.LogInfo(val);
			}
		}

		public static void SendLeaderboard()
		{
			if (FinishTimes.Count == 0)
			{
				MonoBehaviourPublicInInUnique.SendChatMessage(1uL, "round failed (no one finished)");
				return;
			}
			List<KeyValuePair<ulong, float>> list = FinishTimes.OrderBy((KeyValuePair<ulong, float> x) => x.Value).ToList();
			MonoBehaviourPublicInInUnique.SendChatMessage(1uL, "=== race results ===");
			int num = 1;
			foreach (KeyValuePair<ulong, float> item in list)
			{
				if (num > 5)
				{
					break;
				}
				string playerName = GetPlayerName(item.Key);
				string arg = item.Value.ToString("F2");
				MonoBehaviourPublicInInUnique.SendChatMessage(1uL, $"#{num} {playerName}: {arg}s");
				num++;
			}
			MonoBehaviourPublicInInUnique.SendChatMessage(1uL, "====================");
		}

		public static string GetPlayerName(ulong steamId)
		{
			if (MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers.ContainsKey(steamId))
			{
				return MonoBehaviourPublicDi2UIObacspDi2UIObUnique.Instance.activePlayers[steamId].username;
			}
			return "unknown";
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "RaceTimeStats";

		public const string PLUGIN_NAME = "RaceTimeStats";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}