Пример #1
0
        public static void Patch(string modDir)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = true;
            startInfo.FileName       = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\rdb_tool.exe";
            if (!FileIOWrapper.Exists(startInfo.FileName))
            {
                Console.WriteLine($"[ERROR] Couldn't find {startInfo.FileName}. Please check if it was blocked by your anti-virus.");
                return;
            }

            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;
            foreach (var rdb in Directory.GetFiles(modDir, "*.rdb"))
            {
                startInfo.Arguments = $@"""{rdb}"" ""{rdb}""";
                Console.WriteLine($"[INFO] Patching {rdb}...");
                using (Process process = new Process())
                {
                    process.StartInfo = startInfo;
                    process.Start();
                    while (!process.HasExited)
                    {
                        string text = process.StandardOutput.ReadLine();
                        if (text != "" && text != null)
                        {
                            Console.WriteLine($"[INFO] {text}");
                        }
                    }
                }
            }
        }
        private async void UnpackPacsClick(object sender, RoutedEventArgs e)
        {
            string directory;

            if (main.modPath != null && FileIOWrapper.Exists($@"{Directory.GetParent(main.modPath)}\data00004.pac"))
            {
                directory = Directory.GetParent(main.modPath).ToString();
            }
            else
            {
                directory = openPacsFolder();
            }
            if (directory != null)
            {
                if (FileIOWrapper.Exists($@"{directory}\{main.cpkLang}"))
                {
                    UnpackButton.IsHitTestVisible = false;
                    main.ModGrid.IsHitTestVisible = false;
                    main.GameBox.IsHitTestVisible = false;
                    foreach (var button in main.buttons)
                    {
                        button.Foreground       = new SolidColorBrush(Colors.Gray);
                        button.IsHitTestVisible = false;
                    }
                    await main.pacUnpack(directory);

                    UnpackButton.IsHitTestVisible = true;
                }
                else
                {
                    Console.WriteLine($"[ERROR] Invalid folder cannot find {main.cpkLang}");
                }
            }
        }
Пример #3
0
        public static Dictionary <string, int> getTmxNames(string spr)
        {
            Dictionary <string, int> tmxNames = new Dictionary <string, int>();

            byte[] sprBytes = FileIOWrapper.ReadAllBytes(spr);
            byte[] pattern  = Encoding.ASCII.GetBytes("TMX0");
            int    offset   = 0;
            int    found    = 0;

            while (found != -1)
            {
                // Start search after "TMX0"
                found  = Search(SliceArray(sprBytes, offset, sprBytes.Length), pattern);
                offset = found + offset + 4;
                if (found != -1)
                {
                    string ogTmxName = getTmxName(SliceArray(sprBytes, (offset + 24), sprBytes.Length));
                    string tmxName   = ogTmxName;
                    int    index     = 2;
                    while (tmxNames.ContainsKey(tmxName))
                    {
                        tmxName = $"{ogTmxName}({index})";
                        index  += 1;
                    }
                    tmxNames.Add(tmxName, offset - 12);
                }
            }
            return(tmxNames);
        }
Пример #4
0
        public static void replaceDDS(string spd, string dds)
        {
            List <DDS> ddsFiles = getDDSFiles(spd);

            byte[] ddsBytes = FileIOWrapper.ReadAllBytes(dds);
            foreach (var ddsFile in ddsFiles)
            {
                if (ddsFile.name == Path.GetFileNameWithoutExtension(dds))
                {
                    if (ddsBytes.Length == ddsFile.size)
                    {
                        using (Stream stream = FileIOWrapper.Open(spd, FileMode.Open))
                        {
                            stream.Position = ddsFile.pos;
                            stream.Write(ddsBytes, 0, ddsFile.size);
                        }
                    }
                    else
                    {
                        byte[] spdBytes = FileIOWrapper.ReadAllBytes(spd);
                        byte[] newSpd   = new byte[spdBytes.Length + (ddsBytes.Length - ddsFile.size)];
                        SliceArray(spdBytes, 0, ddsFile.pos).CopyTo(newSpd, 0);
                        SliceArray(spdBytes, ddsFile.pos + ddsFile.size, spdBytes.Length).CopyTo(newSpd, ddsFile.pos + ddsBytes.Length);
                        ddsBytes.CopyTo(newSpd, ddsFile.pos);
                        FileIOWrapper.WriteAllBytes(spd, newSpd);
                        updateOffsets(spd, getDDSOffsets(spd));
                    }
                }
            }
        }
