Glitch City Laboratories Forums

Lab γ: Video Games and Glitches Discussion => Pokémon Glitch Discussion => Generation I Glitch Discussion => Topic started by: SatoMew on February 18, 2015, 11:10:57 pm

Title: WTW mechanics discussions
Post by: SatoMew on February 18, 2015, 11:10:57 pm
On an unrelated note, 01xx38CD can be set to 00 to revert the behavior of "walking through walls". I don't know if this was already known since people always mention 010138CD but this is far more practical than disabling the code and entering another map from a warp in order to restore the normal behavior.
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on February 18, 2015, 11:28:40 pm
On an unrelated note, 01xx38CD can be set to 00 to revert the behavior of "walking through walls". I don't know if this was already known since people always mention 010138CD but this is far more practical than disabling the code and entering another map from a warp in order to restore the normal behavior.

Yes. I usually go to CD38 in memory viewer, set it to 01 when I need to and set it to 00 when I want it off (e.g. when I want to use an exit) but people may not be aware you can disable WTW like that.

I don't know if you know, but CD38 is actually set to 01 when you jump off a ledge. If you use 010038CD and try to jump off a ledge, you won't go two tiles below for some reason and you will end up on top of the ledge.

It is also used when a guide takes you somewhere; where it counts down from a value (29h for the person who brings you to the Pewter Gym, 11h for Professor Oak) each step until it becomes 00h, after which:

For Professor Oak - he disappears interestingly, the game locks up (if you set CD38 to 00 early) and the guide music still plays. In at least Yellow you enter the door while CD38 is 01 so this behaviour is not seen.
For the Pewter Gym guy - the music goes back to normal, the guide stops and says "If you have the right stuff, go take on BROCK!" and he starts walking back.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 18, 2015, 11:37:04 pm
I don't know if you know, but CD38 is actually set to 01 when you jump off a ledge. If you use 010038CD and try to jump off a ledge, you won't go two tiles below for some reason and you will end up on top of the ledge.

It is also used when a guide takes you somewhere; where it counts down from a value (29h for the person who brings you to the Pewter Gym, 11h for Professor Oak) each step until it becomes 00h, after which:

For Professor Oak - he disappears interestingly, the game locks up (if you set CD38 to 00 early) and the guide music still plays. In at least Yellow you enter the door while CD38 is 01 so this behaviour is not seen.
For the Pewter Gym guy - the music goes back to normal, the guide stops and says "If you have the right stuff, go take on BROCK!" and he starts walking back.

I didn't know that, interesting. I noticed that guides and guards (like the one in the Safari Zone's gate) were affected by CD38 being set to 00 since the game appeared to loop their scripts until I disabled the code.

...And I just found this: https://sourceforge.net/p/vbam/bugs/116/
I had completely forgotten about it. There are some save files there, in case anyone wants to check them out.
Title: Re: WTW mechanics discussions
Post by: pigdevil2010 on February 22, 2015, 03:26:44 am
On an unrelated note, 01xx38CD can be set to 00 to revert the behavior of "walking through walls". I don't know if this was already known since people always mention 010138CD but this is far more practical than disabling the code and entering another map from a warp in order to restore the normal behavior.

Yes. I usually go to CD38 in memory viewer, set it to 01 when I need to and set it to 00 when I want it off (e.g. when I want to use an exit) but people may not be aware you can disable WTW like that.

I don't know if you know, but CD38 is actually set to 01 when you jump off a ledge. If you use 010038CD and try to jump off a ledge, you won't go two tiles below for some reason and you will end up on top of the ledge.

It is also used when a guide takes you somewhere; where it counts down from a value (29h for the person who brings you to the Pewter Gym, 11h for Professor Oak) each step until it becomes 00h, after which:

For Professor Oak - he disappears interestingly, the game locks up (if you set CD38 to 00 early) and the guide music still plays. In at least Yellow you enter the door while CD38 is 01 so this behaviour is not seen.
For the Pewter Gym guy - the music goes back to normal, the guide stops and says "If you have the right stuff, go take on BROCK!" and he starts walking back.

