diff --git a/pk3DS/Main.cs b/pk3DS/Main.cs index 70d783c..bbfd5dc 100644 --- a/pk3DS/Main.cs +++ b/pk3DS/Main.cs @@ -62,7 +62,7 @@ private void openQuick(string path) TB_Path.Text = path; GB_Tools.Enabled = true; backupGARCs(false, "gametext", "storytext", "personal", "trpoke", "trdata", "evolution", "megaevo", "levelup", "eggmove", "item", "move", "maisonpkS", "maisontrS", "maisonpkN", "maisontrN"); - + L_Game.Text = (oras) ? "Game Loaded: ORAS" : "Game Loaded: XY"; string exefs = Util.getExeFSFolder(path); changeLanguage(null, null); // Trigger Text Loading @@ -117,33 +117,35 @@ private void B_Maison_Click(object sender, EventArgs e) if (threads > 0) { Util.Alert("Please wait for all operations to finish first."); return; } DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Edit Super Maison instead of Normal Maison?", "Yes = Super, No = Normal, Cancel = Abort"); if (dr == DialogResult.Cancel) return; - + new Thread(() => { - bool super = (dr == DialogResult.Yes); - string mtr = (super) ? "maisontrS" : "maisontrN"; - string mtrGARC = getGARCFileName(mtr); - threadGet(TB_Path.Text + mtrGARC, mtr, true, true); - while (threads > 0) // Let threads complete - Thread.Sleep(50); + bool super = (dr == DialogResult.Yes); + string mtr = (super) ? "maisontrS" : "maisontrN"; + string mtrGARC = getGARCFileName(mtr); + threadGet(TB_Path.Text + mtrGARC, mtr, true, true); + while (threads > 0) // Let threads complete + Thread.Sleep(50); - string mpk = (super) ? "maisonpkS" : "maisontrS"; - string mpkGARC = getGARCFileName(mpk); - threadGet(TB_Path.Text + mpkGARC, mpk, true, true); - while (threads > 0) // Let threads complete - Thread.Sleep(50); + string mpk = (super) ? "maisonpkS" : "maisonpkN"; + string mpkGARC = getGARCFileName(mpk); + threadGet(TB_Path.Text + mpkGARC, mpk, true, true); + while (threads > 0) // Let threads complete + Thread.Sleep(50); - //threadSet(TB_Path.Text + mtrGARC, mtr); - //while (threads > 0) // Let threads complete - // Thread.Sleep(100); - //if (Directory.Exists(mtr)) Directory.Delete(mtr, true); + Invoke((Action)(() => { new Maison(oras, super).ShowDialog(); })); - //threadSet(TB_Path.Text + mpkGARC, mpk); - //while (threads > 0) // Let threads complete - // Thread.Sleep(100); - //if (Directory.Exists(mpk)) Directory.Delete(mpk, true); + threadSet(TB_Path.Text + mtrGARC, mtr); + while (threads > 0) // Let threads complete + Thread.Sleep(100); + if (Directory.Exists(mtr)) Directory.Delete(mtr, true); - }).Start(); + threadSet(TB_Path.Text + mpkGARC, mpk); + while (threads > 0) // Let threads complete + Thread.Sleep(100); + if (Directory.Exists(mpk)) Directory.Delete(mpk, true); + + }).Start(); } private void B_Personal_Click(object sender, EventArgs e) { @@ -385,10 +387,10 @@ public string getGARCFileName(string request) case "megaevo": ans = (oras) ? getFileName(1, 9, 3) : getFileName(2, 1, 6); break; case "personal": ans = (oras) ? getFileName(1, 9, 5) : getFileName(2, 1, 8); break; case "item": ans = (oras) ? getFileName(1, 9, 7) : getFileName(2, 2, 0); break; - case "maisonpkS": ans = (oras) ? getFileName(1, 8, 2) : getFileName(2, 0, 3); break; - case "maisontrS": ans = (oras) ? getFileName(1, 8, 3) : getFileName(2, 0, 4); break; - case "maisonpkN": ans = (oras) ? getFileName(1, 8, 4) : getFileName(2, 0, 5); break; - case "maisontrN": ans = (oras) ? getFileName(1, 8, 5) : getFileName(2, 0, 6); break; + case "maisonpkN": ans = (oras) ? getFileName(1, 8, 2) : getFileName(2, 0, 3); break; + case "maisontrN": ans = (oras) ? getFileName(1, 8, 3) : getFileName(2, 0, 4); break; + case "maisonpkS": ans = (oras) ? getFileName(1, 8, 4) : getFileName(2, 0, 5); break; + case "maisontrS": ans = (oras) ? getFileName(1, 8, 5) : getFileName(2, 0, 6); break; } return ans; } diff --git a/pk3DS/Subforms/Maison.Designer.cs b/pk3DS/Subforms/Maison.Designer.cs index ac872ca..ffbdfc6 100644 --- a/pk3DS/Subforms/Maison.Designer.cs +++ b/pk3DS/Subforms/Maison.Designer.cs @@ -33,6 +33,11 @@ private void InitializeComponent() this.L_Trainer = new System.Windows.Forms.Label(); this.L_Pokemon = new System.Windows.Forms.Label(); this.GB_Trainer = new System.Windows.Forms.GroupBox(); + this.L_Class = new System.Windows.Forms.Label(); + this.B_Remove = new System.Windows.Forms.Button(); + this.B_Set = new System.Windows.Forms.Button(); + this.LB_Choices = new System.Windows.Forms.ListBox(); + this.CB_Class = new System.Windows.Forms.ComboBox(); this.GB_Pokemon = new System.Windows.Forms.GroupBox(); this.PB_PKM = new System.Windows.Forms.PictureBox(); this.CHK_Spe = new System.Windows.Forms.CheckBox(); @@ -54,12 +59,6 @@ private void InitializeComponent() this.CB_Species = new System.Windows.Forms.ComboBox(); this.B_DumpPKs = new System.Windows.Forms.Button(); this.DumpTRs = new System.Windows.Forms.Button(); - this.CB_Class = new System.Windows.Forms.ComboBox(); - this.LB_Choices = new System.Windows.Forms.ListBox(); - this.B_Set = new System.Windows.Forms.Button(); - this.B_View = new System.Windows.Forms.Button(); - this.B_Remove = new System.Windows.Forms.Button(); - this.L_Class = new System.Windows.Forms.Label(); this.GB_Trainer.SuspendLayout(); this.GB_Pokemon.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.PB_PKM)).BeginInit(); @@ -72,6 +71,7 @@ private void InitializeComponent() this.CB_Trainer.Name = "CB_Trainer"; this.CB_Trainer.Size = new System.Drawing.Size(121, 21); this.CB_Trainer.TabIndex = 0; + this.CB_Trainer.SelectedIndexChanged += new System.EventHandler(this.changeTrainer); // // CB_Pokemon // @@ -80,6 +80,7 @@ private void InitializeComponent() this.CB_Pokemon.Name = "CB_Pokemon"; this.CB_Pokemon.Size = new System.Drawing.Size(106, 21); this.CB_Pokemon.TabIndex = 1; + this.CB_Pokemon.SelectedIndexChanged += new System.EventHandler(this.changePokemon); // // L_Trainer // @@ -103,7 +104,6 @@ private void InitializeComponent() // this.GB_Trainer.Controls.Add(this.L_Class); this.GB_Trainer.Controls.Add(this.B_Remove); - this.GB_Trainer.Controls.Add(this.B_View); this.GB_Trainer.Controls.Add(this.B_Set); this.GB_Trainer.Controls.Add(this.LB_Choices); this.GB_Trainer.Controls.Add(this.CB_Class); @@ -114,6 +114,54 @@ private void InitializeComponent() this.GB_Trainer.TabStop = false; this.GB_Trainer.Text = "Trainer Summary"; // + // L_Class + // + this.L_Class.AutoSize = true; + this.L_Class.Location = new System.Drawing.Point(14, 23); + this.L_Class.Name = "L_Class"; + this.L_Class.Size = new System.Drawing.Size(35, 13); + this.L_Class.TabIndex = 5; + this.L_Class.Text = "Class:"; + // + // B_Remove + // + this.B_Remove.Location = new System.Drawing.Point(182, 158); + this.B_Remove.Name = "B_Remove"; + this.B_Remove.Size = new System.Drawing.Size(62, 23); + this.B_Remove.TabIndex = 4; + this.B_Remove.Text = "[X] Delete"; + this.B_Remove.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.B_Remove.UseVisualStyleBackColor = true; + this.B_Remove.Click += new System.EventHandler(this.B_Remove_Click); + // + // B_Set + // + this.B_Set.Location = new System.Drawing.Point(182, 47); + this.B_Set.Name = "B_Set"; + this.B_Set.Size = new System.Drawing.Size(62, 23); + this.B_Set.TabIndex = 2; + this.B_Set.Text = "[<] Set"; + this.B_Set.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.B_Set.UseVisualStyleBackColor = true; + this.B_Set.Click += new System.EventHandler(this.B_Set_Click); + // + // LB_Choices + // + this.LB_Choices.FormattingEnabled = true; + this.LB_Choices.Location = new System.Drawing.Point(9, 47); + this.LB_Choices.Name = "LB_Choices"; + this.LB_Choices.Size = new System.Drawing.Size(167, 134); + this.LB_Choices.TabIndex = 1; + this.LB_Choices.SelectedIndexChanged += new System.EventHandler(this.B_View_Click); + // + // CB_Class + // + this.CB_Class.FormattingEnabled = true; + this.CB_Class.Location = new System.Drawing.Point(55, 20); + this.CB_Class.Name = "CB_Class"; + this.CB_Class.Size = new System.Drawing.Size(121, 21); + this.CB_Class.TabIndex = 0; + // // GB_Pokemon // this.GB_Pokemon.Controls.Add(this.PB_PKM); @@ -300,6 +348,7 @@ private void InitializeComponent() this.CB_Species.Name = "CB_Species"; this.CB_Species.Size = new System.Drawing.Size(106, 21); this.CB_Species.TabIndex = 8; + this.CB_Species.SelectedIndexChanged += new System.EventHandler(this.changeSpecies); // // B_DumpPKs // @@ -307,7 +356,7 @@ private void InitializeComponent() this.B_DumpPKs.Name = "B_DumpPKs"; this.B_DumpPKs.Size = new System.Drawing.Size(75, 23); this.B_DumpPKs.TabIndex = 6; - this.B_DumpPKs.Text = "Dump PK"; + this.B_DumpPKs.Text = "Dump PKs"; this.B_DumpPKs.UseVisualStyleBackColor = true; // // DumpTRs @@ -316,64 +365,9 @@ private void InitializeComponent() this.DumpTRs.Name = "DumpTRs"; this.DumpTRs.Size = new System.Drawing.Size(75, 23); this.DumpTRs.TabIndex = 7; - this.DumpTRs.Text = "Dump TR"; + this.DumpTRs.Text = "Dump TRs"; this.DumpTRs.UseVisualStyleBackColor = true; // - // CB_Class - // - this.CB_Class.FormattingEnabled = true; - this.CB_Class.Location = new System.Drawing.Point(55, 20); - this.CB_Class.Name = "CB_Class"; - this.CB_Class.Size = new System.Drawing.Size(121, 21); - this.CB_Class.TabIndex = 0; - // - // LB_Choices - // - this.LB_Choices.FormattingEnabled = true; - this.LB_Choices.Location = new System.Drawing.Point(9, 47); - this.LB_Choices.Name = "LB_Choices"; - this.LB_Choices.Size = new System.Drawing.Size(167, 134); - this.LB_Choices.TabIndex = 1; - // - // B_Set - // - this.B_Set.Location = new System.Drawing.Point(182, 77); - this.B_Set.Name = "B_Set"; - this.B_Set.Size = new System.Drawing.Size(62, 23); - this.B_Set.TabIndex = 2; - this.B_Set.Text = "[<] Set"; - this.B_Set.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.B_Set.UseVisualStyleBackColor = true; - // - // B_View - // - this.B_View.Location = new System.Drawing.Point(182, 48); - this.B_View.Name = "B_View"; - this.B_View.Size = new System.Drawing.Size(62, 23); - this.B_View.TabIndex = 3; - this.B_View.Text = "[>] View"; - this.B_View.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.B_View.UseVisualStyleBackColor = true; - // - // B_Remove - // - this.B_Remove.Location = new System.Drawing.Point(182, 158); - this.B_Remove.Name = "B_Remove"; - this.B_Remove.Size = new System.Drawing.Size(62, 23); - this.B_Remove.TabIndex = 4; - this.B_Remove.Text = "[X] Delete"; - this.B_Remove.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - this.B_Remove.UseVisualStyleBackColor = true; - // - // L_Class - // - this.L_Class.AutoSize = true; - this.L_Class.Location = new System.Drawing.Point(14, 23); - this.L_Class.Name = "L_Class"; - this.L_Class.Size = new System.Drawing.Size(35, 13); - this.L_Class.TabIndex = 5; - this.L_Class.Text = "Class:"; - // // Maison // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -392,6 +386,7 @@ private void InitializeComponent() this.MinimumSize = new System.Drawing.Size(595, 265); this.Name = "Maison"; this.Text = "Maison Editor"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.formClosing); this.GB_Trainer.ResumeLayout(false); this.GB_Trainer.PerformLayout(); this.GB_Pokemon.ResumeLayout(false); @@ -432,7 +427,6 @@ private void InitializeComponent() private System.Windows.Forms.PictureBox PB_PKM; private System.Windows.Forms.Label L_Class; private System.Windows.Forms.Button B_Remove; - private System.Windows.Forms.Button B_View; private System.Windows.Forms.Button B_Set; private System.Windows.Forms.ListBox LB_Choices; private System.Windows.Forms.ComboBox CB_Class; diff --git a/pk3DS/Subforms/Maison.cs b/pk3DS/Subforms/Maison.cs index ee1da74..3b10826 100644 --- a/pk3DS/Subforms/Maison.cs +++ b/pk3DS/Subforms/Maison.cs @@ -15,36 +15,198 @@ public partial class Maison : Form public Maison(bool rom_oras, bool super) { oras = rom_oras; + + movelist = Main.getText((oras) ? 14 : 13); + itemlist = Main.getText((oras) ? 114 : 96); + specieslist = Main.getText((oras) ? 98 : 80); Array.Resize(ref specieslist, 722); + movelist[0] = specieslist[0] = itemlist[0] = ""; + + trClass = Main.getText((oras) ? 21 : 20); + natures = Main.getText((oras) ? 51 : 47); + trFiles = Directory.GetFiles((super) ? "maisontrS" : "maisontrN"); - pkFiles = Directory.GetFiles((super) ? "maisonpkS" : "maisontrS"); + pkFiles = Directory.GetFiles((super) ? "maisonpkS" : "maisonpkN"); + + int trTXTFile = (oras) ? 153 : 130; + trNames = Main.getText((super) ? trTXTFile : trTXTFile + 1); Array.Resize(ref trNames, trFiles.Length); + InitializeComponent(); + Setup(); } string[] trFiles; + string[] trNames; string[] pkFiles; bool oras = false; + string[] natures; string[] movelist; - string[] trainerlist; + string[] specieslist; + string[] trClass; string[] itemlist; - string[] trnames; - string[] trsay1; - string[] trsay2; - string[] trsay3; + int trEntry = -1; + int pkEntry = -1; + private void Setup() + { + foreach (string s in trClass) CB_Class.Items.Add(s); + foreach (string s in specieslist) CB_Species.Items.Add(s); + foreach (string s in movelist) CB_Move1.Items.Add(s); + foreach (string s in movelist) CB_Move2.Items.Add(s); + foreach (string s in movelist) CB_Move3.Items.Add(s); + foreach (string s in movelist) CB_Move4.Items.Add(s); + foreach (string s in natures) CB_Nature.Items.Add(s); + foreach (string s in itemlist) CB_Item.Items.Add(s); + foreach (string s in trNames) CB_Trainer.Items.Add(s ?? "UNKNOWN"); + for (int i = 0; i < pkFiles.Length; i++) CB_Pokemon.Items.Add(i.ToString()); - int entry = -1; + CB_Trainer.SelectedIndex = 1; + } private void changeTrainer(object sender, EventArgs e) { setTrainer(); - entry = Array.IndexOf(trainerlist, CB_Trainer.Text); + trEntry = CB_Trainer.SelectedIndex; getTrainer(); + if (GB_Trainer.Enabled) + LB_Choices.SelectedIndex = 0; + } + private void changePokemon(object sender, EventArgs e) + { + setPokemon(); + pkEntry = CB_Pokemon.SelectedIndex; + getPokemon(); } private void getTrainer() { - if (entry < 1) return; - byte[] data = File.ReadAllBytes(files[entry]); + if (trEntry < 0) return; + byte[] data = File.ReadAllBytes(trFiles[trEntry]); + // Get + CB_Class.SelectedIndex = BitConverter.ToUInt16(data, 0); + ushort count = BitConverter.ToUInt16(data, 2); + LB_Choices.Items.Clear(); + GB_Trainer.Enabled = (count > 0); + for (int i = 0; i < count; i++) + LB_Choices.Items.Add(BitConverter.ToUInt16(data, 4 + 2 * i).ToString()); } private void setTrainer() { + if (trEntry < 0 || !GB_Trainer.Enabled) return; + // Gather + int trclass = CB_Class.SelectedIndex; + int count = LB_Choices.Items.Count; + byte[] data = new byte[4 + count * 2]; + // Set + Array.Copy(BitConverter.GetBytes((ushort)trclass), 0, data, 0, 2); + Array.Copy(BitConverter.GetBytes((ushort)count), 0, data, 2, 2); + List choices = new List(); + for (int i = 0; i < count; i++) + choices.Add(Convert.ToUInt16(LB_Choices.Items[i].ToString())); + ushort[] choiceList = choices.ToArray(); Array.Sort(choiceList); + + for (int i = 0; i < count; i++) + Array.Copy(BitConverter.GetBytes((ushort)choiceList[i]), 0, data, 4 + 2 * i, 2); + + File.WriteAllBytes(trFiles[trEntry], data); } + private void getPokemon() + { + if (pkEntry < 0) return; + byte[] data = File.ReadAllBytes(pkFiles[pkEntry]); + + // Get + CB_Species.SelectedIndex = BitConverter.ToUInt16(data, 0); + CB_Move1.SelectedIndex = BitConverter.ToUInt16(data, 2); + CB_Move2.SelectedIndex = BitConverter.ToUInt16(data, 4); + CB_Move3.SelectedIndex = BitConverter.ToUInt16(data, 6); + CB_Move4.SelectedIndex = BitConverter.ToUInt16(data, 8); + byte EVs = data[0xA]; + CHK_HP.Checked = ((EVs & 0x01) > 0); + CHK_ATK.Checked = ((EVs & 0x02) > 0); + CHK_DEF.Checked = ((EVs & 0x04) > 0); + CHK_Spe.Checked = ((EVs & 0x08) > 0); + CHK_SpA.Checked = ((EVs & 0x10) > 0); + CHK_SpD.Checked = ((EVs & 0x20) > 0); + CB_Nature.SelectedIndex = data[0xB]; + CB_Item.SelectedIndex = BitConverter.ToUInt16(data, 0xC); + + // Last 2 Bytes are unused. + } + private void setPokemon() + { + if (pkEntry < 0) return; + + // Each File is 16 Bytes. + byte[] data = new byte[0x10]; + + // Set + Array.Copy(BitConverter.GetBytes((ushort)((int)CB_Species.SelectedIndex)), 0, data, 0, 2); + Array.Copy(BitConverter.GetBytes((ushort)((int)CB_Move1.SelectedIndex)), 0, data, 2, 2); + Array.Copy(BitConverter.GetBytes((ushort)((int)CB_Move2.SelectedIndex)), 0, data, 4, 2); + Array.Copy(BitConverter.GetBytes((ushort)((int)CB_Move3.SelectedIndex)), 0, data, 6, 2); + Array.Copy(BitConverter.GetBytes((ushort)((int)CB_Move4.SelectedIndex)), 0, data, 8, 2); + int EVs = 0; + EVs |= (CHK_HP.Checked) ? 1 << 0 : 0; + EVs |= (CHK_ATK.Checked) ? 1 << 1 : 0; + EVs |= (CHK_DEF.Checked) ? 1 << 2 : 0; + EVs |= (CHK_Spe.Checked) ? 1 << 3 : 0; + EVs |= (CHK_SpA.Checked) ? 1 << 4 : 0; + EVs |= (CHK_SpD.Checked) ? 1 << 5 : 0; + data[0xA] = (byte)EVs; + data[0xB] = (byte)((int)CB_Nature.SelectedIndex); + Array.Copy(BitConverter.GetBytes((ushort)((int)CB_Item.SelectedIndex)), 0, data, 0xC, 2); + + // Last 2 Bytes are unused. + File.WriteAllBytes(pkFiles[pkEntry], data); + } + + private void changeSpecies(object sender, EventArgs e) + { + string filename = "_" + CB_Species.SelectedIndex; + PB_PKM.Image = (Bitmap)Properties.Resources.ResourceManager.GetObject(filename); + } + + private void B_Remove_Click(object sender, EventArgs e) + { + if (LB_Choices.SelectedIndex > -1 && GB_Trainer.Enabled) + LB_Choices.Items.RemoveAt(LB_Choices.SelectedIndex); + } + + private void B_Set_Click(object sender, EventArgs e) + { + + if (LB_Choices.SelectedIndex > -1 && GB_Trainer.Enabled) + { + int toAdd = CB_Pokemon.SelectedIndex; + int count = LB_Choices.Items.Count; + List choices = new List(); + for (int i = 0; i < count; i++) + choices.Add(Convert.ToUInt16(LB_Choices.Items[i].ToString())); + + if (Array.IndexOf(choices.ToArray(), toAdd) > 0) return; // Abort if already in the list + else choices.Add((ushort)toAdd); // Add it to the list. + + // Get new list, and sort it. + ushort[] choiceList = choices.ToArray(); Array.Sort(choiceList); + + // Set new list. + LB_Choices.Items.Clear(); + for (int i = 0; i < choiceList.Length; i++) + LB_Choices.Items.Add(choiceList[i].ToString()); + + // Set current index to the one just added. + LB_Choices.SelectedIndex = Array.IndexOf(choiceList, toAdd); + } + } + + private void B_View_Click(object sender, EventArgs e) + { + if (LB_Choices.SelectedIndex > -1 && GB_Trainer.Enabled) + CB_Pokemon.SelectedIndex = Convert.ToUInt16(LB_Choices.Items[LB_Choices.SelectedIndex].ToString()); + } + + private void formClosing(object sender, FormClosingEventArgs e) + { + setTrainer(); + setPokemon(); + } + } } diff --git a/pk3DS/pk3DS.csproj b/pk3DS/pk3DS.csproj index b1da1ae..3e1e8d0 100644 --- a/pk3DS/pk3DS.csproj +++ b/pk3DS/pk3DS.csproj @@ -50,10 +50,10 @@ - + Form - + Maison.cs @@ -136,7 +136,7 @@ Main.cs - + Maison.cs