public static void AddSpecificTexturesFromBinder(string name, List <string> textures, bool directEntryNameMatch = false) { if (!File.Exists(name)) { return; } IBinder bnd = null; if (BXF4.IsBHD(name)) { bnd = BXF4.Read(name, name.Substring(0, name.Length - 7) + ".tpfbdt"); } else if (BXF4.IsBDT(name)) { bnd = BXF4.Read(name.Substring(0, name.Length - 7) + ".tpfbhd", name); } else if (BXF3.IsBHD(name)) { bnd = BXF3.Read(name, name.Substring(0, name.Length - 7) + ".tpfbdt"); } else if (BXF3.IsBDT(name)) { bnd = BXF3.Read(name.Substring(0, name.Length - 7) + ".tpfbhd", name); } else if (BND4.Is(name)) { bnd = BND4.Read(name); } else if (BND3.Is(name)) { bnd = BND3.Read(name); } foreach (var f in bnd.Files) { if (directEntryNameMatch ? textures.Contains(Utils.GetShortIngameFileName(f.Name).ToLower()) : TPF.Is(f.Bytes)) { var tpf = TPF.Read(f.Bytes); foreach (var tx in tpf.Textures) { var shortTexName = Utils.GetShortIngameFileName(tx.Name).ToLower(); if (textures.Contains(shortTexName)) { AddFetchTPF(tpf, tx.Name.ToLower()); textures.Remove(shortTexName); } } } } }
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); } }
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); } }