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 @@ namespace Steamworks 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