Decompiled source of StatsMenu v1.0.5

StatsMenu.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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: AssemblyTitle("StatsMenu")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StatsMenu")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ce668b16-7815-4fd8-88ec-38dd831b5cdc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace StatsMenu;

[BepInPlugin("dev.aresiel.wol.statsmenu", "Stats Menu", "4.0.0.0")]
public class StatsMenu : BaseUnityPlugin
{
	public static bool toggleBool = true;

	public static ConfigEntry<string> toggleKey;

	private void Awake()
	{
		Harmony.CreateAndPatchAll(typeof(StatsMenu), (string)null);
		toggleKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keybindings", "ToggleMenu", "", "The key used to toggle the menu while the inventory is closed. Name of the key, as used by https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html");
	}

	public static SkillState currentlySelected(Player player, SkillState fallback)
	{
		LowerHUD val = ((Array.FindIndex(GameController.activePlayers, (Player p) => (Object)(object)p == (Object)(object)player) != 0) ? GameUI.P1Hud : GameUI.P1Hud);
		object value = Traverse.Create((object)val).Field("inventoryMenu").GetValue();
		InventoryMenu val2 = (InventoryMenu)((value is InventoryMenu) ? value : null);
		EquipMenu equipMenu = val2.equipMenu;
		int value2 = Traverse.Create((object)equipMenu).Field("navigationIndex").GetValue<int>();
		try
		{
			return player.assignedSkills[value2] ?? fallback;
		}
		catch (IndexOutOfRangeException)
		{
			return fallback;
		}
	}