Пример #5
0
        public static void Merge(List <string> ModList, string modDir)
        {
            foreach (var mod in ModList)
            {
                if (!Directory.Exists(mod))
                {
                    Console.WriteLine($"[ERROR] Cannot find {mod}");
                    continue;
                }

                // Run prebuild.bat
                if (FileIOWrapper.Exists($@"{mod}\prebuild.bat") && new FileInfo($@"{mod}\prebuild.bat").Length > 0)
                {
                    Console.WriteLine($@"[INFO] Running {mod}\prebuild.bat...");

                    ProcessStartInfo ProcessInfo;

                    ProcessInfo                  = new ProcessStartInfo();
                    ProcessInfo.FileName         = Path.GetFullPath($@"{mod}\prebuild.bat");
                    ProcessInfo.CreateNoWindow   = true;
                    ProcessInfo.UseShellExecute  = false;
                    ProcessInfo.WorkingDirectory = Path.GetFullPath(mod);

                    using (Process process = new Process())
                    {
                        process.StartInfo = ProcessInfo;
                        process.Start();
                        process.WaitForExit();
                    }

                    Console.WriteLine($@"[INFO] Finished running {mod}\prebuild.bat!");
                }

                if (!Directory.Exists($@"{mod}\data"))
                {
                    Console.WriteLine($"[WARNING] No data folder found in {mod}, skipping...");
                    continue;
                }

                // Copy over .files, hashing them when neccessary
                foreach (var file in Directory.GetFiles($@"{mod}\data", "*", SearchOption.AllDirectories))
                {
                    string fileName = Path.GetFileName(file);
                    if (Path.GetExtension(file).ToLower() != ".file")
                    {
                        fileName = Hash(Path.GetFileName(file));
                    }
                    Console.WriteLine($@"[INFO] Copying over {file} to {modDir}\data\{fileName}");
                    try
                    {
                        FileIOWrapper.Copy(file, $@"{modDir}\data\{fileName.ToLower()}", true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't copy over {file} ({e.Message})");
                    }
                }
            }
        }
Пример #6
0
        // P3F
        public static void Unzip(string iso)
        {
            if (!FileIOWrapper.Exists(iso))
            {
                Console.Write($"[ERROR] Couldn't find {iso}. Please correct the file path in config.");
                return;
            }

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = true;
            startInfo.FileName       = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\7z\7z.exe";
            if (!FileIOWrapper.Exists(startInfo.FileName))
            {
                Console.Write($"[ERROR] Couldn't find {startInfo.FileName}. Please check if it was blocked by your anti-virus.");
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = Cursors.Wait;
            });

            startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute = false;
            startInfo.Arguments       = $"x -y \"{iso}\" -o\"" + @"Original\Persona 3 FES" + "\" BTL.CVM DATA.CVM";
            Console.WriteLine($"[INFO] Extracting BTL.CVM and DATA.CVM from {iso}");
            using (Process process = new Process())
            {
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }
            startInfo.Arguments = "x -y \"" + $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 3 FES\BTL.CVM" + "\" -o\"" + $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 3 FES\BTL" + "\" *.BIN *.PAK *.PAC *.TBL *.SPR -r";
            Console.WriteLine($"[INFO] Extracting base files from BTL.CVM");
            using (Process process = new Process())
            {
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }
            FileIOWrapper.Delete($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 3 FES\BTL.CVM");
            startInfo.Arguments = "x -y \"" + $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 3 FES\DATA.CVM" + "\" -o\"" + $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 3 FES\DATA" + "\" *.BIN *.PAK *.PAC *.SPR -r";
            Console.WriteLine($"[INFO] Extracting base files from DATA.CVM");
            using (Process process = new Process())
            {
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }
            FileIOWrapper.Delete($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 3 FES\DATA.CVM");
            Console.WriteLine($"[INFO] Finished unpacking base files!");
            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = null;
            });
        }
Пример #7
0
        public static byte[] extractTmx(string spr, string tmx)
        {
            string tmxPattern = Path.GetFileNameWithoutExtension(tmx);
            int    offset     = findTmx(spr, tmxPattern);

            if (offset > -1)
            {
                byte[] sprBytes = FileIOWrapper.ReadAllBytes(spr);
                int    tmxLen   = BitConverter.ToInt32(sprBytes, (offset + 4));
                return(SliceArray(sprBytes, offset, offset + tmxLen));
            }
            return(null);
        }
