private static void UnpackXBox360Package(string sourceFileName, string savePath, Platform platform) { LogRecord x = new LogRecord(); STFSPackage xboxPackage = new STFSPackage(sourceFileName, x); if (!xboxPackage.ParseSuccess) { throw new InvalidDataException("Invalid Rocksmith XBox 360 package!" + Environment.NewLine + x.Log); } var rootDir = Path.Combine(savePath, Path.GetFileNameWithoutExtension(sourceFileName)) + String.Format("_{0}", platform.platform.ToString()); xboxPackage.ExtractPayload(rootDir, true, true); foreach (var fileName in Directory.EnumerateFiles(Path.Combine(rootDir, ROOT_XBox360))) { if (Path.GetExtension(fileName) == ".psarc") { using (var outputFileStream = File.OpenRead(fileName)) { ExtractPSARC(fileName, Path.GetDirectoryName(fileName), outputFileStream, new Platform(GamePlatform.XBox360, GameVersion.None), false); } } if (File.Exists(fileName) && Path.GetExtension(fileName) == ".psarc") { File.Delete(fileName); } } xboxPackage.CloseIO(); }
void fix(int i) { STFSPackage x = null; try { x = new STFSPackage((string)listBox1.Items[i], null); } catch { } if (x != null) { if (x.ParseSuccess) { if (checkBoxX1.Checked) { x.Header.MakeAnonymous(); } if (checkBoxX2.Checked) { x.FlushPackage(par.PublicKV); } else { x.UpdateHeader(par.PublicKV); } } x.CloseIO(); } }
private void frm_game_info_multiple_Load(object sender, EventArgs e) { new Thread(new ThreadStart(delegate { for (int i = 0; i < Files.Count(); i++) { Image Content = null, Package = null; bool Error = false, HasImage = true; string Display = "", Title = "", DeviceID = "", TitleID = "", ConsoleID = "", ProfileID = "", SubFolder = "", TitleFolder = "", ContentRoot = "", FullDirectory = "", Hash = "", Revision = ""; STFSP = new STFSPackage(this.Files[i], Logs); if (STFSP.ParseSuccess) { try { try { Content = this.STFSP.Header.ContentImage; Package = this.STFSP.Header.PackageImage; } catch { HasImage = false; } Display = this.STFSP.Header.Title_Display; Title = this.STFSP.Header.Title_Package; DeviceID = Conversion.BytesToHexString(this.STFSP.Header.DeviceID); TitleID = this.STFSP.Header.TitleID.ToString("X2").ToUpper(); this.STFSP.CloseIO(); List <byte> fileBytes = FileEx.ReadBytes(this.Files[i], 0, 0x9725 /*0x450*/).ToList(); string[] accepted = { "LIVE", "PIRS", "CON " }; string fileType = Encoding.UTF8.GetString(fileBytes.GetRange(0, 0x4).ToArray()); if (accepted.Contains(fileType)) { ConsoleID = Conversion.BytesToHexString(fileBytes.GetRange(0x36C, 0x4).ToArray()); ProfileID = Conversion.BytesToHexString(fileBytes.GetRange(0x371, 0x4).ToArray()); SubFolder = Conversion.BytesToHexString(fileBytes.GetRange(0x344, 0x4).ToArray()); TitleFolder = Conversion.BytesToHexString(fileBytes.GetRange(0x360, 0x4).ToArray()); Revision = Convert.ToInt32(fileBytes.GetRange(0x9724, 0x1).ToArray()[0]).ToString(); ContentRoot = this.STFSP.Header.ThisType != PackageType.Profile ? Conversion.BytesToHexString(fileBytes.GetRange(0x364, 0x8).ToArray()) : this.STFSP.Header.Title_Display; FullDirectory = String.Format("HDD:\\Content\\{0}\\{1}\\{2}", ContentRoot, TitleFolder, SubFolder); Hash = Hashing.MD5(fileBytes.ToArray()).Substring(0, 12).ToUpper(); } } catch { Invoke(new MethodInvoker(() => { Error = true; this.Text = String.Format("Game Info - {0}/{1} | Errors: {2}", this.Successes, this.Files.Count(), this.Errors++); })); } Info.Add(new STFSInfo { Display = Display, Title = TitleFolder, DeviceID = DeviceID, TitleID = TitleID, ConsoleID = ConsoleID, ProfileID = ProfileID, Sub = SubFolder, TitleName = Title, Content = Content, FullDirectory = FullDirectory, Package = Package, Root = ContentRoot, Local = this.Files[i], Error = Error, Hash = Hash, HasImage = HasImage, Revision = Revision }); Invoke(new MethodInvoker(() => { this.Text = String.Format("Game Info - {0}/{1}{2}{3}", this.Successes++, this.Files.Count(), (Error ? " | Errors: " : ""), (Error ? this.Errors.ToString() : "")); if (!Error) { FormE.ListViews.addToListView(lv_main, TitleID, (Title == "" ? Xbox.HexTitleToName(Convert.ToUInt32(TitleID, 16)) : Title), "Loaded", Hash, Revision); } })); } else { this.Errors++; } } Invoke(new MethodInvoker(() => { this.Text = "Game Info - Finished Loading Files"; this.Finished = true; Info.ForEach(s => Console.WriteLine(s.ToString())); })); })).Start(); }
static STFSPackage LoadSTFS(byte[] data) { DJsIO dj = new DJsIO(data, true); var ret = new STFSPackage(dj, null); if (ret.ParseSuccess == false) ret = null; return ret; }
/// <summary> /// Initializes an instance /// </summary> /// <param name="x"></param> public ProfilePackage(ref STFSPackage x) : base(ref x) { if (Header.ThisType == PackageType.Profile) { LoadProfile(true); } }
public bool ExtractDecryptMogg(string CON_file, bool bypass, NemoTools tools, DTAParser parser) { Initialize(); Tools = tools; Parser = parser; Tools.ReleaseStreamHandle(); if (!Parser.ExtractDTA(CON_file)) { ErrorLog.Add("Couldn't extract songs.dta file from that CON file"); return(false); } if (!Parser.ReadDTA(Parser.DTA) || !Parser.Songs.Any()) { ErrorLog.Add("Couldn't read that songs.dta file"); return(false); } if (Parser.Songs.Count > 1) { ErrorLog.Add("This feature does not support packs, only single songs\nUse the dePACK feature in C3 CON Tools' Quick Pack Editor to split this pack into single songs and try again"); return(false); } var internal_name = Parser.Songs[0].InternalName; var xCON = new STFSPackage(CON_file); if (!xCON.ParseSuccess) { ErrorLog.Add("Couldn't parse that CON file"); xCON.CloseIO(); return(false); } var xMogg = xCON.GetFile("songs/" + internal_name + "/" + internal_name + ".mogg"); if (xMogg == null) { ErrorLog.Add("Couldn't find the mogg file inside that CON file"); xCON.CloseIO(); return(false); } var mData = xMogg.Extract(); xCON.CloseIO(); if (mData == null || mData.Length == 0) { ErrorLog.Add("Couldn't extract the mogg file from that CON file"); return(false); } LoadLibraries(); if (Tools.DecM(mData, bypass, false, DecryptMode.ToMemory)) { return(true); } ErrorLog.Add("Mogg file is encrypted and I could not decrypt it, can't split it"); return(false); }
private void buttonX2_Click(object sender, EventArgs e) { try { STFSPackage STFS = new STFSPackage(OFD1.FileName, null); STFS.FlushPackage(new RSAParams(Application.StartupPath + "\\KV.bin")); MessageBox.Show("Rehashed and Resigned"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private bool LoadCon(string filename) { con = STFSPackage.OpenFile(GameArchives.Util.LocalFile(filename)); if (con.Type != STFSType.CON) { MessageBox.Show("Error: given file was not a CON file"); return(false); } var songs = PkgCreator.ConvertDLCPackage(con.RootDirectory.GetDirectory("songs")); idBox.Text = PkgCreator.GenId(songs[0]); descriptionBox.Text = $"Custom: \"{songs[0].SongData.Name} - {songs[0].SongData.Artist}\""; groupBox2.Enabled = true; return(true); }
private void updateSaveFile() { // FIXME: This is hax, you have to invoke the dispatcher from a STA thread so that showQuestion will work -_- Thread backupThread = new Thread(() => { Dispatcher.Invoke(new Action(makeBackup)); }); backupThread.SetApartmentState(ApartmentState.STA); backupThread.Start(); backupThread.Join(); STFSPackage package = new STFSPackage(_packagePath, null); _saveManager.SaveChanges(package, Properties.Resources.KV); package.CloseIO(); }
/// <summary> /// Does the whole process of converting a CON to a GP4 project /// </summary> /// <param name="conPath">Path to CON file</param> /// <param name="buildDir">Output directory for project and files</param> /// <param name="eu">If true then an SCEE project is made (otherwise, SCEA)</param> public static void ConToGp4(string conPath, string buildDir, bool eu = false, string id = null, string desc = null) { // Phase 1: Reading from CON var con = STFSPackage.OpenFile(GameArchives.Util.LocalFile(conPath)); if (con.Type != STFSType.CON) { Console.WriteLine("Error: given file was not a CON file"); return; } var songs = ConvertDLCPackage(con.RootDirectory.GetDirectory("songs")); var identifier = id ?? GenId(songs.Select(s => s.SongData).ToList()); var pkgId = eu ? $"EP8802-CUSA02901_00-{identifier}" : $"UP8802-CUSA02084_00-{identifier}"; var pkgDesc = GenDesc(songs.Select(s => s.SongData).ToList()); DLCSongsToGP4(songs, pkgId, desc ?? pkgDesc, buildDir, eu); }
private bool PackageCreate(string con, CreateSTFS xsession) { var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); try { xsession.HeaderData.Title_Display = artistSongTool.Checked ? (SongArtist + " - " + SongTitle) : ("\"" + SongTitle + "\"" + (songByArtistTool.Checked ? " by " + SongArtist : "")); xsession.HeaderData.Description = "Converted to CON using C3 CON Tools"; var xy = new STFSPackage(xsession, signature, con); xy.CloseIO(); return(true); } catch (Exception) { return(false); } }
private bool LoadCon(string filename) { using (var con = STFSPackage.OpenFile(GameArchives.Util.LocalFile(filename))) { if (con.Type != STFSType.CON) { throw new Exception($"File is not a CON file."); } var datas = PkgCreator.GetSongMetadatas(con.RootDirectory.GetDirectory("songs")); if (datas.Count > 0) { dtas[filename] = datas; listBox1.Items.Add(filename); } } return(true); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { xsession.HeaderData.ContentImageBinary = picContent.Image.ImageToBytes(ImageFormat.Png); xsession.HeaderData.PackageImageBinary = picPackage.Image.ImageToBytes(ImageFormat.Png); switch (GameIndex) { case 0: xsession.HeaderData.TitleID = 0x45410829; break; case 1: xsession.HeaderData.TitleID = 0x45410869; break; case 2: xsession.HeaderData.TitleID = 0x45410914; break; } xsession.HeaderData.Publisher = ""; xsession.HeaderData.Title_Package = "Rock Band " + (GameIndex + 1); xsession.HeaderData.SetLanguage(Languages.English); xsession.HeaderData.Title_Display = Title; xsession.HeaderData.Description = Description; xsession.STFSType = STFSType.Type0; xsession.HeaderData.MakeAnonymous(); xsession.HeaderData.ThisType = radioCON.Checked ? PackageType.SavedGame : PackageType.MarketPlace; signature = radioCON.Checked ? new RSAParams(Application.StartupPath + "\\bin\\KV.bin") : new RSAParams(StrongSigned.LIVE); var xy = new STFSPackage(xsession, signature, xOut); xy.CloseIO(); //now open and unlock if (!Tools.UnlockCON(xOut)) { MessageBox.Show("There was an error unlocking CON file\nCan't finish", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //convert to CON if button checked, if not, leave as LIVE if (!radioCON.Checked) { return; } if (!Tools.SignCON(xOut)) { MessageBox.Show("There was an error signing CON file\nCan't finish", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public XBoxUniqueID(string FileName) { BinaryReader br = new BinaryReader(File.Open(FileName, FileMode.Open), Encoding.ASCII); string Magic = new string(br.ReadChars(3)); if (Magic != "CON") { throw new FileFormatException(); } br.Close(); br = null; STFSPackage CON = new STFSPackage(new DJsIO(FileName, DJFileMode.Open, true), new X360.Other.LogRecord()); ProfileID = CON.Header.ProfileID; DeviceID = CON.Header.DeviceID; CON.CloseIO(); }
void plugclick(object sender, EventArgs e) { string locale = VariousFunctions.GetUserFileLocale("Open a File", "", true); if (locale == null) { return; } // Integrate log choice STFSPackage x = new STFSPackage(locale, null); if (!x.ParseSuccess) { return; } try { ((LFPlugIn)((ToolStripItem)sender).Tag).xConst.Invoke(new object[] { x, (Form)this }); } catch (Exception z) { x.CloseIO(); MessageBox.Show(z.Message); } }
private void GatherInformation(string Location) { try { this.STFSP = new STFSPackage(Location, this.Log); if (this.STFSP.ParseSuccess) { try { pb_content.Image = this.STFSP.Header.ContentImage; pb_package.Image = this.STFSP.Header.PackageImage; } catch { } tb_display.Text = this.STFSP.Header.Title_Display; tb_titleName.Text = this.STFSP.Header.Title_Package; tb_deviceID.Text = Conversion.BytesToHexString(this.STFSP.Header.DeviceID); tb_titleID.Text = this.STFSP.Header.TitleID.ToString("X2").ToUpper(); this.STFSP.CloseIO(); // Now we'll do our own shit to get the location of where this package goes. List <byte> fileBytes = FileEx.ReadBytes(Location, 0, 0x9725).ToList(); string[] accepted = { "LIVE", "PIRS", "CON " }; string fileType = Encoding.UTF8.GetString(fileBytes.GetRange(0, 0x4).ToArray()); if (accepted.Contains(fileType)) { tb_consoleID.Text = Conversion.BytesToHexString(fileBytes.GetRange(0x36C, 0x4).ToArray()); tb_profileID.Text = Conversion.BytesToHexString(fileBytes.GetRange(0x371, 0x4).ToArray()); string SubFolder = Conversion.BytesToHexString(fileBytes.GetRange(0x344, 0x4).ToArray()); string TitleFolder = Conversion.BytesToHexString(fileBytes.GetRange(0x360, 0x4).ToArray()); string ContentRoot = this.STFSP.Header.ThisType != PackageType.Profile ? Conversion.BytesToHexString(fileBytes.GetRange(0x364, 0x8).ToArray()) : this.STFSP.Header.Title_Display; string Revision = Convert.ToInt32(fileBytes.GetRange(0x9724, 0x1).ToArray()[0]).ToString(); lbl_rootFolder.Text = ContentRoot; lbl_titleFolder.Text = TitleFolder; lbl_subFolder.Text = SubFolder; tb_fullDirectory.Text = String.Format("HDD:\\Content\\{0}\\{1}\\{2}", ContentRoot, TitleFolder, SubFolder); this.Text = String.Format("Game Info - {0}: TU {1}", (tb_titleName.Text != "" ? tb_titleName.Text : Xbox.HexTitleToName(Convert.ToUInt32(tb_titleID.Text, 16))), Revision); } else { if (MessageBox.Show(Location + "\r\n\r\nInvalid file format! " + fileType, "Invalid Format", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { return; } } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error Loading File", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private Util.SaveType detectGame(STFSPackage package, out string rawFileName) { if (((~package.Header.TitleID) ^ 0x12345678) == 0xAC9DA14C) { rawFileName = null; return(Util.SaveType.SomeGame); } Util.SaveType game = Util.GameID.IdentifyGame(package); switch (game) { case Util.SaveType.Reach: _saveManager = _reachSaveManager; rawFileName = "mmiof.bmf"; break; case Util.SaveType.Anniversary: _saveManager = _hcexSaveManager; rawFileName = "saves.cfg"; break; case Util.SaveType.Halo3: _saveManager = _halo3SaveManager; rawFileName = "mmiof.bmf"; break; case Util.SaveType.Halo3ODST: _saveManager = _halo3ODSTSaveManager; rawFileName = "mmiof.bmf"; break; case Util.SaveType.Halo4: _saveManager = _halo4SaveManager; rawFileName = "mmiof.bmf"; break; default: rawFileName = null; break; } return(game); }
private void backgroundWorker2_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { var counter = 0; foreach (var file in FilesToConvert.TakeWhile(file => !backgroundWorker2.CancellationPending)) { Log("Converting STFS file '" + Path.GetFileName(file) + "'"); try { var xFile = new STFSPackage(file); if (!xFile.ParseSuccess) { Log("Couldn't parse that file, skipping..."); continue; } xFile.Header.MakeAnonymous(); xFile.Header.ThisType = doLIVE ? PackageType.MarketPlace : PackageType.SavedGame; var signature = doLIVE ? new RSAParams(StrongSigned.LIVE) : new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); xFile.RebuildPackage(signature); xFile.FlushPackage(signature); xFile.CloseIO(); Tools.UnlockCON(file); if (!doLIVE) { Tools.SignCON(file); } Log("Successfully converted '" + Path.GetFileName(file) + "' to " + (doLIVE ? "LIVE" : "CON...")); counter++; xFile.CloseIO(); } catch (Exception ex) { Log("There was an error converting that file"); Log("The error says: " + ex.Message); } } Log("Finished converting " + (counter == 1 ? "file" : "files")); Log("Ready"); }
private void buttonX1_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure you want to change these packages?", "WARNING", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } menuStrip1.Enabled = groupPanel1.Enabled = listBox1.Enabled = false; progressBarX1.Value = 0; progressBarX1.Maximum = listBox1.Items.Count; for (int i = 0; i < listBox1.Items.Count; i++) { STFSPackage x = null; try { x = new STFSPackage((string)listBox1.Items[i], null); } catch { } if (x != null) { fix(i); } progressBarX1.Value++; } menuStrip1.Enabled = groupPanel1.Enabled = listBox1.Enabled = true; }
private bool buildPackage() { bool success; try { var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); var bigpack = new STFSPackage(packfiles, signature, xOut); var count1 = bigpack.xFileDirectory.Count; bigpack.CloseIO(); var pack = new STFSPackage(xOut); var count2 = pack.xFileDirectory.Count; pack.CloseIO(); if (count1 == count2) { Log("Awesome ... looks like everything went smoothly"); success = true; } else { MessageBox.Show("Sorry, it looks like there was a problem creating your pack\nThere should be a total of " + count1 + " files but the pack is only reporting " + count2 + " files\n\nThis is caused by a nasty bug in the X360 library " + "we thought we had fixed!\n\nClick 'View Package' to open pack in CON Explorer and start checking each song's folder, " + "whenever you find the first song that has only a .mid file in its folder, that's likely the file causing the problem\nRemove that " + "file and try building the pack again\n\nDO NOT PUT THIS PACK IN YOUR GAME", Text + " - Big Bad Bug", MessageBoxButtons.OK, MessageBoxIcon.Error); sOpenPackage = xOut; Log("Pack creation failed ... remove problem file and try again"); success = false; } } catch { Log("There was an error building CON file"); success = false; } return(success); }
private void HandleDragDrop(object sender, DragEventArgs e) { if (picWorking.Visible) { return; } var files = (string[])e.Data.GetData(DataFormats.FileDrop); if (VariousFunctions.ReadFileType(files[0]) == XboxFileType.STFS) { var xFile = new STFSPackage(files[0]); if (xFile.ParseSuccess) { doLIVE = xFile.Header.ThisType != PackageType.MarketPlace; xFile.CloseIO(); SelectFilesToConvert(Path.GetDirectoryName(files[0])); return; } } txtFolder.Text = Path.GetDirectoryName(files[0]); Tools.CurrentFolder = txtFolder.Text; }
private string ExtractMIDI(string con, bool isUpgrade) { var midi = ""; var xPackage = new STFSPackage(con); if (!xPackage.ParseSuccess) { MessageBox.Show("There was an error parsing CON file, can't extract MIDI", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); Log("Can't work with this CON file, try again"); return(""); } try { var xent = xPackage.GetFolder("songs"); if (xent == null && !isUpgrade) { xent = xPackage.GetFolder("songs_upgrades"); MessageBox.Show(xent != null ? "This looks like a pro upgrade, only song files are valid here" : "I can't find a 'songs' folder in that CON file, make sure sure it's a Rock Band song file", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } //we can't work with packs or pro upgrades, so check and skip xent = xPackage.GetFolder("songs_upgrades"); if (xent != null && !isUpgrade) { xent = xPackage.GetFolder("songs"); MessageBox.Show(xent != null ? "It looks like this is a pack, only individual song files are valid here" : "This looks like a pro upgrade, only song files are valid here", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } var folder = isUpgrade ? "songs_upgrades/" : "songs/"; var dtaFile = isUpgrade ? "upgrades.dta" : "songs.dta"; var dta = temp_folder + dtaFile; if (Parser.ExtractDTA(xPackage, false, isUpgrade)) { if (Parser.ReadDTA(Parser.DTA) && Parser.Songs.Count > 1) { MessageBox.Show("It looks like this is a pack, only individual song files are valid here", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } } var xFile = xPackage.GetFile(folder + dtaFile); if (xFile == null) { MessageBox.Show("Can't find " + dtaFile + " inside this CON file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } var fileName = Path.GetFileName(con); if (fileName != null) { if (!Parser.WriteDTAToFile(dta)) { MessageBox.Show("Something went wrong in extracting the " + dtaFile + " file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } } var artists = 0; var songname = ""; var sr = new StreamReader(dta, Parser.GetDTAEncoding(Parser.DTA)); // read one line at a time until the end while (sr.Peek() >= 0) { var line = sr.ReadLine(); if (string.IsNullOrWhiteSpace(line.Trim())) { continue; } if (line.ToLowerInvariant().Contains("artist") && !line.ToLowerInvariant().Contains(";") && !isUpgrade) { artists++; } else if (line.ToLowerInvariant().Contains("songs/") && !line.Contains("midi_file") && !isUpgrade) { songname = Parser.GetInternalName(line); song_int_name = songname; } else if (line.Contains("song_id")) { if (isUpgrade) { upgradeID = Parser.GetSongID(line); } else { songID = Parser.GetSongID(line); CheckIDMatch(); } } else if (line.Contains("midi_file") && isUpgrade) { var midipath = line.Replace("(", ""); midipath = midipath.Replace(")", ""); midipath = midipath.Replace("midi_file", ""); midipath = midipath.Replace("songs_upgrades", ""); midipath = midipath.Replace("\"", ""); midipath = midipath.Replace("/", ""); songname = midipath.Trim(); upgrade_int_name = songname.Replace(".mid", ""); } } sr.Dispose(); if (artists > 1) //if single song, packs will have values > 1 { MessageBox.Show("It looks like this is a pack, only individual song files are valid here", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } xFile = xPackage.GetFile(folder + songname + (isUpgrade ? "" : "/" + songname + ".mid")); if (xFile != null) { midi = temp_folder + songname + (isUpgrade? "" : ".mid"); Tools.DeleteFile(midi); if (!xFile.ExtractToFile(midi)) { MessageBox.Show("Can't find a MIDI file inside this CON file\nI can't work without it", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); xPackage.CloseIO(); Log("Can't work with this CON file, try again"); return(""); } } xPackage.CloseIO(); if (isUpgrade) { newupgdta = dta; ReadUpgDTA(newupgdta); } else { orig_dta = dta; } } catch (Exception ex) { MessageBox.Show("There was an error:\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); xPackage.CloseIO(); } return(midi); }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { if (!File.Exists(orig_con)) { Log("CON file " + Path.GetFileName(orig_con) + " seems to have been deleted, can't continue without it"); return; } var BundleFile = orig_con + " (bundled)"; Tools.DeleteFile(BundleFile); File.Copy(orig_con, BundleFile); var xPackage = new STFSPackage(BundleFile); if (!xPackage.ParseSuccess) { Log("There was an error parsing CON file to bundle"); xPackage.CloseIO(); return; } var xent = xPackage.GetFile("/songs/songs.dta"); if (xent != null) { if (xent.Replace(newDTA)) { Log("Bundled DTA file successfully"); } } xent = xPackage.GetFile("/songs/" + Path.GetFileNameWithoutExtension(orig_midi) + "/" + Path.GetFileName(orig_midi)); if (xent != null) { if (xent.Replace(newMIDI)) { Log("Bundled MIDI file successfully"); } } xPackage.Header.MakeAnonymous(); xPackage.Header.ThisType = PackageType.SavedGame; var success = false; try { Log("Rebuilding CON file ... this might take a little while"); signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); if (ChangeGameID.Checked) { xPackage.Header.TitleID = 0x45410914; xPackage.Header.Title_Package = "Rock Band 3"; xPackage.Header.ContentImageBinary = Resources.RB3.ImageToBytes(ImageFormat.Png); } xPackage.RebuildPackage(signature); xPackage.FlushPackage(signature); xPackage.CloseIO(); success = true; } catch (Exception ex) { Log("There was an error: " + ex.Message); xPackage.CloseIO(); } if (success) { Log("Trying to unlock CON file"); if (Tools.UnlockCON(BundleFile)) { Log("Unlocked CON file successfully"); } else { Log("Error unlocking CON file"); success = false; } } if (success) { Log("Trying to sign CON file"); if (Tools.SignCON(BundleFile)) { Log("CON file signed successfully"); } else { Log("Error signing CON file"); success = false; } } Log(success ? "Your files were bundled successfully!" : "Something went wrong along the way, sorry!"); if (!cleanUpAfterBundlingFiles.Checked) { return; } Log("Cleaning up"); CleanUp(); }
void ReadFile(string file) { try { switch (VariousFunctions.ReadFileType(file)) { case XboxFileType.STFS: { LogRecord x = new LogRecord(); STFSPackage xPackage = new STFSPackage(file, x); if (!xPackage.ParseSuccess) { return; } PackageExplorer xExplorer = new PackageExplorer(this); xExplorer.listBox4.Items.AddRange(x.Log); x.WhenLogged += new LogRecord.OnLog(xExplorer.xAddLog); xExplorer.set(ref xPackage); xExplorer.Show(); } break; case XboxFileType.SVOD: { SVODPackage hd = new SVODPackage(file, null); if (!hd.IsValid) { return; } HDDGameForm frm = new HDDGameForm(hd, file, this); frm.MdiParent = this; frm.Show(); } break; case XboxFileType.Music: { MusicFile xfile = new MusicFile(file); MusicView xview = new MusicView(this, file, xfile); xview.MdiParent = this; xview.Show(); } break; case XboxFileType.GPD: { GameGPD y = new GameGPD(file, 0xFFFFFFFF); GPDViewer z = new GPDViewer(y, file, this); z.MdiParent = this; z.Show(); } break; case XboxFileType.FATX: { FATXDrive xdrive = new FATXDrive(file); Files.Add(file); FATXBrowser y = new FATXBrowser(xdrive, file, this); y.MdiParent = this; y.Show(); } break; case XboxFileType.GDF: { StatsForm x = new StatsForm(0); x.Text = "Select Deviation"; if (x.ShowDialog() != DialogResult.OK) { return; } GDFImage ximg = new GDFImage(file, x.ChosenID); if (!ximg.Valid) { throw new Exception("Invalid package"); } GDFViewer xViewer = new GDFViewer(ximg, this); xViewer.MdiParent = this; xViewer.Show(); } break; default: MessageBox.Show("Error: Unknown file"); return; } Files.Add(file); } catch (Exception x) { MessageBox.Show(x.Message); } }
public static byte[] CreateRB3Pro(CreateProConfig config) { STFSPackage pk = null; bool loadedExisting = false; if (config.existingCONFile != null) { try { pk = LoadSTFS(config.existingCONFile); } catch { } if (pk == null) { pk = LoadSTFS(Resources.proconfile); } else { loadedExisting = true; } } else { pk = LoadSTFS(Resources.proconfile); } bool loadedOK = false; if (pk != null) { //pk.Header.ContentImage = Resources.rockband; //pk.Header.PackageImage = Resources.rockband2; pk.Header.TitleID = config.TitleID; //pk.Header.MediaID = 4FC9256F; pk.Header.Description = config.description; pk.Header.Title_Display = config.displayTitle; var folder = pk.GetFolder("songs_upgrades"); if (loadedExisting) { var files = folder.GetSubFiles(); bool foundDTA = false; bool foundMID = false; foreach (var f in files) { if (string.Compare(f.Name, "upgrades.dta", StringComparison.OrdinalIgnoreCase) == 0) { string upgradeFile = Encoding.ASCII.GetString(Resources.upgrades); upgradeFile = upgradeFile.Replace("##songshortname##", config.songShortName); upgradeFile = upgradeFile.Replace("##profilename##", config.proMidiFileName); upgradeFile = upgradeFile.Replace("##songid##", config.song_id); upgradeFile = upgradeFile.Replace("##guitardifficulty##", config.guitarDifficulty); upgradeFile = upgradeFile.Replace("##bassdifficulty##", config.bassDifficulty); f.Replace(Encoding.ASCII.GetBytes(upgradeFile)); foundDTA = true; } else if (string.Compare(f.Name, config.proMidiFileName, StringComparison.OrdinalIgnoreCase) == 0) { f.Replace(config.midFileContents); foundMID = true; } } loadedOK = foundDTA && foundMID; if (!loadedOK) { pk.CloseIO(); config.existingCONFile = null; return CreateRB3Pro(config); } } else { foreach (var f in folder.GetSubFiles()) { if (f.Name.EndsWith(".mid", StringComparison.OrdinalIgnoreCase) || f.Name.EndsWith(".midi", StringComparison.OrdinalIgnoreCase)) { f.Name = config.proMidiFileName; f.Replace(config.midFileContents); } else if (f.Name.EndsWith(".dta", StringComparison.OrdinalIgnoreCase)) { string upgradeFile = Encoding.ASCII.GetString(Resources.upgrades); f.Name = "upgrades.dta"; upgradeFile = upgradeFile.Replace("##songshortname##", config.songShortName); upgradeFile = upgradeFile.Replace("##profilename##", config.proMidiFileName); upgradeFile = upgradeFile.Replace("##songid##", config.song_id); upgradeFile = upgradeFile.Replace("##guitardifficulty##", config.guitarDifficulty); upgradeFile = upgradeFile.Replace("##bassdifficulty##", config.bassDifficulty); f.Replace(Encoding.ASCII.GetBytes(upgradeFile)); } } } } var bytes = pk.RebuildPackageInMemory( new RSAParams(new DJsIO(Resources.KV, true))); pk.CloseIO(); return bytes; }
private Util.SaveType loadSaveFile(string stfsPath) { // lolmultithreading _reachTaglists.RemoveMapSpecificTaglists(); if (_saveManager != null) { _saveManager.Close(); } STFSPackage package = null; try { // Open the STFS package string rawFileName; try { package = new STFSPackage(stfsPath, null); } catch (Exception ex) { throw new ArgumentException("The selected file is not a valid STFS package.", ex); } // Before detecting the save's game, check if it's a "Halo 4 Data" package // These packages aren't actually saved games, but a lot of users are getting this confused if (package.GetFile("data.cache") != null) { Action wrongFileAction = new Action(() => { showMessage("Packages named \"Halo 3 Data\" or \"Halo 4 Data\" aren't actual save files. You need to copy the ~11 MB file named after your gamertag instead. If you don't see anything, make sure to get to a checkpoint first.", "OOPS"); } ); Dispatcher.Invoke(wrongFileAction); return(Util.SaveType.Unknown); } // Detect the save's game _currentGame = detectGame(package, out rawFileName); classInfo.storage.settings.applicationSettings.gameIdent.gameID = _currentGame; if (_currentGame == Util.SaveType.Unknown) { Action notSupportedAction = new Action(() => { showMessage(package.Header.Title_Display + " saves are not supported yet. Currently, only Halo 3, Halo 3: ODST, Halo: Reach, Halo: CE Anniversary, and Halo 4 saves are supported. Please select a different file.", "GAME NOT SUPPORTED"); } ); Dispatcher.Invoke(notSupportedAction); return(Util.SaveType.Unknown); } else if (_currentGame == Util.SaveType.SomeGame) { Action eggAction = new Action(() => { eggData.egg3Dialog dialog = new eggData.egg3Dialog(); dialog.Owner = this; dialog.ShowDialog(); } ); Dispatcher.Invoke(eggAction); return(Util.SaveType.Unknown); } _saveManager.LoadSTFS(package, rawFileName, classInfo.extraIO.makeTempSaveDir()); _packagePath = stfsPath; // Update some UI controls with package info Dispatcher.Invoke(new Action <string, uint, string, long>(setPackageInfo), new object[] { package.Header.Title_Package, package.Header.TitleID, package.Header.Title_Display, package.Header.ProfileID }); } catch (ArgumentException ex) { Dispatcher.Invoke(new Action <string, string>(showMessage), new object[] { ex.Message, "ERROR" }); return(Util.SaveType.Unknown); } catch (Exception ex) { Dispatcher.Invoke(new Action <string, bool>(showException), new object[] { ex.ToString(), true }); return(Util.SaveType.Unknown); } finally { if (package != null) { package.CloseIO(); } } return(_currentGame); }
private void installGamePackageToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.ShowDialog(); if (File.Exists(ofd.FileName)) { // Open STFS Package STFSPackage package = new STFSPackage(ofd.FileName, null); // Unpack Archive string titleName = package.Header.Title_Display; string path = "Games/" + titleName; if (Directory.Exists(path)) { package.CloseIO(); goto CheckXNA; } Directory.CreateDirectory(path); MessageBox.Show("Ex360E will now install the game package, this may take a while\n and may appear to stop responding. Please be patient."); package.ExtractPayload(path, true, false); package.CloseIO(); CheckXNA: path += "/Root/"; // Check if XNA title if (!Directory.Exists(path + "Runtime")) { MessageBox.Show("Package not supported\nOnly XBLA games created with XNA Game Studio currently work."); return; } // Check if supported string[] directories = Directory.GetDirectories(path + "Runtime"); string frameworkVersion = "Unsupported"; for (int i = 0; i < directories.Length; i++) { // Currently only supports XNA 3.1 if (directories[i].Contains("v3.1")) { frameworkVersion = "v3.1"; } } if (frameworkVersion == "Unsupported") { MessageBox.Show("Sorry, this game uses a currently unsupported version of the XNA Framework."); return; } // Decrypt XEX Files string[] xexFiles = Directory.GetFiles(path, "*.xex", SearchOption.AllDirectories); for (int i = 0; i < xexFiles.Length; i++) { ProcessStartInfo info = new ProcessStartInfo("xextool.exe", "-b " + xexFiles[i].Replace(".xex", "") + " " + xexFiles[i]); info.CreateNoWindow = true; info.UseShellExecute = false; info.RedirectStandardOutput = true; Process proc = new Process(); proc.StartInfo = info; proc.Start(); proc.WaitForExit(); } // Trim useless PE Headers, leaving .NET assemblies behind string[] dllFiles = Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories); string[] exeFiles = Directory.GetFiles(path, "*.exe", SearchOption.AllDirectories); for (int i = 0; i < dllFiles.Length; i++) { string tmpFileName = dllFiles[i] + ".tmp"; FileStream inStream = new FileStream(dllFiles[i], FileMode.Open); FileStream outStream; // Set position inStream.Position = 0x30000; // Read Magic Number byte[] magic = new Byte[2]; inStream.Read(magic, 0, 2); // Check for MZ Header if (magic[0] == 0x4D && magic[1] == 0x5A) { outStream = new FileStream(tmpFileName, FileMode.Create); // Reset Position inStream.Position = 0x30000; // Copy data to temporary file int bufferSize = (int)inStream.Length - 0x30000; byte[] outData = new byte[bufferSize]; inStream.Read(outData, 0, bufferSize); inStream.Close(); outStream.Write(outData, 0, bufferSize); outStream.Flush(); outStream.Close(); File.Delete(dllFiles[i]); File.Move(tmpFileName, dllFiles[i]); } } for (int i = 0; i < exeFiles.Length; i++) { string tmpFileName = dllFiles[i] + ".tmp"; FileStream inStream = new FileStream(exeFiles[i], FileMode.Open); FileStream outStream; // Set position inStream.Position = 0x30000; // Read Magic Number byte[] magic = new Byte[2]; inStream.Read(magic, 0, 2); // Check for MZ Header if (magic[0] == 0x4D && magic[1] == 0x5A) { outStream = new FileStream(tmpFileName, FileMode.Create); // Reset Position inStream.Position = 0x30000; // Copy data to temporary file int bufferSize = (int)inStream.Length - 0x30000; byte[] outData = new byte[bufferSize]; inStream.Read(outData, 0, bufferSize); inStream.Close(); outStream.Write(outData, 0, bufferSize); outStream.Flush(); outStream.Close(); File.Delete(exeFiles[i]); File.Move(tmpFileName, exeFiles[i]); } } // Patch And Copy Runtime Files string[] XNALibs = Directory.GetFiles(path + "Runtime/" + frameworkVersion, "*.dll"); for (int i = 0; i < XNALibs.Length; i++) { // Patch files string patchFile = XNALibs[i].Replace(path, "Patches/") + ".xdelta"; string destFile = XNALibs[i].Replace("Runtime/" + frameworkVersion, ""); // If patch exists, apply it if (File.Exists(patchFile)) { ProcessStartInfo info = new ProcessStartInfo("xdelta", " -d -f -s " + XNALibs[i] + " " + patchFile + " " + destFile); info.CreateNoWindow = true; info.UseShellExecute = false; info.RedirectStandardOutput = true; Process proc = new Process(); proc.StartInfo = info; proc.Start(); proc.WaitForExit(); } // Copy un-patched files if (!File.Exists(destFile)) { File.Move(XNALibs[i], XNALibs[i].Replace("Runtime/" + frameworkVersion, "")); } // Patch to remove assembly verification DisableStrongNameSignatures(destFile); } // Patch Game Files string[] GameFiles = Directory.GetFiles(path, "*.*"); for (int i = 0; i < GameFiles.Length; i++) { // Patch files string patchFile = GameFiles[i].Replace(path, "Patches/Games/" + titleName + "/") + ".xdelta"; string destFile = GameFiles[i] + ".patched"; // If patch exists, apply it if (File.Exists(patchFile)) { ProcessStartInfo info = new ProcessStartInfo("xdelta", " -d -f -s " + GameFiles[i] + " " + patchFile + " " + destFile); info.CreateNoWindow = true; info.UseShellExecute = false; info.RedirectStandardOutput = true; Process proc = new Process(); proc.StartInfo = info; proc.Start(); proc.WaitForExit(); File.Delete(GameFiles[i]); File.Move(destFile, GameFiles[i]); } DisableStrongNameSignatures(GameFiles[i]); } // Copy Xbox 360 Emulation libraries string[] X360Libs = Directory.GetFiles("XboxLibs", "*.dll"); for (int i = 0; i < X360Libs.Length; i++) { File.Copy(X360Libs[i], X360Libs[i].Replace("XboxLibs", path), true); } // Ask to create desktop shortcut to game // Ask if game should be launched now } }
public void set(ref STFSPackage x) { xpack = x; Log("Package parsed"); node1.NodeClick += new EventHandler(xReturn_NodeClick); SetNodes(); node1.SetChecked(true, eTreeAction.Expand); Log("Contents loaded"); if (xPackage.FileNameShort.Length < 30) { this.Text = "Package - " + xPackage.FileNameShort; } else { this.Text = "Package - " + xPackage.FileNameShort.Substring(0, 30) + "..."; } textBoxX1.Text = xPackage.FileNameLong; textBoxX2.Text = xPackage.Header.Title_Display; textBoxX3.Text = xPackage.Header.Description; try { pictureBox1.Image = xPackage.Header.ContentImage; } catch { pictureBox1.Enabled = false; } try { pictureBox2.Image = xPackage.Header.PackageImage; } catch { pictureBox2.Enabled = false; } comboBoxEx1.SelectedIndex = 0; numericUpDown5.Value = xPackage.Header.SaveConsoleID; numericUpDown6.Value = xPackage.Header.ProfileID; textBoxX17.Text = xPackage.Header.DeviceID.HexString(); numericUpDown9_ValueChanged(null, null); if (xPackage.Header.IDTransfer == TransferLock.NoTransfer) { checkBoxX1.Checked = false; } else { checkBoxX2.Checked = ((byte)xPackage.Header.IDTransfer & 1) == 1; checkBoxX3.Checked = (((byte)xPackage.Header.IDTransfer >> 1) & 1) == 1; } labelX8.Text = "Title ID: " + xpack.Header.TitleID.ToString("X"); if (xPackage.Header.ThisType != PackageType.Profile) { tabItem4.Visible = false; return; } xprof = new ProfilePackage(ref x); xpack = null; xprof.RemovePhDAT(); if (xprof.HasValidAccount) { if (xprof.UserFile.IsLiveEnabled) { textBoxX9.Text = VariousFunctions.EndianConvert(BitConverter.GetBytes(xprof.UserFile.XUID)).HexString(); textBoxX9.Enabled = buttonX4.Enabled = checkBoxX5.Enabled = true; PassCode[] xPass = xprof.UserFile.GetPassCode(); if (xPass.Length > 0) { checkBoxX5.Checked = true; comboBoxEx3.SelectedItem = xPass[0]; comboBoxEx4.SelectedItem = xPass[1]; comboBoxEx5.SelectedItem = xPass[2]; comboBoxEx6.SelectedItem = xPass[3]; } } textBoxX8.Text = xprof.UserFile.GetGamertag(); buttonX5.Enabled = true; Log("Account loaded"); } if (xprof.HasDashGPD) { UserInfo xInfo = xprof.GetUserStrings(); if (xInfo.Bio != null) { textBoxX10.Text = xInfo.Bio; } if (xInfo.Motto != null) { textBoxX11.Text = xInfo.Motto; } if (xInfo.Name != null) { textBoxX12.Text = xInfo.Name; } if (xInfo.Location != null) { textBoxX13.Text = xInfo.Location; } Setting temp = xprof.UserGPD.GetSetting(GPDIDs.GCardZone); if (temp != null) { comboBoxEx7.Enabled = true; GamerZone[] zones = (GamerZone[])Enum.GetValues(typeof(GamerZone)); comboBoxEx7.DataSource = zones; if (Enum.IsDefined(typeof(GamerZone), temp.Data)) { comboBoxEx7.SelectedItem = (GamerZone)((uint)temp.Data); } else { comboBoxEx7.SelectedItem = GamerZone.Unknown; } has1 = buttonX16.Enabled = true; } temp = xprof.UserGPD.GetSetting(GPDIDs.GCardRep, SettingType.Float); if (temp != null) { numericUpDown1.Enabled = true; numericUpDown1.Value = (decimal)((float)temp.Data); has2 = buttonX16.Enabled = true; } SetList(); buttonX15.Enabled = listBox3.Enabled = true; // groupPanel2.Enabled = true; SetNmric(GPDIDs.GCardCredit, textBoxX15); Log("Profile loaded"); } if (!xprof.IsValidProfile) { if (xprof.HasValidAccount && !xprof.HasDashGPD) { MessageBox.Show("This file does not have valid Dash information, therefore achievement modding is disabled"); } else if (!xprof.HasValidAccount && xprof.HasDashGPD) { MessageBox.Show("This file does not have a valid user account, therefore, account block editing is disabled"); } else { tabItem4.Visible = false; MessageBox.Show("This file has no valid user information, profile - specific editing is disabled"); } } }