• 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?".
  • Staff applications for our PokéCommunity Daily and Social Media team are now open! Interested in joining staff? Then click here for more info!
  • 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.

Code: Mega Evolutions and Primal Reversion

Touched

Resident ASMAGICIAN
  • 625
    Posts
    10
    Years
    • Age 122
    • Seen Feb 1, 2018
    For Emerald see this post by kleenexfeu.

    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.
     
    Last edited:

    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
     
    Wow this is great Touched! Thank you for sharing this! Also I have questions ^ what PurpleOrange said :D
     
    Great work on this. Can we use this for stance change?
     
    Wow this is great Touched! Thank you for sharing this! Also I have questions ^ what PurpleOrange said :D

    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)

    [PokeCommunity.com] Mega Evolutions and Primal Reversion


    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:

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

    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

    [PokeCommunity.com] Mega Evolutions and Primal Reversion


    [PokeCommunity.com] Mega Evolutions and Primal Reversion

    Interesting. Could you post a video and source code for this? I would be good to combine projects if possible.
     
    Nice work, Touched! I hope to see the Emerald version of this.
     
    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.


    Very nice. Could you show me the code for this? I would like to see how you programmed this.
     
    Absolutely incredible!

    I'm so waiting for the instructions Touched!
     
    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!
     
    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.
     
    Wow! This is great!
    I'm waiting for the complete code of this hack!
     
    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.

    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.
     
    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...
     
    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.
     
    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();
     
    Last edited:
    Being blown away with all of this. Kudos to both of you guys. This is all crazy awesome.
     
    Back
    Top