diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index e56921051f..f743ac32bf 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -251,6 +251,7 @@ namespace BizHawk.Client.Common public bool AutoLoadHexEditor = false; public bool HexEditorBigEndian = false; public int HexEditorDataSize = 1; + public RecentFiles RecentTables = new RecentFiles(8); // Hex Editor Colors public Color HexBackgrndColor = Color.FromName("Control"); diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs index 14091650d2..672ec3ad61 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs @@ -37,6 +37,9 @@ this.SaveMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SaveAsBinaryMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SaveAsTextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator(); + this.LoadTableFileMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.RecentTablesSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.EditMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -67,6 +70,7 @@ this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.SaveWindowsPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.RestoreDefaultSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator(); @@ -88,7 +92,7 @@ this.HexScrollBar = new System.Windows.Forms.VScrollBar(); this.AddressesLabel = new System.Windows.Forms.Label(); this.Header = new System.Windows.Forms.Label(); - this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.noneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.HexMenuStrip.SuspendLayout(); this.ViewerContextMenuStrip.SuspendLayout(); this.MemoryViewerBox.SuspendLayout(); @@ -114,6 +118,9 @@ this.SaveMenuItem, this.SaveAsBinaryMenuItem, this.SaveAsTextMenuItem, + this.toolStripSeparator4, + this.LoadTableFileMenuItem, + this.RecentTablesSubMenu, this.toolStripSeparator1, this.ExitMenuItem}); this.FileSubMenu.Name = "FileSubMenu"; @@ -146,6 +153,27 @@ this.SaveAsTextMenuItem.Text = "Save as text..."; this.SaveAsTextMenuItem.Click += new System.EventHandler(this.SaveAsTextMenuItem_Click); // + // toolStripSeparator4 + // + this.toolStripSeparator4.Name = "toolStripSeparator4"; + this.toolStripSeparator4.Size = new System.Drawing.Size(226, 6); + // + // LoadTableFileMenuItem + // + this.LoadTableFileMenuItem.Name = "LoadTableFileMenuItem"; + this.LoadTableFileMenuItem.Size = new System.Drawing.Size(229, 22); + this.LoadTableFileMenuItem.Text = "&Load .tbl file"; + this.LoadTableFileMenuItem.Click += new System.EventHandler(this.LoadTableFileMenuItem_Click); + // + // RecentTablesSubMenu + // + this.RecentTablesSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.noneToolStripMenuItem}); + this.RecentTablesSubMenu.Name = "RecentTablesSubMenu"; + this.RecentTablesSubMenu.Size = new System.Drawing.Size(229, 22); + this.RecentTablesSubMenu.Text = "Recent"; + this.RecentTablesSubMenu.DropDownOpened += new System.EventHandler(this.RecentTablesSubMenu_DropDownOpened); + // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; @@ -396,6 +424,13 @@ this.AlwaysOnTopMenuItem.Text = "Always On Top"; this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click); // + // FloatingWindowMenuItem + // + this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem"; + this.FloatingWindowMenuItem.Size = new System.Drawing.Size(199, 22); + this.FloatingWindowMenuItem.Text = "&Floating Window"; + this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click); + // // toolStripSeparator3 // this.toolStripSeparator3.Name = "toolStripSeparator3"; @@ -589,12 +624,11 @@ this.Header.TabIndex = 2; this.Header.Text = "label1"; // - // FloatingWindowMenuItem + // noneToolStripMenuItem // - this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem"; - this.FloatingWindowMenuItem.Size = new System.Drawing.Size(199, 22); - this.FloatingWindowMenuItem.Text = "&Floating Window"; - this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click); + this.noneToolStripMenuItem.Name = "noneToolStripMenuItem"; + this.noneToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.noneToolStripMenuItem.Text = "None"; // // HexEditor // @@ -685,5 +719,9 @@ private System.Windows.Forms.ToolStripMenuItem PokeContextItem; private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem; private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator4; + private System.Windows.Forms.ToolStripMenuItem LoadTableFileMenuItem; + private System.Windows.Forms.ToolStripMenuItem RecentTablesSubMenu; + private System.Windows.Forms.ToolStripMenuItem noneToolStripMenuItem; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 1f7b096f65..416a32e110 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -22,6 +22,8 @@ namespace BizHawk.Client.EmuHawk private readonly char[] _nibbles = { 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G' }; // G = off 0-9 & A-F are acceptable values private readonly List _secondaryHighlightedAddresses = new List(); + private readonly Dictionary _textTable = new Dictionary(); + private int _defaultWidth; private int _defaultHeight; private int _rowsVisible; @@ -257,19 +259,31 @@ namespace BizHawk.Client.EmuHawk #endregion - private static char Remap(byte val) + private char Remap(byte val) { - if (val < ' ') + if (_textTable.Any()) { - return '.'; + if (_textTable.ContainsKey(val)) + { + return _textTable[val]; + } + + return '?'; } - - if (val >= 0x80) + else { - return '.'; + if (val < ' ') + { + return '.'; + } + + if (val >= 0x80) + { + return '.'; + } + + return (char)val; } - - return (char)val; } private static int? GetDomainInt(string name) @@ -412,6 +426,12 @@ namespace BizHawk.Client.EmuHawk SetMemoryDomainMenu(); SetDataSize(_dataSize); + + if (Global.Config.RecentTables.AutoLoad) + { + LoadFileFromRecent(Global.Config.RecentTables[0]); + } + UpdateValues(); } @@ -1161,6 +1181,30 @@ namespace BizHawk.Client.EmuHawk } } + private bool LoadTable(string path) + { + var file = new FileInfo(path); + if (!file.Exists) + { + return false; + } + + using (var sr = file.OpenText()) + { + string line; + + while ((line = sr.ReadLine()) != null) + { + var parts = line.Split('='); + _textTable.Add( + int.Parse(parts[0], + NumberStyles.HexNumber), parts[1].First()); + } + } + + return true; + } + #region Events #region File Menu @@ -1220,6 +1264,52 @@ namespace BizHawk.Client.EmuHawk } } + private void LoadTableFileMenuItem_Click(object sender, EventArgs e) + { + var ofd = new OpenFileDialog + { + InitialDirectory = PathManager.GetPlatformBase(Global.Emulator.SystemId), + Filter = "Text Table files (*.tbl)|*.tbl|All Files|*.*", + RestoreDirectory = false + }; + + GlobalWin.Sound.StopSound(); + var result = ofd.ShowDialog(); + GlobalWin.Sound.StartSound(); + + if (result == DialogResult.OK) + { + LoadTable(ofd.FileName); + Global.Config.RecentTables.Add(ofd.FileName); + UpdateValues(); + } + } + + public void LoadFileFromRecent(string path) + { + + var result = LoadTable(path); + if (!result) + { + ToolHelpers.HandleLoadError(Global.Config.RecentTables, path); + } + else + { + Global.Config.RecentTables.Add(path); + UpdateValues(); + } + } + + private void RecentTablesSubMenu_DropDownOpened(object sender, EventArgs e) + { + RecentTablesSubMenu.DropDownItems.Clear(); + RecentTablesSubMenu.DropDownItems.AddRange( + ToolHelpers.GenerateRecentMenu(Global.Config.RecentTables, LoadFileFromRecent)); + + RecentTablesSubMenu.DropDownItems.Add( + ToolHelpers.GenerateAutoLoadItem(Global.Config.RecentTables)); + } + private void ExitMenuItem_Click(object sender, EventArgs e) { Close();