#include "pch.hpp"
//===========================================================================//
// File:	 DirectPlay.cpp													 //
// Project: GameOS															 //
// Contents: Interface to DirectPlay									     //
//---------------------------------------------------------------------------//
// Date   Who  Modification													 //
// 01/21/98 AG   Created													 //
//---------------------------------------------------------------------------//
// Copyright (C) 1999 Microsoft Corp.						                 //
// All Rights reserved worldwide											 //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL				 //
//===========================================================================//
#include "Globals.hpp"
#include "ErrorHandler.hpp"
#include "DirectX.hpp"
#include "DXRasterizer.hpp"
#include "DirectXDebugging.hpp"



HRESULT wAddPlayerToGroup( IDirectPlay4A* dplay4, DPID idGroup, DPID idPlayer )
{
	SPEW(( GROUP_DIRECTPLAY, "AddPlayerToGroup(g:%d p:%d)",(int)idGroup, (int)idPlayer));

	HRESULT result=dplay4 -> AddPlayerToGroup(idGroup, idPlayer);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - AddPlayerToGroup(g:%d p:%d)",result,ErrorNumberToMessage(result),idGroup, idPlayer));

	return result;
}

HRESULT wCancelMessage( IDirectPlay4A* dplay4, DWORD dwMsgID, DWORD dwFlags)
{
	SPEW(( GROUP_DIRECTPLAY, "CancelMessage(id:%d, flags:%d)",(int)dwMsgID, (int)dwFlags));

	HRESULT result=dplay4->CancelMessage( dwMsgID, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CancelMessage(id:%d, flags:%d)",
				result,ErrorNumberToMessage(result),(int)dwMsgID,(int)dwFlags));

	return result;
}

HRESULT wCancelPriority( IDirectPlay4A* dplay4, DWORD dwMinPriority, DWORD dwMaxPriority, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "CancelPriority(%d, %d, %d)",(int)dwMinPriority, (int)dwMaxPriority, (int)dwFlags));

	HRESULT result= dplay4->CancelPriority( dwMinPriority, dwMaxPriority, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CancelPriority(%d, %d, %d)",
			result,ErrorNumberToMessage(result),(int)dwMaxPriority, (int)dwFlags));

	return result;
}

HRESULT wClose( IDirectPlay4A* dplay4 )
{
	SPEW(( GROUP_DIRECTPLAY, "Close"));

	HRESULT result=dplay4->Close();

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Close",
			result,ErrorNumberToMessage(result)));

	return result;
}


HRESULT wCreateGroup( IDirectPlay4A* dplay4, LPDPID lpidGroup, LPDPNAME lpGroupName, LPVOID lpData, DWORD dwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "CreateGroup(0x%x, 0x%x, 0x%x, %d, %d)", (int)lpidGroup, (int)lpGroupName, (int)lpData, dwDataSize, dwFlags));

	HRESULT result=dplay4->CreateGroup( lpidGroup, lpGroupName, lpData, dwDataSize, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateGroup(0x%x, 0x%x, 0x%x, %d, %d)", result,ErrorNumberToMessage(result),(int)lpidGroup, (int)lpGroupName, (int)lpData, dwDataSize, dwFlags));

	return result;
}

HRESULT wCreateGroupInGroup( IDirectPlay4A* dplay4, DPID idParentGroup, LPDPID lpidGroup, LPDPNAME lpGroupName, LPVOID lpData, DWORD dwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "CreateGroupInGroup(%d, 0x%x, 0x%x, 0x%x, %d, %d)",(int)idParentGroup, (int)lpidGroup, (int)lpGroupName, (int)lpData, dwDataSize, dwFlags));

	HRESULT result=dplay4->CreateGroupInGroup( idParentGroup, lpidGroup, lpGroupName, lpData, dwDataSize, dwFlags);
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateGroupInGroup(%d, 0x%x, 0x%x, 0x%x, %d, %d)",result,ErrorNumberToMessage(result),(int)idParentGroup, (int)lpidGroup, (int)lpGroupName, (int)lpData, dwDataSize, dwFlags));
	
	return result;
}

HRESULT wCreatePlayer( IDirectPlay4A* dplay4, LPDPID lpidPlayer, LPDPNAME lpPlayerName, HANDLE hEvent, LPVOID lpData, DWORD dwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "CreatePlayer(Name=\"%s\", Event=0x%x, Flags=%s) +", GetPlayerName(lpPlayerName), (int)hEvent, GetCreatePlayerFlags(dwFlags)  ));

	HRESULT result=dplay4->CreatePlayer(lpidPlayer, lpPlayerName, hEvent, lpData, dwDataSize, dwFlags);

	SPEW(( GROUP_DIRECTPLAY, " - ID=0x%x",(int)*lpidPlayer));

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreatePlayer(Name=%s, Event=0x%x, Flags=%s)",result,ErrorNumberToMessage(result),GetPlayerName(lpPlayerName), (int)hEvent, GetCreatePlayerFlags(dwFlags) ));

	return result;
}

