Decompiled source of CombatMeter v0.2.1

BepInEx/plugins/CombatMeter/CombatMeter.Client.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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CombatMeter.Core;
using CombatMeter.Runtime;
using CombatMeter.Shared;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Network;
using ProjectM.UI;
using Stunlock.Core;
using Stunlock.Localization;
using TMPro;
using Unity.Entities;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Sprites;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("Reloadable", "true")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CombatMeter.Client")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+7bf5d4af4539905a627ee336fb44ed2fa9bdee99")]
[assembly: AssemblyProduct("CombatMeter.Client")]
[assembly: AssemblyTitle("CombatMeter.Client")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.1.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 CombatMeter.Client
{
	internal sealed class ClientRuntime : IDisposable
	{
		private readonly Plugin _plugin;

		private readonly NativeTransport _transport;

		internal readonly MeterState State = new MeterState();

		internal readonly SourceDetailState Details = new SourceDetailState();

		internal readonly ConfigEntry<bool> Visible;

		internal readonly ConfigEntry<bool> Locked;

		internal readonly ConfigEntry<float> Scale;

		internal readonly ConfigEntry<float> BackgroundOpacity;

		internal readonly ConfigEntry<float> OffsetX;

		internal readonly ConfigEntry<float> OffsetY;

		internal readonly ConfigEntry<KeyCode> ReviewKey;

		internal readonly ConfigEntry<bool> ShowEnemies;

		internal readonly ConfigEntry<BossTargetFilter> Filter;

		internal readonly Dictionary<EncounterKind, ConfigEntry<bool>> Modes = new Dictionary<EncounterKind, ConfigEntry<bool>>();

		private NativeHud? _hud;

		private double _nextHudSearch;

		private double _nextRefresh;

		private double _nextRegistration;

		private bool _registered;

		private InputActionSystem? _focusedSystem;

		private ChatFocusedInputContext? _nativeContext;

		private IInputContext? _inputContext;

		private bool _inputRegistered;

		private CursorLockMode _oldCursorLock;

		private bool _oldCursorVisible;

		private readonly List<InputAction> _blockedScrollActions = new List<InputAction>();

		internal bool ReviewOpen => _hud?.ReviewOpen ?? false;

		internal void SynchronizeInput(InputActionSystem system)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if (_focusedSystem != system)
			{
				ReleaseScrollInputs();
				ReleaseInput();
				_focusedSystem = system;
			}
			bool flag = _hud?.WantsInputFocus ?? false;
			if (flag && !_inputRegistered)
			{
				_nativeContext = new ChatFocusedInputContext();
				_inputContext = ((Il2CppObjectBase)_nativeContext).Cast<IInputContext>();
				system.AddInputContext(_inputContext, (Object)(object)_nativeContext, 100);
				_inputRegistered = true;
				_oldCursorLock = Cursor.lockState;
				_oldCursorVisible = Cursor.visible;
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			else if (!flag)
			{
				ReleaseInput();
			}
			SynchronizeScrollInputs(system);
		}

		private void SynchronizeScrollInputs(InputActionSystem system)
		{
			//IL_003a: 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)
			NativeHud? hud = _hud;
			if (hud == null || !hud.CapturesWheel)
			{
				ReleaseScrollInputs();
				return;
			}
			Dictionary<InputAction, AnalogInputAction> analogInputActions = system._AnalogInputActions;
			if (analogInputActions == null)
			{
				return;
			}
			Enumerator<InputAction, AnalogInputAction> enumerator = analogInputActions.GetEnumerator();
			while (enumerator.MoveNext())
			{
				KeyValuePair<InputAction, AnalogInputAction> current = enumerator.Current;
				if ((current.Value & 0x21010) != 0 && current.Key.enabled)
				{
					if (!_blockedScrollActions.Contains(current.Key))
					{
						_blockedScrollActions.Add(current.Key);
					}
					current.Key.Disable();
				}
			}
		}

		private void ReleaseScrollInputs()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			bool flag = default(bool);
			foreach (InputAction blockedScrollAction in _blockedScrollActions)
			{
				try
				{
					blockedScrollAction.Enable();
				}
				catch (Exception ex)
				{
					ManualLogSource log = ((BasePlugin)_plugin).Log;
					BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(39, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter scroll input was released: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogDebug(val);
				}
			}
			_blockedScrollActions.Clear();
		}

		private void ReleaseInput()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if (!_inputRegistered)
			{
				return;
			}
			try
			{
				if (_focusedSystem != null && _inputContext != null)
				{
					_focusedSystem.RemoveInputContext(_inputContext);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)_plugin).Log;
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(38, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter input world was released: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogDebug(val);
			}
			_inputRegistered = false;
			_inputContext = null;
			_nativeContext = null;
			Cursor.lockState = _oldCursorLock;
			Cursor.visible = _oldCursorVisible;
		}

		public unsafe ClientRuntime(Plugin plugin)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			_plugin = plugin;
			Visible = ((BasePlugin)plugin).Config.Bind<bool>("Display", "Visible", true, "Show the live meter.");
			Locked = ((BasePlugin)plugin).Config.Bind<bool>("Display", "PositionLocked", true, "Lock the position to disable dragging the meter header.");
			Scale = ((BasePlugin)plugin).Config.Bind<float>("Display", "Scale", 1f, new ConfigDescription("Meter scale.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.6f, 2f), Array.Empty<object>()));
			BackgroundOpacity = ((BasePlugin)plugin).Config.Bind<float>("Display", "BackgroundOpacity", 0.9f, new ConfigDescription("DPS list background opacity. 0 is fully transparent; text, bars, icons, and menus keep their normal opacity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			OffsetX = ((BasePlugin)plugin).Config.Bind<float>("Display", "OffsetX", -8f, "Horizontal offset from the upper right HUD corner.");
			OffsetY = ((BasePlugin)plugin).Config.Bind<float>("Display", "OffsetY", -944f, "Vertical offset from the upper right HUD corner.");
			ConfigEntry<int> val = ((BasePlugin)plugin).Config.Bind<int>("Display", "LayoutVersion", 1, "Internal layout migration version.");
			if (val.Value < 1)
			{
				if (OffsetX.Value == -24f && OffsetY.Value == -240f)
				{
					OffsetX.Value = -8f;
					OffsetY.Value = -944f;
				}
				val.Value = 1;
			}
			ReviewKey = ((BasePlugin)plugin).Config.Bind<KeyCode>("Controls", "ReviewKey", (KeyCode)289, "Open/close review and settings. Escape closes it.");
			ShowEnemies = ((BasePlugin)plugin).Config.Bind<bool>("Display", "ShowEnemies", true, "Show a separate list of monster and boss damage dealt to players.");
			Filter = ((BasePlugin)plugin).Config.Bind<BossTargetFilter>("Display", "BossTargets", (BossTargetFilter)1, "Count the boss alone or the boss and its summons.");
			EncounterKind[] values = Enum.GetValues<EncounterKind>();
			for (int i = 0; i < values.Length; i++)
			{
				EncounterKind key = values[i];
				Modes[key] = ((BasePlugin)plugin).Config.Bind<bool>("Visibility", ((object)(*(EncounterKind*)(&key))/*cast due to .constrained prefix*/).ToString(), true, "Display this mode when server tracking is enabled.");
			}
			_transport = new NativeTransport(OnPolicy, OnEncounter, OnSources, Ready);
		}

		private void Ready()
		{
			_registered = false;
			_nextRegistration = 0.0;
		}

		private void OnPolicy(PolicyPacket packet)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			string sessionId = State.SessionId;
			_registered = State.Apply(packet);
			if (!_registered || sessionId != State.SessionId)
			{
				Details.Clear();
				_hud?.CloseDetails();
			}
			ManualLogSource log = ((BasePlugin)_plugin).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(60, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[CombatMeter:Transport] policy received; accepted=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(_registered);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; session=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(packet.ServerSessionId);
			}
			log.LogInfo(val);
			_hud?.Refresh();
		}

		private void OnEncounter(EncounterPacket packet)
		{
			if (State.Apply(packet))
			{
				_hud?.Refresh();
			}
		}

		private void OnSources(SourceResponsePacket packet)
		{
			if (Details.Apply(packet))
			{
				_hud?.RefreshDetails();
			}
		}

		internal void Inspect(DetailSelection? selection)
		{
			Details.Select(State.SessionId, selection, Time.realtimeSinceStartupAsDouble);
		}

		internal void LogStyle(string text)
		{
			((BasePlugin)_plugin).Log.LogInfo((object)("[CombatMeter:Style] " + text));
		}

		internal void Update()
		{
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Expected O, but got Unknown
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				double realtimeSinceStartupAsDouble = Time.realtimeSinceStartupAsDouble;
				if (_transport.PollConnection(realtimeSinceStartupAsDouble))
				{
					((BasePlugin)_plugin).Log.LogInfo((object)"[CombatMeter:Transport] native game connection ready");
				}
				if (!_transport.IsReady && _registered)
				{
					_registered = false;
					State.Disconnect();
					Details.Clear();
					_hud?.CloseReview();
					ReleaseScrollInputs();
					ReleaseInput();
				}
				if (_transport.IsReady && !_registered && realtimeSinceStartupAsDouble >= _nextRegistration)
				{
					_nextRegistration = realtimeSinceStartupAsDouble + 5.0;
					_transport.Register();
					((BasePlugin)_plugin).Log.LogInfo((object)"[CombatMeter:Transport] registration sent");
				}
				if (_hud != null && !_hud.IsAlive)
				{
					ReleaseScrollInputs();
					ReleaseInput();
					_hud.Dispose();
					_hud = null;
					State.Disconnect();
					Details.Clear();
					_registered = false;
					_nextRegistration = 0.0;
				}
				if (_hud == null && realtimeSinceStartupAsDouble >= _nextHudSearch)
				{
					_nextHudSearch = realtimeSinceStartupAsDouble + 2.0;
					UICanvasBase val = Object.FindObjectOfType<UICanvasBase>();
					if (val != null && val.HUDParent != null)
					{
						_hud = new NativeHud(this, val);
						((BasePlugin)_plugin).Log.LogInfo((object)"CombatMeter attached to the native HUD canvas.");
					}
				}
				if (_hud == null)
				{
					return;
				}
				if (Input.GetKeyDown(ReviewKey.Value))
				{
					_hud.CloseDetails();
					_hud.ToggleReview();
				}
				if (Input.GetKeyDown((KeyCode)27))
				{
					if (_hud.DetailsOpen)
					{
						_hud.CloseDetails();
					}
					else if (ReviewOpen)
					{
						_hud.CloseReview();
					}
				}
				_hud.UpdateDrag();
				if (_registered && _transport.IsReady)
				{
					SourceRequestPacket val2 = Details.Poll(realtimeSinceStartupAsDouble);
					if (val2 != null)
					{
						_transport.RequestSources(val2);
					}
				}
				if (realtimeSinceStartupAsDouble >= _nextRefresh)
				{
					_nextRefresh = realtimeSinceStartupAsDouble + 0.25;
					_hud.Refresh();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)_plugin).Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(34, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("CombatMeter client update failed: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val3);
				_nextHudSearch = Time.realtimeSinceStartupAsDouble + 5.0;
			}
		}

		internal void RequestHistory()
		{
			if (State.Policy != null && _transport.IsReady)
			{
				_transport.RequestHistory(State.SessionId);
			}
		}

		public void Dispose()
		{
			ReleaseScrollInputs();
			ReleaseInput();
			_hud?.Dispose();
			_hud = null;
			State.Disconnect();
			Details.Clear();
			_transport.Dispose();
		}
	}
	internal static class DamagePresentation
	{
		private const string TargetGroupPrefix = "targets:";

		private static readonly Regex TargetSuffix = new Regex("[ _]+Target[ _]*[0-9]+$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

		public static string TargetName(string name)
		{
			return TargetSuffix.Replace(name, "").TrimEnd();
		}

		public static bool IsTargetGroup(SourceRow source)
		{
			return source.Id.StartsWith("targets:", StringComparison.Ordinal);
		}

		public static SourceRow[] Sources(SourceResponsePacket detail, BossTargetFilter filter)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return (from x in SourceDetailState.Rank(detail, filter).GroupBy<SourceRow, string>(delegate(SourceRow source)
				{
					//IL_000d: 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_0013: Unknown result type (might be due to invalid IL or missing references)
					//IL_0015: Unknown result type (might be due to invalid IL or missing references)
					//IL_0017: Invalid comparison between Unknown and I4
					//IL_0046: Unknown result type (might be due to invalid IL or missing references)
					//IL_004c: Expected I4, but got Unknown
					string text = TargetName(source.Name);
					DamageSourceKind kind = source.Kind;
					bool flag = kind - 5 <= 1;
					return (flag || text.Length <= 0 || !(text != source.Name)) ? source.Id : ("targets:" + (int)source.Kind + ":" + text);
				}, StringComparer.Ordinal).Select(delegate(IGrouping<string, SourceRow> @group)
				{
					SourceRow val = @group.OrderBy<SourceRow, string>((SourceRow x) => x.Id, StringComparer.Ordinal).First();
					SourceRow obj = val.<Clone>$();
					obj.set_Id(@group.Key);
					obj.set_Name(@group.Key.StartsWith("targets:", StringComparison.Ordinal) ? TargetName(val.Name) : val.Name);
					obj.set_Damage(@group.Sum((SourceRow x) => x.Damage));
					obj.set_Dps(@group.Sum((SourceRow x) => x.Dps));
					obj.set_Share(@group.Sum((SourceRow x) => x.Share));
					return obj;
				})
				orderby x.Damage descending
				select x).ThenBy<SourceRow, string>((SourceRow x) => x.Id, StringComparer.Ordinal).ToArray();
		}

		public static double BarMaximum(IEnumerable<MeterRow> players, IEnumerable<MeterRow> enemies)
		{
			return (from x in players.Concat(enemies)
				select x.Damage).DefaultIfEmpty().Max();
		}

		public static int ColorKey(SourceRow source)
		{
			if (!IsTargetGroup(source))
			{
				return source.PrefabHash;
			}
			uint num = 2166136261u;
			string id = source.Id;
			foreach (char c in id)
			{
				num = (num ^ c) * 16777619;
			}
			return (int)num;
		}
	}
	internal sealed class HudIcons : IDisposable
	{
		private readonly List<Texture2D> _textures = new List<Texture2D>();

		private readonly List<Sprite> _sprites = new List<Sprite>();

		public Sprite Cog { get; }

		public Sprite Locked { get; }

		public Sprite Unlocked { get; }

		public HudIcons()
		{
			Cog = Create("CombatMeter Cog", Gear);
			Locked = Create("CombatMeter Locked", (Vector2 p) => Lock(p, open: false));
			Unlocked = Create("CombatMeter Unlocked", (Vector2 p) => Lock(p, open: true));
		}

		private Sprite Create(string name, Func<Vector2, float> distance)
		{
			//IL_00d6: 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_00e2: 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_00f1: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[16384];
			Vector2 arg = default(Vector2);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					((Vector2)(ref arg))..ctor(((float)j + 0.5f) * 2f / 128f - 1f, ((float)i + 0.5f) * 2f / 128f - 1f);
					float num = Mathf.Clamp01(0.5f - distance(arg) * 128f / 2f);
					array[i * 128 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num * 255f));
				}
			}
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true)
			{
				name = name,
				filterMode = (FilterMode)2,
				wrapMode = (TextureWrapMode)1
			};
			_textures.Add(val);
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply(true, true);
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 128f);
			((Object)val2).name = name;
			_sprites.Add(val2);
			return val2;
		}

		private static float Box(Vector2 point, Vector2 half, float radius = 0f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0032: 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_0052: 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_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)
			Vector2 val = new Vector2(Mathf.Abs(point.x), Mathf.Abs(point.y)) - half + Vector2.one * radius;
			Vector2 val2 = new Vector2(Mathf.Max(val.x, 0f), Mathf.Max(val.y, 0f));
			return ((Vector2)(ref val2)).magnitude + Mathf.Min(Mathf.Max(val.x, val.y), 0f) - radius;
		}

		private static Vector2 Rotate(Vector2 p, float angle)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(p.x * Mathf.Cos(angle) - p.y * Mathf.Sin(angle), p.x * Mathf.Sin(angle) + p.y * Mathf.Cos(angle));
		}

		private static float Gear(Vector2 p)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Vector2)(ref p)).magnitude - 0.62f;
			for (int i = 0; i < 8; i++)
			{
				num = Mathf.Min(num, Box(Rotate(p, (float)i * (float)Math.PI / 4f) - new Vector2(0.67f, 0f), new Vector2(0.17f, 0.13f), 0.035f));
			}
			return Mathf.Max(num, 0.29f - ((Vector2)(ref p)).magnitude);
		}

		private static float Lock(Vector2 p, bool open)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			float num = Box(p - new Vector2(0f, -0.3f), new Vector2(0.52f, 0.38f), 0.08f);
			Vector2 val = p - new Vector2(0f, -0.22f);
			float num2 = Mathf.Min(((Vector2)(ref val)).magnitude - 0.09f, Box(p - new Vector2(0f, -0.35f), new Vector2(0.045f, 0.12f)));
			float num3 = Mathf.Max(num, 0f - num2);
			Vector2 val2 = (open ? (Rotate(p - new Vector2(0.36f, 0.05f), 0.55f) + new Vector2(0.36f, 0.05f)) : p);
			val = val2 - new Vector2(0f, 0.28f);
			float num4 = Mathf.Max(Mathf.Abs(((Vector2)(ref val)).magnitude - 0.36f) - 0.085f, 0.28f - val2.y);
			float num5 = Box(new Vector2(Mathf.Abs(val2.x) - 0.36f, val2.y - 0.16f), new Vector2(0.085f, 0.12f));
			return Mathf.Min(num3, Mathf.Min(num4, num5));
		}

		public void Dispose()
		{
			foreach (Sprite sprite in _sprites)
			{
				if ((Object)(object)sprite != (Object)null)
				{
					Object.Destroy((Object)(object)sprite);
				}
			}
			foreach (Texture2D texture in _textures)
			{
				if ((Object)(object)texture != (Object)null)
				{
					Object.Destroy((Object)(object)texture);
				}
			}
			_sprites.Clear();
			_textures.Clear();
		}
	}
	internal sealed class NativeHud : IDisposable
	{
		private sealed record ScrollView(RectTransform Viewport, RectTransform Content, ScrollRect Scroll, RectTransform? Track, RectTransform? Thumb);

		private sealed record Row(GameObject Root, Image Bar, TextMeshProUGUI Name, TextMeshProUGUI Value)
		{
			public DetailSelection? Selection;

			public string ActorName = "";

			public string EncounterLabel = "";

			public Image? Icon;

			public Image? SourceMarker;
		}

		private const float HudWidth = 320f;

		private const float HudHeight = 136f;

		private const float HudListWidth = 308f;

		private const float HudRowPitch = 24f;

		private const float ReviewWidth = 830f;

		private const float ReviewHeight = 760f;

		private const float HistoryWidth = 204f;

		private const float ReviewListWidth = 474f;

		private const float DetailWidth = 650f;

		private const float DetailHeight = 560f;

		private const float SourceListWidth = 538f;

		private const float WindowInset = 48f;

		private const float ScrollbarGutter = 16f;

		private const float TextScale = 1.2f;

		private const float RowPitch = 30f;

		private static readonly Color ButtonRed = new Color(0.36f, 0.09f, 0.12f, 1f);

		private static readonly Color SelectedButtonRed = new Color(0.55f, 0.13f, 0.17f, 1f);

		private readonly ClientRuntime _runtime;

		private readonly GameObject _meter;

		private readonly GameObject _review;

		private readonly GameObject _details;

		private readonly RectTransform _detailRect;

		private readonly RectTransform _detailHeader;

		private readonly RectTransform _detailContent;

		private readonly TextMeshProUGUI _detailTitle;

		private readonly TextMeshProUGUI _detailSubtitle;

		private readonly TextMeshProUGUI _detailMessage;

		private readonly (Button Button, TextMeshProUGUI Text) _detailFilter;

		private readonly List<Row> _sourceRows = new List<Row>();

		private readonly SourceVisuals _sourceVisuals = new SourceVisuals();

		private readonly HudIcons _icons;

		private DetailSelection? _pinned;

		private (DetailSelection Selection, string Name, string Label)? _pressedActor;

		private bool _detailDragging;

		private bool _dismissPointerClick;

		private int _dismissReleasedFrame = -1;

		private Vector2 _detailDragStart;

		private Vector2 _detailInitial;

		private string? _hoverKey;

		private double _hoverStart;

		private string? _tooltipText;

		private Vector3 _tooltipPosition;

		private readonly RectTransform _meterRect;

		private readonly RectTransform _header;

		private readonly RectTransform _meterContent;

		private readonly RectTransform _reviewContent;

		private readonly RectTransform _historyContent;

		private readonly Image _meterBackground;

		private readonly TMP_FontAsset _font;

		private readonly Material _fontMaterial;

		private readonly Dictionary<int, Material> _outlinedFonts = new Dictionary<int, Material>();

		private readonly Image? _windowTemplate;

		private readonly Image? _windowHeaderTemplate;

		private readonly Sprite? _trimmedWindowSprite;

		private readonly Sprite? _barSprite;

		private readonly List<Row> _meterRows = new List<Row>();

		private readonly List<Row> _reviewRows = new List<Row>();

		private readonly List<(Button Button, TextMeshProUGUI Text)> _historyButtons = new List<(Button, TextMeshProUGUI)>();

		private readonly List<(Button Button, TextMeshProUGUI Text, EncounterKind Kind)> _modeButtons = new List<(Button, TextMeshProUGUI, EncounterKind)>();

		private readonly TextMeshProUGUI _meterDetail;

		private readonly TextMeshProUGUI _reviewTitle;

		private readonly TextMeshProUGUI _reviewDetail;

		private readonly TextMeshProUGUI _enemyLabel;

		private readonly TextMeshProUGUI _filterLabel;

		private readonly TextMeshProUGUI _lockLabel;

		private readonly TextMeshProUGUI _visibleLabel;

		private readonly RectTransform _openButton;

		private readonly RectTransform _lockButton;

		private readonly Image _lockIcon;

		private readonly Image _cogIcon;

		private readonly List<(Button Button, Action Action)> _buttons = new List<(Button, Action)>();

		private readonly List<ScrollView> _scrolls = new List<ScrollView>();

		private ScrollView? _draggedScroll;

		private float _scrollGrab;

		private Button? _pressedButton;

		private int _keyboardButton = -1;

		private readonly FakeTooltip? _tooltip;

		private readonly List<(RectTransform Target, string Title, string Description)> _tooltips = new List<(RectTransform, string, string)>();

		private RectTransform? _hovered;

		private string? _selectedEncounter;

		private bool _dragging;

		private Vector2 _dragStart;

		private Vector2 _initialPosition;

		public bool ReviewOpen { get; private set; }

		public bool DetailsOpen => _pinned != null;

		public bool IsAlive
		{
			get
			{
				if ((Object)(object)_meter != (Object)null && (Object)(object)_review != (Object)null)
				{
					return (Object)(object)_details != (Object)null;
				}
				return false;
			}
		}

		public bool CapturesWheel
		{
			get
			{
				if (!(_draggedScroll != null))
				{
					return _scrolls.Any((ScrollView x) => ((Component)x.Viewport).gameObject.activeInHierarchy && InActiveLayer((Transform)(object)x.Viewport) && (PointerVisible(x.Viewport) || ((Object)(object)x.Track != (Object)null && PointerVisible(x.Track))));
				}
				return true;
			}
		}

		public bool WantsInputFocus
		{
			get
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				if (!ReviewOpen && !DetailsOpen && !_dismissPointerClick && !_dragging && !((Object)(object)_pressedButton != (Object)null) && !(_draggedScroll != null) && (Input.mouseScrollDelta.y == 0f || !_scrolls.Any((ScrollView x) => ((Component)x.Viewport).gameObject.activeInHierarchy && ContainsPointer(x.Viewport))))
				{
					if (Input.GetMouseButton(0) && _meter.activeInHierarchy)
					{
						if (!ContainsPointer(_openButton) && !ContainsPointer(_lockButton) && (_runtime.Locked.Value || !ContainsPointer(_header)))
						{
							return _meterRows.Any((Row x) => x.Selection != null && PointerVisible(x.Root.GetComponent<RectTransform>()));
						}
						return true;
					}
					return false;
				}
				return true;
			}
		}

		private static bool ContainsPointer(RectTransform rect)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			Canvas componentInParent = ((Component)rect).GetComponentInParent<Canvas>();
			Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
			return RectTransformUtility.RectangleContainsScreenPoint(rect, Vector2.op_Implicit(Input.mousePosition), val);
		}

		private static bool PointerVisible(RectTransform rect)
		{
			if (!((Component)rect).gameObject.activeInHierarchy || !ContainsPointer(rect))
			{
				return false;
			}
			Transform parent = ((Transform)rect).parent;
			while ((Object)(object)parent != (Object)null)
			{
				if ((Object)(object)((Component)parent).GetComponent<RectMask2D>() != (Object)null && !ContainsPointer(((Il2CppObjectBase)parent).Cast<RectTransform>()))
				{
					return false;
				}
				parent = parent.parent;
			}
			return true;
		}

		public NativeHud(ClientRuntime runtime, UICanvasBase canvas)
		{
			//IL_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ca: 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_07e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0450: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d22: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d51: Unknown result type (might be due to invalid IL or missing references)
			//IL_0df5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e39: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e40: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e4a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e57: Unknown result type (might be due to invalid IL or missing references)
			_runtime = runtime;
			TextMeshProUGUI val = ((IEnumerable<TextMeshProUGUI>)((Component)canvas.HUDParent).GetComponentsInChildren<TextMeshProUGUI>(true)).FirstOrDefault((Func<TextMeshProUGUI, bool>)((TextMeshProUGUI x) => (Object)(object)((TMP_Text)x).font != (Object)null)) ?? throw new InvalidOperationException("Native HUD font is not available yet");
			_font = ((TMP_Text)val).font;
			_fontMaterial = OutlinedFont(((TMP_Text)val).fontSharedMaterial);
			runtime.LogStyle($"Text outline: {((Object)_fontMaterial.shader).name}; supported={_fontMaterial.HasProperty("_OutlineWidth")}");
			FakeTooltip componentInChildren = ((Component)canvas.TooltipsParent).GetComponentInChildren<FakeTooltip>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				_tooltip = Object.Instantiate<FakeTooltip>(componentInChildren, (Transform)(object)canvas.TooltipsParent, false);
				((Object)_tooltip).name = "CombatMeter Tooltip";
				_tooltip.UseAdditionalTooltip = false;
				_tooltip.ClampWithinRect = ((Il2CppObjectBase)((Component)canvas).transform).Cast<RectTransform>();
				foreach (Graphic componentsInChild in ((Component)_tooltip).GetComponentsInChildren<Graphic>(true))
				{
					componentsInChild.raycastTarget = false;
				}
				foreach (TextMeshProUGUI componentsInChild2 in ((Component)_tooltip).GetComponentsInChildren<TextMeshProUGUI>(true))
				{
					((TMP_Text)componentsInChild2).richText = true;
					if ((Object)(object)((TMP_Text)componentsInChild2).font != (Object)null && (Object)(object)((TMP_Text)componentsInChild2).fontSharedMaterial != (Object)null)
					{
						((TMP_Text)componentsInChild2).fontSharedMaterial = OutlinedFont(((TMP_Text)componentsInChild2).fontSharedMaterial);
						((TMP_Text)componentsInChild2).UpdateMeshPadding();
					}
				}
				_tooltip.DisableTooltip();
			}
			Il2CppArrayBase<Image> source = (((Object)(object)canvas.ArenaSummaryParentPrefab != (Object)null) ? ((Component)canvas.ArenaSummaryParentPrefab).GetComponentsInChildren<Image>(true) : ((Component)canvas.HUDParent).GetComponentsInChildren<Image>(true));
			Image? obj = ((IEnumerable<Image>)source).FirstOrDefault((Func<Image, bool>)((Image x) => (Object)(object)x.sprite != (Object)null && ((Object)x).name.Contains("Fill", StringComparison.OrdinalIgnoreCase)));
			_barSprite = ((obj != null) ? obj.sprite : null);
			List<Image> list = new List<Image>();
			Enumerator<HUDMenuMapping> enumerator3 = canvas.HUDMenus.GetEnumerator();
			while (enumerator3.MoveNext())
			{
				HUDMenuMapping current2 = enumerator3.Current;
				if ((Object)(object)current2.Prefab != (Object)null)
				{
					list.AddRange((IEnumerable<Image>)((Component)current2.Prefab).GetComponentsInChildren<Image>(true));
				}
			}
			_windowTemplate = ((IEnumerable<Image>)list).FirstOrDefault((Func<Image, bool>)((Image x) => (Object)(object)x.sprite != (Object)null && ((Object)x.sprite).name == "Window_Background"));
			_windowHeaderTemplate = ((IEnumerable<Image>)list).FirstOrDefault((Func<Image, bool>)((Image x) => (Object)(object)x.sprite != (Object)null && ((Object)x.sprite).name == "Window_Background_Header"));
			Image? windowTemplate = _windowTemplate;
			object obj2;
			if (windowTemplate == null)
			{
				obj2 = null;
			}
			else
			{
				Sprite sprite = windowTemplate.sprite;
				obj2 = ((sprite != null) ? ((Object)sprite).name : null);
			}
			if (obj2 == null)
			{
				obj2 = "solid fallback";
			}
			Image? windowHeaderTemplate = _windowHeaderTemplate;
			object obj3;
			if (windowHeaderTemplate == null)
			{
				obj3 = null;
			}
			else
			{
				Sprite sprite2 = windowHeaderTemplate.sprite;
				obj3 = ((sprite2 != null) ? ((Object)sprite2).name : null);
			}
			if (obj3 == null)
			{
				obj3 = "none";
			}
			runtime.LogStyle("Native window: " + (string?)obj2 + "; header: " + (string?)obj3);
			if ((Object)(object)_windowTemplate != (Object)null)
			{
				Sprite sprite3 = _windowTemplate.sprite;
				Rect textureRect = sprite3.textureRect;
				Vector4 border = sprite3.border;
				Vector4 padding = DataUtility.GetPadding(sprite3);
				if (Mathf.Approximately(((Rect)(ref textureRect)).height, 241f) && Mathf.Approximately(border.y, 100f))
				{
					((Rect)(ref textureRect)).y = ((Rect)(ref textureRect)).y + 52f;
					((Rect)(ref textureRect)).height = ((Rect)(ref textureRect)).height - 52f;
					((Vector4)(ref border))..ctor(Math.Max(0f, border.x - padding.x), border.y - 52f, Math.Max(0f, border.z - padding.z), Math.Max(0f, border.w - padding.w));
					_trimmedWindowSprite = Sprite.Create(sprite3.texture, textureRect, new Vector2(0.5f, 0.5f), sprite3.pixelsPerUnit, 0u, (SpriteMeshType)0, border);
					((Object)_trimmedWindowSprite).name = "CombatMeter Native Window (trimmed)";
				}
			}
			_icons = new HudIcons();
			_meter = Panel("CombatMeter HUD", (Transform)(object)canvas.HUDParent, 320f, 136f, new Color(0.055f, 0.045f, 0.055f, 0f), decorate: false);
			_meterRect = _meter.GetComponent<RectTransform>();
			RectTransform meterRect = _meterRect;
			RectTransform meterRect2 = _meterRect;
			RectTransform meterRect3 = _meterRect;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(1f, 1f);
			meterRect3.pivot = val2;
			meterRect.anchorMin = (meterRect2.anchorMax = val2);
			_meterBackground = _meter.GetComponent<Image>();
			_header = Box("Drag strip", _meter.transform, 32f, 2f, 256f, 26f);
			Image obj4 = ((Component)_header).gameObject.AddComponent<Image>();
			((Graphic)obj4).color = Color.clear;
			((Graphic)obj4).raycastTarget = false;
			_meterDetail = Text((Transform)(object)_header, "Waiting for a fight", 2f, 0f, 252f, 26f, 12f);
			_meterContent = Scroll(_meter.transform, 6f, 32f, 308f, 96f, showScrollbar: false);
			_openButton = ((Component)Button(_meter.transform, "", 6f, 5f, 20f, 20f, ToggleReview, showBackground: false).Button).GetComponent<RectTransform>();
			_cogIcon = AddIcon(_openButton, _icons.Cog);
			_lockButton = ((Component)Button(_meter.transform, "", 294f, 5f, 20f, 20f, ToggleLock, showBackground: false).Button).GetComponent<RectTransform>();
			_lockIcon = AddIcon(_lockButton, _icons.Unlocked);
			((Component)_openButton).gameObject.SetActive(false);
			((Component)_lockButton).gameObject.SetActive(false);
			_tooltips.Add((_openButton, "CombatMeter", "Review this fight, recent encounters, and display settings. The shortcut is configurable in the client config."));
			_tooltips.Add((_lockButton, "Lock meter position", "Click to lock or unlock dragging. A closed padlock means the meter position is locked."));
			_tooltips.Add((_header, "Move CombatMeter", "Drag this header to move the meter. Position is saved when you release the mouse. Lock the position in Review / settings."));
			_review = Panel("CombatMeter Review", (Transform)(object)canvas.HUDParent, 830f, 760f, new Color(0.05f, 0.04f, 0.055f, 0.98f));
			RectTransform component = _review.GetComponent<RectTransform>();
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			component.pivot = val2;
			component.anchorMin = (component.anchorMax = val2);
			component.anchoredPosition = Vector2.zero;
			_reviewTitle = Text(_review.transform, "CombatMeter", 48f, 64f, 632f, 34f, 24f);
			Button(_review.transform, "Close", 698f, 64f, 84f, 28f, CloseReview);
			_reviewDetail = Text(_review.transform, "", 48f, 110f, 734f, 24f, 14f);
			(Button, TextMeshProUGUI) tuple = Button(_review.transform, "", 48f, 148f, 170f, 30f, delegate
			{
				_runtime.ShowEnemies.Value = !_runtime.ShowEnemies.Value;
				Refresh();
			});
			_enemyLabel = tuple.Item2;
			(Button, TextMeshProUGUI) tuple2 = Button(_review.transform, "", 228f, 148f, 210f, 30f, CycleFilter);
			_filterLabel = tuple2.Item2;
			_tooltips.Add((((Component)tuple.Item1).GetComponent<RectTransform>(), "Enemy damage", "Show damage dealt by monsters, bosses, and boss summons to players. Enemy totals are separate from player damage and shares."));
			_tooltips.Add((((Component)tuple2.Item1).GetComponent<RectTransform>(), "Boss targets", "Switch between damage to the boss alone and damage to the boss plus its owned summons. Unrelated nearby enemies are excluded."));
			Text(_review.transform, "ENCOUNTERS", 48f, 194f, 204f, 22f, 14f);
			Text(_review.transform, "DAMAGE · DPS", 292f, 194f, 474f, 22f, 14f);
			RectTransform val5 = (_historyContent = Scroll(_review.transform, 48f, 220f, 204f, 252f));
			for (int num = 0; num < 21; num++)
			{
				int index = num;
				_historyButtons.Add(Button((Transform)(object)val5, "", 0f, num * 36, 204f, 30f, delegate
				{
					SelectHistory(index);
				}));
			}
			val5.sizeDelta = new Vector2(204f, 756f);
			_reviewContent = Scroll(_review.transform, 292f, 220f, 474f, 252f);
			Text(_review.transform, "DISPLAY SETTINGS", 48f, 500f, 734f, 24f, 14f);
			_visibleLabel = Button(_review.transform, "", 48f, 536f, 122f, 30f, delegate
			{
				_runtime.Visible.Value = !_runtime.Visible.Value;
				Refresh();
			}).Text;
			_lockLabel = Button(_review.transform, "", 178f, 536f, 124f, 30f, ToggleLock).Text;
			Button(_review.transform, "Scale −", 310f, 536f, 96f, 30f, delegate
			{
				_runtime.Scale.Value = Math.Max(0.6f, _runtime.Scale.Value - 0.1f);
				Refresh();
			});
			Button(_review.transform, "Scale +", 414f, 536f, 96f, 30f, delegate
			{
				_runtime.Scale.Value = Math.Min(2f, _runtime.Scale.Value + 0.1f);
				Refresh();
			});
			(Button, TextMeshProUGUI) tuple3 = Button(_review.transform, "BG opacity −", 518f, 536f, 128f, 30f, delegate
			{
				_runtime.BackgroundOpacity.Value = Math.Max(0f, _runtime.BackgroundOpacity.Value - 0.1f);
				Refresh();
			});
			(Button, TextMeshProUGUI) tuple4 = Button(_review.transform, "BG opacity +", 654f, 536f, 128f, 30f, delegate
			{
				_runtime.BackgroundOpacity.Value = Math.Min(1f, _runtime.BackgroundOpacity.Value + 0.1f);
				Refresh();
			});
			_tooltips.Add((((Component)tuple3.Item1).GetComponent<RectTransform>(), "DPS list background", "Reduce background opacity. At zero the background is fully transparent; text, bars and icons remain visible."));
			_tooltips.Add((((Component)tuple4.Item1).GetComponent<RectTransform>(), "DPS list background", "Increase background opacity. This only affects the DPS list background."));
			EncounterKind[] values = Enum.GetValues<EncounterKind>();
			for (int num2 = 0; num2 < values.Length; num2++)
			{
				EncounterKind mode = values[num2];
				(Button, TextMeshProUGUI) tuple5 = Button(_review.transform, "", 48f + (float)(num2 * 148), 582f, 140f, 32f, delegate
				{
					//IL_0011: 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)
					_runtime.Modes[mode].Value = !_runtime.Modes[mode].Value;
					Refresh();
				});
				_modeButtons.Add((tuple5.Item1, tuple5.Item2, mode));
				_tooltips.Add((((Component)tuple5.Item1).GetComponent<RectTransform>(), $"{mode} visibility", "Controls display only. If the label says 'server off', tracking is disabled in the server's CombatMeter config. Enable that mode under [Tracking] and restart the server. 'Waiting' means server policy has not arrived yet."));
			}
			Text(_review.transform, "Session history · Drag the unlocked HUD to move it.", 48f, 654f, 734f, 24f, 13f);
			_review.SetActive(false);
			_details = Panel("CombatMeter Damage Sources", (Transform)(object)canvas.HUDParent, 650f, 560f, new Color(0.05f, 0.04f, 0.055f, 0.98f));
			_detailRect = _details.GetComponent<RectTransform>();
			RectTransform detailRect = _detailRect;
			RectTransform detailRect2 = _detailRect;
			RectTransform detailRect3 = _detailRect;
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			detailRect3.pivot = val2;
			detailRect.anchorMin = (detailRect2.anchorMax = val2);
			_detailRect.anchoredPosition = Vector2.zero;
			_detailHeader = Box("Detail drag strip", _details.transform, 48f, 60f, 460f, 46f);
			_detailTitle = Text((Transform)(object)_detailHeader, "Damage sources", 0f, 4f, 450f, 34f, 22f);
			Button(_details.transform, "Close", 524f, 64f, 78f, 28f, CloseDetails);
			_detailSubtitle = Text(_details.transform, "", 48f, 110f, 554f, 24f, 14f);
			_detailFilter = Button(_details.transform, "", 48f, 146f, 210f, 28f, CycleFilter);
			((TMP_Text)Text(_details.transform, "DAMAGE · SHARE", 428f, 148f, 150f, 24f, 13f)).alignment = (TextAlignmentOptions)4100;
			_detailContent = Scroll(_details.transform, 48f, 192f, 538f, 270f);
			_detailMessage = Text(_details.transform, "", 56f, 208f, 530f, 54f, 16f);
			_details.SetActive(false);
			Refresh();
		}

		private RectTransform Box(string name, Transform parent, float x, float y, float width, float height)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			RectTransform obj = new GameObject(name).AddComponent<RectTransform>();
			((Transform)obj).SetParent(parent, false);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			obj.pivot = val;
			Vector2 anchorMin = (obj.anchorMax = val);
			obj.anchorMin = anchorMin;
			obj.anchoredPosition = new Vector2(x, 0f - y);
			obj.sizeDelta = new Vector2(width, height);
			return obj;
		}

		private Image AddIcon(RectTransform button, Sprite sprite)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)Box(((Object)sprite).name, (Transform)(object)button, 2f, 2f, 16f, 16f)).gameObject.AddComponent<Image>();
			obj.sprite = sprite;
			obj.preserveAspect = true;
			((Graphic)obj).color = new Color(0.9f, 0.86f, 0.79f);
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private GameObject Panel(string name, Transform parent, float width, float height, Color color, bool decorate = true)
		{
			//IL_0023: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Box(name, parent, 0f, 0f, width, height);
			Image val2 = ((Component)val).gameObject.AddComponent<Image>();
			((Graphic)val2).color = color;
			((Graphic)val2).raycastTarget = false;
			if (decorate && (Object)(object)_windowTemplate != (Object)null)
			{
				((Graphic)val2).color = Color.clear;
				Image obj = ((Component)Box("Window backing", (Transform)(object)val, 20f, 20f, width - 40f, height - 40f)).gameObject.AddComponent<Image>();
				((Graphic)obj).color = new Color(0.025f, 0.028f, 0.032f, 0.98f);
				((Graphic)obj).raycastTarget = false;
				CopyWindowImage(_windowTemplate, (Transform)(object)val, "Native window frame", 8f, 8f, width - 16f, height - 16f);
				if ((Object)(object)_windowHeaderTemplate != (Object)null)
				{
					CopyWindowImage(_windowHeaderTemplate, (Transform)(object)val, "Native window header", 20f, 12f, width - 40f, 48f);
				}
			}
			return ((Component)val).gameObject;
		}

		private void CopyWindowImage(Image template, Transform parent, string name, float x, float y, float width, float height)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)Box(name, parent, x, y, width, height)).gameObject.AddComponent<Image>();
			obj.sprite = (Sprite)(((Object)(object)template == (Object)(object)_windowTemplate && (Object)(object)_trimmedWindowSprite != (Object)null) ? ((object)_trimmedWindowSprite) : ((object)template.sprite));
			((Graphic)obj).material = ((Graphic)template).material;
			obj.type = template.type;
			((Graphic)obj).color = ((Graphic)template).color;
			obj.pixelsPerUnitMultiplier = template.pixelsPerUnitMultiplier;
			obj.fillCenter = template.fillCenter;
			((Graphic)obj).raycastTarget = false;
		}

		private Material OutlinedFont(Material source)
		{
			//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)
			//IL_0036: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)source).GetInstanceID();
			if (_outlinedFonts.TryGetValue(instanceID, out Material value))
			{
				return value;
			}
			Material val = new Material(source)
			{
				name = ((Object)source).name + " (CombatMeter outline)"
			};
			_outlinedFonts[instanceID] = val;
			if (val.HasProperty("_OutlineColor") && val.HasProperty("_OutlineWidth"))
			{
				val.SetColor("_OutlineColor", new Color(0.008f, 0.006f, 0.009f, 1f));
				val.SetFloat("_OutlineWidth", 0.16f);
				if (val.HasProperty("_OutlineSoftness"))
				{
					val.SetFloat("_OutlineSoftness", 0.06f);
				}
				if (val.HasProperty("_Sharpness"))
				{
					val.SetFloat("_Sharpness", 0f);
				}
				val.EnableKeyword("OUTLINE_ON");
				ShaderUtilities.UpdateShaderRatios(val);
			}
			return val;
		}

		private TextMeshProUGUI Text(Transform parent, string value, float x, float y, float width, float height, float size)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)Box("Text", parent, x, y, width, height)).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = _font;
			((TMP_Text)obj).fontSharedMaterial = _fontMaterial;
			((TMP_Text)obj).fontSize = size * 1.2f;
			((Graphic)obj).color = new Color(0.97f, 0.94f, 0.88f);
			((TMP_Text)obj).richText = false;
			((Graphic)obj).raycastTarget = false;
			((TMP_Text)obj).enableWordWrapping = false;
			((TMP_Text)obj).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)obj).overflowMode = (TextOverflowModes)1;
			((TMP_Text)obj).text = value;
			((TMP_Text)obj).UpdateMeshPadding();
			return obj;
		}

		private (Button Button, TextMeshProUGUI Text) Button(Transform parent, string label, float x, float y, float width, float height, Action action, bool showBackground = true)
		{
			//IL_002c: 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)
			RectTransform val = Box("Button", parent, x, y, width, height);
			Image val2 = ((Component)val).gameObject.AddComponent<Image>();
			((Graphic)val2).color = (showBackground ? ButtonRed : Color.clear);
			Button val3 = ((Component)val).gameObject.AddComponent<Button>();
			((Selectable)val3).targetGraphic = (Graphic)(object)val2;
			if (!showBackground)
			{
				((Selectable)val3).transition = (Transition)0;
			}
			_buttons.Add((val3, action));
			TextMeshProUGUI val4 = Text((Transform)(object)val, label, 4f, 2f, width - 8f, height - 4f, 13f);
			((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val4).enableAutoSizing = true;
			((TMP_Text)val4).fontSizeMin = 14f;
			((TMP_Text)val4).fontSizeMax = 15.6f;
			return (Button: val3, Text: val4);
		}

		private RectTransform Scroll(Transform parent, float x, float y, float width, float height, bool showScrollbar = true)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Box("Scroll view", parent, x, y, width + (showScrollbar ? 16f : 0f), height);
			RectTransform val2 = Box("Viewport", (Transform)(object)val, 0f, 0f, width, height);
			Image obj = ((Component)val2).gameObject.AddComponent<Image>();
			((Graphic)obj).color = Color.white;
			((Graphic)obj).raycastTarget = false;
			((Component)val2).gameObject.AddComponent<Mask>().showMaskGraphic = false;
			((Component)val2).gameObject.AddComponent<RectMask2D>();
			RectTransform val3 = Box("Content", (Transform)(object)val2, 0f, 0f, width, height);
			ScrollRect val4 = ((Component)val).gameObject.AddComponent<ScrollRect>();
			val4.viewport = val2;
			val4.content = val3;
			val4.horizontal = false;
			val4.vertical = true;
			val4.movementType = (MovementType)2;
			val4.scrollSensitivity = 22f;
			((Behaviour)val4).enabled = false;
			RectTransform val5 = null;
			RectTransform val6 = null;
			if (showScrollbar)
			{
				val5 = Box("Scrollbar track", (Transform)(object)val, width + 4f, 0f, 12f, height);
				Image obj2 = ((Component)val5).gameObject.AddComponent<Image>();
				((Graphic)obj2).color = new Color(0.15f, 0.14f, 0.15f, 1f);
				((Graphic)obj2).raycastTarget = false;
				val6 = Box("Scrollbar thumb", (Transform)(object)val5, 2f, 0f, 8f, height);
				Image obj3 = ((Component)val6).gameObject.AddComponent<Image>();
				((Graphic)obj3).color = new Color(0.64f, 0.59f, 0.49f, 1f);
				((Graphic)obj3).raycastTarget = false;
				((Component)val5).gameObject.SetActive(false);
			}
			_scrolls.Add(new ScrollView(val2, val3, val4, val5, val6));
			return val3;
		}

		private static ScrollGeometry Geometry(ScrollView view)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = view.Content.rect;
			float height = ((Rect)(ref rect)).height;
			rect = view.Viewport.rect;
			return ScrollGeometry.Calculate(height, ((Rect)(ref rect)).height, view.Content.anchoredPosition.y);
		}

		private void RefreshScrollbars()
		{
			//IL_0026: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			foreach (ScrollView scroll in _scrolls)
			{
				ScrollGeometry scrollGeometry = Geometry(scroll);
				Vector2 anchoredPosition = scroll.Content.anchoredPosition;
				anchoredPosition.y = Mathf.Clamp(anchoredPosition.y, 0f, scrollGeometry.Range);
				scroll.Content.anchoredPosition = anchoredPosition;
				if (!((Object)(object)scroll.Track == (Object)null) && !((Object)(object)scroll.Thumb == (Object)null))
				{
					((Component)scroll.Track).gameObject.SetActive(scrollGeometry.CanScroll);
					scroll.Thumb.sizeDelta = new Vector2(8f, scrollGeometry.ThumbHeight);
					scroll.Thumb.anchoredPosition = new Vector2(2f, 0f - scrollGeometry.ThumbTop);
					((Graphic)((Component)scroll.Thumb).GetComponent<Image>()).color = ((scroll == _draggedScroll || PointerVisible(scroll.Track)) ? new Color(0.94f, 0.85f, 0.65f, 1f) : new Color(0.64f, 0.59f, 0.49f, 1f));
				}
			}
		}

		private static float TrackPointer(RectTransform track)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Canvas componentInParent = ((Component)track).GetComponentInParent<Canvas>();
			Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
			Vector2 val2 = default(Vector2);
			RectTransformUtility.ScreenPointToLocalPointInRectangle(track, Vector2.op_Implicit(Input.mousePosition), val, ref val2);
			return 0f - val2.y;
		}

		private Row CreateRow(Transform parent, float width, bool interactive = true, bool compact = false)
		{
			RectTransform val = Box("Player", parent, 0f, 0f, width, compact ? 24 : 28);
			Image val2 = ((Component)Box("Damage bar", (Transform)(object)val, 0f, 1f, width, compact ? 22 : 26)).gameObject.AddComponent<Image>();
			val2.sprite = _barSprite;
			val2.type = (Type)1;
			((Graphic)val2).raycastTarget = false;
			TextMeshProUGUI name = Text((Transform)(object)val, "", 6f, compact ? 1 : 2, width * 0.6f, compact ? 22 : 25, compact ? 12 : 13);
			TextMeshProUGUI val3 = Text((Transform)(object)val, "", width * 0.62f, compact ? 1 : 2, width * 0.36f, compact ? 22 : 25, compact ? 12 : 13);
			((TMP_Text)val3).alignment = (TextAlignmentOptions)4100;
			Row row = new Row(((Component)val).gameObject, val2, name, val3);
			if (interactive)
			{
				Button val4 = ((Component)val).gameObject.AddComponent<Button>();
				((Selectable)val4).targetGraphic = (Graphic)(object)val2;
				((Selectable)val4).transition = (Transition)0;
				_buttons.Add((val4, delegate
				{
					DetailSelection selection = row.Selection;
					if (selection != null)
					{
						OpenDetails(selection, row.ActorName, row.EncounterLabel);
					}
				}));
			}
			return row;
		}

		private void RenderRows(List<Row> rows, RectTransform content, EncounterSnapshot? fight, float width, bool compact = false)
		{
			//IL_000f: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: 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_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: 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_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			MeterRow[] array = ((fight == null) ? Array.Empty<MeterRow>() : MeterPresentation.Players(fight, _runtime.Filter.Value));
			MeterRow[] array2 = ((fight == null || !_runtime.ShowEnemies.Value) ? Array.Empty<MeterRow>() : MeterPresentation.Enemies(fight));
			int num = array.Length + array2.Length;
			while (rows.Count < num)
			{
				rows.Add(CreateRow((Transform)(object)content, width, interactive: true, compact));
			}
			float num2 = (compact ? 24f : 30f);
			double num3 = DamagePresentation.BarMaximum(array, array2);
			Color color = default(Color);
			for (int i = 0; i < rows.Count; i++)
			{
				Row row = rows[i];
				row.Root.SetActive(i < num);
				if (i < num)
				{
					row.Root.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, (float)(-i) * num2);
					bool flag = i >= array.Length;
					int num4 = (flag ? (i - array.Length) : i);
					MeterRow val = (flag ? array2[num4] : array[num4]);
					row.Selection = ((fight == null || (val.PlayerId == 0L && val.CreatureId.Length == 0)) ? ((DetailSelection)null) : new DetailSelection(fight.Id, (DetailActorKind)(flag ? 1 : 0), val.PlayerId, val.CreatureId));
					row.ActorName = val.Name;
					row.EncounterLabel = ((fight != null) ? fight.Label : null) ?? "";
					((Selectable)row.Root.GetComponent<Button>()).interactable = row.Selection != null;
					((Graphic)row.Bar).rectTransform.sizeDelta = new Vector2((num3 > 0.0) ? (width * (float)(val.Damage / num3)) : 0f, (float)(compact ? 22 : 26));
					Image bar = row.Bar;
					if (flag)
					{
						((Color)(ref color))..ctor(0.49f, 0.33f, 0.12f, 0.8f);
					}
					else
					{
						color = (Color)(val.Team switch
						{
							1 => new Color(0.55f, 0.18f, 0.22f, 0.8f), 
							2 => new Color(0.16f, 0.33f, 0.52f, 0.8f), 
							3 => new Color(0.2f, 0.42f, 0.3f, 0.8f), 
							4 => new Color(0.44f, 0.24f, 0.5f, 0.8f), 
							_ => new Color(0.48f, 0.2f, 0.23f, 0.8f), 
						});
					}
					((Graphic)bar).color = color;
					((TMP_Text)row.Name).text = $"{num4 + 1}. {((val.Team > 0) ? $"[{val.Team}] " : "")}{val.Name}";
					((TMP_Text)row.Value).text = MeterPresentation.Values(val);
					float num5 = Mathf.Clamp(((TMP_Text)row.Value).GetPreferredValues(((TMP_Text)row.Value).text).x + 8f, 90f, width * 0.55f);
					((TMP_Text)row.Value).rectTransform.anchoredPosition = new Vector2(width - num5 - 4f, (float)(compact ? (-1) : (-2)));
					((TMP_Text)row.Value).rectTransform.sizeDelta = new Vector2(num5, (float)(compact ? 22 : 25));
					((TMP_Text)row.Name).rectTransform.sizeDelta = new Vector2(width - num5 - 16f, (float)(compact ? 22 : 25));
				}
			}
			content.sizeDelta = new Vector2(width, Math.Max(1f, (float)num * num2));
			RefreshScrollbars();
		}

		private EncounterSnapshot[] Encounters()
		{
			return (from x in _runtime.State.Active.OrderByDescending((EncounterSnapshot x) => x.StartedAt).Concat(_runtime.State.History)
				where _runtime.Modes[x.Kind].Value
				select x).ToArray();
		}

		public unsafe void Refresh()
		{
			//IL_003e: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Invalid comparison between Unknown and I4
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Invalid comparison between Unknown and I4
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0557: Invalid comparison between Unknown and I4
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
			if (!IsAlive)
			{
				return;
			}
			EncounterSnapshot[] array = Encounters();
			EncounterSnapshot val = array.FirstOrDefault();
			_meter.SetActive(_runtime.Visible.Value);
			RefreshHudControls();
			Color color = ((Graphic)_meterBackground).color;
			color.a = _runtime.BackgroundOpacity.Value;
			((Graphic)_meterBackground).color = color;
			((Transform)_meterRect).localScale = Vector3.one * _runtime.Scale.Value;
			if (!_dragging)
			{
				_meterRect.anchoredPosition = new Vector2(_runtime.OffsetX.Value, _runtime.OffsetY.Value);
			}
			((TMP_Text)_meterDetail).text = ((val == null) ? _runtime.State.StatusMessage : $"{val.Label} · {TimeSpan.FromSeconds(val.DurationSeconds):mm\\:ss}");
			RenderRows(_meterRows, _meterContent, val, 308f, compact: true);
			RefreshDetails();
			if (!ReviewOpen)
			{
				return;
			}
			RectTransform val2 = ((Il2CppObjectBase)_review.transform.parent).Cast<RectTransform>();
			Transform transform = _review.transform;
			Vector3 one = Vector3.one;
			Rect rect = val2.rect;
			float val3 = ((Rect)(ref rect)).width / 862f;
			rect = val2.rect;
			transform.localScale = one * Math.Min(1f, Math.Min(val3, ((Rect)(ref rect)).height / 792f));
			EncounterSnapshot val4 = ((IEnumerable<EncounterSnapshot>)array).FirstOrDefault((Func<EncounterSnapshot, bool>)((EncounterSnapshot x) => x.Id == _selectedEncounter)) ?? val;
			((TMP_Text)_reviewTitle).text = "CombatMeter";
			((TMP_Text)_reviewDetail).text = ((val4 == null) ? _runtime.State.StatusMessage : $"{val4.Label} · {val4.Players.Length} {((val4.Players.Length == 1) ? "player" : "players")} · {val4.DurationSeconds:N1}s");
			RenderRows(_reviewRows, _reviewContent, val4, 474f);
			((TMP_Text)_enemyLabel).text = (_runtime.ShowEnemies.Value ? "Enemies: shown" : "Enemies: hidden");
			((Component)((TMP_Text)_filterLabel).transform.parent).gameObject.SetActive(val4 != null && (int)val4.Kind == 0);
			((TMP_Text)_filterLabel).text = (((int)_runtime.Filter.Value == 1) ? "Targets: boss only" : "Targets: boss + summons");
			((TMP_Text)_visibleLabel).text = (_runtime.Visible.Value ? "HUD: shown" : "HUD: hidden");
			((TMP_Text)_lockLabel).text = (_runtime.Locked.Value ? "Position: locked" : "Position: unlocked");
			while (_historyButtons.Count < array.Length)
			{
				int index = _historyButtons.Count;
				_historyButtons.Add(Button((Transform)(object)_historyContent, "", 0f, index * 36, 204f, 30f, delegate
				{
					SelectHistory(index);
				}));
			}
			_historyContent.sizeDelta = new Vector2(204f, (float)Math.Max(1, array.Length * 36 - 6));
			for (int num = 0; num < _historyButtons.Count; num++)
			{
				(Button, TextMeshProUGUI) tuple = _historyButtons[num];
				((Component)tuple.Item1).gameObject.SetActive(num < array.Length);
				if (num < array.Length)
				{
					((TMP_Text)tuple.Item2).text = $"{array[num].Label} · {array[num].DurationSeconds:N0}s";
					((Selectable)tuple.Item1).targetGraphic.color = ((array[num].Id == ((val4 != null) ? val4.Id : null)) ? SelectedButtonRed : ButtonRed);
				}
			}
			foreach (var modeButton in _modeButtons)
			{
				PolicyPacket policy = _runtime.State.Policy;
				bool flag = policy != null && policy.EnabledModes.Contains(modeButton.Kind);
				((Selectable)modeButton.Button).interactable = flag;
				object obj;
				if ((int)modeButton.Kind != 4)
				{
					EncounterKind item = modeButton.Kind;
					obj = ((object)(*(EncounterKind*)(&item))/*cast due to .constrained prefix*/).ToString();
				}
				else
				{
					obj = "World";
				}
				string text = (string)obj;
				((TMP_Text)modeButton.Text).text = ((_runtime.State.Policy == null) ? (text + ": waiting") : (flag ? (text + ": " + (_runtime.Modes[modeButton.Kind].Value ? "shown" : "hidden")) : (text + ": server off")));
			}
			RefreshScrollbars();
		}

		private void SelectHistory(int index)
		{
			EncounterSnapshot[] array = Encounters();
			if (index < array.Length)
			{
				_selectedEncounter = array[index].Id;
			}
			Refresh();
		}

		private void CycleFilter()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			_runtime.Filter.Value = (BossTargetFilter)((int)_runtime.Filter.Value != 1);
			Refresh();
		}

		private void ToggleLock()
		{
			_runtime.Locked.Value = !_runtime.Locked.Value;
			_dragging = false;
			Refresh();
		}

		private void RefreshHudControls()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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)
			bool flag = _meter.activeInHierarchy && !ReviewOpen && !DetailsOpen && ContainsPointer(_meterRect);
			((Component)_openButton).gameObject.SetActive(flag);
			((Component)_lockButton).gameObject.SetActive(flag);
			((TMP_Text)_meterDetail).rectTransform.anchoredPosition = new Vector2((float)(flag ? 2 : (-24)), 0f);
			((TMP_Text)_meterDetail).rectTransform.sizeDelta = new Vector2(flag ? 252f : 304f, 26f);
			_lockIcon.sprite = (_runtime.Locked.Value ? _icons.Locked : _icons.Unlocked);
			Color val = default(Color);
			((Color)(ref val))..ctor(0.82f, 0.79f, 0.72f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0.9f, 0.66f);
			((Graphic)_cogIcon).color = ((flag && ContainsPointer(_openButton)) ? val2 : val);
			((Graphic)_lockIcon).color = ((_runtime.Locked.Value || (flag && ContainsPointer(_lockButton))) ? val2 : val);
		}

		private void OpenDetails(DetailSelection selection, string name, string label)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			_pinned = selection;
			((TMP_Text)_detailTitle).text = name;
			((TMP_Text)_detailSubtitle).text = label;
			_details.SetActive(true);
			_details.transform.SetAsLastSibling();
			_detailContent.anchoredPosition = Vector2.zero;
			_keyboardButton = -1;
			_dragging = false;
			FakeTooltip? tooltip = _tooltip;
			if (tooltip != null)
			{
				tooltip.DisableTooltip();
			}
			_tooltipText = null;
			_runtime.Inspect(selection);
			RefreshDetails();
		}

		public void CloseDetails()
		{
			_pinned = null;
			_detailDragging = false;
			_pressedButton = null;
			_pressedActor = null;
			_draggedScroll = null;
			if ((Object)(object)_details != (Object)null)
			{
				_details.SetActive(false);
			}
			_runtime.Inspect(null);
			_hoverKey = null;
			_keyboardButton = -1;
			_tooltipText = null;
		}

		public void RefreshDetails()
		{
			//IL_0020: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Invalid comparison between Unknown and I4
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Invalid comparison between Unknown and I4
			//IL_0287: 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_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0593: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			if (!DetailsOpen)
			{
				return;
			}
			RectTransform val = ((Il2CppObjectBase)((Transform)_detailRect).parent).Cast<RectTransform>();
			RectTransform detailRect = _detailRect;
			Vector3 one = Vector3.one;
			Rect rect = val.rect;
			float val2 = ((Rect)(ref rect)).width / 682f;
			rect = val.rect;
			((Transform)detailRect).localScale = one * Math.Min(1f, Math.Min(val2, ((Rect)(ref rect)).height / 592f));
			ClampDetailPosition();
			SourceResponsePacket current = _runtime.Details.Current;
			SourceRow[] array = (SourceRow[])((current != null && current.Available) ? ((Array)DamagePresentation.Sources(current, _runtime.Filter.Value)) : ((Array)Array.Empty<SourceRow>()));
			((TMP_Text)_detailMessage).text = ((current != null && current.Available && array.Length == 0) ? "No damage recorded for these targets" : _runtime.Details.Message);
			((Component)_detailMessage).gameObject.SetActive(array.Length == 0);
			if (current != null && current.Available)
			{
				((TMP_Text)_detailTitle).text = current.ActorName;
				((TMP_Text)_detailSubtitle).text = $"{current.EncounterLabel} · {current.DurationSeconds:N1}s";
			}
			((Component)_detailFilter.Button).gameObject.SetActive(current != null && current.Available && (int)current.ActorKind == 0 && (int)current.Kind == 0);
			((TMP_Text)_detailFilter.Text).text = (((int)_runtime.Filter.Value == 1) ? "Targets: boss only" : "Targets: boss + summons");
			while (_sourceRows.Count < array.Length)
			{
				Row row = CreateRow((Transform)(object)_detailContent, 538f, interactive: false);
				Image val3 = ((Component)Box("Source color", row.Root.transform, 0f, 2f, 3f, 22f)).gameObject.AddComponent<Image>();
				((Graphic)val3).raycastTarget = false;
				row.SourceMarker = val3;
				Image val4 = ((Component)Box("Source icon", row.Root.transform, 7f, 2f, 22f, 22f)).gameObject.AddComponent<Image>();
				((Graphic)val4).raycastTarget = false;
				val4.preserveAspect = true;
				row.Icon = val4;
				((TMP_Text)row.Name).rectTransform.anchoredPosition = new Vector2(35f, -2f);
				((TMP_Text)row.Name).rectTransform.sizeDelta = new Vector2(335f, 25f);
				((TMP_Text)row.Value).rectTransform.anchoredPosition = new Vector2(380f, -2f);
				((TMP_Text)row.Value).rectTransform.sizeDelta = new Vector2(150f, 25f);
				_sourceRows.Add(row);
			}
			double num = array.Select((SourceRow x) => x.Damage).DefaultIfEmpty().Max();
			for (int num2 = 0; num2 < _sourceRows.Count; num2++)
			{
				Row row2 = _sourceRows[num2];
				row2.Root.SetActive(num2 < array.Length);
				if (num2 < array.Length)
				{
					SourceRow val5 = array[num2];
					(string, Sprite, Color) tuple = _sourceVisuals.Get(val5);
					row2.Root.GetComponent<RectTransform>().anchoredPosition = new Vector2(0f, (float)(-num2) * 30f);
					((Graphic)row2.Bar).rectTransform.sizeDelta = new Vector2((num > 0.0) ? (538f * (float)(val5.Damage / num)) : 0f, 26f);
					((Graphic)row2.Bar).color = new Color(tuple.Item3.r, tuple.Item3.g, tuple.Item3.b, 0.55f);
					((Graphic)row2.SourceMarker).color = tuple.Item3;
					((Graphic)row2.Name).color = Color.Lerp(tuple.Item3, Color.white, 0.55f);
					((TMP_Text)row2.Name).text = tuple.Item1;
					row2.Icon.sprite = tuple.Item2;
					((Component)row2.Icon).gameObject.SetActive((Object)(object)tuple.Item2 != (Object)null);
					((TMP_Text)row2.Name).rectTransform.anchoredPosition = new Vector2((float)(((Object)(object)tuple.Item2 != (Object)null) ? 35 : 9), -2f);
					((TMP_Text)row2.Name).rectTransform.sizeDelta = new Vector2(538f - (float)(((Object)(object)tuple.Item2 != (Object)null) ? 203 : 177), 25f);
					((TMP_Text)row2.Value).text = $"{val5.Damage:N0} · {val5.Share:P1}";
				}
			}
			_detailContent.sizeDelta = new Vector2(538f, Math.Max(1f, (float)array.Length * 30f));
			RefreshScrollbars();
		}

		private void ClampDetailPosition()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00be: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = ((Il2CppObjectBase)((Transform)_detailRect).parent).Cast<RectTransform>();
			Rect rect = _detailRect.rect;
			Vector2 val2 = ((Rect)(ref rect)).size * (((Transform)_detailRect).localScale.x / 2f);
			rect = val.rect;
			float num = Math.Max(0f, ((Rect)(ref rect)).width / 2f - val2.x);
			rect = val.rect;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(num, Math.Max(0f, ((Rect)(ref rect)).height / 2f - val2.y));
			Vector2 anchoredPosition = _detailRect.anchoredPosition;
			_detailRect.anchoredPosition = new Vector2(Mathf.Clamp(anchoredPosition.x, 0f - val3.x, val3.x), Mathf.Clamp(anchoredPosition.y, 0f - val3.y, val3.y));
		}

		public void ToggleReview()
		{
			if (ReviewOpen)
			{
				CloseReview();
				return;
			}
			ReviewOpen = true;
			_review.SetActive(true);
			_review.transform.SetAsLastSibling();
			_keyboardButton = -1;
			_runtime.RequestHistory();
			Refresh();
		}

		public void CloseReview()
		{
			CloseDetails();
			ReviewOpen = false;
			_dragging = false;
			if ((Object)(object)_review != (Object)null)
			{
				_review.SetActive(false);
			}
			FakeTooltip? tooltip = _tooltip;
			if (tooltip != null)
			{
				tooltip.DisableTooltip();
			}
			_hovered = null;
			_hoverKey = null;
		}

		public void UpdateDrag()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_006e: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: 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_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			RefreshHudControls();
			UpdateControls();
			if (_dismissPointerClick)
			{
				FakeTooltip? tooltip = _tooltip;
				if (tooltip != null)
				{
					tooltip.DisableTooltip();
				}
				return;
			}
			UpdateTooltip();
			if (DetailsOpen)
			{
				if (Input.GetMouseButtonDown(0) && ContainsPointer(_detailHeader))
				{
					_detailDragging = true;
					_detailDragStart = Vector2.op_Implicit(Input.mousePosition);
					_detailInitial = _detailRect.anchoredPosition;
				}
				if (_detailDragging && Input.GetMouseButton(0))
				{
					Canvas componentInParent = _details.GetComponentInParent<Canvas>();
					_detailRect.anchoredPosition = _detailInitial + (Vector2.op_Implicit(Input.mousePosition) - _detailDragStart) / Math.Max(componentInParent.scaleFactor, 0.01f);
					ClampDetailPosition();
				}
				if (Input.GetMouseButtonUp(0))
				{
					_detailDragging = false;
				}
				return;
			}
			if (ReviewOpen)
			{
				_dragging = false;
				return;
			}
			if (_runtime.Locked.Value || !_meter.activeInHierarchy)
			{
				_dragging = false;
				return;
			}
			if (Input.GetMouseButtonDown(0) && ContainsPointer(_header))
			{
				_dragging = true;
				_dragStart = Vector2.op_Implicit(Input.mousePosition);
				_initialPosition = _meterRect.anchoredPosition;
			}
			if (_dragging && Input.GetMouseButton(0))
			{
				Canvas componentInParent2 = _meter.GetComponentInParent<Canvas>();
				float num = (((Object)(object)componentInParent2 != (Object)null) ? Math.Max(componentInParent2.scaleFactor, 0.01f) : 1f);
				Vector2 val = _initialPosition + (Vector2.op_Implicit(Input.mousePosition) - _dragStart) / num;
				RectTransform val2 = ((Il2CppObjectBase)((Transform)_meterRect).parent).Cast<RectTransform>();
				float x = val.x;
				Rect rect = val2.rect;
				float num2 = 0f - ((Rect)(ref rect)).width;
				rect = _meterRect.rect;
				val.x = Mathf.Clamp(x, num2 + ((Rect)(ref rect)).width * _runtime.Scale.Value, 0f);
				float y = val.y;
				rect = val2.rect;
				float num3 = 0f - ((Rect)(ref rect)).height;
				rect = _meterRect.rect;
				val.y = Mathf.Clamp(y, num3 + ((Rect)(ref rect)).height * _runtime.Scale.Value, 0f);
				_meterRect.anchoredPosition = val;
			}
			if (_dragging && Input.GetMouseButtonUp(0))
			{
				_dragging = false;
				_runtime.OffsetX.Value = _meterRect.anchoredPosition.x;
				_runtime.OffsetY.Value = _meterRect.anchoredPosition.y;
			}
		}

		private bool InActiveLayer(Transform target)
		{
			if (!DetailsOpen)
			{
				if (ReviewOpen)
				{
					return target.IsChildOf(_review.transform);
				}
				return true;
			}
			return target.IsChildOf(_details.transform);
		}

		private bool ButtonAvailable(Button button)
		{
			if ((Object)(object)button != (Object)null && ((Component)button).gameObject.activeInHierarchy && ((Selectable)button).interactable)
			{
				return InActiveLayer(((Component)button).transform);
			}
			return false;
		}

		private void UpdateControls()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: 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)
			RefreshScrollbars();
			if (_dismissPointerClick)
			{
				if (Input.GetMouseButton(0) || Input.GetMouseButton(1))
				{
					_dismissReleasedFrame = -1;
				}
				else if (_dismissReleasedFrame < 0)
				{
					_dismissReleasedFrame = Time.frameCount;
				}
				else if (Time.frameCount > _dismissReleasedFrame)
				{
					_dismissPointerClick = false;
				}
				return;
			}
			if (DetailsOpen && !_detailDragging && (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) && !ContainsPointer(_detailRect))
			{
				CloseDetails();
				_dismissPointerClick = true;
				_dismissReleasedFrame = -1;
				return;
			}
			ScrollView draggedScroll = _draggedScroll;
			if ((object)draggedScroll != null)
			{
				if (Input.GetMouseButton(0) && (Object)(object)draggedScroll.Track != (Object)null && ((Component)draggedScroll.Track).gameObject.activeInHierarchy && InActiveLayer((Transform)(object)draggedScroll.Track))
				{
					Vector2 anchoredPosition = draggedScroll.Content.anchoredPosition;
					anchoredPosition.y = Geometry(draggedScroll).OffsetAt(TrackPointer(draggedScroll.Track), _scrollGrab);
					draggedScroll.Content.anchoredPosition = anchoredPosition;
				}
				else
				{
					_draggedScroll = null;
				}
				RefreshScrollbars();
				return;
			}
			if (Input.GetMouseButtonDown(0))
			{
				ScrollView scrollView = _scrolls.LastOrDefault((ScrollView x) => (Object)(object)x.Track != (Object)null && ((Component)x.Track).gameObject.activeInHierarchy && InActiveLayer((Transform)(object)x.Track) && PointerVisible(x.Track));
				if ((Object)(object)scrollView?.Track != (Object)null && (Object)(object)scrollView.Thumb != (Object)null)
				{
					_pressedButton = null;
					_pressedActor = null;
					_draggedScroll = scrollView;
					ScrollGeometry scrollGeometry = Geometry(scrollView);
					float num = TrackPointer(scrollView.Track);
					_scrollGrab = (ContainsPointer(scrollView.Thumb) ? (num - scrollGeometry.ThumbTop) : (scrollGeometry.ThumbHeight / 2f));
					Vector2 anchoredPosition2 = scrollView.Content.anchoredPosition;
					anchoredPosition2.y = scrollGeometry.OffsetAt(num, _scrollGrab);
					scrollView.Content.anchoredPosition = anchoredPosition2;
					RefreshScrollbars();
					return;
				}
			}
			ScrollView scrollView2 = null;
			foreach (ScrollView scroll in _scrolls)
			{
				if (((Component)scroll.Viewport).gameObject.activeInHierarchy && InActiveLayer((Transform)(object)scroll.Viewport) && (ContainsPointer(scroll.Viewport) || (!((Object)(object)scroll.Track == (Object)null) && PointerVisible(scroll.Track))))
				{
					scrollView2 = scroll;
					Vector2 anchoredPosition3 = scroll.Content.anchoredPosition;
					anchoredPosition3.y = Mathf.Clamp(anchoredPosition3.y - Input.mouseScrollDelta.y * scroll.Scroll.scrollSensitivity, 0f, Geometry(scroll).Range);
					scroll.Content.anchoredPosition = anchoredPosition3;
				}
			}
			if (ReviewOpen || DetailsOpen)
			{
				ScrollView scrollView3 = scrollView2 ?? _scrolls.FirstOrDefault((ScrollView x) => (Object)(object)x.Content == (Object)(object)(DetailsOpen ? _detailContent : _historyContent));
				if (scrollView3 != null)
				{
					Vector2 anchoredPosition4 = scrollView3.Content.anchoredPosition;
					Rect rect;
					if (Input.GetKeyDown((KeyCode)281))
					{
						ref float y = ref anchoredPosition4.y;
						float num2 = y;
						rect = scrollView3.Viewport.rect;
						y = num2 + ((Rect)(ref rect)).height;
					}
					if (Input.GetKeyDown((KeyCode)280))
					{
						ref float y2 = ref anchoredPosition4.y;
						float num3 = y2;
						rect = scrollView3.Viewport.rect;
						y2 = num3 - ((Rect)(ref rect)).height;
					}
					if (Input.GetKeyDown((KeyCode)278))
					{
						anchoredPosition4.y = 0f;
					}
					if (Input.GetKeyDown((KeyCode)279))
					{
						anchoredPosition4.y = Geometry(scrollView3).Range;
					}
					anchoredPosition4.y = Mathf.Clamp(anchoredPosition4.y, 0f, Geometry(scrollView3).Range);
					scrollView3.Content.anchoredPosition = anchoredPosition4;
				}
			}
			RefreshScrollbars();
			if (Input.GetMouseButtonDown(0))
			{
				_pressedButton = _buttons.LastOrDefault<(Button, Action)>(((Button Button, Action Action) x) => ButtonAvailable(x.Button) && PointerVisible(((Component)x.Button).GetComponent<RectTransform>())).Item1;
				Row row = _meterRows.Concat(_reviewRows).FirstOrDefault((Row x) => (Object)(object)_pressedButton != (Object)null && (Object)(object)x.Root == (Object)(object)((Component)_pressedButton).gameObject);
				DetailSelection val = row?.Selection;
				_pressedActor = ((val != null) ? new(DetailSelection, string, string)?((val, row.ActorName, row.EncounterLabel)) : (((DetailSelection, string, string)?)null));
			}
			if (Input.GetMouseButtonUp(0))
			{
				Button pressed = _pressedButton;
				_pressedButton = null;
				(DetailSelection, string, string)? pressedActor = _pressedActor;
				_pressedActor = null;
				if ((Object)(object)pressed != (Object)null && ButtonAvailable(pressed) && PointerVisible(((Component)pressed).GetComponent<RectTransform>()))
				{
					if (pressedActor.HasValue)
					{
						(DetailSelection, string, string) valueOrDefault = pressedActor.GetValueOrDefault();
						OpenDetails(valueOrDefault.Item1, valueOrDefault.Item2, valueOrDefault.Item3);
					}
					else
					{
						_buttons.First<(Button, Action)>(((Button Button, Action Action) x) => (Object)(object)x.Button == (Object)(object)pressed).Item2();
					}
				}
			}
			if (!ReviewOpen && !DetailsOpen)
			{
				return;
			}
			(Button, Action)[] array = _buttons.Where<(Button, Action)>(((Button Button, Action Action) x) => ButtonAvailable(x.Button)).ToArray();
			if (array.Length != 0)
			{
				if (Input.GetKeyDown((KeyCode)9))
				{
					bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
					_keyboardButton = ((_keyboardButton >= 0) ? ((_keyboardButton + ((!flag) ? 1 : (array.Length - 1))) % array.Length) : (flag ? (array.Length - 1) : 0));
					((Selectable)array[_keyboardButton].Item1).Select();
				}
				if (_keyboardButton >= 0 && _keyboardButton < array.Length && Input.GetKeyDown((KeyCode)13))
				{
					array[_keyboardButton].Item2();
				}
			}
		}

		private void UpdateTooltip()
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			if (DetailsOpen)
			{
				FakeTooltip? tooltip = _tooltip;
				if (tooltip != null)
				{
					tooltip.DisableTooltip();
				}
				_runtime.Inspect(_pinned);
				return;
	

BepInEx/plugins/CombatMeter/CombatMeter.Core.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using CombatMeter.Shared;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CombatMeter.Core")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+7bf5d4af4539905a627ee336fb44ed2fa9bdee99")]
[assembly: AssemblyProduct("CombatMeter.Core")]
[assembly: AssemblyTitle("CombatMeter.Core")]
[assembly: AssemblyVersion("0.2.1.0")]
[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 CombatMeter.Core
{
	public readonly record struct Participant(ulong Id, string Name, int Team = 0);
	public readonly record struct EntityKey(int Index, int Version);
	public readonly record struct CreatureParticipant(EntityKey Entity, string Name, CreatureKind Kind, EntityKey? Boss = null)
	{
		[CompilerGenerated]
		public void Deconstruct(out EntityKey Entity, out string Name, out CreatureKind Kind, out EntityKey? Boss)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected I4, but got Unknown
			Entity = this.Entity;
			Name = this.Name;
			Kind = (CreatureKind)(int)this.Kind;
			Boss = this.Boss;
		}
	}
	public sealed record CombatEvent(string EventId, double Timestamp, EntityKey Source, EntityKey Target, Participant? Attacker, Participant? Victim, double HealthDamage, EncounterKind Kind, string? EncounterKey = null, DamageTarget TargetClass = (DamageTarget)0, CreatureParticipant? CreatureAttacker = null, DamageSource? DamageSource = null)
	{
		[CompilerGenerated]
		public void Deconstruct(out string EventId, out double Timestamp, out EntityKey Source, out EntityKey Target, out Participant? Attacker, out Participant? Victim, out double HealthDamage, out EncounterKind Kind, out string? EncounterKey, out DamageTarget TargetClass, out CreatureParticipant? CreatureAttacker, out DamageSource? DamageSource)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected I4, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected I4, but got Unknown
			EventId = this.EventId;
			Timestamp = this.Timestamp;
			Source = this.Source;
			Target = this.Target;
			Attacker = this.Attacker;
			Victim = this.Victim;
			HealthDamage = this.HealthDamage;
			Kind = (EncounterKind)(int)this.Kind;
			EncounterKey = this.EncounterKey;
			TargetClass = (DamageTarget)(int)this.TargetClass;
			CreatureAttacker = this.CreatureAttacker;
			DamageSource = this.DamageSource;
		}
	}
	public sealed record DamageSource(string Id, string Name, DamageSourceKind Kind, int PrefabHash = 0)
	{
		public static readonly DamageSource Unknown = new DamageSource("unknown", "Unknown source", (DamageSourceKind)5);

		public static readonly DamageSource Other = new DamageSource("other", "Other sources", (DamageSourceKind)6);

		[CompilerGenerated]
		private DamageSource(DamageSource original)
		{
			//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)
			Id = original.Id;
			Name = original.Name;
			Kind = original.Kind;
			PrefabHash = original.PrefabHash;
		}

		[CompilerGenerated]
		public void Deconstruct(out string Id, out string Name, out DamageSourceKind Kind, out int PrefabHash)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected I4, but got Unknown
			Id = this.Id;
			Name = this.Name;
			Kind = (DamageSourceKind)(int)this.Kind;
			PrefabHash = this.PrefabHash;
		}
	}
	public sealed class TrackingPolicy
	{
		public HashSet<EncounterKind> EnabledModes { get; init; } = new HashSet<EncounterKind>
		{
			(EncounterKind)0,
			(EncounterKind)1,
			(EncounterKind)2,
			(EncounterKind)3
		};

		public double TimeoutSeconds { get; init; } = 10.0;
	}
	public sealed class EncounterTracker
	{
		private sealed class Fight
		{
			public string Id = Guid.NewGuid().ToString("N");

			public string Key = "";

			public string Label = "";

			public EncounterKind Kind;

			public EncounterStatus Status;

			public double Start;

			public double Last;

			public long Sequence;

			public long DetailRevision;

			public double End;

			public double Unknown;

			public double UnknownBoss;

			public readonly Dictionary<ulong, PlayerTotals> Players = new Dictionary<ulong, PlayerTotals>();

			public readonly Dictionary<EntityKey, CreatureTotals> Creatures = new Dictionary<EntityKey, CreatureTotals>();

			public readonly Dictionary<string, SourceAccumulator> Sources = new Dictionary<string, SourceAccumulator>();

			public readonly HashSet<EntityKey> Entities = new HashSet<EntityKey>();

			public readonly HashSet<ulong> Observers = new HashSet<ulong>();
		}

		private sealed record HistoryEntry(EncounterSnapshot Snapshot, Fight Fight);

		private readonly Dictionary<string, Fight> _active = new Dictionary<string, Fight>();

		private readonly LinkedList<EncounterSnapshot> _history = new LinkedList<EncounterSnapshot>();

		private readonly Dictionary<ulong, LinkedList<HistoryEntry>> _playerHistory = new Dictionary<ulong, LinkedList<HistoryEntry>>();

		private readonly Dictionary<string, double> _seen = new Dictionary<string, double>();

		private readonly Queue<(string Id, double Timestamp)> _seenOrder = new Queue<(string, double)>();

		public TrackingPolicy Policy { get; }

		public string SessionId { get; } = Guid.NewGuid().ToString("N");

		public int ActiveCount => _active.Count;

		public int HistoryCount => _history.Count;

		public int DeduplicationCount => _seen.Count;

		public event Action<EncounterSnapshot>? Finished;

		public event Action<EncounterSnapshot, IReadOnlyCollection<ulong>>? FinishedForAudience;

		public EncounterTracker(TrackingPolicy? policy = null)
		{
			Policy = policy ?? new TrackingPolicy();
			if (!double.IsFinite(Policy.TimeoutSeconds) || Policy.TimeoutSeconds <= 0.0)
			{
				throw new ArgumentOutOfRangeException("policy");
			}
		}

		public string? Begin(EncounterKind kind, string key, string label, double now, IEnumerable<Participant> roster)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (!Policy.EnabledModes.Contains(kind) || !double.IsFinite(now))
			{
				return null;
			}
			Fight fight = _active.Values.FirstOrDefault((Fight x) => x.Kind == kind && x.Key == key);
			if (fight != null)
			{
				foreach (Participant item in roster)
				{
					AddPlayer(fight, item);
				}
				return fight.Id;
			}
			Fight fight2 = new Fight
			{
				Kind = kind,
				Key = key,
				Label = label,
				Start = now,
				Last = now
			};
			foreach (Participant item2 in roster)
			{
				AddPlayer(fight2, item2);
			}
			_active.Add(fight2.Id, fight2);
			return fight2.Id;
		}

		public void AddParticipants(EncounterKind kind, string key, IEnumerable<Participant> roster)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Fight fight = _active.Values.FirstOrDefault((Fight x) => x.Kind == kind && x.Key == key);
			if (fight == null)
			{
				return;
			}
			foreach (Participant item in roster)
			{
				AddPlayer(fight, item);
			}
		}

		public void SetObservers(EncounterKind kind, string key, IEnumerable<ulong> observers)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Fight fight = _active.Values.FirstOrDefault((Fight x) => x.Kind == kind && x.Key == key);
			if (fight != null)
			{
				fight.Observers.Clear();
				fight.Observers.UnionWith(observers);
			}
		}

		public string? Record(CombatEvent hit)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: 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_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Invalid comparison between Unknown and I4
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Invalid comparison between Unknown and I4
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Invalid comparison between Unknown and I4
			//IL_0557: Unknown result type (might be due to invalid IL or missing references)
			//IL_055d: Invalid comparison between Unknown and I4
			//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Invalid comparison between Unknown and I4
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Expected O, but got Unknown
			//IL_040d: Expected O, but got Unknown
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Invalid comparison between Unknown and I4
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			if (!Policy.EnabledModes.Contains(hit.Kind) || !double.IsFinite(hit.Timestamp) || !double.IsFinite(hit.HealthDamage) || hit.HealthDamage < 0.0)
			{
				return null;
			}
			CreatureParticipant? creatureAttacker = hit.CreatureAttacker;
			CreatureParticipant valueOrDefault = default(CreatureParticipant);
			int num;
			if (creatureAttacker.HasValue)
			{
				valueOrDefault = creatureAttacker.GetValueOrDefault();
				num = 1;
			}
			else
			{
				num = 0;
			}
			bool flag = (byte)num != 0;
			EncounterKind kind;
			if (flag)
			{
				bool flag2 = hit.Attacker.HasValue || !hit.Victim.HasValue;
				if (!flag2)
				{
					kind = hit.Kind;
					bool flag3 = (((int)kind == 0 || (int)kind == 4) ? true : false);
					flag2 = !flag3;
				}
				flag = flag2 || string.IsNullOrWhiteSpace(valueOrDefault.Name) || !Enum.IsDefined(typeof(CreatureKind), valueOrDefault.Kind);
			}
			if (flag)
			{
				return null;
			}
			ExpireDeduplication(hit.Timestamp);
			if (!_seen.TryAdd(hit.EventId, hit.Timestamp))
			{
				return null;
			}
			_seenOrder.Enqueue((hit.EventId, hit.Timestamp));
			Tick(hit.Timestamp);
			kind = hit.Kind;
			Fight fight;
			if (kind - 3 <= 1)
			{
				Fight[] source = (from x in _active.Values.Where(delegate(Fight x)
					{
						//IL_0001: Unknown result type (might be due to invalid IL or missing references)
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						if (x.Kind != hit.Kind)
						{
							return false;
						}
						if (!x.Entities.Contains(hit.Target) && !x.Entities.Contains(hit.Source))
						{
							Participant? attacker = hit.Attacker;
							if (attacker.HasValue)
							{
								Participant valueOrDefault5 = attacker.GetValueOrDefault();
								if (x.Players.ContainsKey(valueOrDefault5.Id))
								{
									goto IL_00a9;
								}
							}
							attacker = hit.Victim;
							if (attacker.HasValue)
							{
								Participant valueOrDefault6 = attacker.GetValueOrDefault();
								return x.Players.ContainsKey(valueOrDefault6.Id);
							}
							return false;
						}
						goto IL_00a9;
						IL_00a9:
						return true;
					})
					orderby x.Start
					select x).ToArray();
				fight = source.FirstOrDefault();
				if (fight == null)
				{
					string key = Begin(hit.Kind, Guid.NewGuid().ToString("N"), ((int)hit.Kind == 3) ? "World PvP" : "Open-world PvE", hit.Timestamp, Array.Empty<Participant>());
					fight = _active[key];
				}
				foreach (Fight item in source.Skip(1))
				{
					Merge(fight, item, hit.Timestamp);
				}
			}
			else
			{
				fight = _active.Values.FirstOrDefault((Fight x) => x.Kind == hit.Kind && x.Key == hit.EncounterKey);
				if (fight == null)
				{
					return null;
				}
			}
			if (hit.Timestamp < fight.Start)
			{
				return null;
			}
			fight.Last = Math.Max(fight.Last, hit.Timestamp);
			fight.Entities.Add(hit.Target);
			fight.Entities.Add(hit.Source);
			Participant? victim = hit.Victim;
			if (victim.HasValue)
			{
				Participant valueOrDefault2 = victim.GetValueOrDefault();
				AddPlayer(fight, valueOrDefault2);
			}
			creatureAttacker = hit.CreatureAttacker;
			if (creatureAttacker.HasValue)
			{
				CreatureParticipant valueOrDefault3 = creatureAttacker.GetValueOrDefault();
				if (!fight.Creatures.TryGetValue(valueOrDefault3.Entity, out CreatureTotals value))
				{
					Dictionary<EntityKey, CreatureTotals> creatures = fight.Creatures;
					EntityKey entity = valueOrDefault3.Entity;
					CreatureTotals val = new CreatureTotals
					{
						EntityId = $"{valueOrDefault3.Entity.Index}:{valueOrDefault3.Entity.Version}",
						Name = valueOrDefault3.Name,
						Kind = valueOrDefault3.Kind
					};
					value = val;
					creatures[entity] = val;
				}
				CreatureTotals obj = value;
				obj.Damage += hit.HealthDamage;
				Sources(fight, "c:" + value.EntityId).Record(hit.DamageSource, hit.HealthDamage, (DamageTarget)0);
			}
			else
			{
				victim = hit.Attacker;
				if (victim.HasValue)
				{
					Participant valueOrDefault4 = victim.GetValueOrDefault();
					PlayerTotals val2 = AddPlayer(fight, valueOrDefault4);
					val2.Damage += hit.HealthDamage;
					if ((int)hit.TargetClass == 1)
					{
						val2.BossDamage += hit.HealthDamage;
					}
					if ((int)hit.TargetClass == 2)
					{
						val2.SummonDamage += hit.HealthDamage;
					}
					Sources(fight, "p:" + valueOrDefault4.Id).Record(hit.DamageSource, hit.HealthDamage, hit.TargetClass);
				}
				else
				{
					fight.Unknown += hit.HealthDamage;
					if ((int)hit.TargetClass == 1)
					{
						fight.UnknownBoss += hit.HealthDamage;
					}
				}
			}
			return fight.Id;
		}

		private static PlayerTotals AddPlayer(Fight fight, Participant player)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003c: Expected O, but got Unknown
			if (!fight.Players.TryGetValue(player.Id, out PlayerTotals value))
			{
				Dictionary<ulong, PlayerTotals> players = fight.Players;
				ulong id = player.Id;
				PlayerTotals val = new PlayerTotals
				{
					PlayerId = player.Id
				};
				value = val;
				players.Add(id, val);
			}
			value.Name = player.Name;
			value.Team = player.Team;
			return value;
		}

		private static SourceAccumulator Sources(Fight fight, string actor)
		{
			if (!fight.Sources.TryGetValue(actor, out SourceAccumulator value))
			{
				value = (fight.Sources[actor] = new SourceAccumulator());
			}
			return value;
		}

		private void Merge(Fight target, Fight source, double now)
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_013d: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			foreach (PlayerTotals value2 in source.Players.Values)
			{
				PlayerTotals obj = AddPlayer(target, new Participant(value2.PlayerId, value2.Name, value2.Team));
				obj.Damage += value2.Damage;
				obj.BossDamage += value2.BossDamage;
				obj.SummonDamage += value2.SummonDamage;
			}
			target.Last = Math.Max(target.Last, source.Last);
			target.Unknown += source.Unknown;
			target.UnknownBoss += source.UnknownBoss;
			foreach (var (key, val2) in source.Creatures)
			{
				if (!target.Creatures.TryGetValue(key, out CreatureTotals value))
				{
					Dictionary<EntityKey, CreatureTotals> creatures = target.Creatures;
					CreatureTotals val3 = new CreatureTotals
					{
						EntityId = val2.EntityId,
						Name = val2.Name,
						Kind = val2.Kind
					};
					value = val3;
					creatures[key] = val3;
				}
				CreatureTotals obj2 = value;
				obj2.Damage += val2.Damage;
			}
			target.Entities.UnionWith(source.Entities);
			foreach (var (actor, other) in source.Sources)
			{
				Sources(target, actor).Merge(other);
			}
			target.Observers.UnionWith(source.Observers);
			_active.Remove(source.Id);
			source.Status = (EncounterStatus)4;
			EncounterSnapshot val4 = Snapshot(source, now);
			val4.MergedInto = target.Id;
			this.Finished?.Invoke(val4);
			this.FinishedForAudience?.Invoke(val4, (IReadOnlyCollection<ulong>)(object)Audience(source));
		}

		public void End(EncounterKind kind, string key, double now, EncounterStatus status = (EncounterStatus)1)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_001b: Invalid comparison between Unknown and I4
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (((int)status == 0 || (int)status == 4) ? true : false)
			{
				throw new ArgumentOutOfRangeException("status");
			}
			Fight fight = _active.Values.FirstOrDefault((Fight x) => x.Kind == kind && x.Key == key);
			if (fight != null)
			{
				Complete(fight, now, status);
			}
		}

		public void Tick(double now)
		{
			ExpireDeduplication(now);
			Fight[] array = _active.Values.Where(delegate(Fight x)
			{
				//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_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Invalid comparison between Unknown and I4
				EncounterKind kind = x.Kind;
				return kind - 3 <= 1;
			}).ToArray();
			foreach (Fight fight in array)
			{
				if (now - fight.Last >= Policy.TimeoutSeconds)
				{
					Complete(fight, fight.Last, (EncounterStatus)1);
				}
			}
		}

		private void Complete(Fight fight, double now, EncounterStatus status)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			_active.Remove(fight.Id);
			fight.Status = status;
			fight.End = Math.Max(now, fight.Last);
			EncounterSnapshot val = Snapshot(fight, Math.Max(now, fight.Last));
			_history.AddFirst(val);
			while (_history.Count > 20)
			{
				_history.RemoveLast();
			}
			ulong[] array = Audience(fight);
			ulong[] array2 = array;
			foreach (ulong key in array2)
			{
				if (!_playerHistory.TryGetValue(key, out LinkedList<HistoryEntry> value))
				{
					value = (_playerHistory[key] = new LinkedList<HistoryEntry>());
				}
				value.AddFirst(new HistoryEntry(val, fight));
				while (value.Count > 20)
				{
					value.RemoveLast();
				}
			}
			this.Finished?.Invoke(val);
			this.FinishedForAudience?.Invoke(val, (IReadOnlyCollection<ulong>)(object)array);
		}

		public EncounterSnapshot[] Active(double now)
		{
			return _active.Values.Select((Fight x) => Snapshot(x, now)).ToArray();
		}

		public EncounterSnapshot[] History(ulong playerId)
		{
			if (!_playerHistory.TryGetValue(playerId, out LinkedList<HistoryEntry> value))
			{
				return Array.Empty<EncounterSnapshot>();
			}
			return value.Select((HistoryEntry x) => x.Snapshot).ToArray();
		}

		private static ulong[] Audience(Fight fight)
		{
			return fight.Players.Keys.Concat(fight.Observers).Distinct().ToArray();
		}

		public bool CanObserve(string id, ulong playerId)
		{
			if (_active.TryGetValue(id, out Fight value))
			{
				if (!value.Players.ContainsKey(playerId))
				{
					return value.Observers.Contains(playerId);
				}
				return true;
			}
			return false;
		}

		public SourceResponsePacket Details(ulong requester, SourceRequestPacket request, double now)
		{
			//IL_000d: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			SourceResponsePacket val = new SourceResponsePacket
			{
				ServerSessionId = SessionId,
				EncounterId = request.EncounterId,
				ActorKind = request.ActorKind,
				PlayerId = request.PlayerId,
				CreatureId = request.CreatureId,
				RequestId = request.RequestId,
				Reason = "Source details unavailable"
			};
			if (request.ProtocolVersion != 4 || request.ServerSessionId != SessionId || string.IsNullOrEmpty(request.EncounterId) || request.EncounterId.Length > 64 || request.RequestId <= 0 || !double.IsFinite(now) || !Enum.IsDefined(typeof(DetailActorKind), request.ActorKind))
			{
				return val;
			}
			Fight fight = null;
			LinkedList<HistoryEntry> value;
			if (CanObserve(request.EncounterId, requester))
			{
				fight = _active[request.EncounterId];
			}
			else if (_playerHistory.TryGetValue(requester, out value))
			{
				fight = value.FirstOrDefault((HistoryEntry x) => x.Snapshot.Id == request.EncounterId)?.Fight;
			}
			if (fight == null)
			{
				return val;
			}
			string key = (((int)request.ActorKind == 0) ? ("p:" + request.PlayerId) : ("c:" + request.CreatureId));
			if ((int)request.ActorKind == 0)
			{
				if (!fight.Players.TryGetValue(request.PlayerId, out PlayerTotals value2))
				{
					return val;
				}
				val.ActorName = value2.Name;
				val.Damage = value2.Damage;
				val.BossDamage = value2.BossDamage;
				val.SummonDamage = value2.SummonDamage;
			}
			else
			{
				CreatureTotals val2 = ((IEnumerable<CreatureTotals>)fight.Creatures.Values).FirstOrDefault((Func<CreatureTotals, bool>)((CreatureTotals x) => x.EntityId == request.CreatureId));
				if (val2 == null)
				{
					return val;
				}
				val.ActorName = val2.Name;
				val.Damage = val2.Damage;
			}
			val.Available = true;
			val.Reason = "";
			val.EncounterLabel = fight.Label;
			val.Kind = fight.Kind;
			val.Status = fight.Status;
			val.Revision = ++fight.DetailRevision;
			val.DurationSeconds = Math.Max(0.0, (((int)fight.Status == 0) ? now : fight.End) - fight.Start);
			val.Sources = (SourceTotals[])(fight.Sources.TryGetValue(key, out SourceAccumulator value3) ? ((Array)value3.Snapshot()) : ((Array)Array.Empty<SourceTotals>()));
			return val;
		}

		private static EncounterSnapshot Snapshot(Fight fight, double now)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			//IL_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			return new EncounterSnapshot
			{
				Id = fight.Id,
				Label = fight.Label,
				Kind = fight.Kind,
				Status = fight.Status,
				Sequence = ++fight.Sequence,
				StartedAt = fight.Start,
				EndedAt = (((int)fight.Status == 0) ? 0.0 : now),
				DurationSeconds = Math.Max(0.0, now - fight.Start),
				UnknownDamage = fight.Unknown,
				UnknownBossDamage = fight.UnknownBoss,
				Creatures = ((IEnumerable<CreatureTotals>)fight.Creatures.Values).Select((Func<CreatureTotals, CreatureTotals>)((CreatureTotals x) => new CreatureTotals
				{
					EntityId = x.EntityId,
					Name = x.Name,
					Kind = x.Kind,
					Damage = x.Damage
				})).ToArray(),
				Players = ((IEnumerable<PlayerTotals>)fight.Players.Values).Select((Func<PlayerTotals, PlayerTotals>)((PlayerTotals x) => new PlayerTotals
				{
					PlayerId = x.PlayerId,
					Name = x.Name,
					Team = x.Team,
					Damage = x.Damage,
					BossDamage = x.BossDamage,
					SummonDamage = x.SummonDamage
				})).ToArray()
			};
		}

		private void ExpireDeduplication(double now)
		{
			(string, double) result;
			while (_seenOrder.TryPeek(out result) && (now - result.Item2 > 120.0 || _seenOrder.Count > 65536))
			{
				_seenOrder.Dequeue();
				_seen.Remove(result.Item1);
			}
		}
	}
	public sealed record MeterRow(string Name, int Team, double Damage, double Dps, double? Share, bool IsEnemy, ulong PlayerId = 0uL, string CreatureId = "");
	public static class MeterPresentation
	{
		public static MeterRow[] Players(EncounterSnapshot fight, BossTargetFilter filter)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			bool showShares = fight.Players.Length > 1;
			List<MeterRow> list = (from x in MeterState.Rank(fight, (MeterMetric)0, filter)
				select new MeterRow(x.Name, x.Team, x.Damage, x.Dps, showShares ? new double?(x.Share) : ((double?)null), IsEnemy: false, x.Id)).ToList();
			double num = (((int)fight.Kind == 0 && (int)filter == 1) ? fight.UnknownBossDamage : fight.UnknownDamage);
			if (num > 0.0)
			{
				list.Add(new MeterRow("Unresolved source", 0, num, (fight.DurationSeconds > 0.0) ? (num / fight.DurationSeconds) : 0.0, null, IsEnemy: false, 0uL));
			}
			return list.ToArray();
		}

		public static MeterRow[] Enemies(EncounterSnapshot fight)
		{
			return (from x in fight.Creatures.OrderByDescending((CreatureTotals x) => x.Damage).ThenBy<CreatureTotals, string>((CreatureTotals x) => x.Name, StringComparer.Ordinal).ThenBy<CreatureTotals, string>((CreatureTotals x) => x.EntityId, StringComparer.Ordinal)
				select new MeterRow(x.Name, 0, x.Damage, (fight.DurationSeconds > 0.0) ? (x.Damage / fight.DurationSeconds) : 0.0, null, IsEnemy: true, 0uL, x.EntityId)).ToArray();
		}

		public static string Values(MeterRow row)
		{
			CultureInfo currentCulture = CultureInfo.CurrentCulture;
			object arg = row.Damage;
			object arg2 = row.Dps;
			double? share = row.Share;
			return string.Format(currentCulture, "{0:N0} · {1:N1} DPS{2}", arg, arg2, (!share.HasValue) ? "" : string.Format(arg0: share.GetValueOrDefault(), provider: CultureInfo.CurrentCulture, format: " · {0:P0}"));
		}
	}
	public sealed record RankedPlayer(ulong Id, string Name, int Team, double Damage, double Dps, double Share);
	public sealed class MeterState
	{
		private readonly Dictionary<string, EncounterSnapshot> _active = new Dictionary<string, EncounterSnapshot>();

		private readonly LinkedList<EncounterSnapshot> _history = new LinkedList<EncounterSnapshot>();

		private readonly Dictionary<string, long> _sequences = new Dictionary<string, long>();

		public string SessionId { get; private set; } = "";

		public string StatusMessage { get; private set; } = "Waiting for server tracking";

		public PolicyPacket? Policy { get; private set; }

		public IReadOnlyCollection<EncounterSnapshot> Active => _active.Values;

		public IEnumerable<EncounterSnapshot> History => _history;

		public EncounterSnapshot? Latest
		{
			get
			{
				EncounterSnapshot obj = _active.Values.OrderByDescending((EncounterSnapshot x) => x.StartedAt).FirstOrDefault();
				if (obj == null)
				{
					LinkedListNode<EncounterSnapshot>? first = _history.First;
					if (first == null)
					{
						return null;
					}
					obj = first.Value;
				}
				return obj;
			}
		}

		public bool Apply(PolicyPacket packet)
		{
			if (packet.ProtocolVersion != 4 || !packet.Accepted || string.IsNullOrEmpty(packet.ServerSessionId))
			{
				Disconnect();
				StatusMessage = ((packet.Reason.Length > 0) ? packet.Reason : "Incompatible server tracking protocol");
				return false;
			}
			if (packet.ServerSessionId != SessionId)
			{
				Disconnect();
				SessionId = packet.ServerSessionId;
			}
			Policy = packet;
			StatusMessage = "Connected";
			return true;
		}

		public bool Apply(EncounterPacket packet)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Invalid comparison between Unknown and I4
			EncounterSnapshot encounter = packet.Encounter;
			if (Policy == null || packet.ProtocolVersion != 4 || packet.ServerSessionId != SessionId || encounter == null || string.IsNullOrEmpty(encounter.Id) || encounter.Players == null || encounter.Players.Length > 256 || encounter.Creatures == null || encounter.Creatures.Length > 2048 || encounter.Creatures.Any((CreatureTotals c) => c == null || string.IsNullOrEmpty(c.EntityId) || string.IsNullOrWhiteSpace(c.Name) || !Enum.IsDefined(typeof(CreatureKind), c.Kind) || !double.IsFinite(c.Damage) || c.Damage < 0.0) || encounter.Creatures.Select((CreatureTotals c) => c.EntityId).Distinct().Count() != encounter.Creatures.Length || !Enum.IsDefined(typeof(EncounterKind), encounter.Kind) || !Enum.IsDefined(typeof(EncounterStatus), encounter.Status) || !double.IsFinite(encounter.StartedAt) || !double.IsFinite(encounter.EndedAt) || !double.IsFinite(encounter.UnknownDamage) || encounter.UnknownDamage < 0.0 || !double.IsFinite(encounter.UnknownBossDamage) || encounter.UnknownBossDamage < 0.0 || !double.IsFinite(encounter.DurationSeconds) || encounter.DurationSeconds < 0.0 || encounter.Players.Any((PlayerTotals p) => p == null || !double.IsFinite(p.Damage) || p.Damage < 0.0 || !double.IsFinite(p.BossDamage) || p.BossDamage < 0.0 || !double.IsFinite(p.SummonDamage) || p.SummonDamage < 0.0) || encounter.Players.Select((PlayerTotals p) => p.PlayerId).Distinct().Count() != encounter.Players.Length)
			{
				return false;
			}
			if (_sequences.TryGetValue(encounter.Id, out var value) && encounter.Sequence <= value)
			{
				return false;
			}
			_sequences[encounter.Id] = encounter.Sequence;
			if ((int)encounter.Status == 0)
			{
				_active[encounter.Id] = encounter;
			}
			else
			{
				_active.Remove(encounter.Id);
				LinkedListNode<EncounterSnapshot> linkedListNode = _history.First;
				while (linkedListNode != null)
				{
					LinkedListNode<EncounterSnapshot>? next = linkedListNode.Next;
					if (linkedListNode.Value.Id == encounter.Id)
					{
						_history.Remove(linkedListNode);
					}
					linkedListNode = next;
				}
				if ((int)encounter.Status != 4)
				{
					_history.AddFirst(encounter);
				}
				while (_history.Count > 20)
				{
					_history.RemoveLast();
				}
				if (_sequences.Count > 4096)
				{
					HashSet<string> keep = _active.Keys.Concat(_history.Select((EncounterSnapshot x) => x.Id)).ToHashSet();
					string[] array = _sequences.Keys.Where((string x) => !keep.Contains(x)).Take(2048).ToArray();
					foreach (string key in array)
					{
						_sequences.Remove(key);
					}
				}
			}
			return true;
		}

		public void Disconnect()
		{
			_active.Clear();
			_history.Clear();
			_sequences.Clear();
			SessionId = "";
			Policy = null;
			StatusMessage = "Waiting for server tracking";
		}

		public static RankedPlayer[] Rank(EncounterSnapshot encounter, MeterMetric metric, BossTargetFilter filter)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			double total = encounter.Players.Sum((PlayerTotals x) => x.ForFilter(encounter.Kind, filter)) + (((int)encounter.Kind == 0 && (int)filter == 1) ? encounter.UnknownBossDamage : encounter.UnknownDamage);
			return (from x in encounter.Players.Select(delegate(PlayerTotals x)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000d: Unknown result type (might be due to invalid IL or missing references)
					double num = x.ForFilter(encounter.Kind, filter);
					return new RankedPlayer(x.PlayerId, x.Name, x.Team, num, (encounter.DurationSeconds > 0.0) ? (num / encounter.DurationSeconds) : 0.0, (total > 0.0) ? (num / total) : 0.0);
				})
				orderby ((int)metric != 0) ? x.Dps : x.Damage descending
				select x).ThenBy<RankedPlayer, string>((RankedPlayer x) => x.Name, StringComparer.Ordinal).ThenBy((RankedPlayer x) => x.Id).ToArray();
		}
	}
	public sealed class OwnershipCache
	{
		private readonly Dictionary<EntityKey, (Participant Player, double Seen)> _players = new Dictionary<EntityKey, (Participant, double)>();

		private readonly Dictionary<EntityKey, (EntityKey Owner, double Seen)> _owners = new Dictionary<EntityKey, (EntityKey, double)>();

		public int Count => _players.Count + _owners.Count;

		public void ObservePlayer(EntityKey entity, Participant player, double now)
		{
			_players[entity] = (player, now);
		}

		public void ObserveOwner(EntityKey entity, EntityKey owner, double now = 0.0)
		{
			_owners[entity] = (owner, now);
		}

		public Participant? Resolve(EntityKey entity, double now)
		{
			HashSet<EntityKey> hashSet = new HashSet<EntityKey>();
			EntityKey entityKey = entity;
			for (int i = 0; i < 32; i++)
			{
				if (!hashSet.Add(entityKey))
				{
					break;
				}
				if (_players.TryGetValue(entityKey, out (Participant, double) value))
				{
					foreach (EntityKey item in hashSet)
					{
						_players[item] = (value.Item1, now);
					}
					return value.Item1;
				}
				if (!_owners.TryGetValue(entityKey, out (EntityKey, double) value2))
				{
					return null;
				}
				entityKey = value2.Item1;
			}
			return null;
		}

		public void Prune(double now, double retentionSeconds = 120.0)
		{
			EntityKey[] array = (from x in _players
				where now - x.Value.Seen > retentionSeconds
				select x.Key).ToArray();
			foreach (EntityKey key in array)
			{
				_players.Remove(key);
			}
			array = (from x in _owners
				where now - x.Value.Seen > retentionSeconds
				select x.Key).ToArray();
			foreach (EntityKey key2 in array)
			{
				_owners.Remove(key2);
			}
		}

		public void Clear()
		{
			_players.Clear();
			_owners.Clear();
		}
	}
	public static class ResolvedHealthDamage
	{
		public static double Between(double before, double after)
		{
			if (!double.IsFinite(before) || !double.IsFinite(after))
			{
				return 0.0;
			}
			return Math.Max(0.0, Math.Max(0.0, before) - Math.Max(0.0, after));
		}
	}
	public sealed class SourceAccumulator
	{
		private readonly Dictionary<string, SourceTotals> _totals = new Dictionary<string, SourceTotals>();

		private int _named;

		public void Record(DamageSource? source, double damage, DamageTarget target)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			if (!(damage <= 0.0))
			{
				Add(source ?? DamageSource.Unknown, damage, ((int)target == 1) ? damage : 0.0, ((int)target == 2) ? damage : 0.0);
			}
		}

		private void Add(DamageSource source, double damage, double boss, double summon)
		{
			//IL_003e: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Invalid comparison between Unknown and I4
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00e1: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Invalid comparison between Unknown and I4
			if (string.IsNullOrWhiteSpace(source.Id) || string.IsNullOrWhiteSpace(source.Name) || !Enum.IsDefined(typeof(DamageSourceKind), source.Kind))
			{
				source = DamageSource.Unknown;
			}
			DamageSourceKind kind = source.Kind;
			bool flag = kind - 5 <= 1;
			bool flag2 = flag;
			if (flag2)
			{
				source = (((int)source.Kind == 5) ? DamageSource.Unknown : DamageSource.Other);
			}
			if (!_totals.ContainsKey(source.Id) && !flag2 && _named >= 128)
			{
				source = DamageSource.Other;
			}
			if (!_totals.TryGetValue(source.Id, out SourceTotals value))
			{
				value = new SourceTotals
				{
					Id = source.Id,
					Name = source.Name,
					Kind = source.Kind,
					PrefabHash = source.PrefabHash
				};
				_totals.Add(source.Id, value);
				kind = source.Kind;
				if (kind - 5 > 1)
				{
					_named++;
				}
			}
			SourceTotals obj = value;
			obj.Damage += damage;
			SourceTotals obj2 = value;
			obj2.BossDamage += boss;
			SourceTotals obj3 = value;
			obj3.SummonDamage += summon;
		}

		public void Merge(SourceAccumulator other)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			foreach (SourceTotals value in other._totals.Values)
			{
				Add(new DamageSource(value.Id, value.Name, value.Kind, value.PrefabHash), value.Damage, value.BossDamage, value.SummonDamage);
			}
		}

		public SourceTotals[] Snapshot()
		{
			return ((IEnumerable<SourceTotals>)_totals.Values).Select((Func<SourceTotals, SourceTotals>)((SourceTotals x) => new SourceTotals
			{
				Id = x.Id,
				Name = x.Name,
				Kind = x.Kind,
				PrefabHash = x.PrefabHash,
				Damage = x.Damage,
				BossDamage = x.BossDamage,
				SummonDamage = x.SummonDamage
			})).ToArray();
		}
	}
	public sealed record DetailSelection(string EncounterId, DetailActorKind Kind, ulong PlayerId = 0uL, string CreatureId = "")
	{
		[CompilerGenerated]
		public void Deconstruct(out string EncounterId, out DetailActorKind Kind, out ulong PlayerId, out string CreatureId)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected I4, but got Unknown
			EncounterId = this.EncounterId;
			Kind = (DetailActorKind)(int)this.Kind;
			PlayerId = this.PlayerId;
			CreatureId = this.CreatureId;
		}
	}
	public sealed record SourceRow(string Id, string Name, DamageSourceKind Kind, int PrefabHash, double Damage, double Dps, double Share)
	{
		[CompilerGenerated]
		public void Deconstruct(out string Id, out string Name, out DamageSourceKind Kind, out int PrefabHash, out double Damage, out double Dps, out double Share)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected I4, but got Unknown
			Id = this.Id;
			Name = this.Name;
			Kind = (DamageSourceKind)(int)this.Kind;
			PrefabHash = this.PrefabHash;
			Damage = this.Damage;
			Dps = this.Dps;
			Share = this.Share;
		}
	}
	public sealed class SourceDetailState
	{
		private readonly Dictionary<DetailSelection, SourceResponsePacket> _cache = new Dictionary<DetailSelection, SourceResponsePacket>();

		private string _session = "";

		private long _serial = DateTime.UtcNow.Ticks;

		private long _firstRequest;

		private long _lastSent;

		private long _lastAccepted;

		private double _next;

		private double _waitingSince;

		public DetailSelection? Selection { get; private set; }

		public SourceResponsePacket? Current
		{
			get
			{
				DetailSelection selection = Selection;
				if ((object)selection == null || !_cache.TryGetValue(selection, out SourceResponsePacket value))
				{
					return null;
				}
				return value;
			}
		}

		public string Message { get; private set; } = "Loading damage sources…";

		public void Select(string session, DetailSelection? selection, double now)
		{
			if (_session != session)
			{
				Clear();
				_session = session;
			}
			if (!(Selection == selection))
			{
				Selection = selection;
				_next = 0.0;
				_waitingSince = now;
				_firstRequest = _serial + 1;
				_lastSent = (_lastAccepted = 0L);
				Message = "Loading damage sources…";
			}
		}

		public SourceRequestPacket? Poll(double now)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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_00bf: 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_00d8: Expected O, but got Unknown
			DetailSelection selection = Selection;
			if ((object)selection == null || string.IsNullOrEmpty(_session))
			{
				return null;
			}
			SourceResponsePacket current = Current;
			if (current != null && current.Available && (int)current.Status != 0)
			{
				return null;
			}
			if (now - _waitingSince >= 5.0 && current == null)
			{
				Message = "Source details unavailable";
			}
			if (now < _next)
			{
				return null;
			}
			_next = now + 0.5;
			_lastSent = ++_serial;
			return new SourceRequestPacket
			{
				ServerSessionId = _session,
				EncounterId = selection.EncounterId,
				ActorKind = selection.Kind,
				PlayerId = selection.PlayerId,
				CreatureId = selection.CreatureId,
				RequestId = _lastSent
			};
		}

		public bool Apply(SourceResponsePacket packet)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Invalid comparison between Unknown and I4
			DetailSelection selection = Selection;
			if ((object)selection == null || packet.ProtocolVersion != 4 || packet.ServerSessionId != _session || selection != new DetailSelection(packet.EncounterId, packet.ActorKind, packet.PlayerId, packet.CreatureId) || packet.RequestId < _firstRequest || packet.RequestId > _lastSent || packet.RequestId <= _lastAccepted)
			{
				return false;
			}
			if (packet.Available)
			{
				if (!Enum.IsDefined(typeof(EncounterKind), packet.Kind) || !Enum.IsDefined(typeof(EncounterStatus), packet.Status) || (int)packet.Status == 4 || packet.Revision <= 0 || packet.Sources == null || packet.Sources.Length > 130 || string.IsNullOrWhiteSpace(packet.ActorName) || !Finite(packet.DurationSeconds) || !Finite(packet.Damage) || !Finite(packet.BossDamage) || !Finite(packet.SummonDamage) || packet.Sources.Any((SourceTotals x) => x == null || string.IsNullOrWhiteSpace(x.Id) || string.IsNullOrWhiteSpace(x.Name) || !Enum.IsDefined(typeof(DamageSourceKind), x.Kind) || !Finite(x.Damage) || !Finite(x.BossDamage) || !Finite(x.SummonDamage) || x.BossDamage + x.SummonDamage > x.Damage + 1E-06) || packet.Sources.Select((SourceTotals x) => x.Id).Distinct().Count() != packet.Sources.Length || !Close(packet.Sources.Sum((SourceTotals x) => x.Damage), packet.Damage) || !Close(packet.Sources.Sum((SourceTotals x) => x.BossDamage), packet.BossDamage) || !Close(packet.Sources.Sum((SourceTotals x) => x.SummonDamage), packet.SummonDamage))
				{
					return false;
				}
				SourceResponsePacket current = Current;
				if (current != null && current.Available && packet.Revision <= current.Revision)
				{
					return false;
				}
			}
			_lastAccepted = packet.RequestId;
			if (_cache.Count >= 512 && !_cache.ContainsKey(selection))
			{
				_cache.Remove(_cache.Keys.First());
			}
			_cache[selection] = packet;
			Message = ((!packet.Available) ? "Source details unavailable" : ((packet.Sources.Length == 0) ? "No damage recorded" : ""));
			return true;
		}

		public void Clear()
		{
			_cache.Clear();
			Selection = null;
			_session = "";
			_firstRequest = (_lastSent = (_lastAccepted = 0L));
			_next = 0.0;
			Message = "Loading damage sources…";
		}

		private static bool Finite(double value)
		{
			if (double.IsFinite(value))
			{
				return value >= 0.0;
			}
			return false;
		}

		private static bool Close(double a, double b)
		{
			return Math.Abs(a - b) <= Math.Max(1E-06, Math.Abs(b) * 1E-09);
		}

		public static SourceRow[] Rank(SourceResponsePacket detail, BossTargetFilter filter)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			bool bossOnly = (int)detail.ActorKind == 0 && (int)detail.Kind == 0 && (int)filter == 1;
			double total = (bossOnly ? detail.BossDamage : detail.Damage);
			return (from x in detail.Sources.Select(delegate(SourceTotals x)
				{
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					double num = (bossOnly ? x.BossDamage : x.Damage);
					return new SourceRow(x.Id, x.Name, x.Kind, x.PrefabHash, num, (detail.DurationSeconds > 0.0) ? (num / detail.DurationSeconds) : 0.0, (total > 0.0) ? (num / total) : 0.0);
				})
				where x.Damage > 0.0
				orderby x.Damage descending
				select x).ThenBy<SourceRow, string>((SourceRow x) => x.Id, StringComparer.Ordinal).ToArray();
		}
	}
	public sealed class SourceOriginCache
	{
		private readonly Dictionary<EntityKey, (DamageSource Source, double Seen)> _sources = new Dictionary<EntityKey, (DamageSource, double)>();

		public void Observe(EntityKey entity, DamageSource source, double now)
		{
			_sources[entity] = (source, now);
		}

		public DamageSource? Resolve(EntityKey entity, double now)
		{
			if (!_sources.TryGetValue(entity, out (DamageSource, double) value) || now - value.Item2 > 120.0)
			{
				return null;
			}
			_sources[entity] = (value.Item1, now);
			return value.Item1;
		}

		public void Prune(double now)
		{
			EntityKey[] array = (from x in _sources
				where now - x.Value.Seen > 120.0
				select x.Key).ToArray();
			foreach (EntityKey key in array)
			{
				_sources.Remove(key);
			}
		}

		public void Clear()
		{
			_sources.Clear();
		}
	}
}

