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); } } } } }
public static void AddMapTexBXF4(int area, IProgress <double> prog) { var dir = InterrootLoader.GetInterrootPath($"map\\m{area:D2}"); if (!Directory.Exists(dir)) { return; } var mapTpfFileNames = Directory.GetFiles(dir, "*.tpfbhd"); int fileIndex = 0; foreach (var t in mapTpfFileNames) { BXF4 bxf = null; lock (_lock_IO) { bxf = BXF4.Read(t, t.Substring(0, t.Length - 7) + ".tpfbdt"); } for (int i = 0; i < bxf.Files.Count; i++) { if (bxf.Files[i].Name.Contains(".tpf")) { var tpf = SoulsFormats.TPF.Read(bxf.Files[i].Bytes); foreach (var tn in tpf.Textures) { AddFetch(tpf, tn.Name); } tpf = null; } GFX.ModelDrawer.RequestTextureLoad(); // Report each subfile as a tiny part of the bar prog?.Report((1.0 * fileIndex / mapTpfFileNames.Length) + ((1.0 / mapTpfFileNames.Length) * ((i + 1.0) / bxf.Files.Count))); } bxf = null; fileIndex++; prog?.Report((1.0 * fileIndex / mapTpfFileNames.Length)); } GFX.ModelDrawer.RequestTextureLoad(); }
public static void AddMapTexBXF4DS2(string area, IProgress <double> prog) { var dir = InterrootLoader.GetInterrootPath($"model\\map\\"); if (!Directory.Exists(dir)) { return; } BXF4 bxf = null; lock (_lock_IO) { bxf = BXF4.Read(dir + "\\t" + area.Substring(1) + ".tpfbhd", dir + "\\t" + area.Substring(1) + ".tpfbdt"); } for (int i = 0; i < bxf.Files.Count; i++) { if (bxf.Files[i].Name.Contains(".tpf")) { var tpf = TPF.Read(bxf.Files[i].Bytes); foreach (var tn in tpf.Textures) { AddFetch(tpf, tn.Name); } tpf = null; } GFX.ModelDrawer.RequestTextureLoad(); // Report each subfile as a tiny part of the bar prog?.Report((i + 1.0) / bxf.Files.Count); } bxf = null; //fileIndex++; //prog?.Report((1.0 * fileIndex / mapTpfFileNames.Length)); GFX.ModelDrawer.RequestTextureLoad(); }
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); } }
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); }