• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Help Thread: ASM & Disassembly

Status
Not open for further replies.

Blah

Free supporter
  • 1,924
    Posts
    11
    Years
    Code:
    .thumb
    start:
     push {r0-r7, lr}
     ldr r0, =(0x20370D0) @x800D, holds the berry number
     ldrh r1, [r0] @r1 now holds the number held in x800D
     ldr r0, =(0x3005541) @may change later because I don't know if this is free
     add r0, r0, r1 @gets the address of the table
     mov r2, r0
     mov r1, r0
     add r2, #0x3
     add r1, #0x2 @r0 is the year pointer, r1 is the month, and r2 is the day
     ldrh r0, r3
     ldrb r1, r4
     ldrb r2, r5
     ldr r6, =(0x300553C)
     ldrh r7, [r6]
     cmp r3, r7
     blo x800D_1
     ldr r6, =(0x300553F)
     ldrb r7, [r6]
     blo x800D_1
     ldr r6, =(0x3005540)
     ldrb r7, [r6]
     blo x800D_1
     ldr r0, =(0x20370D0)
     mov r1, #0x0
     strh r0, [r1] 
     pop {r0-r7}
    x800D_1:
     ldr r6, =(0x300553C)
     ldrh r7, [r6]
     strh r7, [r0]
     ldr r6, =(0x300553C)
     ldrb r7, [r6]
     strb r7, [r1]
     ldr r6, =(0x300553C)
     ldrb r7, [r6]
     strb r7, [r2]
     ldr r0, =(0x20370D0)
     mov r1, #0x1
     strh r0, [r1]
     pop {r0-r7, pc}
    When I try to assemble this(it's a code of my own design), I get an error from the assembler. It tells me that lines 13, 14, and 15 are messed up. The exact error I get is 'invalid offset, value too big (0xFFFFFFFC)', which doesn't make any sense to me.
    You don't have square brackets.
    Code:
    ldrh r0, [r3]
    ldrb r1, [r4]
    ldrb r2, [r5]
    Also, for the love of god, please format your routine. That's so painful to read X_X

    Oh my gosh. FBI actually responded to my question. I'm at awe. O.O Thank you for the first parts! ^U^

    As for the last part of your reply, I'd guess it was JPAN's source code you wanted me to pastebin right? Well, here it is. https://pastebin.com/dxpEFdWb

    EDIT: Oh. I forgot to ask. In the Frontier Opponent Party Generation Routine, how do I make it so that it generates constant number of Pokemon (let's say, I want it to generate 3 Pokemon the whole time), should I remove the "genAmount" section? And if so, what would I replace it with?

    P.S. The Pokemon can't be generated with random level each right? (Or did I guess wrong?)

    You can make it generate a static amount, yes. Change:
    Code:
    	ldr r4, =(0x8044EC8 +1)@gen random number
    	bl linker
    	lsl r0, r0, #0x10
    	lsr r0, r0, #0x10
    	mov r1, #0x6
    	ldr r4, =(0x81E4684 +1)
    	bl linker
    	add r0, r0, #0x1
    	mov r5, r0

    to

    Code:
    mov r5, #0xAmount you want

    As for generating random levels, change:

    Code:
    	mov r0, #0x64
    	mul r0, r0, r7
    	add r0, r0, r6 @free memory
    	mov r2, #0x32 @level
    	mov r3, #0x20 @cnst
    	ldr r4, =(0x803DA54 +1)
    	bl linker
    	add r7, r7, #0x1
    	b genLoop

    to:
    Code:
    	mov r0, #0x64
    	mul r0, r0, r7
    	add r0, r0, r6 @free memory
    	push {r0-r3}
    	ldr r4, =(0x8044EC8 +1)@gen random number
    	bl linker
    	mov r1, #0x64
    	ldr r4, =(0x81E4684 +1)
    	bl linker
    	mov r4, r0
    	pop {r0-r3}
    	mov r2, r4
    	mov r3, #0x20 @cnst
    	ldr r4, =(0x803DA54 +1)
    	bl linker
    	add r7, r7, #0x1
    	b genLoop
    note that this is untested.


    For Jpan's thing. He explains right here:
    /*This code is meant to create a small box, based on the multichoice
    box code, that can be used to input numeric values in-game.

    This box will receive as input the largest possible number in variable
    0x8008 and 0x8009 as a 32 bit number, and returns 0x8008 and 0x8009 as
    the 32 bit input number, and 0x800D as either the digit A was pressed on
    or 0x7f if B was pressed to cancel the box input.*/
    setvar 0x8008 and 0x8009 to 0x0 before doing callasm.
     
  • 534
    Posts
    11
    Years
    • Age 26
    • Seen Jul 24, 2023
    You can make it generate a static amount, yes. Change:
    Code:
        ldr r4, =(0x8044EC8 +1)@gen random number
        bl linker
        lsl r0, r0, #0x10
        lsr r0, r0, #0x10
        mov r1, #0x6
        ldr r4, =(0x81E4684 +1)
        bl linker
        add r0, r0, #0x1
        mov r5, r0
    to

    Code:
    mov r5, #0xAmount you want
    As for generating random levels, change:

    Code:
        mov r0, #0x64
        mul r0, r0, r7
        add r0, r0, r6 @free memory
        mov r2, #0x32 @level
        mov r3, #0x20 @cnst
        ldr r4, =(0x803DA54 +1)
        bl linker
        add r7, r7, #0x1
        b genLoop
    to:
    Code:
        mov r0, #0x64
        mul r0, r0, r7
        add r0, r0, r6 @free memory
        push {r0-r3}
        ldr r4, =(0x8044EC8 +1)@gen random number
        bl linker
        mov r1, #0x64
        ldr r4, =(0x81E4684 +1)
        bl linker
        mov r4, r0
        pop {r0-r3}
        mov r2, r4
        mov r3, #0x20 @cnst
        ldr r4, =(0x803DA54 +1)
        bl linker
        add r7, r7, #0x1
        b genLoop
    note that this is untested.


    For Jpan's thing. He explains right here:

    setvar 0x8008 and 0x8009 to 0x0 before doing callasm.

    Oops. Sorry I didn't read through his routine. ._. Thanks FBI! As always, you're the best! ^U^ Still don't know why the HP Modification Per Step Routines doesn't work though. I have tried everything (applied it to a very very fresh BPRE ROM, started a new game without cheats or anything, checked everything) still freezes. TT^TT Am I the only one?
     

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    Oops. Sorry I didn't read through his routine. ._. Thanks FBI! As always, you're the best! ^U^ Still don't know why the HP Modification Per Step Routines doesn't work though. I have tried everything (applied it to a very very fresh BPRE ROM, started a new game without cheats or anything, checked everything) still freezes. TT^TT Am I the only one?

    I don't know, it might be broken. Can you link the post? I guess I could take a quick peek.
     
  • 534
    Posts
    11
    Years
    • Age 26
    • Seen Jul 24, 2023
    I don't know, it might be broken. Can you link the post? I guess I could take a quick peek.
    Here it is. :)
    And next the HP Modifications per step routines.
    Spoiler:
     
  • 58
    Posts
    8
    Years
    • Seen Jan 7, 2017
    I don't know, it might be broken. Can you link the post? I guess I could take a quick peek.

    I have a question.
    I'm here in this thread to get some information about how to get the battle type in Firered version before loading the mugshots (see Jambo51's thread to get what is pre-battle mugshot)
    As we all know, 0x02022B4C keeps a word indicating the battle type. However, it gets the value after the pre-battle mugshot animation absolutely, which means that I can't use that to judge the type of battle.
    What I'm working on is to add the pre-battle mugshot to every battle, including wild pokemon battle (Jambo51 has done the trainer part)
    The core modification is here:
    Code:
    0x7F650 - 0C 20
    Then every wild pokemon and trainer will have the mugshot of Agatha.
    I want to get the battle type so I can write the routine accordingly. As you can see, if I know that, I can decide whether to get pointer from the trainer sprites table or pokemon sprites table. Then everything goes right.

    Thanks if you or anyone can solve the problem :)
     
    Last edited:

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    I have a question.
    I'm here in this thread to get some information about how to get the battle type in Firered version before loading the mugshots (see Jambo51's thread to get what is pre-battle mugshot)
    As we all know, 0x02022B4C keeps a word indicating the battle type. However, it gets the value after the pre-battle mugshot animation absolutely, which means that I can't use that to judge the type of battle.
    What I'm working on is to add the pre-battle mugshot to every battle, including wild pokemon battle (Jambo51 has done the trainer part)
    The core modification is here:
    Code:
    0x7F650 - 0C 20
    Then every wild pokemon and trainer will have the mugshot of Agatha.
    I want to get the battle type so I can write the routine accordingly. As you can see, if I know that, I can decide whether to get pointer from the trainer sprites table or pokemon sprites table. Then everything goes right.

    Thanks if you or anyone can solve the problem :)

    The Mugshots are determined by trainer class. If the class is elite four or champion, a mugshot is displayed. Jambo51 uses this fact to display mugshots by tricking the game into thinking it is loading a champion or rival battle. I researched this some time ago, and the value is confirmed twice per battle, you'll find the locations once you set bpr points at the trainer table's class byte. I'm unsure if wild battles also break at the routine, I haven't tried that before.

    From there you can load your own mugshot. For wild battles, if it doesn't break, you should just write your own or redirect it (which might mess up other things).
     
  • 58
    Posts
    8
    Years
    • Seen Jan 7, 2017
    The Mugshots are determined by trainer class. If the class is elite four or champion, a mugshot is displayed. Jambo51 uses this fact to display mugshots by tricking the game into thinking it is loading a champion or rival battle. I researched this some time ago, and the value is confirmed twice per battle, you'll find the locations once you set bpr points at the trainer table's class byte. I'm unsure if wild battles also break at the routine, I haven't tried that before.

    From there you can load your own mugshot. For wild battles, if it doesn't break, you should just write your own or redirect it (which might mess up other things).

    There seems to exist an "animation function", which is located at 0x080D08B8. It takes one parameter in r0 and if it's 0xC or 0xD or other similar values the routine will think it's champion or member of elite four and run the "mugshot animation", otherwise it will run the normal animation.
    So I get the byte changes (0C 20 for mov r0, #0xC) to make the function always load the "mugshot animation".
    But IDK how to judge if it's a wildbattle or a trainerbattle lol
    Because that will decide which sprite table and palette table to read...
    The trainer class check and trainer id check are before the routine and if they passed (for example, is Agatha), then 0xC is written to the task argument space and then load into r0 before the "animation function" is called.
     
    Last edited:

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    There seems to exist an "animation function", which is located at 0x080D08B8. It takes one parameter in r0 and if it's 0xC or 0xD or other similar values the routine will think it's champion or member of elite four and run the "mugshot animation", otherwise it will run the normal animation.
    So I get the byte changes (0C 20 for mov r0, #0xC) to make the function always load the "mugshot animation".
    But IDK how to judge if it's a wildbattle or a trainerbattle lol
    Because that will decide which sprite table and palette table to read...
    The trainer class check and trainer id check are before the routine and if they passed (for example, is Agatha), then 0xC is written to the task argument space and then load into r0 before the "animation function" is called.

    So do some research. The game needs to know when to call that function at some point, work backwards until you can find a point where the battle functions diverge.
     

    AkameTheBulbasaur

    Akame Marukawa of Iyotono
  • 409
    Posts
    11
    Years
    Hi! Is it possible for me to be able to combine the Reset Chain routine and the HP Regeneration routine? As they are, it's only possible to have one at a time since they branch off of the same routine.

    For that I would need some sort of mediator but how should I do that?


    Thanks in advance. :D
     

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    Hi! Is it possible for me to be able to combine the Reset Chain routine and the HP Regeneration routine? As they are, it's only possible to have one at a time since they branch off of the same routine.

    For that I would need some sort of mediator but how should I do that?


    Thanks in advance. :D

    Could you quote both routines for the lazy please :3
     
  • 959
    Posts
    11
    Years
    (Not sure if this goes in here or the Quick Questions and Answers thread. Mods please move this post if needed)

    I'm finally working towards inserting ASM routines into Sigma Emerald, so I have a bunch of questions.

    -When writing a pointer in thumb mode, do you + 1 to the offset before or after you shuffle it?
    ie. Let's take 0x345678 as an example. Does it become 34 56 79 -> 79 56 34? Or would it be 78 56 35?

    - When writing pointers into x offset, can I just go into a hex editor and write the changes directly to the bytes?
    ie. just going in there and straight up typing your pointer digits.

    -HackMew stated in his knowledge thread that 0x800000 is the optimal offset for inserting ASM routines into? From what I've heard, Emerald has no freespace there. Where should I insert routines after compiling them with the thumb assembler?

    -I've been trying to find a solution for the incorrect mugshots in my E4 rematch teams in Sigma Emerald; since Jambo's mugshot hack has been ported to BPEE, would it work to insert only the second ASM routine (the one that changes the loaded mugshot to that of the trainer sprite) because I'm only trying to fix the Elite Four mugshots?
     

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    (Not sure if this goes in here or the Quick Questions and Answers thread. Mods please move this post if needed)

    I'm finally working towards inserting ASM routines into Sigma Emerald, so I have a bunch of questions.

    -When writing a pointer in thumb mode, do you + 1 to the offset before or after you shuffle it?
    ie. Let's take 0x345678 as an example. Does it become 34 56 79 -> 79 56 34? Or would it be 78 56 35?

    - When writing pointers into x offset, can I just go into a hex editor and write the changes directly to the bytes?
    ie. just going in there and straight up typing your pointer digits.

    -HackMew stated in his knowledge thread that 0x800000 is the optimal offset for inserting ASM routines into? From what I've heard, Emerald has no freespace there. Where should I insert routines after compiling them with the thumb assembler?

    -I've been trying to find a solution for the incorrect mugshots in my E4 rematch teams in Sigma Emerald; since Jambo's mugshot hack has been ported to BPEE, would it work to insert only the second ASM routine (the one that changes the loaded mugshot to that of the trainer sprite) because I'm only trying to fix the Elite Four mugshots?

    - Add one before shuffling: 34 56 79 -> 79 56 34

    - No, his knowledge of the games are very very outdated. This is the same guy who thought 00s were the free space bytes in Emerald. I suggest you open a hex editor, find a good chunk of free space then just insert them there. There's plenty of room, and you can expand the ROM too.

    How are they incorrect? Are you using a different set of Elite Fours then the first match? Or are you mugshots becoming mixed up (as in swapped around). If that is the case, use the game's original Trainer IDs for the Elite Fours. I don't recall 100% but there is a 4 way switch between the four of them and the default being the rival.
     
  • 959
    Posts
    11
    Years
    How are they incorrect? Are you using a different set of Elite Fours then the first match? Or are you mugshots becoming mixed up (as in swapped around). If that is the case, use the game's original Trainer IDs for the Elite Fours. I don't recall 100% but there is a 4 way switch between the four of them and the default being the rival.

    My thread pretty much sums it up: https://www.pokecommunity.com/showthread.php?p=8927124#post8927124

    I assigned the upgraded teams to new trainer IDs, so they all show Wallace's mugshots on the second run. The first matches are fine though. Basically I tried re-creating the rematch system present in the newer games where they have better teams once you challenge them as the Champion. Everything worked out except for the vs. screens.
     

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    My thread pretty much sums it up: https://www.pokecommunity.com/showthread.php?p=8927124#post8927124

    I assigned the upgraded teams to new trainer IDs, so they all show Wallace's mugshots on the second run. The first matches are fine though. Basically I tried re-creating the rematch system present in the newer games where they have better teams once you challenge them as the Champion. Everything worked out except for the vs. screens.

    Open a clean EM ROM, and check the trainer IDs for the elite four rematches, and just overwrite those ones with your second battle.
     
  • 959
    Posts
    11
    Years
    Open a clean EM ROM, and check the trainer IDs for the elite four rematches, and just overwrite those ones with your second battle.

    But the thing is that vanilla Emerald doesn't have Elite Four rematches, hence why created one in the first place. If you open up a trainer editor, you'll see that the Gym Leader rematches have separate IDs for each of their rematch teams. On the other hand, the Elite Four make use of flags that are cleared either after defeating the Champion or the player loses the challenge; their teams remain at the same level with the same Pokemon when you go back to battle them again.

    What I did was dissect the original E4 script, replicate it, then add a flag that checks if the player has become the Champion, along with the new trainerbattles with the IDs. (and dialogue) I needed the new IDs so that the first run is still the original Emerald E4, then have new higher-level teams upon re-running the League.
     

    AkameTheBulbasaur

    Akame Marukawa of Iyotono
  • 409
    Posts
    11
    Years
    Could you quote both routines for the lazy please :3


    Reset Chain:
    Spoiler:


    HP Regeneration:
    Spoiler:
     

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years

    Replace the hook with a hook to this routine. Feel free to delete the other two.
    Spoiler:
     
  • 325
    Posts
    10
    Years
    Does anyone know the location of FR's wild Pokémon generator? I don't mean the special, I want to know how background byte 1 works.
     
    Last edited:

    Blah

    Free supporter
  • 1,924
    Posts
    11
    Years
    Does anyone know the location of FR's wild Pokémon generator? I don't mean the special, I want to know how background byte 1 works.
    Wild Pokemon generator? There is no such thing. All Pokemon in the game are generated using the same function, ROM:0803DA54.
     
    Status
    Not open for further replies.
    Back
    Top