the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 371 lines 10 kB view raw
1#include "stdafx.h" 2 3#include "SonyRemoteStorage_Orbis.h" 4#include "SonyHttp_Orbis.h" 5#include <stdio.h> 6#include <string> 7#include <stdlib.h> 8// #include <cell/sysmodule.h> 9// #include <cell/http.h> 10// #include <cell/ssl.h> 11// #include <netex/net.h> 12// #include <netex/libnetctl.h> 13// #include <np.h> 14// #include <sysutil/sysutil_common.h> 15// #include <sys/timer.h> 16// #include <sys/paths.h> 17// #include <sysutil\sysutil_savedata.h> 18 19 20 21 22#define AUTH_SCOPE "psn:s2s" 23#define CLIENT_ID "969e9d21-527c-4c22-b539-f8e479f690bc" 24static SceRemoteStorageData s_getDataOutput; 25 26 27void SonyRemoteStorage_Orbis::staticInternalCallback(const SceRemoteStorageEvent event, int32_t retCode, void * userData) 28{ 29 ((SonyRemoteStorage_Orbis*)userData)->internalCallback(event, retCode); 30} 31void SonyRemoteStorage_Orbis::internalCallback(const SceRemoteStorageEvent event, int32_t retCode) 32{ 33 m_lastErrorCode = retCode; 34 35 switch(event) 36 { 37 case ERROR_OCCURRED: 38 app.DebugPrintf("SonyRemoteStorage_Orbis: An error occurred with retCode: 0x%x \n", retCode); 39 m_status = e_error; 40// shutdown(); // removed, as the remote storage lib now tries to reconnect if an error has occurred 41 runCallback(); 42 break; 43 44 case GET_DATA_RESULT: 45 if(retCode >= 0) 46 { 47 app.DebugPrintf("SonyRemoteStorage_Orbis: Get Data success \n"); 48 m_status = e_getDataSucceeded; 49 } 50 else 51 { 52 app.DebugPrintf("SonyRemoteStorage_Orbis: An error occurred while Get Data was being processed. retCode: 0x%x \n", retCode); 53 m_status = e_error; 54 } 55 if(StorageManager.SaveGameDirUnMount(m_mountPoint) == false) 56 { 57 app.DebugPrintf("Failed to unmount %s\n", m_mountPoint); 58 } 59 60 m_mountPoint[0] = 0; 61 runCallback(); 62 break; 63 64 case GET_DATA_PROGRESS: 65 app.DebugPrintf("SonyRemoteStorage_Orbis: Get data progress: %i%%\n", retCode); 66 m_status = e_getDataInProgress; 67 m_dataProgress = retCode; 68 m_startTime = System::currentTimeMillis(); 69 break; 70 71 case GET_STATUS_RESULT: 72 if(retCode >= 0) 73 { 74 app.DebugPrintf("SonyRemoteStorage_Orbis: Get Status success \n"); 75 app.DebugPrintf("SonyRemoteStorage_Orbis: Remaining Syncs for this user: %llu\n", outputGetStatus->remainingSyncs); 76 app.DebugPrintf("SonyRemoteStorage_Orbis: Number of files on the cloud: %d\n", outputGetStatus->numFiles); 77 for(int i = 0; i < outputGetStatus->numFiles; i++) 78 { 79 app.DebugPrintf("\n*** File %d information: ***\n", (i + 1)); 80 app.DebugPrintf("File name: %s \n", outputGetStatus->data[i].fileName); 81 app.DebugPrintf("File description: %s \n", outputGetStatus->data[i].fileDescription); 82 app.DebugPrintf("MD5 Checksum: %s \n", outputGetStatus->data[i].md5Checksum); 83 app.DebugPrintf("Size of the file: %u bytes \n", outputGetStatus->data[i].fileSize); 84 app.DebugPrintf("Timestamp: %s \n", outputGetStatus->data[i].timeStamp); 85 app.DebugPrintf("Visibility: \"%s\" \n", (outputGetStatus->data[i].visibility == 0)?"Private":((outputGetStatus->data[i].visibility == 1)?"Public read only":"Public read and write")); 86 } 87 m_status = e_getStatusSucceeded; 88 } 89 else 90 { 91 app.DebugPrintf("SonyRemoteStorage_Orbis: An error occurred while Get Status was being processed. retCode: 0x%x \n", retCode); 92 m_status = e_error; 93 } 94 runCallback(); 95 break; 96 97 case PSN_SIGN_IN_REQUIRED: 98 app.DebugPrintf("SonyRemoteStorage_Orbis: User's PSN sign-in through web browser is required \n"); 99 m_status = e_signInRequired; 100 runCallback(); 101 break; 102 103 case SET_DATA_RESULT: 104 if(retCode >= 0) 105 { 106 app.DebugPrintf("SonyRemoteStorage_Orbis: Set Data success \n"); 107 m_status = e_setDataSucceeded; 108 } 109 else 110 { 111 app.DebugPrintf("SonyRemoteStorage_Orbis: An error occurred while Set Data was being processed. retCode: 0x%x \n", retCode); 112 m_status = e_error; 113 } 114 runCallback(); 115 break; 116 117 case SET_DATA_PROGRESS: 118 app.DebugPrintf("SonyRemoteStorage_Orbis: Set data progress: %i%%\n", retCode); 119 m_status = e_setDataInProgress; 120 m_dataProgress = retCode; 121 122 break; 123 124 case USER_ACCOUNT_LINKED: 125 app.DebugPrintf("SonyRemoteStorage_Orbis: User's account has been linked with PSN \n"); 126 m_bInitialised = true; 127 m_status = e_accountLinked; 128 runCallback(); 129 break; 130 131 case WEB_BROWSER_RESULT: 132 app.DebugPrintf("SonyRemoteStorage_Orbis: This function is not used on PS Vita, as the account will be linked, it is not needed to open a browser to link it \n"); 133 assert(0); 134 break; 135 136 default: 137 app.DebugPrintf("SonyRemoteStorage_Orbis: This should never happen \n"); 138 assert(0); 139 break; 140 141 } 142} 143 144bool SonyRemoteStorage_Orbis::init(CallbackFunc cb, LPVOID lpParam) 145{ 146 147 int ret = 0; 148 int reqId = 0; 149 SceNpId npId; 150 SceUserServiceUserId userId; 151 SceRemoteStorageInitParams params; 152 153 m_callbackFunc = cb; 154 m_callbackParam = lpParam; 155 156 if(m_bInitialised) 157 { 158 runCallback(); 159 return true; 160 } 161 162 ret = sceUserServiceGetInitialUser(&userId); 163 if (ret < 0) 164 { 165 app.DebugPrintf("Couldn't retrieve user ID 0x%x\n", ret); 166 return false; 167 } 168 169 ret = sceNpGetNpId(userId, &npId); 170 if (ret < 0) { 171 app.DebugPrintf("Couldn't retrieve NP ID 0x%x\n", ret); 172 return false; 173 } 174 175// ret = sceNpAuthCreateRequest(); 176// if (ret < 0) { 177// app.DebugPrintf("Couldn't create auth request 0x%x\n", ret); 178// return false; 179// } 180// 181// reqId = ret; 182// 183// SceNpClientId clientId; 184// memset(&clientId, 0x0, sizeof(clientId)); 185 186// SceNpAuthorizationCode authCode; 187// memset(&authCode, 0x0, sizeof(authCode)); 188 189// SceNpAuthGetAuthorizationCodeParameter authParams; 190// memset(&authParams, 0x0, sizeof(authParams)); 191// 192// authParams.size = sizeof(authParams); 193// authParams.pOnlineId = &npId.handle; 194// authParams.pScope = AUTH_SCOPE; 195 196// memcpy(clientId.id, CLIENT_ID, strlen(CLIENT_ID)); 197// authParams.pClientId = &clientId; 198 199// ret = sceNpAuthGetAuthorizationCode(reqId, &authParams, &authCode, NULL); 200// if (ret < 0) { 201// app.DebugPrintf("Failed to get auth code 0x%x\n", ret); 202// } 203 204// ret = sceNpAuthDeleteRequest(reqId); 205// if (ret < 0) { 206// app.DebugPrintf("Couldn't delete auth request 0x%x\n", ret); 207// } 208 209 params.callback = staticInternalCallback; 210 params.userData = this; 211// memcpy(params.authCode, authCode.code, SCE_NP_AUTHORIZATION_CODE_MAX_LEN); 212 params.userId = userId; 213 params.environment = DEVELOPMENT; 214 params.httpContextId = SonyHttp_Orbis::getHTTPContextID(); 215 strcpy(params.clientId, CLIENT_ID); 216 217 params.thread.threadAffinity = SCE_KERNEL_CPUMASK_USER_ALL; 218 params.thread.threadPriority = SCE_KERNEL_PRIO_FIFO_DEFAULT; 219 220 params.timeout.connectMs = 30 * 1000; //30 seconds is the default 221 params.timeout.resolveMs = 30 * 1000; //30 seconds is the default 222 params.timeout.receiveMs = 120 * 1000; //120 seconds is the default 223 params.timeout.sendMs = 120 * 1000; //120 seconds is the default 224 225 params.pool.memPoolSize = 7 * 1024 * 1024; 226 if(m_memPoolBuffer == NULL) 227 m_memPoolBuffer = malloc(params.pool.memPoolSize); 228 229 params.pool.memPoolBuffer = m_memPoolBuffer; 230 231 ret = sceRemoteStorageInit(params); 232 if (ret >= 0) 233 { 234 app.DebugPrintf("Session will be created \n"); 235 } 236 else if(ret == SCE_REMOTE_STORAGE_ERROR_ALREADY_INITIALISED) 237 { 238 app.DebugPrintf("Already initialised: 0x%x \n", ret); 239 runCallback(); 240 } 241 else 242 { 243 app.DebugPrintf("Error creating session: 0x%x \n", ret); 244 return false; 245 } 246 return true; 247} 248 249 250 251bool SonyRemoteStorage_Orbis::getRemoteFileInfo(SceRemoteStorageStatus* pInfo, CallbackFunc cb, LPVOID lpParam) 252{ 253 m_callbackFunc = cb; 254 m_callbackParam = lpParam; 255 outputGetStatus = pInfo; 256 257 SceRemoteStorageStatusReqParams params; 258 reqId = sceRemoteStorageGetStatus(params, outputGetStatus); 259 m_status = e_getStatusInProgress; 260 261 if(reqId >= 0) 262 { 263 app.DebugPrintf("Get Status request sent \n"); 264 return true; 265 } 266 else 267 { 268 app.DebugPrintf("Error sending Get Status request: 0x%x \n", reqId); 269 return false; 270 } 271} 272 273void SonyRemoteStorage_Orbis::abort() 274{ 275 SceRemoteStorageAbortReqParams params; 276 params.requestId = reqId; 277 int ret = sceRemoteStorageAbort(params); 278 279 if(ret >= 0) 280 { 281 app.DebugPrintf("Abort request done \n"); 282 } 283 else 284 { 285 app.DebugPrintf("Error in Abort request: 0x%x \n", ret); 286 } 287} 288 289 290bool SonyRemoteStorage_Orbis::setData( PSAVE_INFO info, CallbackFunc cb, LPVOID lpParam ) 291{ 292 assert(0); 293 return false; 294 295// m_callbackFunc = cb; 296// m_callbackParam = lpParam; 297// 298// strcpy(m_saveFilename, savePath); 299// strcpy(m_saveFileDesc, saveDesc); 300// m_status = e_setDataInProgress; 301// 302// 303// SceRemoteStorageSetDataReqParams params; 304// params.visibility = PUBLIC_READ_WRITE; 305// strcpy(params.pathLocation, m_saveFilename); 306// sprintf(params.fileName, "/%s/GAMEDATA", m_saveFilename); 307// // strcpy(params.fileName, "/test/small.txt"); 308// strcpy(params.fileDescription, m_saveFileDesc); 309// strcpy(params.ps3DataFilename, "GAMEDATA"); 310// 311// params.ps3FileType = CELL_SAVEDATA_FILETYPE_NORMALFILE; 312// memcpy(params.secureFileId, m_secureFileId, CELL_SAVEDATA_SECUREFILEID_SIZE); 313// 314// 315// 316// reqId = sceRemoteStorageSetData(params); 317// 318// app.DebugPrintf("\n*******************************\n"); 319// if(reqId >= 0) 320// { 321// app.DebugPrintf("Set Data request sent \n"); 322// return true; 323// } 324// else 325// { 326// app.DebugPrintf("Error sending Set Data request: 0x%x \n", reqId); 327// return false; 328// } 329} 330 331bool SonyRemoteStorage_Orbis::getData( const char* remotePath, const char* localPath, CallbackFunc cb, LPVOID lpParam ) 332{ 333 m_callbackFunc = cb; 334 m_callbackParam = lpParam; 335 336 if(StorageManager.SaveGameDirMountExisting(m_mountPoint) == false) 337 { 338 app.DebugPrintf("Error mounting save dir \n"); 339 m_mountPoint[0] = 0; 340 return false; 341 } 342 343 SceRemoteStorageGetDataReqParams params; 344 sprintf(params.pathLocation, "%s/GAMEDATA", m_mountPoint); 345 // strcpy(params.fileName, "/test/small.txt"); 346 strcpy(params.fileName, remotePath); 347 SceRemoteStorageData s_getDataOutput; 348 reqId = sceRemoteStorageGetData(params, &s_getDataOutput); 349 350 app.DebugPrintf("\n*******************************\n"); 351 if(reqId >= 0) 352 { 353 app.DebugPrintf("Get Data request sent \n"); 354 return true; 355 } 356 else 357 { 358 app.DebugPrintf("Error sending Get Data request: 0x%x \n", reqId); 359 return false; 360 } 361} 362 363void SonyRemoteStorage_Orbis::runCallback() 364{ 365 assert(m_callbackFunc); 366 if(m_callbackFunc) 367 { 368 m_callbackFunc(m_callbackParam, m_status, m_lastErrorCode); 369 } 370 m_lastErrorCode = SCE_OK; 371}