diff --git a/PokeTool/Handler/FileCopy.cs b/PokeTool/Handler/FileCopy.cs index 85a9260..df9bdb3 100644 --- a/PokeTool/Handler/FileCopy.cs +++ b/PokeTool/Handler/FileCopy.cs @@ -7,35 +7,30 @@ namespace PokeTool.Handler { static class FileCopy { - public static bool CopyAllNecessaryFiles(int game, List files, string pathRomFs, bool croFilesCheck, List croFiles, string codeBin) + public static bool CopyAllNecessaryFiles(Pokemon.Version game, List files, string pathRomFs, List croFiles, string codeBin) { try { var appLocation = AppDomain.CurrentDomain.BaseDirectory; - var titleIdPath = Path.Combine(new string[] { appLocation, GetTitleId(game) }); // change to actual id - var titleIdPathRomFs = Path.Combine(new string[] { appLocation, GetTitleId(game), "romfs" }); // change to actual id + var titleIdPath = Path.Combine(new string[] { appLocation, GetTitleId(game) }); + var titleIdPathRomFs = Path.Combine(new string[] { titleIdPath, "romfs" }); var titleIdPathExeFs = Path.Combine(Directory.GetParent(pathRomFs).FullName, "exefs"); - if (!Directory.Exists(titleIdPathRomFs)) Directory.CreateDirectory(titleIdPathRomFs); foreach (var romFsFile in files) { + var targetFolder = romFsFile.GetDirectory(titleIdPathRomFs); + if (!Directory.Exists(targetFolder)) Directory.CreateDirectory(targetFolder); var origFilePath = romFsFile.GetFullFilePath(pathRomFs); var newFilePath = romFsFile.GetFullFilePath(titleIdPathRomFs); - if (!Directory.Exists(Path.Combine(titleIdPathRomFs, romFsFile.TopFolder))) Directory.CreateDirectory(Path.Combine(titleIdPathRomFs, romFsFile.TopFolder)); - if (!Directory.Exists(Path.Combine(new string[] { titleIdPathRomFs, romFsFile.TopFolder, romFsFile.FirstFolder }))) Directory.CreateDirectory(Path.Combine(new string[] { titleIdPathRomFs, romFsFile.TopFolder, romFsFile.FirstFolder })); - if (!Directory.Exists(Path.Combine(new string[] { titleIdPathRomFs, romFsFile.TopFolder, romFsFile.FirstFolder, romFsFile.SecondFolder }))) Directory.CreateDirectory(Path.Combine(new string[] { titleIdPathRomFs, romFsFile.TopFolder, romFsFile.FirstFolder, romFsFile.SecondFolder })); File.Copy(origFilePath, newFilePath, true); } - // copy cro files if necessary - if (croFilesCheck) + // copy cro files + foreach (var croFile in croFiles) { - foreach (var croFile in croFiles) - { - var origFilePath = Path.Combine(pathRomFs, croFile); - var newFilePath = Path.Combine(titleIdPathRomFs, croFile); - File.Copy(origFilePath, newFilePath, true); - } + var origFilePath = Path.Combine(pathRomFs, croFile); + var newFilePath = Path.Combine(titleIdPathRomFs, croFile); + File.Copy(origFilePath, newFilePath, true); } // copy and rename to 'code.bin' @@ -52,22 +47,26 @@ public static bool CopyAllNecessaryFiles(int game, List files, string } } - private static string GetTitleId(int game) + private static string GetTitleId(Pokemon.Version game) { switch (game) { - case 0: + case Pokemon.Version.X: return "000400000011C400"; - case 1: + case Pokemon.Version.Y: return "000400000011C500"; - case 2: + case Pokemon.Version.OmegaRuby: return "0004000000055D00"; - case 3: + case Pokemon.Version.AlphaSaphire: return "0004000000055E00"; - case 4: + case Pokemon.Version.Sun: return "0004000000164800"; - case 5: + case Pokemon.Version.Moon: return "0004000000175E00"; + case Pokemon.Version.UltraSun: + return "00040000001B5000"; + case Pokemon.Version.UltraMoon: + return "00040000001B5100"; default: return "titleID"; } diff --git a/PokeTool/Handler/FileHandler.cs b/PokeTool/Handler/FileHandler.cs index 3938817..ad36484 100644 --- a/PokeTool/Handler/FileHandler.cs +++ b/PokeTool/Handler/FileHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using PokeTool.Objects; namespace PokeTool.Handler { @@ -31,16 +32,37 @@ public List GetFileListWithoutExtensions() } } - public List GetCroFileList() + public List GetCroFileList(Pokemon.Version version) { try { var files = Directory.GetFiles(Path, "*.cro"); var fileList = new List(); - foreach (var file in files) + + switch (version) { - fileList.Add(System.IO.Path.GetFileName(file)); + case Pokemon.Version.X: + case Pokemon.Version.Y: + case Pokemon.Version.OmegaRuby: + case Pokemon.Version.AlphaSaphire: + var affectedFilesGen6 = new List { "DllField", "DllPoke3Select", "DllBattle" }; + foreach (var file in files) + { + if (affectedFilesGen6.Contains(System.IO.Path.GetFileNameWithoutExtension(file))) fileList.Add(System.IO.Path.GetFileName(file)); + } + break; + case Pokemon.Version.Sun: + case Pokemon.Version.Moon: + case Pokemon.Version.UltraSun: + case Pokemon.Version.UltraMoon: + var affectedFilesGen7 = new List { "Shop" }; + foreach (var file in files) + { + if (affectedFilesGen7.Contains(System.IO.Path.GetFileNameWithoutExtension(file))) fileList.Add(System.IO.Path.GetFileName(file)); + } + break; } + return fileList; } catch (Exception) diff --git a/PokeTool/Objects/Pokemon.cs b/PokeTool/Objects/Pokemon.cs new file mode 100644 index 0000000..83226e7 --- /dev/null +++ b/PokeTool/Objects/Pokemon.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PokeTool.Objects +{ + class Pokemon + { + public enum Version + { + X = 0, + Y = 1, + OmegaRuby = 2, + AlphaSaphire = 3, + Sun = 4, + Moon = 5, + UltraSun = 6, + UltraMoon = 7 + } + + public enum Validation + { + Backup, + RomFs + } + } +} diff --git a/PokeTool/Objects/RomFsFile.cs b/PokeTool/Objects/RomFsFile.cs index f682845..055f9ae 100644 --- a/PokeTool/Objects/RomFsFile.cs +++ b/PokeTool/Objects/RomFsFile.cs @@ -20,9 +20,14 @@ public RomFsFile(string filename) Filename = split[3]; } + public string GetDirectory(string romfsPath) + { + return Path.Combine(new string[] { romfsPath, TopFolder, FirstFolder, SecondFolder }); + } + public string GetFullFilePath(string romfsPath) { - return Path.Combine(new string[] { romfsPath, TopFolder, FirstFolder, SecondFolder, Filename }); + return Path.Combine(new string[] { GetDirectory(romfsPath), Filename }); } private string[] GetFilenameWithPath(string filenameFull) diff --git a/PokeTool/Form1.Designer.cs b/PokeTool/PokeTool.Designer.cs similarity index 98% rename from PokeTool/Form1.Designer.cs rename to PokeTool/PokeTool.Designer.cs index 6e5b7fa..cfa4c14 100644 --- a/PokeTool/Form1.Designer.cs +++ b/PokeTool/PokeTool.Designer.cs @@ -1,6 +1,6 @@ namespace PokeTool { - partial class Form1 + partial class PokeTool { /// /// Required designer variable. @@ -28,7 +28,7 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PokeTool)); this.btnBackup = new System.Windows.Forms.Button(); this.lblBackupValidator = new System.Windows.Forms.Label(); this.btnRomFs = new System.Windows.Forms.Button(); @@ -96,12 +96,14 @@ private void InitializeComponent() this.cboGameSelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cboGameSelection.FormattingEnabled = true; this.cboGameSelection.Items.AddRange(new object[] { - "Omega Ruby", - "Alpha Sapphire", "X", "Y", + "Omega Ruby", + "Alpha Sapphire", "Sun", - "Moon"}); + "Moon", + "Ultra Sun", + "Ultra Moon"}); this.cboGameSelection.Location = new System.Drawing.Point(87, 6); this.cboGameSelection.Name = "cboGameSelection"; this.cboGameSelection.Size = new System.Drawing.Size(102, 21); diff --git a/PokeTool/Form1.cs b/PokeTool/PokeTool.cs similarity index 64% rename from PokeTool/Form1.cs rename to PokeTool/PokeTool.cs index 4d8aab5..d9ba0b2 100644 --- a/PokeTool/Form1.cs +++ b/PokeTool/PokeTool.cs @@ -9,19 +9,19 @@ namespace PokeTool { - public partial class Form1 : Form + public partial class PokeTool : Form { private readonly PathValidator _pathValidator = new PathValidator(); - private bool _checkBackup = false; - private bool _checkRomFs = false; + private bool _checkBackup; + private bool _checkRomFs; private string _pathBackup; private string _pathRomFs; - public Form1() + public PokeTool() { InitializeComponent(); - cboGameSelection.SelectedIndex = 0; + cboGameSelection.SelectedIndex = 6; new ToolTip().SetToolTip(cboGameSelection, "Please select the correct game, otherwise it will not work."); new ToolTip().SetToolTip(btnBackup, "Select the game folder inside the pk3ds backup folder."); new ToolTip().SetToolTip(btnRomFs, "Select the romfs folder from the extracted game files."); @@ -38,19 +38,13 @@ private void btnBackup_Click(object sender, EventArgs e) var path = _pathValidator.FolderSelector(); if (!_pathValidator.CheckBackupFolder(path)) { - lblBackupValidator.Text = @"invalid"; - lblBackupValidator.ForeColor = Color.Red; - _checkBackup = false; - btnStart.Enabled = false; + ChangeValidationState(lblBackupValidator, false, Pokemon.Validation.Backup); if (path != string.Empty) MessageBox.Show(this, @"Please make sure you selected the game path inside the backup folder of pk3ds!", @"Path not valid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - lblBackupValidator.Text = @"valid"; - lblBackupValidator.ForeColor = Color.Green; - _checkBackup = true; + ChangeValidationState(lblBackupValidator, true, Pokemon.Validation.Backup); _pathBackup = path; - if (_checkBackup && _checkRomFs) AllChecksPositive(); } private void btnRomFs_Click(object sender, EventArgs e) @@ -58,31 +52,19 @@ private void btnRomFs_Click(object sender, EventArgs e) var path = _pathValidator.FolderSelector(); if (!_pathValidator.CheckRomFsFolder(path)) { - lblRomFsValidator.Text = @"invalid"; - lblRomFsValidator.ForeColor = Color.Red; - _checkRomFs = false; - btnStart.Enabled = false; + ChangeValidationState(lblRomFsValidator, false, Pokemon.Validation.RomFs); if (path != string.Empty) MessageBox.Show(this, @"Please make sure you selected the correct romfs path!", @"Path not valid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - lblRomFsValidator.Text = @"valid"; - lblRomFsValidator.ForeColor = Color.Green; - _checkRomFs = true; + ChangeValidationState(lblRomFsValidator, true, Pokemon.Validation.RomFs); _pathRomFs = path; - if (_checkBackup && _checkRomFs) AllChecksPositive(); - } - - private void AllChecksPositive() - { - btnStart.Enabled = true; - // add other useful code here } private void btnStart_Click(object sender, EventArgs e) { // check if read - var question = MessageBox.Show(this, $@"Start the process of copying the necessary files?{Environment.NewLine}This might take a few seconds so please be patient.", @"Please choose", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); + var question = MessageBox.Show(this, $@"Start the copy process now?{Environment.NewLine}This might take a few seconds so please be patient.", @"Please choose", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (question != DialogResult.OK) return; // get files in backup folder @@ -102,20 +84,15 @@ private void btnStart_Click(object sender, EventArgs e) } // get cro files - var croFiles = new List(); - var croFilesCheck = false; - // OR:0, AS:1, X:2, Y:3, Su:4, Mo:5 - if (cboGameSelection.SelectedIndex != 4 && cboGameSelection.SelectedIndex != 5) + // X:0, Y:1, OR:2, AS:3, Su:4, Mo:5, US: 6, UM: 7 + var selectedGame = (Pokemon.Version)cboGameSelection.SelectedIndex; + var fileHandlerCro = new FileHandler(_pathRomFs); + var croFiles = fileHandlerCro.GetCroFileList(selectedGame); + + if (croFiles.Count < 1) { - var fileHandlerCro = new FileHandler(_pathRomFs); - var fileListCro = fileHandlerCro.GetCroFileList(); - if (fileListCro.Count < 1) - { - MessageBox.Show(this, @"Error while parsing the .cro files!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - croFiles = fileListCro; - croFilesCheck = true; + MessageBox.Show(this, @"Error while parsing the .cro files!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } // get code.bin @@ -130,9 +107,33 @@ private void btnStart_Click(object sender, EventArgs e) var codeBin = fileListCodeBin.First(); // copy process - var copyResult = FileCopy.CopyAllNecessaryFiles(cboGameSelection.SelectedIndex, romFsFiles, _pathRomFs, croFilesCheck, croFiles, codeBin); + var copyResult = FileCopy.CopyAllNecessaryFiles(selectedGame, romFsFiles, _pathRomFs, croFiles, codeBin); if (copyResult) MessageBox.Show(this, @"Finished copying all files!", @"Done", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); else MessageBox.Show(this, $@"Error while copying the files!{Environment.NewLine}Check error-log.txt for more information.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + + // reset if successful + if (!copyResult) return; + ChangeValidationState(lblBackupValidator, false, Pokemon.Validation.Backup); + ChangeValidationState(lblRomFsValidator, false, Pokemon.Validation.RomFs); + } + + private void ChangeValidationState(Label lbl, bool valid, Pokemon.Validation folder) + { + lbl.Text = valid ? "valid" : "invalid"; + lbl.ForeColor = valid ? Color.Green : Color.Red; + + switch (folder) + { + case Pokemon.Validation.Backup: + _checkBackup = valid; + break; + case Pokemon.Validation.RomFs: + _checkRomFs = valid; + break; + } + + if (!valid) btnStart.Enabled = false; + if (_checkBackup && _checkRomFs) btnStart.Enabled = true; } } } diff --git a/PokeTool/PokeTool.csproj b/PokeTool/PokeTool.csproj index 0f568ce..817dbeb 100644 --- a/PokeTool/PokeTool.csproj +++ b/PokeTool/PokeTool.csproj @@ -48,11 +48,12 @@ - + + Form - - Form1.cs + + PokeTool.cs @@ -61,8 +62,8 @@ - - Form1.cs + + PokeTool.cs ResXFileCodeGenerator diff --git a/PokeTool/Form1.resx b/PokeTool/PokeTool.resx similarity index 100% rename from PokeTool/Form1.resx rename to PokeTool/PokeTool.resx diff --git a/PokeTool/Program.cs b/PokeTool/Program.cs index c205ac9..e549e81 100644 --- a/PokeTool/Program.cs +++ b/PokeTool/Program.cs @@ -13,7 +13,7 @@ static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new PokeTool()); } } } diff --git a/PokeTool/Properties/AssemblyInfo.cs b/PokeTool/Properties/AssemblyInfo.cs index ea40433..c3213a3 100644 --- a/PokeTool/Properties/AssemblyInfo.cs +++ b/PokeTool/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/README.md b/README.md index 8d36438..3e59b26 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # PokeTool -*A Tool to simplify the Pokemon randomizing process on ORAS, XY and SuMo* +*A Tool to simplify the Pokemon randomizing process for XY, ORAS, SuMo and USUM* -## How do i use this? +## How do I use this? This tool is solely for the [LayeredFS guide](https://zetadesigns.github.io/randomizing-layeredfs.html). If you need any further help please contact me on the [Nintendo Homebrew](https://discord.gg/C29hYvh) Discord server.