mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-13 04:50:04 +03:00
62 lines
1.2 KiB
C#
62 lines
1.2 KiB
C#
using Steamworks.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Steamworks
|
|
{
|
|
internal struct CallbackResult<T> : INotifyCompletion where T : struct, ICallbackData
|
|
{
|
|
SteamAPICall_t call;
|
|
|
|
public CallbackResult( SteamAPICall_t call )
|
|
{
|
|
this.call = call;
|
|
}
|
|
|
|
public void OnCompleted( Action continuation )
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public T? GetResult()
|
|
{
|
|
if ( !SteamUtils.IsCallComplete( call, out var failed ) || failed )
|
|
return null;
|
|
|
|
var t = default( T );
|
|
var size = t.DataSize;
|
|
var ptr = Marshal.AllocHGlobal( size );
|
|
|
|
try
|
|
{
|
|
if ( !SteamUtils.Internal.GetAPICallResult( call, ptr, size, t.CallbackId, ref failed ) || failed )
|
|
return null;
|
|
|
|
return ((T)Marshal.PtrToStructure( ptr, typeof( T ) ));
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeHGlobal( ptr );
|
|
}
|
|
}
|
|
|
|
public bool IsCompleted
|
|
{
|
|
get
|
|
{
|
|
if ( SteamUtils.IsCallComplete( call, out var failed ) || failed )
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
internal CallbackResult<T> GetAwaiter()
|
|
{
|
|
return this;
|
|
}
|
|
}
|
|
} |