Romhacking.net

Romhacking => Newcomer's Board => Topic started by: Thirteen 1355 on September 13, 2019, 09:01:18 am

Title: Mega Man - Refill Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 09:01:18 am
This thread discusses the possibility of making weapon energy restore when losing a life in the older Mega Man games. Turns out it's possible! With the help of some others, I've managed to cobble together some patches that achieve this:
- Mega Man 1: Published! https://www.romhacking.net/hacks/4671/
- Mega Man 2: Published! https://www.romhacking.net/hacks/4682/
- Mega Man 3: Published! https://www.romhacking.net/hacks/4689/
- Mega Man 4: Published! https://www.romhacking.net/hacks/4720/
- Mega Man 5: Published! https://www.romhacking.net/hacks/4743/
- Mega Man 6: Published! https://www.romhacking.net/hacks/4758/
- Mega Man World 1: Published! https://www.romhacking.net/hacks/4702/
- Mega Man World 2: Published! https://www.romhacking.net/hacks/4711/
- Mega Man World 3: Published! https://www.romhacking.net/hacks/4733/
- Mega Man World 4: Published! https://www.romhacking.net/hacks/4745/
- Mega Man World 5: Published! https://www.romhacking.net/hacks/4746/
- Mega Man: The Wily Wars: Published! https://www.romhacking.net/hacks/4760/
- Mega Man Xtreme: Published! https://www.romhacking.net/hacks/4827/
- Mega Man Xtreme 2: Published! https://www.romhacking.net/hacks/4828/
- Mega Man 7: made by DarkSamus993
- Mega Man & Bass: made by DarkSamus993
- Mega Man X1: made by DarkSamus993
- Mega Man X2: made by DarkSamus993
- Mega Man X3 + Zero Project: made by DarkSamus993
I intend to upload each Mega Man Refill patch as soon as I've fully played through each game. DarkSamus eventually intends to upload his own patches.

Original post:
"Helloe,
I would like to get a bit more experienced with ROM hacking, and I thought this matter would be an ideal start for me. I want to change the earlier Mega Man games, namely, 1, 2, 3, 4, 5, 6, 7, X1, X2, X3, so that, once you lose a life, your weapon energy meter gets fully refilled, like in the later Mega Man games. My question right now is: Where to start? FCEUX has a handy hex editor, would that be a good beginning point? Any help is appreciated!"
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 09:20:47 am
Yes it would. Start with finding weapon meters in RAM, then we can talk
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 10:00:11 am
Seems the offset for the weapons are spread across the row of 0x00006, in the case of Mega Man 1. In the case of Mega Man 2, the weapon meters are spread across 0x00009 and 0x0000A.

Whenever you use a weapon, it goes from 1C to another value depending on how much energy a weapon uses per shot. Entering the cheat code '006B:1C' for Mega Man 1 will keep the Rolling Cutter suspended on value 1C, basically giving you infinite weapon energy for that specific weapon.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 10:06:28 am
Very nice. Now find his hp, and show me code that refills hp after death, by adding a write breakpoint to it
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 10:33:11 am
Mega Man's HP is on offset 0x00006A. Adding a write breakpoint and letting poor guy die made this show up:
05:BFAA
https://drive.google.com/open?id=1shlfjNpFZtHAcQFcPne2bFSjvr-VnlI6

I went to look at offset 0x00BFAA and noticed it quickly changing once Mega was brought back to life. However, many other values around that one did the same.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 10:36:45 am
Scroll it a up so I can see code above as well.

Also, while emulator is paused after breakpoint triggers at $BFAA, is there any free space in $8000-$FFFF?
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Gemini on September 13, 2019, 10:38:09 am
I would put a breakpoint on write for Megaman's health, make it trigger after a death, that should give you the address of the routine that refills energy post death. Now alter the routine to also refill all weapons and it's done.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 11:36:25 am
Scroll it a up so I can see code above as well.

Also, while emulator is paused after breakpoint triggers at $BFAA, is there any free space in $8000-$FFFF?

https://drive.google.com/open?id=1CCt2kFFqQfbldpnrW1A2YLSouu5XT4_f
This shows the code above.

https://drive.google.com/open?id=1N4O4bdroKAclERo58l7_dSqhkswFYnhe
And this shows free space I found in 0x008F58 through 0x008F6F.

Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 11:52:45 am
That is not refilling his hp code. Game is writing #00 to $006A. Keep searching for another breakpoint hit

