public bool Execute(string[] args) { if (args.Length < 2) { Console.WriteLine("Expected 1 argument."); return(false); } var inputPath = args[1]; if (!File.Exists(inputPath)) { Console.WriteLine("Input file doesn't exist."); return(false); } if (!PAKFileSystem.TryOpen(inputPath, out var pak)) { Console.WriteLine("Invalid PAK file."); return(false); } using ( pak ) { Console.WriteLine($"PAK format version: {Program.FormatVersionEnumToString[pak.Version]}"); foreach (string file in pak.EnumerateFiles()) { Console.WriteLine(file); } } return(true); }
private void AddUncategorizedFilesWithExtension(PAKFileSystem fieldPak, string ext) { foreach (var file in UncategorizedFiles.Where(x => x.Key.EndsWith(ext))) { fieldPak.AddFile(file.Key, file.Value, false, ConflictPolicy.Replace); } }
//Get an EVT from a PAK and decompile event's referenced BMD private void ReadPAK(string path) { pakPath = path; using (var pak = new PAKFileSystem(FormatVersion.Version3BE)) { pak.Load(path); foreach (string file in pak.EnumerateFiles()) { var normalizedFilePath = file.Replace("../", ""); // Remove backwards relative path string filePath = Path.GetDirectoryName(path) + Path.DirectorySeparatorChar + normalizedFilePath; using (var stream = FileUtils.Create(filePath)) using (var inputStream = pak.OpenFile(file)) inputStream.CopyTo(stream); if (file.EndsWith("evt", StringComparison.InvariantCultureIgnoreCase)) { evtPath = filePath; evt = new EvtFile(evtPath); } else if (file.EndsWith("bmd", StringComparison.InvariantCultureIgnoreCase)) { bmdPath = filePath; DecompileBMD(); } } } }
private static void InjectPAC(string file, string outputPath, string searchPattern, string inputFile) { PAKFileSystem pak = new PAKFileSystem(); List <string> pakFiles = new List <string>(); if (PAKFileSystem.TryOpen(file, out pak)) { pakFiles = pak.EnumerateFiles().ToList(); PAKFileSystem newPak = pak; Console.WriteLine($"Replacing files ending with \"{searchPattern}\" in {Path.GetFileName(file)} with \"{Path.GetFileName(inputFile)}\"..."); foreach (var pakFile in pakFiles) { if (pakFile.EndsWith(searchPattern)) { string normalizedFilePath = pakFile.Replace("../", ""); //Remove backwards relative path Console.WriteLine($"Replacing {normalizedFilePath}"); newPak.AddFile(normalizedFilePath.Replace("\\", "/"), inputFile, ConflictPolicy.Replace); } } newPak.Save(Path.Combine(outputPath, Path.GetFileName(file))); } else { Console.WriteLine($"Failed to open {Path.GetFileName(file)}. Skipping..."); } }
private static PAKFileSystem OpenPAKFileSystemFile(Stream stream, bool leaveOpen, string fileName) { var pak = new PAKFileSystem(); LoadFileSystem <PAKFileSystem, string>(pak, stream, leaveOpen, fileName); return(pak); }
//Replace a PAK with new BMD and EVT and save as new PAK private void SavePAK(string path) { using (var pak = new PAKFileSystem(FormatVersion.Version3BE)) { pak.Load(pakPath); string evtHandle = ""; string bmdHandle = ""; foreach (string file in pak.EnumerateFiles()) { if (file.EndsWith("evt", StringComparison.InvariantCultureIgnoreCase)) { evtHandle = file; } else if (file.EndsWith("bmd", StringComparison.InvariantCultureIgnoreCase)) { bmdHandle = file; } } if (evtHandle != "") { pak.AddFile(evtHandle, evtPath, AtlusFileSystemLibrary.ConflictPolicy.Replace); } if (bmdHandle != "") { pak.AddFile(bmdHandle, bmdPath, AtlusFileSystemLibrary.ConflictPolicy.Replace); } pak.Save(path); } }
private T TryLoadFile <T>(PAKFileSystem pak, string path, Func <FileStream <string>, T> fileLoader) { if (TryOpenFile(pak, path, out var stream)) { return(fileLoader(stream)); } return(default);
private bool TryOpenFile(PAKFileSystem pak, string path, out FileStream <string> stream) { if (pak != null && pak.Exists(path)) { mLoadedFiles.Add(path); stream = pak.OpenFile(path); return(true); } stream = null; return(false); }
private static PAKFileSystem LoadFieldPak(string directoryPath, int major, int minor, string fileNameFormat) { PAKFileSystem pak = null; var pakPath = Path.Combine(directoryPath, string.Format(fileNameFormat, major, minor)); if (File.Exists(pakPath)) { pak = new PAKFileSystem(); pak.Load(pakPath); } return(pak); }
public bool Execute(string[] args) { if (args.Length < 2) { Console.WriteLine("Expected at least 1 argument."); return(false); } var inputPath = args[1]; if (!File.Exists(inputPath)) { Console.WriteLine("Input file doesn't exist."); return(false); } var outputPath = Path.ChangeExtension(inputPath, null); if (args.Length > 2) { outputPath = args[2]; } Directory.CreateDirectory(outputPath); if (!PAKFileSystem.TryOpen(inputPath, out var pak)) { Console.WriteLine("Invalid PAK file."); return(false); } using ( pak ) { Console.WriteLine($"PAK format version: {Program.FormatVersionEnumToString[pak.Version]}"); foreach (string file in pak.EnumerateFiles()) { var normalizedFilePath = file.Replace("../", ""); // Remove backwards relative path using (var stream = FileUtils.Create(outputPath + Path.DirectorySeparatorChar + normalizedFilePath)) using (var inputStream = pak.OpenFile(file)) { Console.WriteLine($"Extracting {file}"); inputStream.CopyTo(stream); } } } return(true); }
public bool Execute(string[] args) { if (args.Length < 3) { Console.WriteLine("Expected at least 2 arguments"); return(false); } var inputPath = args[1]; if (!Directory.Exists(inputPath)) { Console.WriteLine("Input directory doesn't exist"); return(false); } var formatName = args[2]; if (!Program.FormatsByName.TryGetValue(formatName, out var format)) { Console.WriteLine("Invalid format specified."); return(false); } var outputPath = Path.ChangeExtension(inputPath, "pak"); if (args.Length > 3) { outputPath = args[3]; } using (var pak = new PAKFileSystem(format)) { foreach (string file in Directory.EnumerateFiles(inputPath, "*.*", SearchOption.AllDirectories)) { Console.WriteLine($"Adding {file}"); pak.AddFile(file.Substring(inputPath.Length) .Trim(Path.DirectorySeparatorChar) .Replace("\\", "/"), file, ConflictPolicy.Ignore); } Console.WriteLine($"Saving..."); pak.Save(outputPath); } return(true); }
private void AddUncategorizedFiles(PAKFileSystem fieldPak, Dictionary <string, Stream> dictionary) { foreach (var file in fieldPak.EnumerateFiles()) { if (!mLoadedFiles.Contains(file)) { using (var stream = fieldPak.OpenFile(file)) { var memoryStream = new MemoryStream(); stream.FullyCopyTo(memoryStream); memoryStream.Position = 0; dictionary[file] = memoryStream; } } } }
private void LoadFieldModel(int majorId, int minorId) { var modelMajorId = majorId; var modelMinorId = minorId; if (majorId >= 150) { modelMajorId -= 100; modelMinorId *= 10; } var modelPath = Path.Combine(Settings.FieldModelDirectory, $"f{modelMajorId:D3}_{modelMinorId:D3}_0.GFS"); if (File.Exists(modelPath)) { var modelPack = GFDLibrary.Resource.Load <ModelPack>(modelPath); var texturePakPath = Path.Combine(Settings.FieldTextureDirectory, $"tex{modelMajorId:D3}_{modelMinorId:D3}_00_00.bin"); var textureDictionary = new Dictionary <string, GLTexture>(); if (File.Exists(texturePakPath)) { using (var texturePak = new PAKFileSystem()) { texturePak.Load(texturePakPath); foreach (string file in texturePak.EnumerateFiles().Where(x => x.EndsWith("dds"))) { textureDictionary[file] = new GLTexture(new FieldTexturePS3(texturePak.OpenFile(file))); } } } else if (modelPack.Textures != null) { foreach (var texture in modelPack.Textures) { textureDictionary[texture.Key] = new GLTexture(texture.Value); } } var modelPackDrawable = new ModelPackDrawable(modelPack, (material, textureName) => textureDictionary[textureName]); FieldModelRootNode.Drawable = modelPackDrawable; SetCollisionVisible(false); } }
private void ExtractPAC(string file) { PAKFileSystem pak = new PAKFileSystem(); if (PAKFileSystem.TryOpen(file, out pak)) { List <string> pakFiles = new List <string>(); txtBox_Log.Text += $"Extracting {Path.GetFileName(file)}...\n"; foreach (var pakFile in pak.EnumerateFiles()) { var normalizedFilePath = pakFile.Replace("../", ""); // Remove backwards relative path string output = txtBox_OutputDir.Text; if (chkBox_KeepFolderStructure.Checked) { output += Path.DirectorySeparatorChar + Path.GetDirectoryName(file).Substring(txtBox_SearchDir.Text.Length); } if (chkBox_NameAfterContainers.Checked) { output += Path.DirectorySeparatorChar + Path.GetFileName(file) + "_extracted" + Path.DirectorySeparatorChar + normalizedFilePath; } else { output += Path.DirectorySeparatorChar + normalizedFilePath; } using (var stream = FileUtils.Create(output)) using (var inputStream = pak.OpenFile(pakFile)) { inputStream.CopyTo(stream); pakFiles.Add(output); } File.Delete(pakFile); } foreach (var pakFile in pakFiles) { Search(pakFile); } } else { txtBox_Log.Text += $"Failed to open. Skipping...\n"; } }
public static void ExtractPAC(string file, string outputPath, string searchPattern) { PAKFileSystem pak = new PAKFileSystem(); if (PAKFileSystem.TryOpen(file, out pak)) { Console.WriteLine($"Extracting all files ending with \"{searchPattern}\" in {Path.GetFileName(file)}..."); List <string> pakFiles = new List <string>(); foreach (var pakFile in pak.EnumerateFiles()) { if (pakFile.EndsWith(searchPattern)) { string normalizedFilePath = pakFile.Replace("../", ""); //Remove backwards relative path string output = outputPath + Path.DirectorySeparatorChar + Path.GetFileName(file) + "_extracted_" + Path.GetFileName(normalizedFilePath); using (var stream = FileUtils.Create(output)) using (var inputStream = pak.OpenFile(pakFile)) { inputStream.CopyTo(stream); pakFiles.Add(output); Console.WriteLine($"Extracted {Path.GetFileName(output)}"); } } } //Extract stuff in PACs contained in this PAC foreach (var pakFile in pakFiles.Where(x => x.ToLower().EndsWith(".pac") || x.ToLower().EndsWith(".pak") || x.ToLower().EndsWith(".arc") || x.ToLower().EndsWith(".bin"))) { ExtractPAC(pakFile, outputPath, searchPattern); } } else { Console.WriteLine($"Failed to open {Path.GetFileName(file)}. Skipping..."); } }
public void Save(string directoryPath, int major, int minor) { Directory.CreateDirectory(directoryPath); using (var fieldPak = new PAKFileSystem(FormatVersion.Version1)) { TryAddFile(fieldPak, DefaultCamera, $"data/f{major:D3}_{minor:D3}.CMR", o => o.Save()); // FBN for (var i = 0; i < Layers.Count; i++) { TryAddFile(fieldPak, Layers[i].ObjectPlacement, $"data/f{major:D3}_{minor:D3}_{i:D2}.FBN", o => o.Save()); } // FPA //TryAddFile( fieldPak, Fpa, $"data/f{major:D3}_{minor:D3}.FPA", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldPak, "FPA"); // MDT //TryAddFile( fieldPak, Mdt, $"data/f{major:D3}_{minor:D3}.MDT", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldPak, "MDT"); // PCD //for ( int i = 1; i < 9; i++ ) // TryAddFile( fieldPak, Pcds[ i ], $"data/f{major:D3}_{minor:D3}_{i:D3}.PCD", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldPak, "PCD"); for (int i = 0; i < Layers.Count; i++) { TryAddFile(fieldPak, Layers[i].HitTable, $"hit/f{major:D3}_{minor:D3}_{i:D2}.HTB", o => o.Save()); } for (int i = 0; i < Layers.Count; i++) { TryAddFile(fieldPak, Layers[i].HitScript, $"hit/fhit_{major:D3}_{minor:D3}_{i:D2}.bf", o => o.ToStream()); } TryAddFile(fieldPak, InitScript, $"init/fini_{major:D3}_{minor:D3}.bf", o => o.ToStream()); // CLT AddUncategorizedFilesWithExtension(fieldPak, "CLT"); // SHT //TryAddFile( fieldPak, Sht, $"sht/f{major:D3}_{minor:D3}.SHT", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldPak, "SHT"); // TBL //TryAddFile( fieldPak, Tbl, $"fext{major:D3}_{minor:D3}.tbl", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldPak, "tbl"); // AWB AddUncategorizedFilesWithExtension(fieldPak, "AWB"); // Remaining uncategorized files foreach (var file in UncategorizedFiles.Where(x => !fieldPak.Exists(x.Key))) { fieldPak.AddFile(file.Key, file.Value, false, ConflictPolicy.Replace); } fieldPak.Save(Path.Combine(directoryPath, $"f{major:D3}_{minor:D3}.pac")); } using (var fieldNpcPak = new PAKFileSystem(FormatVersion.Version1)) { // fnpc BF for (var i = 0; i < Layers.Count; i++) { TryAddFile(fieldNpcPak, Layers[i].NpcScript, $"npc/fnpc{major:D3}_{minor:D3}_{i:D2}.bf", o => o.ToStream()); } // FNT //for ( var i = 0; i < Layers.Count; i++ ) // TryAddFile( fieldNpcPak, Layers[i].Fnt, $"npc/fnt{major:D3}_{minor:D3}_{i:D2}.FNT", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldNpcPak, "FNT"); // FPC //for ( var i = 0; i < Layers.Count; i++ ) // TryAddFile( fieldNpcPak, Layers[i].Fpc, $"npc/fpc{major:D3}_{minor:D3}_{i:D2}.FPC", o => o.Save() ); AddUncategorizedFilesWithExtension(fieldNpcPak, "FPC"); foreach (var file in UncategorizedNpcFiles.Where(x => !fieldNpcPak.Exists(x.Key))) { fieldNpcPak.AddFile(file.Key, file.Value, false, ConflictPolicy.Replace); } fieldNpcPak.Save(Path.Combine(directoryPath, $"fnpc{major:D3}_{minor:D3}.pac")); } }
protected static bool Execute(string[] args, bool allowAdd) { if (args.Length < 3) { Console.WriteLine("Expected at least 2 arguments."); return(false); } var inputPath = args[1]; if (!File.Exists(inputPath)) { Console.WriteLine("Input file doesn't exist."); return(false); } if (!PAKFileSystem.TryOpen(inputPath, out var pak)) { Console.WriteLine("Invalid PAK file."); return(false); } string outputPath = inputPath; if (Directory.Exists(args[2])) { var directoryPath = args[2]; if (args.Length > 3) { outputPath = args[3]; } using ( pak ) { foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories)) { Console.WriteLine($"{( pak.Exists(file) ? "Replacing" : "Adding" )} {file}"); pak.AddFile(file.Substring(directoryPath.Length) .Trim(Path.DirectorySeparatorChar) .Replace("\\", "/"), file, ConflictPolicy.Replace); } Console.WriteLine("Saving..."); pak.Save(outputPath); } } else { if (args.Length > 4) { outputPath = args[4]; } using ( pak ) { var entryName = args[2]; var entryExists = pak.Exists(entryName); if (!allowAdd && !entryExists) { Console.WriteLine("Specified entry doesn't exist."); return(false); } var filePath = args[3]; if (!File.Exists(filePath)) { Console.WriteLine("Specified replacement file doesn't exist."); return(false); } Console.WriteLine($"{( entryExists ? "Replacing" : "Adding")} {entryName}"); pak.AddFile(entryName, filePath, ConflictPolicy.Replace); Console.WriteLine("Saving..."); pak.Save(outputPath); } } return(true); }