Decompiled source of CollapseDisplay v1.4.0

plugins/CollapseDisplay/CollapseDisplay.dll

Decompiled 2 weeks ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CollapseDisplay;
using CollapseDisplay.Config;
using CollapseDisplay.Networking;
using CollapseDisplay.Properties;
using CollapseDisplay.Utilities;
using CollapseDisplay.Utilities.Extensions;
using EntityStates.GlobalSkills.LunarDetonator;
using IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.Utils;
using On.RoR2.UI;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.UI;
using Unity;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CollapseDisplay")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyConfiguration("Release")]
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyInformationalVersion("1.0.0+d663233bf341a5b0f0c2c437f82c95c092ef90da")]
[assembly: AssemblyTitle("CollapseDisplay")]
[assembly: AssemblyProduct("CollapseDisplay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	[CompilerGenerated]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	[Microsoft.CodeAnalysis.Embedded]
	[CompilerGenerated]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CollapseDisplay
{
	public class AcceptableValueMin<T> : AcceptableValueBase where T : IComparable
	{
		public T MinValue { get; }

		public AcceptableValueMin(T minValue)
			: base(typeof(T))
		{
			if (minValue == null)
			{
				throw new ArgumentNullException("minValue");
			}
			MinValue = minValue;
		}

		public override object Clamp(object value)
		{
			if (MinValue.CompareTo(value) > 0)
			{
				return MinValue;
			}
			return value;
		}

		public override bool IsValid(object value)
		{
			return MinValue.CompareTo(value) <= 0;
		}

		public override string ToDescriptionString()
		{
			return $"# Acceptable value range: Greater than or equal to {MinValue}";
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Gorakh.CollapseDisplay", "CollapseDisplay", "1.4.0")]
	public class CollapseDisplayPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Gorakh.CollapseDisplay";

		public const string PluginAuthor = "Gorakh";

		public const string PluginName = "CollapseDisplay";

		public const string PluginVersion = "1.4.0";

		private static Sprite _healthBarHighlight;

		internal static CollapseDisplayPlugin Instance { get; private set; }

		public static DelayedDamageDisplayOptions CollapseDisplayOptions { get; private set; }

		public static DelayedDamageDisplayOptions EssenceOfHeresyDisplayOptions { get; private set; }

		private void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_004f: 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_007e: 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_00d0: 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_012f: 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)
			Stopwatch stopwatch = Stopwatch.StartNew();
			Log.Init(((BaseUnityPlugin)this).Logger);
			Instance = SingletonHelper.Assign<CollapseDisplayPlugin>(Instance, this);
			Texture2D val = new Texture2D(1, 1);
			if (ImageConversion.LoadImage(val, Resources.HealthBarHighlight_Opaque))
			{
				_healthBarHighlight = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)1, new Vector4(4f, 3f, 3f, 4f));
				((Object)_healthBarHighlight).name = "HealthBarHighlightOpaque";
			}
			else
			{
				Log.Error("Failed to load health bar overlay texture", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\CollapseDisplayPlugin.cs", "Awake", 42);
				_healthBarHighlight = null;
			}
			Sprite highlightSprite = (Object.op_Implicit((Object)(object)_healthBarHighlight) ? _healthBarHighlight : Addressables.LoadAssetAsync<Sprite>((object)"RoR2/Base/Common/texUIHighlightExecute.png").WaitForCompletion());
			CollapseDisplayOptions = new DelayedDamageDisplayOptions(highlightSprite, ((BaseUnityPlugin)this).Config, "Collapse", new Color(84f / 85f, 0.14509805f, 22f / 85f, 1f), 1f);
			EssenceOfHeresyDisplayOptions = new DelayedDamageDisplayOptions(highlightSprite, ((BaseUnityPlugin)this).Config, "Heretic Ruin", Color32.op_Implicit(new Color32((byte)41, (byte)138, (byte)242, byte.MaxValue)), 1f);
			if (RiskOfOptionsCompat.Enabled)
			{
				RiskOfOptionsCompat.Initialize();
			}
			HealthBarTypeRegistration.Initialize();
			HealthBarHooks.Initialize();
			DelayedDamageProviderHooks.Initialize();
			stopwatch.Stop();
			Log.Info_NoCallerPrefix($"Initialized in {stopwatch.Elapsed.TotalSeconds:F2} seconds");
		}

		private void OnDestroy()
		{
			HealthBarTypeRegistration.Cleanup();
			HealthBarHooks.Cleanup();
			DelayedDamageProviderHooks.Cleanup();
			Instance = SingletonHelper.Unassign<CollapseDisplayPlugin>(Instance, this);
		}
	}
	public struct DelayedDamageInfo : IEquatable<DelayedDamageInfo>
	{
		public static readonly DelayedDamageInfo None = new DelayedDamageInfo(-1f, FixedTimeStamp.negativeInfinity);

		public float Damage;

		public Net_RunFixedTimeStampWrapper Wrap_DamageTimestamp;

		public FixedTimeStamp DamageTimestamp
		{
			readonly get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return Wrap_DamageTimestamp;
			}
			set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				Wrap_DamageTimestamp = value;
			}
		}

		public DelayedDamageInfo()
		{
			Damage = 0f;
			Wrap_DamageTimestamp = default(Net_RunFixedTimeStampWrapper);
		}

		public DelayedDamageInfo(float damage, FixedTimeStamp damageTimestamp)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			Damage = damage;
			Wrap_DamageTimestamp = damageTimestamp;
		}

		public readonly bool Equals(DelayedDamageInfo other)
		{
			if (Damage == other.Damage)
			{
				return Wrap_DamageTimestamp.Equals(other.Wrap_DamageTimestamp);
			}
			return false;
		}
	}
	[DisallowMultipleComponent]
	public class DelayedDamageProvider : NetworkBehaviour
	{
		[SyncVar]
		private DelayedDamageInfo _collapseDamage;

		private CharacterBody _body;

		private HealthComponent _healthComponent;

		public DelayedDamageInfo CollapseDamage => _collapseDamage;

		public DelayedDamageInfo Network_collapseDamage
		{
			get
			{
				return _collapseDamage;
			}
			[param: In]
			set
			{
				((NetworkBehaviour)this).SetSyncVar<DelayedDamageInfo>(value, ref _collapseDamage, 1u);
			}
		}

		private void Awake()
		{
			_body = ((Component)this).GetComponent<CharacterBody>();
			_healthComponent = ((Component)this).GetComponent<HealthComponent>();
		}

		private void FixedUpdate()
		{
			if (NetworkServer.active)
			{
				fixedUpdateServer();
			}
		}

		[Server]
		private void fixedUpdateServer()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Invalid comparison between Unknown and I4
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void CollapseDisplay.DelayedDamageProvider::fixedUpdateServer()' called on client");
				return;
			}
			DelayedDamageInfo none = DelayedDamageInfo.None;
			if (Object.op_Implicit((Object)(object)_body) && Object.op_Implicit((Object)(object)_healthComponent) && _healthComponent.alive)
			{
				DotController val = DotController.FindDotController(((Component)this).gameObject);
				if (Object.op_Implicit((Object)(object)val) && val.HasDotActive((DotIndex)8))
				{
					float num = float.PositiveInfinity;
					none.Damage = 0f;
					foreach (DotStack dotStack in val.dotStackList)
					{
						if ((int)dotStack.dotIndex == 8)
						{
							num = Mathf.Min(num, dotStack.timer);
							DamageInfo damageInfo = new DamageInfo
							{
								attacker = dotStack.attackerObject,
								damageType = (dotStack.damageType | DamageTypeCombo.op_Implicit((DamageType)67108864)),
								damage = dotStack.damage
							};
							float num2 = HealthComponentUtils.EstimateTakeDamage(_healthComponent, damageInfo);
							if (num2 > 0f)
							{
								none.Damage += num2;
							}
						}
					}
					if (float.IsFinite(num) && num > 0f)
					{
						none.DamageTimestamp = FixedTimeStamp.now + num;
					}
				}
			}
			Network_collapseDamage = none;
		}

		private void UNetVersion()
		{
		}

		public override bool OnSerialize(NetworkWriter writer, bool forceAll)
		{
			if (forceAll)
			{
				GeneratedNetworkCode._WriteDelayedDamageInfo_None(writer, _collapseDamage);
				return true;
			}
			bool flag = false;
			if ((((NetworkBehaviour)this).syncVarDirtyBits & (true ? 1u : 0u)) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				GeneratedNetworkCode._WriteDelayedDamageInfo_None(writer, _collapseDamage);
			}
			if (!flag)
			{
				writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
			}
			return flag;
		}

		public override void OnDeserialize(NetworkReader reader, bool initialState)
		{
			if (initialState)
			{
				_collapseDamage = GeneratedNetworkCode._ReadDelayedDamageInfo_None(reader);
				return;
			}
			int num = (int)reader.ReadPackedUInt32();
			if (((uint)num & (true ? 1u : 0u)) != 0)
			{
				_collapseDamage = GeneratedNetworkCode._ReadDelayedDamageInfo_None(reader);
			}
		}
	}
	internal static class DelayedDamageProviderHooks
	{
		private static readonly List<DelayedDamageProvider> _delayedDamageProviderPrefabComponents = new List<DelayedDamageProvider>();

		public static void Initialize()
		{
			destroyAllPrefabComponents();
			((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)delegate
			{
				if (_delayedDamageProviderPrefabComponents.Capacity < BodyCatalog.bodyCount)
				{
					_delayedDamageProviderPrefabComponents.Capacity = BodyCatalog.bodyCount;
				}
				foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
				{
					if (Object.op_Implicit((Object)(object)allBodyPrefab.GetComponent<HealthComponent>()))
					{
						DelayedDamageProvider item = allBodyPrefab.AddComponent<DelayedDamageProvider>();
						_delayedDamageProviderPrefabComponents.Add(item);
					}
				}
			});
		}

		public static void Cleanup()
		{
			destroyAllPrefabComponents();
		}

		private static void destroyAllPrefabComponents()
		{
			foreach (DelayedDamageProvider delayedDamageProviderPrefabComponent in _delayedDamageProviderPrefabComponents)
			{
				Object.Destroy((Object)(object)delayedDamageProviderPrefabComponent);
			}
			_delayedDamageProviderPrefabComponents.Clear();
		}
	}
	internal static class HealthBarHooks
	{
		private readonly struct AdditionalBarInfos
		{
			public static readonly FieldInfo[] BarInfoFields = (from f in typeof(AdditionalBarInfos).GetFields(BindingFlags.Instance | BindingFlags.Public)
				where f.FieldType == typeof(BarInfo)
				select f).ToArray();

			public readonly BarInfo CollapseDamageBarInfo;

			public readonly BarInfo EssenceOfHeresyBarInfo;

			public readonly int EnabledBarCount;

			public AdditionalBarInfos(BarInfo collapseDamageBarInfo, BarInfo essenceOfHeresyBarInfo)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0004: 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)
				int num = 0;
				CollapseDamageBarInfo = collapseDamageBarInfo;
				if (CollapseDamageBarInfo.enabled)
				{
					num++;
				}
				EssenceOfHeresyBarInfo = essenceOfHeresyBarInfo;
				if (EssenceOfHeresyBarInfo.enabled)
				{
					num++;
				}
				EnabledBarCount = num;
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__HealthBar_ApplyBars;

			public static Func<HealthBar, AdditionalBarInfos> <1>__collectBarInfos;

			public static <>F{00000018}<int, AdditionalBarInfos, int> <2>__addDamageDisplayBarsToCount;
		}

		public static void Initialize()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			object obj = <>O.<0>__HealthBar_ApplyBars;
			if (obj == null)
			{
				Manipulator val = HealthBar_ApplyBars;
				<>O.<0>__HealthBar_ApplyBars = val;
				obj = (object)val;
			}
			HealthBar.ApplyBars += (Manipulator)obj;
		}

		public static void Cleanup()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			object obj = <>O.<0>__HealthBar_ApplyBars;
			if (obj == null)
			{
				Manipulator val = HealthBar_ApplyBars;
				<>O.<0>__HealthBar_ApplyBars = val;
				obj = (object)val;
			}
			HealthBar.ApplyBars -= (Manipulator)obj;
		}

		private static void HealthBar_ApplyBars(ILContext il)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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_01e2: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			MethodReference handleBarMethod = null;
			if (val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref handleBarMethod) && nameStartsWith(handleBarMethod, "<ApplyBars>g__HandleBar|")
			}))
			{
				int localsVarIndex = -1;
				if (val.TryGotoPrev(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, ref localsVarIndex)
				}))
				{
					VariableDefinition val2 = il.Method.Body.Variables[localsVarIndex];
					val.Index = 0;
					VariableDefinition val3 = il.AddVariable<AdditionalBarInfos>();
					val.Emit(OpCodes.Ldarg_0);
					val.EmitDelegate<Func<HealthBar, AdditionalBarInfos>>((Func<HealthBar, AdditionalBarInfos>)collectBarInfos);
					val.Emit(OpCodes.Stloc, val3);
					if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<BarInfoCollection>(x, "GetActiveCount")
					}))
					{
						val.Emit(OpCodes.Ldloca, val3);
						val.EmitDelegate<<>F{00000018}<int, AdditionalBarInfos, int>>((<>F{00000018}<int, AdditionalBarInfos, int>)addDamageDisplayBarsToCount);
						if (!val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[1]
						{
							(Instruction x) => ILPatternMatchingExt.MatchRet(x)
						}))
						{
							Log.Error("Failed to find patch location", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarHooks.cs", "HealthBar_ApplyBars", 119);
							return;
						}
						FieldInfo[] barInfoFields = AdditionalBarInfos.BarInfoFields;
						foreach (FieldInfo fieldInfo in barInfoFields)
						{
							val.Emit(OpCodes.Ldarg_0);
							val.Emit(OpCodes.Ldloca, val3);
							val.Emit(OpCodes.Ldflda, fieldInfo);
							val.Emit(OpCodes.Ldloca, val2);
							val.Emit(OpCodes.Call, handleBarMethod);
						}
					}
					else
					{
						Log.Error("Failed to find bar count patch location", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarHooks.cs", "HealthBar_ApplyBars", 112);
					}
				}
				else
				{
					Log.Error("Failed to find locals variable", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarHooks.cs", "HealthBar_ApplyBars", 79);
				}
			}
			else
			{
				Log.Error("Failed to find HandleBar method", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarHooks.cs", "HealthBar_ApplyBars", 85);
			}
			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			static int addDamageDisplayBarsToCount(int activeCount, in AdditionalBarInfos damageDisplayBarInfos)
			{
				return activeCount + damageDisplayBarInfos.EnabledBarCount;
			}
			static bool nameStartsWith(MethodReference methodReference, string value)
			{
				if (methodReference == null || ((MemberReference)methodReference).Name == null)
				{
					return false;
				}
				return ((MemberReference)methodReference).Name.StartsWith(value);
			}
		}

		private static AdditionalBarInfos collectBarInfos(HealthBar healthBar)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_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_0047: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0089: 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_00a3: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00d1: 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_00dd: 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_0103: 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_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Expected O, but got Unknown
			HealthBarType barType = HealthBarType.Unknown;
			HealthBarTypeProvider healthBarTypeProvider = default(HealthBarTypeProvider);
			if (((Component)healthBar).TryGetComponent<HealthBarTypeProvider>(ref healthBarTypeProvider))
			{
				barType = healthBarTypeProvider.Type;
			}
			DelayedDamageBarStyle damageBarStyle = CollapseDisplayPlugin.EssenceOfHeresyDisplayOptions.GetDamageBarStyle(barType);
			BarStyle barStyle = damageBarStyle.BarStyle;
			BarInfo val = default(BarInfo);
			val.enabled = false;
			val.color = barStyle.baseColor;
			val.sprite = barStyle.sprite;
			val.imageType = barStyle.imageType;
			val.sizeDelta = barStyle.sizeDelta;
			val.normalizedXMin = 0f;
			val.normalizedXMax = 0f;
			BarInfo barInfo2 = val;
			DelayedDamageBarStyle damageBarStyle2 = CollapseDisplayPlugin.CollapseDisplayOptions.GetDamageBarStyle(barType);
			BarStyle barStyle2 = damageBarStyle2.BarStyle;
			val = default(BarInfo);
			val.enabled = false;
			val.color = barStyle2.baseColor;
			val.sprite = barStyle2.sprite;
			val.imageType = barStyle2.imageType;
			val.sizeDelta = barStyle2.sizeDelta;
			val.normalizedXMin = 0f;
			val.normalizedXMax = 0f;
			BarInfo barInfo3 = val;
			HealthComponent healthComponent = healthBar.source;
			float totalBarDamageAmount = 0f;
			if (Object.op_Implicit((Object)(object)healthComponent))
			{
				if (Object.op_Implicit((Object)(object)healthComponent.body) && Object.op_Implicit((Object)(object)healthBar.viewerBody))
				{
					int buffCount = healthComponent.body.GetBuffCount(Buffs.LunarDetonationCharge);
					if (buffCount > 0 && damageBarStyle.EnabledConfig.Value)
					{
						float num = healthBar.viewerBody.damage * Detonate.baseDamageCoefficient;
						float num2 = healthBar.viewerBody.damage * Detonate.damageCoefficientPerStack;
						float damageAmount2 = HealthComponentUtils.EstimateTakeDamage(healthComponent, new DamageInfo
						{
							damage = num + (float)buffCount * num2,
							attacker = ((Component)healthBar.viewerBody).gameObject
						});
						tryAddBar(ref barInfo2, damageAmount2);
					}
				}
				DelayedDamageProvider delayedDamageProvider = default(DelayedDamageProvider);
				if (((Component)healthComponent).TryGetComponent<DelayedDamageProvider>(ref delayedDamageProvider) && damageBarStyle2.EnabledConfig.Value)
				{
					tryAddDelayedDamageBar(delayedDamageProvider.CollapseDamage, ref barInfo3);
				}
			}
			return new AdditionalBarInfos(barInfo3, barInfo2);
			void tryAddBar(ref BarInfo barInfo, float damageAmount)
			{
				//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_006a: Unknown result type (might be due to invalid IL or missing references)
				damageAmount -= healthComponent.barrier;
				if (!(damageAmount <= 0f))
				{
					barInfo.enabled = true;
					HealthBarValues healthBarValues = healthComponent.GetHealthBarValues();
					float combinedHealth = healthComponent.combinedHealth;
					float fullCombinedHealth = healthComponent.fullCombinedHealth;
					float num3 = Mathf.Max(0f, combinedHealth - totalBarDamageAmount);
					float num4 = Mathf.Max(0f, num3 - damageAmount);
					float num5 = 1f - healthBarValues.curseFraction;
					float num6 = num4 / fullCombinedHealth * num5;
					barInfo.normalizedXMin = Mathf.Clamp01(num6);
					float num7 = num3 / fullCombinedHealth * num5;
					barInfo.normalizedXMax = Mathf.Clamp01(num7);
					totalBarDamageAmount += Mathf.Max(0f, num3 - num4);
				}
			}
			void tryAddDelayedDamageBar(DelayedDamageInfo delayedDamageInfo, ref BarInfo barInfo)
			{
				//IL_0002: 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)
				FixedTimeStamp damageTimestamp = delayedDamageInfo.DamageTimestamp;
				if (((FixedTimeStamp)(ref damageTimestamp)).timeUntil > 0f)
				{
					tryAddBar(ref barInfo, delayedDamageInfo.Damage);
				}
			}
		}
	}
	public enum HealthBarType
	{
		Unknown,
		Hud,
		Combat,
		AllyList,
		Count
	}
	public class HealthBarTypeProvider : MonoBehaviour
	{
		public HealthBarType Type;
	}
	internal static class HealthBarTypeRegistration
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_Awake <0>__HealthBar_Awake;
		}

		private static readonly HealthBarStyle _combatHealthBarStyle = Addressables.LoadAssetAsync<HealthBarStyle>((object)"RoR2/Base/Common/CombatHealthBar.asset").WaitForCompletion();

		private static readonly List<HealthBarTypeProvider> _addedPrefabProviders = new List<HealthBarTypeProvider>();

		public static void Initialize()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			object obj = <>O.<0>__HealthBar_Awake;
			if (obj == null)
			{
				hook_Awake val = HealthBar_Awake;
				<>O.<0>__HealthBar_Awake = val;
				obj = (object)val;
			}
			HealthBar.Awake += (hook_Awake)obj;
			registerHealthBarPrefab("RoR2/Base/UI/HUDSimple.prefab", HealthBarType.Hud);
			registerHealthBarPrefab("RoR2/Base/UI/CombatHealthbar.prefab", HealthBarType.Combat);
			registerHealthBarPrefab("RoR2/Base/UI/AllyCard.prefab", HealthBarType.AllyList);
			static void registerHealthBarPrefab(string assetPath, HealthBarType type)
			{
				//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)
				GameObject val2 = Addressables.LoadAssetAsync<GameObject>((object)assetPath).WaitForCompletion();
				if (!Object.op_Implicit((Object)(object)val2))
				{
					Log.Error("Invalid asset path '" + assetPath + "'", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarTypeRegistration.cs", "Initialize", 23);
				}
				else
				{
					int num = 0;
					HealthBar[] componentsInChildren = val2.GetComponentsInChildren<HealthBar>(true);
					foreach (HealthBar val3 in componentsInChildren)
					{
						if (!Object.op_Implicit((Object)(object)((Component)val3).GetComponent<HealthBarTypeProvider>()))
						{
							HealthBarTypeProvider healthBarTypeProvider = ((Component)val3).gameObject.AddComponent<HealthBarTypeProvider>();
							healthBarTypeProvider.Type = type;
							_addedPrefabProviders.Add(healthBarTypeProvider);
							num++;
						}
					}
					if (num == 0)
					{
						Log.Warning("No health bars found on asset '" + assetPath + "'", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarTypeRegistration.cs", "Initialize", 43);
					}
				}
			}
		}

		public static void Cleanup()
		{
			//IL_0010: 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_001b: Expected O, but got Unknown
			object obj = <>O.<0>__HealthBar_Awake;
			if (obj == null)
			{
				hook_Awake val = HealthBar_Awake;
				<>O.<0>__HealthBar_Awake = val;
				obj = (object)val;
			}
			HealthBar.Awake -= (hook_Awake)obj;
			foreach (HealthBarTypeProvider addedPrefabProvider in _addedPrefabProviders)
			{
				Object.Destroy((Object)(object)addedPrefabProvider);
			}
			_addedPrefabProviders.Clear();
		}

		private static void HealthBar_Awake(orig_Awake orig, HealthBar self)
		{
			if (!Object.op_Implicit((Object)(object)((Component)self).GetComponent<HealthBarTypeProvider>()))
			{
				HealthBarType healthBarType = HealthBarType.Unknown;
				if ((Object)(object)self.style == (Object)(object)_combatHealthBarStyle)
				{
					healthBarType = HealthBarType.Combat;
				}
				Log.Info($"Health bar {self} is not registered, assuming bar type of {healthBarType}", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\HealthBarTypeRegistration.cs", "HealthBar_Awake", 80);
				((Component)self).gameObject.AddComponent<HealthBarTypeProvider>().Type = healthBarType;
			}
			orig.Invoke(self);
		}
	}
	internal static class Log
	{
		internal static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		private static string getLogPrefix(string callerPath, string callerMemberName, int callerLineNumber)
		{
			int num = callerPath.LastIndexOf("CollapseDisplay\\");
			if (num >= 0)
			{
				callerPath = callerPath.Substring(num + "CollapseDisplay\\".Length);
			}
			return $"{callerPath}:{callerLineNumber} ({callerMemberName}) ";
		}

		internal static void Error(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogError((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Error_NoCallerPrefix(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogFatal((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Fatal_NoCallerPrefix(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogInfo((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Info_NoCallerPrefix(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogMessage((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Message_NoCallerPrefix(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogWarning((object)(getLogPrefix(callerPath, callerMemberName, callerLineNumber) + data));
		}

		internal static void Warning_NoCallerPrefix(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	internal static class RiskOfOptionsCompat
	{
		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Initialize()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00ba: 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)
			addDisplayOptions(CollapseDisplayPlugin.CollapseDisplayOptions);
			addDisplayOptions(CollapseDisplayPlugin.EssenceOfHeresyDisplayOptions);
			ModSettingsManager.SetModDescription("Options for Collapse Display", "Gorakh.CollapseDisplay", "Collapse Display");
			FileInfo fileInfo = null;
			DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(((BaseUnityPlugin)CollapseDisplayPlugin.Instance).Info.Location));
			do
			{
				FileInfo[] files = directoryInfo.GetFiles("icon.png", SearchOption.TopDirectoryOnly);
				if (files != null && files.Length != 0)
				{
					fileInfo = files[0];
					break;
				}
				directoryInfo = directoryInfo.Parent;
			}
			while (directoryInfo != null && !string.Equals(directoryInfo.Name, "plugins", StringComparison.OrdinalIgnoreCase));
			if (fileInfo != null)
			{
				Texture2D val = new Texture2D(256, 256);
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(fileInfo.FullName)))
				{
					Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
					((Object)obj).name = "CollapseDisplayIcon";
					ModSettingsManager.SetModIcon(obj, "Gorakh.CollapseDisplay", "Collapse Display");
				}
			}
			static void addDamageBarStyle(DelayedDamageBarStyle damageBarStyle)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Expected O, but got Unknown
				ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(damageBarStyle.EnabledConfig), "Gorakh.CollapseDisplay", "Collapse Display");
			}
			static void addDisplayOptions(DelayedDamageDisplayOptions displayOptions)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Expected O, but got Unknown
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				//IL_0035: Expected O, but got Unknown
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Expected O, but got Unknown
				ModSettingsManager.AddOption((BaseOption)new ColorOption(displayOptions.IndicatorColor), "Gorakh.CollapseDisplay", "Collapse Display");
				ConfigEntry<float> indicatorScale = displayOptions.IndicatorScale;
				FloatFieldConfig val2 = new FloatFieldConfig();
				((NumericFieldConfig<float>)val2).Min = 0f;
				ModSettingsManager.AddOption((BaseOption)new FloatFieldOption(indicatorScale, val2), "Gorakh.CollapseDisplay", "Collapse Display");
				addDamageBarStyle(displayOptions.HUDHealthBarStyle);
				addDamageBarStyle(displayOptions.AllyListHealthBarStyle);
				addDamageBarStyle(displayOptions.CombatHealthBarStyle);
			}
		}
	}
}
namespace CollapseDisplay.Utilities
{
	public static class HealthComponentUtils
	{
		public static float EstimateTakeDamage(HealthComponent victim, DamageInfo damageInfo)
		{
			//IL_002f: 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_0035: 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_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_009a: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00c6: 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_00d5: Invalid comparison between Unknown and I4
			//IL_0065: 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_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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_0738: Unknown result type (might be due to invalid IL or missing references)
			//IL_0742: Unknown result type (might be due to invalid IL or missing references)
			//IL_0747: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: 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_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_0763: Unknown result type (might be due to invalid IL or missing references)
			//IL_0765: Invalid comparison between Unknown and I4
			//IL_03af: 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_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_01b1: Invalid comparison between Unknown and I4
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Invalid comparison between Unknown and I4
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0794: Unknown result type (might be due to invalid IL or missing references)
			//IL_079a: Unknown result type (might be due to invalid IL or missing references)
			//IL_079f: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: 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_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Invalid comparison between Unknown and I4
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: 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_053a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Invalid comparison between Unknown and I4
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			if (damageInfo == null)
			{
				throw new ArgumentNullException("damageInfo");
			}
			if (!Object.op_Implicit((Object)(object)victim) || !Object.op_Implicit((Object)(object)victim.body))
			{
				return damageInfo.damage;
			}
			CharacterMaster val = null;
			CharacterBody val2 = null;
			TeamIndex val3 = (TeamIndex)(-1);
			Vector3 val4 = Vector3.zero;
			float combinedHealth = victim.combinedHealth;
			if (Object.op_Implicit((Object)(object)damageInfo.attacker))
			{
				val2 = damageInfo.attacker.GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)val2))
				{
					val3 = val2.teamComponent.teamIndex;
					val4 = val2.corePosition - damageInfo.position;
				}
			}
			bool flag = DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)2)) != 0;
			bool flag2 = DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)64)) != 0;
			if ((int)DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageTypeExtended)268435456)) == 268435456)
			{
				damageInfo.damage = victim.fullHealth * 0.1f;
			}
			KnockbackFinUtil.ModifyDamageInfo(ref damageInfo, val2, victim.body);
			if (victim.body.HasBuff(Buffs.lunarruin))
			{
				float num = (float)victim.body.GetBuffCount(Buffs.lunarruin) * 0.1f;
				float num2 = damageInfo.damage * num;
				DamageInfo obj = damageInfo;
				obj.damage += num2;
			}
			if (val3 == victim.body.teamComponent.teamIndex)
			{
				TeamDef teamDef = TeamCatalog.GetTeamDef(val3);
				if (teamDef != null)
				{
					DamageInfo obj2 = damageInfo;
					obj2.damage *= teamDef.friendlyFireScaling;
				}
			}
			if (damageInfo.damage > 0f)
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					if (val2.canPerformBackstab && (int)DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)67108864)) != 67108864 && (((ProcChainMask)(ref damageInfo.procChainMask)).HasProc((ProcType)17) || BackstabManager.IsBackstab(-val4, victim.body)))
					{
						damageInfo.crit = true;
						((ProcChainMask)(ref damageInfo.procChainMask)).AddProc((ProcType)17);
					}
					val = val2.master;
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.inventory))
					{
						if (combinedHealth >= victim.fullCombinedHealth * 0.9f)
						{
							int itemCount = val.inventory.GetItemCount(Items.Crowbar);
							if (itemCount > 0)
							{
								DamageInfo obj3 = damageInfo;
								obj3.damage *= 1f + 0.75f * (float)itemCount;
							}
						}
						int itemCount2 = val.inventory.GetItemCount(Items.NearbyDamageBonus);
						if (itemCount2 > 0 && ((Vector3)(ref val4)).sqrMagnitude <= 169f)
						{
							damageInfo.damageColorIndex = (DamageColorIndex)10;
							DamageInfo obj4 = damageInfo;
							obj4.damage *= 1f + (float)itemCount2 * 0.2f;
						}
						int itemCount3 = val.inventory.GetItemCount(Items.FragileDamageBonus);
						if (itemCount3 > 0)
						{
							DamageInfo obj5 = damageInfo;
							obj5.damage *= 1f + (float)itemCount3 * 0.2f;
						}
						if (damageInfo.procCoefficient > 0f && victim.body.HasBuff(Buffs.MercExpose) && Object.op_Implicit((Object)(object)val2) && val2.bodyIndex == BodyCatalog.FindBodyIndex("MercBody"))
						{
							float num3 = val2.damage * 3.5f;
							DamageInfo obj6 = damageInfo;
							obj6.damage += num3;
						}
						if (victim.body.isBoss)
						{
							int itemCount4 = val.inventory.GetItemCount(Items.BossDamageBonus);
							if (itemCount4 > 0)
							{
								DamageInfo obj7 = damageInfo;
								obj7.damage *= 1f + 0.2f * (float)itemCount4;
								damageInfo.damageColorIndex = (DamageColorIndex)5;
							}
						}
					}
					if (damageInfo.crit)
					{
						DamageInfo obj8 = damageInfo;
						obj8.damage *= val2.critMultiplier;
					}
				}
				if (DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)16)) != 0L)
				{
					DamageInfo obj9 = damageInfo;
					obj9.damage *= 1.5f;
					damageInfo.damageColorIndex = (DamageColorIndex)5;
				}
				if (victim.body.HasBuff(Buffs.DeathMark))
				{
					DamageInfo obj10 = damageInfo;
					obj10.damage *= 1.5f;
					damageInfo.damageColorIndex = (DamageColorIndex)7;
				}
				if (!flag)
				{
					if (!damageInfo.delayedDamageSecondHalf)
					{
						float armor = victim.body.armor;
						armor += victim.adaptiveArmorValue;
						bool flag3 = DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)131072)) != 0;
						if ((victim.body.bodyFlags & 0x40) > 0 && flag3)
						{
							armor += 300f;
						}
						float num4 = ((armor >= 0f) ? (1f - armor / (armor + 100f)) : (2f - 100f / (100f - armor)));
						damageInfo.damage = Mathf.Max(1f, damageInfo.damage * num4);
					}
					if (victim.itemCounts.armorPlate > 0)
					{
						damageInfo.damage = Mathf.Max(1f, damageInfo.damage - 5f * (float)victim.itemCounts.armorPlate);
					}
				}
				if (!flag2 && damageInfo.damage > 0f && !damageInfo.delayedDamageSecondHalf && !damageInfo.rejected && !damageInfo.firstHitOfDelayedDamageSecondHalf && victim.body.HasBuff(Buffs.DelayedDamageBuff))
				{
					DamageInfo obj11 = damageInfo;
					obj11.damage *= 0.8f;
				}
				if (victim.body.hasOneShotProtection && (int)DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)262144)) != 262144)
				{
					float num5 = (victim.fullCombinedHealth + victim.barrier) * (1f - victim.body.oneShotProtectionFraction);
					float num6 = Mathf.Max(0f, num5 - victim.serverDamageTakenThisUpdate);
					damageInfo.damage = Mathf.Min(damageInfo.damage, num6);
				}
				if (DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)524288)) != 0L)
				{
					float num7 = Mathf.Lerp(3f, 1f, victim.combinedHealthFraction);
					DamageInfo obj12 = damageInfo;
					obj12.damage *= num7;
				}
				if (victim.body.HasBuff(Buffs.LunarShell) && damageInfo.damage > victim.fullHealth * 0.1f)
				{
					damageInfo.damage = victim.fullHealth * 0.1f;
				}
				if (victim.itemCounts.minHealthPercentage > 0)
				{
					float num8 = victim.fullCombinedHealth * ((float)victim.itemCounts.minHealthPercentage / 100f);
					damageInfo.damage = Mathf.Max(0f, Mathf.Min(damageInfo.damage, victim.combinedHealth - num8));
				}
			}
			float num9 = Mathf.Min(damageInfo.damage, victim.barrier);
			float num10 = victim.barrier - num9;
			DamageInfo obj13 = damageInfo;
			obj13.damage -= num9;
			float num11 = Mathf.Min(damageInfo.damage, victim.shield);
			float num12 = victim.shield - num11;
			DamageInfo obj14 = damageInfo;
			obj14.damage -= num11;
			if (victim.itemCounts.unstableTransmitter > 0 && victim.IsHealthBelowThreshold(victim.health - damageInfo.damage, 0.25f) && victim.body.HasBuff(Buffs.TeleportOnLowHealth) && victim.health - damageInfo.damage > 0f && Object.op_Implicit((Object)(object)((Component)victim).GetComponent<TeleportOnLowHealthBehavior>()))
			{
				int num13 = victim.GetHealthAtThreshold(0.25f) + 1;
				float num14 = victim.health - (float)num13;
				if (num14 > 0f)
				{
					damageInfo.damage = num14;
				}
			}
			bool num15 = DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)65536)) != 0L && (victim.body.bodyFlags & 0x800) == 0;
			float num16 = victim.health;
			if (damageInfo.damage > 0f)
			{
				float num17 = num16 - damageInfo.damage;
				if (num17 < 1f && DamageTypeCombo.op_Implicit(damageInfo.damageType & DamageTypeCombo.op_Implicit((DamageType)1)) != 0L && num16 >= 1f)
				{
					num17 = 1f;
				}
				num16 = num17;
			}
			float num18 = float.NegativeInfinity;
			bool flag4 = (victim.body.bodyFlags & 0x10) > 0;
			if (!num15 && !flag4)
			{
				if (victim.isInFrozenState && num18 < 0.3f)
				{
					num18 = 0.3f;
				}
				if (Object.op_Implicit((Object)(object)val2) && victim.body.isElite)
				{
					float executeEliteHealthFraction = val2.executeEliteHealthFraction;
					if (num18 < executeEliteHealthFraction)
					{
						num18 = executeEliteHealthFraction;
					}
				}
			}
			float num19 = (num16 + num12 + num10) / victim.fullCombinedHealth;
			if (num15 || (num18 > 0f && num19 <= num18))
			{
				damageInfo.damage = victim.health;
			}
			DamageInfo obj15 = damageInfo;
			obj15.damage += num9 + num11;
			return damageInfo.damage;
		}
	}
	public static class ObjectUtils
	{
		public static T ShallowCopy<T>(T original, BindingFlags fieldCopyFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
		{
			if (typeof(T).IsValueType || original == null)
			{
				return original;
			}
			if ((object)original is ICloneable cloneable)
			{
				return (T)cloneable.Clone();
			}
			T val = Activator.CreateInstance<T>();
			FieldInfo[] fields = typeof(T).GetFields(fieldCopyFlags);
			foreach (FieldInfo fieldInfo in fields)
			{
				try
				{
					object value = fieldInfo.GetValue(original);
					fieldInfo.SetValue(val, value);
				}
				catch (Exception arg)
				{
					Log.Error_NoCallerPrefix($"Failed to copy field value {fieldInfo.DeclaringType.FullName}.{fieldInfo.Name}: {arg}");
				}
			}
			return val;
		}
	}
}
namespace CollapseDisplay.Utilities.Extensions
{
	public static class PatchExtensions
	{
		public static void EmitSkipMethodCall(this ILCursor c, MethodDefinition method = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			c.EmitSkipMethodCall(OpCodes.Br, method);
		}

