示例#1
0
 public Plugin(IChainChompCorruptor newInstance)
 {
     corruptor              = newInstance;
     settings.pluginName    = newInstance.Name;
     settings.pluginAuthor  = newInstance.Author;
     settings.pluginVersion = newInstance.Version;
 }
示例#2
0
 public Plugin(string path)
 {
     LoadSettings(path);
     corruptor = PluginManager.Current.CreateMatchingCorruptor(settings);
     if (settings != null)
     {
         settings.Restore(corruptor);
     }
     else
     {
         MessageBox.Show("Attempted to load a Corruptor that is not installed.", "Error", MessageBoxButtons.OK);
     }
 }
示例#3
0
        public void Restore(IChainChompCorruptor corruptor)
        {
            Type t = corruptor.GetType();

            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (Attribute.IsDefined(prop, typeof(SaveableSetting)))
                {
                    object value = data[prop.Name];

                    prop.SetValue(corruptor, Convert.ChangeType(value, prop.PropertyType));
                }
            }
        }
示例#4
0
        public void Store(IChainChompCorruptor corruptor)
        {
            Type t = corruptor.GetType();

            data = new Dictionary <string, dynamic>();

            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (Attribute.IsDefined(prop, typeof(SaveableSetting)))
                {
                    dynamic value = prop.GetValue(corruptor);
                    string  name  = prop.Name;

                    data.Add(name, value);
                }
            }
        }
示例#5
0
        //plugin loader
        private ICollection <IChainChompCorruptor> LoadPlugins(string path)
        {
            //aggregate files
            string[] dllFileNames = new string[0];
            if (Directory.Exists(path))
            {
                dllFileNames = Directory.GetFiles(path, "*.dll");
            }

            //load assemblies
            ICollection <Assembly> assemblies = new List <Assembly>(dllFileNames.Length);

            foreach (string dll in dllFileNames)
            {
                AssemblyName assN;
                try
                {
                    assN = AssemblyName.GetAssemblyName(dll);
                }
                catch (FileLoadException e)
                {
                    MessageBox.Show(e.Message);
                    continue;
                }

                Console.WriteLine(assN.FullName);
                Assembly ass;
                try
                {
                    ass = Assembly.Load(assN);
                }
                catch (FileLoadException e)
                {
                    MessageBox.Show(e.Message);
                    continue;
                }
                assemblies.Add(ass);
            }

            //search assemblies for corruptors
            Type corruptorType             = typeof(IChainChompCorruptor);
            ICollection <Type> pluginTypes = new List <Type>();

            foreach (Assembly assembly in assemblies)
            {
                if (assembly != null)
                {
                    Type[] types = assembly.GetTypes();
                    foreach (Type type in types)
                    {
                        if (type.IsInterface || type.IsAbstract)
                        {
                            continue;
                        }
                        else
                        {
                            if (type.GetInterface(corruptorType.FullName) != null)
                            {
                                pluginTypes.Add(type);
                            }
                        }
                    }
                }
            }

            //create instances
            ICollection <IChainChompCorruptor> plugins = new List <IChainChompCorruptor>(pluginTypes.Count);

            foreach (Type type in pluginTypes)
            {
                IChainChompCorruptor corruptor = (IChainChompCorruptor)Activator.CreateInstance(type);
                plugins.Add(corruptor);
            }

            return(plugins);
        }
示例#6
0
        public IChainChompCorruptor CreateMatchingCorruptor(PluginSettings settings)
        {
            IChainChompCorruptor x = FindMatchingPlugin(settings);

            return(x != null?CreateCorruptor(_plugins.IndexOf(x)) : null);
        }
示例#7
0
        // Chain Expansion
        private void pluginDropDown_SelectedIndexChanged(object sender, EventArgs e)
        {
            IChainChompCorruptor c = PluginManager.Current.GetCorruptor((ComboBoxItem)pluginDropDown.SelectedItem);

            editorToolTip.SetToolTip(pluginDropDown, string.Format("{0} (Version {1} by {2})", c.Name, c.Version, c.Author));
        }
示例#8
0
 public Plugin(IChainChompCorruptor newInstance, string path) : this(newInstance)
 {
     LoadSettings(path, true);
 }