From b58a289561ff6fcde5a3c4e068ba69ebfd00847a Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 29 Nov 2021 20:41:24 +0100 Subject: [PATCH] Escape sequences are now a problem of the past --- BMGEditor/BMG.cs | 57 +++++++++++++--------------------- BMGEditor/UI/BcsvEditorForm.cs | 14 --------- BMGEditor/UI/MainForm.cs | 2 +- 3 files changed, 22 insertions(+), 51 deletions(-) diff --git a/BMGEditor/BMG.cs b/BMGEditor/BMG.cs index 31290c3..9de0c89 100644 --- a/BMGEditor/BMG.cs +++ b/BMGEditor/BMG.cs @@ -1234,12 +1234,7 @@ namespace BMGEditor { public byte length; public byte unk1; - public UInt16 binValue1; - public UInt16 binValue2; - public UInt16 binValue3; - public UInt16 binValue4; - public UInt16 binValue5; - public List bigBinValue; + public List binValue = new List(); } public List BytesFromEscapeSequence(EscapeSequence escSeq) @@ -1250,35 +1245,9 @@ namespace BMGEditor ret.Add(escSeq.length); ret.Add(escSeq.unk1); - switch (escSeq.length) + foreach (Byte b in escSeq.binValue) { - case 0x06: - byte[] binVal1case6 = BitConverter.GetBytes(escSeq.binValue1); - foreach (byte by in binVal1case6) ret.Add(by); - break; - - case 0x08: - byte[] binVal1case8 = BitConverter.GetBytes(escSeq.binValue1); - foreach (byte by in binVal1case8) ret.Add(by); - byte[] binVal2case8 = BitConverter.GetBytes(escSeq.binValue2); - foreach (byte by in binVal2case8) ret.Add(by); - break; - - case 0x0E: - byte[] binVal1caseE = BitConverter.GetBytes(escSeq.binValue1); - foreach (byte by in binVal1caseE) ret.Add(by); - byte[] binVal2caseE = BitConverter.GetBytes(escSeq.binValue2); - foreach (byte by in binVal2caseE) ret.Add(by); - byte[] binVal3caseE = BitConverter.GetBytes(escSeq.binValue3); - foreach (byte by in binVal3caseE) ret.Add(by); - byte[] binVal4caseE = BitConverter.GetBytes(escSeq.binValue4); - foreach (byte by in binVal4caseE) ret.Add(by); - byte[] binVal5caseE = BitConverter.GetBytes(escSeq.binValue5); - foreach (byte by in binVal5caseE) ret.Add(by); - break; - - case 0x36: //TODO: Implement this - break; + ret.Add(b); } return ret; } @@ -1331,7 +1300,7 @@ namespace BMGEditor } - public void NukeFile() //It's almost ready to be copied to WriteToFile() since it doesn't destroy the file anymore! + public void NukeFile() //Makin' it to WriteToFile() soon !! { //File header m_File.Stream.Position = 0; @@ -1388,7 +1357,23 @@ namespace BMGEditor { if (strToWrite[i].Equals('*')) { - //TODO: Rewrite escape sequence parser + EscapeSequence escSeq = new EscapeSequence(); + escSeq.length = Byte.Parse(String.Concat(strToWrite[i + 1], strToWrite[i + 2]), NumberStyles.HexNumber); + escSeq.unk1 = Byte.Parse(String.Concat(strToWrite[i + 3], strToWrite[i + 4]), NumberStyles.HexNumber); + i += 0x05; + for (int j = 0; j < escSeq.length * 2 - 8; j += 2) + { + escSeq.binValue.Add(Byte.Parse(String.Concat(strToWrite[i + j], strToWrite[i+j+1]), NumberStyles.HexNumber)); + } + + List seqToWrite = BytesFromEscapeSequence(escSeq); + foreach (Byte b in seqToWrite) + { + m_File.Writer.Write(b); + } + i += escSeq.length * 2 - 8; + + } else m_File.Writer.Write(strToWrite[i]); diff --git a/BMGEditor/UI/BcsvEditorForm.cs b/BMGEditor/UI/BcsvEditorForm.cs index a24fa0a..2e9f91c 100644 --- a/BMGEditor/UI/BcsvEditorForm.cs +++ b/BMGEditor/UI/BcsvEditorForm.cs @@ -1,10 +1,5 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; using System.Windows.Forms; namespace BMGEditor @@ -99,15 +94,6 @@ namespace BMGEditor private void sortBtn_Click(object sender, EventArgs e) { - //foreach (DataGridViewCell cell in dgvBcsv.Columns[0]) { } - - /*for (int i = 0; i < dgvBcsv.RowCount; i++) - { - DataGridViewCell curCell = dgvBcsv.Rows[i].Cells[0]; - DataGridViewCell nextCell = dgvBcsv.Rows[i+1].Cells[0]; - - }*/ - dgvBcsv.Sort(new RowCompare(SortOrder.Ascending)); } diff --git a/BMGEditor/UI/MainForm.cs b/BMGEditor/UI/MainForm.cs index bb129ec..4802f4b 100644 --- a/BMGEditor/UI/MainForm.cs +++ b/BMGEditor/UI/MainForm.cs @@ -55,7 +55,7 @@ namespace BMGEditor return; } - openBcsvEditorBtn.Enabled = true; + //openBcsvEditorBtn.Enabled = true; openTextEditorBtn.Enabled = true; closeFileBtn.Enabled = true; arcOpen = true;