/// <summary> /// Loads DLL and function delegate of <paramref name="nativeFunction"/> if not yet loaded. /// To achieve thread safety calls to this method must be synchronized. /// Note: This method is being called by dynamically generated code. Be careful when changing its signature. /// </summary> internal static void LoadTargetFunction(NativeFunction nativeFunction, bool ignoreLoadError) { var dll = nativeFunction.containingDll; if (dll.handle == IntPtr.Zero) { dll.handle = SysLoadDll(dll.path); if (dll.handle == IntPtr.Zero) { if (!ignoreLoadError) { dll.loadingError = true; #if UNITY_EDITOR DispatchOnMainThread(() => { EditorApplication.isPaused = true; }); #endif throw new NativeDllException($"Could not load DLL \"{dll.name}\" at path \"{dll.path}\"."); } return; } else { dll.loadingError = false; LowLevelPluginManager.OnDllLoaded(dll); // Call the custom triggers once UnityPluginLoad has been called // For Lazy mode call the triggers immediately, preload waits until all functions are loaded (in LoadAll) if (Options.loadingMode == DllLoadingMode.Lazy) { InvokeCustomTriggers(_customLoadedTriggers, dll); } } } if (nativeFunction.@delegate == null) { IntPtr funcPtr = SysGetDllProcAddress(dll.handle, nativeFunction.identity.symbol); if (funcPtr == IntPtr.Zero) { if (!ignoreLoadError) { dll.symbolError = true; #if UNITY_EDITOR DispatchOnMainThread(() => { EditorApplication.isPaused = true; }); #endif throw new NativeDllException($"Could not get address of symbol \"{nativeFunction.identity.symbol}\" in DLL \"{dll.name}\" at path \"{dll.path}\"."); } return; } else { dll.symbolError = false; } nativeFunction.@delegate = Marshal.GetDelegateForFunctionPointer(funcPtr, nativeFunction.delegateType); } }
/// <summary> /// Loads DLL and function delegate of <paramref name="nativeFunction"/> if not yet loaded. /// To achieve thread safety calls to this method must be synchronized. /// Note: This method is being called by dynamically generated code. Be careful when changing its signature. /// </summary> internal static void LoadTargetFunction(NativeFunction nativeFunction, bool ignoreLoadError) { var dll = nativeFunction.containingDll; if (dll.handle == IntPtr.Zero) { dll.handle = SysLoadDll(dll.path); if (dll.handle == IntPtr.Zero) { if (!ignoreLoadError) { dll.loadingError = true; Prop_EditorApplication_isPaused.Value?.SetValue(null, true); throw new NativeDllException($"Could not load DLL \"{dll.name}\" at path \"{dll.path}\"."); } return; } else { dll.loadingError = false; InvokeCustomTriggers(_customLoadedTriggers, dll); LowLevelPluginManager.OnDllLoaded(dll); } } if (nativeFunction.@delegate == null) { IntPtr funcPtr = SysGetDllProcAddress(dll.handle, nativeFunction.identity.symbol); if (funcPtr == IntPtr.Zero) { if (!ignoreLoadError) { dll.symbolError = true; Prop_EditorApplication_isPaused.Value?.SetValue(null, true); throw new NativeDllException($"Could not get address of symbol \"{nativeFunction.identity.symbol}\" in DLL \"{dll.name}\" at path \"{dll.path}\"."); } return; } else { dll.symbolError = false; } nativeFunction.@delegate = Marshal.GetDelegateForFunctionPointer(funcPtr, nativeFunction.delegateType); } }