private void NUSDownloader_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; // this function would need major rewriting to get rid of this... WriteStatus("Starting NUS Download. Please be patient!", infocolor); SetEnableforDownload(false); downloadstartbtn.Text = "Starting NUS Download!"; // WebClient configuration WebClient nusWC = new WebClient(); nusWC = ConfigureWithProxy(nusWC); // Create\Configure NusClient libWiiSharp.NusClient nusClient = new libWiiSharp.NusClient(); nusClient.ConfigureNusClient(nusWC); nusClient.UseLocalFiles = localuse.Checked; nusClient.ContinueWithoutTicket = true; // Server if (serverLbl.Text == "Wii") nusClient.SetToWiiServer(); else if (serverLbl.Text == "DSi") nusClient.SetToDSiServer(); // Events nusClient.Debug += new EventHandler<libWiiSharp.MessageEventArgs>(nusClient_Debug); nusClient.Progress += new EventHandler<ProgressChangedEventArgs>(nusClient_Progress); libWiiSharp.StoreType[] storeTypes = new libWiiSharp.StoreType[3]; if (packbox.Checked) storeTypes[0] = libWiiSharp.StoreType.WAD; else storeTypes[0] = libWiiSharp.StoreType.Empty; if (decryptbox.Checked) storeTypes[1] = libWiiSharp.StoreType.DecryptedContent; else storeTypes[1] = libWiiSharp.StoreType.Empty; if (keepenccontents.Checked) storeTypes[2] = libWiiSharp.StoreType.EncryptedContent; else storeTypes[2] = libWiiSharp.StoreType.Empty; string wadName; if (String.IsNullOrEmpty(WAD_Saveas_Filename)) wadName = wadnamebox.Text; else wadName = WAD_Saveas_Filename; try { nusClient.DownloadTitle(titleidbox.Text, titleversion.Text, Path.Combine(CURRENT_DIR, "titles"), wadName, storeTypes); } catch (Exception ex) { WriteStatus("Download failed: \"" + ex.Message + " ):\"", errorcolor); } if (iosPatchCheckbox.Checked == true) { // Apply patches then... bool didpatch = false; int noofpatches = 0; string appendpatch = ""; // Okay, it's checked. libWiiSharp.IosPatcher iosp = new libWiiSharp.IosPatcher(); libWiiSharp.WAD ioswad = new libWiiSharp.WAD(); wadName = wadName.Replace("[v]", nusClient.TitleVersion.ToString()); if (wadName.Contains(Path.DirectorySeparatorChar.ToString()) || wadName.Contains(Path.AltDirectorySeparatorChar.ToString())) ioswad.LoadFile(wadName); else ioswad.LoadFile(Path.Combine(Path.Combine(Path.Combine(Path.Combine(CURRENT_DIR, "titles"), titleidbox.Text), nusClient.TitleVersion.ToString()), wadName)); try { iosp.LoadIOS(ref ioswad); } catch (Exception) { WriteStatus("NUS Download Finished.", infocolor); return; } foreach (object checkItem in iosPatchesListBox.CheckedItems) { // ensure not 'indeterminate' if (iosPatchesListBox.GetItemCheckState(iosPatchesListBox.Items.IndexOf(checkItem)).ToString() == "Checked") { switch (checkItem.ToString()) { case "Trucha bug": noofpatches = iosp.PatchFakeSigning(); if (noofpatches > 0) { WriteStatus(" - Patched in fake-signing:", infocolor); if (noofpatches > 1) appendpatch = "es"; else appendpatch = ""; WriteStatus(String.Format(" {0} patch{1} applied.", noofpatches, appendpatch)); didpatch = true; } else WriteStatus(" - Could not patch fake-signing", errorcolor); break; case "ES_Identify": noofpatches = iosp.PatchEsIdentify(); if (noofpatches > 0) { WriteStatus(" - Patched in ES_Identify:", infocolor); if (noofpatches > 1) appendpatch = "es"; else appendpatch = ""; WriteStatus(String.Format(" {0} patch{1} applied.", noofpatches, appendpatch)); didpatch = true; } else WriteStatus(" - Could not patch ES_Identify", errorcolor); break; case "NAND permissions": noofpatches = iosp.PatchNandPermissions(); if (noofpatches > 0) { WriteStatus(" - Patched in NAND permissions:", infocolor); if (noofpatches > 1) appendpatch = "es"; else appendpatch = ""; WriteStatus(String.Format(" {0} patch{1} applied.", noofpatches, appendpatch)); didpatch = true; } else WriteStatus(" - Could not patch NAND permissions", errorcolor); break; } } else { // WriteStatus(iosPatchesListBox.GetItemCheckState(iosPatchesListBox.Items.IndexOf(checkItem)).ToString()); } } if (didpatch) { wadName = wadName.Replace(".wad",".patched.wad"); try { if (wadName.Contains(Path.DirectorySeparatorChar.ToString()) || wadName.Contains(Path.AltDirectorySeparatorChar.ToString())) ioswad.Save(wadName); else ioswad.Save(Path.Combine(Path.Combine(Path.Combine(Path.Combine(CURRENT_DIR, "titles"), titleidbox.Text), nusClient.TitleVersion.ToString()), wadName)); WriteStatus(String.Format("Patched WAD saved as: {0}", Path.GetFileName(wadName)), infocolor); } catch (Exception ex) { WriteStatus(String.Format("Couldn't save patched WAD: \"{0}\" :(",ex.Message), errorcolor); } } } WriteStatus("NUS Download Finished."); }
private void openToolStripButton_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && openFileDialog1.FileName.Length > 0) { timer1.Enabled = false; simpleOpenGlControl1.DestroyContexts(); simpleOpenGlControl1.InitializeContexts(); InitOpenGl(); Animation = null; FrameNr = 0; toolStripButton1.Enabled = true; toolStripButton2.Enabled = false; toolStripButton2.Checked = false; if (openFileDialog1.FileName.ToLower().EndsWith(".brlyt")) { Dictionary <string, byte[]> files = new Dictionary <string, byte[]>(); if (Directory.Exists(Path.GetDirectoryName(openFileDialog1.FileName).Replace("blyt", "timg"))) { foreach (FileInfo f in new DirectoryInfo(Path.GetDirectoryName(openFileDialog1.FileName).Replace("blyt", "timg")).GetFiles()) { files.Add(f.Name, File.ReadAllBytes(f.FullName)); } } foreach (FileInfo f in new DirectoryInfo(Path.GetDirectoryName(openFileDialog1.FileName)).GetFiles()) { if (f.Extension == ".brfnt") { files.Add(f.Name, File.ReadAllBytes(f.FullName)); } } Layout = new IO.BRLYT(File.ReadAllBytes(openFileDialog1.FileName), files); } else if (openFileDialog1.FileName.ToLower().EndsWith("banner.bin")) { byte[] file = File.ReadAllBytes(openFileDialog1.FileName); if (libWiiSharp.Lz77.IsLz77Compressed(file)) { file = new libWiiSharp.Lz77().Decompress(file); } libWiiSharp.U8 u = libWiiSharp.U8.Load(file); Dictionary <string, byte[]> files = new Dictionary <string, byte[]>(); int i = 0; foreach (libWiiSharp.U8_Node n in u.Nodes) { if (u.StringTable[i].ToLower().EndsWith(".brfnt") || u.StringTable[i].ToLower().EndsWith(".tpl")) { files.Add(u.StringTable[i], u.Data[i]); } i++; } i = 0; foreach (libWiiSharp.U8_Node n in u.Nodes) { if (u.StringTable[i].ToLower().EndsWith(".brlyt")) { Layout = new IO.BRLYT(u.Data[i], files); break; } i++; } } else if (openFileDialog1.FileName.ToLower().EndsWith(".wad")) { byte[] file = File.ReadAllBytes(openFileDialog1.FileName); if (libWiiSharp.Lz77.IsLz77Compressed(file)) { file = new libWiiSharp.Lz77().Decompress(file); } libWiiSharp.WAD w = libWiiSharp.WAD.Load(file); libWiiSharp.U8 u = null; int i = 0; foreach (libWiiSharp.U8_Node n in w.BannerApp.Nodes) { if (w.BannerApp.StringTable[i].ToLower().EndsWith("banner.bin")) { u = libWiiSharp.U8.Load(w.BannerApp.Data[i]); break; } i++; } Dictionary <string, byte[]> files = new Dictionary <string, byte[]>(); i = 0; foreach (libWiiSharp.U8_Node n in u.Nodes) { if (u.StringTable[i].ToLower().EndsWith(".brfnt") || u.StringTable[i].ToLower().EndsWith(".tpl")) { files.Add(u.StringTable[i], u.Data[i]); } i++; } i = 0; bool layout = false; foreach (libWiiSharp.U8_Node n in u.Nodes) { if (u.StringTable[i].ToLower().EndsWith(".brlyt") && !layout) { Layout = new IO.BRLYT(u.Data[i], files); layout = true; } else if (u.StringTable[i].ToLower().EndsWith("banner_start.brlan")) { Animation = new IO.BRLAN(u.Data[i], files); FrameNr = 0; toolStripButton2.Enabled = true; } else if (u.StringTable[i].ToLower().EndsWith("banner.brlan")) { Animation = new IO.BRLAN(u.Data[i], files); FrameNr = 0; toolStripButton2.Enabled = true; } i++; } } else if (openFileDialog1.FileName.ToLower().EndsWith(".bnr")) { byte[] file = File.ReadAllBytes(openFileDialog1.FileName); if (libWiiSharp.Lz77.IsLz77Compressed(file)) { file = new libWiiSharp.Lz77().Decompress(file); } libWiiSharp.U8 w = libWiiSharp.U8.Load(file); libWiiSharp.U8 u = null; int i = 0; foreach (libWiiSharp.U8_Node n in w.Nodes) { if (w.StringTable[i].ToLower().EndsWith("banner.bin")) { u = libWiiSharp.U8.Load(w.Data[i]); break; } i++; } Dictionary <string, byte[]> files = new Dictionary <string, byte[]>(); i = 0; foreach (libWiiSharp.U8_Node n in u.Nodes) { if (u.StringTable[i].ToLower().EndsWith(".brfnt") || u.StringTable[i].ToLower().EndsWith(".tpl")) { files.Add(u.StringTable[i], u.Data[i]); } i++; } i = 0; bool layout = false; foreach (libWiiSharp.U8_Node n in u.Nodes) { if (u.StringTable[i].ToLower().EndsWith(".brlyt") && !layout) { Layout = new IO.BRLYT(u.Data[i], files); layout = true; } else if (u.StringTable[i].ToLower().EndsWith("banner_start.brlan")) { Animation = new IO.BRLAN(u.Data[i], files); FrameNr = 0; toolStripButton2.Enabled = true; } i++; } } propertyGrid1.SelectedObject = null; treeView1.BeginUpdate(); treeView1.Nodes.Clear(); treeView1.Nodes.Add("Brlyt"); treeView1.Nodes[0].ImageIndex = 5; treeView1.Nodes[0].SelectedImageIndex = 5; TreeNode c = treeView1.Nodes[0].Nodes.Add("Txl1"); c.ImageIndex = 6; c.SelectedImageIndex = 6; if (Layout.FNL1 != null) { c = treeView1.Nodes[0].Nodes.Add("Fnl1"); c.ImageIndex = 7; c.SelectedImageIndex = 7; } c = treeView1.Nodes[0].Nodes.Add("Mat1"); c.ImageIndex = 4; c.SelectedImageIndex = 4; foreach (IO.BRLYT.mat1.MAT1Entry m in Layout.MAT1.Entries) { m.GetTreeNode(c.Nodes); } Layout.PAN1.GetTreeNodes(treeView1.Nodes[0].Nodes); treeView1.EndUpdate(); Layout.BindTextures(); simpleOpenGlControl1.Width = (int)Layout.LYT1.Width; simpleOpenGlControl1.Height = (int)Layout.LYT1.Height; Render(); } }