private void Parse(Stream s)
            {
                var br = new BinaryStreamWrapper(s);

                br.ByteOrder = ByteOrder.BigEndian;
                mId          = (SoundProperty)br.ReadUInt32();

                mTypeCode = (DataType)br.ReadUInt16();
                mRepCode  = br.ReadUInt16();
                var data = new List <TypedData>();

                if (!HasTypeData)
                {
                    data.Add(ReadTypedData(0, handler, mTypeCode, s));
                }
                else
                {
                    int count    = br.ReadInt32();
                    int itemSize = br.ReadInt32();
                    if (itemSize != ItemSize)
                    {
                        throw new InvalidDataException(String.Format("Bad item size: Expected {0}, but got {1}", ItemSize, itemSize));
                    }
                    for (int i = 0; i < count; i++)
                    {
                        data.Add(ReadTypedData(0, handler, mTypeCode, s));
                    }
                }
                mItems = new DataList(handler, data, this);
            }
        public void Parse(Stream inputStream)
        {
            var s = new BinaryStreamWrapper(inputStream, ByteOrder.BigEndian);

            mVersion              = s.ReadUInt16();
            mEffectSections       = new EffectSectionList(OnResourceChanged, inputStream);
            mResourceSections     = new ResourceSectionList(OnResourceChanged, inputStream);
            mVisualEffectSections = new VisualEffectSection(0, OnResourceChanged, s.ReadUInt16(), inputStream);
            mVisualEffectIds      = new VisualEffectIdList(OnResourceChanged, inputStream);
            mVisualEffectNames    = new VisualEffectNameList(OnResourceChanged, inputStream);
        }
Exemple #3
0
        protected override void Parse(Stream stream)
        {
            var    s         = new BinaryStreamWrapper(stream, ByteOrder.BigEndian);
            ushort blockType = s.ReadUInt16();

            while (blockType != 0xFFFF)
            {
                ushort   blockVersion = s.ReadUInt16();
                Type     sectionType  = GetSectionType(blockType);
                TSection blocklist    = CreateElement(blockType, blockVersion, stream);
                base.Add(blocklist);
                blockType = s.ReadUInt16();
            }
        }
Exemple #4
0
        protected void Parse(Stream s)
        {
            BinaryStreamWrapper wrapper = new BinaryStreamWrapper(s, ByteOrder.BigEndian);

            this.mVersion = wrapper.ReadUInt16();
            // Initialize Effect Sections
            this.mEffectSectionList = new EffectResource.EffectSectionList(this.OnResourceChanged, s);
            this.InitEffectSectionIndices();
            // Initialize Resource Sections
            this.mResourceSectionList = new EffectResource.ResourceSectionList(this.OnResourceChanged, s);
            this.InitResourceSectionIndices();
            // Initialize Visual Effect Builders
            this.mVisualEffectSection = new EffectResource.VisualEffectSection(0, this.OnResourceChanged, wrapper.ReadUInt16());
            //this.mVisualEffectVersion = wrapper.ReadUInt16();
            //this.mVisualEffectBuilders = new SectionDataList<VisualEffectBuilder>(this.OnResourceChanged, null, s);
            // Initialize Reserved
            this.mReserved = wrapper.ReadBytes(4);
            // Initialize Handle List
            this.mVisualEffectHandleList = new VisualEffectHandleList(this.OnResourceChanged, s);
            // Initialize Visual Effect Builder Properties
            this.InitEffectNames();
            this.InitEffectBuilders();
        }
