Save Data: Difference between revisions

From PS4 Developer wiki
Jump to navigation Jump to search
m (CelesteBlue moved page Savegames to Save Data without leaving a redirect)
No edit summary
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
===Location===
=== Location ===
Savegames are stored encrypted inside /user/home/[[User ID|user Id]]/[[NP Title ID|title Id]]/[[save data directory]]/[[sce_sys]]/


files contained within:
There is a mountpoint for the current application save data, usually "savedata0" but can be up to "savedata15".
 
Save Data are stored encrypted inside <code>/user/home/[[User ID|user Id]]/[[NP Title ID|title Id]]/savedata0/[[sce_sys]]/</code>.
 
==== External ====
 
Save data can be copied from PS4 to a USB mass storage device.
 
Files are exported to <code>USB:\PS4\SAVEDATA\[[User ID|user Id]]\[[NP Title ID|title Id]]\</code>.
 
File Format if dumped to usb will look like this:
'''savedata_10000000_CUSA09175_DaysGone0002'''
 
=== Files ===
 
Every savedata contains at least these files:
* [[param.sfo]]
* [[param.sfo]]
* [[icon0.png]]
* [[icon0.png]]
* [[sdslot.dat]]
* [[Keystone]]
* [[sealedkey / pfsSKKey|sealedkey]]
* [[sealedkey / pfsSKKey|sealedkey]]


==== External ====
=== Files (/user/home/[[User ID|user Id]]/[[NP Title ID|title Id]]/) ===
Savegames may be copied from PS4 to a USB mass storage device.
 
When dumping files using FTP you might see your files similar to this structure:
 
    ├── Title ID                               
    │  ├── SAVEDATA00.bin                      /*This File Holds the pfsSKKey*/
    │  ├── sdimg_SAVEDATA00                    /*This is the encrypted save file*/
 
Somehow there is another structure (how? where?):
 
[Save Data Root Dir]
├─ [User Id Directory]
│  └─ savedata/
│      └─ [Title Id Directory]
│          └─ [save data directory]
│              └─ sce_sys/
│                └─ param.sfo                                          /*sfo containing savedata info will be also shown in the savedata.db*/
│                └─ icon0.png                                          /*savedata icon file*/
│              └─ [save files here] e.g (bendsavegame.ps4.sav)          /*savedata file created by the developer e.g. is of days gone*/
│               
 
=== Accessing Save Data ===
 
The PS4 has a few API's for accessing save data one of which is for the VSH.
 
Below is a small example code:
 
'''C++ Example'''
<source lang="csharp">
//somehow Initialize user service,saveapi ect.
int ret = 0;
ret = SaveDataInitialize3(NULL);//Initialize save data
 
OrbisSaveDataMount mount;
memset(&mount, 0x00, sizeof (mount));
 
mount.userId = userId;
mount.dirName = &dirName;
mount.fingerprint = &fingerprint;
mount.titleId = &titleId;
mount.blocks = 32768;
mount.mountMode = ORBIS_SAVE_DATA_MOUNT_MODE_RDONLY ;//(ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF | ORBIS_SAVE_DATA_MOUNT_MODE_RDWR);
 
OrbisSaveDataMountResult mountResult;
memset(&mountResult, 0x00, sizeof(mountResult));
 
ret = SaveDataMount(&mount, &mountResult);
</source>
 
=== Passcode and Fingerprint ===
 
Passcodes are set when creating your pkg with PKG Creation tools.
 
To access a save from any other game/app that is not your own you will need to set the hashed passcode 'Fingerprint' as a parameter to mount the save
 
=== Number of Simultaneous Savedata Mounts ===
 
Up to 16 save data can be mounted at the same time.
 
(if you need more than that you will need to ask the user to select the ones he wants and do them one by one or do them in chuncks and save to usb)


They will be located at USB:\PS4\SAVEDATA\[[User ID|user Id]]\[[NP Title ID|title Id]]\
=== Mount-enabled Period ===


===Files===
If a save is mounted with the ORBIS_SAVE_DATA_MOUNT_MODE_RDWR flag it must be unmounted within 15 seconds. Or not but you can risk the save getting corrupted if a user logs out or terminates the application without unmounting saves first.
Every savegame contains 4 files:


1) [[sdslot.dat|Data file]]
=== Data in Saves ===


- size frequently 10.485.760 bytes (bf4 : 18.874.368 bytes)
There are some restrictions to what you can save in a savedir (someone can fill this in):
* sce_sys will be automatically created by the system (THIS IS A RESERVED NAME).
* You cannot save elf files or prx files in the save itself.


{| class="wikitable"
=== Save Data Limitations ===
|-
! From !! To !! Description
|-
| 0000 || 00AF || Header (176 bytes)
|-
| 00B0 || 00B7 || Magic Block (8 bytes)
|-
| 00B8 || 036F || Block (704 bytes)
|-
| 0370 || 039F || Block (48 bytes)
|-
| 03A0 || 7FFF || Empty Block (31.840 bytes)
|-
| 8000 || eof || Data Block (? bytes)
|}


2) [[sealedkey / pfsSKKey|Key file]]
* Saves can only be up to 1GB in size per save slot. (CTurt thinks that it was 1GB, but then raised a bit for Cyberpunk's release, to check)


3) [[param.sfo]]
=== Save Data Database ===


4) [[icon0.png]]
System logs all save data info in each users directory under save data.


===Files(/user/home/[[User ID|user Id]]/[[NP Title ID|title Id]]/)===
e.g./system_data/savedata/10000000/db/user/savedata.db


