Skip to content

Commit

Permalink
Added Persona 3 Reload support
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Feb 3, 2024
1 parent 23cc1e5 commit d75244f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions games.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@
"name": "Railway Empire 2",
"package": "KalypsoMediaGroup.RailwayEmpire2Win_e60j8nnj33ga6",
"handler": "railway-empire-2"
},
// Persona 3 Reload
{
"name": "Persona 3 Reload",
"package": "SEGAofAmericaInc.L0cb6b3aea_s751p9cej88mt",
"handler": "persona-3-reload"
}
]
}
37 changes: 37 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,43 @@ def get_save_paths(
continue
save_meta.append((container["name"], file["path"]))

elif handler_name == "persona-3-reload":
# "1 container, 1 file" (1c1f). Each container contains only one file which name will be the name of the container.
# The Store version of Persona 3 Reload use unencrypted savefiles, whereas the Steam version use encrypted savefiles.
# illusion0001 uncovered the encryption method and key used in this solution.
temp_save_meta = [] # Temporary list

for container in containers:
fname = container["name"]
fname += ".sav"
fpath = container["files"][0]["path"]
temp_save_meta.append((fname, fpath)) # save_meta replaced by temp_save_meta

# Creating a temporary folder for P3R
temp_folder = Path(temp_dir.name) / "P3R"
temp_folder.mkdir()

key = "ae5zeitaix1joowooNgie3fahP5Ohph" #Key used to encrypt/decrypt the savefile
key_length = len(key)

# Encryption method
for file_name, file_path in temp_save_meta:
encrypted_file_path = temp_folder / file_name

with open(file_path, 'rb') as f:
data = f.read()

output_data = bytearray()
for j, byte in enumerate(data):
key_byte = ord(key[j % key_length])
encrypted_byte = ((((byte & 0xff) >> 4) & 3 | (byte & 3) << 4 | byte & 0xcc) ^ key_byte)
output_data.append(encrypted_byte)

with open(encrypted_file_path, 'wb') as f:
f.write(bytearray(output_data))

save_meta.append((file_name, encrypted_file_path))

else:
raise Exception('Unsupported XGP app "%s"' % store_pkg_name)

Expand Down

0 comments on commit d75244f

Please sign in to comment.