private NewMesh LoadArmorMesh(IBinder partsbnd) { List <TPF> tpfs = new List <TPF>(); FLVER2 flver = null; foreach (var f in partsbnd.Files) { string nameCheck = f.Name.ToLower(); if (nameCheck.EndsWith(".tpf") || TPF.Is(f.Bytes)) { tpfs.Add(TPF.Read(f.Bytes)); } else if (flver == null && nameCheck.EndsWith(".flver") || FLVER2.Is(f.Bytes)) { flver = FLVER2.Read(f.Bytes); } } foreach (var tpf in tpfs) { TexturePool.AddTpf(tpf); } NewMesh mesh = null; if (flver != null) { mesh = new NewMesh(flver, false, boneIndexRemap); } Scene.RequestTextureLoad(); return(mesh); }
public (bool TextureExists, IntPtr TextureHandle) GetFfxTextureIntPtr(int textureId) { if (!_loadedTexturesDictionary.ContainsKey(textureId)) { var a = _ffxTexturesIEnumerable.Where(item => item.Name.Contains($"s{textureId.ToString("00000")}.tpf")); if (a.Any()) { var tpfBytes = a.First().Bytes; var tpfTexturesList = TPF.Read(tpfBytes).Textures; if (tpfTexturesList.Any()) { var ddsBytes = tpfTexturesList.First().Bytes; DdsImage ddsImage = new DdsImage(ddsBytes); Image <Rgba32> image = Image.LoadPixelData <Rgba32>(ddsImage.Data, ddsImage.Width, ddsImage.Height); var img = new ImageSharpTexture(image); var veldridTexture = img.CreateDeviceTexture(MainUserInterface.Gd, MainUserInterface.Gd.ResourceFactory); var textureHandle = MainUserInterface.Controller.GetOrCreateImGuiBinding(MainUserInterface.Gd.ResourceFactory, veldridTexture); veldridTexture.Dispose(); _loadedTexturesDictionary.Add(textureId, textureHandle); return(true, textureHandle); } } return(false, IntPtr.Zero); } else { return(true, _loadedTexturesDictionary[textureId]); } }
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 AddSpecificTexturesFromBXF3(string name, List <string> textures) { var bxf = BXF3.Read(name, name.Substring(0, name.Length - 7) + ".tpfbdt"); foreach (var f in bxf.Files) { if (f.Name != null && f.Name.ToLower().Contains(".tpf") && textures.Contains(Utils.GetShortIngameFileName(f.Name.ToLower()))) { AddTpf(TPF.Read(f.Bytes)); } } }
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; } } }
public List <string> GetEnvMapTextureNames(string mapid) { var l = new List <string>(); if (Type == GameType.DarkSoulsIII) { var mid = mapid.Substring(0, 3); var t = TPF.Read(GetAssetPath($@"map\{mid}\{mid}_envmap.tpf.dcx")); foreach (var tex in t.Textures) { l.Add(tex.Name); } } return(l); }
public static void CombineDragonTpfs() { // Utility for creating Divine Dragon texbnd. Requires using Yabber to unpack these bnds, and repack after done. string gamePath = GameSpec.ForGame(GameSpec.FromGame.SDT).GameDir; string mainPath = $@"{gamePath}\chr\c5200-texbnd-dcx\chr\c5200\c5200.tpf"; SFUtil.Backup(mainPath); TPF dragon = TPF.Read(mainPath); foreach (string p in Directory.GetFiles($@"{gamePath}\map\m25\m25_0000-tpfbhd", "m25_Dragon*.tpf.dcx")) { TPF t = TPF.Read(p); dragon.Textures.AddRange(t.Textures); } dragon.Write(mainPath); }
public static void AddTextureBnd(IBinder bnd, IProgress <double> prog) { var tpfs = bnd.Files.Where(file => file.Name != null && (file.Name.ToLower().EndsWith(".tpf") || file.Name.ToLower().EndsWith(".tpf.dcx"))).ToList(); var tbnds = bnd.Files.Where(file => file.Name != null && file.Name.ToLower().EndsWith(".tbnd")).ToList(); double total = tpfs.Count + tbnds.Count; double tpfFraction = 0; double tbndFraction = 0; if (total > 0) { tpfFraction = tpfs.Count / total; tbndFraction = tbnds.Count / total; } for (int i = 0; i < tpfs.Count; i++) { var file = tpfs[i]; if (file.Bytes.Length > 0) { TPF tpf = TPF.Read(file.Bytes); AddTpf(tpf); } prog?.Report(i / tpfFraction); } for (int i = 0; i < tbnds.Count; i++) { var file = tbnds[i]; if (file.Bytes.Length > 0) { IBinder tbnd = BND3.Read(file.Bytes); for (int j = 0; j < tbnd.Files.Count; j++) { TPF tpf = TPF.Read(tbnd.Files[j].Bytes); AddTpf(tpf); prog?.Report(tpfFraction + i / tbndFraction + j / tbnd.Files.Count * (tbndFraction / tbnds.Count)); } } prog?.Report(tpfFraction + i / tbndFraction); } prog?.Report(1); }
private void loadFiles(string gameDir, bool silent = false) { if (File.Exists($@"{gameDir}\DARKSOULS.exe")) { remastered = false; } else if (File.Exists($@"{gameDir}\DarkSoulsRemastered.exe")) { remastered = true; } else { ShowError($"Dark Souls executable not found in directory:\n{gameDir}", silent); return; } TPF menuTPF; string tpfPath = $"{gameDir}{TPF_PATH}{(remastered ? ".dcx" : "")}"; try { menuTPF = TPF.Read(tpfPath); } catch (Exception ex) { ShowError($"Failed to read TPF:\n{tpfPath}\n\n{ex}", silent); return; } DRB menuDRB; string drbPath = $"{gameDir}{DRB_PATH}{(remastered ? ".dcx" : "")}"; try { menuDRB = DRB.Read(drbPath, remastered); } catch (Exception ex) { ShowError($"Failed to read DRB:\n{drbPath}{ex}", silent); return; } fillDataGridView(menuTPF, menuDRB); enableControls(true); }
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 = 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 ImGuiFxrTextureHandler(BND4 ffxResourcesBin) { this._ffxTexturesIEnumerable = ffxResourcesBin.Files.Where(item => item.Name.Contains("sfx\\tex")); foreach (var binderFileTpf in _ffxTexturesIEnumerable) { var tpfBytes = binderFileTpf.Bytes; var tpfTexturesList = TPF.Read(tpfBytes).Textures; if (tpfTexturesList.Any()) { var tpf = tpfTexturesList.First(); if (int.TryParse(tpf.Name.TrimStart('s'), out int textureId)) { FfxTexturesIdList.Add(textureId); } } } FfxTexturesIdList.Sort(); LoadAllFfxTexturesInMemory(_ffxTexturesIEnumerable); }
/// <summary> /// Loads a loose virtual file /// </summary> /// <param name="virtualPath"></param> public void AddLoadFileTask(string virtualPath, AccessLevel al) { string bndout; var path = Locator.VirtualToRealPath(virtualPath, out bndout); IResourceHandle handle; if (path == null || virtualPath == "null") { return; } if (virtualPath.EndsWith(".hkx")) { handle = GetResource <HavokCollisionResource>(virtualPath); } else if (path.ToUpper().EndsWith(".TPF") || path.ToUpper().EndsWith(".TPF.DCX")) { string virt = virtualPath; if (virt.StartsWith($@"map/tex")) { var regex = new Regex(@"\d{4}$"); if (regex.IsMatch(virt)) { virt = virt.Substring(0, virt.Length - 5); } else if (virt.EndsWith("tex")) { virt = virt.Substring(0, virt.Length - 4); } } var ttask = new LoadTPFResourcesTask(virt, TPF.Read(path), al, Locator.Type); Tasks.Add(ttask); return; } else { handle = GetResource <FlverResource>(virtualPath); } var task = new LoadResourceFromFileTask(handle, path, al, Locator.Type); Tasks.Add(task); }
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); }
public static void AddInterrootTPFFolder(string folderPath, bool dcx = false, bool directDdsFetches = false) { var tpfs = GameDataManager.GetInterrootFiles(folderPath, dcx ? "*.tpf.dcx" : "*.tpf"); foreach (var t in tpfs) { string shortName = Utils.GetShortIngameFileName(t).ToLower(); if (directDdsFetches) { foreach (var tex in TPF.Read(t).Textures) { AddFetchDDS(tex.Bytes, tex.Name); } } else { AddFetchTPF(TPF.Read(File.ReadAllBytes(t)), shortName); } } }
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(); }
public void Run() { ProcessBinder(); if (!PopulateResourcesOnly) { foreach (var p in PendingResources) { var f = Binder.ReadFile(p.Item3); var task = new LoadResourceFromBytesTask(p.Item1, f, AccessLevel, ResourceManager.Locator.Type); task.Run(); } foreach (var t in PendingTPFs) { var f = TPF.Read(Binder.ReadFile(t.Item2)); var task = new LoadTPFResourcesTask(t.Item1, f, AccessLevel, ResourceManager.Locator.Type); task.Run(); } } PendingResources.Clear(); Binder = null; }
public void LoadAllFfxTexturesInMemory(IEnumerable <BinderFile> ffxTexturesIEnumerable) { foreach (var a in ffxTexturesIEnumerable) { var tpfBytes = a.Bytes; var tpfTexturesList = TPF.Read(tpfBytes).Textures; if (tpfTexturesList.Any()) { var tpf = tpfTexturesList.First(); if (int.TryParse(tpf.Name.TrimStart('s'), out int textureId) && !_loadedTexturesDictionary.ContainsKey(textureId)) { var ddsBytes = tpf.Bytes; DdsImage ddsImage = new DdsImage(ddsBytes); Image <Rgba32> image = Image.LoadPixelData <Rgba32>(ddsImage.Data, ddsImage.Width, ddsImage.Height); for (int y = 0; y < image.Height; y++) { for (int x = 0; x < image.Width; x++) { var rgba32 = image[x, y]; var r = rgba32.R; var g = rgba32.G; var b = rgba32.B; rgba32.R = b; rgba32.G = g; rgba32.B = r; image[x, y] = rgba32; //Set Inverted Pixels } } var img = new ImageSharpTexture(image); var veldridTexture = img.CreateDeviceTexture(MainUserInterface.Gd, MainUserInterface.Gd.ResourceFactory); var textureHandle = MainUserInterface.Controller.GetOrCreateImGuiBinding(MainUserInterface.Gd.ResourceFactory, veldridTexture); veldridTexture.Dispose(); _loadedTexturesDictionary.Add(textureId, textureHandle); } } } }
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++; } }
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 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 Task RunAsync(IProgress <int> progress) { return(BinderTaskFactory.StartNew(() => { ProcessBinder(); if (!PopulateResourcesOnly) { bool doasync = (PendingResources.Count() + PendingTPFs.Count()) > 1; int i = 0; foreach (var p in PendingResources) { var f = Binder.ReadFile(p.Item3); var task = new LoadResourceFromBytesTask(p.Item1, f, AccessLevel, ResourceManager.Locator.Type); var size = task.GetEstimateTaskSize(); TotalSize += size; if (doasync) { var progress1 = new Progress <int>(); TaskSizes.Add(size); lock (ProgressLock) { TaskProgress.Add(0); } int bindi = i; progress1.ProgressChanged += (x, e) => { lock (ProgressLock) { TaskProgress[bindi] = e; } UpdateProgress(progress); }; LoadingTasks.Add(task.RunAsync(progress1)); i++; } else { task.Run(); i++; progress.Report(i); } } foreach (var t in PendingTPFs) { var f = TPF.Read(Binder.ReadFile(t.Item2)); var task = new LoadTPFResourcesTask(t.Item1, f, AccessLevel, ResourceManager.Locator.Type); var size = task.GetEstimateTaskSize(); TotalSize += size; if (doasync) { var progress1 = new Progress <int>(); TaskSizes.Add(size); lock (ProgressLock) { TaskProgress.Add(0); } int bindi = i; progress1.ProgressChanged += (x, e) => { lock (ProgressLock) { TaskProgress[bindi] = e; } UpdateProgress(progress); }; LoadingTasks.Add(task.RunAsync(progress1)); i++; } else { task.Run(); i++; progress.Report(i); } } } PendingResources.Clear(); // Wait for all the tasks to complete while (LoadingTasks.Count() > 0) { int idx = Task.WaitAny(LoadingTasks.ToArray()); LoadingTasks.RemoveAt(idx); } Binder = null; })); }
public Model(IProgress <double> loadingProgress, string name, IBinder chrbnd, int modelIndex, IBinder anibnd, IBinder texbnd = null, List <string> additionalTpfNames = null, string possibleLooseTpfFolder = null, int baseDmyPolyID = 0, bool ignoreStaticTransforms = false, IBinder additionalTexbnd = null) : this() { Name = name; List <BinderFile> flverFileEntries = new List <BinderFile>(); List <TPF> tpfsUsed = new List <TPF>(); if (additionalTpfNames != null) { foreach (var t in additionalTpfNames) { if (File.Exists(t)) { tpfsUsed.Add(TPF.Read(t)); } } } FLVER2 flver = null; foreach (var f in chrbnd.Files) { var nameCheck = f.Name.ToLower(); if (flver == null && (nameCheck.EndsWith(".flver") || FLVER2.Is(f.Bytes))) { if (nameCheck.EndsWith($"_{modelIndex}.flver") || modelIndex == 0) { flver = FLVER2.Read(f.Bytes); } } else if (nameCheck.EndsWith(".tpf") || TPF.Is(f.Bytes)) { tpfsUsed.Add(TPF.Read(f.Bytes)); } else if (anibnd == null && nameCheck.EndsWith(".anibnd")) { if (nameCheck.EndsWith($"_{modelIndex}.anibnd") || modelIndex == 0) { if (BND3.Is(f.Bytes)) { anibnd = BND3.Read(f.Bytes); } else { anibnd = BND4.Read(f.Bytes); } } } } if (flver == null) { throw new ArgumentException("No FLVERs found within CHRBND."); } LoadFLVER2(flver, useSecondUV: false, baseDmyPolyID, ignoreStaticTransforms); loadingProgress.Report(1.0 / 4.0); AnimContainer = new NewAnimationContainer(this); if (anibnd != null) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_ANIBND", $"Loading ANIBND for {Name}...", innerProg => { AnimContainer.LoadBaseANIBND(anibnd, innerProg); }); } else { // This just messes up the model cuz they're already in // reference pose, whoops //Skeleton.ApplyBakedFlverReferencePose(); } loadingProgress.Report(2.0 / 3.0); if (tpfsUsed.Count > 0) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_TPFs", $"Loading TPFs for {Name}...", innerProg => { for (int i = 0; i < tpfsUsed.Count; i++) { TexturePool.AddTpf(tpfsUsed[i]); MainMesh.TextureReloadQueued = true; innerProg.Report(1.0 * i / tpfsUsed.Count); } MainMesh.TextureReloadQueued = true; }); } loadingProgress.Report(3.0 / 4.0); if (texbnd != null) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_TEXBND", $"Loading TEXBND for {Name}...", innerProg => { TexturePool.AddTextureBnd(texbnd, innerProg); MainMesh.TextureReloadQueued = true; }); } loadingProgress.Report(3.5 / 4.0); if (additionalTexbnd != null) { LoadingTaskMan.DoLoadingTaskSynchronous($"{Name}_AdditionalTEXBND", $"Loading extra TEXBND for {Name}...", innerProg => { TexturePool.AddTextureBnd(additionalTexbnd, innerProg); MainMesh.TextureReloadQueued = true; }); } loadingProgress.Report(3.9 / 4.0); if (possibleLooseTpfFolder != null && Directory.Exists(possibleLooseTpfFolder)) { TexturePool.AddTPFFolder(possibleLooseTpfFolder); MainMesh.TextureReloadQueued = true; } MainMesh.TextureReloadQueued = true; loadingProgress.Report(1.0); }
/// <summary> /// Attempts to load unloaded resources (with active references) via UDSFM textures /// </summary> public void AddLoadUDSFMTexturesTask() { foreach (var r in ResourceDatabase) { if (r.Value is TextureResourceHande t && t.AccessLevel == AccessLevel.AccessUnloaded && t.GetReferenceCounts() > 0) { var texpath = r.Key; string path = null; if (texpath.StartsWith("map/tex")) { path = $@"{Locator.GameRootDirectory}\map\tx\{Path.GetFileName(texpath)}.tpf"; } if (path != null && File.Exists(path)) { var task = new LoadTPFResourcesTask(Path.GetDirectoryName(r.Key).Replace('\\', '/'), TPF.Read(path), AccessLevel.AccessGPUOptimizedOnly, Locator.Type); Tasks.Add(task); } } } }