sceUtilitySavedata patch

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
weltall
Posts: 310
Joined: Fri Feb 20, 2004 1:56 am
Contact:

sceUtilitySavedata patch

Post by weltall »

I haven't seen this in pspsdk: it's missing.
So I did a patch to the pspsdk checked out to revision 1400 and added a sample and a new include:

Code: Select all

--- ./pspsdk/sdk/samples/Makefile.am	Mon Nov  7 15:50:37 2005
+++ ./pspsdk/sdk/samples/Makefile.am	Mon Nov  7 15:17:31 2005
***************
*** 43,49 ****
  	usb/storage \
  	utility/netconf \
  	utility/msgdialog \
! 	utility/systemparam \
  	me/basic \
  	wlan
  
--- 43,50 ----
  	usb/storage \
  	utility/netconf \
  	utility/msgdialog \
! 	utility/systemparam \
! 	utility/savedata
  	me/basic \
  	wlan
  
--- ./pspsdk/sdk/samples/utility/savedata/Makefile.sample	Thu Jan  1 01:00:00 1970
+++ ./pspsdk/sdk/samples/utility/savedata/Makefile.sample	Mon Nov  7 15:14:42 2005
***************
*** 0 ****
--- 1,12 ----
+ PSPSDK = $(shell psp-config --pspsdk-path)
+ PSPLIBSDIR = $(PSPSDK)/..
+ TARGET = savedatasample
+ OBJS = main.o
+ LIBS = -lpspdebug -lpsputility -lm
+ 
+ 
+ CFLAGS = -O2 -G0 -Wall
+ CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
+ ASFLAGS = $(CFLAGS)
+ 
+ include $(PSPSDK)/lib/build.mak
--- ./pspsdk/sdk/samples/utility/savedata/main.c	Thu Jan  1 01:00:00 1970
+++ ./pspsdk/sdk/samples/utility/savedata/main.c	Mon Nov  7 15:13:45 2005
***************
*** 0 ****
--- 1,192 ----
+ /*
+  * PSP Software Development Kit - http://www.pspdev.org
+  * -----------------------------------------------------------------------
+  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
+  *
+  * main.c - Sample to desmonstrate how to use savedata utility
+  *
+  * Copyright (c) 2005 weltall ([email protected])
+  * Based on work by Shine
+  *
+  * $Id:$
+  */
+ #include <pspkernel.h>
+ #include <pspdisplay.h>
+ #include <pspctrl.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <pspmoduleinfo.h>
+ #include <pspiofilemgr.h>
+ #include <pspdebug.h>
+ #include <psputility.h>
+ 
+ /* Define the module info section */
+ PSP_MODULE_INFO&#40;"Savedata Sample", 0, 1, 0&#41;;
+ 
+ /* Define printf, just to make typing easier */
+ #define printf  pspDebugScreenPrintf
+ 
+ //this is for the save under the folder ULJS00015-000 with a DATA.BIN file inside it, the game is tales of eternia &#40;J&#41;
+ char* gameName = "ULJS00015";
+ char* saveName = "-000";
+ char* dataName = "DATA.BIN";
+ 
+ //define for buffer lenght
+ 
+ #define DATABUFFLEN   0x100000
+ #define READICON0LEN  0x100000
+ #define READICON1LEN  0x100000
+ #define READPIC1LEN   0x100000
+ 
+ /* Exit callback */
+ int exit_callback&#40;int arg1, int arg2, void *common&#41;
+ &#123;
+     sceKernelExitGame&#40;&#41;;
+     return 0;
+ &#125;
+ 
+ /* Callback thread */
+ int CallbackThread&#40;SceSize args, void *argp&#41;
+ &#123;
+     int cbid;
+     cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
+     sceKernelRegisterExitCallback&#40;cbid&#41;;
+     sceKernelSleepThreadCB&#40;&#41;;
+ 
+     return 0;
+ &#125;
+ 
+ /* Sets up the callback thread and returns its thread id */
+ int SetupCallbacks&#40;void&#41;
+ &#123;
+     int thid = 0;
+     thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
+     if &#40;thid >= 0&#41;
+ 	sceKernelStartThread&#40;thid, 0, 0&#41;;
+     return thid;
+ &#125;
+ 
+ /* Utility Savedata functions */
+ 
+ /* based Shine's function, args&#58; SceUtilitySavedataParam* savedata pass the save data structure
+ 				           mode&#58; pass the mode parameter 0 = load 1 = save */
+ 
+ void initSavedata&#40;SceUtilitySavedataParam* savedata, int mode&#41; &#123;
+ 	memset&#40;savedata, 0, sizeof&#40;SceUtilitySavedataParam&#41;&#41;; //zeroes out the struct
+ 	savedata->size = sizeof&#40;SceUtilitySavedataParam&#41;;     //size of the structure
+ 	savedata->unknown3 = 0x11;  // ?
+ 	savedata->unknown4 = 0x13;
+ 	savedata->unknown5 = 0x12;
+ 	savedata->unknown6 = 0x10;
+ 	savedata->unknown13 = 1;
+ 	savedata->mode = mode;  //mode&#58; 0 = load, 1 = save
+ 	strcpy&#40;savedata->gameNameAsciiZ, gameName&#41;; //first part of the save name, game identifier name
+ 	strcpy&#40;savedata->saveNameAsciiZ, saveName&#41;; //second part of the save name, save identifier name
+ 	strcpy&#40;savedata->dataDotBinAsciiZ, dataName&#41;; //name of the data file
+ 
+ 	//alllocates buffers to store various part of the savedata
+ 	savedata->dataBuf = malloc&#40;DATABUFFLEN&#41;;
+ 	savedata->sizeOfDataBuf = DATABUFFLEN;	
+ 
+ 	savedata->readIcon0Buf = malloc&#40;READICON0LEN&#41;;
+ 	savedata->sizeOfReadIcon0Buf = READICON0LEN;
+ 
+ 	savedata->readIcon1Buf = malloc&#40;READICON1LEN&#41;;
+ 	savedata->sizeOfReadIcon1Buf = READICON1LEN;
+ 
+ 	savedata->readPic1Buf = malloc&#40;READPIC1LEN&#41;;
+ 	savedata->sizeOfReadPic1Buf = READPIC1LEN;
+ &#125;
+ 
+ void WorkSaveData&#40;int mode&#41;
+ &#123;
+     SceUtilitySavedataParam savedata;
+ 	initSavedata&#40;&savedata, mode&#41;;
+ 
+ 	//opens files to write or read savedata
+ 	int fd_data = sceIoOpen&#40;"ms0&#58;/dataBuf", PSP_O_TRUNC | PSP_O_CREAT | PSP_O_WRONLY,0777&#41;;
+ 	int fd_sfo = sceIoOpen&#40;"ms0&#58;/sfodata", PSP_O_TRUNC | PSP_O_CREAT | PSP_O_WRONLY,0777&#41;;
+ 
+ 	if&#40;mode == 1&#41; //if we are in mode 1 &#40;writing savedata&#41;, reads files and put their contents on the savedata structure
+ 	&#123;
+ 				sceIoRead&#40;fd_data,savedata.dataBuf, DATABUFFLEN&#41;;
+ 				sceIoRead&#40;fd_sfo,&savedata.paramsSfoTitle, 0x80&#41;;
+ 				sceIoRead&#40;fd_sfo,&savedata.paramsSfoSavedataTitle, 0x80&#41;;
+ 				sceIoRead&#40;fd_sfo,&savedata.paramsSfoDetail, 0x400&#41;;
+ 				sceIoClose&#40;fd_data&#41;;
+ 				sceIoClose&#40;fd_sfo&#41;;
+ 	&#125;
+ 
+ 	int result = sceUtilitySavedataInitStart&#40;&savedata&#41;; //calls the save data utility
+ 	
+ 	printf&#40;"sceUtilitySavedataInitStart result&#58; %i\n", result&#41;; //writes on screen sceUtilitySavedataInitStart result
+ 
+ 	if &#40;result&#41; //if an error happened write it to screen
+ 	&#123;
+ 		printf&#40;"sceUtilitySavedataInitStart failed&#58; %i\n", result&#41;;
+ 	&#125;
+ 
+ 
+ 	while &#40;1&#41; //wait for sceUtilitySavedataInitStart to completes
+ 	&#123;
+ 		result = sceUtilitySavedataGetStatus&#40;&#41;; //get status of sceUtilitySavedata
+ 		if &#40;result == 3&#41; break; //if 3 it has completed let's go out
+ 		sceUtilitySavedataUpdate&#40;1&#41;; //update sceUtilitySavedata
+ 		sceDisplayWaitVblankStart&#40;&#41;; //wait some time
+ 	&#125;
+ 
+ 	result = sceUtilitySavedataShutdownStart&#40;&#41;; //shutdown the Savedata Utility
+ 
+ 	printf&#40;"sceUtilitySavedataShutdownStart result&#58; %i", result&#41;; //writes on screen sceUtilitySavedataShutdownStart result
+ 
+ 	if &#40;result&#41; //if an error happened write it to screen
+ 	&#123;
+ 		printf&#40;"sceUtilitySavedataShutdownStart failed&#58; %i", result&#41;;
+ 	&#125;
+ 
+ 	while &#40;1&#41; //wait for sceUtilitySavedataShutdownStart to completes
+ 	&#123;
+ 		result = sceUtilitySavedataGetStatus&#40;&#41;; //get status of sceUtilitySavedata
+ 		if &#40;result == 4&#41; break; //if 3 it has shutdown let's go out
+ 		sceUtilitySavedataUpdate&#40;1&#41;; //update sceUtilitySavedata
+ 		sceDisplayWaitVblankStart&#40;&#41;; //wait some time
+ 	&#125;
+ 
+ 	if&#40;mode == 0&#41; //if we was reading savedata then write it to a file in the ms0 root
+ 	&#123;
+ 				sceIoWrite&#40;fd_data,savedata.dataBuf, DATABUFFLEN&#41;;
+ 				sceIoWrite&#40;fd_sfo,&savedata.paramsSfoTitle, 0x80&#41;;
+ 				sceIoWrite&#40;fd_sfo,&savedata.paramsSfoSavedataTitle, 0x80&#41;;
+ 				sceIoWrite&#40;fd_sfo,&savedata.paramsSfoDetail, 0x400&#41;;
+ 				sceIoClose&#40;fd_data&#41;;
+ 				sceIoClose&#40;fd_sfo&#41;;
+ 	&#125;
+ 
+ &#125;
+ 
+ /* main routine */
+ int main&#40;int argc, char *argv&#91;&#93;&#41;
+ &#123;
+ 	SetupCallbacks&#40;&#41;;
+ 	pspDebugScreenInit&#40;&#41;;
+ 	printf&#40;"sceUtilitySavedata sample\n\nPress O to load savedata, and put it into ms0&#58;/\nPress X to save savedata, from files put into ms0&#58;/\n"&#41;;
+ 	while&#40;1&#41;
+ 	&#123;
+ 		SceCtrlData pad;
+ 		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
+ 		if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41;
+ 		&#123;
+ 			WorkSaveData&#40;0&#41;;
+ 		&#125;
+ 		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
+ 		&#123;
+ 			WorkSaveData&#40;1&#41;;
+ 		&#125;
+ 		if&#40;pad.Buttons & PSP_CTRL_TRIANGLE&#41;
+ 			break;
+ 	&#125;
+ 
+     sceKernelExitGame&#40;&#41;;
+     return 0;
+ &#125;
--- ./pspsdk/sdk/utility/Makefile.am	Mon Nov  7 15&#58;50&#58;25 2005
+++ ./pspsdk/sdk/utility/Makefile.am	Mon Nov  7 15&#58;18&#58;06 2005
***************
*** 17,23 ****
                                 psputility_sysparam.h \
                                 psputility_netconf.h \
                                 psputility_netparam.h \
