Пример #1
0
        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.");
                }
            }
        }
Пример #2
0
        public byte[] PatchACCE(CharacterMakingIndex cmx, byte[] cmxRaw)
        {
            List <byte> acceBytes = new List <byte>();

            foreach (var acceKey in cmx.accessoryDict.Keys)
            {
                acceBytes.AddRange(AquaObjectMethods.ConvertStruct(cmx.accessoryDict[acceKey].acce));
                acceBytes.AddRange(AquaObjectMethods.ConvertStruct(cmx.accessoryDict[acceKey].acce2));
            }
            Array.Copy(acceBytes.ToArray(), 0, cmxRaw, cmx.cmxTable.accessoryAddress, acceBytes.Count);

            return(cmxRaw);
        }
Пример #3
0
        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;
        }
Пример #4
0
        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.");
            }
        }
Пример #5
0
        public void InitializeCMX()
        {
            Directory.CreateDirectory(modPath);
            if (File.Exists(settingsPath + "settings.txt"))
            {
                var lines = File.ReadAllLines(settingsPath + "settings.txt");
                pso2_binDir = lines[0];


                BackupCMX();
                if (File.Exists(backupPath + "\\pl_data_info.cmx"))
                {
                    cmx    = CharacterMakingIndexMethods.ReadCMX(backupPath + "\\pl_data_info.cmx");
                    cmxRaw = File.ReadAllBytes(backupPath + "\\pl_data_info.cmx");
                }
                //InjectCMXMods();
            }
            else
            {
                MessageBox.Show("Must set pso2_bin before attempting to patch .cmx!");
            }
        }