forked from FoxCouncil/Steamworks.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallResult.cs
66 lines (61 loc) · 2.18 KB
/
CallResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Text;
namespace Steamworks.Core
{
static class CallbackFactory
{
unsafe internal delegate void InternalHandler(void* A_0, bool A_1);
#if IA32
[System.Runtime.InteropServices.DllImport("APICallbackFactoryx86")]
#elif AMD64
[System.Runtime.InteropServices.DllImport("APICallbackFactoryx64")]
#endif
internal static extern IntPtr MakeCallResult(int callbackID, CallResultFlags flags, ulong apiCallHandle, int size, InternalHandler handler);
}
/// <summary>
/// Flags
/// </summary>
public enum CallResultFlags : byte
{
/// <summary>No other options.</summary>
None = 0,
///<summary>Steamworks internal.</summary>
k_ECallbackFlagsRegistered = 1,
/// <summary>Make this callresult as game server call.</summary>
k_ECallbackFlagsGameServer = 2
}
/// <summary>
/// Provide access to Callresult System.
/// </summary>
/// <typeparam name="T"></typeparam>
public class CallResult<T> where T : unmanaged
{
/// <summary>
/// Callresult handler
/// </summary>
/// <param name="result"></param>
/// <param name="ioFail"></param>
public delegate void CallResultHandler(ref T result, bool ioFail);
/// <summary>
/// This will be invoked when result is received.
/// </summary>
public event CallResultHandler OnReceivedResult;
/// <summary>
/// Create A Call result listener
/// </summary>
/// <param name="APICallHandle"></param>
/// <param name="k_iCallback"></param>
/// <param name="flags"></param>
public unsafe CallResult(ulong APICallHandle, int k_iCallback, CallResultFlags flags = CallResultFlags.None)
{
CallbackBase = CallbackFactory.MakeCallResult(k_iCallback, flags, APICallHandle, sizeof(T), InternalCallresultHandler);
}
private IntPtr CallbackBase = IntPtr.Zero;
private unsafe void InternalCallresultHandler(void* param, bool iofail)
{
T result = *(T*)param;
OnReceivedResult(ref result, iofail);
}
}
}