public bool Unload() { try { if (!Enabled) { return(true); } PointBlankLogging.Log("Stopping " + Name + "..."); SaveConfiguration(); // Save the configuration SaveTranslation(); // Save the translation PointBlankPluginEvents.RunPluginStop(PluginClass); // Run the stop event PluginClass.Unload(); // Run the unload function PointBlankPluginEvents.RunPluginUnloaded(PluginClass); // Run the unloaded event Enviroment.runtimeObjects["Plugins"].RemoveCodeObject(PluginClass.GetType().Name); // Remove the plugin from gameobject Enabled = false; // Set the enabled to false t.Abort(); // Abort the thread return(true); } catch (Exception ex) { PointBlankLogging.LogError("Error stopping plugin: " + Name, ex); return(false); } }
public override void Unload() { foreach (PluginWrapper wrapper in _plugins) { wrapper.Unload(); // Unload the wrapper } PointBlankPluginEvents.RunPluginsUnloaded(); SaveConfig(); }
public override void Load() { if (!Directory.Exists(PointBlankServer.LibrariesPath)) { Directory.CreateDirectory(PointBlankServer.LibrariesPath); // Create libraries directory } if (!Directory.Exists(PointBlankServer.PluginsPath)) { Directory.CreateDirectory(PointBlankServer.PluginsPath); // Create plugins directory } if (!Directory.Exists(ConfigurationPath)) { Directory.CreateDirectory(ConfigurationPath); // Create plugins directory } if (!Directory.Exists(TranslationPath)) { Directory.CreateDirectory(TranslationPath); // Create plugins directory } // Setup the config UniConfig = new UniversalData(SM.ConfigurationPath + "\\PluginManager"); JSONConfig = UniConfig.GetData(EDataType.JSON) as JsonData; LoadConfig(); foreach (string library in Directory.GetFiles(PointBlankServer.LibrariesPath, "*.dll")) // Get all the dll files in libraries directory { _libraries.Add(Assembly.Load(File.ReadAllBytes(library))); // Load and add the library } foreach (string plugin in Directory.GetFiles(PointBlankServer.PluginsPath, "*.dll")) // Get all the dll files in plugins directory { try { PluginWrapper wrapper = new PluginWrapper(plugin); // Create the plugin wrapper _plugins.Add(wrapper); // Add the wrapper if (!wrapper.Load() && !PluginConfiguration.ContinueOnError) { break; } } catch (Exception ex) { PointBlankLogging.LogError("Error initializing plugin!", ex); if (!PluginConfiguration.ContinueOnError) { break; } } } PointBlankPluginEvents.RunPluginsLoaded(); }
public bool Load() { try { if (Enabled) { return(true); } PointBlankLogging.Log("Starting " + Name + "..."); Type _class = PluginAssembly.GetTypes().First(a => a.IsClass && typeof(PointBlankPlugin).IsAssignableFrom(a)); // Get the first plugin class PluginClass = Enviroment.runtimeObjects["Plugins"].AddCodeObject(_class) as PointBlankPlugin; // Instentate the plugin class Name = PluginClass.GetType().Name; // Change the name Version = PluginClass.Version; if (CheckUpdates()) { if (PluginConfiguration.NotifyUpdates) { Notify(); } if (PluginConfiguration.AutoUpdate) { Update(); } } LoadConfiguration(); // Load the configuration LoadTranslation(); // Load the translation PointBlankPluginEvents.RunPluginStart(PluginClass); // Run the start event PluginClass.Load(); // Run the load function PointBlankPluginEvents.RunPluginLoaded(PluginClass); // Run the loaded event Enabled = true; // Set the enabled to true t.Start(); // Start the thread return(true); } catch (Exception ex) { PointBlankLogging.LogError("Error starting plugin: " + Name, ex); Unload(); return(false); } }