Go Back   The PokéCommunity Forums > ROM Hacking > Research & Development
Reload this Page Development: Mega Evolutions and Primal Reversion

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 April 29th, 2015 (01:49 PM). Edited 1 Week Ago by Touched.
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
A while back, some hacker posted a thread here on the same topic - however they refused to release the source and instead used the thread to advertise their hack/brag. This isn't that. As far as I'm concerned Mega Evolution should function exactly like Gen 6 or it shouldn't be implemented at all. Despite this, Mega Evolution remains a popular "feature" in many hacks - hackers resort to using true evolutions instead of implementing them properly.

So before this becomes tl;dr, here is a video sample. Thanks to SphericalIce for letting me use the video from his hack, Pokémon Gaia.



This code works by hacking the existing evolution table. I added a custom evolution type (0xFE) that allows you to do Mega Evolutions. The variants (Wishing, standard Mega Evolution and Primals) are controlled by a unused halfword at the end of each evolution entry. The level argument is either an item (Mega Stone/Orb) or a move depending on this variant. Because I'm using the evolution table, it should be really easy to modify existing tools to edit these Megas.

I've also made it possible to use any item index as the Mega Accessory (it displays the Standard Mega evolution message) for aesthetic purposes.

This code is open source and available on my GitHub. I will port to Emerald when it's completed.

Right now, Mega Evolution is triggered by pressing Start when selecting an attack, which is reflected in the button. The button image is pretty simple to change, however the alternate palettes (for enabled and unusable) are determined by the code.

There are still a few bugs, and it doesn't work with link battles, so stay tuned for updates.

Documentation:

Configuration:

See the file src/config.h when doing the insertion step. There are a number of variable indices and item indices you can change there.

Code:
#define KEYSTONE_PLAYER_VAR 0x4001 /* Variable that holds item index for player keystone */
#define KEYSTONE_OPPONENT_VAR 0x4002 /* Same as above but for partner */
#define KEYSTONE_DEFAULT 0x161    /* Default Key Stone item index */
Where it says "#define XXX 0xSOMEHEXNUMBER" Change ONLY 0xSOMEHEXNUMBER and leave the rest the same so that the code can find your changes. KEYSTONE_PLAYER_VAR is the variable used to store the item index for the player's keystone and KEYSTONE_OPPONENT_VAR is the same, but for the opponent (see Usage below). If, for some reason, you set the variable for KEYSTONE_OPPONENT_VAR to 0, then the message for mega evolution will default to using whatever item index whatever you have in KEYSTONE_DEFAULT. By default this is configured to "Gold Teeth" so you'll probably want to change it (despite their awesome power). These variables help you with tiny story-telling details that are probably insignificant, but I judged them to be important in my perfectionism.

The remaining configuration options are for controlling the colours that are changed in the Mega Evolution healthbox addition in it's various states. You can change the sprite just by replacing the file in the "assets" folder. You then will probably need to change the colours here (and the number of colours you ignore) in these options. The code changes parts of the palette to a lighter variant or desaturates them entirely, so you need to set these correctly lest your sprite look funny. If you have changed your HP box at all, this might be necessary to change. I will add options for changing the relative X and Y position of this sprite if it becomes an issue.

Inserting (window users): See this post

Usage:

Mega evolutions are made using the evolution table data. It is preferable to hex edit these until tool support is adequate (see this guide for how to do this with G3T). Megas have evolution type 0xFE, so that they remain separate from regular evolution types. The unknown hword in this structure should stay 0 for Mega Evolution. Types 1 and 2 are reserved for Primal Reversion and Rayquaza's (move based) Mega Evolution. The target species is the species you want to Mega Evolve into. This Pokemon should have the same Dex number as the original. Try not to change much. You should keep the gender ratio, name, base HP, level curve and learnset the same to prevent strange things from happening. The argument for the mega evolution is the item index of your Mega Stone or Primal Orb. In type 2's case it is the move index.

