Decompiled source of RecapDmgUiMod v1.0.7

BepInEx/plugins/RecapDmgUiMod/RecapDmgUiMod.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnboundLib.GameModes;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RecapDmgUiMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+bebcfde19bf66e2146f36e29c55ea54aabedbe0b")]
[assembly: AssemblyProduct("RecapDmgUiMod")]
[assembly: AssemblyTitle("RecapDmgUiMod")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace RecapDmgUiMod
{
	[BepInPlugin("com.vias.recapdmgui", "RecapDmgUiMod", "1.9.0")]
	[BepInProcess("Rounds.exe")]
	public class RecapDmgUiModPlugin : BaseUnityPlugin, IOnEventCallback
	{
		[CompilerGenerated]
		private sealed class <OnRoundEnd>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IGameModeHandler _;

			public RecapDmgUiModPlugin <>4__this;

			private List<DamageEntry> <entries>5__1;

			private List<DamageEntry> <entries>5__2;

			private int[] <ids>5__3;

			private float[] <damages>5__4;

			private object[] <content>5__5;

			private RaiseEventOptions <opts>5__6;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <OnRoundEnd>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<entries>5__1 = null;
				<entries>5__2 = null;
				<ids>5__3 = null;
				<damages>5__4 = null;
				<content>5__5 = null;
				<opts>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_021c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0221: Unknown result type (might be due to invalid IL or missing references)
				//IL_0223: Unknown result type (might be due to invalid IL or missing references)
				//IL_022d: Expected O, but got Unknown
				//IL_023b: Unknown result type (might be due to invalid IL or missing references)
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				if (s_recappedThisRound)
				{
					ManualLogSource log = Log;
					if (log != null)
					{
						log.LogInfo((object)"[RecapDmgUiMod] RoundEnd -> already recapped");
					}
					return false;
				}
				if (!IsNetworked())
				{
					s_recappedThisRound = true;
					<entries>5__1 = DamageThisRound.Select((KeyValuePair<int, float> kv) => new DamageEntry
					{
						playerId = kv.Key,
						damage = kv.Value
					}).ToList();
					if (<entries>5__1.Count == 0)
					{
						ManualLogSource log2 = Log;
						if (log2 != null)
						{
							log2.LogInfo((object)"[RecapDmgUiMod] RoundEnd (offline) -> no damage, skip UI");
						}
					}
					else
					{
						Instance.ReceiveDamageData(<entries>5__1.Select((DamageEntry e) => e.playerId).ToArray(), <entries>5__1.Select((DamageEntry e) => e.damage).ToArray());
					}
					return false;
				}
				if (IsHostSafe())
				{
					s_recappedThisRound = true;
					<entries>5__2 = DamageThisRound.Select((KeyValuePair<int, float> kv) => new DamageEntry
					{
						playerId = kv.Key,
						damage = kv.Value
					}).ToList();
					if (<entries>5__2.Count == 0)
					{
						ManualLogSource log3 = Log;
						if (log3 != null)
						{
							log3.LogInfo((object)"[RecapDmgUiMod] RoundEnd (network) -> no damage, skip send");
						}
						return false;
					}
					<ids>5__3 = <entries>5__2.Select((DamageEntry e) => e.playerId).ToArray();
					<damages>5__4 = <entries>5__2.Select((DamageEntry e) => e.damage).ToArray();
					<content>5__5 = new object[2] { <ids>5__3, <damages>5__4 };
					<opts>5__6 = new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)1
					};
					PhotonNetwork.RaiseEvent((byte)77, (object)<content>5__5, <opts>5__6, SendOptions.SendReliable);
					ManualLogSource log4 = Log;
					if (log4 != null)
					{
						log4.LogInfo((object)$"[RecapDmgUiMod] Sent recap to all (n={<entries>5__2.Count})");
					}
					<entries>5__2 = null;
					<ids>5__3 = null;
					<damages>5__4 = null;
					<content>5__5 = null;
					<opts>5__6 = null;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <OnRoundStart>d__11 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IGameModeHandler _;

			public RecapDmgUiModPlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <OnRoundStart>d__11(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				s_recappedThisRound = false;
				if (IsHostSafe())
				{
					DamageThisRound.Clear();
					ManualLogSource log = Log;
					if (log != null)
					{
						log.LogInfo((object)"[RecapDmgUiMod] RoundStart -> reset counters (per round, host-only)");
					}
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal static RecapDmgUiModPlugin Instance;

		public static ManualLogSource Log;

		private const byte EVT_RECAP = 77;

		private static readonly Dictionary<int, float> DamageThisRound = new Dictionary<int, float>();

		private static bool s_recappedThisRound = false;

		private void Awake()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"=== RecapDmgUiMod loaded (networked round recap) ===");
			new Harmony("com.vias.recapdmgui").PatchAll();
			GameModeManager.AddHook("RoundStart", (Func<IGameModeHandler, IEnumerator>)((IGameModeHandler gm) => OnRoundStart(gm)));
			GameModeManager.AddHook("RoundEnd", (Func<IGameModeHandler, IEnumerator>)((IGameModeHandler gm) => OnRoundEnd(gm)));
			GameModeManager.AddHook("GameEnd", (Func<IGameModeHandler, IEnumerator>)((IGameModeHandler gm) => OnRoundEnd(gm)));
		}

		private void OnEnable()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		private void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		public static bool IsHostSafe()
		{
			if (!PhotonNetwork.IsConnected || !PhotonNetwork.InRoom)
			{
				return true;
			}
			return PhotonNetwork.IsMasterClient;
		}

		private static bool IsNetworked()
		{
			return PhotonNetwork.IsConnected && PhotonNetwork.InRoom;
		}

		public static void AddDamage(int playerId, float dmg)
		{
			if (playerId >= 0)
			{
				if (!DamageThisRound.TryGetValue(playerId, out var value))
				{
					value = 0f;
				}
				DamageThisRound[playerId] = value + Mathf.Max(0f, dmg);
			}
		}

		[IteratorStateMachine(typeof(<OnRoundStart>d__11))]
		private IEnumerator OnRoundStart(IGameModeHandler _)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <OnRoundStart>d__11(0)
			{
				<>4__this = this,
				_ = _
			};
		}

		[IteratorStateMachine(typeof(<OnRoundEnd>d__12))]
		private IEnumerator OnRoundEnd(IGameModeHandler _)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <OnRoundEnd>d__12(0)
			{
				<>4__this = this,
				_ = _
			};
		}

		public void OnEvent(EventData photonEvent)
		{
			if (photonEvent.Code != 77)
			{
				return;
			}
			try
			{
				if (!(photonEvent.CustomData is object[] array) || array.Length < 2)
				{
					ManualLogSource log = Log;
					if (log != null)
					{
						log.LogWarning((object)"[RecapDmgUiMod] OnEvent(EVT_RECAP): malformed payload");
					}
					return;
				}
				int[] array2 = array[0] as int[];
				float[] array3 = array[1] as float[];
				if ((array2 == null || array3 == null) && array[0] is object[] source && array[1] is object[] source2)
				{
					array2 = source.Select((object o) => Convert.ToInt32(o)).ToArray();
					array3 = source2.Select((object o) => Convert.ToSingle(o)).ToArray();
				}
				if (array2 == null || array3 == null)
				{
					ManualLogSource log2 = Log;
					if (log2 != null)
					{
						log2.LogWarning((object)"[RecapDmgUiMod] OnEvent(EVT_RECAP): null arrays");
					}
					return;
				}
				if (!s_recappedThisRound)
				{
					s_recappedThisRound = true;
				}
				ReceiveDamageData(array2, array3);
				ManualLogSource log3 = Log;
				if (log3 != null)
				{
					log3.LogInfo((object)$"[RecapDmgUiMod] OnEvent -> showed recap (count={Mathf.Min(array2.Length, array3.Length)})");
				}
			}
			catch (Exception arg)
			{
				ManualLogSource log4 = Log;
				if (log4 != null)
				{
					log4.LogError((object)$"[RecapDmgUiMod] OnEvent parse error: {arg}");
				}
			}
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)289))
			{
				List<DamageEntry> source = DamageThisRound.Select((KeyValuePair<int, float> kv) => new DamageEntry
				{
					playerId = kv.Key,
					damage = kv.Value
				}).ToList();
				ReceiveDamageData(source.Select((DamageEntry e) => e.playerId).ToArray(), source.Select((DamageEntry e) => e.damage).ToArray());
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogInfo((object)"[RecapDmgUiMod] F8 -> Show damage recap (DEV, local only)");
				}
			}
		}

		private void ReceiveDamageData(int[] ids, float[] damages)
		{
			List<DamageEntry> list = new List<DamageEntry>(Mathf.Min((ids != null) ? ids.Length : 0, (damages != null) ? damages.Length : 0));
			if (ids != null && damages != null)
			{
				for (int i = 0; i < ids.Length && i < damages.Length; i++)
				{
					list.Add(new DamageEntry
					{
						playerId = ids[i],
						damage = damages[i]
					});
				}
			}
			ShowEndOfRoundUI(list);
		}

		private static void ShowEndOfRoundUI(List<DamageEntry> data)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0093: 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_00ec: 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_0110: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			//IL_0233: 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_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: 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_029c: 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_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Expected O, but got Unknown
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: 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_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Expected O, but got Unknown
			//IL_0575: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Expected O, but got Unknown
			//IL_060a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0611: Expected O, but got Unknown
			//IL_0648: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_068c: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_069a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0735: Unknown result type (might be due to invalid IL or missing references)
			//IL_074d: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0775: Unknown result type (might be due to invalid IL or missing references)
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0791: Unknown result type (might be due to invalid IL or missing references)
			//IL_0796: Unknown result type (might be due to invalid IL or missing references)
			//IL_07be: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_081b: Unknown result type (might be due to invalid IL or missing references)
			//IL_083b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0843: Unknown result type (might be due to invalid IL or missing references)
			//IL_0857: Unknown result type (might be due to invalid IL or missing references)
			//IL_087a: Unknown result type (might be due to invalid IL or missing references)
			//IL_089d: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0906: Unknown result type (might be due to invalid IL or missing references)
			//IL_0926: Unknown result type (might be due to invalid IL or missing references)
			//IL_092e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0938: Unknown result type (might be due to invalid IL or missing references)
			//IL_0953: Unknown result type (might be due to invalid IL or missing references)
			//IL_0955: Unknown result type (might be due to invalid IL or missing references)
			//IL_095f: Unknown result type (might be due to invalid IL or missing references)
			//IL_097d: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a27: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a42: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a59: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("RecapDmgUiMod_Canvas");
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)val);
			}
			GameObject val2 = new GameObject("RecapDmgUiMod_Canvas", new Type[3]
			{
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster)
			});
			Object.DontDestroyOnLoad((Object)(object)val2);
			Canvas component = val2.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 9999;
			CanvasScaler component2 = val2.GetComponent<CanvasScaler>();
			component2.uiScaleMode = (ScaleMode)1;
			component2.referenceResolution = new Vector2(1920f, 1080f);
			Image component3 = new GameObject("BG", new Type[1] { typeof(Image) }).GetComponent<Image>();
			((Component)component3).transform.SetParent(val2.transform, false);
			((Graphic)component3).color = new Color(0f, 0f, 0f, 0.65f);
			((Graphic)component3).rectTransform.anchorMin = Vector2.zero;
			((Graphic)component3).rectTransform.anchorMax = Vector2.one;
			((Graphic)component3).rectTransform.offsetMin = Vector2.zero;
			((Graphic)component3).rectTransform.offsetMax = Vector2.zero;
			Image component4 = new GameObject("Panel", new Type[1] { typeof(Image) }).GetComponent<Image>();
			((Component)component4).transform.SetParent(val2.transform, false);
			((Graphic)component4).color = new Color(0.1f, 0.1f, 0.1f, 0.95f);
			RectTransform rectTransform = ((Graphic)component4).rectTransform;
			rectTransform.sizeDelta = new Vector2(1200f, 620f);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			rectTransform.anchorMax = val3;
			rectTransform.anchorMin = val3;
			rectTransform.anchoredPosition = Vector2.zero;
			GameObject val4 = new GameObject("Header", new Type[1] { typeof(RectTransform) });
			val4.transform.SetParent(((Component)component4).transform, false);
			RectTransform component5 = val4.GetComponent<RectTransform>();
			component5.anchorMin = new Vector2(0.5f, 1f);
			component5.anchorMax = new Vector2(0.5f, 1f);
			component5.pivot = new Vector2(0.5f, 1f);
			component5.sizeDelta = new Vector2(rectTransform.sizeDelta.x - 80f, 110f);
			component5.anchoredPosition = new Vector2(0f, -10f);
			TextMeshProUGUI val5 = CreateText(val4.transform, "Damage Recap", 52, (TextAlignmentOptions)514, Color.white, bold: true);
			((TMP_Text)val5).rectTransform.sizeDelta = new Vector2(component5.sizeDelta.x, 110f);
			((TMP_Text)val5).rectTransform.anchoredPosition = new Vector2(0f, -43f);
			((TMP_Text)val5).transform.SetAsLastSibling();
			GameObject val6 = new GameObject("Grid", new Type[1] { typeof(RectTransform) });
			val6.transform.SetParent(((Component)component4).transform, false);
			RectTransform component6 = val6.GetComponent<RectTransform>();
			component6.anchorMin = new Vector2(0.5f, 0.5f);
			component6.anchorMax = new Vector2(0.5f, 0.5f);
			component6.pivot = new Vector2(0.5f, 0.5f);
			component6.sizeDelta = new Vector2(rectTransform.sizeDelta.x - 80f, rectTransform.sizeDelta.y - 110f - 60f);
			component6.anchoredPosition = new Vector2(0f, -65f);
			if (data == null || data.Count == 0)
			{
				TextMeshProUGUI val7 = CreateText(val6.transform, "Aucun dégât enregistré.", 32, (TextAlignmentOptions)514, Color.white, bold: false);
				((TMP_Text)val7).rectTransform.anchoredPosition = Vector2.zero;
				((TMP_Text)val7).transform.SetAsLastSibling();
				val2.AddComponent<AutoCloseDamageUI>();
				return;
			}
			List<DamageEntry> list = data.OrderByDescending((DamageEntry e) => e.damage).ToList();
			float num = Mathf.Max(1f, list.Max((DamageEntry e) => e.damage));
			int count = list.Count;
			int num2 = Mathf.Clamp(count, 1, 8);
			float num3 = (component6.sizeDelta.x - 20f * (float)(num2 - 1)) / (float)num2;
			float y = component6.sizeDelta.y;
			Vector2 val11 = default(Vector2);
			for (int i = 0; i < count; i++)
			{
				DamageEntry damageEntry = list[i];
				float num4 = (0f - component6.sizeDelta.x) / 2f + num3 / 2f + (float)i * (num3 + 20f);
				GameObject val8 = new GameObject($"Col_{damageEntry.playerId}", new Type[1] { typeof(RectTransform) });
				val8.transform.SetParent(val6.transform, false);
				RectTransform component7 = val8.GetComponent<RectTransform>();
				component7.sizeDelta = new Vector2(num3, y);
				((Vector2)(ref val3))..ctor(0.5f, 0.5f);
				component7.anchorMax = val3;
				component7.anchorMin = val3;
				component7.anchoredPosition = new Vector2(num4, 0f);
				GameObject val9 = new GameObject("BarLayer", new Type[1] { typeof(RectTransform) });
				GameObject val10 = new GameObject("TextLayer", new Type[3]
				{
					typeof(RectTransform),
					typeof(Canvas),
					typeof(CanvasRenderer)
				});
				val9.transform.SetParent(val8.transform, false);
				val10.transform.SetParent(val8.transform, false);
				RectTransform component8 = val9.GetComponent<RectTransform>();
				component8.sizeDelta = component7.sizeDelta;
				RectTransform component9 = val10.GetComponent<RectTransform>();
				component9.sizeDelta = component7.sizeDelta;
				((Vector2)(ref val11))..ctor(0.5f, 0.5f);
				component9.anchorMax = val11;
				Vector2 val13 = (component9.anchorMin = val11);
				val3 = (component8.anchorMin = (component8.anchorMax = val13));
				val3 = (component8.anchoredPosition = (component9.anchoredPosition = Vector2.zero));
				Canvas component10 = val10.GetComponent<Canvas>();
				component10.overrideSorting = true;
				component10.sortingOrder = component.sortingOrder + 1;
				Image component11 = new GameObject("ColBG", new Type[1] { typeof(Image) }).GetComponent<Image>();
				((Component)component11).transform.SetParent(val9.transform, false);
				((Graphic)component11).color = new Color(1f, 1f, 1f, 0.05f);
				RectTransform rectTransform2 = ((Graphic)component11).rectTransform;
				rectTransform2.sizeDelta = component7.sizeDelta;
				((Vector2)(ref val3))..ctor(0.5f, 0.5f);
				rectTransform2.anchorMax = val3;
				rectTransform2.anchorMin = val3;
				rectTransform2.anchoredPosition = Vector2.zero;
				Color playerColor = GetPlayerColor(damageEntry.playerId);
				string playerName = GetPlayerName(damageEntry.playerId);
				Image component12 = new GameObject("BarBG", new Type[1] { typeof(Image) }).GetComponent<Image>();
				((Component)component12).transform.SetParent(val9.transform, false);
				((Graphic)component12).color = new Color(1f, 1f, 1f, 0.1f);
				RectTransform rectTransform3 = ((Graphic)component12).rectTransform;
				rectTransform3.sizeDelta = new Vector2(num3 * 0.45f, y * 0.55f);
				((Vector2)(ref val3))..ctor(0.5f, 0.5f);
				rectTransform3.anchorMax = val3;
				rectTransform3.anchorMin = val3;
				rectTransform3.anchoredPosition = new Vector2(0f, -20f);
				Image component13 = new GameObject("Bar", new Type[1] { typeof(Image) }).GetComponent<Image>();
				((Component)component13).transform.SetParent(((Component)component12).transform, false);
				((Graphic)component13).color = playerColor;
				component13.type = (Type)3;
				component13.fillMethod = (FillMethod)1;
				component13.fillOrigin = 0;
				component13.fillAmount = Mathf.Clamp01(damageEntry.damage / num);
				RectTransform rectTransform4 = ((Graphic)component13).rectTransform;
				rectTransform4.sizeDelta = new Vector2(rectTransform3.sizeDelta.x - 8f, rectTransform3.sizeDelta.y - 8f);
				((Vector2)(ref val3))..ctor(0.5f, 0.5f);
				rectTransform4.anchorMax = val3;
				rectTransform4.anchorMin = val3;
				rectTransform4.anchoredPosition = Vector2.zero;
				TextMeshProUGUI val17 = CreateText(val10.transform, playerName, 40, (TextAlignmentOptions)514, Color.Lerp(playerColor, Color.white, 0.2f), bold: true);
				((TMP_Text)val17).rectTransform.anchoredPosition = new Vector2(0f, -40f);
				((TMP_Text)val17).transform.SetAsLastSibling();
				TextMeshProUGUI val18 = CreateText(val10.transform, $"{damageEntry.damage:0}", 56, (TextAlignmentOptions)514, Color.white, bold: true);
				((TMP_Text)val18).rectTransform.anchoredPosition = new Vector2(0f, -100f);
				((TMP_Text)val18).transform.SetAsLastSibling();
				TextMeshProUGUI val19 = CreateText(val10.transform, $"{damageEntry.damage:0} dmg", 28, (TextAlignmentOptions)514, new Color(1f, 1f, 1f, 0.85f), bold: false);
				((TMP_Text)val19).rectTransform.anchoredPosition = new Vector2(0f, (0f - component7.sizeDelta.y) / 2f + 40f);
				((TMP_Text)val19).transform.SetAsLastSibling();
			}
			val2.AddComponent<AutoCloseDamageUI>();
		}

		private static TextMeshProUGUI CreateText(Transform parent, string content, int size, TextAlignmentOptions align, Color col, bool bold)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_005c: 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_008e: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TMP_Text", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).text = (bold ? ("<b>" + content + "</b>") : content);
			((TMP_Text)val2).fontSize = size;
			((TMP_Text)val2).alignment = align;
			((Graphic)val2).color = col;
			((TMP_Text)val2).enableWordWrapping = false;
			((Graphic)val2).raycastTarget = false;
			RectTransform rectTransform = ((TMP_Text)val2).rectTransform;
			rectTransform.sizeDelta = new Vector2(760f, 60f);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			rectTransform.anchorMax = val3;
			rectTransform.anchorMin = val3;
			rectTransform.anchoredPosition = Vector2.zero;
			return val2;
		}

		private static Color GetPlayerColor(int playerId)
		{
			//IL_0018: 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_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_004e: 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_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_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)
			//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)
			//IL_00ba: 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_00d5: 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_00eb: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[8]
			{
				new Color(0.95f, 0.25f, 0.25f),
				new Color(0.25f, 0.55f, 1f),
				new Color(0.15f, 0.85f, 0.4f),
				new Color(1f, 0.85f, 0.2f),
				new Color(0.8f, 0.35f, 0.95f),
				new Color(1f, 0.55f, 0.25f),
				new Color(0.25f, 0.9f, 0.9f),
				new Color(0.9f, 0.3f, 0.5f)
			};
			return array[Mathf.Abs(playerId) % array.Length];
		}

		private static string GetPlayerName(int playerId)
		{
			try
			{
				PlayerManager instance = PlayerManager.instance;
				if ((Object)(object)instance == (Object)null || instance.players == null)
				{
					return $"P{playerId}";
				}
				foreach (Player player in instance.players)
				{
					if ((Object)(object)player == (Object)null || player.playerID != playerId)
					{
						continue;
					}
					object? obj = typeof(Player).GetField("data", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(player);
					CharacterData val = (CharacterData)((obj is CharacterData) ? obj : null);
					if ((Object)(object)val != (Object)null)
					{
						object? obj2 = typeof(CharacterData).GetField("view", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(val);
						PhotonView val2 = (PhotonView)((obj2 is PhotonView) ? obj2 : null);
						Player val3 = ((val2 != null) ? val2.Owner : null);
						if (val3 != null && !string.IsNullOrEmpty(val3.NickName))
						{
							return val3.NickName;
						}
					}
					FieldInfo field = typeof(Player).GetField("teamID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					int num = ((field != null) ? ((int)field.GetValue(player)) : (-1));
					if (num >= 0)
					{
						return $"Player {num + 1}";
					}
					return $"Player {player.playerID + 1}";
				}
			}
			catch
			{
			}
			return $"P{playerId}";
		}
	}
	public class DamageEntry
	{
		public int playerId;

		public float damage;
	}
	public class AutoCloseDamageUI : MonoBehaviour
	{
		private float t;

		private bool ready;

		private void Update()
		{
			t += Time.unscaledDeltaTime;
			if (!ready && t > 2f)
			{
				ready = true;
			}
			if (t > 7f || (ready && Input.anyKeyDown))
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	[HarmonyPatch(typeof(HealthHandler))]
	public static class Patch_HealthHandler_TakeDamage
	{
		private static FieldInfo _fiHealth;

		[HarmonyPatch("TakeDamage", new Type[]
		{
			typeof(Vector2),
			typeof(Vector2),
			typeof(Color),
			typeof(GameObject),
			typeof(Player),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyPrefix]
		private static void Prefix(HealthHandler __instance, out float __state)
		{
			__state = GetHealthSafe(__instance);
		}

		[HarmonyPatch("TakeDamage", new Type[]
		{
			typeof(Vector2),
			typeof(Vector2),
			typeof(Color),
			typeof(GameObject),
			typeof(Player),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyPostfix]
		private static void Postfix(HealthHandler __instance, GameObject damagingWeapon, Player damagingPlayer, float __state)
		{
			try
			{
				float healthSafe = GetHealthSafe(__instance);
				float num = Mathf.Max(0f, __state - healthSafe);
				ManualLogSource log = RecapDmgUiModPlugin.Log;
				if (log != null)
				{
					log.LogInfo((object)$"[RecapDmgUiMod] TakeDamage: before={__state:0.##} after={healthSafe:0.##} delta={num:0.##} attacker={(((Object)(object)damagingPlayer != (Object)null) ? damagingPlayer.playerID : (-1))}");
				}
				if (RecapDmgUiModPlugin.IsHostSafe() && !(num <= 0f))
				{
					int num2 = -1;
					if ((Object)(object)damagingPlayer != (Object)null)
					{
						num2 = damagingPlayer.playerID;
					}
					if (num2 < 0)
					{
						num2 = ResolveAttackerId(damagingWeapon);
					}
					if (num2 >= 0)
					{
						RecapDmgUiModPlugin.AddDamage(num2, num);
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource log2 = RecapDmgUiModPlugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)$"[RecapDmgUiMod] Postfix error: {arg}");
				}
			}
		}

		private static float GetHealthSafe(HealthHandler hh)
		{
			if ((Object)(object)hh == (Object)null)
			{
				return 0f;
			}
			if (_fiHealth == null)
			{
				_fiHealth = ((object)hh).GetType().GetField("health", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? ((object)hh).GetType().GetField("currentHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_fiHealth != null && _fiHealth.GetValue(hh) is float result)
			{
				return result;
			}
			object obj = ((object)hh).GetType().GetField("data", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(hh);
			if (obj != null)
			{
				Type type = obj.GetType();
				FieldInfo fieldInfo = type.GetField("health", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("currentHealth", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) ?? type.GetField("hp", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (fieldInfo != null && fieldInfo.GetValue(obj) is float result2)
				{
					return result2;
				}
			}
			return 0f;
		}

		private static int ResolveAttackerId(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return -1;
			}
			Player val = go.GetComponent<Player>() ?? go.GetComponentInParent<Player>();
			if ((Object)(object)val != (Object)null)
			{
				return val.playerID;
			}
			ProjectileHit val2 = go.GetComponent<ProjectileHit>() ?? go.GetComponentInParent<ProjectileHit>();
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.ownPlayer != (Object)null)
			{
				return val2.ownPlayer.playerID;
			}
			return -1;
		}
	}
	[HarmonyPatch(typeof(HealthHandler))]
	public static class Patch_HealthHandler_DoDamage
	{
		[HarmonyPatch("DoDamage", new Type[]
		{
			typeof(Vector2),
			typeof(Vector2),
			typeof(Color),
			typeof(GameObject),
			typeof(Player),
			typeof(bool),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyPostfix]
		private static void Postfix(HealthHandler __instance, Vector2 damage, Vector2 position, Color blinkColor, GameObject damagingWeapon, Player damagingPlayer, bool healthRemoval, bool lethal, bool ignoreBlock)
		{
			try
			{
				if (!RecapDmgUiModPlugin.IsHostSafe())
				{
					return;
				}
				float magnitude = ((Vector2)(ref damage)).magnitude;
				if (magnitude <= 0f)
				{
					return;
				}
				int num = -1;
				if ((Object)(object)damagingPlayer != (Object)null)
				{
					num = damagingPlayer.playerID;
				}
				if (num < 0 && (Object)(object)damagingWeapon != (Object)null)
				{
					ProjectileHit val = damagingWeapon.GetComponent<ProjectileHit>() ?? damagingWeapon.GetComponentInParent<ProjectileHit>();
					if ((Object)(object)val != (Object)null && (Object)(object)val.ownPlayer != (Object)null)
					{
						num = val.ownPlayer.playerID;
					}
					if (num < 0)
					{
						Player val2 = damagingWeapon.GetComponent<Player>() ?? damagingWeapon.GetComponentInParent<Player>();
						if ((Object)(object)val2 != (Object)null)
						{
							num = val2.playerID;
						}
					}
				}
				if (num >= 0)
				{
					RecapDmgUiModPlugin.AddDamage(num, magnitude);
					ManualLogSource log = RecapDmgUiModPlugin.Log;
					if (log != null)
					{
						log.LogInfo((object)$"[RecapDmgUiMod] DoDamage +{magnitude:0.##} by P{num}");
					}
				}
			}
			catch (Exception arg)
			{
				ManualLogSource log2 = RecapDmgUiModPlugin.Log;
				if (log2 != null)
				{
					log2.LogError((object)$"[RecapDmgUiMod] DoDamage postfix error: {arg}");
				}
			}
		}
	}
}