Ejemplo n.º 1
0
        static string GetRootNameInternal(Stream stream, bool bigEndian)
        {
            Debug.Assert(stream != null);
            int firstByte = stream.ReadByte();

            if (firstByte < 0)
            {
                throw new EndOfStreamException();
            }
            else if (firstByte != (int)NbtTagType.Compound)
            {
                throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound");
            }
            var reader = new NbtBinaryReader(stream, bigEndian);

            return(reader.ReadString());
        }
Ejemplo n.º 2
0
        /// <summary> Initializes a new instance of the NbtReader class. </summary>
        /// <param name="stream"> Stream to read from. </param>
        /// <param name="bigEndian"> Whether NBT data is in Big-Endian encoding. </param>
        /// <exception cref="ArgumentNullException"> <paramref name="stream"/> is <c>null</c>. </exception>
        /// <exception cref="ArgumentException"> <paramref name="stream"/> is not readable. </exception>
        public NbtReader(Stream stream, bool bigEndian)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            SkipEndTags    = true;
            CacheTagValues = false;
            ParentTagType  = NbtTagType.Unknown;
            TagType        = NbtTagType.Unknown;

            canSeekStream = stream.CanSeek;
            if (canSeekStream)
            {
                streamStartOffset = stream.Position;
            }

            reader = new NbtBinaryReader(stream, bigEndian);
        }
Ejemplo n.º 3
0
        void LoadFromStreamInternal(Stream stream, TagSelector tagSelector)
        {
            // Make sure the first byte in this file is the tag for a TAG_Compound
            int firstByte = stream.ReadByte();

            if (firstByte < 0)
            {
                throw new EndOfStreamException();
            }
            if (firstByte != (int)NbtTagType.Compound)
            {
                throw new NbtFormatException("Given NBT stream does not start with a TAG_Compound");
            }
            var reader = new NbtBinaryReader(stream, BigEndian)
            {
                Selector = tagSelector
            };

            var rootCompound = new NbtCompound(reader.ReadString());

            rootCompound.ReadTag(reader);
            RootTag = rootCompound;
        }