!                                psputility_msgdialog.h
  
  lib_LIBRARIES = libpsputility.a
  libpsputility_a_SOURCES = sceUtility.S
--- 17,24 ----
                                 psputility_sysparam.h \
                                 psputility_netconf.h \
                                 psputility_netparam.h \
!                                psputility_msgdialog.h \
! 							   psputility_savedata.h
  
  lib_LIBRARIES = libpsputility.a
  libpsputility_a_SOURCES = sceUtility.S
--- ./pspsdk/sdk/utility/psputility.h	Mon Nov  7 15&#58;50&#58;25 2005
+++ ./pspsdk/sdk/utility/psputility.h	Mon Nov  7 13&#58;24&#58;14 2005
***************
*** 15,20 ****
  #include <psputility_sysparam.h>
  #include <psputility_netconf.h>
  #include <psputility_netparam.h>
! #include <psputility_msgdialog.h>
  
  #endif
--- 15,21 ----
  #include <psputility_sysparam.h>
  #include <psputility_netconf.h>
  #include <psputility_netparam.h>
! #include <psputility_msgdialog.h>
! #include <psputility_savedata.h>
  
  #endif
--- ./pspsdk/sdk/utility/psputility_savedata.h	Thu Jan  1 01&#58;00&#58;00 1970
+++ .pspsdk/sdk/utility/psputility_savedata.h	Mon Nov  7 15&#58;47&#58;51 2005
***************
*** 0 ****
--- 1,149 ----
+ /*
+  * PSP Software Development Kit - http&#58;//www.pspdev.org
+  * -----------------------------------------------------------------------
+  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
+  *
+  *  psputility_savedata.h - Definitions and Functions for savedata part of
+  *							pspUtility library
+  *
+  * Copyright &#40;c&#41; 2005    Shine
+  *                       weltall <[email protected]>
+  *
+  * $Id&#58; $
+  */
+ #ifndef __PSPUTILITY_SAVEDATA_H__
+ #define __PSPUTILITY_SAVEDATA_H__
+ 
+ #ifdef __cplusplus
+ extern "C" &#123;
+ #endif
+ 
+ #include <psptypes.h>
+ 
+ /** Structure to hold the parameters for the savedatainit function
+   */
+ 
+ typedef struct
+ &#123;
+ 	/** Size of the structure */
+ 	int size;
+ 
+ 	int unknown1;
+ 
+ 	int unknown2;
+ 
+ 	/** unknown3 use 0x11 */
+ 	int unknown3;
+ 
+ 	/** unknown4 use 0x13 */
+ 	int unknown4;
+ 
+ 	/** unknown5 use 0x12 */
+ 	int unknown5;
+ 
+ 	/** unknown6 use 0x10 */
+ 	int unknown6;
+ 	int unknown7;
+ 	int unknown8;
+ 	int unknown9;
+ 	int unknown10;
+ 	int unknown11;
+ 
+ 	/** mode&#58; 0 to load, 1 to save */
+ 	int mode;
+ 	int unknown12;
+ 
+ 	/** unknown13 use 0x10 */
+ 	int unknown13;
+ 
+ 	/** gameNameAsciiZ&#58; name used from the game for saves, equal for all saves */
+ 	char gameNameAsciiZ&#91;16&#93;;
+ 
+ 	/** saveNameAsciiZ&#58; name of the particular save, normally a number */
+ 	char saveNameAsciiZ&#91;24&#93;;
+ 
+ 	/** dataDotBinAsciiZ&#58; name of the data file of the game for example DATA.BIN */
+ 	char dataDotBinAsciiZ&#91;16&#93;;
+ 
+ 	/** pointer to a buffer that will contain data file unencrypted data */
+ 	unsigned char* dataBuf;
+ 
+ 	/** size of allocated space to 	unsigned char* dataBuf; */
+ 	int sizeOfDataBuf;
+ 	int sizeOfData;
+ 
+ 	/** paramsSfoTitle, paramsSfoSavedataTitle, paramsSfoDetail&#58; parts of the unencrypted sfo data, it contains
+ 	    what the VSH and standard load screen shows */
+ 	char paramsSfoTitle&#91;0x80&#93;;
+ 	char paramsSfoSavedataTitle&#91;0x80&#93;;
+ 	char paramsSfoDetail&#91;0x400&#93;;
+ 	unsigned char paramsSfoParentalLevel;
+ 	unsigned char unknown14&#91;3&#93;;
+ 	
+ 	/** pointer to a buffer to contain Icon0 */
+ 	unsigned char* readIcon0Buf;
+ 
+ 	/** allocated size of unsigned char* readIcon0Buf */
+ 	int sizeOfReadIcon0Buf;
+ 	int sizeOfReadIcon0;
+ 	int unknown15;
+ 
+ 	/** pointer to a buffer to contain Icon1 */
+ 	unsigned char* readIcon1Buf;
+ 
+ 	/** allocated size of unsigned char* readIcon1Buf */
+ 	int sizeOfReadIcon1Buf;
+ 	int sizeOfReadIcon1;
+ 	int unknown16;
+ 
+ 	/** pointer to a buffer to contain Pic1 */
+ 	unsigned char* readPic1Buf;
+ 
+ 	/** allocated size of unsigned char* readPic1Buf */
+ 	int sizeOfReadPic1Buf;
+ 	int sizeOfReadPic1;
+ 	unsigned char unknown17&#91;0x18&#93;;
+ &#125; SceUtilitySavedataParam;
+ 
+ 
+ /**
+  * Saves or Load savedata to/from the passed structure
+  * After having called this continue calling sceUtilitySavedataGetStatus to check if the operation is completed
+  *
+  * @param params - savedata parameters
+  * @returns 0 on success
+  */
+ int sceUtilitySavedataInitStart&#40;SceUtilitySavedataParam *params&#41;;
+ 
+ /**
+  * Check the current status of the saving/loading/shutdown process
+  * Continue calling this to check current status of the process
+  * before calling this call also sceUtilitySavedataUpdate
+  * @returns 2 if the process is still being processed.
+  * 3 on save/load success, then you can call sceUtilitySavedataShutdownStart.
+  * 4 on complete shutdown.
+  */
+ int sceUtilitySavedataGetStatus&#40;void&#41;;
+ 
+ 
+ /**
+  * Shutdown the savedata utility. after calling this continue calling sceUtilitySavedataGetStatus to check
+  * when it has shutdown
+  *
+  * @return 0 on success
+  *
+  */
+ int sceUtilitySavedataShutdownStart&#40;void&#41;;
+ 
+ /**
+  * Refresh status of the savedata function
+  *
+  * @param unknown - unknown, pass 1
+  */
+ void sceUtilitySavedataUpdate&#40;int unknown&#41;;
+ 
+ #ifdef __cplusplus
+ &#125;
+ #endif
+ 
+ #endif
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Thanks for the patch! I'll apply it a bit later today.
Post Reply