squid-man / MegaMan2Randomizer2

Mega Man 2 Randomizer
8 stars 5 forks source link

Rewrite password system #21

Open dagit opened 4 years ago

dagit commented 4 years ago

The current password system calculates which items mega man should have based on which bosses have been beaten. That doesn't match up with randomization. We should fix this. It will probably need a slightly different patch in each generated rom.

bunder2015 commented 3 years ago

Posting before I forget this again...

I might have a possible solution to this...

We should theoretically have enough dots for this method and still have a few dots leftover.

madewokherd commented 3 years ago

Findings from investigating this issue:

The password itself is generated based on the weapons acquired, not the stages completed. For a reason I don't understand, these are mapped to the correct stages upon loading the password, so it seems to be only the items that are incorrect.

The code for populating the items and weapons is at offset 364BD in the ROM and looks like this:

$02 = stages completed flags
A4AD:  A5 02     LDA $02         A:FF  X:05  Y:01  SP:FB  P:27  nvTbdIZC  Cy:427653336  PPU-Cy:0
A4AF:  85 9A     STA $9A         A:01  X:05  Y:01  SP:FB  P:25  nvTbdIzC  Cy:427653339  PPU-Cy:0
items 1 and 2:
A4B1:  29 03     AND #$03        A:01  X:05  Y:01  SP:FB  P:25  nvTbdIzC  Cy:427653342  PPU-Cy:0
A4B3:  85 9B     STA $9B         A:01  X:05  Y:01  SP:FB  P:25  nvTbdIzC  Cy:427653344  PPU-Cy:0
item 3:
A4B5:  A5 9A     LDA $9A         A:01  X:05  Y:01  SP:FB  P:25  nvTbdIzC  Cy:427653347  PPU-Cy:0
A4B7:  29 20     AND #$20        A:01  X:05  Y:01  SP:FB  P:25  nvTbdIzC  Cy:427653350  PPU-Cy:0
A4B9:  4A        LSR A           A:00  X:05  Y:01  SP:FB  P:27  nvTbdIZC  Cy:427653352  PPU-Cy:0
A4BA:  4A        LSR A           A:00  X:05  Y:01  SP:FB  P:26  nvTbdIZc  Cy:427653354  PPU-Cy:0
A4BB:  4A        LSR A           A:00  X:05  Y:01  SP:FB  P:26  nvTbdIZc  Cy:427653356  PPU-Cy:0
A4BC:  05 9B     ORA $9B         A:00  X:05  Y:01  SP:FB  P:26  nvTbdIZc  Cy:427653358  PPU-Cy:0
A4BE:  85 9B     STA $9B         A:01  X:05  Y:01  SP:FB  P:24  nvTbdIzc  Cy:427653361  PPU-Cy:0

So there's a hard-coded assumption that heat man and air man weapons (flags 1 and 2) correspond to items 1 and 2, and flash stopper (flag 0x20) corresponds to item 3. I think if we hook or modify the code here, it probably shouldn't affect anything else? Well, it's not like we can make the password situation any worse.

madewokherd commented 3 years ago

Looking at that bank, I'm not sure where the unused space is. I would estimate that I need 23 bytes of space to make this work in the general case.