Decompiled source of DPSMeter v1.3.0

DpsMeter.dll

Decompiled 9 hours 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SineusArena;
using Unity.Collections;
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("DpsMeter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+475c616db734eb5eac363c2d2748427cb6a41e36")]
[assembly: AssemblyProduct("DpsMeter")]
[assembly: AssemblyTitle("DpsMeter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 DpsMeter
{
	public class PlayerDamageRecord
	{
		public string DisplayName { get; set; } = "";

		public Sprite? IconSprite { get; set; }

		public PlayerTeam Team { get; set; }

		public float TotalDamage { get; set; }

		public int Kills { get; set; }

		public float MatchStartTime { get; set; }

		public bool IsSelf { get; set; }

		public float DPS(float now)
		{
			SessionTimerService i = SessionTimerService.I;
			float num = (((Object)(object)i != (Object)null && i.IsRunning && i.ElapsedTime > 0f) ? i.ElapsedTime : (now - MatchStartTime));
			if (!(num > 0.5f))
			{
				return 0f;
			}
			return TotalDamage / num;
		}
	}
	public static class DpsData
	{
		public static readonly Dictionary<int, PlayerDamageRecord> Records = new Dictionary<int, PlayerDamageRecord>();

		public static bool MatchActive;

		public static float MatchStartTime;

		private static PlayerGameDataManager? _cachedPgdm;

		private static FactionManager? _cachedFm;

		private static FactionDefinition[]? _cachedFactionDefs;

		public static void Reset()
		{
			Records.Clear();
			MatchActive = false;
			MatchStartTime = Time.time;
			_cachedPgdm = null;
			_cachedFm = null;
		}

		public static void OnMatchStart()
		{
			if (!MatchActive || Records.Count <= 0)
			{
				Reset();
				MatchActive = true;
				MatchStartTime = Time.time;
				ManualLogSource? log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"[DpsMeter] Match started – DPS tracking active.");
				}
			}
		}

		public static void OnMatchEnd()
		{
			MatchActive = false;
			ManualLogSource? log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"[DpsMeter] Match ended.");
			}
		}

		public static void RecordDamage(PlayerTeam team, float damage)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected I4, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (damage <= 0f)
			{
				return;
			}
			if (!MatchActive)
			{
				MatchActive = true;
				if (Records.Count == 0)
				{
					MatchStartTime = Time.time;
				}
			}
			int key = (int)team;
			if (!Records.TryGetValue(key, out PlayerDamageRecord value))
			{
				(string playerName, Sprite? heroIcon, bool isSelf) tuple = ResolvePlayerInfo(team);
				string item = tuple.playerName;
				Sprite item2 = tuple.heroIcon;
				bool item3 = tuple.isSelf;
				value = new PlayerDamageRecord
				{
					Team = team,
					DisplayName = item,
					IconSprite = item2,
					IsSelf = item3,
					MatchStartTime = MatchStartTime
				};
				Records[key] = value;
			}
			value.TotalDamage += damage;
		}

		public static void RecordKill(PlayerTeam team, int amount)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected I4, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (amount <= 0)
			{
				return;
			}
			if (!MatchActive)
			{
				MatchActive = true;
				if (Records.Count == 0)
				{
					MatchStartTime = Time.time;
				}
			}
			int key = (int)team;
			if (!Records.TryGetValue(key, out PlayerDamageRecord value))
			{
				(string playerName, Sprite? heroIcon, bool isSelf) tuple = ResolvePlayerInfo(team);
				string item = tuple.playerName;
				Sprite item2 = tuple.heroIcon;
				bool item3 = tuple.isSelf;
				value = new PlayerDamageRecord
				{
					Team = team,
					DisplayName = item,
					IconSprite = item2,
					IsSelf = item3,
					MatchStartTime = MatchStartTime
				};
				Records[key] = value;
			}
			value.Kills += amount;
		}

		public static void RefreshDisplayNames()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			foreach (PlayerDamageRecord value in Records.Values)
			{
				(string playerName, Sprite? heroIcon, bool isSelf) tuple = ResolvePlayerInfo(value.Team);
				string item = tuple.playerName;
				Sprite item2 = tuple.heroIcon;
				bool item3 = tuple.isSelf;
				value.DisplayName = item;
				value.IsSelf = item3;
				if ((Object)(object)item2 != (Object)null)
				{
					value.IconSprite = item2;
				}
			}
		}

		public static bool IsBombSource(string sourceName)
		{
			if (string.IsNullOrEmpty(sourceName))
			{
				return false;
			}
			string text = sourceName.ToLowerInvariant();
			if (!text.Contains("bomb") && !text.Contains("nuke"))
			{
				return text.Contains("pickup");
			}
			return true;
		}

		public unsafe static void SyncFromNetwork()
		{
			//IL_0039: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected I4, but got Unknown
			//IL_00c8: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PlayerStatisticsManager val = PlayerStatisticsManager.I ?? Object.FindAnyObjectByType<PlayerStatisticsManager>();
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				PlayerTeam[] array = new PlayerTeam[4];
				RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
				PlayerTeam[] array2 = (PlayerTeam[])(object)array;
				foreach (PlayerTeam val2 in array2)
				{
					float num = 0f;
					List<DamageSourceStatEntry> damageBySourceStats = val.GetDamageBySourceStats(val2);
					if (damageBySourceStats != null)
					{
						for (int j = 0; j < damageBySourceStats.Count; j++)
						{
							DamageSourceStatEntry val3 = damageBySourceStats[j];
							if (!IsBombSource(((object)(*(FixedString128Bytes*)(&val3.SourceName))/*cast due to .constrained prefix*/).ToString()))
							{
								num += damageBySourceStats[j].Damage;
							}
						}
					}
					int kills = val.GetKills(val2);
					if (!(num > 0f) && kills <= 0)
					{
						continue;
					}
					int key = (int)val2;
					if (!Records.TryGetValue(key, out PlayerDamageRecord value))
					{
						(string playerName, Sprite? heroIcon, bool isSelf) tuple = ResolvePlayerInfo(val2);
						string item = tuple.playerName;
						Sprite item2 = tuple.heroIcon;
						bool item3 = tuple.isSelf;
						value = new PlayerDamageRecord
						{
							Team = val2,
							DisplayName = item,
							IconSprite = item2,
							IsSelf = item3,
							MatchStartTime = MatchStartTime
						};
						Records[key] = value;
					}
					if (num > value.TotalDamage)
					{
						value.TotalDamage = num;
					}
					if (kills > value.Kills)
					{
						value.Kills = kills;
					}
					if (!MatchActive && (num > 0f || kills > 0))
					{
						MatchActive = true;
						if (MatchStartTime <= 0f)
						{
							MatchStartTime = Time.time;
						}
					}
				}
			}
			catch
			{
			}
		}

		private static (string playerName, Sprite? heroIcon, bool isSelf) ResolvePlayerInfo(PlayerTeam team)
		{
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			string text = "";
			Sprite val = null;
			bool item = false;
			try
			{
				if ((Object)(object)_cachedFm == (Object)null)
				{
					_cachedFm = FactionManager.I ?? Object.FindAnyObjectByType<FactionManager>();
				}
				if ((Object)(object)_cachedFm != (Object)null)
				{
					FactionSkinDefinition teamSkin = _cachedFm.GetTeamSkin(team);
					if ((Object)(object)teamSkin != (Object)null && (Object)(object)teamSkin.preview != (Object)null)
					{
						val = teamSkin.preview;
					}
					if ((Object)(object)val == (Object)null)
					{
						FactionDefinition teamFaction = _cachedFm.GetTeamFaction(team);
						if ((Object)(object)teamFaction != (Object)null)
						{
							if ((Object)(object)teamFaction.defaultSkin != (Object)null && (Object)(object)teamFaction.defaultSkin.preview != (Object)null)
							{
								val = teamFaction.defaultSkin.preview;
							}
							else if ((Object)(object)teamFaction.icon != (Object)null)
							{
								val = teamFaction.icon;
							}
							else if ((Object)(object)teamFaction.PrimaryAbilityIcon != (Object)null)
							{
								val = teamFaction.PrimaryAbilityIcon;
							}
							else if ((Object)(object)teamFaction.WeaponIcon != (Object)null)
							{
								val = teamFaction.WeaponIcon;
							}
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)_cachedPgdm == (Object)null)
				{
					_cachedPgdm = PlayerGameDataManager.I ?? Object.FindAnyObjectByType<PlayerGameDataManager>();
				}
				if ((Object)(object)_cachedPgdm != (Object)null)
				{
					item = _cachedPgdm.localPlayerTeam == team;
					PlayerData playerData = _cachedPgdm.GetPlayerData(team);
					if (playerData != null && !string.IsNullOrEmpty(playerData.playerSteamName))
					{
						text = playerData.playerSteamName;
					}
					if ((Object)(object)val == (Object)null)
					{
						Unit val2 = _cachedPgdm.GetTeamHeroUnit(team);
						if ((Object)(object)val2 == (Object)null && playerData != null)
						{
							val2 = playerData.playerUnit;
						}
						if ((Object)(object)val2 != (Object)null)
						{
							if (_cachedFactionDefs == null || _cachedFactionDefs.Length == 0)
							{
								_cachedFactionDefs = Resources.FindObjectsOfTypeAll<FactionDefinition>();
							}
							string unitName = val2.UnitName;
							string value = ((Object)((Component)val2).gameObject).name.Replace("(Clone)", "").Trim();
							if (_cachedFactionDefs != null)
							{
								FactionDefinition[] cachedFactionDefs = _cachedFactionDefs;
								foreach (FactionDefinition val3 in cachedFactionDefs)
								{
									if ((Object)(object)val3 != (Object)null && ((!string.IsNullOrEmpty(val3.HeroName) && (val3.HeroName.Equals(unitName, StringComparison.OrdinalIgnoreCase) || val3.HeroName.Equals(value, StringComparison.OrdinalIgnoreCase))) || (!string.IsNullOrEmpty(val3.factionId) && (val3.factionId.Equals(unitName, StringComparison.OrdinalIgnoreCase) || val3.factionId.Equals(value, StringComparison.OrdinalIgnoreCase)))))
									{
										if ((Object)(object)val3.defaultSkin != (Object)null && (Object)(object)val3.defaultSkin.preview != (Object)null)
										{
											val = val3.defaultSkin.preview;
										}
										else if ((Object)(object)val3.icon != (Object)null)
										{
											val = val3.icon;
										}
										break;
									}
								}
							}
						}
					}
				}
			}
			catch
			{
			}
			if (string.IsNullOrEmpty(text))
			{
				text = TeamToFriendlyName(team);
			}
			return (playerName: text, heroIcon: val, isSelf: item);
		}

		private unsafe static string TeamToFriendlyName(PlayerTeam team)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected I4, but got Unknown
			return (team - 1) switch
			{
				0 => "Player 1", 
				1 => "Player 2", 
				2 => "Player 3", 
				3 => "Player 4", 
				_ => ((object)(*(PlayerTeam*)(&team))/*cast due to .constrained prefix*/).ToString(), 
			};
		}
	}
	[BepInPlugin("com.github.antigravity.dpsmeter", "DPS Meter", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource? Log;

		private Harmony? _harmony;

		public static ConfigEntry<KeyCode>? CfgToggleKey;

		public static ConfigEntry<bool>? CfgDefaultVisible;

		public static ConfigEntry<float>? CfgUpdateInterval;

		public static ConfigEntry<float>? CfgWindowWidth;

		public static ConfigEntry<float>? CfgRowHeight;

		public static ConfigEntry<float>? CfgBarOpacity;

		public static ConfigEntry<int>? CfgFontSize;

		public static ConfigEntry<float>? CfgPositionX;

		public static ConfigEntry<float>? CfgPositionY;

		private void Awake()
		{
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"DPS Meter loading configuration...");
			CfgToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)127, "Key code used to toggle visibility of the DPS Meter.");
			CfgDefaultVisible = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DefaultVisible", true, "Should the DPS Meter window be visible by default upon starting.");
			CfgUpdateInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "UpdateInterval", 0.25f, "Seconds between UI refreshes (lower is smoother, higher saves CPU).");
			CfgWindowWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "WindowWidth", 380f, "Width of the DPS Meter window in pixels.");
			CfgRowHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "RowHeight", 28f, "Height of each player row in pixels.");
			CfgBarOpacity = ((BaseUnityPlugin)this).Config.Bind<float>("Appearance", "BarOpacity", 0.22f, "Opacity/alpha of the rank bar fill (0.0 to 1.0).");
			CfgFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Appearance", "FontSize", 11, "Font size of player rows text.");
			CfgPositionX = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "PositionX", 430f, "Saved X position offset of the window relative to screen center.");
			CfgPositionY = ((BaseUnityPlugin)this).Config.Bind<float>("Position", "PositionY", 180f, "Saved Y position offset of the window relative to screen center.");
			try
			{
				_harmony = new Harmony("com.github.antigravity.dpsmeter");
				_harmony.PatchAll();
				Log.LogInfo((object)"DPS Meter Harmony patches applied.");
				GameObject val = new GameObject("DpsMeterController");
				Object.DontDestroyOnLoad((Object)val);
				val.AddComponent<DpsMeterController>();
				Log.LogInfo((object)$"DPS Meter ready. Press {CfgToggleKey.Value} to toggle.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to initialize DPS Meter: " + ex));
			}
		}

		private void OnDestroy()
		{
			Harmony? harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(GameFlowManager), "DoRematch")]
	public static class GameRematchPatch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			ManualLogSource? log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"[DpsMeter] Round restarting (Rematch) – resetting DPS data.");
			}
			DpsData.Reset();
		}
	}
	[HarmonyPatch(typeof(SessionTimerService), "RestartTimer")]
	public static class TimerRestartPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			ManualLogSource? log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"[DpsMeter] Session timer restarted – resetting DPS data.");
			}
			DpsData.Reset();
		}
	}
	[HarmonyPatch(typeof(CollectableItemBomb), "DrainPendingDamage")]
	public static class BombDrainDamagePatch
	{
		public static bool IsExecutingBomb;

		[HarmonyPrefix]
		public static void Prefix()
		{
			IsExecutingBomb = true;
		}

		[HarmonyPostfix]
		public static void Postfix()
		{
			IsExecutingBomb = false;
		}
	}
	[HarmonyPatch(typeof(CollectableItemBomb), "ApplyCollectReward")]
	public static class BombCollectRewardPatch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			BombDrainDamagePatch.IsExecutingBomb = true;
		}

		[HarmonyPostfix]
		public static void Postfix()
		{
			BombDrainDamagePatch.IsExecutingBomb = false;
		}
	}
	[HarmonyPatch(typeof(PlayerStatisticsManager), "AddDamage")]
	public static class AddDamagePatch
	{
		[HarmonyPrefix]
		public static bool Prefix(PlayerTeam team, string sourceName, float amount)
		{
			if (BombDrainDamagePatch.IsExecutingBomb || DpsData.IsBombSource(sourceName))
			{
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		public static void Postfix(PlayerTeam team, string sourceName, float amount)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!BombDrainDamagePatch.IsExecutingBomb && !DpsData.IsBombSource(sourceName))
			{
				DpsData.RecordDamage(team, amount);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerStatisticsManager), "AddKill")]
	public static class AddKillPatch
	{
		[HarmonyPrefix]
		public static bool Prefix(PlayerTeam team, int amount)
		{
			if (BombDrainDamagePatch.IsExecutingBomb)
			{
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		public static void Postfix(PlayerTeam team, int amount)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (!BombDrainDamagePatch.IsExecutingBomb)
			{
				DpsData.RecordKill(team, amount);
			}
		}
	}
	public class DpsMeterController : MonoBehaviour
	{
		private GameObject? _canvasObj;

		private GameObject? _windowObj;

		private RectTransform? _windowRect;

		private Text? _timerText;

		private Text? _titleText;

		private GameObject? _scrollContent;

		private readonly List<PlayerRow> _rows = new List<PlayerRow>();

		private bool _isDragging;

		private Vector2 _dragOffset;

		private bool _visible = true;

		private float _refreshTimer;

		private float _nameRefreshTimer;

		private static readonly Color ColHeader = new Color(0.06f, 0.08f, 0.14f, 0.97f);

		private static readonly Color ColBody = new Color(0.04f, 0.05f, 0.1f, 0.93f);

		private static readonly Color ColBorderOuter = new Color(0.22f, 0.48f, 1f, 0.95f);

		private static readonly Color ColTitle = new Color(0.55f, 0.82f, 1f, 1f);

		private static readonly Color ColTimer = new Color(0.6f, 0.65f, 0.78f, 1f);

		private static readonly Color ColDps = new Color(0.6f, 0.95f, 1f, 1f);

		private static readonly Color ColKills = new Color(1f, 0.55f, 0.3f, 1f);

		private static readonly Color ColLabel = new Color(0.45f, 0.6f, 0.88f, 1f);

		private const float HeaderH = 30f;

		private const float SubH = 20f;

		private Font? _font;

		private GameObject? _emptyLabel;

		private void Start()
		{
			_visible = Plugin.CfgDefaultVisible?.Value ?? true;
			_font = FindFont();
			SceneManager.sceneLoaded += OnSceneLoaded;
			BuildUI();
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			DpsData.Reset();
		}

		private void Update()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<KeyCode>? cfgToggleKey = Plugin.CfgToggleKey;
			if (Input.GetKeyDown((KeyCode)((cfgToggleKey == null) ? 127 : ((int)cfgToggleKey.Value))))
			{
				SetVisible(!_visible);
			}
			if (!_visible)
			{
				return;
			}
			HandleDrag();
			float num = Plugin.CfgUpdateInterval?.Value ?? 0.25f;
			_refreshTimer += Time.deltaTime;
			if (_refreshTimer >= num)
			{
				_refreshTimer = 0f;
				RefreshUI();
			}
			_nameRefreshTimer += Time.deltaTime;
			if (_nameRefreshTimer >= 5f)
			{
				_nameRefreshTimer = 0f;
				if (DpsData.MatchActive)
				{
					DpsData.RefreshDisplayNames();
				}
			}
		}

		private void HandleDrag()
		{
			//IL_001b: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_windowRect == (Object)null)
			{
				return;
			}
			if (Input.GetMouseButtonDown(0))
			{
				Vector2 val = ScreenToCanvas(Input.mousePosition);
				Vector2 anchoredPosition = _windowRect.anchoredPosition;
				float num = _windowRect.sizeDelta.x * 0.5f;
				float num2 = _windowRect.sizeDelta.y * 0.5f;
				if (val.x > anchoredPosition.x - num && val.x < anchoredPosition.x + num && val.y > anchoredPosition.y + num2 - 30f && val.y < anchoredPosition.y + num2)
				{
					_isDragging = true;
					_dragOffset = anchoredPosition - val;
				}
			}
			if (Input.GetMouseButtonUp(0) && _isDragging)
			{
				_isDragging = false;
				SavePosition();
			}
			if (_isDragging && Input.GetMouseButton(0))
			{
				_windowRect.anchoredPosition = ScreenToCanvas(Input.mousePosition) + _dragOffset;
				ClampToScreen();
			}
		}

		private void SavePosition()
		{
			//IL_0021: 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)
			if (!((Object)(object)_windowRect == (Object)null))
			{
				if (Plugin.CfgPositionX != null)
				{
					Plugin.CfgPositionX.Value = _windowRect.anchoredPosition.x;
				}
				if (Plugin.CfgPositionY != null)
				{
					Plugin.CfgPositionY.Value = _windowRect.anchoredPosition.y;
				}
			}
		}

		private Vector2 ScreenToCanvas(Vector3 screenPos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(screenPos.x - (float)Screen.width * 0.5f, screenPos.y - (float)Screen.height * 0.5f);
		}

		private void ClampToScreen()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_windowRect == (Object)null))
			{
				float num = _windowRect.sizeDelta.x * 0.5f;
				float num2 = _windowRect.sizeDelta.y * 0.5f;
				Vector2 anchoredPosition = _windowRect.anchoredPosition;
				anchoredPosition.x = Mathf.Clamp(anchoredPosition.x, (float)(-Screen.width) * 0.5f + num, (float)Screen.width * 0.5f - num);
				anchoredPosition.y = Mathf.Clamp(anchoredPosition.y, (float)(-Screen.height) * 0.5f + num2, (float)Screen.height * 0.5f - num2);
				_windowRect.anchoredPosition = anchoredPosition;
			}
		}

		private void SetVisible(bool v)
		{
			_visible = v;
			GameObject? windowObj = _windowObj;
			if (windowObj != null)
			{
				windowObj.SetActive(v);
			}
		}

		private void BuildUI()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_060a: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0634: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_0671: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0686: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0711: Unknown result type (might be due to invalid IL or missing references)
			//IL_072c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0758: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_079c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_080b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0822: Unknown result type (might be due to invalid IL or missing references)
			//IL_0837: Unknown result type (might be due to invalid IL or missing references)
			//IL_084c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0860: Unknown result type (might be due to invalid IL or missing references)
			float num = Plugin.CfgWindowWidth?.Value ?? 380f;
			float num2 = Plugin.CfgPositionX?.Value ?? 430f;
			float num3 = Plugin.CfgPositionY?.Value ?? 180f;
			_canvasObj = new GameObject("DpsMeterCanvas");
			Object.DontDestroyOnLoad((Object)(object)_canvasObj);
			Canvas obj = _canvasObj.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 9998;
			_canvasObj.AddComponent<GraphicRaycaster>();
			_windowObj = new GameObject("DpsWindow");
			_windowObj.transform.SetParent(_canvasObj.transform, false);
			_windowRect = _windowObj.AddComponent<RectTransform>();
			_windowRect.anchorMin = new Vector2(0.5f, 0.5f);
			_windowRect.anchorMax = new Vector2(0.5f, 0.5f);
			_windowRect.pivot = new Vector2(0.5f, 0.5f);
			_windowRect.anchoredPosition = new Vector2(num2, num3);
			_windowRect.sizeDelta = new Vector2(num, 200f);
			GameObject obj2 = MakeChild(_windowObj, "Background");
			((Graphic)obj2.AddComponent<Image>()).color = ColBody;
			RectTransform component = obj2.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			GameObject obj3 = MakeChild(_windowObj, "Content");
			RectTransform obj4 = obj3.AddComponent<RectTransform>();
			obj4.anchorMin = Vector2.zero;
			obj4.anchorMax = Vector2.one;
			obj4.offsetMin = new Vector2(2f, 2f);
			obj4.offsetMax = new Vector2(-2f, -2f);
			GameObject val = MakeChild(obj3, "Header");
			((Graphic)val.AddComponent<Image>()).color = ColHeader;
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 1f);
			component2.anchorMax = new Vector2(1f, 1f);
			component2.pivot = new Vector2(0.5f, 1f);
			component2.offsetMin = Vector2.zero;
			component2.offsetMax = Vector2.zero;
			component2.sizeDelta = new Vector2(0f, 30f);
			GameObject obj5 = MakeChild(val, "Accent");
			((Graphic)obj5.AddComponent<Image>()).color = new Color(0.3f, 0.6f, 1f, 0.7f);
			RectTransform component3 = obj5.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 0f);
			component3.anchorMax = new Vector2(1f, 0f);
			component3.pivot = new Vector2(0.5f, 0f);
			component3.sizeDelta = new Vector2(0f, 2f);
			_titleText = MakeText(val, "Title", 0f, 0.65f, 0f, 1f, (TextAnchor)3, 13, (FontStyle)1, ColTitle);
			_titleText.text = "⚔  DPS Meter";
			OffsetText(_titleText, 10f, 0f, 0f, 0f);
			_timerText = MakeText(val, "Timer", 0.65f, 1f, 0f, 1f, (TextAnchor)5, 12, (FontStyle)0, ColTimer);
			_timerText.text = "--:--";
			OffsetText(_timerText, 0f, 0f, -10f, 0f);
			GameObject val2 = MakeChild(obj3, "SubHeader");
			((Graphic)val2.AddComponent<Image>()).color = new Color(0.09f, 0.12f, 0.22f, 0.95f);
			RectTransform component4 = val2.GetComponent<RectTransform>();
			component4.anchorMin = new Vector2(0f, 1f);
			component4.anchorMax = new Vector2(1f, 1f);
			component4.pivot = new Vector2(0.5f, 1f);
			component4.offsetMin = Vector2.zero;
			component4.offsetMax = Vector2.zero;
			component4.anchoredPosition = new Vector2(0f, -30f);
			component4.sizeDelta = new Vector2(0f, 20f);
			GameObject obj6 = MakeChild(val2, "SubAccent");
			((Graphic)obj6.AddComponent<Image>()).color = new Color(0.3f, 0.6f, 1f, 0.35f);
			RectTransform component5 = obj6.GetComponent<RectTransform>();
			component5.anchorMin = new Vector2(0f, 0f);
			component5.anchorMax = new Vector2(1f, 0f);
			component5.pivot = new Vector2(0.5f, 0f);
			component5.sizeDelta = new Vector2(0f, 1f);
			AddColLabel(val2, "", 0f, 0.07f, (TextAnchor)4);
			AddColLabel(val2, "#", 0.07f, 0.13f, (TextAnchor)4);
			AddColLabel(val2, "Player", 0.13f, 0.42f, (TextAnchor)3);
			AddColLabel(val2, "Damage", 0.42f, 0.58f, (TextAnchor)5);
			AddColLabel(val2, "DPS", 0.58f, 0.72f, (TextAnchor)5);
			AddColLabel(val2, "Kills", 0.72f, 0.85f, (TextAnchor)4);
			AddColLabel(val2, "%", 0.85f, 1f, (TextAnchor)5);
			GameObject val3 = MakeChild(obj3, "RowArea");
			val3.AddComponent<RectTransform>();
			RectTransform component6 = val3.GetComponent<RectTransform>();
			component6.anchorMin = Vector2.zero;
			component6.anchorMax = Vector2.one;
			component6.offsetMin = Vector2.zero;
			component6.offsetMax = new Vector2(0f, -51f);
			_scrollContent = MakeChild(val3, "Rows");
			RectTransform obj7 = _scrollContent.AddComponent<RectTransform>();
			obj7.anchorMin = new Vector2(0f, 1f);
			obj7.anchorMax = new Vector2(1f, 1f);
			obj7.pivot = new Vector2(0.5f, 1f);
			obj7.anchoredPosition = Vector2.zero;
			GameObject obj8 = MakeChild(_windowObj, "BorderOverlay");
			obj8.AddComponent<RectTransform>();
			RectTransform component7 = obj8.GetComponent<RectTransform>();
			component7.anchorMin = Vector2.zero;
			component7.anchorMax = Vector2.one;
			component7.offsetMin = Vector2.zero;
			component7.offsetMax = Vector2.zero;
			Color color = default(Color);
			((Color)(ref color))..ctor(0.22f, 0.48f, 1f, 1f);
			GameObject obj9 = MakeChild(obj8, "BorderTop");
			((Graphic)obj9.AddComponent<Image>()).color = color;
			RectTransform component8 = obj9.GetComponent<RectTransform>();
			component8.anchorMin = new Vector2(0f, 1f);
			component8.anchorMax = new Vector2(1f, 1f);
			component8.pivot = new Vector2(0.5f, 1f);
			component8.sizeDelta = new Vector2(0f, 2f);
			GameObject obj10 = MakeChild(obj8, "BorderBottom");
			((Graphic)obj10.AddComponent<Image>()).color = color;
			RectTransform component9 = obj10.GetComponent<RectTransform>();
			component9.anchorMin = new Vector2(0f, 0f);
			component9.anchorMax = new Vector2(1f, 0f);
			component9.pivot = new Vector2(0.5f, 0f);
			component9.sizeDelta = new Vector2(0f, 2f);
			GameObject obj11 = MakeChild(obj8, "BorderLeft");
			((Graphic)obj11.AddComponent<Image>()).color = color;
			RectTransform component10 = obj11.GetComponent<RectTransform>();
			component10.anchorMin = new Vector2(0f, 0f);
			component10.anchorMax = new Vector2(0f, 1f);
			component10.pivot = new Vector2(0f, 0.5f);
			component10.sizeDelta = new Vector2(2f, 0f);
			GameObject obj12 = MakeChild(obj8, "BorderRight");
			((Graphic)obj12.AddComponent<Image>()).color = color;
			RectTransform component11 = obj12.GetComponent<RectTransform>();
			component11.anchorMin = new Vector2(1f, 0f);
			component11.anchorMax = new Vector2(1f, 1f);
			component11.pivot = new Vector2(1f, 0.5f);
			component11.sizeDelta = new Vector2(2f, 0f);
			_windowObj.SetActive(_visible);
		}

		private void AddColLabel(GameObject parent, string text, float xMin, float xMax, TextAnchor anchor)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Text obj = MakeText(parent, "Col_" + text, xMin, xMax, 0f, 1f, anchor, 9, (FontStyle)1, ColLabel);
			obj.text = text.ToUpperInvariant();
			OffsetText(obj, 4f, 0f, -4f, 0f);
		}

		private void RefreshUI()
		{
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_066f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0622: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_windowRect == (Object)null || (Object)(object)_scrollContent == (Object)null)
			{
				return;
			}
			DpsData.SyncFromNetwork();
			float time = Time.time;
			float num = Plugin.CfgWindowWidth?.Value ?? 380f;
			float num2 = Plugin.CfgRowHeight?.Value ?? 28f;
			float num3 = Plugin.CfgBarOpacity?.Value ?? 0.22f;
			if ((Object)(object)_timerText != (Object)null)
			{
				SessionTimerService i = SessionTimerService.I;
				if ((Object)(object)i != (Object)null && i.IsRunning)
				{
					_timerText.text = i.FormattedTime;
				}
				else if (DpsData.MatchActive)
				{
					float num4 = time - DpsData.MatchStartTime;
					_timerText.text = $"{(int)(num4 / 60f)}:{(int)(num4 % 60f):D2}";
				}
				else
				{
					_timerText.text = ((DpsData.Records.Count > 0) ? "ENDED" : "--:--");
				}
			}
			List<PlayerDamageRecord> list = DpsData.Records.Values.OrderByDescending((PlayerDamageRecord r) => r.TotalDamage).ToList();
			float num5 = ((list.Count > 0 && list[0].TotalDamage > 0f) ? list[0].TotalDamage : 1f);
			float num6 = list.Sum((PlayerDamageRecord r) => r.TotalDamage);
			while (_rows.Count < list.Count)
			{
				_rows.Add(BuildRow(_rows.Count));
			}
			for (int num7 = list.Count; num7 < _rows.Count; num7++)
			{
				GameObject? root = _rows[num7].Root;
				if (root != null)
				{
					root.SetActive(false);
				}
			}
			if (list.Count == 0)
			{
				EnsureEmptyLabel();
			}
			else
			{
				DestroyEmptyLabel();
			}
			Color[] array = (Color[])(object)new Color[4]
			{
				new Color(1f, 0.78f, 0.08f, num3),
				new Color(0.68f, 0.68f, 0.78f, num3 * 0.85f),
				new Color(0.78f, 0.48f, 0.22f, num3 * 0.75f),
				new Color(0.2f, 0.42f, 0.8f, num3 * 0.65f)
			};
			for (int num8 = 0; num8 < list.Count; num8++)
			{
				PlayerDamageRecord playerDamageRecord = list[num8];
				PlayerRow playerRow = _rows[num8];
				GameObject? root2 = playerRow.Root;
				if (root2 != null)
				{
					root2.SetActive(true);
				}
				GameObject? root3 = playerRow.Root;
				RectTransform val = ((root3 != null) ? root3.GetComponent<RectTransform>() : null);
				if ((Object)(object)val != (Object)null)
				{
					val.anchoredPosition = new Vector2(0f, (float)(-num8) * num2);
					val.sizeDelta = new Vector2(0f, num2);
				}
				float num9 = playerDamageRecord.TotalDamage / num5;
				if ((Object)(object)playerRow.BarFill != (Object)null)
				{
					RectTransform component = ((Component)playerRow.BarFill).GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null)
					{
						component.anchorMax = new Vector2(Mathf.Clamp01(num9), 1f);
					}
					((Graphic)playerRow.BarFill).color = array[Mathf.Min(num8, array.Length - 1)];
				}
				if ((Object)(object)playerRow.IconImg != (Object)null)
				{
					if ((Object)(object)playerDamageRecord.IconSprite != (Object)null)
					{
						playerRow.IconImg.sprite = playerDamageRecord.IconSprite;
						((Component)playerRow.IconImg).gameObject.SetActive(true);
					}
					else
					{
						((Component)playerRow.IconImg).gameObject.SetActive(false);
					}
				}
				if ((Object)(object)playerRow.RankText != (Object)null)
				{
					playerRow.RankText.text = (num8 + 1).ToString();
					((Graphic)playerRow.RankText).color = (Color)(num8 switch
					{
						2 => new Color(0.8f, 0.5f, 0.25f), 
						1 => new Color(0.75f, 0.75f, 0.82f), 
						0 => new Color(1f, 0.85f, 0.15f), 
						_ => new Color(0.5f, 0.55f, 0.7f), 
					});
				}
				bool isSelf = playerDamageRecord.IsSelf;
				if ((Object)(object)playerRow.NameText != (Object)null)
				{
					playerRow.NameText.text = playerDamageRecord.DisplayName;
					((Graphic)playerRow.NameText).color = (isSelf ? new Color(0.3f, 0.9f, 0.45f) : new Color(0.88f, 0.88f, 0.96f));
					playerRow.NameText.fontStyle = (FontStyle)(isSelf ? 1 : 0);
				}
				if ((Object)(object)playerRow.DmgText != (Object)null)
				{
					playerRow.DmgText.text = FormatDamage(playerDamageRecord.TotalDamage);
				}
				if ((Object)(object)playerRow.DpsText != (Object)null)
				{
					playerRow.DpsText.text = $"{playerDamageRecord.DPS(time):F0}";
				}
				if ((Object)(object)playerRow.KillText != (Object)null)
				{
					playerRow.KillText.text = playerDamageRecord.Kills.ToString();
				}
				float num10 = ((num6 > 0f) ? (playerDamageRecord.TotalDamage / num6 * 100f) : 0f);
				if ((Object)(object)playerRow.PctText != (Object)null)
				{
					playerRow.PctText.text = $"{num10:F1}%";
				}
				if ((Object)(object)playerRow.Bg != (Object)null)
				{
					((Graphic)playerRow.Bg).color = ((num8 % 2 == 0) ? new Color(0.08f, 0.1f, 0.18f, 0.88f) : new Color(0.06f, 0.08f, 0.14f, 0.88f));
				}
			}
			float num11 = Mathf.Max((float)list.Count * num2, 28f);
			float num12 = 50f + num11 + 4f;
			_windowRect.sizeDelta = new Vector2(num, num12);
			RectTransform component2 = _scrollContent.GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.sizeDelta = new Vector2(0f, num11);
			}
		}

		private void EnsureEmptyLabel()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_emptyLabel != (Object)null))
			{
				_emptyLabel = MakeChild(_scrollContent, "Empty");
				Text obj = _emptyLabel.AddComponent<Text>();
				obj.font = _font;
				obj.fontSize = Plugin.CfgFontSize?.Value ?? 11;
				((Graphic)obj).color = new Color(0.38f, 0.44f, 0.6f, 0.85f);
				obj.alignment = (TextAnchor)4;
				obj.text = "Waiting for combat data…";
				RectTransform component = _emptyLabel.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0f, 1f);
				component.anchorMax = new Vector2(1f, 1f);
				component.pivot = new Vector2(0.5f, 1f);
				component.sizeDelta = new Vector2(0f, 28f);
				component.anchoredPosition = new Vector2(0f, 0f);
			}
		}

		private void DestroyEmptyLabel()
		{
			if ((Object)(object)_emptyLabel != (Object)null)
			{
				Object.Destroy((Object)(object)_emptyLabel);
				_emptyLabel = null;
			}
		}

		private PlayerRow BuildRow(int idx)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_022d: 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)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			int num = Plugin.CfgFontSize?.Value ?? 11;
			GameObject val = MakeChild(_scrollContent, $"Row_{idx}");
			RectTransform obj = val.AddComponent<RectTransform>();
			obj.anchorMin = new Vector2(0f, 1f);
			obj.anchorMax = new Vector2(1f, 1f);
			obj.pivot = new Vector2(0.5f, 1f);
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = new Color(0.08f, 0.1f, 0.18f, 0.88f);
			GameObject obj2 = MakeChild(val, "Bar");
			Image barFill = obj2.AddComponent<Image>();
			RectTransform component = obj2.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(0f, 1f);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			GameObject obj3 = MakeChild(val, "Icon");
			Image val3 = obj3.AddComponent<Image>();
			val3.preserveAspect = true;
			RectTransform component2 = obj3.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 0f);
			component2.anchorMax = new Vector2(0.07f, 1f);
			component2.offsetMin = new Vector2(2f, 2f);
			component2.offsetMax = new Vector2(-2f, -2f);
			Text val4 = MakeText(val, "Rank", 0.07f, 0.13f, 0f, 1f, (TextAnchor)4, num + 1, (FontStyle)1, new Color(1f, 0.85f, 0.15f));
			Text val5 = MakeText(val, "Name", 0.13f, 0.42f, 0f, 1f, (TextAnchor)3, num, (FontStyle)0, new Color(0.88f, 0.88f, 0.96f));
			Text val6 = MakeText(val, "Dmg", 0.42f, 0.58f, 0f, 1f, (TextAnchor)5, num, (FontStyle)0, new Color(0.88f, 0.88f, 0.96f));
			Text val7 = MakeText(val, "Dps", 0.58f, 0.72f, 0f, 1f, (TextAnchor)5, num, (FontStyle)1, ColDps);
			Text val8 = MakeText(val, "Kills", 0.72f, 0.85f, 0f, 1f, (TextAnchor)4, num, (FontStyle)0, ColKills);
			Text val9 = MakeText(val, "Pct", 0.85f, 1f, 0f, 1f, (TextAnchor)5, num, (FontStyle)0, new Color(0.75f, 0.92f, 1f));
			Text[] array = (Text[])(object)new Text[6] { val4, val5, val6, val7, val8, val9 };
			for (int i = 0; i < array.Length; i++)
			{
				OffsetText(array[i], 4f, 1f, -4f, -1f);
			}
			return new PlayerRow
			{
				Root = val,
				Bg = val2,
				BarFill = barFill,
				IconImg = val3,
				RankText = val4,
				NameText = val5,
				DmgText = val6,
				DpsText = val7,
				KillText = val8,
				PctText = val9
			};
		}

		private static GameObject MakeChild(GameObject parent, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent.transform, false);
			return val;
		}

		private Text MakeText(GameObject parent, string name, float xMin, float xMax, float yMin, float yMax, TextAnchor anchor, int size, FontStyle style, Color color)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = MakeChild(parent, name);
			Text obj = val.AddComponent<Text>();
			obj.font = _font;
			obj.fontSize = size;
			obj.fontStyle = style;
			((Graphic)obj).color = color;
			obj.alignment = anchor;
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(xMin, yMin);
			component.anchorMax = new Vector2(xMax, yMax);
			return obj;
		}

		private static void OffsetText(Text t, float left, float bottom, float right, float top)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = ((Component)t).GetComponent<RectTransform>();
			component.offsetMin = new Vector2(left, bottom);
			component.offsetMax = new Vector2(right, top);
		}

		private static string FormatDamage(float d)
		{
			if (!(d >= 1000000f))
			{
				if (!(d >= 1000f))
				{
					return $"{d:F0}";
				}
				return $"{d / 1000f:F1}k";
			}
			return $"{d / 1000000f:F2}M";
		}

		private static Font FindFont()
		{
			try
			{
				Text[] array = Object.FindObjectsByType<Text>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				foreach (Text val in array)
				{
					if ((Object)(object)((val != null) ? val.font : null) != (Object)null)
					{
						return val.font;
					}
				}
			}
			catch
			{
			}
			return Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
		}
	}
	public class PlayerRow
	{
		public GameObject? Root;

		public Image? Bg;

		public Image? BarFill;

		public Image? IconImg;

		public Text? RankText;

		public Text? NameText;

		public Text? DmgText;

		public Text? DpsText;

		public Text? PctText;

		public Text? KillText;
	}
}