News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Mega Man - Refill Weapon Energy after Death  (Read 2915 times)

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Mega Man - Refill Weapon Energy after Death
« 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: To be expected
- Mega Man Xtreme 2: To be expected
- Mega Man 7: made by DarkSamus993
- Mega Man X1: made by DarkSamus993
- Mega Man X2: made by DarkSamus993
- Mega Man X3: made by DarkSamus993, Zero Project compatibility follows
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, along with a Mega Man & Bass one.

I'm working on Mega Man Xtreme 1 and 2 at the moment.

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!"
« Last Edit: October 31, 2019, 04:15:31 pm by Thirteen 1355 »
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #1 on: September 13, 2019, 09:20:47 am »
Yes it would. Start with finding weapon meters in RAM, then we can talk
I am the baldest romhacker
NES Romhacking Guide

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #2 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.
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #3 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
I am the baldest romhacker
NES Romhacking Guide

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #4 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.
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #5 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?
I am the baldest romhacker
NES Romhacking Guide

Gemini

  • Hero Member
  • *****
  • Posts: 2016
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: Mega Man - Restore Weapon Energy after Death
« Reply #6 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.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #7 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.

Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #8 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
I am the baldest romhacker
NES Romhacking Guide

nesrocks

  • Hero Member
  • *****
  • Posts: 606
    • View Profile
    • nesrocks.com
Re: Mega Man - Restore Weapon Energy after Death
« Reply #9 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.

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #10 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.
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #11 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
I am the baldest romhacker
NES Romhacking Guide

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #12 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.

Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #13 on: September 13, 2019, 01:53:52 pm »
That will do. Now, any ideas of what the next step should be?
I am the baldest romhacker
NES Romhacking Guide

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #14 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.
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #15 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.
« Last Edit: September 14, 2019, 09:20:04 am by Cyneprepou4uk »
I am the baldest romhacker
NES Romhacking Guide

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #16 on: September 14, 2019, 05:26:15 am »
Think I got it (took a bit). Gonna check it out today.
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #17 on: September 14, 2019, 08:53:57 am »
Any questions about this whole thing so far?
I am the baldest romhacker
NES Romhacking Guide

Thirteen 1355

  • Sr. Member
  • ****
  • Posts: 475
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #18 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?
« Last Edit: September 14, 2019, 03:41:45 pm by Thirteen 1355 »
Helicoptering about till I find some ROM hacking treasure.

Cyneprepou4uk

  • Full Member
  • ***
  • Posts: 186
  • Самый лысый ромхакер
    • View Profile
Re: Mega Man - Restore Weapon Energy after Death
« Reply #19 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.
I am the baldest romhacker
NES Romhacking Guide