Example #1
0
        private static void ExtractArchives()
        {
            foreach (var game in games)
            {
                Log($"Extracting archives for {game.Name}...");
                var game_dir    = Path.Combine("data", game.Name);
                var archive_dir = Path.Combine(game_dir, "boss");
                var dec_dir     = Path.Combine(game_dir, "boss_dec");
                CreateDirectoryIfNull(archive_dir);
                CreateDirectoryIfNull(dec_dir);
                foreach (var file in new DirectoryInfo(archive_dir).GetFiles())
                {
                    if (!file.Name.Contains("-_-"))
                    {
                        continue;
                    }
                    var boss     = BossMetadata.FromArchiveName(file.Name);
                    var dec_path = Path.Combine(dec_dir, boss.FileName);
                    if (File.Exists(dec_path))
                    {
                        continue;
                    }
                    Log($"Decrypting {boss.FileName}...");
                    var dec_data = engine.DecryptBOSS(File.ReadAllBytes(file.FullName));
                    if (dec_data == null)
                    {
                        Log($"Failed to decrypt {boss.FileName}");
                        continue;
                    }
                    Log($"Decrypted {boss.FileName}.");
                    File.WriteAllBytes(dec_path, dec_data);

                    var content_data = dec_data.Skip(0x296).ToArray();
                    if (content_data.Length == 0x310) // Wondercard!
                    {
                        var wcgdir    = Path.Combine("wondercards", game.Name);
                        var wcdir     = Path.Combine(wcgdir, $"wc{game.Generation}");
                        var wcfulldir = Path.Combine(wcgdir, $"wc{game.Generation}full");
                        CreateDirectoryIfNull(wcgdir);
                        CreateDirectoryIfNull(wcdir);
                        CreateDirectoryIfNull(wcfulldir);

                        File.WriteAllBytes(Path.Combine(wcfulldir, boss.FileName + $".wc{game.Generation}full"), content_data);

                        MysteryGift wc = null;
                        if (game.Generation == 6)
                        {
                            wc = new WC6(content_data);
                            File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $".wc{game.Generation}"), wc.Data);
                        }
                        else if (game.Generation == 7)
                        {
                            wc = new WC7(content_data);
                            File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $".wc{game.Generation}"), wc.Data);
                        }

                        Log($"{boss.FileName} is a wondercard ({wc.Type}): ");
                        Log(wc.FullDesc);
                        Log(MysteryGift.getDescription(wc));
                    }
                    else if (boss.Name.ToUpper().Contains("CUP") && content_data.Length == 0x4C0) // CUP Regulation
                    {
                        Log($"{boss.FileName} is a CUP!");
                        var cup_dir = Path.Combine("cups", game.Name);
                        CreateDirectoryIfNull(cup_dir);
                        var reg_arc = new RegulationArchive(content_data, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(cup_dir);
                    }
                    else if (boss.Name.Contains("regulation") && game.Generation == 7) // Gen VII Regulations
                    {
                        Log($"{boss.FileName} is a regulation!");
                        var reg_dir = Path.Combine("regulations", game.Name);
                        CreateDirectoryIfNull(reg_dir);
                        var reg_arc = new RegulationArchive(content_data, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(reg_dir);
                    }
                }
            }
        }
Example #2
0
        private static void ExtractArchives()
        {
            foreach (var game in games)
            {
                Log($"Extracting archives for {game.Name}...");
                var game_dir    = Path.Combine("data", game.Name);
                var archive_dir = Path.Combine(game_dir, "boss");
                var dec_dir     = Path.Combine(game_dir, "boss_dec");
                CreateDirectoryIfNull(archive_dir);
                CreateDirectoryIfNull(dec_dir);
                foreach (var file in new DirectoryInfo(archive_dir).GetFiles())
                {
                    if (!file.Name.Contains("-_-"))
                    {
                        continue;
                    }
                    var boss     = BossMetadata.FromArchiveName(file.Name);
                    var dec_path = Path.Combine(dec_dir, boss.FileName);
                    if (File.Exists(dec_path))
                    {
                        continue;
                    }
                    Log($"Decrypting {boss.FileName}...");
                    var dec_data = engine.DecryptBOSS(File.ReadAllBytes(file.FullName));
                    if (dec_data == null)
                    {
                        Log($"Failed to decrypt {boss.FileName}");
                        continue;
                    }
                    Log($"Decrypted {boss.FileName}.");
                    File.WriteAllBytes(dec_path, dec_data);

                    var contentData = dec_data.Skip(0x296).ToArray();
                    if (contentData.Length % 0x310 == 0) // Wondercard!
                    {
                        var wcgdir    = Path.Combine("wondercards", game.Name);
                        var wcdir     = Path.Combine(wcgdir, $"wc{game.Generation}");
                        var wcfulldir = Path.Combine(wcgdir, $"wc{game.Generation}full");
                        CreateDirectoryIfNull(wcgdir);
                        CreateDirectoryIfNull(wcdir);
                        CreateDirectoryIfNull(wcfulldir);

                        var count = 0;
                        do
                        {
                            count++;
                            var currentWc = contentData.Take(0x310).ToArray();

                            var gameId = contentData.Take(0x03).ToArray();

                            File.WriteAllBytes(Path.Combine(wcfulldir, boss.FileName + $"_{GetGameVersion(gameId, game.Generation)}_{count}.wc{game.Generation}full"), currentWc);

                            MysteryGift wc = null;
                            if (game.Generation == 6)
                            {
                                wc = new WC6(currentWc);
                                File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $"_{GetGameVersion(gameId, game.Generation)}_{count}.wc{game.Generation}"), wc.Data);
                            }
                            else if (game.Generation == 7)
                            {
                                wc = new WC7(currentWc);
                                File.WriteAllBytes(Path.Combine(wcdir, boss.FileName + $"_{GetGameVersion(gameId, game.Generation)}_{count}.wc{game.Generation}"), wc.Data);
                            }

                            Log($"{boss.FileName} ({count}) is a wondercard ({wc.Type}): ");
                            var fullDesc = Util.TrimFromZero(Encoding.Unicode.GetString(currentWc, 4, 0x1FC));
                            //Log(fullDesc);

                            Log(GetWonderCardDescription(wc));
                            contentData = contentData.Skip(0x310).ToArray(); // Keep remaining data
                        } while (contentData.Length > 0 && contentData.Length % 0x310 == 0);

                        if (contentData.Length > 0)
                        {
                            Log($"Data remaining: {contentData.Length}");
                        }
                        Log($"Found WCs: {count}.");
                    }
                    else if (boss.Name.ToUpper().Contains("CUP") && contentData.Length == 0x4C0) // CUP Regulation
                    {
                        Log($"{boss.FileName} is a CUP!");
                        var cup_dir = Path.Combine("cups", game.Name);
                        CreateDirectoryIfNull(cup_dir);
                        var reg_arc = new RegulationArchive(contentData, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(cup_dir);
                    }
                    else if (boss.Name.Contains("regulation") && game.Generation == 7) // Gen VII Regulations
                    {
                        Log($"{boss.FileName} is a regulation!");
                        var reg_dir = Path.Combine("regulations", game.Name);
                        CreateDirectoryIfNull(reg_dir);
                        var reg_arc = new RegulationArchive(contentData, boss.FileName);
                        Log($"Extracting/Saving {boss.FileName}...");
                        reg_arc.Save(reg_dir);
                    }
                    else
                    {
                        Log($"{boss.FileName} {contentData.Length} unknown file format");
                    }
                }
            }
        }