• 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.

[ASM & Hex] Edit Master Ball subroutine

88
Posts
7
Years
    • Seen Jan 16, 2020
    I want to have the master ball fail upon usage against a specific pokemon and/or map. I know it skips the catch rate calculation subroutine, so I'm wondering where this subroutine is called from? In other words, where does the game check to see if the master ball is being used?

    Alternatively, I am thinking of just making it an even better Ultra Ball.

    My current idea is to link to a new subroutine if the master ball is used with something along these lines:
    Code:
    mov r0, #0x67
    lsl r0, r0, #0x2
    sub r0, r0, #0x1            @ID 411 or whichever ID I would use
    ldr r1, =(0x0202402C)      @enemy pokemon
    cmp r1, r0
    beq Fail
    mov r4, #0x50     @if not specified pokemon, catch rate becomes 8x (or jump to wherever it originally jumps to. I haven't decided if I will make it just an absurd catch rate)
    b Ending
    
    Fail:
    mov r4, #0x0
    
    Ending:
    ldr r0, =(0x0802D62A)
    mov pc, r0

    Please let me know if you can help / have any suggestions. Thanks!
     
    Last edited:
    794
    Posts
    10
    Years
  • I want to have the master ball fail upon usage against a specific pokemon and/or map. I know it skips the catch rate calculation subroutine, so I'm wondering where this subroutine is called from? In other words, where does the game check to see if the master ball is being used?

    Alternatively, I am thinking of just making it an even better Ultra Ball.

    My current idea is to link to a new subroutine if the master ball is used with something along these lines:
    Code:
    mov r0, #0x67
    lsl r0, r0, #0x2
    sub r0, r0, #0x1            @ID 411 or whichever ID I would use
    ldr r1, =(0x0202402C)      @enemy pokemon
    cmp r1, r0
    beq Fail
    mov r4, #0x50     @if not specified pokemon, catch rate becomes 8x (or jump to wherever it originally jumps to. I haven't decided if I will make it just an absurd catch rate)
    b Ending
    
    Fail:
    mov r4, #0x0
    
    Ending:
    ldr r0, =(0x0802D62A)
    mov pc, r0
    Please let me know if you can help / have any suggestions. Thanks!

    Pokeball calculations are done in the 0xEF battle command. The address is 08056300 in Emerald, for FR you'll have to find it yourself.
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • There are a couple of similar Pokeball fail routines in the ASM resource thread for FR. You can grab and slightly modify those. What you want to do is compare the last used item index to the masterball and the currently fighting Pokemon species. Good luck.
     
    88
    Posts
    7
    Years
    • Seen Jan 16, 2020
    DizzyEgg said:
    FBI said:
    Spherical Ice said:
    It's 0802D434 in FR. :)

    Thanks for your help, guys :) I combed through the battle command and compared with FBIs trainer-catching ball routine and found a segment that checks if the used ball is a master ball here:
    Code:
    0802D67A:
    ldr r1, =(0x02023D68)	@thrown ball
    ldrh r0, [r1]
    cmp r0, #0x5			@safari ball
    beq $0802D6BC
    cmp r0, #0x1			@master ball
    bne $0802D6A8
    ldr r0, =(0x03004F90)	@0x0802D686
    ldrb r1, [r0, #0x5]
    mov r2, #0x2
    orr r1, r2
    strb r1, [r0, #0x5]
    b $0802D6BC

    Here is my attempt at rewriting the routine:

    EDIT: it is freezing the game when any ball is thrown currently, and I'm not entirely positive why..

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:				@insert 00 48 00 47 (XX+1) XX XX 08 at 0x0802D678
            add r6, r0, #0x0   @this was replaced from inserting the above hex
    	ldr r1, .Ball
    	ldrb r0, [r1]
    	cmp r0, #0x5
    	beq SafariBall
    	cmp r0, #0x1
    	bne OtherBall
    	mov r2, #0x67		@r2 = 0x67
    	lsl r2, r2, #0x2		@r2 = 0x19C = 412
    	sub r2, r2, #0x1            @species #411 = 0x19B
    	ldr r1, =(0x0202402C)       @wild pkmn species ID
            ldrh r1, [r1]
    	cmp r1, r2
    	beq Fail				@master ball fails against this species
    	ldr r1, =(0x0802D686 +1)		@routine to resume otherwise
    	bx r1
    	
    Fail:
    	ldr r1, =(0x02023D74)
    	ldr r0, .String
    	str r0, [r1]			@0802D7EC
    	pop {r4-r6}
    	pop {r0}
    	bx r0
    	
    SafariBall:
    	ldr r0, =(0x0802D6BC +1)
    	bx r0
    
    OtherBall:
    	ldr r0, =(0x0802D6A8 +1)
    	bx r0
    
    .align 2
    .Ball:	.word 0x02023D68
    .String:	.word 0x08XXXXXX		@String saying master ball failed
     
    Last edited:

    Telinc1

    Weirdo Extraordinaire
    168
    Posts
    10
    Years
  • Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:				@insert 00 48 00 47 (XX+1) XX XX 08 at 0x0802D678
            add r6, r0, #0x0   @this was replaced from inserting the above hex
    	ldr r1, .Ball
    	ldrb r0, [r1]
    	cmp r0, #0x5
    	beq SafariBall
    	cmp r0, #0x1
    	bne OtherBall
    	mov r2, #0x67		@r2 = 0x67
    	lsl r2, r2, #0x2		@r2 = 0x19C = 412
    	sub r2, r2, #0x1            @species #411 = 0x19B
    	ldr r1, =(0x0202402C)       @wild pkmn species ID
            ldrh r1, [r1]
    	cmp r1, r2
    	beq Fail				@master ball fails against this species
    	ldr r1, =(0x0802D686 +1)		@routine to resume otherwise
    	bx r1
    	
    Fail:
    	ldr r1, =(0x02023D74)
    	ldr r0, .String
    	str r0, [r1]			@0802D7EC
    	pop {r4-r6}
    	pop {r0}
    	bx r0
    	
    SafariBall:
    	ldr r0, =(0x0802D6BC +1)
    	bx r0
    
    OtherBall:
    	ldr r0, =(0x0802D6A8 +1)
    	bx r0
    
    .align 2
    .Ball:	.word 0x02023D68
    .String:	.word 0x08XXXXXX		@String saying master ball failed
    I didn't really look into it that much, so I could be wrong, but on the last two lines of the main label, you're calling bx r1 with 0x0802D686 + 1 in r1. bx does exchange between ARM and THUMB mode, so the offset you call it with must be aligned (end in 0, 4, 8, or C). You could try doing stack trickery to move pc to 0x0802D686 or find a different offset to jump to.
     
    88
    Posts
    7
    Years
    • Seen Jan 16, 2020
    I didn't really look into it that much, so I could be wrong, but on the last two lines of the main label, you're calling bx r1 with 0x0802D686 + 1 in r1. bx does exchange between ARM and THUMB mode, so the offset you call it with must be aligned (end in 0, 4, 8, or C). You could try doing stack trickery to move pc to 0x0802D686 or find a different offset to jump to.

    Ah, I didn't know that. thanks for the tip! I just needed to add another line from the original routine and bx back to a THUMB aligned offset

    The following code is fully functional. I want to edit it to display a different string than the pokemon dodging the master ball, but here is the working routine:

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    @insert 01 48 00 47 00 00 (XX+1) XX XX 08 at 0x0802D67A
    
    main:
    	ldr r1, .Ball
    	ldrb r0, [r1]
    	cmp r0, #0x5				@safari ball ID
    	beq SafariBall
    	cmp r0, #0x1				@master ball ID
    	bne OtherBall	
    	ldr r0, =(0x0202402C)       @enemy species ID
    	mov r1, #0xB				@get species from GetAttr func.
    	ldr r2, .GetAttr
    	bl linker				@get enemy species, store in r0
    	mov r1, #0x13				@rattatta for testing
    	@mov r1, #0x67				@r2 = 0x67
    	@lsl r1, r1, #0x2			@r2 = 0x19C = 412
    	@sub r1, r1, #0x1            @species #411 = 0x19B
    	cmp r0, r1
    	beq Fail					@master ball fails against this species
    	ldr r0, =(0x03004F90)
    	ldr r1, =(0x0802D688 +1)
    	bx r1
    	
    linker:
    	bx r2
    	
    Fail:
    	ldr r0, = (0x802D460 +1)
    	bx r0
    	@ldr r1, =(0x02023D74)
    	@ldr r0, .String
    	@ldr r2, =(0x0802D7EC)
    	@bx r2
    	
    SafariBall:
    	ldr r0, =(0x0802D6BC +1)
    	bx r0
    
    OtherBall:
    	ldr r0, =(0x0802D6A8 +1)
    	bx r0
    
    .align 2
    .Ball:	.word 0x02023D68
    .GetAttr:	.word 0x0803FBE9
     
    Last edited:
    Back
    Top