public override void Deserialize(BinaryStream stream) { Offset = (int)stream.Position; try { Data.Deserialize(stream); } catch (Exception e) { throw new InvalidOperationException($"Attribute '{Name}' read error -- {e.Message}", e); } // pretty sure this is garbage if (Data.Type == DataType.BinHex) { if (Data.IsBufferValid_LEGACY()) { var guess = Utils.GetAttributeTypeBestGuess(Data); if (guess != DataType.BinHex) { //Debug.WriteLine($"[INFO] Attribute type for '{Name}' (hash={Hash:X8}) in '{Class}' may be '{guess.ToString()}'"); Debug.WriteLine($"<!-- GUESS: --><Attribute Name=\"{FullName}\" Type=\"{guess.ToString()}\" />"); } } else { // really really slow Debug.WriteLine($"[INFO] Attribute type for '{Name}' (hash={Hash:X8}) in '{Class}' is unknown."); } } else { if (Utils.IsAttributeBufferStrangeSize(Data)) { Debug.WriteLine($"Attribute '{Name}' in '{Class}' is defined as a '{Data.Type}' and has a strange size of {Data.Buffer.Length} byte(s)."); } if (Data.Type == DataType.Byte) { if ((Data.Buffer.Length == 1) && (Data.Buffer[0] == 0)) { throw new InvalidOperationException($"VERY BAD: Attribute '{Name}' (hash:{Hash:X8}) defined as a Byte in class '{Class}' but is actually a String.\r\nThis will BREAK the exporter, so please update this attribute immediately!"); } } } }
public static AttributeData Read(BinaryStream stream, DataType type) { var data = new AttributeData(type); try { data.Deserialize(stream); data.SanityCheck(); } catch (Exception e) { throw new InvalidOperationException($"Error reading attribute data type '{data.Type}' -- {e.Message}", e); } return(data); }