Decompiled source of ShawHpOnDeath v1.0.1

BepInEx/plugins/ShawHpOnDeath.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SilksongSpeedup")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Speedup")]
[assembly: AssemblyTitle("SilksongSpeedup")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("silk.show.dist", "Shaw HP on death", "1.0.0")]
public class MaxHpDisplayPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(HeroController), "Die")]
	private class HeroController_Die_Patch
	{
		private static void Prefix()
		{
			HealthManager[] array = Object.FindObjectsOfType<HealthManager>();
			if (array != null && array.Length != 0)
			{
				HealthManager val = array.OrderByDescending((HealthManager hm) => hm.hp).FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					ShowText($"{((Object)((Component)val).gameObject).name} - {val.hp} HP", 3.5f);
				}
			}
		}
	}

	private static Text uiText;

	private static float hideTime;

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		CreateCanvas();
		Harmony val = new Harmony("silk.show.dist");
		val.PatchAll();
	}

	private void Update()
	{
		if ((Object)(object)uiText != (Object)null && ((Behaviour)uiText).enabled && Time.time > hideTime)
		{
			((Behaviour)uiText).enabled = false;
		}
	}

	private void CreateCanvas()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0097: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("MaxHpCanvas");
		Object.DontDestroyOnLoad((Object)(object)val);
		Canvas val2 = val.AddComponent<Canvas>();
		val2.renderMode = (RenderMode)0;
		val2.sortingOrder = 32767;
		val.AddComponent<CanvasScaler>();
		val.AddComponent<GraphicRaycaster>();
		GameObject val3 = new GameObject("MaxHpText");
		val3.transform.SetParent(val.transform);
		uiText = val3.AddComponent<Text>();
		uiText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		uiText.fontSize = 20;
		uiText.alignment = (TextAnchor)8;
		((Graphic)uiText).color = Color.white;
		((Behaviour)uiText).enabled = false;
		RectTransform rectTransform = ((Graphic)uiText).rectTransform;
		rectTransform.anchorMin = new Vector2(1f, 0f);
		rectTransform.anchorMax = new Vector2(1f, 0f);
		rectTransform.pivot = new Vector2(1f, 0f);
		rectTransform.anchoredPosition = new Vector2(-20f, 20f);
		rectTransform.sizeDelta = new Vector2(500f, 40f);
	}

	public static void ShowText(string text, float duration)
	{
		if (!((Object)(object)uiText == (Object)null))
		{
			uiText.text = text;
			((Behaviour)uiText).enabled = true;
			hideTime = Time.time + duration;
		}
	}
}