Crystal: Unused party sanitisation function
Posted by: Stackout
Date: 2017-10-03 11:37:50
As the filename would have you expect, it's in EN Crystal at [tt]$13A47 (4:7A47)[/tt]. (It's in JP Crystal at [tt]$13BB3 (4:7BB3)[/tt]). That's near the end of the bank, located after some Bug-Catching Contest-related stuff, and before a function that uses a lookup table to find square roots. It appears to not be in G/S (and given that it calls a function in a bank related to mobile code, that's not unexpected).
It is completely unreferenced and unused in at least JP and EN Crystal.
Here's what it does:
[li]If the number of Pokémon in the party is over 6, set it to 6[/li]
[li]The party species bytes are checked. If a byte is an invalid species ([tt]$00, $FC, $FE, $FF[/tt]), change that species byte and the first species byte of that Pokémon structure to Smeargle ([tt]$EB[/tt]).[/li]
[li]For all Pokémon in the party:
[li]If the second species byte in the Pokémon structure is invalid ([tt]$FD[/tt] (Egg) is also considered invalid here), change it to Smeargle.[/li]
[li]If the Pokémon's level is below 2, set it to 2; if it is over 100, set it to 100. Recalculate the Pokémon's stats, no matter whether or not the level was modified.[/li]
[li]If the Pokémon's nickname is unterminated after 6 bytes, terminate it by setting the 6th byte to [tt]$50[/tt]; if the nickname has any invalid characters (defined here as anything that is not [tt]$00, $05 - $13, $19 - $1C, $26 - $34, $3A - $3E, $40 - $48, $60 - $FF[/tt]; a function in a bank related to mobile functionality is called to do this), set it to the Pokémon species name (if the Pokémon is an Egg, then set it to [tt]""[/tt] ("Tamago"/Egg) followed by [tt]50 50 50[/tt] instead)[/li]
[li]If the Pokémon's Original Trainer name is unterminated after 6 bytes, terminate it by setting the 6th byte to [tt]$50[/tt]; if it has any invalid characters, set it to the player's name[/li]
[li]If the Pokémon has an invalid move in slot 1 ([tt]$00, $FC, $FD, $FE, $FF[/tt]), replace it with Pound. If there is an invalid move in slot 2, 3, or 4, delete all moves starting from that slot(!!!).[/li]
Note that this code is only half localised in non-JP - it assumes nicknames and OT names are 6 bytes long, the list of characters considered valid assumes a Japanese game, and if an Egg's nickname contains invalid characters, it gets set to ""; however, when removing a Pokémon's nickname, or changing its OT name, it copies the correct number of bytes for the localisation.
Given that this calls a function in a mobile-related bank, this function may have been intended to have been used to force the legitimacy of party Pokémon when using mobile-related features. Of course, it may have just been debug code.