Decompiled source of SBG LiveLeaderboard v1.2.0

SBG-LiveLeaderboard.dll

Decompiled 3 weeks 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 Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("GameAssembly")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SBG-LiveLeaderboard")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+af7d7779e4ebaf6de041a772684231bb7a72ad80")]
[assembly: AssemblyProduct("Super Battle Golf Live Leaderboard")]
[assembly: AssemblyTitle("SBG-LiveLeaderboard")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 Leaderboard
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SBG-LiveLeaderboard";

		public const string PLUGIN_NAME = "Super Battle Golf Live Leaderboard";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}
namespace SpectatorLeaderboard
{
	[BepInPlugin("com.kingcox22.sbg.liveleaderboard", "SBG-Live Leaderboard", "1.1.1")]
	public class SpectatorLeaderboardPlugin : BaseUnityPlugin
	{
		private class LeaderboardEntry
		{
			public string Name;

			public float PlayerDist;

			public float BallDist;

			public bool Finished;

			public float VisualY;

			public float TargetY;

			public bool IsInitialized = false;

			public float FinishOrder = float.MaxValue;
		}

		private ConfigEntry<float> _genUpdateInterval;

		private ConfigEntry<int> _genLeaderboardSize;

		private ConfigEntry<float> _specUpdateInterval;

		private ConfigEntry<int> _specLeaderboardSize;

		private ConfigEntry<float> _configX;

		private ConfigEntry<float> _configY;

		private float _timer = 0f;

		private GolfHole _activeHole;

		private List<LeaderboardEntry> _leaderboardData = new List<LeaderboardEntry>();