CD38 tells the game if it's simulating joypad states. This feature is used to make the game controls the player in some scripts. When the game is simulating joypad states, it will completely ignore any collision just like how the game do it with NPC. This means that setting CD38 to 01 will fools the game out that it's simulating joypad states and won't check the collision data. Hence why you can walk through walls.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 22, 2015, 07:03:29 am
CD38 tells the game if it's simulating joypad states. This feature is used to make the game controls the player in some scripts. When the game is simulating joypad states, it will completely ignore any collision just like how the game do it with NPC. This means that setting CD38 to 01 will fools the game out that it's simulating joypad states and won't check the collision data. Hence why you can walk through walls.

pokechu022 once said (https://www.youtube.com/watch?v=gACpaGFFbkg) that CD38 is a step counter. Which one is correct?

In the Generation II games, there are 4 addresses manipulated by the various codes, with each allowing the player to "walk through walls" in one of the four directions (north, south, east, west--not by this order). Is there an address in these games like CD38 of the Generation I games?
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on February 22, 2015, 12:32:44 pm
CD38 tells the game if it's simulating joypad states. This feature is used to make the game controls the player in some scripts. When the game is simulating joypad states, it will completely ignore any collision just like how the game do it with NPC. This means that setting CD38 to 01 will fools the game out that it's simulating joypad states and won't check the collision data. Hence why you can walk through walls.

pokechu022 once said (https://www.youtube.com/watch?v=gACpaGFFbkg) that CD38 is a step counter. Which one is correct?

It could be both/at least CD38 double serves as letting you walk through walls and as a steps left counter. CD38 can act as a value that decreases every step a guide takes. When you follow guide routes from Professor Oak, the Pewter Gum guy or the Pewter Museum guy, it starts at a value and counts down for every step they take (normally until 00 but Oak is an exception) until the guide takes you to your destination. For the Pewter Gym and Pewter Museum guys CD38 becomes 00, causing you to get a message and they start walking back.

For Oak taking you to his lab, CD38 also serves as a steps left counter, but in Red (Blue?) and Yellow it never gets to 00. If you hack it to 00 when Oak is taking you to his lab then Oak disappears, the music still plays and the game locks up.

CD38 is not a steps left counter for certain other things. I will note for reference that there are different addresses for Repel steps left (I think that address can be found in the diassembly) or steps left until you take poison damage/whether you will black out (that is controlled by D13B).

But I don't know anything about what determines the all fainted Pokémon steps left in Yellow (in Yellow, unlike Red/Blue the game will have it so you can only make one step until you black out if you have all fainted Pokémon even if you save and reset (and in Red/Blue you can increase the amount of extra steps you can take by saving and resetting or using the glitch item "il" (hex:6D)).

In the Generation II games, there are 4 addresses manipulated by the various codes, with each allowing the player to "walk through walls" in one of the four directions (north, south, east, west--not by this order). Is there an address in these games like CD38 of the Generation I games?

I don't know off the top of my head, I'm afraid.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 22, 2015, 12:53:13 pm
Thanks for the input :)
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on February 22, 2015, 01:07:34 pm
Thanks for the input :)

You're welcome.

My description is not exactly accurate. CD38 briefly becomes 02, then 01, then 00 when jumping down off a ledge in Red and there is no guide there. I tried setting it to FF when it become 02 and something weird happened; I jumped up instead and the start menu popped up with the controls locked (and I note that FFF9 is still 00 meaning the game is still reading buttons from the 'joypad' but they still have no effect).