HRESULT wDeleteGroupFromGroup( IDirectPlay4A* dplay4, DPID idParentGroup, DPID idGroup )
{
	SPEW(( GROUP_DIRECTPLAY, "DeleteGroupFromGroup(%d, %d)",idParentGroup, idGroup));

	HRESULT result= dplay4 -> DeleteGroupFromGroup( idParentGroup, idGroup);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DeleteGroupFromGroup(%d, %d)",result,ErrorNumberToMessage(result),(int)idParentGroup, (int)idGroup));

	return result;
}

HRESULT wDeletePlayerFromGroup( IDirectPlay4A* dplay4, DPID idGroup, DPID idPlayer )
{
	SPEW(( GROUP_DIRECTPLAY, "DeletePlayerFromGroup(%d, %d)",idGroup, idPlayer));

	HRESULT result=dplay4 -> DeletePlayerFromGroup( idGroup, idPlayer);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DeletePlayerFromGroup(%d, %d)",result,ErrorNumberToMessage(result),idGroup, idPlayer));

	return result;
}

HRESULT wDestroyGroup( IDirectPlay4A* dplay4, DPID idGroup )
{
	SPEW(( GROUP_DIRECTPLAY, "DestroyGroup(%d)", idGroup));

	HRESULT result = dplay4 -> DestroyGroup(idGroup);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DestroyGroup(%d)",result,ErrorNumberToMessage(result),(int)idGroup));

	return result;
}

HRESULT wDestroyPlayer( IDirectPlay4A* dplay4, DPID idPlayer )
{
	SPEW(( GROUP_DIRECTPLAY, "DestroyPlayer(%d)", idPlayer));

	HRESULT result = dplay4 -> DestroyPlayer(idPlayer);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - DestroyPlayer(%d)",result,ErrorNumberToMessage(result),(int)idPlayer));

	return result;
}

