Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemoryWidget: Add 'Offset' and General Improvements #9080

Merged
merged 1 commit into from Jan 28, 2021

Conversation

SirMangler
Copy link
Contributor

Summary of changes:

  • Added a new field for Search Address Offset
  • Fixed a hard crash when trying set a value while the core is not running.
  • Brushed up the UI and spacing

The primary change here is adding an Offset field next to Search Address. All this does is add the offset to the supplied search address. While this sounds mediocre on paper, this is incredibly convenient for hack and cheat developers (and especially reverse engineers) who frequently work with base addresses and classes. I have been working on PrimeHack for nearly a year, and I constantly need to work with addresses that are offset from dynamically allocated classes in memory. Adding this simple Offset field streamlines traversing through large classes in memory rather than the otherwise clunky process.

The Offset field is resizeable and can be totally collapsed if wanted, but it really doesn't get in the way of the regular Search Address. The Find Next/Find Previous buttons work as expected, they simply clear the offset field if it finds a result.

Before/After
image

@shuffle2
Copy link
Contributor

fwiw ctrl+k,ctrl+d is "format document" in VS (also a named action in vscode / shift+alt+f)

@AdmiralCurtiss
Copy link
Contributor

Not sure if I fully understand how the offset should be used, but otherwise looks fine to me. I could see extracting the 'calc address from GUI fields' code to a separate function so it's not there three times, maybe? But not a huge deal.

@Rumi-Larry
Copy link

All groups have a header, except for the dumping buttons. I suggest adding one saying "Memory Dump"

@Rumi-Larry
Copy link

Also, the "Search" group should be closer to the actual search bar. Like after the "Set Value" button, the "Find Next" and "Find Previous" buttons should be right after, making the "Search" header unnecessary.

@SirMangler
Copy link
Contributor Author

All groups have a header, except for the dumping buttons. I suggest adding one saying "Memory Dump"

the "Search" group should be closer to the actual search bar.

Not bad suggestions!

Not sure if I fully understand how the offset should be used

Say hypothetically you have a class at address 8000000. At 8000004 you have it's health. 8000008 you have ammo. 800000C you have some random array. You can just do the 8000000 as the address, and in offset you put in 4 for health, 8 for ammo, C for the array.

Now sure that's easy to do in your head and easily change the search address field. But what if we use more real numbers, you have a function loading the address 805C72AB into r4, and an instruction loading 0x241(r4) (which means 805C72AB + 0x241 if you didn't know) into r5, and another instruction loading 0x14c(r4) into r6 (aka 801C72AB + 0x14c).

It does an operation, r5 + r6. You want to figure out the answer to that? You have to copy the register r4 into a calculator, add 0x241 to that, and paste the result into the memory search address field. Then once you note that value, you would have to copy register r4 again (most likely from an open notepad somewhere), paste into your calculator and add 0x14c. Paste that into the memory search address field and note that answer down.

Or with this new PR? Copy r4 into the memory search address field. Copy 0x241 into the offset and note the value. Copy 0x14c into the offset and note the second value.

I have to do this process a lot for a variety of different scenarios, this feature while very simple, would be a pretty big time saver. No more needing to store the address somewhere and open a calculator every time I need to calculate an offset without doing it in my head. Especially useful if you're trying to map out a class and have to go between several offsets to see what is doing what.

In the end, you can ignore it if you want, you can even collapse it so its hidden.

@JMC47
Copy link
Contributor

JMC47 commented Sep 16, 2020

Yeah, using offsets is something I see in a lot of other debugging GUIs and I believe it would be a nice feature to have in Dolphin's debugger too.

@AdmiralCurtiss
Copy link
Contributor

So while I'm not 100% happy with some of this, this works fine for what it's intended to do, so I don't really have any objections to just merging it as-is even if those are not addressed. The debugger needs more work anyway.

@SirMangler
Copy link
Contributor Author

Is this okay to be merged? It seems all specific issues and comments have been resolved.

@leoetlino leoetlino self-requested a review November 21, 2020 02:26
@@ -85,13 +86,23 @@ void MemoryWidget::CreateWidgets()
//// Sidebar

// Search
QSplitter* m_address_splitter = new QSplitter(Qt::Horizontal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, but there's no point in repeating the type name here:

Suggested change
QSplitter* m_address_splitter = new QSplitter(Qt::Horizontal);
auto* m_address_splitter = new QSplitter(Qt::Horizontal);

@@ -424,25 +443,34 @@ void MemoryWidget::SetAddress(u32 address)

void MemoryWidget::OnSearchAddress()
{
bool good;
u32 addr = m_search_address->text().toUInt(&good, 16);
bool good_addr, good_off;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool good_addr, good_off;
bool good_addr, good_offset;

off isn't a particularly common abbreviation for offset, and you use offset below, so I'd prefer to see it written out.


QFont font;
QPalette palette;
QFont addr_font, off_font;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QFont addr_font, off_font;
QFont addr_font, offset_font;

QFont font;
QPalette palette;
QFont addr_font, off_font;
QPalette addr_palette, off_palette;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QPalette addr_palette, off_palette;
QPalette addr_palette, offset_palette;

bool good;
u32 addr = m_search_address->text().toUInt(&good, 16);
bool good_addr, good_off;
u32 addr = m_search_address->text().toUInt(&good_addr, 16);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u32 addr = m_search_address->text().toUInt(&good_addr, 16);
const u32 addr = m_search_address->text().toUInt(&good_addr, 16);

u32 addr = m_search_address->text().toUInt(&good, 16);
bool good_addr, good_off;
u32 addr = m_search_address->text().toUInt(&good_addr, 16);
u32 offset = m_search_offset->text().toUInt(&good_off, 16); // Returns 0 if conversion fails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
u32 offset = m_search_offset->text().toUInt(&good_off, 16); // Returns 0 if conversion fails
// Returns 0 if conversion fails
const u32 offset = m_search_offset->text().toUInt(&good_offset, 16);

if (!Core::IsRunning())
return;

bool good_address, good_off;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

u32 addr = m_search_address->text().toUInt(&good_address, 16);
addr += m_search_offset->text().toUInt(&good_off, 16); // Returns 0 if conversion fails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be on its own line.

@SirMangler SirMangler force-pushed the debugger branch 4 times, most recently from 3f815e7 to 2b01633 Compare January 10, 2021 12:04
@leoetlino leoetlino changed the title MemoryWidget: Added 'Offset' and General Improvements MemoryWidget: Add 'Offset' and General Improvements Jan 28, 2021
@leoetlino leoetlino merged commit 4740c2a into dolphin-emu:master Jan 28, 2021
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants