From 5b4845692af2806db4a7bf4fca820c0913263491 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 29 Sep 2015 02:29:19 -0500 Subject: [PATCH] hex editor - clean up copy/paste. fix data scrambling bugs and handling of weird selection areas. copy now creates writes raw (non-byteswapped) values. add 'export' command which creates the text you have copied, complete with spaces. --- .../tools/HexEditor/HexEditor.Designer.cs | 121 ++++++++++-------- .../tools/HexEditor/HexEditor.cs | 97 +++++++++++--- 2 files changed, 147 insertions(+), 71 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs index 7bec131d79..f26beffbd8 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.Designer.cs @@ -44,6 +44,7 @@ this.ExitMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.EditMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CopyMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ExportMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.PasteMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator(); this.FindMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -72,6 +73,7 @@ this.resetToDefaultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ViewerContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); this.CopyContextItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ExportContextItem = new System.Windows.Forms.ToolStripMenuItem(); this.PasteContextItem = new System.Windows.Forms.ToolStripMenuItem(); this.FreezeContextItem = new System.Windows.Forms.ToolStripMenuItem(); this.AddToRamWatchContextItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -122,7 +124,7 @@ this.toolStripSeparator1, this.ExitMenuItem}); this.FileSubMenu.Name = "FileSubMenu"; - this.FileSubMenu.Size = new System.Drawing.Size(37, 20); + this.FileSubMenu.Size = new System.Drawing.Size(35, 20); this.FileSubMenu.Text = "&File"; this.FileSubMenu.DropDownOpened += new System.EventHandler(this.FileSubMenu_DropDownOpened); // @@ -131,7 +133,7 @@ this.SaveMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.SaveAs; this.SaveMenuItem.Name = "SaveMenuItem"; this.SaveMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); - this.SaveMenuItem.Size = new System.Drawing.Size(229, 22); + this.SaveMenuItem.Size = new System.Drawing.Size(225, 22); this.SaveMenuItem.Text = "Save"; this.SaveMenuItem.Click += new System.EventHandler(this.SaveMenuItem_Click); // @@ -140,33 +142,33 @@ this.SaveAsBinaryMenuItem.Name = "SaveAsBinaryMenuItem"; this.SaveAsBinaryMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) | System.Windows.Forms.Keys.S))); - this.SaveAsBinaryMenuItem.Size = new System.Drawing.Size(229, 22); + this.SaveAsBinaryMenuItem.Size = new System.Drawing.Size(225, 22); this.SaveAsBinaryMenuItem.Text = "Save as binary..."; this.SaveAsBinaryMenuItem.Click += new System.EventHandler(this.SaveAsBinaryMenuItem_Click); // // SaveAsTextMenuItem // this.SaveAsTextMenuItem.Name = "SaveAsTextMenuItem"; - this.SaveAsTextMenuItem.Size = new System.Drawing.Size(229, 22); + this.SaveAsTextMenuItem.Size = new System.Drawing.Size(225, 22); 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); + this.toolStripSeparator4.Size = new System.Drawing.Size(222, 6); // // LoadTableFileMenuItem // this.LoadTableFileMenuItem.Name = "LoadTableFileMenuItem"; - this.LoadTableFileMenuItem.Size = new System.Drawing.Size(229, 22); + this.LoadTableFileMenuItem.Size = new System.Drawing.Size(225, 22); this.LoadTableFileMenuItem.Text = "&Load .tbl file"; this.LoadTableFileMenuItem.Click += new System.EventHandler(this.LoadTableFileMenuItem_Click); // // CloseTableFileMenuItem // this.CloseTableFileMenuItem.Name = "CloseTableFileMenuItem"; - this.CloseTableFileMenuItem.Size = new System.Drawing.Size(229, 22); + this.CloseTableFileMenuItem.Size = new System.Drawing.Size(225, 22); this.CloseTableFileMenuItem.Text = "Close .tbl file"; this.CloseTableFileMenuItem.Click += new System.EventHandler(this.CloseTableFileMenuItem_Click); // @@ -175,26 +177,26 @@ 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.Size = new System.Drawing.Size(225, 22); this.RecentTablesSubMenu.Text = "Recent"; this.RecentTablesSubMenu.DropDownOpened += new System.EventHandler(this.RecentTablesSubMenu_DropDownOpened); // // noneToolStripMenuItem // this.noneToolStripMenuItem.Name = "noneToolStripMenuItem"; - this.noneToolStripMenuItem.Size = new System.Drawing.Size(103, 22); + this.noneToolStripMenuItem.Size = new System.Drawing.Size(99, 22); this.noneToolStripMenuItem.Text = "None"; // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(226, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(222, 6); // // ExitMenuItem // this.ExitMenuItem.Name = "ExitMenuItem"; this.ExitMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4))); - this.ExitMenuItem.Size = new System.Drawing.Size(229, 22); + this.ExitMenuItem.Size = new System.Drawing.Size(225, 22); this.ExitMenuItem.Text = "E&xit"; this.ExitMenuItem.Click += new System.EventHandler(this.ExitMenuItem_Click); // @@ -202,13 +204,14 @@ // this.EditMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.CopyMenuItem, + this.ExportMenuItem, this.PasteMenuItem, this.toolStripSeparator6, this.FindMenuItem, this.FindNextMenuItem, this.FindPrevMenuItem}); this.EditMenuItem.Name = "EditMenuItem"; - this.EditMenuItem.Size = new System.Drawing.Size(39, 20); + this.EditMenuItem.Size = new System.Drawing.Size(37, 20); this.EditMenuItem.Text = "&Edit"; this.EditMenuItem.DropDownOpened += new System.EventHandler(this.EditMenuItem_DropDownOpened); // @@ -217,29 +220,37 @@ this.CopyMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Duplicate; this.CopyMenuItem.Name = "CopyMenuItem"; this.CopyMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); - this.CopyMenuItem.Size = new System.Drawing.Size(146, 22); + this.CopyMenuItem.Size = new System.Drawing.Size(152, 22); this.CopyMenuItem.Text = "&Copy"; this.CopyMenuItem.Click += new System.EventHandler(this.CopyMenuItem_Click); // + // ExportMenuItem + // + this.ExportMenuItem.Name = "ExportMenuItem"; + this.ExportMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E))); + this.ExportMenuItem.Size = new System.Drawing.Size(152, 22); + this.ExportMenuItem.Text = "&Export"; + this.ExportMenuItem.Click += new System.EventHandler(this.ExportMenuItem_Click); + // // PasteMenuItem // this.PasteMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Paste; this.PasteMenuItem.Name = "PasteMenuItem"; this.PasteMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V))); - this.PasteMenuItem.Size = new System.Drawing.Size(146, 22); + this.PasteMenuItem.Size = new System.Drawing.Size(152, 22); this.PasteMenuItem.Text = "&Paste"; this.PasteMenuItem.Click += new System.EventHandler(this.PasteMenuItem_Click); // // toolStripSeparator6 // this.toolStripSeparator6.Name = "toolStripSeparator6"; - this.toolStripSeparator6.Size = new System.Drawing.Size(143, 6); + this.toolStripSeparator6.Size = new System.Drawing.Size(149, 6); // // FindMenuItem // this.FindMenuItem.Name = "FindMenuItem"; this.FindMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F))); - this.FindMenuItem.Size = new System.Drawing.Size(146, 22); + this.FindMenuItem.Size = new System.Drawing.Size(152, 22); this.FindMenuItem.Text = "&Find..."; this.FindMenuItem.Click += new System.EventHandler(this.FindMenuItem_Click); // @@ -247,7 +258,7 @@ // this.FindNextMenuItem.Name = "FindNextMenuItem"; this.FindNextMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F3; - this.FindNextMenuItem.Size = new System.Drawing.Size(146, 22); + this.FindNextMenuItem.Size = new System.Drawing.Size(152, 22); this.FindNextMenuItem.Text = "Find Next"; this.FindNextMenuItem.Click += new System.EventHandler(this.FindNextMenuItem_Click); // @@ -255,7 +266,7 @@ // this.FindPrevMenuItem.Name = "FindPrevMenuItem"; this.FindPrevMenuItem.ShortcutKeys = System.Windows.Forms.Keys.F2; - this.FindPrevMenuItem.Size = new System.Drawing.Size(146, 22); + this.FindPrevMenuItem.Size = new System.Drawing.Size(152, 22); this.FindPrevMenuItem.Text = "Find Prev"; this.FindPrevMenuItem.Click += new System.EventHandler(this.FindPrevMenuItem_Click); // @@ -272,7 +283,7 @@ this.UnfreezeAllMenuItem, this.PokeAddressMenuItem}); this.OptionsSubMenu.Name = "OptionsSubMenu"; - this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20); + this.OptionsSubMenu.Size = new System.Drawing.Size(56, 20); this.OptionsSubMenu.Text = "&Options"; this.OptionsSubMenu.DropDownOpened += new System.EventHandler(this.OptionsSubMenu_DropDownOpened); // @@ -281,7 +292,7 @@ this.MemoryDomainsMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripSeparator3}); this.MemoryDomainsMenuItem.Name = "MemoryDomainsMenuItem"; - this.MemoryDomainsMenuItem.Size = new System.Drawing.Size(219, 22); + this.MemoryDomainsMenuItem.Size = new System.Drawing.Size(206, 22); this.MemoryDomainsMenuItem.Text = "&Memory Domains"; this.MemoryDomainsMenuItem.DropDownOpened += new System.EventHandler(this.MemoryDomainsMenuItem_DropDownOpened); // @@ -297,47 +308,47 @@ this.DataSizeWordMenuItem, this.DataSizeDWordMenuItem}); this.DataSizeSubMenu.Name = "DataSizeSubMenu"; - this.DataSizeSubMenu.Size = new System.Drawing.Size(219, 22); + this.DataSizeSubMenu.Size = new System.Drawing.Size(206, 22); this.DataSizeSubMenu.Text = "Data Size"; // // DataSizeByteMenuItem // this.DataSizeByteMenuItem.Name = "DataSizeByteMenuItem"; - this.DataSizeByteMenuItem.Size = new System.Drawing.Size(106, 22); + this.DataSizeByteMenuItem.Size = new System.Drawing.Size(105, 22); this.DataSizeByteMenuItem.Text = "1 Byte"; this.DataSizeByteMenuItem.Click += new System.EventHandler(this.DataSizeByteMenuItem_Click); // // DataSizeWordMenuItem // this.DataSizeWordMenuItem.Name = "DataSizeWordMenuItem"; - this.DataSizeWordMenuItem.Size = new System.Drawing.Size(106, 22); + this.DataSizeWordMenuItem.Size = new System.Drawing.Size(105, 22); this.DataSizeWordMenuItem.Text = "2 Byte"; this.DataSizeWordMenuItem.Click += new System.EventHandler(this.DataSizeWordMenuItem_Click); // // DataSizeDWordMenuItem // this.DataSizeDWordMenuItem.Name = "DataSizeDWordMenuItem"; - this.DataSizeDWordMenuItem.Size = new System.Drawing.Size(106, 22); + this.DataSizeDWordMenuItem.Size = new System.Drawing.Size(105, 22); this.DataSizeDWordMenuItem.Text = "4 Byte"; this.DataSizeDWordMenuItem.Click += new System.EventHandler(this.DataSizeDWordMenuItem_Click); // // BigEndianMenuItem // this.BigEndianMenuItem.Name = "BigEndianMenuItem"; - this.BigEndianMenuItem.Size = new System.Drawing.Size(219, 22); + this.BigEndianMenuItem.Size = new System.Drawing.Size(206, 22); this.BigEndianMenuItem.Text = "Big Endian"; this.BigEndianMenuItem.Click += new System.EventHandler(this.BigEndianMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(216, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(203, 6); // // GoToAddressMenuItem // this.GoToAddressMenuItem.Name = "GoToAddressMenuItem"; this.GoToAddressMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.G))); - this.GoToAddressMenuItem.Size = new System.Drawing.Size(219, 22); + this.GoToAddressMenuItem.Size = new System.Drawing.Size(206, 22); this.GoToAddressMenuItem.Text = "&Go to Address..."; this.GoToAddressMenuItem.Click += new System.EventHandler(this.GoToAddressMenuItem_Click); // @@ -346,7 +357,7 @@ this.AddToRamWatchMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.FindHS; this.AddToRamWatchMenuItem.Name = "AddToRamWatchMenuItem"; this.AddToRamWatchMenuItem.ShortcutKeyDisplayString = "Ctrl+W"; - this.AddToRamWatchMenuItem.Size = new System.Drawing.Size(219, 22); + this.AddToRamWatchMenuItem.Size = new System.Drawing.Size(206, 22); this.AddToRamWatchMenuItem.Text = "Add to Ram Watch"; this.AddToRamWatchMenuItem.Click += new System.EventHandler(this.AddToRamWatchMenuItem_Click); // @@ -355,7 +366,7 @@ this.FreezeAddressMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Freeze; this.FreezeAddressMenuItem.Name = "FreezeAddressMenuItem"; this.FreezeAddressMenuItem.ShortcutKeyDisplayString = "Space"; - this.FreezeAddressMenuItem.Size = new System.Drawing.Size(219, 22); + this.FreezeAddressMenuItem.Size = new System.Drawing.Size(206, 22); this.FreezeAddressMenuItem.Text = "&Freeze Address"; this.FreezeAddressMenuItem.Click += new System.EventHandler(this.FreezeAddressMenuItem_Click); // @@ -364,7 +375,7 @@ this.UnfreezeAllMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Unfreeze; this.UnfreezeAllMenuItem.Name = "UnfreezeAllMenuItem"; this.UnfreezeAllMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Shift | System.Windows.Forms.Keys.Delete))); - this.UnfreezeAllMenuItem.Size = new System.Drawing.Size(219, 22); + this.UnfreezeAllMenuItem.Size = new System.Drawing.Size(206, 22); this.UnfreezeAllMenuItem.Text = "Unfreeze All"; this.UnfreezeAllMenuItem.Click += new System.EventHandler(this.UnfreezeAllMenuItem_Click); // @@ -373,7 +384,7 @@ this.PokeAddressMenuItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.poke; this.PokeAddressMenuItem.Name = "PokeAddressMenuItem"; this.PokeAddressMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.P))); - this.PokeAddressMenuItem.Size = new System.Drawing.Size(219, 22); + this.PokeAddressMenuItem.Size = new System.Drawing.Size(206, 22); this.PokeAddressMenuItem.Text = "&Poke Address"; this.PokeAddressMenuItem.Click += new System.EventHandler(this.PokeAddressMenuItem_Click); // @@ -382,7 +393,7 @@ this.SettingsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.CustomColorsSubMenu}); this.SettingsSubMenu.Name = "SettingsSubMenu"; - this.SettingsSubMenu.Size = new System.Drawing.Size(61, 20); + this.SettingsSubMenu.Size = new System.Drawing.Size(58, 20); this.SettingsSubMenu.Text = "&Settings"; // // CustomColorsSubMenu @@ -392,25 +403,25 @@ this.toolStripSeparator8, this.ResetColorsToDefaultMenuItem}); this.CustomColorsSubMenu.Name = "CustomColorsSubMenu"; - this.CustomColorsSubMenu.Size = new System.Drawing.Size(153, 22); + this.CustomColorsSubMenu.Size = new System.Drawing.Size(143, 22); this.CustomColorsSubMenu.Text = "Custom Colors"; // // SetColorsMenuItem // this.SetColorsMenuItem.Name = "SetColorsMenuItem"; - this.SetColorsMenuItem.Size = new System.Drawing.Size(157, 22); + this.SetColorsMenuItem.Size = new System.Drawing.Size(153, 22); this.SetColorsMenuItem.Text = "Set Colors"; this.SetColorsMenuItem.Click += new System.EventHandler(this.SetColorsMenuItem_Click); // // toolStripSeparator8 // this.toolStripSeparator8.Name = "toolStripSeparator8"; - this.toolStripSeparator8.Size = new System.Drawing.Size(154, 6); + this.toolStripSeparator8.Size = new System.Drawing.Size(150, 6); // // ResetColorsToDefaultMenuItem // this.ResetColorsToDefaultMenuItem.Name = "ResetColorsToDefaultMenuItem"; - this.ResetColorsToDefaultMenuItem.Size = new System.Drawing.Size(157, 22); + this.ResetColorsToDefaultMenuItem.Size = new System.Drawing.Size(153, 22); this.ResetColorsToDefaultMenuItem.Text = "Reset to Default"; this.ResetColorsToDefaultMenuItem.Click += new System.EventHandler(this.ResetColorsToDefaultMenuItem_Click); // @@ -429,6 +440,7 @@ // this.ViewerContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.CopyContextItem, + this.ExportContextItem, this.PasteContextItem, this.FreezeContextItem, this.AddToRamWatchContextItem, @@ -442,7 +454,7 @@ this.toolStripMenuItem1, this.viewN64MatrixToolStripMenuItem}); this.ViewerContextMenuStrip.Name = "ViewerContextMenuStrip"; - this.ViewerContextMenuStrip.Size = new System.Drawing.Size(220, 242); + this.ViewerContextMenuStrip.Size = new System.Drawing.Size(207, 264); this.ViewerContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.ViewerContextMenuStrip_Opening); // // CopyContextItem @@ -450,16 +462,23 @@ this.CopyContextItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Duplicate; this.CopyContextItem.Name = "CopyContextItem"; this.CopyContextItem.ShortcutKeyDisplayString = "Ctrl+C"; - this.CopyContextItem.Size = new System.Drawing.Size(219, 22); + this.CopyContextItem.Size = new System.Drawing.Size(206, 22); this.CopyContextItem.Text = "&Copy"; this.CopyContextItem.Click += new System.EventHandler(this.CopyMenuItem_Click); // + // ExportContextItem + // + this.ExportContextItem.Name = "ExportContextItem"; + this.ExportContextItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.E))); + this.ExportContextItem.Size = new System.Drawing.Size(206, 22); + this.ExportContextItem.Text = "&Export"; + // // PasteContextItem // this.PasteContextItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Paste; this.PasteContextItem.Name = "PasteContextItem"; this.PasteContextItem.ShortcutKeyDisplayString = "Ctrl+V"; - this.PasteContextItem.Size = new System.Drawing.Size(219, 22); + this.PasteContextItem.Size = new System.Drawing.Size(206, 22); this.PasteContextItem.Text = "&Paste"; this.PasteContextItem.Click += new System.EventHandler(this.PasteMenuItem_Click); // @@ -468,7 +487,7 @@ this.FreezeContextItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Freeze; this.FreezeContextItem.Name = "FreezeContextItem"; this.FreezeContextItem.ShortcutKeyDisplayString = "Space"; - this.FreezeContextItem.Size = new System.Drawing.Size(219, 22); + this.FreezeContextItem.Size = new System.Drawing.Size(206, 22); this.FreezeContextItem.Text = "&Freeze"; this.FreezeContextItem.Click += new System.EventHandler(this.FreezeAddressMenuItem_Click); // @@ -477,7 +496,7 @@ this.AddToRamWatchContextItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.FindHS; this.AddToRamWatchContextItem.Name = "AddToRamWatchContextItem"; this.AddToRamWatchContextItem.ShortcutKeyDisplayString = "Ctrl+W"; - this.AddToRamWatchContextItem.Size = new System.Drawing.Size(219, 22); + this.AddToRamWatchContextItem.Size = new System.Drawing.Size(206, 22); this.AddToRamWatchContextItem.Text = "&Add to Ram Watch"; this.AddToRamWatchContextItem.Click += new System.EventHandler(this.AddToRamWatchMenuItem_Click); // @@ -486,7 +505,7 @@ this.UnfreezeAllContextItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.Unfreeze; this.UnfreezeAllContextItem.Name = "UnfreezeAllContextItem"; this.UnfreezeAllContextItem.ShortcutKeyDisplayString = "Shift+Del"; - this.UnfreezeAllContextItem.Size = new System.Drawing.Size(219, 22); + this.UnfreezeAllContextItem.Size = new System.Drawing.Size(206, 22); this.UnfreezeAllContextItem.Text = "&Unfreeze All"; this.UnfreezeAllContextItem.Click += new System.EventHandler(this.UnfreezeAllMenuItem_Click); // @@ -495,20 +514,20 @@ this.PokeContextItem.Image = global::BizHawk.Client.EmuHawk.Properties.Resources.poke; this.PokeContextItem.Name = "PokeContextItem"; this.PokeContextItem.ShortcutKeyDisplayString = "Ctrl+P"; - this.PokeContextItem.Size = new System.Drawing.Size(219, 22); + this.PokeContextItem.Size = new System.Drawing.Size(206, 22); this.PokeContextItem.Text = "&Poke Address"; this.PokeContextItem.Click += new System.EventHandler(this.PokeAddressMenuItem_Click); // // ContextSeparator1 // this.ContextSeparator1.Name = "ContextSeparator1"; - this.ContextSeparator1.Size = new System.Drawing.Size(216, 6); + this.ContextSeparator1.Size = new System.Drawing.Size(203, 6); // // IncrementContextItem // this.IncrementContextItem.Name = "IncrementContextItem"; this.IncrementContextItem.ShortcutKeyDisplayString = "+"; - this.IncrementContextItem.Size = new System.Drawing.Size(219, 22); + this.IncrementContextItem.Size = new System.Drawing.Size(206, 22); this.IncrementContextItem.Text = "&Increment"; this.IncrementContextItem.Click += new System.EventHandler(this.IncrementContextItem_Click); // @@ -516,32 +535,32 @@ // this.DecrementContextItem.Name = "DecrementContextItem"; this.DecrementContextItem.ShortcutKeyDisplayString = "-"; - this.DecrementContextItem.Size = new System.Drawing.Size(219, 22); + this.DecrementContextItem.Size = new System.Drawing.Size(206, 22); this.DecrementContextItem.Text = "&Decrement"; this.DecrementContextItem.Click += new System.EventHandler(this.DecrementContextItem_Click); // // ContextSeparator2 // this.ContextSeparator2.Name = "ContextSeparator2"; - this.ContextSeparator2.Size = new System.Drawing.Size(216, 6); + this.ContextSeparator2.Size = new System.Drawing.Size(203, 6); // // GoToContextItem // this.GoToContextItem.Name = "GoToContextItem"; this.GoToContextItem.ShortcutKeyDisplayString = "Ctrl+G"; - this.GoToContextItem.Size = new System.Drawing.Size(219, 22); + this.GoToContextItem.Size = new System.Drawing.Size(206, 22); this.GoToContextItem.Text = "&Go to Address..."; this.GoToContextItem.Click += new System.EventHandler(this.GoToAddressMenuItem_Click); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(216, 6); + this.toolStripMenuItem1.Size = new System.Drawing.Size(203, 6); // // viewN64MatrixToolStripMenuItem // this.viewN64MatrixToolStripMenuItem.Name = "viewN64MatrixToolStripMenuItem"; - this.viewN64MatrixToolStripMenuItem.Size = new System.Drawing.Size(219, 22); + this.viewN64MatrixToolStripMenuItem.Size = new System.Drawing.Size(206, 22); this.viewN64MatrixToolStripMenuItem.Text = "View N64 Matrix"; this.viewN64MatrixToolStripMenuItem.Click += new System.EventHandler(this.viewN64MatrixToolStripMenuItem_Click); // @@ -700,5 +719,7 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem viewN64MatrixToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ExportContextItem; + private System.Windows.Forms.ToolStripMenuItem ExportMenuItem; } } \ 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 0bcb4f35cb..a14a84c7db 100644 --- a/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -542,14 +542,14 @@ namespace BizHawk.Client.EmuHawk : _domain.PeekByte(address); } - private int MakeValue(long address) + private int MakeValue(int dataSize, long address) { if (Global.CheatList.IsActive(_domain, address)) { return Global.CheatList.GetCheatValue(_domain, address, (Watch.WatchSize)DataSize ).Value; } - switch (DataSize) + switch (dataSize) { default: case 1: @@ -561,6 +561,11 @@ namespace BizHawk.Client.EmuHawk } } + private int MakeValue(long address) + { + return MakeValue(DataSize, address); + } + private void SetMemoryDomain(string name) { if (name == _romDomain.Name) @@ -1333,36 +1338,85 @@ namespace BizHawk.Client.EmuHawk FindNextMenuItem.Enabled = !string.IsNullOrWhiteSpace(_findStr); } + string MakeCopyExportString(bool export) + { + //make room for an array with _secondaryHighlightedAddresses and optionally HighlightedAddress + long[] addresses = new long[_secondaryHighlightedAddresses.Count + (HighlightedAddress.HasValue ? 1 : 0)]; + + //if there was actually nothing to do, return + if (addresses.Length == 0) + return null; + + //fill the array with _secondaryHighlightedAddresses + for (int i = 0; i < _secondaryHighlightedAddresses.Count; i++) + addresses[i] = _secondaryHighlightedAddresses[i]; + //and add HighlightedAddress if present + if (HighlightedAddress.HasValue) + addresses[addresses.Length - 1] = HighlightedAddress.Value; + + //these need to be sorted. it's not just for HighlightedAddress, _secondaryHighlightedAddresses can even be jumbled + Array.Sort(addresses); + + //find the maximum length of the exported string + int maximumLength = addresses.Length * (export ? 3 : 2) + 8; + StringBuilder sb = new StringBuilder(maximumLength); + + //generate it differently for export (as you see it) or copy (raw bytes) + if (export) + for (int i = 0; i < addresses.Length; i++) + { + sb.Append(ValueString(addresses[i])); + if(i != addresses.Length-1) + sb.Append(' '); + } + else + { + for (int i = 0; i < addresses.Length; i++) + { + long start = addresses[i]; + long end = addresses[i] + DataSize -1 ; + for(long a = start;a<=end;a++) + sb.AppendFormat("{0:X2}", MakeValue(1,a)); + } + } + + return sb.ToString(); + } + + private void ExportMenuItem_Click(object sender, EventArgs e) + { + var value = MakeCopyExportString(true); + if (!string.IsNullOrEmpty(value)) + Clipboard.SetDataObject(value); + } + private void CopyMenuItem_Click(object sender, EventArgs e) { - var value = HighlightedAddress.HasValue ? ValueString(HighlightedAddress.Value) : string.Empty; - value = _secondaryHighlightedAddresses.Aggregate(value, (current, x) => current + ValueString(x)); - if (!string.IsNullOrWhiteSpace(value)) - { + var value = MakeCopyExportString(false); + if (!string.IsNullOrEmpty(value)) Clipboard.SetDataObject(value); - } } private void PasteMenuItem_Click(object sender, EventArgs e) { var data = Clipboard.GetDataObject(); - if (data != null && data.GetDataPresent(DataFormats.Text)) + if (data != null && !data.GetDataPresent(DataFormats.Text)) + return; + + var clipboardRaw = (string)data.GetData(DataFormats.Text); + var hex = clipboardRaw.OnlyHex(); + + var numBytes = hex.Length / 2; + for (var i = 0; i < numBytes; i++) { - var clipboardRaw = (string)data.GetData(DataFormats.Text); - var hex = clipboardRaw.OnlyHex(); - - var numBytes = hex.Length / 2; - for (var i = 0; i < numBytes; i++) - { - var value = int.Parse(hex.Substring(i * 2, 2), NumberStyles.HexNumber); - var address = _addressHighlighted + i; - _domain.PokeByte(address, (byte)value); - } - - UpdateValues(); + var value = int.Parse(hex.Substring(i * 2, 2), NumberStyles.HexNumber); + var address = _addressHighlighted + i; + _domain.PokeByte(address, (byte)value); } - } + + UpdateValues(); + } private void FindMenuItem_Click(object sender, EventArgs e) { @@ -2247,5 +2301,6 @@ namespace BizHawk.Client.EmuHawk MessageBox.Show(str); } + } }