Exemplo n.º 1
0
        internal static bool ReadTag(this NbtTag tag, NbtBinaryReader readStream)
        {
            while (true)
            {
                NbtTag nbtTag;
                do
                {
                    NbtTagType nbtTagType = readStream.ReadTagType();
                    switch (nbtTagType)
                    {
                    case NbtTagType.End:
                        return(true);

                    case NbtTagType.Byte:
                        nbtTag = (NbtTag) new NbtByte();
                        break;

                    case NbtTagType.Short:
                        nbtTag = (NbtTag) new NbtShort();
                        break;

                    case NbtTagType.Int:
                        nbtTag = (NbtTag) new NbtInt();
                        break;

                    case NbtTagType.Long:
                        nbtTag = (NbtTag) new NbtLong();
                        break;

                    case NbtTagType.Float:
                        nbtTag = (NbtTag) new NbtFloat();
                        break;

                    case NbtTagType.Double:
                        nbtTag = (NbtTag) new NbtDouble();
                        break;

                    case NbtTagType.ByteArray:
                        nbtTag = (NbtTag) new NbtByteArray();
                        break;

                    case NbtTagType.String:
                        nbtTag = (NbtTag) new NbtString();
                        break;

                    case NbtTagType.List:
                        nbtTag = (NbtTag) new NbtList();
                        break;

                    case NbtTagType.Compound:
                        nbtTag = (NbtTag) new NbtCompound();
                        break;

                    case NbtTagType.IntArray:
                        nbtTag = (NbtTag) new NbtIntArray();
                        break;

                    case NbtTagType.LongArray:
                        nbtTag = (NbtTag) new NbtLongArray();
                        break;

                    case NbtTagType.Unknown:
                        return(true);

                        break;

                    default:
                        throw new FormatException("Unsupported tag type found in NBT_Compound: " + (object)nbtTagType);
                    }
                    //nbtTag.Parent = (NbtTag) this;
                    nbtTag.Name = readStream.ReadString();
                }while (!nbtTag.ReadTag(readStream));

                switch (tag.TagType)
                {
                case NbtTagType.Compound:
                    NbtCompound compound = (NbtCompound)tag;
                    compound.Add(nbtTag);
                    break;

                case NbtTagType.List:
                    NbtList list = (NbtList)tag;
                    list.Add(nbtTag);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        internal override void SkipTag(NbtBinaryReader readStream)
        {
            while (true)
            {
                NbtTagType nextTag = readStream.ReadTagType();
                NbtTag     newTag;
                switch (nextTag)
                {
                case NbtTagType.End:
                    return;

                case NbtTagType.Byte:
                    newTag = new NbtByte();
                    break;

                case NbtTagType.Short:
                    newTag = new NbtShort();
                    break;

                case NbtTagType.Int:
                    newTag = new NbtInt();
                    break;

                case NbtTagType.Long:
                    newTag = new NbtLong();
                    break;

                case NbtTagType.Float:
                    newTag = new NbtFloat();
                    break;

                case NbtTagType.Double:
                    newTag = new NbtDouble();
                    break;

                case NbtTagType.ByteArray:
                    newTag = new NbtByteArray();
                    break;

                case NbtTagType.String:
                    newTag = new NbtString();
                    break;

                case NbtTagType.List:
                    newTag = new NbtList();
                    break;

                case NbtTagType.Compound:
                    newTag = new NbtCompound();
                    break;

                case NbtTagType.IntArray:
                    newTag = new NbtIntArray();
                    break;

                default:
                    throw new NbtFormatException("Unsupported tag type found in NBT_Compound: " + nextTag);
                }
                readStream.SkipString();
                newTag.SkipTag(readStream);
            }
        }
Exemplo n.º 3
0
        internal override void SkipTag(NbtBinaryReader readStream)
        {
            // read list type, and make sure it's defined
            ListType = readStream.ReadTagType();

            int length = readStream.ReadInt32();

            if (length < 0)
            {
                throw new NbtFormatException("Negative list size given.");
            }

            switch (ListType)
            {
            case NbtTagType.Byte:
                readStream.Skip(length);
                break;

            case NbtTagType.Short:
                readStream.Skip(length * sizeof(short));
                break;

            case NbtTagType.Int:
                readStream.Skip(length * sizeof(int));
                break;

            case NbtTagType.Long:
                readStream.Skip(length * sizeof(long));
                break;

            case NbtTagType.Float:
                readStream.Skip(length * sizeof(float));
                break;

            case NbtTagType.Double:
                readStream.Skip(length * sizeof(double));
                break;

            default:
                for (int i = 0; i < length; i++)
                {
                    switch (listType)
                    {
                    case NbtTagType.ByteArray:
                        new NbtByteArray().SkipTag(readStream);
                        break;

                    case NbtTagType.String:
                        readStream.SkipString();
                        break;

                    case NbtTagType.List:
                        new NbtList().SkipTag(readStream);
                        break;

                    case NbtTagType.Compound:
                        new NbtCompound().SkipTag(readStream);
                        break;

                    case NbtTagType.IntArray:
                        new NbtIntArray().SkipTag(readStream);
                        break;
                    }
                }
                break;
            }
        }
Exemplo n.º 4
0
        internal override bool ReadTag(NbtBinaryReader readStream)
        {
            if (Parent != null && readStream.Selector != null && !readStream.Selector(this))
            {
                SkipTag(readStream);
                return(false);
            }

            while (true)
            {
                NbtTagType nextTag = readStream.ReadTagType();
                NbtTag     newTag;
                switch (nextTag)
                {
                case NbtTagType.End:
                    return(true);

                case NbtTagType.Byte:
                    newTag = new NbtByte();
                    break;

                case NbtTagType.Short:
                    newTag = new NbtShort();
                    break;

                case NbtTagType.Int:
                    newTag = new NbtInt();
                    break;

                case NbtTagType.Long:
                    newTag = new NbtLong();
                    break;

                case NbtTagType.Float:
                    newTag = new NbtFloat();
                    break;

                case NbtTagType.Double:
                    newTag = new NbtDouble();
                    break;

                case NbtTagType.ByteArray:
                    newTag = new NbtByteArray();
                    break;

                case NbtTagType.String:
                    newTag = new NbtString();
                    break;

                case NbtTagType.List:
                    newTag = new NbtList();
                    break;

                case NbtTagType.Compound:
                    newTag = new NbtCompound();
                    break;

                case NbtTagType.IntArray:
                    newTag = new NbtIntArray();
                    break;

                default:
                    throw new NbtFormatException("Unsupported tag type found in NBT_Compound: " + nextTag);
                }
                newTag.Parent = this;
                newTag.Name   = readStream.ReadString();
                if (newTag.ReadTag(readStream))
                {
                    // ReSharper disable AssignNullToNotNullAttribute
                    // newTag.Name is never null
                    tags.Add(newTag.Name, newTag);
                    // ReSharper restore AssignNullToNotNullAttribute
                }
            }
        }
Exemplo n.º 5
0
        internal override bool ReadTag(NbtBinaryReader readStream)
        {
            if (readStream.Selector != null && !readStream.Selector(this))
            {
                SkipTag(readStream);
                return(false);
            }

            ListType = readStream.ReadTagType();

            int length = readStream.ReadInt32();

            if (length < 0)
            {
                throw new NbtFormatException("Negative list size given.");
            }

            for (int i = 0; i < length; i++)
            {
                NbtTag newTag;
                switch (ListType)
                {
                case NbtTagType.Byte:
                    newTag = new NbtByte();
                    break;

                case NbtTagType.Short:
                    newTag = new NbtShort();
                    break;

                case NbtTagType.Int:
                    newTag = new NbtInt();
                    break;

                case NbtTagType.Long:
                    newTag = new NbtLong();
                    break;

                case NbtTagType.Float:
                    newTag = new NbtFloat();
                    break;

                case NbtTagType.Double:
                    newTag = new NbtDouble();
                    break;

                case NbtTagType.ByteArray:
                    newTag = new NbtByteArray();
                    break;

                case NbtTagType.String:
                    newTag = new NbtString();
                    break;

                case NbtTagType.List:
                    newTag = new NbtList();
                    break;

                case NbtTagType.Compound:
                    newTag = new NbtCompound();
                    break;

                case NbtTagType.IntArray:
                    newTag = new NbtIntArray();
                    break;

                default:
                    // should never happen, since ListType is checked beforehand
                    throw new NbtFormatException("Unsupported tag type found in a list: " + ListType);
                }
                newTag.Parent = this;
                if (newTag.ReadTag(readStream))
                {
                    tags.Add(newTag);
                }
            }
            return(true);
        }