public void WriteDictionary(BinBuffer bb) { unchecked { bb.WriteByte((ModID)Mods.Count); } foreach (var kvp in Mods) { bb.Write(kvp.Key); bb.Write(kvp.Value); } foreach (var kvp in ModObjects) { bb.Write(kvp.Key); var mod = kvp.Value; bb.Write(unchecked ((ObjID)mod.Count)); foreach (var kvp_ in mod) { bb.Write(kvp_.Key); bb.Write(kvp_.Value); } } }
static void SaveChestItems(BinBuffer bb) { var chests = Main.chest.Where(c => c != null); bb.Write((short)chests.Count()); bb.WriteByte(Chest.maxItems); foreach (var c in chests) { SaveItemSlots(bb, c.item, Chest.maxItems, true, false); } }
/// <summary> /// Save <paramref name="slots" /> items from <paramref name="inventory" /> to the <paramref name="bb" />. /// </summary> /// <param name="bb">The writer for storing data</param> /// <param name="inventory">The array of items</param> /// <param name="slots">The amount of items in the inventory to save</param> /// <param name="stack">Whether or not the stack size should be saved</param> /// <param name="favourited">Whether or not the favourited state should be saved</param> static void SaveItemSlots(BinBuffer bb, Item[] inventory, int slots, bool stack, bool favourited) { for (int i = 0; i < slots; i++) { if (inventory[i].type < ItemID.Count) { bb.Write(String.Empty); // write an empty string instead of 'Vanilla' } else { // Save basic item data ItemDef item = Handler.ItemDef.DefsByType[inventory[i].type]; bb.Write(item.Mod.InternalName); bb.Write(item.InternalName); // why, vanilla writes these already? // only type + mod data is needed imo (and prefix type (+ data?) later on) if (stack) { bb.Write(inventory[i].stack); } bb.WriteByte(inventory[i].prefix); if (favourited) { bb.Write(inventory[i].favorited); } } // Save Mod Data if (inventory[i].P_BHandler != null) { ItemBHandler handler = (ItemBHandler)inventory[i].P_BHandler; handler.Save(bb); } else { bb.Write(0); } } }
static void SavePrismData(BinBuffer bb) { bb.WriteByte(WORLD_VERSION); }