diff --git a/BizHawk.MultiClient/tools/HexEditor.Designer.cs b/BizHawk.MultiClient/tools/HexEditor.Designer.cs index e2b6aa999e..5199f73156 100644 --- a/BizHawk.MultiClient/tools/HexEditor.Designer.cs +++ b/BizHawk.MultiClient/tools/HexEditor.Designer.cs @@ -75,10 +75,12 @@ this.toolStripSeparator5 = new System.Windows.Forms.ToolStripSeparator(); this.gotoAddressToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.MemoryViewerBox = new System.Windows.Forms.GroupBox(); + this.AddressLabel = new System.Windows.Forms.Label(); this.vScrollBar1 = new System.Windows.Forms.VScrollBar(); this.AddressesLabel = new System.Windows.Forms.Label(); this.Header = new System.Windows.Forms.Label(); - this.AddressLabel = new System.Windows.Forms.Label(); + this.copyToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.pasteToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.ViewerContextMenuStrip.SuspendLayout(); this.MemoryViewerBox.SuspendLayout(); @@ -152,7 +154,7 @@ this.copyToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Duplicate; this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; this.copyToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); - this.copyToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.copyToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.copyToolStripMenuItem.Text = "&Copy"; this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); // @@ -161,20 +163,20 @@ this.pasteToolStripMenuItem.Image = global::BizHawk.MultiClient.Properties.Resources.Paste; this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; this.pasteToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V))); - this.pasteToolStripMenuItem.Size = new System.Drawing.Size(146, 22); + this.pasteToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.pasteToolStripMenuItem.Text = "&Paste"; this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Click); // // toolStripSeparator6 // this.toolStripSeparator6.Name = "toolStripSeparator6"; - this.toolStripSeparator6.Size = new System.Drawing.Size(143, 6); + this.toolStripSeparator6.Size = new System.Drawing.Size(149, 6); // // findToolStripMenuItem1 // this.findToolStripMenuItem1.Name = "findToolStripMenuItem1"; this.findToolStripMenuItem1.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.F))); - this.findToolStripMenuItem1.Size = new System.Drawing.Size(146, 22); + this.findToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); this.findToolStripMenuItem1.Text = "&Find..."; this.findToolStripMenuItem1.Click += new System.EventHandler(this.findToolStripMenuItem1_Click); // @@ -368,6 +370,8 @@ // ViewerContextMenuStrip // this.ViewerContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.copyToolStripMenuItem1, + this.pasteToolStripMenuItem1, this.freezeToolStripMenuItem, this.addToRamWatchToolStripMenuItem, this.unfreezeAllToolStripMenuItem1, @@ -377,7 +381,7 @@ this.toolStripSeparator5, this.gotoAddressToolStripMenuItem1}); this.ViewerContextMenuStrip.Name = "ViewerContextMenuStrip"; - this.ViewerContextMenuStrip.Size = new System.Drawing.Size(220, 148); + this.ViewerContextMenuStrip.Size = new System.Drawing.Size(220, 214); this.ViewerContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(this.ViewerContextMenuStrip_Opening); // // freezeToolStripMenuItem @@ -438,7 +442,7 @@ this.gotoAddressToolStripMenuItem1.Name = "gotoAddressToolStripMenuItem1"; this.gotoAddressToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+G"; this.gotoAddressToolStripMenuItem1.Size = new System.Drawing.Size(219, 22); - this.gotoAddressToolStripMenuItem1.Text = "&Go to Addres..."; + this.gotoAddressToolStripMenuItem1.Text = "&Go to Address..."; this.gotoAddressToolStripMenuItem1.Click += new System.EventHandler(this.gotoAddressToolStripMenuItem1_Click); // // MemoryViewerBox @@ -460,6 +464,16 @@ this.MemoryViewerBox.TabStop = false; this.MemoryViewerBox.Paint += new System.Windows.Forms.PaintEventHandler(this.MemoryViewerBox_Paint); // + // AddressLabel + // + this.AddressLabel.AutoSize = true; + this.AddressLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.AddressLabel.Location = new System.Drawing.Point(3, 30); + this.AddressLabel.Name = "AddressLabel"; + this.AddressLabel.Size = new System.Drawing.Size(25, 13); + this.AddressLabel.TabIndex = 2; + this.AddressLabel.Text = " "; + // // vScrollBar1 // this.vScrollBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -494,15 +508,23 @@ this.Header.TabIndex = 2; this.Header.Text = "label1"; // - // AddressLabel + // copyToolStripMenuItem1 // - this.AddressLabel.AutoSize = true; - this.AddressLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.AddressLabel.Location = new System.Drawing.Point(3, 30); - this.AddressLabel.Name = "AddressLabel"; - this.AddressLabel.Size = new System.Drawing.Size(25, 13); - this.AddressLabel.TabIndex = 2; - this.AddressLabel.Text = " "; + this.copyToolStripMenuItem1.Image = global::BizHawk.MultiClient.Properties.Resources.Duplicate; + this.copyToolStripMenuItem1.Name = "copyToolStripMenuItem1"; + this.copyToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+C"; + this.copyToolStripMenuItem1.Size = new System.Drawing.Size(219, 22); + this.copyToolStripMenuItem1.Text = "&Copy"; + this.copyToolStripMenuItem1.Click += new System.EventHandler(this.copyToolStripMenuItem1_Click); + // + // pasteToolStripMenuItem1 + // + this.pasteToolStripMenuItem1.Image = global::BizHawk.MultiClient.Properties.Resources.Paste; + this.pasteToolStripMenuItem1.Name = "pasteToolStripMenuItem1"; + this.pasteToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+V"; + this.pasteToolStripMenuItem1.Size = new System.Drawing.Size(219, 22); + this.pasteToolStripMenuItem1.Text = "&Paste"; + this.pasteToolStripMenuItem1.Click += new System.EventHandler(this.pasteToolStripMenuItem1_Click); // // HexEditor // @@ -584,5 +606,7 @@ private System.Windows.Forms.ToolStripMenuItem resetToDefaultToolStripMenuItem1; public System.Windows.Forms.Label Header; private System.Windows.Forms.Label AddressLabel; + private System.Windows.Forms.ToolStripMenuItem copyToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem pasteToolStripMenuItem1; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/HexEditor.cs b/BizHawk.MultiClient/tools/HexEditor.cs index 2aaf55dc8b..cca870e239 100644 --- a/BizHawk.MultiClient/tools/HexEditor.cs +++ b/BizHawk.MultiClient/tools/HexEditor.cs @@ -15,10 +15,10 @@ namespace BizHawk.MultiClient { //TODO: //Find Prev, Find Next - //Multi-select //Open Up ROM in memory domains, set up logic for saving the rom //Tool strip //Increment/Decrement wrapping logic for 2 and 4 byte values + int defaultWidth; int defaultHeight; List domainMenuItems = new List(); @@ -28,6 +28,7 @@ namespace BizHawk.MultiClient string DigitFormatString = "{0:X2} "; char[] nibbles = { 'G', 'G', 'G', 'G' , 'G', 'G', 'G', 'G'}; //G = off 0-9 & A-F are acceptable values int addressHighlighted = -1; + List SecondaryHighlightedAddresses = new List(); int addressOver = -1; int addrOffset = 0; //If addresses are > 4 digits, this offset is how much the columns are moved to the right int maxRow = 0; @@ -423,7 +424,6 @@ namespace BizHawk.MultiClient ClearNibbles(); info = String.Format(NumDigitsStr, addressOver); UpdateFormText(); - Refresh(); } private void UpdateFormText() @@ -499,33 +499,46 @@ namespace BizHawk.MultiClient UpdateValues(); } + private Watch MakeWatch(int address) + { + Watch w = new Watch(); + w.address = address; + w.bigendian = BigEndian; + w.signed = asigned.HEX; + + switch (DataSize) + { + default: + case 1: + w.type = atype.BYTE; + break; + case 2: + w.type = atype.WORD; + break; + case 4: + w.type = atype.DWORD; + break; + } + return w; + } + private void AddToRamWatch() { //Add to RAM Watch int address = GetHighlightedAddress(); + + if (address >= 0 || SecondaryHighlightedAddresses.Count > 0) + { + Global.MainForm.LoadRamWatch(); + } + if (address >= 0) { - Watch w = new Watch(); - w.address = address; - w.bigendian = BigEndian; - w.signed = asigned.HEX; - - switch (DataSize) - { - default: - case 1: - w.type = atype.BYTE; - break; - case 2: - w.type = atype.WORD; - break; - case 4: - w.type = atype.DWORD; - break; - } - - Global.MainForm.LoadRamWatch(); - Global.MainForm.RamWatch1.AddWatch(w); + Global.MainForm.RamWatch1.AddWatch(MakeWatch(address)); + } + foreach (int addr in SecondaryHighlightedAddresses) + { + Global.MainForm.RamWatch1.AddWatch(MakeWatch(addr)); } } @@ -645,17 +658,27 @@ namespace BizHawk.MultiClient int address = GetHighlightedAddress(); if (IsFrozen(address)) { - UnFreezeAddress(); + UnFreezeAddress(address); } else { - FreezeAddress(); + FreezeAddress(GetHighlightedAddress()); + } + foreach (int addr in SecondaryHighlightedAddresses) + { + if (IsFrozen(addr)) + { + UnFreezeAddress(addr); + } + else + { + FreezeAddress(addr); + } } } - private void UnFreezeAddress() + private void UnFreezeAddress(int address) { - int address = GetHighlightedAddress(); if (address >= 0) { Cheat c = new Cheat(); @@ -702,9 +725,8 @@ namespace BizHawk.MultiClient MemoryViewerBox.Refresh(); } - private void FreezeAddress() + private void FreezeAddress(int address) { - int address = GetHighlightedAddress(); if (address >= 0) { Cheat c = new Cheat(); @@ -896,8 +918,9 @@ namespace BizHawk.MultiClient UpdateValues(); } - private void SetAddressOver(int x, int y) + private int GetPointedAddress(int x, int y) { + int address = -1; //Scroll value determines the first row int row = vScrollBar1.Value; int rowoffset = y / fontHeight; @@ -920,15 +943,15 @@ namespace BizHawk.MultiClient if (row >= 0 && row <= maxRow && column >= 0 && column < (16 / DataSize)) { - addressOver = row * 16 + (column * DataSize); + address = row * 16 + (column * DataSize); info = String.Format(NumDigitsStr, addressOver); } else { - addressOver = -1; + address = -1; info = ""; } - AddressLabel.Text = GenerateAddressString(); + return address; } private void HexEditor_ResizeEnd(object sender, EventArgs e) @@ -938,20 +961,64 @@ namespace BizHawk.MultiClient private void AddressesLabel_MouseMove(object sender, MouseEventArgs e) { - SetAddressOver(e.X, e.Y); + addressOver = GetPointedAddress(e.X, e.Y); Pointedx = e.X; Pointedy = e.Y; } private void AddressesLabel_MouseClick(object sender, MouseEventArgs e) { - SetAddressOver(e.X, e.Y); - if (addressOver == addressHighlighted && addressOver >= 0) + int addressOver = GetPointedAddress(e.X, e.Y); + if (addressOver >= 0) { - ClearHighlighted(); + if ((Control.ModifierKeys & Keys.Control) == Keys.Control) + { + if (addressOver == addressHighlighted) + { + ClearHighlighted(); + } + else if (SecondaryHighlightedAddresses.Contains(addressOver)) + { + SecondaryHighlightedAddresses.Remove(addressOver); + } + else + { + SecondaryHighlightedAddresses.Add(addressOver); + } + } + else if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift) + { + if (addressOver > 0) + { + SecondaryHighlightedAddresses.Clear(); + if (addressOver < addressHighlighted) + { + for (int x = addressOver; x < addressHighlighted; x++) + { + SecondaryHighlightedAddresses.Add(x); + } + } + else if (addressOver > addressHighlighted) + { + for (int x = addressHighlighted + DataSize; x <= addressOver; x++) + { + SecondaryHighlightedAddresses.Add(x); + } + } + } + } + else if (addressOver == addressHighlighted) + { + ClearHighlighted(); + } + else + { + SetHighlighted(addressOver); + SecondaryHighlightedAddresses.Clear(); + } + + MemoryViewerBox.Refresh(); } - else if (addressOver >= 0) - SetHighlighted(addressOver); } private void ClearHighlighted() @@ -1000,6 +1067,20 @@ namespace BizHawk.MultiClient else e.Graphics.FillRectangle(new SolidBrush(Global.Config.HexHighlightColor), rect); } + foreach (int address in SecondaryHighlightedAddresses) + { + Rectangle rect = new Rectangle(GetAddressCoordinates(address), new Size(15 * DataSize, fontHeight)); + e.Graphics.DrawRectangle(new Pen(Brushes.Black), rect); + + if (Global.CheatList.IsActiveCheat(Domain, address)) + { + e.Graphics.FillRectangle(new SolidBrush(Global.Config.HexHighlightFreezeColor), rect); + } + else + { + e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0x77FFD4D4)), rect); //TODO: better color + } + } if (HasNibbles()) { e.Graphics.DrawString(MakeNibbles(), new Font("Courier New", 8, FontStyle.Italic), Brushes.Black, new Point(8,10)); @@ -1086,7 +1167,7 @@ namespace BizHawk.MultiClient if (e.Modifiers == Keys.Shift) RemoveAllCheats(); else - UnFreezeAddress(); + UnFreezeAddress(GetHighlightedAddress()); break; case Keys.W: if (e.Modifiers == Keys.Control) @@ -1339,6 +1420,26 @@ namespace BizHawk.MultiClient private void ViewerContextMenuStrip_Opening(object sender, CancelEventArgs e) { + if (addressHighlighted > 0 || SecondaryHighlightedAddresses.Count() > 0) + { + copyToolStripMenuItem1.Visible = true; + } + else + { + copyToolStripMenuItem1.Visible = false; + } + + IDataObject iData = Clipboard.GetDataObject(); + + if (iData.GetDataPresent(DataFormats.Text)) + { + pasteToolStripMenuItem1.Visible = true; + } + else + { + pasteToolStripMenuItem1.Visible = false; + } + if (IsFrozen(GetHighlightedAddress())) { freezeToolStripMenuItem.Text = "Un&freeze"; @@ -1356,11 +1457,11 @@ namespace BizHawk.MultiClient GoToSpecifiedAddress(); } - private string GetHighlightedValue() + private string ValueString(int address) { - if (addressHighlighted != -1) + if (address != -1) { - return String.Format(DigitFormatString, (int)MakeValue(addressHighlighted)).Trim(); + return String.Format(DigitFormatString, (int)MakeValue(address)).Trim(); } else { @@ -1376,7 +1477,7 @@ namespace BizHawk.MultiClient prompt.HexOnly = true; if (addressHighlighted > 0) { - prompt.SetInitialValue(GetHighlightedValue()); + prompt.SetInitialValue(ValueString(GetHighlightedAddress())); } prompt.ShowDialog(); @@ -1432,16 +1533,25 @@ namespace BizHawk.MultiClient } } - private void copyToolStripMenuItem_Click(object sender, EventArgs e) + private void Copy() { - string value = GetHighlightedValue(); + string value = ValueString(GetHighlightedAddress()); + foreach (int x in SecondaryHighlightedAddresses) + { + value += MakeValue(x); + } if (!String.IsNullOrWhiteSpace(value)) { Clipboard.SetDataObject(value); } } - private void pasteToolStripMenuItem_Click(object sender, EventArgs e) + private void copyToolStripMenuItem_Click(object sender, EventArgs e) + { + Copy(); + } + + private void Paste() { IDataObject iData = Clipboard.GetDataObject(); @@ -1457,8 +1567,8 @@ namespace BizHawk.MultiClient int address = addressHighlighted + i; Domain.PokeByte(address, (byte)value); } + UpdateValues(); - } else { @@ -1466,6 +1576,11 @@ namespace BizHawk.MultiClient } } + private void pasteToolStripMenuItem_Click(object sender, EventArgs e) + { + Paste(); + } + private void findToolStripMenuItem1_Click(object sender, EventArgs e) { Find(); @@ -1504,5 +1619,15 @@ namespace BizHawk.MultiClient Global.Config.HexHighlightColor = Color.Pink; Global.Config.HexHighlightFreezeColor = Color.Violet; } + + private void copyToolStripMenuItem1_Click(object sender, EventArgs e) + { + Copy(); + } + + private void pasteToolStripMenuItem1_Click(object sender, EventArgs e) + { + Paste(); + } } } \ No newline at end of file