Re: Multi-bug fix patch in Pokémon Diamond

Discuss anything related to hacking ROMs of the Telefang games here.
Post Reply
Blaziken257
Posts: 983
Joined: Fri Dec 22, 2006 11:52 am

Re: Multi-bug fix patch in Pokémon Diamond

Post by Blaziken257 »

No, I'm not making this up. You see, in an attempt to figure out why the game crashes upon calling secret Denjuu, I ended up finding out why it does, and came up with a fix for not only this, but a few other bugs as well (see below). First, here is the patch:

http://www.mediafire.com/?dteh0833hif084z

Now let me explain it. The reason why the bug occurs has to do with the way the bootleg prints English (er... Engrish) text on the D-Shot menu. The bootleggers apparently had a hard time figuring out how the tiles are compressed (something that Malias accomplished single-handedly), so they rewrote the code to print the tiles, using uncompressed tiles, not to mention up to 6 letters instead of 4. This rewritten code and uncompressed tiles are in a different ROM bank from the original code -- in ROM bank 1E (that is, in offsets 0x78000-0x7BFFF), instead of ROM bank 04 (in offsets 0x10000-0x13FFF). (A ROM bank is 0x4000 bytes long, so to find an offset from a ROM bank, just take it and multiply it by 0x4000. ROM banks are loaded into RAM when they are needed to be used.) In the original Japanese version, ROM bank 1E is completely empty and therefore is not used at all.

The way that Diamond handles the D-shot menu is strange. If you look here (Diamond is on the left, Power is on the right), you'll see that the code is completely different. For Diamond, you'll see lots of ld a,1E in the code. This is what eventually causes the crash when calling a secret Denjuu, because it causes the game to switch to ROM bank 1E. The reason why it does that in the first place is because, as explained before, the game needs to in order to print the text. This would normally be OK, but just after calling a secret Denjuu, Diamond goes to this same line of code, switches ROM bank to 1E, but never switches it back to 04, which it needs to do in order to load the D-Shot menu in the first place. Therefore, when it tries to load the menu, it looks in the wrong place.

As you can see here, both games eventually go to RAM address 0x7C0A, but the ROM banks are different. Power/Speed go to ROM bank 04, which corresponds to (0x04-1)*0x4000+0x7C0A, or 0x13C0A, but Diamond goes to ROM bank 1E due to the sloppily rewritten code, which corresponds to (0x1E-1)*0x4000+0x7C0A, or 0x7BC0A. Whoops! In Diamond, it goes through a long sequence of no-ops (that is, instructions that do nothing) until it eventually hits VRAM in RAM offset 0x8000, where it crashes and VBA generates an "unknown opcode" message. Uh-oh!

Since the problematic, sloppily rewritten code is in offsets 0x10000-0x13FFF, I figured that I would try taking this data from Power and replacing the data in Diamond with this. This way, it would use the original code to write text, although it would write gibberish, but if this were to work, you could call secret Denjuu and not have it crash.

Well, guess what... it does work. You can call Musa, Amaranth, and more without fear of crashing. Not only that, but using Power/Speed's original code unexpectedly fixed other bugs too. You can now load a saved game, you can view your items while you have none, and you can create custom tunes. Yep, four of Diamond's glitches are a result of the way it outputs text on the D-Shot menu. Embarrassing.
EDIT (Mar. 18, 2016): Actually, it turns out that some of these glitches appear to be unrelated to one another, and simply exist within the same ROM bank (0x04). The secret Denjuu glitch is definitely related to the rewritten text printing routine, but the save "bug" is not (I need to make another thread explaining this issue sometime). It is unknown if the other glitches (viewing your items when you have none, or creating custom tunes) is related to the text printing routine.

Image

Of course, this patch isn't perfect. Besides the fact that it doesn't fix every bug (the intro still has color palette problems, for example), this one adds a bug. Nearly all the text on the D-Shot menu screen is garbled:

Image

This is a result of using the original Japanese code with Diamond's text strings. Even stranger, when I used Malias's decompression/recompression tools to use the English font, it still had problems. If you can get around that, then you will like this patch.

I'm also curious to see if you can't throw vases here. That would be interesting. I know that there are still some bugs: for example, pressing A+B+Select+Start still causes a crash, and the title screen is still glitched in monochrome. I do not know if the game still crashes after the Game Over screen, but I wouldn't be surprised if it did.

One final thing is that the clock works weird after applying this patch. The clock on the status bar on the map screen is still not in real time (and probably still operates at 50fps), but the one in the D-Shot is separate and does work in real time. I have no explanation for this... but oh well.

This is not meant to replace the English translation in progress, by the way. This is just for people who simply prefer Diamond over the original thing for whatever reason.
User avatar
andwhyisit
Site Admin
Posts: 1197
Joined: Fri Dec 14, 2007 9:24 pm

Re: Multi-bug fix patch in Pokémon Diamond

Post by andwhyisit »

Bootlegger Boss: I don't care if it has bugs, I don't care if it's a brick, just release it.
Bootlegger Hacker: (Why do I bother anymore?)
Bootlegger Hacker: Here it is.
Bootlegger Boss: Wheee! Money.
Bootleg Cart Company CEO: Wheee! Money.
Person who bought the game: WTF?!
RacieB
Posts: 871
Joined: Thu Dec 28, 2006 4:27 am

Re: Multi-bug fix patch in Pokémon Diamond

Post by RacieB »

Hahaha, shameful. Although, it is nice to have an explanation on why it's so damn breaky! Though now I'm wondering, what did they do in the case of the copies that already have the ability to save? Do those ones not still have the other issues, or are they jimmy-rigged to just save and still crash during secret calls, etc?
MefistaCenobica(imported)
Posts: 75
Joined: Sat Dec 25, 2010 8:34 am

Re: Multi-bug fix patch in Pokémon Diamond

Post by MefistaCenobica(imported) »

interesting
how to install it?
SougonNaTakumi(imported)
Posts: 61
Joined: Sat Dec 06, 2008 9:59 am

Re: Multi-bug fix patch in Pokémon Diamond

Post by SougonNaTakumi(imported) »

Use an ips patching program like LIPS. They're not too hard to find.
genocidekyuubi(imported)
Posts: 2
Joined: Tue Dec 26, 2017 1:57 pm

Re: Multi-bug fix patch in Pokémon Diamond

Post by genocidekyuubi(imported) »

Will this patch work for Jade version ?
User avatar
andwhyisit
Site Admin
Posts: 1197
Joined: Fri Dec 14, 2007 9:24 pm

Re: Multi-bug fix patch in Pokémon Diamond

Post by andwhyisit »

I would imagine not. This fixes the save bug as well, which isn't present in Jade. In fact I think the secret Denjuu bug is the only issue in Jade.
Sherkel(imported)
Posts: 74
Joined: Mon Dec 28, 2009 10:07 am

Re: Multi-bug fix patch in Pokémon Diamond

Post by Sherkel(imported) »

This is fantastic! I was starting a file on the bootleg again last week and was roaring nonstop with laughter (I was surprised I had forgotten most of the dialogue) until I lost to Nejiro and couldn't load my save afterward...now, though, I don't need to worry about being able to load my save, OR about losing to Nejiro, because I can call the secret numbers! In the bootleg version! I can hardly believe it.

Image
Why, yes I am, Musa!

Thank you so much for making this patch. :)
Post Reply