public static ArrayProperty Parse(string propertyName, int index, BinaryReader reader, int size, out int overhead)
        {
            var result = new ArrayProperty(propertyName, index)
            {
                Type = reader.ReadLengthPrefixedString()
            };

            overhead = result.Type.Length + 6;

            byte unk2 = reader.ReadByte();

            Trace.Assert(unk2 == 0);

            switch (result.Type)
            {
            case StructProperty.TypeName:
            {
                // TODO
                var prop = new StructProperty($"Element i")
                {
                    Data = reader.ReadBytes(size)
                };

                result.Elements.Add(prop);
            }
            break;

            case ObjectProperty.TypeName:
            {
                int count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    string obj1 = reader.ReadLengthPrefixedString();
                    string obj2 = reader.ReadLengthPrefixedString();
                    result.Elements.Add(new ObjectProperty($"Element {i}", obj1, obj2));
                }
            }
            break;

            case IntProperty.TypeName:
            {
                int count = reader.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    int value = reader.ReadInt32();
                    result.Elements.Add(new IntProperty($"Element {i}")
                        {
                            Value = value
                        });
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }
Exemplo n.º 2
0
        public static ArrayProperty Parse(string propertyName, int index, BinaryReader reader, int size, out int overhead)
        {
            var result = new ArrayProperty(propertyName, index)
            {
                Type = reader.ReadLengthPrefixedString()
            };

            overhead = result.Type.Length + 6;

            byte unk = reader.ReadByte();

            Trace.Assert(unk == 0);

            switch (result.Type)
            {
            case StructProperty.TypeName:
            {
                result.Elements.AddRange(StructProperty.ParseArray(reader));
                //for (var i = 0; i < count; i++)
                //{
                //    var prop = SerializedProperty.Parse(reader, out int _, out int _);
                //    result.Elements.Add(prop);
                //}
            }
            break;

            case ObjectProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var obj1 = reader.ReadLengthPrefixedString();
                    var obj2 = reader.ReadLengthPrefixedString();
                    result.Elements.Add(new ObjectProperty($"Element {i}", obj1, obj2));
                }
            }
            break;

            case IntProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var value = reader.ReadInt32();
                    result.Elements.Add(new IntProperty($"Element {i}")
                        {
                            Value = value
                        });
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }
Exemplo n.º 3
0
        public static ArrayProperty Parse(string propertyName, int index, BinaryReader reader, int size, out int overhead)
        {
            var result = new ArrayProperty(propertyName, index)
            {
                Type = reader.ReadLengthPrefixedString()
            };

            overhead = result.Type.Length + 6;

            byte unk = reader.ReadByte();

            Trace.Assert(unk == 0);

            switch (result.Type)
            {
            case StructProperty.TypeName:
            {
                result.Elements.AddRange(StructProperty.ParseArray(reader));
            }
            break;

            case ObjectProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var obj1 = reader.ReadLengthPrefixedString();
                    var obj2 = reader.ReadLengthPrefixedString();
                    result.Elements.Add(new ObjectProperty($"Element {i}", obj1, obj2));
                }
            }
            break;

            case IntProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var value = reader.ReadInt32();
                    result.Elements.Add(new IntProperty($"Element {i}")
                        {
                            Value = value
                        });
                }
            }
            break;

            case ByteProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var value = reader.ReadByte();
                    result.Elements.Add(new ByteProperty($"Element {i}")
                        {
                            Type = "None", Value = value.ToString()
                        });
                }
            }
            break;

            case EnumProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var str = reader.ReadLengthPrefixedString();
                    result.Elements.Add(new EnumProperty($"Element {i}")
                        {
                            Type = str.Split(':')[0], Name = str
                        });
                }
            }
            break;

            case StrProperty.TypeName:
            {
                var count = reader.ReadInt32();
                for (var i = 0; i < count; i++)
                {
                    var str = reader.ReadLengthPrefixedString();
                    result.Elements.Add(new StrProperty($"Element {i}")
                        {
                            Value = str
                        });
                }
            }
            break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }
Exemplo n.º 4
0
        public static SerializedProperty Parse(BinaryReader reader)
        {
            SerializedProperty result;

            var propertyName = reader.ReadLengthPrefixedString();

            if (propertyName == "None")
            {
                return(null);
            }

            Trace.Assert(!String.IsNullOrEmpty(propertyName));

            var fieldType = reader.ReadLengthPrefixedString();
            var size      = reader.ReadInt32();
            var index     = reader.ReadInt32();

            int overhead;
            var before = reader.BaseStream.Position;

            switch (fieldType)
            {
            case ArrayProperty.TypeName:
                result = ArrayProperty.Parse(propertyName, index, reader, size, out overhead);
                break;

            case FloatProperty.TypeName:
                overhead = 1;
                result   = FloatProperty.Parse(propertyName, index, reader);
                break;

            case IntProperty.TypeName:
                overhead = 1;
                result   = IntProperty.Parse(propertyName, index, reader);
                break;

            case ByteProperty.TypeName:
                result = ByteProperty.Parse(propertyName, index, reader, out overhead);
                break;

            case EnumProperty.TypeName:
                result = EnumProperty.Parse(propertyName, index, reader, out overhead);
                break;

            case BoolProperty.TypeName:
                overhead = 2;
                result   = BoolProperty.Parse(propertyName, index, reader);
                break;

            case StrProperty.TypeName:
                overhead = 1;
                result   = StrProperty.Parse(propertyName, index, reader);
                break;

            case NameProperty.TypeName:
                overhead = 1;
                result   = NameProperty.Parse(propertyName, index, reader);
                break;

            case ObjectProperty.TypeName:
                overhead = 1;
                result   = ObjectProperty.Parse(propertyName, index, reader);
                break;

            case StructProperty.TypeName:
                result = StructProperty.Parse(propertyName, index, reader, size, out overhead);
                break;

            case MapProperty.TypeName:
                result = MapProperty.Parse(propertyName, index, reader, size, out overhead);
                break;

            case TextProperty.TypeName:
                overhead = 1;
                result   = TextProperty.Parse(propertyName, index, reader);
                break;

            default:
                throw new NotImplementedException(fieldType);
            }

            var after     = reader.BaseStream.Position;
            var readBytes = (int)(after - before - overhead);

            if (size != readBytes)
            {
                throw new InvalidOperationException($"Expected {size} bytes read but got {readBytes}");
            }

            return(result);
        }