Decompiled source of DamageMeter v1.0.0

BepInEx/plugins/DamageMeter.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("DamageMeter")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0")]
[assembly: AssemblyProduct("DamageMeter")]
[assembly: AssemblyTitle("DamageMeter")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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("com.yourname.mycopunk.damagemeter", "DamageMeter", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class DPSMeter : BaseUnityPlugin
{
	private Harmony harmony;

	public static Queue<(float time, float damage)> damageQueue = new Queue<(float, float)>();

	private static float currentDPS = 0f;

	private bool uiVisible = true;

	private ConfigEntry<float> dpsWindowSeconds;

	private Text dpsText;

	private Image backgroundImage;

	private Canvas uiCanvas;

	private void Awake()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		dpsWindowSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DPSWindowSeconds", 5f, "Time window (in seconds) for calculating DPS. Higher values smooth out spikes.");
		Harmony val = new Harmony("com.yourname.mycopunk.damagemeter");
		val.PatchAll(typeof(DPSPatches));
		((BaseUnityPlugin)this).Logger.LogInfo((object)(val.Id + " loaded!"));
	}

	private void Start()
	{
		CreateUI();
	}

	private void CreateUI()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_013e: Expected O, but got Unknown
		//IL_0194: 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_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)uiCanvas != (Object)null))
		{
			GameObject val = new GameObject("DPSMeterCanvas");
			uiCanvas = val.AddComponent<Canvas>();
			uiCanvas.renderMode = (RenderMode)0;
			uiCanvas.sortingOrder = 9999;
			uiCanvas.pixelPerfect = true;
			CanvasScaler obj = val.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.scaleFactor = 1f;
			val.AddComponent<GraphicRaycaster>();
			GameObject val2 = new GameObject("DPSBg");
			val2.transform.SetParent(val.transform, false);
			backgroundImage = val2.AddComponent<Image>();
			((Graphic)backgroundImage).color = new Color(0f, 0f, 0f, 0.6f);
			((Graphic)backgroundImage).raycastTarget = false;
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.2f, 1f);
			component.anchorMax = new Vector2(0.2f, 1f);
			component.anchoredPosition = new Vector2(0f, -15f);
			component.sizeDelta = new Vector2(150f, 25f);
			GameObject val3 = new GameObject("DPSText");
			val3.transform.SetParent(val2.transform, false);
			dpsText = val3.AddComponent<Text>();
			dpsText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			dpsText.text = "DPS: Loading...";
			dpsText.fontSize = 15;
			((Graphic)dpsText).color = Color.white;
			dpsText.alignment = (TextAnchor)4;
			((Graphic)dpsText).raycastTarget = false;
			dpsText.verticalOverflow = (VerticalWrapMode)1;
			dpsText.supportRichText = true;
			RectTransform component2 = val3.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.offsetMin = new Vector2(1f, 1f);
			component2.offsetMax = new Vector2(-1f, -1f);
			Object.DontDestroyOnLoad((Object)(object)val);
		}
	}

	private void Update()
	{
		if (((ButtonControl)Keyboard.current.f5Key).wasPressedThisFrame)
		{
			uiVisible = !uiVisible;
			if ((Object)(object)backgroundImage != (Object)null)
			{
				((Behaviour)backgroundImage).enabled = uiVisible;
			}
			if ((Object)(object)dpsText != (Object)null)
			{
				((Behaviour)dpsText).enabled = uiVisible;
			}
		}
		if (!uiVisible || (Object)(object)dpsText == (Object)null || (Object)(object)Player.LocalPlayer == (Object)null)
		{
			if ((Object)(object)dpsText != (Object)null && uiVisible)
			{
				dpsText.text = "No Player";
			}
			return;
		}
		float time = Time.time;
		float value = dpsWindowSeconds.Value;
		while (damageQueue.Count > 0 && damageQueue.Peek().time < time - value)
		{
			damageQueue.Dequeue();
		}
		float num = 0f;
		foreach (var item in damageQueue)
		{
			num += item.damage;
		}
		currentDPS = ((damageQueue.Count > 0) ? (num / value) : 0f);
		dpsText.text = $"DPS: <color=#E3242B>{currentDPS:F2}</color>";
	}

	private void OnDestroy()
	{
		if ((Object)(object)uiCanvas != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)uiCanvas).gameObject);
		}
	}
}
internal class DPSPatches
{
	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerData), "OnLocalPlayerDamageTarget")]
	private static void PostDamage(in DamageCallbackData data)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: 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)
		if (data.damageData.damage > 0f)
		{
			TargetType type = ((IFollowable)data.target).Type;
			if ((type & 1) != 0 || (type & 2) != 0)
			{
				DPSMeter.damageQueue.Enqueue((Time.time, data.damageData.damage));
			}
		}
	}
}
namespace DamageMeter
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DamageMeter";

		public const string PLUGIN_NAME = "DamageMeter";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}