Technical description on how the Mew Glitch works (also known as the long-range trainer glitch), which allows you to get Mew (or any other Pokemon, based on the stats of the last fought Pokemon). Questions? twitter.com/sirdarckcat
3. Background
● It was impossible to get Mew, except by attending Nintendo events, as such
it was very exclusive.
● There was a rumour that you could get Mew behind a truck in SS. Anne, but
it wasn't true. Many similar rumours turned out to be false as well.
4. Background
● However, one of those rumours turned out to be true!
● And at first, it seemed like yet another scam.
5. Background
Apparently first publicly described in March 2003 by Daniel26, but TheScythe
made it popular in a forum a month later in in April (and later on analyzed in depth
by WhteCat). Daniel26 explained the glitch like this:
Ok, first you must not battled the youngster that has a slowpoke (the one past nugget bridge he's
the one looking up, about the 4th trainer)and not battled the gambler next to the right entrance to
saffron city. THE CODE:fly to saffron city go out the right exit, go up to the door little house (don't go
in) press down, quickly press start(before the ! comes onto the gamblers head) fly to cerulan city, go
up nugget bridge battle the youngster, walk where he is looking,(when you walk in front of him make
sure you have 1 or 2 squares away from him) let him walk to you then he will battle you, after the
battle fly to saffron city, try going out the right side exit again, the menu will pop up,press b to get off
it then the screen will flash like when a pokemon appears in the grass, and a wild MEW at LV:7 will
appear.
6. Pre-requisites
● not battled the youngster that has a
slowpoke (the one past nugget bridge he's
the one looking up, about the 4th trainer)
● not battled the gambler next to the right
entrance to saffron city
7. The Glitch
● go up to the door little house (don't go in) press down, quickly press start
9. ● fly to cerulan city, go up nugget bridge battle the youngster, walk where he is
looking,(when you walk in front of him make sure you have 1 or 2 squares
away from him) let him walk to you then he will battle you,
The Setup
10. The Last Step
● after the battle fly to saffron city, try going out the right side exit again, the
menu will pop up,press b to get off it
11. The Last Step
● then the screen will flash like when a pokemon appears in the grass, and a
wild MEW at LV:7 will appear
13. Technical Analysis
● The Glitch
○ Escaping from a battle by flying away
● The Setup
○ Fighting with the slowpoke youngster
● The Last Step
○ Going back to where you ran away
Sources
WhteCat analyzed the glitch and published his notes on "The P Files"
github.com/pret has a disassembled version of most Pokemon games
14. Vocabulary
● Trainer
○ An enemy that will fight you if it sees you.
● Sprite
○ Any in-game object, like a trainer, a door, and so on.
15. Technical Background
● GameBoy works the following way:
○ The screen is drawn
○ Code is executed
○ The screen is drawn
○ Code is executed
○ The screen is drawn
○ Code is executed
○ The screen is drawn
○ Code is executed
○ …
● What is drawn on the screen depends on what the code that ran before says
16. Technical Background
● The code (among other things) does:
○ Walking Animation (move the world around the user)
○ Run Map Scripts (code specific to this part of the world)
○ Detect Buttons (if the user pressed any buttons)
○ Check START Menu (if the user pressed the START button)
● The memory (among other things) contains:
○ Temporal memory for holding in-game data.
○ Medium term memory for storing the state in every map.
○ Read only memory for holding the game's code.
17. Map Scripts
● Most maps contain 3 map scripts:
○ CheckFightingMapTrainers
○ DisplayEnemyTrainerTextAndStartBattle
○ EndTrainerBattle
● CheckFightingMapTrainers
○ code responsible for detecting if any trainer can see the player and then having them walk-up
to the player
● DisplayEnemyTrainerTextAndStartBattle
○ runs after the previous script, and shows the pre-battle text and starts the battle
● EndTrainerBattle
○ finishes the battle and lets the user continue
18. CheckFightingMapTrainers vs. UpdateSprites
● UpdateSprites: Loop over all Sprites
○ Animate sprites (most move even if static)
○ But don't update sprites if currently walking
● CheckFightingMapTrainers: Loop over all Trainers in the map
○ Ignore those that aren't currently visible
○ If the trainer is looking at the user, fight!
This is where the glitch happens!
19. The Glitch
● At first, since the player just moved down, the trainer is not yet visible, and so,
can't engage the player. So the player has a single turn to do something
before the trainer becomes visible.
20. CheckFightingMapTrainers vs. UpdateSprites
● UpdateSprites: Loop over all
Sprites
○ Animate sprites (most
move even if static)
○ But don't update sprites if
currently walking
● CheckFightingMapTrainers:
Loop over all Trainers in the
map
○ Ignore those that aren't
currently visible
○ If the trainer is looking at
the user, fight!
21. CheckFightingMapTrainers vs. UpdateSprites
● The Glitch is simply that there is a "turn" during which the user can do
something (move out, or press START) when the Trainer is not yet visible.
22. Teleport / Fly
● When the user Teleports / Flies to somewhere else, the trainer has no time to
start the battle, but has enough time to move the script for the current map to
DisplayEnemyTrainerTextAndStartBattle
23. DisplayEnemyTrainerTextAndStartBattle
● The Script does the following:
○ Wait for the trainer to finish walking to the player (marked by memory 0xD730)
○ Re-enable the joystick controls (set [wJoyIgnore] = 0)
○ Display the Before Battle Text (marked in wSpriteIndex)
○ Start Battle
24. Teleport / Fly
● When the user Teleports/Flies to another map, the following happens:
○ The current map is left in it's current state
■ This means the "active" script in the current map (route 8) is left as
DisplayEnemyTrainerTextAndStartBattle waiting for memory 0xD730 to be 0.
○ The map where you are flying to is set as the new "current" map.
■ The state for each map is stored separately, so this simply leaves the previous state
untouched.
● So the Script in the map for Route 8 is left as
DisplayEnemyTrainerTextAndStartBattle, so when the user returns to Route
8, this script will continue running (and waiting for 0xD730 to be 0)
25. Teleport / Fly
● Most maps contain 3 map scripts:
○ CheckFightingMapTrainers
○ DisplayEnemyTrainerTextAndStartBattle
○ EndTrainerBattle
● So after the user teleports to a new map, the new map's current script is
CheckFightingMapTrainers, however the game is affected by a couple things:
○ The START button is disabled, because memory at D730 is not clear and the game thinks the
trainer is still walking towards the user. Until the D730 is clear, most actions are disabled.
○ Going back to Route 8 will have all trainers disabled because Route 8 is in the
DisplayEnemyTrainerTextAndStartBattle script, so no trainer will know to look for you, but only
on that map, other maps will run the CheckFightingMapTrainers script.
26. The Setup
● After escaping from Route 8, the player will be crippled by the D730, so he
needs to get that cleared. To do that, the player needs to complete a
DisplayEnemyTrainerTextAndStartBattle routine so that the game clears the
value.
27. The Setup
● By fighting with another trainer that will walk up to you (it has to walk up to
you as otherwise the "walk to user" code won't be called) the game will mostly
go back to a normal state (except Route 8 which is stuck in the battle mode).
28. The Setup
● When the player is fighting, the game copies several values of the pokemon
and the trainer on to memory, such as the pokemon's type, it's level, hitpoints,
as well as stats such as attack, defense, speed and special.
● CopyData which copies bc bytes (=1+5*2=11 bytes) from hl
(=wEnemyMonLevel) to de (=wEnemyMonUnmodifiedLevel=cd23).
29. The Setup
● The address in memory where
this data is copied is CD23, and
the amount of data copied is 11
bytes (NUM_STATS is 5,
hitpoints, attack, defense,
speed, special), so up to CD2D.
● Note, however that the memory
in CD2D is also used for
"wEngagedTrainerClass".
30. The Setup
● This means that wEngagedTrainerClass will be equal to the "special" stat of
the pokemon you fight against. If you fight the youngster, it will be a Slowpoke
with a "special" stat of 21.
31. The Setup
● Finally, after fighting the youngster, which serves two purposes
○ Marking the memory at D730 to 0, so that the DisplayEnemyTrainerTextAndStartBattle script
doesn't think there's a trainer walking.
○ Setting the memory at CD2D to 21 via the Slowpoke's "special" stat, so that the
wEngagedTrainerClass will hold that value when read the next time.
32. The Last Step
● The player can now go back to Route 8. Now, when the user enters Route 8,
the game will still try to run the script DisplayEnemyTrainerTextAndStartBattle
but since we already cleared the D730 memory, the game will try to show the
player the enemy text.
33. The Last Step
● The DisplayEnemyTrainerAndStartBattle script will try to display the text in the
memory pointed by wSpriteIndex, which is the last text shown to the user,
which in our case is usually the START menu. So when the user enters the
map Route 8 the START menu is displayed.
34. The Last Step
● And after the START menu is dismissed, the script starts the battle, to do so,
it initializes the battle (the pokemon to fight, it's level and so on) with the
function InitBattleEnemyParameters.
35. The Last Step
● The wCurOpponent (the pokemon type) is set to wEngagedTrainerClass,
which was set to 21 after fighting against the Youngster's Slowpoke
36. ● Since 21 is less than 200, the battle is defined as a "no trainer" (or "wild")
battle, and the pokemon is loaded as 21. 21 is the pokemon identifier for
MEW, so the player fights a "wild" MEW.
The Last Step