From 81e8d149f3a10279034b131f2a330f0c7ad8d8d2 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Thu, 30 May 2019 09:41:28 -0500 Subject: [PATCH] lsteamclient: Fix new network wrapper --- lsteamclient/steamclient_manual_144.cpp | 38 +++++++++++++++++++------ lsteamclient/steamclient_wrappers.c | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/lsteamclient/steamclient_manual_144.cpp b/lsteamclient/steamclient_manual_144.cpp index e17dd769..0acd31f2 100644 --- a/lsteamclient/steamclient_manual_144.cpp +++ b/lsteamclient/steamclient_manual_144.cpp @@ -9,6 +9,10 @@ extern "C" { #include "windows.h" #include "queue.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(steamclient); + /***** manual struct converter for SteamNetworkingMessage_t *****/ struct msg_wrapper { @@ -23,18 +27,24 @@ struct msg_wrapper { SLIST_HEAD(free_msgs_head, msg_wrapper) free_msgs = SLIST_HEAD_INITIALIZER(free_msgs); CRITICAL_SECTION free_msgs_lock = { NULL, -1, 0, 0, 0, 0 }; -void CDECL win_FreeData(struct winSteamNetworkingMessage_t_144 *win_msg) +void __attribute__((ms_abi)) win_FreeData(struct winSteamNetworkingMessage_t_144 *win_msg) { struct msg_wrapper *msg = CONTAINING_RECORD(win_msg, struct msg_wrapper, win_msg); + TRACE("%p\n", msg); if(msg->orig_FreeData) + { + msg->lin_msg->m_pData = msg->win_msg.m_pData; msg->orig_FreeData(msg->lin_msg); + } } -void CDECL win_Release(struct winSteamNetworkingMessage_t_144 *win_msg) +void __attribute__((ms_abi)) win_Release(struct winSteamNetworkingMessage_t_144 *win_msg) { struct msg_wrapper *msg = CONTAINING_RECORD(win_msg, struct msg_wrapper, win_msg); + TRACE("%p\n", msg); msg->lin_msg->m_pfnRelease(msg->lin_msg); msg->lin_msg = NULL; + msg->orig_FreeData = NULL; EnterCriticalSection(&free_msgs_lock); SLIST_INSERT_HEAD(&free_msgs, msg, entry); LeaveCriticalSection(&free_msgs_lock); @@ -42,19 +52,25 @@ void CDECL win_Release(struct winSteamNetworkingMessage_t_144 *win_msg) void lin_FreeData(struct SteamNetworkingMessage_t *lin_msg) { - struct msg_wrapper *msg = CONTAINING_RECORD(lin_msg, struct msg_wrapper, lin_msg); + struct msg_wrapper *msg = (struct msg_wrapper *)lin_msg->m_pData; /* ! see assignment, below */ + TRACE("%p\n", msg); if(msg->win_msg.m_pfnFreeData) - ((void (*)(struct winSteamNetworkingMessage_t_144 *))msg->win_msg.m_pfnFreeData)(&msg->win_msg); + ((void (__attribute__((ms_abi))*)(struct winSteamNetworkingMessage_t_144 *))msg->win_msg.m_pfnFreeData)(&msg->win_msg); } void win_to_lin_struct_SteamNetworkingMessage_t_144(struct winSteamNetworkingMessage_t_144 **w, struct SteamNetworkingMessage_t **l) { + TRACE("\n"); /* it's an output param, do nothing. */ } void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct SteamNetworkingMessage_t **l, struct winSteamNetworkingMessage_t_144 **w) { int i; + + if(n_messages > 0) + TRACE("%u %p %p\n", n_messages, l, w); + for(i = 0; i < n_messages; ++i) { struct msg_wrapper *msg; @@ -64,11 +80,12 @@ void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct Steam msg = SLIST_FIRST(&free_msgs); if(!msg){ + int n; /* allocs can be pricey, so alloc in blocks */ #define MSGS_PER_BLOCK 16 struct msg_wrapper *msgs = (struct msg_wrapper *)HeapAlloc(GetProcessHeap(), 0, sizeof(struct msg_wrapper) * MSGS_PER_BLOCK); - for(i = 1; i < MSGS_PER_BLOCK; ++i) - SLIST_INSERT_HEAD(&free_msgs, &msg[i], entry); + for(n = 1; n < MSGS_PER_BLOCK; ++n) + SLIST_INSERT_HEAD(&free_msgs, &msgs[n], entry); msg = &msgs[0]; }else SLIST_REMOVE_HEAD(&free_msgs, entry); @@ -77,9 +94,6 @@ void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct Steam msg->lin_msg = l[i]; - msg->orig_FreeData = msg->lin_msg->m_pfnFreeData; - msg->lin_msg->m_pfnFreeData = lin_FreeData; - msg->win_msg.m_pData = msg->lin_msg->m_pData; msg->win_msg.m_cbSize = msg->lin_msg->m_cbSize; msg->win_msg.m_conn = msg->lin_msg->m_conn; @@ -92,7 +106,13 @@ void lin_to_win_struct_SteamNetworkingMessage_t_144(int n_messages, struct Steam msg->win_msg.m_nChannel = msg->lin_msg->m_nChannel; msg->win_msg.m___nPadDummy = msg->lin_msg->m___nPadDummy; + msg->orig_FreeData = msg->lin_msg->m_pfnFreeData; + msg->lin_msg->m_pfnFreeData = lin_FreeData; + /* ! store the wrapper here and restore the original pointer from win_msg before calling orig_FreeData */ + msg->lin_msg->m_pData = msg; + w[i] = &msg->win_msg; + TRACE("done with %u, returned wrapper %p\n", i, msg); } } diff --git a/lsteamclient/steamclient_wrappers.c b/lsteamclient/steamclient_wrappers.c index 34c463b5..aa62067e 100644 --- a/lsteamclient/steamclient_wrappers.c +++ b/lsteamclient/steamclient_wrappers.c @@ -283,7 +283,7 @@ void *create_LinuxISteamMatchmakingRulesResponse(void *win, const char *version) /***** FSteamNetworkingSocketsDebugOutput *****/ -static void (CDECL *stored_FSteamNetworkingSocketsDebugOutput)(ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg); +static void (__attribute__((ms_abi)) *stored_FSteamNetworkingSocketsDebugOutput)(ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg); static void lin_FSteamNetworkingSocketsDebugOutput(ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg) {