Exemple #5
0
        public unsafe void TestMethod()
        {
            MemoryStream        stream = new MemoryStream();
            BinaryStreamWrapper bs     = new BinaryStreamWrapper(stream, false);
            Random rand = new Random();
            int    seed = rand.Next();

            rand = new Random(seed);
            byte[] data  = new byte[16];
            byte[] data2 = new byte[16];

            fixed(byte *lp = data)
            {
                for (int x = 0; x < 10000; x++)
                {
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*lp);
                    }
                    int skip = rand.Next(40) + 1;
                    bs.Position += skip;
                    bs.Position -= rand.Next(skip);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(sbyte *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(short *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(int *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(long *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(ushort *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(uint *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(ulong *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(NextDecimal(data, rand));
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(*(Guid *)lp);
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(NextDate(data, rand));
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(NextSingle(data, rand));
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(NextDouble(data, rand));
                    }
                    rand.NextBytes(data);
                    bool value = *lp != 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write(value);
                    }

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(uint *)lp);
                    }
                    data[3] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(uint *)lp);
                    }
                    data[2] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(uint *)lp);
                    }
                    data[1] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(uint *)lp);
                    }

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[7] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[6] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[5] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[4] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[3] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[2] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }
                    data[1] = 0;
                    while (rand.Next(4) < 2)
                    {
                        bs.Write7Bit(*(ulong *)lp);
                    }

                    rand.NextBytes(data);
                    bs.Write(data, 0, data.Length);

                    while (rand.Next(4) < 2)
                    {
                        if (bs.Position > 100)
                        {
                            bs.Position -= 100;
                            int insertCount = rand.Next(16) + 1;
                            bs.InsertBytes(insertCount, 100);
                            bs.Write(data, 0, insertCount);
                            bs.Position -= insertCount;
                            bs.ReadAll(data2, 0, insertCount);
                            bs.Position -= insertCount;
                            bs.RemoveBytes(insertCount, 100);
                            bs.Position += 100;

                            for (int y = 0; y < insertCount; y++)
                            {
                                if (data[y] != data2[y])
                                {
                                    throw new Exception();
                                }
                            }
                        }
                    }
                }
                rand = new Random(seed);

                bs.Position = 0;

                for (int x = 0; x < 10000; x++)
                {
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadUInt8() != *lp)
                        {
                            throw new Exception();
                        }
                    }
                    int skip = rand.Next(40) + 1;
                    bs.Position += skip;
                    bs.Position -= rand.Next(skip);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadInt8() != *(sbyte *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadInt16() != *(short *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadInt32() != *(int *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadInt64() != *(long *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadUInt16() != *(ushort *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadUInt32() != *(uint *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadDecimal() != NextDecimal(data, rand))
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadGuid() != *(Guid *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadDateTime() != NextDate(data, rand))
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadSingle() != NextSingle(data, rand))
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadDouble() != NextDouble(data, rand))
                        {
                            throw new Exception();
                        }
                    }
                    rand.NextBytes(data);
                    bool b2 = *lp != 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.ReadBoolean() != b2)
                        {
                            throw new Exception();
                        }
                    }

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt32() != *(uint *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[3] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt32() != *(uint *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[2] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt32() != *(uint *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[1] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt32() != *(uint *)lp)
                        {
                            throw new Exception();
                        }
                    }

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[7] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[6] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[5] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[4] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[3] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[2] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }
                    data[1] = 0;
                    while (rand.Next(4) < 2)
                    {
                        if (bs.Read7BitUInt64() != *(ulong *)lp)
                        {
                            throw new Exception();
                        }
                    }

                    rand.NextBytes(data);
                    bs.ReadAll(data2, 0, 16);
                    if (!data2.SequenceEqual(data))
                    {
                        throw new Exception();
                    }

                    while (rand.Next(4) < 2)
                    {
                        if (bs.Position > 100)
                        {
                            int insertCount = rand.Next(16);
                        }
                    }
                }
            }
        }
        public unsafe void TestMethod()
        {
            MemoryStream stream = new MemoryStream();
            BinaryStreamWrapper bs = new BinaryStreamWrapper(stream, false);
            Random rand = new Random();
            int seed = rand.Next();
            rand = new Random(seed);
            byte[] data = new byte[16];
            byte[] data2 = new byte[16];

            fixed (byte* lp = data)
            {
                for (int x = 0; x < 10000; x++)
                {
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(byte*)lp);
                    int skip = rand.Next(40) + 1;
                    bs.Position += skip;
                    bs.Position -= rand.Next(skip);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(sbyte*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(short*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(int*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(long*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(ushort*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(uint*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(ulong*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(NextDecimal(data, rand));
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(*(Guid*)lp);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(NextDate(data, rand));
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(NextSingle(data, rand));
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write(NextDouble(data, rand));
                    rand.NextBytes(data);
                    bool value = (*lp != 0);
                    while (rand.Next(4) < 2) bs.Write(value);

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write7Bit(*(uint*)lp);
                    data[3] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(uint*)lp);
                    data[2] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(uint*)lp);
                    data[1] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(uint*)lp);

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[7] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[6] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[5] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[4] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[3] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[2] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);
                    data[1] = 0;
                    while (rand.Next(4) < 2) bs.Write7Bit(*(ulong*)lp);

                    rand.NextBytes(data);
                    bs.Write(data, 0, data.Length);

                    while (rand.Next(4) < 2)
                    {
                        if (bs.Position > 100)
                        {
                            bs.Position -= 100;
                            int insertCount = rand.Next(16) + 1;
                            bs.InsertBytes(insertCount, 100);
                            bs.Write(data, 0, insertCount);
                            bs.Position -= insertCount;
                            bs.ReadAll(data2, 0, insertCount);
                            bs.Position -= insertCount;
                            bs.RemoveBytes(insertCount, 100);
                            bs.Position += 100;

                            for (int y = 0; y < insertCount; y++)
                            {
                                if (data[y] != data2[y])
                                    throw new Exception();
                            }
                        }
                    }
                }
                rand = new Random(seed);

                bs.Position = 0;

                for (int x = 0; x < 10000; x++)
                {
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadUInt8() != (*(byte*)lp)) throw new Exception();
                    int skip = rand.Next(40) + 1;
                    bs.Position += skip;
                    bs.Position -= rand.Next(skip);
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadInt8() != (*(sbyte*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadInt16() != (*(short*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadInt32() != (*(int*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadInt64() != (*(long*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadUInt16() != (*(ushort*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadUInt32() != (*(uint*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadUInt64() != (*(ulong*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadDecimal() != NextDecimal(data, rand)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadGuid() != (*(Guid*)lp)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadDateTime() != NextDate(data, rand)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadSingle() != NextSingle(data, rand)) throw new Exception();
                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.ReadDouble() != NextDouble(data, rand)) throw new Exception();
                    rand.NextBytes(data);
                    bool b2 = (*lp != 0);
                    while (rand.Next(4) < 2) if (bs.ReadBoolean() != b2) throw new Exception();

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt32() != (*(uint*)lp)) throw new Exception();
                    data[3] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt32() != (*(uint*)lp)) throw new Exception();
                    data[2] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt32() != (*(uint*)lp)) throw new Exception();
                    data[1] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt32() != (*(uint*)lp)) throw new Exception();

                    rand.NextBytes(data);
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[7] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[6] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[5] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[4] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[3] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[2] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();
                    data[1] = 0;
                    while (rand.Next(4) < 2) if (bs.Read7BitUInt64() != (*(ulong*)lp)) throw new Exception();

                    rand.NextBytes(data);
                    bs.ReadAll(data2, 0, 16);
                    if (!data2.SequenceEqual<byte>(data)) throw new Exception();

                    while (rand.Next(4) < 2)
                    {
                        if (bs.Position > 100)
                        {
                            int insertCount = rand.Next(16);
                        }
                    }
                }
            }
        }