From 4c1781452e4c2b555a4ed36f02159c98b09825b4 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Sun, 1 Aug 2021 09:41:51 +0200 Subject: [PATCH 01/19] add `Import XML (ZAPD)` menu item with Designer --- Z64Utils/Common/Filters.cs | 1 + Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs | 122 +++++++++++------- Z64Utils/Forms/ObjectAnalyzerForm.cs | 13 ++ Z64Utils/Forms/ObjectAnalyzerForm.resx | 16 ++- Z64Utils/Z64/Z64Object.cs | 5 + 5 files changed, 107 insertions(+), 50 deletions(-) diff --git a/Z64Utils/Common/Filters.cs b/Z64Utils/Common/Filters.cs index 5ed43b6..c4938f4 100644 --- a/Z64Utils/Common/Filters.cs +++ b/Z64Utils/Common/Filters.cs @@ -14,6 +14,7 @@ public static class Filters public const string N64 = "N64 Rom (*.n64; *.z64)|*.n64;*.z64"; public const string BIN = "Bin Files (*.bin)|*.bin"; public const string JSON = "JSON Files (*.json)|*.json"; + public const string XML = "XML Files (*.xml)|*.xml"; public const string C = "C Files (*.c)|*.c"; } } diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs b/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs index e84d229..638eaa2 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs +++ b/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs @@ -29,13 +29,13 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(new string[] { + System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] { "06000000", "-32767, -32767, -32767", "0xFFFF", "-32767, -32767", "255, 255, 255, 255"}, -1); - System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem(new string[] { + System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem(new string[] { "00000000", "cube_vtx", "Vertex"}, -1); @@ -79,6 +79,7 @@ private void InitializeComponent() this.disassemblySettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.importXMLZAPDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tabControl1.SuspendLayout(); this.tabPage_text.SuspendLayout(); this.tabPage_texture.SuspendLayout(); @@ -100,19 +101,21 @@ private void InitializeComponent() this.tabControl1.Controls.Add(this.tabPage_vtx); this.tabControl1.Controls.Add(this.tabPage_unknow); this.tabControl1.ItemSize = new System.Drawing.Size(47, 18); - this.tabControl1.Location = new System.Drawing.Point(377, 27); - this.tabControl1.MinimumSize = new System.Drawing.Size(357, 207); + this.tabControl1.Location = new System.Drawing.Point(-1291, 35); + this.tabControl1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabControl1.MinimumSize = new System.Drawing.Size(476, 271); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(632, 499); + this.tabControl1.Size = new System.Drawing.Size(2188, 653); this.tabControl1.TabIndex = 8; // // tabPage_empty // this.tabPage_empty.Location = new System.Drawing.Point(4, 22); + this.tabPage_empty.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_empty.Name = "tabPage_empty"; - this.tabPage_empty.Padding = new System.Windows.Forms.Padding(3); - this.tabPage_empty.Size = new System.Drawing.Size(624, 473); + this.tabPage_empty.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage_empty.Size = new System.Drawing.Size(2180, 627); this.tabPage_empty.TabIndex = 0; this.tabPage_empty.Text = "nothing"; this.tabPage_empty.UseVisualStyleBackColor = true; @@ -121,9 +124,10 @@ private void InitializeComponent() // this.tabPage_text.Controls.Add(this.textBox_holderInfo); this.tabPage_text.Location = new System.Drawing.Point(4, 22); + this.tabPage_text.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_text.Name = "tabPage_text"; - this.tabPage_text.Padding = new System.Windows.Forms.Padding(3); - this.tabPage_text.Size = new System.Drawing.Size(624, 473); + this.tabPage_text.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage_text.Size = new System.Drawing.Size(835, 627); this.tabPage_text.TabIndex = 1; this.tabPage_text.Text = "ucode"; this.tabPage_text.UseVisualStyleBackColor = true; @@ -134,12 +138,13 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox_holderInfo.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox_holderInfo.Location = new System.Drawing.Point(6, 6); + this.textBox_holderInfo.Location = new System.Drawing.Point(8, 8); + this.textBox_holderInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.textBox_holderInfo.Multiline = true; this.textBox_holderInfo.Name = "textBox_holderInfo"; this.textBox_holderInfo.ReadOnly = true; this.textBox_holderInfo.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox_holderInfo.Size = new System.Drawing.Size(617, 461); + this.textBox_holderInfo.Size = new System.Drawing.Size(821, 602); this.textBox_holderInfo.TabIndex = 7; this.textBox_holderInfo.WordWrap = false; // @@ -148,9 +153,10 @@ private void InitializeComponent() this.tabPage_texture.Controls.Add(this.label_textureInfo); this.tabPage_texture.Controls.Add(this.pic_texture); this.tabPage_texture.Location = new System.Drawing.Point(4, 22); + this.tabPage_texture.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_texture.Name = "tabPage_texture"; - this.tabPage_texture.Padding = new System.Windows.Forms.Padding(3); - this.tabPage_texture.Size = new System.Drawing.Size(624, 473); + this.tabPage_texture.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage_texture.Size = new System.Drawing.Size(835, 627); this.tabPage_texture.TabIndex = 2; this.tabPage_texture.Text = "texture"; this.tabPage_texture.UseVisualStyleBackColor = true; @@ -159,9 +165,10 @@ private void InitializeComponent() // this.label_textureInfo.AutoSize = true; this.label_textureInfo.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label_textureInfo.Location = new System.Drawing.Point(6, 3); + this.label_textureInfo.Location = new System.Drawing.Point(8, 4); + this.label_textureInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.label_textureInfo.Name = "label_textureInfo"; - this.label_textureInfo.Size = new System.Drawing.Size(25, 13); + this.label_textureInfo.Size = new System.Drawing.Size(32, 17); this.label_textureInfo.TabIndex = 1; this.label_textureInfo.Text = "..."; // @@ -172,9 +179,10 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pic_texture.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.pic_texture.Location = new System.Drawing.Point(6, 20); + this.pic_texture.Location = new System.Drawing.Point(8, 26); + this.pic_texture.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.pic_texture.Name = "pic_texture"; - this.pic_texture.Size = new System.Drawing.Size(617, 447); + this.pic_texture.Size = new System.Drawing.Size(823, 585); this.pic_texture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pic_texture.TabIndex = 0; this.pic_texture.TabStop = false; @@ -183,9 +191,10 @@ private void InitializeComponent() // this.tabPage_vtx.Controls.Add(this.listView_vtx); this.tabPage_vtx.Location = new System.Drawing.Point(4, 22); + this.tabPage_vtx.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_vtx.Name = "tabPage_vtx"; - this.tabPage_vtx.Padding = new System.Windows.Forms.Padding(3); - this.tabPage_vtx.Size = new System.Drawing.Size(624, 473); + this.tabPage_vtx.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage_vtx.Size = new System.Drawing.Size(835, 627); this.tabPage_vtx.TabIndex = 3; this.tabPage_vtx.Text = "vertex"; this.tabPage_vtx.UseVisualStyleBackColor = true; @@ -205,10 +214,11 @@ private void InitializeComponent() this.listView_vtx.FullRowSelect = true; this.listView_vtx.HideSelection = false; this.listView_vtx.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem3}); - this.listView_vtx.Location = new System.Drawing.Point(6, 6); + listViewItem2}); + this.listView_vtx.Location = new System.Drawing.Point(8, 8); + this.listView_vtx.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.listView_vtx.Name = "listView_vtx"; - this.listView_vtx.Size = new System.Drawing.Size(619, 461); + this.listView_vtx.Size = new System.Drawing.Size(824, 602); this.listView_vtx.TabIndex = 0; this.listView_vtx.UseCompatibleStateImageBehavior = false; this.listView_vtx.View = System.Windows.Forms.View.Details; @@ -242,9 +252,10 @@ private void InitializeComponent() // this.tabPage_unknow.Controls.Add(this.hexBox1); this.tabPage_unknow.Location = new System.Drawing.Point(4, 22); + this.tabPage_unknow.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_unknow.Name = "tabPage_unknow"; - this.tabPage_unknow.Padding = new System.Windows.Forms.Padding(3); - this.tabPage_unknow.Size = new System.Drawing.Size(624, 473); + this.tabPage_unknow.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.tabPage_unknow.Size = new System.Drawing.Size(835, 627); this.tabPage_unknow.TabIndex = 4; this.tabPage_unknow.Text = "unknow"; this.tabPage_unknow.UseVisualStyleBackColor = true; @@ -257,11 +268,12 @@ private void InitializeComponent() this.hexBox1.ColumnInfoVisible = true; this.hexBox1.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.hexBox1.LineInfoVisible = true; - this.hexBox1.Location = new System.Drawing.Point(6, 6); + this.hexBox1.Location = new System.Drawing.Point(8, 8); + this.hexBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.hexBox1.Name = "hexBox1"; this.hexBox1.ReadOnly = true; this.hexBox1.ShadowSelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(60)))), ((int)(((byte)(188)))), ((int)(((byte)(255))))); - this.hexBox1.Size = new System.Drawing.Size(622, 461); + this.hexBox1.Size = new System.Drawing.Size(829, 603); this.hexBox1.StringViewVisible = true; this.hexBox1.TabIndex = 1; this.hexBox1.UseFixedBytesPerLine = true; @@ -280,11 +292,12 @@ private void InitializeComponent() this.listView_map.FullRowSelect = true; this.listView_map.HideSelection = false; this.listView_map.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem4}); - this.listView_map.Location = new System.Drawing.Point(12, 27); + listViewItem5}); + this.listView_map.Location = new System.Drawing.Point(16, 35); + this.listView_map.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.listView_map.MultiSelect = false; this.listView_map.Name = "listView_map"; - this.listView_map.Size = new System.Drawing.Size(359, 499); + this.listView_map.Size = new System.Drawing.Size(477, 651); this.listView_map.TabIndex = 7; this.listView_map.UseCompatibleStateImageBehavior = false; this.listView_map.View = System.Windows.Forms.View.Details; @@ -307,6 +320,7 @@ private void InitializeComponent() // // contextMenuStrip1 // + this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.openInDlistViewerMenuItem, this.addToDlistViewerMenuItem, @@ -314,52 +328,54 @@ private void InitializeComponent() this.addToolStripMenuItem, this.deleteToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(203, 114); + this.contextMenuStrip1.Size = new System.Drawing.Size(241, 124); // // openInDlistViewerMenuItem // this.openInDlistViewerMenuItem.Name = "openInDlistViewerMenuItem"; - this.openInDlistViewerMenuItem.Size = new System.Drawing.Size(202, 22); + this.openInDlistViewerMenuItem.Size = new System.Drawing.Size(240, 24); this.openInDlistViewerMenuItem.Text = "Open In Dlist Viewer"; this.openInDlistViewerMenuItem.Click += new System.EventHandler(this.openInDisplayViewerMenuItem_Click); // // addToDlistViewerMenuItem // this.addToDlistViewerMenuItem.Name = "addToDlistViewerMenuItem"; - this.addToDlistViewerMenuItem.Size = new System.Drawing.Size(202, 22); + this.addToDlistViewerMenuItem.Size = new System.Drawing.Size(240, 24); this.addToDlistViewerMenuItem.Text = "Add to Dlist Viewer"; this.addToDlistViewerMenuItem.Click += new System.EventHandler(this.addToDisplayViewerMenuItem_Click); // // openSkeletonViewerMenuItem // this.openSkeletonViewerMenuItem.Name = "openSkeletonViewerMenuItem"; - this.openSkeletonViewerMenuItem.Size = new System.Drawing.Size(202, 22); + this.openSkeletonViewerMenuItem.Size = new System.Drawing.Size(240, 24); this.openSkeletonViewerMenuItem.Text = "Open in Skeleton Viewer"; this.openSkeletonViewerMenuItem.Click += new System.EventHandler(this.openSkeletonViewerMenuItem_Click); // // addToolStripMenuItem // this.addToolStripMenuItem.Name = "addToolStripMenuItem"; - this.addToolStripMenuItem.Size = new System.Drawing.Size(202, 22); + this.addToolStripMenuItem.Size = new System.Drawing.Size(240, 24); this.addToolStripMenuItem.Text = "Add"; this.addToolStripMenuItem.Click += new System.EventHandler(this.addToolStripMenuItem_Click); // // deleteToolStripMenuItem // this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - this.deleteToolStripMenuItem.Size = new System.Drawing.Size(202, 22); + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(240, 24); this.deleteToolStripMenuItem.Text = "Delete"; this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click); // // menuStrip1 // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.toolsToolStripMenuItem, this.settingsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(1009, 24); + this.menuStrip1.Padding = new System.Windows.Forms.Padding(8, 3, 0, 3); + this.menuStrip1.Size = new System.Drawing.Size(1345, 30); this.menuStrip1.TabIndex = 9; this.menuStrip1.Text = "menuStrip1"; // @@ -368,14 +384,14 @@ private void InitializeComponent() this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exportCToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24); this.fileToolStripMenuItem.Text = "File"; this.fileToolStripMenuItem.Visible = false; // // exportCToolStripMenuItem // this.exportCToolStripMenuItem.Name = "exportCToolStripMenuItem"; - this.exportCToolStripMenuItem.Size = new System.Drawing.Size(119, 22); + this.exportCToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.exportCToolStripMenuItem.Text = "Export C"; this.exportCToolStripMenuItem.Click += new System.EventHandler(this.exportCToolStripMenuItem_Click); // @@ -386,16 +402,17 @@ private void InitializeComponent() this.analyzeDlistsToolStripMenuItem, this.importJSONToolStripMenuItem, this.exportJSONToolStripMenuItem, + this.importXMLZAPDToolStripMenuItem, this.resetToolStripMenuItem}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; - this.toolsToolStripMenuItem.Size = new System.Drawing.Size(62, 20); + this.toolsToolStripMenuItem.Size = new System.Drawing.Size(76, 24); this.toolsToolStripMenuItem.Text = "Analysis"; // // findDlistsToolStripMenuItem // this.findDlistsToolStripMenuItem.Name = "findDlistsToolStripMenuItem"; this.findDlistsToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+F"; - this.findDlistsToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.findDlistsToolStripMenuItem.Size = new System.Drawing.Size(276, 26); this.findDlistsToolStripMenuItem.Text = "Find Dlists"; this.findDlistsToolStripMenuItem.Click += new System.EventHandler(this.findDlistsToolStripMenuItem_Click); // @@ -403,28 +420,28 @@ private void InitializeComponent() // this.analyzeDlistsToolStripMenuItem.Name = "analyzeDlistsToolStripMenuItem"; this.analyzeDlistsToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+A"; - this.analyzeDlistsToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.analyzeDlistsToolStripMenuItem.Size = new System.Drawing.Size(276, 26); this.analyzeDlistsToolStripMenuItem.Text = "Analyze Dlists"; this.analyzeDlistsToolStripMenuItem.Click += new System.EventHandler(this.analyzeDlistsToolStripMenuItem_Click); // // importJSONToolStripMenuItem // this.importJSONToolStripMenuItem.Name = "importJSONToolStripMenuItem"; - this.importJSONToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.importJSONToolStripMenuItem.Size = new System.Drawing.Size(276, 26); this.importJSONToolStripMenuItem.Text = "Import JSON"; this.importJSONToolStripMenuItem.Click += new System.EventHandler(this.importJSONToolStripMenuItem_Click); // // exportJSONToolStripMenuItem // this.exportJSONToolStripMenuItem.Name = "exportJSONToolStripMenuItem"; - this.exportJSONToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.exportJSONToolStripMenuItem.Size = new System.Drawing.Size(276, 26); this.exportJSONToolStripMenuItem.Text = "Export JSON"; this.exportJSONToolStripMenuItem.Click += new System.EventHandler(this.exportJSONToolStripMenuItem_Click); // // resetToolStripMenuItem // this.resetToolStripMenuItem.Name = "resetToolStripMenuItem"; - this.resetToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.resetToolStripMenuItem.Size = new System.Drawing.Size(276, 26); this.resetToolStripMenuItem.Text = "Reset"; this.resetToolStripMenuItem.Click += new System.EventHandler(this.resetToolStripMenuItem_Click); // @@ -433,13 +450,13 @@ private void InitializeComponent() this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.disassemblySettingsToolStripMenuItem}); this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; - this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(76, 24); this.settingsToolStripMenuItem.Text = "Settings"; // // disassemblySettingsToolStripMenuItem // this.disassemblySettingsToolStripMenuItem.Name = "disassemblySettingsToolStripMenuItem"; - this.disassemblySettingsToolStripMenuItem.Size = new System.Drawing.Size(184, 22); + this.disassemblySettingsToolStripMenuItem.Size = new System.Drawing.Size(231, 26); this.disassemblySettingsToolStripMenuItem.Text = "Disassembly Settings"; this.disassemblySettingsToolStripMenuItem.Click += new System.EventHandler(this.disassemblySettingsToolStripMenuItem_Click); // @@ -447,17 +464,25 @@ private void InitializeComponent() // this.openFileDialog1.FileName = "openFileDialog1"; // + // importXMLZAPDToolStripMenuItem + // + this.importXMLZAPDToolStripMenuItem.Name = "importXMLZAPDToolStripMenuItem"; + this.importXMLZAPDToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.importXMLZAPDToolStripMenuItem.Text = "Import XML (ZAPD)"; + this.importXMLZAPDToolStripMenuItem.Click += new System.EventHandler(this.importXMLZAPDToolStripMenuItem_Click); + // // ObjectAnalyzerForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 17F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1009, 528); + this.ClientSize = new System.Drawing.Size(1345, 690); this.Controls.Add(this.tabControl1); this.Controls.Add(this.listView_map); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.KeyPreview = true; this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "ObjectAnalyzerForm"; this.Text = "Object Analyzer"; this.tabControl1.ResumeLayout(false); @@ -517,5 +542,6 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripMenuItem addToDlistViewerMenuItem; private System.Windows.Forms.ToolStripMenuItem openSkeletonViewerMenuItem; private System.Windows.Forms.Label label_textureInfo; + private System.Windows.Forms.ToolStripMenuItem importXMLZAPDToolStripMenuItem; } } \ No newline at end of file diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.cs b/Z64Utils/Forms/ObjectAnalyzerForm.cs index 9aee990..7e1652c 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.cs +++ b/Z64Utils/Forms/ObjectAnalyzerForm.cs @@ -568,5 +568,18 @@ private void exportCToolStripMenuItem_Click(object sender, EventArgs e) File.WriteAllText(saveFileDialog1.FileName, sw.ToString()); } } + + private void importXMLZAPDToolStripMenuItem_Click(object sender, EventArgs e) + { + openFileDialog1.FileName = ""; + openFileDialog1.Filter = $"{Filters.XML}|{Filters.ALL}"; + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + string xml = File.ReadAllText(openFileDialog1.FileName); + _obj = Z64Object.FromXmlZAPD(xml); + _obj.SetData(_data); + UpdateMap(); + } + } } } diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.resx b/Z64Utils/Forms/ObjectAnalyzerForm.resx index 6817475..1718682 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.resx +++ b/Z64Utils/Forms/ObjectAnalyzerForm.resx @@ -57,8 +57,20 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + + 17, 17 + + + 203, 17 + + + 338, 17 + + + 500, 17 + + + AAABAAUAEBAAAAEAIABoBAAAVgAAABgYAAABACAAiAkAAL4EAAAgIAAAAQAgAKgQAABGDgAAMDAAAAEA IACoJQAA7h4AAAAAAAABACAAYnMAAJZEAAAoAAAAEAAAACAAAAABACAAAAAAAAAEAADCDgAAwg4AAAAA diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 19ba162..ac4cb92 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1130,6 +1130,11 @@ public static Z64Object FromJson(string json) } return obj; } + internal static Z64Object FromXmlZAPD(string xml) + { + throw new NotImplementedException(); + + } } } From 5702c62fc692c0f439634d002c96009a7e4ada4a Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 16:14:36 +0200 Subject: [PATCH 02/19] implement import zapd xml (wip) --- Z64Utils/F3DZEX/Command/CmdEncoding.cs | 20 ++ Z64Utils/Forms/MainForm.cs | 17 +- Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs | 112 ++++---- Z64Utils/Forms/ObjectAnalyzerForm.cs | 39 ++- Z64Utils/Z64/Z64Object.cs | 246 +++++++++++++++++- 5 files changed, 356 insertions(+), 78 deletions(-) diff --git a/Z64Utils/F3DZEX/Command/CmdEncoding.cs b/Z64Utils/F3DZEX/Command/CmdEncoding.cs index b82a555..dde050d 100644 --- a/Z64Utils/F3DZEX/Command/CmdEncoding.cs +++ b/Z64Utils/F3DZEX/Command/CmdEncoding.cs @@ -70,7 +70,27 @@ public static byte[] EncodeCmds(List dlist) return ms.GetBuffer().Take((int)ms.Length).ToArray(); } } + public static int GetDListSize(byte[] ucode, int off = 0) + { + int length = 0; + using (MemoryStream ms = new MemoryStream(ucode)) + { + ms.Position = off; + BitReader br = new BitReader(ms); + while (br.BaseStream.Position < br.BaseStream.Length) + { + length += 1; + CmdID id = (CmdID)br.ReadByte(); + + if (!DEC_TABLE.ContainsKey(id)) + throw new InvalidF3DZEXOpCodeException($"Invalid OpCode : {id:X}"); + if (id == CmdID.G_ENDDL) + break; + } + } + return length * 8; + } public static readonly Dictionary> DEC_TABLE = new Dictionary>() { diff --git a/Z64Utils/Forms/MainForm.cs b/Z64Utils/Forms/MainForm.cs index d5b5ffa..abfe96b 100644 --- a/Z64Utils/Forms/MainForm.cs +++ b/Z64Utils/Forms/MainForm.cs @@ -284,17 +284,18 @@ private void OpenObjectViewerToolStripMenuItem_Click(object sender, EventArgs e) string defaultValue = null; - string fileName = _game.GetFileName(file.VRomStart).ToLower(); + string fileName = _game.GetFileName(file.VRomStart); + string fileNameLC = fileName.ToLower(); - if (fileName.StartsWith("object_")) + if (fileNameLC.StartsWith("object_")) defaultValue = "6"; - else if (fileName.Contains("_room_")) + else if (fileNameLC.Contains("_room_")) defaultValue = "3"; - else if (fileName.EndsWith("_scene")) + else if (fileNameLC.EndsWith("_scene")) defaultValue = "2"; - else if (fileName == "gameplay_keep") + else if (fileNameLC == "gameplay_keep") defaultValue = "4"; - else if (fileName.StartsWith("gameplay_")) + else if (fileNameLC.StartsWith("gameplay_")) defaultValue = "5"; var valueForm = new EditValueForm("Choose Segment", "Plase enter a segment id.", (v) => @@ -305,8 +306,8 @@ private void OpenObjectViewerToolStripMenuItem_Click(object sender, EventArgs e) }, defaultValue); if (valueForm.ShowDialog() == DialogResult.OK) { - var form = new ObjectAnalyzerForm(_game, file.Data, int.Parse(valueForm.Result)); - form.Text += $" - \"{_game.GetFileName(file.VRomStart)}\" ({file.VRomStart:X8}-{file.VRomEnd:X8})"; + var form = new ObjectAnalyzerForm(_game, fileName, file.Data, int.Parse(valueForm.Result)); + form.Text += $" - \"{fileName}\" ({file.VRomStart:X8}-{file.VRomEnd:X8})"; form.Show(); } } diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs b/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs index 638eaa2..fc6bb13 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs +++ b/Z64Utils/Forms/ObjectAnalyzerForm.Designer.cs @@ -29,13 +29,13 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] { + System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(new string[] { "06000000", "-32767, -32767, -32767", "0xFFFF", "-32767, -32767", "255, 255, 255, 255"}, -1); - System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem(new string[] { + System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem(new string[] { "00000000", "cube_vtx", "Vertex"}, -1); @@ -101,21 +101,19 @@ private void InitializeComponent() this.tabControl1.Controls.Add(this.tabPage_vtx); this.tabControl1.Controls.Add(this.tabPage_unknow); this.tabControl1.ItemSize = new System.Drawing.Size(47, 18); - this.tabControl1.Location = new System.Drawing.Point(-1291, 35); - this.tabControl1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabControl1.MinimumSize = new System.Drawing.Size(476, 271); + this.tabControl1.Location = new System.Drawing.Point(377, 27); + this.tabControl1.MinimumSize = new System.Drawing.Size(357, 207); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(2188, 653); + this.tabControl1.Size = new System.Drawing.Size(632, 499); this.tabControl1.TabIndex = 8; // // tabPage_empty // this.tabPage_empty.Location = new System.Drawing.Point(4, 22); - this.tabPage_empty.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_empty.Name = "tabPage_empty"; - this.tabPage_empty.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage_empty.Size = new System.Drawing.Size(2180, 627); + this.tabPage_empty.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_empty.Size = new System.Drawing.Size(624, 473); this.tabPage_empty.TabIndex = 0; this.tabPage_empty.Text = "nothing"; this.tabPage_empty.UseVisualStyleBackColor = true; @@ -124,10 +122,9 @@ private void InitializeComponent() // this.tabPage_text.Controls.Add(this.textBox_holderInfo); this.tabPage_text.Location = new System.Drawing.Point(4, 22); - this.tabPage_text.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_text.Name = "tabPage_text"; - this.tabPage_text.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage_text.Size = new System.Drawing.Size(835, 627); + this.tabPage_text.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_text.Size = new System.Drawing.Size(624, 473); this.tabPage_text.TabIndex = 1; this.tabPage_text.Text = "ucode"; this.tabPage_text.UseVisualStyleBackColor = true; @@ -138,13 +135,12 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.textBox_holderInfo.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.textBox_holderInfo.Location = new System.Drawing.Point(8, 8); - this.textBox_holderInfo.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.textBox_holderInfo.Location = new System.Drawing.Point(6, 6); this.textBox_holderInfo.Multiline = true; this.textBox_holderInfo.Name = "textBox_holderInfo"; this.textBox_holderInfo.ReadOnly = true; this.textBox_holderInfo.ScrollBars = System.Windows.Forms.ScrollBars.Both; - this.textBox_holderInfo.Size = new System.Drawing.Size(821, 602); + this.textBox_holderInfo.Size = new System.Drawing.Size(617, 461); this.textBox_holderInfo.TabIndex = 7; this.textBox_holderInfo.WordWrap = false; // @@ -153,10 +149,9 @@ private void InitializeComponent() this.tabPage_texture.Controls.Add(this.label_textureInfo); this.tabPage_texture.Controls.Add(this.pic_texture); this.tabPage_texture.Location = new System.Drawing.Point(4, 22); - this.tabPage_texture.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_texture.Name = "tabPage_texture"; - this.tabPage_texture.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage_texture.Size = new System.Drawing.Size(835, 627); + this.tabPage_texture.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_texture.Size = new System.Drawing.Size(624, 473); this.tabPage_texture.TabIndex = 2; this.tabPage_texture.Text = "texture"; this.tabPage_texture.UseVisualStyleBackColor = true; @@ -165,10 +160,9 @@ private void InitializeComponent() // this.label_textureInfo.AutoSize = true; this.label_textureInfo.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.label_textureInfo.Location = new System.Drawing.Point(8, 4); - this.label_textureInfo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label_textureInfo.Location = new System.Drawing.Point(6, 3); this.label_textureInfo.Name = "label_textureInfo"; - this.label_textureInfo.Size = new System.Drawing.Size(32, 17); + this.label_textureInfo.Size = new System.Drawing.Size(25, 13); this.label_textureInfo.TabIndex = 1; this.label_textureInfo.Text = "..."; // @@ -179,10 +173,9 @@ private void InitializeComponent() | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.pic_texture.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; - this.pic_texture.Location = new System.Drawing.Point(8, 26); - this.pic_texture.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pic_texture.Location = new System.Drawing.Point(6, 20); this.pic_texture.Name = "pic_texture"; - this.pic_texture.Size = new System.Drawing.Size(823, 585); + this.pic_texture.Size = new System.Drawing.Size(617, 447); this.pic_texture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pic_texture.TabIndex = 0; this.pic_texture.TabStop = false; @@ -191,10 +184,9 @@ private void InitializeComponent() // this.tabPage_vtx.Controls.Add(this.listView_vtx); this.tabPage_vtx.Location = new System.Drawing.Point(4, 22); - this.tabPage_vtx.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_vtx.Name = "tabPage_vtx"; - this.tabPage_vtx.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage_vtx.Size = new System.Drawing.Size(835, 627); + this.tabPage_vtx.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_vtx.Size = new System.Drawing.Size(624, 473); this.tabPage_vtx.TabIndex = 3; this.tabPage_vtx.Text = "vertex"; this.tabPage_vtx.UseVisualStyleBackColor = true; @@ -214,11 +206,10 @@ private void InitializeComponent() this.listView_vtx.FullRowSelect = true; this.listView_vtx.HideSelection = false; this.listView_vtx.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem2}); - this.listView_vtx.Location = new System.Drawing.Point(8, 8); - this.listView_vtx.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + listViewItem3}); + this.listView_vtx.Location = new System.Drawing.Point(6, 6); this.listView_vtx.Name = "listView_vtx"; - this.listView_vtx.Size = new System.Drawing.Size(824, 602); + this.listView_vtx.Size = new System.Drawing.Size(619, 461); this.listView_vtx.TabIndex = 0; this.listView_vtx.UseCompatibleStateImageBehavior = false; this.listView_vtx.View = System.Windows.Forms.View.Details; @@ -252,10 +243,9 @@ private void InitializeComponent() // this.tabPage_unknow.Controls.Add(this.hexBox1); this.tabPage_unknow.Location = new System.Drawing.Point(4, 22); - this.tabPage_unknow.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.tabPage_unknow.Name = "tabPage_unknow"; - this.tabPage_unknow.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.tabPage_unknow.Size = new System.Drawing.Size(835, 627); + this.tabPage_unknow.Padding = new System.Windows.Forms.Padding(3); + this.tabPage_unknow.Size = new System.Drawing.Size(624, 473); this.tabPage_unknow.TabIndex = 4; this.tabPage_unknow.Text = "unknow"; this.tabPage_unknow.UseVisualStyleBackColor = true; @@ -268,12 +258,11 @@ private void InitializeComponent() this.hexBox1.ColumnInfoVisible = true; this.hexBox1.Font = new System.Drawing.Font("Consolas", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); this.hexBox1.LineInfoVisible = true; - this.hexBox1.Location = new System.Drawing.Point(8, 8); - this.hexBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.hexBox1.Location = new System.Drawing.Point(6, 6); this.hexBox1.Name = "hexBox1"; this.hexBox1.ReadOnly = true; this.hexBox1.ShadowSelectionColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(60)))), ((int)(((byte)(188)))), ((int)(((byte)(255))))); - this.hexBox1.Size = new System.Drawing.Size(829, 603); + this.hexBox1.Size = new System.Drawing.Size(622, 461); this.hexBox1.StringViewVisible = true; this.hexBox1.TabIndex = 1; this.hexBox1.UseFixedBytesPerLine = true; @@ -292,12 +281,11 @@ private void InitializeComponent() this.listView_map.FullRowSelect = true; this.listView_map.HideSelection = false; this.listView_map.Items.AddRange(new System.Windows.Forms.ListViewItem[] { - listViewItem5}); - this.listView_map.Location = new System.Drawing.Point(16, 35); - this.listView_map.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + listViewItem4}); + this.listView_map.Location = new System.Drawing.Point(12, 27); this.listView_map.MultiSelect = false; this.listView_map.Name = "listView_map"; - this.listView_map.Size = new System.Drawing.Size(477, 651); + this.listView_map.Size = new System.Drawing.Size(359, 499); this.listView_map.TabIndex = 7; this.listView_map.UseCompatibleStateImageBehavior = false; this.listView_map.View = System.Windows.Forms.View.Details; @@ -320,7 +308,6 @@ private void InitializeComponent() // // contextMenuStrip1 // - this.contextMenuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.openInDlistViewerMenuItem, this.addToDlistViewerMenuItem, @@ -328,54 +315,52 @@ private void InitializeComponent() this.addToolStripMenuItem, this.deleteToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; - this.contextMenuStrip1.Size = new System.Drawing.Size(241, 124); + this.contextMenuStrip1.Size = new System.Drawing.Size(203, 114); // // openInDlistViewerMenuItem // this.openInDlistViewerMenuItem.Name = "openInDlistViewerMenuItem"; - this.openInDlistViewerMenuItem.Size = new System.Drawing.Size(240, 24); + this.openInDlistViewerMenuItem.Size = new System.Drawing.Size(202, 22); this.openInDlistViewerMenuItem.Text = "Open In Dlist Viewer"; this.openInDlistViewerMenuItem.Click += new System.EventHandler(this.openInDisplayViewerMenuItem_Click); // // addToDlistViewerMenuItem // this.addToDlistViewerMenuItem.Name = "addToDlistViewerMenuItem"; - this.addToDlistViewerMenuItem.Size = new System.Drawing.Size(240, 24); + this.addToDlistViewerMenuItem.Size = new System.Drawing.Size(202, 22); this.addToDlistViewerMenuItem.Text = "Add to Dlist Viewer"; this.addToDlistViewerMenuItem.Click += new System.EventHandler(this.addToDisplayViewerMenuItem_Click); // // openSkeletonViewerMenuItem // this.openSkeletonViewerMenuItem.Name = "openSkeletonViewerMenuItem"; - this.openSkeletonViewerMenuItem.Size = new System.Drawing.Size(240, 24); + this.openSkeletonViewerMenuItem.Size = new System.Drawing.Size(202, 22); this.openSkeletonViewerMenuItem.Text = "Open in Skeleton Viewer"; this.openSkeletonViewerMenuItem.Click += new System.EventHandler(this.openSkeletonViewerMenuItem_Click); // // addToolStripMenuItem // this.addToolStripMenuItem.Name = "addToolStripMenuItem"; - this.addToolStripMenuItem.Size = new System.Drawing.Size(240, 24); + this.addToolStripMenuItem.Size = new System.Drawing.Size(202, 22); this.addToolStripMenuItem.Text = "Add"; this.addToolStripMenuItem.Click += new System.EventHandler(this.addToolStripMenuItem_Click); // // deleteToolStripMenuItem // this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem"; - this.deleteToolStripMenuItem.Size = new System.Drawing.Size(240, 24); + this.deleteToolStripMenuItem.Size = new System.Drawing.Size(202, 22); this.deleteToolStripMenuItem.Text = "Delete"; this.deleteToolStripMenuItem.Click += new System.EventHandler(this.deleteToolStripMenuItem_Click); // // menuStrip1 // - this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.toolsToolStripMenuItem, this.settingsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Padding = new System.Windows.Forms.Padding(8, 3, 0, 3); - this.menuStrip1.Size = new System.Drawing.Size(1345, 30); + this.menuStrip1.Size = new System.Drawing.Size(1009, 24); this.menuStrip1.TabIndex = 9; this.menuStrip1.Text = "menuStrip1"; // @@ -384,14 +369,14 @@ private void InitializeComponent() this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.exportCToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); this.fileToolStripMenuItem.Text = "File"; this.fileToolStripMenuItem.Visible = false; // // exportCToolStripMenuItem // this.exportCToolStripMenuItem.Name = "exportCToolStripMenuItem"; - this.exportCToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.exportCToolStripMenuItem.Size = new System.Drawing.Size(119, 22); this.exportCToolStripMenuItem.Text = "Export C"; this.exportCToolStripMenuItem.Click += new System.EventHandler(this.exportCToolStripMenuItem_Click); // @@ -405,14 +390,14 @@ private void InitializeComponent() this.importXMLZAPDToolStripMenuItem, this.resetToolStripMenuItem}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; - this.toolsToolStripMenuItem.Size = new System.Drawing.Size(76, 24); + this.toolsToolStripMenuItem.Size = new System.Drawing.Size(62, 20); this.toolsToolStripMenuItem.Text = "Analysis"; // // findDlistsToolStripMenuItem // this.findDlistsToolStripMenuItem.Name = "findDlistsToolStripMenuItem"; this.findDlistsToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+F"; - this.findDlistsToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.findDlistsToolStripMenuItem.Size = new System.Drawing.Size(220, 22); this.findDlistsToolStripMenuItem.Text = "Find Dlists"; this.findDlistsToolStripMenuItem.Click += new System.EventHandler(this.findDlistsToolStripMenuItem_Click); // @@ -420,28 +405,28 @@ private void InitializeComponent() // this.analyzeDlistsToolStripMenuItem.Name = "analyzeDlistsToolStripMenuItem"; this.analyzeDlistsToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+Shift+A"; - this.analyzeDlistsToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.analyzeDlistsToolStripMenuItem.Size = new System.Drawing.Size(220, 22); this.analyzeDlistsToolStripMenuItem.Text = "Analyze Dlists"; this.analyzeDlistsToolStripMenuItem.Click += new System.EventHandler(this.analyzeDlistsToolStripMenuItem_Click); // // importJSONToolStripMenuItem // this.importJSONToolStripMenuItem.Name = "importJSONToolStripMenuItem"; - this.importJSONToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.importJSONToolStripMenuItem.Size = new System.Drawing.Size(220, 22); this.importJSONToolStripMenuItem.Text = "Import JSON"; this.importJSONToolStripMenuItem.Click += new System.EventHandler(this.importJSONToolStripMenuItem_Click); // // exportJSONToolStripMenuItem // this.exportJSONToolStripMenuItem.Name = "exportJSONToolStripMenuItem"; - this.exportJSONToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.exportJSONToolStripMenuItem.Size = new System.Drawing.Size(220, 22); this.exportJSONToolStripMenuItem.Text = "Export JSON"; this.exportJSONToolStripMenuItem.Click += new System.EventHandler(this.exportJSONToolStripMenuItem_Click); // // resetToolStripMenuItem // this.resetToolStripMenuItem.Name = "resetToolStripMenuItem"; - this.resetToolStripMenuItem.Size = new System.Drawing.Size(276, 26); + this.resetToolStripMenuItem.Size = new System.Drawing.Size(220, 22); this.resetToolStripMenuItem.Text = "Reset"; this.resetToolStripMenuItem.Click += new System.EventHandler(this.resetToolStripMenuItem_Click); // @@ -450,13 +435,13 @@ private void InitializeComponent() this.settingsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.disassemblySettingsToolStripMenuItem}); this.settingsToolStripMenuItem.Name = "settingsToolStripMenuItem"; - this.settingsToolStripMenuItem.Size = new System.Drawing.Size(76, 24); + this.settingsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.settingsToolStripMenuItem.Text = "Settings"; // // disassemblySettingsToolStripMenuItem // this.disassemblySettingsToolStripMenuItem.Name = "disassemblySettingsToolStripMenuItem"; - this.disassemblySettingsToolStripMenuItem.Size = new System.Drawing.Size(231, 26); + this.disassemblySettingsToolStripMenuItem.Size = new System.Drawing.Size(184, 22); this.disassemblySettingsToolStripMenuItem.Text = "Disassembly Settings"; this.disassemblySettingsToolStripMenuItem.Click += new System.EventHandler(this.disassemblySettingsToolStripMenuItem_Click); // @@ -473,16 +458,15 @@ private void InitializeComponent() // // ObjectAnalyzerForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 17F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1345, 690); + this.ClientSize = new System.Drawing.Size(1009, 528); this.Controls.Add(this.tabControl1); this.Controls.Add(this.listView_map); this.Controls.Add(this.menuStrip1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.KeyPreview = true; this.MainMenuStrip = this.menuStrip1; - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "ObjectAnalyzerForm"; this.Text = "Object Analyzer"; this.tabControl1.ResumeLayout(false); diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.cs b/Z64Utils/Forms/ObjectAnalyzerForm.cs index 7e1652c..c5aca19 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.cs +++ b/Z64Utils/Forms/ObjectAnalyzerForm.cs @@ -20,9 +20,10 @@ public partial class ObjectAnalyzerForm : MicrosoftFontForm byte[] _data; Z64Object _obj; int _segment; + string _fileName; Z64Game _game; - public ObjectAnalyzerForm(Z64Game game, byte[] data, int segmentId) + public ObjectAnalyzerForm(Z64Game game, string fileName, byte[] data, int segmentId) { InitializeComponent(); @@ -34,6 +35,7 @@ public ObjectAnalyzerForm(Z64Game game, byte[] data, int segmentId) _data = data; _obj = new Z64Object(_data); _segment = segmentId; + _fileName = fileName; _game = game; tabControl1.ItemSize = new Size(0, 1); @@ -576,9 +578,38 @@ private void importXMLZAPDToolStripMenuItem_Click(object sender, EventArgs e) if (openFileDialog1.ShowDialog() == DialogResult.OK) { string xml = File.ReadAllText(openFileDialog1.FileName); - _obj = Z64Object.FromXmlZAPD(xml); - _obj.SetData(_data); - UpdateMap(); + StringWriter warnings = new StringWriter(); + Z64Object newObj = null; + + try + { + newObj = Z64Object.FromXmlZAPD(xml, _fileName, _data, warnings); + } + catch (FileFormatException ex) + { + warnings.WriteLine(); + warnings.WriteLine("The XML is not a ZAPD-compatible XML file:"); + warnings.WriteLine(ex.Message); + } + catch (NotImplementedException ex) + { + warnings.WriteLine(); + warnings.WriteLine("The XML uses features that aren't implemented yet:"); + warnings.WriteLine(ex.Message); + } + + string warningsStr = warnings.ToString(); + if (warningsStr.Length != 0) + { + TextForm form = new TextForm(SystemIcons.Warning, "Warning", warningsStr); + form.ShowDialog(); + } + + if (newObj != null) + { + _obj = newObj; + UpdateMap(); + } } } } diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index ac4cb92..46cb196 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -7,6 +7,7 @@ using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; +using System.Xml; using N64; using F3DZEX; using Syroot.BinaryData; @@ -1130,10 +1131,251 @@ public static Z64Object FromJson(string json) } return obj; } - internal static Z64Object FromXmlZAPD(string xml) + internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, StringWriter warnings) { - throw new NotImplementedException(); + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + if (doc.ChildNodes.Count != 1) + throw new FileFormatException($"Expected only 1 node at root level, not {doc.ChildNodes.Count}"); + + XmlNode root = doc.FirstChild; + if (root.Name != "Root") + throw new FileFormatException($"Expected the node at root level to be \"Root\", not \"{root.Name}\""); + if (root.ChildNodes.Count == 0) + throw new FileFormatException("Expected the Root node to have at least 1 child, not 0"); + + XmlNode file = null; + if (root.ChildNodes.Count == 1) + { + file = root.FirstChild; + if (file.Name != "File") + throw new FileFormatException($"Expected the child node of Root to be \"File\", not \"{file.Name}\""); + if (file.Attributes["Name"] == null) + throw new FileFormatException("The File node does not set a Name attribute"); + string fileNodeFileName = file.Attributes["Name"].InnerText; + if (fileNodeFileName != fileName) + warnings.WriteLine($"There is only one File node but its name is {fileNodeFileName}, not {fileName}. Using it regardless."); + } + else + { + foreach (XmlNode candidateFile in root.ChildNodes) + { + if (candidateFile.Name != "File") + throw new FileFormatException($"Expected all child nodes of Root to be \"File\", but one is \"{file.Name}\""); + if (candidateFile.Attributes["Name"] == null) + throw new FileFormatException("A File node does not set a Name attribute"); + if (candidateFile.Attributes["Name"].InnerText == fileName) + { + if (file != null) + throw new FileFormatException($"There are several File nodes with the Name attribute \"{fileName}\""); + file = candidateFile; + } + } + } + + if (file == null) + throw new FileFormatException($"Found no File node with the Name attribute \"{fileName}\""); + + System.ComponentModel.Int32Converter int32Converter = new System.ComponentModel.Int32Converter(); + Func parseIntSmart = str => (int)int32Converter.ConvertFromString(str); + + Z64Object obj = new Z64Object(); + List texHolders = new List(); + List deferredTextureNodes = new List(); + foreach (XmlNode resource in file) + { + if (resource is XmlComment) + continue; + switch (resource.Name) + { + case "Texture": + { + string fmtStr = resource.Attributes["Format"].InnerText; + fmtStr = fmtStr.ToUpper(); + if (fmtStr == "RGB5A1") + fmtStr = "RGBA16"; + N64TexFormat fmt = Enum.Parse(fmtStr); + if (fmt == N64TexFormat.CI4 || fmt == N64TexFormat.CI8) + { + deferredTextureNodes.Add(resource); + } + else + { + int w = Int32.Parse(resource.Attributes["Width"].InnerText); + int h = Int32.Parse(resource.Attributes["Height"].InnerText); + string name = resource.Attributes["Name"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + TextureHolder texHolder = obj.AddTexture(w, h, fmt, name, offset); + texHolders.Add(texHolder); + } + break; + } + case "Background": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Blob": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "DList": + { + string name = resource.Attributes["Name"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + int size; + try + { + size = F3DZEX.Command.CmdEncoding.GetDListSize(data, offset); + } + catch (F3DZEX.Command.InvalidF3DZEXOpCodeException ex) + { + warnings.WriteLine($"Could not find the length of DList {name} at 0x{offset:X}"); + warnings.WriteLine(ex.Message); + size = 8; + } + obj.AddDList(size, name, offset); + break; + } + case "Animation": + { + string name = resource.Attributes["Name"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + obj.AddAnimation(name, offset); + break; + } + case "PlayerAnimation": + { + string name = resource.Attributes["Name"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + // todo implement specific holders + // sizeof(LinkAnimationHeader) == 8 + obj.AddUnknow(8, name, offset); + break; + } + case "CurveAnimation": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "LegacyAnimation": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Skeleton": + { + string name = resource.Attributes["Name"].InnerText; + string type = resource.Attributes["Type"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + switch (type) + { + case "Normal": + obj.AddSkeleton(name, offset); + break; + case "Flex": + obj.AddFlexSkeleton(name, offset); + break; + case "Curve": + throw new NotImplementedException($"Unimplemented skeleton type: {type}"); + default: + throw new FileFormatException($"Unknown skeleton type: {type}"); + } + break; + } + case "LimbTable": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Limb": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Symbol": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Collision": + { + string name = resource.Attributes["Name"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + // todo implement specific holders + // sizeof(CollisionHeader) == 0x2C + obj.AddUnknow(0x2C, name, offset); + break; + } + case "Scalar": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Vector": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Vtx": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Mtx": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Cutscene": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + case "Array": + { + string name = resource.Attributes["Name"].InnerText; + string countStr = resource.Attributes["Count"].InnerText; + int count = parseIntSmart(countStr); + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + if (resource.ChildNodes.Count != 1) + throw new FileFormatException($"Expected Array node \"{name}\" to have exactly one child node, not {resource.ChildNodes.Count}"); + + XmlNode arrayElement = resource.FirstChild; + int elementSize; + switch (arrayElement.Name) + { + case "Scalar": + throw new NotImplementedException($"Unimplemented array element: {arrayElement.Name}"); + case "Vector": + { + string type = arrayElement.Attributes["Type"].InnerText; + string dimStr = arrayElement.Attributes["Dimensions"].InnerText; + int dim = parseIntSmart(dimStr); + + int typeSize; + switch (type) + { + case "s16": + typeSize = 2; + break; + case "s32": + typeSize = 4; + break; + case "f32": + typeSize = 4; + break; + default: + throw new FileFormatException($"Unknown array element type: {type}"); + } + elementSize = dim * typeSize; + break; + } + case "Vtx": + throw new NotImplementedException($"Unimplemented array element: {arrayElement.Name}"); + default: + throw new FileFormatException($"Unknown array element: {arrayElement.Name}"); + } + + int size = elementSize * count; + + // todo implement specific holders + obj.AddUnknow(size, name, offset); + break; + } + case "Path": + throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + default: + throw new FileFormatException($"Unknown resource type: {resource.Name}"); + } + } + + // todo deferred textures + + if (obj.GetSize() < data.Length) + obj.AddUnknow(data.Length - obj.GetSize()); + + obj.Entries.RemoveAll(entry => entry.GetSize() == 0 && entry.GetEntryType() == EntryType.Unknown); + + obj.SetData(data); + + return obj; } } From fe989483d2c10efe0faa98d192ac6e90057e4dc9 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 16:35:02 +0200 Subject: [PATCH 03/19] Fix GetDListSize: step 8 bytes per command --- Z64Utils/F3DZEX/Command/CmdEncoding.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Z64Utils/F3DZEX/Command/CmdEncoding.cs b/Z64Utils/F3DZEX/Command/CmdEncoding.cs index dde050d..a1c79bb 100644 --- a/Z64Utils/F3DZEX/Command/CmdEncoding.cs +++ b/Z64Utils/F3DZEX/Command/CmdEncoding.cs @@ -76,15 +76,16 @@ public static int GetDListSize(byte[] ucode, int off = 0) using (MemoryStream ms = new MemoryStream(ucode)) { ms.Position = off; - BitReader br = new BitReader(ms); - while (br.BaseStream.Position < br.BaseStream.Length) + while (ms.Position < ms.Length) { length += 1; - CmdID id = (CmdID)br.ReadByte(); + CmdID id = (CmdID)ms.ReadByte(); if (!DEC_TABLE.ContainsKey(id)) throw new InvalidF3DZEXOpCodeException($"Invalid OpCode : {id:X}"); + ms.Seek(7, SeekOrigin.Current); + if (id == CmdID.G_ENDDL) break; } From fee0f191649af5fadc8d25562a426db512b5c8f1 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 17:14:44 +0200 Subject: [PATCH 04/19] Import CI textures and map the Tlut TextureHolder --- Z64Utils/Z64/Z64Object.cs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 46cb196..996ac07 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1180,7 +1180,7 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, Func parseIntSmart = str => (int)int32Converter.ConvertFromString(str); Z64Object obj = new Z64Object(); - List texHolders = new List(); + Dictionary texturesByOffset = new Dictionary(); List deferredTextureNodes = new List(); foreach (XmlNode resource in file) @@ -1209,7 +1209,7 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, int offset = parseIntSmart(offsetStr); TextureHolder texHolder = obj.AddTexture(w, h, fmt, name, offset); - texHolders.Add(texHolder); + texturesByOffset[offset] = texHolder; } break; } @@ -1366,7 +1366,39 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, } } - // todo deferred textures + foreach (XmlNode resource in deferredTextureNodes) + { + string fmtStr = resource.Attributes["Format"].InnerText; + fmtStr = fmtStr.ToUpper(); + N64TexFormat fmt = Enum.Parse(fmtStr); + int w = Int32.Parse(resource.Attributes["Width"].InnerText); + int h = Int32.Parse(resource.Attributes["Height"].InnerText); + string name = resource.Attributes["Name"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + TextureHolder texHolder = obj.AddTexture(w, h, fmt, name, offset); + + if (resource.Attributes["TlutOffset"] != null) + { + string tlutOffsetStr = resource.Attributes["TlutOffset"].InnerText; + int tlutOffset = parseIntSmart(tlutOffsetStr); + + if (texturesByOffset.ContainsKey(tlutOffset)) + { + TextureHolder tlutHolder = texturesByOffset[tlutOffset]; + if (tlutHolder.Format == N64TexFormat.RGBA16) + texHolder.Tlut = tlutHolder; + else + warnings.WriteLine($"Expected RGBA16 texture format for TLUT of Texture {name}, " + + $"but TlutOffset {tlutOffset:X} is {tlutHolder.Name} and uses format {tlutHolder.Format}"); + } + else + warnings.WriteLine($"TlutOffset {tlutOffset:X} of Texture {name} does not correspond to any non-CI Texture"); + } + else + warnings.WriteLine($"Missing TlutOffset for Texture {name}"); + } if (obj.GetSize() < data.Length) obj.AddUnknow(data.Length - obj.GetSize()); From ca29f58271efa4560a6ff1b45e8c5094ef38aeaa Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 17:15:50 +0200 Subject: [PATCH 05/19] Implement `` (`Type="Standard"` only) --- Z64Utils/Z64/Z64Object.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 996ac07..0266124 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1283,7 +1283,32 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, case "LimbTable": throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); case "Limb": - throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + { + string name = resource.Attributes["Name"].InnerText; + string type = resource.Attributes["Type"].InnerText; + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + switch (type) + { + case "Standard": + { + obj.AddSkeletonLimb(name, offset); + break; + } + case "LOD": + throw new NotImplementedException($"Unimplemented limb type: {type}"); + case "Skin": + throw new NotImplementedException($"Unimplemented limb type: {type}"); + case "Curve": + throw new NotImplementedException($"Unimplemented limb type: {type}"); + case "Legacy": + throw new NotImplementedException($"Unimplemented limb type: {type}"); + default: + throw new FileFormatException($"Unknown limb type: {type}"); + } + break; + } case "Symbol": throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); case "Collision": From c9fe728a74a9784ec95321f43a8865ac2d24742a Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 17:23:01 +0200 Subject: [PATCH 06/19] Check LimbType is Standard for skeletons --- Z64Utils/Z64/Z64Object.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 0266124..6051dae 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1262,9 +1262,23 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, { string name = resource.Attributes["Name"].InnerText; string type = resource.Attributes["Type"].InnerText; + string limbType = resource.Attributes["LimbType"].InnerText; string offsetStr = resource.Attributes["Offset"].InnerText; int offset = parseIntSmart(offsetStr); + switch (limbType) + { + case "Standard": + break; + case "LOD": + case "Skin": + case "Curve": + case "Legacy": + throw new NotImplementedException($"Unimplemented skeleton limb type: {limbType}"); + default: + throw new FileFormatException($"Unknown skeleton limb type: {limbType}"); + } + switch (type) { case "Normal": From ac52bab021805af6c8c07a853932b0c66364e459 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 17:29:09 +0200 Subject: [PATCH 07/19] Implement `` --- Z64Utils/Z64/Z64Object.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 6051dae..531a8a1 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1216,7 +1216,16 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, case "Background": throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); case "Blob": - throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + { + string name = resource.Attributes["Name"].InnerText; + string sizeStr = resource.Attributes["Size"].InnerText; + int size = parseIntSmart(sizeStr); + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + obj.AddUnknow(size, name, offset); + break; + } case "DList": { string name = resource.Attributes["Name"].InnerText; From 1fc48301f9d8a5bc192118408039ca4cb7e4d8a0 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 17:36:10 +0200 Subject: [PATCH 08/19] Implement `` (untested) --- Z64Utils/Z64/Z64Object.cs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 531a8a1..6af52d1 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1304,7 +1304,29 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, break; } case "LimbTable": - throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + { + string name = resource.Attributes["Name"].InnerText; + string limbType = resource.Attributes["LimbType"].InnerText; + string countStr = resource.Attributes["Count"].InnerText; + int count = parseIntSmart(countStr); + string offsetStr = resource.Attributes["Offset"].InnerText; + int offset = parseIntSmart(offsetStr); + + switch (limbType) + { + case "Standard": + break; + case "LOD": + case "Skin": + case "Curve": + case "Legacy": + throw new NotImplementedException($"Unimplemented skeleton limb type: {limbType}"); + default: + throw new FileFormatException($"Unknown skeleton limb type: {limbType}"); + } + obj.AddSkeletonLimbs(count, name, offset); + break; + } case "Limb": { string name = resource.Attributes["Name"].InnerText; From bdedeca759b3739fc2e32e0fdcc56e757dc1046a Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Tue, 24 Aug 2021 17:50:35 +0200 Subject: [PATCH 09/19] Implement `` of `` --- Z64Utils/Z64/Z64Object.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 6af52d1..9471b80 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1388,7 +1388,6 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, throw new FileFormatException($"Expected Array node \"{name}\" to have exactly one child node, not {resource.ChildNodes.Count}"); XmlNode arrayElement = resource.FirstChild; - int elementSize; switch (arrayElement.Name) { case "Scalar": @@ -1414,19 +1413,22 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, default: throw new FileFormatException($"Unknown array element type: {type}"); } - elementSize = dim * typeSize; + + int elementSize = dim * typeSize; + int arraySize = elementSize * count; + + // todo implement specific holders + obj.AddUnknow(arraySize, name, offset); break; } case "Vtx": - throw new NotImplementedException($"Unimplemented array element: {arrayElement.Name}"); + { + obj.AddVertices(count, name, offset); + break; + } default: throw new FileFormatException($"Unknown array element: {arrayElement.Name}"); } - - int size = elementSize * count; - - // todo implement specific holders - obj.AddUnknow(size, name, offset); break; } case "Path": From 1db6a944c6eb6f1a288867f9431ad6a0c8fe7793 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 25 Aug 2021 18:50:22 +0200 Subject: [PATCH 10/19] Add `UnimplementedHolder` (mostly like `UnknowHolder`) This holder is meant for data that doesn't have an adequate holder yet (where the unknown type holder is meant for data which purpose is unknown). It behaves mostly like the unknown type holder, but also allows setting a description string that is shown in the entry type column. Due to issues with Visual Studio Designer I could not add a viewer tab where it could be allowed to show the description string. JSON stuff untested. --- Z64Utils/Forms/ObjectAnalyzerForm.cs | 15 ++++++- Z64Utils/Z64/Z64Object.cs | 59 +++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.cs b/Z64Utils/Forms/ObjectAnalyzerForm.cs index c5aca19..bd5ddf0 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.cs +++ b/Z64Utils/Forms/ObjectAnalyzerForm.cs @@ -104,7 +104,12 @@ private void UpdateMap() { var item = listView_map.Items.Add($"{new SegmentedAddress(_segment, _obj.OffsetOf(entry)).VAddr:X8}"); item.SubItems.Add(entry.Name); - item.SubItems.Add(entry.GetEntryType().ToString()); + string type; + if (entry.GetEntryType() == Z64Object.EntryType.Unimplemented) + type = "XXX " + ((Z64Object.UnimplementedHolder)entry).Description; + else + type = entry.GetEntryType().ToString(); + item.SubItems.Add(type); } listView_map.EndUpdate(); } @@ -290,7 +295,14 @@ private void listView_map_SelectedIndexChanged(object sender, EventArgs e) } case Z64Object.EntryType.FrameData: case Z64Object.EntryType.Unknown: + case Z64Object.EntryType.Unimplemented: { + if (holder.GetEntryType() == Z64Object.EntryType.Unimplemented) + { + string description = ((Z64Object.UnimplementedHolder)holder).Description; + // todo show description + } + tabControl1.SelectedTab = tabPage_unknow; var provider = new DynamicByteProvider(holder.GetData());; @@ -491,6 +503,7 @@ private void exportCToolStripMenuItem_Click(object sender, EventArgs e) break; } case Z64Object.EntryType.Unknown: + case Z64Object.EntryType.Unimplemented: { sw.WriteLine($"u8 {entry.Name}[] = \r\n{{"); diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 9471b80..a96078c 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -44,6 +44,7 @@ public enum EntryType SkeletonLimbs, SkeletonLimb, Unknown, + Unimplemented } public abstract class ObjectHolder @@ -510,6 +511,24 @@ public override void SetData(byte[] data) public override int GetSize() => JointIndices.Length * ENTRY_SIZE; } + public class UnimplementedHolder : ObjectHolder + { + public string Description { get; set; } + public byte[] Data { get; set; } + + public UnimplementedHolder(string name, string description, byte[] data) : base(name) + { + Description = description; + Data = data; + } + + public override EntryType GetEntryType() => EntryType.Unimplemented; + public override byte[] GetData() => Data; + public override void SetData(byte[] data) => Data = data; + public override int GetSize() => Data.Length; + + } + public List Entries { get; set; } public Z64Object() @@ -712,9 +731,15 @@ public DListHolder AddDList(int size, string name = null, int off = -1) public UnknowHolder AddUnknow(int size, string name = null, int off = -1) { if (off == -1) off = GetSize(); - var holder = new UnknowHolder(name?? $"unk_{off:X8}", new byte[size]); + var holder = new UnknowHolder(name ?? $"unk_{off:X8}", new byte[size]); return (UnknowHolder)AddHolder(holder, off); } + public UnimplementedHolder AddUnimplemented(int size, string name = null, string description = null, int off = -1) + { + if (off == -1) off = GetSize(); + var holder = new UnimplementedHolder(name ?? $"unimpl_{off:X8}", description ?? "", new byte[size]); + return (UnimplementedHolder)AddHolder(holder, off); + } public TextureHolder AddTexture(int w, int h, N64TexFormat format, string name = null, int off = -1) { if (off == -1) off = GetSize(); @@ -914,6 +939,12 @@ private class JsonUnknowHolder : JsonObjectHolder { public int Size { get; set; } } + private class JsonUnimplementedHolder : JsonObjectHolder + { + public string Description { get; set; } + public int Size { get; set; } + } + private class JsonUCodeHolder : JsonObjectHolder { public int Size { get; set; } @@ -988,6 +1019,18 @@ public string GetJSON() }); break; } + case EntryType.Unimplemented: + { + var holder = (UnimplementedHolder)iter; + list.Add(new JsonUnimplementedHolder() + { + Name = holder.Name, + Description = holder.Description, + EntryType = holder.GetEntryType(), + Size = holder.GetSize() + }); + break; + } case EntryType.SkeletonLimbs: { var holder = (SkeletonLimbsHolder)iter; @@ -1074,6 +1117,12 @@ public static Z64Object FromJson(string json) obj.AddUnknow(holder.Size, holder.Name); break; } + case EntryType.Unimplemented: + { + var holder = iter.ToObject(); + obj.AddUnimplemented(holder.Size, holder.Name, holder.Description); + break; + } case EntryType.SkeletonHeader: { obj.AddSkeleton(); @@ -1260,7 +1309,7 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, int offset = parseIntSmart(offsetStr); // todo implement specific holders // sizeof(LinkAnimationHeader) == 8 - obj.AddUnknow(8, name, offset); + obj.AddUnimplemented(8, name, "LinkAnimationHeader", offset); break; } case "CurveAnimation": @@ -1361,9 +1410,8 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, string name = resource.Attributes["Name"].InnerText; string offsetStr = resource.Attributes["Offset"].InnerText; int offset = parseIntSmart(offsetStr); - // todo implement specific holders // sizeof(CollisionHeader) == 0x2C - obj.AddUnknow(0x2C, name, offset); + obj.AddUnimplemented(0x2C, name, "CollisionHeader", offset); break; } case "Scalar": @@ -1417,8 +1465,7 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, int elementSize = dim * typeSize; int arraySize = elementSize * count; - // todo implement specific holders - obj.AddUnknow(arraySize, name, offset); + obj.AddUnimplemented(arraySize, name, $"{type}[{count}]", offset); break; } case "Vtx": From 8b396c2bc53ce4ce1d3d17be082ffc39908c70b9 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 25 Aug 2021 18:56:34 +0200 Subject: [PATCH 11/19] "implement" skeleton (all types) using LOD limbs with UnimplementedHolder --- Z64Utils/Z64/Z64Object.cs | 44 ++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index a96078c..b1db934 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1324,11 +1324,40 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, string offsetStr = resource.Attributes["Offset"].InnerText; int offset = parseIntSmart(offsetStr); + switch (type) + { + case "Normal": + case "Flex": + case "Curve": + break; + default: + throw new FileFormatException($"Unknown skeleton type: {type}"); + } + switch (limbType) { case "Standard": - break; + { + switch (type) + { + case "Normal": + obj.AddSkeleton(name, offset); + break; + case "Flex": + obj.AddFlexSkeleton(name, offset); + break; + case "Curve": + throw new NotImplementedException($"Unimplemented skeleton type: {type}"); + } + break; + } case "LOD": + { + // SkeletonHeader ? + // sizeof(SkeletonHeader) == 0x8 + obj.AddUnimplemented(0x8, name, "SkeletonHeader (LOD limbs)", offset); + break; + } case "Skin": case "Curve": case "Legacy": @@ -1337,19 +1366,6 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, throw new FileFormatException($"Unknown skeleton limb type: {limbType}"); } - switch (type) - { - case "Normal": - obj.AddSkeleton(name, offset); - break; - case "Flex": - obj.AddFlexSkeleton(name, offset); - break; - case "Curve": - throw new NotImplementedException($"Unimplemented skeleton type: {type}"); - default: - throw new FileFormatException($"Unknown skeleton type: {type}"); - } break; } case "LimbTable": From 942c74da2ddc85bfa56e5c3c6bfb9090f6730f4e Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 25 Aug 2021 18:57:08 +0200 Subject: [PATCH 12/19] "implement" lod limbs with UnimplementedHolder --- Z64Utils/Z64/Z64Object.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index b1db934..1c2edcb 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1407,7 +1407,11 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, break; } case "LOD": - throw new NotImplementedException($"Unimplemented limb type: {type}"); + { + // sizeof(LodLimb) == 0x10 + obj.AddUnimplemented(0x10, name, "LodLimb", offset); + break; + } case "Skin": throw new NotImplementedException($"Unimplemented limb type: {type}"); case "Curve": From 7e4d2d1b25da75d6409c38dc65c08b5b69896e32 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Wed, 25 Aug 2021 19:09:55 +0200 Subject: [PATCH 13/19] Fix Array of Vector typing in UnimplementedHolder description --- Z64Utils/Z64/Z64Object.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 1c2edcb..899704e 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1485,7 +1485,7 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, int elementSize = dim * typeSize; int arraySize = elementSize * count; - obj.AddUnimplemented(arraySize, name, $"{type}[{count}]", offset); + obj.AddUnimplemented(arraySize, name, $"{type}[{count}][{dim}]", offset); break; } case "Vtx": From f567f51ca09cd3988ca7c2b25bbe703950ddf7ef Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Thu, 26 Aug 2021 10:01:36 +0200 Subject: [PATCH 14/19] Fix `Limb` import, use `LimbType` not `Type` --- Z64Utils/Z64/Z64Object.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 899704e..0510796 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1395,7 +1395,7 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, case "Limb": { string name = resource.Attributes["Name"].InnerText; - string type = resource.Attributes["Type"].InnerText; + string type = resource.Attributes["LimbType"].InnerText; string offsetStr = resource.Attributes["Offset"].InnerText; int offset = parseIntSmart(offsetStr); From 1bee40ffea0accdeb344f124b788647617d677ab Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Thu, 26 Aug 2021 12:43:20 +0200 Subject: [PATCH 15/19] "Implement" Skin Skeleton and Limb (`UnimplementedHolder`) --- Z64Utils/Z64/Z64Object.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 0510796..2ff68ee 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1359,6 +1359,11 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, break; } case "Skin": + { + // sizeof(SkeletonHeader) == 0x8 + obj.AddUnimplemented(0x8, name, "SkeletonHeader (Skin limbs)", offset); + break; + } case "Curve": case "Legacy": throw new NotImplementedException($"Unimplemented skeleton limb type: {limbType}"); @@ -1413,7 +1418,11 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, break; } case "Skin": - throw new NotImplementedException($"Unimplemented limb type: {type}"); + { + // sizeof(SkinLimb) == 0x10 + obj.AddUnimplemented(0x10, name, "SkinLimb", offset); + break; + } case "Curve": throw new NotImplementedException($"Unimplemented limb type: {type}"); case "Legacy": From 939d695feb711fb48fd042e8124382505eaef838 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Thu, 26 Aug 2021 14:48:31 +0200 Subject: [PATCH 16/19] Revert resx changes made by Visual Studio Designer --- Z64Utils/Forms/ObjectAnalyzerForm.resx | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Z64Utils/Forms/ObjectAnalyzerForm.resx b/Z64Utils/Forms/ObjectAnalyzerForm.resx index 1718682..6817475 100644 --- a/Z64Utils/Forms/ObjectAnalyzerForm.resx +++ b/Z64Utils/Forms/ObjectAnalyzerForm.resx @@ -57,20 +57,8 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - - - 203, 17 - - - 338, 17 - - - 500, 17 - - - + + AAABAAUAEBAAAAEAIABoBAAAVgAAABgYAAABACAAiAkAAL4EAAAgIAAAAQAgAKgQAABGDgAAMDAAAAEA IACoJQAA7h4AAAAAAAABACAAYnMAAJZEAAAoAAAAEAAAACAAAAABACAAAAAAAAAEAADCDgAAwg4AAAAA From 783cd2bf410430f382536a03ba3bba4609418acf Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Sun, 29 Aug 2021 14:29:30 +0200 Subject: [PATCH 17/19] Implement `Offset` being optional and default to end offset of last-added resource See https://github.com/zeldaret/ZAPD/issues/171 --- Z64Utils/Z64/Z64Object.cs | 86 ++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 2ff68ee..c2af2d1 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1232,10 +1232,28 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, Dictionary texturesByOffset = new Dictionary(); List deferredTextureNodes = new List(); + int prevResourceEndOffset = 0; + foreach (XmlNode resource in file) { if (resource is XmlComment) continue; + + // offset is optional and defaults to the end of the previously added resource. + // See ZAPD issue #171 + string offsetStr = resource.Attributes["Offset"]?.InnerText; + int offset; + if (offsetStr != null) + offset = parseIntSmart(offsetStr); + else + offset = prevResourceEndOffset; + + // resourceHolder is expected to hold the newly created ObjectHolder for this resource. + // if no holder is created yet (eg deferred CI texture holders) resourceSize should be set instead + // this is used to compute prevResourceEndOffset for the next resource (see after the switch) + int resourceSize = -1; + ObjectHolder resourceHolder = null; + switch (resource.Name) { case "Texture": @@ -1245,20 +1263,24 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, if (fmtStr == "RGB5A1") fmtStr = "RGBA16"; N64TexFormat fmt = Enum.Parse(fmtStr); + + int w = Int32.Parse(resource.Attributes["Width"].InnerText); + int h = Int32.Parse(resource.Attributes["Height"].InnerText); + if (fmt == N64TexFormat.CI4 || fmt == N64TexFormat.CI8) { deferredTextureNodes.Add(resource); + + resourceSize = N64Texture.GetTexSize(w * h, fmt); } else { - int w = Int32.Parse(resource.Attributes["Width"].InnerText); - int h = Int32.Parse(resource.Attributes["Height"].InnerText); string name = resource.Attributes["Name"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); TextureHolder texHolder = obj.AddTexture(w, h, fmt, name, offset); texturesByOffset[offset] = texHolder; + + resourceHolder = texHolder; } break; } @@ -1269,17 +1291,13 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, string name = resource.Attributes["Name"].InnerText; string sizeStr = resource.Attributes["Size"].InnerText; int size = parseIntSmart(sizeStr); - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); - obj.AddUnknow(size, name, offset); + resourceHolder = obj.AddUnknow(size, name, offset); break; } case "DList": { string name = resource.Attributes["Name"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); int size; try { @@ -1291,25 +1309,21 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, warnings.WriteLine(ex.Message); size = 8; } - obj.AddDList(size, name, offset); + resourceHolder = obj.AddDList(size, name, offset); break; } case "Animation": { string name = resource.Attributes["Name"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); - obj.AddAnimation(name, offset); + resourceHolder = obj.AddAnimation(name, offset); break; } case "PlayerAnimation": { string name = resource.Attributes["Name"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); // todo implement specific holders // sizeof(LinkAnimationHeader) == 8 - obj.AddUnimplemented(8, name, "LinkAnimationHeader", offset); + resourceHolder = obj.AddUnimplemented(8, name, "LinkAnimationHeader", offset); break; } case "CurveAnimation": @@ -1321,8 +1335,6 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, string name = resource.Attributes["Name"].InnerText; string type = resource.Attributes["Type"].InnerText; string limbType = resource.Attributes["LimbType"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); switch (type) { @@ -1341,10 +1353,10 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, switch (type) { case "Normal": - obj.AddSkeleton(name, offset); + resourceHolder = obj.AddSkeleton(name, offset); break; case "Flex": - obj.AddFlexSkeleton(name, offset); + resourceHolder = obj.AddFlexSkeleton(name, offset); break; case "Curve": throw new NotImplementedException($"Unimplemented skeleton type: {type}"); @@ -1355,13 +1367,13 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, { // SkeletonHeader ? // sizeof(SkeletonHeader) == 0x8 - obj.AddUnimplemented(0x8, name, "SkeletonHeader (LOD limbs)", offset); + resourceHolder = obj.AddUnimplemented(0x8, name, "SkeletonHeader (LOD limbs)", offset); break; } case "Skin": { // sizeof(SkeletonHeader) == 0x8 - obj.AddUnimplemented(0x8, name, "SkeletonHeader (Skin limbs)", offset); + resourceHolder = obj.AddUnimplemented(0x8, name, "SkeletonHeader (Skin limbs)", offset); break; } case "Curve": @@ -1379,8 +1391,6 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, string limbType = resource.Attributes["LimbType"].InnerText; string countStr = resource.Attributes["Count"].InnerText; int count = parseIntSmart(countStr); - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); switch (limbType) { @@ -1394,33 +1404,31 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, default: throw new FileFormatException($"Unknown skeleton limb type: {limbType}"); } - obj.AddSkeletonLimbs(count, name, offset); + resourceHolder = obj.AddSkeletonLimbs(count, name, offset); break; } case "Limb": { string name = resource.Attributes["Name"].InnerText; string type = resource.Attributes["LimbType"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); switch (type) { case "Standard": { - obj.AddSkeletonLimb(name, offset); + resourceHolder = obj.AddSkeletonLimb(name, offset); break; } case "LOD": { // sizeof(LodLimb) == 0x10 - obj.AddUnimplemented(0x10, name, "LodLimb", offset); + resourceHolder = obj.AddUnimplemented(0x10, name, "LodLimb", offset); break; } case "Skin": { // sizeof(SkinLimb) == 0x10 - obj.AddUnimplemented(0x10, name, "SkinLimb", offset); + resourceHolder = obj.AddUnimplemented(0x10, name, "SkinLimb", offset); break; } case "Curve": @@ -1437,10 +1445,8 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, case "Collision": { string name = resource.Attributes["Name"].InnerText; - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); // sizeof(CollisionHeader) == 0x2C - obj.AddUnimplemented(0x2C, name, "CollisionHeader", offset); + resourceHolder = obj.AddUnimplemented(0x2C, name, "CollisionHeader", offset); break; } case "Scalar": @@ -1458,8 +1464,6 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, string name = resource.Attributes["Name"].InnerText; string countStr = resource.Attributes["Count"].InnerText; int count = parseIntSmart(countStr); - string offsetStr = resource.Attributes["Offset"].InnerText; - int offset = parseIntSmart(offsetStr); if (resource.ChildNodes.Count != 1) throw new FileFormatException($"Expected Array node \"{name}\" to have exactly one child node, not {resource.ChildNodes.Count}"); @@ -1494,12 +1498,12 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, int elementSize = dim * typeSize; int arraySize = elementSize * count; - obj.AddUnimplemented(arraySize, name, $"{type}[{count}][{dim}]", offset); + resourceHolder = obj.AddUnimplemented(arraySize, name, $"{type}[{count}][{dim}]", offset); break; } case "Vtx": { - obj.AddVertices(count, name, offset); + resourceHolder = obj.AddVertices(count, name, offset); break; } default: @@ -1512,6 +1516,14 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, default: throw new FileFormatException($"Unknown resource type: {resource.Name}"); } + + if (resourceSize < 0) + { + if (resourceHolder == null) + throw new InvalidOperationException("One of resourceSize or resourceHolder should be set."); + resourceSize = resourceHolder.GetSize(); + } + prevResourceEndOffset = offset + resourceSize; } foreach (XmlNode resource in deferredTextureNodes) From fba153bc71236bd9cacf7e33dfac7268cdc67835 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Sun, 29 Aug 2021 16:57:54 +0200 Subject: [PATCH 18/19] Use either `Type` or `LimbType` for `` See https://github.com/zeldaret/ZAPD/issues/172 --- Z64Utils/Z64/Z64Object.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index c2af2d1..3a282ca 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1410,7 +1410,13 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, case "Limb": { string name = resource.Attributes["Name"].InnerText; - string type = resource.Attributes["LimbType"].InnerText; + string type = resource.Attributes["LimbType"]?.InnerText; + if (type == null) + { + type = resource.Attributes["Type"]?.InnerText; + if (type == null) + throw new FileFormatException($"Limb {name} is missing a Type"); + } switch (type) { From 0e1d74584da190e929cb1e3b6aabb71d76e0cb75 Mon Sep 17 00:00:00 2001 From: Dragorn421 Date: Mon, 13 Sep 2021 20:14:31 +0200 Subject: [PATCH 19/19] Implement `` --- Z64Utils/Z64/Z64Object.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Z64Utils/Z64/Z64Object.cs b/Z64Utils/Z64/Z64Object.cs index 3a282ca..7821b4b 100644 --- a/Z64Utils/Z64/Z64Object.cs +++ b/Z64Utils/Z64/Z64Object.cs @@ -1462,7 +1462,11 @@ internal static Z64Object FromXmlZAPD(string xml, string fileName, byte[] data, case "Vtx": throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); case "Mtx": - throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); + { + string name = resource.Attributes["Name"].InnerText; + resourceHolder = obj.AddMtx(1, name, offset); + break; + } case "Cutscene": throw new NotImplementedException($"Unimplemented resource type: {resource.Name}"); case "Array":