the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 1513 lines 42 kB view raw
1#include "stdafx.h" 2 3#include "SonyCommerce_PS3.h" 4#include "..\PS3Extras\ShutdownManager.h" 5#include <sys/event.h> 6 7 8bool SonyCommerce_PS3::m_bCommerceInitialised = false; 9SceNpCommerce2SessionInfo SonyCommerce_PS3::m_sessionInfo; 10SonyCommerce_PS3::State SonyCommerce_PS3::m_state = e_state_noSession; 11int SonyCommerce_PS3::m_errorCode = 0; 12LPVOID SonyCommerce_PS3::m_callbackParam = NULL; 13 14void* SonyCommerce_PS3::m_receiveBuffer = NULL; 15SonyCommerce_PS3::Event SonyCommerce_PS3::m_event; 16std::queue<SonyCommerce_PS3::Message> SonyCommerce_PS3::m_messageQueue; 17std::vector<SonyCommerce_PS3::ProductInfo>* SonyCommerce_PS3::m_pProductInfoList = NULL; 18SonyCommerce_PS3::ProductInfoDetailed* SonyCommerce_PS3::m_pProductInfoDetailed = NULL; 19SonyCommerce_PS3::ProductInfo* SonyCommerce_PS3::m_pProductInfo = NULL; 20 21SonyCommerce_PS3::CategoryInfo* SonyCommerce_PS3::m_pCategoryInfo = NULL; 22const char* SonyCommerce_PS3::m_pProductID = NULL; 23char* SonyCommerce_PS3::m_pCategoryID = NULL; 24SonyCommerce_PS3::CheckoutInputParams SonyCommerce_PS3::m_checkoutInputParams; 25SonyCommerce_PS3::DownloadListInputParams SonyCommerce_PS3::m_downloadInputParams; 26 27SonyCommerce_PS3::CallbackFunc SonyCommerce_PS3::m_callbackFunc = NULL; 28sys_memory_container_t SonyCommerce_PS3::m_memContainer = SYS_MEMORY_CONTAINER_ID_INVALID; 29bool SonyCommerce_PS3::m_bUpgradingTrial = false; 30 31SonyCommerce_PS3::CallbackFunc SonyCommerce_PS3::m_trialUpgradeCallbackFunc; 32LPVOID SonyCommerce_PS3::m_trialUpgradeCallbackParam; 33 34CRITICAL_SECTION SonyCommerce_PS3::m_queueLock; 35 36 37 38uint32_t SonyCommerce_PS3::m_contextId=0; ///< The npcommerce2 context ID 39bool SonyCommerce_PS3::m_contextCreated=false; ///< npcommerce2 context ID created? 40SonyCommerce_PS3::Phase SonyCommerce_PS3::m_currentPhase = e_phase_stopped; ///< Current commerce2 util 41char SonyCommerce_PS3::m_commercebuffer[SCE_NP_COMMERCE2_RECV_BUF_SIZE]; 42 43C4JThread* SonyCommerce_PS3::m_tickThread = NULL; 44bool SonyCommerce_PS3::m_bLicenseChecked=false; // Check the trial/full license for the game 45 46 47SonyCommerce_PS3::ProductInfoDetailed s_trialUpgradeProductInfoDetailed; 48void SonyCommerce_PS3::Delete() 49{ 50 m_pProductInfoList=NULL; 51 m_pProductInfoDetailed=NULL; 52 m_pProductInfo=NULL; 53 m_pCategoryInfo = NULL; 54 m_pProductID = NULL; 55 m_pCategoryID = NULL; 56} 57void SonyCommerce_PS3::Init() 58{ 59 int ret; 60 61 assert(m_state == e_state_noSession); 62 if(!m_bCommerceInitialised) 63 { 64 ret = sceNpCommerce2Init(); 65 if (ret < 0) 66 { 67 app.DebugPrintf(4,"sceNpCommerce2Init failed (0x%x)\n", ret); 68 return; 69 } 70 else 71 { 72 m_bCommerceInitialised = true; 73 } 74 m_pCategoryID=(char *)malloc(sizeof(char) * 100); 75 InitializeCriticalSection(&m_queueLock); 76 } 77 78 return ; 79 80} 81 82 83 84void SonyCommerce_PS3::CheckForTrialUpgradeKey_Callback(LPVOID param, bool bFullVersion) 85{ 86 ProfileManager.SetFullVersion(bFullVersion); 87 if(ProfileManager.IsFullVersion()) 88 { 89 StorageManager.SetSaveDisabled(false); 90 ConsoleUIController::handleUnlockFullVersionCallback(); 91 // licence has been checked, so we're ok to install the trophies now 92 ProfileManager.InitialiseTrophies( SQRNetworkManager_PS3::GetSceNpCommsId(), 93 SQRNetworkManager_PS3::GetSceNpCommsSig()); 94 95 } 96 m_bLicenseChecked=true; 97} 98 99bool SonyCommerce_PS3::LicenseChecked() 100{ 101 return m_bLicenseChecked; 102} 103 104void SonyCommerce_PS3::CheckForTrialUpgradeKey() 105{ 106 // 4J-PB - If we are the blu ray disc then we are the full version 107 if(StorageManager.GetBootTypeDisc()) 108 { 109 CheckForTrialUpgradeKey_Callback(NULL,true); 110 } 111 else 112 { 113 StorageManager.CheckForTrialUpgradeKey(CheckForTrialUpgradeKey_Callback, NULL); 114 } 115} 116 117int SonyCommerce_PS3::Shutdown() 118{ 119 int ret=0; 120 if (m_contextCreated) 121 { 122 ret = sceNpCommerce2DestroyCtx(m_contextId); 123 if (ret != 0) 124 { 125 return ret; 126 } 127 128 m_contextId = 0; 129 m_contextCreated = false; 130 } 131 132 ret = sceNpCommerce2Term(); 133 m_bCommerceInitialised = false; 134 if (ret != 0) 135 { 136 return ret; 137 } 138 delete m_pCategoryID; 139 DeleteCriticalSection(&m_queueLock); 140 141 return ret; 142} 143 144 145 146int SonyCommerce_PS3::TickLoop(void* lpParam) 147{ 148 ShutdownManager::HasStarted(ShutdownManager::eCommerceThread); 149 while( (m_currentPhase != e_phase_stopped) && ShutdownManager::ShouldRun(ShutdownManager::eCommerceThread) ) 150 { 151 processEvent(); 152 processMessage(); 153 Sleep(16); // sleep for a frame 154 } 155 156 ShutdownManager::HasFinished(ShutdownManager::eCommerceThread); 157 158 return 0; 159} 160 161int SonyCommerce_PS3::getProductList(std::vector<ProductInfo>* productList, char *categoryId) 162{ 163 int ret = 0; 164 uint32_t requestId; 165 size_t bufSize = sizeof(m_commercebuffer); 166 size_t fillSize = 0; 167 SceNpCommerce2GetCategoryContentsResult result; 168 SceNpCommerce2CategoryInfo categoryInfo; 169 SceNpCommerce2ContentInfo contentInfo; 170 SceNpCommerce2GameProductInfo productInfo; 171 SceNpCommerce2GameSkuInfo skuInfo; 172 ProductInfo tempInfo; 173 std::vector<ProductInfo> tempProductVec; 174 175 if (!m_contextCreated) 176 { 177 ret = createContext(); 178 if (ret < 0) 179 { 180 setError(ret); 181 return ret; 182 } 183 } 184 185 // Create request ID 186 ret = sceNpCommerce2GetCategoryContentsCreateReq(m_contextId, &requestId); 187 if (ret < 0) 188 { 189 setError(ret); 190 return ret; 191 } 192 193 // Obtain category content data 194 ret = sceNpCommerce2GetCategoryContentsStart(requestId, categoryId, 0, SCE_NP_COMMERCE2_GETCAT_MAX_COUNT); 195 if (ret < 0) 196 { 197 sceNpCommerce2DestroyReq(requestId); 198 setError(ret); 199 return ret; 200 } 201 202 ret = sceNpCommerce2GetCategoryContentsGetResult(requestId, m_commercebuffer, bufSize, &fillSize); 203 if (ret < 0) 204 { 205 sceNpCommerce2DestroyReq(requestId); 206 setError(ret); 207 return ret; 208 } 209 210 ret = sceNpCommerce2DestroyReq(requestId); 211 if (ret < 0) 212 { 213 setError(ret); 214 return ret; 215 } 216 217 // We have the initial category content data, 218 // now to take out the category content information. 219 ret = sceNpCommerce2InitGetCategoryContentsResult(&result, m_commercebuffer, fillSize); 220 if (ret < 0) 221 { 222 setError(ret); 223 return ret; 224 } 225 226 // Get the category information 227 ret = sceNpCommerce2GetCategoryInfo(&result, &categoryInfo); 228 if (ret < 0) 229 { 230 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 231 setError(ret); 232 return ret; 233 } 234 235 if(categoryInfo.countOfProduct==0) 236 { 237 // There is no DLC 238 return 0; 239 } 240 241 // Reserve some space 242 tempProductVec.reserve(categoryInfo.countOfProduct); 243 244 // For each product, obtain information 245 for (int i = 0; i < result.rangeOfContents.count; i++) 246 { 247 ret = sceNpCommerce2GetContentInfo(&result, i, &contentInfo); 248 if (ret < 0) 249 { 250 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 251 setError(ret); 252 return ret; 253 } 254 255 // Only process if it is a product 256 if (contentInfo.contentType == SCE_NP_COMMERCE2_CONTENT_TYPE_PRODUCT) 257 { 258 259 // reset tempInfo 260 memset(&tempInfo, 0x0, sizeof(tempInfo)); 261 262 // Get product info 263 ret = sceNpCommerce2GetGameProductInfoFromContentInfo(&contentInfo, &productInfo); 264 if (ret < 0) 265 { 266 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 267 setError(ret); 268 return ret; 269 } 270 271 // populate our temp struct 272 273 strncpy(tempInfo.productId, productInfo.productId, SCE_NP_COMMERCE2_PRODUCT_ID_LEN); 274 strncpy(tempInfo.productName, productInfo.productName, SCE_NP_COMMERCE2_PRODUCT_NAME_LEN); 275 strncpy(tempInfo.shortDescription, productInfo.productShortDescription, SCE_NP_COMMERCE2_PRODUCT_SHORT_DESCRIPTION_LEN); 276 if(tempInfo.longDescription[0]!=0) 277 { 278 strncpy(tempInfo.longDescription, productInfo.productLongDescription, SCE_NP_COMMERCE2_PRODUCT_LONG_DESCRIPTION_LEN); 279 } 280 else 281 { 282#ifdef _DEBUG 283 strcpy(tempInfo.longDescription,"Missing long description"); 284#endif 285 } 286 strncpy(tempInfo.spName, productInfo.spName, SCE_NP_COMMERCE2_SP_NAME_LEN); 287 strncpy(tempInfo.imageUrl, productInfo.imageUrl, SCE_NP_COMMERCE2_URL_LEN); 288 tempInfo.releaseDate = productInfo.releaseDate; 289 290 if (productInfo.countOfSku == 1) 291 { 292 // Get SKU info 293 ret = sceNpCommerce2GetGameSkuInfoFromGameProductInfo(&productInfo, 0, &skuInfo); 294 if (ret < 0) 295 { 296 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 297 setError(ret); 298 return ret; 299 } 300 tempInfo.purchasabilityFlag = skuInfo.purchasabilityFlag; 301 302 // Take out the price. Nicely formatted 303 // but also keep the price as a value in case it's 0 - we need to show "free" for that 304 tempInfo.ui32Price= skuInfo.price; 305 ret = sceNpCommerce2GetPrice(m_contextId, tempInfo.price, sizeof(tempInfo.price), skuInfo.price); 306 307 if (ret < 0) 308 { 309 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 310 setError(ret); 311 return ret; 312 } 313 } 314 tempProductVec.push_back(tempInfo); 315 } 316 } 317 318 // Set our result 319 *productList = tempProductVec; 320 321 // Destroy the category contents result 322 ret = sceNpCommerce2DestroyGetCategoryContentsResult(&result); 323 if (ret < 0) 324 { 325 return ret; 326 } 327 328 return ret; 329} 330 331int SonyCommerce_PS3::getCategoryInfo(CategoryInfo *pInfo, char *categoryId) 332{ 333 int ret = 0; 334 uint32_t requestId; 335 size_t bufSize = sizeof(m_commercebuffer); 336 size_t fillSize = 0; 337 SceNpCommerce2GetCategoryContentsResult result; 338 SceNpCommerce2CategoryInfo categoryInfo; 339 SceNpCommerce2ContentInfo contentInfo; 340 //CategoryInfo tempCatInfo; 341 CategoryInfoSub tempSubCatInfo; 342 343 if (!m_contextCreated) 344 { 345 ret = createContext(); 346 if (ret < 0) 347 { 348 m_errorCode = ret; 349 return ret; 350 } 351 } 352 353 // Create request ID 354 ret = sceNpCommerce2GetCategoryContentsCreateReq(m_contextId, &requestId); 355 if (ret < 0) 356 { 357 m_errorCode = ret; 358 return ret; 359 } 360 361 // Obtain category content data 362 if (categoryId) 363 { 364 ret = sceNpCommerce2GetCategoryContentsStart(requestId, categoryId, 0, SCE_NP_COMMERCE2_GETCAT_MAX_COUNT); 365 } 366 else 367 { 368 ret = sceNpCommerce2GetCategoryContentsStart(requestId,categoryId, 369 0, SCE_NP_COMMERCE2_GETCAT_MAX_COUNT); 370 } 371 if (ret < 0) 372 { 373 sceNpCommerce2DestroyReq(requestId); 374 m_errorCode = ret; 375 return ret; 376 } 377 378 ret = sceNpCommerce2GetCategoryContentsGetResult(requestId, m_commercebuffer, bufSize, &fillSize); 379 if (ret < 0) 380 { 381 if(ret==SCE_NP_COMMERCE2_ERROR_SERVER_MAINTENANCE) 382 { 383 app.DebugPrintf(4,"\n--- SCE_NP_COMMERCE2_ERROR_SERVER_MAINTENANCE ---\n\n"); 384 } 385 sceNpCommerce2DestroyReq(requestId); 386 m_errorCode = ret; 387 return ret; 388 } 389 390 ret = sceNpCommerce2DestroyReq(requestId); 391 if (ret < 0) 392 { 393 m_errorCode = ret; 394 return ret; 395 } 396 397 // We have the initial category content data, 398 // now to take out the category content information. 399 ret = sceNpCommerce2InitGetCategoryContentsResult(&result, m_commercebuffer, fillSize); 400 if (ret < 0) { 401 m_errorCode = ret; 402 return ret; 403 } 404 405 // Get the category information 406 ret = sceNpCommerce2GetCategoryInfo(&result, &categoryInfo); 407 if (ret < 0) { 408 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 409 m_errorCode = ret; 410 return ret; 411 } 412 413 strcpy(pInfo->current.categoryId, categoryInfo.categoryId); 414 strcpy(pInfo->current.categoryName, categoryInfo.categoryName); 415 strcpy(pInfo->current.categoryDescription, categoryInfo.categoryDescription); 416 strcpy(pInfo->current.imageUrl, categoryInfo.imageUrl); 417 pInfo->countOfProducts = categoryInfo.countOfProduct; 418 pInfo->countOfSubCategories = categoryInfo.countOfSubCategory; 419 420 if (categoryInfo.countOfSubCategory > 0) 421 { 422 // For each sub category, obtain information 423 for (int i = 0; i < result.rangeOfContents.count; i++) 424 { 425 426 ret = sceNpCommerce2GetContentInfo(&result, i, &contentInfo); 427 if (ret < 0) 428 { 429 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 430 m_errorCode = ret; 431 return ret; 432 } 433 434 // Only process if it is a category 435 if (contentInfo.contentType == SCE_NP_COMMERCE2_CONTENT_TYPE_CATEGORY) 436 { 437 438 ret = sceNpCommerce2GetCategoryInfoFromContentInfo(&contentInfo, &categoryInfo); 439 if (ret < 0) 440 { 441 sceNpCommerce2DestroyGetCategoryContentsResult(&result); 442 m_errorCode = ret; 443 return ret; 444 } 445 446 strcpy(tempSubCatInfo.categoryId, categoryInfo.categoryId); 447 strcpy(tempSubCatInfo.categoryName, categoryInfo.categoryName); 448 strcpy(tempSubCatInfo.categoryDescription, categoryInfo.categoryDescription); 449 strcpy(tempSubCatInfo.imageUrl, categoryInfo.imageUrl); 450 451 // Add to the list 452 pInfo->subCategories.push_back(tempSubCatInfo); 453 } 454 } 455 } 456 457 // Set our result 458 //*info = tempCatInfo; 459 460 // Destroy the category contents result 461 ret = sceNpCommerce2DestroyGetCategoryContentsResult(&result); 462 if (ret < 0) { 463 return ret; 464 } 465 466 return ret; 467} 468 469 470int SonyCommerce_PS3::getDetailedProductInfo(ProductInfoDetailed *pInfo, const char *productId, char *categoryId) 471{ 472 int ret = 0; 473 uint32_t requestId; 474 size_t bufSize = sizeof(m_commercebuffer); 475 size_t fillSize = 0; 476 std::list<SceNpCommerce2ContentRatingDescriptor> ratingDescList; 477 SceNpCommerce2GetProductInfoResult result; 478 SceNpCommerce2ContentRatingInfo ratingInfo; 479 SceNpCommerce2GameProductInfo productInfo; 480 SceNpCommerce2GameSkuInfo skuInfo; 481 //ProductInfoDetailed tempInfo; 482 483 if (!m_contextCreated) { 484 ret = createContext(); 485 if (ret < 0) { 486 m_errorCode = ret; 487 return ret; 488 } 489 } 490 491 // Obtain product data 492 ret = sceNpCommerce2GetProductInfoCreateReq(m_contextId, &requestId); 493 if (ret < 0) { 494 m_errorCode = ret; 495 return ret; 496 } 497 498 if (categoryId && categoryId[0] != 0) { 499 ret = sceNpCommerce2GetProductInfoStart(requestId, categoryId, productId); 500 } else { 501 ret = sceNpCommerce2GetProductInfoStart(requestId, NULL, productId); 502 } 503 if (ret < 0) { 504 sceNpCommerce2DestroyReq(requestId); 505 m_errorCode = ret; 506 return ret; 507 } 508 509 ret = sceNpCommerce2GetProductInfoGetResult(requestId, m_commercebuffer, bufSize, &fillSize); 510 if (ret < 0) { 511 sceNpCommerce2DestroyReq(requestId); 512 m_errorCode = ret; 513 return ret; 514 } 515 516 ret = sceNpCommerce2DestroyReq(requestId); 517 if (ret < 0) 518 { 519 m_errorCode = ret; 520 return ret; 521 } 522 523 // Take Out Game Product Information 524 ret = sceNpCommerce2InitGetProductInfoResult(&result, m_commercebuffer, fillSize); 525 if (ret < 0) 526 { 527 m_errorCode = ret; 528 return ret; 529 } 530 531 ret = sceNpCommerce2GetGameProductInfo(&result, &productInfo); 532 if (ret < 0) 533 { 534 sceNpCommerce2DestroyGetProductInfoResult(&result); 535 m_errorCode = ret; 536 return ret; 537 } 538 539 // Get rating info 540 ret = sceNpCommerce2GetContentRatingInfoFromGameProductInfo(&productInfo, &ratingInfo); 541 if (ret < 0) 542 { 543 sceNpCommerce2DestroyGetProductInfoResult(&result); 544 m_errorCode = ret; 545 return ret; 546 } 547 548 for (int index = 0; index < ratingInfo.countOfContentRatingDescriptor; index++) 549 { 550 SceNpCommerce2ContentRatingDescriptor desc; 551 sceNpCommerce2GetContentRatingDescriptor(&ratingInfo, index, &desc); 552 ratingDescList.push_back(desc); 553 } 554 555 // populate our temp struct 556 pInfo->ratingDescriptors = ratingDescList; 557 strncpy(pInfo->productId, productInfo.productId, SCE_NP_COMMERCE2_PRODUCT_ID_LEN); 558 strncpy(pInfo->productName, productInfo.productName, SCE_NP_COMMERCE2_PRODUCT_NAME_LEN); 559 strncpy(pInfo->shortDescription, productInfo.productShortDescription, SCE_NP_COMMERCE2_PRODUCT_SHORT_DESCRIPTION_LEN); 560 strncpy(pInfo->longDescription, productInfo.productLongDescription, SCE_NP_COMMERCE2_PRODUCT_LONG_DESCRIPTION_LEN); 561 strncpy(pInfo->legalDescription, productInfo.legalDescription, SCE_NP_COMMERCE2_PRODUCT_LEGAL_DESCRIPTION_LEN); 562 strncpy(pInfo->spName, productInfo.spName, SCE_NP_COMMERCE2_SP_NAME_LEN); 563 strncpy(pInfo->imageUrl, productInfo.imageUrl, SCE_NP_COMMERCE2_URL_LEN); 564 pInfo->releaseDate = productInfo.releaseDate; 565 strncpy(pInfo->ratingSystemId, ratingInfo.ratingSystemId, SCE_NP_COMMERCE2_RATING_SYSTEM_ID_LEN); 566 strncpy(pInfo->ratingImageUrl, ratingInfo.imageUrl, SCE_NP_COMMERCE2_URL_LEN); 567 568 // Get SKU info 569 if (productInfo.countOfSku == 1) 570 { 571 ret = sceNpCommerce2GetGameSkuInfoFromGameProductInfo(&productInfo, 0, &skuInfo); 572 if (ret < 0) 573 { 574 sceNpCommerce2DestroyGetProductInfoResult(&result); 575 m_errorCode = ret; 576 return ret; 577 } 578 strncpy(pInfo->skuId, skuInfo.skuId, SCE_NP_COMMERCE2_SKU_ID_LEN); 579 pInfo->purchasabilityFlag = skuInfo.purchasabilityFlag; 580 581 // Take out the price. Nicely formatted 582 // but also keep the price as a value in case it's 0 - we need to show "free" for that 583 pInfo->ui32Price= skuInfo.price; 584 ret = sceNpCommerce2GetPrice(m_contextId, pInfo->price, sizeof(pInfo->price), skuInfo.price); 585 if (ret < 0) 586 { 587 sceNpCommerce2DestroyGetProductInfoResult(&result); 588 m_errorCode = ret; 589 return ret; 590 } 591 } 592 593 // Set our result 594 //*info = tempInfo; 595 596 ret = sceNpCommerce2DestroyGetProductInfoResult(&result); 597 if (ret < 0) 598 { 599 return ret; 600 } 601 602 return ret; 603} 604 605 606int SonyCommerce_PS3::addDetailedProductInfo(ProductInfo *info, const char *productId, char *categoryId) 607{ 608 int ret = 0; 609 uint32_t requestId; 610 size_t bufSize = sizeof(m_commercebuffer); 611 size_t fillSize = 0; 612 std::list<SceNpCommerce2ContentRatingDescriptor> ratingDescList; 613 SceNpCommerce2GetProductInfoResult result; 614 SceNpCommerce2ContentRatingInfo ratingInfo; 615 SceNpCommerce2GameProductInfo productInfo; 616 SceNpCommerce2GameSkuInfo skuInfo; 617 //ProductInfoDetailed tempInfo; 618 619 if (!m_contextCreated) 620 { 621 ret = createContext(); 622 if (ret < 0) 623 { 624 m_errorCode = ret; 625 return ret; 626 } 627 } 628 629 // Obtain product data 630 ret = sceNpCommerce2GetProductInfoCreateReq(m_contextId, &requestId); 631 if (ret < 0) 632 { 633 m_errorCode = ret; 634 return ret; 635 } 636 637 if (categoryId && categoryId[0] != 0) 638 { 639 ret = sceNpCommerce2GetProductInfoStart(requestId, categoryId, productId); 640 } 641 else 642 { 643 ret = sceNpCommerce2GetProductInfoStart(requestId, categoryId, productId); 644 } 645 if (ret < 0) { 646 sceNpCommerce2DestroyReq(requestId); 647 m_errorCode = ret; 648 return ret; 649 } 650 651 ret = sceNpCommerce2GetProductInfoGetResult(requestId, m_commercebuffer, bufSize, &fillSize); 652 if (ret < 0) 653 { 654 sceNpCommerce2DestroyReq(requestId); 655 m_errorCode = ret; 656 return ret; 657 } 658 659 ret = sceNpCommerce2DestroyReq(requestId); 660 if (ret < 0) 661 { 662 m_errorCode = ret; 663 return ret; 664 } 665 666 // Take Out Game Product Information 667 ret = sceNpCommerce2InitGetProductInfoResult(&result, m_commercebuffer, fillSize); 668 if (ret < 0) 669 { 670 m_errorCode = ret; 671 return ret; 672 } 673 674 ret = sceNpCommerce2GetGameProductInfo(&result, &productInfo); 675 if (ret < 0) 676 { 677 sceNpCommerce2DestroyGetProductInfoResult(&result); 678 m_errorCode = ret; 679 return ret; 680 } 681 682 // Get rating info 683 ret = sceNpCommerce2GetContentRatingInfoFromGameProductInfo(&productInfo, &ratingInfo); 684 if (ret < 0) 685 { 686 sceNpCommerce2DestroyGetProductInfoResult(&result); 687 m_errorCode = ret; 688 return ret; 689 } 690 691 for (int index = 0; index < ratingInfo.countOfContentRatingDescriptor; index++) 692 { 693 SceNpCommerce2ContentRatingDescriptor desc; 694 sceNpCommerce2GetContentRatingDescriptor(&ratingInfo, index, &desc); 695 ratingDescList.push_back(desc); 696 } 697 698 // populate our temp struct 699// tempInfo.ratingDescriptors = ratingDescList; 700// strncpy(tempInfo.productId, productInfo.productId, SCE_NP_COMMERCE2_PRODUCT_ID_LEN); 701// strncpy(tempInfo.productName, productInfo.productName, SCE_NP_COMMERCE2_PRODUCT_NAME_LEN); 702// strncpy(tempInfo.shortDescription, productInfo.productShortDescription, SCE_NP_COMMERCE2_PRODUCT_SHORT_DESCRIPTION_LEN); 703 strncpy(info->longDescription, productInfo.productLongDescription, SCE_NP_COMMERCE2_PRODUCT_LONG_DESCRIPTION_LEN); 704// strncpy(tempInfo.legalDescription, productInfo.legalDescription, SCE_NP_COMMERCE2_PRODUCT_LEGAL_DESCRIPTION_LEN); 705// strncpy(tempInfo.spName, productInfo.spName, SCE_NP_COMMERCE2_SP_NAME_LEN); 706// strncpy(tempInfo.imageUrl, productInfo.imageUrl, SCE_NP_COMMERCE2_URL_LEN); 707// tempInfo.releaseDate = productInfo.releaseDate; 708// strncpy(tempInfo.ratingSystemId, ratingInfo.ratingSystemId, SCE_NP_COMMERCE2_RATING_SYSTEM_ID_LEN); 709// strncpy(tempInfo.ratingImageUrl, ratingInfo.imageUrl, SCE_NP_COMMERCE2_URL_LEN); 710 711 // Get SKU info 712 if (productInfo.countOfSku == 1) 713 { 714 ret = sceNpCommerce2GetGameSkuInfoFromGameProductInfo(&productInfo, 0, &skuInfo); 715 if (ret < 0) 716 { 717 sceNpCommerce2DestroyGetProductInfoResult(&result); 718 m_errorCode = ret; 719 return ret; 720 } 721 strncpy(info->skuId, skuInfo.skuId, SCE_NP_COMMERCE2_SKU_ID_LEN); 722 info->purchasabilityFlag = skuInfo.purchasabilityFlag; 723 info->annotation = skuInfo.annotation; 724 725 // Take out the price. Nicely formatted 726 // but also keep the price as a value in case it's 0 - we need to show "free" for that 727 info->ui32Price= skuInfo.price; 728 ret = sceNpCommerce2GetPrice(m_contextId, info->price, sizeof(info->price), skuInfo.price); 729 if (ret < 0) 730 { 731 sceNpCommerce2DestroyGetProductInfoResult(&result); 732 m_errorCode = ret; 733 return ret; 734 } 735 } 736 else 737 { 738 // 4J-PB - more than one sku id! We have to be able to use the sku id returned for a product, so there is not supposed to be more than 1 739 app.DebugPrintf("MORE THAN 1 SKU ID FOR %s\n",info->productName); 740 } 741 742 // Set our result 743 //*info = tempInfo; 744 745 ret = sceNpCommerce2DestroyGetProductInfoResult(&result); 746 if (ret < 0) 747 { 748 return ret; 749 } 750 751 return ret; 752} 753 754 755int SonyCommerce_PS3::checkout(CheckoutInputParams &params) 756{ 757 int ret = 0; 758 const char *skuIdsTemp[SCE_NP_COMMERCE2_SKU_CHECKOUT_MAX]; 759 std::list<const char *>::iterator iter = params.skuIds.begin(); 760 std::list<const char *>::iterator iterEnd = params.skuIds.end(); 761 762 if (!m_contextCreated) { 763 ret = createContext(); 764 if (ret < 0) { 765 return ret; 766 } 767 } 768 769 for (int i = 0; i < params.skuIds.size(); i++) { 770 skuIdsTemp[i] = (const char *)(*iter); 771 iter++; 772 } 773 774 ret = sceNpCommerce2DoCheckoutStartAsync(m_contextId, skuIdsTemp, params.skuIds.size(), *params.memContainer); 775 if (ret < 0) { 776 return ret; 777 } 778 779 return CELL_OK; 780} 781 782 783int SonyCommerce_PS3::downloadList(DownloadListInputParams &params) 784{ 785 int ret = 0; 786 const char *skuIdsTemp[SCE_NP_COMMERCE2_SKU_CHECKOUT_MAX]; 787 std::list<const char *>::iterator iter = params.skuIds.begin(); 788 std::list<const char *>::iterator iterEnd = params.skuIds.end(); 789 790 if (!m_contextCreated) { 791 ret = createContext(); 792 if (ret < 0) { 793 return ret; 794 } 795 } 796 797 for (int i = 0; i < params.skuIds.size(); i++) { 798 skuIdsTemp[i] = (const char *)(*iter); 799 iter++; 800 } 801 ret = sceNpCommerce2DoDlListStartAsync(m_contextId, app.GetCommerceCategory(), skuIdsTemp, params.skuIds.size(), *params.memContainer); 802 if (ret < 0) { 803 return ret; 804 } 805 806 return CELL_OK; 807} 808 809void SonyCommerce_PS3::UpgradeTrialCallback2(LPVOID lpParam,int err) 810{ 811 SonyCommerce* pCommerce = (SonyCommerce*)lpParam; 812 app.DebugPrintf(4,"SonyCommerce_UpgradeTrialCallback2 : err : 0x%08x\n", err); 813 pCommerce->CheckForTrialUpgradeKey(); 814 if(err != CELL_OK) 815 { 816 UINT uiIDA[1]; 817 uiIDA[0]=IDS_CONFIRM_OK; 818 C4JStorage::EMessageResult result = ui.RequestMessageBox( IDS_PRO_UNLOCKGAME_TITLE, IDS_NO_DLCOFFERS, uiIDA,1,ProfileManager.GetPrimaryPad()); 819 } 820 m_trialUpgradeCallbackFunc(m_trialUpgradeCallbackParam, m_errorCode); 821} 822 823void SonyCommerce_PS3::UpgradeTrialCallback1(LPVOID lpParam,int err) 824{ 825 SonyCommerce* pCommerce = (SonyCommerce*)lpParam; 826 app.DebugPrintf(4,"SonyCommerce_UpgradeTrialCallback1 : err : 0x%08x\n", err); 827 if(err == CELL_OK) 828 { 829 const char* skuID = s_trialUpgradeProductInfoDetailed.skuId; 830 if(s_trialUpgradeProductInfoDetailed.purchasabilityFlag == SCE_NP_COMMERCE2_SKU_PURCHASABILITY_FLAG_OFF) 831 { 832 app.DebugPrintf(4,"UpgradeTrialCallback1 - DownloadAlreadyPurchased\n"); 833 pCommerce->DownloadAlreadyPurchased(UpgradeTrialCallback2, pCommerce, skuID); 834 } 835 else 836 { 837 app.DebugPrintf(4,"UpgradeTrialCallback1 - Checkout\n"); 838 pCommerce->Checkout(UpgradeTrialCallback2, pCommerce, skuID); 839 } 840 } 841 else 842 { 843 UINT uiIDA[1]; 844 uiIDA[0]=IDS_CONFIRM_OK; 845 C4JStorage::EMessageResult result = ui.RequestMessageBox( IDS_PRO_UNLOCKGAME_TITLE, IDS_NO_DLCOFFERS, uiIDA,1,ProfileManager.GetPrimaryPad()); 846 m_trialUpgradeCallbackFunc(m_trialUpgradeCallbackParam, m_errorCode); 847 } 848} 849 850 851 852// global func, so we can call from the profile lib 853void SonyCommerce_UpgradeTrial() 854{ 855 // we're now calling the app function here, which manages pending requests 856 app.UpgradeTrial(); 857} 858 859void SonyCommerce_PS3::UpgradeTrial(CallbackFunc cb, LPVOID lpParam) 860{ 861 m_trialUpgradeCallbackFunc = cb; 862 m_trialUpgradeCallbackParam = lpParam; 863 864// static char szTrialUpgradeSkuID[64]; 865// sprintf(szTrialUpgradeSkuID, "%s-TRIALUPGRADE0001", app.GetCommerceCategory());//, szSKUSuffix); 866 GetDetailedProductInfo(UpgradeTrialCallback1, this, &s_trialUpgradeProductInfoDetailed, app.GetUpgradeKey(), app.GetCommerceCategory()); 867} 868 869 870int SonyCommerce_PS3::createContext() 871{ 872 SceNpId npId; 873 int ret = sceNpManagerGetNpId(&npId); 874 if(ret < 0) 875 { 876 app.DebugPrintf(4,"createContext sceNpManagerGetNpId problem\n"); 877 return ret; 878 } 879 880 if (m_contextCreated) { 881 ret = sceNpCommerce2DestroyCtx(m_contextId); 882 if (ret < 0) 883 { 884 app.DebugPrintf(4,"createContext sceNpCommerce2DestroyCtx problem\n"); 885 return ret; 886 } 887 } 888 889 // Create commerce2 context 890 ret = sceNpCommerce2CreateCtx(SCE_NP_COMMERCE2_VERSION, &npId, commerce2Handler, NULL, &m_contextId); 891 if (ret < 0) 892 { 893 app.DebugPrintf(4,"createContext sceNpCommerce2CreateCtx problem\n"); 894 return ret; 895 } 896 897 m_contextCreated = true; 898 899 return CELL_OK; 900} 901 902int SonyCommerce_PS3::createSession() 903{ 904 int ret = createContext(); 905 if (ret < 0) { 906 return ret; 907 } 908 909 m_currentPhase = e_phase_creatingSessionPhase; 910 ret = sceNpCommerce2CreateSessionStart(m_contextId); 911 if (ret < 0) { 912 return ret; 913 } 914 return ret; 915} 916 917 918void SonyCommerce_PS3::commerce2Handler(uint32_t contextId, uint32_t subjectId, int event, int errorCode, void *arg) 919{ 920// Event reply; 921// reply.service = Toolkit::NP::commerce; 922// 923 EnterCriticalSection(&m_queueLock); 924 925 switch (event) { 926 case SCE_NP_COMMERCE2_EVENT_REQUEST_ERROR: 927 { 928 m_messageQueue.push(e_message_commerceEnd); 929 m_errorCode = errorCode; 930 break; 931 } 932 case SCE_NP_COMMERCE2_EVENT_CREATE_SESSION_DONE: 933 { 934 m_messageQueue.push(e_message_commerceEnd); 935 m_event = e_event_commerceSessionCreated; 936 break; 937 } 938 case SCE_NP_COMMERCE2_EVENT_CREATE_SESSION_ABORT: 939 { 940 m_messageQueue.push(e_message_commerceEnd); 941 m_event = e_event_commerceSessionAborted; 942 break; 943 } 944 case SCE_NP_COMMERCE2_EVENT_DO_CHECKOUT_STARTED: 945 { 946 m_currentPhase = e_phase_checkoutPhase; 947 m_event = e_event_commerceCheckoutStarted; 948 break; 949 } 950 case SCE_NP_COMMERCE2_EVENT_DO_CHECKOUT_SUCCESS: 951 { 952 m_messageQueue.push(e_message_commerceEnd); 953 m_event = e_event_commerceCheckoutSuccess; 954 break; 955 } 956 case SCE_NP_COMMERCE2_EVENT_DO_CHECKOUT_BACK: 957 { 958 m_messageQueue.push(e_message_commerceEnd); 959 m_event = e_event_commerceCheckoutAborted; 960 break; 961 } 962 case SCE_NP_COMMERCE2_EVENT_DO_CHECKOUT_FINISHED: 963 { 964 m_event = e_event_commerceCheckoutFinished; 965 break; 966 } 967 case SCE_NP_COMMERCE2_EVENT_DO_DL_LIST_STARTED: 968 { 969 m_currentPhase = e_phase_downloadListPhase; 970 m_event = e_event_commerceDownloadListStarted; 971 break; 972 } 973 case SCE_NP_COMMERCE2_EVENT_DO_DL_LIST_SUCCESS: 974 { 975 m_messageQueue.push(e_message_commerceEnd); 976 m_event = e_event_commerceDownloadListSuccess; 977 break; 978 } 979 case SCE_NP_COMMERCE2_EVENT_DO_DL_LIST_FINISHED: 980 { 981 m_event = e_event_commerceDownloadListFinished; 982 break; 983 } 984 case SCE_NP_COMMERCE2_EVENT_DO_PROD_BROWSE_STARTED: 985 m_currentPhase = e_phase_productBrowsePhase; 986 m_event = e_event_commerceProductBrowseStarted; 987 break; 988 case SCE_NP_COMMERCE2_EVENT_DO_PROD_BROWSE_SUCCESS: 989 { 990 m_messageQueue.push(e_message_commerceEnd); 991 m_event = e_event_commerceProductBrowseSuccess; 992 break; 993 } 994 case SCE_NP_COMMERCE2_EVENT_DO_PROD_BROWSE_BACK: 995 { 996 m_messageQueue.push(e_message_commerceEnd); 997 m_event = e_event_commerceProductBrowseAborted; 998 break; 999 } 1000 case SCE_NP_COMMERCE2_EVENT_DO_PROD_BROWSE_FINISHED: 1001 { 1002 m_event = e_event_commerceProductBrowseFinished; 1003 break; 1004 } 1005 case SCE_NP_COMMERCE2_EVENT_DO_PROD_BROWSE_OPENED: 1006 break; 1007 case SCE_NP_COMMERCE2_EVENT_DO_PRODUCT_CODE_STARTED: 1008 { 1009 m_currentPhase = e_phase_voucherRedeemPhase; 1010 m_event = e_event_commerceVoucherInputStarted; 1011 break; 1012 } 1013 case SCE_NP_COMMERCE2_EVENT_DO_PRODUCT_CODE_SUCCESS: 1014 { 1015 m_messageQueue.push(e_message_commerceEnd); 1016 m_event = e_event_commerceVoucherInputSuccess; 1017 break; 1018 } 1019 case SCE_NP_COMMERCE2_EVENT_DO_PRODUCT_CODE_BACK: 1020 { 1021 m_messageQueue.push(e_message_commerceEnd); 1022 m_event = e_event_commerceVoucherInputAborted; 1023 break; 1024 } 1025 case SCE_NP_COMMERCE2_EVENT_DO_PRODUCT_CODE_FINISHED: 1026 { 1027 m_event = e_event_commerceVoucherInputFinished; 1028 break; 1029 } 1030 default: 1031 break; 1032 }; 1033 1034 LeaveCriticalSection(&m_queueLock); 1035} 1036 1037 1038 1039void SonyCommerce_PS3::processMessage() 1040{ 1041 EnterCriticalSection(&m_queueLock); 1042 int ret; 1043 if(m_messageQueue.empty()) 1044 { 1045 LeaveCriticalSection(&m_queueLock); 1046 return; 1047 } 1048 Message msg = m_messageQueue.front(); 1049 m_messageQueue.pop(); 1050 1051 switch (msg) 1052 { 1053 1054 case e_message_commerceCreateSession: 1055 ret = createSession(); 1056 if (ret < 0) 1057 { 1058 m_event = e_event_commerceError; 1059 m_errorCode = ret; 1060 } 1061 break; 1062 1063 case e_message_commerceGetCategoryInfo: 1064 { 1065 ret = getCategoryInfo(m_pCategoryInfo, m_pCategoryID); 1066 if (ret < 0) 1067 { 1068 m_event = e_event_commerceError; 1069 app.DebugPrintf(4,"ERROR - e_event_commerceGotCategoryInfo - %s\n",m_pCategoryID); 1070 m_errorCode = ret; 1071 } 1072 else 1073 { 1074 m_event = e_event_commerceGotCategoryInfo; 1075 app.DebugPrintf(4,"e_event_commerceGotCategoryInfo - %s\n",m_pCategoryID); 1076 } 1077 break; 1078 } 1079 1080 case e_message_commerceGetProductList: 1081 { 1082 ret = getProductList(m_pProductInfoList, m_pCategoryID); 1083 if (ret < 0) 1084 { 1085 m_event = e_event_commerceError; 1086 } 1087 else 1088 { 1089 m_event = e_event_commerceGotProductList; 1090 app.DebugPrintf(4,"e_event_commerceGotProductList - %s\n",m_pCategoryID); 1091 } 1092 break; 1093 } 1094 1095 case e_message_commerceGetDetailedProductInfo: 1096 { 1097 ret = getDetailedProductInfo(m_pProductInfoDetailed, m_pProductID, m_pCategoryID); 1098 if (ret < 0) 1099 { 1100 m_event = e_event_commerceError; 1101 m_errorCode = ret; 1102 } 1103 else 1104 { 1105 m_event = e_event_commerceGotDetailedProductInfo; 1106 app.DebugPrintf(4,"e_event_commerceGotDetailedProductInfo - %s\n",m_pCategoryID); 1107 } 1108 break; 1109 } 1110 case e_message_commerceAddDetailedProductInfo: 1111 { 1112 ret = addDetailedProductInfo(m_pProductInfo, m_pProductID, m_pCategoryID); 1113 if (ret < 0) 1114 { 1115 m_event = e_event_commerceError; 1116 m_errorCode = ret; 1117 } 1118 else 1119 { 1120 m_event = e_event_commerceAddedDetailedProductInfo; 1121 } 1122 break; 1123 } 1124 1125// 1126// case e_message_commerceStoreProductBrowse: 1127// { 1128// ret = productBrowse(*(ProductBrowseParams *)msg.inputArgs); 1129// if (ret < 0) { 1130// m_event = e_event_commerceError; 1131// m_errorCode = ret; 1132// } 1133// _TOOLKIT_NP_DEL (ProductBrowseParams *)msg.inputArgs; 1134// break; 1135// } 1136// 1137// case e_message_commerceUpgradeTrial: 1138// { 1139// ret = upgradeTrial(); 1140// if (ret < 0) { 1141// m_event = e_event_commerceError; 1142// m_errorCode = ret; 1143// } 1144// break; 1145// } 1146// 1147// case e_message_commerceRedeemVoucher: 1148// { 1149// ret = voucherCodeInput(*(VoucherInputParams *)msg.inputArgs); 1150// if (ret < 0) { 1151// m_event = e_event_commerceError; 1152// m_errorCode = ret; 1153// } 1154// _TOOLKIT_NP_DEL (VoucherInputParams *)msg.inputArgs; 1155// break; 1156// } 1157// 1158// case e_message_commerceGetEntitlementList: 1159// { 1160// Job<std::vector<SceNpEntitlement> > tmpJob(static_cast<Future<std::vector<SceNpEntitlement> > *>(msg.output)); 1161// 1162// int state = 0; 1163// int ret = sceNpManagerGetStatus(&state); 1164// 1165// // We don't want to process this if we are offline 1166// if (ret < 0 || state != SCE_NP_MANAGER_STATUS_ONLINE) { 1167// m_event = e_event_commerceError; 1168// reply.returnCode = SCE_TOOLKIT_NP_OFFLINE; 1169// tmpJob.setError(SCE_TOOLKIT_NP_OFFLINE); 1170// } else { 1171// getEntitlementList(&tmpJob); 1172// } 1173// break; 1174// } 1175// 1176// case e_message_commerceConsumeEntitlement: 1177// { 1178// int state = 0; 1179// int ret = sceNpManagerGetStatus(&state); 1180// 1181// // We don't want to process this if we are offline 1182// if (ret < 0 || state != SCE_NP_MANAGER_STATUS_ONLINE) { 1183// m_event = e_event_commerceError; 1184// reply.returnCode = SCE_TOOLKIT_NP_OFFLINE; 1185// } else { 1186// 1187// ret = consumeEntitlement(*(EntitlementToConsume *)msg.inputArgs); 1188// if (ret < 0) { 1189// m_event = e_event_commerceError; 1190// m_errorCode = ret; 1191// } else { 1192// m_event = e_event_commerceConsumedEntitlement; 1193// } 1194// } 1195// _TOOLKIT_NP_DEL (EntitlementToConsume *)msg.inputArgs; 1196// 1197// break; 1198// } 1199// 1200 case e_message_commerceCheckout: 1201 { 1202 ret = checkout(m_checkoutInputParams); 1203 if (ret < 0) { 1204 m_event = e_event_commerceError; 1205 m_errorCode = ret; 1206 } 1207 break; 1208 } 1209 1210 case e_message_commerceDownloadList: 1211 { 1212 ret = downloadList(m_downloadInputParams); 1213 if (ret < 0) { 1214 m_event = e_event_commerceError; 1215 m_errorCode = ret; 1216 } 1217 break; 1218 } 1219 1220 case e_message_commerceEnd: 1221 app.DebugPrintf("XXX - e_message_commerceEnd!\n"); 1222 ret = commerceEnd(); 1223 if (ret < 0) 1224 { 1225 m_event = e_event_commerceError; 1226 m_errorCode = ret; 1227 } 1228 // 4J-PB - we don't seem to handle the error code here 1229 else if(m_errorCode!=0) 1230 { 1231 m_event = e_event_commerceError; 1232 } 1233 break; 1234 1235 default: 1236 break; 1237 } 1238 1239 LeaveCriticalSection(&m_queueLock); 1240} 1241 1242 1243void SonyCommerce_PS3::processEvent() 1244{ 1245 int ret = 0; 1246 1247 switch (m_event) 1248 { 1249 case e_event_none: 1250 break; 1251 case e_event_commerceSessionCreated: 1252 app.DebugPrintf(4,"Commerce Session Created.\n"); 1253 runCallback(); 1254 break; 1255 case e_event_commerceSessionAborted: 1256 app.DebugPrintf(4,"Commerce Session aborted.\n"); 1257 runCallback(); 1258 break; 1259 case e_event_commerceGotProductList: 1260 app.DebugPrintf(4,"Got product list.\n"); 1261 runCallback(); 1262 break; 1263 case e_event_commerceGotCategoryInfo: 1264 app.DebugPrintf(4,"Got category info\n"); 1265 runCallback(); 1266 break; 1267 case e_event_commerceGotDetailedProductInfo: 1268 app.DebugPrintf(4,"Got detailed product info.\n"); 1269 runCallback(); 1270 break; 1271 case e_event_commerceAddedDetailedProductInfo: 1272 app.DebugPrintf(4,"Added detailed product info.\n"); 1273 runCallback(); 1274 break; 1275 case e_event_commerceProductBrowseStarted: 1276 break; 1277 case e_event_commerceProductBrowseSuccess: 1278 break; 1279 case e_event_commerceProductBrowseAborted: 1280 break; 1281 case e_event_commerceProductBrowseFinished: 1282 assert(0); 1283// ret = sys_memory_container_destroy(s_memContainer); 1284// if (ret < 0) { 1285// printf("Failed to destroy memory container"); 1286// } 1287// s_memContainer = SYS_MEMORY_CONTAINER_ID_INVALID; 1288 break; 1289 case e_event_commerceVoucherInputStarted: 1290 break; 1291 case e_event_commerceVoucherInputSuccess: 1292 break; 1293 case e_event_commerceVoucherInputAborted: 1294 break; 1295 case e_event_commerceVoucherInputFinished: 1296 assert(0); 1297// ret = sys_memory_container_destroy(s_memContainer); 1298// if (ret < 0) { 1299// printf("Failed to destroy memory container"); 1300// } 1301// s_memContainer = SYS_MEMORY_CONTAINER_ID_INVALID; 1302 break; 1303 case e_event_commerceGotEntitlementList: 1304 break; 1305 case e_event_commerceConsumedEntitlement: 1306 break; 1307 case e_event_commerceCheckoutStarted: 1308 app.DebugPrintf(4,"Checkout Started\n"); 1309 break; 1310 case e_event_commerceCheckoutSuccess: 1311 app.DebugPrintf(4,"Checkout succeeded: 0x%x\n", m_errorCode); 1312 // clear the DLC installed and check again 1313 app.ClearDLCInstalled(); 1314 ui.HandleDLCInstalled(0); 1315 break; 1316 case e_event_commerceCheckoutAborted: 1317 app.DebugPrintf(4,"Checkout aborted: 0x%x\n", m_errorCode); 1318 break; 1319 case e_event_commerceCheckoutFinished: 1320 app.DebugPrintf(4,"Checkout Finished: 0x%x\n", m_errorCode); 1321 ret = sys_memory_container_destroy(m_memContainer); 1322 if (ret < 0) { 1323 app.DebugPrintf(4,"Failed to destroy memory container"); 1324 } 1325 1326 m_memContainer = SYS_MEMORY_CONTAINER_ID_INVALID; 1327 // 4J-PB - if there's been an error - like dlc already purchased, the runcallback has already happened, and will crash this time 1328 if(m_callbackFunc!=NULL) 1329 { 1330 runCallback(); 1331 } 1332 break; 1333 case e_event_commerceDownloadListStarted: 1334 app.DebugPrintf(4,"Download List Started\n"); 1335 break; 1336 case e_event_commerceDownloadListSuccess: 1337 app.DebugPrintf(4,"Download succeeded: 0x%x\n", m_errorCode); 1338 // 4J-PB - they may or may not have downloaded DLC 1339 // clear the DLC installed and check again 1340 app.ClearDLCInstalled(); 1341 ui.HandleDLCInstalled(0); 1342 break; 1343 case e_event_commerceDownloadListFinished: 1344 app.DebugPrintf(4,"Download Finished: 0x%x\n", m_errorCode); 1345 ret = sys_memory_container_destroy(m_memContainer); 1346 if (ret < 0) { 1347 app.DebugPrintf(4,"Failed to destroy memory container"); 1348 } 1349 1350 m_memContainer = SYS_MEMORY_CONTAINER_ID_INVALID; 1351 // 4J-PB - if there's been an error - like dlc already purchased, the runcallback has already happened, and will crash this time 1352 if(m_callbackFunc!=NULL) 1353 { 1354 runCallback(); 1355 } 1356 break; 1357 case e_event_commerceError: 1358 app.DebugPrintf(4,"Commerce Error 0x%x\n", m_errorCode); 1359 1360 if(m_memContainer != SYS_MEMORY_CONTAINER_ID_INVALID) 1361 { 1362 ret = sys_memory_container_destroy(m_memContainer); 1363 if (ret < 0) { 1364 app.DebugPrintf(4,"Failed to destroy memory container"); 1365 } 1366 1367 m_memContainer = SYS_MEMORY_CONTAINER_ID_INVALID; 1368 } 1369 1370 runCallback(); 1371 break; 1372 default: 1373 break; 1374 } 1375 m_event = e_event_none; 1376} 1377 1378 1379int SonyCommerce_PS3::commerceEnd() 1380{ 1381 int ret = 0; 1382 1383 if (m_currentPhase == e_phase_voucherRedeemPhase) 1384 ret = sceNpCommerce2DoProductCodeFinishAsync(m_contextId); 1385 else if (m_currentPhase == e_phase_productBrowsePhase) 1386 ret = sceNpCommerce2DoProductBrowseFinishAsync(m_contextId); 1387 else if (m_currentPhase == e_phase_creatingSessionPhase) 1388 ret = sceNpCommerce2CreateSessionFinish(m_contextId, &m_sessionInfo); 1389 else if (m_currentPhase == e_phase_checkoutPhase) 1390 ret = sceNpCommerce2DoCheckoutFinishAsync(m_contextId); 1391 else if (m_currentPhase == e_phase_downloadListPhase) 1392 ret = sceNpCommerce2DoDlListFinishAsync(m_contextId); 1393 1394 m_currentPhase = e_phase_idle; 1395 1396 return ret; 1397} 1398 1399void SonyCommerce_PS3::CreateSession( CallbackFunc cb, LPVOID lpParam ) 1400{ 1401 // 4J-PB - reset any previous error code 1402 // I had this happen when I was offline on Vita, and accepted the PSN sign-in 1403 // the m_errorCode was picked up in the message queue after the commerce init call 1404 if(m_errorCode!=0) 1405 { 1406 app.DebugPrintf("m_errorCode was set!\n"); 1407 m_errorCode=0; 1408 } 1409 Init(); 1410 EnterCriticalSection(&m_queueLock); 1411 setCallback(cb,lpParam); 1412 m_messageQueue.push(e_message_commerceCreateSession); 1413 if(m_tickThread == NULL) 1414 m_tickThread = new C4JThread(TickLoop, NULL, "SonyCommerce_PS3 tick"); 1415 if(m_tickThread->isRunning() == false) 1416 { 1417 m_currentPhase = e_phase_idle; 1418 m_tickThread->Run(); 1419 } 1420 LeaveCriticalSection(&m_queueLock); 1421} 1422 1423void SonyCommerce_PS3::CloseSession() 1424{ 1425 assert(m_currentPhase == e_phase_idle); 1426 m_currentPhase = e_phase_stopped; 1427 Shutdown(); 1428} 1429 1430void SonyCommerce_PS3::GetProductList( CallbackFunc cb, LPVOID lpParam, std::vector<ProductInfo>* productList, const char *categoryId) 1431{ 1432 EnterCriticalSection(&m_queueLock); 1433 setCallback(cb,lpParam); 1434 m_pProductInfoList = productList; 1435 strcpy(m_pCategoryID,categoryId); 1436 m_messageQueue.push(e_message_commerceGetProductList); 1437 LeaveCriticalSection(&m_queueLock); 1438} 1439 1440void SonyCommerce_PS3::GetDetailedProductInfo( CallbackFunc cb, LPVOID lpParam, ProductInfoDetailed* productInfo, const char *productId, const char *categoryId ) 1441{ 1442 EnterCriticalSection(&m_queueLock); 1443 setCallback(cb,lpParam); 1444 m_pProductInfoDetailed = productInfo; 1445 m_pProductID = productId; 1446 strcpy(m_pCategoryID,categoryId); 1447 m_messageQueue.push(e_message_commerceGetDetailedProductInfo); 1448 LeaveCriticalSection(&m_queueLock); 1449} 1450 1451// 4J-PB - fill out the long description and the price for the product 1452void SonyCommerce_PS3::AddDetailedProductInfo( CallbackFunc cb, LPVOID lpParam, ProductInfo* productInfo, const char *productId, const char *categoryId ) 1453{ 1454 EnterCriticalSection(&m_queueLock); 1455 setCallback(cb,lpParam); 1456 m_pProductInfo = productInfo; 1457 m_pProductID = productId; 1458 strcpy(m_pCategoryID,categoryId); 1459 m_messageQueue.push(e_message_commerceAddDetailedProductInfo); 1460 LeaveCriticalSection(&m_queueLock); 1461} 1462void SonyCommerce_PS3::GetCategoryInfo( CallbackFunc cb, LPVOID lpParam, CategoryInfo *info, const char *categoryId ) 1463{ 1464 EnterCriticalSection(&m_queueLock); 1465 setCallback(cb,lpParam); 1466 m_pCategoryInfo = info; 1467 strcpy(m_pCategoryID,categoryId); 1468 m_messageQueue.push(e_message_commerceGetCategoryInfo); 1469 LeaveCriticalSection(&m_queueLock); 1470} 1471 1472void SonyCommerce_PS3::Checkout( CallbackFunc cb, LPVOID lpParam, const char* skuID ) 1473{ 1474 if(m_memContainer != SYS_MEMORY_CONTAINER_ID_INVALID) 1475 { 1476 return; 1477 } 1478 EnterCriticalSection(&m_queueLock); 1479 setCallback(cb,lpParam); 1480 int ret = sys_memory_container_create(&m_memContainer, SCE_NP_COMMERCE2_DO_CHECKOUT_MEMORY_CONTAINER_SIZE); 1481 if (ret < 0) 1482 { 1483 app.DebugPrintf(4,"sys_memory_container_create() failed. ret = 0x%x\n", ret); 1484 } 1485 1486 m_checkoutInputParams.memContainer = &m_memContainer; 1487 m_checkoutInputParams.skuIds.clear(); 1488 m_checkoutInputParams.skuIds.push_back(skuID); 1489 m_messageQueue.push(e_message_commerceCheckout); 1490 LeaveCriticalSection(&m_queueLock); 1491} 1492 1493void SonyCommerce_PS3::DownloadAlreadyPurchased( CallbackFunc cb, LPVOID lpParam, const char* skuID ) 1494{ 1495 if(m_memContainer != SYS_MEMORY_CONTAINER_ID_INVALID) 1496 return; 1497 EnterCriticalSection(&m_queueLock); 1498 setCallback(cb,lpParam); 1499 int ret = sys_memory_container_create(&m_memContainer, SCE_NP_COMMERCE2_DO_CHECKOUT_MEMORY_CONTAINER_SIZE); 1500 if (ret < 0) 1501 { 1502 app.DebugPrintf(4,"sys_memory_container_create() failed. ret = 0x%x\n", ret); 1503 } 1504 1505 m_downloadInputParams.memContainer = &m_memContainer; 1506 m_downloadInputParams.skuIds.clear(); 1507 m_downloadInputParams.skuIds.push_back(skuID); 1508 m_messageQueue.push(e_message_commerceDownloadList); 1509 LeaveCriticalSection(&m_queueLock); 1510} 1511 1512 1513