		public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, MethodDefinition method = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			c.EmitSkipMethodCall(branchOpCode, null, method);
		}

		public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, Action<ILCursor> emitSkippedReturnValue, MethodDefinition method = null)
		{
			//IL_0010: 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: Invalid comparison between Unknown and I4
			//IL_011d: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: 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_0224: Unknown result type (might be due to invalid IL or missing references)
			if (c == null)
			{
				throw new ArgumentNullException("c");
			}
			if ((int)((OpCode)(ref branchOpCode)).FlowControl != 0 && (int)((OpCode)(ref branchOpCode)).FlowControl != 3)
			{
				throw new ArgumentException($"Invalid branch OpCode: {branchOpCode}");
			}
			if (method == null)
			{
				MethodReference val = default(MethodReference);
				if (!ILPatternMatchingExt.MatchCallOrCallvirt(c.Next, ref val))
				{
					Log.Error($"Failed to find method call to skip: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 33);
					return;
				}
				method = Extensions.SafeResolve(val);
				if (method == null)
				{
					Log.Error($"Failed to resolve method '{((MemberReference)val).FullName}': {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 41);
					return;
				}
			}
			int num = ((MethodReference)method).Parameters.Count + ((!method.IsStatic) ? 1 : 0);
			bool flag = Extensions.Is((MemberReference)(object)((MethodReference)method).ReturnType, (MemberInfo)typeof(void));
			ILLabel val2 = c.DefineLabel();
			c.Emit(branchOpCode, (object)val2);
			int index = c.Index;
			c.Index = index + 1;
			if (num > 0 || !flag)
			{
				ILLabel val3 = c.DefineLabel();
				c.Emit(OpCodes.Br, (object)val3);
				c.MarkLabel(val2);
				for (int i = 0; i < num; i++)
				{
					c.Emit(OpCodes.Pop);
				}
				if (emitSkippedReturnValue != null)
				{
					emitSkippedReturnValue(c);
				}
				else if (!flag)
				{
					Log.Warning($"Skipped method ({((MemberReference)method).FullName}) is not void, emitting default value: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next} ({c.Index})", "X:\\Git\\RoR2\\CollapseDisplay\\CollapseDisplay\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 73);
					if (((MethodReference)method).ReturnType.IsValueType)
					{
						VariableDefinition val4 = c.Context.AddVariable(((MethodReference)method).ReturnType);
						c.Emit(OpCodes.Ldloca, val4);
						c.Emit(OpCodes.Initobj, ((MethodReference)method).ReturnType);
						c.Emit(OpCodes.Ldloc, val4);
					}
					else
					{
						c.Emit(OpCodes.Ldnull);
					}
				}
				c.MarkLabel(val3);
			}
			else
			{
				c.MarkLabel(val2);
			}
		}

		public static bool TryFindParameter(this MethodReference method, Type type, string name, out ParameterDefinition parameter)
		{
			//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)
			Enumerator<ParameterDefinition> enumerator = method.Parameters.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					ParameterDefinition current = enumerator.Current;
					if ((string.IsNullOrEmpty(name) || ((ParameterReference)current).Name == name) && (type == null || Extensions.Is((MemberReference)(object)((ParameterReference)current).ParameterType, (MemberInfo)type)))
					{
						parameter = current;
						return true;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			parameter = null;
			return false;
		}

		public static bool TryFindParameter(this MethodReference method, string name, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(null, name, out parameter);
		}

		public static bool TryFindParameter(this MethodReference method, Type type, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(type, null, out parameter);
		}

		public static bool TryFindParameter<T>(this MethodReference method, string name, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(typeof(T), name, out parameter);
		}

		public static bool TryFindParameter<T>(this MethodReference method, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(typeof(T), null, out parameter);
		}

		public static VariableDefinition AddVariable(this ILContext context, TypeReference variableType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			VariableDefinition val = new VariableDefinition(variableType);
			context.Method.Body.Variables.Add(val);
			return val;
		}

		public static VariableDefinition AddVariable(this ILContext context, Type variableType)
		{
			return context.AddVariable(context.Import(variableType));
		}

		public static VariableDefinition AddVariable<T>(this ILContext context)
		{
			return context.AddVariable(context.Import(typeof(T)));
		}

		public static void EmitStoreStack(this ILCursor cursor, params VariableDefinition[] variables)
		{
			//IL_002a: 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_004d: 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)
			if (cursor == null)
			{
				throw new ArgumentNullException("cursor");
			}
			if (variables == null)
			{
				throw new ArgumentNullException("variables");
			}
			if (variables.Length != 0)
			{
				for (int num = variables.Length - 1; num >= 1; num--)
				{
					cursor.Emit(OpCodes.Stloc, variables[num]);
				}
				cursor.Emit(OpCodes.Dup);
				cursor.Emit(OpCodes.Stloc, variables[0]);
				for (int i = 1; i < variables.Length; i++)
				{
					cursor.Emit(OpCodes.Ldloc, variables[i]);
				}
			}
		}
	}
}
namespace CollapseDisplay.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[CompilerGenerated]
	[DebuggerNonUserCode]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("CollapseDisplay.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] HealthBarHighlight_Opaque => (byte[])ResourceManager.GetObject("HealthBarHighlight_Opaque", resourceCulture);

		internal Resources()
		{
		}
	}
}
namespace CollapseDisplay.Networking
{
	public struct Net_RunFixedTimeStampWrapper : IEquatable<Net_RunFixedTimeStampWrapper>
	{
		public float t;

		public Net_RunFixedTimeStampWrapper()
		{
			t = 0f;
		}

		public readonly bool Equals(Net_RunFixedTimeStampWrapper other)
		{
			return t == other.t;
		}

		public static implicit operator FixedTimeStamp(Net_RunFixedTimeStampWrapper wrapper)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return new FixedTimeStamp(wrapper.t);
		}

		public static implicit operator Net_RunFixedTimeStampWrapper(FixedTimeStamp timeStamp)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			Net_RunFixedTimeStampWrapper result = new Net_RunFixedTimeStampWrapper();
			result.t = timeStamp.t;
			return result;
		}
	}
}
namespace CollapseDisplay.Config
{
	public class DelayedDamageBarStyle
	{
		public readonly ConfigEntry<bool> EnabledConfig;

