Ejemplo n.º 1
0
        public CharSaveResponse(SaveReader playerData, string hash = null)
        {
            Data = playerData.GetBytes(true);                                                           // true is important!
            Hash = (hash != null) ? hash : Helper.MD5(Data);
            HashWithOriginalStat = (hash != null) ? hash : Helper.MD5(playerData.GetBytes(true, true)); // true is important!;

            Version   = playerData.Version;
            TimeStamp = playerData.TimeStamp;

            // items
            foreach (var i in playerData.Inventory.PlayerItems)
            {
                PlayerItems.Add(new CharItemResponse(i));
            }
            foreach (var i in playerData.Inventory.CorpseItems)
            {
                CorpseItems.Add(new CharItemResponse(i));
            }
            foreach (var i in playerData.Inventory.GolemItems)
            {
                GolemItems.Add(new CharItemResponse(i));
            }
            foreach (var i in playerData.Inventory.MercItems)
            {
                MercItems.Add(new CharItemResponse(i));
            }

            Name            = playerData.Character.Name;
            Class           = playerData.Character.Class;
            Died            = playerData.Character.Died;
            Expansion       = playerData.Character.Expansion;
            Hardcore        = playerData.Character.Hardcore;
            Ladder          = playerData.Character.Ladder;
            HasMercenary    = playerData.Character.HasMercenary;
            MercenaryExp    = playerData.Character.MercenaryExp;
            MercenaryNameId = playerData.Character.MercenaryNameId;
            MercenaryType   = playerData.Character.MercenaryType;
            Progression     = playerData.Character.Progression;
            BaseHitpoints   = playerData.Stat.BaseHitpoints;
            BaseMana        = playerData.Stat.BaseMana;
            BaseStamina     = playerData.Stat.BaseStamina;
            DeathCount      = playerData.Stat.DeathCount;
            Dexterity       = playerData.Stat.Dexterity;
            Energy          = playerData.Stat.Energy;
            Experience      = playerData.Stat.Experience;
            Gold            = playerData.Stat.Gold;
            GoldBank        = playerData.Stat.GoldBank;
            Hitpoints       = playerData.Stat.Hitpoints;
            KillCount       = playerData.Stat.KillCount;
            Level           = playerData.Stat.Level;
            Mana            = playerData.Stat.Mana;
            SkillPoints     = playerData.Stat.SkillPoints;
            Stamina         = playerData.Stat.Stamina;
            StatPoints      = playerData.Stat.StatPoints;
            Strength        = playerData.Stat.Strength;
            Vitality        = playerData.Stat.Vitality;

            for (var i = 0; i < playerData.Skill.Length; i++)
            {
                Skills.Add(byte.Parse(playerData.Skill[i].ToString()));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves the next item from specified position in raw inventory data
        /// </summary>
        /// <param name="inventoryBytes">Raw inventory data</param>
        /// <param name="begin">Position in raw inventory data to start looking for item</param>
        /// <returns>Next item in raw inventory data</returns>
        private Item GetNextItem(byte[] inventoryBytes, ref int begin)
        {
            int itemDataSize = GetNextItemSize(inventoryBytes, begin);

            byte[] itemData = new byte[itemDataSize];
            Array.Copy(inventoryBytes, begin, itemData, 0, itemDataSize);

            Item item;

            // TODO: This is a horror - should be rewritten soon
            try
            {
                item = new Item(itemData);
            }
            catch (IndexOutOfRangeException)
            {
                // Using a new itemDataSize because if this fails we need to increase begin by the original
                //  itemDataSize
                int itemDataSizeNew = itemDataSize + GetNextItemSize(inventoryBytes, begin + itemDataSize);

                try
                {
                    // Assume the JM found by GetNextItemSize was just part of the item's data.
                    //  Recalculate the length of the item ignoring the first JM it encounters
                    itemData = new byte[itemDataSizeNew];
                    Array.Copy(inventoryBytes, begin, itemData, 0, itemData.Length);
                    item = new Item(itemData);
                }
                catch (IndexOutOfRangeException)
                {
                    // Not recoverable, handled by code below
                    item = null;
                }

                if (item == null)
                {
                    // Item not recoverable, skip it
                    FailedItemCount++;
                    begin += itemDataSize;
                    return(null);
                }
                else
                {
                    // Set the new itemDataSize since the we fixed the problem
                    itemDataSize = itemDataSizeNew;
                }
            }

            begin += itemDataSize;
            if (item.IsSocketed)
            {
                uint failedSockets = 0;

                for (int i = 0; i < item.SocketsFilled; i++)
                {
                    Item nextItem = GetNextItem(inventoryBytes, ref begin);

                    if (nextItem == null)
                    {
                        failedSockets++;
                        continue;
                    }

                    item.Sockets.Add(nextItem);
                }

                if (failedSockets > 0)
                {
                    item.ClearRunewordData();

                    for (int i = 0; i < item.Sockets.Count; i++)
                    {
                        Item socketedItem = item.Sockets[i].RemoveSocketedItem(i);
                        CorpseItems.Add(socketedItem);
                    }
                }
            }

            return(item);
        }