HRESULT wEnumConnections( IDirectPlay4A* dplay4, LPCGUID lpguidApplication, LPDPENUMCONNECTIONSCALLBACK lpEnumCallback, LPVOID lpContext, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumConnections(0x%x, 0x%x, 0x%x, %d)",lpguidApplication, lpEnumCallback, lpContext, dwFlags));

	HRESULT result = dplay4 -> EnumConnections(lpguidApplication, lpEnumCallback, lpContext, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - EnumConnections(0x%x, 0x%x, 0x%x, %d)",result,ErrorNumberToMessage(result),(int)lpguidApplication, (int)lpEnumCallback, (int)lpContext, dwFlags));

	return result;
}

HRESULT wEnumGroupPlayers( IDirectPlay4A* dplay4, DPID idGroup, LPGUID lpguidInstance, LPDPENUMPLAYERSCALLBACK2 lpEnumPlayersCallback2, LPVOID lpContext, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumGroupPlayers(%d, 0x%x, 0x%x,0x%x, %d)",(int)idGroup, (int)lpguidInstance, (int)lpEnumPlayersCallback2, (int)lpContext, dwFlags ));

	HRESULT result=dplay4->EnumGroupPlayers( idGroup, lpguidInstance, lpEnumPlayersCallback2, lpContext, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - EnumGroupPlayers(%d, 0x%x, 0x%x,0x%x, %d)",result,ErrorNumberToMessage(result),(int)idGroup, (int)lpguidInstance, (int)lpEnumPlayersCallback2, (int)lpContext, dwFlags));

	return result;
}

HRESULT wEnumGroups( IDirectPlay4A* dplay4, LPGUID lpguidInstance, LPDPENUMPLAYERSCALLBACK2 lpEnumPlayersCallback2, LPVOID lpContext, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumGroups(0x%x, 0x%x,0x%x, %d)", (int)lpguidInstance, (int)lpEnumPlayersCallback2, (int)lpContext, dwFlags ));

	HRESULT result=dplay4->EnumGroups( lpguidInstance, lpEnumPlayersCallback2, lpContext, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - EnumGroups(0x%x, 0x%x,0x%x, %d)",result,ErrorNumberToMessage(result),(int)lpguidInstance, (int)lpEnumPlayersCallback2, (int)lpContext, dwFlags));

	return result;
}

HRESULT wEnumGroupsInGroup( IDirectPlay4A* dplay4, DPID idGroup, LPGUID lpguidInstance, LPDPENUMPLAYERSCALLBACK2 lpEnumCallback, LPVOID lpContext, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumGroupsInGroup(%d, 0x%x, 0x%x,0x%x, %d)",idGroup, (int)lpguidInstance, (int)lpEnumCallback, (int)lpContext, dwFlags ));

	HRESULT result=dplay4->EnumGroupsInGroup( idGroup, lpguidInstance, lpEnumCallback, lpContext, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - EnumGroupsInGroup(%d, 0x%x, 0x%x,0x%x, %d)",result,ErrorNumberToMessage(result),idGroup, (int)lpguidInstance, (int)lpEnumCallback, (int)lpContext, dwFlags));

	return result;
}

HRESULT wEnumPlayers( IDirectPlay4A* dplay4, LPGUID lpguidInstance, LPDPENUMPLAYERSCALLBACK2 lpEnumPlayersCallback2, LPVOID lpContext, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumPlayers(%s)",GetEnumPlayersInfo(lpguidInstance,dwFlags) ));

	HRESULT result=dplay4->EnumPlayers( lpguidInstance, lpEnumPlayersCallback2, lpContext, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - wEnumPlayers(%s)",result,ErrorNumberToMessage(result),GetEnumPlayersInfo(lpguidInstance,dwFlags) ));

	return result;
}

HRESULT wEnumSessions( IDirectPlay4A* dplay4, LPDPSESSIONDESC2 lpsd, DWORD dwTimeout, LPDPENUMSESSIONSCALLBACK2 lpEnumSessionsCallback2, LPVOID lpContext, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumSessions(%s, %s)",GetDPSessionDesc2(lpsd),GetEnumSessionFlags(dwTimeout, dwFlags) ));

	HRESULT result=dplay4->EnumSessions( lpsd, dwTimeout, lpEnumSessionsCallback2, lpContext, dwFlags);

	if( FAILED(result) && result!=DPERR_CONNECTING && result!=DPERR_GENERIC )
	{
		PAUSE(( "FAILED (0x%x - %s) - EnumSessions(%s, %s)", result,ErrorNumberToMessage(result),GetDPSessionDesc2(lpsd),GetEnumSessionFlags(dwTimeout, dwFlags) ));
	}
	return result;
}

HRESULT wGetCaps( IDirectPlay4A* dplay4, LPDPCAPS lpDPCaps, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "GetCaps(0x%x, %d)",(int)lpDPCaps, (int)dwFlags ));

	HRESULT result=dplay4->GetCaps( lpDPCaps, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetCaps(0x%x, %d)",result,ErrorNumberToMessage(result),(int)lpDPCaps, (int)dwFlags ));

	return result;
}

HRESULT wGetGroupConnectionSettings( IDirectPlay4A* dplay4, DWORD dwFlags, DPID idGroup, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetGroupConnectionSettings(%d, %d, 0x%x, 0x%x)",(int)dwFlags, idGroup, (int)lpData, (int)lpdwDataSize));

	HRESULT result=dplay4->GetGroupConnectionSettings( dwFlags, idGroup, lpData, lpdwDataSize);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetGroupConnectionSettings(%d, %d, 0x%x,0x%x)",result,ErrorNumberToMessage(result),(int)dwFlags, idGroup, (int)lpData, (int)lpdwDataSize));

	return result;
}

HRESULT wGetGroupData( IDirectPlay4A* dplay4, DPID idGroup, LPVOID lpData, LPDWORD lpdwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "GetGroupData(%d, 0x%x, 0x%x, %d)",idGroup, (int)lpData, (int)lpdwDataSize, (int)dwFlags));

	HRESULT result=dplay4->GetGroupData( idGroup, lpData, lpdwDataSize, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetGroupData(%d, 0x%x, 0x%x, %d)",result,ErrorNumberToMessage(result),idGroup, (int)lpData, (int)lpdwDataSize, (int)dwFlags));

	return result;
}

HRESULT wGetGroupFlags( IDirectPlay4A* dplay4, DPID idGroup, LPDWORD lpdwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "GetGroupFlags(%d, 0x%x)",idGroup, (int)idGroup, (int)lpdwFlags));

	HRESULT result=dplay4->GetGroupFlags( idGroup, lpdwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetGroupFlags(%d, 0x%x)",result,ErrorNumberToMessage(result),idGroup, (int)idGroup, (int)lpdwFlags));

	return result;
}

HRESULT wGetGroupName( IDirectPlay4A* dplay4, DPID idGroup, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetGroupName(%d, 0x%x, 0x%x)",idGroup, (int)lpData, (int)lpdwDataSize));

	HRESULT result=dplay4->GetGroupName( idGroup, lpData, lpdwDataSize);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetGroupName(%d, 0x%x, 0x%x)",result,ErrorNumberToMessage(result),idGroup, (int)lpData, (int)lpdwDataSize));
	return result;
}

HRESULT wGetGroupOwner( IDirectPlay4A* dplay4, DPID idGroup, LPDPID lpidOwner)
{
	SPEW(( GROUP_DIRECTPLAY, "GetGroupOwner(%d, 0x%x)",idGroup, (int)lpidOwner));

	HRESULT result=dplay4->GetGroupOwner( idGroup, lpidOwner);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetGroupOwner(%d, 0x%x)",result,ErrorNumberToMessage(result),idGroup, (int)lpidOwner));

	return result;
}

HRESULT wGetGroupParent( IDirectPlay4A* dplay4, DPID idGroup, LPDPID lpidParent )
{
	SPEW(( GROUP_DIRECTPLAY, "GetGroupParent(%d, 0x%x)",idGroup, (int)lpidParent));

	HRESULT result=dplay4->GetGroupParent( idGroup, lpidParent);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetGroupParent(%d, 0x%x)",result,ErrorNumberToMessage(result),idGroup, (int)lpidParent));

	return result;
}

HRESULT wGetMessageCount( IDirectPlay4A* dplay4, DPID idPlayer, LPDWORD lpdwCount )
{
	SPEW(( GROUP_DIRECTPLAY, "GetMessageCount(%d, 0x%x)",idPlayer, (int)lpdwCount));

	HRESULT result=dplay4->GetMessageCount( idPlayer, lpdwCount);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetMessageCount(%d, 0x%x)",result,ErrorNumberToMessage(result),idPlayer, (int)lpdwCount));

	return result;
}

HRESULT wGetMessageQueue( IDirectPlay4A* dplay4, DPID idFrom, DPID idTo, DWORD dwFlags, LPDWORD lpdwNumMsgs, LPDWORD lpdwNumBytes)
{
	SPEW(( GROUP_DIRECTPLAY, "GetMessageQueue(%d, %d, %d, 0x%x, 0x%x)",idFrom, idTo, dwFlags, lpdwNumMsgs, lpdwNumBytes));

	HRESULT result=dplay4->GetMessageQueue(idFrom, idTo, dwFlags, lpdwNumMsgs, lpdwNumBytes);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetMessageQueue(%d, %d, %d, 0x%x, 0x%x)",result,ErrorNumberToMessage(result),idFrom, idTo, dwFlags, lpdwNumMsgs, lpdwNumBytes));

	return result;
}

HRESULT wGetPlayerAccount( IDirectPlay4A* dplay4, DPID idPlayer, DWORD dwFlags, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetPlayerAccount(%d, %d, 0x%x, 0x%x)",idPlayer, dwFlags, lpData, lpdwDataSize ));

	HRESULT result=dplay4->GetPlayerAccount(idPlayer, dwFlags, lpData, lpdwDataSize);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetPlayerAccount(%d, %d, 0x%x, 0x%x)",result,ErrorNumberToMessage(result),idPlayer, dwFlags, lpData, lpdwDataSize));

	return result;
}

HRESULT wGetPlayerAddress( IDirectPlay4A* dplay4, DPID idPlayer, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetPlayerAddress( Player=%d, BufferSize=%d )",idPlayer, *lpdwDataSize ));

	HRESULT result=dplay4->GetPlayerAddress(idPlayer, lpData, lpdwDataSize);

	if( FAILED(result) && result != DPERR_BUFFERTOOSMALL)
	{
		PAUSE(( "FAILED (0x%x - %s) - GetPlayerAddress( Player=%d, BufferSize=%d )", result,ErrorNumberToMessage(result),idPlayer,*lpdwDataSize ));
	}
		
	return result;
}

HRESULT wGetPlayerCaps( IDirectPlay4A* dplay4, DPID idPlayer, LPDPCAPS lpPlayerCaps, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "GetPlayerCaps(%d, 0x%x, %d)",idPlayer, lpPlayerCaps, dwFlags ));

	HRESULT result=dplay4->GetPlayerCaps(idPlayer, lpPlayerCaps, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetPlayerCaps(%d, 0x%x, %d)",result,ErrorNumberToMessage(result),idPlayer, lpPlayerCaps, dwFlags ));

	return result;
}

HRESULT wGetPlayerData( IDirectPlay4A* dplay4, DPID idPlayer, LPVOID lpData, LPDWORD lpdwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "GetPlayerData(%d, 0x%x, 0x%x, %d)", idPlayer, lpData, lpdwDataSize, dwFlags));

	HRESULT result=dplay4->GetPlayerData(idPlayer, lpData, lpdwDataSize, dwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetPlayerData(%d, 0x%x, 0x%x, %d)", result,ErrorNumberToMessage(result),idPlayer, lpData, lpdwDataSize, dwFlags));

	return result;
}

