the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 1705 lines 51 kB view raw
1 2#include "stdafx.h" 3#include "..\Common\Consoles_App.h" 4#include "..\User.h" 5#include "..\..\Minecraft.Client\Minecraft.h" 6#include "..\..\Minecraft.Client\MinecraftServer.h" 7#include "..\..\Minecraft.Client\PlayerList.h" 8#include "..\..\Minecraft.Client\ServerPlayer.h" 9#include "..\..\Minecraft.World\Level.h" 10#include "..\..\Minecraft.World\LevelSettings.h" 11#include "..\..\Minecraft.World\BiomeSource.h" 12#include "..\..\Minecraft.World\LevelType.h" 13#include "..\..\Minecraft.World\StringHelpers.h" 14#include "PSVita\Network\SonyRemoteStorage_Vita.h" 15#include "PSVita\Network\SonyCommerce_Vita.h" 16#include "..\..\Common\Network\Sony\SonyRemoteStorage.h" 17#include "PSVita/Network/PSVita_NPToolkit.h" 18#include <message_dialog.h> 19#include <savedata_dialog.h> 20#include "Common\UI\UI.h" 21#include "PSVita\PSVitaExtras\PSVitaStrings.h" 22 23#define VITA_COMMERCE_ENABLED 24CConsoleMinecraftApp app; 25 26CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp() 27{ 28 memset(&m_ThumbnailBuffer,0,sizeof(ImageFileBuffer)); 29 memset(&m_SaveImageBuffer,0,sizeof(ImageFileBuffer)); 30 memset(&ProductCodes,0,sizeof(PRODUCTCODES)); 31 32 m_bVoiceChatAndUGCRestricted=false; 33 m_bDisplayFullVersionPurchase=false; 34 35 m_ProductListA=NULL; 36 37 m_pRemoteStorage = new SonyRemoteStorage_Vita; 38 39 m_bSaveIncompleteDialogRunning = false; 40 m_bSaveDataDeleteDialogState = eSaveDataDeleteState_idle; 41 42 m_pSaveToDelete = NULL; 43 m_pCheckoutProductInfo = NULL; 44} 45 46void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId) 47{ 48 ProfileManager.SetRichPresenceContextValue(iPad,CONTEXT_GAME_STATE,contextId); 49} 50 51char *CConsoleMinecraftApp::GetProductCode() 52{ 53 return ProductCodes.chProductCode; 54} 55char *CConsoleMinecraftApp::GetSaveFolderPrefix() 56{ 57 return ProductCodes.chSaveFolderPrefix; 58} 59char *CConsoleMinecraftApp::GetCommerceCategory() 60{ 61 return ProductCodes.chCommerceCategory; 62} 63char *CConsoleMinecraftApp::GetTexturePacksCategoryID() 64{ 65 return NULL; // ProductCodes.chTexturePackID; 66} 67char *CConsoleMinecraftApp::GetUpgradeKey() 68{ 69 return ProductCodes.chUpgradeKey; 70} 71EProductSKU CConsoleMinecraftApp::GetProductSKU() 72{ 73 return ProductCodes.eProductSKU; 74} 75bool CConsoleMinecraftApp::IsJapaneseSKU() 76{ 77 return ProductCodes.eProductSKU == e_sku_SCEJ; 78 79} 80bool CConsoleMinecraftApp::IsEuropeanSKU() 81{ 82 return ProductCodes.eProductSKU == e_sku_SCEE; 83 84} 85bool CConsoleMinecraftApp::IsAmericanSKU() 86{ 87 return ProductCodes.eProductSKU == e_sku_SCEA; 88 89} 90// char *CConsoleMinecraftApp::GetSKUPostfix() 91// { 92// return ProductCodes.chSkuPostfix; 93// } 94 95SONYDLC *CConsoleMinecraftApp::GetSONYDLCInfo(char *pchTitle) 96{ 97 wstring wstrTemp=convStringToWstring(pchTitle); 98 99 AUTO_VAR(it, m_SONYDLCMap.find(wstrTemp)); 100 if(it == m_SONYDLCMap.end()) 101 { 102 app.DebugPrintf("Couldn't find DLC info for %s\n", pchTitle); 103 assert(0); 104 return NULL; 105 } 106 return it->second; 107 108 /*wstring wstrTemp=convStringToWstring(pchTitle); 109 SONYDLC *pTemp=m_SONYDLCMap.at(wstrTemp); 110 111 return pTemp;*/ 112} 113 114SONYDLC *CConsoleMinecraftApp::GetSONYDLCInfo(int iTexturePackID) 115{ 116 for ( AUTO_VAR(it, m_SONYDLCMap.begin()); it != m_SONYDLCMap.end(); ++it ) 117 { 118 if(it->second->iConfig == iTexturePackID) 119 return it->second; 120 } 121 return NULL; 122} 123 124 125#define WRAPPED_READFILE(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped) {if(ReadFile(hFile,lpBuffer,nNumberOfBytesToRead,lpNumberOfBytesRead,lpOverlapped)==FALSE) { return FALSE;}} 126BOOL CConsoleMinecraftApp::ReadProductCodes() 127{ 128 char chDLCTitle[64]; 129 130 // 4J-PB - Read the file containing the product codes. This will be different for the SCEE/SCEA/SCEJ builds 131 HANDLE file = CreateFile("PSVita/PSVitaProductCodes.bin", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 132 if( file == INVALID_HANDLE_VALUE ) 133 { 134 DWORD error = GetLastError(); 135 app.DebugPrintf("Failed to open ProductCodes.bin with error code %d (%x)\n", error, error); 136 return FALSE; 137 } 138 139 DWORD dwHigh=0; 140 DWORD dwFileSize = GetFileSize(file,&dwHigh); 141 142 if(dwFileSize!=0) 143 { 144 DWORD bytesRead; 145 146 WRAPPED_READFILE(file,ProductCodes.chProductCode,PRODUCT_CODE_SIZE,&bytesRead,NULL); 147 WRAPPED_READFILE(file,ProductCodes.chSaveFolderPrefix,SAVEFOLDERPREFIX_SIZE,&bytesRead,NULL); 148 //WRAPPED_READFILE(file,ProductCodes.chDiscSaveFolderPrefix,SAVEFOLDERPREFIX_SIZE,&bytesRead,NULL); 149 WRAPPED_READFILE(file,ProductCodes.chCommerceCategory,COMMERCE_CATEGORY_SIZE,&bytesRead,NULL); 150 //WRAPPED_READFILE(file,ProductCodes.chTexturePackID,SCE_NP_COMMERCE2_CATEGORY_ID_LEN,&bytesRead,NULL); // TODO 151 WRAPPED_READFILE(file,ProductCodes.chUpgradeKey,UPGRADE_KEY_SIZE,&bytesRead,NULL); 152 //WRAPPED_READFILE(file,ProductCodes.chSkuPostfix,SKU_POSTFIX_SIZE,&bytesRead,NULL); 153 154 app.DebugPrintf("ProductCodes.chProductCode %s\n",ProductCodes.chProductCode); 155 app.DebugPrintf("ProductCodes.chSaveFolderPrefix %s\n",ProductCodes.chSaveFolderPrefix); 156 //app.DebugPrintf("ProductCodes.chDiscSaveFolderPrefix %s\n",ProductCodes.chDiscSaveFolderPrefix); 157 app.DebugPrintf("ProductCodes.chCommerceCategory %s\n",ProductCodes.chCommerceCategory); 158 //app.DebugPrintf("ProductCodes.chTexturePackID %s\n",ProductCodes.chTexturePackID); 159 app.DebugPrintf("ProductCodes.chUpgradeKey %s\n",ProductCodes.chUpgradeKey); 160 //app.DebugPrintf("ProductCodes.chSkuPostfix %s\n",ProductCodes.chSkuPostfix); 161 162 // DLC 163 unsigned int uiDLC; 164 WRAPPED_READFILE(file,&uiDLC,sizeof(int),&bytesRead,NULL); 165 166 for(unsigned int i=0;i<uiDLC;i++) 167 { 168 SONYDLC *pDLCInfo= new SONYDLC; 169 memset(pDLCInfo,0,sizeof(SONYDLC)); 170 memset(chDLCTitle,0,64); 171 172 unsigned int uiVal; 173 WRAPPED_READFILE(file,&uiVal,sizeof(int),&bytesRead,NULL); 174 WRAPPED_READFILE(file,pDLCInfo->chDLCKeyname,sizeof(char)*uiVal,&bytesRead,NULL); 175 176 WRAPPED_READFILE(file,&uiVal,sizeof(int),&bytesRead,NULL); 177 WRAPPED_READFILE(file,chDLCTitle,sizeof(char)*uiVal,&bytesRead,NULL); 178 app.DebugPrintf("DLC title %s\n",chDLCTitle); 179 180 WRAPPED_READFILE(file,&pDLCInfo->eDLCType,sizeof(int),&bytesRead,NULL); 181 WRAPPED_READFILE(file,&pDLCInfo->iFirstSkin,sizeof(int),&bytesRead,NULL); 182 WRAPPED_READFILE(file,&pDLCInfo->iConfig,sizeof(int),&bytesRead,NULL); 183 184 // push this into a vector 185 186 wstring wstrTemp=convStringToWstring(chDLCTitle); 187 m_SONYDLCMap[wstrTemp]=pDLCInfo; 188 } 189 CloseHandle(file); 190 } 191 192 if(strcmp(ProductCodes.chProductCode, "PCSB00560") == 0) 193 ProductCodes.eProductSKU = e_sku_SCEE; 194 else if(strcmp(ProductCodes.chProductCode, "PCSE00491") == 0) 195 ProductCodes.eProductSKU = e_sku_SCEA; 196 else if(strcmp(ProductCodes.chProductCode, "PCSG00302") == 0) 197 ProductCodes.eProductSKU = e_sku_SCEJ; 198 else 199 { 200 // unknown product ID 201 assert(0); 202 } 203 204 return TRUE; 205} 206 207void CConsoleMinecraftApp::StoreLaunchData() 208{ 209} 210void CConsoleMinecraftApp::ExitGame() 211{ 212} 213void CConsoleMinecraftApp::FatalLoadError() 214{ 215 assert(0); 216} 217 218void CConsoleMinecraftApp::CaptureSaveThumbnail() 219{ 220 RenderManager.CaptureThumbnail(&m_ThumbnailBuffer); 221} 222void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *ppbThumbnailData,DWORD *pdwThumbnailSize,PBYTE *ppbDataImage,DWORD *pdwSizeImage) 223{ 224 // on a save caused by a create world, the thumbnail capture won't have happened 225 if(m_ThumbnailBuffer.Allocated()) 226 { 227 if( ppbThumbnailData ) 228 { 229 *ppbThumbnailData= new BYTE [m_ThumbnailBuffer.GetBufferSize()]; 230 *pdwThumbnailSize=m_ThumbnailBuffer.GetBufferSize(); 231 memcpy(*ppbThumbnailData,m_ThumbnailBuffer.GetBufferPointer(),*pdwThumbnailSize); 232 } 233 m_ThumbnailBuffer.Release(); 234 } 235 else 236 { 237 if( ppbThumbnailData ) 238 { 239 // use the default image 240 StorageManager.GetDefaultSaveThumbnail(ppbThumbnailData,pdwThumbnailSize); 241 } 242 } 243 244 if(m_SaveImageBuffer.Allocated()) 245 { 246 if( ppbDataImage ) 247 { 248 *ppbDataImage= new BYTE [m_SaveImageBuffer.GetBufferSize()]; 249 *pdwSizeImage=m_SaveImageBuffer.GetBufferSize(); 250 memcpy(*ppbDataImage,m_SaveImageBuffer.GetBufferPointer(),*pdwSizeImage); 251 } 252 m_SaveImageBuffer.Release(); 253 } 254 else 255 { 256 if( ppbDataImage ) 257 { 258 // use the default image 259 StorageManager.GetDefaultSaveImage(ppbDataImage,pdwSizeImage); 260 } 261 } 262} 263 264void CConsoleMinecraftApp::ReleaseSaveThumbnail() 265{ 266 267} 268 269void CConsoleMinecraftApp::GetScreenshot(int iPad,PBYTE *pbData,DWORD *pdwSize) 270{ 271 272} 273 274int CConsoleMinecraftApp::GetLocalTMSFileIndex(WCHAR *wchTMSFile,bool bFilenameIncludesExtension,eFileExtensionType eEXT) 275{ 276 return -1; 277} 278 279 280int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile) 281{ 282 return -1; 283} 284 285int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile, eFileExtensionType eExt) 286{ 287 return -1; 288} 289 290void CConsoleMinecraftApp::FreeLocalTMSFiles(eTMSFileType eType) 291{ 292 293} 294 295void CConsoleMinecraftApp::TemporaryCreateGameStart() 296{ 297 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_Main::OnInit 298 299 app.setLevelGenerationOptions(NULL); 300 301 // From CScene_Main::RunPlayGame 302 Minecraft *pMinecraft=Minecraft::GetInstance(); 303 app.ReleaseSaveThumbnail(); 304 ProfileManager.SetLockedProfile(0); 305 pMinecraft->user->name = L"Vita"; 306 app.ApplyGameSettingsChanged(0); 307 308 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit 309 MinecraftServer::resetFlags(); 310 311 // From CScene_MultiGameJoinLoad::OnNotifyPressEx 312 app.SetTutorialMode( false ); 313 app.SetCorruptSaveDeleted(false); 314 315 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameCreate::CreateGame 316 317 app.ClearTerrainFeaturePosition(); 318 wstring wWorldName = L"TestWorld"; 319 320 bool isFlat = false; 321 __int64 seedValue = 0;//BiomeSource::findSeed(isFlat?LevelType::lvl_flat:LevelType::lvl_normal); // 4J - was (new Random())->nextLong() - now trying to actually find a seed to suit our requirements 322 323 NetworkGameInitData *param = new NetworkGameInitData(); 324 param->seed = seedValue; 325 param->saveData = NULL; 326 327 g_NetworkManager.HostGame(0,false,true,MINECRAFT_NET_MAX_PLAYERS,0); 328 329 app.SetGameHostOption(eGameHostOption_Difficulty,0); 330 app.SetGameHostOption(eGameHostOption_FriendsOfFriends,0); 331 app.SetGameHostOption(eGameHostOption_Gamertags,1); 332 app.SetGameHostOption(eGameHostOption_BedrockFog,1); 333 334 app.SetGameHostOption(eGameHostOption_GameType,GameType::CREATIVE->getId()); 335 app.SetGameHostOption(eGameHostOption_LevelType, 0 ); 336 app.SetGameHostOption(eGameHostOption_Structures, 1 ); 337 app.SetGameHostOption(eGameHostOption_BonusChest, 0 ); 338 339 app.SetGameHostOption(eGameHostOption_PvP, 1); 340 app.SetGameHostOption(eGameHostOption_TrustPlayers, 1 ); 341 app.SetGameHostOption(eGameHostOption_FireSpreads, 1 ); 342 app.SetGameHostOption(eGameHostOption_TNT, 1 ); 343 app.SetGameHostOption(eGameHostOption_HostCanFly, 1); 344 app.SetGameHostOption(eGameHostOption_HostCanChangeHunger, 1); 345 app.SetGameHostOption(eGameHostOption_HostCanBeInvisible, 1 ); 346 347 app.SetGameHostOption(eGameHostOption_MobGriefing, 1 ); 348 app.SetGameHostOption(eGameHostOption_KeepInventory, 0 ); 349 app.SetGameHostOption(eGameHostOption_DoMobSpawning, 1 ); 350 app.SetGameHostOption(eGameHostOption_DoMobLoot, 1 ); 351 app.SetGameHostOption(eGameHostOption_DoTileDrops, 1 ); 352 app.SetGameHostOption(eGameHostOption_NaturalRegeneration, 1 ); 353 app.SetGameHostOption(eGameHostOption_DoDaylightCycle, 1 ); 354 355 param->settings = app.GetGameHostOption( eGameHostOption_All ); 356 357 g_NetworkManager.FakeLocalPlayerJoined(); 358 359 LoadingInputParams *loadingParams = new LoadingInputParams(); 360 loadingParams->func = &CGameNetworkManager::RunNetworkGameThreadProc; 361 loadingParams->lpParam = (LPVOID)param; 362 363 // Reset the autosave time 364 app.SetAutosaveTimerTime(); 365 366 C4JThread* thread = new C4JThread(loadingParams->func, loadingParams->lpParam, "RunNetworkGame"); 367 thread->Run(); 368} 369 370 371// COMMERCE / DLC 372 373void CConsoleMinecraftApp::CommerceInit() 374{ 375 m_bCommerceCategoriesRetrieved=false; 376 m_bCommerceProductListRetrieved=false; 377 m_bCommerceInitialised=false; 378 m_bProductListAdditionalDetailsRetrieved=false; 379#ifdef VITA_COMMERCE_ENABLED 380 m_pCommerce= new SonyCommerce_Vita; 381#endif 382 m_eCommerce_State=eCommerce_State_Offline; // can only init when we have a PSN user 383 m_ProductListRetrievedC=0; 384 m_ProductListAdditionalDetailsC=0; 385 m_ProductListCategoriesC=0; 386 m_iCurrentCategory=0; 387 m_iCurrentProduct=0; 388 memset(m_pchSkuID,0,48); 389} 390 391void CConsoleMinecraftApp::CommerceTick() 392{ 393#ifdef VITA_COMMERCE_ENABLED 394 // only tick this if the primary user is signed in to the PSN 395 if(ProfileManager.IsSignedInLive(0)) 396 { 397 switch(m_eCommerce_State) 398 { 399 case eCommerce_State_Offline: 400 m_eCommerce_State=eCommerce_State_Init; 401 break; 402 case eCommerce_State_Init: 403 m_eCommerce_State=eCommerce_State_Init_Pending; 404 m_pCommerce->CreateSession(&CConsoleMinecraftApp::CommerceInitCallback, this); 405 break; 406 case eCommerce_State_GetCategories: 407 m_eCommerce_State=eCommerce_State_GetCategories_Pending; 408 // get all categories for this product 409 m_pCommerce->GetCategoryInfo(&CConsoleMinecraftApp::CommerceGetCategoriesCallback, this, &m_CategoryInfo,app.GetCommerceCategory()); 410 411 break; 412 case eCommerce_State_GetProductList: 413 { 414 m_eCommerce_State=eCommerce_State_GetProductList_Pending; 415 SonyCommerce::CategoryInfo *pCategories=app.GetCategoryInfo(); 416 std::list<SonyCommerce::CategoryInfoSub>::iterator iter = pCategories->subCategories.begin(); 417 418 for(int i=0;i<m_ProductListRetrievedC;i++) 419 { 420 iter++; 421 } 422 SonyCommerce::CategoryInfoSub category = (SonyCommerce::CategoryInfoSub)(*iter); 423 424 m_pCommerce->GetProductList(&CConsoleMinecraftApp::CommerceGetProductListCallback, this, &m_ProductListA[m_ProductListRetrievedC],category.categoryId); 425 } 426 427 break; 428 case eCommerce_State_AddProductInfoDetailed: 429 { 430 m_eCommerce_State=eCommerce_State_AddProductInfoDetailed_Pending; 431 432 // for each of the products in the categories, get the detailed info. We really only need the long description and price info. 433 SonyCommerce::CategoryInfo *pCategories=app.GetCategoryInfo(); 434 std::list<SonyCommerce::CategoryInfoSub>::iterator iter = pCategories->subCategories.begin(); 435 for(int i=0;i<m_iCurrentCategory;i++) 436 { 437 iter++; 438 } 439 440 SonyCommerce::CategoryInfoSub category = (SonyCommerce::CategoryInfoSub)(*iter); 441 std::vector<SonyCommerce::ProductInfo>*pvProductList=&m_ProductListA[m_iCurrentCategory]; 442 443 // 4J-PB - there may be no products in the category 444 if(pvProductList->size()==0) 445 { 446 CConsoleMinecraftApp::CommerceAddDetailedProductInfoCallback(this,0); 447 } 448 else 449 { 450 assert(pvProductList->size() > m_iCurrentProduct); 451 SonyCommerce::ProductInfo *pProductInfo=&(pvProductList->at(m_iCurrentProduct)); 452 m_pCommerce->AddDetailedProductInfo(&CConsoleMinecraftApp::CommerceAddDetailedProductInfoCallback, this, pProductInfo,pProductInfo->productId,category.categoryId); 453 } 454 } 455 break; 456 case eCommerce_State_Checkout: 457 m_pCommerce->CreateSession(&CConsoleMinecraftApp::CheckoutSessionStartedCallback, this); 458 m_eCommerce_State=eCommerce_State_Checkout_WaitingForSession; 459 break; 460 case eCommerce_State_Checkout_SessionStarted: 461 m_eCommerce_State=eCommerce_State_Checkout_Pending; 462 ((SonyCommerce_Vita*)m_pCommerce)->Checkout(&CConsoleMinecraftApp::CommerceCheckoutCallback, this,m_pCheckoutProductInfo); 463 break; 464 465 case eCommerce_State_RegisterDLC: 466 { 467 m_eCommerce_State=eCommerce_State_Online; 468 // register the DLC info 469 SonyCommerce::CategoryInfo *pCategories=app.GetCategoryInfo(); 470 std::list<SonyCommerce::CategoryInfoSub>::iterator iter = pCategories->subCategories.begin(); 471 for(int i=0;i<m_iCurrentCategory;i++) 472 { 473 std::vector<SonyCommerce::ProductInfo>*pvProductList=&m_ProductListA[i]; 474 for(int j=0;j<pvProductList->size();j++) 475 { 476 SonyCommerce::ProductInfo *pProductInfo=&(pvProductList->at(j)); 477 // just want the final 16 characters of the product id 478 RegisterDLCData(&pProductInfo->productId[20],0,pProductInfo->imageUrl); 479 } 480 iter++; 481 } 482 } 483 break; 484 485 case eCommerce_State_DownloadAlreadyPurchased: 486 m_pCommerce->CreateSession(&CConsoleMinecraftApp::DownloadAlreadyPurchasedSessionStartedCallback, this); 487 m_eCommerce_State=eCommerce_State_DownloadAlreadyPurchased_WaitingForSession; 488 break; 489 case eCommerce_State_DownloadAlreadyPurchased_SessionStarted: 490 m_eCommerce_State=eCommerce_State_DownloadAlreadyPurchased_Pending; 491 m_pCommerce->DownloadAlreadyPurchased(&CConsoleMinecraftApp::CommerceCheckoutCallback, this,m_pchSkuID); 492 break; 493 494 495 case eCommerce_State_UpgradeTrial: 496 m_pCommerce->CreateSession(&CConsoleMinecraftApp::UpgradeTrialSessionStartedCallback, this); 497 m_eCommerce_State=eCommerce_State_UpgradeTrial_WaitingForSession; 498 break; 499 case eCommerce_State_UpgradeTrial_SessionStarted: 500 m_pCommerce->UpgradeTrial(&CConsoleMinecraftApp::CommerceCheckoutCallback, this); 501 m_eCommerce_State=eCommerce_State_UpgradeTrial_Pending; 502 break; 503 } 504 505 // 4J-PB - bit of a hack to display the full version purchase after signing in during a trial trophy popup 506 if(m_bDisplayFullVersionPurchase && ((m_eCommerce_State==eCommerce_State_Online) || (m_eCommerce_State==eCommerce_State_Error))) 507 { 508 m_bDisplayFullVersionPurchase=false; 509 ProfileManager.DisplayFullVersionPurchase(false,ProfileManager.GetPrimaryPad(),eSen_UpsellID_Full_Version_Of_Game); 510 } 511 } 512 else 513 { 514 // was the primary player signed in and is now signed out? 515 if(m_eCommerce_State!=eCommerce_State_Offline) 516 { 517 m_eCommerce_State=eCommerce_State_Offline; 518 519 // clear out all the product info 520 ClearCommerceDetails(); 521 522 m_pCommerce->CloseSession(); 523 } 524 } 525#endif // VITA_COMMERCE_ENABLED 526} 527 528bool CConsoleMinecraftApp::GetCommerceCategoriesRetrieved() 529{ 530 return m_bCommerceCategoriesRetrieved; 531} 532 533bool CConsoleMinecraftApp::GetCommerceProductListRetrieved() 534{ 535 return m_bCommerceProductListRetrieved; 536} 537 538bool CConsoleMinecraftApp::GetCommerceProductListInfoRetrieved() 539{ 540 return m_bProductListAdditionalDetailsRetrieved; 541} 542 543#ifdef VITA_COMMERCE_ENABLED 544SonyCommerce::CategoryInfo *CConsoleMinecraftApp::GetCategoryInfo() 545{ 546 if(m_bCommerceCategoriesRetrieved==false) 547 { 548 return NULL; 549 } 550 551 return &m_CategoryInfo; 552} 553#endif 554 555void CConsoleMinecraftApp::ClearCommerceDetails() 556{ 557#ifdef VITA_COMMERCE_ENABLED 558 for(int i=0;i<m_ProductListCategoriesC;i++) 559 { 560 std::vector<SonyCommerce::ProductInfo>* pProductList=&m_ProductListA[i]; 561 pProductList->clear(); 562 } 563 564 if(m_ProductListA!=NULL) 565 { 566 delete [] m_ProductListA; 567 m_ProductListA=NULL; 568 } 569 570 m_ProductListRetrievedC=0; 571 m_ProductListAdditionalDetailsC=0; 572 m_ProductListCategoriesC=0; 573 m_iCurrentCategory=0; 574 m_iCurrentProduct=0; 575 m_bCommerceCategoriesRetrieved=false; 576 m_bCommerceInitialised=false; 577 m_bCommerceProductListRetrieved=false; 578 m_bProductListAdditionalDetailsRetrieved=false; 579 580 m_CategoryInfo.subCategories.clear(); 581#endif // #ifdef VITA_COMMERCE_ENABLED 582 583} 584 585 586void CConsoleMinecraftApp::GetDLCSkuIDFromProductList(char * pchDLCProductID, char *pchSkuID) 587{ 588#ifdef VITA_COMMERCE_ENABLED 589 590 // find the DLC 591 for(int i=0;i<m_ProductListCategoriesC;i++) 592 { 593 for(int j=0;j<m_ProductListA[i].size();j++) 594 { 595 std::vector<SonyCommerce::ProductInfo>* pProductList=&m_ProductListA[i]; 596 AUTO_VAR(itEnd, pProductList->end()); 597 598 for (AUTO_VAR(it, pProductList->begin()); it != itEnd; it++) 599 { 600 SonyCommerce::ProductInfo Info=*it; 601 if(strcmp(pchDLCProductID,Info.productId)==0) 602 { 603 memcpy(pchSkuID,Info.skuId,SCE_NP_COMMERCE2_SKU_ID_LEN); 604 return; 605 } 606 } 607 } 608 } 609 return; 610#endif // #ifdef VITA_COMMERCE_ENABLED 611 612} 613 614void CConsoleMinecraftApp::Checkout(char *pchSkuID) 615{ 616 SonyCommerce::ProductInfo* productInfo = NULL; 617 618 for(int i=0;i<m_ProductListCategoriesC;i++) 619 { 620 for(int j=0;j<m_ProductListA[i].size();j++) 621 { 622 std::vector<SonyCommerce::ProductInfo>* pProductList=&m_ProductListA[i]; 623 AUTO_VAR(itEnd, pProductList->end()); 624 625 for (AUTO_VAR(it, pProductList->begin()); it != itEnd; it++) 626 { 627 SonyCommerce::ProductInfo Info=*it; 628 if(strcmp(pchSkuID,Info.skuId)==0) 629 { 630 productInfo = &(*it); 631 break; 632 } 633 } 634 } 635 } 636 637 if(productInfo) 638 { 639 if(m_eCommerce_State==eCommerce_State_Online) 640 { 641 strcpy(m_pchSkuID,productInfo->skuId); 642 m_pCheckoutProductInfo = productInfo; 643 m_eCommerce_State=eCommerce_State_Checkout; 644 } 645 } 646 else 647 { 648 assert(0); 649 } 650} 651 652void CConsoleMinecraftApp::DownloadAlreadyPurchased(char *pchSkuID) 653{ 654 if(m_eCommerce_State==eCommerce_State_Online) 655 { 656 strcpy(m_pchSkuID,pchSkuID); 657 m_eCommerce_State=eCommerce_State_DownloadAlreadyPurchased; 658 } 659} 660 661bool CConsoleMinecraftApp::UpgradeTrial() 662{ 663 if(m_eCommerce_State==eCommerce_State_Online) 664 { 665 m_eCommerce_State=eCommerce_State_UpgradeTrial; 666 return true; 667 } 668 else if(m_eCommerce_State==eCommerce_State_Error) 669 { 670 UINT uiIDA[1]; 671 uiIDA[0]=IDS_CONFIRM_OK; 672 C4JStorage::EMessageResult result = ui.RequestErrorMessage( IDS_PRO_UNLOCKGAME_TITLE, IDS_NO_DLCOFFERS, uiIDA,1,ProfileManager.GetPrimaryPad()); 673 return true; 674 } 675 else 676 { 677 // commerce is busy 678 return false; 679 } 680} 681 682#ifdef VITA_COMMERCE_ENABLED 683std::vector<SonyCommerce::ProductInfo>* CConsoleMinecraftApp::GetProductList(int iIndex) 684{ 685 if((m_bCommerceProductListRetrieved==false) || (m_bProductListAdditionalDetailsRetrieved==false) ) 686 { 687 return NULL; 688 } 689 690 return &m_ProductListA[iIndex]; 691} 692#endif // #ifdef VITA_COMMERCE_ENABLED 693 694bool CConsoleMinecraftApp::DLCAlreadyPurchased(char *pchTitle) 695{ 696#ifdef VITA_COMMERCE_ENABLED 697 // find the DLC 698 for(int i=0;i<m_ProductListCategoriesC;i++) 699 { 700 for(int j=0;j<m_ProductListA[i].size();j++) 701 { 702 std::vector<SonyCommerce::ProductInfo>* pProductList=&m_ProductListA[i]; 703 AUTO_VAR(itEnd, pProductList->end()); 704 705 for (AUTO_VAR(it, pProductList->begin()); it != itEnd; it++) 706 { 707 SonyCommerce::ProductInfo Info=*it; 708 if(strcmp(pchTitle,Info.skuId)==0) 709 { 710 if(Info.purchasabilityFlag==SCE_TOOLKIT_NP_COMMERCE_NOT_PURCHASED) 711 { 712 return false; 713 } 714 else 715 { 716 return true; 717 } 718 } 719 } 720 } 721 } 722#endif //#ifdef VITA_COMMERCE_ENABLED 723 return false; 724} 725 726 727 728//////////////////// 729// Commerce callbacks 730///////////////////// 731void CConsoleMinecraftApp::CommerceInitCallback(LPVOID lpParam,int err) 732{ 733 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 734 735 if(err==0) 736 { 737 pClass->m_eCommerce_State=eCommerce_State_GetCategories; 738 } 739 else 740 { 741 pClass->m_eCommerce_State=eCommerce_State_Error; 742 pClass->m_ProductListCategoriesC=0; 743 pClass->m_bCommerceCategoriesRetrieved=true; 744 } 745} 746 747 748void CConsoleMinecraftApp::CommerceGetCategoriesCallback(LPVOID lpParam,int err) 749{ 750#ifdef VITA_COMMERCE_ENABLED 751 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 752 753 if(err==0) 754 { 755 pClass->m_ProductListCategoriesC=pClass->m_CategoryInfo.countOfSubCategories; 756 // allocate the memory for the product info for each categories 757 if(pClass->m_CategoryInfo.countOfSubCategories>0) 758 { 759 pClass->m_ProductListA = (std::vector<SonyCommerce::ProductInfo> *) new std::vector<SonyCommerce::ProductInfo> [pClass->m_CategoryInfo.countOfSubCategories]; 760 pClass->m_eCommerce_State=eCommerce_State_GetProductList; 761 } 762 else 763 { 764 pClass->m_eCommerce_State=eCommerce_State_Online; 765 } 766 } 767 else 768 { 769 pClass->m_ProductListCategoriesC=0; 770 pClass->m_eCommerce_State=eCommerce_State_Error; 771 } 772 773 pClass->m_bCommerceCategoriesRetrieved=true; 774#endif // #ifdef VITA_COMMERCE_ENABLED 775 776} 777 778void CConsoleMinecraftApp::CommerceGetProductListCallback(LPVOID lpParam,int err) 779{ 780 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 781 782 if(err==0) 783 { 784 pClass->m_ProductListRetrievedC++; 785 // if we have more info to get, keep going with the next call 786 if(pClass->m_ProductListRetrievedC==pClass->m_CategoryInfo.countOfSubCategories) 787 { 788 // we're done, so now retrieve the additional product details for each product 789 pClass->m_eCommerce_State=eCommerce_State_AddProductInfoDetailed; 790 pClass->m_bCommerceProductListRetrieved=true; 791 } 792 else 793 { 794 pClass->m_eCommerce_State=eCommerce_State_GetProductList; 795 } 796 } 797 else 798 { 799 pClass->m_eCommerce_State=eCommerce_State_Error; 800 pClass->m_bCommerceProductListRetrieved=true; 801 } 802} 803 804// void CConsoleMinecraftApp::CommerceGetDetailedProductInfoCallback(LPVOID lpParam,int err) 805// { 806// CConsoleMinecraftApp *pScene=(CConsoleMinecraftApp *)lpParam; 807// 808// if(err==0) 809// { 810// pScene->m_eCommerce_State=eCommerce_State_Idle; 811// //pScene->m_bCommerceProductListRetrieved=true; 812// } 813// //printf("Callback hit, error 0x%08x\n", err); 814// 815// } 816 817void CConsoleMinecraftApp::CommerceAddDetailedProductInfoCallback(LPVOID lpParam,int err) 818{ 819#ifdef VITA_COMMERCE_ENABLED 820 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 821 822 if(err==0) 823 { 824 // increment the current product counter. When this gets to the end of the products, move to the next category 825 pClass->m_iCurrentProduct++; 826 827 std::vector<SonyCommerce::ProductInfo>*pvProductList=&pClass->m_ProductListA[pClass->m_iCurrentCategory]; 828 829 // if there are no more products in this category, move to the next category (there may be no products in the category) 830 if(pClass->m_iCurrentProduct>=pvProductList->size()) 831 { 832 // MGH - change this to a while loop so we can skip empty categories. 833 do 834 { 835 pClass->m_iCurrentCategory++; 836 }while(pClass->m_ProductListA[pClass->m_iCurrentCategory].size() == 0 && pClass->m_iCurrentCategory<pClass->m_ProductListCategoriesC); 837 838 pClass->m_iCurrentProduct=0; 839 if(pClass->m_iCurrentCategory==pClass->m_ProductListCategoriesC) 840 { 841 // there are no more categories, so we're done 842 pClass->m_eCommerce_State=eCommerce_State_RegisterDLC; 843 pClass->m_bProductListAdditionalDetailsRetrieved=true; 844 } 845 else 846 { 847 // continue with the next category 848 pClass->m_eCommerce_State=eCommerce_State_AddProductInfoDetailed; 849 } 850 } 851 else 852 { 853 // continue with the next product 854 pClass->m_eCommerce_State=eCommerce_State_AddProductInfoDetailed; 855 } 856 } 857 else 858 { 859 pClass->m_eCommerce_State=eCommerce_State_Error; 860 pClass->m_bProductListAdditionalDetailsRetrieved=true; 861 pClass->m_iCurrentProduct=0; 862 pClass->m_iCurrentCategory=0; 863 } 864 865#endif //#ifdef VITA_COMMERCE_ENABLED 866 867} 868 869void CConsoleMinecraftApp::CommerceCheckoutCallback(LPVOID lpParam,int err) 870{ 871 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 872 873 if(err==0) 874 { 875 } 876 pClass->m_eCommerce_State=eCommerce_State_Online; 877} 878 879void CConsoleMinecraftApp::CheckoutSessionStartedCallback(LPVOID lpParam,int err) 880{ 881 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 882 if(err==0) 883 pClass->m_eCommerce_State=eCommerce_State_Checkout_SessionStarted; 884 else 885 pClass->m_eCommerce_State=eCommerce_State_Error; 886} 887 888void CConsoleMinecraftApp::DownloadAlreadyPurchasedSessionStartedCallback(LPVOID lpParam,int err) 889{ 890 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 891 if(err==0) 892 pClass->m_eCommerce_State=eCommerce_State_DownloadAlreadyPurchased_SessionStarted; 893 else 894 pClass->m_eCommerce_State=eCommerce_State_Error; 895} 896 897void CConsoleMinecraftApp::UpgradeTrialSessionStartedCallback(LPVOID lpParam,int err) 898{ 899 CConsoleMinecraftApp *pClass=(CConsoleMinecraftApp *)lpParam; 900 if(err==0) 901 pClass->m_eCommerce_State=eCommerce_State_UpgradeTrial_SessionStarted; 902 else 903 pClass->m_eCommerce_State=eCommerce_State_Error; 904} 905 906 907bool CConsoleMinecraftApp::GetTrialFromName(char *pchDLCName) 908{ 909 if(pchDLCName[0]=='T') 910 { 911 return true; 912 } 913 914 return false; 915} 916 917eDLCContentType CConsoleMinecraftApp::GetDLCTypeFromName(char *pchDLCName) 918{ 919 char chDLCType[3]; 920 921 chDLCType[0]=pchDLCName[1]; 922 chDLCType[1]=pchDLCName[2]; 923 chDLCType[2]=0; 924 925 app.DebugPrintf(6,"DLC - %s\n",pchDLCName); 926 927 if(strcmp(chDLCType,"SP")==0) 928 { 929 return e_DLC_SkinPack; 930 } 931 else if(strcmp(chDLCType,"GP")==0) 932 { 933 return e_DLC_Gamerpics; 934 } 935 else if(strcmp(chDLCType,"TH")==0) 936 { 937 return e_DLC_Themes; 938 } 939 else if(strcmp(chDLCType,"AV")==0) 940 { 941 return e_DLC_AvatarItems; 942 } 943 else if(strcmp(chDLCType,"MP")==0) 944 { 945 return e_DLC_MashupPacks; 946 } 947 else if(strcmp(chDLCType,"TP")==0) 948 { 949 return e_DLC_TexturePacks; 950 } 951 else 952 { 953 return e_DLC_NotDefined; 954 } 955} 956 957int CConsoleMinecraftApp::GetiConfigFromName(char *pchName) 958{ 959 char pchiConfig[5]; 960 int iStrlen=strlen(pchName); 961 // last four character of DLC product name are the iConfig value 962 pchiConfig[0]=pchName[iStrlen-4]; 963 pchiConfig[1]=pchName[iStrlen-3]; 964 pchiConfig[2]=pchName[iStrlen-2]; 965 pchiConfig[3]=pchName[iStrlen-1]; 966 pchiConfig[4]=0; 967 968 return atoi(pchiConfig); 969} 970 971int CConsoleMinecraftApp::GetiFirstSkinFromName(char *pchName) 972{ 973 char pchiFirstSkin[5]; 974 int iStrlen=strlen(pchName); 975 // last four character of DLC product name are the iConfig value 976 // four before that are the first skin id 977 pchiFirstSkin[0]=pchName[iStrlen-8]; 978 pchiFirstSkin[1]=pchName[iStrlen-7]; 979 pchiFirstSkin[2]=pchName[iStrlen-6]; 980 pchiFirstSkin[3]=pchName[iStrlen-5]; 981 pchiFirstSkin[4]=0; 982 983 return atoi(pchiFirstSkin); 984} 985 986// void CConsoleMinecraftApp::SetVoiceChatAndUGCRestricted(bool bRestricted) 987//{ 988// m_bVoiceChatAndUGCRestricted=bRestricted; 989//} 990 991// bool CConsoleMinecraftApp::GetVoiceChatAndUGCRestricted(void) 992//{ 993// return m_bVoiceChatAndUGCRestricted; 994//} 995 996 997int CConsoleMinecraftApp::GetCommerceState() 998{ 999 return m_eCommerce_State; 1000} 1001 1002// bool g_bCalledJoin = false; 1003void CConsoleMinecraftApp::AppEventTick() 1004{ 1005 int res = SCE_OK; 1006 SceAppMgrAppState appStatus; 1007 res = sceAppMgrGetAppState(&appStatus); 1008 1009// if(!g_bCalledJoin) 1010// { 1011// SceAppUtilNpBasicJoinablePresenceParam joinParam = {0}; 1012// strcpy(joinParam.npId.handle.data, "Mark4J"); 1013// SQRNetworkManager_Vita::GetJoinablePresenceDataAndProcess(&joinParam); 1014// } 1015 if(res == SCE_OK) 1016 { 1017 if (appStatus.appEventNum > 0) 1018 { 1019 SceAppUtilAppEventParam eventParam; 1020 memset(&eventParam, 0, sizeof(SceAppUtilAppEventParam)); 1021 res = sceAppUtilReceiveAppEvent(&eventParam); 1022 if (res == SCE_OK) 1023 { 1024 if (SCE_APPUTIL_APPEVENT_TYPE_NP_APP_DATA_MESSAGE == eventParam.type) 1025 { 1026 PSVitaNPToolkit::getMessageData(&eventParam); 1027 // Messaging::Interface::retrieveMessageAttachment(&eventParam,&s_attachment); 1028 } 1029 else if(SCE_APPUTIL_APPEVENT_TYPE_NP_BASIC_JOINABLE_PRESENCE == eventParam.type) 1030 { 1031 PSVitaNPToolkit::getMessageData(&eventParam); 1032 } 1033 else 1034 { 1035 app.DebugPrintf("unknown app event : 0x%08x\n", eventParam.type); 1036 assert(0); 1037 } 1038 } 1039 } 1040 1041 if (appStatus.systemEventNum > 0) 1042 { 1043 SceAppMgrSystemEvent systemEvent; 1044 memset(&systemEvent, 0, sizeof(SceAppMgrSystemEvent)); 1045 res = sceAppMgrReceiveSystemEvent( &systemEvent ); 1046 if (res == SCE_OK) 1047 { 1048 switch(systemEvent.systemEvent) 1049 { 1050 case SCE_APPMGR_SYSTEMEVENT_ON_STORE_PURCHASE: 1051 SonyCommerce_Vita::checkBackgroundDownloadStatus(); 1052 break; 1053 case SCE_APPMGR_SYSTEMEVENT_ON_RESUME: 1054 app.DebugPrintf("SCE_APPMGR_SYSTEMEVENT_ON_RESUME event received\n"); 1055 break; 1056 1057 case SCE_APPMGR_SYSTEMEVENT_ON_NP_MESSAGE_ARRIVED: 1058 app.DebugPrintf("SCE_APPMGR_SYSTEMEVENT_ON_NP_MESSAGE_ARRIVED event received\n"); 1059 break; 1060 case SCE_APPMGR_SYSTEMEVENT_ON_STORE_REDEMPTION: 1061 app.DebugPrintf("SCE_APPMGR_SYSTEMEVENT_ON_STORE_REDEMPTION event received\n"); 1062 break; 1063 default: 1064 app.DebugPrintf("unknown sys event : 0x%08x\n", systemEvent.systemEvent); 1065 assert(0); 1066 break; 1067 } 1068 } 1069 } 1070 } 1071} 1072 1073 1074bool CConsoleMinecraftApp::CheckForEmptyStore(int iPad) 1075{ 1076 SonyCommerce::CategoryInfo *pCategories=app.GetCategoryInfo(); 1077 1078 bool bEmptyStore=true; 1079 if(pCategories!=NULL) 1080 { 1081 if(pCategories->countOfProducts>0) 1082 { 1083 bEmptyStore=false; 1084 } 1085 else 1086 { 1087 for(int i=0;i<pCategories->countOfSubCategories;i++) 1088 { 1089 std::vector<SonyCommerce::ProductInfo>*pvProductInfo=app.GetProductList(i); 1090 if(pvProductInfo->size()>0) 1091 { 1092 bEmptyStore=false; 1093 break; 1094 } 1095 } 1096 } 1097 } 1098 1099 if(bEmptyStore) 1100 { 1101 ProfileManager.ShowSystemMessage( SCE_MSG_DIALOG_SYSMSG_TYPE_TRC_EMPTY_STORE, iPad ); 1102 } 1103 1104 return bEmptyStore; 1105} 1106 1107 1108void printSaveState() 1109{ 1110#ifndef _CONTENT_PACKAGE 1111 string strState; 1112 switch (StorageManager.GetSaveState()) 1113 { 1114 case C4JStorage::ESaveGame_Idle: strState = "ESaveGame_Idle"; break; 1115 case C4JStorage::ESaveGame_Save: strState = "ESaveGame_Save"; break; 1116 case C4JStorage::ESaveGame_SaveCompleteSuccess: strState = "ESaveGame_SaveCompleteSuccess"; break; 1117 case C4JStorage::ESaveGame_SaveCompleteFail: strState = "ESaveGame_SaveCompleteFail"; break; 1118 case C4JStorage::ESaveGame_SaveIncomplete: strState = "ESaveGame_SaveIncomplete"; break; 1119 case C4JStorage::ESaveGame_SaveIncomplete_WaitingOnResponse: strState = "ESaveGame_SaveIncomplete_WaitingOnResponse"; break; 1120 case C4JStorage::ESaveGame_Load: strState = "ESaveGame_Load"; break; 1121 case C4JStorage::ESaveGame_LoadCompleteSuccess: strState = "ESaveGame_LoadCompleteSuccess"; break; 1122 case C4JStorage::ESaveGame_LoadCompleteFail: strState = "ESaveGame_LoadCompleteFail"; break; 1123 case C4JStorage::ESaveGame_Delete: strState = "ESaveGame_Delete"; break; 1124 case C4JStorage::ESaveGame_DeleteSuccess: strState = "ESaveGame_DeleteSuccess"; break; 1125 case C4JStorage::ESaveGame_DeleteFail: strState = "ESaveGame_DeleteFail"; break; 1126 case C4JStorage::ESaveGame_Rename: strState = "ESaveGame_Rename"; break; 1127 case C4JStorage::ESaveGame_RenameSuccess: strState = "ESaveGame_RenameSuccess"; break; 1128 case C4JStorage::ESaveGame_RenameFail: strState = "ESaveGame_RenameFail"; break; 1129 case C4JStorage::ESaveGame_GetSaveThumbnail: strState = "ESaveGame_GetSaveThumbnail"; break; 1130 case C4JStorage::ESaveGame_GetSaveInfo: strState = "ESaveGame_GetSaveInfo"; break; 1131 case C4JStorage::ESaveGame_SaveCache: strState = "ESaveGame_SaveCache"; break; 1132 case C4JStorage::ESaveGame_ReconstructCache: strState = "ESaveGame_ReconstructCache"; break; 1133 } 1134 1135 app.DebugPrintf("[printSaveState] GetSaveState == %s.\n", strState.c_str()); 1136#endif 1137} 1138 1139 1140void CConsoleMinecraftApp::SaveDataTick() 1141{ 1142 //CD - We must check the savedata for odd failures that require messages 1143 //CD - This is based on the Orbis and Durango code and solves TRC issue 1144 1145 //Are there any errors? 1146 //SaveData? 1147 1148 if (m_bSaveIncompleteDialogRunning) 1149 { 1150 updateSaveIncompleteDialog(); 1151 return; 1152 } 1153 1154 if (sceSaveDataDialogGetStatus() != SCE_COMMON_DIALOG_STATUS_NONE) 1155 { 1156 updateSaveDataDeleteDialog(); 1157 } 1158 1159 switch (m_bSaveDataDeleteDialogState) 1160 { 1161 case eSaveDataDeleteState_idle: 1162 return; 1163 1164 case eSaveDataDeleteState_waitingForUser: 1165 case eSaveDataDeleteState_userConfirmation: 1166 case eSaveDataDeleteState_deleting: 1167 return; 1168 1169 case eSaveDataDeleteState_abort: 1170 case eSaveDataDeleteState_continue: 1171 { 1172 C4JStorage::ESaveGameState eGameState = StorageManager.GetSaveState(); 1173 printSaveState(); 1174 1175 if (eGameState == C4JStorage::ESaveGame_SaveIncomplete_WaitingOnResponse) 1176 { 1177 if (m_bSaveDataDeleteDialogState == eSaveDataDeleteState_abort) 1178 { 1179 app.DebugPrintf("[SaveDataTick] eSaveDataDeleteState_abort.\n"); 1180 StorageManager.CancelIncompleteOperation(); 1181 } 1182 else if (m_bSaveDataDeleteDialogState == eSaveDataDeleteState_continue) 1183 { 1184 app.DebugPrintf("[SaveDataTick] eSaveDataDeleteState_continue.\n"); 1185 StorageManager.ContinueIncompleteOperation(); 1186 } 1187 } 1188 else if (eGameState == C4JStorage::ESaveGame_Idle) 1189 { 1190 app.DebugPrintf("[SaveDataTick] Storage Manager is idle, SaveDataDialog reverting to idle state too.\n"); 1191 } 1192 1193 m_bSaveDataDeleteDialogState = eSaveDataDeleteState_idle; 1194 } 1195 return; 1196 } 1197 1198 1199#if 0 1200 C4JStorage::ESaveIncompleteType errorType = StorageManager.GetSaveError(); 1201 if (errorType == C4JStorage::ESaveIncomplete_None) errorType = StorageManager.GetOptionsSaveError(); 1202 1203 if (errorType == C4JStorage::ESaveIncomplete_OutOfQuota) 1204 { 1205 initSaveDataDeleteDialog(); 1206 } 1207 else if (errorType == C4JStorage::ESaveIncomplete_OutOfLocalStorage) 1208 { 1209 //initSaveIncompleteDialog(1); 1210 } 1211 else if (errorType != C4JStorage::ESaveIncomplete_None) 1212 { 1213 app.DebugPrintf("[SaveDataTick] Unknown save error from StorageManager.\n"); 1214 } 1215 1216 1217 //TRC - Quota Failure 1218 if( errorType == C4JStorage::ESaveIncomplete_OutOfQuota ) 1219 { 1220 UINT uiIDA[1]; 1221 uiIDA[0]=IDS_CONFIRM_OK; 1222 C4JStorage::EMessageResult res = ui.RequestErrorMessage( IDS_SAVE_INCOMPLETE_TITLE, IDS_SAVE_INCOMPLETE_EXPLANATION_QUOTA, uiIDA, 1, ProfileManager.GetPrimaryPad()); 1223 if( res != C4JStorage::EMessage_Busy ) 1224 { 1225 //Clear the error now it's been dealt with 1226 StorageManager.ClearSaveError(); 1227 StorageManager.ClearOptionsSaveError(); 1228 } 1229 } 1230#endif 1231} 1232 1233void CConsoleMinecraftApp::Callback_SaveGameIncomplete(void *pParam, C4JStorage::ESaveIncompleteType saveIncompleteType, int blocksRequired) 1234{ 1235 app.DebugPrintf( 1236 "[Callback_SaveGameIncomplete] saveIncompleteType=%i, blocksRequired=%i,\n", 1237 saveIncompleteType, blocksRequired 1238 ); 1239 1240 if (saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfQuota || saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfLocalStorage) 1241 { 1242 if(UIScene_LoadOrJoinMenu::isSaveTransferRunning()) 1243 { 1244 // 4J MGH - if we're trying to save from the save transfer stuff, only show "ok", and we won't try to save again 1245 if(saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfQuota) blocksRequired = -1; 1246 UINT uiIDA[1]; 1247 uiIDA[0]=IDS_CONFIRM_OK; 1248 C4JStorage::EMessageResult res = ui.RequestErrorMessage( IDS_SAVE_INCOMPLETE_TITLE, IDS_SAVE_INCOMPLETE_EXPLANATION_QUOTA, uiIDA, 1, ProfileManager.GetPrimaryPad(), &NoSaveSpaceReturned, (void *)blocksRequired); 1249 1250 } 1251 else 1252 { 1253 // 4J Stu - If it's quota then we definitely have to delete our saves, so don't show the system UI for this case 1254 if(saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfQuota) blocksRequired = -1; 1255 UINT uiIDA[2]; 1256 uiIDA[0]=IDS_CONFIRM_OK; 1257 uiIDA[1]=IDS_CONFIRM_CANCEL; 1258 C4JStorage::EMessageResult res = ui.RequestErrorMessage( IDS_SAVE_INCOMPLETE_TITLE, IDS_SAVE_INCOMPLETE_EXPLANATION_QUOTA, uiIDA, 2, ProfileManager.GetPrimaryPad(), &NoSaveSpaceReturned, (void *)blocksRequired); 1259 } 1260 } 1261} 1262 1263int CConsoleMinecraftApp::NoSaveSpaceReturned(void *pParam,int iPad,C4JStorage::EMessageResult result) 1264{ 1265 if(result==C4JStorage::EMessage_ResultAccept && !UIScene_LoadOrJoinMenu::isSaveTransferRunning()) // MGH - we won't try to save again during a save tranfer 1266 { 1267 int blocksRequired = (int)pParam; 1268 if(blocksRequired > 0) 1269 { 1270 app.initSaveIncompleteDialog(blocksRequired); 1271 } 1272 else 1273 { 1274 app.initSaveDataDeleteDialog(); 1275 } 1276 } 1277 else 1278 { 1279 StorageManager.CancelIncompleteOperation(); 1280 StorageManager.ClearSaveError(); 1281 StorageManager.ClearOptionsSaveError(); 1282 } 1283 1284 return 0; 1285} 1286 1287int CConsoleMinecraftApp::cbConfirmDeleteMessageBox(void *pParam, int iPad, const C4JStorage::EMessageResult result) 1288{ 1289 CConsoleMinecraftApp *pClass = (CConsoleMinecraftApp*) pParam; 1290 1291 if (pClass != NULL && pClass->m_pSaveToDelete != NULL) 1292 { 1293 if (result == C4JStorage::EMessage_ResultDecline) 1294 { 1295 pClass->m_bSaveDataDeleteDialogState = eSaveDataDeleteState_deleting; 1296 C4JStorage::ESaveGameState eDeleteStatus = StorageManager.DeleteSaveData(pClass->m_pSaveToDelete, cbSaveDataDeleted, pClass); 1297 } 1298 else 1299 { 1300 pClass->initSaveDataDeleteDialog(); 1301 } 1302 } 1303 else 1304 { 1305 pClass->initSaveDataDeleteDialog(); 1306 1307 // 4J-JEV: This could leave the storage library in a waiting for user state. 1308 //pClass->m_bSaveDataDeleteDialogState = eSaveDataDeleteState_idle; 1309 } 1310 return 0; 1311} 1312 1313void CConsoleMinecraftApp::initSaveIncompleteDialog(int spaceNeeded) 1314{ 1315 SceSaveDataDialogParam param; 1316 sceSaveDataDialogParamInit(&param); 1317 1318 SceSaveDataDialogSystemMessageParam sysParam; 1319 ZeroMemory(&sysParam,sizeof(SceSaveDataDialogSystemMessageParam)); 1320 param.sysMsgParam = &sysParam; 1321 1322 param.mode = SCE_SAVEDATA_DIALOG_MODE_SYSTEM_MSG; 1323 param.dispType = SCE_SAVEDATA_DIALOG_TYPE_SAVE; 1324 1325 param.sysMsgParam->sysMsgType = SCE_SAVEDATA_DIALOG_SYSMSG_TYPE_NOSPACE_CONTINUABLE; 1326 param.sysMsgParam->value = (SceInt32) spaceNeeded; 1327 1328 SceInt32 ret = sceSaveDataDialogInit(&param); 1329 if (ret == SCE_OK) 1330 { 1331 m_bSaveIncompleteDialogRunning = true; 1332 InputManager.SetMenuDisplayed(0,true); 1333 ProfileManager.SetSysUIShowing(true); 1334 ui.SetSysUIShowing(true); 1335 } 1336 else 1337 { 1338 app.DebugPrintf("[SaveDataIncompleteDialog] ERROR: INITIALISING DIALOG, sceSaveDataDialogInit() (0x%x).\n", ret); 1339 } 1340 1341} 1342 1343void CConsoleMinecraftApp::updateSaveIncompleteDialog() 1344{ 1345 SceCommonDialogStatus dialogStatus = sceSaveDataDialogGetStatus(); 1346 if (dialogStatus == SCE_COMMON_DIALOG_STATUS_RUNNING) 1347 { 1348 SceCommonDialogStatus dialogSubStatus = sceSaveDataDialogGetSubStatus(); 1349 1350 if (dialogSubStatus == SCE_COMMON_DIALOG_STATUS_RUNNING) 1351 { 1352 // Wait for user. 1353 } 1354 else if (dialogSubStatus == SCE_COMMON_DIALOG_STATUS_FINISHED) 1355 { 1356 SceSaveDataDialogFinishParam finishParam; 1357 ZeroMemory(&finishParam, sizeof(SceSaveDataDialogFinishParam)); 1358 finishParam.flag = SCE_SAVEDATA_DIALOG_FINISH_FLAG_DEFAULT; 1359 1360 SceInt32 ret = sceSaveDataDialogFinish(&finishParam); 1361 if (ret != SCE_OK) 1362 { 1363 app.DebugPrintf("[SaveDataIncompleteDialog] ERROR: UPDATING DIALOG, sceSaveDataDialogFinish() (0x%x).\n", ret); 1364 } 1365 } 1366 } 1367 else if (dialogStatus == SCE_COMMON_DIALOG_STATUS_FINISHED) 1368 { 1369 SceInt32 ret = sceSaveDataDialogTerm(); 1370 if (ret == SCE_OK) 1371 { 1372 finishSaveIncompleteDialog(); 1373 } 1374 else 1375 { 1376 app.DebugPrintf("[SaveDataIncompleteDialog] ERROR: TERMINATING DIALOG, sceSaveDataDialogTerm() (0x%x).\n", ret); 1377 } 1378 } 1379} 1380 1381void CConsoleMinecraftApp::finishSaveIncompleteDialog() 1382{ 1383 m_bSaveIncompleteDialogRunning = false; 1384 InputManager.SetMenuDisplayed(0,false); 1385 ProfileManager.SetSysUIShowing(false); 1386 ui.SetSysUIShowing(false); 1387 1388 StorageManager.ClearSaveError(); 1389 StorageManager.ClearOptionsSaveError(); 1390 1391 initSaveDataDeleteDialog(); 1392} 1393 1394void CConsoleMinecraftApp::initSaveDataDeleteDialog() 1395{ 1396 SceSaveDataDialogParam param; 1397 getSaveDataDeleteDialogParam( &param ); 1398 1399 SceInt32 ret = sceSaveDataDialogInit(&param); 1400 if (ret == SCE_OK) 1401 { 1402 app.DebugPrintf("[SaveDataDeleteDialog] Successfully initialised SaveDataDelete dialog.\n"); 1403 1404 m_bSaveDataDeleteDialogState = eSaveDataDeleteState_waitingForUser; 1405 1406 InputManager.SetMenuDisplayed(0,true); 1407 ProfileManager.SetSysUIShowing(true); 1408 ui.SetSysUIShowing(true); 1409 1410 // Start getting saves data to use when deleting. 1411 if (StorageManager.ReturnSavesInfo() == NULL) 1412 { 1413 C4JStorage::ESaveGameState eSGIStatus 1414 = StorageManager.GetSavesInfo( 1415 ProfileManager.GetPrimaryPad(), 1416 NULL, 1417 this, 1418 "save" 1419 ); 1420 } 1421 1422 // Dim background because sony doesn't do that. 1423 ui.showComponent(0, eUIComponent_MenuBackground, eUILayer_Tooltips, eUIGroup_Fullscreen, true); 1424 1425 StorageManager.SetSaveDisabled(true); 1426 EnterSaveNotificationSection(); 1427 } 1428 else 1429 { 1430 app.DebugPrintf("[SaveDataDeleteDialog] ERROR: INITIALISING DIALOG, sceSaveDataDialogInit() (0x%x).\n", ret); 1431 } 1432 1433 releaseSaveDataDeleteDialogParam( &param ); 1434} 1435 1436void CConsoleMinecraftApp::updateSaveDataDeleteDialog() 1437{ 1438 SceCommonDialogStatus dialogStatus = sceSaveDataDialogGetStatus(); 1439 if (dialogStatus == SCE_COMMON_DIALOG_STATUS_RUNNING) 1440 { 1441 SceCommonDialogStatus dialogSubStatus = sceSaveDataDialogGetSubStatus(); 1442 1443 if (dialogSubStatus == SCE_COMMON_DIALOG_STATUS_RUNNING) 1444 { 1445 // Wait for user. 1446 } 1447 else if (dialogSubStatus == SCE_COMMON_DIALOG_STATUS_FINISHED) 1448 { 1449 SceSaveDataDialogResult dialogResult; 1450 ZeroMemory(&dialogResult, sizeof(SceSaveDataDialogResult)); 1451 1452 SceInt32 ret = sceSaveDataDialogGetResult(&dialogResult); 1453 if (ret == SCE_OK) 1454 { 1455 bool finishDialog = false; 1456 1457 if ( dialogResult.result == SCE_COMMON_DIALOG_RESULT_USER_CANCELED 1458 || dialogResult.result == SCE_COMMON_DIALOG_RESULT_ABORTED ) 1459 { 1460 app.DebugPrintf("[SaveDataDeleteDialog] CANCELED OR ABORTED!\n"); 1461 1462 // 4J-JEV: Check to ensure that finishedDeletingSaves is called only once. 1463 if (m_bSaveDataDeleteDialogState == eSaveDataDeleteState_waitingForUser) 1464 { 1465 finishedDeletingSaves(false); 1466 } 1467 1468 finishDialog = true; 1469 } 1470 1471 if ( dialogResult.result == SCE_COMMON_DIALOG_RESULT_OK ) 1472 { 1473 SceAppUtilSaveDataSlotParam slotParam; 1474 ret = sceAppUtilSaveDataSlotGetParam( dialogResult.slotId, &slotParam, NULL ); 1475 1476 if (ret == SCE_OK) 1477 { 1478 int saveindex = -1; 1479 PSAVE_INFO pSaveInfo = NULL; 1480 PSAVE_DETAILS pSaveDetails = StorageManager.ReturnSavesInfo(); 1481 1482 if (pSaveDetails != NULL) 1483 { 1484 app.DebugPrintf("[SaveDataDeleteDialog] Searching for save files:\n"); 1485 1486 for (unsigned int i = 0; i < pSaveDetails->iSaveC; i++) 1487 { 1488 app.DebugPrintf("\t- '%s'\n", pSaveDetails->SaveInfoA[i].UTF8SaveFilename); 1489 1490 void *buf1, *buf2; 1491 buf1 = &(pSaveDetails->SaveInfoA[i].UTF8SaveFilename); 1492 buf2 = &slotParam.title; 1493 1494 if ( 0 == memcmp(buf1, buf2, MAX_SAVEFILENAME_LENGTH) ) 1495 { 1496 pSaveInfo = &pSaveDetails->SaveInfoA[i]; 1497 saveindex = i; 1498 break; 1499 } 1500 } 1501 } 1502 else 1503 { 1504 app.DebugPrintf("[SaveDataDeleteDialog] ERROR: PERFORMING DELETE OPERATION, pSavesDetails is null.\n"); 1505 } 1506 1507 if (pSaveInfo != NULL) 1508 { 1509 app.DebugPrintf( 1510 "[SaveDataDeleteDialog] User wishes to delete slot_%d:\n\t" 1511 "4jsaveindex=%d, filename='%s', title='%s', subtitle='%s', size=%dKiB.\n", 1512 dialogResult.slotId, 1513 saveindex, 1514 pSaveInfo->UTF8SaveFilename, 1515 slotParam.title, 1516 slotParam.subTitle, 1517 slotParam.sizeKiB 1518 ); 1519 1520 UINT uiIDA[] = 1521 { 1522 IDS_CONFIRM_CANCEL, 1523 IDS_CONFIRM_OK 1524 }; 1525 1526 ui.RequestErrorMessage( 1527 IDS_TOOLTIPS_DELETESAVE, IDS_TEXT_DELETE_SAVE, 1528 uiIDA, 2, 1529 0, 1530 &cbConfirmDeleteMessageBox, this 1531 ); 1532 1533 m_bSaveDataDeleteDialogState = eSaveDataDeleteState_userConfirmation; 1534 1535 m_pSaveToDelete = pSaveInfo; 1536 } 1537 else 1538 { 1539 app.DebugPrintf( 1540 "[SaveDataDeleteDialog] ERROR: PERFORMING DELETE OPERATION, cannot find file in our saves list:\n" 1541 "\t slotId=%i, title=%s, subtitle=%s,\n", 1542 dialogResult.slotId, slotParam.title, slotParam.subTitle 1543 ); 1544 } 1545 1546 finishDialog = true; 1547 } 1548 else 1549 { 1550 app.DebugPrintf("[SaveDataDeleteDialog] ERROR: UPDATING DIALOG, sceAppUtilSaveDataGetParam() (0x%x).\n", ret); 1551 } 1552 } 1553 1554 if (finishDialog) 1555 { 1556 SceSaveDataDialogFinishParam finishParam; 1557 ZeroMemory(&finishParam, sizeof(SceSaveDataDialogFinishParam)); 1558 finishParam.flag = SCE_SAVEDATA_DIALOG_FINISH_FLAG_DEFAULT; 1559 1560 sceSaveDataDialogFinish(&finishParam); 1561 if (ret == SCE_OK) app.DebugPrintf("[SaveDataDeleteDialog] Successfully finished saveDataDialog.\n"); 1562 else app.DebugPrintf("[SaveDataDeleteDialog] ERROR: UPDATING DIALOG, sceSaveDataDialogFinish() (0x%x).\n", ret); 1563 } 1564 1565 } 1566 else 1567 { 1568 app.DebugPrintf("[SaveDataDeleteDialog] ERROR: UPDATING DIALOG, sceSaveDataDialogGetResult() (0x%x).\n", ret); 1569 } 1570 } 1571 } 1572 else if (dialogStatus == SCE_COMMON_DIALOG_STATUS_FINISHED) 1573 { 1574 SceInt32 ret = sceSaveDataDialogTerm(); 1575 if (ret == SCE_OK) 1576 { 1577 finishSaveDataDeleteDialog(); 1578 } 1579 else 1580 { 1581 app.DebugPrintf("[SaveDataDeleteDialog] ERROR: TERMINATING DIALOG, sceSaveDataDialogTerm() (0x%x).\n", ret); 1582 } 1583 } 1584} 1585 1586void CConsoleMinecraftApp::finishSaveDataDeleteDialog() 1587{ 1588 ProfileManager.SetSysUIShowing(false); 1589 InputManager.SetMenuDisplayed(0,false); 1590 ui.SetSysUIShowing(false); 1591 ui.removeComponent(eUIComponent_MenuBackground, eUILayer_Tooltips, eUIGroup_Fullscreen); 1592} 1593 1594void CConsoleMinecraftApp::getSaveDataDeleteDialogParam(SceSaveDataDialogParam *baseParam) 1595{ 1596 sceSaveDataDialogParamInit(baseParam); 1597 1598 static SceSaveDataDialogListParam listParam; 1599 ZeroMemory(&listParam, sizeof(SceSaveDataDialogListParam)); 1600 1601 { 1602 vector<const SceAppUtilSaveDataSlot> slots; 1603 for (unsigned int i = 2; i < SCE_APPUTIL_SAVEDATA_SLOT_MAX; i++) 1604 { 1605 SceAppUtilSaveDataSlotParam slotParam; 1606 int ret = sceAppUtilSaveDataSlotGetParam( i, &slotParam, NULL ); 1607 1608 if (ret == SCE_OK) 1609 { 1610 SceAppUtilSaveDataSlot slot; 1611 ZeroMemory( &slot, sizeof(SceAppUtilSaveDataSlot) ); 1612 1613 slot.id = i; 1614 slot.status = slotParam.status; 1615 slot.userParam = 0; 1616 1617 slots.push_back( slot ); 1618 } 1619 } 1620 1621 SceAppUtilSaveDataSlot *pSavesList = new SceAppUtilSaveDataSlot[slots.size()]; 1622 1623 int slotIndex = 0; 1624 1625 vector<const SceAppUtilSaveDataSlot>::iterator itr; 1626 for (itr = slots.begin(); itr != slots.end(); itr++) 1627 { 1628 pSavesList[slotIndex] = *itr; 1629 slotIndex++; 1630 } 1631 1632 listParam.slotListSize = slots.size(); 1633 listParam.slotList = pSavesList; 1634 } 1635 1636 if (listParam.slotListSize > 0) listParam.focusPos = SCE_SAVEDATA_DIALOG_FOCUS_POS_LISTHEAD; 1637 else listParam.focusPos = SCE_SAVEDATA_DIALOG_FOCUS_POS_EMPTYHEAD; 1638 1639 // static SceCommonDialogColor s_bgColor, s_dColor; 1640 // s_bgColor.r = s_dColor.r = 50; 1641 // s_bgColor.g = s_dColor.g = 50; 1642 // s_bgColor.b = s_dColor.b = 50; 1643 // s_bgColor.a = s_dColor.a = 125; 1644 // baseParam->commonParam.bgColor = &s_bgColor; 1645 // baseParam->commonParam.dimmerColor = &s_dColor; 1646 1647 1648 static uint8_t *strPtr = NULL; 1649 if (strPtr != NULL) delete strPtr; 1650 strPtr = mallocAndCreateUTF8ArrayFromString( IDS_TOOLTIPS_DELETESAVE ); 1651 1652 listParam.listTitle = (const SceChar8 *) strPtr; 1653 listParam.itemStyle = SCE_SAVEDATA_DIALOG_LIST_ITEM_STYLE_TITLE_SUBTITLE_DATE; 1654 1655 baseParam->mode = SCE_SAVEDATA_DIALOG_MODE_LIST; 1656 baseParam->dispType = SCE_SAVEDATA_DIALOG_TYPE_DELETE; 1657 baseParam->listParam = &listParam; 1658 1659 baseParam->flag = SCE_SAVEDATA_DIALOG_ENV_FLAG_DEFAULT; 1660} 1661 1662void CConsoleMinecraftApp::releaseSaveDataDeleteDialogParam(SceSaveDataDialogParam *baseParam) 1663{ 1664 //delete baseParam->listParam; 1665 //delete baseParam->commonParam.dimmerColor; 1666 //delete baseParam->commonParam.bgColor; 1667 //delete baseParam->listParam.listTitle; 1668} 1669 1670int CConsoleMinecraftApp::cbSaveDataDeleted( void *pParam, const bool success ) 1671{ 1672 app.DebugPrintf("[SaveDataDeleteDialog] cbSaveDataDeleted(%s)\n", (success?"success":"fail")); 1673 1674 CConsoleMinecraftApp *pApp = (CConsoleMinecraftApp*) pParam; 1675 if ( pApp->m_bSaveDataDeleteDialogState == eSaveDataDeleteState_deleting ) 1676 { 1677 /* SceSaveDataDialogParam param; 1678 pApp->getSaveDataDeleteDialogParam( &param ); 1679 1680 SceInt32 ret = sceSaveDataDialogContinue(&param); 1681 if (ret != SCE_OK) app.DebugPrintf("[SaveDataDeleteDialog] ERROR: UPDATING DIALOG, sceSaveDataDialogContinue() (0x%x).\n", ret); 1682 1683 pApp->m_bSaveDataDeleteDialogState = eSaveDataDeleteState_waitingForUser; 1684 pApp->releaseSaveDataDeleteDialogParam( &param ); */ 1685 1686 pApp->finishedDeletingSaves(true); 1687 } 1688 1689 return 0; 1690} 1691 1692void CConsoleMinecraftApp::finishedDeletingSaves(bool bContinue) 1693{ 1694 app.DebugPrintf( "[finishedDeletingSaves] %s.\n", (bContinue?"Continuing":"Aborting") ); 1695 1696 StorageManager.SetSaveDisabled(false); 1697 LeaveSaveNotificationSection(); 1698 1699 StorageManager.ClearSaveError(); 1700 StorageManager.ClearOptionsSaveError(); 1701 1702 1703 if (bContinue) m_bSaveDataDeleteDialogState = eSaveDataDeleteState_continue; 1704 else m_bSaveDataDeleteDialogState = eSaveDataDeleteState_abort; 1705}