Decompiled source of DamageNumbers v2.3.4

Mods/DamageNumbers.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using DamageNumbers;
using HarmonyLib;
using Il2CppRUMBLE.Managers;
using Il2CppRUMBLE.Players;
using Il2CppRUMBLE.Players.Subsystems;
using Il2CppRUMBLE.Utilities;
using Il2CppTMPro;
using MelonLoader;
using RumbleModdingAPI.RMAPI;
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: MelonInfo(typeof(main), "DamageNumbers", "2.3.4", "UlvakSkillz", null)]
[assembly: MelonGame("Buckethead Entertainment", "RUMBLE")]
[assembly: MelonColor(255, 195, 0, 255)]
[assembly: MelonAuthorColor(255, 195, 0, 255)]
[assembly: VerifyLoaderVersion(0, 7, 2, true)]
[assembly: AssemblyTitle("DamageNumbers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DamageNumbers")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f6144130-bb99-4232-8aa6-d721c7b07821")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace DamageNumbers;

public class main : MelonMod
{
	[HarmonyPatch(typeof(PlayerHealth), "SetHealth", new Type[]
	{
		typeof(short),
		typeof(short),
		typeof(bool)
	})]
	public static class SetHealth
	{
		private static void Prefix(ref PlayerHealth __instance, short newHealth, short previousHealth, bool useEffects)
		{
			//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_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Invalid comparison between Unknown and I4
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (useEffects && previousHealth != 0 && previousHealth >= newHealth && !((Object)(object)((Component)((PlayerControllerSubsystem)__instance).parentController.PlayerCamera).gameObject.transform == (Object)null) && !((Object)(object)((Component)Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerCamera).gameObject == (Object)null))
				{
					int num = previousHealth - newHealth;
					Color black = Color.black;
					switch (num)
					{
					case 1:
						((Color)(ref black))..ctor(83f / 85f, 50f / 51f, 0.64705884f, 1f);
						break;
					case 2:
						((Color)(ref black))..ctor(0.99607843f, 76f / 85f, 0.34901962f, 1f);
						break;
					case 3:
						((Color)(ref black))..ctor(0.99607843f, 56f / 85f, 0.015686275f, 1f);
						break;
					case 4:
						((Color)(ref black))..ctor(0.9843137f, 0.41960785f, 0.16862746f, 1f);
						break;
					case 5:
						((Color)(ref black))..ctor(50f / 51f, 21f / 85f, 0.29803923f, 1f);
						break;
					case 6:
						((Color)(ref black))..ctor(0.96862745f, 0f, 29f / 51f, 1f);
						break;
					case 7:
						((Color)(ref black))..ctor(0.3529412f, 37f / 85f, 1f, 1f);
						break;
					case 8:
						((Color)(ref black))..ctor(19f / 85f, 0.52156866f, 29f / 85f, 1f);
						break;
					case 9:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 10:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 11:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 12:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 13:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 14:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 15:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 16:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 17:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 18:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 19:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					case 20:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					default:
						((Color)(ref black))..ctor(1f, 0f, 1f, 1f);
						break;
					}
					Transform transform = ((Component)((PlayerControllerSubsystem)__instance).parentController.PlayerCamera).gameObject.transform;
					GameObject val = Create.NewText();
					((Object)val).name = num + " Damage";
					val.transform.position = new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z);
					val.transform.rotation = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerCamera).gameObject.transform.localRotation;
					if ((int)((PlayerControllerSubsystem)__instance).parentController.controllerType == 1)
					{
						val.transform.localScale = new Vector3(0.75f, 0.75f, 0.75f);
					}
					TextMeshPro component = val.GetComponent<TextMeshPro>();
					((TMP_Text)component).fontSize = 12f;
					((TMP_Text)component).text = num.ToString();
					((Graphic)component).color = black;
					((TMP_Text)component).SetOutlineColor(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
					((TMP_Text)component).outlineWidth = 0.5f;
					MelonCoroutines.Start(MoveNumber(val, sceneCount, ((PlayerControllerSubsystem)__instance).parentController));
					if (num > 8)
					{
						MelonCoroutines.Start(RainbowColor(component, sceneCount));
					}
					Object.Destroy((Object)(object)val, 4f);
				}
			}
			catch
			{
			}
		}
	}

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

		private object <>2__current;

		public GameObject damageNumber;

		public int sceneNumber;

		public PlayerController player;

		private DateTime <stopMovingTime>5__1;

		private DateTime <startFadeTime>5__2;

		private float <moveAmount>5__3;

		private TextMeshPro <damageNumberText>5__4;

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

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

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

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

		private bool MoveNext()
		{
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Invalid comparison between Unknown and I4
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<stopMovingTime>5__1 = DateTime.Now.AddSeconds(3.9000000953674316);
				<startFadeTime>5__2 = DateTime.Now.AddSeconds(2.0);
				<moveAmount>5__3 = 0.16f;
				<damageNumberText>5__4 = damageNumber.GetComponent<TextMeshPro>();
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (sceneNumber == sceneCount && DateTime.Now < <stopMovingTime>5__1)
			{
				try
				{
					if ((int)player.controllerType == 2)
					{
						damageNumber.transform.rotation = GetAngleToFaceMe(damageNumber.transform.position, ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerCamera).gameObject.transform.position);
					}
					else
					{
						damageNumber.transform.rotation = ((Component)Singleton<PlayerManager>.instance.localPlayer.Controller.PlayerCamera).gameObject.transform.rotation;
					}
					if (<moveAmount>5__3 > 0f)
					{
						damageNumber.transform.position = new Vector3(damageNumber.transform.position.x, damageNumber.transform.position.y + <moveAmount>5__3, damageNumber.transform.position.z);
						<moveAmount>5__3 -= 0.0064f;
					}
					if (<startFadeTime>5__2 < DateTime.Now)
					{
						((Graphic)<damageNumberText>5__4).color = new Color(((Graphic)<damageNumberText>5__4).color.r, ((Graphic)<damageNumberText>5__4).color.g, ((Graphic)<damageNumberText>5__4).color.b, ((Graphic)<damageNumberText>5__4).color.a - 0.05f);
					}
				}
				catch
				{
				}
				<>2__current = (object)new WaitForFixedUpdate();
				<>1__state = 1;
				return true;
			}
			return false;
		}

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

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

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

		private object <>2__current;

		public TextMeshPro damageNumberText;

		public int sceneNumber;

		private float <r>5__1;

		private float <g>5__2;

		private float <b>5__3;

		private int <colorToChange>5__4;

		private DateTime <timeToPlay>5__5;

		private int <>s__6;

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

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

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

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

		private bool MoveNext()
		{
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<r>5__1 = 255f;
				<g>5__2 = 0f;
				<b>5__3 = 255f;
				<colorToChange>5__4 = 1;
				<timeToPlay>5__5 = DateTime.Now.AddSeconds(3.9000000953674316);
				<>2__current = (object)new WaitForFixedUpdate();
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				break;
			case 2:
				<>1__state = -1;
				break;
			}
			if (DateTime.Now < <timeToPlay>5__5 && sceneNumber == sceneCount)
			{
				try
				{
					int num = <colorToChange>5__4;
					<>s__6 = num;
					switch (<>s__6)
					{
					case 1:
						<g>5__2 += 5f;
						<r>5__1 -= 5f;
						break;
					case 2:
						<r>5__1 += 5f;
						<b>5__3 -= 5f;
						break;
					case 3:
						<b>5__3 += 5f;
						<g>5__2 -= 5f;
						break;
					}
					if (<r>5__1 == 0f || <g>5__2 == 0f || <b>5__3 == 0f)
					{
						<colorToChange>5__4++;
						if (<colorToChange>5__4 == 4)
						{
							<colorToChange>5__4 = 1;
						}
					}
					((Graphic)damageNumberText).color = new Color(<r>5__1 / 255f, <g>5__2 / 255f, <b>5__3 / 255f, ((Graphic)damageNumberText).color.a);
				}
				catch
				{
				}
				<>2__current = (object)new WaitForFixedUpdate();
				<>1__state = 2;
				return true;
			}
			return false;
		}

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

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

	private static int sceneCount;

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		sceneCount++;
	}

	[IteratorStateMachine(typeof(<RainbowColor>d__3))]
	private static IEnumerator RainbowColor(TextMeshPro damageNumberText, int sceneNumber)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <RainbowColor>d__3(0)
		{
			damageNumberText = damageNumberText,
			sceneNumber = sceneNumber
		};
	}

	[IteratorStateMachine(typeof(<MoveNumber>d__4))]
	private static IEnumerator MoveNumber(GameObject damageNumber, int sceneNumber, PlayerController player)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <MoveNumber>d__4(0)
		{
			damageNumber = damageNumber,
			sceneNumber = sceneNumber,
			player = player
		};
	}

	private static Quaternion GetAngleToFaceMe(Vector3 objectPosition, Vector3 lookAtPosition)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = objectPosition - lookAtPosition;
		return Quaternion.LookRotation(val);
	}
}