2026-03-01 12:16:08 +08:00
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
# pragma once
//#include "UserController.h"
class DQRNetworkManager ;
enum ChatPacketType
{
IncomingPacket = 0 ,
OutgoingPacket = 1
} ;
2026-03-02 17:37:16 +07:00
class ChatIntegrationLayer
2026-03-01 12:16:08 +08:00
: public std : : enable_shared_from_this < ChatIntegrationLayer > // shared_from_this is needed to use a weak ref to 'this' when handling delegate callbacks
{
public :
ChatIntegrationLayer ( ) ;
DQRNetworkManager * m_pDQRNet ;
/// <summary>
/// Initializes the chat manager
/// </summary>
2026-03-02 17:37:16 +07:00
void InitializeChatManager (
2026-03-01 12:16:08 +08:00
__in bool combineCaptureBuffersIntoSinglePacketEnabled ,
__in bool useKinectAsCaptureSource ,
__in bool applySoundEffectToCapture ,
__in bool applySoundEffectToRender ,
DQRNetworkManager * pDQRNet
) ;
/// <summary>
/// Shuts down the chat manager
/// </summary>
void Shutdown ( ) ;
class AddedUser
{
public :
AddedUser ( Windows : : Xbox : : System : : IUser ^ user , bool canCaptureAudio ) ;
Windows : : Xbox : : System : : IUser ^ m_user ;
bool m_canCaptureAudio ;
} ;
2026-03-02 17:37:16 +07:00
void AddLocalUser ( __in Windows : : Xbox : : System : : IUser ^ user ) ;
void RemoveLocalUser ( __in Windows : : Xbox : : System : : IUser ^ user ) ;
2026-03-01 12:16:08 +08:00
void EvaluateDevicesForUser ( __in Windows : : Xbox : : System : : IUser ^ user ) ;
vector < AddedUser * > m_addedUsers ;
CRITICAL_SECTION m_csAddedUsers ;
private :
/// <summary>
/// Adds a local user to a specific channel
2026-03-02 17:37:16 +07:00
/// This is helper function waits for the task to complete so shouldn't be called from the UI thread
2026-03-01 12:16:08 +08:00
/// </summary>
/// <param name="channelIndex">The channel to add the user to</param>
/// <param name="user">The local user to add</param>
2026-03-02 17:37:16 +07:00
void AddLocalUserToChatChannel (
2026-03-01 12:16:08 +08:00
__in uint8 channelIndex ,
__in Windows : : Xbox : : System : : IUser ^ user
2026-03-02 17:37:16 +07:00
) ;
2026-03-01 12:16:08 +08:00
/// <summary>
/// Removes a local user from a specific channel
2026-03-02 17:37:16 +07:00
/// This is helper function waits for the task to complete so shouldn't be called from the UI thread
2026-03-01 12:16:08 +08:00
/// </summary>
/// <param name="channelIndex">The channel to remove the user from</param>
/// <param name="user">The local user to remove</param>
void RemoveUserFromChatChannel (
__in uint8 channelIndex ,
__in Windows : : Xbox : : System : : IUser ^ user
) ;
public :
/// <summary>
/// Removes a remote console from chat
2026-03-02 17:37:16 +07:00
/// This is helper function waits for the task to complete so shouldn't be called from the UI thread
2026-03-01 12:16:08 +08:00
/// </summary>
/// <param name="uniqueRemoteConsoleIdentifier">A unique ID for the remote console</param>
2026-03-02 17:37:16 +07:00
void RemoveRemoteConsole (
2026-03-01 12:16:08 +08:00
unsigned int address
) ;
/// <summary>
/// Handles incoming chat messages from the game's network layer
/// </summary>
/// <param name="chatPacket">A buffer containing the chat message</param>
/// <param name="uniqueRemoteConsoleIdentifier">A unique ID for the remote console</param>
2026-03-02 17:37:16 +07:00
void OnIncomingChatMessage (
2026-03-01 12:16:08 +08:00
unsigned int sessionAddress ,
Platform : : Array < byte > ^ message
) ;
/// <summary>
/// Returns a list of chat users in the chat session
/// </summary>
Windows : : Foundation : : Collections : : IVectorView < Microsoft : : Xbox : : GameChat : : ChatUser ^ > ^ GetChatUsers ( ) ;
/// <summary>
/// Returns true if the game has mic focus. Otherwise another app has mic focus
/// </summary>
bool HasMicFocus ( ) ;
/// <summary>
/// Helper function to swap the mute state of a specific chat user
/// </summary>
void ChangeChatUserMuteState (
2026-03-02 17:37:16 +07:00
__in Microsoft : : Xbox : : GameChat : : ChatUser ^ chatUser
2026-03-01 12:16:08 +08:00
) ;
/// <summary>
/// Helper function to change the channel of a specific chat user
/// </summary>
void HandleChatChannelChanged (
__in uint8 oldChatChannelIndex ,
__in uint8 newChatChannelIndex ,
2026-03-02 17:37:16 +07:00
__in Microsoft : : Xbox : : GameChat : : ChatUser ^ chatUser
2026-03-01 12:16:08 +08:00
) ;
/// <summary>
2026-03-02 17:37:16 +07:00
/// Call this when a new console connects.
2026-03-01 12:16:08 +08:00
/// This adds this console to the chat layer
/// </summary>
2026-03-02 17:37:16 +07:00
void OnNewSessionAddressAdded (
__in unsigned int address
2026-03-01 12:16:08 +08:00
) ;
/// <summary>
/// Adds a list of locally signed in users that have intent to play to the chat session on a specific channel index.
2026-03-02 17:37:16 +07:00
/// Avoid adding any user who is signed in that doesn't have intent to play otherwise users who are biometrically
2026-03-01 12:16:08 +08:00
/// signed in automatically will be added to the chat session
/// </summary>
/// <param name="channelIndex">The channel to add the users to</param>
/// <param name="locallySignedInUsers">A list of locally signed in users that have intent to play</param>
void AddAllLocallySignedInUsersToChatClient (
__in uint8 channelIndex ,
__in Windows : : Foundation : : Collections : : IVectorView < Windows : : Xbox : : System : : User ^ > ^ locallySignedInUsers
) ;
/// <summary>
/// Handles when a debug message is received. Send this to the UI and OutputDebugString. Games should integrate with their existing log system.
/// </summary>
/// <param name="args">Contains the debug message to log</param>
2026-03-02 17:37:16 +07:00
void OnDebugMessageReceived (
__in Microsoft : : Xbox : : GameChat : : DebugMessageEventArgs ^ args
2026-03-01 12:16:08 +08:00
) ;
/// <summary>
/// Send the chat packet to all connected consoles
///
/// To integrate the Chat DLL in your game, change the following code to use your game's network layer.
/// You will need to isolate chat messages to be unique from the rest of you game's other message types.
/// When args->SendPacketToAllConnectedConsoles is true, your game should send the chat message to each connected console using the game's network layer.
/// It should send the chat message with Reliable UDP if args->SendReliable is true.
/// It should send the chat message in order (if that feature is available) if args->SendInOrder is true
/// </summary>
/// <param name="args">Describes the packet to send</param>
2026-03-02 17:37:16 +07:00
void OnOutgoingChatPacketReady (
__in Microsoft : : Xbox : : GameChat : : ChatPacketEventArgs ^ args
2026-03-01 12:16:08 +08:00
) ;
/// <summary>
/// Example of how to cast an int to a Platform::Object^
/// </summary>
Platform : : Object ^ IntToPlatformObject (
__in int val
) ;
/// <summary>
/// Example of how to cast an Platform::Object^ to an int
/// </summary>
int PlatformObjectToInt (
__in Platform : : Object ^ obj
) ;
/// <summary>
/// Helper function to get specific ChatUser by xboxUserId
/// </summary>
Microsoft : : Xbox : : GameChat : : ChatUser ^ GetChatUserByXboxUserId (
__in Platform : : String ^ xboxUserId
) ;
/// <summary>
/// Helper function to get specific ChatUser by xboxUserId
/// </summary>
2026-03-02 17:37:16 +07:00
bool ChatIntegrationLayer : : CompareUniqueConsoleIdentifiers (
__in Platform : : Object ^ uniqueRemoteConsoleIdentifier1 ,
__in Platform : : Object ^ uniqueRemoteConsoleIdentifier2
2026-03-01 12:16:08 +08:00
) ;
/// <summary>
2026-03-02 17:37:16 +07:00
/// Helper function to return the ChatPerformanceCounters^ from the ChatManager so perf numbers can be shown on the UI
2026-03-01 12:16:08 +08:00
/// These numbers will only be valid if m_chatManager->ChatSettings->PerformanceCountersEnabled is set to true.
/// </summary>
Microsoft : : Xbox : : GameChat : : ChatPerformanceCounters ^ GetChatPerformanceCounters ( ) ;
/// <summary>
/// Returns a count of the number of chat packets of a specific type that have been either sent or received.
/// It is useful to monitor this number in the UI / logs to debug network issues.
/// </summary>
2026-03-02 17:37:16 +07:00
int GameUI_GetPacketStatistic (
2026-03-01 12:16:08 +08:00
__in Microsoft : : Xbox : : GameChat : : ChatMessageType messageType ,
__in ChatPacketType chatPacketType
) ;
2026-03-02 17:37:16 +07:00
void OnControllerPairingChanged (
__in Windows : : Xbox : : Input : : ControllerPairingChangedEventArgs ^ args
2026-03-01 12:16:08 +08:00
) ;
void ToggleRenderTargetVolume ( ) ;
private :
void GetBufferBytes ( __in Windows : : Storage : : Streams : : IBuffer ^ buffer , __out byte * * ppOut ) ;
Windows : : Storage : : Streams : : IBuffer ^ ArrayToBuffer ( __in Platform : : Array < byte > ^ array ) ;
Concurrency : : critical_section m_lock ;
Microsoft : : Xbox : : GameChat : : ChatManager ^ m_chatManager ;
Windows : : Foundation : : EventRegistrationToken m_tokenOnDebugMessage ;
Windows : : Foundation : : EventRegistrationToken m_tokenOnOutgoingChatPacketReady ;
Windows : : Foundation : : EventRegistrationToken m_tokenOnCompareUniqueConsoleIdentifiers ;
Windows : : Foundation : : EventRegistrationToken m_tokenResourceAvailabilityChanged ;
Windows : : Foundation : : EventRegistrationToken m_tokenOnPreEncodeAudioBuffer ;
Windows : : Foundation : : EventRegistrationToken m_tokenOnPostDecodeAudioBuffer ;
Windows : : Foundation : : EventRegistrationToken m_tokenUserAudioDeviceAdded ;
Windows : : Foundation : : EventRegistrationToken m_tokenUserAudioDeviceRemoved ;
Windows : : Foundation : : EventRegistrationToken m_tokenUserAudioDeviceChanged ;
// Debug stats for chat packets. Use Debug_GetPacketStatistic() to get the values.
/// It is useful to monitor this number in the UI / logs to debug network issues.
2026-03-02 17:37:16 +07:00
void GameUI_RecordPacketStatistic (
2026-03-01 12:16:08 +08:00
__in Microsoft : : Xbox : : GameChat : : ChatMessageType messageType ,
__in ChatPacketType chatPacketType
) ;
Concurrency : : critical_section m_chatPacketStatsLock ;
int m_chatVoicePacketsStatistic [ 2 ] [ ( int ) Microsoft : : Xbox : : GameChat : : ChatMessageType : : InvalidMessage + 1 ] ;
} ;
std : : shared_ptr < ChatIntegrationLayer > GetChatIntegrationLayer ( ) ;