Skip to content

Commit 8b32f63

Browse files
authored
Merge pull request #475 from js6pak/chainloader-events
Add chainloader events
2 parents 78b5b58 + 0d2cbe6 commit 8b32f63

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

BepInEx.Core/Bootstrap/BaseChainloader.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ protected static bool PluginTargetsWrongBepin(PluginInfo pluginInfo)
125125
/// Contains information about what certain plugins were not loaded.
126126
/// </summary>
127127
public List<string> DependencyErrors { get; } = new();
128+
129+
/// <summary>
130+
/// Occurs after a plugin is loaded.
131+
/// </summary>
132+
public event Action<PluginInfo> PluginLoaded;
133+
134+
/// <summary>
135+
/// Occurs after all plugins are loaded.
136+
/// </summary>
137+
public event Action Finished;
128138

129139
public virtual void Initialize(string gameExePath = null)
130140
{
@@ -305,6 +315,7 @@ public virtual void Execute()
305315
var plugins = DiscoverPlugins();
306316
Logger.Log(LogLevel.Info, $"{plugins.Count} plugin{(plugins.Count == 1 ? "" : "s")} to load");
307317
LoadPlugins(plugins);
318+
Finished?.Invoke();
308319
}
309320
catch (Exception ex)
310321
{
@@ -400,7 +411,7 @@ static bool IsHardDependency(BepInDependency dep) =>
400411
plugin.Instance = LoadPlugin(plugin, ass);
401412
loadedPlugins.Add(plugin);
402413

403-
//_plugins.Add((TPlugin)plugin.Instance);
414+
PluginLoaded?.Invoke(plugin);
404415
}
405416
catch (Exception ex)
406417
{

Runtimes/Unity/BepInEx.Unity.IL2CPP/IL2CPPChainloader.cs

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public class IL2CPPChainloader : BaseChainloader<BasePlugin>
4848
/// <param name="t">Type of the component to add</param>
4949
public static Il2CppObjectBase AddUnityComponent(Type t) => Il2CppUtils.AddComponent(t);
5050

51+
/// <summary>
52+
/// Occurs after a plugin is instantiated and just before <see cref="BasePlugin.Load"/> is called.
53+
/// </summary>
54+
public event Action<PluginInfo, Assembly, BasePlugin> PluginLoad;
55+
5156
public override void Initialize(string gameExePath = null)
5257
{
5358
base.Initialize(gameExePath);
@@ -125,6 +130,7 @@ public override BasePlugin LoadPlugin(PluginInfo pluginInfo, Assembly pluginAsse
125130

126131
var pluginInstance = (BasePlugin) Activator.CreateInstance(type);
127132

133+
PluginLoad?.Invoke(pluginInfo, pluginAssembly, pluginInstance);
128134
pluginInstance.Load();
129135

130136
return pluginInstance;

0 commit comments

Comments
 (0)