diff --git a/pk3DS/Main.Designer.cs b/pk3DS/Main.Designer.cs index ca0195c..44e7bd4 100644 --- a/pk3DS/Main.Designer.cs +++ b/pk3DS/Main.Designer.cs @@ -57,6 +57,7 @@ private void InitializeComponent() this.B_TMHM = new System.Windows.Forms.Button(); this.RTB_Status = new System.Windows.Forms.RichTextBox(); this.L_SubTools = new System.Windows.Forms.Label(); + this.B_Rebuild3DS = new System.Windows.Forms.Button(); this.GB_RomFS.SuspendLayout(); this.GB_ExeFS.SuspendLayout(); this.SuspendLayout(); @@ -251,9 +252,9 @@ private void InitializeComponent() "Deutsch", "Español", "한국"}); - this.CB_Lang.Location = new System.Drawing.Point(321, 40); + this.CB_Lang.Location = new System.Drawing.Point(351, 40); this.CB_Lang.Name = "CB_Lang"; - this.CB_Lang.Size = new System.Drawing.Size(121, 21); + this.CB_Lang.Size = new System.Drawing.Size(91, 21); this.CB_Lang.TabIndex = 4; this.CB_Lang.SelectedIndexChanged += new System.EventHandler(this.changeLanguage); // @@ -261,7 +262,7 @@ private void InitializeComponent() // this.L_Lang.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.L_Lang.AutoSize = true; - this.L_Lang.Location = new System.Drawing.Point(257, 43); + this.L_Lang.Location = new System.Drawing.Point(287, 43); this.L_Lang.Name = "L_Lang"; this.L_Lang.Size = new System.Drawing.Size(58, 13); this.L_Lang.TabIndex = 3; @@ -386,11 +387,24 @@ private void InitializeComponent() this.L_SubTools.Text = "[Misc Tools]"; this.L_SubTools.Click += new System.EventHandler(this.L_SubTools_Click); // + // B_Rebuild3DS + // + this.B_Rebuild3DS.Enabled = false; + this.B_Rebuild3DS.Location = new System.Drawing.Point(190, 39); + this.B_Rebuild3DS.Name = "B_Rebuild3DS"; + this.B_Rebuild3DS.Size = new System.Drawing.Size(80, 23); + this.B_Rebuild3DS.TabIndex = 9; + this.B_Rebuild3DS.Text = "Rebuild .3DS"; + this.B_Rebuild3DS.UseVisualStyleBackColor = true; + this.B_Rebuild3DS.Visible = false; + this.B_Rebuild3DS.Click += new System.EventHandler(this.B_Rebuild3DS_Click); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(454, 422); + this.Controls.Add(this.B_Rebuild3DS); this.Controls.Add(this.L_SubTools); this.Controls.Add(this.RTB_Status); this.Controls.Add(this.GB_ExeFS); @@ -447,5 +461,6 @@ private void InitializeComponent() private System.Windows.Forms.Button B_OPower; private System.Windows.Forms.Label L_SubTools; private System.Windows.Forms.Button B_Wallpaper; + private System.Windows.Forms.Button B_Rebuild3DS; } } \ No newline at end of file diff --git a/pk3DS/Main.cs b/pk3DS/Main.cs index 86261db..9132378 100644 --- a/pk3DS/Main.cs +++ b/pk3DS/Main.cs @@ -21,6 +21,7 @@ using System.Threading; using System.Windows.Forms; using BLZ; +using CTR; namespace pk3DS { @@ -60,6 +61,7 @@ public Main() public static bool oras; public static string RomFSPath; public static string ExeFSPath; + public static string ExHeaderPath; public volatile int threads; private static string[] allGARCs = { "gametext", "storytext", "personal", "trpoke", "trdata", "evolution", "megaevo", "levelup", "eggmove", "item", "move", "maisonpkS", "maisontrS", "maisonpkN", "maisontrN" }; private bool skipBoth; @@ -164,7 +166,7 @@ private void openQuick(string path) } else { - // Check for ROMFS/EXEFS + // Check for ROMFS/EXEFS/EXHEADER RomFSPath = ExeFSPath = null; // Reset string[] folders = Directory.GetDirectories(path); int count = folders.Length; @@ -198,11 +200,30 @@ private void openQuick(string path) changeLanguage(null, null); } + // Enable 3DS Rebuilding options if all files have been found + checkIfExHeader(path); + B_Rebuild3DS.Visible = B_Rebuild3DS.Enabled = + (ExHeaderPath != null && RomFSPath != null && ExeFSPath != null); + // Method finished. SystemSounds.Asterisk.Play(); } } } + private int checkGameType(string[] files) + { + switch (files.Length) + { + case 299: // ORAS + return 1; + case 301: // ORAS Demo + return 1; + case 271: // XY + return 0; + default: // Unknown + return -1; + } + } private bool checkIfRomFS(string path) { string[] top = Directory.GetDirectories(path); @@ -210,20 +231,16 @@ private bool checkIfRomFS(string path) // Check to see if the folder is romfs if (fi.Name == "a") { - string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); - if (files.Length == 299) // ORAS - oras = true; - else if (files.Length == 301) // ORAS demo - oras = true; - else if (files.Length == 271) // XY - oras = false; - else // Allow Override + int game = checkGameType(Directory.GetFiles(path, "*", SearchOption.AllDirectories)); + if (game < 0) // Unknown { DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Loading Override Options:", "Yes - OR/AS" + Environment.NewLine + "No - X/Y" + Environment.NewLine + "Cancel - Abort", "Path:" + Environment.NewLine + path); if (dr == DialogResult.Yes) { oras = true; } else if (dr == DialogResult.No) { oras = false; } else { RomFSPath = null; oras = false; return false; } } + else + oras = (game == 1); RomFSPath = path; backupGARCs(false, allGARCs); return true; @@ -245,6 +262,16 @@ private bool checkIfExeFS(string path) ExeFSPath = path; return true; } + private bool checkIfExHeader(string path) + { + ExHeaderPath = null; + // Input folder path should contain the ExHeader. + string[] files = Directory.GetFiles(path); + foreach (string fp in (from s in files let f = new FileInfo(s) where (f.Name.ToLower().StartsWith("exh") && f.Length == 0x800) select s)) + ExHeaderPath = fp; + + return ExHeaderPath != null; + } private void tabMain_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; @@ -522,6 +549,35 @@ private void B_OPower_Click(object sender, EventArgs e) if (ExeFSPath != null) new OPower().Show(); } + // 3DS Building + private void B_Rebuild3DS_Click(object sender, EventArgs e) + { + // Ensure that the romfs paths are valid + if (checkGameType(Directory.GetFiles(TB_Path.Text, "*", SearchOption.AllDirectories)) >= 0) + { + Util.Error("RomFS file count does not match the default game file count."); + return; + } + if (threads > 0) { Util.Alert("Please wait for all operations to finish first."); return; } + + SaveFileDialog sfd = new SaveFileDialog + { + FileName = "newROM.3ds", + Filter = "Binary File|*.*" + }; + if (sfd.ShowDialog() != DialogResult.OK) return; + string path = sfd.FileName; + + new Thread(() => + { + threads++; + Exheader exh = new Exheader(ExHeaderPath); + CTR.CTR.buildROM(true, "Nintendo", ExeFSPath, RomFSPath, ExHeaderPath, exh.GetSerial(), path, pBar1, + RTB_Status); + threads--; + }).Start(); + } + // Extra Tools private void L_SubTools_Click(object sender, EventArgs e) { diff --git a/pk3DS/Main.resx b/pk3DS/Main.resx index 048068b..06d2205 100644 --- a/pk3DS/Main.resx +++ b/pk3DS/Main.resx @@ -150,6 +150,30 @@ True + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + True