The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > ROM Hacking > Research & Development
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

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.


Advertise here

Reply
 
Thread Tools
  #1    
Old January 21st, 2010, 02:42 AM
HackMew's Avatar
HackMew
Mewtwo Strikes Back
 
Join Date: Jun 2006

Advertise here

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

Last edited by HackMew; May 1st, 2010 at 07:03 AM.
Reply With Quote
  #2    
Old January 22nd, 2010, 04:38 AM
Darthatron's Avatar
Darthatron
巨大なトロール。
Community Supporter Tier 2
 
Join Date: Jan 2006
Location: Melbourne, Australia
Age: 22
Gender: Male
Nature: Modest
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
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by Darthatron View Post
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
Mewtwo Strikes Back
 
Join Date: Jun 2006
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.
Orange I s l a n d s~
Community Supporter Tier 2
 
Join Date: Jun 2009
Location: England
Age: 18
Gender: Male
Nature: Quirky
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
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 18
Gender: Male
Nature: Modest
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
Needs NO VMs...
 
Join Date: Dec 2009
Location: Scotland, Lesmahagow
Age: 40
Gender: Male
Nature: Naive
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
The rocks cry out to me
Community Supporter
 
Join Date: Jan 2009
Location: Brooklyn/Marlboro
Age: 20
Gender: Female
Nature: Bashful
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
Needs NO VMs...
 
Join Date: Dec 2009
Location: Scotland, Lesmahagow
Age: 40
Gender: Male
Nature: Naive
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
巨大なトロール。
Community Supporter Tier 2
 
Join Date: Jan 2006
Location: Melbourne, Australia
Age: 22
Gender: Male
Nature: Modest
Quote:
Originally Posted by altariaking View Post
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
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by Ben. View Post
Looks great, HackMew.
I will be using this, thanks a bunch!
You're welcome.


Quote:
Originally Posted by xGGxToiZ View Post
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 View Post
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 View Post
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
xGGxToiZ's Avatar
xGGxToiZ
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 18
Gender: Male
Nature: Modest
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


. . .


Last edited by xGGxToiZ; April 17th, 2010 at 11:52 PM. Reason: Solved it!
Reply With Quote
  #13    
Old April 18th, 2010, 08:27 AM
Johto_legend's Avatar
Johto_legend
Smoochum
 
Join Date: Jan 2010
Gender: Male
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
Needs NO VMs...
 
Join Date: Dec 2009
Location: Scotland, Lesmahagow
Age: 40
Gender: Male
Nature: Naive
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
どないやねん, ヤドン
 
Join Date: May 2009
Location: Hoenn Safari Zone
Age: 16
Gender: Male
Nature: Jolly
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
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by xGGxToiZ View Post
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
xGGxToiZ's Avatar
xGGxToiZ
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 18
Gender: Male
Nature: Modest
Quote:
Originally Posted by HackMew View Post
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


. . .


Last edited by xGGxToiZ; April 25th, 2010 at 01:19 AM. Reason: Solved! ^^
Reply With Quote
  #18    
Old April 25th, 2010, 05:45 AM
HackMew's Avatar
HackMew
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by xGGxToiZ View Post
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
>.//:SO HOT:\\.<
 
Join Date: Mar 2010
Location: We're now near the Tin Tower! . xD
Age: 18
Gender: Male
Nature: Modest
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
Mewtwo Strikes Back
 
Join Date: Jun 2006
Quote:
Originally Posted by xGGxToiZ View Post
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
krillian's Avatar
krillian
Beginning Trainer
 
Join Date: Apr 2010
Gender: Male
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

Last edited by krillian; May 22nd, 2010 at 11:51 PM.
Reply With Quote
  #22    
Old February 11th, 2011, 07:24 PM
daigonite's Avatar
daigonite
"PLAAAY MY GAAAAME!!!1"
Community Supporter
 
Join Date: Feb 2009
Location: With the Birds
Age: 21
Nature: Impish
*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
robin22gongon's Avatar
robin22gongon
 
Join Date: Sep 2012
Location: Want to know? VM me.
Age: 16
Gender: Male
Nature: Quirky
Send a message via Windows Live Messenger to robin22gongon
*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!

Last edited by robin22gongon; April 18th, 2013 at 03:44 PM.
Reply With Quote
  #24    
Old April 18th, 2013, 09:38 AM
hackstar's Avatar
hackstar
Check it out!!
 
Join Date: Jan 2013
Location: Dhaka
Gender: Male
Nature: Bashful
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


Advertise here
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
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 11:03 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.