예제 #1
0
        /// <summary>
        /// Reads item from binary reader and returns it.
        /// </summary>
        /// <param name="br"></param>
        /// <returns></returns>
        public static SetItem ReadFrom(BinaryReader br)
        {
            var result = new SetItem();

            result.Unk2 = br.ReadInt32();
            var dataSize = br.ReadInt32();

            result.FileName  = br.ReadWString();
            result.StateName = br.ReadWString();

            var dataSignature = br.ReadString(4);

            if (dataSignature != "pa!" && dataSignature != "pf!")
            {
                throw new InvalidDataException("Expected 'pa!' or 'pv!' signature.");
            }

            br.BaseStream.Seek(-4, SeekOrigin.Current);
            result.RawData = br.ReadBytes(dataSize);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Reads SET from stream and returns it.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static SetFile ReadFrom(Stream stream)
        {
            var result = new SetFile();
            var br     = new BinaryReader(stream);

            result.Header = SetHeader.ReadFrom(br);

            var itemCount = br.ReadInt32();

            for (var i = 0; i < itemCount; ++i)
            {
                var item = SetItem.ReadFrom(br);
                result.Items.Add(item);
            }

            if (stream.Position != stream.Length)
            {
                throw new InvalidDataException("Leftover data in SET.");
            }

            return(result);
        }