Hex Editor - support loading of Text translation table files (.tbl) including Recent menu and autoload options
This commit is contained in:
parent
2581dccd90
commit
b95a0b648c
|
@ -251,6 +251,7 @@ namespace BizHawk.Client.Common
|
||||||
public bool AutoLoadHexEditor = false;
|
public bool AutoLoadHexEditor = false;
|
||||||
public bool HexEditorBigEndian = false;
|
public bool HexEditorBigEndian = false;
|
||||||
public int HexEditorDataSize = 1;
|
public int HexEditorDataSize = 1;
|
||||||
|
public RecentFiles RecentTables = new RecentFiles(8);
|
||||||
|
|
||||||
// Hex Editor Colors
|
// Hex Editor Colors
|
||||||
public Color HexBackgrndColor = Color.FromName("Control");
|
public Color HexBackgrndColor = Color.FromName("Control");
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
this.SaveMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.SaveMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.SaveAsBinaryMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.SaveAsBinaryMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.SaveAsTextMenuItem = 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.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.EditMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.EditMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
|
@ -67,6 +70,7 @@
|
||||||
this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.SaveWindowsPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.SaveWindowsPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.AlwaysOnTopMenuItem = 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.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
this.RestoreDefaultSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
this.RestoreDefaultSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator();
|
this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator();
|
||||||
|
@ -88,7 +92,7 @@
|
||||||
this.HexScrollBar = new System.Windows.Forms.VScrollBar();
|
this.HexScrollBar = new System.Windows.Forms.VScrollBar();
|
||||||
this.AddressesLabel = new System.Windows.Forms.Label();
|
this.AddressesLabel = new System.Windows.Forms.Label();
|
||||||
this.Header = 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.HexMenuStrip.SuspendLayout();
|
||||||
this.ViewerContextMenuStrip.SuspendLayout();
|
this.ViewerContextMenuStrip.SuspendLayout();
|
||||||
this.MemoryViewerBox.SuspendLayout();
|
this.MemoryViewerBox.SuspendLayout();
|
||||||
|
@ -114,6 +118,9 @@
|
||||||
this.SaveMenuItem,
|
this.SaveMenuItem,
|
||||||
this.SaveAsBinaryMenuItem,
|
this.SaveAsBinaryMenuItem,
|
||||||
this.SaveAsTextMenuItem,
|
this.SaveAsTextMenuItem,
|
||||||
|
this.toolStripSeparator4,
|
||||||
|
this.LoadTableFileMenuItem,
|
||||||
|
this.RecentTablesSubMenu,
|
||||||
this.toolStripSeparator1,
|
this.toolStripSeparator1,
|
||||||
this.ExitMenuItem});
|
this.ExitMenuItem});
|
||||||
this.FileSubMenu.Name = "FileSubMenu";
|
this.FileSubMenu.Name = "FileSubMenu";
|
||||||
|
@ -146,6 +153,27 @@
|
||||||
this.SaveAsTextMenuItem.Text = "Save as text...";
|
this.SaveAsTextMenuItem.Text = "Save as text...";
|
||||||
this.SaveAsTextMenuItem.Click += new System.EventHandler(this.SaveAsTextMenuItem_Click);
|
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
|
// toolStripSeparator1
|
||||||
//
|
//
|
||||||
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
this.toolStripSeparator1.Name = "toolStripSeparator1";
|
||||||
|
@ -396,6 +424,13 @@
|
||||||
this.AlwaysOnTopMenuItem.Text = "Always On Top";
|
this.AlwaysOnTopMenuItem.Text = "Always On Top";
|
||||||
this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click);
|
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
|
// toolStripSeparator3
|
||||||
//
|
//
|
||||||
this.toolStripSeparator3.Name = "toolStripSeparator3";
|
this.toolStripSeparator3.Name = "toolStripSeparator3";
|
||||||
|
@ -589,12 +624,11 @@
|
||||||
this.Header.TabIndex = 2;
|
this.Header.TabIndex = 2;
|
||||||
this.Header.Text = "label1";
|
this.Header.Text = "label1";
|
||||||
//
|
//
|
||||||
// FloatingWindowMenuItem
|
// noneToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem";
|
this.noneToolStripMenuItem.Name = "noneToolStripMenuItem";
|
||||||
this.FloatingWindowMenuItem.Size = new System.Drawing.Size(199, 22);
|
this.noneToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||||
this.FloatingWindowMenuItem.Text = "&Floating Window";
|
this.noneToolStripMenuItem.Text = "None";
|
||||||
this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click);
|
|
||||||
//
|
//
|
||||||
// HexEditor
|
// HexEditor
|
||||||
//
|
//
|
||||||
|
@ -685,5 +719,9 @@
|
||||||
private System.Windows.Forms.ToolStripMenuItem PokeContextItem;
|
private System.Windows.Forms.ToolStripMenuItem PokeContextItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
|
private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem;
|
||||||
private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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 char[] _nibbles = { 'G', 'G', 'G', 'G', 'G', 'G', 'G', 'G' }; // G = off 0-9 & A-F are acceptable values
|
||||||
private readonly List<int> _secondaryHighlightedAddresses = new List<int>();
|
private readonly List<int> _secondaryHighlightedAddresses = new List<int>();
|
||||||
|
|
||||||
|
private readonly Dictionary<int, char> _textTable = new Dictionary<int, char>();
|
||||||
|
|
||||||
private int _defaultWidth;
|
private int _defaultWidth;
|
||||||
private int _defaultHeight;
|
private int _defaultHeight;
|
||||||
private int _rowsVisible;
|
private int _rowsVisible;
|
||||||
|
@ -257,19 +259,31 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
#endregion
|
#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 '?';
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (val >= 0x80)
|
|
||||||
{
|
{
|
||||||
return '.';
|
if (val < ' ')
|
||||||
|
{
|
||||||
|
return '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val >= 0x80)
|
||||||
|
{
|
||||||
|
return '.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (char)val;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char)val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int? GetDomainInt(string name)
|
private static int? GetDomainInt(string name)
|
||||||
|
@ -412,6 +426,12 @@ namespace BizHawk.Client.EmuHawk
|
||||||
|
|
||||||
SetMemoryDomainMenu();
|
SetMemoryDomainMenu();
|
||||||
SetDataSize(_dataSize);
|
SetDataSize(_dataSize);
|
||||||
|
|
||||||
|
if (Global.Config.RecentTables.AutoLoad)
|
||||||
|
{
|
||||||
|
LoadFileFromRecent(Global.Config.RecentTables[0]);
|
||||||
|
}
|
||||||
|
|
||||||
UpdateValues();
|
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 Events
|
||||||
|
|
||||||
#region File Menu
|
#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)
|
private void ExitMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
|
|
Loading…
Reference in New Issue