Пример #1
0
        internal override void WriteData(Stream writeStream)
        {
            // Figure out the type of this list, then check
            // to make sure all elements are that type.
            if (Tags.Count > 0)
            {
                NbtTagType listType = Tags[0].GetTagType();
                foreach (NbtTag tag in Tags)
                {
                    if (tag.GetTagType() != listType)
                    {
                        throw new Exception("All list items must be the same tag type.");
                    }
                }
                Type = listType;
            }

            var tagType = new NbtByte("", (byte)Type);

            tagType.WriteData(writeStream);

            var length = new NbtInt("", Tags.Count);

            length.WriteData(writeStream);

            foreach (NbtTag tag in Tags)
            {
                tag.WriteData(writeStream);
            }
        }
Пример #2
0
        internal override void WriteData(Stream writeStream)
        {
            var length = new NbtInt("", Value.Length);

            length.WriteData(writeStream);

            writeStream.Write(Value, 0, Value.Length);
        }
Пример #3
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            // First read the name of this tag
            Name = "";
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }

            var length = new NbtInt();

            length.ReadTag(readStream, false);

            var buffer    = new byte[length.Value];
            int totalRead = 0;

            while ((totalRead += readStream.Read(buffer, totalRead, length.Value - totalRead)) < length.Value)
            {
            }
            Value = buffer;
        }
Пример #4
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            // First read the name of this tag
            Name = "";
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }

            var tagId = new NbtByte();

            tagId.ReadTag(readStream, false);
            Type = (NbtTagType)tagId.Value;

            var length = new NbtInt();

            length.ReadTag(readStream, false);

            Tags.Clear();
            for (int idx = 0; idx < length.Value; idx++)
            {
                switch ((NbtTagType)tagId.Value)
                {
                case NbtTagType.TAG_Byte:
                    var nextByte = new NbtByte();
                    nextByte.ReadTag(readStream, false);
                    Tags.Add(nextByte);
                    break;

                case NbtTagType.TAG_Short:
                    var nextShort = new NbtShort();
                    nextShort.ReadTag(readStream, false);
                    Tags.Add(nextShort);
                    break;

                case NbtTagType.TAG_Int:
                    var nextInt = new NbtInt();
                    nextInt.ReadTag(readStream, false);
                    Tags.Add(nextInt);
                    break;

                case NbtTagType.TAG_Long:
                    var nextLong = new NbtLong();
                    nextLong.ReadTag(readStream, false);
                    Tags.Add(nextLong);
                    break;

                case NbtTagType.TAG_Float:
                    var nextFloat = new NbtFloat();
                    nextFloat.ReadTag(readStream, false);
                    Tags.Add(nextFloat);
                    break;

                case NbtTagType.TAG_Double:
                    var nextDouble = new NbtDouble();
                    nextDouble.ReadTag(readStream, false);
                    Tags.Add(nextDouble);
                    break;

                case NbtTagType.TAG_Byte_Array:
                    var nextByteArray = new NbtByteArray();
                    nextByteArray.ReadTag(readStream, false);
                    Tags.Add(nextByteArray);
                    break;

                case NbtTagType.TAG_String:
                    var nextString = new NbtString();
                    nextString.ReadTag(readStream, false);
                    Tags.Add(nextString);
                    break;

                case NbtTagType.TAG_List:
                    var nextList = new NbtList();
                    nextList.ReadTag(readStream, false);
                    Tags.Add(nextList);
                    break;

                case NbtTagType.TAG_Compound:
                    var nextCompound = new NbtCompound();
                    nextCompound.ReadTag(readStream, false);
                    Tags.Add(nextCompound);
                    break;
                }
            }
        }
Пример #5
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            // First read the name of this tag
            Name = "";
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }

            mTags.Clear();
            bool          foundEnd = false;
            List <NbtTag> buffer   = new List <NbtTag>();

            while (!foundEnd)
            {
                int nextTag = readStream.ReadByte();
                switch ((NbtTagType)nextTag)
                {
                case NbtTagType.TAG_End:
                    foundEnd = true;
                    break;

                case NbtTagType.TAG_Byte:
                    var nextByte = new NbtByte();
                    nextByte.ReadTag(readStream);
                    Add(nextByte.Name, nextByte);
                    break;

                case NbtTagType.TAG_Short:
                    var nextShort = new NbtShort();
                    nextShort.ReadTag(readStream);
                    Add(nextShort.Name, nextShort);
                    break;

                case NbtTagType.TAG_Int:
                    var nextInt = new NbtInt();
                    nextInt.ReadTag(readStream);
                    Add(nextInt.Name, nextInt);
                    break;

                case NbtTagType.TAG_Long:
                    var nextLong = new NbtLong();
                    nextLong.ReadTag(readStream);
                    Add(nextLong.Name, nextLong);
                    break;

                case NbtTagType.TAG_Float:
                    var nextFloat = new NbtFloat();
                    nextFloat.ReadTag(readStream);
                    Add(nextFloat.Name, nextFloat);
                    break;

                case NbtTagType.TAG_Double:
                    var nextDouble = new NbtDouble();
                    nextDouble.ReadTag(readStream);
                    Add(nextDouble.Name, nextDouble);
                    break;

                case NbtTagType.TAG_Byte_Array:
                    var nextByteArray = new NbtByteArray();
                    nextByteArray.ReadTag(readStream);
                    Add(nextByteArray.Name, nextByteArray);
                    break;

                case NbtTagType.TAG_String:
                    var nextString = new NbtString();
                    nextString.ReadTag(readStream);
                    Add(nextString.Name, nextString);
                    break;

                case NbtTagType.TAG_List:
                    var nextList = new NbtList();
                    nextList.ReadTag(readStream);
                    Add(nextList.Name, nextList);
                    break;

                case NbtTagType.TAG_Compound:
                    var nextCompound = new NbtCompound();
                    nextCompound.ReadTag(readStream);
                    Add(nextCompound.Name, nextCompound);
                    break;

                default:
                    Console.WriteLine(string.Format("Unsupported Tag Found: {0}", nextTag));
                    break;
                }
            }
        }