Decompiled source of DamageStats v1.0.0

xyz.parsl.damage_stats.dll

Decompiled 7 months 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("xyz.parsl.damage_stats")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Displays damage numbers")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("xyz.parsl.damage_stats")]
[assembly: AssemblyTitle("xyz.parsl.damage_stats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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;
		}
	}
}
namespace DamageStats
{
	[BepInPlugin("xyz.parsl.damage_stats", "xyz.parsl.damage_stats", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource log;

		private static Harmony harmony;

		public static ConfigEntry<uint> numlabels;

		public static ConfigEntry<float> uiscale_config;

		public float scale;

		private static List<string> texts = new List<string>();

		private static string cachedLastOriginal;

		private static GUIStyle style;

		private static int multiplier;

		private void Awake()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			log = ((BaseUnityPlugin)this).Logger;
			numlabels = ((BaseUnityPlugin)this).Config.Bind<uint>("General", "num_lines", 8u, "Number of lines of damage history to display");
			uiscale_config = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ui_scale", 0.75f, "Value by which to scale ui. Recommend 1 for 1440p, 0.75 for 1080p");
			scale = uiscale_config.Value;
			style.fontSize = (int)((float)style.fontSize * scale);
			harmony = new Harmony("xyz.parsl.damage_stats");
			harmony.PatchAll();
			ResetText();
		}

		public static void AddText(string text, float damage, float dhealth)
		{
			if (text == cachedLastOriginal)
			{
				multiplier++;
				string arg = (damage * (float)multiplier).ToString("0.000");
				string arg2 = (dhealth * (float)multiplier).ToString("0.000");
				texts.RemoveAt(0);
				texts.Insert(0, text + $" (<b>x{multiplier}</b> = {arg} | {arg2})");
			}
			else
			{
				texts.Insert(0, text);
				cachedLastOriginal = text;
				multiplier = 1;
				texts.RemoveAt(Convert.ToInt32(numlabels.Value));
			}
		}

		public static void ResetText()
		{
			texts.Clear();
			for (int i = 0; i < numlabels.Value; i++)
			{
				texts.Insert(i, "");
			}
		}

		private void OnGUI()
		{
			//IL_003d: 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)
			GUI.Box(new Rect(10f * scale, 10f * scale, 750f * scale, (float)(30 * numlabels.Value + 10) * scale), "");
			int num = 0;
			foreach (string text in texts)
			{
				GUI.Label(new Rect(20f * scale, (float)(30 * numlabels.Value - 30 * num - 15) * scale, 360f * scale, 40f * scale), text, style);
				num++;
			}
		}

		static Plugin()
		{
			//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_0017: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			GUIStyle val = new GUIStyle
			{
				fontSize = 22,
				richText = true
			};
			val.normal.textColor = Color.white;
			style = val;
		}
	}
	[HarmonyPatch(typeof(EnemyIdentifier))]
	internal class EnemyIdentifierPatch
	{
		[HarmonyPatch("DeliverDamage")]
		private static void Prefix(EnemyIdentifier __instance, out float __state)
		{
			__state = __instance.health;
		}

		[HarmonyPatch("DeliverDamage")]
		private static void Postfix(EnemyIdentifier __instance, float __state, float multiplier, GameObject sourceWeapon)
		{
			bool flag = false;
			if (!(__state <= 0f))
			{
				__instance.ForceGetHealth();
				float num;
				if (__instance.health <= 0f)
				{
					num = 0f;
					flag = true;
				}
				else
				{
					num = __instance.health;
				}
				float dhealth = __state - num;
				string text = dhealth.ToString("0.000");
				string text2 = multiplier.ToString("0.000");
				Plugin.AddText("dmg: <b>" + text2 + "</b> | dHealth: <b>" + text + "</b> (<color=lime>" + __instance.hitter + "</color>)" + (flag ? " [<color=red>killed</color>]" : ""), multiplier, dhealth);
			}
		}
	}
	[HarmonyPatch(typeof(SceneHelper))]
	internal class SceneChangePatch
	{
		[HarmonyPatch("LoadScene")]
		private static void Prefix()
		{
			Plugin.ResetText();
		}
	}
	[HarmonyPatch(typeof(SceneHelper))]
	internal class SceneRestartPatch
	{
		[HarmonyPatch("RestartScene")]
		private static void Prefix()
		{
			Plugin.ResetText();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "xyz.parsl.damage_stats";

		public const string PLUGIN_NAME = "xyz.parsl.damage_stats";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}