Beispiel #1
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }

            var buffer    = new byte[1];
            int totalRead = 0;

            while ((totalRead += readStream.Read(buffer, totalRead, 1)) < 1)
            {
            }
            Value = buffer[0];
        }
Beispiel #2
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }

            var buffer  = new byte[2];
            int numRead = readStream.Read(buffer, 0, buffer.Length);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(buffer);
            }
            if (numRead == 2)
            {
                Value = BitConverter.ToInt16(buffer, 0);
            }
        }
Beispiel #3
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }


            var buffer    = new byte[4];
            int totalRead = 0;

            while ((totalRead += readStream.Read(buffer, totalRead, 4)) < 4)
            {
            }
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(buffer);
            }
            Value = BitConverter.ToInt32(buffer, 0);
        }
Beispiel #4
0
        internal override void ReadTag(Stream readStream, bool readName)
        {
            if (readName)
            {
                var name = new NbtString();
                name.ReadTag(readStream, false);

                Name = name.Value;
            }

            // Get the length of the string
            var length = new NbtShort();

            length.ReadTag(readStream, false);

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

            while ((totalRead += readStream.Read(buffer, totalRead, length.Value)) < length.Value)
            {
            }
            Value = Encoding.UTF8.GetString(buffer);
        }
Beispiel #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;
            }

            Tags.Clear();
            bool foundEnd = false;

            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);
                    Tags.Add(nextByte);
                    break;

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

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

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

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

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

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

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

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

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

                default:
                    Console.WriteLine(string.Format("Unsupported Tag Found: {0}", nextTag));
                    break;
                }
            }
        }
Beispiel #6
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;
            ListType = Type;

            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;
                }
            }
        }