/// <summary> /// Load a BND4 archive from a file and return a <see cref="BND4File"></see> object. /// </summary> /// <param name="filePath"></param> public static BND4File Load(string filePath) { var BND = new BND4File(); BND.LoadInPlace(filePath); return(BND); }
/// <summary> /// Create a BND4File object from subfiles stored in a folder. /// </summary> /// <param name="folder"></param> /// <param name="encrypt"></param> /// <returns></returns> public static BND4File Pack(string folder, bool encrypt = true) { if (DEBUG) { Console.WriteLine("[DEBUG] PACKING FOLDER INTO BND4 ARCHIVE..."); } Utils.Assert(Directory.Exists(folder), "Folder does not exist"); string[] files = Directory.GetFiles(folder); Utils.Assert(files.Length != 0, "No subfiles to add to archive"); var BND = new BND4File(); BND.isUnicode = true; BND.entries = new BND4Entry[files.Length]; for (int i = 0; i < files.Length; i++) { BND.entries[i] = new BND4Entry(); BND.entries[i].name = Path.GetFileName(files[i]); byte[] data = File.ReadAllBytes(files[i]); if (encrypt) { BND.entries[i].SetEncryptedData(data, false); } else { BND.entries[i].data = data; } } if (DEBUG) { Console.WriteLine("[DEBUG] PACKING COMPLETED"); } return(BND); }
static void Main() { while (true) { Console.Clear(); Console.WriteLine(@"Choose action: [1] Unpack encrypted SL2 save file [2] Pack encrypted SL2 save file [3] Unpack unencrypted BND4 archive [4] Pack unencrypted BND4 archive [5] Patch SL2 save file linked account [6] Recursively patch all saves in a folder [7] Exit "); char key; do { key = Console.ReadKey(true).KeyChar; } while (key < '1' || key > '7'); if (key == '7') { return; } // Get default DS3 Save location & prompt open save file var ds3Folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DarkSoulsIII\\"); if (key == '2' || key == '4') { var diagFolder = new CommonOpenFileDialog() { Title = "Select unpack directory", IsFolderPicker = true, InitialDirectory = ds3Folder }; if (diagFolder.ShowDialog() != CommonFileDialogResult.Ok) { continue; } BND4File file = BND4File.Pack(diagFolder.FileName, key == '2'); var diagSave = new SaveFileDialog() { Title = "Save packet file at...", DefaultExt = "sl2", FileName = "DS30000.sl2", InitialDirectory = ds3Folder }; if (diagSave.ShowDialog() != DialogResult.OK) { continue; } file.Save(diagSave.FileName); Console.Write("\nDone, press any key to return to menu"); Console.ReadKey(true); continue; } if (key == '6') { var diagFolder = new CommonOpenFileDialog() { Title = "Select root directory", IsFolderPicker = true, InitialDirectory = ds3Folder }; if (diagFolder.ShowDialog() != CommonFileDialogResult.Ok) { continue; } Console.WriteLine("Proceed carefully. Entering the wrong ID will make the save unreadable."); ulong steamID = 0; while (steamID == 0) { Console.Write("Enter your 64-bit Steam ID (number in profile URL): "); if (!ulong.TryParse(Console.ReadLine(), out steamID)) { Console.WriteLine("Please input a valid number."); } } foreach (string saveFile in Directory.EnumerateFiles(diagFolder.FileName, "*.sl2", SearchOption.AllDirectories)) { Console.WriteLine(" Patching " + saveFile + "..."); BND4File BND = new BND4File(saveFile); BND.PatchDS3AccountFlag(steamID); BND.Save(saveFile); } Console.Write("\nDone, press any key to return to menu"); Console.ReadKey(true); continue; } var diagOpen = new OpenFileDialog() { Title = "Select BND4/SL2 file", DefaultExt = "sl2", CheckFileExists = true, CheckPathExists = true, Multiselect = false, InitialDirectory = ds3Folder }; if (diagOpen.ShowDialog() != DialogResult.OK) { continue; } if (key == '1' || key == '3') { var diagFolder = new CommonOpenFileDialog() { Title = "Select unpack directory", IsFolderPicker = true, InitialDirectory = ds3Folder }; if (diagFolder.ShowDialog() != CommonFileDialogResult.Ok) { continue; } BND4File.Unpack(diagOpen.FileName, diagFolder.FileName, key == '1'); } if (key == '5') { var save = new BND4File(diagOpen.FileName); Console.WriteLine("Proceed carefully. Entering the wrong ID will make the save unreadable."); ulong steamID = 0; while (steamID == 0) { Console.Write("Enter your 64-bit Steam ID (number in profile URL): "); if (!ulong.TryParse(Console.ReadLine(), out steamID)) { Console.WriteLine("Please input a valid number."); } } save.PatchDS3AccountFlag(steamID); var diagSave = new SaveFileDialog() { Title = "Save patched file at...", DefaultExt = "sl2", FileName = "DS30000.sl2", InitialDirectory = ds3Folder }; if (diagSave.ShowDialog() != DialogResult.OK) { continue; } save.Save(diagSave.FileName); } Console.Write("\nDone, press any key to return to menu"); Console.ReadKey(true); } }
/// <summary> /// Unpack a BND4 file into a folder. /// </summary> /// <param name="filePath"></param> /// <param name="folder"></param> /// <param name="decrypt"></param> public static void Unpack(string filePath, string folder, bool decrypt = true) { var BND = new BND4File(filePath); BND.Unpack(folder, decrypt); }