Added Utils.GetResult( call ) (generic)

This commit is contained in:
Garry Newman 2019-04-13 18:46:57 +01:00
parent 39a63f6906
commit fac123324d

View File

@ -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<T>( 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 );
}
}
}
}