the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2
3#include "SonyVoiceChat_Orbis.h"
4
5
6
7bool m_bIsPartyAPIInitialized;
8bool m_bIsPartyBinaryMessageAPIReady;
9
10SceNpPartyState m_stPartyState;
11
12 SonyVoiceChatParty_Orbis::PartyInfo SonyVoiceChatParty_Orbis::m_partyInfo;
13
14void SonyVoiceChatParty_Orbis::init()
15{
16// m_bIsRunning = false;
17// m_pRenderer = NULL;
18// m_pPadContext = NULL;
19// m_pGraphicsContext = NULL;
20// m_iPartyMemberCount = 0;
21// m_iPartyLeader = 0;
22 int ret = SCE_OK;
23 SceNpPartyInitializeParam stPartyInit;
24 SceUserServiceLoginUserIdList userIdList;
25
26
27 // Run PartyInitializeParamInitialize inline
28 sceNpPartyInitializeParamInitialize( &stPartyInit );
29
30 // Initialize the Party API
31 ret = sceNpPartyInitialize( &stPartyInit );
32 if( ret != SCE_OK )
33 {
34 app.DebugPrintf( "Error: sceNpPartyInitialize failed result:0x%x\n", ret );
35 return;
36 }
37
38 // Register handlers for party room events
39 SceNpPartyEventHandlers stPartyEventHandler;
40 memset( &stPartyEventHandler, 0, sizeof( SceNpPartyEventHandlers ) );
41 stPartyEventHandler.roomEventHandler = partyRoomEventHandler;
42 stPartyEventHandler.voiceEventHandler = partyVoiceEventHandler;
43 stPartyEventHandler.binaryMessageEventHandler = partyBinaryMessageEventHandler;
44 ret = sceNpPartyRegisterHandler( &stPartyEventHandler, NULL );
45 if( ret != SCE_OK )
46 {
47 app.DebugPrintf( "Error: sceNpPartyRegisterHandler failed result:0x%x\n", ret );
48 return;
49 }
50
51
52 // Get current party state
53 ret = sceNpPartyGetState( &m_stPartyState );
54 if( ret != SCE_OK )
55 {
56 app.DebugPrintf( "Error: sceNpPartyGetState failed result:0x%x\n", ret );
57 return;
58 }
59
60 m_bIsPartyAPIInitialized = true;
61}
62
63void SonyVoiceChatParty_Orbis::shutdown()
64{
65}
66
67void SonyVoiceChatParty_Orbis::setEnabled( bool bEnabled )
68{
69}
70
71
72
73
74void SonyVoiceChatParty_Orbis::tick()
75{
76 sceNpPartyCheckCallback();
77}
78
79
80
81bool SonyVoiceChatParty_Orbis::hasMicConnected(const PlayerUID& memberUID)
82{
83 MemberInfo* pInfo = m_partyInfo.getMember(memberUID);
84 if(pInfo)
85 {
86 // in the party, might not have a mic though, still need to check for this
87 return true;
88 }
89 return false;
90}
91
92void SonyVoiceChatParty_Orbis::mute( bool bMute )
93{
94// if(sm_bLoaded && !sm_bUnloading)
95// {
96// int err = cellSysutilAvc2SetVoiceMuting(bMute);
97// assert(err == CELL_OK);
98// }
99}
100
101void SonyVoiceChatParty_Orbis::mutePlayer( const SceNpMatching2RoomMemberId member_id, bool bMute ) /*Turn chat audio from a specified player on or off */
102{
103// if(sm_bLoaded && !sm_bUnloading)
104// {
105// int err = cellSysutilAvc2SetPlayerVoiceMuting(member_id, bMute);
106// assert(err == CELL_OK);
107// }
108}
109
110void SonyVoiceChatParty_Orbis::muteLocalPlayer( bool bMute ) /*Turn microphone input on or off */
111{
112// if(sm_bLoaded && !sm_bUnloading)
113// {
114// int err = cellSysutilAvc2SetVoiceMuting(bMute);
115// assert(err == CELL_OK);
116// }
117}
118
119
120bool SonyVoiceChatParty_Orbis::isMuted()
121{
122// if(sm_bLoaded && !sm_bUnloading)
123// {
124// uint8_t bMute;
125// int err = cellSysutilAvc2GetVoiceMuting(&bMute);
126// assert(err == CELL_OK);
127// return bMute;
128// }
129// return false;
130}
131
132bool SonyVoiceChatParty_Orbis::isMutedPlayer( const PlayerUID& memberUID)
133{
134 MemberInfo* pInfo = m_partyInfo.getMember(memberUID);
135 if(pInfo)
136 return pInfo->m_voiceMuted;
137 assert(0 && "Didn't find playerUID"); //
138 return false;
139// if(sm_bLoaded && !sm_bUnloading)
140// {
141// uint8_t bMute;
142// int err = cellSysutilAvc2GetPlayerVoiceMuting(member_id, &bMute);
143// assert(err == CELL_OK);
144// return bMute;
145// }
146// return false;
147}
148
149bool SonyVoiceChatParty_Orbis::isMutedLocalPlayer()
150{
151// if(sm_bLoaded && !sm_bUnloading)
152// {
153// uint8_t bMute;
154// int err = cellSysutilAvc2GetVoiceMuting(&bMute);
155// assert(err == CELL_OK);
156// return bMute;
157// }
158// return false;
159}
160
161
162bool SonyVoiceChatParty_Orbis::isTalking( const PlayerUID& memberUID)
163{
164 MemberInfo* pInfo = m_partyInfo.getMember(memberUID);
165 if(pInfo)
166 {
167 DWORD currTime = GetTickCount();
168 DWORD timeElapsed = currTime - pInfo->m_lastTimeTalking;
169 return (timeElapsed < 1000);
170 }
171 assert(0 && "Didn't find playerUID"); //
172 return false;
173}
174
175
176
177
178void SonyVoiceChatParty_Orbis::partyRoomEventHandler(SceNpPartyRoomEventType eventType, const void* data, void* userdata)
179{
180
181 switch(eventType)
182 {
183 case SCE_NP_PARTY_ROOM_EVENT_JOINED:
184 {
185 // local player joined party
186 app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_JOINED\n");
187 SceNpPartyJoinedInfo* pPartyJoinedInfo = (SceNpPartyJoinedInfo*) data;
188
189 m_partyInfo.clear();
190 app.DebugPrintf("Local user joined party.\n");
191 for(int i=0; i<pPartyJoinedInfo->memberNum;i++)
192 {
193 m_partyInfo.addMember(pPartyJoinedInfo->memberIds[i], pPartyJoinedInfo->members[i], false, false);
194 app.DebugPrintf("Member room ID : %d - Member PSN ID : %s\n", pPartyJoinedInfo->memberIds[i], pPartyJoinedInfo->members[i].handle.data);
195 }
196 }
197 break;
198
199 case SCE_NP_PARTY_ROOM_EVENT_MEMBER_JOINED:
200 {
201 // remote player joined party
202 app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_MEMBER_JOINED\n");
203 SceNpPartyMemberInfo *pNewPartyMemberInfo = (SceNpPartyMemberInfo*) data;
204 app.DebugPrintf("A remote player[%s] has a joined the party.\n",pNewPartyMemberInfo->npId.handle.data);
205
206 m_partyInfo.addMember(pNewPartyMemberInfo->memberId, pNewPartyMemberInfo->npId, pNewPartyMemberInfo->memberFlags & SCE_NP_PARTY_MEMBER_FLAG_IS_LOCAL, pNewPartyMemberInfo->memberFlags & SCE_NP_PARTY_MEMBER_FLAG_IS_PARTY_LEADER);
207 }
208 break;
209
210 case SCE_NP_PARTY_ROOM_EVENT_MEMBER_LEFT:
211 {
212 // remote player left party
213 app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_MEMBER_LEFT\n");
214 SceNpPartyMemberInfo *pLeavingPartyMemberInfo = (SceNpPartyMemberInfo*) data;
215 app.DebugPrintf("A remote player[%s] has left the party.\n", pLeavingPartyMemberInfo->npId.handle.data);
216 m_partyInfo.removeMember(pLeavingPartyMemberInfo->memberId);
217 }
218 break;
219
220 case SCE_NP_PARTY_ROOM_EVENT_LEFT:
221 {
222 // local player left party
223 app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_LEFT\n");
224 SceNpPartyRoomLeftInfo *pLeftInfo = (SceNpPartyRoomLeftInfo*)data;
225 printf("Local party member[%s] id:%d has left the party. Reason[%d]\n", pLeftInfo->npId.handle.data, pLeftInfo->memberId, pLeftInfo->reason);
226 m_partyInfo.removeMember(pLeftInfo->memberId);
227 }
228 break;
229
230 case SCE_NP_PARTY_ROOM_EVENT_CREATE_RESPONSE:
231 {
232 app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_CREATE_RESPONSE\n");
233 SceNpPartyCreateResponseInfo *pCreateResponseInfo = (SceNpPartyCreateResponseInfo*) data;
234
235 switch( pCreateResponseInfo->status )
236 {
237 case SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_OK:
238 app.DebugPrintf( "Local party member userId[0x%x] response for creating a party. Status = SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_OK\n" , pCreateResponseInfo->userId );
239 break;
240 case SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_CANCELLED:
241 app.DebugPrintf( "Local party member userId[0x%x] response for creating a party. Status = SCE_NP_PARTY_ROOM_CREATE_RESPONSE_STATUS_CANCELLED\n" , pCreateResponseInfo->userId );
242 break;
243 default:
244 app.DebugPrintf( "Warning: Unknown SceNpPartyCreateResponseStatus [%d]. Ignore.\n", pCreateResponseInfo->status );
245 break;
246 }
247 }
248 break;
249
250 case SCE_NP_PARTY_ROOM_EVENT_SHOW_INVITATION_RESPONSE:
251 {
252 app.DebugPrintf("SCE_NP_PARTY_ROOM_EVENT_SHOW_INVITATION_RESPONSE\n");
253 SceNpPartyShowInvitationResponseInfo *pShowInvitationResponseInfo = (SceNpPartyShowInvitationResponseInfo*) data;
254
255 switch( pShowInvitationResponseInfo->status )
256 {
257 case SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_OK:
258 app.DebugPrintf( "Local party member userId[0x%x] response for sending an invitation/suggestion. Status = SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_OK\n" , pShowInvitationResponseInfo->userId );
259 break;
260 case SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_CANCELLED:
261 app.DebugPrintf( "Local party member userId[0x%x] response for sending an invitation/suggestion. Status = SCE_NP_PARTY_ROOM_SHOW_INVITATION_RESPONSE_STATUS_CANCELLED\n" , pShowInvitationResponseInfo->userId );
262 break;
263 default:
264 app.DebugPrintf( "Warning: Unknown SceNpPartyShowInvitationResponseStatus [%d]. Ignore.\n", pShowInvitationResponseInfo->status );
265 break;
266 }
267 }
268 break;
269
270 default:
271 {
272 app.DebugPrintf( "Warning: Un-handled party event[%d]. Ignore.\n", eventType );
273 }
274 break;
275
276 }
277
278}
279
280
281
282void SonyVoiceChatParty_Orbis::partyVoiceEventHandler( const SceNpPartyMemberVoiceInfo* memberVoiceInfo, void* userdata )
283{
284
285 switch(memberVoiceInfo->memberVoiceState)
286 {
287 case SCE_NP_PARTY_MEMBER_VOICE_STATE_DISCONNECTED:
288 {
289 app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_DISCONNECTED\n");
290 MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
291 assert(pInfo);
292 if(pInfo)
293 pInfo->m_voiceConnected = false;
294 }
295 break;
296 case SCE_NP_PARTY_MEMBER_VOICE_STATE_CONNECTED:
297 {
298 app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_CONNECTED\n");
299 MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
300 assert(pInfo);
301 if(pInfo)
302 pInfo->m_voiceConnected = true;
303 }
304 break;
305 case SCE_NP_PARTY_MEMBER_VOICE_STATE_TALKING:
306 {
307 app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_TALKING\n");
308 MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
309 assert(pInfo);
310 if(pInfo)
311 {
312 pInfo->m_voiceMuted = false;
313 pInfo->m_lastTimeTalking = GetTickCount();
314 }
315 }
316 break;
317 case SCE_NP_PARTY_MEMBER_VOICE_STATE_MUTED:
318 {
319 app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_MUTED\n");
320 MemberInfo* pInfo = m_partyInfo.getMember(memberVoiceInfo->memberId);
321 assert(pInfo);
322 if(pInfo)
323 pInfo->m_voiceMuted = true;
324 }
325 break;
326 case SCE_NP_PARTY_MEMBER_VOICE_STATE_UNKNOWN:
327 {
328 app.DebugPrintf("SCE_NP_PARTY_MEMBER_VOICE_STATE_UNKNOWN\n");
329 }
330 break;
331 default:
332 {
333 app.DebugPrintf("Warning: Un-handled voice event. Ignore.\n");
334 }
335 break;
336 }
337}
338
339
340void SonyVoiceChatParty_Orbis::partyBinaryMessageEventHandler( SceNpPartyBinaryMessageEvent event,
341 const void *data,
342 void * userdata
343 )
344{
345 switch(event)
346 {
347 case SCE_NP_PARTY_BINARY_MESSAGE_EVENT_READY:
348 case SCE_NP_PARTY_BINARY_MESSAGE_EVENT_DATA:
349 case SCE_NP_PARTY_BINARY_MESSAGE_EVENT_COMPATIBILITY:
350 default:
351// app.DebugPrintf("partyBinaryMessageEventHandler not supported");
352// assert(0);
353 break;
354 }
355}