Exemple #1
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage    = pluginScreenSpace;
                this.label      = pluginStatusText;
                this.label.Text = "Init Phase 1: Infrastructure";

#if DEBUG
                _logger.Log(LogLevel.Warning, "##################################");
                _logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                _logger.Log(LogLevel.Warning, "##################################");
#endif

                _logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                // ** Init phase 1
                // Only init stuff here that works without the FFXIV plugin or addons (event sources, overlays).
                // Everything else should be initialized in the second phase.
                // 1.a Stuff without state
                FFXIVExportVariables.Init();

                // 1.b Stuff with state
                _container.Register(new NativeMethods(_container));
                _container.Register(new EventDispatcher(_container));
                _container.Register(new Registry(_container));
                _container.Register(new KeyboardHook(_container));

                this.label.Text = "Init Phase 1: Config";
                if (!LoadConfig())
                {
                    _logger.Log(LogLevel.Error, "Failed to load the plugin config. Please report this error on the GitHub repo or on the ACT Discord.");
                    _logger.Log(LogLevel.Error, "");
                    _logger.Log(LogLevel.Error, "  ACT Discord: https://discord.gg/ahFKcmx");
                    _logger.Log(LogLevel.Error, "  GitHub repo: https://github.com/ngld/OverlayPlugin");
                    FailWithLog();
                    return;
                }

                this.label.Text = "Init Phase 1: WSServer";
                _container.Register(new WSServer(_container));

