1
0
mirror of synced 2025-02-25 22:38:07 +01:00

Support MSBT editing

This commit is contained in:
KillzXGaming 2023-12-01 18:41:08 -05:00
parent efe975c48e
commit 194dbd46af
2 changed files with 38 additions and 4 deletions

View File

@ -15,7 +15,7 @@ namespace FirstPlugin
{ {
public FileType FileType { get; set; } = FileType.Message; 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[] Description { get; set; } = new string[] { "Message Studio Binary Text" };
public string[] Extension { get; set; } = new string[] { "*.msbt" }; public string[] Extension { get; set; } = new string[] { "*.msbt" };
public string FileName { get; set; } public string FileName { get; set; }
@ -71,8 +71,6 @@ namespace FirstPlugin
public void Load(System.IO.Stream stream) public void Load(System.IO.Stream stream)
{ {
CanSave = false;
header = new Header(); header = new Header();
header.Read(new FileReader(stream)); header.Read(new FileReader(stream));
} }
@ -266,16 +264,21 @@ namespace FirstPlugin
{ {
private uint _index; private uint _index;
public byte[] OriginalDataCached = new byte[0];
public StringEntry(byte[] data) { public StringEntry(byte[] data) {
Data = data; Data = data;
OriginalDataCached = Data;
} }
public StringEntry(byte[] data, Encoding encoding) { public StringEntry(byte[] data, Encoding encoding) {
Data = data; Data = data;
OriginalDataCached = Data;
} }
public StringEntry(string text, Encoding encoding) { public StringEntry(string text, Encoding encoding) {
Data = encoding.GetBytes(text); Data = encoding.GetBytes(text);
OriginalDataCached = encoding.GetBytes(text);
} }
public uint Index public uint Index
@ -297,6 +300,15 @@ namespace FirstPlugin
return encoding.GetString(Data); 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) public byte[] ToBytes(Encoding encoding, bool isBigEndian)
{ {
return Data; return Data;
@ -320,6 +332,12 @@ namespace FirstPlugin
writer.Write((byte)text[++i]); writer.Write((byte)text[++i]);
} }
} }
if (c == 0xF)
{
//end tag
writer.Write((short)text[++i]);
writer.Write((short)text[++i]);
}
} }
writer.Write('\0'); writer.Write('\0');
} }

View File

@ -33,9 +33,25 @@ namespace FirstPlugin.Forms
hexEditor1.EnableMenuBar = false; hexEditor1.EnableMenuBar = false;
editTextTB.TextChanged += TextChanged;
Reload(); 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() private void Reload()
{ {
string[] fontSizes = { "8", "9", "10", "11", "12", "14", "16", "18", string[] fontSizes = { "8", "9", "10", "11", "12", "14", "16", "18",
@ -107,7 +123,7 @@ namespace FirstPlugin.Forms
var msbtString = (MSBT.StringEntry)item.Tag; var msbtString = (MSBT.StringEntry)item.Tag;
editTextTB.Text = msbtString.GetText(activeMessageFile.header.StringEncoding); 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); hexEditor1.LoadData(msbtString.Data);
} }
} }