public void InjectCMXMods(bool restoreMode = false) { if (readyToMod == false) { MessageBox.Show("Please set all paths properly and attempt this again."); } //Reload backup cmx if (File.Exists(backupPath + "\\pl_data_info.cmx")) { cmx = CharacterMakingIndexMethods.ReadCMX(backupPath + "\\pl_data_info.cmx"); cmxRaw = File.ReadAllBytes(backupPath + "\\pl_data_info.cmx"); } //Write cmx to ice string cmxPath = Path.Combine(pso2_binDir, dataDir, CharacterMakingIndexMethods.GetFileHash(classicCMX)); if (File.Exists(cmxPath)) { var strm = new MemoryStream(File.ReadAllBytes(cmxPath)); cmxIce = IceFile.LoadIceFile(strm); strm.Dispose(); InjectCmxToIceGroup(cmxIce.groupOneFiles, cmxRaw); InjectCmxToIceGroup(cmxIce.groupTwoFiles, cmxRaw); } //Gather and write mods to cmx if (restoreMode == false) { GatherCMXModText(); } #if DEBUG File.WriteAllBytes(settingsPath + "test.cmx", cmxRaw); #endif //Write ice - We recreate the file in case for some strange reason it was something other than a v4 ice byte[] rawData = new IceV4File((new IceHeaderStructures.IceArchiveHeader()).GetBytes(), cmxIce.groupOneFiles, cmxIce.groupTwoFiles).getRawData(false, false); try { File.WriteAllBytes(cmxPath, rawData); } catch { MessageBox.Show("Unable to write cmx to game directory. Check file permissions. \nIf using the MS Store version, this may not be fixable.\n" + $"Attempting to write to {moddedCMXPath}"); try { Directory.CreateDirectory(moddedCMXPath); File.WriteAllBytes(moddedCMXPath + CharacterMakingIndexMethods.GetFileHash(classicCMX), rawData); } catch { MessageBox.Show("Unable to write cmx to patcher directory. Check file permissions."); } } }
public void BackupCMX() { bool isOldCmx = false; //Check original CMX to see if we need to do a new backup. string cmxPath = Path.Combine(pso2_binDir, dataDir, CharacterMakingIndexMethods.GetFileHash(classicCMX)); if (File.Exists(cmxPath)) { //bool foundCmx = false; var strm = new MemoryStream(File.ReadAllBytes(cmxPath)); cmxIce = IceFile.LoadIceFile(strm); strm.Dispose(); List <byte[]> files = (new List <byte[]>(cmxIce.groupOneFiles)); files.AddRange(cmxIce.groupTwoFiles); //Loop through files to get what we need foreach (byte[] file in files) { if (IceFile.getFileName(file).ToLower().Contains(".cmx")) { //If the filesize is actually different, since it should be the same between modded ones and the originals, we want to back it up if (cmxRaw == null || file.Length != cmxRaw.Length) { isOldCmx = true; cmxRaw = file; cmx = CharacterMakingIndexMethods.ReadCMX(file); } //foundCmx = true; //We can break here since we're really only expecting an NGS cmx and there's only one of those. break; } } files.Clear(); } else { throw new Exception("Cannot find CMX ice!"); } //Backup if the file didn't exist or the CMX was old if (!File.Exists(backupPath + "\\pl_data_info.cmx") || isOldCmx) { Directory.CreateDirectory(backupPath); File.WriteAllBytes(backupPath + "\\pl_data_info.cmx", cmxRaw); } readyToMod = true; }
public static PSO2Text GetTextConditional(string normalPath, string overridePath, string textFileName) { PSO2Text partsText = new PSO2Text(); string partsPath = null; if (File.Exists(overridePath)) { partsPath = overridePath; } else if (File.Exists(normalPath)) { partsPath = normalPath; } else { return(null); } if (partsPath != null) { var strm = new MemoryStream(File.ReadAllBytes(partsPath)); var partsIce = IceFile.LoadIceFile(strm); strm.Dispose(); List <byte[]> files = (new List <byte[]>(partsIce.groupOneFiles)); files.AddRange(partsIce.groupTwoFiles); //Loop through files to get what we need foreach (byte[] file in files) { if (IceFile.getFileName(file).ToLower().Contains(textFileName)) { partsText = ReadPSO2Text(file); } } partsIce = null; } return(partsText); }
public void DowngradeCmx() { if (readyToMod == false) { MessageBox.Show("Please set all paths properly and attempt this again."); } //Reload backup cmx if (File.Exists(backupPath + "\\pl_data_info.cmx")) { cmx = CharacterMakingIndexMethods.ReadCMX(backupPath + "\\pl_data_info.cmx"); cmxRaw = File.ReadAllBytes(backupPath + "\\pl_data_info.cmx"); } string cmxPath = Path.Combine(pso2_binDir, dataDir, CharacterMakingIndexMethods.GetFileHash(classicCMX)); if (File.Exists(cmxPath)) { var strm = new MemoryStream(File.ReadAllBytes(cmxPath)); cmxIce = IceFile.LoadIceFile(strm); strm.Dispose(); InjectCmxToIceGroup(cmxIce.groupOneFiles, cmxRaw); InjectCmxToIceGroup(cmxIce.groupTwoFiles, cmxRaw); } //ACCE replacement PatchACCE(cmx, cmxRaw); //Write ice - We recreate the file in case for some strange reason it was something other than a v4 ice byte[] rawData = new IceV4File((new IceHeaderStructures.IceArchiveHeader()).GetBytes(), cmxIce.groupOneFiles, cmxIce.groupTwoFiles).getRawData(false, false); try { Directory.CreateDirectory(downgradeCMXPath); File.WriteAllBytes(downgradeCMXPath + CharacterMakingIndexMethods.GetFileHash(classicCMX), rawData); } catch { MessageBox.Show("Unable to write cmx to patcher directory. Check file permissions."); } }
public static byte[] ShowDialog(string iceName, string filter) { var strm = new MemoryStream(File.ReadAllBytes(iceName)); var fVarIce = IceFile.LoadIceFile(strm); var filteredFiles = new List <byte[]>(); var filteredFileNames = new List <string>(); strm.Dispose(); List <byte[]> files = new List <byte[]>(fVarIce.groupOneFiles); files.AddRange(fVarIce.groupTwoFiles); //Loop through files to get what we need foreach (byte[] file in files) { var name = IceFile.getFileName(file).ToLower(); if (name.Contains(filter)) { filteredFileNames.Add(name); filteredFiles.Add(file); } } files = null; Form prompt = new Form(); prompt.Width = 200; prompt.Height = 100; prompt.Text = $"Select a file:"; Label label = new Label() { Text = "Select a file: ", Left = 30, Top = 1, Width = 100 }; ComboBox cb = new ComboBox() { Left = 40, Top = 18, Width = 100 }; foreach (var name in filteredFileNames) { cb.Items.Add(name); } if (cb.Items.Count == 0) { return(null); } cb.SelectedIndex = 0; Button confirmation = new Button() { Text = "Ok", Dock = DockStyle.Bottom }; confirmation.Click += (sender, e) => { prompt.Close(); }; prompt.Controls.Add(confirmation); prompt.Controls.Add(cb); prompt.Controls.Add(label); prompt.ShowDialog(); fVarIce = null; return(filteredFiles[cb.SelectedIndex]); }