|Please note that this glitch only exists in the Japanese versions of the game, or is otherwise a glitch from a Pokémon game which was only released in Japan.|
The Saffron Gym glitch (Japanese: ヤマブキジムのバグ, Yamabuki Gym BugStrange behavior of Yamabuki Gym, Legendary Star Blob 2) is a glitch that only happens in Pokémon Red and Green. It was fixed in Japanese Blue, Pocket Monsters Pikachu, and the localizations.
This glitch manifests itself in two different ways: If the player loses to a trainer in Saffron Gym, the game will act as if the player won when the player re-enters the gym. If the player wins against a trainer in Saffron Gym, there is a frame window in which the player can talk to the trainer to restart the fight. Both phenomena are caused by the same problem in the map script of Saffron Gym.
Loss becomes victoryAfter losing to a trainer in Saffron Gym, if the player returns to the gym, the game will act as if the player just won the fight. This means that that trainer cannot be fought again, and if talked to, they will say the line of dialog that normally appears after defeating them or defeating the gym. Furthermore, if that trainer is Sabrina: When the player re-enters the gym, the game will immediately print the line of dialog that normally appears after winning the battle and exiting to the overworld (about the Marsh Badge letting Pokémon up to level 70 obey the player). The player will receive TM46 (Psywave) and the Marsh Badge. None of the trainers in the gym will fight the player, as if the player has defeated the gym. The player's name will show on the statue at the front of the gym. The prize money lost is not affected by this glitch.
Infinite rematch exploit
After winning against a trainer in Saffron Gym, if the player presses A during the first overworld frame, then the trainer will say their pre-battle dialog, and the fight will start again. This can be repeated indefinitely. However, to continue exploiting this glitch, the player must win every fight, because otherwise the first part of this glitch will trigger and prevent the player from fighting the same trainer again.
A very easy way to achieve this is by clearing the last in-fight text box (which states how much money the player has won) with the B button, then immediately starting holding A. This A press will be processed on the earliest frame possible, triggering this glitch.
Doing this with any trainer other than Sabrina will result in glitch meta-map script activation, because talking to a normal trainer not yet beaten increments the meta-map script ID by 2, and the ID is never reset to 0 since meta-map script 2 (EndTrainerBattle) is never executed. Sabrina is the only exception because her pre-battle dialog explicitly sets the meta-map script ID to 3 (special script for ending the gym leader battle), so it will work the same way no matter how many times the player fights her.
ExplanationWhen the player enters a gym, or returns to its overworld map from a battle, on the first overworld frame the game loads the names of the city and the gym leader to be shown on the gym statue. This is done by a function call in the gym's map script.The function call to load the names of the city and the gym leader However, in Japanese Red and Green only, and in Saffron Gym only, this "call" instruction is erroneously replaced by a "jp" instruction. This means that, on the first overworld frame, the meta-map script is skipped.
Normally, the meta-map script ID immediately after a trainer battle in the gym is either 2 (EndTrainerBattle) or 3 (special script for ending the gym leader battle), and both serve some important purposes: If the player won, the meta-map script will set the flag for beating the trainer. In the case of the gym leader battle, it will also give out the badge and TM award, and set the flags for beating the gym and for beating everyone else in the gym. No matter whether the player won or lost, the meta-map script will reset the meta-map script ID to 0, so that it would not execute again. Therefore it is important that this meta-map script executes before the player can talk to the trainer again or death-warp away. In particular, when the player blacks out, the game executes the map script for exactly one more overworld frame, precisely for this purpose.
However, due to the flaw in the map script of Saffron Gym, it fails to call the meta-map script the first time. Therefore: If the player won, the player gets the chance to talk to the same trainer again before the meta-map script sets the "trainer beaten" flag. Therefore the player can rematch trainers indefinitely. If the player lost, the player will death-warp away before the meta-map script could reset to 0. Since the meta-map script determines whether the player lost by checking whether wIsInBattle is 0xFF, and wIsInBattle is reset to 0 after the player death-warps, the next time the player enters the gym, the meta-map script will execute and erroneously believe that the player has won.