protected NomadValue ReadAttributeData(BinaryStream stream, NomadObject parent, int hash) { var ptr = (int)stream.Position; var id = StringId.Parse(hash); var type = (id == "RML_DATA") ? DataType.RML : AttributeTypes.GetBestType(id, parent.Id); var data = AttributeData.Read(stream, type); switch (type) { case DataType.BinHex: { if (data.Type == DataType.String) { StringId fullType = $"{parent.Id}.{id}"; if (!AttributeTypes.IsTypeKnown(fullType)) { AttributeTypes.RegisterGuessType(fullType, data.Type); } } } break; case DataType.String: { if (data.Type == DataType.BinHex) { StringId fullType = $"{parent.Id}.{id}"; Context.LogDebug($"**** Attribute '{fullType}' was incorrectly assumed to be a String! ****"); } } break; } var result = new NomadValue() { Id = id, Data = data, }; if (parent != null) { parent.Attributes.Add(result); } return(result); }
public NomadValue ReadXmlAttribute(XAttribute xml, NomadObject parent) { Context.State = ContextStateType.Member; Context.MemberIndex++; var name = xml.Name.LocalName; var cName = xml.Parent.Name.LocalName; var id = StringId.Parse(name); var type = (parent.IsRml) ? DataType.RML : AttributeTypes.GetBestType(id, cName); var value = xml.Value; if (type == DataType.BinHex) { // handle potential strings safely if ((value.Length > 0) && !Utils.IsHexString(value)) { type = DataType.String; } } NomadValue result = null; try { result = new NomadValue(type, value) { Id = id }; parent.Attributes.Add(result); return(result); } catch (Exception e) { throw new XmlException($"Error parsing attribute '{id}' in '{parent.Id}' of type '{type}' : {e.Message}", e); } }