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