From 8ed1a6aa98d04f2f380226b7da627df4384b9340 Mon Sep 17 00:00:00 2001 From: Denis <93516910+Bussun@users.noreply.github.com> Date: Sat, 25 Dec 2021 00:27:41 +0100 Subject: [PATCH] Trying to add little endian support Changed some lines, I expect bugs to happen, if people tested it (w/ SM3DAS files) to report them Commented some code --- BMGEditor/FS/BMG.cs | 6 ++++-- BMGEditor/FS/BigEndian.cs | 7 ------- BMGEditor/FS/FilesystemBase.cs | 8 ++++++-- BMGEditor/Program.cs | 13 +++++++++---- BMGEditor/UI/BMGEditForm.Designer.cs | 15 ++++++++++++++- BMGEditor/UI/BMGEditForm.cs | 6 ++++++ BMGEditor/UI/BMGEditForm.resx | 11 +++++++++++ 7 files changed, 50 insertions(+), 16 deletions(-) diff --git a/BMGEditor/FS/BMG.cs b/BMGEditor/FS/BMG.cs index b8a0021..4ed1b8a 100644 --- a/BMGEditor/FS/BMG.cs +++ b/BMGEditor/FS/BMG.cs @@ -245,6 +245,8 @@ namespace BMGEditor INF1itemNumber++; Entries.Add(newEntry); + //Code to sort entries by alphabetical order and then reassign an ID + //Works perfectly but is unused right now because it breaks flows /* Entries.Sort((x, y) => { string entryNameA = x.entryName, entryNameB = y.entryName; @@ -272,8 +274,8 @@ namespace BMGEditor m_File.Writer.Write((Int32)m_FileType); m_File.Writer.Write((UInt32)0x00); //Final fileSize will be written at the end m_File.Writer.Write((UInt32)0x04); //Number of sections, always 4 in Super Mario Galaxy, this editor isn't meant to be used on anything else anyway. - m_File.Writer.Write((Byte)0x02); //Encoding - while (m_File.Stream.Position != 0x20) m_File.Writer.Write((Byte)0x00); // The 15 bytes of nothing + m_File.Writer.Write((Byte)0x02); //Encoding: UTF-16 + while (m_File.Stream.Position != 0x20) m_File.Writer.Write((Byte)0x00); // The 15 bytes of nothing/padding //INF1 section Int64 INF1start = m_File.Stream.Position; diff --git a/BMGEditor/FS/BigEndian.cs b/BMGEditor/FS/BigEndian.cs index 6d909d3..6ae1ada 100644 --- a/BMGEditor/FS/BigEndian.cs +++ b/BMGEditor/FS/BigEndian.cs @@ -29,13 +29,6 @@ namespace BMGEditor return (Int32)((val >> 24) | ((val & 0xFF0000) >> 8) | ((val & 0xFF00) << 8) | (val << 24)); } - /*public override long ReadInt64() - { - UInt64 val = base.ReadUInt64(); - return (Int64)() - }*/ - - public override ushort ReadUInt16() { UInt16 val = base.ReadUInt16(); diff --git a/BMGEditor/FS/FilesystemBase.cs b/BMGEditor/FS/FilesystemBase.cs index c598654..752263f 100644 --- a/BMGEditor/FS/FilesystemBase.cs +++ b/BMGEditor/FS/FilesystemBase.cs @@ -68,8 +68,12 @@ namespace BMGEditor private void InitRW() { - Reader = m_BigEndian ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding); - Writer = m_BigEndian ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding); + //Original code + //Reader = m_BigEndian ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding); + //Writer = m_BigEndian ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding); + + Reader = Tests.isBE ? new BinaryReaderBE(m_Stream, m_Encoding) : new BinaryReader(m_Stream, m_Encoding); + Writer = Tests.isBE ? new BinaryWriterBE(m_Stream, m_Encoding) : new BinaryWriter(m_Stream, m_Encoding); } diff --git a/BMGEditor/Program.cs b/BMGEditor/Program.cs index d64174c..9d0e107 100644 --- a/BMGEditor/Program.cs +++ b/BMGEditor/Program.cs @@ -8,10 +8,15 @@ namespace BMGEditor public static class Variables { public const string softwareName = "Luma"; - public const string softwareVersion = "v1.0"; - public const UInt64 build = 1; - public const bool isBeta = false; - public const bool isBE = true; + public const string softwareVersion = "v1.1"; + public const UInt64 build = 2; + public const bool isBeta = true; + } + + public static class Tests + { + //Not a good place to put this I know but I'm trying to figure it out + public static bool isBE = true; } internal static class Program { diff --git a/BMGEditor/UI/BMGEditForm.Designer.cs b/BMGEditor/UI/BMGEditForm.Designer.cs index 5bd5964..af81aa0 100644 --- a/BMGEditor/UI/BMGEditForm.Designer.cs +++ b/BMGEditor/UI/BMGEditForm.Designer.cs @@ -43,6 +43,7 @@ this.deleteEntryBtn = new System.Windows.Forms.ToolStripMenuItem(); this.entriesListBox = new System.Windows.Forms.ListBox(); this.openARCDialog = new System.Windows.Forms.OpenFileDialog(); + this.toggleBEBtn = new System.Windows.Forms.ToolStripButton(); this.toolStrip.SuspendLayout(); this.SuspendLayout(); // @@ -52,7 +53,8 @@ this.toolStrip.ImageScalingSize = new System.Drawing.Size(20, 20); this.toolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileMenu, - this.editBtn}); + this.editBtn, + this.toggleBEBtn}); this.toolStrip.Location = new System.Drawing.Point(0, 0); this.toolStrip.Name = "toolStrip"; this.toolStrip.Size = new System.Drawing.Size(700, 25); @@ -177,6 +179,16 @@ this.openARCDialog.Filter = "Nintendo ARC Files|*.arc"; this.openARCDialog.Title = "Open ARC"; // + // toggleBEBtn + // + this.toggleBEBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text; + this.toggleBEBtn.Image = ((System.Drawing.Image)(resources.GetObject("toggleBEBtn.Image"))); + this.toggleBEBtn.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toggleBEBtn.Name = "toggleBEBtn"; + this.toggleBEBtn.Size = new System.Drawing.Size(158, 22); + this.toggleBEBtn.Text = "toggle BE/LE (BE by default)"; + this.toggleBEBtn.Click += new System.EventHandler(this.toggleBEBtn_Click); + // // BMGEditForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -213,5 +225,6 @@ private System.Windows.Forms.ToolStripMenuItem openBCSVBtn; private System.Windows.Forms.OpenFileDialog openARCDialog; private System.Windows.Forms.ToolStripMenuItem openFlowEditorBtn; + private System.Windows.Forms.ToolStripButton toggleBEBtn; } } \ No newline at end of file diff --git a/BMGEditor/UI/BMGEditForm.cs b/BMGEditor/UI/BMGEditForm.cs index 59444f3..5d8541e 100644 --- a/BMGEditor/UI/BMGEditForm.cs +++ b/BMGEditor/UI/BMGEditForm.cs @@ -133,5 +133,11 @@ namespace BMGEditor Form bcsvEdit = new BcsvEditorForm(m_ARC); bcsvEdit.Show(); } + + private void toggleBEBtn_Click(object sender, EventArgs e) + { + Tests.isBE = !Tests.isBE; + MessageBox.Show("Switched successfully"); + } } } diff --git a/BMGEditor/UI/BMGEditForm.resx b/BMGEditor/UI/BMGEditForm.resx index eb32eb7..d9a602a 100644 --- a/BMGEditor/UI/BMGEditForm.resx +++ b/BMGEditor/UI/BMGEditForm.resx @@ -81,6 +81,17 @@ U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM qgAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEISURBVEhL3ZErDsJAGIR7DlA47oArV8CDR9RiSDAQPBcA + Qx1BgUMQBEk1ooJAKE0I4Wlqf5gmu1n6oqW7hiZfthkx33aqeZ5HKvEFpmmSYRhSQScXINB1XSroDAke + 96cUpAmupyPZsx7Z8x4drAnPpQmsgU7LdoHDJNIEYjnAlyBXJ3jPhVyaYLca8nLMhX+CPJXAOT+ouTj5 + p5in4asApdWpS8XRwT+zShIFG/fOyxlZJbGC9f5G5bHzUf6LJFJQqTViyxlxEmRiHhLUW10qDbeRpUGC + ErwjE/OQoG9dIsviYGWsXMwxc24BYLcO5pgZc+cWJIG5MbsyAUDnHwlUAkFHJZraR9NeMVq3zi+WF/0A + AAAASUVORK5CYII=