BepInEx/plugins/CombatMeter/CombatMeter.Runtime.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using CombatMeter.Core;
using CombatMeter.Shared;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.UI;
using Unity.Collections;
using Unity.Entities;
using Unity.Entities.Internal;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CombatMeter.Runtime")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+7bf5d4af4539905a627ee336fb44ed2fa9bdee99")]
[assembly: AssemblyProduct("CombatMeter.Runtime")]
[assembly: AssemblyTitle("CombatMeter.Runtime")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.1.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 CombatMeter.Runtime
{
	internal static class HealthJobBridge
	{
		private static JobRunWithoutJobSystemDelegate? _original;

		private static JobRunWithoutJobSystemDelegate? _bridge;

		internal static long Calls { get; private set; }

		internal static void Install()
		{
			JobRunWithoutJobSystemDelegate functionPtrFieldBurst = ApplyChanges_Job.FunctionPtrFieldBurst;
			if (functionPtrFieldBurst != null && (_bridge == null || !(((Il2CppObjectBase)functionPtrFieldBurst).Pointer == ((Il2CppObjectBase)_bridge).Pointer)))
			{
				_original = functionPtrFieldBurst;
				if (_bridge == null)
				{
					_bridge = JobRunWithoutJobSystemDelegate.op_Implicit((Action<IntPtr>)Run);
				}
				ApplyChanges_Job.FunctionPtrFieldBurst = _bridge;
				((BasePlugin)RuntimeHost.Instance).Log.LogInfo((object)"CombatMeter stat-change job bridge installed; native non-Burst damage calculation selected for this job only.");
			}
		}

		private unsafe static void Run(IntPtr pointer)
		{
			Calls++;
			if (Calls == 1)
			{
				((BasePlugin)RuntimeHost.Instance).Log.LogInfo((object)"CombatMeter stat-change job bridge observed its first execution.");
			}
			((ApplyChanges_Job)(ref Unsafe.AsRef<ApplyChanges_Job>((void*)pointer))).OriginalLambdaBody();
		}

		internal static void Restore()
		{
			JobRunWithoutJobSystemDelegate functionPtrFieldBurst = ApplyChanges_Job.FunctionPtrFieldBurst;
			if (_bridge != null && _original != null && ((functionPtrFieldBurst != null) ? new IntPtr?(((Il2CppObjectBase)functionPtrFieldBurst).Pointer) : ((IntPtr?)null)) == ((Il2CppObjectBase)_bridge).Pointer)
			{
				ApplyChanges_Job.FunctionPtrFieldBurst = _original;
			}
			_original = null;
			_bridge = null;
		}
	}
	[HarmonyPatch(typeof(StatChangeSystem), "OnUpdate")]
	internal static class ServerTickPatch
	{
		[HarmonyPrefix]
		private static void Prefix()
		{
			HealthJobBridge.Install();
		}

		[HarmonyPostfix]
		private static void Postfix()
		{
			HealthJobBridge.Install();
		}
	}
	[HarmonyPatch(typeof(InputActionSystem), "OnUpdate")]
	internal static class ReviewInputPatch
	{
		[HarmonyPrefix]
		private static void Prefix(InputActionSystem __instance)
		{
			RuntimeHost.DispatchInput(__instance);
		}
	}
	public static class MessageBridge
	{
		public static event Action<EntityManager, Entity, string>? ServerReceived;

		public static event Action<string>? ClientReceived;

		internal unsafe static string Read(FixedString512Bytes text)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			ushort utf8LengthInBytes = text.utf8LengthInBytes;
			if (utf8LengthInBytes > 509)
			{
				return "";
			}
			return Encoding.UTF8.GetString((byte*)(&text) + 2, utf8LengthInBytes);
		}

		internal static void Receive(EntityManager manager, bool server)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00bd: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery val = ((EntityManager)(ref manager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { server ? ComponentType.ReadOnly<ChatMessageEvent>() : ComponentType.ReadOnly<ChatMessageServerEvent>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				for (int i = 0; i < val2.Length; i++)
				{
					Entity val3 = val2[i];
					string text = (server ? Read(((EntityManager)(ref manager)).GetComponentData<ChatMessageEvent>(val3).MessageText) : Read(((EntityManager)(ref manager)).GetComponentData<ChatMessageServerEvent>(val3).MessageText));
					if (!text.StartsWith("~CM4|", StringComparison.Ordinal))
					{
						continue;
					}
					if (server)
					{
						if (((EntityManager)(ref manager)).HasComponent<FromCharacter>(val3))
						{
							Entity user = ((EntityManager)(ref manager)).GetComponentData<FromCharacter>(val3).User;
							((EntityManager)(ref manager)).DestroyEntity(val3);
							if (((EntityManager)(ref manager)).Exists(user) && ((EntityManager)(ref manager)).HasComponent<User>(user) && ((EntityManager)(ref manager)).GetComponentData<User>(user).IsConnected)
							{
								MessageBridge.ServerReceived?.Invoke(manager, user, text);
							}
						}
					}
					else
					{
						ChatMessageServerEvent componentData = ((EntityManager)(ref manager)).GetComponentData<ChatMessageServerEvent>(val3);
						((EntityManager)(ref manager)).DestroyEntity(val3);
						if ((int)componentData.MessageType == 6)
						{
							MessageBridge.ClientReceived?.Invoke(text);
						}
					}
				}
			}
			finally
			{
				val2.Dispose();
				((EntityQuery)(ref val)).Dispose();
			}
		}

		internal static void ReceiveSafely(EntityManager manager, bool server)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			try
			{
				Receive(manager, server);
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)RuntimeHost.Instance).Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter native message delivery failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}

		public static void SendClient(World world, Entity user, string frame)
		{
			//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_0011: 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)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_002e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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)
			//IL_0056: 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)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = world.EntityManager;
			Entity val = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[3]
			{
				ComponentType.ReadWrite<ChatMessageEvent>(),
				ComponentType.ReadWrite<SendNetworkEventTag>(),
				ComponentType.ReadWrite<NetworkEventType>()
			});
			((EntityManager)(ref entityManager)).SetComponentData<ChatMessageEvent>(val, new ChatMessageEvent
			{
				MessageType = (ChatMessageType)3,
				ReceiverEntity = ((EntityManager)(ref entityManager)).GetComponentData<NetworkId>(user),
				MessageText = new FixedString512Bytes(frame)
			});
			((EntityManager)(ref entityManager)).SetComponentData<NetworkEventType>(val, new NetworkEventType
			{
				EventId = NetworkEvents.EventId_ChatMessageEvent
			});
		}

		public static void SendServer(EntityManager manager, User user, string frame)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			FixedString512Bytes val = default(FixedString512Bytes);
			((FixedString512Bytes)(ref val))..ctor(frame);
			ServerChatUtils.SendSystemMessageToClient(manager, user, ref val);
		}
	}
	[HarmonyPatch(typeof(ChatMessageSystem), "OnUpdate")]
	internal static class ServerMessagePatch
	{
		private static void Prefix(ChatMessageSystem __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			MessageBridge.ReceiveSafely(((ComponentSystemBase)__instance).EntityManager, server: true);
		}
	}
	[HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")]
	internal static class ClientMessagePatch
	{
		private static void Prefix(ClientChatSystem __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			MessageBridge.ReceiveSafely(((ComponentSystemBase)__instance).EntityManager, server: false);
		}
	}
	internal sealed class NativeHealthDetour : IDisposable
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		private delegate void ApplyHealth(IntPtr input, ulong changeEntity, IntPtr change, IntPtr commands, double time, IntPtr balance, IntPtr debug, IntPtr method);

		private readonly INativeDetour _detour;

		private readonly ApplyHealth _original;

		internal NativeHealthDetour()
		{
			if (!OperatingSystem.IsWindows() || IntPtr.Size != 8)
			{
				throw new PlatformNotSupportedException("CombatMeter native health capture currently requires Windows x64.");
			}
			RuntimeHelpers.RunClassConstructor(typeof(StatChangeSystem).TypeHandle);
			IntPtr intPtr = Marshal.ReadIntPtr((IntPtr)typeof(StatChangeSystem).GetFields(BindingFlags.Static | BindingFlags.NonPublic).Single((FieldInfo x) => x.Name.StartsWith("NativeMethodInfoPtr_ApplyHealthChangeToEntity_", StringComparison.Ordinal)).GetValue(null));
			if (intPtr == IntPtr.Zero)
			{
				throw new InvalidOperationException("Native health method pointer is unavailable.");
			}
			_detour = INativeDetour.CreateAndApply<ApplyHealth>(intPtr, (ApplyHealth)Invoke, ref _original);
		}

		private unsafe void Invoke(IntPtr input, ulong changeEntity, IntPtr changePointer, IntPtr commands, double time, IntPtr balance, IntPtr debug, IntPtr method)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			StatChangeEvent change = Unsafe.Read<StatChangeEvent>((void*)changePointer);
			float? before = null;
			bool flag = default(bool);
			try
			{
				before = RuntimeHost.CaptureBefore(change);
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)RuntimeHost.Instance).Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(35, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter health capture failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
			_original(input, changeEntity, changePointer, commands, time, balance, debug, method);
			try
			{
				RuntimeHost.CaptureAfter(change, before);
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = ((BasePlugin)RuntimeHost.Instance).Log;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter resolved damage capture failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
				}
				log2.LogWarning(val);
			}
		}

		public void Dispose()
		{
			((IDisposable)_detour).Dispose();
		}
	}
	[BepInPlugin("io.combatmeter.runtime", "CombatMeter Runtime", "0.2.1")]
	public sealed class RuntimeHost : BasePlugin
	{
		internal static RuntimeHost Instance;

		private Harmony? _harmony;

		private NativeHealthDetour? _health;

		public static long HealthJobCalls => HealthJobBridge.Calls;

		public static event Action? Frame;

		public static event Action<InputActionSystem>? Input;

		public static event Func<StatChangeEvent, float?>? BeforeHealth;

		public static event Action<StatChangeEvent, float?>? AfterHealth;

		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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			Instance = this;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter stable libraries ready: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(typeof(MeterState).Assembly.GetName().Name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(typeof(Protocol).Assembly.GetName().Name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
			}
			log.LogInfo(val);
			_harmony = new Harmony("io.combatmeter.runtime");
			if (Process.GetCurrentProcess().ProcessName == "VRisingServer")
			{
				_health = new NativeHealthDetour();
				_harmony.CreateClassProcessor(typeof(ServerTickPatch)).Patch();
				_harmony.CreateClassProcessor(typeof(ServerMessagePatch)).Patch();
			}
			else
			{
				_harmony.CreateClassProcessor(typeof(ReviewInputPatch)).Patch();
				_harmony.CreateClassProcessor(typeof(ClientMessagePatch)).Patch();
			}
			ClassInjector.RegisterTypeInIl2Cpp<RuntimeBehaviour>();
			((BasePlugin)this).AddComponent<RuntimeBehaviour>();
			((BasePlugin)this).Log.LogInfo((object)"CombatMeter persistent runtime ready; client/server logic may subscribe and reload independently.");
		}

		internal static void DispatchFrame()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			if (RuntimeHost.Frame == null)
			{
				return;
			}
			Delegate[] invocationList = RuntimeHost.Frame.GetInvocationList();
			bool flag = default(bool);
			for (int i = 0; i < invocationList.Length; i++)
			{
				Action action = (Action)invocationList[i];
				try
				{
					action();
				}
				catch (Exception ex)
				{
					ManualLogSource log = ((BasePlugin)Instance).Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(35, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter frame callback failed: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val);
				}
			}
		}

		internal static void DispatchInput(InputActionSystem system)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			try
			{
				RuntimeHost.Input?.Invoke(system);
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)Instance).Log;
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter input context unavailable: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogDebug(val);
			}
		}

		internal static float? CaptureBefore(StatChangeEvent change)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return RuntimeHost.BeforeHealth?.Invoke(change);
		}

		internal static void CaptureAfter(StatChangeEvent change, float? before)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			RuntimeHost.AfterHealth?.Invoke(change, before);
		}

		public override bool Unload()
		{
			return false;
		}
	}
	public sealed class RuntimeBehaviour : MonoBehaviour
	{
		public RuntimeBehaviour(IntPtr pointer)
			: base(pointer)
		{
		}

		public void Update()
		{
			RuntimeHost.DispatchFrame();
		}
	}
}

