Skip to content

Commit edc68d8

Browse files
authored
Bug fix, customLoadedTriggers with preloaded mode (#18)
* 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. * Add comments * More comments
1 parent 1f0e9bc commit edc68d8

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

scripts/Attributes.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ public class TriggerAttribute : Attribute
4949
}
5050

5151
/// <summary>
52-
/// Methods with this attribute are called directly after a native DLL has been loaded.
52+
/// Methods with this attribute are called directly after a native DLL has been loaded. Native functions can be used within such a method.
53+
/// This is called after <c>UnityPluginLoad</c>.<br/>
5354
/// Such method must be <see langword="static"/> and either have no parameters or one parameter of type <see cref="NativeDll"/>
54-
/// which indicates the state of the dll being loaded. Please treat this parameter as readonly.
55+
/// which indicates the state of the dll being loaded. Please treat this parameter as readonly.<br/>
56+
/// Preloaded: only called once all native methods have been loaded.
5557
/// <br/><inheritdoc cref="TriggerAttribute"/>
5658
/// </summary>
5759
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]

scripts/DllManipulator.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ public static void LoadAll()
148148
{
149149
LoadTargetFunction(nativeFunction, false);
150150
}
151+
152+
// Notify that the dll and its functions have been loaded in preload mode
153+
// This here allows use of native functions in the triggers
154+
if(Options.loadingMode == DllLoadingMode.Preload)
155+
InvokeCustomTriggers(_customLoadedTriggers, dll);
151156
}
152157
}
153158
}
@@ -497,8 +502,12 @@ internal static void LoadTargetFunction(NativeFunction nativeFunction, bool igno
497502
else
498503
{
499504
dll.loadingError = false;
500-
InvokeCustomTriggers(_customLoadedTriggers, dll);
501505
LowLevelPluginManager.OnDllLoaded(dll);
506+
507+
// Call the custom triggers once UnityPluginLoad has been called
508+
// For Lazy mode call the triggers immediately, preload waits until all functions are loaded (in LoadAll)
509+
if(Options.loadingMode == DllLoadingMode.Lazy)
510+
InvokeCustomTriggers(_customLoadedTriggers, dll);
502511
}
503512
}
504513

0 commit comments

Comments
 (0)