Main Menu

Glitches

References/Resources

Affiliates

Technical

Search Wiki

Toolbox

Glitch Pokédex flag
 Page | Discussion | View source | History

From Glitch City Laboratories

(Redirected from Glitch Pokédex flags)
Jump to: navigation, search
Bulbapedia also has an article about Glitch Pokédex flag.

In Pokémon Red, Blue, and Yellow, glitch Pokédex flags are "seen" and "own" Pokédex flags for glitch Pokémon with Pokédex numbers 152-255 and 0. While every valid Pokémon in the game has their "seen" and "own" flags in two 19-byte flag arrays, glitch Pokémon with invalid Pokédex numbers (with the exception of No. 152) extrapolate from the "own" flags into the "seen" flags, and from the "seen" flags into bag items. Therefore, setting or checking those flags may have unintuitive results.

The most well-known case of glitch Pokédex flags is the "seen" flag of Pokédex number 0 (e.g. MissingNo., 'M (00)), which is treated as "No. 256" due to how this particular flag array operation is implemented. This flag corresponds to the most significant bit of the quantity of item 6 in the bag, so setting it (by encountering or catching those Pokémon) will increase the quantity of item 6 by 128 if it is not already greater or equal to 128. This effect is commonly known as item duplication. It is the most common reason that makes an encounter with MissingNo. or 'M (00) desirable, and it is also the usual way to set up item underflow for an expanded item pack.

Not all glitch Pokémon have glitch Pokédex flags: Glitch Pokémon with Pokédex numbers 1-151, i.e. hybrids of valid Pokémon, share the Pokédex flags of those valid Pokémon, so encountering or catching them will just set those valid Pokédex flags.

This article may need a cleanup for better quality.
Sprite chaos D057.png
If possible, please edit this article to improve factors like the readability, accuracy and clarity of the article.


Why glitch flags?

In computer programming, and games are no exception to this, everything is numbers. Thus, each Pokémon is assigned a number, called its ID. The game identifies each Pokémon using its ID, and each ID corresponds to a specific Pokémon.

When the game wants to retrieve or edit the Pokédex flags of Pokémon X, it gets the flag with the same ID as the Pokémon (eg, the first flag of the "encountered" list is associated with Pokémon ID 1, etc.)

Since a flag is represented by a bit, and a byte is 8 bits large, the game does more or less the following :

  1. Get byte number (Pokédex ID - 1) / 8 in the corresponding table, rounding down.
  2. Tamper with its ( (Pokédex ID - 1) % 8)th flag (Note : % is the modulo operator).

Why "Pokédex ID-1"? Because in computer programming, IDs start at 0 (for mathematical and convenience reasons). So, instead of going from 1 to 151, internally, IDs go from 0 to 150. For the same reason, the bits of a byte are numbered from 0 (rightmost) to 7 (leftmost).

For example, take Generation I and its 151 (non-glitch) Pokémon. We need to store all the flags in an integer amount of bytes, hence, 19 bytes (152 bits) are used.

Now, imagine we caught a Rattata (Pokédex ID 19). The game starts at address D2F7 (wPokedexOwned), and advances (18 / 8 :) 2 bytes forward. Then it sets bit (18 % 8 :) 2, because we have captured it.

Now, this method works fine for all IDs up to 151. But what would happen with higher IDs? You guessed it, the game will go beyond the end of the Pokédex flags table. (The exception being Pokédex flag 152, which is still in-bounds, and has its own unused bit), and will affect the player's inventory.

The more complicated case is Pokémon with ID 0 (like Missingno or 'M (R/B)), because upon subtracting 1 (Pokédex ID - 1, remember?), the 0 underflows to 255.

Effects

Setting a flag (whether it be "seen" or "caught") modifies one bit in memory. The most famous example is when seeing Missingno, where it sets bit 7 of the quantity of the 6th item in the player's inventory (which is why it is known as "gives 128 if has less than 128").

The other way around is that if a Pokémon is marked as "already caught", its Pokédex entry won't show up. Since some glitch Pokémon's Pokédex entries crash the game, they are required to be "already caught" to be catchable without freezing.

Via "seen" flags

  • Item duplication: Involves the game adding to a specific item quantity in the player's inventory. The most infamous example is the glitch Pokémon MissingNo. and 'M (00) adding 127 to the sixth item quantity upon encountering it or catching it, if the value is less than 128.
  • Item mutation: Involves the game changing an item's ID in the player's inventory. One example is glitch Pokémon 94 (0xF1).
  • Total items changing glitch Pokémon: Only caused by Pokédex numbers between 153-160
  • Pokémon No. 152: Only applies to アノ゙ (CC). Has its own viewable Pokédex entry, even from the Pokédex menu, and without any further glitches.

Note that the "seen" flags are set not only when the Pokémon is encountered in battle, but also when the Pokémon is obtained through a normal means, such as by catching, from evolution, or directly given by an NPC.[1] A common trick is to put a single consumable item usable in battle (e.g. an X Special) in the sixth item slot, encounter MissingNo. or 'M (00) to set its quantity to 129, use that item twice so that there are 127 left, then capturing the Pokémon to duplicate the item again, setting the quantity to 255 with a single encounter. (This does not work if the player throws a Poké Ball from the sixth slot while there are 128, because the quantity of Poké Balls is decremented after the game deals with Pokédex flags.)

Via "own" flags

  • Setting Pokémon as seen: The flag for a glitch Pokémon with ID beyond 151 being 'own'ed will set an unrelated Pokémon as seen. Example: MissingNo. and Cubone.
  • Pokémon No. 152 (see above)

References

  1. When catching a Pokémon, LoadEnemyMonData is called again, which has the side effect of setting the "seen" flag again. The same mechanism is used when directly given a Pokémon by an NPC if it is sent to the box, while the case of adding to the party is handled by the AddPartyMon function.