	public static string FetchStatsMessage(Player player)
	{
		StringBuilder stringBuilder = new StringBuilder();
		Health health = ((Entity)player).health;
		string name = ((State<Player>)(object)currentlySelected(player, player.GetBasicSkill())).name;
		string name2 = ((State<Player>)(object)player.GetSignatureSkill()).name;
		int num = Array.FindIndex(GameController.activePlayers, (Player p) => (Object)(object)p == (Object)(object)player);
		StatData statData = StatManager.GetStatData("Skills", "Player" + num, name);
		StatData statData2 = StatManager.GetStatData("Skills", "Player", name);
		StatData statData3 = StatManager.GetStatData("Skills", "Player" + num, name2);
		StatData statData4 = StatManager.GetStatData("Skills", "Player", name2);
		stringBuilder.AppendLine("[Damage]");
		float input = statData.ApplyVarStatMod<float>("damage", 1000f) / 1000f;
		stringBuilder.AppendLine("<color=#606060>" + ((statData.GetValue<int>("damage", -1) == 0) ? "None" : (statData.GetValue<int>("damage", -1) + " (" + Percentify(input) + ")")) + "</color>");
		stringBuilder.AppendLine("[Crit Heal CHN]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(((VarStat<float>)(object)health.critHealModStat).CurrentValue) + "</color>");
		stringBuilder.AppendLine("[Heal Amount]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(((VarStat<float>)(object)health.healModifierStat).CurrentValue) + "</color>");
		stringBuilder.AppendLine("[Evade Chance]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(((VarStat<float>)(object)health.evadeStat).CurrentValue) + "</color>");
		stringBuilder.AppendLine("[EFF Armor]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(1f - (1f - ((VarStat<float>)(object)health.armorStat).CurrentValue) * ((VarStat<float>)(object)health.damageTakenStat).CurrentValue) + "</color>");
		stringBuilder.AppendLine("[Shield]");
		stringBuilder.AppendLine("<color=#606060>" + Math.Round(((VarStat<float>)(object)health.shieldStat).CurrentValue, 2) + "</color>");
		stringBuilder.AppendLine("[Critical]");
		stringBuilder.AppendLine("<color=#606060>CHN: " + Percentify(statData.GetValue<float>("criticalHitChance", -1)) + "</color>");
		stringBuilder.AppendLine("<color=#606060>DMG: " + Percentify(statData.GetValue<float>("criticalDamageModifier", -1)) + "</color>");
		stringBuilder.AppendLine("[Cooldown]");
		float input2 = statData.GetValue<float>("cooldown", -1) / statData2.GetValue<float>("cooldown", -1);
		stringBuilder.AppendLine("<color=#606060>" + ((statData.GetValue<float>("cooldown", -1) == 0f) ? "None" : (Math.Round(statData.GetValue<float>("cooldown", -1)) + "s (" + Percentify(input2) + ")")) + "</color>");
		stringBuilder.AppendLine("[Knockback]");
		stringBuilder.AppendLine("<color=#606060>TKN: " + Percentify(((VarStat<float>)(object)health.knockbackModifierStat).CurrentValue) + "</color>");
		float num2 = statData.GetValue<float>("knockbackMultiplier", -1) / statData2.GetValue<float>("knockbackMultiplier", -1);
		stringBuilder.AppendLine("<color=#606060>GVN: " + (float.IsNaN(num2) ? "None" : (Math.Round(statData.GetValue<float>("knockbackMultiplier", -1), 2) + " (" + Percentify(num2) + ")")) + "</color>");
		stringBuilder.AppendLine("[Speed]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(((VarStat<float>)(object)((Entity)player).movement.moveSpeedStat).CurrentValue / ((VarStat<float>)(object)((Entity)player).movement.moveSpeedStat).BaseValue) + "</color>");
		stringBuilder.AppendLine("[Stun Duration]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(statData.GetValue<float>("hitStunDurationModifier", -1)) + "</color>");
		stringBuilder.AppendLine("[Sig Damage]");
		stringBuilder.AppendLine("<color=#606060>" + Percentify(statData3.GetValue<float>("overdriveDamageMultiplier", -1)) + "</color>");
		stringBuilder.AppendLine("[Sig Gain]");
		float num3 = statData3.GetValue<float>("overdriveProgressMultiplier", -1) / statData4.GetValue<float>("overdriveProgressMultiplier", -1);
		stringBuilder.AppendLine("<color=#606060>" + (float.IsNaN(num3) ? "None" : Percentify(num3)) + "</color>");
		stringBuilder.AppendLine("[Sig Decay]");
		stringBuilder.AppendLine("<color=#606060>Passive: " + Percentify(((VarStat<float>)(object)player.overdriveBuildDecayRate).CurrentValue / ((VarStat<float>)(object)player.overdriveBuildDecayRate).BaseValue) + "</color>");
		stringBuilder.AppendLine("<color=#606060>Active: " + Percentify(((VarStat<float>)(object)player.overdriveActiveDecayRate).CurrentValue / ((VarStat<float>)(object)player.overdriveBuildDecayRate).BaseValue) + "</color>");
		stringBuilder.AppendLine("[Curr Gain]");
		stringBuilder.AppendLine("<color=#606060>Gold: " + Percentify(((VarStat<float>)(object)LootManager.globalGoldModifier).CurrentValue) + "</color>");
		stringBuilder.AppendLine("<color=#606060>Gems: " + Math.Round(((VarStat<float>)(object)LootManager.globalPlatModifier).CurrentValue, 2) + "</color>");
		return stringBuilder.ToString();
	}

	public static string Percentify(float input)
	{
		return Math.Round(input * 100f, 2) + "%";
	}

	[HarmonyPatch(typeof(LowerHUD), "Update")]
	[HarmonyPostfix]
	private static void UpdateMenu(LowerHUD __instance)
	{
		object value = Traverse.Create((object)__instance).Field("hudObj").GetValue();
		GameObject val = (GameObject)((value is GameObject) ? value : null);
		Transform transform = val.transform;
		Transform val2 = transform.Find("StatsMenu");
		if (!((Object)(object)val2 == (Object)null))
		{
			if (((Component)val2).gameObject.activeInHierarchy)
			{
				object value2 = Traverse.Create((object)((Component)transform.Find("CooldownUI")).GetComponent<CooldownUI>()).Field("player").GetValue();
				Player player = (Player)((value2 is Player) ? value2 : null);
				((Component)val2.Find("Content")).GetComponent<Text>().text = FetchStatsMessage(player);
			}
			if (toggleKey.Value != "" && Input.GetKeyDown(toggleKey.Value))
			{
				((Component)val2).gameObject.SetActive(toggleBool);
				toggleBool = !toggleBool;
			}
		}
	}

	[HarmonyPatch(typeof(LowerHUD), "SetEquipMenuStatus")]
	[HarmonyPostfix]
	private static void ToggleMenu(bool givenStatus, LowerHUD __instance)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Expected O, but got Unknown
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Expected O, but got Unknown
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Expected O, but got Unknown
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		object value = Traverse.Create((object)__instance).Field("hudObj").GetValue();
		GameObject val = (GameObject)((value is GameObject) ? value : null);
		Transform transform = val.transform;
		Transform val2 = transform.Find("StatsMenu");
		Player player = default(Player);
		ref Player reference = ref player;
		object value2 = Traverse.Create((object)((Component)transform.Find("CooldownUI")).GetComponent<CooldownUI>()).Field("player").GetValue();
		reference = (Player)((value2 is Player) ? value2 : null);
		if ((Object)(object)val2 == (Object)null)
		{
			Font font = ChaosBundle.Get<Font>("Assets/Fonts/MunroSmall.ttf");
			GameObject val3 = new GameObject("StatsMenu");
			RectTransform val4 = val3.AddComponent<RectTransform>();
			CanvasRenderer val5 = val3.AddComponent<CanvasRenderer>();
			Image val6 = val3.AddComponent<Image>();
			val6.sprite = IconManager.GetCDBorder(0, true);
			((Graphic)val6).color = new Color(0.11f, 0.153f, 0.192f, 0.941f);
			val6.type = (Type)1;
			val4.anchorMin = new Vector2(0.1f, 0f);
			val4.anchorMax = new Vector2(0.4f, 0.5f);
			if (Array.FindIndex(GameController.activePlayers, (Player p) => (Object)(object)p == (Object)(object)player) == 0)
			{
				val4.offsetMin = new Vector2(-45.71f, 10.8f);
				val4.offsetMax = new Vector2(-142.95f, 121.5f);
			}
			else
			{
				val4.offsetMin = new Vector2(383f, 10.8f);
				val4.offsetMax = new Vector2(286f, 121.5f);
			}
			GameObject val7 = new GameObject("Title");
			val7.transform.SetParent(val3.transform);
			CanvasRenderer val8 = val7.AddComponent<CanvasRenderer>();
			RectTransform val9 = val7.AddComponent<RectTransform>();
			Outline val10 = val7.AddComponent<Outline>();
			Text val11 = val7.AddComponent<Text>();
			val11.text = "- Stats -";
			((Graphic)val11).color = new Color(1f, 1f, 1f, 0.8f);
			val11.font = font;
			val11.fontSize = 10;
			val11.fontStyle = (FontStyle)0;
			((Shadow)val10).effectDistance = new Vector2(0.5f, 0.5f);
			val9.anchorMin = new Vector2(0f, 0f);
			val9.anchorMax = new Vector2(0f, 1f);
			val9.offsetMin = new Vector2(7f, -4f);
			val9.offsetMax = new Vector2(200f, -4f);
			GameObject val12 = new GameObject("Content");
			val12.transform.SetParent(val3.transform);
			CanvasRenderer val13 = val12.AddComponent<CanvasRenderer>();
			RectTransform val14 = val12.AddComponent<RectTransform>();
			Text val15 = val12.AddComponent<Text>();
			val15.font = font;
			val15.fontSize = 6;
			val15.fontStyle = (FontStyle)0;
			((Graphic)val15).color = new Color(61f / 85f, 64f / 85f, 0.7647059f, 1f);
			val15.supportRichText = true;
			val14.anchorMin = new Vector2(0.5f, 0f);
			val14.anchorMax = new Vector2(0.5f, 1f);
			val14.offsetMin = new Vector2(-19f, 0f);
			val14.offsetMax = new Vector2(23f, -14f);
			val2 = Object.Instantiate<GameObject>(val3, transform).transform;
			((Object)val2).name = ((Object)val3).name;
		}
		if (givenStatus)
		{
			((Component)val2.Find("Content")).GetComponent<Text>().text = FetchStatsMessage(player);
			((Component)val2).gameObject.SetActive(true);
			toggleBool = false;
		}
		else
		{
			((Component)val2).gameObject.SetActive(false);
			toggleBool = true;
		}
	}
}