Thread: Development: Taking Pokémon away
View Single Post
  #1    
Old January 21st, 2010 (2:42 AM). Edited May 1st, 2010 by HackMew.
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314

Brief Intro


How many times has this been asked before? Quite a lot, I guess. While I cannot stop people from asking the same questions over and over again because they're too lazy to search or whatever, I can still give you a nice ASM routine to do the job.

Description


It is not commented, but if you're any experienced you shouldn't have problems understanding it. Basically the routine will take the value stored into variable 0x8004 and remove that Pokémon from the party. The first one would be setvar 0x8004 0x0, and so on. The routine also performs some safety checks in case you want to set the variable manually. Of course, it's not a bad idea to use the select Pokémon special(s). To prevent obvious problems, the routine won't allow you to take away your last Pokémon. If everything goes fine, the return value (conveniently stored into LASTRESULT) will be 0x1. In any other case it will be set to 0x0.

There's another short routine too, which is similar but has no safety checks and requires no input: it will simply erase the first Pokémon. It can be useful in some occasions, for example having a starter and then getting a new one or similar. In this case, the previous routine would not work indeed.

The Code


TakePokemon


  • FireRed/LeafGreen

    Code:
    .text .align 2 .thumb .thumb_func .global TakePokemon main: push {r0-r7, lr} mov r5, #0x0 ldr r6, .VAR ldr r7, .POKEMON_AMOUNT ldrb r4, [r7] cmp r4, #0x2 blt return ldrh r3, [r6] cmp r3, r4 bhs return sub r2, r4, #0x1 strb r2, [r7] add r3, #0x1 sub r2, r4, r3 mov r5, #0x64 mul r2, r5 lsr r2, r2, #0x1 mul r3, r5 ldr r7, .POKEMON_PARTY add r0, r7, r3 sub r1, r0, r5 swi #0xB mul r4, r5 add r7, r4 sub r7, r5 mov r0, #0x0 mov r2, #0x19 mov r5, #0x1 erase_loop: stmia r7!, {r0} sub r2, #0x1 cmp r2, #0x0 bne erase_loop return: strh r5, [r6, #0x10] pop {r0-r7, pc} .align 2 .POKEMON_AMOUNT: .word 0x02024029 .POKEMON_PARTY: .word 0x02024284 .VAR: .word 0x020270B8 + (0x8004 * 2)
  • Ruby/Sapphire

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    .align 2 .POKEMON_AMOUNT: .word 0x03004350 .POKEMON_PARTY: .word 0x03004360 .VAR: .word 0x0201E8C4 + (0x8004 * 2)
  • Emerald

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    .align 2 .POKEMON_AMOUNT: .word 0x020244E9 .POKEMON_PARTY: .word 0x020244EC .VAR: .word 0x020275D8 + (0x8004 * 2)

EraseFirstPokemon


  • FireRed/LeafGreen

    Code:
    .text .align 2 .thumb .thumb_func .global EraseFirstPokemon main: push {r0-r2, lr} mov r0, #0x0 ldr r1, .POKEMON_PARTY mov r2, #0x19 erase_loop: stmia r1!, {r0} sub r2, #0x1 cmp r2, #0x0 bne erase_loop return: pop {r0-r2, pc} .align 2 .POKEMON_PARTY: .word 0x02024284
  • Ruby/Sapphire

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    .align 2 .POKEMON_PARTY: .word 0x03004360
  • Emerald

    Note: The routine is the same as the FR/LG one; just replace the bottom part with the following:

    Code:
    .align 2 .POKEMON_PARTY: .word 0x020244EC

This research document is Copyright © 2010 by HackMew.
You are not allowed to copy, modify or distribute it without permission.
__________________
Reply With Quote