Go Back   The PokéCommunity Forums > ROM Hacking > Research & Development
Reload this Page Taking Pokémon away

Notices
For all updates, view the main page.

Research & Development Got a well-founded knack with ROM hacking? Love reverse-engineering the Pokémon games? Or perhaps you love your assembly language. This is the spot for polling and gathering your ideas, and then implementing them! Share your hypothesis, get ideas from others, and collaborate to create!
Research & Development programs in this forum are subject to moderator approval before they are displayed.



Reply
 
Thread Tools
  #1    
Old January 21st, 2010 (02: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
  #2    
Old January 22nd, 2010 (04:38 AM).
Darthatron's Avatar
Darthatron Darthatron is offline
巨大なトロール。
Silver Tier
 
Join Date: Jan 2006
Location: Melbourne, Australia
Age: 23
Gender: Male
Nature: Modest
Posts: 1,152
Looks good, except for some things that would seem to backfire. If you wouldn't mind telling me if my thoughts are wrong or not, that would be great.

Code:
...
	cmp r4, #0x2
	blt return
	ldr r6, .VAR
...
return:
	strh r5, [r6, #0x10]
	pop {r0-r7, pc}
r4 contains the the Pokemon Amount and if it's less than 2 then it quits, but when quitting wouldn't it write 0x0 to the address 0x00000010 in the RAM? Surely it's not meant to do that.

EDIT: Also, isn't it supposed to return the value to 0x800D, not 0x8004? Or did I miss something?
__________________
あなた は しきしゃ です
わたし は ばか です
Reply With Quote
  #3    
Old January 24th, 2010 (02:19 AM).
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314
Quote originally posted by Darthatron:
Looks good, except for some things that would seem to backfire. If you wouldn't mind telling me if my thoughts are wrong or not, that would be great.

Code:
...
	cmp r4, #0x2
	blt return
	ldr r6, .VAR
...
return:
	strh r5, [r6, #0x10]
	pop {r0-r7, pc}
r4 contains the the Pokemon Amount and if it's less than 2 then it quits, but when quitting wouldn't it write 0x0 to the address 0x00000010 in the RAM? Surely it's not meant to do that.

EDIT: Also, isn't it supposed to return the value to 0x800D, not 0x8004? Or did I miss something?
Not really... since the value of r6 would then be unpredictable, a random address would be used, basically. E.g. it would not work properly, obviously. I fixed that already even before posting this, anyway. As for the return value, that's correct. Because variable 0x8004 is exactly 0x10 byte before 0x800D.
__________________
Reply With Quote
  #4    
Old February 25th, 2010 (08:53 AM).
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314
Bumping this because I just wanted to say I've updated and fixed the first routine.
In case you used it before February 13th, I strongly suggest you to get the new one.
__________________
Reply With Quote
  #5    
Old March 4th, 2010 (11:19 AM).
Ben.'s Avatar
Ben. Ben. is offline
Orange I s l a n d s~
Silver Tier
 
Join Date: Jun 2009
Location: England
Age: 18
Gender: Male
Nature: Quirky
Posts: 626
Send a message via Windows Live Messenger to Ben.
Looks great, HackMew.
I will be using this, thanks a bunch!
__________________


Reply With Quote
  #6    
Old April 3rd, 2010 (12:07 AM).
xGGxToiZ's Avatar
xGGxToiZ xGGxToiZ is offline
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 19
Gender: Male
Nature: Modest
Posts: 44
Alright! The routine worked!
Thank you, again!

My, you are the best hacker I've ever seen. (And good with ASM too )

~
__________________


JOHTO ELITE FOUR


. . .

Reply With Quote
  #7    
Old April 8th, 2010 (02:40 PM).
altariaking's Avatar
altariaking altariaking is offline
Needs NO VMs...
 
Join Date: Dec 2009
Location: Scotland, Lesmahagow
Age: 40
Gender: Male
Nature: Naive
Posts: 1,098
Send a message via Windows Live Messenger to altariaking
looks good. it didn't work for me but then i can only apply asm and then never be able to use it lol. i tried to take away treeko with
setvar 0x8004 0x115
...i know, my scripting is bad...
__________________
http://www.pokecommunity.com/member.php?u=253113
Reply With Quote
  #8    
Old April 8th, 2010 (02:45 PM).
NarutoActor's Avatar
NarutoActor NarutoActor is offline
The rocks cry out to me
Silver Tier
 
Join Date: Jan 2009
Location: Brooklyn/Marlboro
Age: 21
Gender: Female
Nature: Bashful
Posts: 1,975
Send a message via AIM to NarutoActor Send a message via Windows Live Messenger to NarutoActor
pretty sure that the var should be set to the slot of the pokemon you want to take away(1-6) not the actual species.
__________________
~There are those people who understand hex, F the rest
Reply With Quote
  #9    
Old April 8th, 2010 (03:01 PM).
altariaking's Avatar
altariaking altariaking is offline
Needs NO VMs...
 
Join Date: Dec 2009
Location: Scotland, Lesmahagow
Age: 40
Gender: Male
Nature: Naive
Posts: 1,098
Send a message via Windows Live Messenger to altariaking
ok, tried it now, and it works, but i have to talk to the person twice.
__________________
http://www.pokecommunity.com/member.php?u=253113
Reply With Quote
  #10    
Old April 8th, 2010 (06:49 PM).
Darthatron's Avatar
Darthatron Darthatron is offline
巨大なトロール。
Silver Tier
 
Join Date: Jan 2006
Location: Melbourne, Australia
Age: 23
Gender: Male
Nature: Modest
Posts: 1,152
Quote originally posted by altariaking:
ok, tried it now, and it works, but i have to talk to the person twice.
You need to set the variables, THEN use callasm.
__________________
あなた は しきしゃ です
わたし は ばか です
Reply With Quote
  #11    
Old April 10th, 2010 (02:51 AM).
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314
Quote originally posted by Ben.:
Looks great, HackMew.
I will be using this, thanks a bunch!
You're welcome.


Quote originally posted by xGGxToiZ:
Alright! The routine worked!
Thank you, again!

My, you are the best hacker I've ever seen. (And good with ASM too ^^)

~ ^^
Thanks :)


Quote originally posted by altariaking:
looks good. it didn't work for me but then i can only apply asm and then never be able to use it lol. i tried to take away treeko with
setvar 0x8004 0x115
...i know, my scripting is bad...
No, the routine doesn't work like that; the setvar 0x8004 needs the value of the actual slot of your Pokémon party. The first one would be setvar 0x8004 0x0 and so on.


Quote originally posted by NarutoActor:
pretty sure that the var should be set to the slot of the pokemon you want to take away(1-6) not the actual species.
Almost right. The first slot is 0x0, just like the select Pokémon special(s). I did that for compatibility, indeed.
__________________
Reply With Quote
  #12    
Old April 17th, 2010 (02:02 AM). Edited April 17th, 2010 by xGGxToiZ.
xGGxToiZ's Avatar
xGGxToiZ xGGxToiZ is offline
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 19
Gender: Male
Nature: Modest
Posts: 44
Edit2: I managed to solve the problem! You just need to switch your main Pokémon with the "?". Then you use an item from your bag and it disappears! (Needs to be refreshed?)

Still, taking Pokémon away is cool!
__________________


JOHTO ELITE FOUR


. . .

Reply With Quote
  #13    
Old April 18th, 2010 (08:27 AM).
Johto_legend's Avatar
Johto_legend Johto_legend is offline
 
Join Date: Jan 2010
Gender: Male
Posts: 186
could someone give an example of using this in a script for ruby. im just very confused by asm.
Reply With Quote
  #14    
Old April 18th, 2010 (10:06 AM).
altariaking's Avatar
altariaking altariaking is offline
Needs NO VMs...
 
Join Date: Dec 2009
Location: Scotland, Lesmahagow
Age: 40
Gender: Male
Nature: Naive
Posts: 1,098
Send a message via Windows Live Messenger to altariaking
you don't need asm to script...
__________________
http://www.pokecommunity.com/member.php?u=253113
Reply With Quote
  #15    
Old April 19th, 2010 (06:03 AM).
Shiny Quagsire's Avatar
Shiny Quagsire Shiny Quagsire is offline
STOP HIM SAM, HE'S GONNA TELL US A STORY!!!
 
Join Date: May 2009
Location: Hoenn Safari Zone
Age: 17
Gender: Male
Nature: Jolly
Posts: 689
The only part that's asm is inserting the compiled asm into the game. To use the asm, put this in your script:

setvar 0x8004 0x0 (Party slot. This is the first slot)
callasm 0x(ASM OFFSET)
__________________



Reply With Quote
  #16    
Old April 19th, 2010 (06:12 AM).
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314
Quote originally posted by xGGxToiZ:
Edit2: I managed to solve the problem! You just need to switch your main Pokémon with the "?". Then you use an item from your bag and it disappears! (Needs to be refreshed?)

Still, taking Pokémon away is cool! ^^
Well, before you removed the script you had a setvar 0x8004 0x1, and then the callasm. Could you tell me what was the script meant to do, exactly?
__________________
Reply With Quote
  #17    
Old April 23rd, 2010 (12:57 AM). Edited April 25th, 2010 by xGGxToiZ.
xGGxToiZ's Avatar
xGGxToiZ xGGxToiZ is offline
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 19
Gender: Male
Nature: Modest
Posts: 44
Quote originally posted by HackMew:
Well, before you removed the script you had a setvar 0x8004 0x1, and then the callasm. Could you tell me what was the script meant to do, exactly?
Well, my script was supposed to loan you a Pokémon then have a wildbattle with your soon-to-be starter. (I used a special along with setwildbattle.)

Then after catching your starter, the loaned Pokémon was supposed to be erased so that you only have your starter.

Thing is, there's are a blank spot before the starter.
(To fix it, you need to access the Pokémon Menu then you have to switch the two Pokémon then use an item from your bag before it disappears.)

Oh and one more thing, that script was messed up, I meant it to be
setvar 0x8004 0x0 to erase the first Pokémon.

I'm using the EraseFirstPokemon routine. (Was it unnecessary to put a setvar since it Erases the first Pokémon?)

To see the Wild Battle, click Here.
To see the Battle, click Here. (Low quality, sped up)
To see how to make the empty slot disappear, click Here.

Hope you can see through the problem . .

^^

Edit: Solved it! It's a sin to use EraseFirstPokemon in that type of script, I need to use the first one.
Whew! (Because, it only ERASES the POKEMON right? It doesn't take?)
__________________


JOHTO ELITE FOUR


. . .

Reply With Quote
  #18    
Old April 25th, 2010 (05:45 AM).
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314
Quote originally posted by xGGxToiZ:
Well, my script was supposed to loan you a Pokémon then have a wildbattle with your soon-to-be starter. (I used a special along with setwildbattle.)

Then after catching your starter, the loaned Pokémon was supposed to be erased so that you only have your starter.

Thing is, there's are a blank spot before the starter.
(To fix it, you need to access the Pokémon Menu then you have to switch the two Pokémon then use an item from your bag before it disappears.)

Oh and one more thing, that script was messed up, I meant it to be
setvar 0x8004 0x0 to erase the first Pokémon.

I'm using the EraseFirstPokemon routine. (Was it unnecessary to put a setvar since it Erases the first Pokémon?)

To see the Wild Battle, click Here.
To see the Battle, click Here. (Low quality, sped up)
To see how to make the empty slot disappear, click Here.

Hope you can see through the problem . .

^^

Edit: Solved it! It's a sin to use EraseFirstPokemon in that type of script, I need to use the first one.
Whew! (Because, it only ERASES the POKEMON right? It doesn't take?)
Well... I watched the videos. And yeah, you shouldn't use EraseFirstPokemon at all: that's only meant to erase the first, and only the first, Pokémon in your party when you have only one Pokémon though (because the TakePokemon wouldn't work in that case, due to the safety checks). Anyway, while TakePokemon can actually take away any Pokémon in the team (as long as the necessary conditions are met), how can you be sure that the borrowed Pokémon (the one that should be removed from the team) is always the first one in the party? The player could change the order eventually. Have you thought about that?
__________________
Reply With Quote
  #19    
Old April 26th, 2010 (12:43 AM).
xGGxToiZ's Avatar
xGGxToiZ xGGxToiZ is offline
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 19
Gender: Male
Nature: Modest
Posts: 44
Right after you catch your starter, the loaned Pokémon is taken instantly. (The script doesn't stop after the battle, the whole battle against the starter is a special and oh, it's a level script to be exact.)

So that means, the loaned Pokémon will always be the first and the Pokémon menu will be available when the script ends.
__________________


JOHTO ELITE FOUR


. . .

Reply With Quote
  #20    
Old April 28th, 2010 (08:16 AM).
HackMew's Avatar
HackMew HackMew is offline
Mewtwo Strikes Back
Crystal Tier
 
Join Date: Jun 2006
Posts: 1,314
Quote originally posted by xGGxToiZ:
Right after you catch your starter, the loaned Pokémon is taken instantly. (The script doesn't stop after the battle, the whole battle against the starter is a special and oh, it's a level script to be exact.)

So that means, the loaned Pokémon will always be the first and the Pokémon menu will be available when the script ends.
I see. Well, when I tried the routine on Ruby it worked fine, so it might have something to do with the special you used. So please send me the full script either via PM/VM.
__________________
Reply With Quote
  #21    
Old May 22nd, 2010 (11:31 PM). Edited May 22nd, 2010 by krillian.
krillian's Avatar
krillian krillian is offline
 
Join Date: Apr 2010
Gender: Male
Posts: 42
I can't get it to work an what is ASM routine?

This does look like an awesome feature.

However putting 'special 0x29' into XSE is much better and easier So people who can't get this to work just do that
Reply With Quote
  #22    
Old February 11th, 2011 (07:24 PM).
Corvus of the Black Night's Avatar
Corvus of the Black Night Corvus of the Black Night is offline
Wild Duck Pokémon
Gold Tier
CS
 
Join Date: Feb 2009
Location: With the Birds
Age: 22
Gender: Other
Nature: Impish
Posts: 3,429
*bump-a-matic*

I was wondering, this routine specifies slot, correct, and can't do... Pokemon? So say I wanted to remove, say, a Grovyle... would I need to compile a separate ASM routine to identify which slot has Grovyle, then combine it with the Taking Pokemon Away routine to remove Grovyle? Because someone could easily just swap the team around and then Grovyle wouldn't be in a set place anymore... ._.'
Reply With Quote
  #23    
Old April 18th, 2013 (06:39 AM). Edited April 18th, 2013 by BlackWhiteRobin.
BlackWhiteRobin's Avatar
BlackWhiteRobin BlackWhiteRobin is offline
 
Join Date: Sep 2012
Location: Want to know? VM me.
Age: 17
Gender: Male
Nature: Quirky
Posts: 400
Send a message via Windows Live Messenger to BlackWhiteRobin
*bump*

Do I have to compile both routines to make setvar 0x8004 0x(let's say 0x5) work?


EDIT: Nevermind. I should have read the whole description.
__________________
LET'S PARTY!
Reply With Quote
  #24    
Old April 18th, 2013 (09:38 AM).
hackstar's Avatar
hackstar hackstar is offline
Check it out!!
 
Join Date: Jan 2013
Location: Dhaka
Gender: Male
Nature: Bashful
Posts: 157
what a great researched by hackmew! nut I cant seem to understand..
__________________
Do not waste your time by seeing my signature.
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are UTC -8. The time now is 06:06 PM.