mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-10 11:30:05 +03:00
Added Utils.GetResult( call ) (generic)
This commit is contained in:
parent
39a63f6906
commit
fac123324d
@ -29,5 +29,32 @@ namespace Steamworks
|
|||||||
failed = false;
|
failed = false;
|
||||||
return steamutils.IsAPICallCompleted( call, ref failed );
|
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…
x
Reference in New Issue
Block a user