private static bool Decompress(string sourceFile) { Console.WriteLine($"Decompressing DCX: {Path.GetFileName(sourceFile)}..."); string sourceDir = Path.GetDirectoryName(sourceFile); string outPath; if (sourceFile.EndsWith(".dcx")) { outPath = $"{sourceDir}\\{Path.GetFileNameWithoutExtension(sourceFile)}"; } else { outPath = $"{sourceFile}.undcx"; } byte[] bytes = DCX.Decompress(sourceFile, out DCX.Type compression); File.WriteAllBytes(outPath, bytes); XmlWriterSettings xws = new XmlWriterSettings(); xws.Indent = true; XmlWriter xw = XmlWriter.Create($"{outPath}-yabber-dcx.xml", xws); xw.WriteStartElement("dcx"); xw.WriteElementString("compression", compression.ToString()); xw.WriteEndElement(); xw.Close(); return(false); }
public static IntPtr GetDCEx(IHandle hWnd, IntPtr hrgnClip, DCX flags) { IntPtr result = GetDCEx(hWnd.Handle, hrgnClip, flags); GC.KeepAlive(hWnd); return(result); }
bool IResource._Load(string file, AccessLevel al, GameType type) { if (type == GameType.Bloodborne) { Hkx = HKX.Read(file, HKX.HKXVariation.HKXBloodBorne); } else if (type == GameType.DarkSoulsIII) { DCX.Type t; var decomp = DCX.Decompress(file, out t); var br = new BinaryReaderEx(false, decomp); var des = new HKX2.PackFileDeserializer(); Hkx2 = (hkRootLevelContainer)des.Deserialize(br); } else { Hkx = HKX.Read(file); } if (type == GameType.DarkSoulsIISOTFS || type == GameType.DarkSoulsIII || type == GameType.Bloodborne) { FrontFace = FrontFace.Clockwise; } else { FrontFace = FrontFace.CounterClockwise; } if (type == GameType.DarkSoulsIII) { return(LoadInternalNew(al)); } return(LoadInternal(al)); }
public void ReDcx(string dir, string ext) { foreach (string path in Directory.GetFiles($@"{dir}\dcx", "*." + ext)) { string name = Path.GetFileNameWithoutExtension(path); DCX.Compress(File.ReadAllBytes(path), (DCX.Type)DCX.DefaultType.Sekiro, $@"{dir}\{name}.{ext}.dcx"); } }
public void UnDcx(string dir) { foreach (string path in Directory.GetFiles(dir, "*.dcx")) { string name = Path.GetFileNameWithoutExtension(path); byte[] f = DCX.Decompress(path); File.WriteAllBytes($@"{dir}\dcx\{name}", f); } }
private int PackBinder(IBinder binder, string relOutputDir, CancellationToken cancelToken) { int textureCount = 0; foreach (BinderFile file in binder.Files) { if (cancelToken.IsCancellationRequested) { return(textureCount); } if (TPUtil.HasValidExtension(file.Name)) { try { byte[] bytes = file.Bytes; DCX.Type dcxType = DCX.Type.None; if (DCX.Is(bytes)) { bytes = DCX.Decompress(bytes, out dcxType); } if (TPF.IsRead(bytes, out TPF tpf)) { int thisTextureCount = PackTPF(tpf, relOutputDir); if (thisTextureCount > 0) { file.Bytes = tpf.Write(dcxType); } textureCount += thisTextureCount; } else if (BND4.IsRead(bytes, out BND4 bnd)) { int thisTextureCount = PackBinder(bnd, relOutputDir, cancelToken); if (thisTextureCount > 0) { file.Bytes = bnd.Write(dcxType); } textureCount += thisTextureCount; } else { throw new NotSupportedException("Unknown file type."); } } catch (Exception ex) { throw new Exception($"Error in binder file \"{file.Name}\"", ex); } } } return(textureCount); }
private void Browse_Click(object sender, RoutedEventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.DefaultExt = ".anibnd.dcx"; fileDialog.Filter = "ANIBND.DCX Files (*.anibnd.dcx)|*.anibnd.dcx"; fileDialog.Title = "Select a .animbnd.dcx file"; fileDialog.CheckFileExists = true; fileDialog.CheckPathExists = true; bool?result = fileDialog.ShowDialog(); if (result == true) { StackPanel.Children.Clear(); Canvas.Children.Clear(); string filePath = fileDialog.FileName; Console.WriteLine(filePath); if (!File.Exists(filePath)) { return; } if (!BND4.Is(DCX.Decompress(filePath))) { return; } anibnd = BND4.Read(filePath); OpenFile.bndPath = filePath; dropdownOptions = new Dictionary <string, Dictionary <string, int> >(); foreach (BND4.File f in anibnd.Files) { if (System.IO.Path.GetExtension(f.Name).Equals(".hkx")) { Console.WriteLine(f.ToString()); string moveset = new DirectoryInfo(f.Name).Parent.Name; string fileName = System.IO.Path.GetFileNameWithoutExtension(f.Name); if (!dropdownOptions.ContainsKey(moveset)) { dropdownOptions[moveset] = new Dictionary <string, int>(); } dropdownOptions[moveset][fileName] = f.ID; } } lbl_anibnd.Content = System.IO.Path.GetFileNameWithoutExtension(filePath); cmb_moveset.ItemsSource = dropdownOptions.Keys.Count > 0 ? dropdownOptions.Keys : Enumerable.Empty <string>(); cmb_animation.ItemsSource = Enumerable.Empty <string>(); } }
private void UnpackTPFs(ConcurrentQueue <string> filepaths) { string filepath; while (filepaths.TryDequeue(out filepath)) { Log.Enqueue("Unpacking texture file " + (fileCount - filepaths.Count) + " of " + fileCount); // These are already full paths, but trust no one, not even yourself string absolute = Path.GetFullPath(filepath); string relative = absolute.Substring(gameDir.Length + 1); byte[] bytes = File.ReadAllBytes(absolute); string extension = Path.GetExtension(absolute); string subpath = Path.GetDirectoryName(relative) + "\\" + Path.GetFileNameWithoutExtension(absolute); if (extension == ".dcx") { bytes = DCX.Decompress(bytes); extension = Path.GetExtension(Path.GetFileNameWithoutExtension(absolute)); subpath = subpath.Substring(0, subpath.Length - extension.Length); } switch (extension) { case ".tpf": TPF tpf = TPF.Read(bytes); UnpackTPF(tpf, looseDir, subpath); break; case ".chrbnd": case ".ffxbnd": case ".fgbnd": case ".objbnd": case ".partsbnd": BND3 bnd = BND3.Read(bytes); foreach (var entry in bnd.Files) { string entryExtension = Path.GetExtension(entry.Name); if (entryExtension == ".tpf") { TPF bndTPF = TPF.Read(entry.Bytes); UnpackTPF(bndTPF, looseDir, subpath); } } break; } } }
static void Main(string[] args) { if (args.Length == 0) { Assembly assembly = Assembly.GetExecutingAssembly(); Console.WriteLine( $"{assembly.GetName().Name} {assembly.GetName().Version}\n\n" + "Yabber.DCX has no GUI.\n" + "Drag and drop a DCX onto the exe to decompress it,\n" + "or a decompressed file to recompress it.\n\n" + "Press any key to exit." ); Console.ReadKey(); return; } bool pause = false; foreach (string path in args) { try { if (DCX.Is(path)) { pause |= Decompress(path); } else { pause |= Compress(path); } } catch (Exception ex) { Console.WriteLine($"Unhandled exception: {ex}"); pause = true; } Console.WriteLine(); } if (pause) { Console.WriteLine("One or more errors were encountered and displayed above.\nPress any key to exit."); Console.ReadKey(); } }
private bool processBDT(BDT bdt, string baseDir, string subPath) { bool edited = false; foreach (BDT.File bdtEntry in bdt.Files) { if (stop) { return(false); } bool dcx = false; byte[] bdtEntryBytes = bdtEntry.Bytes; string bdtEntryExtension = Path.GetExtension(bdtEntry.Name); if (bdtEntryExtension == ".dcx") { dcx = true; bdtEntryBytes = DCX.Decompress(bdtEntryBytes); bdtEntryExtension = Path.GetExtension(bdtEntry.Name.Substring(0, bdtEntry.Name.Length - 4)); } if (bdtEntryExtension == ".tpf") { TPF tpf = TPF.Read(bdtEntryBytes); if (processTPF(tpf, baseDir, subPath)) { bdtEntry.Bytes = tpf.Write(); if (dcx) { bdtEntry.Bytes = DCX.Compress(bdtEntry.Bytes); } edited = true; } } // This whouldn't really be a problem, but I would like to know about it else { appendError("Error: {0}\r\n\u2514\u2500 Non-tpf found in tpfbdt: {1}", subPath, bdtEntry.Name); } } return(edited); }
private static bool Compress(string path) { string xmlPath = $"{path}-yabber-dcx.xml"; if (!File.Exists(xmlPath)) { Console.WriteLine($"XML file not found: {xmlPath}"); return(true); } Console.WriteLine($"Compressing file: {Path.GetFileName(path)}..."); XmlDocument xml = new XmlDocument(); xml.Load(xmlPath); DCX.Type compression = (DCX.Type)Enum.Parse(typeof(DCX.Type), xml.SelectSingleNode("dcx/compression").InnerText); string outPath; if (path.EndsWith(".undcx")) { outPath = path.Substring(0, path.Length - 6); } else { outPath = path + ".dcx"; } if (File.Exists(outPath) && !File.Exists(outPath + ".bak")) { File.Move(outPath, outPath + ".bak"); } DCX.Compress(File.ReadAllBytes(path), compression, outPath); return(false); }
/// <summary> /// Creates a <see cref="Gdi32.HDC"/> using <see cref="GetDCEx(IntPtr, IntPtr, DCX)"/>. /// </summary> /// <remarks> /// GetWindowDC calls GetDCEx(hwnd, null, DCX_WINDOW | DCX_USESTYLE). /// /// GetDC calls GetDCEx(hwnd, null, DCX_USESTYLE) when given a handle. (When given null it has additional /// logic, and can't be replaced directly by GetDCEx. /// </remarks> public GetDcScope(IntPtr hwnd, IntPtr hrgnClip, DCX flags) { HWND = hwnd; HDC = GetDCEx(hwnd, hrgnClip, flags); }
private static bool UnpackFile(string sourceFile) { string sourceDir = Path.GetDirectoryName(sourceFile); string filename = Path.GetFileName(sourceFile); string targetDir = $"{sourceDir}\\{filename.Replace('.', '-')}"; if (File.Exists(targetDir)) { targetDir += "-ybr"; } if (DCX.Is(sourceFile)) { Console.WriteLine($"Decompressing DCX: {filename}..."); byte[] bytes = DCX.Decompress(sourceFile, out DCX.Type compression); if (BND3.Is(bytes)) { Console.WriteLine($"Unpacking BND3: {filename}..."); BND3 bnd = BND3.Read(bytes); bnd.Compression = compression; bnd.Unpack(filename, targetDir); } else if (BND4.Is(bytes)) { Console.WriteLine($"Unpacking BND4: {filename}..."); BND4 bnd = BND4.Read(bytes); bnd.Compression = compression; bnd.Unpack(filename, targetDir); } else if (TPF.Is(bytes)) { Console.WriteLine($"Unpacking TPF: {filename}..."); TPF tpf = TPF.Read(bytes); tpf.Compression = compression; tpf.Unpack(filename, targetDir); } else if (sourceFile.EndsWith(".gparam.dcx")) { Console.WriteLine($"Unpacking GPARAM: {filename}..."); GPARAM gparam = GPARAM.Read(bytes); gparam.Unpack(sourceFile); } else { Console.WriteLine($"File format not recognized: {filename}"); return(true); } } else { if (BND3.Is(sourceFile)) { Console.WriteLine($"Unpacking BND3: {filename}..."); BND3 bnd = BND3.Read(sourceFile); bnd.Unpack(filename, targetDir); } else if (BND4.Is(sourceFile)) { Console.WriteLine($"Unpacking BND4: {filename}..."); BND4 bnd = BND4.Read(sourceFile); bnd.Unpack(filename, targetDir); } else if (BXF3.IsBHD(sourceFile)) { string bdtExtension = Path.GetExtension(filename).Replace("bhd", "bdt"); string bdtFilename = $"{Path.GetFileNameWithoutExtension(filename)}{bdtExtension}"; string bdtPath = $"{sourceDir}\\{bdtFilename}"; if (File.Exists(bdtPath)) { Console.WriteLine($"Unpacking BXF3: {filename}..."); BXF3 bxf = BXF3.Read(sourceFile, bdtPath); bxf.Unpack(filename, bdtFilename, targetDir); } else { Console.WriteLine($"BDT not found for BHD: {filename}"); return(true); } } else if (BXF4.IsBHD(sourceFile)) { string bdtExtension = Path.GetExtension(filename).Replace("bhd", "bdt"); string bdtFilename = $"{Path.GetFileNameWithoutExtension(filename)}{bdtExtension}"; string bdtPath = $"{sourceDir}\\{bdtFilename}"; if (File.Exists(bdtPath)) { Console.WriteLine($"Unpacking BXF4: {filename}..."); BXF4 bxf = BXF4.Read(sourceFile, bdtPath); bxf.Unpack(filename, bdtFilename, targetDir); } else { Console.WriteLine($"BDT not found for BHD: {filename}"); return(true); } } else if (TPF.Is(sourceFile)) { Console.WriteLine($"Unpacking TPF: {filename}..."); TPF tpf = TPF.Read(sourceFile); tpf.Unpack(filename, targetDir); } else if (sourceFile.EndsWith(".fmg")) { Console.WriteLine($"Unpacking FMG: {filename}..."); FMG fmg = FMG.Read(sourceFile); fmg.Unpack(sourceFile); } else if (sourceFile.EndsWith(".fmg.xml")) { Console.WriteLine($"Repacking FMG: {filename}..."); YFMG.Repack(sourceFile); } else if (sourceFile.EndsWith(".gparam")) { Console.WriteLine($"Unpacking GPARAM: {filename}..."); GPARAM gparam = GPARAM.Read(sourceFile); gparam.Unpack(sourceFile); } else if (sourceFile.EndsWith(".gparam.xml") || sourceFile.EndsWith(".gparam.dcx.xml")) { Console.WriteLine($"Repacking GPARAM: {filename}..."); YGPARAM.Repack(sourceFile); } else if (sourceFile.EndsWith(".luagnl")) { Console.WriteLine($"Unpacking LUAGNL: {filename}..."); LUAGNL gnl = LUAGNL.Read(sourceFile); gnl.Unpack(sourceFile); } else if (sourceFile.EndsWith(".luagnl.xml")) { Console.WriteLine($"Repacking LUAGNL: {filename}..."); YLUAGNL.Repack(sourceFile); } else if (LUAINFO.Is(sourceFile)) { Console.WriteLine($"Unpacking LUAINFO: {filename}..."); LUAINFO info = LUAINFO.Read(sourceFile); info.Unpack(sourceFile); } else if (sourceFile.EndsWith(".luainfo.xml")) { Console.WriteLine($"Repacking LUAINFO: {filename}..."); YLUAINFO.Repack(sourceFile); } else { Console.WriteLine($"File format not recognized: {filename}"); return(true); } } return(false); }
public static extern HDC GetDCEx(HWND hWnd, HRGN hrgnClip, DCX flags);
private static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgn, DCX flags);
static void Main(string[] args) { if (args.Length == 0) { Assembly assembly = Assembly.GetExecutingAssembly(); Console.WriteLine( $"{assembly.GetName().Name} {assembly.GetName().Version}\n\n" + "Yabber.DCX has no GUI.\n" + "Drag and drop a DCX onto the exe to decompress it,\n" + "or a decompressed file to recompress it.\n\n" + "Press any key to exit." ); Console.ReadKey(); return; } bool pause = false; foreach (string path in args) { try { if (DCX.Is(path)) { pause |= Decompress(path); } else { pause |= Compress(path); } } catch (DllNotFoundException ex) when(ex.Message.Contains("oo2core_6_win64.dll")) { Console.WriteLine("In order to decompress .dcx files from Sekiro, you must copy oo2core_6_win64.dll from Sekiro into Yabber's lib folder."); pause = true; } catch (UnauthorizedAccessException) { using (Process current = Process.GetCurrentProcess()) { var admin = new Process(); admin.StartInfo = current.StartInfo; admin.StartInfo.FileName = current.MainModule.FileName; admin.StartInfo.Arguments = Environment.CommandLine.Replace($"\"{Environment.GetCommandLineArgs()[0]}\"", ""); admin.StartInfo.Verb = "runas"; admin.Start(); return; } } catch (Exception ex) { Console.WriteLine($"Unhandled exception: {ex}"); pause = true; } Console.WriteLine(); } if (pause) { Console.WriteLine("One or more errors were encountered and displayed above.\nPress any key to exit."); Console.ReadKey(); } }
public static extern Gdi32.HDC GetDCEx(IntPtr hWnd, IntPtr hrgnClip, DCX flags);
private int PackVirtualFile(VirtualFile vf, CancellationToken cancelToken) { byte[] bytes; long baseMemory; lock (this) { while (BaseMemoryCommitted > TPUtil.MAX_BASE_MEMORY) { Thread.Sleep(10); } if (cancelToken.IsCancellationRequested) { return(0); } bytes = vf.Load(); baseMemory = bytes.Length; Interlocked.Add(ref BaseMemoryCommitted, baseMemory); } try { string relOutputDir = TPUtil.GetRelativeOutputDir(vf.Path); DCX.Type dcxType = DCX.Type.None; if (DCX.Is(bytes)) { bytes = DCX.Decompress(bytes, out dcxType); } int textureCount; if (TPF.IsRead(bytes, out TPF tpf)) { textureCount = PackTPF(tpf, relOutputDir); if (textureCount > 0) { tpf.Write($@"{OutputDirectory}\{vf.Path}", dcxType); } } else if (BND4.IsRead(bytes, out BND4 bnd)) { textureCount = PackBinder(bnd, relOutputDir, cancelToken); if (textureCount > 0) { bnd.Write($@"{OutputDirectory}\{vf.Path}", dcxType); } } else if (BXF4.IsBDT(bytes)) { string ext = Path.GetExtension(vf.Path).Replace("bdt", "bhd"); string bhdPath = Path.ChangeExtension(vf.Path, ext); VirtualFile vfHeader = VirtualFS.Files[bhdPath]; byte[] bhdBytes = vfHeader.Load(); var bxf = BXF4.Read(bhdBytes, bytes); textureCount = PackBinder(bxf, relOutputDir, cancelToken); if (textureCount > 0) { bxf.Write($@"{OutputDirectory}\{vfHeader.Path}", $@"{OutputDirectory}\{vf.Path}"); } } else { throw new NotSupportedException("Unknown file type."); } return(textureCount); } finally { Interlocked.Add(ref BaseMemoryCommitted, -baseMemory); } }
public static extern IntPtr GetDCEx( [In] IntPtr hWnd, [In] IntPtr hrgnClip, [In] DCX flags);
public static partial Gdi32.HDC GetDCEx(IntPtr hWnd, IntPtr hrgnClip, DCX flags);
private static void Main(string[] args) { if (args.Length == 0) { var assembly = Assembly.GetExecutingAssembly(); Console.WriteLine( $"{assembly.GetName().Name} {assembly.GetName().Version}\n\n" + $"{ExeName} 没有图形用户界面。\n" + "将DCX拖放到exe上以对其进行解压缩,或将已解压缩的文件重新进行压缩。\n\n" + "按任意键退出。" ); AutoQuit(); return; } var pause = false; foreach (var path in args) { try { if (Directory.Exists(path)) { Console.WriteLine($"略过目录“{path}”"); continue; } if (DCX.Is(path)) { pause |= Decompress(path); } else { pause |= Compress(path); } } catch (DllNotFoundException ex) when(ex.Message.Contains(DllOo2Core)) { Console.WriteLine($"要解压缩游戏《只狼:影逝二度》的 .dcx 文件,你必须从游戏《只狼:影逝二度》复制文件 {DllOo2Core}.dll 到文件 {ExeName}.exe 所在目录中!"); pause = true; } catch (UnauthorizedAccessException) { using var current = Process.GetCurrentProcess(); var admin = new Process { StartInfo = current.StartInfo }; admin.StartInfo.FileName = current.MainModule?.FileName ?? string.Empty; admin.StartInfo.Arguments = Environment.CommandLine.Replace($"\"{Environment.GetCommandLineArgs()[0]}\"", ""); admin.StartInfo.Verb = "runas"; admin.Start(); return; } catch (Exception ex) { Console.WriteLine($"未捕获异常:{ex}"); pause = true; } } if (pause) { AutoQuit(); } }
public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, DCX flags);
private void RepackTPFs(ConcurrentQueue <string> filepaths) { string filepath; while (filepaths.TryDequeue(out filepath)) { Log.Enqueue("Repacking texture file " + (fileCount - filepaths.Count) + " of " + fileCount); // These are already full paths, but trust no one, not even yourself string absolute = Path.GetFullPath(filepath); string relative = absolute.Substring(gameDir.Length + 1); bool dcx = false; byte[] bytes = File.ReadAllBytes(absolute); string extension = Path.GetExtension(absolute); string subpath = Path.GetDirectoryName(relative) + "\\" + Path.GetFileNameWithoutExtension(absolute); if (extension == ".dcx") { dcx = true; bytes = DCX.Decompress(bytes); extension = Path.GetExtension(Path.GetFileNameWithoutExtension(absolute)); subpath = subpath.Substring(0, subpath.Length - extension.Length); } switch (extension) { case ".tpf": TPF tpf = TPF.Read(bytes); repackTPF(tpf, looseDir, subpath); byte[] tpfBytes = tpf.Write(); if (dcx) { tpfBytes = DCX.Compress(tpfBytes, DCX.Type.DarkSouls1); } Directory.CreateDirectory(Path.GetDirectoryName(gameDir + "\\TextSoundRando\\Output\\" + relative)); File.WriteAllBytes(gameDir + "\\TextSoundRando\\Output\\" + relative, tpfBytes); break; case ".chrbnd": case ".ffxbnd": case ".fgbnd": case ".objbnd": case ".partsbnd": BND3 bnd = BND3.Read(bytes); foreach (var entry in bnd.Files) { string entryExtension = Path.GetExtension(entry.Name); if (entryExtension == ".tpf") { TPF bndTPF = TPF.Read(entry.Bytes); repackTPF(bndTPF, looseDir, subpath); entry.Bytes = bndTPF.Write(); } } byte[] bndBytes = bnd.Write(); if (dcx) { bndBytes = DCX.Compress(bndBytes, DCX.Type.DarkSouls1); } Directory.CreateDirectory(Path.GetDirectoryName(gameDir + "\\TextSoundRando\\Output\\" + relative)); File.WriteAllBytes(gameDir + "\\TextSoundRando\\Output\\" + relative, bndBytes); break; } } }
private int UnpackVirtualFile(VirtualFile vf, CancellationToken cancelToken) { byte[] bytes; long baseMemory; lock (this) { while (BaseMemoryCommitted > TPUtil.MAX_BASE_MEMORY) { Thread.Sleep(10); } if (cancelToken.IsCancellationRequested) { return(0); } bytes = vf.Load(); baseMemory = bytes.Length; Interlocked.Add(ref BaseMemoryCommitted, baseMemory); } try { string relOutputDir = TPUtil.GetRelativeOutputDir(vf.Path); if (DCX.Is(bytes)) { bytes = DCX.Decompress(bytes); } int textureCount; var report = new UnpackReport(); if (TPF.IsRead(bytes, out TPF tpf)) { textureCount = UnpackTPF(tpf, relOutputDir, report); } else if (BND4.IsRead(bytes, out BND4 bnd)) { textureCount = UnpackBinder(bnd, relOutputDir, report, cancelToken); } else if (BXF4.IsBDT(bytes)) { string ext = Path.GetExtension(vf.Path).Replace("bdt", "bhd"); string bhdPath = Path.ChangeExtension(vf.Path, ext); VirtualFile vfHeader = VirtualFS.Files[bhdPath]; byte[] bhdBytes = vfHeader.Load(); var bxf = BXF4.Read(bhdBytes, bytes); textureCount = UnpackBinder(bxf, relOutputDir, report, cancelToken); } else { throw new NotSupportedException("Unknown file type."); } if (report.Files.Count > 0) { File.WriteAllText($@"{Game.Settings.UnpackDirectory.TrimEnd('\\')}\{relOutputDir}\_report.txt", report.Write()); } return(textureCount); } finally { Interlocked.Add(ref BaseMemoryCommitted, -baseMemory); } }
private void iterateFiles(ConcurrentQueue <string> filepaths) { while (!stop && filepaths.TryDequeue(out string filepath)) { // These are already full paths, but trust no one, not even yourself string absolute = Path.GetFullPath(filepath); string relative = absolute.Substring(gameDir.Length + 1); if (repack) { appendLog("Checking: " + relative); } else { appendLog("Unpacking: " + relative); } bool dcx = false; byte[] bytes = File.ReadAllBytes(absolute); string extension = Path.GetExtension(absolute); string subpath = Path.GetDirectoryName(relative) + "\\" + Path.GetFileNameWithoutExtension(absolute); if (extension == ".dcx") { dcx = true; bytes = DCX.Decompress(bytes); extension = Path.GetExtension(Path.GetFileNameWithoutExtension(absolute)); subpath = subpath.Substring(0, subpath.Length - extension.Length); } bool edited = false; switch (extension) { case ".tpf": TPF tpf = TPF.Read(bytes); if (processTPF(tpf, looseDir, subpath)) { edited = true; byte[] tpfBytes = tpf.Write(); if (dcx) { tpfBytes = DCX.Compress(tpfBytes); } writeRepack(absolute, tpfBytes); lock (countLock) fileCount++; } break; case ".tpfbhd": string dir = Path.GetDirectoryName(absolute); string name = Path.GetFileNameWithoutExtension(absolute); string bdtPath = dir + "\\" + name + ".tpfbdt"; if (File.Exists(bdtPath)) { byte[] bdtBytes = File.ReadAllBytes(bdtPath); BDT bdt = BDT.Read(bytes, bdtBytes); if (processBDT(bdt, looseDir, subpath)) { edited = true; (byte[], byte[])repacked = bdt.Write(); if (dcx) { repacked.Item1 = DCX.Compress(repacked.Item1); } writeRepack(absolute, repacked.Item1); writeRepack(bdtPath, repacked.Item2); lock (countLock) fileCount++; } } else { throw new FileNotFoundException("Data file not found for header: " + relative); } break; case ".chrbnd": case ".ffxbnd": case ".fgbnd": case ".objbnd": case ".partsbnd": BND bnd = BND.Read(bytes); foreach (BND.File entry in bnd.Files) { if (stop) { break; } string entryExtension = Path.GetExtension(entry.Name); if (entryExtension == ".tpf") { TPF bndTPF = TPF.Read(entry.Bytes); if (processTPF(bndTPF, looseDir, subpath)) { entry.Bytes = bndTPF.Write(); edited = true; } } else if (entryExtension == ".chrtpfbhd") { string bndDir = Path.GetDirectoryName(absolute); string bndName = Path.GetFileNameWithoutExtension(absolute); if (dcx) { bndName = Path.GetFileNameWithoutExtension(bndName); } string bndBDTPath = bndDir + "\\" + bndName + ".chrtpfbdt"; if (File.Exists(bndBDTPath)) { byte[] bdtBytes = File.ReadAllBytes(bndBDTPath); BDT bndBDT = BDT.Read(entry.Bytes, bdtBytes); if (processBDT(bndBDT, looseDir, subpath)) { (byte[], byte[])repacked = bndBDT.Write(); entry.Bytes = repacked.Item1; writeRepack(bndBDTPath, repacked.Item2); edited = true; } } else { throw new FileNotFoundException("Data file not found for header: " + relative); } } } if (edited && !stop) { byte[] bndBytes = bnd.Write(); if (dcx) { bndBytes = DCX.Compress(bndBytes); } writeRepack(absolute, bndBytes); lock (countLock) fileCount++; } break; } if (repack && !edited && !stop) { appendError("Notice: {0}\r\n\u2514\u2500 No overrides found.", relative); } lock (progressLock) progress++; } }