aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PSVita/4JLibs/inc/4J_Storage.h
blob: 4c9219a9f107093b5ae5dfcd08c260cffb99f14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#pragma once
using namespace std;

#include <fios2.h>

//#define MAX_DISPLAYNAME_LENGTH 128 // SCE_SAVE_DATA_SUBTITLE_MAXSIZE on PS4
#define MAX_DISPLAYNAME_LENGTH 128 // SCE_APPUTIL_SAVEDATA_SLOT_SUBTITLE_MAXSIZE on Vita

//#define MAX_SAVEFILENAME_LENGTH 32 // SCE_SAVE_DATA_DIRNAME_DATA_MAXSIZE on PS4
#define MAX_SAVEFILENAME_LENGTH 64//SCE_APPUTIL_SAVEDATA_SLOT_TITLE_MAXSIZE on Vita

#define USER_INDEX_ANY 0x000000FF
#define RESULT	LONG

class StringTable;

typedef struct  
{
	char UTF8SaveFilename[MAX_SAVEFILENAME_LENGTH];
	char UTF8SaveTitle[MAX_DISPLAYNAME_LENGTH];
	time_t modifiedTime;
	PBYTE thumbnailData;
	unsigned int thumbnailSize;
	//int sizeKB;
}
SAVE_INFO,*PSAVE_INFO;

typedef struct  
{
	int iSaveC;
	PSAVE_INFO SaveInfoA;
}
SAVE_DETAILS,*PSAVE_DETAILS;

class CONTENT_DATA
{
public:
	enum Type
	{
		e_contentLocked,
		e_contentUnlocked
	};
	int DeviceID;
	DWORD dwContentType;
	WCHAR wszDisplayName[256];
	CHAR szFileName[SCE_FIOS_PATH_MAX];
};
typedef CONTENT_DATA XCONTENT_DATA, *PXCONTENT_DATA;			// TODO - put back in when actually interfacing with game

#define MARKETPLACE_CONTENTOFFER_INFO int

// Current version of the dlc data creator
#define CURRENT_DLC_VERSION_NUM 3

// MGH - moved these here from Orbis_App.h
enum e_SONYDLCType
{
	eSONYDLCType_SkinPack=0,
	eSONYDLCType_TexturePack,
	eSONYDLCType_MashUpPack,
	eSONYDLCType_All
};

typedef struct
{
	char chDLCKeyname[16];
	//char chDLCTitle[64];
	e_SONYDLCType eDLCType;
	int iFirstSkin;
	int iConfig; // used for texture pack data files
}
SONYDLC;

class C4JStorage
{
public:

	struct PROFILESETTINGS
	{
		int iYAxisInversion;
		int iControllerSensitivity;
		int iVibration;
		bool bSwapSticks;
	};

	// Structs defined in the DLC_Creator, but added here to be used in the app
	typedef struct  
	{
		unsigned int	uiFileSize;
		DWORD			dwType;
		DWORD			dwWchCount; // count of WCHAR in next array
		WCHAR			wchFile[1];
	}
	DLC_FILE_DETAILS, *PDLC_FILE_DETAILS;

	typedef struct
	{
		DWORD	dwType;
		DWORD	dwWchCount; // count of WCHAR in next array;
		WCHAR	wchData[1]; // will be an array of size dwBytes
	}
	DLC_FILE_PARAM, *PDLC_FILE_PARAM;
	// End of DLC_Creator structs

	typedef struct  
	{
		DWORD dwVersion;
		DWORD dwNewOffers;
		DWORD dwTotalOffers;
		DWORD dwInstalledTotalOffers;
		BYTE bPadding[1024-sizeof(DWORD)*4]; // future expansion
	}
	DLC_TMS_DETAILS;

	typedef struct  
	{
		DWORD dwSize;
		PBYTE pbData;
	}
	TMSPP_FILEDATA, *PTMSPP_FILEDATA;

