void bwCreateWad_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bwCreateWad = sender as BackgroundWorker; Stopwatch creationTimer = new Stopwatch(); creationTimer.Start(); try { WadCreationInfo wadInfo = (WadCreationInfo)e.Argument; disableControls(); //Check Startup IOS if (wadInfo.startupIos < 0 || wadInfo.startupIos > 255) { throw new Exception("Startup IOS must be between 0 and 255!"); } wadInfo.success = false; wadInfo.sendWadReady = false; wadCreationInfo = wadInfo; //Make TPLs transparent makeBannerTplsTransparent(); makeIconTplsTransparent(); //Pack icon.bin bwCreateWad.ReportProgress(0, "Packing icon.bin..."); if (string.IsNullOrEmpty(replacedIcon)) { iconBin.AddHeaderImd5(); iconBin.Lz77Compress = wadInfo.lz77; for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++) { if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin") { sourceWad.BannerApp.ReplaceFile(i, iconBin.ToByteArray()); break; } } } else { newIconBin.AddHeaderImd5(); newIconBin.Lz77Compress = wadInfo.lz77; for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++) { if (sourceWad.BannerApp.StringTable[i].ToLower() == "icon.bin") { sourceWad.BannerApp.ReplaceFile(i, newIconBin.ToByteArray()); break; } } } //Pack banner.bin bwCreateWad.ReportProgress(20, "Packing banner.bin..."); if (string.IsNullOrEmpty(replacedBanner)) { bannerBin.AddHeaderImd5(); bannerBin.Lz77Compress = wadInfo.lz77; for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++) { if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin") { sourceWad.BannerApp.ReplaceFile(i, bannerBin.ToByteArray()); break; } } } else { newBannerBin.AddHeaderImd5(); bannerBin.Lz77Compress = wadInfo.lz77; for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++) { if (sourceWad.BannerApp.StringTable[i].ToLower() == "banner.bin") { sourceWad.BannerApp.ReplaceFile(i, newBannerBin.ToByteArray()); break; } } } //Pack sound.bin bwCreateWad.ReportProgress(40, "Packing sound.bin..."); if (!string.IsNullOrEmpty(replacedSound) || !string.IsNullOrEmpty(wadInfo.sound)) { for (int i = 0; i < sourceWad.BannerApp.NumOfNodes; i++) { if (sourceWad.BannerApp.StringTable[i].ToLower() == "sound.bin") { sourceWad.BannerApp.ReplaceFile(i, newSoundBin); break; } } } //Insert new dol if (!string.IsNullOrEmpty(wadInfo.dol)) { bwCreateWad.ReportProgress(50, "Inserting DOL..."); sourceWad.RemoveAllContents(); if (wadInfo.nandLoader == WadCreationInfo.NandLoader.comex) { sourceWad.AddContent(Properties.Resources.comex, 1, 1, ContentType.Normal); if (wadInfo.dol.StartsWith("Simple Forwarder:")) { sourceWad.AddContent(createForwarderSimple(), 2, 2, ContentType.Normal); } else if (wadInfo.dol.StartsWith("Complex Forwarder")) { bwCreateWad.ReportProgress(55, "Compiling Forwarder..."); sourceWad.AddContent(createForwarderComplex(), 2, 2, ContentType.Normal); } else { sourceWad.AddContent(newDol, 2, 2, ContentType.Normal); } sourceWad.BootIndex = 1; } else { sourceWad.AddContent(Properties.Resources.Waninkoko, 2, 2, ContentType.Normal); if (wadInfo.dol.StartsWith("Simple Forwarder:")) { sourceWad.AddContent(createForwarderSimple(), 1, 1, ContentType.Normal); } else if (wadInfo.dol.StartsWith("Complex Forwarder")) { bwCreateWad.ReportProgress(55, "Compiling Forwarder..."); sourceWad.AddContent(createForwarderComplex(), 1, 1, ContentType.Normal); } else { sourceWad.AddContent(newDol, 1, 1, ContentType.Normal); } sourceWad.BootIndex = 2; } } //Change channel information for (int i = 0; i < wadInfo.titles.Length; i++) { if (string.IsNullOrEmpty(wadInfo.titles[i])) { wadInfo.titles[i] = wadInfo.allLangTitle; } } bwCreateWad.ReportProgress(75, "Updating Channel Information..."); sourceWad.ChangeStartupIOS(wadInfo.startupIos); sourceWad.ChangeChannelTitles(wadInfo.titles); if (!string.IsNullOrEmpty(wadInfo.titleId)) { sourceWad.ChangeTitleID(LowerTitleID.Channel, wadInfo.titleId); } sourceWad.FakeSign = true; sourceWad.ChangeTitleKey("GottaGetSomeBeer"); //Pack WAD bwCreateWad.ReportProgress(80, "Packing WAD..."); if (!wadInfo.sendToWii) { sourceWad.Save(wadInfo.outFile); } else { wadInfo.wadFile = sourceWad.ToByteArray(); } bwCreateWad.ReportProgress(100, " "); creationTimer.Stop(); if (!wadInfo.sendToWii) { FileInfo fi = new FileInfo(wadInfo.outFile); double fileSize = Math.Round(fi.Length * 0.0009765625 * 0.0009765625, 2); infoBox(string.Format("Successfully created custom channel!\nTime elapsed: {0} ms\nFilesize: {1} MB\nApprox. Blocks: {2}", creationTimer.ElapsedMilliseconds, fileSize, sourceWad.NandBlocks)); } else { wadInfo.sendWadReady = true; } wadCreationInfo = wadInfo; wadCreationInfo.success = true; } catch (Exception ex) { wadCreationInfo.sendWadReady = false; creationTimer.Stop(); enableControls(); errorBox(ex.Message); } }
private static void Editor(string[] args, bool edit) { //Setting up variables string input = args[2]; string output = args[3]; string id = ""; int ios = -1; string title = ""; string lwrid = ""; bool fake = false; string sound = ""; string banner = ""; string icon = ""; string app = ""; //Check if file/folder exists if (edit == true) if (File.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open file: {0}", input); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } if (edit == false) if (Directory.Exists(input) == false) { Console.WriteLine("ERROR: Unable to open folder: {0}", input); Console.WriteLine("Either the folder doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FOLDER_ERR_01"); Environment.Exit(0x00003E94); return; } for (int i = 1; i < args.Length; i++) { switch (args[i].ToUpper()) { case "-F": fake = true; break; case "-ID": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No ID set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_ID_01"); Environment.Exit(0x00003E8E); return; } id = args[i + 1]; if (id.Length < 4) { Console.WriteLine("ERROR: ID too short"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_SHORT_ID_01"); Environment.Exit(0x00003E97); return; } id = id.Substring(0, 4); break; case "-TYPE": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No type set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TYPE_01"); Environment.Exit(0x00003E98); return; } lwrid = args[i + 1].ToUpper(); if (lwrid != "CHANNEL" && lwrid != "DLC" && lwrid != "GAMECHANNEL" && lwrid != "HIDDENCHANNELS" && lwrid != "SYSTEMCHANNELS" && lwrid != "SYSTEMTITLES") { Console.WriteLine("ERROR: Unknown WAD type: {0}", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_TYPE_01"); Environment.Exit(0x00003E99); return; } break; case "-IOS": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No type set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TYPE_01"); Environment.Exit(0x00003E98); return; } if (!int.TryParse(args[i + 1], out ios)) { Console.WriteLine("Invalid slot {0}...", args[i + 1]); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_INVALID_SLOT_01"); Environment.Exit(0x00003E8A); return; } if (ios < 0 || ios > 255) { Console.WriteLine("Invalid slot {0}...", ios); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_INVALID_SLOT_01"); Environment.Exit(0x00003E8A); return; } break; case "-TITLE": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No title set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_TITLE_01"); Environment.Exit(0x00003E95); return; } title = args[i + 1]; break; case "-SOUND": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No sound set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_SOUND_01"); Environment.Exit(0x00003E9A); return; } sound = args[i + 1]; if (File.Exists(sound) == false) { Console.WriteLine("ERROR: Unable to find sound wad"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; case "-BANNER": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No banner set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_BANNER_01"); Environment.Exit(0x00003E9B); return; } banner = args[i + 1]; if (File.Exists(banner) == false) { Console.WriteLine("ERROR: Unable to find banner wad"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; case "-ICON": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No sound set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_SOUND_01"); Environment.Exit(0x00003E9A); return; } icon = args[i + 1]; if (File.Exists(icon) == false) { Console.WriteLine("ERROR: Unable to find icon wad"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; case "-DOL": if (i + 1 >= args.Length) { Console.WriteLine("ERROR: No dol set"); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_NO_DOL_01"); Environment.Exit(0x00003E84); return; } app = args[i + 1]; if (File.Exists(app) == false) { Console.WriteLine("ERROR: Unable to find dol wad/file"); Console.WriteLine("Either the file doesn't exist, or Sharpii doesn't have permission to open it."); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_FILE_ERR_01"); Environment.Exit(0x00003E81); return; } break; } } //Run main part, and check for exceptions try { WAD wad = new WAD(); if (edit == true) { if (BeQuiet.quiet > 2) Console.Write("Loading file..."); wad.LoadFile(input); } else { if (BeQuiet.quiet > 2) Console.Write("Loading folder..."); wad.CreateNew(input); } if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (sound != "" || banner != "" || icon != "" || app != "") { string temp = Path.GetTempPath() + "Sharpii.tmp"; if (Directory.Exists(temp) == true) DeleteADir.DeleteDirectory(temp); Directory.CreateDirectory(temp); wad.Unpack(Path.Combine(temp, "main")); U8 u = new U8(); u.LoadFile(Path.Combine(temp, "main", "00000000.app")); u.Extract(Path.Combine(temp, "main", "00000000")); WAD twad = new WAD(); if (sound != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing sound..."); twad.LoadFile(sound); twad.Unpack(Path.Combine(temp + "sound")); U8 tu = new U8(); tu.LoadFile(Path.Combine(temp, "sound", "00000000.app")); tu.Extract(Path.Combine(temp, "sound", "00000000")); File.Copy(Path.Combine(temp, "sound", "00000000", "meta", "sound.bin"), Path.Combine(temp, "main", "00000000", "meta", "sound.bin"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } if (banner != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing banner..."); twad.LoadFile(banner); twad.Unpack(Path.Combine(temp, "banner")); U8 tu = new U8(); tu.LoadFile(Path.Combine(temp, "banner", "00000000.app")); tu.Extract(Path.Combine(temp, "banner", "00000000")); File.Copy(Path.Combine(temp, "banner", "00000000", "meta", "banner.bin"), Path.Combine(temp, "main", "00000000", "meta", "banner.bin"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } if (icon != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing icon..."); twad.LoadFile(icon); twad.Unpack(Path.Combine(temp, "icon")); U8 tu = new U8(); tu.LoadFile(Path.Combine(temp, "icon", "00000000.app")); tu.Extract(Path.Combine(temp, "icon", "00000000")); File.Copy(Path.Combine(temp, "icon", "00000000", "meta", "icon.bin"), Path.Combine(temp, "main", "00000000", "meta", "icon.bin"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } if (app != "") { if (BeQuiet.quiet > 2) Console.Write("Grabbing dol..."); if (app.Substring(app.Length - 4, 4) == ".dol") { Directory.CreateDirectory(Path.Combine(temp, "dol")); File.Copy(app, Path.Combine(temp, "dol", "00000001.app")); } else { twad.LoadFile(app); twad.Unpack(Path.Combine(temp, "dol")); } File.Copy(Path.Combine(temp, "dol", "00000001.app"), Path.Combine(temp, "main", "00000001.app"), true); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); } u.ReplaceFile(1, Path.Combine(temp, "main", "00000000", "meta", "banner.bin")); u.ReplaceFile(2, Path.Combine(temp, "main", "00000000", "meta", "icon.bin")); u.ReplaceFile(3, Path.Combine(temp, "main", "00000000", "meta", "sound.bin")); u.Save(Path.Combine(temp, "main", "00000000.app")); DeleteADir.DeleteDirectory(Path.Combine(temp, "main", "00000000")); wad.CreateNew(Path.Combine(temp, "main")); DeleteADir.DeleteDirectory(temp); } if (BeQuiet.quiet > 2 && fake == true) Console.WriteLine("FakeSigning WAD"); wad.FakeSign = fake; if (id != "" || lwrid != "") { if (id != "") { if (BeQuiet.quiet > 2) Console.WriteLine("Changing channel ID to: {0}", id); } else { id = wad.UpperTitleID; } if (lwrid != "") { if (BeQuiet.quiet > 2) Console.WriteLine("Changing channel type to: {0}", lwrid); } else { lwrid = "CHANNEL"; } if (lwrid == "CHANNEL") wad.ChangeTitleID(LowerTitleID.Channel, id); else if (lwrid == "DLC") wad.ChangeTitleID(LowerTitleID.DLC, id); else if (lwrid == "GAMECHANNEL") wad.ChangeTitleID(LowerTitleID.GameChannel, id); else if (lwrid == "HIDDENCHANNELS") wad.ChangeTitleID(LowerTitleID.HiddenChannels, id); else if (lwrid == "SYSTEMCHANNELS") wad.ChangeTitleID(LowerTitleID.SystemChannels, id); else if (lwrid == "SYSTEMTITLES") wad.ChangeTitleID(LowerTitleID.SystemTitles, id); } if (ios > -1) { if (BeQuiet.quiet > 2) Console.WriteLine("Changing startup IOS to: {0}", ios); wad.ChangeStartupIOS(ios); } if (title != "") { if (BeQuiet.quiet > 2) Console.WriteLine("Changing channel title to: {0}", title); wad.ChangeChannelTitles(title); } if (BeQuiet.quiet > 2) Console.Write("Saving file..."); if (output.Substring(output.Length - 4, 4).ToUpper() != ".WAD") output = output + ".wad"; wad.Save(output); if (BeQuiet.quiet > 2) Console.Write("Done!\n"); if (BeQuiet.quiet > 1) Console.WriteLine("Operation completed succesfully!"); } catch (Exception ex) { if (ex.Message == "Index was outside the bounds of the array.") { Console.WriteLine("You need to have all the required .app files, a tmd file, a tik file, and a cert file to do this."); Console.WriteLine(""); Console.WriteLine("Error: SHARPII_NET_CORE_NUSD_MISSING_FILES_01"); ExceptionListRan = 1; Environment.Exit(0x00003E9D); } if (ExceptionListRan == 0) { Console.WriteLine("An unknown error occured, please try again"); Console.WriteLine(""); Console.WriteLine("ERROR DETAILS: {0}", ex.Message); Console.WriteLine("Error: SHARPII_NET_CORE_WAD_UNKNOWN_01"); Environment.Exit(0x00003E82); } } }