Exemple #1
0
        internal static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Logger.Error(null, "Usage: Dragapult.Experiment.exe path_to_romfs path_to_export_directory");
                return;
            }

            var root     = args.First();
            var dest     = args.ElementAt(1);
            var fileList = new FileListManager(args.ElementAtOrDefault(2));
            var catalog  = new ManagedPokemonCatalog(Paths.GetPokemonCatalogPath(root));

            foreach (var catalogEntry in catalog.Entries)
            {
                var archive     = new GFPAK(Path.Combine(root, catalogEntry.PackagePath));
                var unknownDest = Path.GetDirectoryName(catalogEntry.ConfigurationPath);
                for (var index = 0; index < archive.Files.Count; index++)
                {
                    var file = archive.Files[index];
                    var hash = archive.AbsoluteFilePathHashes[index];
                    var(folder, files) = archive.Folders.FirstOrDefault(x => x.files.Any(y => y.Index == index));
                    var folderFile = files?.FirstOrDefault(x => x.Index == index);
                    if (!fileList.AbsoluteHashes.TryGetValue(hash, out var outPath))
                    {
                        if (!fileList.NameHashes.TryGetValue(folderFile.GetValueOrDefault().Hash, out var fileName))
                        {
                            fileName = $"{hash:X16}_{folderFile.GetValueOrDefault().Hash:X16}";
                        }
                        outPath = fileList.DirectoryHashes.TryGetValue(folder.Hash, out var folderPath) ? Path.Combine(folderPath, fileName) : Path.Combine(unknownDest, folder.Hash.ToString("X16"), fileName);
                    }

                    outPath = Path.Combine(dest, outPath);
                    var dir = Path.GetDirectoryName(outPath);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    File.WriteAllBytes(outPath, file.ToArray());
                    Logger.Log24Bit(ConsoleSwatch.XTermColor.White, true, Console.Out, null, $"Saved {outPath}");
                }
            }
        }
Exemple #2
0
        private static void ProcessCatalog(ManagedPokemonCatalog catalog, ISet <string> fileNames, string root)
        {
            foreach (var catalogEntry in catalog.Entries)
            {
                fileNames.Add(catalogEntry.ModelPath);
                fileNames.Add(catalogEntry.ConfigurationPath);
                var archive   = new GFPAK(Path.Combine(root, catalogEntry.PackagePath));
                var model     = PokemonModel.GetRootAsPokemonModel(archive.GetFile(catalogEntry.ModelPath).Span.ToByteBuffer());
                var modelPath = Path.GetDirectoryName(catalogEntry.ModelPath);
                fileNames.Add(Path.Combine(modelPath, "__ArchiveShader.bnsh").UnixPath(false));
                fileNames.Add(Path.Combine(modelPath, "__Combined.bntx").UnixPath(false));
                for (var i = 0; i < model.TexturesLength; ++i)
                {
                    fileNames.Add(Path.Combine(modelPath, model.Textures(i) + ".bntx").UnixPath(false));
                }
                for (var i = 0; i < model.ShaderNamesLength; ++i)
                {
                    var shader = model.ShaderNames(i);
                    // NOICE!
                    fileNames.Add(Path.Combine(modelPath, shader + ".bnsh").UnixPath(false));
                    fileNames.Add(Path.Combine(modelPath, shader + ".bnsh_fsh").UnixPath(false));
                    fileNames.Add(Path.Combine(modelPath, shader + ".bnsh_gsh").UnixPath(false));
                    fileNames.Add(Path.Combine(modelPath, shader + ".bnsh_vsh").UnixPath(false));
                    fileNames.Add(Path.Combine(modelPath, $"ArchiveShader-{shader}.bnsh").UnixPath(false));
                }

                var name = Path.GetFileName(Path.GetDirectoryName(catalogEntry.ConfigurationPath));
                foreach (var animationConfig in catalogEntry.AnimationSets.Values)
                {
                    fileNames.Add(animationConfig);
                    var animationPath = Path.GetDirectoryName(animationConfig);
                    fileNames.Add(Path.Combine(animationPath, name + ".gfbanm").UnixPath(false));
                    var config        = PokemonAnimationConfig.GetRootAsPokemonAnimationConfig(archive.GetFile(animationConfig).Span.ToByteBuffer());
                    var animationData = config.AnimationData.GetValueOrDefault();
                    for (var i = 0; i < animationData.ReferencesLength; ++i)
                    {
                        fileNames.Add(Path.Combine(animationPath, animationData.References(i).GetValueOrDefault().Path).UnixPath(false));
                    }
                }
            }
        }