Files
ClientModLoader/Plugin.ClientModLoader/Utils/CallResultAsync.cs
pas2704 e475c32843
Some checks failed
Build / Compute Version (push) Successful in 5s
Build / Build Nuget package (push) Failing after 6s
build workflow and spacing cleanup
2025-05-11 16:37:46 -04:00

32 lines
919 B
C#

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Steamworks;
namespace Plugin.ClientModLoader.Utils;
public static class CallResultAsync<T> where T : struct
{
public static async Task<T> Create(SteamAPICall_t call)
{
var tcs = new TaskCompletionSource<T>();
using var callResult = CallResult<T>.Create((args, failed) =>
{
if (failed)
{
ref var result = ref Unsafe.As<T, GenericCallResult>(ref args);
tcs.TrySetException(new Exception($"CallResult failed: {result.m_eResult}"));
}
else tcs.TrySetResult(args);
});
callResult.Set(call);
return await tcs.Task;
}
[StructLayout(LayoutKind.Sequential, Pack = 8)]
private struct GenericCallResult
{
public UGCQueryHandle_t m_handle;
public EResult m_eResult;
}
}