HRESULT wGetPlayerFlags( IDirectPlay4A* dplay4, DPID idPlayer, LPDWORD lpdwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "GetPlayerFlags(%d, 0x%x)", idPlayer, lpdwFlags));

	HRESULT result=dplay4->GetPlayerFlags(idPlayer, lpdwFlags);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetPlayerFlags(%d, 0x%x)", result,ErrorNumberToMessage(result),idPlayer, lpdwFlags));

	return result;
}

HRESULT wGetPlayerName( IDirectPlay4A* dplay4, DPID idPlayer, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetPlayerName(0x%x, 0x%x)", lpData, lpdwDataSize));

	HRESULT result=dplay4->GetPlayerName(idPlayer, lpData, lpdwDataSize);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetPlayerName(0x%x, 0x%x)", result,ErrorNumberToMessage(result),lpData, lpdwDataSize));

	return result;
}

HRESULT wGetSessionDesc( IDirectPlay4A* dplay4, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetSessionDesc(0x%x, 0x%x)", lpData, lpdwDataSize ));

	HRESULT result=dplay4->GetSessionDesc(lpData, lpdwDataSize);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - GetSessionDesc(0x%x, 0x%x)", result,ErrorNumberToMessage(result),lpData, lpdwDataSize));

	return result;
}

