Advertiser Content

Pokeemerald Create a debug menu

Started by ThomasWinwood April 21st, 2019 11:09 AM
  • 1235 views
  • 6 replies

ThomasWinwood

Male
Seen 4 Hours Ago
Posted 4 Hours Ago
86 posts
5.9 Years
I learned about windows and list menus today, and I've written a short-ish tutorial on how to add a debug menu to pokeemerald using the same hooks Game Freak used for their own debug menu in order to try and help others in turn. BBcode depresses me, so I've hosted it as a gist.

If you're a better C programmer than me or more familiar with the pokeemerald codebase, I'd like to know about any ways in which I can do what I'm doing more efficiently. In particular, having three different lists which need to be kept in sync strikes me as odd; I considered writing a macro, but then I remembered how C's macro system works and decided not doing that sounded way more fun.
The rival in Red and Blue is called Green. Gary is some character from a lame cartoon.

Sidrk

Professional Lurker

Age 24
Male
India
Seen 1 Week Ago
Posted July 26th, 2019
145 posts
10.6 Years
Thanks a lot for the tutorial! I'm still in the process of understanding it completely, but for now I've just added your code as it is, and I'm facing this error:

`Debug_ShowMainMenu' referenced in section `.text' of src/field_control_avatar.o: defined in discarded section `.text' of src/debug.o
make: *** [Makefile:204: pokeemerald.elf] Error 1
Do you have any idea why that would be happening?

ThomasWinwood

Male
Seen 4 Hours Ago
Posted 4 Hours Ago
86 posts
5.9 Years
You need to add src/debug.o to the linker script. It looks like I forgot to mention that, possibly because I replaced it with one that didn't include filenames individually by name. (Presumably eventually someone will fork pokeemerald to make it more suited to ROM hacking, and you won't have to do this anymore.)

1. Open ld_script.txt.
2. Find the line src/start_menu.o(.text);; add a new line after it that says src/debug.o(.text);.
3. Find the line src/start_menu.o(.rodata);; add a new line after it that says src/debug.o(.rodata);.
The rival in Red and Blue is called Green. Gary is some character from a lame cartoon.

Sidrk

Professional Lurker

Age 24
Male
India
Seen 1 Week Ago
Posted July 26th, 2019
145 posts
10.6 Years
You need to add src/debug.o to the linker script. It looks like I forgot to mention that, possibly because I replaced it with one that didn't include filenames individually by name. (Presumably eventually someone will fork pokeemerald to make it more suited to ROM hacking, and you won't have to do this anymore.)

1. Open ld_script.txt.
2. Find the line src/start_menu.o(.text);; add a new line after it that says src/debug.o(.text);.
3. Find the line src/start_menu.o(.rodata);; add a new line after it that says src/debug.o(.rodata);.
Thanks a lot! That worked There's only a minor problem where unless I open the Start Menu once the palette for the border is garbled, but I don't think that should be an issue and instead I'll work on actually adding debug options to this

Sidrk

Professional Lurker

Age 24
Male
India
Seen 1 Week Ago
Posted July 26th, 2019
145 posts
10.6 Years
Thanks a lot! That worked ������ There's only a minor problem where unless I open the Start Menu once the palette for the border is garbled, but I don't think that should be an issue and instead I'll work on actually adding debug options to this

I was able to fix this by looking at start_menu.c and map_popup_menu.c: the issue seems to have been caused by 1) the game not loading the gfx/palettes for the border and 2) the map popup obscuring the debug window since it's on the left



To fix the problem, add the Map Popup Header

#include "map_name_popup.h"
to the top, then add these lines

HideMapNamePopUpWindow();
sub_81973A4();
Above the lines indicated by // create window.

The function sub_81973A4(); doesn't seem to have been renamed, but this is what it looks like, in case anyone was wondering:

void sub_81973A4(void)
{
    LoadMessageBoxGfx(0, DLG_WINDOW_BASE_TILE_NUM, DLG_WINDOW_PALETTE_NUM * 0x10);
    LoadUserWindowBorderGfx(0, STD_WINDOW_BASE_TILE_NUM, STD_WINDOW_PALETTE_NUM * 0x10);
}
I spent an obscene amount of time trying to figure this out, but I intend to make a general purpose debug menu at some point that romhackers can use for easy testing.
Non-binary
USA-PST
Seen 4 Days Ago
Posted August 6th, 2019
9 posts
137 Days
how to you make a build without the debug menu once you implement it? I tried just plain make, added an else clause to debug in the makefile that sets the flags to 0 if no param is sent. each time the compiler just either said "nothing to do for 'rom'", or it copied cached data from pokeemerald.elf. I even tried deleting the elf file, but the code constrained under the debug flags is still functional in game. I'm nowhere near anything worth putting out yet, but I thought I would see if my code worked without the debug functions or if I had botched something. glad I caught it now rather than later, but I still have no idea how to fix it.

ThomasWinwood

Male
Seen 4 Hours Ago
Posted 4 Hours Ago
86 posts
5.9 Years
added an else clause to debug in the makefile that sets the flags to 0 if no param is sent
I don't have a repo set up to check, but this isn't necessary and is probably the source of the problem you're having. #if DEBUG isn't checking whether DEBUG is equal to 1 - it's checking whether it's set at all. Setting DEBUG to 0 is still setting it, so your debug code is always compiled.
The rival in Red and Blue is called Green. Gary is some character from a lame cartoon.
Advertiser Content