Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of MaxStackHider v1.0.0
MaxStackHider.dll
Decompiled 2 years agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; 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("MaxStackHider")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("MaxStackHider")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("31c0a8c1-6396-41be-8ea8-7d2e0a4be28e")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.0.0.0")] namespace MaxStackHider; internal class ConfigurationFile { public static ConfigEntry<bool> debug; public static ConfigEntry<string> maxQuantityText; public static ConfigEntry<float> delayRefreshNumbers; private static ConfigFile configFile; private static string ConfigFileName = "Turbero.MaxStackHider.cfg"; private static string ConfigFileFullPath; internal static void LoadConfig(BaseUnityPlugin plugin) { configFile = plugin.Config; debug = configFile.Bind<bool>("1 - General", "DebugMode", false, "Enabling/Disabling the debugging in the console (default = false)"); delayRefreshNumbers = configFile.Bind<float>("1 - General", "DelayRefreshNumbers", 0.05f, "Necessary forced delay to refresh stack numbers. Only change under your own risk (default = 0.1f)"); maxQuantityText = configFile.Bind<string>("2 - Language", "MaxQuantityText", "Max Stack Size", "Translated text to display in tooltip for Max Stack Size"); SetupWatcher(); } private static void SetupWatcher() { FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName); fileSystemWatcher.Changed += ReadConfigValues; fileSystemWatcher.Created += ReadConfigValues; fileSystemWatcher.Renamed += ReadConfigValues; fileSystemWatcher.IncludeSubdirectories = true; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; } private static void ReadConfigValues(object sender, FileSystemEventArgs e) { if (!File.Exists(ConfigFileFullPath)) { return; } try { Logger.Log("Attempting to reload configuration..."); configFile.Reload(); } catch { Logger.LogError("There was an issue loading " + ConfigFileName); } } static ConfigurationFile() { string configPath = Paths.ConfigPath; char directorySeparatorChar = Path.DirectorySeparatorChar; ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName; } } public static class Logger { private static readonly ManualLogSource logger = Logger.CreateLogSource("Max Stack Hider"); internal static void Log(object s) { if (ConfigurationFile.debug.Value) { logger.LogInfo((object)s?.ToString()); } } internal static void LogInfo(object s) { logger.LogInfo((object)s?.ToString()); } internal static void LogWarning(object s) { logger.LogWarning((object)s?.ToString()); } internal static void LogError(object s) { logger.LogError((object)s?.ToString()); } } public class LoggerEmptyPatch { [HarmonyPatch(typeof(Player), "OnInventoryChanged")] public static class OnInventoryChangedPatch { public static void Postfix(Player __instance) { Logger.Log("**Player.OnInventoryChanged"); } } [HarmonyPatch(typeof(InventoryGui), "OnDropOutside")] public static class OnDropOutsidePatch { public static void Postfix(InventoryGui __instance) { Logger.Log("**InventoryGui.OnDropOutside"); } } [HarmonyPatch(typeof(Humanoid), "DropItem")] public static class DropItemPatch { public static void Postfix(Humanoid __instance) { Logger.Log("**Humanoid.DropItemPatch"); } } } [BepInPlugin("Turbero.MaxStackHider", "Max Stack Hider", "1.0.0")] public class MaxStackHider : BaseUnityPlugin { public const string GUID = "Turbero.MaxStackHider"; public const string NAME = "Max Stack Hider"; public const string VERSION = "1.0.0"; private readonly Harmony harmony = new Harmony("Turbero.MaxStackHider"); private void Awake() { ConfigurationFile.LoadConfig((BaseUnityPlugin)(object)this); harmony.PatchAll(); } private void onDestroy() { harmony.UnpatchSelf(); } } public class InventoryPatch { [HarmonyPatch(typeof(Inventory), "Changed")] public static class InventoryChangedPatch { public static void Postfix(Inventory __instance) { Logger.Log("**Inventory.Changed"); updateInventoryStackNumbersAwait(ConfigurationFile.delayRefreshNumbers.Value, __instance, __instance.GetName() == "Inventory"); } } [HarmonyPatch(typeof(InventoryGui), "Show")] public static class InventoryGuiShowPatch { public static void Postfix(InventoryGui __instance, Container container, int activeGroup = 1) { Logger.Log("**InventoryGui.InventoryGuiShowPatch"); updateInventoryStackNumbersAwait(ConfigurationFile.delayRefreshNumbers.Value, ((Humanoid)Player.m_localPlayer).GetInventory(), isPlayerInventory: true); if ((Object)(object)container != (Object)null) { updateInventoryStackNumbersAwait(ConfigurationFile.delayRefreshNumbers.Value, container.GetInventory(), isPlayerInventory: false); } } } [HarmonyPatch(typeof(Inventory), "MoveItemToThis", new Type[] { typeof(Inventory), typeof(ItemData), typeof(int), typeof(int), typeof(int) })] public static class MoveItemToThisBoolPatch { public static void Postfix(Inventory __instance, Inventory fromInventory, ItemData item, int amount, int x, int y, ref bool __result) { Logger.Log("**Inventory.MoveItemToThis Bool"); if (__instance.GetName() == fromInventory.GetName()) { updateInventoryStackNumbersAwait(ConfigurationFile.delayRefreshNumbers.Value, __instance, __instance.GetName() == "Inventory"); return; } updateInventoryStackNumbersAwait(ConfigurationFile.delayRefreshNumbers.Value, __instance, __instance.GetName() == "Inventory"); updateInventoryStackNumbersAwait(ConfigurationFile.delayRefreshNumbers.Value, fromInventory, fromInventory.GetName() == "Inventory"); } } public static async Task updateInventoryStackNumbersAwait(float seconds, Inventory inventory, bool isPlayerInventory) { await Task.Delay((int)(Math.Max(0f, seconds) * 1000f)); updateInventoryStackNumbers(inventory, isPlayerInventory); } public static void updateInventoryStackNumbers(Inventory inventory, bool isPlayerInventory) { Transform val = (isPlayerInventory ? ((Component)InventoryGui.instance).transform.Find("root/Player/PlayerGrid/Root") : ((Component)InventoryGui.instance).transform.Find("root/Container/ContainerGrid/Root")); if ((Object)(object)val.GetChild(0) == (Object)null) { return; } int num = (int)typeof(Inventory).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(inventory); int num2 = (int)typeof(Inventory).GetField("m_height", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(inventory); for (int i = 0; i < num2; i++) { for (int j = 0; j < num; j++) { if ((Object)(object)((Component)val.GetChild(i * num + j)).transform.Find("amountQuantity") == (Object)null) { createAmountQuantity(val.GetChild(i * num + j)); } ItemData itemAt = inventory.GetItemAt(j, i); if (itemAt == null || itemAt.m_shared.m_maxStackSize == 1) { ((TMP_Text)((Component)((Component)val.GetChild(i * num + j)).transform.Find("amountQuantity")).gameObject.GetComponent<TextMeshProUGUI>()).text = ""; } else { ((TMP_Text)((Component)((Component)val.GetChild(i * num + j)).transform.Find("amountQuantity")).gameObject.GetComponent<TextMeshProUGUI>()).text = itemAt.m_stack.ToString() ?? ""; } } } } private static void createAmountQuantity(Transform child) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) Transform obj = ((Component)child).transform.Find("amount"); RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null); ((Component)val).gameObject.SetActive(false); Transform obj2 = ((Component)child).transform.Find("amountQuantity"); if ((Object)(object)((obj2 != null) ? ((Component)obj2).gameObject : null) == (Object)null) { GameObject val2 = new GameObject("amountQuantity"); val2.transform.SetParent(((Component)child).transform, false); RectTransform val3 = val2.AddComponent<RectTransform>(); val3.sizeDelta = val.sizeDelta; val3.anchoredPosition = new Vector2(0f, -24f); TextMeshProUGUI val4 = val2.AddComponent<TextMeshProUGUI>(); ((TMP_Text)val4).alignment = (TextAlignmentOptions)514; ((TMP_Text)val4).fontSize = ((TMP_Text)((Component)val).GetComponent<TextMeshProUGUI>()).fontSize; ((TMP_Text)val4).fontStyle = ((TMP_Text)((Component)val).GetComponent<TextMeshProUGUI>()).fontStyle; ((TMP_Text)val4).font = ((TMP_Text)((Component)val).GetComponent<TextMeshProUGUI>()).font; ((TMP_Text)val4).fontMaterial = ((TMP_Text)((Component)val).GetComponent<TextMeshProUGUI>()).fontMaterial; } } } [HarmonyPatch(typeof(InventoryGrid), "CreateItemTooltip")] public static class UITooltipPatch { public static bool Prefix(InventoryGrid __instance, ItemData item, UITooltip tooltip) { //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) if (item.m_shared.m_maxStackSize == 1) { return true; } string tooltip2 = item.GetTooltip(-1); string text = "\n" + ConfigurationFile.maxQuantityText.Value + ": <color=\"orange\">" + item.m_shared.m_maxStackSize + "</color>"; tooltip2 = tooltip2.Replace("_description", "_description " + text); tooltip.Set(item.m_shared.m_name, tooltip2, __instance.m_tooltipAnchor, default(Vector2)); return false; } }