public override void Load(string nothing) { 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; } else { Type classType = plugin.GetType($"{Name}.{Name}"); if (classType == null || !classType.IsSubclassOf(typeof(CSharpPlugin)) || !classType.IsPublic || classType.IsAbstract) { Console.WriteLine("Main module class not found: " + Name); State = PluginState.FailedToLoad; } else { Engine = (CSharpPlugin)Activator.CreateInstance(classType); Engine.Plugin = this; Globals = (from method in classType.GetMethods() select method.Name).ToList(); State = PluginState.Loaded; } } } catch (Exception ex) { Logger.LogException(ex); State = PluginState.FailedToLoad; } PluginLoader.GetInstance().OnPluginLoaded(this); }
public override void Load(string code) { try { byte[] bin = File.ReadAllBytes(code); if (CoreConfig.GetInstance().GetBoolValue("csharp", "checkHash") && !bin.VerifyMD5Hash()) { Logger.LogDebug($"[{GetType().Name}] MD5Hash not found for: {Name}"); State = PluginState.HashNotFound; } else { LoadReferences(); Assembly assembly = Assembly.Load(bin); Type classType = assembly.GetType($"{Name}.{Name}"); if (classType == null || !classType.IsSubclassOf(typeof(CSharpPlugin)) || !classType.IsPublic || classType.IsAbstract) { Console.WriteLine("Main module class not found:" + Name); State = PluginState.FailedToLoad; } else { Engine = (CSharpPlugin)Activator.CreateInstance(classType); Engine.Plugin = this; Globals = (from method in classType.GetMethods() select method.Name).ToList(); State = PluginState.Loaded; } } } catch (Exception ex) { Logger.LogException(ex); State = PluginState.FailedToLoad; } PluginLoader.GetInstance().OnPluginLoaded(this); }