Files
BusyRabbit/Plugins/UnrealSharp/Managed/UnrealSharp/UnrealSharp.Binds/BindsManager.cs
wyatt 648386cd73 Lua向C#逻辑迁移 一期 #13
将整个插件代码上传
2025-10-26 21:48:39 +08:00

38 lines
1.2 KiB
C#

namespace UnrealSharp.Binds;
public static class NativeBinds
{
private unsafe static delegate* unmanaged[Cdecl]<char*, char*, int, IntPtr> _getBoundFunction = null;
public unsafe static void InitializeNativeBinds(IntPtr bindsCallbacks)
{
if (_getBoundFunction != null)
{
throw new Exception("NativeBinds.InitializeNativeBinds called twice");
}
_getBoundFunction = (delegate* unmanaged[Cdecl]<char*, char*, int, IntPtr>)bindsCallbacks;
}
public unsafe static IntPtr TryGetBoundFunction(string outerName, string functionName, int functionSize)
{
if (_getBoundFunction == null)
{
throw new Exception("NativeBinds not initialized");
}
IntPtr functionPtr = IntPtr.Zero;
fixed (char* outerNamePtr = outerName)
fixed (char* functionNamePtr = functionName)
{
functionPtr = _getBoundFunction(outerNamePtr, functionNamePtr, functionSize);
}
if (functionPtr == IntPtr.Zero)
{
throw new Exception($"Failed to find bound function {functionName} in {outerName}");
}
return functionPtr;
}
}