Decompiled source of DPSMod v1.2.0

DPSMod.dll

Decompiled 15 hours 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 BepInEx.Configuration;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DPSMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+81b37d63fe6b89220b54f495a7a8ccc9606a5715")]
[assembly: AssemblyProduct("DPSMod")]
[assembly: AssemblyTitle("DPSMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
	[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;
		}
	}
}
namespace BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace DPSMod
{
	[Harmony]
	[BepInPlugin("io.github.randomscorp.dpsmod", "DPS Mod", "1.2.0")]
	public class DPSModPlugin : BaseUnityPlugin
	{
		internal static GameObject dpsCanvas;

		public static ConfigEntry<float> timeToReset;

		public static ConfigEntry<float> timeBetweenUpdates;

		public static ConfigEntry<int> textFontSize;

		public static ConfigEntry<TextAnchor> alignment;

		public static DPSDisplay displayMonoB;

		public static ConfigEntry<bool> showTimeInComboat;

		public static ConfigEntry<bool> showDisplay;

		private void Awake()
		{
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_01d8: 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)
			timeToReset = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "Time to reset", 5f, "Time in seconds to reset the counters after doing no damage");
			timeBetweenUpdates = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "Time to update", 1f, "Time to update the DPS counter");
			alignment = ((BaseUnityPlugin)this).Config.Bind<TextAnchor>("UI", "Text Position", (TextAnchor)2, "UI position, updates in real time");
			alignment.SettingChanged += delegate
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				displayMonoB.text.alignment = alignment.Value;
			};
			textFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("UI", "Text Size", 20, "The font size used to render the display");
			textFontSize.SettingChanged += delegate
			{
				displayMonoB.text.fontSize = textFontSize.Value;
			};
			showTimeInComboat = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "Show Time in combat counter?", true, (ConfigDescription)null);
			showDisplay = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "Display visible", true, (ConfigDescription)null);
			showDisplay.SettingChanged += delegate
			{
				dpsCanvas.SetActive(showDisplay.Value);
			};
			dpsCanvas = new GameObject
			{
				name = "DPS Canvas"
			};
			Object.DontDestroyOnLoad((Object)(object)dpsCanvas);
			dpsCanvas.layer = 5;
			dpsCanvas.AddComponent<Canvas>().renderMode = (RenderMode)0;
			dpsCanvas.AddComponent<RectTransform>();
			dpsCanvas.SetActive(showDisplay.Value);
			Text val = dpsCanvas.AddComponent<Text>();
			val.fontSize = textFontSize.Value;
			val.font = Font.GetDefault();
			val.text = "PLACEHOLDER";
			val.alignment = alignment.Value;
			displayMonoB = dpsCanvas.AddComponent<DPSDisplay>();
			new Harmony("io.github.randomscorp.dpsmod").PatchAll();
		}

		[HarmonyPatch(typeof(HealthManager), "TakeDamage")]
		[HarmonyPrefix]
		private static void SaveHealthBefore0(HealthManager __instance, HitInstance hitInstance)
		{
			displayMonoB.hpBeforeEachHit = __instance.hp;
		}

		[HarmonyPatch(typeof(HealthManager), "TakeDamage")]
		[HarmonyPostfix]
		private static void DamageDealt(HealthManager __instance, HitInstance hitInstance)
		{
			DPSDisplay dPSDisplay = displayMonoB;
			double num = displayMonoB.hpBeforeEachHit - (double)__instance.hp;
			displayMonoB.totalDamageDone += ((num >= 0.0) ? num : displayMonoB.hpBeforeEachHit);
			dPSDisplay.timeSinceLastDamage = 0f;
		}
	}
	public class DPSDisplay : MonoBehaviour
	{
		public float timeSinceLastDamage;

		private float timeDoingDamage = 0f;

		public float timeSinceLastUpdate = 0f;

		public double hpBeforeEachHit = 0.0;

		public double totalDamageDone = 0.0;

		public Text text;

		private void Awake()
		{
			text = ((Component)this).gameObject.GetComponent<Text>();
			timeSinceLastDamage = DPSModPlugin.timeToReset.Value;
		}

		private void FixedUpdate()
		{
			if (timeSinceLastDamage >= DPSModPlugin.timeToReset.Value)
			{
				totalDamageDone = 0.0;
				timeDoingDamage = 0f;
			}
			else
			{
				timeDoingDamage += Time.deltaTime;
			}
			timeSinceLastDamage += Time.deltaTime;
			timeSinceLastUpdate += Time.deltaTime;
			if (timeSinceLastUpdate > DPSModPlugin.timeBetweenUpdates.Value)
			{
				text.text = "DPS: " + ((timeDoingDamage == 0f) ? "0" : (totalDamageDone / (double)timeDoingDamage).ToString("F2"));
				timeSinceLastUpdate = 0f;
			}
			else
			{
				text.text = text.text.Split(Environment.NewLine)[0];
			}
			Text obj = text;
			obj.text = obj.text + Environment.NewLine + $"Total damage: {totalDamageDone}";
			if (DPSModPlugin.showTimeInComboat.Value)
			{
				Text obj2 = text;
				obj2.text = obj2.text + Environment.NewLine + "Time in combat: " + timeDoingDamage.ToString("F2");
			}
		}
	}
}