Decompiled source of NM Enemy Info REPO v0.2.0

BepInEx/plugins/NM_Enemy_Info_REPO/NM_Enemy_Info_REPO.dll

Decompiled 2 days 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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Nightmare.REPO.Core;
using Nightmare.REPO.Localization;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Nightmare Community / NM")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 Nick1Z2 (Nightmare Community / NM).")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("NM_Enemy_Info_REPO")]
[assembly: AssemblyTitle("NM_Enemy_Info_REPO")]
[assembly: AssemblyVersion("0.1.0.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 Nightmare.REPO.Localization
{
	internal static class L
	{
		internal static readonly Dictionary<string, string> Translations = new Dictionary<string, string>(StringComparer.Ordinal)
		{
			{ "Gegner", "Enemy" },
			{ "Gegner-Lebensanzeige lokal aktivieren.", "Enable the local enemy health display." },
			{ "Gebündelte Schadenszahlen anzeigen. Ohne NM-Host nur vom Spiel gemeldeter Rohschaden.", "Show combined damage numbers. Without an NM host, only raw damage reported by the game is available." },
			{ "Lebensanzeige dauerhaft; aus: nach Spawn oder Änderung für die eingestellte Dauer.", "Show health permanently; when off, show it for the configured duration after spawning or a change." },
			{ "Gegnernamen anzeigen.", "Show enemy names." },
			{ "Balken, Zahlen oder beides.", "Bar, numbers or both. BalkenUndZahlen = both; NurBalken = bar only; NurZahlen = numbers only." },
			{ "Maximale Entfernung in Metern.", "Maximum distance in meters." },
			{ "Größe der Anzeige.", "Display size." },
			{ "Anzeigedauer, wenn Dauerhaft aus ist.", "Display duration when permanent display is disabled." },
			{ "Zeit für zusammengefasste Schadenszahlen.", "Duration of combined damage numbers." },
			{ "Zusätzlicher Höhenversatz über dem Gegner.", "Additional height offset above the enemy." },
			{ "Normale Balkenfarbe.", "Normal health bar color." },
			{ "Balkenfarbe unter 30 Prozent.", "Health bar color below 30 percent." },
			{ "Farbe für Namen und Lebenszahlen.", "Color of names and health numbers." },
			{ "Schaden", "Damage" },
			{ "Farbe der Schadenszahlen.", "Damage number color." },
			{ "Gegner-Info", "Enemy Info" },
			{ "Schadenszahlen und Gegnerleben; bestätigte HP vom NM-Host für Gäste.", "Damage numbers and enemy health; confirmed HP from the NM host for guests." },
			{ "Original REPO MOD ist ebenfalls geladen. Bitte einen der beiden Anzeigemods entfernen und das Spiel neu starten.", "The original REPO MOD is also loaded. Remove one of the two display mods and restart the game." },
			{ "Gegneranzeige angehalten: ", "Enemy display stopped: " },
			{ "GEGNER-INFO", "ENEMY INFO" },
			{ "Anzeige wird vorbereitet.", "Preparing display." },
			{ "Host: tatsächliche HP und tatsächlicher Schaden.", "Host: actual HP and actual damage." },
			{ "Gast: bestätigte HP vom NM-Host.", "Guest: confirmed HP from the NM host." },
			{ "Gast: HP unbekannt. Ohne NM-Host zeigen Schadenszahlen nur gemeldeten Rohschaden (~).", "Guest: HP unknown. Without an NM host, damage numbers only show reported raw damage (~)." },
			{ "Lebensanzeige aktiv", "Enable health display" },
			{ "Schadenszahlen anzeigen", "Show damage numbers" },
			{ "Lebensanzeige dauerhaft", "Show health permanently" },
			{ "Gegnernamen anzeigen", "Show enemy names" },
			{ "Darstellung: ", "Display: " },
			{ " · wechseln", " · change" },
			{ "Reichweite (Meter)", "Range (meters)" },
			{ "Größe", "Size" },
			{ "Lebensanzeige (Sekunden)", "Health display (seconds)" },
			{ "Schadenszahlen (Sekunden)", "Damage numbers (seconds)" },
			{ "Zusätzliche Höhe (Meter)", "Additional height (meters)" },
			{ "Balken", "Bar" },
			{ "Wenig Leben", "Low health" },
			{ "Speicherung automatisch. Änderungen gelten für deine Anzeige. Die Übertragung an passende Gäste bleibt unabhängig von deinen Anzeige-Schaltern aktiv. Veraltete oder fehlende HP werden als ? angezeigt. Gegner mit vollständig eigenem Lebenssystem benötigen einen Adapter.", "Saved automatically. Changes affect your display. Transmission to compatible guests stays active independently of your display switches. Stale or missing HP appears as ?. Enemies with a completely custom health system require an adapter." },
			{ " · Rot / Grün / Blau", " · Red / Green / Blue" },
			{ "BalkenUndZahlen", "Bar and numbers" },
			{ "NurBalken", "Bar only" },
			{ "NurZahlen", "Numbers only" }
		};

		[ThreadStatic]
		private static string? captureLanguage;

		internal static string Language => captureLanguage ?? CoreApi.Language;

		internal static string T(string german)
		{
			if (!(Language == "de"))
			{
				return English(german);
			}
			return german;
		}

		internal static string English(string german)
		{
			if (!Translations.TryGetValue(german, out string value) || value == null)
			{
				return german;
			}
			return value;
		}

		internal static string Help(string german)
		{
			return "DE: " + german + "\nEN: " + English(german);
		}

		internal static LocalText Capture(Func<string> render)
		{
			string text = captureLanguage;
			try
			{
				captureLanguage = "de";
				string german = render();
				captureLanguage = "en";
				return new LocalText(german, render());
			}
			finally
			{
				captureLanguage = text;
			}
		}

		internal static AddonDefinition Describe(AddonDefinition definition, string name, string description)
		{
			definition.NameProvider = () => T(name);
			definition.DescriptionProvider = () => T(description);
			return definition;
		}
	}
	internal sealed class LocalText
	{
		private readonly string de;

		private readonly string en;

		internal int Length => ToString().Length;

		internal LocalText(string german, string english)
		{
			de = german;
			en = english;
		}

		public override string ToString()
		{
			if (!(L.Language == "de"))
			{
				return en;
			}
			return de;
		}

		public static implicit operator string(LocalText value)
		{
			return value.ToString();
		}

		public static implicit operator LocalText(string value)
		{
			return new LocalText(value, value);
		}
	}
}
namespace Nightmare.REPO.EnemyInfo
{
	internal sealed class EnemyHud
	{
		private sealed class Row
		{
			internal EnemyTrack Track;

			internal Vector2 Point;

			internal bool Visible;

			internal bool Known;

			internal int Hp = -1;

			internal int Max = -1;

			internal long Pop = -1L;

			internal string HealthText = "?";

			internal string PopText = "";

			internal string Name = "";
		}

		private readonly Plugin plugin;

		private readonly Row[] rows = (from _ in Enumerable.Range(0, 32)
			select new Row()).ToArray();

		private EnemyTrack[] selected = Array.Empty<EnemyTrack>();

		private GUIStyle? text;

		private GUIStyle? damageStyle;

		private float nextSelection;

		internal EnemyHud(Plugin plugin)
		{
			this.plugin = plugin;
		}

		internal void Update(EnemyRuntime runtime)
		{
			//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_0218: 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_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: 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_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: 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_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: 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_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)main) || (!plugin.Show.Value && !plugin.Damage.Value))
			{
				Row[] array = rows;
				for (int i = 0; i < array.Length; i++)
				{
					array[i].Visible = false;
				}
				return;
			}
			Vector3 origin = ((Component)main).transform.position;
			float maxDistance = plugin.Range.Value * plugin.Range.Value;
			if (Time.unscaledTime >= nextSelection)
			{
				nextSelection = Time.unscaledTime + 0.25f;
				foreach (EnemyTrack value in runtime.Tracks.Values)
				{
					if (Object.op_Implicit((Object)(object)value.Health) && ((Component)value.Health).gameObject.activeInHierarchy && Object.op_Implicit((Object)(object)value.Center))
					{
						value.Position = value.Center.position;
					}
				}
				selected = runtime.Tracks.Values.Where(delegate(EnemyTrack t)
				{
					//IL_0042: 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_0052: Unknown result type (might be due to invalid IL or missing references)
					if (((Object.op_Implicit((Object)(object)t.Health) && ((Component)t.Health).gameObject.activeInHierarchy) || t.PopUntil > Time.unscaledTime) && (!t.Dead || t.PopUntil > Time.unscaledTime))
					{
						Vector3 val3 = t.Position - origin;
						return ((Vector3)(ref val3)).sqrMagnitude <= maxDistance;
					}
					return false;
				}).OrderBy(delegate(EnemyTrack t)
				{
					//IL_0001: 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_0011: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val3 = t.Position - origin;
					return ((Vector3)(ref val3)).sqrMagnitude;
				}).Take(rows.Length)
					.ToArray();
			}
			for (int num = 0; num < rows.Length; num++)
			{
				Row row = rows[num];
				row.Visible = false;
				if (num >= selected.Length)
				{
					continue;
				}
				EnemyTrack enemyTrack = selected[num];
				if (Object.op_Implicit((Object)(object)enemyTrack.Center) && Object.op_Implicit((Object)(object)enemyTrack.Health) && ((Component)enemyTrack.Health).gameObject.activeInHierarchy)
				{
					enemyTrack.Position = enemyTrack.Center.position;
				}
				if ((!Object.op_Implicit((Object)(object)enemyTrack.Health) || !((Component)enemyTrack.Health).gameObject.activeInHierarchy) && enemyTrack.PopUntil <= Time.unscaledTime)
				{
					continue;
				}
				Vector3 val = enemyTrack.Position - origin;
				if (((Vector3)(ref val)).sqrMagnitude > maxDistance)
				{
					continue;
				}
				Vector3 val2 = main.WorldToScreenPoint(enemyTrack.Position + Vector3.up * (enemyTrack.Height + plugin.Height.Value));
				if (!(val2.z <= 0f) && !(val2.x < 0f) && !(val2.x > (float)Screen.width) && !(val2.y < 0f) && !(val2.y > (float)Screen.height))
				{
					bool flag = enemyTrack.Known && runtime.Synced;
					if (row.Track != enemyTrack || row.Hp != enemyTrack.Hp || row.Max != enemyTrack.Max || row.Known != flag || row.Name != enemyTrack.Name)
					{
						row.HealthText = (flag ? (enemyTrack.Hp + " / " + enemyTrack.Max) : "? / ?");
						row.Hp = enemyTrack.Hp;
						row.Max = enemyTrack.Max;
						row.Known = flag;
						row.Name = enemyTrack.Name;
					}
					string text = ((runtime.Host || runtime.HostAnnounced) ? "−" : "~−");
					if (row.Track != enemyTrack || row.Pop != enemyTrack.Pop || !row.PopText.StartsWith(text, StringComparison.Ordinal))
					{
						row.PopText = text + enemyTrack.Pop;
						row.Pop = enemyTrack.Pop;
					}
					row.Track = enemyTrack;
					row.Point = new Vector2(val2.x, (float)Screen.height - val2.y);
					row.Visible = true;
				}
			}
		}

		internal void Draw()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_03e4: 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_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_002d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type != 7)
			{
				return;
			}
			if (text == null)
			{
				text = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					richText = false,
					wordWrap = false,
					fontStyle = (FontStyle)1
				};
				damageStyle = new GUIStyle(text);
			}
			Color color = GUI.color;
			int depth = GUI.depth;
			GUI.depth = -100;
			try
			{
				float num = plugin.Scale.Value * Mathf.Clamp((float)Screen.height / 1080f, 0.6f, 2f);
				text.fontSize = Mathf.RoundToInt(15f * num);
				damageStyle.fontSize = Mathf.RoundToInt(22f * num);
				Row[] array = rows;
				foreach (Row row in array)
				{
					if (!row.Visible)
					{
						continue;
					}
					EnemyTrack track = row.Track;
					float num2 = 150f * num;
					float num3 = row.Point.x - num2 / 2f;
					float y = row.Point.y;
					if (plugin.Show.Value && Object.op_Implicit((Object)(object)track.Health) && ((Component)track.Health).gameObject.activeInHierarchy && !track.Dead && (plugin.Always.Value || track.VisibleUntil > Time.unscaledTime))
					{
						if (plugin.Names.Value)
						{
							Label(new Rect(num3 - 50f * num, y - 24f * num, num2 + 100f * num, 22f * num), row.Name, text, plugin.TextColor.Value);
						}
						if (plugin.Mode.Value != HealthDisplay.NurZahlen)
						{
							GUI.color = new Color(0.03f, 0.04f, 0.06f, 0.9f);
							GUI.DrawTexture(new Rect(num3, y, num2, 12f * num), (Texture)(object)Texture2D.whiteTexture);
							if (row.Known)
							{
								float num4 = Mathf.Clamp01((float)row.Hp / (float)Math.Max(1, row.Max));
								GUI.color = ((num4 < 0.3f) ? plugin.LowColor.Value : plugin.BarColor.Value);
								GUI.DrawTexture(new Rect(num3 + num, y + num, (num2 - 2f * num) * num4, 10f * num), (Texture)(object)Texture2D.whiteTexture);
							}
						}
						if (plugin.Mode.Value != HealthDisplay.NurBalken || !row.Known)
						{
							Label(new Rect(num3, y + 12f * num, num2, 24f * num), row.HealthText, text, plugin.TextColor.Value);
						}
					}
					if (plugin.Damage.Value && track.Pop > 0 && track.PopUntil > Time.unscaledTime)
					{
						float num5 = track.PopUntil - Time.unscaledTime;
						float num6 = 25f * num * (1f - Mathf.Clamp01(num5 / plugin.DamageDuration));
						Color value = plugin.DamageColor.Value;
						value.a *= Mathf.Clamp01(num5 / 0.3f);
						Label(new Rect(num3, y - 58f * num - num6, num2, 28f * num), row.PopText, damageStyle, value);
					}
				}
			}
			finally
			{
				GUI.color = color;
				GUI.depth = depth;
			}
		}

		private static void Label(Rect rect, string value, GUIStyle style, Color color)
		{
			//IL_0000: 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_0025: 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_0069: 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)
			GUI.color = Color.white;
			style.normal.textColor = new Color(0f, 0f, 0f, color.a);
			GUI.Label(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width, ((Rect)(ref rect)).height), value, style);
			style.normal.textColor = color;
			GUI.Label(rect, value, style);
		}
	}
	internal sealed class EnemyTrack
	{
		internal EnemyHealth Health;

		internal PhotonView? View;

		internal Transform? Center;

		internal Vector3 Position;

		internal float Height = 1.5f;

		internal float VisibleUntil;

		internal float PopUntil;

		internal float RetainUntil;

		internal int ViewId;

		internal int Life = 1;

		internal int Hp;

		internal int Max;

		internal bool Dead;

		internal bool Known;

		internal bool Dirty = true;

		internal long Damage;

		internal long Pop;

		internal string Name = L.T("Gegner");

		internal EnemyState State()
		{
			return new EnemyState
			{
				View = ViewId,
				Life = Life,
				Hp = Hp,
				Max = Max,
				Dead = Dead,
				Damage = Damage,
				Name = Name
			};
		}
	}
	internal sealed class EnemyRuntime : IOnEventCallback, IDisposable
	{
		internal const string Capability = "nm.enemy.hp.v1";

		private const byte Code = 192;

		private readonly Plugin plugin;

		private readonly Harmony harmony = new Harmony("nightmare.repo.enemyinfo");

		private static readonly FieldRef<EnemyHealth, int> Hp = AccessTools.FieldRefAccess<EnemyHealth, int>("healthCurrent");

		private static readonly FieldRef<EnemyHealth, bool> Dead = AccessTools.FieldRefAccess<EnemyHealth, bool>("dead");

		internal readonly Dictionary<int, EnemyTrack> Tracks = new Dictionary<int, EnemyTrack>();

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

		private readonly EnemyInbox inbox = new EnemyInbox();

		private object? room;

		private int scene = -1;

		private int master;

		private int sequence;

		private string scope = "";

		private string token = "";

		private string hostToken = "";

		private float nextScan;

		private float nextSend;

		private float nextHeartbeat;

		private float lastPacket;

		private bool registered;

		internal static EnemyRuntime? Current;

		internal bool Host => SemiFunc.IsMasterClientOrSingleplayer();

		private static string Scope => CoreApi.Context.SceneName + ":" + (Object.op_Implicit((Object)(object)RunManager.instance) ? RunManager.instance.levelsCompleted : (-1));

		internal bool HostAnnounced
		{
			get
			{
				if (PhotonNetwork.InRoom)
				{
					Player masterClient = PhotonNetwork.MasterClient;
					return ValidCapability(((masterClient != null) ? masterClient.CustomProperties[(object)"nm.enemy.hp.v1"] : null) as string);
				}
				return false;
			}
		}

		internal bool Synced
		{
			get
			{
				if (!Host)
				{
					if (HostAnnounced)
					{
						string text = hostToken;
						Player masterClient = PhotonNetwork.MasterClient;
						if (text == ((masterClient != null) ? masterClient.CustomProperties[(object)"nm.enemy.hp.v1"] : null) as string)
						{
							return Time.unscaledTime - lastPacket < 25f;
						}
					}
					return false;
				}
				return true;
			}
		}

		internal EnemyRuntime(Plugin plugin)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			this.plugin = plugin;
			Current = this;
			try
			{
				Patch("Awake", null, "Awoke");
				Patch("OnSpawn", null, "Spawned");
				Patch("Hurt", "BeforeHurt", "AfterHurt");
				Patch("HurtRPC", null, "LocalHurt");
				Patch("Heal", null, "Changed");
				Patch("DeathImpulseRPC", null, "Changed");
			}
			catch
			{
				harmony.UnpatchSelf();
				Current = null;
				throw;
			}
		}

		private void Patch(string method, string? prefix, string? postfix)
		{
			//IL_0034: 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)
			MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(EnemyHealth), method, (Type[])null, (Type[])null) ?? throw new MissingMethodException(method);
			harmony.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(EnemyRuntime), prefix, (Type[])null), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(EnemyRuntime), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void Safe(Action<EnemyRuntime> action)
		{
			EnemyRuntime current = Current;
			if (current == null || !((Behaviour)current.plugin).isActiveAndEnabled)
			{
				return;
			}
			try
			{
				action(current);
			}
			catch (Exception ex)
			{
				current.plugin.Fail(ex);
			}
		}

		private static void Awoke(EnemyHealth __instance)
		{
			Safe(delegate(EnemyRuntime s)
			{
				s.Track(__instance);
			});
		}

		private static void Spawned(EnemyHealth __instance)
		{
			Safe(delegate(EnemyRuntime s)
			{
				EnemyTrack enemyTrack = s.Track(__instance);
				if (enemyTrack != null)
				{
					enemyTrack.Pop = 0L;
					if (s.Host)
					{
						enemyTrack.Life++;
						enemyTrack.Damage = 0L;
						enemyTrack.Dead = false;
						enemyTrack.Known = false;
						enemyTrack.Dirty = true;
						s.Capture(enemyTrack);
					}
				}
			});
		}

		private static void BeforeHurt(EnemyHealth __instance, out int __state)
		{
			__state = Hp.Invoke(__instance);
		}

		private static void AfterHurt(EnemyHealth __instance, int __state)
		{
			Safe(delegate(EnemyRuntime s)
			{
				if (s.Host)
				{
					EnemyTrack enemyTrack = s.Track(__instance);
					if (enemyTrack != null)
					{
						int num = Math.Max(0, __state - Hp.Invoke(__instance));
						if (num > 0)
						{
							enemyTrack.Damage = Math.Min(1000000000000L, enemyTrack.Damage + num);
							s.Pop(enemyTrack, num);
						}
						s.Capture(enemyTrack);
					}
				}
			});
		}

		private static void Changed(EnemyHealth __instance)
		{
			Safe(delegate(EnemyRuntime s)
			{
				EnemyTrack enemyTrack = s.Track(__instance);
				if (enemyTrack != null && s.Host)
				{
					s.Capture(enemyTrack);
				}
			});
		}

		private static void LocalHurt(EnemyHealth __instance, int _damage, PhotonMessageInfo _info)
		{
			//IL_000d: 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)
			Safe(delegate(EnemyRuntime s)
			{
				if (!s.Host && !s.HostAnnounced && _damage > 0 && _info.Sender != null && _info.Sender.IsMasterClient)
				{
					EnemyTrack enemyTrack = s.Track(__instance);
					if (enemyTrack != null)
					{
						enemyTrack.Known = false;
						s.Pop(enemyTrack, _damage);
					}
				}
			});
		}

		private void Pop(EnemyTrack t, long damage)
		{
			t.Pop = ((Time.unscaledTime <= t.PopUntil) ? Math.Min(1000000000000L, t.Pop + damage) : damage);
			t.PopUntil = Time.unscaledTime + plugin.DamageDuration;
			t.VisibleUntil = Time.unscaledTime + plugin.HealthDuration;
		}

		private EnemyTrack? Track(EnemyHealth health)
		{
			//IL_00c9: 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_00d2: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)health))
			{
				return null;
			}
			if (Tracks.TryGetValue(((Object)health).GetInstanceID(), out EnemyTrack value))
			{
				if (Object.op_Implicit((Object)(object)value.View))
				{
					value.ViewId = value.View.ViewID;
				}
				return value;
			}
			if (Tracks.Count >= 512)
			{
				return null;
			}
			EnemyParent componentInParent = ((Component)health).GetComponentInParent<EnemyParent>();
			Transform val = ((Component)health).transform;
			object? obj = CoreReflection.Field(typeof(EnemyHealth), "enemy")?.GetValue(health);
			Enemy val2 = (Enemy)((obj is Enemy) ? obj : null);
			if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.CenterTransform))
			{
				val = val2.CenterTransform;
			}
			Collider val3 = (Object.op_Implicit((Object)(object)componentInParent) ? ((Component)componentInParent).GetComponentInChildren<Collider>() : null);
			float num;
			if (!Object.op_Implicit((Object)(object)val3))
			{
				num = 1.5f;
			}
			else
			{
				Bounds bounds = val3.bounds;
				num = Mathf.Clamp(((Bounds)(ref bounds)).max.y - val.position.y + 0.4f, 0.5f, 10f);
			}
			float height = num;
			EnemyTrack enemyTrack = new EnemyTrack
			{
				Health = health,
				View = ((Component)health).GetComponent<PhotonView>(),
				Center = val,
				Height = height,
				Position = val.position,
				Name = CombatText.Clean(Object.op_Implicit((Object)(object)componentInParent) ? componentInParent.enemyName : ((Object)health).name, "Unbekannt"),
				VisibleUntil = Time.unscaledTime + plugin.HealthDuration
			};
			if (Object.op_Implicit((Object)(object)enemyTrack.View))
			{
				enemyTrack.ViewId = enemyTrack.View.ViewID;
			}
			Tracks.Add(((Object)health).GetInstanceID(), enemyTrack);
			EnemyState value2;
			if (Host)
			{
				Capture(enemyTrack);
			}
			else if (Object.op_Implicit((Object)(object)enemyTrack.View) && inbox.States.TryGetValue(enemyTrack.View.ViewID, out value2))
			{
				Apply(enemyTrack, value2, 0L);
			}
			return enemyTrack;
		}

		private void Capture(EnemyTrack t)
		{
			//IL_0077: 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)
			int num = Math.Max(0, Hp.Invoke(t.Health));
			int num2 = Math.Max(1, t.Health.health);
			bool flag = Dead.Invoke(t.Health) || num == 0;
			if (Object.op_Implicit((Object)(object)t.View))
			{
				t.ViewId = t.View.ViewID;
			}
			if (Object.op_Implicit((Object)(object)t.Center))
			{
				t.Position = t.Center.position;
			}
			if (!t.Known || t.Hp != num || t.Max != num2 || t.Dead != flag)
			{
				t.Dirty = true;
				t.VisibleUntil = Time.unscaledTime + plugin.HealthDuration;
			}
			t.RetainUntil = Time.unscaledTime + 2f;
			t.Known = true;
			t.Hp = num;
			t.Max = num2;
			t.Dead = flag;
		}

		internal void Tick()
		{
			//IL_011c: 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_013d: Expected O, but got Unknown
			if (!registered)
			{
				PhotonNetwork.AddCallbackTarget((object)this);
				registered = true;
			}
			int num = CoreApi.Context.Scene;
			Player masterClient = PhotonNetwork.MasterClient;
			int num2 = ((masterClient != null) ? masterClient.ActorNumber : 0);
			string text = Scope;
			if (scene != num || room != PhotonNetwork.CurrentRoom || num2 != master || scope != text)
			{
				Tracks.Clear();
				inbox.Clear();
				recipients.Clear();
				scene = num;
				room = PhotonNetwork.CurrentRoom;
				master = num2;
				scope = text;
				token = scope + "|" + Guid.NewGuid().ToString("N");
				hostToken = "";
				sequence = 0;
				lastPacket = float.NegativeInfinity;
				nextScan = (nextSend = (nextHeartbeat = 0f));
				if (PhotonNetwork.InRoom)
				{
					PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable { [(object)"nm.enemy.hp.v1"] = token }, (Hashtable)null, (WebFlags)null);
					CoreTraffic.Record("Gegner-Anmeldung", token.Length * 2 + 32);
				}
			}
			if (!Host)
			{
				Player masterClient2 = PhotonNetwork.MasterClient;
				string text2 = (((masterClient2 != null) ? masterClient2.CustomProperties[(object)"nm.enemy.hp.v1"] : null) as string) ?? "";
				if (text2 != hostToken)
				{
					hostToken = text2;
					inbox.Clear();
					lastPacket = float.NegativeInfinity;
					foreach (EnemyTrack value2 in Tracks.Values)
					{
						value2.Known = false;
					}
				}
			}
			int[] array;
			if (Time.unscaledTime >= nextScan)
			{
				nextScan = Time.unscaledTime + 0.5f;
				foreach (EnemyTrack value3 in Tracks.Values)
				{
					if (Object.op_Implicit((Object)(object)value3.Health) && ((Component)value3.Health).gameObject.activeInHierarchy)
					{
						value3.RetainUntil = Time.unscaledTime + 2f;
					}
				}
				array = (from p in Tracks
					where !Object.op_Implicit((Object)(object)p.Value.Health) && (!Host || !p.Value.Dirty || p.Value.ViewId <= 0) && Time.unscaledTime > Math.Max(p.Value.PopUntil, p.Value.RetainUntil)
					select p.Key).ToArray();
				foreach (int key in array)
				{
					Tracks.Remove(key);
				}
				if (Object.op_Implicit((Object)(object)EnemyDirector.instance) && EnemyDirector.instance.enemiesSpawned != null)
				{
					foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
					{
						if (Object.op_Implicit((Object)(object)item))
						{
							object? obj2 = CoreReflection.Field(typeof(EnemyParent), "Enemy")?.GetValue(item);
							Enemy val = (Enemy)((obj2 is Enemy) ? obj2 : null);
							EnemyHealth val2 = (EnemyHealth)(Object.op_Implicit((Object)(object)val) ? /*isinst with value type is only supported in some contexts*/: null);
							if (Object.op_Implicit((Object)(object)val2))
							{
								Track(val2);
							}
						}
					}
				}
			}
			if (!Host || Time.unscaledTime < nextSend)
			{
				return;
			}
			nextSend = Time.unscaledTime + 0.2f;
			foreach (EnemyTrack value4 in Tracks.Values)
			{
				if (Object.op_Implicit((Object)(object)value4.Health) && ((Component)value4.Health).gameObject.activeInHierarchy)
				{
					Capture(value4);
				}
			}
			if (!PhotonNetwork.InRoom)
			{
				foreach (EnemyTrack value5 in Tracks.Values)
				{
					value5.Dirty = false;
				}
				return;
			}
			EnemyTrack[] array2 = Tracks.Values.Where((EnemyTrack t) => t.ViewId > 0 && (t.Dirty || t.RetainUntil > Time.unscaledTime || (Object.op_Implicit((Object)(object)t.Health) && ((Component)t.Health).gameObject.activeInHierarchy))).ToArray();
			EnemyTrack[] array3 = array2.Where((EnemyTrack t) => t.Dirty).ToArray();
			bool flag = Time.unscaledTime >= nextHeartbeat;
			if (flag)
			{
				nextHeartbeat = Time.unscaledTime + 10f;
			}
			Player[] playerList = PhotonNetwork.PlayerList;
			foreach (Player val3 in playerList)
			{
				string text3 = val3.CustomProperties[(object)"nm.enemy.hp.v1"] as string;
				if (val3.IsLocal || !ValidCapability(text3))
				{
					continue;
				}
				string value;
				bool flag2 = !recipients.TryGetValue(val3.ActorNumber, out value) || value != text3;
				EnemyTrack[] array4 = (flag2 ? array2 : array3);
				bool flag3 = true;
				if (array4.Length != 0)
				{
					for (int num4 = 0; num4 < array4.Length; num4 += 32)
					{
						flag3 &= Send(val3.ActorNumber, text3, array4.Skip(num4).Take(32).Select((Func<EnemyTrack, object>)((EnemyTrack t) => t.State().Encode()))
							.ToArray());
					}
				}
				else if (flag2 || flag)
				{
					flag3 = Send(val3.ActorNumber, text3, Array.Empty<object>());
				}
				if (flag3)
				{
					recipients[val3.ActorNumber] = text3;
				}
				else
				{
					recipients.Remove(val3.ActorNumber);
				}
			}
			array = recipients.Keys.Where((int a) => !PhotonNetwork.CurrentRoom.Players.ContainsKey(a)).ToArray();
			foreach (int key2 in array)
			{
				recipients.Remove(key2);
			}
			EnemyTrack[] array5 = array2;
			for (int num3 = 0; num3 < array5.Length; num3++)
			{
				array5[num3].Dirty = false;
			}
		}

		private bool ValidCapability(string? cap)
		{
			if (cap != null && cap.Length == scope.Length + 33)
			{
				return cap.StartsWith(scope + "|", StringComparison.Ordinal);
			}
			return false;
		}

		private bool Send(int actor, string nonce, object[] rows)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_005e: 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)
			object[] obj = new object[6]
			{
				"nm.enemy.hp.v1",
				nonce,
				token,
				scope,
				++sequence,
				rows
			};
			RaiseEventOptions val = new RaiseEventOptions();
			val.TargetActors = new int[1] { actor };
			val.CachingOption = (EventCaching)0;
			bool num = PhotonNetwork.RaiseEvent((byte)192, (object)obj, val, SendOptions.SendReliable);
			if (num)
			{
				CoreTraffic.Record("Gegner-HP", 200 + rows.Length * 100);
			}
			return num;
		}

		public void OnEvent(EventData e)
		{
			if (e.Code != 192 || Host || !PhotonNetwork.InRoom)
			{
				return;
			}
			int sender = e.Sender;
			Player masterClient = PhotonNetwork.MasterClient;
			if (sender != ((masterClient != null) ? new int?(masterClient.ActorNumber) : ((int?)null)) || room != PhotonNetwork.CurrentRoom || !(e.CustomData is object[] array) || array.Length != 6 || !object.Equals(array[0], "nm.enemy.hp.v1") || !object.Equals(array[1], token) || !object.Equals(array[3], scope) || !(array[2] is string text))
			{
				return;
			}
			Player masterClient2 = PhotonNetwork.MasterClient;
			if (text != ((masterClient2 != null) ? masterClient2.CustomProperties[(object)"nm.enemy.hp.v1"] : null) as string || !ValidCapability(text) || !(array[4] is int nextSequence) || !(array[5] is object[] rows))
			{
				return;
			}
			if (hostToken != text)
			{
				hostToken = text;
				inbox.Clear();
				foreach (EnemyTrack value in Tracks.Values)
				{
					value.Known = false;
				}
			}
			if (inbox.Apply(nextSequence, rows, delegate(EnemyState s, long damage)
			{
				EnemyTrack enemyTrack = Tracks.Values.FirstOrDefault((EnemyTrack v) => v.ViewId == s.View);
				if (enemyTrack == null)
				{
					PhotonView val = PhotonView.Find(s.View);
					EnemyHealth val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<EnemyHealth>() : null);
					if (Object.op_Implicit((Object)(object)val2))
					{
						enemyTrack = Track(val2);
					}
				}
				if (enemyTrack != null)
				{
					Apply(enemyTrack, s, damage);
				}
			}))
			{
				lastPacket = Time.unscaledTime;
			}
		}

		private void Apply(EnemyTrack t, EnemyState s, long damage)
		{
			if (!t.Known || t.Hp != s.Hp || t.Life != s.Life)
			{
				t.VisibleUntil = Time.unscaledTime + plugin.HealthDuration;
			}
			t.Known = true;
			t.Hp = s.Hp;
			t.Max = s.Max;
			t.Dead = s.Dead;
			t.Life = s.Life;
			t.Name = s.Name;
			if (damage > 0)
			{
				Pop(t, damage);
			}
		}

		public void Dispose()
		{
			//IL_0025: 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_003f: Expected O, but got Unknown
			harmony.UnpatchSelf();
			if (registered)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
			}
			if (PhotonNetwork.InRoom)
			{
				PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable { [(object)"nm.enemy.hp.v1"] = null }, (Hashtable)null, (WebFlags)null);
			}
			Tracks.Clear();
			inbox.Clear();
			recipients.Clear();
			if (Current == this)
			{
				Current = null;
			}
		}
	}
	internal sealed class EnemyState
	{
		internal int View;

		internal int Life;

		internal int Hp;

		internal int Max;

		internal bool Dead;

		internal long Damage;

		internal string Name = "";

		internal object[] Encode()
		{
			return new object[7] { View, Life, Hp, Max, Dead, Damage, Name };
		}

		internal static EnemyState? Decode(object value)
		{
			if (!(value is object[] array) || array.Length != 7 || !(array[0] is int num) || num <= 0 || !(array[1] is int num2) || num2 < 1 || !(array[2] is int num3) || num3 < 0 || num3 > 1000000000 || !(array[3] is int num4) || num4 < 1 || num4 > 1000000000 || !(array[4] is bool dead) || !(array[5] is long num5) || num5 < 0 || num5 > 1000000000000L || !(array[6] is string { Length: <=100 } text))
			{
				return null;
			}
			string text2 = text;
			foreach (char c in text2)
			{
				if (char.IsControl(c) || c == '<' || c == '>')
				{
					return null;
				}
			}
			return new EnemyState
			{
				View = num,
				Life = num2,
				Hp = num3,
				Max = num4,
				Dead = dead,
				Damage = num5,
				Name = text
			};
		}
	}
	internal sealed class EnemyInbox
	{
		internal readonly Dictionary<int, EnemyState> States = new Dictionary<int, EnemyState>();

		private int sequence;

		internal bool Apply(int nextSequence, object[] rows, Action<EnemyState, long> accept)
		{
			if (nextSequence <= sequence || rows.Length > 32)
			{
				return false;
			}
			List<EnemyState> list = new List<EnemyState>();
			HashSet<int> hashSet = new HashSet<int>();
			for (int i = 0; i < rows.Length; i++)
			{
				EnemyState enemyState = EnemyState.Decode(rows[i]);
				if (enemyState == null || !hashSet.Add(enemyState.View))
				{
					return false;
				}
				list.Add(enemyState);
			}
			sequence = nextSequence;
			foreach (EnemyState item in list)
			{
				States.TryGetValue(item.View, out EnemyState value);
				if ((value == null || (item.Life >= value.Life && (item.Life != value.Life || item.Damage >= value.Damage))) && (value != null || States.Count < 512))
				{
					long arg = ((value != null && value.Life == item.Life) ? (item.Damage - value.Damage) : 0);
					States[item.View] = item;
					accept(item, arg);
				}
			}
			return true;
		}

		internal void Clear()
		{
			States.Clear();
			sequence = 0;
		}
	}
	public enum HealthDisplay
	{
		BalkenUndZahlen,
		NurBalken,
		NurZahlen
	}
	[BepInPlugin("nightmare.repo.enemyinfo", "NM_Enemy_Info_REPO", "0.2.0")]
	[BepInProcess("REPO.exe")]
	[BepInDependency("nightmare.repo.core", "2.10.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "nightmare.repo.enemyinfo";

		public const string Version = "0.2.0";

		private AddonHandle? page;

		private EnemyRuntime? runtime;

		private EnemyHud? hud;

		internal ConfigEntry<bool> Show;

		internal ConfigEntry<bool> Damage;

		internal ConfigEntry<bool> Always;

		internal ConfigEntry<bool> Names;

		internal ConfigEntry<HealthDisplay> Mode;

		internal ConfigEntry<float> Range;

		internal ConfigEntry<float> Scale;

		internal ConfigEntry<float> Duration;

		internal ConfigEntry<float> PopDuration;

		internal ConfigEntry<float> Height;

		internal ConfigEntry<Color> BarColor;

		internal ConfigEntry<Color> LowColor;

		internal ConfigEntry<Color> TextColor;

		internal ConfigEntry<Color> DamageColor;

		private LocalText fault = "";

		private Vector2 scroll;

		private Action? tick;

		internal float HealthDuration => Duration.Value;

		internal float DamageDuration => PopDuration.Value;

		private void Awake()
		{
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: 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_024c: 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_029b: Expected O, but got Unknown
			Show = ((BaseUnityPlugin)this).Config.Bind<bool>("Anzeige", "Aktiv", true, L.Help("Gegner-Lebensanzeige lokal aktivieren."));
			Damage = ((BaseUnityPlugin)this).Config.Bind<bool>("Anzeige", "Schadenszahlen", true, L.Help("Gebündelte Schadenszahlen anzeigen. Ohne NM-Host nur vom Spiel gemeldeter Rohschaden."));
			Always = ((BaseUnityPlugin)this).Config.Bind<bool>("Anzeige", "Dauerhaft", true, L.Help("Lebensanzeige dauerhaft; aus: nach Spawn oder Änderung für die eingestellte Dauer."));
			Names = ((BaseUnityPlugin)this).Config.Bind<bool>("Anzeige", "Gegnernamen", true, L.Help("Gegnernamen anzeigen."));
			Mode = ((BaseUnityPlugin)this).Config.Bind<HealthDisplay>("Anzeige", "Darstellung", HealthDisplay.BalkenUndZahlen, L.Help("Balken, Zahlen oder beides."));
			Range = Number("Reichweite", 30f, 1f, 100f, L.Help("Maximale Entfernung in Metern."));
			Scale = Number("Skalierung", 1f, 0.5f, 2f, L.Help("Größe der Anzeige."));
			Duration = Number("LebensanzeigeSekunden", 10f, 1f, 60f, L.Help("Anzeigedauer, wenn Dauerhaft aus ist."));
			PopDuration = Number("SchadensanzeigeSekunden", 1.5f, 0.3f, 5f, L.Help("Zeit für zusammengefasste Schadenszahlen."));
			Height = Number("Hoehenversatz", 0.5f, -2f, 5f, L.Help("Zusätzlicher Höhenversatz über dem Gegner."));
			BarColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Farben", "Lebensbalken", new Color(0.25f, 0.85f, 0.65f), L.Help("Normale Balkenfarbe."));
			LowColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Farben", "WenigLeben", new Color(1f, 0.3f, 0.25f), L.Help("Balkenfarbe unter 30 Prozent."));
			TextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Farben", "Text", Color.white, L.Help("Farbe für Namen und Lebenszahlen."));
			DamageColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Farben", "Schaden", new Color(1f, 0.8f, 0.25f), L.Help("Farbe der Schadenszahlen."));
			page = CoreApi.Register(L.Describe(new AddonDefinition("nightmare.repo.enemyinfo", "Gegner-Info", "0.2.0", "Schadenszahlen und Gegnerleben; bestätigte HP vom NM-Host für Gäste.", (Action<AddonUi>)Draw, 1), "Gegner-Info", "Schadenszahlen und Gegnerleben; bestätigte HP vom NM-Host für Gäste."));
			hud = new EnemyHud(this);
		}

		private ConfigEntry<float> Number(string key, float value, float min, float max, string description)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<float>("Anzeige", key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
		}

		private void Update()
		{
			CoreRuntime.Run("nightmare.repo.enemyinfo", (Action)Tick);
		}

		private void Tick()
		{
			if (fault.Length > 0)
			{
				return;
			}
			if (Chainloader.PluginInfos.ContainsKey("com.XhPlugin.Repo_Mod"))
			{
				fault = L.Capture(() => L.T("Original REPO MOD ist ebenfalls geladen. Bitte einen der beiden Anzeigemods entfernen und das Spiel neu starten."));
				return;
			}
			try
			{
				if (runtime == null)
				{
					runtime = new EnemyRuntime(this);
				}
				runtime.Tick();
			}
			catch (Exception ex)
			{
				Fail(ex);
			}
		}

		internal void Fail(Exception ex)
		{
			if (fault.Length <= 0)
			{
				fault = L.Capture(() => L.T("Gegneranzeige angehalten: ") + ex.Message);
				CoreRuntime.Report("nightmare.repo.enemyinfo", ex);
				runtime?.Dispose();
				runtime = null;
			}
		}

		private void LateUpdate()
		{
			if (runtime != null && hud != null)
			{
				try
				{
					hud.Update(runtime);
				}
				catch (Exception ex)
				{
					Fail(ex);
				}
			}
		}

		private void OnGUI()
		{
			if (runtime != null && hud != null && fault.Length == 0)
			{
				hud.Draw();
			}
		}

		private void Draw(AddonUi ui)
		{
			//IL_00a7: 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)
			GUILayout.Label(L.T("GEGNER-INFO"), ui.Title, Array.Empty<GUILayoutOption>());
			if (fault.Length > 0)
			{
				GUILayout.Label((string)fault, ui.Danger, Array.Empty<GUILayoutOption>());
			}
			else
			{
				GUILayout.Label((runtime == null) ? L.T("Anzeige wird vorbereitet.") : (runtime.Host ? L.T("Host: tatsächliche HP und tatsächlicher Schaden.") : (runtime.Synced ? L.T("Gast: bestätigte HP vom NM-Host.") : L.T("Gast: HP unbekannt. Ohne NM-Host zeigen Schadenszahlen nur gemeldeten Rohschaden (~)."))), ui.Body, Array.Empty<GUILayoutOption>());
			}
			scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
			try
			{
				Toggle(ui, Show, L.T("Lebensanzeige aktiv"));
				Toggle(ui, Damage, L.T("Schadenszahlen anzeigen"));
				Toggle(ui, Always, L.T("Lebensanzeige dauerhaft"));
				Toggle(ui, Names, L.T("Gegnernamen anzeigen"));
				if (GUILayout.Button(L.T("Darstellung: ") + L.T(Mode.Value.ToString()) + L.T(" · wechseln"), ui.Button, Array.Empty<GUILayoutOption>()))
				{
					Mode.Value = (HealthDisplay)((int)(Mode.Value + 1) % 3);
				}
				Slider(ui, Range, L.T("Reichweite (Meter)"), 1f, 100f);
				Slider(ui, Scale, L.T("Größe"), 0.5f, 2f);
				Slider(ui, Duration, L.T("Lebensanzeige (Sekunden)"), 1f, 60f);
				Slider(ui, PopDuration, L.T("Schadenszahlen (Sekunden)"), 0.3f, 5f);
				Slider(ui, Height, L.T("Zusätzliche Höhe (Meter)"), -2f, 5f);
				ColorSliders(ui, BarColor, L.T("Balken"));
				ColorSliders(ui, LowColor, L.T("Wenig Leben"));
				ColorSliders(ui, TextColor, "Text");
				ColorSliders(ui, DamageColor, L.T("Schaden"));
				GUILayout.Label(L.T("Speicherung automatisch. Änderungen gelten für deine Anzeige. Die Übertragung an passende Gäste bleibt unabhängig von deinen Anzeige-Schaltern aktiv. Veraltete oder fehlende HP werden als ? angezeigt. Gegner mit vollständig eigenem Lebenssystem benötigen einen Adapter."), ui.Small, Array.Empty<GUILayoutOption>());
			}
			finally
			{
				GUILayout.EndScrollView();
			}
		}

		private static void Toggle(AddonUi ui, ConfigEntry<bool> c, string label)
		{
			if (GUILayout.Button((c.Value ? "✓ " : "○ ") + label, ui.Button, Array.Empty<GUILayoutOption>()))
			{
				c.Value = !c.Value;
			}
		}

		private static void Slider(AddonUi ui, ConfigEntry<float> c, string label, float min, float max)
		{
			GUILayout.Label(label + ": " + c.Value.ToString("0.0"), ui.Body, Array.Empty<GUILayoutOption>());
			float num = Mathf.Round(GUILayout.HorizontalSlider(c.Value, min, max, Array.Empty<GUILayoutOption>()) * 10f) / 10f;
			if (!Mathf.Approximately(num, c.Value))
			{
				c.Value = num;
			}
		}

		private static void ColorSliders(AddonUi ui, ConfigEntry<Color> c, string label)
		{
			//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_0029: 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_005d: 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)
			//IL_0082: 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)
			Color value = c.Value;
			GUILayout.Label(label + L.T(" · Rot / Grün / Blau"), ui.Body, Array.Empty<GUILayoutOption>());
			Color val = default(Color);
			((Color)(ref val))..ctor(GUILayout.HorizontalSlider(value.r, 0f, 1f, Array.Empty<GUILayoutOption>()), GUILayout.HorizontalSlider(value.g, 0f, 1f, Array.Empty<GUILayoutOption>()), GUILayout.HorizontalSlider(value.b, 0f, 1f, Array.Empty<GUILayoutOption>()), 1f);
			if (val != value)
			{
				c.Value = val;
			}
		}

		private void OnDestroy()
		{
			runtime?.Dispose();
			AddonHandle? obj = page;
			if (obj != null)
			{
				obj.Dispose();
			}
		}
	}
}