(http://i7.minus.com/iHB8DJDzizKmM.png)

Pigdevil2010's explanation explains the start menu thing partly because the game is in the position for simulating button presses and up, down, left, right aren't the only buttons.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 22, 2015, 01:20:18 pm
My description is not exactly accurate. CD38 briefly becomes 02, then 01, then 00 when jumping down off a ledge in Red and there is no guide there. I tried setting it to FF when it become 02 and something weird happened; I jumped up instead and the start menu popped up with the controls locked (and I note that FFF9 is still 00 meaning the game is still reading buttons from the 'joypad' but they still have no effect).

(http://i7.minus.com/iHB8DJDzizKmM.png)

Interesting. I tried the same (FF the moment it became 02) in Japanese Red; it became FB after jumping down the ledge and I can "walk through walls". I did this with the ledge right next to the Pokémon Center in Cerulean City and playing on BGB.

(http://i.imgur.com/EdlVW4Z.png)
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on February 22, 2015, 02:02:07 pm
I forgot to mention something related to the unexpected ledge behaviour.

If after the game does a route (e.g. changing CD38 to someting like 29h and making it count down) you change CD38 to a high value greater than the maxium CD38 value (like what we did for the ledge 02 value) then the game may make 'joypad' inputs not included in the route like going up unexpectedly or opening the start menu.

It turns out that an individual CD38 value may represent one of the button presses or combination of button presses in the route. For example, for talking to the Pewter Gym guy from the left, when CD38 is 15 the game simulates an up press.

So if you kept writing 15 to CD38 during this route you (but not the guide) would keep walking up, and another example would be if you kept writing 07 you would keep walking down.

(http://i2.minus.com/iUTdsZRzNfodE.png)

I think the source of the excessive 'glitch' CD38 value inputs may be extrapolated from the route as it appears in the ROM. Though that is a theory. When I get my own laptop back I will test this theory.

As we have learned from "Brock Through Walls (https://www.youtube.com/watch?v=SM6pp4ewOQM)" to make a route the game looks for coordinates that match your coordinates from where you activated the route, at an address ending in 2, 6, A or E. It then reads a pointer directly following those coordinates that represents what the route is and executes it (so in the format: y, x, path pointer byte 1, path pointer byte 2).

I do not know the data structure of a route, but say it included 50 joypad inputs. If you forced the game to load input 255, maybe the input would be located past where the route is located in the ROM (so it would be unrelated data executed as a button).
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 22, 2015, 02:15:02 pm
That would explain the different results we got, correct? Actually, isn't the menu open automatically when you perform the Mew glitch as soon as you arrive at the exact tile on Route 24? I'm not sure of that behavior right now (may be a false memory) but perhaps it happens due to CD38 changing?
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on February 22, 2015, 02:56:01 pm
Maybe. To grasp at straws it could be a memory related thing too though.

That would explain the different results we got, correct? Actually, isn't the menu open automatically when you perform the Mew glitch as soon as you arrive at the exact tile on Route 24? I'm not sure of that behavior right now (may be a false memory) but perhaps it happens due to CD38 changing?

I don't think that's related to CD38 personally.

While the start menu often pops up when you return to the place you escaped from after beating a Trainer on another route, what pops up is determined by which text box you viewed last.

The game stores the index number of the last text box in CF13. If you opened the start menu it is 00 and the game seems to bring up the start menu for 00 values for every applicable Trainer-Fly place.

However, you can do things like talk to people and view signs to get different CF13 values. Different maps have different text boxes, so you can get unexpected messages. For example, one of the signs in Lavender Town is "May the Souls of POKéMON Rest Easy"(...) and has an ID of 09. On Route 8 (west of Lavender Town and where you can set up a Trainer-Fly), ID 09 belongs to the text of a Lass.

This means if you Trainer-Flied from Route 8, beat a Trainer from another route, viewed that sign in Lavender Town then returned to Route 8 the game would bring up her text (I confirmed it bringing up her text from after battle and I previously beat her, maybe the game would bring up her text before battle if you didn't beat her?)

Is it OK if I split the talk about CD38 from this thread Sato? It's getting deep and not related to the glitch Pikachu eye states.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 22, 2015, 02:59:46 pm
I see, thanks for clarifying.

Is it OK if I split the talk about CD38 from this thread Sato? It's getting deep and not related to the glitch Pikachu eye states.

Sure, go ahead and split it ;)
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on February 22, 2015, 03:07:43 pm
You're welcome.

Cool. Split.
Title: Re: WTW mechanics discussions
Post by: pigdevil2010 on February 22, 2015, 06:49:55 pm
CD38 tells the game if it's simulating joypad states. This feature is used to make the game controls the player in some scripts. When the game is simulating joypad states, it will completely ignore any collision just like how the game do it with NPC. This means that setting CD38 to 01 will fools the game out that it's simulating joypad states and won't check the collision data. Hence why you can walk through walls.

pokechu022 once said (https://www.youtube.com/watch?v=gACpaGFFbkg) that CD38 is a step counter. Which one is correct?

In the Generation II games, there are 4 addresses manipulated by the various codes, with each allowing the player to "walk through walls" in one of the four directions (north, south, east, west--not by this order). Is there an address in these games like CD38 of the Generation I games?

Because it is an array index of CCD3. If you execute this code in Red/Blue:
Code: [Select]
call $3486while CD38 is set to 4 and CCD3-CCD6 are filled with 08 (start button joypad constant). You can see that the game starts to act like you pressed start button 4 times and the value at CD38 will decrease. Since the script mostly load direction buttons to CCD3, one may mistake that it's a step counter.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 23, 2015, 10:07:23 am
Because it is an array index of CCD3. If you execute this code in Red/Blue:
Code: [Select]
call $3486while CD38 is set to 4 and CCD3-CCD6 are filled with 08 (start button joypad constant). You can see that the game starts to act like you pressed start button 4 times and the value at CD38 will decrease. Since the script mostly load direction buttons to CCD3, one may mistake that it's a step counter.

Thanks for the explanation :)

So what exactly happens when CD38 is set to 01 (which is what the well-known "walk through walls" GameShark code 010138CD does)?
Title: Re: WTW mechanics discussions
Post by: pigdevil2010 on February 23, 2015, 01:10:46 pm
Because it is an array index of CCD3. If you execute this code in Red/Blue:
Code: [Select]
call $3486while CD38 is set to 4 and CCD3-CCD6 are filled with 08 (start button joypad constant). You can see that the game starts to act like you pressed start button 4 times and the value at CD38 will decrease. Since the script mostly load direction buttons to CCD3, one may mistake that it's a step counter.

Thanks for the explanation :)

So what exactly happens when CD38 is set to 01 (which is what the well-known "walk through walls" GameShark code 010138CD does)?

Collision check will check this value. If it's non-zero, it won't block the player (this thing may applied to avoid a player bumping with an NPC or unwanted objects during walking I suppose?)
. But since the joypad simulation script is not running, this value won't be decremented.

Also, I found out that the code at $3486 also involves setting bit 7 of D730 ([D730] = [D730] | $80) too. Maybe this is used for overworld movement script.
Title: Re: WTW mechanics discussions
Post by: SatoMew on February 23, 2015, 03:17:21 pm
Collision check will check this value. If it's non-zero, it won't block the player (this thing may applied to avoid a player bumping with an NPC or unwanted objects during walking I suppose?)
. But since the joypad simulation script is not running, this value won't be decremented.

Also, I found out that the code at $3486 also involves setting bit 7 of D730 ([D730] = [D730] | $80) too. Maybe this is used for overworld movement script.

Thanks. Do you know if there's an equivalent to CD38 in the Generation II games?
Title: Re: WTW mechanics discussions
Post by: bbbbbbbbba on March 11, 2015, 03:25:55 pm
Because it is an array index of CCD3. If you execute this code in Red/Blue:
Code: [Select]
call $3486while CD38 is set to 4 and CCD3-CCD6 are filled with 08 (start button joypad constant). You can see that the game starts to act like you pressed start button 4 times and the value at CD38 will decrease. Since the script mostly load direction buttons to CCD3, one may mistake that it's a step counter.

Thanks for the explanation :)

So what exactly happens when CD38 is set to 01 (which is what the well-known "walk through walls" GameShark code 010138CD does)?

Collision check will check this value. If it's non-zero, it won't block the player (this thing may applied to avoid a player bumping with an NPC or unwanted objects during walking I suppose?)
. But since the joypad simulation script is not running, this value won't be decremented.

Also, I found out that the code at $3486 also involves setting bit 7 of D730 ([D730] = [D730] | $80) too. Maybe this is used for overworld movement script.

Right, bit 7 of D730 determines whether "the joypad simulation script is running". More accurately, that bit is checked every time the game reads joypad input in the overworld. If it is set, a simulated input is read from a sequence (starting at CCD3), with CD38 as an decreasing index (it is decreasing so that the game knows to end the simulation when it goes to 0).
Title: Re: WTW mechanics discussions
Post by: ISSOtm on June 10, 2015, 09:42:27 am
Something else : for the ledge method of WTW, we simply have CD38 non-zero with bit 7 of D730 deactivated.
However, the Museum guy method is different.

There is a path, indeed, that is written and that you follow; but it is THAT large, that it actually overwrites another very important byte : wOverrideSimulatedJoypadStatesMask (according to Pokéred's disassembly), which is CD3B.

To make things clear, this is a piece of pseudo-code that seems to be the game's logic for movement.
Code: [Select]
If D730 's 7th bit is set, then
  Perform logical AND of CD3B and joypad input
  If result is non-zero then
    Put joypad input in _move
  Else
    Read the byte at CCD3 + [content of CD37], and put it into _move
    Increase CD37
    Decrease CD38
    If CD38 is zero, then
      Reset bit 7 of D730
    EndIf
  EndIf
Else
  Put the joypad state into _move
EndIf
Change direction the player is facing
If the tile the player is facing is non-solid OR CD38 is non-zero
  Move once in the direction the player is facing
EndIf
Note : _move isn't the content of a memory address, I suppose it is any of the 8-bit z80 registers.
There is a logic behind collision deactivation if CD38 is non-zero : as much more code is read if CD38 is non-zero, it seems legit do skip collision detection to compensate. Also pre-programmed paths should never fail (we all know that when glitches are thrown into the mix, pre-programmed paths DO fail :P)
All this code and hypotheses are totally empirical, and have NOT been checked against the disassembly. It just seems that it works so.

I'd then categorize WTW methods as follows :
1. CD38 non-zero, but bit 7 of D730 reset (ledge method, select bug/ACE methods)
2. CD38 non-zero, bit 7 of D730 set, but CD3B is non-zero (Museum guy, Youngster methods)

According to this post of mine (http://forums.glitchcity.info/index.php/topic,6675.msg198359.html#msg198359), a spot for "Museum guy" WTW disallows up/down movement. However, holding left/right will allow up/down movement, and as up/down key presses are checked first in the overworld movement script, you may go up/down. (e.g. it wouldn't work if only U/D was allowed)


This means if you Trainer-Flied from Route 8, beat a Trainer from another route, viewed that sign in Lavender Town then returned to Route 8 the game would bring up her text (I confirmed it bringing up her text from after battle and I previously beat her, maybe the game would bring up her text before battle if you didn't beat her?)
Absolutely, tested it on VBA and real hardware.

Right, bit 7 of D730 determines whether "the joypad simulation script is running". More accurately, that bit is checked every time the game reads joypad input in the overworld. If it is set, a simulated input is read from a sequence (starting at CCD3), with CD38 as an decreasing index (it is decreasing so that the game knows to end the simulation when it goes to 0).
Looks like CD37 is an increasing index, to track the position of the player in the guide list ? Or is it a step counter ?
Still, CD38 is used by the collision engine, and D730 by the overworld movement script.

I have a theory about guidance list reading :
# Either the list is read backwards, then the game reads byte at CCD3 + [content of CD38] if CD38 is non-zero;
# Or the list is read forwards, then the game uses the formula presented in the above pseudo-code section.
No idea which is correct.
[EDIT after testing on BGB]
The list is read backwards.

Initialization seems to work like so :
1. Start at CCD3
2. Increment (CD38).
3. Is it $FF ?
4. If no, repeat from step 2, looking at the next address in RAM.
(like this asm ?)
Code: [Select]
  ld bc, CCD3
  ld hl, CD38
guidanceInitLoop:
  inc (hl)
  ld a, (bc)
  inc bc
  cp $FF
  jr nz, guidanceInitLoop


Collision check will check this value. If it's non-zero, it won't block the player (this thing may applied to avoid a player bumping with an NPC or unwanted objects during walking I suppose?)
.
Actually, you're right : you partially clip into the NPC guiding you.
(http://i.imgur.com/ViH15wX.png)
Should try changing the collision detection to still work during guidance. I think you'll bump into Oak ? (If yes, you'll freeze after a while, when Oak enters the lab, much like the glitch using the girl to prevent Red correctly following Oak and thus, never entering the lab)


Collision check will check this value. If it's non-zero, it won't block the player (this thing may applied to avoid a player bumping with an NPC or unwanted objects during walking I suppose?)
. But since the joypad simulation script is not running, this value won't be decremented.

Also, I found out that the code at $3486 also involves setting bit 7 of D730 ([D730] = [D730] | $80) too. Maybe this is used for overworld movement script.

Thanks. Do you know if there's an equivalent to CD38 in the Generation II games?
More or less. Looks like Generation II uses a different method : there are four addresses that control collision (one per direction). That's the "WTW" part of CD38. For the "guidance" part, there must be an equivalent of CD38, but I have no idea where it is located in memory.

I'll peek at the disassembly later to (in-)validate my "bullshit theories", I'll be back !
Title: Re: WTW mechanics discussions
Post by: Evie the Mother Hen ☽ ❤ on June 12, 2015, 08:21:44 am
Cheers for your research, ISSOtm.