From b4b468d2a631ae5e545623091fd41be4304fd063 Mon Sep 17 00:00:00 2001 From: Kurt Date: Fri, 10 Apr 2015 19:57:59 -0700 Subject: [PATCH] Implement O-Power Editor changing/saving --- pk3DS/Subforms/OPower.Designer.cs | 124 ++++++++++++------------------ pk3DS/Subforms/OPower.cs | 42 +++++++--- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/pk3DS/Subforms/OPower.Designer.cs b/pk3DS/Subforms/OPower.Designer.cs index ec25971..c389c2b 100644 --- a/pk3DS/Subforms/OPower.Designer.cs +++ b/pk3DS/Subforms/OPower.Designer.cs @@ -45,14 +45,13 @@ private void InitializeComponent() this.L_Duration = new System.Windows.Forms.Label(); this.L_Efficacy = new System.Windows.Forms.Label(); this.TB_Mini = new System.Windows.Forms.TextBox(); - this.L_Temp = new System.Windows.Forms.Label(); this.TB_Quality = new System.Windows.Forms.TextBox(); this.NUD_2 = new System.Windows.Forms.NumericUpDown(); - this.NUD_1 = new System.Windows.Forms.NumericUpDown(); - this.NUD_0 = new System.Windows.Forms.NumericUpDown(); - this.L_0 = new System.Windows.Forms.Label(); - this.L_1 = new System.Windows.Forms.Label(); + this.NUD_Usability = new System.Windows.Forms.NumericUpDown(); this.L_2 = new System.Windows.Forms.Label(); + this.CB_SortOrder = new System.Windows.Forms.ComboBox(); + this.L_UsabilityText = new System.Windows.Forms.Label(); + this.L_Usability = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.NUD_PlayerCost)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_OtherCost)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Stage)).BeginInit(); @@ -60,8 +59,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.NUD_Duration)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Efficacy)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_2)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.NUD_1)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.NUD_0)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Usability)).BeginInit(); this.SuspendLayout(); // // RTB @@ -102,7 +100,6 @@ private void InitializeComponent() 0, 0}); this.NUD_PlayerCost.Name = "NUD_PlayerCost"; - this.NUD_PlayerCost.ReadOnly = true; this.NUD_PlayerCost.Size = new System.Drawing.Size(45, 20); this.NUD_PlayerCost.TabIndex = 42; // @@ -116,7 +113,6 @@ private void InitializeComponent() 0, 0}); this.NUD_OtherCost.Name = "NUD_OtherCost"; - this.NUD_OtherCost.ReadOnly = true; this.NUD_OtherCost.Size = new System.Drawing.Size(45, 20); this.NUD_OtherCost.TabIndex = 43; // @@ -130,7 +126,6 @@ private void InitializeComponent() 0, 0}); this.NUD_Stage.Name = "NUD_Stage"; - this.NUD_Stage.ReadOnly = true; this.NUD_Stage.Size = new System.Drawing.Size(45, 20); this.NUD_Stage.TabIndex = 44; // @@ -144,7 +139,6 @@ private void InitializeComponent() 0, 0}); this.NUD_LevelUp.Name = "NUD_LevelUp"; - this.NUD_LevelUp.ReadOnly = true; this.NUD_LevelUp.Size = new System.Drawing.Size(45, 20); this.NUD_LevelUp.TabIndex = 45; // @@ -167,7 +161,6 @@ private void InitializeComponent() 0, 0}); this.NUD_Duration.Name = "NUD_Duration"; - this.NUD_Duration.ReadOnly = true; this.NUD_Duration.Size = new System.Drawing.Size(45, 20); this.NUD_Duration.TabIndex = 47; // @@ -181,7 +174,6 @@ private void InitializeComponent() 0, 0}); this.NUD_Efficacy.Name = "NUD_Efficacy"; - this.NUD_Efficacy.ReadOnly = true; this.NUD_Efficacy.Size = new System.Drawing.Size(45, 20); this.NUD_Efficacy.TabIndex = 48; // @@ -253,15 +245,6 @@ private void InitializeComponent() this.TB_Mini.Size = new System.Drawing.Size(45, 20); this.TB_Mini.TabIndex = 55; // - // L_Temp - // - this.L_Temp.AutoSize = true; - this.L_Temp.Location = new System.Drawing.Point(150, 62); - this.L_Temp.Name = "L_Temp"; - this.L_Temp.Size = new System.Drawing.Size(50, 13); - this.L_Temp.TabIndex = 56; - this.L_Temp.Text = "No Edits."; - // // TB_Quality // this.TB_Quality.Location = new System.Drawing.Point(12, 59); @@ -272,7 +255,7 @@ private void InitializeComponent() // // NUD_2 // - this.NUD_2.Location = new System.Drawing.Point(153, 142); + this.NUD_2.Location = new System.Drawing.Point(203, 137); this.NUD_2.Maximum = new decimal(new int[] { 999, 0, @@ -283,73 +266,67 @@ private void InitializeComponent() this.NUD_2.Size = new System.Drawing.Size(45, 20); this.NUD_2.TabIndex = 58; // - // NUD_1 + // NUD_Usability // - this.NUD_1.Location = new System.Drawing.Point(89, 142); - this.NUD_1.Maximum = new decimal(new int[] { + this.NUD_Usability.Location = new System.Drawing.Point(89, 137); + this.NUD_Usability.Maximum = new decimal(new int[] { 999, 0, 0, 0}); - this.NUD_1.Name = "NUD_1"; - this.NUD_1.ReadOnly = true; - this.NUD_1.Size = new System.Drawing.Size(45, 20); - this.NUD_1.TabIndex = 59; - // - // NUD_0 - // - this.NUD_0.Location = new System.Drawing.Point(25, 142); - this.NUD_0.Maximum = new decimal(new int[] { - 999, - 0, - 0, - 0}); - this.NUD_0.Name = "NUD_0"; - this.NUD_0.ReadOnly = true; - this.NUD_0.Size = new System.Drawing.Size(45, 20); - this.NUD_0.TabIndex = 60; - // - // L_0 - // - this.L_0.AutoSize = true; - this.L_0.Location = new System.Drawing.Point(12, 144); - this.L_0.Name = "L_0"; - this.L_0.Size = new System.Drawing.Size(13, 13); - this.L_0.TabIndex = 61; - this.L_0.Text = "0"; - // - // L_1 - // - this.L_1.AutoSize = true; - this.L_1.Location = new System.Drawing.Point(76, 144); - this.L_1.Name = "L_1"; - this.L_1.Size = new System.Drawing.Size(13, 13); - this.L_1.TabIndex = 62; - this.L_1.Text = "1"; + this.NUD_Usability.Name = "NUD_Usability"; + this.NUD_Usability.Size = new System.Drawing.Size(45, 20); + this.NUD_Usability.TabIndex = 59; // // L_2 // this.L_2.AutoSize = true; - this.L_2.Location = new System.Drawing.Point(140, 144); + this.L_2.Location = new System.Drawing.Point(190, 139); this.L_2.Name = "L_2"; this.L_2.Size = new System.Drawing.Size(13, 13); this.L_2.TabIndex = 63; this.L_2.Text = "2"; // + // CB_SortOrder + // + this.CB_SortOrder.Enabled = false; + this.CB_SortOrder.FormattingEnabled = true; + this.CB_SortOrder.Location = new System.Drawing.Point(153, 59); + this.CB_SortOrder.Name = "CB_SortOrder"; + this.CB_SortOrder.Size = new System.Drawing.Size(45, 21); + this.CB_SortOrder.TabIndex = 64; + // + // L_UsabilityText + // + this.L_UsabilityText.AutoSize = true; + this.L_UsabilityText.Location = new System.Drawing.Point(-2, 159); + this.L_UsabilityText.Name = "L_UsabilityText"; + this.L_UsabilityText.Size = new System.Drawing.Size(167, 13); + this.L_UsabilityText.TabIndex = 65; + this.L_UsabilityText.Text = "254 - Nobody, 0 - Self, 2 - Anyone"; + // + // L_Usability + // + this.L_Usability.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.L_Usability.Location = new System.Drawing.Point(-17, 134); + this.L_Usability.Name = "L_Usability"; + this.L_Usability.Size = new System.Drawing.Size(100, 23); + this.L_Usability.TabIndex = 66; + this.L_Usability.Text = "Usability(?):"; + this.L_Usability.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // // OPower // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(384, 172); + this.Controls.Add(this.L_UsabilityText); + this.Controls.Add(this.CB_SortOrder); this.Controls.Add(this.TB_Name); this.Controls.Add(this.L_2); - this.Controls.Add(this.L_1); - this.Controls.Add(this.L_0); - this.Controls.Add(this.NUD_0); - this.Controls.Add(this.NUD_1); + this.Controls.Add(this.NUD_Usability); this.Controls.Add(this.NUD_2); this.Controls.Add(this.TB_Quality); - this.Controls.Add(this.L_Temp); this.Controls.Add(this.TB_Mini); this.Controls.Add(this.L_Stage); this.Controls.Add(this.L_OtherCost); @@ -366,6 +343,7 @@ private void InitializeComponent() this.Controls.Add(this.L_Efficacy); this.Controls.Add(this.L_Duration); this.Controls.Add(this.L_LevelUp); + this.Controls.Add(this.L_Usability); this.MaximizeBox = false; this.MaximumSize = new System.Drawing.Size(400, 210); this.MinimumSize = new System.Drawing.Size(400, 210); @@ -380,8 +358,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.NUD_Duration)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_Efficacy)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.NUD_2)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.NUD_1)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.NUD_0)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.NUD_Usability)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -406,13 +383,12 @@ private void InitializeComponent() private System.Windows.Forms.Label L_Duration; private System.Windows.Forms.Label L_Efficacy; private System.Windows.Forms.TextBox TB_Mini; - private System.Windows.Forms.Label L_Temp; private System.Windows.Forms.TextBox TB_Quality; private System.Windows.Forms.NumericUpDown NUD_2; - private System.Windows.Forms.NumericUpDown NUD_1; - private System.Windows.Forms.NumericUpDown NUD_0; - private System.Windows.Forms.Label L_0; - private System.Windows.Forms.Label L_1; + private System.Windows.Forms.NumericUpDown NUD_Usability; private System.Windows.Forms.Label L_2; + private System.Windows.Forms.ComboBox CB_SortOrder; + private System.Windows.Forms.Label L_UsabilityText; + private System.Windows.Forms.Label L_Usability; } } \ No newline at end of file diff --git a/pk3DS/Subforms/OPower.cs b/pk3DS/Subforms/OPower.cs index 7036de8..5988168 100644 --- a/pk3DS/Subforms/OPower.cs +++ b/pk3DS/Subforms/OPower.cs @@ -23,8 +23,10 @@ public OPower() // Gather Data for (int i = 0; i < powerData.Length; i++) - powerData[i] = exefsData.Skip(offset + 22*i).Take(22).ToArray(); + powerData[i] = exefsData.Skip(offset + 22 * i).Take(22).ToArray(); + // Prepare View + for (int i = 0; i < 10; i++) CB_SortOrder.Items.Add(i); for (int i = 1; i < powerData.Length; i++) CB_Item.Items.Add(i); CB_Item.SelectedIndex = 0; } @@ -47,7 +49,7 @@ private void getEntry() if (entry < 1) return; // Fetch Data - byte _00 = powerData[entry][0]; + byte quality = powerData[entry][0]; byte _01 = powerData[entry][1]; byte _02 = powerData[entry][2]; byte playerCost = powerData[entry][0x3]; @@ -59,7 +61,7 @@ private void getEntry() int name = BitConverter.ToUInt16(powerData[entry], 0xC); int stage = powerData[entry][0xE]; int lvlup = powerData[entry][0xF]; - int quality = BitConverter.ToUInt16(powerData[entry], 0x10); + int sortOrder = BitConverter.ToUInt16(powerData[entry], 0x10); int efficacy = BitConverter.ToUInt16(powerData[entry], 0x12); byte duration = powerData[entry][0x14]; // sbyte FF = -1 (no duration?) // 0x15 unused? @@ -72,28 +74,50 @@ private void getEntry() TB_Type.Text = powerFlavor[type]; TB_Mini.Text = powerFlavor[mini]; TB_Name.Text = powerFlavor[name]; - TB_Quality.Text = quality.ToString(); // powerFlavor[quality]; + TB_Quality.Text = powerFlavor[1 + quality]; // powerFlavor[quality]; RTB.Text = powerFlavor[desc].Replace("\\n", Environment.NewLine); NUD_Efficacy.Value = efficacy; NUD_Duration.Value = duration; - NUD_0.Value = _00; - NUD_1.Value = _01; + CB_SortOrder.SelectedIndex = sortOrder; + NUD_Usability.Value = _01; NUD_2.Value = _02; } private void setEntry() { if (entry < 1) return; - for (int i = 0; i < powerData.Length; i++) - Array.Copy(powerData[i], 0, exefsData, offset + i * powerData[i].Length, powerData[i].Length); + // Copy back in the edited data sections + byte playerCost = (byte)NUD_PlayerCost.Value; + byte otherCost = (byte)NUD_OtherCost.Value; + byte stage = (byte)NUD_Stage.Value; + byte lvlup = (byte)NUD_LevelUp.Value; + byte duration = (byte)NUD_Duration.Value; + ushort efficacy = (ushort)NUD_Efficacy.Value; + + powerData[entry][0x3] = playerCost; + powerData[entry][0x4] = otherCost; + powerData[entry][0xE] = stage; + powerData[entry][0xF] = lvlup; + + Array.Copy(powerData[entry], 0x12, BitConverter.GetBytes(efficacy), 0, 2); + powerData[entry][0x14] = duration; // sbyte FF = -1 (no duration?) + + byte usability = (byte)NUD_Usability.Value; + + if (usability == 2 || usability == 254 || usability == 0) + powerData[entry][1] = usability; } private void formClosing(object sender, FormClosingEventArgs e) { setEntry(); - File.WriteAllBytes(codebin, exefsData); + // Copy data back to storage + for (int i = 0; i < powerData.Length; i++) + Array.Copy(powerData[i], 0, exefsData, offset + i * powerData[i].Length, powerData[i].Length); + if (ModifierKeys != Keys.Control) + File.WriteAllBytes(codebin, exefsData); } } } \ No newline at end of file