This commit is contained in:
zznty
2025-05-11 02:37:57 +07:00
commit 947fcde9ca
14 changed files with 754 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
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;
}
}