コード例 #1
0
        public void ReadDictionary(BinBuffer bb)
        {
            int modAmt = bb.ReadByte();

            for (int i = 0; i < modAmt; i++)
            {
                Mods.Add(bb.ReadString(), bb.ReadByte());
            }

            for (int i = 0; i < modAmt; i++)
            {
                ModID mid = bb.ReadByte();

                var modObjs = new BiDictionary <ObjName, ObjID>();

                short objAmt = bb.ReadInt16();

                for (int j = 0; j < objAmt; j++)
                {
                    modObjs.Add(bb.ReadString(), bb.ReadUInt16());
                }

                ModObjects.Add(mid, modObjs);
            }
        }
コード例 #2
0
        /// <summary>
        /// Load <paramref name="slots" /> items to <paramref name="inventory" /> from the <paramref name="bb" />.
        /// </summary>
        /// <param name="bb">The reader for loading data</param>
        /// <param name="inventory">The array of items</param>
        /// <param name="slots">The amount of items in the inventory to load</param>
        /// <param name="stack">Whether or not the stack size should be loaded</param>
        /// <param name="favourited">Whether or not the favourited state should be loaded</param>
        static void LoadItemSlots(BinBuffer bb, Item[] inventory, int slots, bool stack, bool favourited)
        {
            for (int i = 0; i < slots; i++)
            {
                // Load basic item data
                string mod = bb.ReadString();
                if (!String.IsNullOrEmpty(mod) && mod != PrismApi.VanillaString)
                {
                    string item = bb.ReadString();

                    if (!ModData.modsFromInternalName.ContainsKey(mod) || !ModData.modsFromInternalName[mod].ItemDefs.ContainsKey(item))
                    {
                        inventory[i].SetDefaults(ItemDefHandler.UnknownItemID);

                        inventory[i].toolTip  = mod;
                        inventory[i].toolTip2 = item;
                    }
                    else
                    {
                        inventory[i].SetDefaults(ModData.modsFromInternalName[mod].ItemDefs[item].Type);
                    }

                    if (stack)
                    {
                        inventory[i].stack = bb.ReadInt32();
                    }
                    inventory[i].prefix = bb.ReadByte();
                    if (favourited)
                    {
                        inventory[i].favorited = bb.ReadBoolean();
                    }
                }

                // Load Mod Data
                if (inventory[i].P_BHandler == null)
                {
                    inventory[i].P_BHandler = new ItemBHandler();

                    ((ItemBHandler)inventory[i].P_BHandler).Create();
                }

                ((ItemBHandler)inventory[i].P_BHandler).Load(bb);
            }
        }
コード例 #3
0
        /// <summary>
        /// Load player data from a .plr.prism file
        /// </summary>
        /// <param name="playerPath">The path to the vanilla .plr file</param>
        internal static void LoadPlayer(Player player, string playerPath)
        {
            playerPath += ".prism";

            // If mod data doesn't exist, don't try to load it
            if (!File.Exists(playerPath))
            {
                return;
            }

            try
            {
                using (FileStream fileStream = File.OpenRead(playerPath))
                {
                    byte version = (byte)fileStream.ReadByte(); // should be safe to cast here, very unlikely that the file is empty
                    if (version > PLAYER_VERSION)
                    {
                        throw new FileFormatException("Tried to load a player file from a future version of Prism.");
                    }
                    if (version < MIN_PLAYER_SUPPORT_VER)
                    {
                        throw new FileFormatException("This player is saved in a format that is too old and unsupported.");
                    }

                    using (CryptoStream cryptoStream = new CryptoStream(fileStream, new RijndaelManaged()
                    {
                        Padding = PaddingMode.None
                    }.CreateDecryptor(GenerateKey(player.name), ENCRYPTION_KEY), CryptoStreamMode.Read))
                        using (BinBuffer bb = new BinBuffer(cryptoStream))
                        {
                            #region Player Data
                            if (player.P_BHandler == null)
                            {
                                player.P_BHandler = new PlayerBHandler();

                                ((PlayerBHandler)player.P_BHandler).Create();
                            }

                            ((PlayerBHandler)player.P_BHandler).Load(bb);
                            #endregion Player Data

                            #region Item Data
                            LoadItemSlots(bb, player.armor, player.armor.Length, false, false);
                            LoadItemSlots(bb, player.dye, player.dye.Length, false, false);
                            LoadItemSlots(bb, player.inventory, Main.maxInventory, true, true);
                            LoadItemSlots(bb, player.miscEquips, player.miscEquips.Length, false, false);
                            LoadItemSlots(bb, player.bank.item, Chest.maxItems, true, false);
                            LoadItemSlots(bb, player.bank2.item, Chest.maxItems, true, false);
                            #endregion Item Data

                            #region Buff Data
                            for (int i = 0; i < Player.maxBuffs; i++)
                            {
                                var mod = bb.ReadString();

                                if (String.IsNullOrEmpty(mod) || !ModData.modsFromInternalName.ContainsKey(mod))
                                {
                                    continue;
                                }

                                var md = ModData.modsFromInternalName[mod];

                                var buff = bb.ReadString();
                                var t    = bb.ReadInt32();

                                if (!md.BuffDefs.ContainsKey(buff))
                                {
                                    continue;
                                }

                                player.AddBuff(md.BuffDefs[buff].Type, t);

                                if (player.P_BuffBHandler[i] == null)
                                {
                                    player.P_BuffBHandler[i] = new BuffBHandler();

                                    ((BuffBHandler)player.P_BuffBHandler[i]).Create();
                                }

                                ((BuffBHandler)player.P_BuffBHandler[i]).Save(bb);
                            }
                            #endregion Buff Data
                        }
                }
            }
            catch (Exception e)
            {
                // Character could not be properly loaded, report and prevent playing
                //TODO: report
                Logging.LogError("Could not load player " + player.name + ": " + e);
                Trace.WriteLine("Could not load player " + player.name + ": " + e.Message);
                player.loadStatus = 1;
            }
        }