Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Generation I Glitch Discussion

mew glitch + item underflow - Page 1

mew glitch + item underflow

Posted by: davidenettuno
Date: 2019-07-15 17:16:03
I'm starting to study pokemon blue techniques. In the video I would like to understand what exactly happens in memory after activating the item underflow glitch. Because it positions itself in that specific spot for slowpoke combat
https://www.youtube.com/watch?v=8dyE0XWNylA

Re: mew glitch + item underflow

Posted by: Sherkel
Date: 2019-07-15 17:24:50
wNumBagItems is changed to something above 20. In the case of underflow, it's "decreasing" it from 0 to 255.

Also, welcome!

Re: mew glitch + item underflow

Posted by: davidenettuno
Date: 2019-07-18 14:26:22
Thanks for the reply. But would you mind explaining in detail?

Re: mew glitch + item underflow

Posted by: Sherkel
Date: 2019-07-18 16:13:49
Shen is using dry underflow in the PC, letting him change bytes at will starting from here: https://github.com/pret/pokered/blob/master/wram.asm#L2637 . A lot of what he does after that is…admittedly beyond me. The basic idea is that it centers around map script pointer manipulation, letting him fight a trainer that has a Slowpoke with the right Special stat to find Mew with the trainer escape glitch without having to actually go to where the trainer is originally located.

Catching all 151 as quickly as possible is pretty complicated and was part of what helped push glitchology to the limits it's reached, and I'm still catching up on a lot of it. The guide here starts with the basics, and the run itself is a matter of combining and executing those in different ways. I'd recommend looking at the links at the beginning of that guide.

Re: mew glitch + item underflow

Posted by: davidenettuno
Date: 2019-07-18 16:55:18
thank you for the help

Re: mew glitch + item underflow

Posted by: Torchickens
Date: 2019-07-20 08:14:04

I'm starting to study pokemon blue techniques. In the video I would like to understand what exactly happens in memory after activating the item underflow glitch. Because it positions itself in that specific spot for slowpoke combat
https://www.youtube.com/watch?v=8dyE0XWNylA


It works something like this.

The cause called "dry underflow" exploits an obscure mechanic that allows item quantities to merge to become one stack if they are the same base item (e.g. two Ultra Ball stacks), as well as
a x255 stack's ability to reduce the number of items by both reducing the number of items in the bag and copying itself after tossing directly above it - which works because Cancel buttons are 0xFF (dec:255), so the game must only move items above that if you tossed all of a stack.

We first toss above x255 to obtain three x255 items at the top with a registered item count of 1. Although the item count is 1, the second item can still be selected (just not possible to use as a Cancel would be). Tossing 253 of the top item leaves us with x2. Swapping the x2 stack with the x255 stack below 'merges' the two, converting the top into x1 and making the item count x0. Repeating this (leaving us with the remainding third x255) due to item count being a standard one byte value underflows x0 by subtracting 1, resulting in an item count of x255.

With the item count of x255, items beyond slot 20 can be selected, and items 1 through 20 occupy memory addresses D31E-D345 (see Game Boy memory structure. Now, items 21 and their quantities will be loaded and upon modification saved as extrapolations of D345; so item 21 is D346, item 21 quantity is D347 and so on - allowing us to have control over unrelated RAM such as your rival's name, the exit map and much more. The memory addresses can be analysed here: https://github.com/pret/pokered/blob/master/wram.asm with corresponding items and quantities here  https://glitchcity.info/wiki/Expanded_bag_item_documentation_(Generation_I) but for elaborate explanations of specific tricks an understanding of how they work is needed; for instance D35F-D360 is a pointer for the top-left tile block of a map. Note that apparently due to an arithmetic error in the engine, items 129-255 are a copy of items 1-128. Additionally if using Yellow you'll have to interpret all of the Red/Blue expanded items pack addresses by -1.

Hope this helps with your questions. :)