mirror of
https://github.com/gwdevhub/Daybreak.git
synced 2026-07-21 01:59:49 +00:00
20 lines
465 B
C#
20 lines
465 B
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Daybreak.API.Interop;
|
|
|
|
public sealed class GWDelegateCache<TDelegate>(GWAddressCache cache)
|
|
where TDelegate : Delegate
|
|
{
|
|
public GWAddressCache Cache { get; } = cache;
|
|
|
|
public TDelegate? GetDelegate()
|
|
{
|
|
if (this.Cache.GetAddress() is not nuint address)
|
|
{
|
|
return default;
|
|
}
|
|
|
|
return Marshal.GetDelegateForFunctionPointer<TDelegate>((nint)address);
|
|
}
|
|
}
|