Because nobody ever really understood how trainer music was determined until now, and it seems like a useful feature to have.
Alright so for this you're gonna want to extract your rom and decompress a couple of the files. I normally use ndstool and blz.exe to do this:
ndstool -x originalromname.nds -9 arm9.bin -7 arm7.bin -y9 y9.bin -y7 y7.bin -d data -y overlay -t banner.bin -h header.bin
copy arm9.bin arm9decomp.bin
blz -d arm9decomp.bin
copy overlay\overlay_0036.bin overlay_0036decomp.bin
blz -d overlay_0036decomp.bin
Now we need to make a few changes to our decompressed overlay 36. They change slightly based on version.
Now, this change will affect how big the file is when compressed, so we need to edit a table in y9.bin to take that into account open it up, go to offset 0x49C, and change it from 58 E9 03 -> 5C E9 03 for Black 2 or 30 E9 03 -> 34 E9 03 for White 2.
Finally, we insert the music table itself. Originally the game contains a table for each of the 236 trainer classes in the form AA GG EE EE, where AA is unknown, GG is gender, and EE EE is the encounter (not the battle) music. The gender field isn't really used for much of anything, so we're just gonna overwrite it with a field for battle music. Note that we only have one byte to work with, so we're restricted to music in the range 0400 to 04FF, but that includes pretty much everything anyway. Now, open your decompressed arm9, and go to 0x8E394 for Black 2 or 0x8E3C0 for White 2. Here, you want to replace
This will assign each trainer class the same music they had in the vanilla game. Obviously this is not very useful, so go ahead and edit that second column to assign whatever music you like to each trainer class. You can use BWTE or something to remind yourself what order the 236 classes come in.
Once you've done that, it's time to rebuild the rom. Which brings us to the bad news. Even though we didn't change the size of the decompressed arm9, our changes still affect what size it is after compression, which for some reason causes major issues when rebuilding the rom. One way to solve this is to just insert the decompressed arm9, instead of compressing it first. This basically solves the issue, but at a cost: the game will now supposedly only be compatible with emulators, not an actual DS.
copy overlay_0036decomp.bin overlay\overlay_0036.bin
blz -en overlay\overlay_0036.bin
ndstool -c newromname.nds -9 arm9decomp.bin -7 arm7.bin -y9 y9.bin -y7 y7.bin -d data -y overlay -t banner.bin -h header.bin
Obviously this is not ideal, so if anyone knows how to insert a compressed arm9.bin with a different size from the original WITHOUT making the game impossible to boot, please let me know. But either way, hope someone finds all this useful.