HRESULT wInitialize( IDirectPlay4A* dplay4, LPGUID lpGUID )
{
	SPEW(( GROUP_DIRECTPLAY, "Initialize(0x%x)", lpGUID ));

	HRESULT result=dplay4->Initialize( lpGUID );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Initialize(0x%x)",result,ErrorNumberToMessage(result),lpGUID));

	return result;
}

HRESULT wInitializeConnection( IDirectPlay4A* dplay4, LPVOID lpConnection, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "InitializeConnection( %s)",GetConnectionInfo(lpConnection) ));

	HRESULT result=dplay4->InitializeConnection( lpConnection, dwFlags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - InitializeConnection( %s)",result,ErrorNumberToMessage(result),GetConnectionInfo(lpConnection) ));

	return result;
}

HRESULT wOpen( IDirectPlay4A* dplay4, LPDPSESSIONDESC2 lpsd, DWORD dwFlags)
{
	SPEW(( GROUP_DIRECTPLAY, "Open(%s %s)",GetDPOpenFLags(dwFlags), GetDPSessionDesc2(lpsd) ));

	HRESULT result=dplay4->Open( lpsd, dwFlags );

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - Open(%s %s)",result,ErrorNumberToMessage(result),GetDPOpenFLags(dwFlags), GetDPSessionDesc2(lpsd) ));

	return result;
}

//
// This API does not spew BEFORE calling directx
//
HRESULT wReceive( IDirectPlay4A* dplay4, LPDPID lpidFrom, LPDPID lpidTo, DWORD dwFlags, LPVOID lpData, LPDWORD lpdwDataSize )
{
	HRESULT result=dplay4->Receive(lpidFrom, lpidTo, dwFlags, lpData, lpdwDataSize);

	if( DP_OK==result )
	{
		SPEW(( GROUP_DIRECTPLAY, "Receive(%s) - %s", GetReceiveFlags(dwFlags,lpidFrom,lpidTo), GetReceivedData(lpidFrom,lpData,lpdwDataSize) ));
	}
	else
	{
		if( result==DPERR_NOMESSAGES )
			return result;
		else if( result==DPERR_BUFFERTOOSMALL )
			SPEW(( GROUP_DIRECTPLAY, "Receive(%s) - Buffer too small, needed %d bytes", GetReceiveFlags(dwFlags,lpidFrom,lpidTo), *lpdwDataSize ));
		else
			SPEW(( GROUP_DIRECTPLAY, "Receive(%s) - %s", GetReceiveFlags(dwFlags,lpidFrom,lpidTo), ErrorNumberToMessage(result) ));
	}

	if( FAILED(result) && result!=DPERR_NOMESSAGES )
		PAUSE(( "FAILED (0x%x - %s) - Receive(%s)",result,ErrorNumberToMessage(result),GetReceiveFlags(dwFlags,lpidFrom,lpidTo) ));

	return result;
}

HRESULT wSecureOpen( IDirectPlay4A* dplay4, LPCDPSESSIONDESC2 lpsd, DWORD dwFlags, LPCDPSECURITYDESC lpSecurity, LPCDPCREDENTIALS lpCredentials )
{
	SPEW(( GROUP_DIRECTPLAY, "SecureOpen(%s %s, 0x%x, 0x%x)", GetDPOpenFLags(dwFlags), GetDPSessionDesc2((LPDPSESSIONDESC2)lpsd), lpSecurity, lpCredentials));

	HRESULT result=dplay4->SecureOpen(lpsd, dwFlags, lpSecurity, lpCredentials);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SecureOpen(%s %s, 0x%x, 0x%x)",result, ErrorNumberToMessage(result), GetDPOpenFLags(dwFlags), GetDPSessionDesc2((LPDPSESSIONDESC2)lpsd), lpSecurity, lpCredentials));

	return result;
}

HRESULT wSendChatMessage( IDirectPlay4A* dplay4, DPID idFrom, DPID idTo, DWORD dwFlags, LPDPCHAT lpChatMessage )
{
	SPEW(( GROUP_DIRECTPLAY, "SendChatMessage(From=0x%x, To=0x%x, '%s' %s)",idFrom,idTo,lpChatMessage->lpszMessageA,dwFlags&DPSEND_GUARANTEED ? "GUARANTEED" : "" ));

	HRESULT result=dplay4->SendChatMessage(idFrom, idTo, dwFlags, lpChatMessage);

	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SendChatMessage(From=0x%x, To=0x%x, '%s' %s)",result,ErrorNumberToMessage(result),idFrom,idTo,lpChatMessage->lpszMessageA,dwFlags&DPSEND_GUARANTEED ? "GUARANTEED" : "" ));

	return result;
}

