mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Added Utils.GetResult( call ) (generic)
This commit is contained in:
parent
39a63f6906
commit
fac123324d
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user