Example #1
0
 /// <summary>
 /// Called by engine every server frame
 /// </summary>
 private void OnFrame(float delta)
 {
     object[] args = new object[] { delta };
     foreach (System.Collections.Generic.KeyValuePair <string, Core.Plugins.Plugin> kv in loader.LoadedPlugins)
     {
         CSharpPlugin plugin = kv.Value as CSharpPlugin;
         if (plugin != null && plugin.HookedOnFrame)
         {
             plugin.CallHook("OnFrame", args);
         }
     }
 }
 private void OnFrame(float delta)
 {
     object[] objArray = new object[] { delta };
     foreach (KeyValuePair <string, Plugin> loadedPlugin in this.loader.LoadedPlugins)
     {
         CSharpPlugin value = loadedPlugin.Value as CSharpPlugin;
         if (value == null || !value.HookedOnFrame)
         {
             continue;
         }
         value.CallHook("OnFrame", objArray);
     }
 }
Example #3
0
        public override void Unloading(Plugin pluginBase)
        {
            CSharpPlugin cSharpPlugin = pluginBase as CSharpPlugin;

            if (cSharpPlugin == null)
            {
                return;
            }
            this.LoadedPlugins.Remove(cSharpPlugin.Name);
            foreach (CompilablePlugin value in CSharpPluginLoader.plugins.Values)
            {
                if (!value.Requires.Contains(cSharpPlugin.Name))
                {
                    continue;
                }
                Interface.Oxide.UnloadPlugin(value.Name);
            }
        }
Example #4
0
        /// <summary>
        /// Called when the plugin manager is unloading a plugin that was loaded by this plugin loader
        /// </summary>
        /// <param name="pluginBase"></param>
        public override void Unloading(Plugin pluginBase)
        {
            CSharpPlugin plugin = pluginBase as CSharpPlugin;

            if (plugin == null)
            {
                return;
            }

            LoadedPlugins.Remove(plugin.Name);

            // Unload plugins which require this plugin first
            foreach (CompilablePlugin compilablePlugin in plugins.Values)
            {
                if (compilablePlugin.Requires.Contains(plugin.Name))
                {
                    Interface.Oxide.UnloadPlugin(compilablePlugin.Name);
                }
            }
        }
Example #5
0
        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);
                }
            });
        }