internal static UEProperty Deserialize(string name, string type, long valueLength, BinaryReader reader) { UEProperty result; var itemOffset = reader.BaseStream.Position; switch (type) { case "BoolProperty": result = new UEBoolProperty(reader, valueLength); break; case "IntProperty": result = new UEIntProperty(reader, valueLength); break; case "FloatProperty": result = new UEFloatProperty(reader, valueLength); break; case "NameProperty": case "StrProperty": case "SoftObjectProperty": case "ObjectProperty": result = new UEStringProperty(reader, valueLength); break; case "TextProperty": result = new UETextProperty(reader, valueLength); break; case "EnumProperty": result = new UEEnumProperty(reader, valueLength); break; case "StructProperty": result = UEStructProperty.Read(reader, valueLength); break; case "ArrayProperty": result = new UEArrayProperty(reader, valueLength); break; case "MapProperty": result = new UEMapProperty(reader, valueLength); break; case "ByteProperty": result = UEByteProperty.Read(reader, valueLength); break; default: throw new FormatException($"Offset: 0x{itemOffset:x8}. Unknown value type '{type}' of item '{name}'"); } result.Name = name; result.Type = type; result.ValueLength = valueLength; return(result); }
public UEArrayProperty ReadUEArrayProperty(JObject o) { UEArrayProperty value = new UEArrayProperty(); value.ItemType = o["ItemType"].ToString(); value.Count = int.Parse(o["Count"].ToString()); List <UEProperty> items = new List <UEProperty>(); foreach (JObject item in o["Items"]) { items.Add(ReadUEProperty(item)); } value.Items = items.ToArray(); return(value); }
internal static UEProperty Deserialize(string name, string type, long valueLength, BinaryReader reader) { UEProperty result; var itemOffset = reader.BaseStream.Position; switch (type) { case "BoolProperty": result = new UEBoolProperty(reader, valueLength); break; case "IntPropertyArray": result = new UEIntProperty(reader, valueLength, false); break; case "IntProperty": result = new UEIntProperty(reader, valueLength, true); break; case "UInt32Property": result = new UEInt32Property(reader, valueLength); break; case "FloatProperty": result = new UEFloatProperty(reader, valueLength); break; case "NameProperty": case "StrProperty": result = new UEStringProperty(reader, valueLength); break; case "TextProperty": result = new UETextProperty(reader, valueLength); break; case "EnumProperty": result = new UEEnumProperty(reader, valueLength); break; case "StructProperty": result = UEStructProperty.Read(reader, valueLength); result.Address = $"0x{ reader.BaseStream.Position - 1:x8}"; break; case "ArrayProperty": result = new UEArrayProperty(reader, valueLength); break; case "MapProperty": result = new UEMapProperty(reader, valueLength); break; case "ByteProperty": result = UEByteProperty.Read(reader, valueLength); result.Address = $"0x{ reader.BaseStream.Position - 1:x8}"; break; case "SetProperty": result = new UESetProperty(reader, valueLength); break; case "SoftObjectProperty": result = new UEStringProperty(reader, valueLength); break; case "ObjectProperty": result = new UEStringProperty(reader, valueLength); break; default: result = new UEStringProperty(reader, valueLength); break; } result.Name = name; result.Type = type; Debug.WriteLine(String.Format("{0} ({1}) {2}", name, type, $"0x{ reader.BaseStream.Position - 1:x8}")); return(result); }
public static UEProperty ReadUEProperty(this BinaryReader br) { var name = br.ReadUEString(); if (name == null) { return(null); } if (name == "None") { br.BaseStream.Position += 4; // Skip 4 zeros return(new UENoneProperty()); } var type = br.ReadUEString(); var valueLength = br.ReadInt64(); switch (type) { case "IntProperty": { var terminator = br.ReadByte(); if (terminator != 0) { throw new FormatException($"Offset: 0x{br.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})"); } if (valueLength != sizeof(int)) { throw new FormatException($"Expected int value of length {sizeof(int)}, but was {valueLength}"); } return(new UEIntProperty { Name = name, Type = type, Value = br.ReadInt32() }); } case "ArrayProperty": { var subType = br.ReadUEString(); var terminator = br.ReadByte(); if (terminator != 0) { throw new FormatException($"Offset: 0x{br.BaseStream.Position - 1:x8}. Expected terminator (0x00), but was (0x{terminator:x2})"); } switch (subType) { case "ByteProperty": { var itemLength = br.ReadInt32(); var obj = new UEArrayProperty <byte> { Name = name, Type = type }; obj.Value = br.ReadBytes(itemLength); return(obj); } default: throw new Exception("Unrecognized property type!"); } } default: throw new Exception($"Unrecognized property type '{type}'"); } }