From fac123324d6675e2b405571fe78086957d17112d Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Sat, 13 Apr 2019 18:46:57 +0100 Subject: [PATCH] Added Utils.GetResult( call ) (generic) --- Facepunch.Steamworks/Redux/Utils.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Facepunch.Steamworks/Redux/Utils.cs b/Facepunch.Steamworks/Redux/Utils.cs index f634ddd..86e8d2c 100644 --- a/Facepunch.Steamworks/Redux/Utils.cs +++ b/Facepunch.Steamworks/Redux/Utils.cs @@ -29,5 +29,32 @@ internal static bool IsCallComplete( SteamAPICall_t call, out bool failed ) failed = false; return steamutils.IsAPICallCompleted( call, ref failed ); } + + internal static T? GetResult( SteamAPICall_t call ) where T : struct, ISteamCallback + { + var t = new T(); + + var size = t.GetStructSize(); + var ptr = Marshal.AllocHGlobal( size ); + + try + { + bool failed = false; + + if ( !steamutils.GetAPICallResult( call, ptr, size, t.GetCallbackId(), ref failed ) ) + return null; + + if ( failed ) + return null; + + t = (T)t.Fill( ptr, size ); + + return t; + } + finally + { + Marshal.FreeHGlobal( ptr ); + } + } } } \ No newline at end of file