		private void Awake()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			AcceptableValueRange<float> val = new AcceptableValueRange<float>(0.1f, 30f);
			AcceptableValueRange<int> val2 = new AcceptableValueRange<int>(1, 32);
			_genUpdateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Player", "Update Interval", 1f, new ConfigDescription("Seconds between updates.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			_genLeaderboardSize = ((BaseUnityPlugin)this).Config.Bind<int>("Player", "Leaderboard Size", 16, new ConfigDescription("Players to show.", (AcceptableValueBase)(object)val2, Array.Empty<object>()));
			_specUpdateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Spectator", "Update Interval", 5f, new ConfigDescription("Seconds between updates when spectating.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			_specLeaderboardSize = ((BaseUnityPlugin)this).Config.Bind<int>("Spectator", "Leaderboard Size", 16, new ConfigDescription("Players to show when spectating.", (AcceptableValueBase)(object)val2, Array.Empty<object>()));
			AcceptableValueRange<float> val3 = new AcceptableValueRange<float>(0f, 1920f);
			AcceptableValueRange<float> val4 = new AcceptableValueRange<float>(0f, 1080f);
			_configX = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "X Position", 20f, new ConfigDescription("Horizontal position of the leaderboard.", (AcceptableValueBase)(object)val3, Array.Empty<object>()));
			_configY = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "Y Position", 190f, new ConfigDescription("Vertical position of the leaderboard.", (AcceptableValueBase)(object)val4, Array.Empty<object>()));
		}

		private void Update()
		{
			if (!NetworkClient.active || (Object)(object)GolfHoleManager.MainHole == (Object)null)
			{
				if (_leaderboardData.Count > 0)
				{
					_leaderboardData.Clear();
				}
				return;
			}
			float num = (((Object)(object)GameManager.LocalPlayerAsSpectator != (Object)null) ? _specUpdateInterval.Value : _genUpdateInterval.Value);
			_timer += Time.deltaTime;
			if (_timer >= num)
			{
				_timer = 0f;
				RefreshLeaderboardData();
			}
			foreach (LeaderboardEntry leaderboardDatum in _leaderboardData)
			{
				if (!leaderboardDatum.IsInitialized)
				{
					leaderboardDatum.VisualY = leaderboardDatum.TargetY;
					leaderboardDatum.IsInitialized = true;
				}
				leaderboardDatum.VisualY = Mathf.Lerp(leaderboardDatum.VisualY, leaderboardDatum.TargetY, Time.deltaTime * 8f);
			}
		}

		private void RefreshLeaderboardData()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_activeHole == (Object)null)
			{
				_activeHole = GolfHoleManager.MainHole;
			}
			if ((Object)(object)_activeHole == (Object)null)
			{
				return;
			}
			Vector3 holePos = ((Component)_activeHole).transform.position;
			int num = (((Object)(object)GameManager.LocalPlayerAsSpectator != (Object)null) ? _specLeaderboardSize.Value : _genLeaderboardSize.Value);
			try
			{
				var currentGolfers = (from p in Object.FindObjectsByType<PlayerGolfer>((FindObjectsSortMode)0)
					where (Object)(object)p != (Object)null && (Object)(object)p.PlayerInfo != (Object)null && (Object)(object)p.OwnBall != (Object)null
					select p).Select(delegate(PlayerGolfer p)
				{
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0012: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: Invalid comparison between Unknown and I4
					//IL_005f: 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)
					float bDist = Vector3.Distance(((Component)p.OwnBall).transform.position, holePos);
					bool flag = (int)p.MatchResolution == 1;
					bool flag2 = (Object)(object)p.OwnBall != (Object)null && p.OwnBall.isInHole;
					bool done = flag || flag2;
					return new
					{
						Name = GetPlayerName(p.PlayerInfo),
						PDist = Vector3.Distance(((Component)p).transform.position, holePos),
						BDist = bDist,
						Done = done
					};
				}).ToList();
				foreach (var data in currentGolfers)
				{
					LeaderboardEntry leaderboardEntry = _leaderboardData.FirstOrDefault((LeaderboardEntry x) => x.Name == data.Name);
					if (leaderboardEntry == null)
					{
						leaderboardEntry = new LeaderboardEntry
						{
							Name = data.Name
						};
						_leaderboardData.Add(leaderboardEntry);
					}
					if (data.Done && !leaderboardEntry.Finished)
					{
						leaderboardEntry.FinishOrder = Time.time;
					}
					else if (!data.Done)
					{
						leaderboardEntry.FinishOrder = float.MaxValue;
					}
					leaderboardEntry.PlayerDist = data.PDist;
					leaderboardEntry.BallDist = data.BDist;
					leaderboardEntry.Finished = data.Done;
				}
				_leaderboardData = (from x in _leaderboardData
					orderby x.FinishOrder, x.BallDist
					select x).Take(Mathf.Clamp(num, 1, 32)).ToList();
				float num2 = _configY.Value + 45f;
				for (int i = 0; i < _leaderboardData.Count; i++)
				{
					_leaderboardData[i].TargetY = num2 + (float)i * 25f;
				}
				_leaderboardData.RemoveAll((LeaderboardEntry x) => !currentGolfers.Any(g => g.Name == x.Name));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Refresh Error: " + ex.Message));
			}
		}

		private void OnGUI()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkClient.active || _leaderboardData.Count == 0)
			{
				return;
			}
			float value = _configX.Value;
			float value2 = _configY.Value;
			float num = 420f;
			float num2 = 25f;
			float num3 = 35f;
			float num4 = 10f;
			float num5 = num3 + num4 * 2f + (float)_leaderboardData.Count * num2;
			GUI.backgroundColor = Color.black;
			GUI.Box(new Rect(value, value2, num, num5), "");
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = 13,
				alignment = (TextAnchor)3,
				richText = true
			};
			GUIStyle val2 = new GUIStyle(val)
			{
				alignment = (TextAnchor)5
			};
			GUIStyle val3 = new GUIStyle(val2);
			val3.normal.textColor = new Color(1f, 0.85f, 0f);
			GUIStyle val4 = val3;
			float num6 = value2 + num4;
			float num7 = num6 + num3;
			for (int i = 0; i < _leaderboardData.Count; i++)
			{
				GUI.Label(new Rect(value + num4, num7 + (float)i * num2, 30f, num2), $"{i + 1}.", val);
			}
			GUI.Label(new Rect(value + num4 + 20f, num6, 140f, num3), "<b>PLAYER NAME</b>", val);
			GUI.Label(new Rect(value + 180f, num6, 100f, num3), "<b>PLAYER DIST</b>", val2);
			GUI.Label(new Rect(value + 290f, num6, 110f, num3), "<b>BALL DIST</b>", val2);
			foreach (LeaderboardEntry leaderboardDatum in _leaderboardData)
			{
				if (leaderboardDatum.IsInitialized)
				{
					string text = (leaderboardDatum.Finished ? "#00FF00" : "#FFFFFF");
					string text2 = (leaderboardDatum.Finished ? "<b><color=#00FF00>FINISHED</color></b>" : $"{leaderboardDatum.BallDist:F1}m");
					GUI.Label(new Rect(value + num4 + 20f, leaderboardDatum.VisualY, 140f, num2), "<color=" + text + ">" + leaderboardDatum.Name + "</color>", val);
					GUI.Label(new Rect(value + 180f, leaderboardDatum.VisualY, 100f, num2), $"{leaderboardDatum.PlayerDist:F1}m", val4);
					GUI.Label(new Rect(value + 290f, leaderboardDatum.VisualY, 110f, num2), text2, val2);
				}
			}
		}

		private string GetPlayerName(PlayerInfo info)
		{
			if ((Object)(object)info == (Object)null)
			{
				return "Unknown";
			}
			Component component = ((Component)info).GetComponent("PlayerId");
			if ((Object)(object)component != (Object)null)
			{
				Type type = ((object)component).GetType();
				PropertyInfo property = type.GetProperty("PlayerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null)
				{
					return property.GetValue(component)?.ToString() ?? "Unknown";
				}
				FieldInfo field = type.GetField("playerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					return field.GetValue(component)?.ToString() ?? "Unknown";
				}
			}
			Type type2 = ((object)info).GetType();
			FieldInfo field2 = type2.GetField("playerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field2 != null)
			{
				return field2.GetValue(info)?.ToString() ?? "Unknown";
			}
			return "Golfer";
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}