Skip to content

Commit

Permalink
Add chainloader events
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Aug 24, 2022
1 parent 78b5b58 commit 0d2cbe6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion BepInEx.Core/Bootstrap/BaseChainloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ protected static bool PluginTargetsWrongBepin(PluginInfo pluginInfo)
/// Contains information about what certain plugins were not loaded.
/// </summary>
public List<string> DependencyErrors { get; } = new();

/// <summary>
/// Occurs after a plugin is loaded.
/// </summary>
public event Action<PluginInfo> PluginLoaded;

/// <summary>
/// Occurs after all plugins are loaded.
/// </summary>
public event Action Finished;

public virtual void Initialize(string gameExePath = null)
{
Expand Down Expand Up @@ -305,6 +315,7 @@ public virtual void Execute()
var plugins = DiscoverPlugins();
Logger.Log(LogLevel.Info, $"{plugins.Count} plugin{(plugins.Count == 1 ? "" : "s")} to load");
LoadPlugins(plugins);
Finished?.Invoke();
}
catch (Exception ex)
{
Expand Down Expand Up @@ -400,7 +411,7 @@ static bool IsHardDependency(BepInDependency dep) =>
plugin.Instance = LoadPlugin(plugin, ass);
loadedPlugins.Add(plugin);

//_plugins.Add((TPlugin)plugin.Instance);
PluginLoaded?.Invoke(plugin);
}
catch (Exception ex)
{
Expand Down
6 changes: 6 additions & 0 deletions Runtimes/Unity/BepInEx.Unity.IL2CPP/IL2CPPChainloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public class IL2CPPChainloader : BaseChainloader<BasePlugin>
/// <param name="t">Type of the component to add</param>
public static Il2CppObjectBase AddUnityComponent(Type t) => Il2CppUtils.AddComponent(t);

/// <summary>
/// Occurs after a plugin is instantiated and just before <see cref="BasePlugin.Load"/> is called.
/// </summary>
public event Action<PluginInfo, Assembly, BasePlugin> PluginLoad;

public override void Initialize(string gameExePath = null)
{
base.Initialize(gameExePath);
Expand Down Expand Up @@ -125,6 +130,7 @@ public override BasePlugin LoadPlugin(PluginInfo pluginInfo, Assembly pluginAsse

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

PluginLoad?.Invoke(pluginInfo, pluginAssembly, pluginInstance);
pluginInstance.Load();

return pluginInstance;
Expand Down

0 comments on commit 0d2cbe6

Please sign in to comment.