the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 244 lines 9.7 kB view raw
1//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 2//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 3//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 4//// PARTICULAR PURPOSE. 5//// 6//// Copyright (c) Microsoft Corporation. All rights reserved 7#pragma once 8 9//#include "UserController.h" 10 11class DQRNetworkManager; 12 13enum ChatPacketType 14{ 15 IncomingPacket = 0, 16 OutgoingPacket = 1 17}; 18 19class ChatIntegrationLayer 20 : public std::enable_shared_from_this<ChatIntegrationLayer> // shared_from_this is needed to use a weak ref to 'this' when handling delegate callbacks 21{ 22public: 23 ChatIntegrationLayer(); 24 25 DQRNetworkManager *m_pDQRNet; 26 /// <summary> 27 /// Initializes the chat manager 28 /// </summary> 29 void InitializeChatManager( 30 __in bool combineCaptureBuffersIntoSinglePacketEnabled, 31 __in bool useKinectAsCaptureSource, 32 __in bool applySoundEffectToCapture, 33 __in bool applySoundEffectToRender, 34 DQRNetworkManager *pDQRNet 35 ); 36 37 /// <summary> 38 /// Shuts down the chat manager 39 /// </summary> 40 void Shutdown(); 41 42 class AddedUser 43 { 44 public: 45 AddedUser(Windows::Xbox::System::IUser^ user, bool canCaptureAudio); 46 Windows::Xbox::System::IUser^ m_user; 47 bool m_canCaptureAudio; 48 }; 49 50 void AddLocalUser( __in Windows::Xbox::System::IUser^ user ); 51 void RemoveLocalUser( __in Windows::Xbox::System::IUser^ user ); 52 void EvaluateDevicesForUser(__in Windows::Xbox::System::IUser^ user ); 53 54 vector<AddedUser *> m_addedUsers; 55 CRITICAL_SECTION m_csAddedUsers; 56 57private: 58 /// <summary> 59 /// Adds a local user to a specific channel 60 /// This is helper function waits for the task to complete so shouldn't be called from the UI thread 61 /// </summary> 62 /// <param name="channelIndex">The channel to add the user to</param> 63 /// <param name="user">The local user to add</param> 64 void AddLocalUserToChatChannel( 65 __in uint8 channelIndex, 66 __in Windows::Xbox::System::IUser^ user 67 ); 68 69 /// <summary> 70 /// Removes a local user from a specific channel 71 /// This is helper function waits for the task to complete so shouldn't be called from the UI thread 72 /// </summary> 73 /// <param name="channelIndex">The channel to remove the user from</param> 74 /// <param name="user">The local user to remove</param> 75 void RemoveUserFromChatChannel( 76 __in uint8 channelIndex, 77 __in Windows::Xbox::System::IUser^ user 78 ); 79public: 80 81 /// <summary> 82 /// Removes a remote console from chat 83 /// This is helper function waits for the task to complete so shouldn't be called from the UI thread 84 /// </summary> 85 /// <param name="uniqueRemoteConsoleIdentifier">A unique ID for the remote console</param> 86 void RemoveRemoteConsole( 87 unsigned int address 88 ); 89 90 /// <summary> 91 /// Handles incoming chat messages from the game's network layer 92 /// </summary> 93 /// <param name="chatPacket">A buffer containing the chat message</param> 94 /// <param name="uniqueRemoteConsoleIdentifier">A unique ID for the remote console</param> 95 void OnIncomingChatMessage( 96 unsigned int sessionAddress, 97 Platform::Array<byte>^ message 98 ); 99 100 /// <summary> 101 /// Returns a list of chat users in the chat session 102 /// </summary> 103 Windows::Foundation::Collections::IVectorView<Microsoft::Xbox::GameChat::ChatUser^>^ GetChatUsers(); 104 105 /// <summary> 106 /// Returns true if the game has mic focus. Otherwise another app has mic focus 107 /// </summary> 108 bool HasMicFocus(); 109 110 /// <summary> 111 /// Helper function to swap the mute state of a specific chat user 112 /// </summary> 113 void ChangeChatUserMuteState( 114 __in Microsoft::Xbox::GameChat::ChatUser^ chatUser 115 ); 116 117 /// <summary> 118 /// Helper function to change the channel of a specific chat user 119 /// </summary> 120 void HandleChatChannelChanged( 121 __in uint8 oldChatChannelIndex, 122 __in uint8 newChatChannelIndex, 123 __in Microsoft::Xbox::GameChat::ChatUser^ chatUser 124 ); 125 126 /// <summary> 127 /// Call this when a new console connects. 128 /// This adds this console to the chat layer 129 /// </summary> 130 void OnNewSessionAddressAdded( 131 __in unsigned int address 132 ); 133 134 /// <summary> 135 /// Adds a list of locally signed in users that have intent to play to the chat session on a specific channel index. 136 /// Avoid adding any user who is signed in that doesn't have intent to play otherwise users who are biometrically 137 /// signed in automatically will be added to the chat session 138 /// </summary> 139 /// <param name="channelIndex">The channel to add the users to</param> 140 /// <param name="locallySignedInUsers">A list of locally signed in users that have intent to play</param> 141 void AddAllLocallySignedInUsersToChatClient( 142 __in uint8 channelIndex, 143 __in Windows::Foundation::Collections::IVectorView<Windows::Xbox::System::User^>^ locallySignedInUsers 144 ); 145 146 /// <summary> 147 /// Handles when a debug message is received. Send this to the UI and OutputDebugString. Games should integrate with their existing log system. 148 /// </summary> 149 /// <param name="args">Contains the debug message to log</param> 150 void OnDebugMessageReceived( 151 __in Microsoft::Xbox::GameChat::DebugMessageEventArgs^ args 152 ); 153 154 /// <summary> 155 /// Send the chat packet to all connected consoles 156 /// 157 /// To integrate the Chat DLL in your game, change the following code to use your game's network layer. 158 /// You will need to isolate chat messages to be unique from the rest of you game's other message types. 159 /// When args->SendPacketToAllConnectedConsoles is true, your game should send the chat message to each connected console using the game's network layer. 160 /// It should send the chat message with Reliable UDP if args->SendReliable is true. 161 /// It should send the chat message in order (if that feature is available) if args->SendInOrder is true 162 /// </summary> 163 /// <param name="args">Describes the packet to send</param> 164 void OnOutgoingChatPacketReady( 165 __in Microsoft::Xbox::GameChat::ChatPacketEventArgs^ args 166 ); 167 168 /// <summary> 169 /// Example of how to cast an int to a Platform::Object^ 170 /// </summary> 171 Platform::Object^ IntToPlatformObject( 172 __in int val 173 ); 174 175 /// <summary> 176 /// Example of how to cast an Platform::Object^ to an int 177 /// </summary> 178 int PlatformObjectToInt( 179 __in Platform::Object^ obj 180 ); 181 182 /// <summary> 183 /// Helper function to get specific ChatUser by xboxUserId 184 /// </summary> 185 Microsoft::Xbox::GameChat::ChatUser^ GetChatUserByXboxUserId( 186 __in Platform::String^ xboxUserId 187 ); 188 189 /// <summary> 190 /// Helper function to get specific ChatUser by xboxUserId 191 /// </summary> 192 bool ChatIntegrationLayer::CompareUniqueConsoleIdentifiers( 193 __in Platform::Object^ uniqueRemoteConsoleIdentifier1, 194 __in Platform::Object^ uniqueRemoteConsoleIdentifier2 195 ); 196 197 /// <summary> 198 /// Helper function to return the ChatPerformanceCounters^ from the ChatManager so perf numbers can be shown on the UI 199 /// These numbers will only be valid if m_chatManager->ChatSettings->PerformanceCountersEnabled is set to true. 200 /// </summary> 201 Microsoft::Xbox::GameChat::ChatPerformanceCounters^ GetChatPerformanceCounters(); 202 203 /// <summary> 204 /// Returns a count of the number of chat packets of a specific type that have been either sent or received. 205 /// It is useful to monitor this number in the UI / logs to debug network issues. 206 /// </summary> 207 int GameUI_GetPacketStatistic( 208 __in Microsoft::Xbox::GameChat::ChatMessageType messageType, 209 __in ChatPacketType chatPacketType 210 ); 211 212 void OnControllerPairingChanged( 213 __in Windows::Xbox::Input::ControllerPairingChangedEventArgs^ args 214 ); 215 216 void ToggleRenderTargetVolume(); 217 218private: 219 void GetBufferBytes( __in Windows::Storage::Streams::IBuffer^ buffer, __out byte** ppOut ); 220 Windows::Storage::Streams::IBuffer^ ArrayToBuffer( __in Platform::Array<byte>^ array ); 221 222 Concurrency::critical_section m_lock; 223 Microsoft::Xbox::GameChat::ChatManager^ m_chatManager; 224 Windows::Foundation::EventRegistrationToken m_tokenOnDebugMessage; 225 Windows::Foundation::EventRegistrationToken m_tokenOnOutgoingChatPacketReady; 226 Windows::Foundation::EventRegistrationToken m_tokenOnCompareUniqueConsoleIdentifiers; 227 Windows::Foundation::EventRegistrationToken m_tokenResourceAvailabilityChanged; 228 Windows::Foundation::EventRegistrationToken m_tokenOnPreEncodeAudioBuffer; 229 Windows::Foundation::EventRegistrationToken m_tokenOnPostDecodeAudioBuffer; 230 Windows::Foundation::EventRegistrationToken m_tokenUserAudioDeviceAdded; 231 Windows::Foundation::EventRegistrationToken m_tokenUserAudioDeviceRemoved; 232 Windows::Foundation::EventRegistrationToken m_tokenUserAudioDeviceChanged; 233 234 // Debug stats for chat packets. Use Debug_GetPacketStatistic() to get the values. 235 /// It is useful to monitor this number in the UI / logs to debug network issues. 236 void GameUI_RecordPacketStatistic( 237 __in Microsoft::Xbox::GameChat::ChatMessageType messageType, 238 __in ChatPacketType chatPacketType 239 ); 240 Concurrency::critical_section m_chatPacketStatsLock; 241 int m_chatVoicePacketsStatistic[2][(int)Microsoft::Xbox::GameChat::ChatMessageType::InvalidMessage+1]; 242}; 243 244std::shared_ptr<ChatIntegrationLayer> GetChatIntegrationLayer();