Decompiled source of PopupTotals v1.1.0

PopupTotals.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.UI;
using StunShared.UI;
using Stunlock.Core;
using Stunlock.Localization;
using TMPro;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Entities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PopupTotals")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Shows the total amount of an item in your inventory when collecting resources")]
[assembly: AssemblyFileVersion("0.1.10.0")]
[assembly: AssemblyInformationalVersion("0.1.10+1.Branch.main.Sha.c33d0879382e1a0da34861ec55914ba7e637a80e")]
[assembly: AssemblyProduct("PopupTotals")]
[assembly: AssemblyTitle("PopupTotals")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.10.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 PopupTotals
{
	[HarmonyPatch]
	public class ItemUtils
	{
		private static readonly Dictionary<string, PrefabGUID> ItemNameToPrefabLookup = new Dictionary<string, PrefabGUID>();

		private static readonly HashSet<string> Errored = new HashSet<string>();

		private static readonly List<string> SubStringsToMatch = new List<string>(3) { "_Ingredient_", "Item_Consumable", "Item_Building_Plants" };

		private static GameDataSystem DataSystem { get; set; }

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameDataSystem), "RegisterItems")]
		private static void GameDataSystem_RegisterItems_Postfix(ref GameDataSystem __instance)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			DataSystem = __instance;
			if (__instance.ItemHashLookupMap.Count() != 0)
			{
				Plugin.Logger.LogInfo((object)"Creating lookup tables...");
				RebuildLut();
			}
		}

		private static void RebuildLut()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			ItemNameToPrefabLookup.Clear();
			Errored.Clear();
			ManagedDataRegistry managedDataRegistry = DataSystem.ManagedDataRegistry;
			Enumerator<PrefabGUID, ItemData> enumerator = DataSystem.ItemHashLookupMap.GetEnumerator();
			FixedString128Bytes val = default(FixedString128Bytes);
			while (enumerator.MoveNext())
			{
				KeyValue<PrefabGUID, ItemData> current = enumerator.Current;
				try
				{
					PrefabGUID key = current.Key;
					ManagedItemData orDefault = managedDataRegistry.GetOrDefault<ManagedItemData>(key, (ManagedItemData)null);
					if (orDefault == null)
					{
						continue;
					}
					PrefabLookupMap prefabLookupMap = managedDataRegistry._PrefabLookupMap;
					((PrefabLookupMap)(ref prefabLookupMap)).TryGetFixedName(key, ref val);
					string text = ((object)(FixedString128Bytes)(ref val)).ToString();
					if (!SubStringsToMatch.Any(text.Contains))
					{
						continue;
					}
					bool flag = ((text == "Item_Ingredient_Kit_Base" || text == "Item_Ingredient_Gem_Base") ? true : false);
					if (!flag)
					{
						string text2 = Localization.Get(orDefault.Name, false);
						ManualLogSource logger = Plugin.Logger;
						BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(34, 3, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Item: ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text2);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", PrefabName: ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", PrefabGUID: ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((object)(PrefabGUID)(ref key)).ToString());
						}
						logger.LogDebug(val2);
						ItemNameToPrefabLookup.TryAdd(text2, key);
					}
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)ex);
				}
			}
		}

		public static PrefabGUID GetOrRebuild(string itemName)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			if (ItemNameToPrefabLookup.TryGetValue(itemName, out var value))
			{
				return value;
			}
			RebuildLut();
			if (ItemNameToPrefabLookup.TryGetValue(itemName, out var value2))
			{
				return value2;
			}
			if (Errored.Contains(itemName))
			{
				return PrefabGUID.Empty;
			}
			ManualLogSource logger = Plugin.Logger;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(41, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Error rebuilding LUT no item name found: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(itemName);
			}
			logger.LogError(val);
			Errored.Add(itemName);
			return PrefabGUID.Empty;
		}
	}
	[BepInPlugin("PopupTotals", "PopupTotals", "0.1.10")]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		internal static ManualLogSource Logger { get; private set; }

		public override void Load()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			Logger = ((BasePlugin)this).Log;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("PopupTotals");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.10");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("PopupTotals");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	[HarmonyPatch]
	public class ScrollingCombatTextParentMapperPatch
	{
		private static Action<SCTText, EntryData> _handler;

		private static bool _hooked;

		private static PrefabGUID _sctTypeResourceGain = new PrefabGUID(1876501183);

		private static World _world;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ScrollingCombatTextParentMapper), "OnUpdate")]
		private static void OnUpdate_Prefix(ref ScrollingCombatTextParentMapper __instance)
		{
			if (!_hooked)
			{
				PrefabCollectionSystem existingSystemManaged = ((ComponentSystemBase)__instance).World.GetExistingSystemManaged<PrefabCollectionSystem>();
				if (existingSystemManaged == null || __instance._Elements == null)
				{
					_hooked = false;
					return;
				}
				_world = ((ComponentSystemBase)__instance).World;
				_handler = OnEntryUpdate;
				EntryGroup<SCTText, EntryData> elements = __instance._Elements;
				((EntryGroupBase<SCTText, EntryData>)(object)elements).OnEntryUpdate = ((EntryGroupBase<SCTText, EntryData>)(object)elements).OnEntryUpdate + Action<SCTText, EntryData>.op_Implicit(_handler);
				_hooked = true;
			}
		}

		private static void OnEntryUpdate(SCTText text, EntryData entry)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if (((PrefabGUID)(ref entry.Type)).GuidHash != ((PrefabGUID)(ref _sctTypeResourceGain)).GuidHash)
			{
				return;
			}
			string text2 = ((object)(FixedString128Bytes)(ref entry.SourceTypeText)).ToString();
			if (!text2.Contains('(') || !text2.Contains(')'))
			{
				PrefabGUID orRebuild = ItemUtils.GetOrRebuild(text2);
				Entity val = default(Entity);
				if (ConsoleShared.TryGetLocalCharacterInCurrentWorld(ref val, _world))
				{
					int itemAmount = InventoryUtilities.GetItemAmount(_world.EntityManager, val, orRebuild, default(Nullable_Unboxed<int>));
					string text3 = $"{text2} ({itemAmount})";
					entry.SourceTypeText = new FixedString128Bytes(text3);
					((TMP_Text)text.Text).m_text = ((TMP_Text)text.Text).m_text.Replace(text2, text3);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ScrollingCombatTextParentMapper), "OnDestroy")]
		private static void OnDestroy_Postfix(ref ScrollingCombatTextParentMapper __instance)
		{
			if (_handler != null)
			{
				EntryGroup<SCTText, EntryData> elements = __instance._Elements;
				((EntryGroupBase<SCTText, EntryData>)(object)elements).OnEntryUpdate = ((EntryGroupBase<SCTText, EntryData>)(object)elements).OnEntryUpdate - Action<SCTText, EntryData>.op_Implicit(_handler);
				_hooked = false;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "PopupTotals";

		public const string PLUGIN_NAME = "PopupTotals";

		public const string PLUGIN_VERSION = "0.1.10";
	}
}