Decompiled source of BetterScoreboard v1.0.3

BetterScoreboard.dll

Decompiled 4 hours ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using RoR2;
using RoR2.ContentManagement;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
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("BetterScoreboard")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetterScoreboard")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9dbaf54f-c6d4-4960-912e-20c5f0a0fc4c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public class ItemTierConfig
{
	public ItemTierDef tierDef { get; private set; }

	public ConfigEntry<bool> active { get; private set; }

	public ConfigEntry<int> order { get; private set; }

	public ConfigEntry<string> color { get; private set; }

	public ConfigEntry<string> includedTiers { get; private set; }

	public ItemTierConfig(ItemTierDef tierDef)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Invalid comparison between Unknown and I4
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Expected I4, but got Unknown
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Invalid comparison between Unknown and I4
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Invalid comparison between Unknown and I4
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Expected I4, but got Unknown
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Invalid comparison between Unknown and I4
		this.tierDef = tierDef;
		string text = "Item Tier: " + ((Object)tierDef).name;
		bool flag = (int)tierDef.tier > 10;
		if (!flag)
		{
			ItemTier tier = tierDef.tier;
			ItemTier val = tier;
			switch ((int)val)
			{
			case 0:
				text += " (White/Common)";
				break;
			case 1:
				text += " (Green/Uncommon)";
				break;
			case 2:
				text += " (Red/Legendary)";
				break;
			case 3:
				text += " (Blue/Lunar)";
				break;
			case 4:
				text += " (Yellow/Boss)";
				break;
			case 6:
			case 7:
			case 8:
			case 9:
				text += " (Purple/Void)";
				break;
			}
		}
		active = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>(text, "Enabled", (int)tierDef.tier != 6 && (int)tierDef.tier != 7 && (int)tierDef.tier != 8, "Determines whether to count this tier.");
		order = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>(text, "Order", tierDef.tier - (flag ? 1 : 0) + 1, "Determines the priority of this tier.");
		color = ((BaseUnityPlugin)Plugin.instance).Config.Bind<string>(text, "Color", ColorCatalog.GetColorHexString(tierDef.colorIndex), "Specifies the color for this tier. Leave blank for default color.");
		includedTiers = ((BaseUnityPlugin)Plugin.instance).Config.Bind<string>(text, "Included Tiers", ((int)tierDef.tier == 9) ? "VoidTier1Def,VoidTier2Def,VoidTier3Def" : "", "Includes the count of the listed tiers to this tier. Seperate the tier names with commas.");
	}
}
[BepInPlugin("bulletbot.betterscoreboard", "BetterScoreboard", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
	private const string modGUID = "bulletbot.betterscoreboard";

	private const string modName = "BetterScoreboard";

	private const string modVer = "1.0.3";

	public static Plugin instance;

	private ConfigEntry<int> textSizeIncrease;

	public ManualLogSource logger;

	private readonly Harmony harmony = new Harmony("bulletbot.betterscoreboard");

	public List<ItemTierConfig> itemTierConfigs = new List<ItemTierConfig>();

	private UIElementAllocator<ScoreboardStrip> stripAllocator;

	private bool triedApplyingUIChanges;

	public ConfigEntry<bool> hideBelowZero { get; private set; }

	public ConfigEntry<bool> showLunarCoins { get; private set; }

	private void Awake()
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		instance = this;
		hideBelowZero = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "Hide Item Tier Counters Below Zero", true, "Hides all the item tier counters that are under zero.");
		textSizeIncrease = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "Item Tier Counter Size Increase", 20, "Increases the text size on X axis to the left.");
		showLunarCoins = ((BaseUnityPlugin)this).Config.Bind<bool>("Config", "Show Lunar Coins On Hover", true, "It shows lunar coins instead of the money when hovered over.");
		Stage.onStageStartGlobal += delegate
		{
			stripAllocator = null;
			triedApplyingUIChanges = false;
		};
		logger = Logger.CreateLogSource("BetterScoreboard");
		HUD.shouldHudDisplay += (ShouldHudDisplayDelegate)delegate(HUD hud, ref bool _)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			if (!triedApplyingUIChanges)
			{
				if (stripAllocator == null)
				{
					stripAllocator = (UIElementAllocator<ScoreboardStrip>)typeof(ScoreboardController).GetField("stripAllocator", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(hud.scoreboardPanel.GetComponent<ScoreboardController>());
				}
				else
				{
					List<PlayerCharacterMasterController> list = PlayerCharacterMasterController.instances.Where((PlayerCharacterMasterController x) => ((Component)x).gameObject.activeInHierarchy && (Object)(object)x.master.GetBody() != (Object)null && Util.GetBestMasterName(x.master) != null).ToList();
					int num = 0;
					for (int i = 0; i < list.Count; i++)
					{
						TextMeshProUGUI itemCountText = stripAllocator.elements[i].itemCountText;
						int value = textSizeIncrease.Value;
						RectTransform component = ((Component)itemCountText).GetComponent<RectTransform>();
						((Transform)component).localPosition = new Vector3(((Transform)component).localPosition.x - (float)(value / 2), ((Transform)component).localPosition.y, ((Transform)component).localPosition.z);
						component.sizeDelta = new Vector2(component.sizeDelta.x + (float)value, component.sizeDelta.y);
						((TMP_Text)itemCountText).horizontalAlignment = (HorizontalAlignmentOptions)4;
						((TMP_Text)itemCountText).enableAutoSizing = true;
						num++;
					}
					if (list.Count == num)
					{
						logger.LogMessage((object)"Applied UI changes.");
					}
					else
					{
						logger.LogMessage((object)"Couldn't apply UI changes.");
					}
					triedApplyingUIChanges = true;
				}
			}
		};
		harmony.PatchAll();
	}
}
namespace BetterItemCounter.Patches;

