the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 180 lines 8.7 kB view raw
1#pragma once 2 3#include <stdio.h> 4#include <stdlib.h> 5#include <string.h> 6#include <np.h> 7#include <np/drm.h> 8#include <np/commerce2.h> 9#include "Common\Network\Sony\SonyCommerce.h" 10 11#define SCE_TOOLKIT_NP_SKU_PRICE_LEN (SCE_NP_COMMERCE2_CURRENCY_CODE_LEN \ 12 + SCE_NP_COMMERCE2_CURRENCY_SYMBOL_LEN \ 13 + SCE_NP_COMMERCE2_THOUSAND_SEPARATOR_LEN \ 14 + SCE_NP_COMMERCE2_DECIMAL_LETTER_LEN) ///< The maximum length of a price in characters. 15 16class SonyCommerce_PS3 : public SonyCommerce 17{ 18 enum State 19 { 20 e_state_noSession, 21 e_state_creatingSession, 22 e_state_createSessionDone, 23 e_state_idle, 24 25 26 }; 27 /// This enum is used to verify the current utility that is running 28 enum Phase 29 { 30 e_phase_stopped = 0, 31 e_phase_idle, 32 e_phase_voucherRedeemPhase, 33 e_phase_productBrowsePhase, 34 e_phase_creatingSessionPhase, 35 e_phase_checkoutPhase, 36 e_phase_downloadListPhase 37 }; 38 39 enum Message 40 { 41 e_message_commerceNone, 42 e_message_commerceCreateSession, ///< Create a commerce session 43 e_message_commerceGetCategoryInfo, ///< Information about a category in the Store 44 e_message_commerceGetProductList, ///< Get a list of products available in the Store 45 e_message_commerceGetDetailedProductInfo, ///< Get a list of products available in the Store, with additional details 46 e_message_commerceAddDetailedProductInfo, ///< Add additional details to a ProdcutInfo already retrieved 47 e_message_commerceStoreProductBrowse, ///< Launches the Store to a specified product 48 e_message_commerceUpgradeTrial, ///< Upgrade a trial to full game 49 e_message_commerceRedeemVoucher, ///< Redeem a voucher code 50 e_message_commerceGetEntitlementList, ///< Get a list of entitlements associated with the current PSN user. 51 e_message_commerceConsumeEntitlement, ///< Consume an amount from a consumable entitlement. 52 e_message_commerceCheckout, ///< Launch the Store checkout 53 e_message_commerceDownloadList, ///< Launch the download list 54 e_message_commerceEnd ///< End commerce2 processing 55 }; 56 57 enum Event 58 { 59 e_event_none, 60 e_event_commerceSessionCreated, ///< An event generated when a commerce session has successfully been created. 61 e_event_commerceSessionAborted, ///< An event generated when the creation of commerce session has been aborted. 62 e_event_commerceGotCategoryInfo, ///< An event generated when some category information has been retrieved from the store. 63 e_event_commerceGotProductList, ///< An event generated when a list of products that are available has been retrieved from the store. 64 e_event_commerceGotDetailedProductInfo, ///< An event generated when some detailed product information has been retrieved from the store. 65 e_event_commerceAddedDetailedProductInfo, ///< An event generated when some detailed product information has been retrieved from the store. 66 e_event_commerceProductBrowseStarted, ///< An event generated when product overlay has started. 67 e_event_commerceProductBrowseSuccess, ///< An event generated when a product browse was completed successfully, and the user purchased the product. 68 e_event_commerceProductBrowseAborted, ///< An event generated when a product browse was aborted by the user (the user pressed back). 69 e_event_commerceProductBrowseFinished, ///< An event generated when a product browse has finished and it is now safe to free memory. 70 e_event_commerceVoucherInputStarted, ///< An event generated when a voucher code input overlay was started. 71 e_event_commerceVoucherInputSuccess, ///< An event generated when a voucher code input completed successfully. 72 e_event_commerceVoucherInputAborted, ///< An event generated when a voucher code input was aborted by the user (user pressed back). 73 e_event_commerceVoucherInputFinished, ///< An event generated when a voucher code input has finished. It is now safe to free memory. 74 e_event_commerceGotEntitlementList, ///< An event generated when a the list of entitlements has been received for the current user. 75 e_event_commerceConsumedEntitlement, ///< An event generated when the has successfully consumed an entitlement. 76 e_event_commerceCheckoutStarted, ///< An event generated when a store checkout overlay has started. 77 e_event_commerceCheckoutSuccess, ///< An event generated when user has successfully purchased from the checkout. 78 e_event_commerceCheckoutAborted, ///< An event generated when the checkout was aborted by the user (user pressed back). 79 e_event_commerceCheckoutFinished, ///< An event generated when a store checkout overlay has finished. 80 e_event_commerceDownloadListStarted, ///< An event generated when a download list overlay has started. 81 e_event_commerceDownloadListSuccess, ///< An event generated when the user has ended the download list. 82 e_event_commerceDownloadListFinished, ///< An event generated when a download list overlay has finished. 83 e_event_commerceError ///< An event generated when a commerce error has occurred. 84 }; 85 86 static bool m_bLicenseChecked; 87 static bool m_bCommerceInitialised; 88 static SceNpCommerce2SessionInfo m_sessionInfo; 89 static State m_state; 90 static int m_errorCode; 91 static LPVOID m_callbackParam; 92 static Event m_event; 93 static Message m_message; 94// static uint32_t m_requestID; 95 static void* m_receiveBuffer; 96 static std::vector<ProductInfo> *m_pProductInfoList; 97 static ProductInfoDetailed *m_pProductInfoDetailed; 98 static ProductInfo *m_pProductInfo; 99 static CategoryInfo* m_pCategoryInfo; 100 static char* m_pCategoryID; 101 static const char* m_pProductID; 102 static std::queue<Message> m_messageQueue; 103 static CallbackFunc m_callbackFunc; 104 static CheckoutInputParams m_checkoutInputParams; 105 static DownloadListInputParams m_downloadInputParams; 106 static sys_memory_container_t m_memContainer; 107 static bool m_bUpgradingTrial; 108 static C4JThread* m_tickThread; 109 static CallbackFunc m_trialUpgradeCallbackFunc; 110 static LPVOID m_trialUpgradeCallbackParam; 111 static CRITICAL_SECTION m_queueLock; 112 113 static void runCallback() 114 { 115 assert(m_callbackFunc); 116 CallbackFunc func = m_callbackFunc; 117 m_callbackFunc = NULL; 118 if(func) 119 func(m_callbackParam, m_errorCode); 120 m_errorCode = CELL_OK; 121 } 122 static void setCallback(CallbackFunc cb,LPVOID lpParam) 123 { 124 assert(m_callbackFunc == NULL); 125 m_callbackFunc = cb; 126 m_callbackParam = lpParam; 127 } 128 129 130 static uint32_t m_contextId; ///< The npcommerce2 context ID 131 static bool m_contextCreated; ///< npcommerce2 context ID created? 132 static Phase m_currentPhase; ///< Current commerce2 util 133 static char m_commercebuffer[SCE_NP_COMMERCE2_RECV_BUF_SIZE]; 134 135 136 137 static void commerce2Handler(uint32_t contextId, uint32_t subjectId, int event, int errorCode, void *arg); 138 static void processMessage(); 139 static void processEvent(); 140 141 static int createContext(); 142 static int createSession(); 143 static void setError(int err) { m_errorCode = err; } 144 static int getCategoryInfo(CategoryInfo *info, char *categoryId); 145 static int getProductList(std::vector<ProductInfo>* productList, char *categoryId); 146 static int getDetailedProductInfo(ProductInfoDetailed *info, const char *productId, char *categoryId); 147 static int addDetailedProductInfo(ProductInfo *info, const char *productId, char *categoryId); 148 static int checkout(CheckoutInputParams &params); 149 static int downloadList(DownloadListInputParams &params); 150 static void UpgradeTrialCallback1(LPVOID lpParam,int err); 151 static void UpgradeTrialCallback2(LPVOID lpParam,int err); 152 static void Delete(); 153 154 155 static int commerceEnd(); 156// static int upgradeTrial(); 157 158 static int TickLoop(void* lpParam); 159 160 static void Init(); 161 static int Shutdown(); 162 163 static void CheckForTrialUpgradeKey_Callback(LPVOID param, bool bFullVersion); 164 165public: 166 167 virtual void CreateSession(CallbackFunc cb, LPVOID lpParam); 168 virtual void CloseSession(); 169 170 virtual void GetCategoryInfo(CallbackFunc cb, LPVOID lpParam, CategoryInfo *info, const char *categoryId); 171 virtual void GetProductList(CallbackFunc cb, LPVOID lpParam, std::vector<ProductInfo>* productList, const char *categoryId); 172 virtual void GetDetailedProductInfo(CallbackFunc cb, LPVOID lpParam, ProductInfoDetailed* productInfoDetailed, const char *productId, const char *categoryId); 173 virtual void AddDetailedProductInfo( CallbackFunc cb, LPVOID lpParam, ProductInfo* productInfo, const char *productId, const char *categoryId ); 174 virtual void Checkout(CallbackFunc cb, LPVOID lpParam, const char* skuID); 175 virtual void DownloadAlreadyPurchased(CallbackFunc cb, LPVOID lpParam, const char* skuID); 176 virtual void UpgradeTrial(CallbackFunc cb, LPVOID lpParam); 177 virtual void CheckForTrialUpgradeKey(); 178 virtual bool LicenseChecked(); 179 180};