diff --git a/src/MessageStudio/Formats/BinaryText/ImmutableMsbt.cs b/src/MessageStudio/Formats/BinaryText/ImmutableMsbt.cs index fe15e75..af9511a 100644 --- a/src/MessageStudio/Formats/BinaryText/ImmutableMsbt.cs +++ b/src/MessageStudio/Formats/BinaryText/ImmutableMsbt.cs @@ -2,12 +2,12 @@ using MessageStudio.Formats.BinaryText.Structures; using MessageStudio.IO; using System.Runtime.CompilerServices; -using System.Text; namespace MessageStudio.Formats.BinaryText; public readonly ref struct ImmutableMsbt { + public readonly MsbtHeader Header; public readonly AttributeSectionReader AttributeSectionReader; public readonly LabelSectionReader LabelSectionReader; public readonly TextSectionReader TextSectionReader; @@ -46,5 +46,15 @@ public ImmutableMsbt(ref SpanReader reader) reader.Align(0x10); } + + Header = header; + + // Fix the BoM for consumers + unsafe { + fixed (Endian* ptr = &Header.ByteOrderMark) { + Span range = new(ptr, sizeof(Endian)); + range.Reverse(); + } + } } } diff --git a/src/MessageStudio/Formats/BinaryText/Msbt.cs b/src/MessageStudio/Formats/BinaryText/Msbt.cs index 6d5d483..2371b46 100644 --- a/src/MessageStudio/Formats/BinaryText/Msbt.cs +++ b/src/MessageStudio/Formats/BinaryText/Msbt.cs @@ -13,6 +13,9 @@ public class Msbt : Dictionary internal const uint LBL1_MAGIC = 0x314C424C; internal const uint TXT2_MAGIC = 0x32545854; + public Endian Endian { get; set; } = Endian.Little; + public TextEncoding Encoding { get; set; } = TextEncoding.Unicode; + /// /// Create a new object from a data buffer /// @@ -32,7 +35,11 @@ public static Msbt FromBinary(Span buffer) /// public static Msbt FromImmutable(ref ImmutableMsbt msbt) { - Msbt managed = []; + Msbt managed = new() { + Encoding = msbt.Header.Encoding, + Endian = msbt.Header.ByteOrderMark + }; + foreach (var label in msbt.LabelSectionReader) { int index = label.Index; string? key = label.GetManaged();