emukidid / swiss-gc

Swiss - The swiss army knife of GameCube homebrew
GNU General Public License v2.0
1.23k stars 93 forks source link

Metroid Prime 2: Echoes (NTSC-U) Conditionals Don't Work #793

Closed ReclaimerShawn closed 5 months ago

ReclaimerShawn commented 1 year ago

Describe the bug

Basically, it seems as if some, if not all the codes with button conditionals on Metroid Prime 2 refuse to work. I have seen Code Types 28 and 20 fail in-game so far. I have also confirmed that the button address is the same as the reported address for codes while Swiss is running via USB Gecko, so this shouldn't be happening unless something's wrong on the end of the codehandler. Codes without conditionals seem to work.

Strangely enough, button conditionals work on Pokemon Colosseum, which makes me think this issue may be specific to Metroid Prime 2. This issue is present so far in r1387 and r1420. This bug might exist on versions even further back, as well.

Steps to reproduce

Use any code with Code Types 28 and/or 20 and you'll see them fail. For example, place this code in a cheat file and attempt to use it in-game: Enable Phazon Shot (Press L+R) 28704C24 00000060 041CC824 3B600004 041CC9BC 3BE00004 041DA590 3A600004 E2000001 80008000

However, this code without the button modifier works: Enable Phazon Shot 041CC824 3B600004 041CC9BC 3BE00004 041DA590 3A600004

If you cannot reproduce this issue, it must be on my end. I've tried with a regular controller and a wavebird controller and gotten the same results, if that matters.

Expected behavior

Pressing L+R on the Enable Phazon Shot code above should enable the code, and from there, the code should function like the code without the button conditional does. The code would normally cause your beam to shoot circular blue blasts, but this doesn't happen with the version of the code that has the button conditional.

Relevant log output

No response

Add screenshots

No response

Diegorella commented 1 year ago

you must disable IPL boot. and the igr. and see if it works...

ReclaimerShawn commented 1 year ago

you must disable IPL boot. and the igr. and see if it works...

Neither were or are enabled. I've changed no settings from default.

ReclaimerShawn commented 1 year ago

Issue is still present in r1443.

ReclaimerShawn commented 5 months ago

@emukidid @Extrems Button activators are able to work after applying the following Master Code: (M) C6354E70 800018A8 //Hook 80354E70 to 800018A8 C636F000 800018A8 //Hook 8036F000 to 800018A8 2130294C 4E800020 //If 8130294C == 4E800020 (blr instruction) then C730294C 800018A8 //Hook 8130294C to 800018A8 0441FD80 00000000 // 8041FD80 = 0 E0000000 80008000 //End

Roughly, here's what this code does: 80354E70 = 0x494A9238 (Set instruction to b 0x817FE0A8. I expected a b 0x800018A8, but perhaps Swiss stores its hook elsewhere, so Swiss's codehandler might've automatically changed the instruction.) 8036F000 = 0x4948F0A8 (Set instruction to b 0x817FE0A8. I expected a b 0x800018A8, but perhaps Swiss stores its hook elsewhere, so Swiss's codehandler might've automatically changed the instruction.)

If 8130294C == 0x4E800020 then 8130294C = 0x484FB75C (Set instruction to b 0x817FE0A8. Didn't see this get set in real time, so not 100% certain, but considering this is where the other hooks branched to, probably it.) 8041FD80 = 0x00000000 End

I never saw 8130294C equal the blr instruction and I never saw 8041FD80 equal anything other than 0 in my short amount of time testing the code. If you want to fix the codehandler issue, put at least the first two lines into the DOL patcher to patch the game DOL before the game starts. If necessary, add the rest if crashes or restarts occur. I recommend including this not just to fix the codehandler, but also to allow the USB Gecko to hook, as the USB Gecko can only hook when this code is enabled.

Extrems commented 5 months ago

Let's see... 80354E70 is VIGetTvFormat. 8036F000 is ICFlashInvalidate. 8130294C is DCInvalidateRange in apploader.

This seems random.

ReclaimerShawn commented 5 months ago

@Extrems It was originally a code made by CodeJunkies in the ARMax era, but goemon_guy converted every line except the last one to WiiRD. The forum posts where he did that are here: https://wiird.gamehacking.org/forum/index.php/topic,5823.225.html.

Later on in the thread, it appears the same patches used for Pokemon Colosseum in Swiss also originated from goemon_guy and this thread. I personally do not know how the Master Code works other than what the codetypes mean, but it does fix the problem. My guess is it sets up the VI hook that Gecko OS would use on the game.

If you want to test to see I'm right, try using any code with the button address without the (M) code and it'll fail. You could also try to enable WiiRD debugging and use a USB Gecko. It will also fail to connect without the M code.

The code isn't a full fix for the entire codehandler (for instance, you're apparently not able to take a full mem80/81 dump, only partial segments at a time), but it does fix the problem reported in this issue. The other master code goemon_guy was trying to write presumably would fix any problems in the codehandler, but it crashes the game at the title screen. So, this would serve as a full bug fix for the button conditional issue and a partial bug fix for USB Gecko debugging.

Extrems commented 5 months ago

Fixed in 503186b (r1589).