private static void LoadParamFromBinder(IBinder parambnd) { // Load every param in the regulation // _params = new Dictionary<string, PARAM>(); foreach (var f in parambnd.Files) { if (!f.Name.ToUpper().EndsWith(".PARAM") || Path.GetFileNameWithoutExtension(f.Name).StartsWith("default_")) { continue; } if (f.Name.EndsWith("LoadBalancerParam.param")) { continue; } if (_params.ContainsKey(Path.GetFileNameWithoutExtension(f.Name))) { continue; } PARAM p = PARAM.Read(f.Bytes); if (!_paramdefs.ContainsKey(p.ParamType)) { continue; } p.ApplyParamdef(_paramdefs[p.ParamType]); _params.Add(Path.GetFileNameWithoutExtension(f.Name), p); } }
public static void LoadParams(SQLiteConnection con, string paramdefFilepath, IList <string> paramDirs) { // The metadata tables should be created ahead of time. CreateBndMetadataTables(con); CreateBndTableOfContentsTable(con); CreateParamMetadataTables(con); // Reading an original paramdefbnd var paramdefs = new Dictionary <string, PARAMDEF>(); var paramdefbnd = BND3.Read(paramdefFilepath); foreach (BinderFile file in paramdefbnd.Files) { var paramdef = PARAMDEF.Read(file.Bytes); paramdefs[paramdef.ParamType] = paramdef; } ReadParamdefsIntoDatabase(con, paramdefs.Values.ToList()); // Loading parambnd List <string> paramFilepaths = new List <string>(); foreach (var paramDir in paramDirs) { // DeS has both a gameparam.parambnd.dcx and a gameparamna.parambnd.dcx. // Only grab gameparamna.parambnd.dcx if we have it. string filterPattern = "*.parambnd.dcx"; if (Directory.GetFiles(paramDir, "*gameparamna.parambnd.dcx").Length > 0) { Console.WriteLine("Skipping gameparam.parambnd.dcx"); filterPattern = "*gameparamna.parambnd.dcx"; } paramFilepaths.AddRange(Directory.GetFiles(paramDir, filterPattern)); } foreach (var paramFilepath in paramFilepaths) { // Have to construct Table of Contents as we go through, since the info isn't all at BND level, but is needed when reconstructing var bndContents = new List <BndContentsEntry>(); Console.WriteLine("Loading file: " + paramFilepath); var parambnd = BND3.Read(paramFilepath); foreach (BinderFile file in parambnd.Files) { PARAM param = PARAM.Read(file.Bytes); // DSR doesn't seem to like applying carefully, specifically SP_EFFECT_PARAM_ST in Gameparam. At minimum. param.ApplyParamdef(paramdefs[param.ParamType]); var entry = new BndContentsEntry(paramFilepath, file.ID, file.Name, file.Flags, file.CompressionType, param.ParamType); bndContents.Add(entry); ReadParamIntoDatabase(con, Path.GetFileNameWithoutExtension(file.Name), param); } // Create the metadata tables ReadBndMetadataIntoDatabase(con, paramFilepath, parambnd); ReadBndTableOfContentsIntoDatabase(con, Path.GetFileName(paramFilepath), bndContents); } }
public GameParamHandler(Dictionary <string, PARAMDEF> paramdefs, TextHandler text, byte[] paramBNDData) { ParamDefs = paramdefs; ParamBnd = BND3.Read(paramBNDData); foreach (BinderFile file in ParamBnd.Files) { string name = Path.GetFileNameWithoutExtension(file.Name); PARAM param = PARAM.Read(file.Bytes); PARAMDEF p = ParamDefs[param.ParamType]; param.ApplyParamdef(p); Params[name] = param; } AI = new ParamDict <NPCThought>("NpcThinkParam", this, text); Armor = new ParamDict <Armor>("EquipParamProtector", this, text); ArmorUpgrades = new ParamDict <ArmorUpgrade>("ReinforceParamProtector", this, text); AttacksPC = new ParamDict <Attack>("AtkParam_Pc", this, text); AttacksNPC = new ParamDict <Attack>("AtkParam_Npc", this, text); BehaviorsPC = new ParamDict <Behavior>("BehaviorParam_PC", this, text); BehaviorsNPC = new ParamDict <Behavior>("BehaviorParam", this, text); Bullets = new ParamDict <Bullet>("Bullet", this, text); CalcCorrects = new ParamDict <CalcCorrect>("CalcCorrectGraph", this, text); ChrInits = new ParamDict <ChrInit>("CharaInitParam", this, text); CoolTimes = new ParamDict <CoolTime>("CoolTimeParam", this, text); UpgradeMaterials = new ParamDict <EquipMtrlSet>("EquipMtrlSetParam", this, text); FaceGens = new ParamDict <FaceGen>("FaceGenParam", this, text); GameAreas = new ParamDict <GameArea>("GameAreaParam", this, text); Goods = new ParamDict <Good>("EquipParamGoods", this, text); HitMtrls = new ParamDict <HitMtrl>("HitMtrlParam", this, text); ItemLots = new ParamDict <ItemLot>("ItemLotParam", this, text); Knockbacks = new ParamDict <Knockback>("KnockBackParam", this, text); LockCams = new ParamDict <LockCam>("LockCamParam", this, text); Magic = new ParamDict <Magic>("Magic", this, text); Movement = new ParamDict <Move>("MoveParam", this, text); MenuColorTables = new ParamDict <MenuColorTable>("MenuColorTableParam", this, text); NPCs = new ParamDict <NPC>("NpcParam", this, text); ObjActs = new ParamDict <ObjAct>("ObjActParam", this, text); Objects = new ParamDict <GameObject>("ObjectParam", this, text); Rings = new ParamDict <Accessory>("EquipParamAccessory", this, text); ShopLineups = new ParamDict <ShopLineup>("ShopLineupParam", this, text); Skeletons = new ParamDict <Skeleton>("SkeletonParam", this, text); SpEffects = new ParamDict <SpEffect>("SpEffectParam", this, text); SpEffectVFXs = new ParamDict <SpEffectVFX>("SpEffectVfxParam", this, text); Talks = new ParamDict <Talk>("TalkParam", this, text); Throws = new ParamDict <Throw>("ThrowParam", this, text); Weapons = new ParamDict <Weapon>("EquipParamWeapon", this, text); WeaponUpgrades = new ParamDict <WeaponUpgrade>("ReinforceParamWeapon", this, text); WhiteCoolTimes = new ParamDict <WhiteCoolTime>("WhiteCoolTimeParam", this, text); }
public ParamWrapper(string name, PARAM param, PARAM.Layout layout, string description) { if (layout == null || layout.Size != param.DetectedSize) { layout = new PARAM.Layout { new PARAM.Layout.Entry(PARAM.CellType.dummy8, "Unknown", (int)param.DetectedSize, null) }; Error = true; } Name = name; Param = param; Layout = layout; Paramdef = Layout.ToParamdef(name, out Paramtdfs); Param.ApplyParamdef(Paramdef); Description = description; }
public PARAM Read(string name, PARAMDEF def) { var worksheet = Spreadsheet.Workbook.Worksheets.First(sheet => sheet.Name.Equals(name)); var rowCount = worksheet.Dimension.Rows; var param = new PARAM(); param.ParamType = def.ParamType; param.Rows = new List <PARAM.Row>(rowCount - 2); param.ApplyParamdef(def); for (var rowIndex = 3; rowIndex <= rowCount; rowIndex++) { var id = int.Parse(worksheet.Cells[rowIndex, 1].Value.ToString()); var rowName = worksheet.Cells[rowIndex, 2].Value ?? string.Empty; var row = new PARAM.Row(id, (string?)rowName, def); for (var cellIndex = 0; cellIndex < def.Fields.Count; cellIndex++) { var value = worksheet.Cells[rowIndex, 3 + cellIndex].Value; if (value is string v && v == "-") { // padding, we don't store this in excel files continue; } if (value is null) { Console.WriteLine($"Row ID {id} and field ${def.Fields[cellIndex].DisplayName} has null value, assuming default"); continue; } row.Cells[cellIndex].Value = value; } param.Rows.Add(row); } return(param); }
public ParamFile(string name, PARAM param, Dictionary <string, PARAM.Layout> layouts) { Name = name; Param = param; string format = Param.ParamType; if (!layouts.ContainsKey(format)) { layouts[format] = new PARAM.Layout(); } try { Layout = layouts[format]; Param.ApplyParamdef(Layout.ToParamdef(param.ParamType, out _)); Rows = Param.Rows; } catch (Exception ex) { Rows = new List <PARAM.Row>(); ShowError($"Error in layout {format}, please try again.\r\n\r\n{ex}"); } }
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 WriteParams(SQLiteConnection con, string outputPath, bool overwriteOutputFiles) { // Writing a parambnd // Need to construct our BND3 files based on what's in our DB. // This is a kludge to create a mapping (filename -> (source_path, BND)). var bnds = new Dictionary <string, KeyValuePair <string, BND3> >(); // First thing to do is get our basic BND file setup. using (var cmd = new SQLiteCommand(@"SELECT * FROM 'bnd_metadata'", con)) { var reader = cmd.ExecuteReader(); while (reader.Read()) { var bnd = new BND3 { BigEndian = reader.GetBoolean(reader.GetOrdinal(@"big_endian")), BitBigEndian = reader.GetBoolean(reader.GetOrdinal(@"bit_big_endian")), Compression = (DCX.Type)Enum.Parse(typeof(DCX.Type), reader.GetString(reader.GetOrdinal(@"compression"))), Format = (Binder.Format)reader.GetInt64(reader.GetOrdinal(@"format")), Unk18 = reader.GetInt32(reader.GetOrdinal(@"unk18")), Version = reader.GetString(reader.GetOrdinal(@"version")), Files = new List <BinderFile>() }; var filename = reader.GetString(reader.GetOrdinal(@"filename")); bnds.Add(Path.GetFileName(filename), new KeyValuePair <string, BND3>(filename, bnd)); } } // Get our list of files. We'll grab the contents afterwards. // Note that it's a List because there can be multiple files associated with a given ParamType. var files = new Dictionary <string, KeyValuePair <string, List <BinderFile> > >(); using (var cmd = new SQLiteCommand(@"SELECT * FROM 'bnd_contents'", con)) { var reader = cmd.ExecuteReader(); while (reader.Read()) { var source_file = reader.GetString(reader.GetOrdinal(@"source_file")); var file = new BinderFile { ID = reader.GetInt32(reader.GetOrdinal(@"file_id")), Name = reader.GetString(reader.GetOrdinal(@"name")), Flags = (Binder.FileFlags)reader.GetInt64(reader.GetOrdinal(@"flags")), CompressionType = (DCX.Type)System.Enum.Parse(typeof(DCX.Type), reader.GetString(reader.GetOrdinal(@"compression_type"))) }; var paramType = reader.GetString(reader.GetOrdinal("param_type")); // Add the file to both our list of files in the appropriate BND and also to our dictionary // so that we can continue building it out. bnds[source_file].Value.Files.Add(file); if (files.ContainsKey(Path.GetFileNameWithoutExtension(file.Name))) { var dictValue = files.TryGetValue(Path.GetFileNameWithoutExtension(file.Name), out KeyValuePair <string, List <BinderFile> > value) ? value : new KeyValuePair <string, List <BinderFile> >(paramType, new List <BinderFile>()); dictValue.Value.Add(file); } else { var dictValue = new KeyValuePair <string, List <BinderFile> >(paramType, new List <BinderFile>() { file }); files.Add(Path.GetFileNameWithoutExtension(file.Name), dictValue); } } } // Get all of our PARAMDEFs Dictionary <string, PARAMDEF> paramTypeToParamDef = new Dictionary <string, PARAMDEF>(); using (var cmd = new SQLiteCommand(@"SELECT * FROM 'paramdef_metadata';", con)) using (var fieldsCmd = new SQLiteCommand(@"SELECT * FROM 'paramdef_fields' WHERE param_type=$param_type;", con)) { var reader = cmd.ExecuteReader(); while (reader.Read()) { PARAMDEF paramdef = new PARAMDEF { BigEndian = reader.GetBoolean(reader.GetOrdinal(@"big_endian")), Compression = (DCX.Type)Enum.Parse(typeof(DCX.Type), reader.GetString(reader.GetOrdinal(@"compression"))), ParamType = reader.GetString(reader.GetOrdinal(@"param_type")), Unicode = reader.GetBoolean(reader.GetOrdinal(@"unicode")), DataVersion = reader.GetInt16(reader.GetOrdinal(@"data_version")), FormatVersion = reader.GetInt16(reader.GetOrdinal(@"format_version")) }; paramTypeToParamDef.Add(paramdef.ParamType, paramdef); } } using (var cmd = new SQLiteCommand(@"SELECT * FROM 'paramdef_fields' WHERE param_type=$param_type;", con)) { foreach (KeyValuePair <string, PARAMDEF> keyValue in paramTypeToParamDef) { // Get all the fields for our paramdef AddParamToCommand(cmd, @"$param_type", keyValue.Key); var fieldReader = cmd.ExecuteReader(); var fields = new List <Field>(); while (fieldReader.Read()) { var descOrdinal = fieldReader.GetOrdinal(@"description"); var field = new Field { ArrayLength = fieldReader.GetInt32(fieldReader.GetOrdinal(@"array_length")), BitSize = fieldReader.GetInt32(fieldReader.GetOrdinal(@"bit_size")), Default = fieldReader.GetFloat(fieldReader.GetOrdinal(@"default")), // Description can be NULL. Need to check. Sigh. Description = fieldReader.IsDBNull(descOrdinal) ? null : fieldReader.GetFieldValue <string>(descOrdinal), DisplayFormat = fieldReader.GetString(fieldReader.GetOrdinal(@"display_format")), DisplayName = fieldReader.GetString(fieldReader.GetOrdinal(@"display_name")), DisplayType = (DefType)System.Enum.Parse(typeof(DefType), fieldReader.GetString(fieldReader.GetOrdinal(@"display_type"))), EditFlags = (EditFlags)fieldReader.GetInt64(fieldReader.GetOrdinal(@"edit_flags")), Increment = fieldReader.GetFloat(fieldReader.GetOrdinal(@"increment")), InternalName = fieldReader.GetString(fieldReader.GetOrdinal(@"internal_name")), InternalType = fieldReader.GetString(fieldReader.GetOrdinal(@"internal_type")), Maximum = fieldReader.GetFloat(fieldReader.GetOrdinal(@"maximum")), Minimum = fieldReader.GetFloat(fieldReader.GetOrdinal(@"minimum")), SortID = fieldReader.GetInt32(fieldReader.GetOrdinal(@"sort_id")) }; fields.Add(field); } keyValue.Value.Fields = fields; var exc = new Exception(); if (!keyValue.Value.Validate(out exc)) { throw exc; } fieldReader.Close(); } } // Now we need to grab our contents for each file. foreach (KeyValuePair <string, KeyValuePair <string, List <BinderFile> > > entry in files) { // Want to iterate through each file. Keep in mind multiple tables can have same ParamType, so we can't loop via ParamType. // e.g. DeS AtkParam_Npc and AtkParam_Pc foreach (BinderFile file in entry.Value.Value) { //var tableName = Path.GetFileNameWithoutExtension(file.Name); var tableName = entry.Key; Console.WriteLine("Reading from: " + tableName); using (var cmd = new SQLiteCommand(@"SELECT * FROM '" + tableName + "';", con)) using (var metadataCmd = new SQLiteCommand(@"SELECT * FROM param_metadata WHERE param_type = $param_type", con)) { var paramDef = paramTypeToParamDef[entry.Value.Key]; var paramFile = new PARAM(); paramFile.ParamType = entry.Value.Key; AddParamToCommand(metadataCmd, @"$param_type", entry.Value.Key); var metadataReader = metadataCmd.ExecuteReader(); while (metadataReader.Read()) { paramFile.BigEndian = metadataReader.GetBoolean(metadataReader.GetOrdinal(@"big_endian")); paramFile.Compression = (DCX.Type)Enum.Parse(typeof(DCX.Type), metadataReader.GetString(metadataReader.GetOrdinal(@"compression"))); paramFile.Format2D = (PARAM.FormatFlags1)Enum.Parse(typeof(PARAM.FormatFlags1), metadataReader.GetString(metadataReader.GetOrdinal(@"format2d"))); paramFile.Format2E = (PARAM.FormatFlags2)Enum.Parse(typeof(PARAM.FormatFlags2), metadataReader.GetString(metadataReader.GetOrdinal(@"format2e"))); byte[] buf = new byte[1]; metadataReader.GetBytes(metadataReader.GetOrdinal("paramdef_format_version"), 0, buf, 0, 1); paramFile.ParamdefFormatVersion = buf[0]; paramFile.Unk06 = metadataReader.GetInt16(metadataReader.GetOrdinal(@"unk06")); paramFile.ParamdefDataVersion = metadataReader.GetInt16(metadataReader.GetOrdinal(@"paramdef_data_version")); } var reader = cmd.ExecuteReader(); paramFile.Rows = new List <PARAM.Row>(); while (reader.Read()) { var id = reader.GetInt32(reader.GetOrdinal(@"id")); // Description can be NULL var descOrdinal = reader.GetOrdinal(@"description"); var description = reader.IsDBNull(descOrdinal) ? null : reader.GetFieldValue <string>(descOrdinal); var row = new PARAM.Row(id, description, paramDef); foreach (Field field in paramDef.Fields) { var name = field.InternalName; // Not using InternalType. I don't know the complete set of raw strings across all games. // It would be better to use not be tied to a display field. For some value of "better". var type = field.DisplayType; switch (type) { // Padding case case DefType.dummy8: int length = field.ArrayLength; if (field.BitSize == -1) { row[name].Value = Enumerable.Repeat((byte)0, length).ToArray(); } else { row[name].Value = 0; } break; // All the integer cases case DefType.s8: case DefType.s16: case DefType.s32: case DefType.u8: case DefType.u16: case DefType.u32: row[name].Value = reader.GetInt32(reader.GetOrdinal(name)); break; // Float cases case DefType.f32: row[name].Value = reader.GetFloat(reader.GetOrdinal(name)); break; // String case case DefType.fixstr: case DefType.fixstrW: row[name].Value = reader.GetString(reader.GetOrdinal(name)); break; } } paramFile.Rows.Add(row); } // Don't apply carefully. We don't have the ability to set the DetectedSize. It only occurs on Read paramFile.ApplyParamdef(paramDef); var exc = new Exception(); if (!paramFile.Validate(out exc)) { Console.WriteLine("Failed with exception: " + exc); } file.Bytes = paramFile.Write(); } } } foreach (KeyValuePair <string, KeyValuePair <string, BND3> > entry in bnds) { // Default to writing the original file. // If output path is defined, put everything there. var outputFile = entry.Value.Key; if (outputPath != null) { outputFile = outputPath + Path.DirectorySeparatorChar + entry.Key; Console.WriteLine("Output current parambnd.dcx: " + outputFile); } if (!File.Exists(outputFile) || overwriteOutputFiles) { entry.Value.Value.Write(outputFile); } else { // Backup the eisting file before writing. // Just append the unix time and ".bak" to avoid managing whole sets of backup nonsense. var unixTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); string backupFile = outputFile + "." + unixTime + ".bak"; Console.WriteLine("Collision found. Not overwriting. Moving original file to backup at: " + backupFile); File.Move(outputFile, backupFile); entry.Value.Value.Write(outputFile); } } }
static void translateParams(string a, string b) { string paramDir = a.EndsWith("\\") ? a.Substring(a.Length - 1, 1) : a; string paramDefDir = b.EndsWith("\\") ? b.Substring(b.Length - 1, 1) : b; string[] paramFileList = Directory.GetFiles(paramDir); string[] paramDefFileList = Directory.GetFiles(paramDefDir); List <string> paramFileNameList = new List <string>(); List <PARAMDEF> paramDefs = new List <PARAMDEF>(); List <PARAM> paramaroos = new List <PARAM>(); Console.WriteLine("### " + paramDir); Console.WriteLine("### " + paramDefDir + "\n"); for (int i = 0; i < paramFileList.Length; i++) { string fn = paramFileList[i].Substring(paramDir.Length + 1, paramFileList[i].Length - (paramDir.Length + 1)); paramFileNameList.Add(fn); paramaroos.Add(PARAM.Read(File.ReadAllBytes(paramFileList[i]))); } for (int i = 0; i < paramDefFileList.Length; i++) { paramDefs.Add(PARAMDEF.Read(File.ReadAllBytes(paramDefFileList[i]))); } for (int i = 0; i < paramaroos.Count; i++) { PARAM p = paramaroos[i]; for (int j = 0; j < paramDefs.Count; j++) { PARAMDEF pd = paramDefs[j]; if (p.ParamType.Equals(pd.ParamType)) { p.ApplyParamdef(pd); } } } TranslationClient client = TranslationClient.Create(GoogleCredential.FromFile("C:\\Users\\dmtin\\google-translate-api-key.txt")); for (int i = 0; i < paramaroos.Count; i++) { Console.WriteLine("\n\n\n\n==================" + paramaroos[i].ParamType + "=================="); for (int j = 0; j < paramaroos[i].Rows.Count; j++) { PARAM.Row row = paramaroos[i].Rows[j]; try { if (row.Name != null && !row.Name.Trim().Equals("") && !row.Name.Trim().Equals("0")) { TranslationResult response = client.TranslateText(row.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0) { row.Name = response.TranslatedText; } } } catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); } Console.WriteLine(row.ID + ":: " + row.Name); } } Directory.CreateDirectory(paramDir + "\\translated\\"); for (int i = 0; i < paramaroos.Count; i++) { string outPath = paramDir + "\\translated\\" + paramFileNameList[i]; byte[] outData = paramaroos[i].Write(); File.WriteAllBytes(outPath, outData); } Console.WriteLine("\n\n Done!"); }
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") { PARAM param = PARAM.Read(file.Bytes); string layoutPath = $"Layouts\\{param.ParamType}.xml"; txtStatus.AppendText(file.Name + "\r\n"); var worksheet = package.Workbook.Worksheets.Add(Path.GetFileNameWithoutExtension(file.Name)); PARAM.Layout layout; if (File.Exists(layoutPath)) { layout = PARAM.Layout.ReadXMLFile(layoutPath); if (layout.Size != param.DetectedSize) { layout = new PARAM.Layout(); for (int i = 0; i < param.DetectedSize / 4; i++) { layout.Add(new PARAM.Layout.Entry(CellType.u32, $"unk0x{i * 4:X4}", (uint)0)); } for (int i = 0; i < param.DetectedSize % 4; i++) { layout.Add(new PARAM.Layout.Entry(CellType.u8, "unkb" + i, (byte)0)); } } } else { layout = new PARAM.Layout(); } param.ApplyParamdef(layout.ToParamdef(param.ParamType, out _)); List <PARAM.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 (PARAM.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++) { PARAM.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 (PARAM.Cell cell in row.Cells) { var type = cell.Def.DisplayType; if (type != DefType.dummy8) { var range = worksheet.Cells[i + 2, ++columnCount]; if (type == DefType.f32) { range.Value = (double)(float)cell.Value; } else if (type == DefType.u8 || type == DefType.u16 || type == DefType.u32) { 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 == DefType.u8) { range.Value = $"0x{cell.Value:X2}"; range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; } else if (type == DefType.u16) { range.Value = $"0x{cell.Value:X4}"; range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right; } else if (type == DefType.u32) { 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); }