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

            overhead = result.Type.Length + 22;

            result.Unk1 = reader.ReadInt32();
            Trace.Assert(result.Unk1 == 0);

            result.Unk2 = reader.ReadInt32();
            Trace.Assert(result.Unk2 == 0);

            result.Unk3 = reader.ReadInt32();
            Trace.Assert(result.Unk3 == 0);

            result.Unk4 = reader.ReadInt32();
            Trace.Assert(result.Unk4 == 0);

            result.Unk5 = reader.ReadByte();
            Trace.Assert(result.Unk5 == 0);

            result.Data = reader.ReadBytes(size);

            return(result);
        }
Beispiel #2
0
        public static StructProperty Parse(string propertyName, int index, BinaryReader reader, int size, out int overhead)
        {
            var result = new StructProperty(propertyName, index);
            var type   = reader.ReadLengthPrefixedString();

            overhead = type.Length + 22;

            result.Unk1 = reader.ReadInt32();
            Trace.Assert(result.Unk1 == 0);

            result.Unk2 = reader.ReadInt32();
            Trace.Assert(result.Unk2 == 0);

            result.Unk3 = reader.ReadInt32();
            Trace.Assert(result.Unk3 == 0);

            result.Unk4 = reader.ReadInt32();
            Trace.Assert(result.Unk4 == 0);

            result.Unk5 = reader.ReadByte();
            Trace.Assert(result.Unk5 == 0);

            var before = reader.BaseStream.Position;

            result.Data = ParseStructData(reader, type);
            var after = reader.BaseStream.Position;

            if (before + size != after)
            {
                throw new InvalidOperationException($"Expected {size} bytes read but got {after - before}");
            }

            return(result);
        }
        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);
        }
Beispiel #4
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);
        }
        public override void Serialize(BinaryWriter writer, bool writeHeader = true)
        {
            if (writeHeader)
            {
                base.Serialize(writer, writeHeader);
            }

            using (var ms = new MemoryStream())
                using (var msWriter = new BinaryWriter(ms))
                {
                    switch (Type)
                    {
                    case StructProperty.TypeName:
                    {
                        StructProperty.SerializeArray(msWriter, Elements.Cast <StructProperty>().ToArray());
                    }
                    break;

                    case ObjectProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <ObjectProperty>())
                        {
                            msWriter.WriteLengthPrefixedString(prop.Root);
                            msWriter.WriteLengthPrefixedString(prop.Name);
                        }
                    }
                    break;

                    case IntProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <IntProperty>())
                        {
                            msWriter.Write(prop.Value);
                        }
                    }
                    break;

                    default:
                        throw new NotImplementedException();
                    }

                    var bytes = ms.ToArray();

                    writer.Write(bytes.Length);
                    writer.Write(Index);

                    writer.WriteLengthPrefixedString(Type);
                    writer.Write((byte)0);

                    writer.Write(bytes);
                }
        }
        public static StructProperty[] ParseArray(BinaryReader reader)
        {
            var count = reader.ReadInt32();

            StructProperty[] result = new StructProperty[count];

            var name = reader.ReadLengthPrefixedString();

            var propertyType = reader.ReadLengthPrefixedString();

            Trace.Assert(propertyType == "StructProperty");

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

            var structType = reader.ReadLengthPrefixedString();


            var unk1 = reader.ReadInt32();
            //Trace.Assert(unk1 == 0);

            var unk2 = reader.ReadInt32();
            //Trace.Assert(unk2 == 0);

            var unk3 = reader.ReadInt32();
            //Trace.Assert(unk3 == 0);

            var unk4 = reader.ReadInt32();
            //Trace.Assert(unk4 == 0);

            var unk5 = reader.ReadByte();

            Trace.Assert(unk5 == 0);

            for (var i = 0; i < count; i++)
            {
                result[i] = new StructProperty($"Element {i}", index)
                {
                    Unk1 = unk1,
                    Unk2 = unk2,
                    Unk3 = unk3,
                    Unk4 = unk4,
                    Unk5 = unk5,
                    Type = structType,
                    Data = ParseStructData(reader, structType)
                };
            }


            return(result);
        }
Beispiel #7
0
        public static StructProperty[] ParseArray(BinaryReader reader)
        {
            var count = reader.ReadInt32();

            StructProperty[] result = new StructProperty[count];

            var name         = reader.ReadLengthPrefixedString();
            var propertyType = reader.ReadLengthPrefixedString();
            var size         = reader.ReadInt32();
            var index        = reader.ReadInt32();

            var structType = reader.ReadLengthPrefixedString();


            var unk1 = reader.ReadInt32();
            //Trace.Assert(unk1 == 0);

            var unk2 = reader.ReadInt32();
            //Trace.Assert(unk2 == 0);

            var unk3 = reader.ReadInt32();
            //Trace.Assert(unk3 == 0);

            var unk4 = reader.ReadInt32();
            //Trace.Assert(unk4 == 0);

            var unk5 = reader.ReadByte();

            Trace.Assert(unk5 == 0);

            for (var i = 0; i < count; i++)
            {
                result[i] = new StructProperty(name, index)
                {
                    Data = ParseStructData(structType, reader)
                };
            }


            return(result);
        }
Beispiel #8
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);
        }
Beispiel #9
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);
        }
Beispiel #10
0
        public override void Serialize(BinaryWriter writer, bool writeHeader = true)
        {
            if (writeHeader)
            {
                base.Serialize(writer, writeHeader);
            }

            using (var ms = new MemoryStream())
                using (var msWriter = new BinaryWriter(ms))
                {
                    switch (Type)
                    {
                    case StructProperty.TypeName:
                    {
                        StructProperty.SerializeArray(msWriter, Elements.Cast <StructProperty>().ToArray());
                    }
                    break;

                    case ObjectProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <ObjectProperty>())
                        {
                            msWriter.WriteLengthPrefixedString(prop.LevelName);
                            msWriter.WriteLengthPrefixedString(prop.PathName);
                        }
                    }
                    break;

                    case IntProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <IntProperty>())
                        {
                            msWriter.Write(prop.Value);
                        }
                    }
                    break;

                    case ByteProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <ByteProperty>())
                        {
                            msWriter.Write(byte.Parse(prop.Value));
                        }
                    }
                    break;

                    case EnumProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <EnumProperty>())
                        {
                            msWriter.WriteLengthPrefixedString(prop.Name);
                        }
                    }
                    break;

                    case StrProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <StrProperty>())
                        {
                            msWriter.WriteLengthPrefixedString(prop.Value);
                        }
                    }
                    break;

                    case FloatProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <FloatProperty>())
                        {
                            msWriter.Write(prop.Value);
                        }
                    }
                    break;

                    case TextProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <TextProperty>())
                        {
                            prop.Serialize(msWriter, false);
                        }
                    }
                    break;

                    case InterfaceProperty.TypeName:
                    {
                        msWriter.Write(Elements.Count);
                        foreach (var prop in Elements.Cast <InterfaceProperty>())
                        {
                            msWriter.WriteLengthPrefixedString(prop.LevelName);
                            msWriter.WriteLengthPrefixedString(prop.PathName);
                        }
                    }
                    break;

                    default:
                        throw new NotImplementedException($"Serializing an array of {Type} is not yet supported.");
                    }

                    var bytes = ms.ToArray();

                    writer.Write(bytes.Length);
                    writer.Write(Index);

                    writer.WriteLengthPrefixedString(Type);
                    writer.Write((byte)0);

                    writer.Write(bytes);
                }
        }