	enum eTMS_FILETYPEVAL
	{
		TMS_FILETYPE_BINARY=0,
		TMS_FILETYPE_CONFIG=1,
		TMS_FILETYPE_JSON=2,
		TMS_FILETYPE_MAX,
	};

	enum eGlobalStorage
	{
		//eGlobalStorage_GameClip=0,
		eGlobalStorage_Title=0,
		eGlobalStorage_TitleUser,
		eGlobalStorage_Max
	};

	enum EMessageResult
	{
		EMessage_Undefined=0,
		EMessage_Busy,
		EMessage_Pending,
		EMessage_Cancelled,
		EMessage_ResultAccept,
		EMessage_ResultDecline,
		EMessage_ResultThirdOption,
		EMessage_ResultFourthOption
	};

	enum ESaveGameState
	{
		ESaveGame_Idle=0,

		ESaveGame_Save,	
		ESaveGame_SaveCompleteSuccess,
		ESaveGame_SaveCompleteFail,
		ESaveGame_SaveIncomplete,
		ESaveGame_SaveIncomplete_WaitingOnResponse,

		ESaveGame_Load,
		ESaveGame_LoadCompleteSuccess,
		ESaveGame_LoadCompleteFail,

		ESaveGame_Delete,
		ESaveGame_DeleteSuccess,
		ESaveGame_DeleteFail,

		ESaveGame_Rename,
		ESaveGame_RenameSuccess,
		ESaveGame_RenameFail,

		ESaveGame_GetSaveThumbnail,		// Not used as an actual state in the PS4, but the game expects this to be returned to indicate success when getting a thumbnail
		ESaveGame_GetSaveInfo,

		ESaveGame_SaveCache,
		ESaveGame_ReconstructCache
	};

	enum EOptionsState
	{
		EOptions_Idle=0,
		EOptions_Save,	
		EOptions_Load,	
		EOptions_Delete,	
		EOptions_NoSpace,	
		EOptions_Corrupt,	
	};

	enum ESaveGameStatus
	{
		EDeleteGame_Idle=0,
		EDeleteGame_InProgress,
	};

	enum EDLCStatus
	{
		EDLC_Error=0,
		EDLC_Idle,
		EDLC_NoOffers,
		EDLC_AlreadyEnumeratedAllOffers,
		EDLC_NoInstalledDLC,
		EDLC_Pending,
		EDLC_LoadInProgress,
		EDLC_Loaded,
		EDLC_ChangedDevice
	};

	enum ESavingMessage
	{
		ESavingMessage_None=0,
		ESavingMessage_Short,
		ESavingMessage_Long
	};

	enum ESaveIncompleteType
	{
		ESaveIncomplete_None,
		ESaveIncomplete_OutOfQuota,
		ESaveIncomplete_OutOfLocalStorage,
		ESaveIncomplete_Unknown
	};

	enum ETMSStatus
	{
		ETMSStatus_Idle=0,
		ETMSStatus_Fail,
		ETMSStatus_ReadInProgress,
		ETMSStatus_ReadFileListInProgress,
		ETMSStatus_WriteInProgress,
		ETMSStatus_Fail_ReadInProgress,
		ETMSStatus_Fail_ReadFileListInProgress,
		ETMSStatus_Fail_ReadDetailsNotRetrieved,
		ETMSStatus_Fail_WriteInProgress,
		ETMSStatus_DeleteInProgress,
		ETMSStatus_Pending,
	};

	enum eTMS_FileType
	{
		eTMS_FileType_Normal=0,
		eTMS_FileType_Graphic,
	};

	enum ESGIStatus
	{
		ESGIStatus_Error=0,
		ESGIStatus_Idle,
		ESGIStatus_ReadInProgress,
		ESGIStatus_NoSaves,
	};

	enum
	{
		PROFILE_READTYPE_ALL,
		PROFILE_READTYPE_XBOXSETTINGS // just read the settings (after a notification of settings change)
	};

