From 1f60545688de6fde90daaeb171fda4348b6c31a0 Mon Sep 17 00:00:00 2001 From: Riley Labrecque Date: Sat, 5 Jun 2021 08:34:45 -0700 Subject: [PATCH 1/2] SteamNetworkingMessage_t: Implement a Release function which takes an IntPtr --- .../SteamNetworkingMessage_t.cs | 15 ++++++++++++++- .../SteamNetworkingMessage_t.cs | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs b/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs index 4fff04cc..6a9beb56 100644 --- a/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs +++ b/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs @@ -79,7 +79,20 @@ public struct SteamNetworkingMessage_t /// You MUST call this when you're done with the object, /// to free up memory, etc. public void Release() { - NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(m_pfnRelease); + throw new System.NotImplementedException("Please use the static Release function instead which takes an IntPtr."); + } + + /// You MUST call this when you're done with the object, + /// to free up memory, etc. + /// This is a Steamworks.NET extension. + public static void Release(IntPtr pointer) { + NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(pointer); + } + + /// Convert an IntPtr received from ISteamNetworkingSockets.ReceiveMessagesOnPollGroup into our structure. + /// This is a Steamworks.NET extension. + public static SteamNetworkingMessage_t FromIntPtr(IntPtr pointer) { + return (SteamNetworkingMessage_t)Marshal.PtrToStructure(pointer, typeof(SteamNetworkingMessage_t)); } } } diff --git a/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs b/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs index 7335075f..84ac88ee 100644 --- a/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs +++ b/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs @@ -95,7 +95,20 @@ public struct SteamNetworkingMessage_t /// You MUST call this when you're done with the object, /// to free up memory, etc. public void Release() { - NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(m_pfnRelease); + throw new System.NotImplementedException("Please use the static Release function instead which takes an IntPtr."); + } + + /// You MUST call this when you're done with the object, + /// to free up memory, etc. + /// This is a Steamworks.NET extension. + public static void Release(IntPtr pointer) { + NativeMethods.SteamAPI_SteamNetworkingMessage_t_Release(pointer); + } + + /// Convert an IntPtr received from ISteamNetworkingSockets.ReceiveMessagesOnPollGroup into our structure. + /// This is a Steamworks.NET extension. + public static SteamNetworkingMessage_t FromIntPtr(IntPtr pointer) { + return (SteamNetworkingMessage_t)Marshal.PtrToStructure(pointer, typeof(SteamNetworkingMessage_t)); } } } From 353de9da3f59a56b7fc173aa2660571c95571bb8 Mon Sep 17 00:00:00 2001 From: Riley Labrecque Date: Sat, 5 Jun 2021 08:35:08 -0700 Subject: [PATCH 2/2] SteamNetworkingMessage_t: Convert p_pfnFreeData from internal to public --- .../SteamNetworkingTypes/SteamNetworkingMessage_t.cs | 2 +- .../types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs b/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs index 6a9beb56..7bebdbb1 100644 --- a/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs +++ b/CodeGen/CustomTypes/SteamNetworkingTypes/SteamNetworkingMessage_t.cs @@ -53,7 +53,7 @@ public struct SteamNetworkingMessage_t /// usually be something like: /// /// free( pMsg->m_pData ); - internal IntPtr m_pfnFreeData; + public IntPtr m_pfnFreeData; /// Function to used to decrement the internal reference count and, if /// it's zero, release the message. You should not set this function pointer, diff --git a/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs b/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs index 84ac88ee..31b5f843 100644 --- a/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs +++ b/com.rlabrecque.steamworks.net/Runtime/types/SteamNetworkingTypes/SteamNetworkingMessage_t.cs @@ -69,7 +69,7 @@ public struct SteamNetworkingMessage_t /// usually be something like: /// /// free( pMsg->m_pData ); - internal IntPtr m_pfnFreeData; + public IntPtr m_pfnFreeData; /// Function to used to decrement the internal reference count and, if /// it's zero, release the message. You should not set this function pointer,