aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PSVita/4JLibs/inc/4J_Profile.h
blob: 4c1f4e013201f5a7357479bfda28974dd1d37c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#pragma once
#include <np/np_common.h>
#include <np_toolkit.h>
#include <np.h>
#include <message_dialog.h>

using namespace sce::Toolkit::NP;
using namespace sce::Toolkit::NP::Utilities;

class CXuiStringTable;

// Note - there are now 3 types of PlayerUID
// (1) A full online ID - either the primary login, or a sub-signin through to PSN. This has m_onlineID set up as a normal SceNpOnlineId, with dummy[0] set to 0
// (2) An offline ID, where there is also a primary login on the system. This has m_onlineID set up to copy the primary SceNpOnlineId, except with dummy[0] set to the controller ID of this other player
// (3) An offline ID, where there isn't a primary PSN login on the system. This has SceNpOnlineId fully zeroed.

class PlayerUID
{
	char m_onlineID[SCE_NP_ONLINEID_MAX_LENGTH];
	char term;
	bool m_bSignedIntoPSN : 1;
	unsigned char m_quadrant : 2;
	uint8_t m_macAddress[SCE_NET_ETHER_ADDR_LEN];
	int	m_userID;		// user logged on to the XMB

public:

	class Hash 
	{
	public:		
		std::size_t operator()(const PlayerUID& k) const;
	};

	PlayerUID();
	PlayerUID(int userID, SceNpOnlineId& onlineID, bool bSignedInPSN, int quadrant);
	PlayerUID(std::wstring fromString);

	bool operator==(const PlayerUID& rhs) const;
	bool operator!=(const PlayerUID& rhs);
	void setCurrentMacAddress();
	std::wstring macAddressStr() const;
	std::wstring userIDStr() const;
	std::wstring toString() const;
	void setOnlineID(SceNpOnlineId& id, bool bSignedIntoPSN);
	void setUserID(unsigned int id);


	const char*			getOnlineID() const		{ return m_onlineID; }
	int					getUserID() const		{ return m_userID; }
	int					getQuadrant() const		{ return m_quadrant;  }
	bool				isPrimaryUser() const;	// only true if we're on the local machine and signed into the first quadrant;
	bool				isSignedIntoPSN() const	{ return m_bSignedIntoPSN; }
	void				setForAdhoc();
private:
};

typedef PlayerUID *PPlayerUID;

class GameSessionUID
{
	char m_onlineID[SCE_NP_ONLINEID_MAX_LENGTH];
	char term;
	bool m_bSignedIntoPSN : 1;
	unsigned char m_quadrant : 2;
public:
	GameSessionUID();
	GameSessionUID(int nullVal);

	bool operator==(const GameSessionUID& rhs) const;
	bool operator!=(const GameSessionUID& rhs);
	GameSessionUID& operator=(const PlayerUID& rhs);

	const char*			getOnlineID() const		{ return m_onlineID; }
	int					getQuadrant() const		{ return m_quadrant;  }
	bool				isSignedIntoPSN() const	{ return m_bSignedIntoPSN; }
	void				setForAdhoc();

};

enum eAwardType
{
	eAwardType_Achievement	= 0,
	eAwardType_GamerPic,
	eAwardType_Theme,
	eAwardType_AvatarItem,
};

enum eUpsellType
{
	eUpsellType_Custom = 0, // This is the default, and means that the upsell dialog was initiated in the app code
	eUpsellType_Achievement,
	eUpsellType_GamerPic,
	eUpsellType_Theme,
	eUpsellType_AvatarItem,
};

enum eUpsellResponse
{
	eUpsellResponse_Declined,
	eUpsellResponse_Accepted_NoPurchase,
	eUpsellResponse_Accepted_Purchase,
	eUpsellResponse_UserNotSignedInPSN
};