	enum eOptionsCallback
	{
		eOptions_Callback_Idle,
		eOptions_Callback_Write,
		eOptions_Callback_Write_Fail_NoSpace,
		eOptions_Callback_Write_Fail,
		eOptions_Callback_Read,		
		eOptions_Callback_Read_Fail,		
		eOptions_Callback_Read_FileNotFound,		
		eOptions_Callback_Read_Corrupt,		
		eOptions_Callback_Read_CorruptDeletePending,
		eOptions_Callback_Read_CorruptDeleted
	};

	///////////////////////////////////////////////////////////////////////////// Global storage manager //////////////////////////////////////////////////////////////////////////////

	C4JStorage();
	void						Tick(void);																																			// General storage manager tick to be called from game
	
	///////////////////////////////////////////////////////////////////////////// Savegame data ///////////////////////////////////////////////////////////////////////////////////////

	// Initialisation
	void						Init(unsigned int uiSaveVersion,LPCWSTR pwchDefaultSaveName,char *pszSavePackName,int iMinimumSaveSize,												// General manager initialisation
									 int( *Func)(LPVOID, const ESavingMessage, int),LPVOID lpParam,LPCSTR szGroupID);																		
	void						SetGameSaveFolderTitle(WCHAR *wszGameSaveFolderTitle);																								// Sets the title to be set in the param.sfo of saves (this doesn't vary, the sub-title is used for the user cho
	void						SetSaveCacheFolderTitle(WCHAR *wszSaveCacheFolderTitle);																							// Sets the title to be set in the param.sfo of the save cache
	void						SetOptionsFolderTitle(WCHAR *wszOptionsFolderTitle);																								// Sets the title to be set in the param.sfo of the options file
	void						SetGameSaveFolderPrefix(char *szGameSaveFolderPrefix);																								// Sets the prefix to be added to the unique filename of each save to construct a final folder name
	void						SetMaxSaves(int iMaxC);																																// Sets the maximum number of saves to be evaluated by GetSavesInfo etc.
	void						SetDefaultImages(PBYTE pbOptionsImage,DWORD dwOptionsImageBytes,PBYTE pbSaveImage,DWORD dwSaveImageBytes,											// Sets default save image and thumbnail, which can be used when saving a game that hasn't generated any yet
												 PBYTE pbSaveThumbnail,DWORD dwSaveThumbnailBytes);	

	void						SetIncompleteSaveCallback(void( *Func)(LPVOID, const ESaveIncompleteType, int blocksRequired), LPVOID param);										// Sets callback to be used in the event of a save method not being able to complete

	// Miscellaneous control
	void						SetSaveDisabled(bool bDisable);																														// Sets saving disabled/enabled state
	bool						GetSaveDisabled(void);																																// Determines whether saving has been disabled
	void						ResetSaveData();																																	// Releases any internal storage being held for previously saved/loaded data
	C4JStorage::ESaveGameState	DoesSaveExist(bool *pbExists);																														// Determine if current savegame exists on storage device
	bool						EnoughSpaceForAMinSaveGame();

	// Get details of existing savedata
	C4JStorage::ESaveGameState	GetSavesInfo(int iPad,int ( *Func)(LPVOID lpParam,SAVE_DETAILS *pSaveDetails,const bool),LPVOID lpParam,char *pszSavePackName);						// Start search
	PSAVE_DETAILS				ReturnSavesInfo();																																	// Returns result of search (or nullptr if not yet received)
	void						ClearSavesInfo();																																	// Clears results
	C4JStorage::ESaveGameState	LoadSaveDataThumbnail(PSAVE_INFO pSaveInfo,int( *Func)(LPVOID lpParam,PBYTE pbThumbnail,DWORD dwThumbnailBytes), LPVOID lpParam);					// Get the thumbnail for an individual save referenced by pSaveInfo

