private static void SetCallMethodMethods(IntPtr assemblyHandle) { _setManagedCallMethod = NativeAssembly.GetMethod <SetManagedCallMethodDelegate>(assemblyHandle, "SetManagedCallMethodMethod"); _setManagedCallMethod.Invoke(CallMethod); _setManagedCallMethodOut = NativeAssembly.GetMethod <SetManagedCallMethodOutDelegate>(assemblyHandle, "SetManagedCallMethodOutMethod"); _setManagedCallMethodOut.Invoke(CallMethodOut); }
public static void Initialize(IntPtr assemblyHandle) { SetEssentialsMethods(assemblyHandle); SetTypeMethods(assemblyHandle); SetGetSetMethods(assemblyHandle); SetCallMethodMethods(assemblyHandle); _initializeNative = NativeAssembly.GetMethod <NativeVoidMethod>(assemblyHandle, "InitializeNative"); _initializeNative.Invoke(); }
private static void SetTypeMethods(IntPtr assemblyHandle) { _setManagedGetTypePtr = NativeAssembly.GetMethod <SetManagedGetTypePtrDelegate>(assemblyHandle, "SetManagedGetTypePtrMethod"); _setManagedGetTypePtr.Invoke(GetTypePtr); _setManagedGetConstructorPtr = NativeAssembly.GetMethod <SetManagedGetTypeConstructorPtrDelegate>(assemblyHandle, "SetManagedGetConstructorPtrMethod"); _setManagedGetConstructorPtr.Invoke(GetTypeConstructorPtr); _setManagedGetMemberPtr = NativeAssembly.GetMethod <SetManagedGetTypeMemberPtrDelegate>(assemblyHandle, "SetManagedGetMemberPtrMethod"); _setManagedGetMemberPtr.Invoke(GetTypeMemberPtr); _setManagedConstructor = NativeAssembly.GetMethod <SetManagedConstructorDelegate>(assemblyHandle, "SetManagedConstructorMethod"); _setManagedConstructor.Invoke(Constructor); }
private void OnDestroy() { _nativeEndCountdown -= 1; if (_nativeEndCountdown > 0) { return; } NativeMethods.DeInitialize(_nativeAssemblyHandle); if (!NativeAssembly.Unload(_nativeAssemblyHandle)) { Debug.Log("Something went wrong unloading native code handle."); } }
private void Awake() { string assemblyPath = NativeConstants.GetAssemblyPath(); Debug.Log($"Searching for native library in {assemblyPath}"); IntPtr nativeAssemblyHandle = NativeAssembly.Load(assemblyPath); if (nativeAssemblyHandle == IntPtr.Zero) { Debug.Log($"Failed to load native assembly {assemblyPath}"); return; } NativeMethods.Initialize(nativeAssemblyHandle); NativeEnd.SetNativeHandle(nativeAssemblyHandle); Destroy(gameObject); }
private static void SetEssentialsMethods(IntPtr assemblyHandle) { _setDebugLog = NativeAssembly.GetMethod <SetUnityDebugLogDelegate>(assemblyHandle, "SetUnityDebugLogMethod"); _setDebugLog.Invoke(DebugLog); _setUnitySendMessage = NativeAssembly.GetMethod <SetSendMessageDelegate>(assemblyHandle, "SetUnitySendMessageMethod"); _setUnitySendMessage.Invoke(UnitySendMessageMethod); createNativeMonoBehaviour = NativeAssembly.GetMethod <CreateNativeMonoBehaviourInstance>(assemblyHandle, "CreateNativeMonoBehaviourInstance"); destroyNativeMonoBehaviour = NativeAssembly.GetMethod <DestroyNativeMonoBehaviourInstance>(assemblyHandle, "DestroyNativeMonoBehaviourInstance"); monoBehaviourAwake = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourAwake"); monoBehaviourOnDestroy = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourOnDestroy"); monoBehaviourStart = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourStart"); monoBehaviourStop = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourStop"); monoBehaviourOnEnable = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourOnEnable"); monoBehaviourOnDisable = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourOnDisable"); monoBehaviourFixedUpdate = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourFixedUpdate"); monoBehaviourUpdate = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourUpdate"); monoBehaviourLateUpdate = NativeAssembly.GetMethod <MonoBehaviourMethod>(assemblyHandle, "CallMonoBehaviourLateUpdate"); }
public static void DeInitialize(IntPtr assemblyHandle) { _deInitializeNative = NativeAssembly.GetMethod <NativeVoidMethod>(assemblyHandle, "DeInitializeNative"); _deInitializeNative.Invoke(); }
private static void SetGetSetMethods(IntPtr assemblyHandle) { _setManagedGetSetValue = NativeAssembly.GetMethod <SetManagedGetSetValueDelegate>(assemblyHandle, "SetManagedGetSetValueMethod"); _setManagedGetSetValue.Invoke(GetMemberValue, SetMemberValue); }
public async Task LoadUnmanagedDll_Works() { var testContext = await SetupLoadedPluginTextContext(); var loadContext = testContext.Sut(); var initialPluginLoadDirectory = testContext.InitialPluginLoadDirectory; var assemblyLoadStrategy = testContext.GetMock <IAssemblyLoadStrategy>(); var pluginDependencyContext = testContext.GetMock <IPluginDependencyContext>(); var nativeDependency = "Nativelib.dll"; var nativePtr = new IntPtr(1024 * 10000); assemblyLoadStrategy.Setup(a => a.LoadUnmanagedDll(initialPluginLoadDirectory, nativeDependency, pluginDependencyContext.Object, It.IsAny <Func <string, string, ValueOrProceed <string> > >(), It.IsAny <Func <string, string, ValueOrProceed <string> > >(), It.IsAny <Func <string, string, ValueOrProceed <IntPtr> > >())).Returns(NativeAssembly.Create(null, nativePtr)); var result = InvokeProtectedMethodOnLoadContextAndGetResult <IntPtr>( loadContext, "LoadUnmanagedDll", new object[] { nativeDependency }); Assert.IsNotNull(result); Assert.AreEqual(nativePtr, result); }