private static FullSpriteSet DoInitPSP(Stream iso, BackgroundWorker worker) { PatcherLib.Iso.PspIso.PspIsoInfo info = PatcherLib.Iso.PspIso.PspIsoInfo.GetPspIsoInfo(iso); const int numberOfPspSprites = 143; int tasks = numberOfPspSprites * 2 + 1; int tasksComplete = 0; var sprites = new List <AbstractSprite>(); XmlDocument doc = new XmlDocument(); doc.LoadXml(Properties.Resources.PSPFiles); foreach (XmlNode node in doc.SelectNodes(string.Format("/PspFiles/{0}/Sprite", typeof(MonsterSprite).FullName))) { string name = node.SelectSingleNode("@name").InnerText; List <string> filenames = new List <string>(); List <byte[]> bytes = new List <byte[]>(); foreach (XmlNode file in node.SelectNodes("Files/File")) { string filename = file.SelectSingleNode("@name").InnerText; worker.ReportProgress(tasksComplete++ *100 / tasks, "Reading " + filename); filenames.Add(filename); bytes.Add(FFTPack.GetFileFromIso(iso, info, (FFTPack.Files)Enum.Parse(typeof(FFTPack.Files), file.SelectSingleNode("@enum").InnerText))); } if (bytes.Count > 1) { sprites.Add(new MonsterSprite(bytes[0], bytes.Sub(1).ToArray())); } else { sprites.Add(new MonsterSprite(bytes[0])); } } foreach (Type t in new Type[] { typeof(TYPE1Sprite), typeof(TYPE2Sprite), typeof(ShortSprite), typeof(KANZEN), typeof(CYOKO), typeof(ARUTE) }) { ConstructorInfo constructor = t.GetConstructor(new Type[] { typeof(string), typeof(IList <byte>) }); foreach (XmlNode node in doc.SelectNodes(string.Format("/PspFiles/{0}/Sprite", t.FullName))) { worker.ReportProgress(tasksComplete++ *100 / tasks, "Reading " + node.SelectSingleNode("Files/File/@name").InnerText); sprites.Add((AbstractSprite)constructor.Invoke(new object[] { node.SelectSingleNode("@name").InnerText, FFTPack.GetFileFromIso(iso, info, (FFTPack.Files)Enum.Parse(typeof(FFTPack.Files), node.SelectSingleNode("Files/File/@enum").InnerText)) })); } } worker.ReportProgress(tasksComplete++ *100 / tasks, "Sorting..."); sprites.Sort((a, b) => a.Name.CompareTo(b.Name)); return(new FullSpriteSet(sprites, worker, tasksComplete, tasks)); }
public void PatchPspISO(Stream stream, BackgroundWorker worker, IList <PatchedByteArray> patches) { int totalTasks = patches.Count; int tasksComplete = 0; foreach (var patch in patches) { worker.ReportProgress(tasksComplete++ *100 / totalTasks, "Patching " + patch.SectorEnum.ToString()); FFTPack.PatchFile(stream, (int)((FFTPack.Files)patch.SectorEnum), (int)patch.Offset, patch.Bytes); } }
private void rebuildFFTPackMenuItem_Click(object sender, EventArgs e) { DoWorkEventHandler doWork = delegate(object sender1, DoWorkEventArgs args) { FFTPack.MergeDumpedFiles(folderBrowserDialog.SelectedPath, saveFileDialog.FileName, sender1 as BackgroundWorker); }; ProgressChangedEventHandler progress = delegate(object sender2, ProgressChangedEventArgs args) { progressBar.Visible = true; progressBar.Value = args.ProgressPercentage; }; RunWorkerCompletedEventHandler completed = null; completed = delegate(object sender3, RunWorkerCompletedEventArgs args) { progressBar.Visible = false; Enabled = true; patchPsxBackgroundWorker.ProgressChanged -= progress; patchPsxBackgroundWorker.RunWorkerCompleted -= completed; patchPsxBackgroundWorker.DoWork -= doWork; if (args.Error is Exception) { MessageBox.Show( "Could not merge files.\n" + "Make sure you chose the correct file and that there is\n" + "enough room in the destination directory.", "Error", MessageBoxButtons.OK); } }; saveFileDialog.OverwritePrompt = true; saveFileDialog.Filter = "fftpack.bin|fftpack.bin|All Files (*.*)|*.*"; saveFileDialog.FilterIndex = 0; folderBrowserDialog.Description = "Where are the extracted files?"; if ((folderBrowserDialog.ShowDialog(this) == DialogResult.OK) && (saveFileDialog.ShowDialog(this) == DialogResult.OK)) { patchPsxBackgroundWorker.ProgressChanged += progress; patchPsxBackgroundWorker.RunWorkerCompleted += completed; patchPsxBackgroundWorker.DoWork += doWork; Enabled = false; progressBar.Value = 0; progressBar.Visible = true; progressBar.BringToFront(); patchPsxBackgroundWorker.RunWorkerAsync(); } }
private static IList <byte> BytesFromPspIso(Stream iso, Enum file, int offset, int size) { if (file.GetType() == typeof(FFTPack.Files)) { return(FFTPack.GetFileFromIso(iso, pspIsoInfo, (FFTPack.Files)file).Sub(offset, offset + size - 1)); } else if (file.GetType() == typeof(PatcherLib.Iso.PspIso.Sectors)) { return(PatcherLib.Iso.PspIso.GetFile(iso, pspIsoInfo, (PatcherLib.Iso.PspIso.Sectors)file, offset, size)); } else { throw new ArgumentException(); } }
public static void ApplyPatch(Stream stream, PspIsoInfo info, PatcherLib.Datatypes.PatchedByteArray patch) { if (patch.SectorEnum != null) { if (patch.SectorEnum.GetType() == typeof(PspIso.Sectors)) { stream.WriteArrayToPosition(patch.GetBytes(), (int)(info[(PspIso.Sectors)patch.SectorEnum] * 2048) + patch.Offset); } else if (patch.SectorEnum.GetType() == typeof(FFTPack.Files)) { FFTPack.PatchFile(stream, info, (int)((FFTPack.Files)patch.SectorEnum), (int)patch.Offset, patch.GetBytes()); } else { throw new ArgumentException("invalid type"); } } }
private void rebuildFFTPackMenuItem_Click(object sender, EventArgs e) { CommonOpenFileDialog dialog = new CommonOpenFileDialog(); dialog.InitialDirectory = "."; dialog.IsFolderPicker = true; //using (Ionic.Utils.FolderBrowserDialogEx folderBrowserDialog = new Ionic.Utils.FolderBrowserDialogEx()) //{ DoWorkEventHandler doWork = delegate(object sender1, DoWorkEventArgs args) { //FFTPack.MergeDumpedFiles( folderBrowserDialog.SelectedPath, saveFileDialog.FileName, sender1 as BackgroundWorker ); FFTPack.MergeDumpedFiles(dialog.FileName, saveFileDialog.FileName, sender1 as BackgroundWorker); }; ProgressChangedEventHandler progress = delegate(object sender2, ProgressChangedEventArgs args) { progressBar.Visible = true; progressBar.Value = args.ProgressPercentage; }; RunWorkerCompletedEventHandler completed = null; completed = delegate(object sender3, RunWorkerCompletedEventArgs args) { progressBar.Visible = false; Enabled = true; patchPsxBackgroundWorker.ProgressChanged -= progress; patchPsxBackgroundWorker.RunWorkerCompleted -= completed; patchPsxBackgroundWorker.DoWork -= doWork; if (args.Error is Exception) { MyMessageBox.Show(this, "Could not merge files.\n" + "Make sure you chose the correct file and that there is\n" + "enough room in the destination directory.", "Error", MessageBoxButtons.OK); } }; saveFileDialog.OverwritePrompt = true; saveFileDialog.Filter = "fftpack.bin|fftpack.bin|All Files (*.*)|*.*"; saveFileDialog.FilterIndex = 0; //folderBrowserDialog.Description = "Where are the extracted files?"; //folderBrowserDialog.NewStyle = true; //folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop; //folderBrowserDialog.SelectedPath = Environment.CurrentDirectory; //folderBrowserDialog.ShowBothFilesAndFolders = false; //folderBrowserDialog.ShowEditBox = true; //folderBrowserDialog.ShowFullPathInEditBox = false; //folderBrowserDialog.ShowNewFolderButton = false; //if ((folderBrowserDialog.ShowDialog( this ) == DialogResult.OK) && (saveFileDialog.ShowDialog( this ) == DialogResult.OK)) if ((dialog.ShowDialog() == CommonFileDialogResult.Ok) && (saveFileDialog.ShowDialog(this) == DialogResult.OK)) { patchPsxBackgroundWorker.ProgressChanged += progress; patchPsxBackgroundWorker.RunWorkerCompleted += completed; patchPsxBackgroundWorker.DoWork += doWork; //Environment.CurrentDirectory = folderBrowserDialog.SelectedPath; Environment.CurrentDirectory = dialog.FileName; Enabled = false; progressBar.Value = 0; progressBar.Visible = true; progressBar.BringToFront(); patchPsxBackgroundWorker.RunWorkerAsync(); } //} }
public static byte[] GetFile(Stream stream, PspIsoInfo info, FFTPack.Files file) { return(FFTPack.GetFileFromIso(stream, info, file)); }
public static byte[] GetFile(Stream stream, PspIsoInfo info, FFTPack.Files file, int start, int length) { return(FFTPack.GetFileFromIso(stream, info, file, start, length)); }
public static IList <byte> GetFile(Stream stream, PspIsoInfo info, FFTPack.Files file, int start, int length) { byte[] result = FFTPack.GetFileFromIso(stream, info, file); return(result.Sub(start, start + length - 1)); }
private void extractFFTPackMenuItem_Click(object sender, EventArgs e) { using (Ionic.Utils.FolderBrowserDialogEx folderBrowserDialog = new Ionic.Utils.FolderBrowserDialogEx()) { DoWorkEventHandler doWork = delegate(object sender1, DoWorkEventArgs args) { FFTPack.DumpToDirectory(openFileDialog.FileName, folderBrowserDialog.SelectedPath, sender1 as BackgroundWorker); }; ProgressChangedEventHandler progress = delegate(object sender2, ProgressChangedEventArgs args) { progressBar.Visible = true; progressBar.Value = Math.Min(args.ProgressPercentage, 100); }; RunWorkerCompletedEventHandler completed = null; completed = delegate(object sender3, RunWorkerCompletedEventArgs args) { progressBar.Visible = false; Enabled = true; patchPsxBackgroundWorker.ProgressChanged -= progress; patchPsxBackgroundWorker.RunWorkerCompleted -= completed; patchPsxBackgroundWorker.DoWork -= doWork; if (args.Error is Exception) { MyMessageBox.Show(this, "Could not extract file.\n" + "Make sure you chose the correct file and that there \n" + "enough room in the destination directory.", "Error", MessageBoxButtons.OK); } }; openFileDialog.Filter = "fftpack.bin|fftpack.bin|All Files (*.*)|*.*"; openFileDialog.FilterIndex = 0; folderBrowserDialog.NewStyle = true; folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop; folderBrowserDialog.SelectedPath = Environment.CurrentDirectory; folderBrowserDialog.ShowBothFilesAndFolders = false; folderBrowserDialog.ShowEditBox = true; folderBrowserDialog.ShowFullPathInEditBox = false; folderBrowserDialog.ShowNewFolderButton = true; folderBrowserDialog.Description = "Where should the files be extracted?"; if ((openFileDialog.ShowDialog(this) == DialogResult.OK) && (folderBrowserDialog.ShowDialog(this) == DialogResult.OK)) { patchPsxBackgroundWorker.ProgressChanged += progress; patchPsxBackgroundWorker.RunWorkerCompleted += completed; patchPsxBackgroundWorker.DoWork += doWork; Environment.CurrentDirectory = folderBrowserDialog.SelectedPath; Enabled = false; progressBar.Value = 0; progressBar.Visible = true; progressBar.BringToFront(); patchPsxBackgroundWorker.RunWorkerAsync(); } } }