	// Loading savedata & obtaining information from just-loaded file
	C4JStorage::ESaveGameState	LoadSaveData(PSAVE_INFO pSaveInfo,int( *Func)(LPVOID lpParam,const bool, const bool), LPVOID lpParam);												// Loads savedata referenced by pSaveInfo, calls callback once complete
	unsigned int				GetSaveSize();																																		// Obtains sizse of just-loaded save
	void						GetSaveData(void *pvData,unsigned int *puiBytes);																									// Obtains pointer to, and size, of just-loaded save
	bool						GetSaveUniqueNumber(INT *piVal);																													// Gets the unique numeric portion of the folder name used for the save (encodes m
	bool						GetSaveUniqueFilename(char *pszName);																												// Get the full unique "filename" used as part of the folder name for the save
	bool						GetSaveUniqueFileDir(char *pszName);																												// Get the full unique "filename" used as part of the folder name for the save

	// Saving savedata
	void						SetSaveTitle(const wchar_t *UTF16String);																											// Sets the name which is used as a sub-title in the savedata param.sfo
	PVOID						AllocateSaveData(unsigned int uiBytes);																												// Allocate storage manager owned memory to the data which is to be saved to
	void						SetSaveDataSize(unsigned int uiBytes);																												// Set the actual size of data to be saved
	void						GetDefaultSaveImage(PBYTE *ppbSaveImage,DWORD *pdwSaveImageBytes);																					// Get the default save thumbnail (as set by SetDefaultImages) for use on saving games t
	void						GetDefaultSaveThumbnail(PBYTE *ppbSaveThumbnail,DWORD *pdwSaveThumbnailBytes);																		// Get the default save image (as set by SetDefaultImages) for use on saving games that 
	void						SetSaveImages( PBYTE pbThumbnail,DWORD dwThumbnailBytes,PBYTE pbImage,DWORD dwImageBytes, PBYTE pbTextData ,DWORD dwTextDataBytes);					// Sets the thumbnail & image for the save, optionally setting the metadata in the png
	C4JStorage::ESaveGameState	SaveSaveData(int( *Func)(LPVOID ,const bool),LPVOID lpParam);																						// Save the actual data, calling callback on completion

	// Handling of incomplete saves (either sub-files or save data). To be used after game has had callback for an incomplete save event
	void						ContinueIncompleteOperation();
	void						CancelIncompleteOperation();

	ESaveIncompleteType			GetSaveError();																																		// Returns the save error [SaveData]
	void						ClearSaveError();																																	// Clears any save error
	ESaveIncompleteType			GetOptionsSaveError();																																// Returns the save error [Options]
	void						ClearOptionsSaveError();																															// Clears any save error

	// Other file operations
	C4JStorage::ESaveGameState	DeleteSaveData(PSAVE_INFO pSaveInfo,int( *Func)(LPVOID lpParam,const bool), LPVOID lpParam);														// Deletes savedata referenced by pSaveInfo, calls callback when comple
	C4JStorage::ESaveGameState	RenameSaveData(int iRenameIndex, uint16_t*pui16NewName, int( *Func)(LPVOID lpParam,const bool), LPVOID lpParam);										// Renamed savedata with index from last established ReturnSavesInfo.
	
	// Internal methods
private:
	void						GetSaveImage(PBYTE *ppbSaveImage, int *puiSaveImageBytes);
	void						GetSaveThumbnail(PBYTE *ppbSaveThumbnail, int *puiSaveThumbnailBytes);
public:		
	void						SetSaveUniqueFilename(char *szFilename);		// MGH - made this public, used for the cross save stuff
	void						EnableDownloadSave();							// CD - Used for cross/download-save, sets a flag for saving

	///////////////////////////////////////////////////////////////////////////// Profile data ////////////////////////////////////////////////////////////////////////////////////////
public:
	// Initialisation
	void						InitialiseProfileData(unsigned short usProfileVersion, UINT uiProfileValuesC, UINT uiProfileSettingsC, DWORD *pdwProfileSettingsA, int iGameDefinedDataSizeX4, unsigned int *puiGameDefinedDataChangedBitmask);	// General initialisation
	int							SetDefaultOptionsCallback(int( *Func)(LPVOID,PROFILESETTINGS *, const int iPad),LPVOID lpParam);													// Set a callback that can initialise a profile's storage to its default settings
	void						SetOptionsDataCallback(int( *Func)(LPVOID,  int iPad, unsigned short usVersion, C4JStorage::eOptionsCallback),LPVOID lpParam);	// Sets callback that is called when status of any options has changed
	int							SetOldProfileVersionCallback(int( *Func)(LPVOID,unsigned char *, const unsigned short,const int),LPVOID lpParam);

