View Single Post
Old December 30th, 2012 (7:08 AM). Edited June 24th, 2013 by Jambo51.
Jambo51's Avatar
Jambo51 Jambo51 is offline
Glory To Arstotzka
Join Date: Jun 2009
Gender: Male
Nature: Quiet
Posts: 732
Hey there, Jambo51 here with another ASM/Hex editing combination tutorial.

In Fire Red, you will surely have noticed, that apart from a few specific classes (Champion, Leader and Elite 4) there is absolutely no class based music for the trainer battles. Generally speaking, that is fine, since you don't want the average Youngsters etc to have special battle music, but what about Team Rocket? Shouldn't they have a special battle theme?


You can't do that with Fire Red?!

I beg to differ! Follow this tutorial, and we'll have class based music in no time!

So, firstly, assemble and insert this routine, and note down the location of your insert.

.align 2
.global battlemusichack

	ldr r0, there
	ldr r1, [r0, #0x0]
	mov r0, #0x80
	lsl r0, r0, #0x5
	and r0, r1
	cmp r0, #0x0
	bne later
	mov r0, #0x80
	lsl r0, r0, #0x7
	and r0, r1
	cmp r0, #0x0
	bne later2
	mov r0, #0x2
	and r0, r1
	cmp r0, #0x0
	beq one
later2:	mov r0, #0x85
	lsl r0, r0, #0x1
	b return2
later:	mov r0, #0x95
	lsl r0, r0, #0x1
	b return2
one:	mov r0, #0x8
	and r1, r0
	cmp r1, #0x0
	beq wild
	ldr r2, table
	ldr r2, [r2, #0x0]
	ldr r0, ramoffset
	ldrh r1, [r0, #0x0]
	lsl r0, r1, #0x2
	add r0, r0, r1
	lsl r0, r0, #0x3
	add r0, r0, r2
	ldrb r0, [r0, #0x1]
	cmp r0, #0x54
	beq gym
        cmp r0, #0x57
        beq gym
        cmp r0, #0x5A
        beq champ
normal:	push {r2,r3}
	ldr r3, terminate
	ldr r1, classtable
loop:	ldrh r2, [r1, #0x0]
	cmp r2, r0
	beq loadmusic
	cmp r2, r3
	beq carryon
	add r1, #0x4
	b loop
carryon:	mov r0, #0x2
	pop {r2,r3}
	b return
loadmusic:	ldrh r0, [r1, #0x2]
	pop {r2,r3}
	b return2
wild:	ldr r0, there
	ldr r0, [r0, #0x0]
	mov r1, #0x1
	and r0, r1
	cmp r0, #0x0
	bne alternate
	mov r0, #0x0
	b return
alternate:	mov r0, #0x1
	b return
gym:	mov r0, #0x3
	b return
champ:	mov r0, #0x4
return:	push {r2-r7}
	mov r11, r0
	ldr r0, variable
	bl vardecrypt
	ldrh r0, [r0, #0x0]
	mov r1, #0xA
	mul r0, r1
	ldr r1, normaltable
	add r0, r0, r1
	mov r1, r11
	lsl r1, r1, #0x1
        add r0, r0, r1
	ldrh r0, [r0, #0x0]
	mov r1, #0x0
	mov r11, r1
	pop {r2-r7}
return2:	pop {r1}
	bx r1
vardecrypt:	ldr r1, vardec
	bx r1
table:		.word 0x08044028
there:		.word 0x02022B4C
ramoffset:	.word 0x020386AE
terminate:	.word 0x0000FEFE
classtable:	.word 0x08FDFDFD
normaltable:	.word 0x08FEFEFE
vardec:		.word 0x0806E455
variable:	.word 0x000040F6
Now, navigate to 0x43FF2 and change the code to 01 48 00 47 00 00 XX XX XX 08, where the XX's stand for your reversed pointer to the ASM you just inserted, plus 1 for THUMB mode, of course.

Now, we're still not done, of course, so return to the location of the inserted ASM.

Now, we must create a table which contains definitions for the class based music. This allows you to define as many EXTRA classes as you want, but you CANNOT change the music assigned to the Champion/Elite 4/Gym Leaders using this.

So, in some aligned free space, create a table in this format:

[Trainer Class - Byte][00 - Byte][Song to play - Half-Word]

So, for example, I wanted the Team Rocket class to have track 0x130, I would put the following set of bytes into the table:

55 00 30 01
You must do this for every class you wish to have custom music.

When you're done with this, place:

FE FE 00 00 at the end of the table, so in my example, it would be:

55 00 30 01 FE FE 00 00
Easy, huh? Note down the location of this table and navigate to The ASM's insert location + 0xC0. Change the pointer here (should be FD FD FD 08) to point to the table you just created, NOT plus one.

Now, for anyone who knows ASM, or is eagle eyed, you will have noticed it also contains a variable check. This variable check allows you to have regional music!

Now, to create a set of regional music, navigate to some aligned free space, and start by putting the following set of values in:

2A 01 54 01 29 01 28 01 2B 01
You may recognise these as the existing battle theme track numbers. If you don't intend to use regional music, you can move on from here straight to the changing the pointer later on.

However, if you want regional music, you should follow the existing values with this format:

[Wild Battle Track - Half-Word][Double Wild Battle Track - Half-Word][Trainer Battle Track - Half-Word][Gym Battle Track - Half-Word][Champion Battle Track - Half-Word]

If you want any tracks to use the same values as their "normal" versions, you must set them to the same value. Eg, I want tracks 0x10A (wild), 0x140 (double wild), 0x109 (trainer), 0x154 (gym) but want to keep the Champion battle as 0x12B, then I would add the following values:

0A 01 40 01 09 01 54 01 2B 01
When you're done adding new values, note down the start location of this table, and then navigate to the start of the ASM + 0xC4. The pointer here should be FE FE FE 08. Now you must change it to point to the new regional table you just created.

Once you have done this, you are done!

In terms of in game use, you don't have to do anything to get the class based music, it will immediately start working. For the regional music, you must set variable number 0x40F6 to the set of regional music you want to use.

That is, for the "normal" set, set the variable to 0, and for any additional sets, set it to the correct number to pick that set. Everything else is handled in the background.
Hey guys, please check out my recreations of the gen 1 and 2 music on my custom engine at my SoundCloud! - Here!
Reply With Quote