private NodeAttribute ReadAttribute(NodeAttribute.DataType type, BinaryReader reader, uint length) { // LSF and LSB serialize the buffer types differently, so specialized // code is added to the LSB and LSf serializers, and the common code is // available in BinUtils.ReadAttribute() switch (type) { case NodeAttribute.DataType.DT_String: case NodeAttribute.DataType.DT_Path: case NodeAttribute.DataType.DT_FixedString: case NodeAttribute.DataType.DT_LSString: case NodeAttribute.DataType.DT_WString: case NodeAttribute.DataType.DT_LSWString: { var attr = new NodeAttribute(type); attr.Value = ReadString(reader, (int)length); return(attr); } case NodeAttribute.DataType.DT_TranslatedString: { var attr = new NodeAttribute(type); var str = new TranslatedString(); if (Version >= (uint)FileVersion.VerBG3) { str.Version = reader.ReadUInt16(); } else { str.Version = 0; var valueLength = reader.ReadInt32(); str.Value = ReadString(reader, valueLength); } var handleLength = reader.ReadInt32(); str.Handle = ReadString(reader, handleLength); attr.Value = str; return(attr); } case NodeAttribute.DataType.DT_TranslatedFSString: { var attr = new NodeAttribute(type); attr.Value = ReadTranslatedFSString(reader); return(attr); } case NodeAttribute.DataType.DT_ScratchBuffer: { var attr = new NodeAttribute(type); attr.Value = reader.ReadBytes((int)length); return(attr); } default: return(BinUtils.ReadAttribute(type, reader)); } }
private NodeAttribute ReadAttribute(NodeAttribute.DataType type) { switch (type) { case NodeAttribute.DataType.DT_String: case NodeAttribute.DataType.DT_Path: case NodeAttribute.DataType.DT_FixedString: case NodeAttribute.DataType.DT_LSString: { var attr = new NodeAttribute(type); attr.Value = ReadString(true); return(attr); } case NodeAttribute.DataType.DT_WString: case NodeAttribute.DataType.DT_LSWString: { var attr = new NodeAttribute(type); attr.Value = ReadWideString(true); return(attr); } case NodeAttribute.DataType.DT_TranslatedString: { var attr = new NodeAttribute(type); var str = new TranslatedString(); str.Value = ReadString(true); str.Handle = ReadString(true); attr.Value = str; return(attr); } case NodeAttribute.DataType.DT_ScratchBuffer: { var attr = new NodeAttribute(type); var bufferLength = reader.ReadInt32(); attr.Value = reader.ReadBytes(bufferLength); return(attr); } // DT_TranslatedFSString not supported in LSB default: return(BinUtils.ReadAttribute(type, reader)); } }
private NodeAttribute ReadAttribute(NodeAttribute.DataType type) { switch (type) { case NodeAttribute.DataType.DT_String: case NodeAttribute.DataType.DT_Path: case NodeAttribute.DataType.DT_FixedString: case NodeAttribute.DataType.DT_LSString: { var attr = new NodeAttribute(type); attr.Value = ReadString(true); return(attr); } case NodeAttribute.DataType.DT_WString: case NodeAttribute.DataType.DT_LSWString: { var attr = new NodeAttribute(type); attr.Value = ReadWideString(true); return(attr); } case NodeAttribute.DataType.DT_TranslatedString: { var attr = new NodeAttribute(type); var str = new TranslatedString(); if (IsBG3) { str.Version = reader.ReadUInt16(); // Sometimes BG3 string keys still contain the value? // Weird heuristic to find these cases var test = reader.ReadUInt16(); if (test == 0) { stream.Seek(-4, SeekOrigin.Current); str.Version = 0; str.Value = ReadString(true); } else { stream.Seek(-2, SeekOrigin.Current); str.Value = null; } } else { str.Version = 0; str.Value = ReadString(true); } str.Handle = ReadString(true); attr.Value = str; return(attr); } case NodeAttribute.DataType.DT_ScratchBuffer: { var attr = new NodeAttribute(type); var bufferLength = reader.ReadInt32(); attr.Value = reader.ReadBytes(bufferLength); return(attr); } // DT_TranslatedFSString not supported in LSB default: return(BinUtils.ReadAttribute(type, reader)); } }