-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
SharedCSharpResourceImpl.cs
46 lines (37 loc) · 1.17 KB
/
SharedCSharpResourceImpl.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
using System.Runtime.InteropServices;
using AltV.Net.Elements.Args;
namespace AltV.Net.Shared
{
public class SharedCSharpResourceImpl : ISharedCSharpResourceImpl
{
internal readonly IntPtr NativePointer;
protected ISharedCore core;
private readonly Dictionary<IntPtr, GCHandle> invokers = new();
public IntPtr CreateInvoker(MValueFunctionCallback function)
{
IntPtr invoker;
unsafe
{
invoker = core.Library.Shared.Invoker_Create(NativePointer, function);
}
invokers[invoker] = GCHandle.Alloc(function);
return invoker;
}
public void DestroyInvoker(IntPtr invoker)
{
if (invokers.Remove(invoker, out var gcHandle))
{
gcHandle.Free();
}
unsafe
{
core.Library.Shared.Invoker_Destroy(NativePointer, invoker);
}
}
public SharedCSharpResourceImpl(ISharedCore core, IntPtr nativePointer)
{
this.core = core;
this.NativePointer = nativePointer;
}
}
}