diff --git a/scripts/Attributes.cs b/scripts/Attributes.cs index c4a18e4..14eef45 100644 --- a/scripts/Attributes.cs +++ b/scripts/Attributes.cs @@ -49,9 +49,11 @@ public class TriggerAttribute : 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)] diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 84f143f..147d474 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -148,6 +148,11 @@ 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); } } } @@ -497,8 +502,12 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno else { dll.loadingError = false; - InvokeCustomTriggers(_customLoadedTriggers, dll); 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); } }