UE_Map Read_UE_Map(ValueInfo value_info) { string key_type = reader.ReadString(); string value_type = reader.ReadString(); long unknown_position = reader.BaseStream.Position; var unknown = reader.ReadBytes(5); if (unknown.Any(b => b != 0)) { throw new InvalidOperationException($"Offset 0x{unknown_position:X8}: the 5 bytes are expected to be all 0. I cannot do json to gvas conversion in this case."); } int count = reader.ReadInt32(); List <UE_Map_KeyValuePair> content = new List <UE_Map_KeyValuePair>(); ValueInfo value_info_temp = new ValueInfo(); value_info_temp.length = -1; value_info_temp.position = PositionToken.InsideMap; for (int i = 0; i < count; i++) { value_info_temp.type = key_type; UE_Value key = Read_UE_Value(value_info_temp); value_info_temp.type = value_type; UE_Value value = Read_UE_Value(value_info_temp); content.Add(new UE_Map_KeyValuePair(key, value)); } return(new UE_Map(value_info.type, key_type, value_type, count, content)); }
void Write_UE_Value(UE_Value value, PositionToken position) { Type value_cs_type = value.GetType(); // Non-container Type if (value_cs_type == typeof(UE_ <bool>)) { Write((UE_ <bool>)value, position); } else if (value_cs_type == typeof(UE_ <byte>)) { Write((UE_ <byte>)value, position); } else if (value_cs_type == typeof(UE_Enum)) { Write((UE_Enum)value, position); } else if (value_cs_type == typeof(UE_ <float>)) { Write((UE_ <float>)value, position); } else if (value_cs_type == typeof(UE_ <int>)) { Write((UE_ <int>)value, position); } else if (value_cs_type == typeof(UE_ <string>)) { Write((UE_ <string>)value, position); } // Container Type else if (value_cs_type == typeof(UE_Map)) { Write((UE_Map)value, position); } else if (value_cs_type == typeof(UE_Array)) { Write((UE_Array)value, position); } else if (value_cs_type == typeof(UE_StructArray)) { Write((UE_StructArray)value, position); } // Struct Type else if (value_cs_type == typeof(UE_Struct_Vector)) { Write((UE_Struct_Vector)value, position); } else if (value_cs_type == typeof(UE_Struct_Quat)) { Write((UE_Struct_Quat)value, position); } else if (value_cs_type == typeof(UE_Struct_Generic)) { Write((UE_Struct_Generic)value, position); } else { throw new NotImplementedException(value_cs_type.ToString()); } }
UE_Array Read_UE_Array(ValueInfo value_info, string item_type) { int count = reader.ReadInt32(); UE_Value[] item_list = new UE_Value[count]; ValueInfo value_info_temp = new ValueInfo(); value_info_temp.type = item_type; value_info_temp.length = -1; value_info_temp.position = PositionToken.InsideArray; for (var i = 0; i < count; i++) { item_list[i] = Read_UE_Value(value_info_temp); } return(new UE_Array(value_info.type, item_type, count, item_list)); }
static GvasFormat.UE_Value UE_Value(JsonReader reader, bool skip_start_token = false) { if (!skip_start_token) { reader.AssertReadToken(JsonToken.StartObject); } string type_string = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Value.TypeString); // code structure copied from GvasFormat.Serialization.Binary.UE_Property_Reader.Read_UE_Value GvasFormat.UE_Value result; switch (type_string) { // // non-container case UE_Value_TypeString.BoolProperty: bool value_bool = reader.AssertReadPropertyNameValue <bool>(JsonNaming.UE_Value.Value); result = new UE_ <bool>(type_string, value_bool); break; case UE_Value_TypeString.ByteProperty: byte value_byte = reader.AssertReadPropertyNameValue <byte>(JsonNaming.UE_Value.Value); result = new UE_ <byte>(type_string, value_byte); break; case UE_Value_TypeString.EnumProperty: string enum_type = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Enum.EnumType); string enum_value = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Value.Value); result = new UE_Enum(type_string, enum_type, enum_value); break; case UE_Value_TypeString.FloatProperty: float value_float = reader.AssertReadPropertyNameValue <float>(JsonNaming.UE_Value.Value); result = new UE_ <float>(type_string, value_float); break; case UE_Value_TypeString.IntProperty: int value_int = reader.AssertReadPropertyNameValue <int>(JsonNaming.UE_Value.Value); result = new UE_ <int>(type_string, value_int); break; case UE_Value_TypeString.NameProperty: //case UE_ValueTypeString.StrProperty: string value_string = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Value.Value); result = new UE_ <string>(type_string, value_string); break; // // container // redirect. // UE_Struct ... lots of them are not engine defined, but game author defined. case UE_Value_TypeString.StructProperty: string struct_type = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Struct.StructTypeString); reader.AssertReadPropertyName(JsonNaming.UE_Value.Value); switch (struct_type) { case UE_Value_TypeString.Struct.Vector: case UE_Value_TypeString.Struct.Rotator: reader.AssertReadToken(JsonToken.StartArray); float x = reader.AssertReadValue <float>(); float y = reader.AssertReadValue <float>(); float z = reader.AssertReadValue <float>(); reader.AssertReadToken(JsonToken.EndArray); result = new UE_Struct_Vector(struct_type, x, y, z); break; case UE_Value_TypeString.Struct.Quat: reader.AssertReadToken(JsonToken.StartArray); float a = reader.AssertReadValue <float>(); float b = reader.AssertReadValue <float>(); float c = reader.AssertReadValue <float>(); float d = reader.AssertReadValue <float>(); reader.AssertReadToken(JsonToken.EndArray); result = new UE_Struct_Quat(struct_type, a, b, c, d); break; default: List <UE_Property> property_list = Read.Object_as_PropertyList(reader); result = new UE_Struct_Generic(struct_type, property_list); break; } break; case UE_Value_TypeString.ArrayProperty: string item_type = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Array.ItemType); reader.AssertReadPropertyNameValue <int>(JsonNaming.UE_Map.Count); List <GvasFormat.UE_Value> item_list; if (item_type == UE_Value_TypeString.StructProperty) { string sa_name = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_StructArray.SA_Name); string sa_item_type = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_StructArray.SA_ItemType); string sa_struct_type_string = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_StructArray.SA_StructTypeString); reader.AssertReadPropertyName(JsonNaming.UE_Array.ItemList); item_list = Read.UE_Value_List(reader); result = new UE_StructArray(type_string, item_type, item_list.Count, item_list.ToArray(), sa_name, sa_item_type, sa_struct_type_string); } else { reader.AssertReadPropertyName(JsonNaming.UE_Array.ItemList); item_list = Read.UE_Value_List(reader); result = new UE_Array(type_string, item_type, item_list.Count, item_list.ToArray()); } break; case UE_Value_TypeString.MapProperty: string key_type = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Map.KeyType); string value_type = reader.AssertReadPropertyNameValue <string>(JsonNaming.UE_Map.ValueType); reader.AssertReadPropertyNameValue <int>(JsonNaming.UE_Map.Count); reader.AssertReadPropertyName(JsonNaming.UE_Map.Map); reader.AssertReadToken(JsonToken.StartArray); var map = new List <UE_Map_KeyValuePair>(); while (true) { var token = reader.AssertRead(); if (token == JsonToken.StartObject) { reader.AssertReadPropertyName(JsonNaming.UE_Map_KeyValuePair.Key); UE_Value key = Read.UE_Value(reader); reader.AssertReadPropertyName(JsonNaming.UE_Map_KeyValuePair.Value); UE_Value value = Read.UE_Value(reader); reader.AssertReadToken(JsonToken.EndObject); UE_Map_KeyValuePair kvp = new UE_Map_KeyValuePair(key, value); map.Add(kvp); } else if (token == JsonToken.EndArray) { break; } else { throw new FormatException(); } } result = new UE_Map(type_string, key_type, value_type, map.Count, map); break; default: throw new FormatException($"Unknown value type `{type_string}`."); } reader.AssertReadToken(JsonToken.EndObject); return(result); }
public UE_Map_KeyValuePair(UE_Value key, UE_Value value) { this.Key = key; this.Value = value; }