Ejemplo n.º 1
0
        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);
        }
        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));
        }
Ejemplo n.º 3
0
 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);
     }
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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>();
            }
        }
Ejemplo n.º 6
0
        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;
                }
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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);
            }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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;
                }
            }
        }
Ejemplo n.º 12
0
        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++;
            }
        }