private void RemoveGameList_ItemActivate(object sender, EventArgs e) { string TitleID = (string)((ListView)sender).SelectedItems[0].Tag; string Name = (string)((ListView)sender).SelectedItems[0].Text; DialogResult res = MessageBox.Show("Are you sure you want to Delete " + Name + " (" + TitleID + ")?", "Are you sure?", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { GameList.RemoveGameListEntry(TitleID); MainForm.ReloadGameList(); UpdateList(); } }
private void GetMetadataCDN_Click(object sender, EventArgs e) { if (Meta.npdm.TitleID == null) { Meta = GameList.ParseGameFiles(PathText.Text); } GameList.GameListNACP nacp = NintendoCDN.GetGameMetadata(Meta.npdm.TitleID); GameName.Text = nacp.TitleName; PublisherName.Text = nacp.Publisher; Image image = Image.FromFile("./Images/GameThumbnails/" + Meta.npdm.TitleID + ".jpg"); Bitmap scaledImage = ResizeImage(image, 256, 256); Thumbnail.Image = scaledImage; }
private void Add_Click(object sender, EventArgs e) { if (entrysfound != null) { foreach (GameList.GameListEntry entry in entrysfound) { GameList.AddGameListEntry(entry); } MainForm.ReloadGameList(); } else { if (Meta.npdm.TitleID == null) { Meta = GameList.ParseGameFiles(PathText.Text); } if (!String.IsNullOrWhiteSpace(ThumbnailPath.Text)) { if (File.Exists("./Images/GameThumbnails/" + Meta.npdm.TitleID + ".jpg")) { File.Delete("./Images/GameThumbnails/" + Meta.npdm.TitleID + ".jpg"); } File.Copy(ThumbnailPath.Text, "./Images/GameThumbnails/" + Meta.npdm.TitleID + ".jpg"); } GameList.GameListEntry entry = new GameList.GameListEntry(); if (String.IsNullOrWhiteSpace(GameName.Text)) { MessageBox.Show("Please fill in the at least Game Name.", "Error"); return; } entry.AppName = GameName.Text; entry.Publisher = PublisherName.Text; entry.GamePath = PathText.Text; entry.TitleID = Meta.npdm.TitleID; GameList.AddGameListEntry(entry); MainForm.ReloadGameList(); Meta = new GameList.GameListMetaData(); } this.Close(); }
private void SelectGamePath_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog { Description = "Please select a RomFS / ExeFS Folder." }; DialogResult result = folderBrowser.ShowDialog(); if (result == DialogResult.OK) { PathText.Text = folderBrowser.SelectedPath; if (GameList.IsGameDirectoryValid(folderBrowser.SelectedPath)) { if (!String.IsNullOrWhiteSpace(PathText.Text)) { isUnlocked = true; Add.Enabled = true; ScanDir.Enabled = false; } UpdateLock(); } else { if (!String.IsNullOrWhiteSpace(PathText.Text)) { ScanDir.Enabled = true; Add.Enabled = true; } } folderBrowser.Dispose(); } else if (result == DialogResult.Cancel) { folderBrowser.Dispose(); return; } }
private void ScanDir_Click(object sender, EventArgs e) { if (Settings.GET_METADATA_FROM_CDN) { entrysfound = new List <GameList.GameListEntry>(); int foundgames = 0; int skippedgames = 0; foreach (string dir in Directory.GetDirectories(PathText.Text)) { if (GameList.IsGameDirectoryValid(dir)) { ScanState.Text = "Games found: " + foundgames + "\nSkipped Games (Aka Games not found on the CDN): " + skippedgames + "\n(This process may take a while)"; GameList.GameListMetaData metaData = GameList.ParseGameFiles(dir); metaData.nacp = NintendoCDN.GetGameMetadata(metaData.npdm.TitleID); if (metaData.nacp.TitleName == null) { ++skippedgames; continue; } entrysfound.Add(new GameList.GameListEntry { AppName = metaData.nacp.TitleName, Publisher = metaData.nacp.Publisher, TitleID = metaData.npdm.TitleID, GamePath = dir }); ++foundgames; } } ScanState.Text = "All Games found: " + foundgames + "\nAll Games Skipped: " + skippedgames; } else if (Settings.USE_NUCLEUS) { entrysfound = new List <GameList.GameListEntry>(); int foundgames = 0; int skippedgames = 0; foreach (string dir in Directory.GetDirectories(PathText.Text)) { if (GameList.IsGameDirectoryValid(dir)) { ScanState.Text = "Games found: " + foundgames + "\nSkipped Games (Aka Games not found on the CDN): " + skippedgames + "\n(This process may take a while)"; GameList.GameListMetaData metaData = GameList.ParseGameFiles(dir); NucleusCDN.GameHeader header = NucleusCDN.MakeHeadRequest(metaData.npdm.TitleID); if (header.Return == NucleusCDN.ReturnType.Success) { if (!File.Exists("./Images/GameThumbnails/" + metaData.npdm.TitleID + ".jpg")) { File.WriteAllBytes("./Images/GameThumbnails/" + metaData.npdm.TitleID + ".jpg", NucleusCDN.MakeIconRequest(metaData.npdm.TitleID)); } entrysfound.Add(new GameList.GameListEntry { AppName = header.GameName, Publisher = header.Publisher, TitleID = metaData.npdm.TitleID, GamePath = dir }); ++foundgames; } else { ++skippedgames; continue; } } } ScanState.Text = "All Games found: " + foundgames + "\nAll Games Skipped: " + skippedgames; } }
public static GameList.GameListNACP GetGameMetadata(string TitleID) { Process hactool = null; ProcessStartInfo startInfo = new ProcessStartInfo(); did = RandomString(16); // Set up the inital Certificate and URL ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications; string MetaURL = "https://atum.hac.lp1.d4c.nintendo.net/t/a/" + TitleID + "/" + ver; X509Certificate2 Cert = new X509Certificate2(CertPath, "switch"); // Get the Meta NCA ID HttpWebRequest GetMetaNCAID = (HttpWebRequest)WebRequest.Create(MetaURL); GetMetaNCAID.ClientCertificates.Add(Cert); GetMetaNCAID.Method = "HEAD"; GetMetaNCAID.UserAgent = "NintendoSDK Firmware/" + fw + " (platform:NX; did:" + did + "; eid:lp1)"; HttpWebResponse ParseMetaNCAID = null; try { ParseMetaNCAID = (HttpWebResponse)GetMetaNCAID.GetResponse(); } catch (WebException we) { HttpStatusCode statusCode = ((HttpWebResponse)we.Response).StatusCode; if (statusCode == HttpStatusCode.NotFound) { return(new GameList.GameListNACP()); // If it's not found on the CDN then just return null values. } else { throw we; // Else just throw the Exception. } } ParseMetaNCAID.Close(); // Download The Meta NCA string MetaNCAURL = "https://atum.hac.lp1.d4c.nintendo.net/c/a/" + ParseMetaNCAID.GetResponseHeader("x-nintendo-content-id"); HttpWebRequest GetMetaNCA = (HttpWebRequest)WebRequest.Create(MetaNCAURL); GetMetaNCA.ClientCertificates.Add(Cert); GetMetaNCA.UserAgent = "NintendoSDK Firmware/" + fw + " (platform:NX; did:" + did + "; eid:lp1)"; HttpWebResponse ParseMetaNCA = (HttpWebResponse)GetMetaNCA.GetResponse(); BinaryReader MetaNCA = new BinaryReader(ParseMetaNCA.GetResponseStream()); File.WriteAllBytes(ver, MetaNCA.ReadBytes(100000)); MetaNCA.Close(); ParseMetaNCA.Close(); // Use Hactool to extract the CNMT startInfo.FileName = "hactool.exe"; startInfo.Arguments = "-k keys.txt " + ver + " --section0dir=CNMT"; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.UseShellExecute = true; hactool = Process.Start(startInfo); hactool.Start(); hactool.WaitForExit(); Thread.Sleep(300); File.Delete(ver); // Parse the CNMT to get the NCA ID BinaryReader OpenCNMT = new BinaryReader(File.Open("CNMT/Application_" + TitleID + ".cnmt", FileMode.Open)); string ParseCNMT = ByteArrayToString(OpenCNMT.ReadBytes(1000)); OpenCNMT.Close(); string ContNCAID = ""; if (ParseCNMT.Substring(32, 2) == "03") { if (ParseCNMT.Substring(316, 2) == "03") { ContNCAID = ParseCNMT.Substring(272, 32); } else if (ParseCNMT.Substring(428, 2) == "03") { ContNCAID = ParseCNMT.Substring(384, 32); } } else if (ParseCNMT.Substring(32, 2) == "04") { if (ParseCNMT.Substring(316, 2) == "03") { ContNCAID = ParseCNMT.Substring(272, 32); } else if (ParseCNMT.Substring(428, 2) == "03") { ContNCAID = ParseCNMT.Substring(384, 32); } else if (ParseCNMT.Substring(540, 2) == "03") { ContNCAID = ParseCNMT.Substring(496, 32); } } Directory.Delete("./CNMT", true); // Get the Control NCA string ContNCAURL = "https://atum.hac.lp1.d4c.nintendo.net/c/c/" + ContNCAID; HttpWebRequest GetContNCA = (HttpWebRequest)WebRequest.Create(ContNCAURL); GetContNCA.ClientCertificates.Add(Cert); GetContNCA.UserAgent = "NintendoSDK Firmware/" + fw + " (platform:NX; did:" + did + "; eid:lp1)"; HttpWebResponse ParseContNCA = (HttpWebResponse)GetContNCA.GetResponse(); BinaryReader ContNCA = new BinaryReader(ParseContNCA.GetResponseStream()); File.WriteAllBytes("TempCont", ContNCA.ReadBytes(10000000)); ParseContNCA.Close(); // Finally extract the Control NCA into a folder called Cont startInfo.Arguments = " -k keys.txt TempCont --section0dir=Cont"; hactool = Process.Start(startInfo); hactool.Start(); hactool.WaitForExit(); Thread.Sleep(300); File.Delete("TempCont"); GameList.GameListNACP res = GameList.ParseControlNacp("./Cont/control.nacp"); // Get the Icon File (and default to American English) string IconFile = ""; if (File.Exists("Cont/icon_AmericanEnglish.dat")) { IconFile = "Cont/icon_AmericanEnglish.dat"; } else { foreach (string s in Directory.GetFiles("./Cont")) { if (Path.GetFileName(s).StartsWith("icon_")) { IconFile = s; break; } } } if (File.Exists("./Images/GameThumbnails/" + TitleID + ".jpg")) { File.Delete("./Images/GameThumbnails/" + TitleID + ".jpg"); } File.Copy(IconFile, "./Images/GameThumbnails/" + TitleID + ".jpg"); Directory.Delete("./Cont", true); return(res); }