Пример #8
0
 private static int findTmx(string spr, string tmxName)
 {
     // Get all tmx names instead to prevent replacing similar names
     if (FileIOWrapper.Exists(spr))
     {
         Dictionary <string, int> tmxNames = getTmxNames(spr);
         if (tmxNames.ContainsKey(tmxName))
         {
             return(tmxNames[tmxName]);
         }
     }
     return(-1);
 }
Пример #9
0
        private static void updateOffsets(string spr, List <int> offsets)
        {
            // Start of tmx offsets
            int pos = 36;

            using (Stream stream = FileIOWrapper.Open(spr, FileMode.Open))
            {
                foreach (int offset in offsets)
                {
                    byte[] offsetBytes = BitConverter.GetBytes(offset);
                    stream.Position = pos;
                    stream.Write(offsetBytes, 0, 4);
                    pos += 8;
                }
            }
        }
Пример #10
0
 private async Task DownloadFile(string uri, string fileName, string game, DisplayedMetadata row, string version, Progress <DownloadProgress> progress, CancellationTokenSource cancellationToken, GameBananaItemUpdate update = null)
 {
     try
     {
         // Create the downloads folder if necessary
         if (!Directory.Exists($@"{assemblyLocation}\Downloads"))
         {
             Directory.CreateDirectory($@"{assemblyLocation}\Downloads");
         }
         // Download the file if it doesn't already exist
         if (!FileIOWrapper.Exists($@"{assemblyLocation}\Downloads\{fileName}"))
         {
             progressBox = new UpdateProgressBox(cancellationToken);
             progressBox.progressBar.Value = 0;
             progressBox.progressText.Text = $"Downloading {fileName}";
             progressBox.finished          = false;
             progressBox.Title             = $"{row.name} Update Progress";
             progressBox.Show();
             progressBox.Activate();
             Console.WriteLine($"[INFO] Downloading {fileName}");
             // Write and download the file
             using (var fs = new FileStream(
                        $@"{assemblyLocation}\Downloads\{fileName}", System.IO.FileMode.Create, FileAccess.Write, FileShare.None))
             {
                 await client.DownloadAsync(uri, fs, fileName, progress, cancellationToken.Token);
             }
             Console.WriteLine($"[INFO] Finished downloading {fileName}");
             progressBox.Close();
         }
         else
         {
             Console.WriteLine($"[INFO] {fileName} already exists in downloads, using this instead");
         }
         ExtractFile(fileName, game, row, version, update);
     }
     catch (OperationCanceledException)
     {
         // Remove the file is it will be a partially downloaded one and close up
         FileIOWrapper.Delete(@$ "Downloads\{fileName}");
         if (progressBox != null)
         {
             progressBox.finished = true;
             progressBox.Close();
         }
         return;
     }
Пример #11
0
        public static void replaceSPDKey(string spd, string spdspr)
        {
            List <SPDKey> spdKeys = getSPDKeys(spd);

            byte[] spdBytes = FileIOWrapper.ReadAllBytes(spdspr);
            foreach (var spdKey in spdKeys)
            {
                if (spdKey.id.ToString() == Path.GetFileNameWithoutExtension(spdspr))
                {
                    using (Stream stream = FileIOWrapper.Open(spd, FileMode.Open))
                    {
                        stream.Position = spdKey.pos;
                        stream.Write(spdBytes, 0, 160);
                    }
                    return;
                }
            }
        }
Пример #12
0
        public static string GetChecksumString(string filePath)
        {
            string checksumString = null;

            // get md5 checksum of file
            using (var md5 = MD5.Create())
            {
                using (var stream = FileIOWrapper.OpenRead(filePath))
                {
                    // get hash
                    byte[] currentFileSum = md5.ComputeHash(stream);
                    // convert hash to string
                    checksumString = BitConverter.ToString(currentFileSum).Replace("-", "");
                }
            }

            return(checksumString);
        }
Пример #13
0
        private static void updateOffsets(string spd, List <SpdHeaderHelper> helpers)
        {
            // Start of dds offsets
            int pos = 40;

            using (Stream stream = FileIOWrapper.Open(spd, FileMode.Open))
            {
                foreach (var helper in helpers)
                {
                    stream.Position = pos;
                    stream.Write(BitConverter.GetBytes(helper.offset), 0, 4);
                    pos            += 4;
                    stream.Position = pos;
                    stream.Write(BitConverter.GetBytes(helper.size), 0, 4);
                    pos += 44;
                }
            }
        }
Пример #14
0
        public static List <SPDKey> getSPDKeys(string spd)
        {
            List <SPDKey> spdKeys = new List <SPDKey>();

            byte[] spdBytes = FileIOWrapper.ReadAllBytes(spd);
            int    numKeys  = BitConverter.ToUInt16(spdBytes, 22);
            int    pos      = BitConverter.ToInt32(spdBytes, 28);
            SPDKey spdKey;

            for (int i = 0; i < numKeys; i++)
            {
                spdKey      = new SPDKey();
                spdKey.pos  = pos;
                spdKey.id   = BitConverter.ToInt32(spdBytes, pos);
                spdKey.file = SliceArray(spdBytes, spdKey.pos, spdKey.pos + 160);
                spdKeys.Add(spdKey);
                pos += 160;
            }
            return(spdKeys);
        }
Пример #15
0
        private static List <int> getTmxOffsets(string spr)
        {
            List <int> tmxOffsets = new List <int>();

            byte[] sprBytes = FileIOWrapper.ReadAllBytes(spr);
            byte[] pattern  = Encoding.ASCII.GetBytes("TMX0");
            int    offset   = 0;
            int    found    = 0;

            while (found != -1)
            {
                // Start search after "TMX0"
                found  = Search(SliceArray(sprBytes, offset, sprBytes.Length), pattern);
                offset = found + offset + 4;
                if (found != -1)
                {
                    tmxOffsets.Add(offset - 12);
                }
            }
            return(tmxOffsets);
        }
Пример #16
0
 public static void Backup(string modPath)
 {
     Directory.CreateDirectory($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data");
     foreach (var file in original_data)
     {
         Console.WriteLine($@"[INFO] Backing up {modPath}\data\{file}");
         if (FileIOWrapper.Exists($@"{modPath}\data\{file}"))
         {
             FileIOWrapper.Copy($@"{modPath}\data\{file}", $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{file}", true);
         }
         else
         {
             Console.WriteLine($@"[ERROR] Couldn't find {modPath}\data\{file}");
         }
     }
     foreach (var rdb in Directory.GetFiles(modPath, "*.rdb"))
     {
         Console.WriteLine($"[INFO] Backing up {rdb}");
         FileIOWrapper.Copy(rdb, $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\{Path.GetFileName(rdb)}", true);
     }
 }
Пример #17
0
        public static List <DDS> getDDSFiles(string spd)
        {
            List <DDS> ddsNames = new List <DDS>();

            byte[] spdBytes    = FileIOWrapper.ReadAllBytes(spd);
            int    numTextures = BitConverter.ToUInt16(spdBytes, 20);
            int    pos         = 32;
            DDS    dds;

            for (int i = 0; i < numTextures; i++)
            {
                dds = new DDS();
                int tag = BitConverter.ToInt32(spdBytes, pos);
                dds.pos  = BitConverter.ToUInt32(spdBytes, pos + 8);
                dds.size = BitConverter.ToInt32(spdBytes, pos + 12);
                dds.name = $"{Encoding.ASCII.GetString(SliceArray(spdBytes, pos + 32, pos + 47)).TrimEnd('\0')}[{tag}]";
                dds.file = SliceArray(spdBytes, dds.pos, dds.pos + dds.size - 1);
                ddsNames.Add(dds);
                pos += 48;
            }
            return(ddsNames);
        }
Пример #18
0
        private static List <SpdHeaderHelper> getDDSOffsets(string spd)
        {
            List <SpdHeaderHelper> ddsHelpers = new List <SpdHeaderHelper>();

            byte[]          spdBytes = FileIOWrapper.ReadAllBytes(spd);
            byte[]          pattern  = Encoding.ASCII.GetBytes("DDS");
            int             offset   = 0;
            int             found    = 0;
            SpdHeaderHelper helper;

            while (found != -1)
            {
                helper = new SpdHeaderHelper();
                // Start search after "DDS"
                found  = Search(SliceArray(spdBytes, offset, spdBytes.Length), pattern);
                offset = found + offset;
                if (found != -1)
                {
                    helper.offset = offset;
                    ddsHelpers.Add(helper);
                }
                offset += 4;
            }
            for (int i = 0; i < ddsHelpers.Count; i++)
            {
                if (i != ddsHelpers.Count - 1)
                {
                    ddsHelpers[i].size = (int)(ddsHelpers[i + 1].offset - ddsHelpers[i].offset);
                }
                else
                {
                    ddsHelpers[i].size = (int)(spdBytes.Length - ddsHelpers[i].offset);
                }
            }

            return(ddsHelpers);
        }
Пример #19
0
        public static void replaceTmx(string spr, string tmx)
        {
            string tmxPattern = Path.GetFileNameWithoutExtension(tmx);
            int    offset     = findTmx(spr, tmxPattern);

            if (offset > -1)
            {
                Console.WriteLine($"[INFO] Merging {tmx} onto {spr}");
                byte[] tmxBytes  = FileIOWrapper.ReadAllBytes(tmx);
                int    repTmxLen = tmxBytes.Length;
                int    ogTmxLen  = BitConverter.ToInt32(FileIOWrapper.ReadAllBytes(spr), (offset + 4));

                if (repTmxLen == ogTmxLen)
                {
                    using (Stream stream = FileIOWrapper.Open(spr, FileMode.Open))
                    {
                        stream.Position = offset;
                        stream.Write(tmxBytes, 0, repTmxLen);
                    }
                }
                else // Insert and update offsets
                {
                    byte[] sprBytes = FileIOWrapper.ReadAllBytes(spr);
                    byte[] newSpr   = new byte[sprBytes.Length + (repTmxLen - ogTmxLen)];
                    SliceArray(sprBytes, 0, offset).CopyTo(newSpr, 0);
                    SliceArray(sprBytes, offset + ogTmxLen, sprBytes.Length).CopyTo(newSpr, offset + repTmxLen);
                    tmxBytes.CopyTo(newSpr, offset);
                    FileIOWrapper.WriteAllBytes(spr, newSpr);
                    updateOffsets(spr, getTmxOffsets(spr));
                }
            }
            else
            {
                Console.WriteLine($"[WARNING] Couldn't find {tmx} in {spr}");
            }
        }
Пример #20
0
        public async Task ExtractPackageAsync(string sourceFilePath, string destDirPath,
                                              IProgress <double>?progress = null, CancellationToken cancellationToken = default)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = true;
            startInfo.FileName       = @$ "{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\7z\7z.exe";
            if (!FileIOWrapper.Exists(startInfo.FileName))
            {
                Console.WriteLine($"[ERROR] Couldn't find {startInfo.FileName}. Please check if it was blocked by your anti-virus.");
                return;
            }
            // Extract the file
            startInfo.Arguments = $"x -y \"{sourceFilePath}\" -o\"{destDirPath}\"";
            Console.WriteLine($"[INFO] Extracting {sourceFilePath}");

            startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute = false;

            using (Process process = new Process())
            {
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
            }
            // TODO Check if it actually succeeded (by reading the command output I guess)
            Console.WriteLine($"[INFO] Done Extracting {sourceFilePath}");
            FileIOWrapper.Delete(@$ "{sourceFilePath}");
            Console.WriteLine(@$ "[INFO] Deleted {sourceFilePath}");
            // Move the folders to the right place
            string parentPath = Directory.GetParent(destDirPath).FullName;

            Directory.Move(Directory.GetDirectories(destDirPath)[0], $@"{parentPath}\Aemulus");
            Directory.Delete(destDirPath);
            Directory.Move($@"{parentPath}\Aemulus", destDirPath);
        }
Пример #21
0
        public static void Restart(string modPath)
        {
            Console.WriteLine($"[INFO] Restoring directory to original state...");
            // Just in case its missing for some reason
            Directory.CreateDirectory($@"{modPath}\data");
            // Clear data directory
            Parallel.ForEach(Directory.GetFiles($@"{modPath}\data"), file =>
            {
                // Delete if not found in Original
                if (!FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}"))
                {
                    Console.WriteLine($@"[INFO] Deleting {file}...");
                    try
                    {
                        FileIOWrapper.Delete(file);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't delete {file} ({e.Message})");
                    }
                }
                // Overwrite if file size/date modified are different
                else if (new FileInfo(file).Length != new FileInfo($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}").Length ||
                         FileIOWrapper.GetLastWriteTime(file) != FileIOWrapper.GetLastWriteTime($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}"))
                {
                    Console.WriteLine($@"[INFO] Reverting {file} to original...");
                    try
                    {
                        FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{Path.GetFileName(file)}", file, true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't overwrite {file} ({e.Message})");
                    }
                }
            });

            // Copy over original files that may have accidentally been deleted
            foreach (var file in original_data)
            {
                if (!FileIOWrapper.Exists($@"{modPath}\data\{file}") && FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{file}"))
                {
                    Console.WriteLine($"[INFO] Restoring {file}...");
                    try
                    {
                        FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\data\{file}", $@"{modPath}\data\{file}", true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"[ERROR] Couldn't copy over {file} ({e.Message})");
                    }
                }
            }

            // Copy over backed up original rdbs
            foreach (var file in Directory.GetFiles(modPath, "*.rdb"))
            {
                Console.WriteLine($@"[INFO] Reverting {file} to original...");
                try
                {
                    FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5 Strikers\motor_rsc\{Path.GetFileName(file)}", file, true);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"[ERROR] Couldn't overwrite {file} ({e.Message})");
                }
            }
        }
Пример #22
0
        // P4G
        public static void Unpack(string directory, string cpk)
        {
            Directory.CreateDirectory($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden");
            if (!Directory.Exists(directory))
            {
                Console.WriteLine($"[ERROR] Couldn't find {directory}. Please correct the file path in config.");
                return;
            }
            List <string> pacs  = new List <string>();
            List <string> globs = new List <string> {
                "*[!0-9].bin", "*2[0-1][0-9].bin", "*.arc", "*.pac", "*.pack"
            };

            switch (cpk)
            {
            case "data_e.cpk":
                pacs.Add("data00004.pac");
                pacs.Add("data_e.cpk");
                break;

            case "data.cpk":
                pacs.Add("data00000.pac");
                pacs.Add("data00001.pac");
                pacs.Add("data00003.pac");
                pacs.Add("data.cpk");
                break;

            case "data_k.cpk":
                pacs.Add("data00005.pac");
                pacs.Add("data_k.cpk");
                break;

            case "data_c.cpk":
                pacs.Add("data00006.pac");
                pacs.Add("data_c.cpk");
                break;
            }
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = true;
            startInfo.FileName       = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\Preappfile\preappfile.exe";
            if (!FileIOWrapper.Exists(startInfo.FileName))
            {
                Console.WriteLine($"[ERROR] Couldn't find {startInfo.FileName}. Please check if it was blocked by your anti-virus.");
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = Cursors.Wait;
            });
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;
            foreach (var pac in pacs)
            {
                Console.WriteLine($"[INFO] Unpacking files for {pac}...");
                foreach (var glob in globs)
                {
                    startInfo.Arguments = $@"-i ""{directory}\{pac}"" -o ""{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\{Path.GetFileNameWithoutExtension(pac)}"" --unpack-filter {glob}";
                    using (Process process = new Process())
                    {
                        process.StartInfo = startInfo;
                        process.Start();
                        while (!process.HasExited)
                        {
                            string text = process.StandardOutput.ReadLine();
                            if (text != "" && text != null)
                            {
                                Console.WriteLine($"[INFO] {text}");
                            }
                        }
                    }
                }
            }
            if (FileIOWrapper.Exists($@"{directory}\{cpk}") && !FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\{cpk}"))
            {
                Console.WriteLine($@"[INFO] Backing up {cpk}");
                FileIOWrapper.Copy($@"{directory}\{cpk}", $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\{cpk}", true);
            }
            if (FileIOWrapper.Exists($@"{directory}\movie.cpk") && !FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\movie.cpk"))
            {
                Console.WriteLine($@"[INFO] Backing up movie.cpk");
                FileIOWrapper.Copy($@"{directory}\movie.cpk", $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\movie.cpk", true);
            }

            Console.WriteLine("[INFO] Finished unpacking base files!");
            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = null;
            });
        }
Пример #23
0
        public static void UnpackCPK(string directory)
        {
            if (!Directory.Exists(directory))
            {
                Console.WriteLine($"[ERROR] Couldn't find {directory}. Please correct the file path in config.");
                return;
            }
            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = Cursors.Wait;
            });

            if (FileIOWrapper.Exists($@"{directory}\ps3.cpk.66600") && FileIOWrapper.Exists($@"{directory}\ps3.cpk.66601") && FileIOWrapper.Exists($@"{directory}\ps3.cpk.66602") &&
                !FileIOWrapper.Exists($@"{directory}\ps3.cpk"))
            {
                Console.Write("[INFO] Combining ps3.cpk parts");
                ProcessStartInfo cmdInfo = new ProcessStartInfo();
                cmdInfo.CreateNoWindow = true;
                cmdInfo.FileName       = @"CMD.exe";
                cmdInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                cmdInfo.Arguments      = $@"/C copy /b ""{directory}\ps3.cpk.66600"" + ""{directory}\ps3.cpk.66601"" + ""{directory}\ps3.cpk.66602"" ""{directory}\ps3.cpk""";

                using (Process process = new Process())
                {
                    process.StartInfo = cmdInfo;
                    process.Start();
                    process.WaitForExit();
                }
            }

            Directory.CreateDirectory($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5");

            if (!FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\MakeCpk\filtered_data.csv") ||
                !FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\MakeCpk\filtered_ps3.csv"))
            {
                Console.WriteLine($@"[ERROR] Couldn't find CSV files used for unpacking in Dependencies\MakeCpk");
                Application.Current.Dispatcher.Invoke(() =>
                {
                    Mouse.OverrideCursor = null;
                });
                return;
            }

            string[] dataFiles = FileIOWrapper.ReadAllLines($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\MakeCpk\filtered_data.csv");
            string[] ps3Files  = FileIOWrapper.ReadAllLines($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\MakeCpk\filtered_ps3.csv");

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow = true;
            startInfo.FileName       = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\MakeCpk\YACpkTool.exe";
            if (!FileIOWrapper.Exists(startInfo.FileName))
            {
                Console.WriteLine($"[ERROR] Couldn't find {startInfo.FileName}. Please check if it was blocked by your anti-virus.");
                Application.Current.Dispatcher.Invoke(() =>
                {
                    Mouse.OverrideCursor = null;
                });
                return;
            }
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.RedirectStandardOutput = true;
            startInfo.UseShellExecute        = false;


            if (FileIOWrapper.Exists($@"{directory}\data.cpk"))
            {
                Console.WriteLine($"[INFO] Extracting data.cpk");
                foreach (var file in dataFiles)
                {
                    startInfo.Arguments = $@"-X {file} -i ""{directory}\data.cpk"" -o ""{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5""";

                    using (Process process = new Process())
                    {
                        process.StartInfo = startInfo;
                        process.Start();
                        while (!process.HasExited)
                        {
                            string text = process.StandardOutput.ReadLine();
                            if (text != "" && text != null)
                            {
                                Console.WriteLine($"[INFO] {text}");
                            }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine($"[ERROR] Couldn't find data.cpk in {directory}.");
            }

            if (FileIOWrapper.Exists($@"{directory}\data.cpk"))
            {
                Console.WriteLine($"[INFO] Extracting ps3.cpk");
                foreach (var file in ps3Files)
                {
                    startInfo.Arguments = $@"-X {file} -i ""{directory}\ps3.cpk"" -o ""{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 5""";

                    using (Process process = new Process())
                    {
                        process.StartInfo = startInfo;
                        process.Start();
                        while (!process.HasExited)
                        {
                            string text = process.StandardOutput.ReadLine();
                            if (text != "" && text != null)
                            {
                                Console.WriteLine($"[INFO] {text}");
                            }
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine($"[ERROR] Couldn't find ps3.cpk in {directory}.");
            }
            Console.WriteLine($"[INFO] Finished unpacking base files!");
            Application.Current.Dispatcher.Invoke(() =>
            {
                Mouse.OverrideCursor = null;
            });
        }
Пример #24
0
        public static void Validate(string path, string cpkLang)
        {
            var validated = true;
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow         = true;
            startInfo.FileName               = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\Preappfile\preappfile.exe";
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardOutput = true;
            if (FileIOWrapper.Exists($@"{path}\data00007.pac"))
            {
                startInfo.Arguments = $@"""{path}\data00007.pac""";
                using (Process process = new Process())
                {
                    process.StartInfo = startInfo;
                    process.Start();
                    process.WaitForExit();
                }
                foreach (var file in Directory.GetFiles($@"{path}\mods\preappfile\{Path.GetFileNameWithoutExtension(cpkLang)}", "*", SearchOption.AllDirectories))
                {
                    var folders = new List <string>(file.Split(char.Parse("\\")));
                    int idx     = folders.IndexOf(Path.GetFileNameWithoutExtension(cpkLang));
                    if (File.Exists($@"{path}\data00007\{string.Join("\\", folders.Skip(idx + 1).ToArray())}"))
                    {
                        Console.WriteLine($"[INFO] Validated that {file} was appended");
                    }
                    else
                    {
                        Console.WriteLine($"[WARNING] {file} not appended");
                        validated = false;
                    }
                }
                if (Directory.Exists($@"{path}\data00007"))
                {
                    Directory.Delete($@"{path}\data00007", true);
                }
            }
            if (FileIOWrapper.Exists($@"{path}\movie00003.pac"))
            {
                startInfo.Arguments = $@"""{path}\movie00003.pac""";
                using (Process process = new Process())
                {
                    process.StartInfo = startInfo;
                    process.Start();
                    process.WaitForExit();
                }
                foreach (var file in Directory.GetFiles($@"{path}\mods\preappfile\movie", "*", SearchOption.AllDirectories))
                {
                    var folders = new List <string>(file.Split(char.Parse("\\")));
                    int idx     = folders.IndexOf("movie00003");
                    if (File.Exists($@"{path}\movie00003\{string.Join("\\", folders.Skip(idx + 1).ToArray())}"))
                    {
                        Console.WriteLine($"[INFO] Validated appended {file}");
                    }
                    else
                    {
                        Console.WriteLine($"[Warning] {file} not appended");
                        validated = false;
                    }
                }
                if (Directory.Exists($@"{path}\movie00003"))
                {
                    Directory.Delete($@"{path}\movie00003", true);
                }
            }
            if (!validated)
            {
                Console.WriteLine($"[WARNING] Not all appended files were validated, trying again");
                Append(path, cpkLang);
                Validate(path, cpkLang);
            }
        }
Пример #25
0
        public static void Append(string path, string cpkLang)
        {
            // Check if required files are there
            if (!FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\preappfile\preappfile.exe"))
            {
                Console.WriteLine($@"[ERROR] Couldn't find Dependencies\preappfile\preappfile.exe. Please check if it was blocked by your anti-virus.");
                return;
            }

            if (!FileIOWrapper.Exists($@"{path}\{cpkLang}"))
            {
                Console.WriteLine($@"[ERROR] Couldn't find {path}\{cpkLang} for appending.");
                return;
            }
            // Backup cpk if not backed up already
            if (!FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\{cpkLang}"))
            {
                Console.WriteLine($@"[INFO] Backing up {cpkLang}.cpk");
                FileIOWrapper.Copy($@"{path}\{cpkLang}", $@"Original\Persona 4 Golden\{cpkLang}");
            }
            // Copy original cpk back if different
            if (GetChecksumString($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\{cpkLang}") != GetChecksumString($@"{path}\{cpkLang}"))
            {
                Console.WriteLine($@"[INFO] Reverting {cpkLang} back to original");
                FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\{cpkLang}", $@"{path}\{cpkLang}", true);
            }
            if (!FileIOWrapper.Exists($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\movie.cpk"))
            {
                Console.WriteLine($@"[INFO] Backing up movie.cpk");
                FileIOWrapper.Copy($@"{path}\movie.cpk", $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\movie.cpk");
            }
            // Copy original cpk back if different
            if (GetChecksumString($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\movie.cpk") != GetChecksumString($@"{path}\movie.cpk"))
            {
                Console.WriteLine($@"[INFO] Reverting movie.cpk back to original");
                FileIOWrapper.Copy($@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Original\Persona 4 Golden\movie.cpk", $@"{path}\movie.cpk", true);
            }
            // Delete modified pacs
            if (FileIOWrapper.Exists($@"{path}\data00007.pac"))
            {
                Console.WriteLine($"[INFO] Deleting data00007.pac");
                FileIOWrapper.Delete($@"{path}\data00007.pac");
            }
            if (FileIOWrapper.Exists($@"{path}\movie00003.pac"))
            {
                Console.WriteLine($"[INFO] Deleting movie00003.pac");
                FileIOWrapper.Delete($@"{path}\movie00003.pac");
            }

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.CreateNoWindow  = true;
            startInfo.FileName        = $@"{Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)}\Dependencies\Preappfile\preappfile.exe";
            startInfo.WindowStyle     = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute = false;
            if (Directory.Exists($@"{path}\mods\preappfile\{Path.GetFileNameWithoutExtension(cpkLang)}"))
            {
                Console.WriteLine($@"[INFO] Appending to {cpkLang}");
                startInfo.Arguments = $@"-i  ""{path}\mods\preappfile\{Path.GetFileNameWithoutExtension(cpkLang)}"" -a ""{path}\{cpkLang}"" -o ""{path}\{cpkLang}"" --pac-index 7";
                using (Process process = new Process())
                {
                    process.StartInfo = startInfo;
                    process.Start();
                    process.WaitForExit();
                }
            }
            if (Directory.Exists($@"{path}\mods\preappfile\movie"))
            {
                Console.WriteLine($@"[INFO] Appending to movie");
                startInfo.Arguments = $@"-i  ""{path}\mods\preappfile\movie"" -a ""{path}\movie.cpk"" -o ""{path}\movie.cpk"" --pac-index 3";
                using (Process process = new Process())
                {
                    process.StartInfo = startInfo;
                    process.Start();
                    process.WaitForExit();
                }
            }
        }