zoukankan      html  css  js  c++  java
  • HearthBuddy的plugin加载

    // Hearthbuddy.Windows.MainWindow
    // Token: 0x060001FF RID: 511 RVA: 0x0008951C File Offset: 0x0008771C
    private void method_1(object sender, RoutedEventArgs e)
    {
        try
        {
            base.Title = "Hearthbuddy";
            base.SetBinding(Window.LeftProperty, new Binding("WindowX")
            {
                Source = MainSettings.Instance,
                Mode = BindingMode.TwoWay
            });
            base.SetBinding(Window.TopProperty, new Binding("WindowY")
            {
                Source = MainSettings.Instance,
                Mode = BindingMode.TwoWay
            });
            base.SetBinding(FrameworkElement.WidthProperty, new Binding("WindowWidth")
            {
                Source = MainSettings.Instance,
                Mode = BindingMode.TwoWay
            });
            base.SetBinding(FrameworkElement.HeightProperty, new Binding("WindowHeight")
            {
                Source = MainSettings.Instance,
                Mode = BindingMode.TwoWay
            });
            MainSettings.Instance.LoadRowDefinitions(this.rowDefinition_0, this.rowDefinition_1, this.rowDefinition_2);
            this.method_3();
            this.textBox_0.Text = Logger.FileName;
            this.method_17();
            this.method_18();
            this.method_19();
            this.method_20();
        }
        catch (Exception exception)
        {
            MainWindow.ilog_0.Error("[Ui] An exception occurred.", exception);
        }
    }
    // Hearthbuddy.Windows.MainWindow
    // Token: 0x06000201 RID: 513 RVA: 0x00003C51 File Offset: 0x00001E51
    private void method_3()
    {
        ThreadPool.QueueUserWorkItem(new WaitCallback(this.method_21));
    }
    // Hearthbuddy.Windows.MainWindow
    // Token: 0x06000231 RID: 561 RVA: 0x0008AC20 File Offset: 0x00088E20
    [CompilerGenerated]
    private void method_21(object object_0)
    {
        try
        {
            base.Dispatcher.Invoke(new Action(this.method_22));
            string text;
            if (this.process_0 == null)
            {
                base.Dispatcher.BeginInvoke(new Action(base.Close), Array.Empty<object>());
            }
            else if (!TritonHs.smethod_0(this.process_0, new TritonHs.Delegate6(Class12.smethod_4), out text))
            {
                MainWindow.ilog_0.Error(text);
                System.Windows.MessageBox.Show(text, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                base.Dispatcher.BeginInvoke(new Action(base.Close), Array.Empty<object>());
            }
            else
            {
                TritonHs.Memory.ProcessExited += MainWindow.Class25.ChuckInstance9.method_1;
                TritonHs.Memory.Executor.FrameDropWaitTime = 15000u;
                TritonHs.Memory.Executor.ExecuteWaitTime = 15000;
                TritonHs.Memory.DisableCache();
                TritonHs.Memory.ClearCache();
                int version;
                int clientChangelist;
                using (TritonHs.AcquireFrame())
                {
                    version = Triton.Game.Mapping.Version.version;
                    clientChangelist = Triton.Game.Mapping.Version.clientChangelist;
                }
                if ((long)version != (long)((ulong)Class247.UInt32_1) && (long)clientChangelist != (long)((ulong)Class247.UInt32_2))
                {
                    MainWindow.ilog_0.InfoFormat("Hearthstone client version ({0}, {1})", version, clientChangelist);
                    new Coroutine(new Func<Task>(MainWindow.Class25.ChuckInstance9.method_2));
                    Configuration.Instance.AddSettings(MainSettings.Instance);
                    Configuration.Instance.AddSettings(DevSettings.Instance);
                    Configuration.Instance.SaveAll();
                    base.Dispatcher.Invoke(new Action(this.method_23));
                    BotManager.PreStart += this.method_11;
                    BotManager.PostStop += this.method_10;
                    BotManager.Load();
                    base.Dispatcher.Invoke(new Action(this.method_24));
                    this.comboBox_0.Dispatcher.BeginInvoke(new Action(this.method_25), Array.Empty<object>());
                    BotManager.OnBotChanged += this.method_6;
                    RoutineManager.Load();
                    base.Dispatcher.Invoke(new Action(this.method_26));
                    this.comboBox_1.Dispatcher.BeginInvoke(new Action(this.method_27), Array.Empty<object>());
                    RoutineManager.OnRoutineChanged += this.method_7;
                    PluginManager.Load();
                    foreach (IPlugin plugin in PluginManager.Plugins)
                    {
                        if (MainSettings.Instance.EnabledPlugins.Contains(plugin.Name))
                        {
                            using (TritonHs.AcquireFrame())
                            {
                                PluginManager.Enable(plugin);
                            }
                            Thread.Sleep(20);
                        }
                        else
                        {
                            using (TritonHs.AcquireFrame())
                            {
                                PluginManager.Disable(plugin);
                            }
                            Thread.Sleep(20);
                        }
                    }
                    this.listBox_0.Dispatcher.Invoke<IEnumerable>(new Func<IEnumerable>(this.method_28), DispatcherPriority.Normal);
                    base.Dispatcher.Invoke(new Action(this.method_29));
                    PluginManager.PluginEnabled += this.method_5;
                    PluginManager.PluginDisabled += this.method_4;
                    MainWindow.ilog_0.InfoFormat("{0}Please read the following guide before using this program:{0}https://www.thebuddyforum.com/hearthbuddy-forum/210230-hearthbuddy-bm-release-thread.html", Environment.NewLine);
                    base.Dispatcher.Invoke(new Action(this.method_30));
                    base.Dispatcher.Invoke(new Action(this.method_31));
                    this.stopwatch_0.Restart();
                    RoutineManager.OnRoutineChanged += this.method_7;
                    BotManager.OnBotChanged += this.method_6;
                    TritonHs.IsBotFullyLoaded = true;
                    Hotkeys.Register("BotManager.StartStop", Keys.S, ModifierKeys.Alt | ModifierKeys.Shift, new Action<Hotkey>(MainWindow.Class25.ChuckInstance9.method_3));
                    if (CommandLine.Arguments.Exists("autostart"))
                    {
                        BotManager.Start();
                    }
                }
                else
                {
                    text = string.Format("This client version ({0}, {1}) is unsupported. Hearthbuddy currently supports client version ({2}, {3}). Please check the forums for more information: https://www.thebuddyforum.com/hearthbuddy-forum/", new object[]
                    {
                        version,
                        clientChangelist,
                        Class247.UInt32_1,
                        Class247.UInt32_2
                    });
                    MainWindow.ilog_0.ErrorFormat(text, Array.Empty<object>());
                    System.Windows.MessageBox.Show(text, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
                    base.Dispatcher.BeginInvoke(new Action(base.Close), Array.Empty<object>());
                }
            }
        }
        catch (Exception exception)
        {
            MainWindow.ilog_0.Error("[OnStartup] A top-level exception has been caught.", exception);
        }
    }

    namespace Triton.Bot

    public static class PluginManager

    通过load函数进行加载,而且加载的是固定路径,扫描Plugins文件夹

    public static bool Load()
    {
        try
        {
            string pluginsPath = PluginManager.PluginsPath;
            if (BotManager.IsRunning)
            {
                throw new InvalidOperationException("Cannot Load plugins while the bot is running.");
            }
            if (PluginManager.Plugins != null)
            {
                PluginManager.ilog_0.ErrorFormat("[Load] This function can only be called once.", Array.Empty<object>());
                return false;
            }
            if (!Directory.Exists(pluginsPath))
            {
                Directory.CreateDirectory(pluginsPath);
            }
            AssemblyLoader<IPlugin> assemblyLoader = new AssemblyLoader<IPlugin>(pluginsPath, false);
            PluginManager.Plugins = new List<IPlugin>();
            foreach (IPlugin plugin in assemblyLoader.Instances.AsReadOnly())
            {
                try
                {
                    Utility.smethod_0(plugin);
                    plugin.Initialize();
                    PluginManager.Plugins.Add(plugin);
                }
                catch (Exception exception)
                {
                    PluginManager.ilog_0.Debug("[Load] Exception thrown when initializing " + plugin.Name + ". Plugin will not be loaded.", exception);
                    Utility.smethod_1(plugin);
                    plugin.Deinitialize();
                }
            }
            return true;
        }
        catch (Exception arg)
        {
            PluginManager.ilog_0.ErrorFormat("[Load] An exception occurred: {0}.", arg);
        }
        return false;
    }
    public static string PluginsPath
            {
                get
                {
                    return Path.Combine(PluginManager.String_0, "Plugins");
                }
            }
    private static string String_0
            {
                get
                {
                    return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                }
            }

    使用AssemblyLoader加载插件,只扫描.cs文件

    this.fileSystemWatcher_0.Filter = "*.cs";
    public AssemblyLoader(string directory, bool detectFileChanges)
            {
                this.Instances = new List<T>();
                this.string_0 = directory;
                this.bool_0 = detectFileChanges;
                if (this.bool_0)
                {
                    this.fileSystemWatcher_0.Path = directory;
                    this.fileSystemWatcher_0.Filter = "*.cs";
                    this.fileSystemWatcher_0.IncludeSubdirectories = true;
                    this.fileSystemWatcher_0.EnableRaisingEvents = true;
                    this.fileSystemWatcher_0.Changed += this.method_0;
                    this.fileSystemWatcher_0.Created += this.method_1;
                    this.fileSystemWatcher_0.Deleted += this.method_2;
                }
                this.Reload("Initializing");
            }
    public void Reload(string reason)
            {
                this.ilog_0.Debug(string.Format("Reloading AssemblyLoader<{0}> - {1}", typeof(T), reason));
                this.Instances = new List<T>();
                if (!Directory.Exists(this.string_0))
                {
                    this.ilog_0.Error(string.Format("Could not Reload assemblies because the path "{0}" does not exist.", this.string_0));
                    return;
                }
                foreach (string path in Directory.GetDirectories(this.string_0))
                {
                    try
                    {
                        CodeCompiler codeCompiler = new CodeCompiler(path);
                        CompilerResults compilerResults = codeCompiler.Compile();
                        if (compilerResults != null)
                        {
                            if (compilerResults.Errors.HasErrors)
                            {
                                foreach (object obj in compilerResults.Errors)
                                {
                                    this.ilog_0.Error("Compiler Error: " + obj.ToString());
                                }
                            }
                            else
                            {
                                this.Instances.AddRange(new TypeLoader<T>(codeCompiler.CompiledAssembly, null));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex is ReflectionTypeLoadException)
                        {
                            foreach (Exception exception in (ex as ReflectionTypeLoadException).LoaderExceptions)
                            {
                                this.ilog_0.Error("[Reload] An exception occurred.", exception);
                            }
                        }
                        else
                        {
                            this.ilog_0.Error("[Reload] An exception occurred.", ex);
                        }
                    }
                }
                using (List<T>.Enumerator enumerator2 = new TypeLoader<T>(null, null).GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        AssemblyLoader<T>.Class229 @class = new AssemblyLoader<T>.Class229();
                        @class.gparam_0 = enumerator2.Current;
                        if (!this.Instances.Any(new Func<T, bool>(@class.method_0)))
                        {
                            this.Instances.Add(@class.gparam_0);
                        }
                    }
                }
                if (this.eventHandler_0 != null)
                {
                    this.eventHandler_0(this, null);
                }
            }
  • 相关阅读:
    SAP 标准成本滚算小记
    记一次SAP新业务开发项目
    让人头疼的关键用户
    SAP GUI个性化设置
    惊心动魄的SAP S4客户额度调整运动
    最新.net和Java调用SAP RFC中间件下载
    那些年我遇到的ERP顾问
    【SAP业务模式】之STO(二):系统配置
    SAP S4系统创建Customer和Vendor的BAPI
    【SAP S/4 1511之变】:主数据之变
  • 原文地址:https://www.cnblogs.com/chucklu/p/11197685.html
Copyright © 2011-2022 走看看