Doesn't look like a 100% free space to me, find something else
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: nesrocks on September 13, 2019, 11:54:09 am
Doesn't the game already have code that refills all weapons when using a continue? I don't remember exactly.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 12:58:52 pm
Aha, so I just reported the first breakpoint trigger it gave, once I fell in the pit. This is the second trigger, which happens just before the screen goes from black to back to the level (the exact same moment the HP goes from 00 back to 1C):
https://drive.google.com/open?id=1BT36e8Qk8UPIjBhjETCbSw8kRk8aUsDZ

https://drive.google.com/open?id=13PBdvaaKS6uqBpWm_ctF8ErEiynbrTYt
Here's free space I found. What I did wrong last time was to simply look for free space in the NES Memory, rather than the ROM File.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 01:13:18 pm
Yes, this is the code we were looking for.

No, you need to find free space in $8000-$FFFF in NES Memory after breakpoints hits at $912E and pauses emulator. Not in ROM File

Doesn't the game already have code that refills all weapons when using a continue? I don't remember exactly.

I think it has
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 01:44:44 pm
https://drive.google.com/open?id=19ltxiy_L8-wtP9fHPv1u1lxNbohn_e_M

This is the biggest free space part I could find, from 0X008FC3-0x008FFF.

Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 01:53:52 pm
That will do. Now, any ideas of what the next step should be?
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 13, 2019, 02:41:14 pm
Good question. I think something will need to be inserted in the free space that makes the refilling of HP apply to weapon energy as well. Got no idea on how to do that.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 13, 2019, 03:46:45 pm
You need to jump to that free space, into $8FD0 for example, and execute your new code here. Then jump backwards to keep original flow of game code intact.

Jump should begin from $912C. Instead of LDA + STA that are already here, you write a JMP instruction (there is an example of JMP in $9129). The fourth remaining byte overwrite with #EA. In $8FD0 paste those original LDA + STA, and add a bunch of STA's to weapon addresses. I suppose you want #1C value into them as well, so you don't need to add another LDA before new STA's. And a JMP to $9130 in the end, so original code will be able to jump back and execute whatever he needed to execute afterwards. Check with debugger to see if you wrote everything correctly.

Since you can't edit code in NES Memory directly, right click on wanted address in Hex Editor and choose "Go here in ROM File". And you might wanna add an execute breakpoint to $912C by double clicking on that address in debugger, to test code later using Step Into button. If you want to test new code right away after your old write breakpoint hit, first change address near Seek PC button to $912C and press it.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 14, 2019, 05:26:15 am
Think I got it (took a bit). Gonna check it out today.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 14, 2019, 08:53:57 am
Any questions about this whole thing so far?
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 14, 2019, 09:37:46 am
Done it all. It took a while to get the logic behind the steps you need to perform, but thanks to a guide and a friend who has some knowledge on opcodes, the pieces came together.

Wrote down a little thingy for myself, which I eventually can use for the other five games:
Mega Man 1
- Health Offset: 0x00006A
- Weapon Offsets:0x00006B
       0x00006C
       0x00006D
       0x00006E
       0x00006F
       0x000070
       0x000071
- Breakpoint trigger for Health refill: 05:912E
- Free space: 0X008FC3-0x008FFF
- How to make a jump command:
Trigger the breakpoint, which opens the debugger. Switch to ROM File.
Change the byte at the offset preceeding the triggered command (in this case, 912C, preceeding 912E) from 85 to 4C
(4C being the 'jump' command).
Then, change the arguments (the offset it will jump to) from A26A to the first byte of the free space
(in this case, 8FD0). Be aware that the bytes are written backwards in the hex editor. So first you write D0, next byte 8F.
Replace the byte following the argument (13) with EA.
- Add new commands in free space:
Switch to NES Memory. Head to the free space (8FD0). Switch back to ROM File. First, add an LDA command (A9).
The next byte, what the LDA will refer to, should be 1C (the maximum amount of health/weapon energy).
Add an STA (85) to the next byte. Then, add the byte referring to the offset of health (6A).
Repeat these two steps until you've covered every offset for weapon energy. The result should look like this:
  85  6A  85  6B  85  6C  85  6D  85  6E  85  6F  85  70
  85  71  00  00  00  00  00  00  00  00  00  00  00  00
Then, add a jump to the next free byte. Make the jump refer to the beginning of the offset after the triggered command
(in this case, 9130, following 912E). First you write 30, next byte 91.

September 14, 2019, 09:41:21 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Now, I looked a little bit into doing this for MM7 and the X games, and it seems like a ten times bigger job.

