pagefaultgames / pokerogue

A browser based Pokémon fangame heavily inspired by the roguelite genre.
https://pokerogue.net
GNU Affero General Public License v3.0
4.32k stars 1.72k forks source link

[BUG] Wave stopped after clear wave at korean language spec #2614

Open milkyway0308 opened 2 months ago

milkyway0308 commented 2 months ago

Describe the bug

Game stopped after 193 wave with korean language spec.

To Reproduce

  1. Import provided prsv file, and win with skill "Heavy Slam".
  2. Boom! Game stopped with last dialog.

Expected behavior

Screenshots / Videos image

Device Chrome, Self-hosted. Run with commit hash f8a15570fa50af0a6de83651447b9e0cdf153c2e.

Additional context Seems like korean language translation, or something out of range at latin1 spec, and save logic corrupted with failed encoding. If possible, suggest change encoding from latin1 to utf-8. Here's some stack trace :

main.ts:24 DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
    at http://192.168.0.38:8000/src/system/game-data.ts:89:37
    at encrypt (http://192.168.0.38:8000/src/system/game-data.ts:89:90)
    at http://192.168.0.38:8000/src/system/game-data.ts:865:119
game-data.ts:79 Uncaught (in promise) DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.
    at http://192.168.0.38:8000/src/system/game-data.ts:89:37
    at encrypt (http://192.168.0.38:8000/src/system/game-data.ts:89:90)
    at http://192.168.0.38:8000/src/system/game-data.ts:865:119

Here's save file causing error. sessionData_Guest.zip

flx-sta commented 2 months ago

Seems like a certain character is not valid for base64 encoding (btoa is just base64 encoding). Since I don't know korean at all do you, @milkyway0308 have a guess if there is any special character in that message that might be uncommon?

milkyway0308 commented 2 months ago

Okay, I'll try to find it.

I will mention it again after I find it.

flx-sta commented 2 months ago

I just found this SO answer that might be relevant: https://stackoverflow.com/a/26603875

milkyway0308 commented 2 months ago

@flx-sta Seems like I found it - triggerMessage contains locale message.

It's too long to write here, so I attach as file.

message.json

I suggest two main solutions to this problem:

  1. Change save format or encoding. PokeRogue using btoa method, that not supports specific language. It can fix with change save format. I found error at game-data.ts#encrypt.

  2. Filter out non-english messages. Looks like game save data contains too many informations - we can just delete it, and fix error. As you can see in the file, arena.tags[0].triggerMessage contains locale message, not message key.

Sorry for just offering an opinion, my Typescript skills are too poor for that.

milkyway0308 commented 2 months ago

P.S: Looks like official service are using AES as serialize solution, so I can say this problem only occurs at self hosted version of PokeRogue.

flx-sta commented 2 months ago

Well. that puts the priority quite down unfortunately. It's an interesting observation though. Having localized content inside the save-data..

Yes indeed. I think AES is a lot sturdier (and obv. safer)

milkyway0308 commented 2 months ago

Maybe I think we can use some trick at save data - Let me do some prototyping at this problem.

milkyway0308 commented 2 months ago

@flx-sta Here's some little trick for save file, fully test completed. I know this isn't the best way to fix it, but it's the best I could do.

Keeping base64 backward compatilibity, and changed format to AES.