From 2003944b905571b784ae7a17cc703f5fe03af51c Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 24 Apr 2020 17:11:04 +0200 Subject: [PATCH 1/3] Bug fix, customLoadedTriggers with preloaded mode The loaded trigger is now called after all mocked methods have been loaded for preloaded mode. This allows using a native method inside the callback, such as a native initialize function. --- scripts/DllManipulator.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 8440a3f..bef842a 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -132,6 +132,9 @@ public static void LoadAll() { LoadTargetFunction(nativeFunction, false); } + + if(Options.loadingMode == DllLoadingMode.Preload) + InvokeCustomTriggers(_customLoadedTriggers, dll); } } } @@ -481,8 +484,9 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno else { dll.loadingError = false; - InvokeCustomTriggers(_customLoadedTriggers, dll); LowLevelPluginManager.OnDllLoaded(dll); + if(Options.loadingMode == DllLoadingMode.Lazy) + InvokeCustomTriggers(_customLoadedTriggers, dll); } } From c8410539e2e51df87b6bae6a192fb5085712191f Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Thu, 30 Apr 2020 15:03:29 +0200 Subject: [PATCH 2/3] Add comments --- scripts/Attributes.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/Attributes.cs b/scripts/Attributes.cs index bae18f9..43d9cdb 100644 --- a/scripts/Attributes.cs +++ b/scripts/Attributes.cs @@ -31,9 +31,11 @@ public class DisableMockingAttribute : Attribute } /// - /// Methods with this attribute are called directly after a native DLL has been loaded. + /// Methods with this attribute are called directly after a native DLL has been loaded. Native functions can be used within such a method. + /// This is called after UnityPluginLoad.
/// Such method must be and either have no parameters or one parameter of type - /// which indicates the state of the dll being loaded. Please treat this parameter as readonly. + /// which indicates the state of the dll being loaded. Please treat this parameter as readonly.
+ /// Preloaded: only called once all native methods have been loaded. ///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public class NativeDllLoadedTriggerAttribute : Attribute From c1aba9c03f962f8d57425052baf032056fffb701 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 1 May 2020 11:13:36 +0200 Subject: [PATCH 3/3] More comments --- scripts/DllManipulator.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index bef842a..5763c71 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -133,6 +133,8 @@ public static void LoadAll() LoadTargetFunction(nativeFunction, false); } + // Notify that the dll and its functions have been loaded in preload mode + // This here allows use of native functions in the triggers if(Options.loadingMode == DllLoadingMode.Preload) InvokeCustomTriggers(_customLoadedTriggers, dll); } @@ -485,6 +487,9 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno { 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); }