Decompiled source of SkillXPDisplay v1.0.0

SkillXPDisplay.dll

Decompiled 2 weeks ago
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SkillXPDisplay;

[BepInPlugin("com.custom.skillxpdisplay", "Skill XP Display", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Skill XP Display: numeric XP values in skills dialog");
		new Harmony("com.custom.skillxpdisplay").PatchAll();
	}

	public static float GetNextLevelRequirement(float level)
	{
		float num = Mathf.Floor(level + 1f);
		return Mathf.Pow(num, 1.5f) * 0.5f + 0.5f;
	}
}
[HarmonyPatch(typeof(SkillsDialog), "Setup")]
internal static class PatchSkillsDialogSetup
{
	private static FieldInfo f_elements = AccessTools.Field(typeof(SkillsDialog), "m_elements");

	private static TMP_Text FindOrCreateXPText(Transform parent, TMP_Text source)
	{
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		Transform val = parent.Find("xptext");
		if ((Object)(object)val != (Object)null)
		{
			return ((Component)val).GetComponent<TMP_Text>();
		}
		GameObject val2 = Object.Instantiate<GameObject>(((Component)source).gameObject, parent);
		((Object)val2).name = "xptext";
		TMP_Text component = val2.GetComponent<TMP_Text>();
		component.alignment = (TextAlignmentOptions)4100;
		component.fontSize = source.fontSize * 0.7f;
		component.overflowMode = (TextOverflowModes)0;
		component.enableWordWrapping = false;
		Transform transform = val2.transform;
		RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		RectTransform val4 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		float num;
		if (!((Object)(object)val4 != (Object)null))
		{
			num = 400f;
		}
		else
		{
			Rect rect = val4.rect;
			num = ((Rect)(ref rect)).width;
		}
		float num2 = num;
		val3.anchorMin = new Vector2(1f, 0f);
		val3.anchorMax = new Vector2(1f, 1f);
		val3.pivot = new Vector2(1f, 0.5f);
		val3.sizeDelta = new Vector2(200f, 0f);
		val3.anchoredPosition = new Vector2(-8f, 0f);
		return component;
	}

	private static void Postfix(SkillsDialog __instance, Player player)
	{
		List<Skill> skillList = ((Character)player).GetSkills().GetSkillList();
		List<GameObject> list = (List<GameObject>)f_elements.GetValue(__instance);
		if (skillList == null || list == null)
		{
			return;
		}
		int count = skillList.Count;
		if (count > list.Count)
		{
			count = list.Count;
		}
		for (int i = 0; i < count; i++)
		{
			Skill val = skillList[i];
			GameObject val2 = list[i];
			if ((Object)(object)val2 == (Object)null || !val2.activeSelf)
			{
				continue;
			}
			Transform transform = val2.transform;
			Transform val3 = Utils.FindChild(transform, "leveltext", (IterativeSearchType)0);
			if ((Object)(object)val3 == (Object)null)
			{
				continue;
			}
			TMP_Text component = ((Component)val3).GetComponent<TMP_Text>();
			if (!((Object)(object)component == (Object)null))
			{
				component.text = ((int)val.m_level).ToString();
				component.alignment = (TextAlignmentOptions)514;
				TMP_Text val4 = FindOrCreateXPText(transform, component);
				float accumulator = val.m_accumulator;
				float nextLevelRequirement = Plugin.GetNextLevelRequirement(val.m_level);
				if (val.m_level >= 100f)
				{
					val4.text = "<color=#FFAA00>MAX</color>";
					continue;
				}
				string text = accumulator.ToString("0.#");
				string text2 = nextLevelRequirement.ToString("0.#");
				val4.text = "<color=#FFAA00>" + text + " / " + text2 + "</color>";
			}
		}
	}
}