September 14, 2019, 02:11:55 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Well, seems this won't do much for all the other NES games. Mega Man 2 has its health value at a pretty late offset, a problem which I thought could be circumvented by using an alternate STA, but the game resets whenever you enter a stage.

Mega Man 3 works, except it gives you every weapon from the start of the game. Didn't plan on doing that. Mega Man 4 freezes except for the stage I was in when triggering the breakpoint, Bright Man.

September 14, 2019, 02:32:24 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Okay, so, Mega Man 2 just needed a few more EAs to fix it all. Apparently I mistook sprite data for 'free space' in MM3.

September 14, 2019, 03:41:45 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Any questions about this whole thing so far?
What's the reason I had to look for free space only between 008000 and 00FFFF?
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 14, 2019, 04:15:09 pm
Because this is how CPU works. It is limited to "see" only 32 KB from ROM File at a time. So CPU loads other banks of memory from ROM File into NES Memory to $8000-$FFFF location. He can select many different banks during a single frame.

Since you can't switch memory banks at your current level, free space in ROM File is basically useless to you now. You need to use a bank which is currently loaded in NES Memory during a breakpoint hit.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 14, 2019, 06:30:42 pm
Okay, so, Mega Man 1 and 2 should be all good. Tested them quite a bit and they seem to work. However, with Mega Man 3, I start off with all weapons without having defeated any Robot Master. The weapons refill after death like they should, though. Does this problem have to do with Mega Man 3 having more banks to load than the earlier games? Also, when I get hit my health goes to 6 immediately, when I use a weapon, its energy gets reduced to 6 as well.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Cyneprepou4uk on September 14, 2019, 06:43:22 pm
Quote
Mega Man 3, I start off with all weapons without having defeated any Robot Master
This will be harder. You need to find some flags in RAM that tell the game if player has a particular weapon or not (it can be a single address if you are unlucky). Then use these addresses to check for necessity of refilling those weapons, one by one. Creating a loop would be nice.

Quote
Does this problem have to do with Mega Man 3 having more banks to load than the earlier games?
Nope. It's how game code works, not how many banks or whatever.

Quote
Also, when I get hit my health goes to 6 immediately, when I use a weapon, its energy gets reduced to 6 as well
I can't tell from here, I need to see original and your code to say what can be wrong. Obviously original game works fine, then it must be something that you've done.
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: DarkSamus993 on September 15, 2019, 12:35:47 am
Now, I looked a little bit into doing this for MM7 and the X games, and it seems like a ten times bigger job.
Here's the patch files and source code I made for weapon refilling for MM7 and MMX1-3: https://drive.google.com/open?id=10w5bmcswE8VmJdBkLV4w9jfXn_JgI6YK

The process was simple:
1) find the subroutine for filling weapon energy when a stage is loaded.
2) find when the life counter is decreased (player died) and hijack it to also run the 'refill weapon energy' subroutine.

The 'refill weapon energy' subroutine checks if the boss is beaten by seeing if the proper bit is set in the weapon energy RAM value. This results in circular checks:
 - you beat the boss so you have the weapon (when starting a stage).
 - you earned the weapon so you beat the boss (when going through the boss doors).
Title: Re: Mega Man - Restore Weapon Energy after Death
Post by: Thirteen 1355 on September 15, 2019, 05:25:41 am
Here's the patch files and source code I made for weapon refilling for MM7 and MMX1-3: https://drive.google.com/open?id=10w5bmcswE8VmJdBkLV4w9jfXn_JgI6YK

The process was simple:
1) find the subroutine for filling weapon energy when a stage is loaded.
2) find when the life counter is decreased (player died) and hijack it to also run the 'refill weapon energy' subroutine.

The 'refill weapon energy' subroutine checks if the boss is beaten by seeing if the proper bit is set in the weapon energy RAM value. This results in circular checks:
 - you beat the boss so you have the weapon (when starting a stage).
 - you earned the weapon so you beat the boss (when going through the boss doors).

Great job as always. Thanks a load!
After all these I plan to give Mega Man V for the Game Boy a try, and if I'm able to, Wily Wars for Genesis (though that one I can see some roadblocks for).

September 15, 2019, 09:10:58 am - (Auto Merged - Double Posts are not allowed before 7 days.)
Fiddled around with flags for MM3, and I think I found a way to help this all.

September 16, 2019, 03:20:02 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
With some help from DarkSamus, Mega Man 3 now has a working health refill edit!

4, 5 and 6 should follow suit!

