예제 #1
0
파일: CSPlugin.cs 프로젝트: Notulp/Pluton
        public override void Load(string code = "")
        {
            try {
                byte[] bin = File.ReadAllBytes(code);
                if (CoreConfig.GetInstance().GetBoolValue("csharp", "checkHash") && !bin.VerifyMD5Hash()) {
                    Logger.LogDebug(String.Format("[Plugin] MD5Hash not found for: {0} [{1}]!", Name, Type));
                    State = PluginState.HashNotFound;
                    return;
                }

                LoadReferences();

                Assembly assembly = Assembly.Load(bin);
                Type classType = assembly.GetType(Name + "." + Name);
                if (classType == null || !classType.IsSubclassOf(typeof(CSharpPlugin)) || !classType.IsPublic || classType.IsAbstract)
                    throw new TypeLoadException("Main module class not found:" + Name);

                Engine = (CSharpPlugin)Activator.CreateInstance(classType);

                Engine.Plugin = this;
                Engine.Commands = chatCommands;
                Engine.ServerConsoleCommands = consoleCommands;

                Globals = (from method in classType.GetMethods()
                                       select method.Name).ToList<string>();

                State = PluginState.Loaded;
            } catch (Exception ex) {
                Logger.LogException(ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
예제 #2
0
        public override void Load(string code = "")
        {
            try {
                LoadReferences();

                Assembly plugin = Compile();

                /*//For C# plugins code is the dll path
                 * byte[] bin = File.ReadAllBytes(code);
                 * if (CoreConfig.GetInstance().GetBoolValue("csharp", "checkHash") && !bin.VerifyMD5Hash()) {
                 *  Logger.LogDebug(String.Format("[Plugin] MD5Hash not found for: {0} [{1}]!", name, Type));
                 *  State = PluginState.HashNotFound;
                 *  return;
                 * }*/
                if (plugin == null)
                {
                    State = PluginState.FailedToLoad;
                    return;
                }

                Type classType = plugin.GetType(Name + "." + Name);

                if (classType == null || !classType.IsSubclassOf(typeof(CSharpPlugin)) || !classType.IsPublic || classType.IsAbstract)
                {
                    throw new TypeLoadException("Main module class not found: " + Name);
                }

                Engine = (CSharpPlugin)Activator.CreateInstance(classType);

                Engine.Plugin   = this;
                Engine.Commands = chatCommands;
                Engine.ServerConsoleCommands = consoleCommands;

                Globals = (from method in classType.GetMethods()
                           select method.Name).ToList <string>();

                State = PluginState.Loaded;
            } catch (Exception ex) {
                Logger.LogException(ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }