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 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 = "")] [assembly: AssemblyCompany("PopupTotals")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Shows the total amount of an item in your inventory when collecting resources")] [assembly: AssemblyFileVersion("1.1.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyProduct("PopupTotals")] [assembly: AssemblyTitle("PopupTotals")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] [module: UnverifiableCode] namespace PopupTotals; [HarmonyPatch] public class ItemUtils { private static readonly Dictionary ItemNameToPrefabLookup = new Dictionary(); private static readonly HashSet Errored = new HashSet(); private static readonly List SubStringsToMatch = new List { "_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 unsafe 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown //IL_0160: Unknown result type (might be due to invalid IL or missing references) ItemNameToPrefabLookup.Clear(); Errored.Clear(); ManagedDataRegistry managedDataRegistry = DataSystem.ManagedDataRegistry; Enumerator enumerator = DataSystem.ItemHashLookupMap.GetEnumerator(); FixedString128Bytes val = default(FixedString128Bytes); bool flag = default(bool); while (enumerator.MoveNext()) { KeyValue current = enumerator.Current; try { PrefabGUID key = current.Key; ManagedItemData orDefault = managedDataRegistry.GetOrDefault(key, (ManagedItemData)null); if (orDefault == null) { continue; } PrefabLookupMap prefabLookupMap = managedDataRegistry._PrefabLookupMap; ((PrefabLookupMap)(ref prefabLookupMap)).TryGetFixedName(key, ref val); string text = ((object)(*(FixedString128Bytes*)(&val))/*cast due to .constrained prefix*/).ToString(); if (SubStringsToMatch.Any(text.Contains) && !(text == "Item_Ingredient_Kit_Base") && !(text == "Item_Ingredient_Gem_Base")) { 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(text2); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", PrefabName: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(text); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", PrefabGUID: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(((object)(*(PrefabGUID*)(&key))/*cast due to .constrained prefix*/).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(itemName); } logger.LogError(val); Errored.Add(itemName); return PrefabGUID.Empty; } } [BepInPlugin("PopupTotals", "PopupTotals", "1.1.0")] 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("PopupTotals"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted("1.1.0"); ((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 _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(); if (existingSystemManaged == null || __instance._Elements == null) { _hooked = false; return; } _world = ((ComponentSystemBase)__instance).World; _handler = OnEntryUpdate; EntryGroup elements = __instance._Elements; ((EntryGroupBase)(object)elements).OnEntryUpdate = ((EntryGroupBase)(object)elements).OnEntryUpdate + Action.op_Implicit(_handler); _hooked = true; } } private unsafe 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*)(&entry.SourceTypeText))/*cast due to .constrained prefix*/).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)); 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 elements = __instance._Elements; ((EntryGroupBase)(object)elements).OnEntryUpdate = ((EntryGroupBase)(object)elements).OnEntryUpdate - Action.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 = "1.1.0"; }