diff --git a/UWUVCI AIO WPF/Classes/Injection.cs b/UWUVCI AIO WPF/Classes/Injection.cs index 9247b6a..15feeed 100644 --- a/UWUVCI AIO WPF/Classes/Injection.cs +++ b/UWUVCI AIO WPF/Classes/Injection.cs @@ -22,7 +22,7 @@ namespace UWUVCI_AIO_WPF private static readonly string toolsPath = Path.Combine(Directory.GetCurrentDirectory(), "Tools"); /* - * GameConsole: Can either be NDS, N64, GBA, NES or SNES + * GameConsole: Can either be NDS, N64, GBA, NES, SNES or TG16 * baseRom = Name of the BaseRom, which is the folder name too (example: Super Metroid EU will be saved at the BaseRom path under the folder SMetroidEU, so the BaseRom is in this case SMetroidEU). * customBasePath = Path to the custom Base. Is null if no custom base is used. * injectRomPath = Path to the Rom to be injected into the Base Game. @@ -35,52 +35,44 @@ namespace UWUVCI_AIO_WPF * iniPath = Only used for N64. Path to the INI configuration. If "blank", a blank ini will be used. * darkRemoval = Only used for N64. Indicates whether the dark filter should be removed. */ - /*public static void Inject(GameConsoles console, string baseRom, string customBasePath, string injectRomPath, string[] bootImages, string gameName, string iniPath = null, bool darkRemoval = false) + + public static bool Inject(GameConfig Configuration, string RomPath) { - CopyBase(baseRom, customBasePath); - switch (console) + try { - case GameConsoles.NDS: - NDS(injectRomPath); - break; + if (Configuration.BaseRom.Name != "Custom") + { + //Normal Base functionality here + CopyBase($"{Configuration.BaseRom.Name.Replace(":", "")} [{Configuration.BaseRom.Region.ToString()}]", null); + } + else + { + //Custom Base Functionality here + CopyBase($"Custom", Configuration.CBasePath); + } + RunSpecificInjection(Configuration, RomPath); + EditXML(Configuration.GameName); + Images(Configuration); + MessageBox.Show("Injection Finished, please choose how you want to export the Inject next", "Finished Injection Part", MessageBoxButton.OK, MessageBoxImage.Information); + return true; + }catch(Exception e) + { + + if (e.Message.Contains("Images")){ + MessageBox.Show("Injection Failed due to wrong BitDepth, please check if your Files are in a different bitdepth than 32bit or 24bit", "Injection Failed", MessageBoxButton.OK, MessageBoxImage.Error); + } + else if (e.Message.Contains("Size")) + { + MessageBox.Show("Injection Failed due to Image Issues. Please check if your Images are made using following Information:\n\niconTex: \nDimensions: 128x128\nBitDepth: 32\n\nbootDrcTex: \nDimensions: 854x480\nBitDepth: 24\n\nbootTvTex: \nDimensions: 1280x720\nBitDepth: 24\n\nbootLogoTex: \nDimensions: 170x42\nBitDepth: 32", "Injection Failed", MessageBoxButton.OK, MessageBoxImage.Error); + } + else + { + MessageBox.Show("Injection Failed due to unknown circumstances, please contact us on the UWUVCI discord", "Injection Failed", MessageBoxButton.OK, MessageBoxImage.Error); - case GameConsoles.N64: - N64(injectRomPath, iniPath, darkRemoval); - break; - - case GameConsoles.GBA: - GBA(injectRomPath); - break; - - case GameConsoles.NES: - NESSNES(injectRomPath); - break; - case GameConsoles.SNES: - NESSNES(RemoveHeader(injectRomPath)); - break; + } + return false; } - EditXML(gameName); - Images(bootImages); - //MessageBox.Show(Resources.InjectionFinishedText, Resources.InjectionFinishedCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); - }*/ - - public static void Inject(GameConfig Configuration, string RomPath) - { - if(Configuration.BaseRom.Name != "Custom") - { - //Normal Base functionality here - CopyBase($"{Configuration.BaseRom.Name.Replace(":", "")} [{Configuration.BaseRom.Region.ToString()}]", null); - } - else - { - //Custom Base Functionality here - CopyBase($"Custom", Configuration.CBasePath); - } - RunSpecificInjection(Configuration, RomPath); - EditXML(Configuration.GameName); - //Images(Configuration); - MessageBox.Show("Injection Finished, please choose how you want to export the Inject next", "Finished Injection Part", MessageBoxButton.OK, MessageBoxImage.Information); } private static void RunSpecificInjection(GameConfig console, string RomPath) @@ -439,83 +431,174 @@ namespace UWUVCI_AIO_WPF } } - private static void Images(string[] paths) + private static void ReadFileFromBin(byte[] bin, string output) { - bool tv = false; - bool drc = false; - bool icon = false; - bool logo = false; - - if (Directory.Exists(imgPath)) // sanity check - { - Directory.Delete(imgPath, true); - } - Directory.CreateDirectory(imgPath); - - if (paths[0] != null) - { - tv = true; - CopyAndConvertImage(paths[0], Path.Combine(imgPath, "bootTvTex.tga")); - } - - if (paths[1] != null) - { - drc = true; - CopyAndConvertImage(paths[1], Path.Combine(imgPath, "bootDrcTex.tga")); - } - - if (paths[2] != null) - { - icon = true; - CopyAndConvertImage(paths[2], Path.Combine(imgPath, "iconTex.tga")); - } - - if (paths[3] != null) - { - logo = true; - CopyAndConvertImage(paths[3], Path.Combine(imgPath, "bootLogoTex.tga")); - } - - if (tv || drc || icon || logo) { - using (Process tgaverifyFixup = new Process()) - { - tgaverifyFixup.StartInfo.UseShellExecute = false; - tgaverifyFixup.StartInfo.CreateNoWindow = true; - tgaverifyFixup.StartInfo.FileName = Path.Combine(toolsPath, "tga_verify.exe"); - tgaverifyFixup.StartInfo.Arguments = $"--fixup \"{imgPath}\""; - - tgaverifyFixup.Start(); - tgaverifyFixup.WaitForExit(); - } - - if (tv) - { - File.Delete(Path.Combine(baseRomPath, "meta", "bootTvTex.tga")); - File.Move(Path.Combine(imgPath, "bootTvTex.tga"), Path.Combine(baseRomPath, "meta", "bootTvTex.tga")); - } - if (drc) - { - File.Delete(Path.Combine(baseRomPath, "meta", "bootDrcTex.tga")); - File.Move(Path.Combine(imgPath, "bootDrcTex.tga"), Path.Combine(baseRomPath, "meta", "bootDrcTex.tga")); - } - if (icon) - { - File.Delete(Path.Combine(baseRomPath, "meta", "iconTex.tga")); - File.Move(Path.Combine(imgPath, "iconTex.tga"), Path.Combine(baseRomPath, "meta", "iconTex.tga")); - } - if (logo) - { - File.Delete(Path.Combine(baseRomPath, "meta", "bootLogoTex.tga")); - File.Move(Path.Combine(imgPath, "bootLogoTex.tga"), Path.Combine(baseRomPath, "meta", "bootLogoTex.tga")); - } - } + File.WriteAllBytes(output, bin); } + private static void Images(GameConfig config) + { + try + { - private static void CopyAndConvertImage(string inputPath, string outputPath) + + //is an image embedded? yes => export them and check for issues + //no => using path + if (Directory.Exists(imgPath)) // sanity check + { + Directory.Delete(imgPath, true); + } + Directory.CreateDirectory(imgPath); + //ICON + List Images = new List(); + if (config.TGAIco.ImgBin == null) + { + //use path + if (config.TGAIco.ImgPath != null) + { + Images.Add(true); + CopyAndConvertImage(config.TGAIco.ImgPath, Path.Combine(imgPath), false, 128,128,32, "iconTex.tga"); + } + else + { + Images.Add(false); + } + } + else + { + ReadFileFromBin(config.TGAIco.ImgBin, $"iconTex.{config.TGAIco.extension}"); + CopyAndConvertImage($"iconTex.{config.TGAIco.extension}", Path.Combine(imgPath), true, 128, 128, 32, "iconTex.tga"); + Images.Add(true); + } + + //Drc + if (config.TGADrc.ImgBin == null) + { + //use path + if (config.TGADrc.ImgPath != null) + { + Images.Add(true); + CopyAndConvertImage(config.TGADrc.ImgPath, Path.Combine(imgPath), false, 854,480,24, "bootDrcTex.tga"); + } + else + { + Images.Add(false); + } + } + else + { + ReadFileFromBin(config.TGADrc.ImgBin, $"bootDrcTex.{config.TGADrc.extension}"); + CopyAndConvertImage($"bootDrcTex.{config.TGADrc.extension}", Path.Combine(imgPath), true,854,480,24, "bootDrcTex.tga"); + Images.Add(true); + } + + //tv + if (config.TGATv.ImgBin == null) + { + //use path + if (config.TGATv.ImgPath != null) + { + Images.Add(true); + CopyAndConvertImage(config.TGATv.ImgPath, Path.Combine(imgPath), false,1280,720,24, "bootTvTex.tga"); + } + else + { + Images.Add(false); + } + } + else + { + ReadFileFromBin(config.TGATv.ImgBin, $"bootTvTex.{config.TGATv.extension}"); + CopyAndConvertImage($"bootTvTex.{config.TGATv.extension}", Path.Combine(imgPath), true, 1280, 720, 24, "bootTvTex.tga"); + Images.Add(true); + } + + //logo + if (config.TGALog.ImgBin == null) + { + //use path + if (config.TGALog.ImgPath != null) + { + Images.Add(true); + CopyAndConvertImage(config.TGALog.ImgPath, Path.Combine(imgPath), false, 170,42,32, "bootLogoTex.tga"); + } + else + { + Images.Add(false); + } + } + else + { + ReadFileFromBin(config.TGALog.ImgBin, $"bootLogoTex.{config.TGALog.extension}"); + CopyAndConvertImage($"bootLogoTex.{config.TGALog.extension}", Path.Combine(imgPath), true, 170, 42, 32, "bootLogoTex.tga"); + Images.Add(true); + } + + //Fixing Images + Injecting them + if (Images[0] || Images[1] || Images[2] || Images[3]) + { + using (Process checkIfIssue = new Process()) + { + checkIfIssue.StartInfo.UseShellExecute = false; + checkIfIssue.StartInfo.CreateNoWindow = false; + checkIfIssue.StartInfo.RedirectStandardOutput = true; + checkIfIssue.StartInfo.RedirectStandardError = true; + checkIfIssue.StartInfo.FileName = $"{Path.Combine(toolsPath,"tga_verify.exe")}"; + Console.WriteLine(Directory.GetCurrentDirectory()); + checkIfIssue.StartInfo.Arguments = $"\"{imgPath}\""; + checkIfIssue.Start(); + checkIfIssue.WaitForExit(); + var s = checkIfIssue.StandardOutput.ReadToEnd(); + if (s.Contains("width") || s.Contains("height") || s.Contains("depth")) + { + throw new Exception("Size"); + } + var e = checkIfIssue.StandardError.ReadToEnd(); + if (e.Contains("width") || e.Contains("height") || e.Contains("depth")) + { + throw new Exception("Size"); + } + + Console.ReadLine(); + } + + if (Images[2]) + { + File.Delete(Path.Combine(baseRomPath, "meta", "bootTvTex.tga")); + File.Move(Path.Combine(imgPath, "bootTvTex.tga"), Path.Combine(baseRomPath, "meta", "bootTvTex.tga")); + } + if (Images[1]) + { + File.Delete(Path.Combine(baseRomPath, "meta", "bootDrcTex.tga")); + File.Move(Path.Combine(imgPath, "bootDrcTex.tga"), Path.Combine(baseRomPath, "meta", "bootDrcTex.tga")); + } + if (Images[0]) + { + File.Delete(Path.Combine(baseRomPath, "meta", "iconTex.tga")); + File.Move(Path.Combine(imgPath, "iconTex.tga"), Path.Combine(baseRomPath, "meta", "iconTex.tga")); + } + if (Images[3]) + { + File.Delete(Path.Combine(baseRomPath, "meta", "bootLogoTex.tga")); + File.Move(Path.Combine(imgPath, "bootLogoTex.tga"), Path.Combine(baseRomPath, "meta", "bootLogoTex.tga")); + } + } + } + catch(Exception e) + { + if (e.Message.Contains("Size")) + { + throw e; + } + throw new Exception("Images"); + } + + } + + private static void CopyAndConvertImage(string inputPath, string outputPath, bool delete, int widht, int height, int bit, string newname) { if (inputPath.EndsWith(".tga")) { - File.Copy(inputPath, outputPath); + File.Copy(inputPath, Path.Combine(outputPath,newname)); } else { @@ -524,11 +607,20 @@ namespace UWUVCI_AIO_WPF png2tga.StartInfo.UseShellExecute = false; png2tga.StartInfo.CreateNoWindow = true; png2tga.StartInfo.FileName = Path.Combine(toolsPath, "png2tga.exe"); - png2tga.StartInfo.Arguments = $"\"{inputPath}\" \"{outputPath}\""; + png2tga.StartInfo.Arguments = $"-i \"{inputPath}\" -o \"{outputPath}\" --width={widht} --height={height} --tga-bpp={bit} --tga-compression=none"; png2tga.Start(); png2tga.WaitForExit(); } + string name = Path.GetFileNameWithoutExtension(inputPath); + if(File.Exists(Path.Combine(outputPath , name + ".tga"))) + { + File.Move(Path.Combine(outputPath, name + ".tga"), Path.Combine(outputPath, newname)); + } + } + if (delete) + { + File.Delete(inputPath); } } diff --git a/UWUVCI AIO WPF/Classes/PNGTGA.cs b/UWUVCI AIO WPF/Classes/PNGTGA.cs index db9a69f..20c2918 100644 --- a/UWUVCI AIO WPF/Classes/PNGTGA.cs +++ b/UWUVCI AIO WPF/Classes/PNGTGA.cs @@ -8,9 +8,9 @@ namespace UWUVCI_AIO_WPF.Classes { class PNGTGA : BaseModel { - private string imgPath; + private string imgPath = null; - public string ImgPath + public string ImgPath { get { return imgPath; } set { imgPath = value; @@ -18,6 +18,8 @@ namespace UWUVCI_AIO_WPF.Classes } } - public byte[] ImgBin { get; set; } + public byte[] ImgBin { get; set; } = null; + + public string extension { get; set; } } } diff --git a/UWUVCI AIO WPF/Classes/ToolCheck.cs b/UWUVCI AIO WPF/Classes/ToolCheck.cs index 528bb71..b549757 100644 --- a/UWUVCI AIO WPF/Classes/ToolCheck.cs +++ b/UWUVCI AIO WPF/Classes/ToolCheck.cs @@ -23,7 +23,9 @@ namespace UWUVCI_AIO_WPF.Classes "wiiurpxtool.exe", "INICreator.exe", "7za.exe", - "blank.ini" + "blank.ini", + "FreeImage.dll", + "BuildPcePkg.exe" }; public static bool DoesToolsFolderExist() diff --git a/UWUVCI AIO WPF/Models/MainViewModel.cs b/UWUVCI AIO WPF/Models/MainViewModel.cs index b4659d2..7962315 100644 --- a/UWUVCI AIO WPF/Models/MainViewModel.cs +++ b/UWUVCI AIO WPF/Models/MainViewModel.cs @@ -238,7 +238,9 @@ namespace UWUVCI_AIO_WPF } public void Inject() { - Injection.Inject(GameConfiguration, RomPath); + if (Injection.Inject(GameConfiguration, RomPath)) Injected = true; + else Injected = false; + } private void BaseCheck() { @@ -705,6 +707,24 @@ namespace UWUVCI_AIO_WPF return false; } + public void ImageWarning() + { + MessageBox.Show("Images need to either be in a Bit Depth of 32bit or 24bit. \nIf using Tools like paint.net do not choose the Auto function.", "Image Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + public void CBaseWarning() + { + MessageBox.Show("If using Custom Bases there will be a chance that the programm crashes if adding a wrong base (example: a normal wiiu game instead of a nds vc game).\nIf you add a wrong base, we will not assist you fixing it, other than telling you to use another base.", "Custom base Warning", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + public bool CBaseConvertInfo() + { + bool ret = false; + DialogResult res = MessageBox.Show("You seem to have added a NUS format Custom Base.\nDo you want it to be converted to be used with the Injector?", "NUS Custom Base", MessageBoxButtons.YesNo, MessageBoxIcon.Information); + if(res == DialogResult.Yes) + { + ret = true; + } + return ret; + } public TKeys getTkey(GameBases bases) { var temp = KeyFile.ReadBasesFromKeyFile($@"keys\{GetConsoleOfBase(bases).ToString().ToLower()}.vck"); diff --git a/UWUVCI AIO WPF/UI/Frames/InjectFrames/Bases/CustomBaseFrame.xaml.cs b/UWUVCI AIO WPF/UI/Frames/InjectFrames/Bases/CustomBaseFrame.xaml.cs index ad78e8e..d89379c 100644 --- a/UWUVCI AIO WPF/UI/Frames/InjectFrames/Bases/CustomBaseFrame.xaml.cs +++ b/UWUVCI AIO WPF/UI/Frames/InjectFrames/Bases/CustomBaseFrame.xaml.cs @@ -46,12 +46,13 @@ namespace UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Bases mvm.GameConfiguration.BaseRom = Base; } - + private void Button_Click(object sender, RoutedEventArgs e) { + //warning if using custom bases programm may crash //get folder - //check if everything fine + //check if WUP or Loadiine //if yes, enable config and create new game config } } diff --git a/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/N64Config.xaml.cs b/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/N64Config.xaml.cs index 634e87e..d1c7f76 100644 --- a/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/N64Config.xaml.cs +++ b/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/N64Config.xaml.cs @@ -48,11 +48,12 @@ namespace UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations private void InjectGame(object sender, RoutedEventArgs e) { mvm.Inject(); - mvm.Injected = true; + } private void Set_TvTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGATv.ImgPath = path; @@ -61,18 +62,21 @@ namespace UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations private void Set_DrcTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGADrc.ImgPath = path; } private void Set_IconTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGAIco.ImgPath = path; } private void Set_LogoTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGALog.ImgPath = path; } diff --git a/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/OtherConfigs.xaml.cs b/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/OtherConfigs.xaml.cs index 0bd8d9e..81750c8 100644 --- a/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/OtherConfigs.xaml.cs +++ b/UWUVCI AIO WPF/UI/Frames/InjectFrames/Configurations/OtherConfigs.xaml.cs @@ -50,11 +50,11 @@ namespace UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations private void InjectGame(object sender, RoutedEventArgs e) { mvm.Inject(); - mvm.Injected = true; } private void Set_TvTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGATv.ImgPath = path; @@ -63,18 +63,21 @@ namespace UWUVCI_AIO_WPF.UI.Frames.InjectFrames.Configurations private void Set_DrcTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGADrc.ImgPath = path; } private void Set_IconTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGAIco.ImgPath = path; } private void Set_LogoTex(object sender, RoutedEventArgs e) { + mvm.ImageWarning(); string path = mvm.GetFilePath(false, false); if (!CheckIfNull(path)) mvm.GameConfiguration.TGALog.ImgPath = path; }