DaWoblefet said:When using Wish on turn 255, or using Future Sight on turn 254, both Wish and Future Sight will become "stuck" and not able to actually heal the slot or deal damage to the slot. They'll be permanently stuck on the Y-info screen, and attempting to reuse Future Sight or Wish will fail. I
recorded footage of this interaction. The final turns leading up to 256 are around the 53:32 mark. After this, I mashed A for another hour and a half and neither Wish nor Future Sight ever resolved, so I would speculate they would never resolve.
I think this is due to the turn counter variable being an unsigned 8-bit integer. Wish being used on turn 255, for example, causes turn 255 to be stored as the turn Wish was used. On the next turn, it checks if the turn value is greater than the stored value. But because the turn counter is an 8-bit unsigned integer, it's either capped at 255 or rolls over to 0. Either way, the check fails, so Wish never heals and as a result you can't use Wish ever again.
I am not exactly sure how this works, though. I wanted to check what happened if you used Wish / Future Sight
after 256 turns. I did not count turns, but mashed A for about an hour, which was a bit beyond what I did in my original test. Using Wish worked, and would heal the slot, but using Future Sight got Future Sight similarly stuck. I predict you could test with Quick Ball, Timer Ball, and Echoed Voice to see additional unusual turn counter behavior. Because it takes roughly an hour to set up one attempt, I'm hopeful that other interested folks could test some of those interactions. I also am not sure if this has the same behavior in past generations.
EDIT: a Japanese account named @Venom_Drench responded to me indicating additional information from
research they did on Echoed Voice. They report a bizarre non-linear set of base powers after turn 256.
EDIT 2: Anubis poked around at this a bit. The turn counter itself has a cap of 9999 (it's specifically prevented from being incremented higher than this). She found that the reason Wish is failing is because it stores the turn counter it was used on as an unsigned 8-bit integer, and then also casts the current turn to an 8-bit unsigned integer for comparison. So using Wish on a turn that is a multiple of 256-1 will always cause Wish to "get stuck" and fail. So Wish would "get stuck" when used on turns 255, 511, 767, etc. Future Sight is different - it does not appear to be doing casting in that same way. The reason it's getting stuck does not appear to be linked to turn count in the same way Wish is linked to turn count. More research will be needed there.
I messed around with the turn count glitches a bit because it's a lot easier when you can set the turn count to whatever you want.
DaWoblefet had already identified the methods for fetching turn count in BDSP and I found the analogous methods in SV, so we spent a couple of evenings working this out. That said, I'll explain how each of these mechanics is broken.
Turn Counter
The turn counter is actually capped at 9999. This isn't an issue of the turn counter being capped at 255, but the getter returning a byte.
Wish
When you use Wish, it stores the turn that it was used, cast to an unsigned byte. Then on subsequent turns, it checks if that turn count cast to an unsigned byte is greater than the stored Wish turn value. If so, then Wish goes off.
- Example #1: You use Wish on turn 7. On turn 8, it checks if 7 < 8 and if so, Wish will activate. This is how you get Wish activating next turn.
- Example #2: You use Wish on turn 9999. Since turn count will never advance past this, Wish will never activate. It will repeatedly check if 15 < 15.
- Example #3: You use Wish on turn 255. However, 256 cast to an unsigned byte will be 0. On turn 256, the game checks if 255 < 0 which isn't satisfied. In fact, turn count can only ever be 0-255, so Wish will never go off again, nor can you use it again once you break it this way.
Future Sight
When you use Future Sight, the game stores the expected turn that it should activate. This value is an integer, which is fine. However, when it fetches the current turn count, this is again an unsigned byte. Future Sight activates if the expected turn is less than or equal to the current turn count, cast to an unsigned byte.
- Example #1: You use Future Sight on turn 7. This stores turn 9 as the turn to activate. On turn 8, it checks if 9 <= 8, and doesn't activate. On turn 9, it checks if 9 <= 9, and does activate.
- Example #2: You use Future Sight on turn 255. This stores turn 257 as the turn to activate. On turn 256, it checks if 257 <= 0 and doesn't activate. On turn 257, it checks if 257 <= 1 and doesn't activate. Since turn count will always return a number from 0-255, Future Sight will break if used on turn 254 or higher, since the expected activation turn is 256 or higher, which can't be reached.
Echoed Voice
This one is pretty complicated so bear with me.
The game stores a list of 400 move records in a battle. Here's an example of the start of the records block. The first row is a header with an address, then the number of entries (0x37).
Each row after that is a record storing: turn count (at 0x00), the Pokemon that used the move (at 0x04), the move used (at 0x08), and whether it was successful (at 0x0A).
Using a move adds an entry. Missing a turn or using an item doesn't add any entry. When all 400 entries are filled, the game starts overwriting the first entries starting at 0xC and starts counting number of entries from 1. It looks like when checking, it starts at the latest entry, runs backwards until it hits the first entry, and then loops around to the end of the block. Loop exits when it counts down and reaches the latest entry where the check started. See
this post for more details on how this record logs specific moves.
Echoed Voice works by checking backwards for consecutive Echoed Voice uses by the same Pokemon until it no longer finds one. So for example, if you use Echoed Voice on turns 2, 3, 4, 5, then use it again on turn 6, it will check the records block for this Pokemon using it on turn 5, then turn 4, then turn 3, then turn 2, then fail to find one on turn 1, and calculate for 5 consecutive Echoed Voice uses.
The problem with Echoed Voice is that again, when it fetches turn count, this is cast to an unsigned byte. Turn 256 = turn 0, turn 257 = turn 1, turn 258 = turn 2, etc. On turn 258, the game thinks that you are actually on turn 2 and checks the record block for Echoed Voice used on turn 1 instead!
There are some implications of this:
- If you haven't overwritten any turn counts under 256, then the base power of Echoed Voice depends on what you did within the first 0-255 turns. The corresponding turn is the current turn cast to an unsigned byte. For this reason, I can't explain what the Japanese user observed, because I don't know what happened for the first 255 turns, what moves were recorded, and how much was overwritten.
- If you overwrite any moves and you are past turn 255, then Echoed Voice won't be able to find another turn to consider consecutive, and BP will be 40.
Fusion Flare/Fusion Bolt
These moves check the above record block to see if the last move used on the same turn was the other fusion move. Again, turn count is cast to an unsigned byte. For this reason, you can do a cool party trick where you chain Fusion Flare with Fusion Bolt in a singles battle.
- Make sure you are the last Pokémon to use either Fusion Bolt or Fusion Flare on the first turn (turn 0).
- Make sure you do not use more than 400 moves to overwrite the first turn's moves.
- On turn 256, make sure you are the first Pokemon to use the Fusion move that was not used on turn 0. This will chain with the move you used at the start of the battle for 200 BP instead of 100 BP.
SadisticMystic said:Does a weather move on turn 252, or Perish Song on turn 253, also break with this?
No, these work fine. They don't check the turn count the same way as the other moves.
----
I did not test Round, which also uses this mechanic. I'll try to answer any questions if my explanation is unclear.
I did not check how far back these glitches exist, but I would guess they affect at least gen 8, possibly even more before that.
Here is a gist showing the pseudocode and disassembly for the above functions.
If there are more questions, we can gather up a bunch and answer them as pertinent.
EDIT: looked at it this morning and the record block looks like it loops around to the end, so getting to 400 moves shouldn't be an issue.