예제 #1
0
        public Item(byte[] itemData)
        {
            if (!IsPacketData && itemData[0] != 'J' && itemData[1] != 'M')
            {
                throw new Exception("Item data missing JM header");
            }
            if(IsPacketData && itemData[0] != 0x9c && itemData[0] != 0x9d)
            {
                throw new Exception("Attempting to parse a non-item packet!");
            }

            bs = new BitStream(itemData);

            if (!IsPacketData)
            {
                // Skip 'JM' Header
                bs.SkipBits(16);
            }

            ReadItemData();
            ReadRemainingBits();
        }
예제 #2
0
        /// <summary>
        /// Parses raw character stat data
        /// </summary>
        /// <param name="headerBytes">Raw characte stat data found between "gf" and "if" near offset 765 in save file</param>
        /// <remarks>Bit lengths of stat types are found in the CSvBits column of ItemStatCost.txt</remarks>
        /// Source: http://phrozenkeep.hugelaser.com/forum/viewtopic.php?f=8&t=9011&start=50
        private void ReadStats()
        {
            BitStream bs = new BitStream(statsBytes);

            // Skip header bytes
            bs.SkipBits(8);
            bs.SkipBits(8);

            while (bs.RemainingBits >= 9)
            {
                // ID of stat (See ItemStatCost.txt)
                int statIndex = (int)bs.ReadReversed(9);
                // Value contains this many bits (See CSvBits in ItemStatCost.txt)
                int statValueBits = 0;
                // Value needs to be shifted by this amount
                int valShift = 0;

                // Terminating stat index
                if (statIndex == 0x1ff)
                {
                    break;
                }

                statValueBits = ItemDefs.ItemStatCostsById[statIndex].CSvBits;
                if (statValueBits == 0)
                {
                    break;
                }

                valShift = ItemDefs.ItemStatCostsById[(int)statIndex].ValShift;

                int statValue = (int)bs.ReadReversed(statValueBits);
                if (!statValues.ContainsKey(statIndex))
                {
                    statValues.Add(statIndex, (statValue >> valShift));
                }
            }
        }