HRESULT wSendEx( IDirectPlay4A* dplay4, DPID idFrom, DPID idTo, DWORD dwFlags, LPVOID lpData, DWORD dwDataSize, DWORD dwPriority, DWORD dwTimeout, LPVOID lpContext, LPDWORD lpdwMsgID )
{
	SPEW(( GROUP_DIRECTPLAY, "SendEx( %s)", GetSendExInfo(idFrom,idTo,dwFlags,dwDataSize,dwPriority,dwTimeout,lpContext,lpdwMsgID) ));

	HRESULT result=dplay4->SendEx(idFrom, idTo, dwFlags, lpData, dwDataSize, dwPriority, dwTimeout, lpContext, lpdwMsgID );
	
	if( FAILED(result) && result != DPERR_PENDING )
		PAUSE(( "FAILED (0x%x - %s) - SendEx( %s)",result,ErrorNumberToMessage(result),GetSendExInfo(idFrom,idTo,dwFlags,dwDataSize,dwPriority,dwTimeout,lpContext,lpdwMsgID) ));

	return result;
}

HRESULT wSend( IDirectPlay4A* dplay4, DPID idFrom, DPID idTo, DWORD dwFlags, LPVOID lpData, DWORD dwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "Send( %s)", GetSendInfo(idFrom,idTo,dwFlags,dwDataSize) ));

	HRESULT result=dplay4->Send(idFrom, idTo, dwFlags, lpData, dwDataSize );
	
	if( FAILED(result) && result != DPERR_PENDING )
		PAUSE(( "FAILED (0x%x - %s) - Send( %s)",result,ErrorNumberToMessage(result),GetSendInfo(idFrom,idTo,dwFlags,dwDataSize) ));

	return result;
}

HRESULT wSetGroupConnectionSettings( IDirectPlay4A* dplay4, DWORD dwFlags, DPID idGroup, LPDPLCONNECTION lpConnection )
{
	SPEW(( GROUP_DIRECTPLAY, "SetGroupConnectionSettings(%d, %d, 0x%x)",dwFlags, idGroup, lpConnection));

	HRESULT result=dplay4->SetGroupConnectionSettings(dwFlags, idGroup, lpConnection);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetGroupConnectionSettings(%d, %d, 0x%x)",result,ErrorNumberToMessage(result),dwFlags, idGroup, lpConnection));

	return result;
}

HRESULT wSetGroupData( IDirectPlay4A* dplay4, DPID idGroup, LPVOID lpData, DWORD dwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "SetGroupData(%d, 0x%x, %d, %d)",dplay4, idGroup, lpData, dwDataSize, dwFlags));

	HRESULT result=dplay4->SetGroupData(idGroup, lpData, dwDataSize, dwFlags);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetGroupData(%d, 0x%x, %d, %d)",result,ErrorNumberToMessage(result),dplay4, idGroup, lpData, dwDataSize, dwFlags));
	
	return result;
}

HRESULT wSetGroupName( IDirectPlay4A* dplay4, DPID idGroup, LPDPNAME lpGroupName, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "SetGroupName(%d, 0x%x, %d)",idGroup, lpGroupName, dwFlags));

	HRESULT result=dplay4->SetGroupName(idGroup, lpGroupName, dwFlags);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetGroupName(%d, 0x%x, %d)",result,ErrorNumberToMessage(result),idGroup, lpGroupName, dwFlags));

	return result;
}

HRESULT wSetGroupOwner( IDirectPlay4A* dplay4, DPID idGroup, DPID idOwner )
{
	SPEW(( GROUP_DIRECTPLAY, "SetGroupOwner(%d, 0x%x, %d)",idGroup, idOwner));

	HRESULT result=dplay4->SetGroupOwner(idGroup, idOwner);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetGroupOwner(%d, 0x%x, %d)",result,ErrorNumberToMessage(result),idGroup, idOwner));

	return result;
}

HRESULT wSetPlayerData( IDirectPlay4A* dplay4, DPID idPlayer, LPVOID lpData, DWORD dwDataSize, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "SetPlayerData(%d, 0x%x, %d, %d)",idPlayer, lpData, dwDataSize, dwFlags));

	HRESULT result=dplay4->SetPlayerData(idPlayer, lpData, dwDataSize, dwFlags);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetPlayerData(%d, 0x%x, %d, %d)",result,ErrorNumberToMessage(result),idPlayer, lpData, dwDataSize, dwFlags));

	return result;
}

HRESULT wSetPlayerName( IDirectPlay4A* dplay4, DPID idPlayer, LPDPNAME lpPlayerName, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "SetPlayerName(%d, 0x%x, %d)",idPlayer, lpPlayerName, dwFlags));

	HRESULT result=dplay4->SetPlayerName(idPlayer, lpPlayerName, dwFlags);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetPlayerName(%d, 0x%x, %d)",	result,ErrorNumberToMessage(result),idPlayer, lpPlayerName, dwFlags));

	return result;
}

