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 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."); } }