Next, you need to make the species revert back to their original state. You need to add another evolution table entry, this time to the Pokemon's Mega Form. This should be identical to the one above, except the target species is the non-mega form, and the item index/argument is 0. I did it this way for speed reasons at the cost of making the configuration more complicated - searching through all the evolution data takes too long and makes the game lag.

Lastly, you'll need the item. In config.h, you should have put two free variables you'll use for this hack. The first is for the keystone item index for the player, the second is for the enemy trainer. For the player, simply set this to the index of your mega bracelet/anklet/whatever. You can do this via a script when you award the player their keystone. The code will then check whether you have this item and disabled Mega Evolution if you do not. The enemy trainer is the same, except this won't perform checks. It only changes the item used in the message (like certain characters in ORAS and XY). If you wish to disable Mega Evolution for the player at whatever time, either remove their bracelet item, or set the variable to 0.

Closing notes:

Please submit any issues, bugs and feature requests (or rather, improvements; I don't want large feature requests. Keep it to new configuration settings and such) on GitHub. You'll need an account there, but it helps me track these bugs and mark them as solved. It also allows me to follow up on them better than in this thread. It also is easier for other people to look up issues there.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #2    
Old April 30th, 2015 (12:21 AM).
PurpleOrange's Avatar
PurpleOrange PurpleOrange is offline
still don't know what I'm doing
 
Join Date: Sep 2013
Location: Littleroot Town
Gender: Male
Posts: 152
Quote originally posted by Touched:
holy crap! that's awesome! amazing work touched!!

a couple of quick questions:
1. Does the pokemon revert after battle? (the video didn't show if it did or not)
2. How possible is it for the mega symbol to appear by their name?
3. Have you been able to make mega-evolution only possible once per battle?
of course, i understand that this code's in early stages, i'm just very curious

this is really a great achievement, so kudos to you

let's just hope hackers use this in a good way
__________________

Reply With Quote
  #3    
Old April 30th, 2015 (12:40 AM).
Splash's Avatar
Splash Splash is offline
But nothing happened.
 
Join Date: Oct 2009
Location: Just use an Old Rod
Gender: Male
Nature: Hasty
Posts: 553
Wow this is great Touched! Thank you for sharing this! Also I have questions ^ what PurpleOrange said :D
__________________
༼ つ ◕_◕ ༽つ PRAISE Splash ༼ つ ◕_◕ ༽つ
|VM|Firered A RebooT|PM
|
|Pokemon FlareRed: Total Reboot!
|
Rom Hacking Beginners Click Here
!
Reply With Quote
  #4    
Old April 30th, 2015 (01:23 AM).
KDS's Avatar
KDS KDS is offline
 
Join Date: Jul 2013
Age: 20
Gender: Male
Posts: 207
Great work on this. Can we use this for stance change?
Reply With Quote
  #5    
Old April 30th, 2015 (01:24 AM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Quote originally posted by Splash:
Wow this is great Touched! Thank you for sharing this! Also I have questions ^ what PurpleOrange said :D
Quote originally posted by PurpleOrange:
holy crap! that's awesome! amazing work touched!!

a couple of quick questions:
1. Does the pokemon revert after battle? (the video didn't show if it did or not)
2. How possible is it for the mega symbol to appear by their name?
3. Have you been able to make mega-evolution only possible once per battle?
of course, i understand that this code's in early stages, i'm just very curious

this is really a great achievement, so kudos to you

let's just hope hackers use this in a good way
1) Not yet. I haven't added the necessary hooks yet. I have to make it expire when you faint too.
2) Bela made this, which I hope to emulate (haha)



The part on the left will appear if you can Mega Evolve.

3) Yeah, not yet; but it will be done.

I would also like to get this working for the AI sometime so that we can have fully working mega battles.

EDIT:

Quote originally posted by KDS:
Great work on this. Can we use this for stance change?
Thanks. Yes, I suppose you could - I hadn't really thought of that. Maybe I'll add (optional, through preprocessor macros) stance change when the mega and primal part is complete.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #6    
Old April 30th, 2015 (02:44 AM).
Splash's Avatar
Splash Splash is offline
But nothing happened.
 
Join Date: Oct 2009
Location: Just use an Old Rod
Gender: Male
Nature: Hasty
Posts: 553
I have another question will you make a tool for this? Or even a tutorial on how to insert it? What Bela made is looking pretty sweet btw! I hope it can be implemented that way.
__________________
༼ つ ◕_◕ ༽つ PRAISE Splash ༼ つ ◕_◕ ༽つ
|VM|Firered A RebooT|PM
|
|Pokemon FlareRed: Total Reboot!
|
Rom Hacking Beginners Click Here
!
Reply With Quote
  #7    
Old April 30th, 2015 (03:50 AM).
gujiahao's Avatar
gujiahao gujiahao is offline
 
Join Date: Nov 2013
Gender: Male
Posts: 3
I'm sorry, I am a Chinese, can't speak English, see you MEGA results, I am very happy, because I'm doing this I hope we can have a good communication once if possible



Reply With Quote
  #8    
Old April 30th, 2015 (03:59 AM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Quote originally posted by Splash:
I have another question will you make a tool for this? Or even a tutorial on how to insert it? What Bela made is looking pretty sweet btw! I hope it can be implemented that way.
I'll probably just put instructions in the README. It's not exactly difficult to insert and is entirely automated for testing purposes.

Quote originally posted by gujiahao:
I'm sorry, I am a Chinese, can't speak English, see you MEGA results, I am very happy, because I'm doing this I hope we can have a good communication once if possible



Interesting. Could you post a video and source code for this? I would be good to combine projects if possible.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #9    
Old April 30th, 2015 (04:10 AM).
Percy's Avatar
Percy Percy is offline
Let's moonwalk, sha'mone!
 
Join Date: Sep 2014
Location: Somewhere in the world, obviously
Gender: Male
Nature: Gentle
Posts: 2,207
Nice work, Touched! I hope to see the Emerald version of this.
__________________
Pair | #TeamTrivia
Reply With Quote
  #10    
Old April 30th, 2015 (04:30 AM).
PurpleOrange's Avatar
PurpleOrange PurpleOrange is offline
still don't know what I'm doing
 
Join Date: Sep 2013
Location: Littleroot Town
Gender: Male
Posts: 152
another quick question, how will you go about doing this for rayquaza since it doesn't need a mega stone to evolve?
__________________

Reply With Quote
  #11    
Old April 30th, 2015 (04:31 AM). Edited April 30th, 2015 by Spherical Ice.
gujiahao's Avatar
gujiahao gujiahao is offline
 
Join Date: Nov 2013
Gender: Male
Posts: 3
https://youtu.be/5ZylfytAdgc

Reply With Quote
  #12    
Old April 30th, 2015 (04:58 AM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Quote originally posted by PurpleOrange:
another quick question, how will you go about doing this for rayquaza since it doesn't need a mega stone to evolve?
Rayquaza needs the move Dragon Ascent to evolve. I made it possible to have Mega Evolution variants - one of which checks if you have a certain move and lets you trigger mega Evolution if the Pokemon has learned that move.

Quote originally posted by gujiahao:
Very nice. Could you show me the code for this? I would like to see how you programmed this.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #13    
Old April 30th, 2015 (06:19 AM).
Telemetius Telemetius is offline
 
Join Date: Nov 2014
Gender: Male
Posts: 21
Absolutely incredible!

I'm so waiting for the instructions Touched!
Reply With Quote
  #14    
Old April 30th, 2015 (08:48 PM).
gujiahao's Avatar
gujiahao gujiahao is offline
 
Join Date: Nov 2013
Gender: Male
Posts: 3
I'm very sorry, I'm completely with the ASM programming, because there is no habit of taking notes, so the code is very messy, I think I should have to tidy it up, if use the time。
Reply With Quote
  #15    
Old May 1st, 2015 (04:05 PM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Quote originally posted by gujiahao:
I'm very sorry, I'm completely with the ASM programming, because there is no habit of taking notes, so the code is very messy, I think I should have to tidy it up, if use the time。
It would be nice to see it anyway. Or could you give us a patch?

UPDATE:
Anyway, this hack seems to be moving smoothly. I have it loading from the evolution table. The downside is that you need to define the evolution twice so that the reversion works. The Pokemon revert to their normal forms when you exit a battle or they faint so long as you have this extra entry - otherwise it's permanent.

Next up is making Primal Reversion and AI Mega Evolution!
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #16    
Old May 1st, 2015 (04:24 PM).
Deokishisu's Avatar
Deokishisu Deokishisu is offline
Mr. Magius
 
Join Date: Feb 2006
Location: If I'm online, it's a safe bet I'm at a computer.
Gender: Male
Nature: Relaxed
Posts: 504
Quote originally posted by Touched:
It would be nice to see it anyway. Or could you give us a patch?

UPDATE:
Anyway, this hack seems to be moving smoothly. I have it loading from the evolution table. The downside is that you need to define the evolution twice so that the reversion works. The Pokemon revert to their normal forms when you exit a battle or they faint so long as you have this extra entry - otherwise it's permanent.

Next up is making Primal Reversion and AI Mega Evolution!
Meh, unless people are Mega Evolving Eevee, the extra entries aren't going to be an issue. This is amazing by the way. Is AI Mega Evolution going to be super complicated to code? Because it seems like it's going to be. Awesome work, and thank you for always sharing all of your stuff with the community.
Reply With Quote
  #17    
Old May 1st, 2015 (06:35 PM).
Lance32497's Avatar
Lance32497 Lance32497 is offline
LanceKoijer of Pokemon_Addicts
 
Join Date: Aug 2014
Location: Criscanto town-Ginoa Region xD
Gender: Male
Nature: Adamant
Posts: 576
Wow! This is great!
I'm waiting for the complete code of this hack!
__________________
My Threads

Reply With Quote
  #18    
Old May 2nd, 2015 (04:59 AM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Just to clarify how the extra evolution slot works by way of example. Say I have a Charizard and want Charizard Y. I would add the Charizard evolution using evolution type 0xFE (Mega) and variant 0 (standard Mega Evolution - not sure any tools can edit that padding yet). We used Charizard Y as the target species for the evolution. Next we use the item (Charizardite) as the evolution argument. This is the first evolution. The second is for Charizard Y. We define the 0xFE and variant 0 evolution, with target species Charizard. The argument is 0, which means that it's reversion information. At the end of the battle, the code checks all your party Pokemon for whether they have reversion information and reverts them if they do.

Quote originally posted by Deokishisu:
Meh, unless people are Mega Evolving Eevee, the extra entries aren't going to be an issue. This is amazing by the way. Is AI Mega Evolution going to be super complicated to code? Because it seems like it's going to be. Awesome work, and thank you for always sharing all of your stuff with the community.
I don't think it will be hard at all. Even in Gen 6, the AI just Mega Evolves at the first possible opportunity. I'm going to copy this and make a check before the opponent makes a move:

Code:
if (can_mega_evolve(current_pokemon)) {
    trigger_mega_evolve();
}
So hopefully this shouldn't be too difficult.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #19    
Old May 3rd, 2015 (03:19 AM).
FIQ FIQ is offline
 
Join Date: Nov 2012
Gender: Male
Posts: 39
If you want to maintain 6gen-style AI mega handling -- that AI is also programmed to never select his Mega pokemon until it is the very last standing. This can be blatantly seen by fighting Steven, and if he has 2 pokemon left (Metagross + something else), if that other pokemon cannot touch you at all, he will send it out, and then immediately switch it out.Personally I wouldn't bother with this though, it only makes the AI worse...
Reply With Quote
  #20    
Old May 3rd, 2015 (04:43 AM).
LCCoolJ95's Avatar
LCCoolJ95 LCCoolJ95 is offline
Limited Capacity
 
Join Date: May 2009
Location: The World That Never Was
Age: 20
Gender: Male
Nature: Naive
Posts: 271
Quote originally posted by FIQ:
If you want to maintain 6gen-style AI mega handling -- that AI is also programmed to never select his Mega pokemon until it is the very last standing. This can be blatantly seen by fighting Steven, and if he has 2 pokemon left (Metagross + something else), if that other pokemon cannot touch you at all, he will send it out, and then immediately switch it out.Personally I wouldn't bother with this though, it only makes the AI worse...
Same with Sidney, Phoebe, Glacia, and Drake. They didn't send out their Megas until they were down to their last Pokémon.
__________________
"The greatest obstacle in life is Yourself. Overcome it, and you will achieve the greatest accomplishment of all." -Art Beins, 1982

Pokémon Emerald 650 (Resource Patch): http://www.pokecommunity.com/showthread.php?t=346694
Pokémon Theta Emerald: http://www.pokecommunity.com/showthread.php?t=349258
Reply With Quote
  #21    
Old May 3rd, 2015 (06:13 AM). Edited May 3rd, 2015 by Touched.
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Quote originally posted by FIQ:
If you want to maintain 6gen-style AI mega handling -- that AI is also programmed to never select his Mega pokemon until it is the very last standing. This can be blatantly seen by fighting Steven, and if he has 2 pokemon left (Metagross + something else), if that other pokemon cannot touch you at all, he will send it out, and then immediately switch it out.Personally I wouldn't bother with this though, it only makes the AI worse...
I did some tests (on Sidney) and it if I force him to switch to Absol (with Roar), he immediately Mega Evolves. Maybe this is a bug with switching logic?

Anyhow, I will just force mega evolution - or as daniilS put it:
Code:
if (haz_mega) do_mega();
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #22    
Old May 5th, 2015 (04:01 AM).
Criminon's Avatar
Criminon Criminon is offline
Pokemon: Aqua Blue
 
Join Date: Aug 2012
Gender: Male
Posts: 191
Being blown away with all of this. Kudos to both of you guys. This is all crazy awesome.
__________________
FC: 3582 - 9598 - 9978. Add me!
Reply With Quote
  #23    
Old May 8th, 2015 (03:42 AM).
Sky High's Avatar
Sky High Sky High is offline
Impressive! Most impressive!
 
Join Date: Feb 2014
Location: Shiganshina District
Nature: Adamant
Posts: 183
So, that means should I expand the evolution methods?
__________________

One who does simply watch his own anime.
Reply With Quote
  #24    
Old May 8th, 2015 (05:01 AM).
Touched's Avatar
Touched Touched is offline
Resident ASMAGICIAN
 
Join Date: Jul 2014
Gender: Male
Posts: 333
Quote originally posted by RaileysXerilyasRX:
So, that means should I expand the evolution methods?
You don't need to at all. There is no Pokemon that has a Mega evolution that has a regular evolution, since all Megas are for fully evolved Pokemon anyway. You don't need more than 5 per Pokemon.

If you mean should you expand the ways you can evolve, then again, the answer is no. This hack will not interfere with standard evolutions and is not related to them at all. I'm just reusing the evolution table to store this data as it seemed convenient.
__________________
My Emerald IDB
Knizz's FireRed IDB
I will ASMentor people who exhibit enough enthusiASM. Join the IRC to become an ASMentee.
Reply With Quote
  #25    
Old May 8th, 2015 (06:43 AM). Edited May 8th, 2015 by Exelis'20.
Exelis'20's Avatar
Exelis'20 Exelis'20 is offline
Filipino Pride!
 
Join Date: Dec 2014
Location: Paris, France
Gender: Male
Nature: Jolly
Posts: 13
This looks very awesome! I've tried to insert it following what you've said at the github. But i'm quite lost with this part: Create a directory called 'build' in the project root. I can't understand this... Can you explain it, please?
Reply With Quote
Reply
Quick Reply

Sponsored Links

You may also like.. (Beta)
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 10:39 PM.