HRESULT wSetSessionDesc( IDirectPlay4A* dplay4, LPDPSESSIONDESC2 lpSessDesc, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "SetSessionDesc(0x%x, %d)",lpSessDesc, dwFlags ));

	HRESULT result=dplay4->SetSessionDesc(lpSessDesc, dwFlags);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetSessionDesc(0x%x, %d)", result,ErrorNumberToMessage(result),lpSessDesc, dwFlags ));

	return result;
}

HRESULT wStartSession( IDirectPlay4A* dplay4, DWORD dwFlags, DPID idGroup )
{
	SPEW(( GROUP_DIRECTPLAY, "StartSession(%d, %d)",dwFlags, idGroup));

	HRESULT result=dplay4->StartSession(dwFlags, idGroup);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - StartSession(%d, %d)",result,ErrorNumberToMessage(result),dwFlags, idGroup));

	return result;
}

//
// DirectPlay Lobby functions
//
HRESULT wCreateAddress( IDirectPlayLobby3A* dplobby3, REFGUID guidSP, REFGUID guidDataType, LPCVOID lpData, DWORD dwDataSize, LPVOID lpAddress, LPDWORD lpdwAddressSize )
{
	SPEW(( GROUP_DIRECTPLAY, "CreateAddress(0x%x, 0x%x, 0x%x, %d, 0x%x, 0x%x)", (int)&guidSP, (int)&guidDataType, (int)lpData, dwDataSize, (int)lpAddress, (int)lpdwAddressSize));

	HRESULT result=dplobby3->CreateAddress(guidSP, guidDataType, lpData, dwDataSize, lpAddress, lpdwAddressSize);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateAddress(0x%x, 0x%x, 0x%x, %d, 0x%x, 0x%x)", result,ErrorNumberToMessage(result),(int)&guidSP, (int)&guidDataType, (int)lpData, dwDataSize, (int)lpAddress, (int)lpdwAddressSize));

	return result;
}

HRESULT wCreateCompoundAddress( IDirectPlayLobby3A* dplobby3, LPDPCOMPOUNDADDRESSELEMENT lpElements, DWORD dwElementCount, LPVOID lpAddress, LPDWORD lpdwAddressSize )
{
	SPEW(( GROUP_DIRECTPLAY, "CreateCompoundAddress( Elements=%d, Size=%d )",dwElementCount,*lpdwAddressSize ));

	HRESULT result=dplobby3->CreateCompoundAddress(lpElements, dwElementCount, lpAddress, lpdwAddressSize );
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - CreateCompoundAddress( Elements=%d, Size=%d )",result,ErrorNumberToMessage(result),dwElementCount,*lpdwAddressSize ));

	return result;
}

HRESULT wEnumAddress( IDirectPlayLobby3A* dplobby3, LPDPENUMADDRESSCALLBACK lpEnumAddressCallback, LPCVOID lpAddress, DWORD dwAddressSize, LPVOID lpContext )
{
	SPEW(( GROUP_DIRECTPLAY, "EnumAddress()" ));

	HRESULT result=dplobby3->EnumAddress(lpEnumAddressCallback, lpAddress, dwAddressSize, lpContext);
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - EnumAddress()", result,ErrorNumberToMessage(result) ));

	return result;
}

HRESULT wGetConnectionSettings( IDirectPlayLobby3A* dplobby3, DWORD dwAppID, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "GetConnectionSettings(%d, 0x%x, 0x%x)",(int)dwAppID, (int)lpData, (int)lpdwDataSize ));

	HRESULT result=dplobby3->GetConnectionSettings(dwAppID, lpData,lpdwDataSize);	
	
	if( FAILED(result) && result!=DPERR_NOTLOBBIED && result!=DPERR_BUFFERTOOSMALL )
		PAUSE(( "FAILED (0x%x - %s) - GetConnectionSettings(%d, 0x%x, 0x%x)",result,ErrorNumberToMessage(result),(int)dwAppID, (int)lpData, (int)lpdwDataSize ));

	return result;
}

HRESULT wReceiveLobbyMessage( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, DWORD dwAppID, LPDWORD lpdwMessageFlags, LPVOID lpData, LPDWORD lpdwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "ReceiveLobbyMessage(%d, %d, 0x%x, 0x%x, 0x%x)",
		(int)dwFlags, (int)dwAppID, (int)lpdwMessageFlags, (int)lpData, (int)lpdwDataSize ));

	HRESULT result=dplobby3->ReceiveLobbyMessage(dwFlags, dwAppID, lpdwMessageFlags, lpData, lpdwDataSize);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - ReceiveLobbyMessage(%d, %d, 0x%x, 0x%x, 0x%x)",result,ErrorNumberToMessage(result),(int)dwFlags, (int)dwAppID, (int)lpdwMessageFlags, (int)lpData, (int)lpdwDataSize ));

	return result;
}

