Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Support MSBT editing
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed Dec 1, 2023
1 parent efe975c commit 194dbd4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
24 changes: 21 additions & 3 deletions File_Format_Library/FileFormats/Message/MSBT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MSBT : IEditor<MSBTEditor>, IFileFormat, IConvertableTextFormat
{
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; }
Expand Down Expand Up @@ -71,8 +71,6 @@ public void FillEditor(UserControl control)

public void Load(System.IO.Stream stream)
{
CanSave = false;

header = new Header();
header.Read(new FileReader(stream));
}
Expand Down Expand Up @@ -266,16 +264,21 @@ public class StringEntry : MSBTEntry
{
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
Expand All @@ -297,6 +300,15 @@ public string GetText(Encoding encoding)
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;
Expand All @@ -320,6 +332,12 @@ public byte[] ToBytes(Encoding encoding, bool isBigEndian)
writer.Write((byte)text[++i]);
}
}
if (c == 0xF)
{
//end tag
writer.Write((short)text[++i]);
writer.Write((short)text[++i]);
}
}
writer.Write('\0');
}
Expand Down
18 changes: 17 additions & 1 deletion File_Format_Library/GUI/Message/MSBTEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,25 @@ public MSBTEditor()

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",
Expand Down Expand Up @@ -107,7 +123,7 @@ private void listViewCustom1_SelectedIndexChanged(object sender, EventArgs e)
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);
}
}
Expand Down

0 comments on commit 194dbd4

Please sign in to comment.