public static void ReloadParams() { BND4 paramBnd = SFUtil.DecryptDS3Regulation(DarkSoulsTools.GetOverridenPath(ParamPath)); DS3Param = PARAM64.Read(paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "ItemLotParam.param").Bytes); PARAM64.Layout layout = PARAM64.Layout.ReadXMLFile($@"{Application.dataPath.Replace('/', '\\')}\dstools\ParamLayouts\DS3\{DS3Param.ID}.xml"); DS3Param.SetLayout(layout); // Build and cache the item name list HashSet <int> usedItemIds = new HashSet <int>(); ItemNameList = new List <Tuple <int, string> >(); foreach (var row in DS3Param.Rows) { ItemLotParam param = new ItemLotParam(row); foreach (int id in param.ItemID) { if (!usedItemIds.Contains(id)) { usedItemIds.Add(id); ItemNameList.Add(new Tuple <int, string>(id, FMGUtils.LookupItemName(id))); } } } ItemNameList.Sort((a, b) => StringComparer.InvariantCulture.Compare(a.Item2, b.Item2)); }
public ParamWrapper(string name, PARAM64 param, PARAM64.Layout layout, string description) { Name = name; Param = param; Layout = layout; Param.SetLayout(layout); Description = description; }
public static Dictionary <string, PARAM64.Layout> LoadLayouts(string directory) { var layouts = new Dictionary <string, PARAM64.Layout>(); if (Directory.Exists(directory)) { foreach (string path in Directory.GetFiles(directory, "*.xml")) { string paramID = Path.GetFileNameWithoutExtension(path); try { PARAM64.Layout layout = PARAM64.Layout.ReadXMLFile(path); layouts[paramID] = layout; } catch (Exception ex) { ShowError($"Failed to load layout {paramID}.txt\r\n\r\n{ex}"); } } } return(layouts); }
public ParamFile(string name, PARAM64 param, Dictionary <string, PARAM64.Layout> layouts) { Name = name; Param = param; string format = Param.ID; if (!layouts.ContainsKey(format)) { layouts[format] = new PARAM64.Layout(); } try { Layout = layouts[format]; Param.SetLayout(Layout); Rows = Param.Rows; } catch (Exception ex) { Rows = new List <PARAM64.Row>(); ShowError($"Error in layout {format}, please try again.\r\n\r\n{ex}"); } }
private void Randomize(IProgress <string> progress) { progress.Report("Loading regulation..."); string regPath = Path.Combine(txtGameDir.Text, "Data0.bdt"); if (!File.Exists(regPath)) { progress.Report("Aborted."); ShowError($"Regulation file not found in game directory:\n{regPath}\nPlease make sure the path is correct."); return; } try { if (!File.Exists(regPath + ".bak")) { File.Copy(regPath, regPath + ".bak"); } } catch (Exception ex) { progress.Report("Aborted."); ShowError($"Failed to back up regulation file:\n{regPath}\n\n{ex}"); return; } BND4 regulation; var paramDict = new Dictionary <string, PARAM64>(); try { regulation = Util.DecryptDS3Regulation(regPath); foreach (BND4.File f in regulation.Files) { if (f.Name.EndsWith(".param")) { PARAM64 param = PARAM64.Read(f.Bytes); PARAM64.Layout layout = PARAM64.Layout.ReadXMLFile($"Layouts\\{param.ID}.xml"); param.SetLayout(layout); paramDict[Path.GetFileNameWithoutExtension(f.Name)] = param; } } } catch (Exception ex) { progress.Report("Aborted."); ShowError($"Failed to load regulation file:\n{regPath}\n\n{ex}"); return; } progress.Report("Randomizing..."); try { bool[] weaponOptions = { radDefault.Checked, radBalanced.Checked, radNoShields.Checked }; Irregulator irreg = new Irregulator(txtSeed.Text); irreg.Randomize(paramDict, cbxArmor.Checked, cbxWeapons.Checked, weaponOptions, cbxRings.Checked, cbxGoods.Checked, cbxSpells.Checked, cbxBullets.Checked, cbxBulletsPlus.Checked, cbxHumans.Checked, cbxOther.Checked, cbxTesting.Checked); } catch (Exception ex) { progress.Report("Aborted."); ShowError($"Failed to randomize regulation file:\n{regPath}\n\n{ex}"); return; } progress.Report("Saving regulation..."); try { foreach (BND4.File f in regulation.Files) { if (paramDict.ContainsKey(Path.GetFileNameWithoutExtension(f.Name))) { f.Bytes = paramDict[Path.GetFileNameWithoutExtension(f.Name)].Write(); } } Util.EncryptDS3Regulation(regPath, regulation); } catch (Exception ex) { progress.Report("Aborted."); ShowError($"Failed to save regulation file:\n{regPath}\n\n{ex}"); return; } progress.Report("Finished!"); SystemSounds.Asterisk.Play(); }
public static LoadParamsResult LoadParams(string paramPath, Dictionary <string, ParamInfo> paramInfo, Dictionary <string, PARAM64.Layout> layouts, 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 { result.ParamBND = SFUtil.DecryptDS3Regulation(paramPath); result.Encrypted = true; } } 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 { PARAM64 param = PARAM64.Read(file.Bytes); if (layouts.ContainsKey(param.ID)) { PARAM64.Layout layout = layouts[param.ID]; if (layout.Size == param.DetectedSize) { string description = null; if (paramInfo.ContainsKey(name)) { description = paramInfo[name].Description; } var wrapper = new ParamWrapper(name, param, layout, description); result.ParamWrappers.Add(wrapper); } else { } } } catch (Exception ex) { ShowError($"Failed to load param file: {name}.param\r\n\r\n{ex}"); } } result.ParamWrappers.Sort(); return(result); }
private void btnDump_Click(object sender, EventArgs e) { BND4 bnd; try { bnd = SFUtil.DecryptDS3Regulation(txtRegulation.Text); } catch (Exception ex) { MessageBox.Show($"Failed to load regulation:\r\n\r\n{txtRegulation.Text}\r\n\r\n{ex}"); return; } var translations = new Dictionary <string, string>(); var xml = new XmlDocument(); xml.Load("translations.xml"); foreach (XmlNode text in xml.SelectNodes("translations/text")) { string jp = text.SelectSingleNode("jp").InnerText; string en = text.SelectSingleNode("en").InnerText; translations[WebUtility.HtmlDecode(jp)] = WebUtility.HtmlDecode(en); } var package = new ExcelPackage(); foreach (BinderFile file in bnd.Files) { if (Path.GetExtension(file.Name) == ".param") { PARAM64 param = PARAM64.Read(file.Bytes); string layoutPath = $"Layouts\\{param.ID}.xml"; txtStatus.AppendText(file.Name + "\r\n"); var worksheet = package.Workbook.Worksheets.Add(Path.GetFileNameWithoutExtension(file.Name)); PARAM64.Layout layout; if (File.Exists(layoutPath)) { layout = PARAM64.Layout.ReadXMLFile(layoutPath); if (layout.Size != param.DetectedSize) { layout = new PARAM64.Layout(); for (int i = 0; i < param.DetectedSize / 4; i++) { layout.Add(new PARAM64.Layout.Entry(CellType.u32, $"unk0x{i * 4:X4}", (uint)0)); } for (int i = 0; i < param.DetectedSize % 4; i++) { layout.Add(new PARAM64.Layout.Entry(CellType.u8, "unkb" + i, (byte)0)); } } } else { layout = new PARAM64.Layout(); } param.SetLayout(layout); List <PARAM64.Row> rows = param.Rows; worksheet.Cells[1, 1].Value = "ID"; worksheet.Cells[1, 2].Value = "Name"; worksheet.Cells[1, 3].Value = "Translated"; int columnCount = 3; foreach (PARAM64.Layout.Entry lv in layout) { if (lv.Type != CellType.dummy8) { worksheet.Cells[1, ++columnCount].Value = lv.Name; } } for (int i = 0; i < rows.Count; i++) { PARAM64.Row row = rows[i]; worksheet.Cells[i + 2, 1].Value = row.ID; if (row.Name != null) { if (translations.ContainsKey(row.Name)) { worksheet.Cells[i + 2, 2].Value = row.Name; worksheet.Cells[i + 2, 3].Value = translations[row.Name]; } else if (row.Name.Contains(" -- ")) { worksheet.Cells[i + 2, 2].Value = row.Name.Substring(row.Name.IndexOf(" -- ") + 4); worksheet.Cells[i + 2, 3].Value = row.Name.Substring(0, row.Name.IndexOf(" -- ")); } } else { worksheet.Cells[i + 2, 2].Value = row.Name; } columnCount = 3; foreach (PARAM64.Cell cell in row.Cells) { CellType type = cell.Type; if (type != CellType.dummy8) { var range = worksheet.Cells[i + 2, ++columnCount]; if (type == CellType.f32) { range.Value = (double)(float)cell.Value; } else if (type == CellType.b8 || type == CellType.b32) { bool b = (bool)cell.Value; range.Value = b.ToString(); range.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; range.Style.Fill.BackgroundColor.SetColor(b ? Color.LightGreen : Color.LightPink); } else if (type == CellType.x8) { range.Value = $"0x{cell.Value:X2}"; range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; } else if (type == CellType.x16) { range.Value = $"0x{cell.Value:X4}"; range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; } else if (type == CellType.x32) { range.Value = $"0x{cell.Value:X8}"; range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; } else { range.Value = cell.Value; } } } } worksheet.Row(1).Style.Font.Bold = true; worksheet.Column(1).Style.Font.Bold = true; worksheet.View.FreezePanes(2, 4); worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns(); } } FileInfo f = new FileInfo(Path.Combine(txtOutput.Text, "dump.xlsx")); package.SaveAs(f); }