lsteamclient: Rewrite SteamNetworkingMessage_t_144 unix thunks.

CW-Bug-Id: #22729
This commit is contained in:
Rémi Bernon 2023-10-02 10:51:14 +02:00 committed by Arkadiusz Hiler
parent 0e4fab2dff
commit b56d6aa766
8 changed files with 285 additions and 114 deletions

View file

@ -215,8 +215,6 @@ SOURCES = \
cppISteamUserStats_STEAMUSERSTATS_INTERFACE_VERSION012.cpp \
cppISteamVideo_STEAMVIDEO_INTERFACE_V001.cpp \
cppISteamVideo_STEAMVIDEO_INTERFACE_V002.cpp \
steamclient_manual_144.cpp \
steamclient_manual_146.cpp \
steamclient_manual_147.cpp \
steamclient_manual_148a.cpp \
steamclient_manual_150.cpp \
@ -289,5 +287,6 @@ SOURCES = \
struct_converters_158.cpp \
unix_steam_client_manual.cpp \
unix_steam_input_manual.cpp \
unix_steam_networking_manual.cpp \
unix_steam_utils_manual.cpp \
unixlib_generated.cpp \

View file

@ -204,8 +204,8 @@ MANUAL_STRUCTS = [
MANUAL_METHODS = {
#TODO: 001 005 007
#NOTE: 003 never appeared in a public SDK, but is an alias for 002 (the version in SDK 1.45 is actually 004 but incorrectly versioned as 003)
"ISteamNetworkingSockets_ReceiveMessagesOnConnection": lambda ver, abi: abi == 'u',
"ISteamNetworkingSockets_ReceiveMessagesOnListenSocket": lambda ver, abi: abi == 'u',
"ISteamNetworkingSockets_ReceiveMessagesOnConnection": lambda ver, abi: abi == 'u' or ver <= 4,
"ISteamNetworkingSockets_ReceiveMessagesOnListenSocket": lambda ver, abi: abi == 'u' or ver <= 4,
"ISteamNetworkingSockets_ReceiveMessagesOnPollGroup": lambda ver, abi: abi == 'u',
"ISteamNetworkingSockets_SendMessages": lambda ver, abi: abi == 'u',

View file

@ -1,9 +1,194 @@
#include "steamclient_private.h"
#include "cppISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort001.h"
#include "cppISteamNetworkingSockets_SteamNetworkingSockets002.h"
#include "cppISteamNetworkingSockets_SteamNetworkingSockets004.h"
WINE_DEFAULT_DEBUG_CHANNEL(steamclient);
struct networking_message_pool
{
LONG ref;
void *message_data;
struct networking_message messages[];
};
C_ASSERT( sizeof(struct networking_message_pool) == offsetof( struct networking_message_pool, messages[0] ) );
static void networking_message_pool_release( struct networking_message_pool *pool )
{
if (!InterlockedDecrement( &pool->ref ))
{
HeapFree( GetProcessHeap(), 0, pool->message_data );
HeapFree( GetProcessHeap(), 0, pool );
}
}
static bool networking_message_pool_alloc_data( uint32_t count, struct networking_message_pool *pool )
{
uint32_t i, size;
char *ptr;
for (i = 0, size = 0; i < count; i++) size += *pool->messages[i].p_size;
if (!(pool->message_data = HeapAlloc( GetProcessHeap(), 0, size )))
{
ERR( "Failed to allocate memory for networking messages\n" );
return false;
}
for (i = 0, ptr = pool->message_data; i < count; i++)
{
*pool->messages[i].p_data = ptr;
ptr += *pool->messages[i].p_size;
}
return true;
}
static void W_STDCALL w_SteamNetworkingMessage_t_144_FreeData( w_SteamNetworkingMessage_t_144 *msg )
{
if (msg->m_pData) SecureZeroMemory( msg->m_pData, msg->m_cbSize );
}
static void W_STDCALL w_SteamNetworkingMessage_t_144_Release( w_SteamNetworkingMessage_t_144 *msg )
{
struct networking_message *message = CONTAINING_RECORD( msg, struct networking_message, w_msg_144 );
if (msg->m_pfnFreeData) msg->m_pfnFreeData( msg );
SecureZeroMemory( msg, sizeof(*msg) );
networking_message_pool_release( message->pool );
}
static w_SteamNetworkingMessage_t_144 *networking_message_init_144( struct networking_message *message,
struct networking_message_pool *pool )
{
message->pool = pool;
message->p_data = &message->w_msg_144.m_pData;
message->p_size = &message->w_msg_144.m_cbSize;
message->w_msg_144.m_pfnFreeData = w_SteamNetworkingMessage_t_144_FreeData;
message->w_msg_144.m_pfnRelease = w_SteamNetworkingMessage_t_144_Release;
return &message->w_msg_144;
}
static bool networking_message_pool_create_144( uint32_t count, w_SteamNetworkingMessage_t_144 **messages )
{
uint32_t size = offsetof( struct networking_message_pool, messages[count] );
struct networking_message_pool *pool;
if (!(pool = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size )))
{
ERR( "Failed to allocate memory for networking messages\n" );
return false;
}
pool->ref = count;
while (count--) messages[count] = networking_message_init_144( &pool->messages[count], pool );
return true;
}
static bool networking_message_pool_receive_144( int32_t capacity, int32_t count, w_SteamNetworkingMessage_t_144 **messages )
{
struct networking_message_pool *pool = CONTAINING_RECORD( messages[0], struct networking_message, w_msg_144 )->pool;
int32_t i;
for (i = count; i < capacity; i++) messages[i]->m_pfnRelease( messages[i] );
if (count > 0)
{
if (!networking_message_pool_alloc_data( count, pool )) return false;
unix_networking_messages_receive_144( count, messages );
}
return true;
}
/* ISteamNetworkingSockets_SteamNetworkingSockets002 */
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection( struct w_steam_iface *_this,
uint32_t hConn, w_SteamNetworkingMessage_t_144 **ppOutMessages,
int32_t nMaxMessages )
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection_params params =
{
.linux_side = _this->u_iface,
.hConn = hConn,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE( "%p\n", _this );
if (!networking_message_pool_create_144( nMaxMessages, params.ppOutMessages )) return 0;
cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection( &params );
if (!networking_message_pool_receive_144( nMaxMessages, params._ret, params.ppOutMessages )) return 0;
return params._ret;
}
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket( struct w_steam_iface *_this, uint32_t hSocket,
w_SteamNetworkingMessage_t_144 **ppOutMessages, int32_t nMaxMessages )
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket_params params =
{
.linux_side = _this->u_iface,
.hSocket = hSocket,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE( "%p\n", _this );
if (!networking_message_pool_create_144( nMaxMessages, params.ppOutMessages )) return 0;
cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket( &params );
if (!networking_message_pool_receive_144( nMaxMessages, params._ret, params.ppOutMessages )) return 0;
return params._ret;
}
/* ISteamNetworkingSockets_SteamNetworkingSockets004 */
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection( struct w_steam_iface *_this,
uint32_t hConn, w_SteamNetworkingMessage_t_144 **ppOutMessages,
int32_t nMaxMessages )
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection_params params =
{
.linux_side = _this->u_iface,
.hConn = hConn,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE( "%p\n", _this );
if (!networking_message_pool_create_144( nMaxMessages, params.ppOutMessages )) return 0;
cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection( &params );
if (!networking_message_pool_receive_144( nMaxMessages, params._ret, params.ppOutMessages )) return 0;
return params._ret;
}
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket( struct w_steam_iface *_this, uint32_t hSocket,
w_SteamNetworkingMessage_t_144 **ppOutMessages, int32_t nMaxMessages )
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket_params params =
{
.linux_side = _this->u_iface,
.hSocket = hSocket,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE( "%p\n", _this );
if (!networking_message_pool_create_144( nMaxMessages, params.ppOutMessages )) return 0;
cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket( &params );
if (!networking_message_pool_receive_144( nMaxMessages, params._ret, params.ppOutMessages )) return 0;
return params._ret;
}
/* ISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort001 */
void __thiscall winISteamNetworkingFakeUDPPort_SteamNetworkingFakeUDPPort001_DestroyFakeUDPPort( struct w_steam_iface *_this )

View file

@ -1,27 +0,0 @@
#include "unix_private.h"
extern "C"
{
#define SDK_VERSION 1440
#include "steamclient_manual_common.h"
}
#include "cppISteamNetworkingSockets_SteamNetworkingSockets002.hpp"
void cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection( struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_ppOutMessages[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnConnection( params->hConn, u_ppOutMessages, params->nMaxMessages );
lin_to_win_struct_SteamNetworkingMessage_t( params->_ret, u_ppOutMessages,
params->ppOutMessages, params->nMaxMessages );
}
void cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket( struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_ppOutMessages[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnListenSocket( params->hSocket, u_ppOutMessages, params->nMaxMessages );
lin_to_win_struct_SteamNetworkingMessage_t( params->_ret, u_ppOutMessages,
params->ppOutMessages, params->nMaxMessages );
}

View file

@ -1,27 +0,0 @@
#include "unix_private.h"
extern "C"
{
#define SDK_VERSION 1460
#include "steamclient_manual_common.h"
}
#include "cppISteamNetworkingSockets_SteamNetworkingSockets004.hpp"
void cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection( struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_ppOutMessages[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnConnection( params->hConn, u_ppOutMessages, params->nMaxMessages );
lin_to_win_struct_SteamNetworkingMessage_t( params->_ret, u_ppOutMessages,
params->ppOutMessages, params->nMaxMessages );
}
void cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket( struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_ppOutMessages[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnListenSocket( params->hSocket, u_ppOutMessages, params->nMaxMessages );
lin_to_win_struct_SteamNetworkingMessage_t( params->_ret, u_ppOutMessages,
params->ppOutMessages, params->nMaxMessages );
}

View file

@ -0,0 +1,78 @@
#include "steamclient_structs.h"
#include "cppISteamNetworkingSockets_SteamNetworkingSockets002.hpp"
#include "cppISteamNetworkingSockets_SteamNetworkingSockets004.hpp"
static void receive_messages_utow_144( uint32_t count, u_SteamNetworkingMessage_t_144 **u_msgs,
w_SteamNetworkingMessage_t_144 **w_msgs )
{
uint32_t i;
for (i = 0; i < count; i++)
{
struct networking_message *message = CONTAINING_RECORD( w_msgs[i], struct networking_message, w_msg_144 );
w_SteamNetworkingMessage_t_144 *w_msg = &message->w_msg_144;
u_SteamNetworkingMessage_t_144 *u_msg = u_msgs[i];
message->u_msg_144 = u_msg;
w_msg->m_cbSize = u_msg->m_cbSize;
w_msg->m_conn = u_msg->m_conn;
w_msg->m_sender = u_msg->m_sender;
w_msg->m_nConnUserData = u_msg->m_nConnUserData;
w_msg->m_usecTimeReceived = u_msg->m_usecTimeReceived;
w_msg->m_nMessageNumber = u_msg->m_nMessageNumber;
w_msg->m_nChannel = u_msg->m_nChannel;
}
}
void unix_networking_messages_receive_144( uint32_t count, w_SteamNetworkingMessage_t_144 **w_msgs )
{
uint32_t i;
for (i = 0; i < count; i++)
{
struct networking_message *message = CONTAINING_RECORD( w_msgs[i], struct networking_message, w_msg_144 );
w_SteamNetworkingMessage_t_144 *w_msg = &message->w_msg_144;
u_SteamNetworkingMessage_t_144 *u_msg = message->u_msg_144;
memcpy( w_msg->m_pData, u_msg->m_pData, u_msg->m_cbSize );
u_msg->m_pfnRelease( u_msg );
message->u_msg_144 = NULL;
}
}
/* ISteamNetworkingSockets_SteamNetworkingSockets002 */
void cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection( struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_msgs[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnConnection( params->hConn, u_msgs, params->nMaxMessages );
if (params->_ret > 0) receive_messages_utow_144( params->_ret, u_msgs, params->ppOutMessages );
}
void cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket( struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets002 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_msgs[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnListenSocket( params->hSocket, u_msgs, params->nMaxMessages );
if (params->_ret > 0) receive_messages_utow_144( params->_ret, u_msgs, params->ppOutMessages );
}
/* ISteamNetworkingSockets_SteamNetworkingSockets004 */
void cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection( struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_msgs[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnConnection( params->hConn, u_msgs, params->nMaxMessages );
if (params->_ret > 0) receive_messages_utow_144( params->_ret, u_msgs, params->ppOutMessages );
}
void cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket( struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket_params *params )
{
struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *iface = (struct u_ISteamNetworkingSockets_SteamNetworkingSockets004 *)params->linux_side;
u_SteamNetworkingMessage_t_144 *u_msgs[params->nMaxMessages];
params->_ret = iface->ReceiveMessagesOnListenSocket( params->hSocket, u_msgs, params->nMaxMessages );
if (params->_ret > 0) receive_messages_utow_144( params->_ret, u_msgs, params->ppOutMessages );
}

View file

@ -9,6 +9,10 @@
#include <windef.h>
#include <winbase.h>
#ifndef STEAM_API_H
#include "steamclient_structs.h"
#endif
#ifdef __cplusplus
extern "C"
{
@ -62,6 +66,21 @@ struct callback_data
void execute_callback(struct callback_data *cb_data);
bool is_native_thread(void);
#ifndef STEAM_API_H
struct networking_message_pool;
struct networking_message
{
struct networking_message_pool *pool;
void **p_data;
uint32_t *p_size;
u_SteamNetworkingMessage_t_144 *u_msg_144;
w_SteamNetworkingMessage_t_144 w_msg_144;
};
extern void unix_networking_messages_receive_144( uint32_t count, w_SteamNetworkingMessage_t_144 **w_msgs );
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */

View file

@ -201,34 +201,6 @@ uint32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets002_FlushMe
return params._ret;
}
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection(struct w_steam_iface *_this, uint32_t hConn, w_SteamNetworkingMessage_t_144 **ppOutMessages, int32_t nMaxMessages)
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection_params params =
{
.linux_side = _this->u_iface,
.hConn = hConn,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE("%p\n", _this);
cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnConnection( &params );
return params._ret;
}
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket(struct w_steam_iface *_this, uint32_t hSocket, w_SteamNetworkingMessage_t_144 **ppOutMessages, int32_t nMaxMessages)
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket_params params =
{
.linux_side = _this->u_iface,
.hSocket = hSocket,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE("%p\n", _this);
cppISteamNetworkingSockets_SteamNetworkingSockets002_ReceiveMessagesOnListenSocket( &params );
return params._ret;
}
bool __thiscall winISteamNetworkingSockets_SteamNetworkingSockets002_GetConnectionInfo(struct w_steam_iface *_this, uint32_t hConn, SteamNetConnectionInfo_t_144 *pInfo)
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets002_GetConnectionInfo_params params =
@ -650,34 +622,6 @@ uint32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets004_FlushMe
return params._ret;
}
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection(struct w_steam_iface *_this, uint32_t hConn, w_SteamNetworkingMessage_t_144 **ppOutMessages, int32_t nMaxMessages)
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection_params params =
{
.linux_side = _this->u_iface,
.hConn = hConn,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE("%p\n", _this);
cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnConnection( &params );
return params._ret;
}
int32_t __thiscall winISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket(struct w_steam_iface *_this, uint32_t hSocket, w_SteamNetworkingMessage_t_144 **ppOutMessages, int32_t nMaxMessages)
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket_params params =
{
.linux_side = _this->u_iface,
.hSocket = hSocket,
.ppOutMessages = ppOutMessages,
.nMaxMessages = nMaxMessages,
};
TRACE("%p\n", _this);
cppISteamNetworkingSockets_SteamNetworkingSockets004_ReceiveMessagesOnListenSocket( &params );
return params._ret;
}
bool __thiscall winISteamNetworkingSockets_SteamNetworkingSockets004_GetConnectionInfo(struct w_steam_iface *_this, uint32_t hConn, SteamNetConnectionInfo_t_144 *pInfo)
{
struct cppISteamNetworkingSockets_SteamNetworkingSockets004_GetConnectionInfo_params params =