diff --git a/UI/Debugger/Labels/BassLabelFile.cs b/UI/Debugger/Labels/BassLabelFile.cs new file mode 100644 index 0000000..16c4a6a --- /dev/null +++ b/UI/Debugger/Labels/BassLabelFile.cs @@ -0,0 +1,58 @@ +using Mesen.GUI.Config; +using Mesen.GUI.Debugger.Labels; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Mesen.GUI.Debugger +{ + public class BassLabelFile + { + public static void Import(string path, bool silent = false) + { + List labels = new List(1000); + + int errorCount = 0; + foreach(string row in File.ReadAllLines(path, Encoding.UTF8)) { + string lineData = row.Trim(); + int splitIndex = lineData.IndexOf(' '); + UInt32 address; + + if(!UInt32.TryParse(lineData.Substring(0, splitIndex), NumberStyles.HexNumber, null, out address)) { + errorCount++; + } + + AddressInfo absAddress = DebugApi.GetAbsoluteAddress(new AddressInfo() { Address = (int)address, Type = SnesMemoryType.CpuMemory }); + + if(absAddress.Address >= 0) { + CodeLabel label = new CodeLabel(); + label.Address = (UInt32)absAddress.Address; + label.MemoryType = absAddress.Type; + label.Comment = ""; + string labelName = lineData.Substring(splitIndex + 1).Replace('.', '_'); + if(string.IsNullOrEmpty(labelName) || !LabelManager.LabelRegex.IsMatch(labelName)) { + errorCount++; + } else { + label.Label = labelName; + labels.Add(label); + } + } + } + + LabelManager.SetLabels(labels); + + if(!silent) { + string message = $"Import completed with {labels.Count} labels imported"; + if(errorCount > 0) { + message += $" and {errorCount} error(s)"; + } + MessageBox.Show(message, "Mesen-S", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + } +} diff --git a/UI/Debugger/MslLabelFile.cs b/UI/Debugger/Labels/MslLabelFile.cs similarity index 100% rename from UI/Debugger/MslLabelFile.cs rename to UI/Debugger/Labels/MslLabelFile.cs diff --git a/UI/Debugger/Workspace/DebugWorkspaceManager.cs b/UI/Debugger/Workspace/DebugWorkspaceManager.cs index 3f90c42..9e0a99f 100644 --- a/UI/Debugger/Workspace/DebugWorkspaceManager.cs +++ b/UI/Debugger/Workspace/DebugWorkspaceManager.cs @@ -148,7 +148,14 @@ namespace Mesen.GUI.Debugger.Workspace if(ConfigManager.Config.Debug.DbgIntegration.ResetLabelsOnImport) { ResetLabels(); } - new WlaDxImporter().Import(symPath, silent); + + string symContent = File.ReadAllText(symPath); + if(symContent.Contains("[labels]")) { + //Assume WLA-DX symbol files + new WlaDxImporter().Import(symPath, silent); + } else { + BassLabelFile.Import(symPath, silent); + } LabelManager.RefreshLabels(); } diff --git a/UI/UI.csproj b/UI/UI.csproj index 8c70071..5b3fa2a 100644 --- a/UI/UI.csproj +++ b/UI/UI.csproj @@ -298,6 +298,7 @@ Component + UserControl @@ -396,7 +397,7 @@ frmEditLabel.cs - + UserControl