diff --git a/File_Format_Library/FileFormats/Message/MSBT.cs b/File_Format_Library/FileFormats/Message/MSBT.cs index 45eebf45..f3ee479a 100644 --- a/File_Format_Library/FileFormats/Message/MSBT.cs +++ b/File_Format_Library/FileFormats/Message/MSBT.cs @@ -15,7 +15,7 @@ namespace FirstPlugin { public FileType FileType { get; set; } = FileType.Message; - public bool CanSave { get; set; } + public bool CanSave { get; set; } = true; public string[] Description { get; set; } = new string[] { "Message Studio Binary Text" }; public string[] Extension { get; set; } = new string[] { "*.msbt" }; public string FileName { get; set; } @@ -71,8 +71,6 @@ namespace FirstPlugin public void Load(System.IO.Stream stream) { - CanSave = false; - header = new Header(); header.Read(new FileReader(stream)); } @@ -266,16 +264,21 @@ namespace FirstPlugin { private uint _index; + public byte[] OriginalDataCached = new byte[0]; + public StringEntry(byte[] data) { Data = data; + OriginalDataCached = Data; } public StringEntry(byte[] data, Encoding encoding) { Data = data; + OriginalDataCached = Data; } public StringEntry(string text, Encoding encoding) { Data = encoding.GetBytes(text); + OriginalDataCached = encoding.GetBytes(text); } public uint Index @@ -297,6 +300,15 @@ namespace FirstPlugin return encoding.GetString(Data); } + public string GetOriginalText(Encoding encoding) { + return encoding.GetString(OriginalDataCached); + } + + public void SetText(string text, Encoding encoding) + { + Data = encoding.GetBytes(text); + } + public byte[] ToBytes(Encoding encoding, bool isBigEndian) { return Data; @@ -320,6 +332,12 @@ namespace FirstPlugin writer.Write((byte)text[++i]); } } + if (c == 0xF) + { + //end tag + writer.Write((short)text[++i]); + writer.Write((short)text[++i]); + } } writer.Write('\0'); } diff --git a/File_Format_Library/GUI/Message/MSBTEditor.cs b/File_Format_Library/GUI/Message/MSBTEditor.cs index d3959e7b..8cb75458 100644 --- a/File_Format_Library/GUI/Message/MSBTEditor.cs +++ b/File_Format_Library/GUI/Message/MSBTEditor.cs @@ -33,9 +33,25 @@ namespace FirstPlugin.Forms hexEditor1.EnableMenuBar = false; + editTextTB.TextChanged += TextChanged; + Reload(); } + private void TextChanged(object sender, EventArgs args) + { + if (listViewCustom1.SelectedItems.Count > 0) + { + var item = listViewCustom1.SelectedItems[0]; + if (item.Tag is MSBT.StringEntry) + { + var msbtString = (MSBT.StringEntry)item.Tag; + msbtString.SetText(editTextTB.Text, activeMessageFile.header.StringEncoding); + hexEditor1.LoadData(msbtString.Data); + } + } + } + private void Reload() { string[] fontSizes = { "8", "9", "10", "11", "12", "14", "16", "18", @@ -107,7 +123,7 @@ namespace FirstPlugin.Forms var msbtString = (MSBT.StringEntry)item.Tag; editTextTB.Text = msbtString.GetText(activeMessageFile.header.StringEncoding); - originalTextTB.Text = msbtString.GetText(activeMessageFile.header.StringEncoding); + originalTextTB.Text = msbtString.GetOriginalText(activeMessageFile.header.StringEncoding); hexEditor1.LoadData(msbtString.Data); } }