示例#1
0
    public static void ReloadParams()
    {
        if (!File.Exists(ParamPath))
        {
            Debug.Log("DS2 enc_regulation.bnd.dcx not found");
            return;
        }
        if (!BND4.Is(DarkSoulsTools.GetOverridenPath(ParamPath)))
        {
            Debug.Log("Decrypt your regulation by saving in Yapped");
            return;
        }
        BND4 paramBnd = BND4.Read(DarkSoulsTools.GetOverridenPath(ParamPath));

        EnemyParam = PARAM.Read(paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "EnemyParam.param").Bytes);
        PARAM.Layout layout = PARAM.Layout.ReadXMLFile($@"{Application.dataPath.Replace('/', '\\')}\dstools\ParamLayouts\DS2SOTFS\{EnemyParam.ID}.xml");
        EnemyParam.SetLayout(layout);

        // Build and cache the enemy param dictionary
        ParamDictionary = new Dictionary <long, PARAM.Row>();
        foreach (var row in EnemyParam.Rows)
        {
            ParamDictionary.Add(row.ID, row);
        }
    }
示例#2
0
    public static void ReloadParams()
    {
        if (!File.Exists(ParamPath))
        {
            Debug.Log("Data0.bdt not found. This will make treasure editor have less functionality.");
            return;
        }
        BND4 paramBnd = SFUtil.DecryptDS3Regulation(DarkSoulsTools.GetOverridenPath(ParamPath));

        DS3Param = PARAM.Read(paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "ItemLotParam.param").Bytes);
        PARAM.Layout layout = PARAM.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));
    }
示例#3
0
        public ParamWrapper(string name, PARAM param, PARAM.Layout layout, string description)
        {
            if (layout.Size != param.DetectedSize)
            {
                layout = new PARAM.Layout();
                layout.Add(new PARAM.Layout.Entry(PARAM.CellType.dummy8, "Unknown", (int)param.DetectedSize, null));
                Error = true;
            }

            Name   = name;
            Param  = param;
            Layout = layout;
            Param.SetLayout(layout);
            Description = description;
        }
示例#4
0
        // Loads layouts from layout dir, relative to the current dir
        public Dictionary <string, PARAM.Layout> LoadLayouts()
        {
            if (Spec.LayoutDir == null)
            {
                throw new Exception("Layout dir not provided");
            }
            Dictionary <string, PARAM.Layout> layouts = new Dictionary <string, PARAM.Layout>();

            foreach (string path in Directory.GetFiles(Spec.LayoutDir, "*.xml"))
            {
                string       paramID = Path.GetFileNameWithoutExtension(path);
                PARAM.Layout layout  = PARAM.Layout.ReadXMLFile(path);
                layouts[paramID] = layout;
            }
            return(layouts);
        }
示例#5
0
 // https://github.com/JKAnderson/Yapped/blob/master/Yapped/FormMain.cs
 private void LoadLayouts()
 {
     foreach (string path in Directory.GetFiles($@"{dir}\Layouts", "*.xml"))
     {
         string paramID = Path.GetFileNameWithoutExtension(path);
         try
         {
             PARAM.Layout layout = PARAM.Layout.ReadXMLFile(path);
             layouts[paramID] = layout;
         }
         catch (Exception ex)
         {
             throw new Exception($"Failed to load layout {paramID}.txt\r\n\r\n{ex}");
         }
     }
 }
        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;
        }
示例#7
0
 // Load params from given path, relative to current dir
 public Dictionary <string, PARAM> LoadParams(string path, Dictionary <string, PARAM.Layout> layouts = null, bool allowError = false)
 {
     layouts = layouts ?? LoadLayouts();
     return(LoadBnd(path, (data, paramPath) =>
     {
         PARAM param;
         try
         {
             param = PARAM.Read(data);
         }
         catch (Exception e)
         {
             if (!allowError)
             {
                 throw new Exception($"Failed to load param {paramPath}: " + e);
             }
             // For DS3 this also includes draw params, so just silently fail
             // TODO: Find a better way to load all params reliably
             return null;
         }
         if (layouts == null)
         {
             return param;
         }
         else if (layouts.ContainsKey(param.ParamType))
         {
             PARAM.Layout layout = layouts[param.ParamType];
             if (layout.Size == param.DetectedSize)
             {
                 param.ApplyParamdef(layout.ToParamdef(param.ParamType, out var _));
                 return param;
             }
             else
             {
                 // Console.WriteLine($"Mismatched size for {path} - {layout.Size} vs {param.DetectedSize} actual");
             }
         }
         return null;
     }));
 }
示例#8
0
文件: Util.cs 项目: rwgky/Yapped
        public static Dictionary <string, PARAM.Layout> LoadLayouts(string directory)
        {
            var layouts = new Dictionary <string, PARAM.Layout>();

            if (Directory.Exists(directory))
            {
                foreach (string path in Directory.GetFiles(directory, "*.xml"))
                {
                    string paramID = Path.GetFileNameWithoutExtension(path);
                    try
                    {
                        PARAM.Layout layout = PARAM.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, 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}");
                }
            }
示例#10
0
        public static LoadParamsResult LoadParams(string paramPath, Dictionary <string, ParamInfo> paramInfo,
                                                  Dictionary <string, PARAM.Layout> layouts, Dictionary <BinderFile, ParamWrapper> fileWrapperCache, GameMode gameMode, bool hideUnusedParams)
        {
            if (!File.Exists(paramPath))
            {
                ShowError($"Parambnd类型文件 {paramPath} 不存在!\r\n请选定要给要编辑的Data0.bdt文件或Parambnd类型文件。");
                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("无法识别文件的数据格式!");
                }
            }
            catch (DllNotFoundException ex) when(ex.Message.Contains("oo2core_6_win64.dll"))
            {
                ShowError("为了加载Sekiro参数,必须将文件oo2core_6_win64.dll从Sekiro复制到文件DSParamEditor.exe的同一目录中。");
                return(null);
            }
            catch (Exception ex)
            {
                ShowError($"加载Parambnd类型文件失败!\r\n{paramPath}\r\n\r\n{ex}");
                return(null);
            }

            fileWrapperCache.Clear();
            result.ParamWrappers = new List <ParamWrapper>();
            foreach (var file in result.ParamBND.Files.Where(f => f.Name.EndsWith(".param")))
            {
                var name = Path.GetFileNameWithoutExtension(file.Name);
                if (paramInfo.ContainsKey(name))
                {
                    if (paramInfo[name].Blocked || paramInfo[name].Hidden && hideUnusedParams)
                    {
                        continue;
                    }
                }

                try
                {
                    var          param  = PARAM.Read(file.Bytes);
                    PARAM.Layout layout = null;
                    if (layouts.ContainsKey(param.ParamType))
                    {
                        layout = layouts[param.ParamType];
                    }

                    string description = null;
                    if (paramInfo.ContainsKey(name))
                    {
                        description = paramInfo[name].Description;
                    }

                    var wrapper = new ParamWrapper(name, param, layout, description);
                    result.ParamWrappers.Add(wrapper);
                    fileWrapperCache[file] = wrapper;
                }
                catch (Exception ex)
                {
                    ShowError($"加载参数文件:{name}.param失败!\r\n\r\n{ex}");
                }
            }

            result.ParamWrappers.Sort();
            return(result);
        }
示例#11
0
        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.ID}.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.SetLayout(layout);
                    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)
                        {
                            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.b16 || 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);
        }
示例#12
0
        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);
        }