	// Getting and setting of profile data
	PROFILESETTINGS *			GetDashboardProfileSettings(int iPad);																												// Get pointer to the standard (originally xbox dashboard) profile data for one user
	void						*GetGameDefinedProfileData(int iQuadrant);																											// Get pointer to the game-defined profile data for one user

	// Reading and writing profiles
	void						ReadFromProfile(int iQuadrant, int iReadType=PROFILE_READTYPE_ALL);																					// Initiate read profile data for one user - read type is ignored on this platform
	void						WriteToProfile(int iQuadrant, bool bGameDefinedDataChanged=false, bool bOverride5MinuteLimitOnProfileWrites=false);									// Initiate write profile for one user
	void						DeleteOptionsData(int iPad);																														// Delete profile data for one user
	void						ForceQueuedProfileWrites(int iPad=XUSER_INDEX_ANY);																									// Force any queued profile writes to write now
	C4JStorage::ESaveGameState	GetSaveState();


	///////////////////////////////////////////////////////////////////////////// Unimplemented stubs /////////////////////////////////////////////////////////////////////////////////
	void						SetSaveDeviceSelected(unsigned int uiPad,bool bSelected) {}
	bool						GetSaveDeviceSelected(unsigned int iPad) { return true; }
	void						ClearDLCOffers() {}
	C4JStorage::ETMSStatus		ReadTMSFile(int iQuadrant,eGlobalStorage eStorageFacility,C4JStorage::eTMS_FileType eFileType, WCHAR *pwchFilename,BYTE **ppBuffer,DWORD *pdwBufferSize,int( *Func)(LPVOID, WCHAR *,int, bool, int),LPVOID lpParam, int iAction) { return C4JStorage::ETMSStatus_Idle; }
	bool						WriteTMSFile(int iQuadrant,eGlobalStorage eStorageFacility,WCHAR *pwchFilename,BYTE *pBuffer,DWORD dwBufferSize) { return true; }
	bool						DeleteTMSFile(int iQuadrant,eGlobalStorage eStorageFacility,WCHAR *pwchFilename) { return true; }
	C4JStorage::EDLCStatus		GetDLCOffers(int iPad,int( *Func)(LPVOID, int, DWORD, int),LPVOID lpParam, DWORD dwOfferTypesBitmaskT) { return C4JStorage::EDLC_Idle; }

	// DLC
	void						SetDLCPackageRoot(char *pszDLCRoot);
	EDLCStatus					GetInstalledDLC(int iPad,int( *Func)(LPVOID, int, int),LPVOID lpParam);
	CONTENT_DATA&				GetDLC(DWORD dw);
	DWORD						GetAvailableDLCCount( int iPad );
	DWORD						MountInstalledDLC(int iPad,DWORD dwDLC,int( *Func)(LPVOID, int, DWORD,DWORD),LPVOID lpParam,LPCSTR szMountDrive = nullptr);
	DWORD						UnmountInstalledDLC(LPCSTR szMountDrive = nullptr);
	void						GetMountedDLCFileList(const char* szMountDrive, std::vector<std::string>& fileList);
	std::string					GetMountedPath(std::string szMount);
	void						SetDLCProductCode(const char* szProductCode);
	void						SetProductUpgradeKey(const char* szKey);
	bool						CheckForTrialUpgradeKey(void( *Func)(LPVOID, bool),LPVOID lpParam);
	void						SetDLCInfoMap(std::unordered_map<wstring, SONYDLC *>* pSONYDLCMap);
	void						EntitlementsCallback(bool bFoundEntitlements);

};

extern C4JStorage StorageManager;