Пример #1
0
        public static IEnumerable <WZProperty> PropertyList(WZReader reader, WZProperty parent)
        {
            if (reader.BaseStream.Position + 4 >= reader.BaseStream.Length)
            {
                return(new WZProperty[0]);
            }
            return(Enumerable.Range(0, reader.ReadWZInt()).Select(i =>
            {
                uint position = (uint)reader.BaseStream.Position;
                if (position >= reader.BaseStream.Length)
                {
                    return null;
                }
                string name = reader.ReadWZStringBlock(parent.Encrypted | parent.Container.Encrypted);
                byte type = reader.ReadByte();
                switch (type)
                {
                case 0:
                    return new WZProperty(name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Null, parent, 0, 0, position);

                case 0x10:
                    return new WZPropertyVal <sbyte>(reader.ReadSByte(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.UInt16, parent, 1, 0, position);

                case 0x11:
                    return new WZPropertyVal <byte>(reader.ReadByte(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.UInt16, parent, 1, 0, position);

                case 0x0B:
                case 2:
                case 0x12:
                    return new WZPropertyVal <UInt16>(reader.ReadUInt16(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.UInt16, parent, 2, 0, position);

                case 3:
                    return new WZPropertyVal <Int32>(reader.ReadWZInt(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Int32, parent, 4, 0, position);

                case 19:
                    return new WZPropertyVal <Rgba32>(new Rgba32((uint)reader.ReadWZInt()), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Int32, parent, 4, 0, position);

                case 4:
                    return new WZPropertyVal <Single>(reader.ReadWZSingle(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Single, parent, 4, 0, position);

                case 5:
                    return new WZPropertyVal <Double>(reader.ReadDouble(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Double, parent, 8, 0, position);

                case 8:
                    return new WZPropertyVal <string>(reader.ReadWZStringBlock(parent.Encrypted | parent.Container.Encrypted), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.String, parent, 0, 0, position);

                case 9:
                    uint blockLen = reader.ReadUInt32();
                    WZProperty result = reader.PeekFor(() => ParseExtendedProperty(reader, parent, name));
                    reader.BaseStream.Seek(blockLen, SeekOrigin.Current);
                    return result;

                case 20:
                    return new WZPropertyVal <long>(reader.ReadWZLong(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Int64, parent, 8, 0, position);

                case 21:
                    return new WZPropertyVal <ulong>((ulong)reader.ReadWZLong(), name, Path.Combine(parent.Path, name), parent.FileContainer, PropertyType.Int64, parent, 8, 0, position);

                default:
                    throw new Exception("Unknown property type at ParsePropertyList");
                }
            }));
        }