From 14d947c7bae625522eb0d086dc52d52465d35417 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Mon, 6 May 2019 12:02:09 +0100 Subject: [PATCH] NetMsg with Release --- Facepunch.Steamworks/Structs/NetMsg.cs | 35 +++++++++++++++++++ .../Structs/SteamNetworking.cs | 31 ---------------- 2 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 Facepunch.Steamworks/Structs/NetMsg.cs diff --git a/Facepunch.Steamworks/Structs/NetMsg.cs b/Facepunch.Steamworks/Structs/NetMsg.cs new file mode 100644 index 0000000..cd79b92 --- /dev/null +++ b/Facepunch.Steamworks/Structs/NetMsg.cs @@ -0,0 +1,35 @@ +using Steamworks.Data; +using System; +using System.Runtime.InteropServices; + +namespace Steamworks.Data +{ + [StructLayout( LayoutKind.Sequential )] + internal struct NetMsg + { + // #32bit + internal IntPtr DataPtr; + internal int DataSize; + internal NetConnection Connection; + internal NetworkIdentity Identity; + internal long ConnectionUserData; + internal SteamNetworkingMicroseconds TimeRecv; + internal long MessageNumber; + internal IntPtr FreeDataPtr; + internal IntPtr ReleasePtr; + internal int Channel; + + + internal delegate void ReleaseDelegate( IntPtr msg ); + + public void Release( IntPtr data ) + { + // + // I think this function might be a static global, so we could probably + // cache this release call. + // + var d = Marshal.GetDelegateForFunctionPointer( ReleasePtr ); + d( data ); + } + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/SteamNetworking.cs b/Facepunch.Steamworks/Structs/SteamNetworking.cs index 02966f3..ce751c2 100644 --- a/Facepunch.Steamworks/Structs/SteamNetworking.cs +++ b/Facepunch.Steamworks/Structs/SteamNetworking.cs @@ -41,37 +41,6 @@ namespace Steamworks.Data public override string ToString() => Value.ToString(); } - [StructLayout( LayoutKind.Sequential )] - public struct SteamNetworkingMessage_t - { - public IntPtr data; - public int length; - public NetConnection connection; - public NetworkIdentity identity; - public long userData; - public SteamNetworkingMicroseconds timeReceived; - public long messageNumber; - internal IntPtr release; - public int channel; - private int pad; - /* - public void CopyTo( byte[] destination ) - { - if ( destination == null ) - throw new ArgumentNullException( "destination" ); - - Marshal.Copy( data, destination, 0, length ); - } - - public void Destroy() - { - if ( release == IntPtr.Zero ) - throw new InvalidOperationException( "Message not created" ); - - Native.SteamAPI_SteamNetworkingMessage_t_Release( release ); - }*/ - } - [StructLayout( LayoutKind.Sequential )] public struct SteamNetworkingQuickConnectionStatus {