class C_4JProfile
{
public:

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// INIT
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 4 players have game defined data, puiGameDefinedDataChangedBitmask needs to be checked by the game side to see if there's an update needed - it'll have the bits set for players to be updated
	void				Initialise( const SceNpCommunicationConfig _commsId,
									const std::string _serviceID,
									unsigned short usProfileVersion,
									UINT uiProfileValuesC,
									UINT uiProfileSettingsC,
									DWORD *pdwProfileSettingsA, 
									int iGameDefinedDataSizeX4,
									unsigned int *puiGameDefinedDataChangedBitmask); 

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// SIGN-IN/USERS
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	bool				IsSignedIn(int iQuadrant);
	bool				IsSignedInLive(int iProf);
	bool				IsSignedInPSN(int iProf);
	bool				IsGuest(int iQuadrant);
	UINT				RequestSignInUI(bool bFromInvite,bool bLocalGame,bool bNoGuestsAllowed,bool bMultiplayerSignIn,bool bAddUser, int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant=XUSER_INDEX_ANY);
	UINT				DisplayOfflineProfile(int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant=XUSER_INDEX_ANY);
	UINT				RequestConvertOfflineToGuestUI(int( *Func)(LPVOID,const bool, const int iPad),LPVOID lpParam,int iQuadrant=XUSER_INDEX_ANY);
	void				SetPrimaryPlayerChanged(bool bVal);								
	bool				QuerySigninStatus(void);
	void				GetXUID(int iPad, PlayerUID *pXuid,bool bOnlineXuid);
	BOOL				AreXUIDSEqual(PlayerUID xuid1,PlayerUID xuid2);
	void				GetSceNpId(int iPad, SceNpId *npId);
	DWORD				GetSignedInUsersMask();
	void				SetNetworkStatus(bool bOnlinePSN, bool bSignedInPSN);

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// MISC
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	int					GetLockedProfile();
	void				SetLockedProfile(int iProf);
	void				SetGetStringFunc(LPCWSTR ( *Func)(int));
	void				SetPlayerListTitleID(int id);
	bool				AllowedToPlayMultiplayer(int iProf);
	bool				HasPlayStationPlus(int iProf);
	void				StartTrialGame(); // disables saves and leaderboard, and change state to readyforgame from pregame
	void				AllowedPlayerCreatedContent(int iPad, bool thisQuadrantOnly, BOOL *allAllowed, BOOL *friendsAllowed);
	BOOL				CanViewPlayerCreatedContent(int iPad, bool thisQuadrantOnly, PPlayerUID pXuids, DWORD dwXuidCount );
	void				ResetProfileProcessState(); // after a sign out from the primary player, call this	
	void				Tick( void );

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// AVATAR
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	typedef struct 
	{
		int					iPad;
		int					( *m_fnFunc)(LPVOID lpParam,PBYTE pbThumbnail,DWORD dwThumbnailBytes);
		LPVOID				m_fnFunc_Param;
	}
	FUNCPARAMS;
	bool				GetProfileAvatar(int iPad,int( *Func)(LPVOID lpParam,PBYTE pbThumbnail,DWORD dwThumbnailBytes), LPVOID lpParam);
	void				CancelProfileAvatarRequest();	
		
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// SYS
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	int					GetPrimaryPad();
	void				SetPrimaryPad(int iPad);
	char*				GetGamertag(int iPad);
	std::wstring		GetDisplayName(int iPad);										

