private void _enablePlugins() { foreach (var entry in _plugins) { Longship.Log($"Enabling plugin {entry.Value.Name}..."); try { entry.Value.Plugin.OnEnable(); } catch (Exception e) { Debug.LogError($"Can't enable plugin {entry.Value.Name}."); Debug.LogException(e); } } }
private void _loadPlugins() { var pluginsDirectory = new DirectoryInfo(_pluginsPath); if (!pluginsDirectory.Exists) { pluginsDirectory.Create(); } foreach (var file in pluginsDirectory.GetFiles("*.dll")) { var assembly = Assembly.LoadFrom(file.FullName); foreach (var type in assembly.GetTypes()) { if (!type.IsSubclassOf(typeof(IPlugin)) || type.IsAbstract) { continue; } Longship.Log($"Loading plugin {file.Name}..."); try { _plugins[type] = new LoadedPlugin() { Plugin = type.InvokeMember( null, BindingFlags.CreateInstance, null, null, null) as IPlugin, Name = file.Name }; } catch (Exception e) { Longship.LogError($"Can't load plugin {file.Name}."); Longship.LogException(e); } } } }
public bool DisablePlugin <T>() where T : IPlugin { if (!_plugins.TryGetValue(typeof(T), out var value)) { return(false); } Longship.Log($"Disabling {value.Name}..."); try { Longship.Instance.EventManager.ClearListeners(value.Plugin); Longship.Instance.CommandsManager.ClearListeners(value.Plugin); value.Plugin.OnDisable(); } catch (Exception e) { Longship.LogError($"Error while disabling plugin {value.Name}"); Longship.LogException(e); } Longship.Log($"{value.Name} disabled."); return(false); }
static void PatchZDOManConstructor(ref int ___m_dataPerSec) { ___m_dataPerSec = (int)Longship.Instance.ConfigurationManager.Configuration.Network.DataPerSeconds; Longship.Log($"ZDOMan m_dataPerSec patched to value {___m_dataPerSec}"); }