When dumping files using FTP you might see your files similar to this structure
Savedata database is in sqlite so any sqlite editor can read and write on it. It is not protected in PS4 OS from modification.


=== Save Data export/import to USB requires connection to a PSN account ===


    ├── Title ID                               
Since some System Software version (true since at least 5.05), the PS4 does not allow export/import of savedata of a local account.
    │  ├── SAVEDATA00.bin                      /*This File Holds the pfsSKKey*/
Consequently, a user whose console is not up-to-date cannot access PSN on his console so cannot add a PSN account.
    │  ├── sdimg_SAVEDATA00                    /*This is the encrypted save file*/


A workaround if you are on PS4 <= 11.00 is to fake activate a PSN account using https://github.com/charlyzard/PS4OfflineAccountActivator.


On PS5 <= 7.61, use https://github.com/ps5-payload-dev/offact to set a PSN account ID. If export to USB is still forbidden, you can use an homebrew to do it.


{{File Formats}}
{{File Formats}}<noinclude>[[Category:Main]]</noinclude>
<noinclude>[[Category:Main]]</noinclude>

Latest revision as of 05:50, 14 December 2024

Location[edit | edit source]

There is a mountpoint for the current application save data, usually "savedata0" but can be up to "savedata15".

Save Data are stored encrypted inside /user/home/user Id/title Id/savedata0/sce_sys/.

External[edit | edit source]

Save data can be copied from PS4 to a USB mass storage device.

Files are exported to USB:\PS4\SAVEDATA\user Id\title Id\.

File Format if dumped to usb will look like this: savedata_10000000_CUSA09175_DaysGone0002

Files[edit | edit source]

Every savedata contains at least these files:

Files (/user/home/user Id/title Id/)[edit | edit source]

When dumping files using FTP you might see your files similar to this structure:

   ├── Title ID                                
   │   ├── SAVEDATA00.bin                       /*This File Holds the pfsSKKey*/
   │   ├── sdimg_SAVEDATA00                     /*This is the encrypted save file*/

Somehow there is another structure (how? where?):

[Save Data Root Dir]
├─ [User Id Directory]
│   └─ savedata/
│       └─ [Title Id Directory]
│           └─ [save data directory]
│              └─ sce_sys/
│                 └─ param.sfo                                          /*sfo containing savedata info will be also shown in the savedata.db*/
│                 └─ icon0.png                                          /*savedata icon file*/
│              └─ [save files here] e.g (bendsavegame.ps4.sav)          /*savedata file created by the developer e.g. is of days gone*/
│                 

Accessing Save Data[edit | edit source]

The PS4 has a few API's for accessing save data one of which is for the VSH.

Below is a small example code:

C++ Example

		//somehow Initialize user service,saveapi ect.
		int ret = 0;
		ret = SaveDataInitialize3(NULL);//Initialize save data 

		OrbisSaveDataMount mount;
		memset(&mount, 0x00, sizeof (mount));

		mount.userId = userId;
		mount.dirName = &dirName;
		mount.fingerprint = &fingerprint;
		mount.titleId = &titleId;
		mount.blocks = 32768;
		mount.mountMode = ORBIS_SAVE_DATA_MOUNT_MODE_RDONLY ;//(ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF | ORBIS_SAVE_DATA_MOUNT_MODE_RDWR);

		OrbisSaveDataMountResult mountResult;
		memset(&mountResult, 0x00, sizeof(mountResult));

		ret = SaveDataMount(&mount, &mountResult);

Passcode and Fingerprint[edit | edit source]

Passcodes are set when creating your pkg with PKG Creation tools.

To access a save from any other game/app that is not your own you will need to set the hashed passcode 'Fingerprint' as a parameter to mount the save

Number of Simultaneous Savedata Mounts[edit | edit source]

Up to 16 save data can be mounted at the same time.

(if you need more than that you will need to ask the user to select the ones he wants and do them one by one or do them in chuncks and save to usb)

Mount-enabled Period[edit | edit source]

If a save is mounted with the ORBIS_SAVE_DATA_MOUNT_MODE_RDWR flag it must be unmounted within 15 seconds. Or not but you can risk the save getting corrupted if a user logs out or terminates the application without unmounting saves first.

Data in Saves[edit | edit source]

There are some restrictions to what you can save in a savedir (someone can fill this in):

  • sce_sys will be automatically created by the system (THIS IS A RESERVED NAME).
  • You cannot save elf files or prx files in the save itself.

Save Data Limitations[edit | edit source]

  • Saves can only be up to 1GB in size per save slot. (CTurt thinks that it was 1GB, but then raised a bit for Cyberpunk's release, to check)

Save Data Database[edit | edit source]

System logs all save data info in each users directory under save data.

e.g./system_data/savedata/10000000/db/user/savedata.db

Savedata database is in sqlite so any sqlite editor can read and write on it. It is not protected in PS4 OS from modification.

Save Data export/import to USB requires connection to a PSN account[edit | edit source]

Since some System Software version (true since at least 5.05), the PS4 does not allow export/import of savedata of a local account. Consequently, a user whose console is not up-to-date cannot access PSN on his console so cannot add a PSN account.

A workaround if you are on PS4 <= 11.00 is to fake activate a PSN account using https://github.com/charlyzard/PS4OfflineAccountActivator.

On PS5 <= 7.61, use https://github.com/ps5-payload-dev/offact to set a PSN account ID. If export to USB is still forbidden, you can use an homebrew to do it.