September 19, 2019, 03:32:00 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Mega Man 4's doing a little strange, in that I got energy refilling working all right, except it's only working in the stage I triggered the breakpoint in (Bright Man's stage). Upon selecting another stage, the screen goes and stays black instead of loading the stage.

September 19, 2019, 06:46:34 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Another update no one will notice since my posts keep merging, but Mega Man 5's refill edit seems to work all good. Very strange considering MM4's situation.
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Thirteen 1355 on September 26, 2019, 04:07:49 pm
The Mega Man 4 patch is all done! The Mega Man 1 and 2 refill patches have been uploaded to romhacking.net

Mega Man 5 is probably done but needs to be tested still. All that remains is the Mega Man 6 patch and maybe the Game Boy Mega Man games, and Mega Man & Bass but that one's being covered by DarkSamus993.

Right now I'd like to focus on the Game Boy Mega Man games. Anyone got any leads on that?
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Cyneprepou4uk on October 02, 2019, 08:39:31 am
It's basically the same method for other platforms as well. Find addresses, find free space, write code and execute it. Or use existing refilling weapons routine if you've got the skills, like DarkSamus993.

I'm not a gameboy romhacker, so I can't help with that. I would start with googling for an emulator with debugger.
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Thirteen 1355 on October 02, 2019, 12:56:25 pm
Yep, right now me and a friend are in the process of tackling all the GB games (maybe the Xtreme games as well). I found BGB, a GB emu with debugger. Finding the right values was easy. Now it's just a matter of understanding Game Boy coding. What helps is that finding free space in these games is way easier.

After that I have time to test the games, including MM4 and 5, whose patches I will upload once done with them. Then only MM6 remains.

October 03, 2019, 06:57:17 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
EDIT
I managed to edit all the Game Boy Mega Man games (save for Xtreme, which will likely follow). Trying the weapons out in Wily Stages produces satisfactory results for each of the five games. Now I just need to play through all of them. If they are 100% alright, I will submit them shortly after.
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Thirteen 1355 on October 19, 2019, 08:36:06 am
UPDATE:
Next week I will have a lot more time for testing and hacking Mega Man. The pace of uploading these patches will be picked up quite a bit. Mega Man 6 and all the GB games should be good, but I still want to play through all of them just to be sure (I found a small issue in MM5's ROM while testing, and there I also believed everything was perfect). Mega Man 9, 10 and Wily Wars are still the main focus of figuring out. Haven't had much time to look into these. I've done some research on Xtreme as well. Seems to work the same way as the other GB games except that, as usual in the X series, the max health value isn't always the same throughout the game. I will soon start thinking of ways to get around that tidbit.
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Thirteen 1355 on October 31, 2019, 04:16:26 pm
Editing the WAD files for Mega Man 9 and 10 seems to go nowhere. We finally could get into looking for free space but there's barely any in there. Focus will now go to Mega Man Xtreme, and I wanna look into the SNES games myself as well.
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Thirteen 1355 on December 05, 2019, 05:59:34 pm
I just submitted the refill patch files for Mega Man Xtreme 1 and 2. I do have patches of the SNES X games, but as of yet, I haven't had permission to upload them from DarkSamus.
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Trumpster on January 05, 2020, 06:55:20 pm
Hey man. Do you have a link for the DarkSamus Megaman 7 one? Thanks for your hard work, God bless you!
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: DarkSamus993 on January 06, 2020, 09:26:15 am
Mega Man 7, Mega Man X1-3: https://drive.google.com/open?id=10w5bmcswE8VmJdBkLV4w9jfXn_JgI6YK

Mega Man & Bass (translation is also compatible) (http://www.romhacking.net/translations/621/), Mega Man X3 (Zero Project) (http://www.romhacking.net/hacks/4086/): https://drive.google.com/open?id=1hcxrJzpZqN6z8NlVzfwMjV03_9XX8Hm0
Title: Re: Mega Man - Refill Weapon Energy after Death
Post by: Trumpster on January 21, 2020, 07:40:33 pm
Mega Man 7, Mega Man X1-3: https://drive.google.com/open?id=10w5bmcswE8VmJdBkLV4w9jfXn_JgI6YK

Mega Man & Bass (translation is also compatible) (http://www.romhacking.net/translations/621/), Mega Man X3 (Zero Project) (http://www.romhacking.net/hacks/4086/): https://drive.google.com/open?id=1hcxrJzpZqN6z8NlVzfwMjV03_9XX8Hm0

Thank you so much, man! You're the best!