diff --git a/Z64Utils/Common/ArrayUtil.cs b/Z64Utils/Common/ArrayUtil.cs index ed61f64..66e1709 100644 --- a/Z64Utils/Common/ArrayUtil.cs +++ b/Z64Utils/Common/ArrayUtil.cs @@ -8,6 +8,12 @@ namespace Common { class ArrayUtil { + public static int ReadInt32BE(byte[] data, int offset = 0) + { + byte[] buff = new byte[sizeof(int)]; + Buffer.BlockCopy(data, offset, buff, 0, sizeof(int)); + return BitConverter.ToInt32(buff.Reverse().ToArray(), 0); + } public static uint ReadUint32BE(byte[] data, int offset = 0) { byte[] buff = new byte[sizeof(uint)]; diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.cs b/Z64Utils/Forms/ObjectAnalyzerForm.cs index e3e3848..0ebaa69 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.cs +++ b/Z64Utils/Forms/ObjectAnalyzerForm.cs @@ -244,19 +244,37 @@ private void listView_map_SelectedIndexChanged(object sender, EventArgs e) StringWriter sw = new StringWriter(); for (int n = 0; n < matrices.Matrices.Count; n++) { - sw.WriteLine($" ┌ ┐ "); + var mtx = new Mtx(matrices.Matrices[n].GetBuffer()).ToMatrix4(); + string[,] mtxStr = new string[4, 4]; + int[] columnsWidth = { 0, 0, 0, 0 }; + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + float val = mtx[j, i]; // Matrix4 uses column-major order + string valStr = $"{val}"; + mtxStr[i,j] = valStr; + columnsWidth[j] = Math.Max(valStr.Length, columnsWidth[j]); + } + } + + string columnSeparator = " "; + int w = 3 * columnSeparator.Length; + for (int j = 0; j < 4; j++) + w += columnsWidth[j]; + sw.WriteLine(" ┌ " + new string(' ', w) + " ┐ "); for (int i = 0; i < 4; i++) { var values = ""; for (int j = 0; j < 4; j++) { - values += $"0x{ArrayUtil.ReadUint32BE(matrices.Matrices[n].GetBuffer(), 4*(4 * i + j)):X08}"; + values += mtxStr[i, j].PadLeft(columnsWidth[j]); if (j != 3) - values += $" "; + values += columnSeparator; } sw.WriteLine($" │ {values} │ "); } - sw.WriteLine($" └ ┘ "); + sw.WriteLine(" └ " + new string(' ', w) + " ┘ "); } textBox_holderInfo.Text = sw.ToString(); break;