Item underflow: Difference between revisions

m
clean up, typos fixed: etc) → etc.)
(→‎Method: iirc includes map script pointer, etc.)
m (clean up, typos fixed: etc) → etc.))
Line 7: Line 7:
Keeping the drink in the Bag, the player must repeatedly perform the 255-stack item duplication glitch until the topmost item becomes the acting Cancel button. As mentioned in the item duplication glitch article, at this point the number of items in the Bag and the actual items in the Bag are out of sync; the game believes that the player has 0 items in the [[Bag]], but it also believes that the player has a drink in their Bag. At this point, the player can go to any one of the Saffron City guards and give them the drink to unlock passage to the city (as the game believes that the player has a drink in their Bag to give), but as this is the only drink in their Bag, it will also attempt to decrease the total number of item stacks in the Bag by 1. This will cause the number of items in the Bag to become -1, which underflows to 255 (hence the name of glitch).
Keeping the drink in the Bag, the player must repeatedly perform the 255-stack item duplication glitch until the topmost item becomes the acting Cancel button. As mentioned in the item duplication glitch article, at this point the number of items in the Bag and the actual items in the Bag are out of sync; the game believes that the player has 0 items in the [[Bag]], but it also believes that the player has a drink in their Bag. At this point, the player can go to any one of the Saffron City guards and give them the drink to unlock passage to the city (as the game believes that the player has a drink in their Bag to give), but as this is the only drink in their Bag, it will also attempt to decrease the total number of item stacks in the Bag by 1. This will cause the number of items in the Bag to become -1, which underflows to 255 (hence the name of glitch).


As the game now believes that the player has 255 item slots to scroll through, the player is able to access several important regions of memory that happen to be stored just beyond the items in RAM, and manipulate these memory areas as if they were items (by swapping, tossing, etc). This effectively gives the player arbitrary read and write access to these regions of memory. This perhaps most notably includes the player's current map data and coordinates, and so for example it is possible to instantly complete the game by warping to the [[Hall of Fame]]. Manipulating coordinates is also a relatively easy way to access glitch items such as [[List of unobtainable items#8F|8F]], by standing on a particular tile (such that the player's coordinates are interpreted as the item 8F) and then swapping that item to a normal Bag slot.
As the game now believes that the player has 255 item slots to scroll through, the player is able to access several important regions of memory that happen to be stored just beyond the items in RAM, and manipulate these memory areas as if they were items (by swapping, tossing, etc.). This effectively gives the player arbitrary read and write access to these regions of memory. This perhaps most notably includes the player's current map data and coordinates, and so for example it is possible to instantly complete the game by warping to the [[Hall of Fame]]. Manipulating coordinates is also a relatively easy way to access glitch items such as [[List of unobtainable items#8F|8F]], by standing on a particular tile (such that the player's coordinates are interpreted as the item 8F) and then swapping that item to a normal Bag slot.


This item underflow method can also be performed in a nearly identical manner using a [[Fossil]] and the scientist in the [[Pokémon Lab]] on [[Cinnabar Island]] who revives it and thus removes it from the inventory.
This item underflow method can also be performed in a nearly identical manner using a [[Fossil]] and the scientist in the [[Pokémon Lab]] on [[Cinnabar Island]] who revives it and thus removes it from the inventory.


Restoring the player's Bag to normal can be easily performed by simply obtaining or purchasing various different items; this will bring the number of item stacks in the Bag back up to 0 or usual positive numbers.  
Restoring the player's Bag to normal can be easily performed by simply obtaining or purchasing various different items; this will bring the number of item stacks in the Bag back up to 0 or usual positive numbers.


Importantly, while the item underflow glitch allows nearly arbitrary ''read'' and ''write'' access to memory, it does not allow arbitrary ''execution'' of that memory as code. Hence this glitch, while powerful, is not as powerful as [[arbitrary code execution]] glitches.
Importantly, while the item underflow glitch allows nearly arbitrary ''read'' and ''write'' access to memory, it does not allow arbitrary ''execution'' of that memory as code. Hence this glitch, while powerful, is not as powerful as [[arbitrary code execution]] glitches.


===Dry item underflow===
===Dry item underflow===
The "dry" variant of the item underflow glitch does not require a Saffron City guard to remove a drink from the player's Bag (hence the name) nor the Pokémon Lab scientist to remove a Fossil; thus it can be performed as soon as the player has access to the necessary 255-stack variant of the item duplication glitch (in theory, as soon as they can perform the Extended [[Mew glitch]] or [[Ditto glitch]] to encounter [[Missingno.]]), before reaching Celadon City.
The "dry" variant of the item underflow glitch does not require a Saffron City guard to remove a drink from the player's Bag (hence the name) nor the Pokémon Lab scientist to remove a Fossil; thus it can be performed as soon as the player has access to the necessary 255-stack variant of the item duplication glitch (in theory, as soon as they can perform the Extended [[Mew glitch]] or [[Ditto glitch]] to encounter [[MissingNo.]]), before reaching Celadon City.


This method relies on a little-known feature in that using the Select button to swap two stacks of the same item in fact merges the stacks together (thus subtracting 1 from the number of item stacks in the player's inventory). This effect can occur in normal gameplay; for example, if the player buys 99 [[Potion]]s and then obtains another one, they will have two separate stacks of 99 and 1 Potion(s) respectively. If the player then uses 10 Potions from the stack of 99 (to obtain stacks of 89 and 1), then swaps the two stacks of Potions with the Select button, they will be merged into one stack of 90 Potions.
This method relies on a little-known feature in that using the Select button to swap two stacks of the same item in fact merges the stacks together (thus subtracting 1 from the number of item stacks in the player's inventory). This effect can occur in normal gameplay; for example, if the player buys 99 [[Potion]]s and then obtains another one, they will have two separate stacks of 99 and 1 Potion(s) respectively. If the player then uses 10 Potions from the stack of 99 (to obtain stacks of 89 and 1), then swaps the two stacks of Potions with the Select button, they will be merged into one stack of 90 Potions.