using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Steamworks; namespace Plugin.ClientModLoader.Utils; public static class CallResultAsync where T : struct { public static async Task Create(SteamAPICall_t call) { var tcs = new TaskCompletionSource(); using var callResult = CallResult.Create((args, failed) => { if (failed) { ref var result = ref Unsafe.As(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; } }