cheahjs / palworld-save-tools

Tools for converting Palworld .sav files to JSON and back
MIT License
776 stars 66 forks source link

durability appears 'NaN' value #108

Closed zaigie closed 5 months ago

zaigie commented 5 months ago

This is a dedicated server archieve file, and added durability*5 MOD in this server.

It can write to Level.sav.json normally, but an error is reported when another tool parses it.

uses ijson to stream parse files:

error

This looks like a problem caused by server cheating, is there a way to catch exceptions.

The archive is larger than 25M, so I uploaded it here: https://share.zaigie.com/s/U5ODI3N

cheahjs commented 5 months ago

Dear lord that's one of the largest save files I've seen so far.

Looking at the durability mod, it shouldn't produce NaN durabilities, so that shouldn't be the issue.

So the main issue is with the NaN float value that's emitted. The ijson lib that you're using specifically does not support NaNs as they are not part of the JSON spec (https://github.com/ICRAR/ijson/issues/33).

json.dump has the allow_nan=False flag to avoid outputting non-conformant float values (NaN, Infinity, and -Infinity), but that would require additional logic to either:

  1. Take the hit with the loss of information for converting NaN/Inf/-Inf into nulls, and just encode nulls as NaNs on the reverse, or
  2. Maintain the loseless approach, and add some sort of string handling to encode them into their string equivalents, and then decode back as necessary.
zaigie commented 5 months ago

Thank you for your answer, I give up, or performance is important :(

cheahjs commented 5 months ago

There's a PR up (#114) to emit null instead of NaN, haven't had the chance to test it yet, gotta run to work for now.

EDIT: and it's immediately broken oops, will fix it up at some point