#if DEBUG
                _logger.Log(LogLevel.Debug, "Component init and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                this.label.Text = "Init Phase 1: CEF";
                try
                {
                    Renderer.Initialize(PluginDirectory, ActGlobals.oFormActMain.AppDataFolder.FullName, Config.ErrorReports);
                }
                catch (Exception e)
                {
                    _logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                _logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                this.label.Text = "Init Phase 1: Legacy message bus";
                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif

                this.label.Text = "Init Phase 1: UI";

                // Setup the UI
                this.controlPanel      = new ControlPanel(_container);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "ngld悬浮窗";

                this.wsConfigPanel      = new WSConfigPanel(_container);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("悬浮窗WS服务");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                _logger.Log(LogLevel.Info, "InitPlugin: Initialised.");

                if (false) //if (Config.UpdateCheck)
                {
                    Updater.Updater.PerformUpdateIfNecessary(PluginDirectory, _container);
                }

                this.label.Text = "Init Phase 1: Presets";
                // Load our presets
                try
                {
#if DEBUG
                    var presetFile = Path.Combine(PluginDirectory, "libs", "resources", "presets.json");
#else
                    var presetFile = Path.Combine(PluginDirectory, "resources", "presets.json");
#endif
                    var presetData = "{}";

                    try
                    {
                        presetData = File.ReadAllText(presetFile);
                    }
                    catch (Exception ex)
                    {
                        _logger.Log(LogLevel.Error, string.Format(Resources.ErrorCouldNotLoadPresets, ex));
                    }

                    var presets  = JsonConvert.DeserializeObject <Dictionary <string, OverlayPreset> >(presetData);
                    var registry = _container.Resolve <Registry>();
                    foreach (var pair in presets)
                    {
                        pair.Value.Name = pair.Key;
                        registry.RegisterOverlayPreset2(pair.Value);
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log(LogLevel.Error, string.Format("Failed to load presets: {0}", ex));
                }

                this.label.Text    = "Init Phase 1: Waiting for plugins to load";
                initTimer          = new Timer();
                initTimer.Interval = 300;
                initTimer.Tick    += async(o, e) =>
                {
                    if (ActGlobals.oFormActMain == null)
                    {
                        // Something went really wrong.
                        initTimer.Stop();
                    }
                    else if (ActGlobals.oFormActMain.InitActDone && ActGlobals.oFormActMain.Handle != IntPtr.Zero)
                    {
                        try
                        {
                            initTimer.Stop();

                            // ** Init phase 2
                            this.label.Text = "Init Phase 2: Integrations";

                            // Initialize the parser in the second phase since it needs the FFXIV plugin.
                            // If OverlayPlugin is placed above the FFXIV plugin, it won't be available in the first
                            // phase but it'll be loaded by the time we enter the second phase.
                            _container.Register(new FFXIVRepository(_container));
                            _container.Register(new NetworkParser(_container));
                            _container.Register(new TriggIntegration(_container));

                            // This timer runs on the UI thread (it has to since we create UI controls) but LoadAddons()
                            // can block for some time. We run it on the background thread to avoid blocking the UI.
                            // We can't run LoadAddons() in the first init phase since it checks other ACT plugins for
                            // addons. Plugins below OverlayPlugin wouldn't have been loaded in the first init phase.
                            // However, in the second phase all plugins have been loaded which means we can look for addons
                            // in that list.
                            this.label.Text = "Init Phase 2: Addons";
                            await Task.Run(LoadAddons);

#if DEBUG
                            this.label.Text = "Init Phase 2: Unstable new stuff";
                            _container.Register(new UnstableNewLogLines(_container));
#endif


                            this.label.Text = "Init Phase 2: UI";
                            ActGlobals.oFormActMain.Invoke((Action)(() =>
                            {
                                try
                                {
                                    // Now that addons have been loaded, we can finish the overlay setup.
                                    this.label.Text = "Init Phase 2: Overlays";

                                    InitializeOverlays();
                                    controlPanel.InitializeOverlayConfigTabs();

                                    this.label.Text = "Init Phase 2: Overlay tasks";
                                    _container.Register(new OverlayHider(_container));
                                    _container.Register(new OverlayZCorrector(_container));

                                    // WSServer has to start after the LoadAddons() call because clients can connect immediately
                                    // after it's initialized and that requires the event sources to be initialized.
                                    if (Config.WSServerRunning)
                                    {
                                        this.label.Text = "Init Phase 2: WSServer";
                                        _container.Resolve <WSServer>().Start();
                                    }

                                    this.label.Text = "Init Phase 2: Save timer";
                                    configSaveTimer.Start();

                                    this.label.Text = "Initialised";
                                } catch (Exception ex)
                                {
                                    _logger.Log(LogLevel.Error, "InitPlugin: {0}", ex);
                                }
                            }));
                        }
                        catch (Exception ex)
                        {
                            _logger.Log(LogLevel.Error, "InitPlugin: {0}", ex);
                        }
                    }
                };
                initTimer.Start();
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());
                FailWithLog();
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage = pluginScreenSpace;
                this.label   = pluginStatusText;

#if DEBUG
                Logger.Log(LogLevel.Warning, "##################################");
                Logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                Logger.Log(LogLevel.Warning, "##################################");
#endif

                Logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                // ** Init phase 1
                // Only init stuff here that works without the FFXIV plugin or addons (event sources, overlays).
                // Everything else should be initialized in the second phase.
                NativeMethods.Init();
                FFXIVExportVariables.Init();
                EventDispatcher.Init();
                Registry.Register(new KeyboardHook());
                LoadConfig();

#if DEBUG
                Logger.Log(LogLevel.Debug, "Component init and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                try
                {
                    Renderer.Initialize(PluginDirectory, ActGlobals.oFormActMain.AppDataFolder.FullName, Config.ErrorReports);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                Logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif

                // コンフィグUI系初期化
                this.controlPanel      = new ControlPanel(this, this.Config);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "OverlayPlugin";

                this.wsConfigPanel      = new WSConfigPanel(this.Config);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("OverlayPlugin WSServer");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                Logger.Log(LogLevel.Info, "InitPlugin: Initialized.");
                this.label.Text = "Initialized.";

                if (Config.UpdateCheck)
                {
                    Updater.Updater.PerformUpdateIfNecessary(PluginDirectory);
                }

                initTimer          = new Timer();
                initTimer.Interval = 300;
                initTimer.Tick    += async(o, e) =>
                {
                    if (ActGlobals.oFormActMain == null)
                    {
                        // Something went really wrong.
                        initTimer.Stop();
                    }
                    else if (ActGlobals.oFormActMain.InitActDone && ActGlobals.oFormActMain.Handle != IntPtr.Zero)
                    {
                        try
                        {
                            initTimer.Stop();

                            // ** Init phase 2

                            // Initialize the parser in the second phase since it needs the FFXIV plugin.
                            // If OverlayPlugin is placed above the FFXIV plugin, it won't be available in the first
                            // phase but it'll be loaded by the time we enter the second phase.
                            NetworkParser.Init();

                            TriggIntegration.Init();

                            // This timer runs on the UI thread (it has to since we create UI controls) but LoadAddons()
                            // can block for some time. We run it on the background thread to avoid blocking the UI.
                            // We can't run LoadAddons() in the first init phase since it checks other ACT plugins for
                            // addons. Plugins below OverlayPlugin wouldn't have been loaded in the first init phase.
                            // However, in the second phase all plugins have been loaded which means we can look for addons
                            // in that list.
                            await Task.Run(LoadAddons);

                            ActGlobals.oFormActMain.Invoke((Action)(() =>
                            {
                                // Now that addons have been loaded, we can finish the overlay setup.
                                InitializeOverlays();
                                controlPanel.InitializeOverlayConfigTabs();
                                OverlayHider.Init();
                                OverlayZCorrector.Init();

                                // WSServer has to start after the LoadAddons() call because clients can connect immediately
                                // after it's initialized and that requires the event sources to be initialized.
                                if (Config.WSServerRunning)
                                {
                                    WSServer.Init();
                                }
                            }));
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(LogLevel.Error, "InitPlugin: {0}", ex);
                        }
                    }
                };
                initTimer.Start();
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());

                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage = pluginScreenSpace;
                this.label   = pluginStatusText;

#if DEBUG
                Logger.Log(LogLevel.Warning, "##################################");
                Logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                Logger.Log(LogLevel.Warning, "##################################");
#endif

                Logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                try
                {
                    Renderer.Initialize(PluginDirectory);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                Logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                FFXIVExportVariables.Init();

                // プラグイン読み込み
                LoadAddons();

                // コンフィグ系読み込み
                LoadConfig();

#if DEBUG
                Logger.Log(LogLevel.Debug, "Addon and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                if (Config.WSServerRunning)
                {
                    try
                    {
                        WSServer.Initialize();
                    }
                    catch (Exception e)
                    {
                        Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                    }
                }

                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif
                InitializeOverlays();

#if DEBUG
                Logger.Log(LogLevel.Debug, "ES and overlay init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Stop();
#endif

                // コンフィグUI系初期化
                this.controlPanel      = new ControlPanel(this, this.Config);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "OverlayPlugin";

                this.wsConfigPanel      = new WSConfigPanel(this.Config);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("OverlayPlugin WSServer");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                Logger.Log(LogLevel.Info, "InitPlugin: Initialized.");
                this.label.Text = "Initialized.";
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());

                throw;
            }
        }
Exemple #4
0
        /// <summary>
        /// プラグインが有効化されたときに呼び出されます。
        /// </summary>
        /// <param name="pluginScreenSpace"></param>
        /// <param name="pluginStatusText"></param>
        public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
        {
            try
            {
                this.tabPage = pluginScreenSpace;
                this.label   = pluginStatusText;

#if DEBUG
                Logger.Log(LogLevel.Warning, "##################################");
                Logger.Log(LogLevel.Warning, "    THIS IS THE DEBUG BUILD");
                Logger.Log(LogLevel.Warning, "##################################");
#endif

                Logger.Log(LogLevel.Info, "InitPlugin: PluginDirectory = {0}", PluginDirectory);

#if DEBUG
                Stopwatch watch = new Stopwatch();
                watch.Start();
#endif

                FFXIVExportVariables.Init();
                NetworkParser.Init();
                EventDispatcher.Init();

                // LoadAddons();
                LoadConfig();

#if DEBUG
                Logger.Log(LogLevel.Debug, "Component init and config load took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                try
                {
                    Renderer.Initialize(PluginDirectory, ActGlobals.oFormActMain.AppDataFolder.FullName, Config.ErrorReports);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "InitPlugin: {0}", e);
                }

#if DEBUG
                Logger.Log(LogLevel.Debug, "CEF init took {0}s.", watch.Elapsed.TotalSeconds);
                watch.Reset();
#endif

                // プラグイン間のメッセージ関連
                OverlayApi.BroadcastMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        foreach (var overlay in this.Overlays)
                        {
                            overlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.SendMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.SendMessage(e.Message);
                        }
                    });
                };
                OverlayApi.OverlayMessage += (o, e) =>
                {
                    Task.Run(() =>
                    {
                        var targetOverlay = this.Overlays.FirstOrDefault(x => x.Name == e.Target);
                        if (targetOverlay != null)
                        {
                            targetOverlay.OverlayMessage(e.Message);
                        }
                    });
                };

#if DEBUG
                watch.Reset();
#endif

                // コンフィグUI系初期化
                this.controlPanel      = new ControlPanel(this, this.Config);
                this.controlPanel.Dock = DockStyle.Fill;
                this.tabPage.Controls.Add(this.controlPanel);
                this.tabPage.Name = "OverlayPlugin";

                this.wsConfigPanel      = new WSConfigPanel(this.Config);
                this.wsConfigPanel.Dock = DockStyle.Fill;

                this.wsTabPage = new TabPage("OverlayPlugin WSServer");
                this.wsTabPage.Controls.Add(wsConfigPanel);
                ((TabControl)this.tabPage.Parent).TabPages.Add(this.wsTabPage);

                Logger.Log(LogLevel.Info, "InitPlugin: Initialized.");
                this.label.Text = "Initialized.";

                if (Config.UpdateCheck)
                {
                    Updater.Updater.PerformUpdateIfNecessary(controlPanel, PluginDirectory);
                }

                initTimer          = new Timer();
                initTimer.Interval = 300;
                initTimer.Tick    += (o, e) =>
                {
                    if (ActGlobals.oFormActMain.InitActDone && ActGlobals.oFormActMain.Handle != IntPtr.Zero)
                    {
                        initTimer.Stop();

                        Registry.Register(new KeyboardHook());

                        LoadAddons();
                        InitializeOverlays();
                        controlPanel.InitializeOverlayConfigTabs();

                        OverlayHider.Initialize();

                        if (Config.WSServerRunning)
                        {
                            try
                            {
                                WSServer.Initialize();
                            }
                            catch (Exception ex)
                            {
                                Logger.Log(LogLevel.Error, "InitPlugin: {0}", ex);
                            }
                        }
                    }
                };
                initTimer.Start();
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Error, "InitPlugin: {0}", e.ToString());
                MessageBox.Show(e.ToString());

                throw;
            }
        }