		public readonly HealthBarType BarType;

		private readonly DelayedDamageDisplayOptions _displayOptions;

		private readonly float _baseSizeDelta;

		private BarStyle _barStyle;

		public BarStyle BarStyle => _barStyle;

		public DelayedDamageBarStyle(ConfigFile file, string sectionName, HealthBarType type, BarStyle baseStyle, DelayedDamageDisplayOptions displayOptions)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0088: 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)
			BarType = type;
			string text = type switch
			{
				HealthBarType.Hud => "Player HUD", 
				HealthBarType.AllyList => "Ally List", 
				HealthBarType.Combat => "Enemy", 
				_ => throw new NotImplementedException($"Bar type {type} is not implemented"), 
			};
			EnabledConfig = file.Bind<bool>(sectionName, "Show on " + text, true, new ConfigDescription("If this damage indicator should display on " + text + " healthbars", (AcceptableValueBase)null, Array.Empty<object>()));
			_barStyle = baseStyle;
			_baseSizeDelta = _barStyle.sizeDelta;
			_displayOptions = displayOptions;
			_displayOptions.IndicatorColor.SettingChanged += IndicatorColor_SettingChanged;
			updateBarColor();
			_displayOptions.IndicatorScale.SettingChanged += IndicatorScale_SettingChanged;
			updateBarSizeDelta();
		}

		private void IndicatorColor_SettingChanged(object sender, EventArgs e)
		{
			updateBarColor();
		}

		private void updateBarColor()
		{
			//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)
			_barStyle.baseColor = _displayOptions.IndicatorColor.Value;
		}

		private void IndicatorScale_SettingChanged(object sender, EventArgs e)
		{
			updateBarSizeDelta();
		}

		private void updateBarSizeDelta()
		{
			_barStyle.sizeDelta = Mathf.Max(0f, _baseSizeDelta * _displayOptions.IndicatorScale.Value);
		}
	}
	public class DelayedDamageDisplayOptions
	{
		public readonly ConfigEntry<Color> IndicatorColor;

		public readonly ConfigEntry<float> IndicatorScale;

		public readonly DelayedDamageBarStyle HUDHealthBarStyle;

		public readonly DelayedDamageBarStyle AllyListHealthBarStyle;

		public readonly DelayedDamageBarStyle CombatHealthBarStyle;

		public DelayedDamageBarStyle FallbackHealthBarStyle => CombatHealthBarStyle ?? AllyListHealthBarStyle ?? HUDHealthBarStyle;

		public DelayedDamageDisplayOptions(Sprite highlightSprite, ConfigFile file, string sectionName, Color defaultColor, float defaultIndicatorScale)
		{
			//IL_000e: 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_0025: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0054: 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_007e: 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_00a1: 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_00cc: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			IndicatorColor = file.Bind<Color>(sectionName, "Indicator Color", defaultColor, new ConfigDescription("The color of this damage indicator", (AcceptableValueBase)null, Array.Empty<object>()));
			IndicatorScale = file.Bind<float>(sectionName, "Indicator Scale", defaultIndicatorScale, new ConfigDescription("The scale of this damage indicator", (AcceptableValueBase)null, Array.Empty<object>()));
			HUDHealthBarStyle = new DelayedDamageBarStyle(file, sectionName, HealthBarType.Hud, new BarStyle
			{
				enabled = true,
				imageType = (Type)1,
				sizeDelta = 5f,
				sprite = highlightSprite
			}, this);
			AllyListHealthBarStyle = new DelayedDamageBarStyle(file, sectionName, HealthBarType.AllyList, new BarStyle
			{
				enabled = true,
				imageType = (Type)1,
				sizeDelta = 1f,
				sprite = highlightSprite
			}, this);
			CombatHealthBarStyle = new DelayedDamageBarStyle(file, sectionName, HealthBarType.Combat, new BarStyle
			{
				enabled = true,
				imageType = (Type)1,
				sizeDelta = 1f,
				sprite = highlightSprite
			}, this);
		}

		public DelayedDamageBarStyle GetDamageBarStyle(HealthBarType barType)
		{
			return barType switch
			{
				HealthBarType.Hud => HUDHealthBarStyle, 
				HealthBarType.Combat => CombatHealthBarStyle, 
				HealthBarType.AllyList => AllyListHealthBarStyle, 
				HealthBarType.Unknown => FallbackHealthBarStyle, 
				_ => throw new NotImplementedException($"{barType} is not implemented"), 
			};
		}
	}
}
namespace Unity
{
	[StructLayout(LayoutKind.Auto, CharSet = CharSet.Auto)]
	public class GeneratedNetworkCode
	{
		public static void _WriteNet_RunFixedTimeStampWrapper_None(NetworkWriter writer, Net_RunFixedTimeStampWrapper value)
		{
			writer.Write(value.t);
		}

		public static void _WriteDelayedDamageInfo_None(NetworkWriter writer, DelayedDamageInfo value)
		{
			writer.Write(value.Damage);
			_WriteNet_RunFixedTimeStampWrapper_None(writer, value.Wrap_DamageTimestamp);
		}

		public static Net_RunFixedTimeStampWrapper _ReadNet_RunFixedTimeStampWrapper_None(NetworkReader reader)
		{
			Net_RunFixedTimeStampWrapper result = default(Net_RunFixedTimeStampWrapper);
			result.t = reader.ReadSingle();
			return result;
		}

		public static DelayedDamageInfo _ReadDelayedDamageInfo_None(NetworkReader reader)
		{
			DelayedDamageInfo result = default(DelayedDamageInfo);
			result.Damage = reader.ReadSingle();
			result.Wrap_DamageTimestamp = _ReadNet_RunFixedTimeStampWrapper_None(reader);
			return result;
		}
	}
}