示例#1
0
        /// <summary>
        /// Encodes the internal item data back into raw data
        /// </summary>
        /// <returns>raw data for the item data</returns>
        private byte[] EncodeItemData()
        {
            int dataLength;

            byte[] data;

            // Encode the item data into a memory stream
            using (MemoryStream writeStream = new MemoryStream(2048))
            {
                using (BinaryWriter writer = new BinaryWriter(writeStream))
                {
                    // Write zero into the checksum value
                    writer.Write(Convert.ToInt32(0, CultureInfo.InvariantCulture));

                    TQData.WriteCString(writer, "begin_block");
                    writer.Write(this.beginBlockCrap);

                    TQData.WriteCString(writer, "stashVersion");
                    writer.Write(this.stashVersion);

                    TQData.WriteCString(writer, "fName");

                    // Changed to raw data to support extended characters
                    writer.Write(this.name.Length);
                    writer.Write(this.name);

                    TQData.WriteCString(writer, "sackWidth");
                    writer.Write(this.Width);

                    TQData.WriteCString(writer, "sackHeight");
                    writer.Write(this.Height);

                    // SackType should already be set at this point
                    this.sack.Encode(writer);
                    dataLength = (int)writeStream.Length;
                }

                // now just return the buffer we wrote to.
                data = writeStream.GetBuffer();
            }

            // The problem is that data[] may be bigger than the amount of data in it.
            // We need to resize the array
            if (dataLength == data.Length)
            {
                return(data);
            }

            byte[] realData = new byte[dataLength];
            Array.Copy(data, realData, dataLength);
            return(realData);
        }
示例#2
0
        /// <summary>
        /// Encodes the live item data into raw binary format
        /// </summary>
        /// <returns>byte array holding the converted binary data</returns>
        private byte[] EncodeItemData()
        {
            int dataLength;

            byte[] data;

            // Encode the item data into a memory stream
            using (MemoryStream writeStream = new MemoryStream(2048))
            {
                using (BinaryWriter writer = new BinaryWriter(writeStream))
                {
                    TQData.WriteCString(writer, "numberOfSacks");
                    writer.Write(this.numberOfSacks);

                    TQData.WriteCString(writer, "currentlyFocusedSackNumber");
                    writer.Write(this.currentlyFocusedSackNumber);

                    TQData.WriteCString(writer, "currentlySelectedSackNumber");
                    writer.Write(this.currentlySelectedSackNumber);

                    for (int i = 0; i < this.numberOfSacks; ++i)
                    {
                        // SackType should already be set at this point
                        this.sacks[i].Encode(writer);
                    }

                    dataLength = (int)writeStream.Length;
                }

                // now just return the buffer we wrote to.
                data = writeStream.GetBuffer();
            }

            // The problem is that ans() may be bigger than the amount of data in it.
            // We need to resize the array
            if (dataLength == data.Length)
            {
                return(data);
            }

            byte[] realData = new byte[dataLength];
            Array.Copy(data, realData, dataLength);
            return(realData);
        }
示例#3
0
        /// <summary>
        /// Encodes the live equipment data into raw binary
        /// </summary>
        /// <returns>byte array holding the converted binary data</returns>
        private byte[] EncodeEquipmentData()
        {
            int dataLength;

            byte[] data;

            // Encode the item data into a memory stream
            using (MemoryStream writeStream = new MemoryStream(2048))
            {
                using (BinaryWriter writer = new BinaryWriter(writeStream))
                {
                    if (this.IsImmortalThrone)
                    {
                        TQData.WriteCString(writer, "equipmentCtrlIOStreamVersion");
                        writer.Write(this.equipmentCtrlIOStreamVersion);
                    }

                    this.EquipmentSack.Encode(writer);

                    dataLength = (int)writeStream.Length;
                }

                // now just return the buffer we wrote to.
                data = writeStream.GetBuffer();
            }

            // The problem is that ans() may be bigger than the amount of data in it.
            // We need to resize the array
            if (dataLength == data.Length)
            {
                return(data);
            }

            byte[] realData = new byte[dataLength];
            Array.Copy(data, realData, dataLength);
            return(realData);
        }
示例#4
0
        /// <summary>
        /// Encodes the sack into binary form
        /// </summary>
        /// <param name="writer">BinaryWriter instance</param>
        public void Encode(BinaryWriter writer)
        {
            if (this.sackType == SackType.Stash)
            {
                // Item stacks are stored as single items in the stash
                TQData.WriteCString(writer, "numItems");
                writer.Write(this.Count);
            }
            else if (this.sackType == SackType.Equipment)
            {
                // Nothing special except to skip all of the other header crap
                // since the number of items is always fixed.
            }
            else
            {
                TQData.WriteCString(writer, "begin_block");
                writer.Write(this.beginBlockCrap);

                TQData.WriteCString(writer, "tempBool");
                writer.Write(this.tempBool);

                TQData.WriteCString(writer, "size");
                writer.Write(this.CountTQItems());
            }

            int slotNumber = -1;

            foreach (Item item in this)
            {
                ++slotNumber;
                item.ContainerType = this.sackType;
                int itemAttached = 0;
                int alternate    = 0;

                // Additional logic to encode the weapon slots in the equipment section
                if (this.sackType == SackType.Equipment && (slotNumber == 7 || slotNumber == 9))
                {
                    TQData.WriteCString(writer, "begin_block");
                    writer.Write(this.beginBlockCrap);

                    TQData.WriteCString(writer, "alternate");
                    if (slotNumber == 9)
                    {
                        // Only set the flag for the second set of weapons
                        alternate = 1;
                    }
                    else
                    {
                        // Otherwise set the flag to false.
                        alternate = 0;
                    }

                    writer.Write(alternate);
                }

                item.Encode(writer);

                if (this.sackType == SackType.Equipment)
                {
                    TQData.WriteCString(writer, "itemAttached");
                    if (!string.IsNullOrEmpty(item.BaseItemId) && slotNumber != 9 && slotNumber != 10)
                    {
                        // If there is an item in this slot, set the flag.
                        // Unless it's in the secondary weapon slot.
                        itemAttached = 1;
                    }
                    else
                    {
                        // This is only a dummy item so we do not set the flag.
                        itemAttached = 0;
                    }

                    writer.Write(itemAttached);
                }

                // Additional logic to encode the weapon slots in the equipment section
                if (this.sackType == SackType.Equipment && (slotNumber == 8 || slotNumber == 10))
                {
                    TQData.WriteCString(writer, "end_block");
                    writer.Write(this.endBlockCrap);
                }
            }

            TQData.WriteCString(writer, "end_block");
            writer.Write(this.endBlockCrap);
        }