Esempio n. 1
0
            private static bool Prefix(StorageUnit __instance, ref ItemTable ___storage, ref ItemTable __result)
            {
                if (!enabled || !settings.UpdateExistingStorages)
                {
                    return(true);
                }

                TableSlot[] slots = (TableSlot[])typeof(ItemTable).GetField("slots", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(___storage);

                int count = slots.Length;
                int lcount;

                switch (__instance.Level)
                {
                case 0:
                    lcount = settings.WoodenStorageSize;
                    break;

                case 1:
                    lcount = settings.MetalStorageSize;
                    break;

                case 2:
                case -1:
                    lcount = settings.SafetyBoxSize;
                    break;

                default:
                    return(true);
                }

                if (count == lcount)
                {
                    return(true);
                }

                Dbgl($"Changing slots for level {__instance.Level} from {count} to {lcount}");
                TableSlot[] newSlots = new TableSlot[lcount];
                Array.Copy(slots, newSlots, lcount > count ? count : lcount);
                if (lcount > count)
                {
                    for (int i = 0; i < lcount - count; i++)
                    {
                        newSlots[count + i] = new TableSlot();
                    }
                }
                typeof(ItemTable).GetField("slots", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(___storage, newSlots);
                typeof(ItemTable).GetField("unlockedCount", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(___storage, newSlots.Length);
                __result = ___storage;
                return(false);
            }
Esempio n. 2
0
        private static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            GUILayout.Label(string.Format("Inventory Pages: <b>{0}</b>", pages), new GUILayoutOption[0]);
            pages = (int)GUILayout.HorizontalSlider(pages, 3f, 100f, new GUILayoutOption[0]);
            if (GUILayout.Button("Resize", new GUILayoutOption[0]) && Module <Player> .Self?.bag != null)
            {
                Dbgl("Resizing");

                ItemBag     bag   = Module <Player> .Self.bag;
                ItemTable[] table = (ItemTable[])typeof(ItemBag).GetField("itemTables", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(bag);
                for (int i = 0; i < table.Length; i++)
                {
                    ItemTable   t        = table[i];
                    TableSlot[] slots    = (TableSlot[])typeof(ItemTable).GetField("slots", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(t);
                    TableSlot[] newslots = new TableSlot[40 * pages];
                    for (int j = 0; j < 40 * pages; j++)
                    {
                        if (j < slots.Length)
                        {
                            newslots[j] = slots[j];
                        }
                        else
                        {
                            newslots[j] = new TableSlot();
                        }
                    }
                    Dbgl($"Replacing table {i}");
                    typeof(ItemTable).GetField("slots", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(table[i], newslots);
                }
                Dbgl($"Replacing tables");
                typeof(ItemBag).GetField("itemTables", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(Module <Player> .Self.bag, table);
            }
            if (GUILayout.Button("Unlock", new GUILayoutOption[0]))
            {
                Dbgl("Unlocking");

                Module <Player> .Self.bag.UnlockSlotByRow(500, false);
            }
        }