jmkl009 / PalworldCharacterTransfer

This script transfers character between worlds in Palworld, which allows friends to transfer their characters to each other's server without losing one's progress.
93 stars 5 forks source link

Bug: Save output of SaveConverter to JSON throws UUID error #11

Closed tux550 closed 4 months ago

tux550 commented 4 months ago

Error

JSON Serialization error thrown when trying to save output of SaveConverter to JSON file.

Command

python SaveConverter.py -o output.json "C:\(...)\Level.sav"

Error Message

Converting C:\(...)\Level.sav to JSON, saving to output.json
Decompressing sav file
Loading GVAS file
Writing JSON to output.json
[TRACEBACK INFO ...]
File "C:\(...)\PalworldCharacterTransfer\lib\noindent.py", line 36, in default
    return super(CustomEncoder, self).default(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\(...)\Lib\json\encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type UUID is not JSON serializable

Cause

Error is thrown because CustomEncoder.default expects to recieve uuid.UUID but instead recieves custom UUID wrapper lib.archive.UUID.

Possible Solution

Add additional case to handle wrapper lib.archive.UUID

# lib/noindent.py
from .archive import UUID as CustomUUID
#(...)
def default(self, obj):
    if isinstance(obj, NoIndent):
        return self.FORMAT_SPEC.format(id(obj))
    elif isinstance(obj, uuid.UUID):
        return str(obj)
    elif isinstance(obj, CustomUUID):
        return str(obj)
    return super(CustomEncoder, self).default(obj)
jmkl009 commented 4 months ago

Hi, SaveConverter.py is deprecated in my repository. If you just want to extract JSON from sav files, take a look at https://github.com/cheahjs/palworld-save-tools/tree/main