internal void LoadPlugin(Action <CSharpPlugin> callback = null) { if (CompiledAssembly == null) { Interface.Oxide.LogError("Load called before a compiled assembly exists: " + Name); RemoteLogger.Error("Load called before a compiled assembly exists: " + Name); return; } loadCallback = callback; CompiledAssembly.LoadAssembly(loaded => { if (!loaded) { if (callback != null) { callback(null); } return; } if (CompilerErrors != null) { InitFailed("Unable to load " + ScriptName + ". " + CompilerErrors); return; } var type = CompiledAssembly.LoadedAssembly.GetType("Oxide.Plugins." + Name); if (type == null) { InitFailed("Unable to find main plugin class: " + Name); return; } CSharpPlugin plugin = null; try { plugin = Activator.CreateInstance(type) as CSharpPlugin; } catch (MissingMethodException) { InitFailed("Main plugin class should not have a constructor defined: " + Name); return; } catch (TargetInvocationException invocation_exception) { var ex = invocation_exception.InnerException; InitFailed("Unable to load " + ScriptName + ". " + ex.ToString()); return; } catch (Exception ex) { InitFailed("Unable to load " + ScriptName + ". " + ex.ToString()); return; } if (plugin == null) { RemoteLogger.Error("Plugin assembly failed to load: " + ScriptName); InitFailed("Plugin assembly failed to load: " + ScriptName); return; } plugin.SetPluginInfo(ScriptName, ScriptPath); plugin.Watcher = Extension.Watcher; plugin.Loader = Loader; if (!Interface.Oxide.PluginLoaded(plugin)) { InitFailed(); return; } if (!CompiledAssembly.IsBatch) { LastGoodAssembly = CompiledAssembly; } if (callback != null) { callback(plugin); } }); }