BepInEx/plugins/CombatMeter/CombatMeter.Server.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 System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CombatMeter.Core;
using CombatMeter.Runtime;
using CombatMeter.Shared;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Behaviours;
using ProjectM.Contest;
using ProjectM.Network;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyMetadata("Reloadable", "true")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CombatMeter.Server")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+7bf5d4af4539905a627ee336fb44ed2fa9bdee99")]
[assembly: AssemblyProduct("CombatMeter.Server")]
[assembly: AssemblyTitle("CombatMeter.Server")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[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 CombatMeter.Server
{
	internal sealed class DamageSourceResolver
	{
		private static class Component<T>
		{
			internal static readonly ComponentType Type = ComponentType.ReadOnly(Il2CppType.Of<T>());
		}

		private readonly World _world;

		private readonly EntityManager _manager;

		private readonly SourceOriginCache _cache = new SourceOriginCache();

		private readonly Dictionary<int, string> _names = new Dictionary<int, string>();

		private bool _catalogLoaded;

		public DamageSourceResolver(World world)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			_world = world;
			_manager = world.EntityManager;
		}

		private bool Has<T>(Entity e)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0016: 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)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (e != Entity.Null)
			{
				EntityManager manager = _manager;
				if (((EntityManager)(ref manager)).Exists(e))
				{
					manager = _manager;
					return ((EntityManager)(ref manager)).HasComponent(e, Component<T>.Type);
				}
			}
			return false;
		}

		private unsafe T Read<T>(Entity e) where T : unmanaged
		{
			//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_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager manager = _manager;
			return Unsafe.Read<T>(((EntityManager)(ref manager)).GetComponentDataRawRO(e, Component<T>.Type.TypeIndex));
		}

		private static EntityKey Key(Entity e)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			return new EntityKey(e.Index, e.Version);
		}

		public DamageSource Resolve(StatChangeEvent change, double now)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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)
			//IL_0040: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Entity val = change.Source;
			if (Has<DealDamageEvent>(change.StatChangeEntity))
			{
				val = Read<DealDamageEvent>(change.StatChangeEntity).SpellSource;
			}
			else if (Has<DealDamageEvent>(val))
			{
				val = Read<DealDamageEvent>(val).SpellSource;
			}
			return Observe(val, now) ?? DamageSource.Unknown;
		}

		public DamageSource? Observe(Entity effect, double now)
		{
			//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_000a: 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)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Invalid comparison between Unknown and I4
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: 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_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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)
			EntityManager manager = _manager;
			if (!((EntityManager)(ref manager)).Exists(effect))
			{
				return _cache.Resolve(Key(effect), now);
			}
			if (Has<PlayerCharacter>(effect))
			{
				return null;
			}
			DamageSource val = _cache.Resolve(Key(effect), now);
			DamageSource val2 = null;
			Entity val3 = effect;
			HashSet<EntityKey> hashSet = new HashSet<EntityKey>();
			while (true)
			{
				manager = _manager;
				if (!((EntityManager)(ref manager)).Exists(val3) || !hashSet.Add(Key(val3)) || hashSet.Count > 32 || Has<PlayerCharacter>(val3) || (Has<Health>(val3) && Has<Movement>(val3)))
				{
					break;
				}
				if (Has<Buff>(val3) && (int)Read<Buff>(val3).BuffEffectType == 0)
				{
					val2 = Describe(val3, (DamageSourceKind)2);
					break;
				}
				if (Has<AbilityOwner>(val3))
				{
					AbilityOwner val4 = Read<AbilityOwner>(val3);
					Entity entityOnServer = ((NetworkedEntity)(ref val4.AbilityGroup)).GetEntityOnServer();
					manager = _manager;
					if (((EntityManager)(ref manager)).Exists(entityOnServer))
					{
						val2 = Describe(entityOnServer, (DamageSourceKind)((IsWeapon(entityOnServer) || IsWeapon(val3)) ? 1 : 0));
						if (val2 != null)
						{
							break;
						}
					}
				}
				if (val2 == null)
				{
					val2 = DescribeEffect(val3);
				}
				if (!Has<EntityOwner>(val3))
				{
					break;
				}
				val3 = Read<EntityOwner>(val3).Owner;
			}
			Entity? val5 = SummonOrigin(effect);
			if (val5.HasValue)
			{
				Entity valueOrDefault = val5.GetValueOrDefault();
				DamageSource val6 = Describe(valueOrDefault, (DamageSourceKind)4);
				if (val6 != null)
				{
					DamageSource obj;
					if (val2 != null)
					{
						obj = val2.<Clone>$();
						obj.set_Id(val6.Id + ":" + val2.Id);
						obj.set_Name(val6.Name + " · " + val2.Name);
					}
					else
					{
						obj = val6.<Clone>$();
						obj.set_Name(val6.Name + " attacks");
					}
					val2 = obj;
				}
			}
			if (val != null)
			{
				if (val2 == null || (val.Id.StartsWith("Summon:", StringComparison.Ordinal) && !val2.Id.StartsWith("Summon:", StringComparison.Ordinal)))
				{
					goto IL_022f;
				}
				if (Has<PrefabGUID>(effect))
				{
					int prefabHash = val.PrefabHash;
					PrefabGUID val7 = Read<PrefabGUID>(effect);
					if (prefabHash != ((PrefabGUID)(ref val7)).GuidHash)
					{
						int prefabHash2 = val2.PrefabHash;
						val7 = Read<PrefabGUID>(effect);
						if (prefabHash2 == ((PrefabGUID)(ref val7)).GuidHash)
						{
							goto IL_022f;
						}
					}
				}
			}
			goto IL_0231;
			IL_022f:
			val2 = val;
			goto IL_0231;
			IL_0231:
			if (val2 != null && (!Has<Health>(effect) || !Has<Movement>(effect) || (int)val2.Kind == 4))
			{
				_cache.Observe(Key(effect), val2, now);
			}
			return val2;
		}

		private Entity? SummonOrigin(Entity effect)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_001e: 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_0027: 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_0055: 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)
			//IL_005f: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			Entity? result = null;
			HashSet<EntityKey> hashSet = new HashSet<EntityKey>();
			Entity val = effect;
			while (true)
			{
				EntityManager manager = _manager;
				if (!((EntityManager)(ref manager)).Exists(val) || !hashSet.Add(Key(val)) || hashSet.Count > 32)
				{
					break;
				}
				if (Has<PlayerCharacter>(val))
				{
					return result;
				}
				if (Has<Health>(val) && Has<Movement>(val))
				{
					Entity valueOrDefault = result.GetValueOrDefault();
					if (!result.HasValue)
					{
						valueOrDefault = val;
						result = valueOrDefault;
					}
				}
				if (!Has<EntityOwner>(val))
				{
					break;
				}
				val = Read<EntityOwner>(val).Owner;
			}
			return null;
		}

		private DamageSource? DescribeEffect(Entity entity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			if (!Has<PrefabGUID>(entity))
			{
				return null;
			}
			PrefabGUID val = Read<PrefabGUID>(entity);
			int guidHash = ((PrefabGUID)(ref val)).GuidHash;
			string text = RawName(guidHash);
			if (IsWeapon(entity))
			{
				return Describe(entity, (DamageSourceKind)1);
			}
			if (Has<Buff>(entity))
			{
				return Describe(entity, (DamageSourceKind)3);
			}
			if (!text.StartsWith("AB_", StringComparison.Ordinal))
			{
				return null;
			}
			return Describe(entity, (DamageSourceKind)0);
		}

		private bool IsWeapon(Entity entity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0019: 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)
			if (Has<WeaponAbilityData>(entity))
			{
				return true;
			}
			if (!Has<PrefabGUID>(entity))
			{
				return false;
			}
			PrefabGUID val = Read<PrefabGUID>(entity);
			return Regex.IsMatch(RawName(((PrefabGUID)(ref val)).GuidHash), "^AB_Vampire_(Sword|Axe|Axes|Mace|Spear|Reaper|Slasher|Slashers|GreatSword|Pistols|Crossbow|Longbow|Whip|Rapier|Daggers|Twinblade|Twinblades|Claws)_");
		}

		private DamageSource? Describe(Entity entity, DamageSourceKind kind)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			if (!Has<PrefabGUID>(entity))
			{
				return null;
			}
			PrefabGUID val = Read<PrefabGUID>(entity);
			int guidHash = ((PrefabGUID)(ref val)).GuidHash;
			string text = RawName(guidHash);
			if (text.Length == 0)
			{
				return null;
			}
			string input = Regex.Replace(text, "^(AB_|BUFF_|Buff_|CHAR_)", "");
			input = Regex.Replace(input, "_(AbilityGroup|Group)$", "");
			input = Regex.Replace(input, "(?<=[a-z])(?=[A-Z])", " ").Replace('_', ' ');
			input = Regex.Replace(input, "\\s+", " ").Trim();
			if (input.Length > 120)
			{
				input = input.Substring(0, 120);
			}
			return new DamageSource($"{kind}:{guidHash}", input, kind, guidHash);
		}

		private string RawName(int hash)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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)
			if (!_catalogLoaded)
			{
				PrefabCollectionSystem existingSystemManaged = _world.GetExistingSystemManaged<PrefabCollectionSystem>();
				if (existingSystemManaged != null && existingSystemManaged.SpawnableNameToPrefabGuidDictionary.Count > 0)
				{
					Enumerator<string, PrefabGUID> enumerator = existingSystemManaged.SpawnableNameToPrefabGuidDictionary.GetEnumerator();
					while (enumerator.MoveNext())
					{
						KeyValuePair<string, PrefabGUID> current = enumerator.Current;
						Dictionary<int, string> names = _names;
						PrefabGUID value = current.Value;
						names[((PrefabGUID)(ref value)).GuidHash] = current.Key;
					}
					_catalogLoaded = true;
				}
			}
			if (_names.TryGetValue(hash, out string value2))
			{
				return value2;
			}
			PrefabCollectionSystem existingSystemManaged2 = _world.GetExistingSystemManaged<PrefabCollectionSystem>();
			ConvertedAssetData data = default(ConvertedAssetData);
			if (existingSystemManaged2 != null && PrefabLookupUtility.TryGetConvertedAssetDataForPrefab(new PrefabGUID(hash), ref data))
			{
				string text = AssetName(data);
				if (!string.IsNullOrWhiteSpace(text))
				{
					_names[hash] = text;
					return text;
				}
			}
			return _names[hash] = "";
		}

		private unsafe static string AssetName(ConvertedAssetData data)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			FixedString128Bytes assetName = data.AssetName;
			ushort utf8LengthInBytes = assetName.utf8LengthInBytes;
			if (utf8LengthInBytes == 0 || utf8LengthInBytes > 126 || Unsafe.SizeOf<FixedString128Bytes>() < utf8LengthInBytes + 2)
			{
				return "";
			}
			string text = Encoding.UTF8.GetString((byte*)(&assetName) + 2, utf8LengthInBytes);
			if (!Regex.IsMatch(text, "^[A-Za-z0-9_]+$"))
			{
				return "";
			}
			return text;
		}

		public void Prune(double now)
		{
			_cache.Prune(now);
		}
	}
	internal sealed class NativeArrayLease<T> : IDisposable where T : unmanaged
	{
		private readonly NativeArray<T> _array;

		public int Length => _array.Length;

		public T this[int index] => _array[index];

		public NativeArrayLease(NativeArray<T> array)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			_array = array;
		}

		public IEnumerator<T> GetEnumerator()
		{
			for (int index = 0; index < _array.Length; index++)
			{
				yield return _array[index];
			}
		}

		public void Dispose()
		{
			//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)
			_array.Dispose();
		}
	}
	internal static class NativeArrayQueries
	{
		public static NativeArrayLease<Entity> ToEntityArrayAccessor(this EntityQuery query, Allocator allocator)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new NativeArrayLease<Entity>(((EntityQuery)(ref query)).ToEntityArray(AllocatorHandle.op_Implicit(allocator)));
		}

		public static NativeArrayLease<T> ToComponentDataArrayAccessor<T>(this EntityQuery query, Allocator allocator) where T : unmanaged
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new NativeArrayLease<T>(((EntityQuery)(ref query)).ToComponentDataArray<T>(AllocatorHandle.op_Implicit(allocator)));
		}
	}
	internal sealed class NativeTransport : IDisposable
	{
		private sealed class Peer
		{
			public string Channel = "";

			public readonly WireInbox Inbox = new WireInbox();

			public long Serial;

			public double Window;

			public double LastRegistration = double.NegativeInfinity;

			public int Requests;
		}

		private readonly ServerRuntime _runtime;

		private readonly Plugin _plugin;

		private readonly HashSet<ulong> _subscribers = new HashSet<ulong>();

		private readonly Dictionary<ulong, double> _historyRequested = new Dictionary<ulong, double>();

		private readonly Dictionary<ulong, double> _detailsRequested = new Dictionary<ulong, double>();

		private readonly Dictionary<ulong, Peer> _peers = new Dictionary<ulong, Peer>();

		internal int SubscriberCount => _subscribers.Count;

		public NativeTransport(ServerRuntime runtime, Plugin plugin)
		{
			_runtime = runtime;
			_plugin = plugin;
			MessageBridge.ServerReceived += Receive;
		}

		private void Receive(EntityManager manager, Entity senderEntity, string frame)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			User componentData = ((EntityManager)(ref manager)).GetComponentData<User>(senderEntity);
			if (!componentData.IsConnected)
			{
				return;
			}
			if (!_peers.TryGetValue(componentData.PlatformId, out Peer value))
			{
				if (_peers.Count >= 128)
				{
					return;
				}
				value = (_peers[componentData.PlatformId] = new Peer());
			}
			double now = _runtime.Now;
			if (now - value.Window >= 1.0)
			{
				value.Window = now;
				value.Requests = 0;
			}
			if (++value.Requests > 12)
			{
				return;
			}
			string text = default(string);
			object obj = value.Inbox.Receive(frame, (string)null, true, now, ref text);
			RegistrationPacket val = (RegistrationPacket)((obj is RegistrationPacket) ? obj : null);
			if (val != null)
			{
				if (!(now - value.LastRegistration < 2.0))
				{
					value.LastRegistration = now;
					value.Channel = text;
					Register(componentData, val);
				}
			}
			else
			{
				if (!(text == value.Channel))
				{
					return;
				}
				HistoryRequestPacket val2 = (HistoryRequestPacket)((obj is HistoryRequestPacket) ? obj : null);
				if (val2 != null)
				{
					History(componentData, val2);
					return;
				}
				SourceRequestPacket val3 = (SourceRequestPacket)((obj is SourceRequestPacket) ? obj : null);
				if (val3 != null)
				{
					Details(componentData, val3);
				}
			}
		}

		private void SendPacket<T>(User user, T packet)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (!_peers.TryGetValue(user.PlatformId, out Peer value) || value.Channel.Length == 0)
			{
				return;
			}
			foreach (string item in WireCodec.Encode<T>(value.Channel, ++value.Serial, packet))
			{
				MessageBridge.SendServer(_runtime.Manager, user, item);
			}
		}

		private void Register(User sender, RegistrationPacket packet)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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)
			if (!sender.IsConnected)
			{
				return;
			}
			bool flag = packet.ProtocolVersion == 4;
			SendPacket<PolicyPacket>(sender, _runtime.Policy(flag, flag ? "" : "CombatMeter protocol version does not match the server"));
			if (!flag)
			{
				_subscribers.Remove(sender.PlatformId);
				return;
			}
			_subscribers.Add(sender.PlatformId);
			ManualLogSource log = ((BasePlugin)_plugin).Log;
			bool flag2 = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(70, 2, ref flag2);
			if (flag2)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[CombatMeter:Transport] client registration received; user=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(sender.PlatformId);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; protocol=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(packet.ProtocolVersion);
			}
			log.LogInfo(val);
			SendHistory(sender);
		}

		private void History(User sender, HistoryRequestPacket packet)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			if (_subscribers.Contains(sender.PlatformId) && packet.ProtocolVersion == 4 && !(packet.ServerSessionId != _runtime.Tracker.SessionId))
			{
				double now = _runtime.Now;
				if (!_historyRequested.TryGetValue(sender.PlatformId, out var value) || !(now - value < 1.0))
				{
					_historyRequested[sender.PlatformId] = now;
					SendHistory(sender);
				}
			}
		}

		private void Details(User sender, SourceRequestPacket packet)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_000e: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (!sender.IsConnected || !_subscribers.Contains(sender.PlatformId) || packet.ProtocolVersion != 4 || packet.ServerSessionId != _runtime.Tracker.SessionId)
			{
				return;
			}
			double now = _runtime.Now;
			if (_detailsRequested.TryGetValue(sender.PlatformId, out var value) && now - value < 0.48)
			{
				return;
			}
			_detailsRequested[sender.PlatformId] = now;
			try
			{
				SendPacket<SourceResponsePacket>(sender, _runtime.Tracker.Details(sender.PlatformId, packet, now));
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)_plugin).Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter source delivery failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}

		private void SendHistory(User user)
		{
			//IL_000b: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			foreach (EncounterSnapshot item in _runtime.Tracker.History(user.PlatformId).Reverse())
			{
				Send(user, item);
			}
			EncounterSnapshot[] array = _runtime.Tracker.Active(_runtime.Now);
			foreach (EncounterSnapshot val in array)
			{
				if (_runtime.Tracker.CanObserve(val.Id, user.PlatformId))
				{
					Send(user, val);
				}
			}
		}

		public void Flush(double now)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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)
			ulong[] array = _peers.Keys.Where((ulong id) => !_runtime.FindUser(id).HasValue).ToArray();
			foreach (ulong num2 in array)
			{
				_peers.Remove(num2);
				_subscribers.Remove(num2);
				_historyRequested.Remove(num2);
				_detailsRequested.Remove(num2);
			}
			EncounterSnapshot[] array2 = _runtime.Tracker.Active(now);
			array = _subscribers.ToArray();
			foreach (ulong num3 in array)
			{
				User? val = _runtime.FindUser(num3);
				if (val.HasValue)
				{
					User valueOrDefault = val.GetValueOrDefault();
					EncounterSnapshot[] array3 = array2;
					foreach (EncounterSnapshot val2 in array3)
					{
						if (_runtime.Tracker.CanObserve(val2.Id, num3))
						{
							Send(valueOrDefault, val2);
						}
					}
				}
				else
				{
					_subscribers.Remove(num3);
					_historyRequested.Remove(num3);
					_detailsRequested.Remove(num3);
					_peers.Remove(num3);
				}
			}
		}

		public void PublishFinal(EncounterSnapshot snapshot, IReadOnlyCollection<ulong> audience)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			ulong[] array = _subscribers.ToArray();
			foreach (ulong num in array)
			{
				if (audience.Contains(num))
				{
					User? val = _runtime.FindUser(num);
					if (val.HasValue)
					{
						User valueOrDefault = val.GetValueOrDefault();
						Send(valueOrDefault, snapshot);
					}
				}
			}
		}

		private void Send(User user, EncounterSnapshot snapshot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0031: Expected O, but got Unknown
			try
			{
				if ((int)snapshot.Status == 0)
				{
					SendPacket<EncounterPacket>(user, new EncounterPacket
					{
						ServerSessionId = _runtime.Tracker.SessionId,
						Encounter = snapshot
					});
				}
				else
				{
					SendPacket<EncounterCompletedPacket>(user, new EncounterCompletedPacket
					{
						ServerSessionId = _runtime.Tracker.SessionId,
						Encounter = snapshot
					});
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = ((BasePlugin)_plugin).Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter packet delivery failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val);
			}
		}

		public void Reset()
		{
			_subscribers.Clear();
			_historyRequested.Clear();
			_detailsRequested.Clear();
			_peers.Clear();
		}

		internal void NotifyReload()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			ulong[] array = _subscribers.ToArray();
			bool flag = default(bool);
			foreach (ulong id in array)
			{
				User? val = _runtime.FindUser(id);
				if (!val.HasValue)
				{
					continue;
				}
				User valueOrDefault = val.GetValueOrDefault();
				try
				{
					SendPacket<PolicyPacket>(valueOrDefault, _runtime.Policy(accepted: false, "CombatMeter collector reloading"));
				}
				catch (Exception ex)
				{
					ManualLogSource log = ((BasePlugin)_plugin).Log;
					BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(33, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Reload notification unavailable: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					}
					log.LogDebug(val2);
				}
			}
		}

		public void Dispose()
		{
			Reset();
			MessageBridge.ServerReceived -= Receive;
		}
	}
	[BepInPlugin("io.combatmeter.server", "CombatMeter Server", "0.2.1")]
	[BepInProcess("VRisingServer.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BasePlugin
	{
		internal static Plugin Instance;

		internal static ServerRuntime? Runtime;

		public override void Load()
		{
			Instance = this;
			Runtime = new ServerRuntime(this);
			RuntimeHost.Frame += Runtime.Tick;
			RuntimeHost.BeforeHealth += Runtime.BeforeHealth;
			RuntimeHost.AfterHealth += Runtime.AfterHealth;
			((BasePlugin)this).Log.LogInfo((object)"CombatMeter server loaded; native damage callbacks attached to persistent runtime.");
		}

		public override bool Unload()
		{
			ServerRuntime runtime = Runtime;
			if (runtime != null)
			{
				RuntimeHost.Frame -= runtime.Tick;
				RuntimeHost.BeforeHealth -= runtime.BeforeHealth;
				RuntimeHost.AfterHealth -= runtime.AfterHealth;
				Runtime = null;
				runtime.NotifyReload();
				runtime.Dispose();
			}
			((BasePlugin)this).Log.LogInfo((object)"CombatMeter server unloaded; collector callbacks and packet handlers released.");
			return true;
		}
	}
	internal sealed class ServerRuntime : IDisposable
	{
		private readonly Plugin _plugin;

		private readonly Dictionary<EncounterKind, ConfigEntry<bool>> _modes = new Dictionary<EncounterKind, ConfigEntry<bool>>();

		private readonly ConfigEntry<double> _timeout;

		private readonly ConfigEntry<bool> _audit;

		private readonly OwnershipCache _ownership = new OwnershipCache();

		private readonly Dictionary<EntityKey, (CreatureParticipant Creature, double Seen)> _creatureOrigins = new Dictionary<EntityKey, (CreatureParticipant, double)>();

		private readonly Dictionary<int, string> _prefabNames = new Dictionary<int, string>();

		private readonly Dictionary<EntityKey, Entity> _bosses = new Dictionary<EntityKey, Entity>();

		private readonly Dictionary<EntityKey, EntityKey> _bossOwners = new Dictionary<EntityKey, EntityKey>();

		private readonly Dictionary<EntityKey, (EncounterKind Kind, string Key)> _contests = new Dictionary<EntityKey, (EncounterKind, string)>();

		private readonly Dictionary<EntityKey, (EncounterKind Kind, string Key, int Team)> _contestPlayers = new Dictionary<EntityKey, (EncounterKind, string, int)>();

		private World? _world;

		private EntityManager _manager;

		private DamageSourceResolver? _sources;

		private readonly Stack<DamageSource> _healthSources = new Stack<DamageSource>();

		private EntityQuery _contestQuery;

		private EntityQuery _userQuery;

		private EntityQuery _bossQuery;

		private EntityQuery _timeQuery;

		private EntityQuery _finishedQuery;

		private EntityQuery _cancelledQuery;

		private EntityQuery _spawnQuery;

		private EntityQuery _buffQuery;

		private double _nextPush;

		private double _nextPrune;

		private long _serial;

		private double _nextErrorLog;

		private bool _clockReady;

		private double _nextDiagnostics;

		internal long HealthHookCalls { get; private set; }

		internal long RoutedDamageEvents { get; private set; }

		public long CapturedHealthChanges { get; private set; }

		internal EncounterTracker Tracker { get; private set; } = new EncounterTracker((TrackingPolicy)null);

		internal NativeTransport Transport { get; }

		internal EntityManager Manager => _manager;

		internal double Now
		{
			get
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				if (_world == null || !_world.IsCreated)
				{
					return 0.0;
				}
				return ((EntityQuery)(ref _timeQuery)).GetSingleton<ServerTime>().Time;
			}
		}

		public unsafe ServerRuntime(Plugin plugin)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_0108: Expected O, but got Unknown
			_plugin = plugin;
			EncounterKind[] values = Enum.GetValues<EncounterKind>();
			for (int i = 0; i < values.Length; i++)
			{
				EncounterKind key = values[i];
				_modes[key] = ((BasePlugin)plugin).Config.Bind<bool>("Tracking", ((object)(*(EncounterKind*)(&key))/*cast due to .constrained prefix*/).ToString(), true, "Collect this encounter type. Client visibility settings cannot enable server-disabled tracking.");
			}
			_timeout = ((BasePlugin)plugin).Config.Bind<double>("Tracking", "CombatTimeoutSeconds", 10.0, new ConfigDescription("Quiet period that ends ordinary PvP/PvE segments. The idle tail is excluded from DPS.", (AcceptableValueBase)(object)new AcceptableValueRange<double>(1.0, 120.0), Array.Empty<object>()));
			_audit = ((BasePlugin)plugin).Config.Bind<bool>("Diagnostics", "LogResolvedDamage", false, "Log each measured target health delta for real-game verification. Leave off for normal play.");
			Transport = new NativeTransport(this, plugin);
		}

		private bool EnsureWorld()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00c2: Expected O, but got Unknown
			//IL_00cb: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0129: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			if (_world != null && !_world.IsCreated)
			{
				ResetWorld();
			}
			if (_world != null)
			{
				return ((EntityQuery)(ref _timeQuery)).CalculateEntityCount() == 1;
			}
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			bool flag = default(bool);
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.IsCreated && current.Name.Equals("Server", StringComparison.OrdinalIgnoreCase))
				{
					_world = current;
					_manager = current.EntityManager;
					_sources = new DamageSourceResolver(current);
					_contestQuery = Query<ContestInstance>();
					_userQuery = Query<User>();
					_bossQuery = Query<VBloodUnit>();
					ref EntityManager manager = ref _manager;
					EntityQueryDesc[] array = new EntityQueryDesc[1];
					EntityQueryDesc val = new EntityQueryDesc();
					val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<ServerTime>() });
					val.Options = (EntityQueryOptions)16;
					array[0] = val;
					_timeQuery = ((EntityManager)(ref manager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
					_finishedQuery = Query<FinishedEvent>();
					_cancelledQuery = Query<CancelledEvent>();
					ref EntityManager manager2 = ref _manager;
					EntityQueryDesc[] array2 = new EntityQueryDesc[1];
					val = new EntityQueryDesc();
					val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
					{
						ComponentType.ReadOnly<SpawnTag>(),
						ComponentType.ReadOnly<EntityOwner>()
					});
					val.Options = (EntityQueryOptions)64;
					array2[0] = val;
					_spawnQuery = ((EntityManager)(ref manager2)).CreateEntityQuery((EntityQueryDesc[])(object)array2);
					_buffQuery = ((EntityManager)(ref _manager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[3]
					{
						ComponentType.ReadOnly<Buff>(),
						ComponentType.ReadOnly<PrefabGUID>(),
						ComponentType.ReadOnly<EntityOwner>()
					});
					TrackingPolicy val2 = new TrackingPolicy();
					val2.set_EnabledModes((from x in _modes
						where x.Value.Value
						select x.Key).ToHashSet());
					val2.set_TimeoutSeconds(_timeout.Value);
					Tracker = new EncounterTracker(val2);
					Tracker.FinishedForAudience += OnFinished;
					ManualLogSource log = ((BasePlugin)_plugin).Log;
					BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(66, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("CombatMeter server world ready; session=");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(Tracker.SessionId);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("; snapshot interval=250ms.");
					}
					log.LogInfo(val3);
					return ((EntityQuery)(ref _timeQuery)).CalculateEntityCount() == 1;
				}
			}
			return false;
		}

		private EntityQuery Query<T>() where T : struct
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			ref EntityManager manager = ref _manager;
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<T>() });
			val.Options = (EntityQueryOptions)192;
			array[0] = val;
			return ((EntityManager)(ref manager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
		}

		private bool Has<T>(Entity entity) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			if (entity != Entity.Null && ((EntityManager)(ref _manager)).Exists(entity))
			{
				return ((EntityManager)(ref _manager)).HasComponent<T>(entity);
			}
			return false;
		}

		private T Read<T>(Entity entity) where T : struct
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return ((EntityManager)(ref _manager)).GetComponentData<T>(entity);
		}

		private static EntityKey Key(Entity entity)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			return new EntityKey(entity.Index, entity.Version);
		}

		internal void Tick()
		{
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			try
			{
				if (!EnsureWorld())
				{
					return;
				}
				double now = Now;
				if (_audit.Value && now >= _nextDiagnostics)
				{
					_nextDiagnostics = now + 15.0;
					ManualLogSource log = ((BasePlugin)_plugin).Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(102, 6, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[CombatMeter:Diagnostics] healthJobCalls=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(RuntimeHost.HealthJobCalls);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; healthHookCalls=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(HealthHookCalls);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; captured=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(CapturedHealthChanges);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; routed=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(RoutedDamageEvents);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; active=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Tracker.ActiveCount);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; subscribers=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Transport.SubscriberCount);
					}
					log.LogInfo(val);
				}
				if (!_clockReady)
				{
					_clockReady = true;
					ManualLogSource log2 = ((BasePlugin)_plugin).Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(70, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter collector ticking; native server time=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(now, "R");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; V Blood entities=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(((EntityQuery)(ref _bossQuery)).CalculateEntityCount());
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					}
					log2.LogInfo(val);
				}
				CaptureSpawnOwnership(now);
				PollEndEvents(now);
				if (now < _nextPush)
				{
					return;
				}
				_nextPush = now + 0.25;
				PollContests(now);
				PollBosses(now);
				Tracker.Tick(now);
				Transport.Flush(now);
				if (now >= _nextPrune)
				{
					_nextPrune = now + 10.0;
					_ownership.Prune(now, 120.0);
					_sources?.Prune(now);
					EntityKey[] array = (from x in _creatureOrigins
						where now - x.Value.Seen > 120.0
						select x.Key).ToArray();
					foreach (EntityKey key in array)
					{
						_creatureOrigins.Remove(key);
					}
					array = _bossOwners.Keys.Where((EntityKey x) => !Exists(x)).ToArray();
					foreach (EntityKey key2 in array)
					{
						_bossOwners.Remove(key2);
					}
				}
			}
			catch (Exception ex)
			{
				if (Time.realtimeSinceStartupAsDouble >= _nextErrorLog)
				{
					_nextErrorLog = Time.realtimeSinceStartupAsDouble + 10.0;
					ManualLogSource log3 = ((BasePlugin)_plugin).Log;
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CombatMeter update failed: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					}
					log3.LogError(val2);
				}
			}
		}

		private bool Exists(EntityKey key)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return ((EntityManager)(ref _manager)).Exists(new Entity
			{
				Index = ((EntityKey)(ref key)).Index,
				Version = ((EntityKey)(ref key)).Version
			});
		}

		private void CaptureSpawnOwnership(double now)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0038: 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_004c: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			using NativeArrayLease<Entity> nativeArrayLease = _spawnQuery.ToEntityArrayAccessor((Allocator)2);
			bool flag = default(bool);
			foreach (Entity item in nativeArrayLease)
			{
				_ownership.ObserveOwner(Key(item), Key(Read<EntityOwner>(item).Owner), now);
				ResolvePlayer(item);
				ResolveCreature(item);
				TryBossOwner(item, out var _);
				try
				{
					_sources?.Observe(item, now);
				}
				catch (Exception ex)
				{
					ManualLogSource log = ((BasePlugin)_plugin).Log;
					BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(38, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CombatMeter spawn source unavailable: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogDebug(val);
				}
			}
		}

		internal User? FindUser(ulong id)
		{
			//IL_0013: 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_002e: 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)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!EnsureWorld())
			{
				return null;
			}
			using NativeArrayLease<User> nativeArrayLease = _userQuery.ToComponentDataArrayAccessor<User>((Allocator)2);
			foreach (User item in nativeArrayLease)
			{
				if (item.PlatformId == id && item.IsConnected)
				{
					return item;
				}
			}
			return null;
		}

		internal PolicyPacket Policy(bool accepted, string reason = "")
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0024: 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_0056: Expected O, but got Unknown
			return new PolicyPacket
			{
				Accepted = accepted,
				Reason = reason,
				ServerSessionId = Tracker.SessionId,
				EnabledModes = Tracker.Policy.EnabledModes.ToArray(),
				CombatTimeoutSeconds = Tracker.Policy.TimeoutSeconds
			};
		}

		private unsafe Participant? ResolvePlayer(Entity source)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002a: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_009b: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00c2: 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)
			Entity val = source;
			Participant val4 = default(Participant);
			for (int i = 0; i < 32; i++)
			{
				if (!(val != Entity.Null))
				{
					break;
				}
				if (!((EntityManager)(ref _manager)).Exists(val))
				{
					break;
				}
				if (Has<PlayerCharacter>(val))
				{
					PlayerCharacter val2 = Read<PlayerCharacter>(val);
					if (Has<User>(val2.UserEntity))
					{
						User val3 = Read<User>(val2.UserEntity);
						((Participant)(ref val4))..ctor(val3.PlatformId, ((object)(*(FixedString64Bytes*)(&val2.Name))/*cast due to .constrained prefix*/).ToString(), 0);
						_ownership.ObservePlayer(Key(val), val4, Now);
					}
					break;
				}
				if (!Has<EntityOwner>(val))
				{
					break;
				}
				Entity owner = Read<EntityOwner>(val).Owner;
				if (owner == val)
				{
					break;
				}
				_ownership.ObserveOwner(Key(val), Key(owner), Now);
				val = owner;
			}
			return _ownership.Resolve(Key(source), Now);
		}

		internal float? BeforeHealth(StatChangeEvent change)
		{
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			_healthSources.Push(DamageSource.Unknown);
			HealthHookCalls++;
			if (HealthHookCalls == 1)
			{
				((BasePlugin)_plugin).Log.LogInfo((object)"CombatMeter native health hook observed its first operation.");
			}
			if (!EnsureWorld())
			{
				return null;
			}
			bool flag = default(bool);
			if (_audit.Value)
			{
				ManualLogSource log = ((BasePlugin)_plugin).Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(72, 7, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[CombatMeter:HealthOperation] source=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(change.Source.Index);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(change.Source.Version);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" target=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(change.Entity.Index);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(":");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(change.Entity.Version);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" type=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<StatType>(change.StatType);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" change=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(change.Change, "R");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" hasHealth=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(Has<Health>(change.Entity));
				}
				log.LogInfo(val);
			}
			PollEndEvents(Now);
			if (change.Change >= 0f || !Has<Health>(change.Entity))
			{
				return null;
			}
			try
			{
				DamageSource item = _sources?.Resolve(change, Now) ?? DamageSource.Unknown;
				if (_healthSources.Count > 0)
				{
					_healthSources.Pop();
				}
				_healthSources.Push(item);
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = ((BasePlugin)_plugin).Log;
				BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("CombatMeter damage source unavailable: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log2.LogDebug(val2);
			}
			ResolvePlayer(change.Source);
			ResolveCreature(change.Source);
			Health val3 = Read<Health>(change.Entity);
			if (!val3.IsDead && !(val3.Value <= 0f))
			{
				return val3.Value;
			}
			return null;
		}

		internal void AfterHealth(StatChangeEvent change, float? before)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: 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_01ab: 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_008d: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: 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_0245: 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_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: 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)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: 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_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: 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_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: 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_04ac: Expected O, but got Unknown
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0593: Invalid comparison between Unknown and I4
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Expected O, but got Unknown
			//IL_053e: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_055d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			DamageSource result;
			DamageSource val = (_healthSources.TryPop(out result) ? result : DamageSource.Unknown);
			if (!before.HasValue || !Has<Health>(change.Entity))
			{
				return;
			}
			float value = Read<Health>(change.Entity).Value;
			double num = ResolvedHealthDamage.Between((double)before.Value, (double)value);
			CapturedHealthChanges++;
			bool flag = default(bool);
			if (_audit.Value)
			{
				ManualLogSource log = ((BasePlugin)_plugin).Log;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(85, 9, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[CombatMeter:ResolvedDamage] source=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(change.Source.Index);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(":");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(change.Source.Version);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" target=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(change.Entity.Index);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(":");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(change.Entity.Version);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" before=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(before.Value, "R");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" after=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(value, "R");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" amount=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<double>(num, "R");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" change=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(change.Change, "R");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" reason=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<StatChangeReason>(change.Reason);
				}
				log.LogInfo(val2);
			}
			Participant? val3 = ResolvePlayer(change.Source);
			Participant? val4 = ResolvePlayer(change.Entity);
			CreatureParticipant? val5 = ((!val3.HasValue) ? ResolveCreature(change.Source) : ((CreatureParticipant?)null));
			double now = Now;
			EntityKey val6 = Key(change.Entity);
			EntityKey val7 = Key(change.Source);
			string text = null;
			DamageTarget val8 = (DamageTarget)0;
			Participant value3;
			EncounterKind val9;
			Entity boss2;
			if (_contestPlayers.TryGetValue(val6, out (EncounterKind, string, int) value2))
			{
				if (!val3.HasValue)
				{
					return;
				}
				value3 = val3.Value;
				if (!TryContestForPlayer(((Participant)(ref value3)).Id, value2.Item2, out (EncounterKind, string, int) result2))
				{
					return;
				}
				value3 = val3.Value;
				((Participant)(ref value3)).set_Team(result2.Item3);
				val3 = value3;
				if (val4.HasValue)
				{
					Participant valueOrDefault = val4.GetValueOrDefault();
					value3 = valueOrDefault;
					((Participant)(ref value3)).set_Team(value2.Item3);
					val4 = value3;
				}
				(val9, text, _) = value2;
			}
			else if (val4.HasValue)
			{
				if (val3.HasValue)
				{
					value3 = val3.Value;
					ulong id = ((Participant)(ref value3)).Id;
					value3 = val4.Value;
					if (id == ((Participant)(ref value3)).Id)
					{
						return;
					}
					val9 = (EncounterKind)3;
				}
				else
				{
					if (val5.HasValue)
					{
						CreatureParticipant valueOrDefault2 = val5.GetValueOrDefault();
						EntityKey? boss = ((CreatureParticipant)(ref valueOrDefault2)).Boss;
						if (boss.HasValue)
						{
							EntityKey valueOrDefault3 = boss.GetValueOrDefault();
							Entity val10 = new Entity
							{
								Index = ((EntityKey)(ref valueOrDefault3)).Index,
								Version = ((EntityKey)(ref valueOrDefault3)).Version
							};
							if (!Has<Health>(val10))
							{
								return;
							}
							Health val11 = Read<Health>(val10);
							if (val11.IsDead || val11.Value <= 0f)
							{
								return;
							}
							BeginBoss(val10, now, val4);
							val9 = (EncounterKind)0;
							text = BossKey(val10);
							goto IL_0414;
						}
					}
					if (!val5.HasValue)
					{
						return;
					}
					val9 = (EncounterKind)4;
				}
			}
			else if (TryBossOwner(change.Entity, out boss2))
			{
				if (!val3.HasValue && val5.HasValue)
				{
					return;
				}
				val9 = (EncounterKind)0;
				text = BossKey(boss2);
				val8 = (DamageTarget)((Key(boss2) == val6) ? 1 : 2);
				BeginBoss(boss2, now, val3);
			}
			else
			{
				if (!val3.HasValue || !Has<Movement>(change.Entity) || Has<YieldResourcesOnDamageTaken>(change.Entity))
				{
					return;
				}
				val9 = (EncounterKind)4;
			}
			goto IL_0414;
			IL_0414:
			if (Tracker.Record(new CombatEvent($"{val7}:{val6}:{++_serial}", now, val7, val6, val3, val4, num, val9, text, val8, (val4.HasValue && !val3.HasValue) ? val5 : ((CreatureParticipant?)null), val)) != null)
			{
				RoutedDamageEvents++;
			}
			if (_audit.Value && num > 0.0)
			{
				ManualLogSource log2 = ((BasePlugin)_plugin).Log;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(61, 5, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[CombatMeter:DamageSource] source=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.Id);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" name=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(val.Name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" statEntity=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(change.StatChangeEntity.Index);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(":");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(change.StatChangeEntity.Version);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" amount=");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<double>(num, "R");
				}
				log2.LogInfo(val2);
			}
			if ((int)val9 == 0 && (int)val8 == 1 && value <= 0f)
			{
				Tracker.End(val9, text, now, (EncounterStatus)1);
				_bosses.Remove(val6);
			}
		}

		private CreatureParticipant? ResolveCreature(Entity source)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00b6: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00dd: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			EntityKey key = Key(source);
			if (_creatureOrigins.TryGetValue(key, out (CreatureParticipant, double) value))
			{
				_creatureOrigins[key] = (value.Item1, Now);
				return value.Item1;
			}
			Entity val = source;
			HashSet<EntityKey> hashSet = new HashSet<EntityKey>();
			CreatureParticipant val3 = default(CreatureParticipant);
			while (((EntityManager)(ref _manager)).Exists(val) && hashSet.Add(Key(val)) && hashSet.Count <= 32)
			{
				if (Has<PlayerCharacter>(val))
				{
					return null;
				}
				if (Has<Health>(val) && (Has<Movement>(val) || Has<VBloodUnit>(val) || Has<UnitStats>(val)) && !Has<YieldResourcesOnDamageTaken>(val))
				{
					Entity boss;
					bool flag = TryBossOwner(val, out boss);
					CreatureKind val2 = (CreatureKind)(Has<VBloodUnit>(val) ? 1 : (flag ? 2 : 0));
					((CreatureParticipant)(ref val3))..ctor(Key(val), CreatureName(val, val2), val2, flag ? new EntityKey?(Key(boss)) : ((EntityKey?)null));
					foreach (EntityKey item in hashSet)
					{
						_creatureOrigins[item] = (val3, Now);
					}
					return val3;
				}
				if (!Has<EntityOwner>(val))
				{
					break;
				}
				val = Read<EntityOwner>(val).Owner;
			}
			return null;
		}

		private unsafe string CreatureName(Entity entity, CreatureKind kind)
		{
			//IL_0001: 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)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_00ee: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Invalid comparison between Unknown and I4
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (Has<NameableInteractable>(entity))
			{
				NameableInteractable val = Read<NameableInteractable>(entity);
				string text = ((object)(*(FixedString64Bytes*)(&val.Name))/*cast due to .constrained prefix*/).ToString();
				if (!string.IsNullOrWhiteSpace(text))
				{
					return text;
				}
			}
			if (Has<PrefabGUID>(entity))
			{
				PrefabGUID val2 = Read<PrefabGUID>(entity);
				if (_prefabNames.Count == 0)
				{
					PrefabCollectionSystem existingSystemManaged = _world.GetExistingSystemManaged<PrefabCollectionSystem>();
					if (existingSystemManaged != null)
					{
						Enumerator<string, PrefabGUID> enumerator = existingSystemManaged.SpawnableNameToPrefabGuidDictionary.GetEnumerator();
						while (enumerator.MoveNext())
						{
							KeyValuePair<string, PrefabGUID> current = enumerator.Current;
							Dictionary<int, string> prefabNames = _prefabNames;
							PrefabGUID value = current.Value;
							prefabNames[((PrefabGUID)(ref value)).GuidHash] = current.Key.Replace("CHAR_", "").Replace("_VBlood", "").Replace("_", " ");
						}
					}
				}
				if (_prefabNames.TryGetValue(((PrefabGUID)(ref val2)).GuidHash, out string value2))
				{
					return value2;
				}
			}
			if ((int)kind != 1)
			{
				if ((int)kind == 2)
				{
					return "Boss summon";
				}
				return "Monster";
			}
			return "V Blood boss";
		}

		private bool TryContestForPlayer(ulong id, string contestKey, out (EncounterKind Kind, string Key, int Team) result)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<EntityKey, (EncounterKind, string, int)> contestPlayer in _contestPlayers)
			{
				if (contestPlayer.Value.Item2 != contestKey)
				{
					continue;
				}
				Entity val = default(Entity);
				EntityKey key = contestPlayer.Key;
				val.Index = ((EntityKey)(ref key)).Index;
				key = contestPlayer.Key;
				val.Version = ((EntityKey)(ref key)).Version;
				Entity source = val;
				Participant? val2 = ResolvePlayer(source);
				if (val2.HasValue)
				{
					Participant valueOrDefault = val2.GetValueOrDefault();
					if (((Participant)(ref valueOrDefault)).Id == id)
					{
						result = contestPlayer.Value;
						return true;
					}
				}
			}
			result = default((EncounterKind, string, int));
			return false;
		}

		private string BossKey(Entity boss)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			return $"boss:{boss.Index}:{boss.Version}";
		}

		private unsafe void BeginBoss(Entity boss, double now, Participant? player)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0053: 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_006b: 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)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			_bosses[Key(boss)] = boss;
			object obj;
			if (!Has<NameableInteractable>(boss))
			{
				obj = "V Blood encounter";
			}
			else
			{
				NameableInteractable val = Read<NameableInteractable>(boss);
				obj = ((object)(*(FixedString64Bytes*)(&val.Name))/*cast due to .constrained prefix*/).ToString();
			}
			string text = (string)obj;
			if (string.IsNullOrWhiteSpace(text))
			{
				text = "V Blood encounter";
			}
			EncounterTracker tracker = Tracker;
			string text2 = BossKey(boss);
			string text3 = text;
			object obj2;
			if (player.HasValue)
			{
				Participant valueOrDefault = player.GetValueOrDefault();
				obj2 = new Participant[1] { valueOrDefault };
			}
			else
			{
				obj2 = Array.Empty<Participant>();
			}
			tracker.Begin((EncounterKind)0, text2, text3, now, (IEnumerable<Participant>)obj2);
		}

		private bool TryBossOwner(Entity entity, out Entity boss)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_0080: 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)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_0094: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			EntityKey key = Key(entity);
			if (_bossOwners.TryGetValue(key, out var value) && Exists(value))
			{
				boss = new Entity
				{
					Index = ((EntityKey)(ref value)).Index,
					Version = ((EntityKey)(ref value)).Version
				};
				return true;
			}
			Entity val = entity;
			HashSet<EntityKey> hashSet = new HashSet<EntityKey>();
			for (int i = 0; i < 32; i++)
			{
				if (!((EntityManager)(ref _manager)).Exists(val))
				{
					break;
				}
				if (!hashSet.Add(Key(val)))
				{
					break;
				}
				if (Has<VBloodUnit>(val))
				{
					boss = val;
					_bossOwners[key] = Key(val);
					return true;
				}
				if (Has<EntityOwner>(val))
				{
					val = Read<EntityOwner>(val).Owner;
					continue;
				}
				if (!Has<Minion>(val))
				{
					break;
				}
				val = Read<Minion>(val).SpawnEventTarget;
			}
			boss = Entity.Null;
			return false;
		}

		private void PollBosses(double now)
		{
			//IL_0001: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_006c: Invalid comparison between Unknown and I4
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Un

BepInEx/plugins/CombatMeter/CombatMeter.Shared.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CombatMeter.Shared")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+7bf5d4af4539905a627ee336fb44ed2fa9bdee99")]
[assembly: AssemblyProduct("CombatMeter.Shared")]
[assembly: AssemblyTitle("CombatMeter.Shared")]
[assembly: AssemblyVersion("0.2.1.0")]
[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 CombatMeter.Shared
{
	public enum EncounterKind
	{
		Boss,
		Arena,
		Duel,
		PvP,
		OpenWorld
	}
	public enum EncounterStatus
	{
		Active,
		Completed,
		Reset,
		Cancelled,
		Merged
	}
	public enum DamageTarget
	{
		Other,
		Boss,
		BossSummon
	}
	public enum MeterMetric
	{
		Damage,
		Dps
	}
	public enum BossTargetFilter
	{
		BossAndSummons,
		BossOnly
	}
	public enum CreatureKind
	{
		Monster,
		Boss,
		BossSummon
	}
	public enum DamageSourceKind
	{
		Ability,
		Weapon,
		Debuff,
		Proc,
		Summon,
		Unknown,
		Other
	}
	public enum DetailActorKind
	{
		Player,
		Creature
	}
	public static class Protocol
	{
		public const int Version = 4;

		public const int SourceLimit = 128;

		public const double DetailInterval = 0.5;

		public const int HistoryLimit = 20;

		public const double SnapshotInterval = 0.25;
	}
	public sealed class RegistrationPacket
	{
		public int ProtocolVersion { get; set; } = 4;

		public string ClientVersion { get; set; } = "0.2.1";
	}
	public sealed class HistoryRequestPacket
	{
		public int ProtocolVersion { get; set; } = 4;

		public string ServerSessionId { get; set; } = "";
	}
	public sealed class PolicyPacket
	{
		public int ProtocolVersion { get; set; } = 4;

		public string ServerSessionId { get; set; } = "";

		public bool Accepted { get; set; }

		public string Reason { get; set; } = "";

		public EncounterKind[] EnabledModes { get; set; } = Array.Empty<EncounterKind>();

		public double CombatTimeoutSeconds { get; set; } = 10.0;
	}
	public class EncounterPacket
	{
		public int ProtocolVersion { get; set; } = 4;

		public string ServerSessionId { get; set; } = "";

		public EncounterSnapshot Encounter { get; set; } = new EncounterSnapshot();
	}
	public sealed class EncounterCompletedPacket : EncounterPacket
	{
	}
	public sealed class SourceRequestPacket
	{
		public int ProtocolVersion { get; set; } = 4;

		public string ServerSessionId { get; set; } = "";

		public string EncounterId { get; set; } = "";

		public DetailActorKind ActorKind { get; set; }

		public ulong PlayerId { get; set; }

		public string CreatureId { get; set; } = "";

		public long RequestId { get; set; }
	}
	public sealed class SourceResponsePacket
	{
		public int ProtocolVersion { get; set; } = 4;

		public string ServerSessionId { get; set; } = "";

		public string EncounterId { get; set; } = "";

		public DetailActorKind ActorKind { get; set; }

		public ulong PlayerId { get; set; }

		public string CreatureId { get; set; } = "";

		public long RequestId { get; set; }

		public long Revision { get; set; }

		public bool Available { get; set; }

		public string Reason { get; set; } = "";

		public string ActorName { get; set; } = "";

		public string EncounterLabel { get; set; } = "";

		public EncounterKind Kind { get; set; }

		public EncounterStatus Status { get; set; }

		public double DurationSeconds { get; set; }

		public double Damage { get; set; }

		public double BossDamage { get; set; }

		public double SummonDamage { get; set; }

		public SourceTotals[] Sources { get; set; } = Array.Empty<SourceTotals>();
	}
	public sealed class SourceTotals
	{
		public string Id { get; set; } = "";

		public string Name { get; set; } = "";

		public DamageSourceKind Kind { get; set; }

		public int PrefabHash { get; set; }

		public double Damage { get; set; }

		public double BossDamage { get; set; }

		public double SummonDamage { get; set; }
	}
	public sealed class EncounterSnapshot
	{
		public string Id { get; set; } = "";

		public string Label { get; set; } = "";

		public EncounterKind Kind { get; set; }

		public EncounterStatus Status { get; set; }

		public long Sequence { get; set; }

		public double StartedAt { get; set; }

		public double EndedAt { get; set; }

		public double DurationSeconds { get; set; }

		public string MergedInto { get; set; } = "";

		public PlayerTotals[] Players { get; set; } = Array.Empty<PlayerTotals>();

		public CreatureTotals[] Creatures { get; set; } = Array.Empty<CreatureTotals>();

		public double UnknownDamage { get; set; }

		public double UnknownBossDamage { get; set; }
	}
	public sealed class CreatureTotals
	{
		public string EntityId { get; set; } = "";

		public string Name { get; set; } = "";

		public CreatureKind Kind { get; set; }

		public double Damage { get; set; }
	}
	public sealed class PlayerTotals
	{
		public ulong PlayerId { get; set; }

		public string Name { get; set; } = "";

		public int Team { get; set; }

		public double Damage { get; set; }

		public double BossDamage { get; set; }

		public double SummonDamage { get; set; }

		public double ForFilter(EncounterKind kind, BossTargetFilter filter)
		{
			if (kind != EncounterKind.Boss || filter != BossTargetFilter.BossOnly)
			{
				return Damage;
			}
			return BossDamage;
		}
	}
	public static class WireCodec
	{
		public const string Prefix = "~CM4|";

		public const int ChunkSize = 360;

		public const int MaxChunks = 256;

		public const int MaxJsonBytes = 524288;

		public static IEnumerable<string> Encode<T>(string channel, long id, T packet)
		{
			char c;
			if (!(packet is RegistrationPacket))
			{
				if (!(packet is HistoryRequestPacket))
				{
					if (!(packet is SourceRequestPacket))
					{
						if (!(packet is PolicyPacket))
						{
							if (!(packet is EncounterCompletedPacket))
							{
								if (!(packet is EncounterPacket))
								{
									if (!(packet is SourceResponsePacket))
									{
										throw new ArgumentException("Unsupported packet");
									}
									c = 'S';
								}
								else
								{
									c = 'E';
								}
							}
							else
							{
								c = 'F';
							}
						}
						else
						{
							c = 'P';
						}
					}
					else
					{
						c = 'Q';
					}
				}
				else
				{
					c = 'H';
				}
			}
			else
			{
				c = 'R';
			}
			char kind = c;
			byte[] array = JsonSerializer.SerializeToUtf8Bytes(packet);
			if (array.Length > 524288)
			{
				throw new InvalidDataException("Packet exceeds JSON limit");
			}
			using MemoryStream output = new MemoryStream();
			using (BrotliStream brotliStream = new BrotliStream(output, CompressionLevel.Fastest, leaveOpen: true))
			{
				brotliStream.Write(array);
			}
			string payload = Convert.ToBase64String(output.ToArray());
			int count = (payload.Length + 360 - 1) / 360;
			if (count > 256)
			{
				throw new InvalidDataException("Packet exceeds frame limit");
			}
			for (int index = 0; index < count; index++)
			{
				yield return $"{"~CM4|"}{channel}|{id}|{kind}|{index}|{count}|{payload.Substring(index * 360, Math.Min(360, payload.Length - index * 360))}";
			}
		}

		public static object Decode(char kind, string encoded, int maxJsonBytes = 524288)
		{
			using MemoryStream stream = new MemoryStream(Convert.FromBase64String(encoded));
			using BrotliStream brotliStream = new BrotliStream(stream, CompressionMode.Decompress);
			using MemoryStream memoryStream = new MemoryStream();
			byte[] array = new byte[4096];
			int num;
			while ((num = brotliStream.Read(array, 0, array.Length)) != 0)
			{
				if (memoryStream.Length + num > maxJsonBytes)
				{
					throw new InvalidDataException("Expanded packet exceeds limit");
				}
				memoryStream.Write(array, 0, num);
			}
			byte[] array2 = memoryStream.ToArray();
			return kind switch
			{
				'R' => JsonSerializer.Deserialize<RegistrationPacket>(array2), 
				'H' => JsonSerializer.Deserialize<HistoryRequestPacket>(array2), 
				'Q' => JsonSerializer.Deserialize<SourceRequestPacket>(array2), 
				'P' => JsonSerializer.Deserialize<PolicyPacket>(array2), 
				'E' => JsonSerializer.Deserialize<EncounterPacket>(array2), 
				'F' => JsonSerializer.Deserialize<EncounterCompletedPacket>(array2), 
				'S' => JsonSerializer.Deserialize<SourceResponsePacket>(array2), 
				_ => throw new InvalidDataException("Unknown packet kind"), 
			};
		}
	}
	public sealed class WireInbox
	{
		private sealed record Transfer(char Kind, string[] Chunks, double Started);

		private readonly Dictionary<(string Channel, long Id), Transfer> _pending = new Dictionary<(string, long), Transfer>();

		private readonly HashSet<(string Channel, long Id)> _completed = new HashSet<(string, long)>();

		private readonly Queue<(string Channel, long Id)> _order = new Queue<(string, long)>();

		public void Clear()
		{
			_pending.Clear();
			_completed.Clear();
			_order.Clear();
		}

		public object? Receive(string frame, string? expectedChannel, bool serverbound, double now, out string channel)
		{
			channel = "";
			(string, long)[] array = (from x in _pending
				where now - x.Value.Started > 5.0
				select x.Key).ToArray();
			foreach ((string, long) key in array)
			{
				_pending.Remove(key);
			}
			if (frame.Length > 500 || !frame.StartsWith("~CM4|", StringComparison.Ordinal))
			{
				return null;
			}
			string[] array2 = frame.Split('|');
			if (array2.Length != 7 || array2[1].Length != 32 || !Guid.TryParseExact(array2[1], "N", out var _) || (expectedChannel != null && array2[1] != expectedChannel) || !long.TryParse(array2[2], out var result2) || result2 <= 0 || array2[3].Length != 1 || !int.TryParse(array2[4], out var result3) || !int.TryParse(array2[5], out var result4) || result4 < 1 || result4 > 256 || result3 < 0 || result3 >= result4 || array2[6].Length > 360)
			{
				return null;
			}
			char c = array2[3][0];
			if (!(serverbound ? "RHQ" : "PEFS").Contains(c))
			{
				return null;
			}
			if (serverbound && result4 != 1)
			{
				return null;
			}
			channel = array2[1];
			(string, long) tuple = (channel, result2);
			if (_completed.Contains(tuple))
			{
				return null;
			}
			if (!_pending.TryGetValue(tuple, out Transfer value))
			{
				if (_pending.Count >= 4)
				{
					return null;
				}
				value = (_pending[tuple] = new Transfer(c, new string[result4], now));
			}
			if (value.Kind != c || value.Chunks.Length != result4)
			{
				_pending.Remove(tuple);
				return null;
			}
			string text = value.Chunks[result3];
			if (text != null && text != array2[6])
			{
				_pending.Remove(tuple);
				return null;
			}
			value.Chunks[result3] = array2[6];
			if (value.Chunks.Any((string x) => x == null))
			{
				return null;
			}
			_pending.Remove(tuple);
			_completed.Add(tuple);
			_order.Enqueue(tuple);
			while (_order.Count > 128)
			{
				_completed.Remove(_order.Dequeue());
			}
			try
			{
				return WireCodec.Decode(c, string.Concat(value.Chunks), serverbound ? 4096 : 524288);
			}
			catch (Exception ex) when (((ex is InvalidDataException || ex is FormatException || ex is JsonException || ex is IOException) ? 1 : 0) != 0)
			{
				return null;
			}
		}
	}
}