[HarmonyPatch(typeof(ItemCatalog))]
internal class ItemCatalogPatch
{
	[HarmonyPatch("Init")]
	[HarmonyPostfix]
	private static void Init()
	{
		ItemTierDef[] itemTierDefs = ContentManager.itemTierDefs;
		foreach (ItemTierDef tierDef in itemTierDefs)
		{
			Plugin.instance.itemTierConfigs.Add(new ItemTierConfig(tierDef));
		}
	}
}
[HarmonyPatch(typeof(ScoreboardStrip))]
internal class ScoreboardStripPatch
{
	private static GameObject hoveredMoneyText;

	[HarmonyPatch("UpdateItemCountText")]
	[HarmonyPrefix]
	private static bool UpdateItemCountText(ScoreboardStrip __instance, CharacterMaster ___master, ref int ___previousItemCount)
	{
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		ItemInventoryDisplay itemInventoryDisplay = __instance.itemInventoryDisplay;
		int totalVisibleItemCount = itemInventoryDisplay.GetTotalVisibleItemCount();
		if (Object.op_Implicit((Object)(object)___master) && Object.op_Implicit((Object)(object)itemInventoryDisplay) && totalVisibleItemCount != ___previousItemCount)
		{
			___previousItemCount = totalVisibleItemCount;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(___previousItemCount);
			List<string> list = new List<string>();
			ItemTierConfig[] array = Plugin.instance.itemTierConfigs.OrderBy((ItemTierConfig x) => x.order.Value).ToArray();
			Color val = default(Color);
			foreach (ItemTierConfig itemTierConfig in array)
			{
				if (!itemTierConfig.active.Value)
				{
					continue;
				}
				int num = ___master.inventory.GetTotalItemCountOfTier(itemTierConfig.tierDef.tier);
				if (!string.IsNullOrEmpty(itemTierConfig.includedTiers.Value))
				{
					string[] array2 = (from x in itemTierConfig.includedTiers.Value.Split(new char[1] { ',' })
						select x.Trim()).ToArray();
					foreach (string includedTier in array2)
					{
						ItemTierConfig itemTierConfig2 = Plugin.instance.itemTierConfigs.FirstOrDefault((ItemTierConfig x) => ((Object)x.tierDef).name == includedTier);
						if (itemTierConfig2 != null)
						{
							num += ___master.inventory.GetTotalItemCountOfTier(itemTierConfig2.tierDef.tier);
						}
					}
				}
				if (!Plugin.instance.hideBelowZero.Value || num > 0)
				{
					string text = "#" + itemTierConfig.color.Value;
					if (!ColorUtility.TryParseHtmlString(text, ref val))
					{
						text = "#" + ColorCatalog.GetColorHexString(itemTierConfig.tierDef.colorIndex);
					}
					list.Add($"<color={text}>{num}</color>");
				}
			}
			if (list.Count > 0)
			{
				stringBuilder.Append(" (");
				stringBuilder.Append(string.Join(" ", list));
				stringBuilder.Append(")");
			}
			((TMP_Text)__instance.itemCountText).text = stringBuilder.ToString();
			return true;
		}
		return false;
	}

	[HarmonyPatch("UpdateMoneyText")]
	[HarmonyPrefix]
	private static bool UpdateMoneyText(ScoreboardStrip __instance, CharacterMaster ___master, ref uint ___previousMoney)
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)___master) && Plugin.instance.showLunarCoins.Value)
		{
			PointerEventData val = new PointerEventData(EventSystem.current);
			val.position = Vector2.op_Implicit(UnityInput.Current.mousePosition);
			List<RaycastResult> list = new List<RaycastResult>();
			((BaseRaycaster)((Component)((Component)__instance).transform.parent.parent.parent).GetComponent<GraphicRaycaster>()).Raycast(val, list);
			RaycastResult val2 = list.Find((RaycastResult result) => ((Object)((RaycastResult)(ref result)).gameObject).name == "MoneyText");
			GameObject gameObject = ((RaycastResult)(ref val2)).gameObject;
			if (Object.op_Implicit((Object)(object)gameObject) && (Object)(object)((Component)__instance.moneyText).gameObject == (Object)(object)gameObject)
			{
				((TMP_Text)__instance.moneyText).text = $"<color=#{ColorCatalog.GetColorHexString((ColorIndex)12)}><sprite name=\"LunarCoin\" tint=1>{((Component)___master).GetComponent<PlayerCharacterMasterController>().networkUser.lunarCoins}</color>";
				hoveredMoneyText = gameObject;
			}
			else if (___master.money != ___previousMoney || (Object)(object)((Component)__instance.moneyText).gameObject == (Object)(object)hoveredMoneyText)
			{
				___previousMoney = ___master.money;
				((TMP_Text)__instance.moneyText).text = "$" + ___previousMoney;
				gameObject = null;
			}
			return true;
		}
		return false;
	}
}