Decompiled source of RpgDamage v1.0.0

RpgDamage.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RpgDamage")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RpgDamage")]
[assembly: AssemblyTitle("RpgDamage")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
[BepInPlugin("com.flame.ultrakill.damagenumbers", "Floating Damage Numbers", "1.6.0")]
public class DamageNumbersPlugin : BaseUnityPlugin
{
	public static DamageNumbersPlugin Instance;

	private Dictionary<EnemyIdentifier, float> lastHitTimes = new Dictionary<EnemyIdentifier, float>();

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		Instance = this;
		try
		{
			Harmony val = new Harmony("com.flame.ultrakill.damagenumbers");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[DamageNumbers] V1.6 Initialized successfully!");
		}
		catch (Exception arg)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"[DamageNumbers] FATAL ERROR: {arg}");
		}
	}

	public void LogDebug(string message)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)message);
	}

	public bool CanProcessHit(EnemyIdentifier enemy)
	{
		float time = Time.time;
		if (lastHitTimes.TryGetValue(enemy, out var value) && time - value < 0.08f)
		{
			return false;
		}
		lastHitTimes[enemy] = time;
		return true;
	}

	public void SpawnDamageText(Vector3 position, float damage, bool isSpecialHit)
	{
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_0085: Expected O, but got Unknown
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			float num = Mathf.Round(damage * 10f) / 10f;
			if (!(num <= 0f))
			{
				bool flag = isSpecialHit || num >= 2.5f;
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(Random.Range(-0.8f, 0.8f), Random.Range(2.5f, 3.5f), Random.Range(-0.8f, 0.8f));
				Vector3 position2 = position + val;
				GameObject val2 = new GameObject("DamagePopup");
				val2.transform.position = position2;
				TextMeshPro val3 = val2.AddComponent<TextMeshPro>();
				string text = (flag ? "#FF2222" : "#FFDD00");
				((TMP_Text)val3).text = "<color=" + text + "><b>" + num.ToString("0.#") + "</b></color>";
				((TMP_Text)val3).fontSize = 26f;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val3).isOverlay = true;
				MeshRenderer component = val2.GetComponent<MeshRenderer>();
				if ((Object)(object)component != (Object)null)
				{
					((Renderer)component).sortingOrder = 32767;
				}
				GameObject val4 = new GameObject("DamageShadow");
				val4.transform.SetParent(val2.transform);
				val4.transform.localPosition = new Vector3(0.05f, -0.05f, 0.01f);
				TextMeshPro val5 = val4.AddComponent<TextMeshPro>();
				((TMP_Text)val5).text = "<b>" + num.ToString("0.#") + "</b>";
				((Graphic)val5).color = new Color(0f, 0f, 0f, 0.8f);
				((TMP_Text)val5).fontSize = 26f;
				((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val5).isOverlay = true;
				MeshRenderer component2 = val4.GetComponent<MeshRenderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					((Renderer)component2).sortingOrder = 32766;
				}
				val2.AddComponent<DamagePopupMover>();
			}
		}
		catch (Exception arg)
		{
			LogDebug($"[DamageNumbers] ERROR: {arg}");
		}
	}
}
public class DamagePopupMover : MonoBehaviour
{
	private float timer = 1.2f;

	private float maxTimer = 1.2f;

	private TextMeshPro[] tms = null;

	private Transform? camTransform;

	private void Start()
	{
		tms = ((Component)this).GetComponentsInChildren<TextMeshPro>();
		if ((Object)(object)Camera.main != (Object)null)
		{
			camTransform = ((Component)Camera.main).transform;
		}
	}

	private void Update()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		timer -= Time.deltaTime;
		Transform transform = ((Component)this).transform;
		transform.position += Vector3.up * (Time.deltaTime * 5f);
		if ((Object)(object)camTransform != (Object)null)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - camTransform.position);
		}
		if (tms != null)
		{
			TextMeshPro[] array = tms;
			foreach (TextMeshPro val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Color color = ((Graphic)val).color;
					float num = ((((Object)((Component)val).gameObject).name == "DamageShadow") ? 0.8f : 1f);
					((Graphic)val).color = new Color(color.r, color.g, color.b, timer / maxTimer * num);
				}
			}
		}
		if (timer <= 0f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
}
[HarmonyPatch(typeof(EnemyIdentifier), "DeliverDamage")]
public class EnemyDeliverDamagePatch
{
	public static void Postfix(EnemyIdentifier __instance, Vector3 hitPoint, float multiplier, float critMultiplier)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: 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_0066: 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)
		try
		{
			if ((Object)(object)__instance != (Object)null && multiplier > 0f && DamageNumbersPlugin.Instance.CanProcessHit(__instance))
			{
				bool isSpecialHit = critMultiplier > 0f || __instance.hitter == "limb";
				Vector3 position = ((hitPoint != Vector3.zero) ? hitPoint : ((Component)__instance).transform.position);
				DamageNumbersPlugin.Instance.SpawnDamageText(position, multiplier, isSpecialHit);
			}
		}
		catch (Exception arg)
		{
			DamageNumbersPlugin.Instance.LogDebug($"[DamageNumbers] ERROR in DeliverDamage: {arg}");
		}
	}
}