HRESULT wRegisterApplication( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, LPDPAPPLICATIONDESC lpAppDesc )
{
	SPEW(( GROUP_DIRECTPLAY, "RegisterApplication(%d, 0x%x)", (int)dwFlags, (int)lpAppDesc));

	HRESULT result=dplobby3->RegisterApplication(dwFlags, lpAppDesc);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - RegisterApplication(%d, 0x%x)", result,ErrorNumberToMessage(result),(int)dwFlags, (int)lpAppDesc));

	return result;
}

HRESULT wRunApplication( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, LPDWORD lpdwAppID, LPDPLCONNECTION lpConn, HANDLE hReceiveEvent )
{
	SPEW(( GROUP_DIRECTPLAY, "RunApplication(%d, 0x%x, 0x%x, %d)", dwFlags, (int)lpdwAppID, (int)lpConn, (int)hReceiveEvent));

	HRESULT result=dplobby3->RunApplication(dwFlags, lpdwAppID, lpConn, hReceiveEvent);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - RunApplication(%d, 0x%x, 0x%x, %d)", result,ErrorNumberToMessage(result),dwFlags, (int)lpdwAppID, (int)lpConn, (int)hReceiveEvent));

	return result;
}

HRESULT wSendLobbyMessage( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, DWORD dwAppID, LPVOID lpData, DWORD dwDataSize )
{
	SPEW(( GROUP_DIRECTPLAY, "SendLobbyMessage(%d, %d, 0x%x, %d)", (int)dwFlags, (int)dwAppID, (int)lpData, (int)dwDataSize ));

	HRESULT result=dplobby3->SendLobbyMessage(dwFlags, dwAppID, lpData, dwDataSize);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SendLobbyMessage(%d, %d, 0x%x, %d)", result,ErrorNumberToMessage(result),(int)dwFlags, (int)dwAppID, (int)lpData, (int)dwDataSize ));

	return result;
}

HRESULT wConnectEx( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, REFIID riid, LPVOID *lplpDP, IUnknown* pUnk )
{
	SPEW(( GROUP_DIRECTPLAY, "ConnectEx()" ));

	HRESULT result=dplobby3->ConnectEx(dwFlags, riid, lplpDP, pUnk);	
	
	if( FAILED(result) && result!=DPERR_CONNECTING )
		PAUSE(( "FAILED (0x%x - %s) - ConnectEx()", result,ErrorNumberToMessage(result) ));

	return result;
}

HRESULT wSetConnectionSettings( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, DWORD dwAppID, LPDPLCONNECTION lpConn )
{
	SPEW(( GROUP_DIRECTPLAY, "SetConnectionSettings(%d, %d, 0x%x, %d)", (int)dwFlags, (int)dwAppID, (int)lpConn));

	HRESULT result=dplobby3->SetConnectionSettings(dwFlags, dwAppID, lpConn);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetConnectionSettings(%d, %d, 0x%x, %d)", result,ErrorNumberToMessage(result),(int)dwFlags, (int)dwAppID, (int)lpConn));

	return result;
}

HRESULT wSetLobbyMessageEvent( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, DWORD dwAppID, HANDLE hReceiveEvent )
{
	SPEW(( GROUP_DIRECTPLAY, "SetLobbyMessageEvent(%d, %d, %d)", (int)dwFlags, (int)dwAppID, (int)hReceiveEvent));

	HRESULT result=dplobby3->SetLobbyMessageEvent(dwFlags, dwAppID, hReceiveEvent);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - SetLobbyMessageEvent(%d, %d, %d)", result,ErrorNumberToMessage(result),(int)dwFlags, (int)dwAppID, (int)hReceiveEvent));

	return result;
}

HRESULT wUnregisterApplication( IDirectPlayLobby3A* dplobby3, DWORD dwFlags, REFGUID guidApplication )
{
	SPEW(( GROUP_DIRECTPLAY, "UnregisterApplication(%d, 0x%x)", (int)dwFlags, (int)&guidApplication));

	HRESULT result=dplobby3->UnregisterApplication(dwFlags, guidApplication);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - UnregisterApplication(%d, 0x%x)", result,ErrorNumberToMessage(result),(int)dwFlags, (int)&guidApplication));

	return result;
}

HRESULT wWaitForConnectionSettings( IDirectPlayLobby3A* dplobby3, DWORD dwFlags )
{
	SPEW(( GROUP_DIRECTPLAY, "WaitForConnectionSettings(%d)", (int)dwFlags));

	HRESULT result=dplobby3->WaitForConnectionSettings(dwFlags);	
	
	if( FAILED(result) )
		PAUSE(( "FAILED (0x%x - %s) - WaitForConnectionSettings(%d)", result,ErrorNumberToMessage(result),(int)dwFlags));

	return result;
}