	bool				IsFullVersion();
	void				SetFullVersion(bool bFull);
	void				SetSignInChangeCallback(void ( *Func)(LPVOID, bool, unsigned int),LPVOID lpParam);
	void				SetNotificationsCallback(void ( *Func)(LPVOID, DWORD, unsigned int),LPVOID lpParam);
	bool				RegionIsNorthAmerica(void);
	bool				LocaleIsUSorCanada(void);
	HRESULT				GetLiveConnectionStatus();
	bool				IsSystemUIDisplayed();
	void				SetSysUIShowing( bool bUIDisplayed );
	void				DisplaySystemMessage( SceMsgDialogSystemMessageType _type, int iQuadrant);
	void				SetProfileReadErrorCallback(void ( *Func)(LPVOID), LPVOID lpParam);
	void				ShowSystemMessage( int _type, int _val );

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// ACHIEVEMENTS & AWARDS
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void				InitialiseTrophies();				//CD - Don't use this, auto setup after login
	void				RegisterAward(int iAwardNumber,int iGamerconfigID, eAwardType eType, bool bLeaderboardAffected=false, 
										CXuiStringTable*pStringTable=nullptr, int iTitleStr=-1, int iTextStr=-1, int iAcceptStr=-1, char *pszThemeName=nullptr, unsigned int uiThemeSize=0L);
	int					GetAwardId(int iAwardNumber);
	eAwardType			GetAwardType(int iAwardNumber);
	bool				CanBeAwarded(int iQuadrant, int iAwardNumber);
	void				Award(int iQuadrant, int iAwardNumber, bool bForce=false);
	bool				IsAwardsFlagSet(int iQuadrant, int iAward);	
	void				Terminate();
	void				SetFatalTrophyErrorID(int id);		//CD - Deprecated	
	int					WaitTrophyInitComplete();			//CD - Deprecated
	int					tryWaitTrophyInitComplete();		//CD - Deprecated
	void				SetTrialTextStringTable(CXuiStringTable *pStringTable,int iAccept,int iReject);
	void				SetTrialAwardText(eAwardType AwardType,int iTitle,int iText); // achievement popup in the trial game
	void				SetHDDFreeKB(int iHDDFreeKB);
	void				SetMinSaveKB(int iMinSaveKB);
	int					GetHDDFreeKB(void);	
	bool				AreTrophiesInstalled();

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// RICH PRESENCE
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void				RichPresenceRegisterPresenceString(int index, const char* str);
	void				RichPresenceRegisterContext(int ctxID, const char* token);
	void				RichPresenceRegisterContextString(int ctxID, int strIndex, const char* str);
	void				RichPresenceInit(int iPresenceCount, int iContextCount);
	void				SetRichPresenceContextValue(int iPad,int iContextID, int iVal);
	void				SetCurrentGameActivity(int iPad,int iNewPresence, bool bSetOthersToIdle=false);
	void				SetRichPresenceSettingFn(int ( *SetPresenceInfoFn)(const void *data));

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// PURCHASE
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void				DisplayFullVersionPurchase(bool bRequired, int iQuadrant, int iUpsellParam = -1);
	void				SetUpsellCallback(void ( *Func)(LPVOID lpParam, eUpsellType type, eUpsellResponse response, int iUserData),LPVOID lpParam);

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Debug 
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void				SetDebugFullOverride(bool bVal); // To override the license version (trail/full). Only in debug/release, not ContentPackage
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Chat and content restrictions
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	bool				GetChatAndContentRestrictions(int iPad, bool thisQuadrantOnly,bool *pbChatRestricted,bool *pbContentRestricted,int *piAge);
	void				SetServiceID(char *pchServiceID); // needed for the ticket request for the chat restrictions of secondary PSN players
	void				HandleNetworkTicket(int result,void *arg);
	void				SetMinimumAge(int iAge, int iRegion);// 0 - SCEE, 1- SCEA, 2 - SCEJ
	int					GetMinimumAge();
	void				SetGermanyMinimumAge(int iAge);
	int					GetGermanyMinimumAge();
	void				SetRussiaMinimumAge(int iAge);
	int					GetRussiaMinimumAge();
	void				SetAustraliaMinimumAge(int iAge);
	int					GetAustraliaMinimumAge();
	void				SetJapanMinimumAge(int iAge);
	int					GetJapanMinimumAge();
	void				SetKoreaMinimumAge(int iAge);
	int					GetKoreaMinimumAge();
	int					getUserID(int iQuadrant); //  grab the PS4 userID for this quadrant (SCE_USER_SERVICE_USER_ID_INVALID if it's not signed in)

	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Http calls
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	bool SonyHttp_init();
	void SonyHttp_shutdown();
	bool SonyHttp_getDataFromURL(const char* szURL, void** ppOutData, int* pDataSize);

};

// Singleton
extern C_4JProfile ProfileManager;