Decompiled source of DamageIndicatorFix v1.1.0

DamageIndicatorFix.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using On.RoR2.PostProcessing;
using RoR2;
using RoR2.PostProcessing;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("DamageIndicatorFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DamageIndicatorFix")]
[assembly: AssemblyTitle("DamageIndicatorFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace DamageIndicatorFix;

[BepInPlugin("com.Nuxlar.DamageIndicatorFix", "DamageIndicatorFix", "1.1.0")]
public class DamageIndicatorFix : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static hook_Awake <>9__0_0;

		public static hook_OnClientDamage <>9__0_1;

		public static hook_OnRenderImage <>9__0_2;

		internal void <Awake>b__0_0(orig_Awake orig, DamageIndicator self)
		{
			orig.Invoke(self);
			self.indicatorDuration = 0.5f;
		}

		internal void <Awake>b__0_1(orig_OnClientDamage orig, DamageIndicator self, DamageDealtMessage damageDealtMessage)
		{
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)damageDealtMessage.victim == (Object)null || !Object.op_Implicit((Object)(object)self.cameraRigController) || !((Object)(object)damageDealtMessage.victim == (Object)(object)self.cameraRigController.localUserViewer.cachedBodyObject) || !Object.op_Implicit((Object)(object)self.cameraRigController) || !Object.op_Implicit((Object)(object)self.cameraRigController.target))
			{
				return;
			}
			float num = 0f;
			float num2 = 1f;
			HealthComponent component = damageDealtMessage.victim.GetComponent<HealthComponent>();
			if (Object.op_Implicit((Object)(object)component))
			{
				float num3 = Mathf.Clamp((component.health + damageDealtMessage.damage) / component.fullHealth, 0f, 1f);
				num2 = Mathf.Clamp(component.health / component.fullHealth, 0f, 1f);
				num = Mathf.Clamp(num3 - num2, 0.3f, 0.9f);
				self._indicatorValue = num;
				for (int i = 0; i < self.indicators.Length; i++)
				{
					self._indicatorTimestamps[i].hitTimeStamp = FixedTimeStamp.now;
					self._indicatorTimestamps[i].isActive = true;
				}
			}
		}

		internal void <Awake>b__0_2(orig_OnRenderImage orig, DamageIndicator self, RenderTexture source, RenderTexture destination)
		{
			//IL_015e: 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)
			if (Object.op_Implicit((Object)(object)self.cameraRigController) && Object.op_Implicit((Object)(object)self.cameraRigController.target))
			{
				float num = 1f;
				HealthComponent component = self.cameraRigController.target.GetComponent<HealthComponent>();
				if (Object.op_Implicit((Object)(object)component))
				{
					num = Mathf.Clamp(component.health / component.fullHealth, 0f, 1f);
				}
				if (num <= 0.25f)
				{
					self._indicatorValue = 0.75f;
					for (int i = 0; i < self.indicators.Length; i++)
					{
						self._indicatorTimestamps[i].hitTimeStamp = FixedTimeStamp.now;
						self._indicatorTimestamps[i].isActive = true;
					}
				}
			}
			if (Mathf.Approximately(self._indicatorValue, 0f))
			{
				if (self.isEnabled)
				{
					self.ResetIndicators();
					self.mat.SetVectorArray("_Indicators", self.indicators);
					self.isEnabled = false;
				}
				Graphics.Blit((Texture)(object)source, destination, self.mat);
				return;
			}
			if (!self.isEnabled)
			{
				self.isEnabled = true;
			}
			self.mat.SetFloat("_BoxCornerRadius", self.boxCornerRadius);
			self.mat.SetFloat("_BoxFeather", self.boxFeather);
			self.mat.SetFloat("_BoxSize", self.GetBoxSize(self._indicatorValue));
			self.mat.SetColor("_TintColor", self.tintColor);
			self.mat.SetFloat("_IndicatorRadius", self.indicatorRadius);
			self.mat.SetFloat("_IndicatorFeather", self.indicatorFeather);
			for (int j = 0; j < self._indicatorTimestamps.Length; j++)
			{
				if (self._indicatorTimestamps[j].isActive)
				{
					float timeSince = ((FixedTimeStamp)(ref self._indicatorTimestamps[j].hitTimeStamp)).timeSince;
					if ((double)timeSince >= (double)self.indicatorDuration)
					{
						self._indicatorTimestamps[j].isActive = false;
					}
					else
					{
						self.indicators[j].z = Mathf.Clamp(self.indicatorOpacity.Evaluate(timeSince / self.indicatorDuration), 0f, 1f);
					}
				}
			}
			self.mat.SetVectorArray("_Indicators", self.indicators);
			Graphics.Blit((Texture)(object)source, destination, self.mat);
		}
	}

	public void Awake()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		object obj = <>c.<>9__0_0;
		if (obj == null)
		{
			hook_Awake val = delegate(orig_Awake orig, DamageIndicator self)
			{
				orig.Invoke(self);
				self.indicatorDuration = 0.5f;
			};
			<>c.<>9__0_0 = val;
			obj = (object)val;
		}
		DamageIndicator.Awake += (hook_Awake)obj;
		object obj2 = <>c.<>9__0_1;
		if (obj2 == null)
		{
			hook_OnClientDamage val2 = delegate(orig_OnClientDamage orig, DamageIndicator self, DamageDealtMessage damageDealtMessage)
			{
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)damageDealtMessage.victim == (Object)null) && Object.op_Implicit((Object)(object)self.cameraRigController) && (Object)(object)damageDealtMessage.victim == (Object)(object)self.cameraRigController.localUserViewer.cachedBodyObject && Object.op_Implicit((Object)(object)self.cameraRigController) && Object.op_Implicit((Object)(object)self.cameraRigController.target))
				{
					float num2 = 0f;
					float num3 = 1f;
					HealthComponent component2 = damageDealtMessage.victim.GetComponent<HealthComponent>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						float num4 = Mathf.Clamp((component2.health + damageDealtMessage.damage) / component2.fullHealth, 0f, 1f);
						num3 = Mathf.Clamp(component2.health / component2.fullHealth, 0f, 1f);
						num2 = Mathf.Clamp(num4 - num3, 0.3f, 0.9f);
						self._indicatorValue = num2;
						for (int k = 0; k < self.indicators.Length; k++)
						{
							self._indicatorTimestamps[k].hitTimeStamp = FixedTimeStamp.now;
							self._indicatorTimestamps[k].isActive = true;
						}
					}
				}
			};
			<>c.<>9__0_1 = val2;
			obj2 = (object)val2;
		}
		DamageIndicator.OnClientDamage += (hook_OnClientDamage)obj2;
		object obj3 = <>c.<>9__0_2;
		if (obj3 == null)
		{
			hook_OnRenderImage val3 = delegate(orig_OnRenderImage orig, DamageIndicator self, RenderTexture source, RenderTexture destination)
			{
				//IL_015e: 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)
				if (Object.op_Implicit((Object)(object)self.cameraRigController) && Object.op_Implicit((Object)(object)self.cameraRigController.target))
				{
					float num = 1f;
					HealthComponent component = self.cameraRigController.target.GetComponent<HealthComponent>();
					if (Object.op_Implicit((Object)(object)component))
					{
						num = Mathf.Clamp(component.health / component.fullHealth, 0f, 1f);
					}
					if (num <= 0.25f)
					{
						self._indicatorValue = 0.75f;
						for (int i = 0; i < self.indicators.Length; i++)
						{
							self._indicatorTimestamps[i].hitTimeStamp = FixedTimeStamp.now;
							self._indicatorTimestamps[i].isActive = true;
						}
					}
				}
				if (Mathf.Approximately(self._indicatorValue, 0f))
				{
					if (self.isEnabled)
					{
						self.ResetIndicators();
						self.mat.SetVectorArray("_Indicators", self.indicators);
						self.isEnabled = false;
					}
					Graphics.Blit((Texture)(object)source, destination, self.mat);
				}
				else
				{
					if (!self.isEnabled)
					{
						self.isEnabled = true;
					}
					self.mat.SetFloat("_BoxCornerRadius", self.boxCornerRadius);
					self.mat.SetFloat("_BoxFeather", self.boxFeather);
					self.mat.SetFloat("_BoxSize", self.GetBoxSize(self._indicatorValue));
					self.mat.SetColor("_TintColor", self.tintColor);
					self.mat.SetFloat("_IndicatorRadius", self.indicatorRadius);
					self.mat.SetFloat("_IndicatorFeather", self.indicatorFeather);
					for (int j = 0; j < self._indicatorTimestamps.Length; j++)
					{
						if (self._indicatorTimestamps[j].isActive)
						{
							float timeSince = ((FixedTimeStamp)(ref self._indicatorTimestamps[j].hitTimeStamp)).timeSince;
							if ((double)timeSince >= (double)self.indicatorDuration)
							{
								self._indicatorTimestamps[j].isActive = false;
							}
							else
							{
								self.indicators[j].z = Mathf.Clamp(self.indicatorOpacity.Evaluate(timeSince / self.indicatorDuration), 0f, 1f);
							}
						}
					}
					self.mat.SetVectorArray("_Indicators", self.indicators);
					Graphics.Blit((Texture)(object)source, destination, self.mat);
				}
			};
			<>c.<>9__0_2 = val3;
			obj3 = (object)val3;
		}
		DamageIndicator.OnRenderImage += (hook_OnRenderImage)obj3;
	}
}