Decompiled source of ItemCounters v1.0.5

ItemCounters.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using On.RoR2.UI;
using RoR2;
using RoR2.UI;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ItemCounters")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ItemCounters")]
[assembly: AssemblyCopyright("Copyright © MrARM 2019")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a8049d35-c0f4-4c4c-8ef1-077583f1b7a2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace ItemCounters;

[BepInPlugin("com.github.mcmrarm.itemcounters", "Item Counters", "1.0.5")]
public class ItemCountersPlugin : BaseUnityPlugin
{
	private const string ModGuid = "com.github.mcmrarm.itemcounters";

	private static FieldInfo scoreboardStripMasterField = typeof(ScoreboardStrip).GetField("master", BindingFlags.Instance | BindingFlags.NonPublic);

	public void Start()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		ScoreboardStrip.UpdateItemCountText += new hook_UpdateItemCountText(ScoreboardStrip_UpdateItemCountText);
	}

	private void ScoreboardStrip_UpdateItemCountText(orig_UpdateItemCountText orig, ScoreboardStrip self)
	{
		int totalVisibleItemCount = self.itemInventoryDisplay.GetTotalVisibleItemCount();
		if (Object.op_Implicit((Object)(object)self.master) && Object.op_Implicit((Object)(object)self.itemInventoryDisplay) && totalVisibleItemCount != self.previousItemCount)
		{
			CharacterMaster master = self.master;
			int totalItemCountOfTier = master.inventory.GetTotalItemCountOfTier((ItemTier)0);
			int totalItemCountOfTier2 = master.inventory.GetTotalItemCountOfTier((ItemTier)6);
			int totalItemCountOfTier3 = master.inventory.GetTotalItemCountOfTier((ItemTier)1);
			int totalItemCountOfTier4 = master.inventory.GetTotalItemCountOfTier((ItemTier)7);
			int totalItemCountOfTier5 = master.inventory.GetTotalItemCountOfTier((ItemTier)2);
			int totalItemCountOfTier6 = master.inventory.GetTotalItemCountOfTier((ItemTier)8);
			int totalItemCountOfTier7 = master.inventory.GetTotalItemCountOfTier((ItemTier)3);
			int totalItemCountOfTier8 = master.inventory.GetTotalItemCountOfTier((ItemTier)4);
			int num = totalItemCountOfTier2 + totalItemCountOfTier4 + totalItemCountOfTier6;
			self.previousItemCount = totalVisibleItemCount;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendFormat("<nobr><color=#fff>{0} (", totalVisibleItemCount);
			if (totalItemCountOfTier > 0)
			{
				stringBuilder.AppendFormat("<color=#{1}>{0}</color> ", totalItemCountOfTier, ColorCatalog.GetColorHexString((ColorIndex)1));
			}
			if (totalItemCountOfTier3 > 0)
			{
				stringBuilder.AppendFormat("<color=#{1}>{0}</color> ", totalItemCountOfTier3, ColorCatalog.GetColorHexString((ColorIndex)2));
			}
			if (totalItemCountOfTier5 > 0)
			{
				stringBuilder.AppendFormat("<color=#{1}>{0}</color> ", totalItemCountOfTier5, ColorCatalog.GetColorHexString((ColorIndex)3));
			}
			if (totalItemCountOfTier7 > 0)
			{
				stringBuilder.AppendFormat("<color=#{1}>{0}</color> ", totalItemCountOfTier7, ColorCatalog.GetColorHexString((ColorIndex)4));
			}
			if (totalItemCountOfTier8 > 0)
			{
				stringBuilder.AppendFormat("<color=#{1}>{0}</color> ", totalItemCountOfTier8, ColorCatalog.GetColorHexString((ColorIndex)13));
			}
			if (num > 0)
			{
				stringBuilder.AppendFormat("<color=#{1}>{0}</color> ", num, ColorCatalog.GetColorHexString((ColorIndex)25));
			}
			if (stringBuilder[stringBuilder.Length - 1] == ' ')
			{
				stringBuilder[stringBuilder.Length - 1] = ')';
			}
			else if (stringBuilder[stringBuilder.Length - 1] == '(')
			{
				stringBuilder.Length -= 2;
			}
			((TMP_Text)self.itemCountText).text = stringBuilder.ToString();
		}
	}
}