kwsch / PKHeX

Pokémon Save File Editor
https://projectpokemon.org/pkhex/
Other
3.64k stars 684 forks source link

Trash editor breaks Japanese G3PKM strings #4222

Closed Kermalis closed 5 months ago

Kermalis commented 6 months ago

Describe the bug Editing the nickname trash or OT name trash of a Japanese gen3 Pokémon breaks the string. Perhaps the trash editor is ignoring the IsJapanese property?

To Reproduce Edit any Japanese gen3 Pokémon. Change FF trash to 00 for example. For some reason this changes the string's bytes before the trash, though this is only reflected at the top of the trash editor or when reloading it. I uploaded a gif below:

PKHeX_2024-03-18_11-21-41

In this example, the relevant bytes are changing from [6C 5C 88 91 68 FF] to [6C 5B 88 91 FF]

The "apply layers" button also seems to be struggling here: image

TO NOTE: I have not tested other languages, only English/Japanese. Maybe others have an issue too. This is on the latest commit as of writing (8a3a338c0b41af801e3ba2a7947aaade864417ef)

kwsch commented 5 months ago

In the main window, the string conversion uses the PK3's methods. In the trash editor, the string conversion uses the SAV3's methods.

Open trash editor -> string is copied to text field. Change trash -> string is re-converted from byte[] to string using the {converter} and displayed.

Since PK3 (and PKM) do not have a generalized GetString() and SetString() method, it was easiest to just use the save file's methods.

However...

For most text, the game's native character set is used, but if a Pokémon's origin language is Japanese, its nickname and its Original Trainer's name use the Japanese character set.

Seems like the correct solution is to have the PKM to encode it rather than the save file. For Gen1/2 it won't really matter because the available chars for text-entry do not clash across international languages, and JPN & INT cannot trade between each other. Need to add an interface and let the trash editor use that instead of a strict SaveFile reference.