public void Deserialize(XmlAttribute xml) { var name = xml.Name; if (name[0] == '_') { Hash = int.Parse(name.Substring(1), NumberStyles.HexNumber); } else { // known attribute :) Name = name; } var type = AttributeTypes.GetType(Hash); // try resolving the full name, e.g. 'Class.bProperty' var fullHash = StringHasher.GetHash(FullName); if (fullHash != Hash) { if (AttributeTypes.IsTypeKnown(fullHash)) { type = AttributeTypes.GetType(fullHash); } } Data = new AttributeData(type, xml.Value); // looks to be part of the spec :/ //if (Data.Type != type) // Debug.WriteLine($"Attribute '{FullName}' was created as a '{type.ToString()}' but was actually a '{Data.Type.ToString()}'!"); }
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); } }
public static void Dump(string dir) { #if DUMPSTR_SPLIT_FILES var names = new List <String>(); var types = new List <String>(); foreach (var kv in m_lookup) { var k = kv.Key; var v = kv.Value; if (Utils.CheckString(v) >= 0) { if (AttributeTypes.IsTypeKnown(k)) { types.Add(v); } else { names.Add(v); } } } File.WriteAllLines(Path.Combine(dir, "dumpstr_names.txt"), names.OrderBy(s => s)); File.WriteAllLines(Path.Combine(dir, "dumpstr_types.txt"), types.OrderBy(s => s)); #else var strings = from kv in m_lookup let k = kv.Key let v = kv.Value // don't include strings with spaces! where ((Utils.CheckString(v) >= 0) && (v.IndexOf(' ') == -1)) orderby v select v; File.WriteAllLines(Path.Combine(dir, "strings_dump.txt"), strings); #endif }
public void Deserialize(BinaryStream stream, bool readHash) { if (readHash) { var hash = stream.ReadInt32(); var name = StringHasher.ResolveHash(hash); var type = AttributeTypes.GetType(hash); // cannot be null or contain spaces var nameResolved = ((name != null) && !name.Contains(" ")); if (nameResolved) { Name = name; } else { Hash = hash; } // try resolving the full name, e.g. 'Class.bProperty' var fullHash = StringHasher.GetHash(FullName); if (fullHash != hash) { if (AttributeTypes.IsTypeKnown(fullHash)) { type = AttributeTypes.GetType(fullHash); } } Data = new AttributeData(type); } else { Deserialize(stream); } }