public static LoadParamsResult LoadParams(string paramPath, Dictionary <string, ParamInfo> paramInfo, Dictionary <string, PARAM.Layout> layouts, GameMode gameMode, bool hideUnusedParams) { if (!File.Exists(paramPath)) { ShowError($"Parambnd not found:\r\n{paramPath}\r\nPlease browse to the Data0.bdt or parambnd you would like to edit."); return(null); } var result = new LoadParamsResult(); try { if (BND4.Is(paramPath)) { result.ParamBND = BND4.Read(paramPath); result.Encrypted = false; } else if (BND3.Is(paramPath)) { result.ParamBND = BND3.Read(paramPath); result.Encrypted = false; } else if (gameMode.Game == GameMode.GameType.DarkSouls2) { result.ParamBND = DecryptDS2Regulation(paramPath); result.Encrypted = true; } else if (gameMode.Game == GameMode.GameType.DarkSouls3) { result.ParamBND = SFUtil.DecryptDS3Regulation(paramPath); result.Encrypted = true; } else { throw new FormatException("Unrecognized file format."); } } catch (DllNotFoundException ex) when(ex.Message.Contains("oo2core_6_win64.dll")) { ShowError("In order to load Sekiro params, you must copy oo2core_6_win64.dll from Sekiro into Yapped's lib folder."); return(null); } catch (Exception ex) { ShowError($"Failed to load parambnd:\r\n{paramPath}\r\n\r\n{ex}"); return(null); } result.ParamWrappers = new List <ParamWrapper>(); foreach (BinderFile file in result.ParamBND.Files.Where(f => f.Name.EndsWith(".param"))) { string name = Path.GetFileNameWithoutExtension(file.Name); if (paramInfo.ContainsKey(name)) { if (paramInfo[name].Blocked || paramInfo[name].Hidden && hideUnusedParams) { continue; } } try { PARAM param = PARAM.Read(file.Bytes); PARAM.Layout layout = null; if (layouts.ContainsKey(param.ID)) { layout = layouts[param.ID]; } string description = null; if (paramInfo.ContainsKey(name)) { description = paramInfo[name].Description; } var wrapper = new ParamWrapper(name, param, layout, description); result.ParamWrappers.Add(wrapper); } catch (Exception ex) { ShowError($"Failed to load param file: {name}.param\r\n\r\n{ex}"); } } result.ParamWrappers.Sort(); return(result); }
private void LoadFile(string path, bool silent = false) { statusStripMTDPath.Text = ""; if (!File.Exists(path)) { ShowError($"File not found:\r\n{path}", silent); return; } string filename = Path.GetFileName(path); string extension = SFUtil.GetRealExtension(filename); cmbMTD.Enabled = false; cmbMTD.Items.Clear(); mtdBnd = null; mtd = null; var mtdItems = new List <MTDWrapper>(); try { if (MTD.Is(path)) { mtdItems.Add(new MTDWrapper(MTD.Read(path), filename)); } else if (BND3.Is(path)) { mtdBnd = BND3.Read(path); foreach (BinderFile file in mtdBnd.Files) { if (MTD.Is(file.Bytes)) { mtdItems.Add(new MTDWrapper(MTD.Read(file.Bytes), file.Name)); } } } else if (BND4.Is(path)) { mtdBnd = BND4.Read(path); foreach (BinderFile file in mtdBnd.Files) { if (MTD.Is(file.Bytes)) { mtdItems.Add(new MTDWrapper(MTD.Read(file.Bytes), file.Name)); } } } else { ShowError($"Unrecognized file type:\r\n{path}", silent); return; } } catch (Exception ex) { ShowError($"Failed to load file:\r\n{path}\r\n{ex}", silent); return; } statusStripMTDPath.Text = path; mtdItems.Sort((i1, i2) => i1.Name.CompareTo(i2.Name)); cmbMTD.Items.AddRange(mtdItems.ToArray()); cmbMTD.SelectedIndex = 0; if (mtdItems.Count > 1) { cmbMTD.Enabled = true; } }
private static void LoadParamsDS2() { var dir = AssetLocator.GameRootDirectory; var mod = AssetLocator.GameModDirectory; if (!File.Exists($@"{dir}\enc_regulation.bnd.dcx")) { MessageBox.Show("Could not find DS2 regulation file. Functionality will be limited.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!BND4.Is($@"{dir}\enc_regulation.bnd.dcx")) { MessageBox.Show("Use yapped to decrypt your DS2 regulation file. Functionality will be limited.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Keep track of loaded params as we load loose and regulation params HashSet <string> loadedParams = new HashSet <string>(); // Load params List <string> scandir = new List <string>(); if (mod != null && Directory.Exists($@"{mod}\Param")) { scandir.Add($@"{mod}\Param"); } scandir.Add($@"{dir}\Param"); foreach (var d in scandir) { var paramfiles = Directory.GetFileSystemEntries(d, @"*.param"); foreach (var p in paramfiles) { bool blacklisted = false; var name = Path.GetFileNameWithoutExtension(p); foreach (var bl in _ds2ParamBlacklist) { if (name.StartsWith(bl)) { blacklisted = true; } } if (blacklisted) { continue; } var lp = PARAM.Read(p); var fname = lp.ParamType; PARAMDEF def = AssetLocator.GetParamdefForParam(fname); lp.ApplyParamdef(def); if (!_params.ContainsKey(name)) { _params.Add(name, lp); } } } // Load params var param = $@"{mod}\enc_regulation.bnd.dcx"; if (!File.Exists(param)) { param = $@"{dir}\enc_regulation.bnd.dcx"; } BND4 paramBnd = BND4.Read(param); EnemyParam = GetParam(paramBnd, "EnemyParam.param"); if (EnemyParam != null) { PARAMDEF def = AssetLocator.GetParamdefForParam(EnemyParam.ParamType); EnemyParam.ApplyParamdef(def); } LoadParamFromBinder(paramBnd); }
public static void DowngradeAnibnd(string anibndPath, IProgress <double> prog = null) { lock (_lock_DoingTask) { lock (_lock_messageBoxSpamPrevent) _messageBoxSpamCancel = false; IBinder anibnd = null; if (BND3.Is(anibndPath)) { anibnd = BND3.Read(anibndPath); } else if (BND4.Is(anibndPath)) { anibnd = BND4.Read(anibndPath); } else { throw new Exception("Invalid ANIBND"); } List <BinderFile> animations = new List <BinderFile>(); BinderFile skeleton = null; BinderFile compendium = null; foreach (var f in anibnd.Files) { var nameCheck = f.Name.ToUpper(); if (nameCheck.EndsWith(".COMPENDIUM")) { compendium = f; } else if (nameCheck.EndsWith("SKELETON.HKX")) { skeleton = f; } else if (nameCheck.EndsWith(".HKX")) { animations.Add(f); } } double progTotalFileCount = animations.Count + 1; if (skeleton != null) { progTotalFileCount++; } CreateTempIfNeeded(); bool converted_skeleton = false; bool[] converted_anim = new bool[animations.Count]; try { if (compendium != null) { SaveCompendiumToTemp(compendium.Bytes); } bool wasCanceled = false; List <Process> processQueue = new List <Process>(); List <Process> processDeleteQueue = new List <Process>(); if (skeleton != null) { var skellingtonProc = GetDowngradeHkxProcess(skeleton.Name, skeleton.Bytes, compendium != null, -1, (convertProc, result, i) => { lock (_lock_animFinished) { if (result == null) { wasCanceled = true; return; } else { skeleton.Bytes = result; converted_skeleton = true; } } }); lock (_lock_processQueue) { processQueue.Add(skellingtonProc); } skellingtonProc.Start(); } prog.Report(1 / progTotalFileCount); //for (int i = 0; i < animations.Count; i += PARALLEL_CONVERSIONS) //{ // //Process[] conversionProcs = new Process[PARALLEL_CONVERSIONS]; // for (int j = 0; j < PARALLEL_CONVERSIONS; j++) // { // if ((i + j) >= animations.Count) // break; // StartDowngradingHKX(animations[i + j].Bytes, compendium != null, i + j, result => // { // animations[i + j].Bytes = result; // converted_anim[i + j] = true; // }); // } // //for (int j = 0; j < PARALLEL_CONVERSIONS; j++) // //{ // // if (j >= animations.Count) // // break; // // prog.Report(((i + j) + 2) / progTotalFileCount); // // animations[i + j].Bytes = WaitForDowngradeHKXFinishAndRead(conversionProcs[j], i + j); // //} //} int numAnimsConverted = 0; int meme = animations.Count; for (int i = 0; i < meme; i++) { bool checkCancelled = false; lock (_lock_processQueue) checkCancelled = wasCanceled; if (checkCancelled) { return; } var nextProc = GetDowngradeHkxProcess(animations[i].Name, animations[i].Bytes, compendium != null, i, (convertProc, result, j) => { if (result == null) { lock (_lock_processQueue) { wasCanceled = true; foreach (var proc in processDeleteQueue) { if (!proc.HasExited) { proc.Kill(); } if (processQueue.Contains(proc)) { processQueue.Remove(proc); } proc.Dispose(); } processDeleteQueue.Clear(); foreach (var proc in processQueue) { if (!proc.HasExited) { proc.Kill(); } proc.Dispose(); } processQueue.Clear(); for (int k = 0; k < meme; k++) { animations[k].Bytes = null; converted_anim[k] = false; } numAnimsConverted = meme; } } else { animations[j].Bytes = result; converted_anim[j] = true; numAnimsConverted++; prog.Report(((numAnimsConverted) + 2) / progTotalFileCount); lock (_lock_processQueue) { processDeleteQueue.Add(convertProc); } } }); lock (_lock_processQueue) { processQueue.Add(nextProc); } nextProc.Start(); int processCount = PARALLEL_CONVERSIONS + 1; do { Thread.Sleep(100); lock (_lock_processQueue) { foreach (var proc in processDeleteQueue) { try { if (!proc.HasExited) { proc.Kill(); } } catch (InvalidOperationException) { } if (processQueue.Contains(proc)) { processQueue.Remove(proc); } proc.Dispose(); } processDeleteQueue.Clear(); foreach (var proc in processQueue) { try { if (proc.HasExited) { processDeleteQueue.Add(proc); } } catch (InvalidOperationException) { processDeleteQueue.Add(proc); } } processCount = processQueue.Count; } }while (processCount > PARALLEL_CONVERSIONS); } bool everythingFinished = false; do { everythingFinished = true; if (skeleton != null && !converted_skeleton) { everythingFinished = false; } if (numAnimsConverted < meme) { everythingFinished = false; } //for (int i = 0; i < converted_anim.Length; i++) //{ // if (!converted_anim[i]) // { // everythingFinished = false; // break; // } //} System.Threading.Thread.Sleep(20); }while (!(everythingFinished || wasCanceled)); if (File.Exists(anibndPath + ".2010")) { File.Delete(anibndPath + ".2010"); } if (anibnd is BND3 asBnd3) { asBnd3.Write(anibndPath + ".2010"); } else if (anibnd is BND4 asBnd4) { asBnd4.Write(anibndPath + ".2010"); } prog.Report(1); } finally { DeleteTempIfNeeded(); } } }
private static bool UnpackFile(string sourceFile, IProgress <float> progress) { 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}..."); using (var bnd = new BND3Reader(bytes)) { bnd.Compression = compression; bnd.Unpack(filename, targetDir, progress); } } else if (BND4.Is(bytes)) { Console.WriteLine($"Unpacking BND4: {filename}..."); using (var bnd = new BND4Reader(bytes)) { bnd.Compression = compression; bnd.Unpack(filename, targetDir, progress); } } else if (FFXDLSE.Is(bytes)) { Console.WriteLine($"Unpacking FFX: {filename}..."); var ffx = FFXDLSE.Read(bytes); ffx.Compression = compression; ffx.Unpack(sourceFile); } else if (sourceFile.EndsWith(".fmg.dcx")) { Console.WriteLine($"Unpacking FMG: {filename}..."); FMG fmg = FMG.Read(bytes); fmg.Compression = compression; fmg.Unpack(sourceFile); } else if (GPARAM.Is(bytes)) { Console.WriteLine($"Unpacking GPARAM: {filename}..."); GPARAM gparam = GPARAM.Read(bytes); gparam.Compression = compression; gparam.Unpack(sourceFile); } else if (TPF.Is(bytes)) { Console.WriteLine($"Unpacking TPF: {filename}..."); TPF tpf = TPF.Read(bytes); tpf.Compression = compression; tpf.Unpack(filename, targetDir, progress); } else { Console.WriteLine($"File format not recognized: {filename}"); return(true); } } else { if (BND3.Is(sourceFile)) { Console.WriteLine($"Unpacking BND3: {filename}..."); using (var bnd = new BND3Reader(sourceFile)) { bnd.Unpack(filename, targetDir, progress); } } else if (BND4.Is(sourceFile)) { Console.WriteLine($"Unpacking BND4: {filename}..."); using (var bnd = new BND4Reader(sourceFile)) { bnd.Unpack(filename, targetDir, progress); } } 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}..."); using (var bxf = new BXF3Reader(sourceFile, bdtPath)) { bxf.Unpack(filename, bdtFilename, targetDir, progress); } } 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}..."); using (var bxf = new BXF4Reader(sourceFile, bdtPath)) { bxf.Unpack(filename, bdtFilename, targetDir, progress); } } else { Console.WriteLine($"BDT not found for BHD: {filename}"); return(true); } } else if (FFXDLSE.Is(sourceFile)) { Console.WriteLine($"Unpacking FFX: {filename}..."); var ffx = FFXDLSE.Read(sourceFile); ffx.Unpack(sourceFile); } else if (sourceFile.EndsWith(".ffx.xml") || sourceFile.EndsWith(".ffx.dcx.xml")) { Console.WriteLine($"Repacking FFX: {filename}..."); YFFX.Repack(sourceFile); } else if (sourceFile.EndsWith(".fmg")) { Console.WriteLine($"Unpacking FMG: {filename}..."); FMG fmg = FMG.Read(sourceFile); fmg.Unpack(sourceFile); } else if (sourceFile.EndsWith(".fmg.xml") || sourceFile.EndsWith(".fmg.dcx.xml")) { Console.WriteLine($"Repacking FMG: {filename}..."); YFMG.Repack(sourceFile); } else if (GPARAM.Is(sourceFile)) { Console.WriteLine($"Unpacking GPARAM: {filename}..."); GPARAM gparam = GPARAM.Read(sourceFile); gparam.Unpack(sourceFile); } else if (sourceFile.EndsWith(".gparam.xml") || sourceFile.EndsWith(".gparam.dcx.xml") || sourceFile.EndsWith(".fltparam.xml") || sourceFile.EndsWith(".fltparam.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 if (TPF.Is(sourceFile)) { Console.WriteLine($"Unpacking TPF: {filename}..."); TPF tpf = TPF.Read(sourceFile); tpf.Unpack(filename, targetDir, progress); } else if (Zero3.Is(sourceFile)) { Console.WriteLine($"Unpacking 000: {filename}..."); Zero3 z3 = Zero3.Read(sourceFile); z3.Unpack(targetDir); } else { Console.WriteLine($"File format not recognized: {filename}"); return(true); } } return(false); }