Glitch City Laboratories Forums

Lab γ: Video Games and Glitches Discussion => Pokémon Glitch Discussion => Generation I Glitch Discussion => Topic started by: davidenettuno on July 15, 2019, 04:16:03 pm

Title: mew glitch + item underflow
Post by: davidenettuno on July 15, 2019, 04:16:03 pm
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
Title: Re: mew glitch + item underflow
Post by: Sherkel on July 15, 2019, 04:24:50 pm
wNumBagItems is changed to something above 20. In the case of underflow, it's "decreasing" it from 0 to 255.

Also, welcome!
Title: Re: mew glitch + item underflow
Post by: davidenettuno on July 18, 2019, 01:26:22 pm
Thanks for the reply. But would you mind explaining in detail?
Title: Re: mew glitch + item underflow
Post by: Sherkel on July 18, 2019, 03:13:49 pm
Shen is using dry underflow (https://glitchcity.info/wiki/Dry_underflow_glitch) 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 (https://docs.google.com/document/d/1zha5vCRkszVLINahD18Q-ep5sFV4K22muByYm4rPFr0/edit) 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.
Title: Re: mew glitch + item underflow
Post by: davidenettuno on July 18, 2019, 03:55:18 pm
thank you for the help
Title: Re: mew glitch + item underflow
Post by: Evie the Mother Hen ☽ ❤ on July 20, 2019, 07:14:04 am
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 (http://gameboy.mongenel.com/dmg/asmmemmap.html). 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. :)