コード例 #1
0
        private void AttachFfxiv()
        {
            //Debug.WriteLine("Debug trip B");

            if (InitiateMemory())
            {
                //Console.WriteLine("Attached");
                //rtb_debug.Invoke((Action)delegate { rtb_debug.AppendText("Attached" + Environment.NewLine); });
                WriteConsole(ConsoleTypes.Ffxiv, "Attached to FFXIV");
                _gameNotify        = false;
                notify_master.Text = @"Attached to FFXIV";

                if (ChromaticsSettings.ChromaticsSettingsDesktopNotifications)
                {
                    notify_master.BalloonTipText = @"Attached to FFXIV";
                    notify_master.ShowBalloonTip(1500);
                }

                if (ArxSdkCalled == 1 && ArxState == 0)
                {
                    _arx.ArxUpdateInfo("Attached to FFXIV");
                }

                if (LcdSdkCalled == 1)
                {
                    _lcd.StatusLCDInfo(@"Attached to FFXIV");
                }

                Attatched = 1;
                SetFormName(@"Chromatics " + _currentVersionX + @" (Attached)");

                _attachcts.Cancel();

                MemoryTasks.Remove(MemoryTask);
                MemoryTask  = null;
                _memoryTask = new CancellationTokenSource();
                _ffxiVcts   = new CancellationTokenSource();

                //_call = CallFfxivMemory(_ffxiVcts.Token);

                MemoryTask = new Task(() =>
                {
                    _call = CallFfxivMemory(_ffxiVcts);
                }, _memoryTask.Token, TaskCreationOptions.LongRunning);

                MemoryTasks.Add(MemoryTask);
                MemoryTasks.Run(MemoryTask);
            }
            else
            {
                if (!_gameNotify)
                {
                    WriteConsole(ConsoleTypes.Ffxiv, "Waiting for Game Launch..");
                    notify_master.Text = @"Waiting for Game Launch..";

                    if (LcdSdkCalled == 1)
                    {
                        _lcd.StatusLCDInfo(@"Waiting for Game Launch..");
                    }

                    if (ArxSdkCalled == 1 && ArxState == 0)
                    {
                        _arx.ArxUpdateInfo("Waiting for Game Launch..");
                    }

                    SetFormName(@"Chromatics " + _currentVersionX);

                    _gameNotify = true;
                }
            }
        }
コード例 #2
0
        private void MainThread()
        {
            //Setup References
            //Watchdog.WatchdogStartup();
            if (!_debugmode)
            {
                Text = @"Chromatics " + _currentVersionX;
            }
            else
            {
                Text = @"Chromatics " + _currentVersionX + @" (BETA)";
            }

            //Setup Event Listeners
            FormClosing += OnFormClosing;
            Resize      += ChromaticsForm_Resize;
            Application.ApplicationExit += OnApplicationExit;
            exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;
            mi_effectsenable.Click      += enableeffects_Click;
            mi_arxenable.Click          += enablearx_Click;
            mi_showwindow.Click         += showwindow_Click;
            mi_winstart.Click           += mi_winstart_Click;
            mi_updatecheck.Click        += mi_updatecheck_Click;

            _mGlobalHook          = Hook.GlobalEvents();
            _mGlobalHook.KeyDown += Kh_KeyDown;
            _mGlobalHook.KeyUp   += Kh_KeyUp;

            try
            {
                var lgsApp = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Logitech\\Logitech Gaming Software", false);
                if (lgsApp != null)
                {
                    _lgsInstall = lgsApp.GetValue("InstallDir").ToString();
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            //Bind
            if (!_debugmode)
            {
                WriteConsole(ConsoleTypes.System, @"Starting Chromatics Version " + _currentVersionX);
            }
            else
            {
                WriteConsole(ConsoleTypes.System, @"Starting Chromatics Version " + _currentVersionX + " (BETA)");
            }


            //Load Functions
            LoadDevices();
            LoadChromaticsSettings();
            LoadColorMappings();


            //Check Administrator permissions
            if (!IsAdministrator())
            {
                WriteConsole(ConsoleTypes.Error,
                             @"Chromatics is not running as Administrator. Please restart with administrative privileges.");

                if (chk_lccauto.Checked)
                {
                    tooltip_main.SetToolTip(gB_lcc,
                                            @"Logitech Conflict Mode requires Chromatics to be run with Administrative privileges. Please restart with administrative privileges.");
                }

                gB_lcc.Enabled = false;
                btn_ffxivcachereset.Enabled = false;
            }
            else
            {
                var enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;

                if (!ChromaticsSettings.ChromaticsSettingsMemoryCache)
                {
                    if (File.Exists(enviroment + @"/signatures-x64.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/signatures-x64.json");
                    }

                    if (File.Exists(enviroment + @"/structures-x64.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/structures-x64.json");
                    }
                }

                if (ChromaticsSettings.ChromaticsSettingsLanguage != ChromaticsSettings.ChromaticsSettingsPreviousLanguage)
                {
                    if (File.Exists(enviroment + @"/signatures-x64.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/signatures-x64.json");
                    }

                    if (File.Exists(enviroment + @"/structures-x64.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/structures-x64.json");
                    }

                    if (File.Exists(enviroment + @"/actions.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/actions.json");
                    }

                    if (File.Exists(enviroment + @"/statuses.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/statuses.json");
                    }

                    if (File.Exists(enviroment + @"/zones.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/zones.json");
                    }

                    WriteConsole(ConsoleTypes.Ffxiv, @"Language change detected. Clearing Cache..");
                    ChromaticsSettings.ChromaticsSettingsPreviousLanguage = ChromaticsSettings.ChromaticsSettingsLanguage;
                }

                if (!ChromaticsSettings.FirstRun)
                {
                    if (File.Exists(enviroment + @"/signatures-x64.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/signatures-x64.json");
                    }

                    if (File.Exists(enviroment + @"/structures-x64.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/structures-x64.json");
                    }

                    if (File.Exists(enviroment + @"/actions.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/actions.json");
                    }

                    if (File.Exists(enviroment + @"/statuses.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/statuses.json");
                    }

                    if (File.Exists(enviroment + @"/zones.json"))
                    {
                        FileSystem.DeleteFile(enviroment + @"/zones.json");
                    }

                    ChromaticsSettings.FirstRun = true;
                    SaveChromaticsSettings(0);
                }
            }

            //Check Updater
            try
            {
                string enviroment = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;
                if (!File.Exists(enviroment + @"/updater.exe"))
                {
                    if (File.Exists(enviroment + @"/_updater.exe"))
                    {
                        FileSystem.RenameFile(enviroment + @"/_updater.exe", "updater.exe");
                        WriteConsole(ConsoleTypes.System, @"Updated Chromatics Updater to latest version.");
                    }
                }
                else
                {
                    if (File.Exists(enviroment + @"/_updater.exe"))
                    {
                        File.Delete(enviroment + @"/updater.exe");
                        FileSystem.RenameFile(enviroment + @"/_updater.exe", "updater.exe");
                        WriteConsole(ConsoleTypes.System, @"Updated Chromatics Updater to latest version.");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            //Setup GUI
            InitDeviceDataGrid();
            InitColorMappingGrid();
            InitSettingsGui();
            SetupTooltips();
            CenterPictureBox(pB_logo1, pB_logo1.Image);
            notify_master.ContextMenuStrip = contextMenuStrip1;

            Localization.SetKeyRegion(ChromaticsSettings.ChromaticsSettingsQwertyMode);

            try
            {
                if (ChromaticsSettings.ChromaticsSettingsDebugOpt)
                {
                    AutoMeasurement.Instance = new WinFormAutoMeasurement();
                    AutoMeasurement.Start(new MeasurementConfiguration("UA-92921709-2", "Chromatics", _currentVersionX));
                }
            }
            catch (Exception ex)
            {
                WriteConsole(ConsoleTypes.Error, @"Unable to hook debug reporting. Ex: " + ex.Message);
            }

            if (ChromaticsSettings.ChromaticsSettingsDesktopNotifications)
            {
                notify_master.BalloonTipText = @"Chromatics will automatically attach to Final Fantasy XIV";
                notify_master.ShowBalloonTip(2000);
            }

            new Task(() => { CheckUpdates(0); }).Start();

            //Setup Device Interfaces
            InitializeSdk();
            InitDevicesGui();

            if (LogitechSdkCalled == 1 && Process.GetProcessesByName("LCore").Length > 0)
            {
                if (gB_lcc.Enabled)
                {
                    //Check Logitech Enviroment
                    try
                    {
                        if (File.Exists(_lgsInstall + @"\SDK\LED\x64\LogitechLed.dll"))
                        {
                            if (chk_lccauto.Checked)
                            {
                                ToggleLccMode(true);

                                chk_lccenable.CheckedChanged -= chk_lccenable_CheckedChanged;
                                chk_lccenable.Checked         = true;
                                chk_lccenable.CheckedChanged += chk_lccenable_CheckedChanged;
                            }
                            else
                            {
                                WriteConsole(ConsoleTypes.Error,
                                             @"Logitech: Chromatics has detected that the LGS internal SDK library is causing a conflict between FFXIV and Chromatics. Please make sure to enable 'Logitech Conflict Mode' under the settings tab and check that 'LED Illumination' is disabled for 'ffxiv_dx11' within LGS.");
                            }
                        }
                        else
                        {
                            WriteConsole(ConsoleTypes.Logitech, @"Logitech Conflict Mode is already enabled.");

                            chk_lccenable.CheckedChanged -= chk_lccenable_CheckedChanged;
                            chk_lccenable.Checked         = true;
                            chk_lccenable.CheckedChanged += chk_lccenable_CheckedChanged;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);

                        if (chk_lccauto.Checked)
                        {
                            WriteConsole(ConsoleTypes.Error,
                                         @"Logitech Conflict Mode failed to automatically start. Error: " + ex.Message);

                            chk_lccenable.CheckedChanged -= chk_lccenable_CheckedChanged;
                            chk_lccenable.Checked         = false;
                            chk_lccenable.CheckedChanged += chk_lccenable_CheckedChanged;
                        }
                    }
                }
                else
                {
                    if (File.Exists(_lgsInstall + @"\SDK\LED\x64\LogitechLed.dll"))
                    {
                        WriteConsole(ConsoleTypes.Error,
                                     "Logitech: Chromatics has detected that the LGS internal SDK library is causing a conflict between FFXIV and Chromatics. Please make sure to enable 'Logitech Conflict Mode' under the settings tab and check that 'LED Illumination' is disabled for 'ffxiv_dx11' within LGS.");
                    }
                }
            }
            else
            {
                if (Process.GetProcessesByName("lghub").Length == 0)
                {
                    tooltip_main.SetToolTip(gB_lcc,
                                            "Logitech SDK not loaded. Please open LGS Software and restart Chromatics as Administrator.");
                }

                gB_lcc.Enabled = false;
            }


            //Setup LCD Interfaces

            if (ChromaticsSettings.ChromaticsSettingsLcdEnabled)
            {
                _lcd = LogitechLcdInterface.InitializeLcdSdk();

                if (_lcd != null)
                {
                    LcdSdk       = true;
                    LcdSdkCalled = 1;
                    WriteConsole(ConsoleTypes.Logitech, @"LCD SDK Loaded");
                }
            }


            if (chk_arxtoggle.Checked)
            {
                _arx = LogitechArxInterface.InitializeArxSdk();

                if (_arx != null)
                {
                    ArxSdk       = true;
                    ArxState     = 0;
                    ArxSdkCalled = 1;
                    WriteConsole(ConsoleTypes.Arx, @"ARX SDK Loaded");

                    //Load Plugins
                    LoadArxPlugins();
                }
            }


            //Finish GUI Setup
            InitSettingsArxGui();
            Startup = true;

            //Ambience

            /*
             * if (IsAdministrator())
             *  AmbienceInterface.StartAmbience();
             */

            var gameLanguage = "English";

            switch (ChromaticsSettings.ChromaticsSettingsLanguage)
            {
            case 0:
                //English
                gameLanguage = "English";
                break;

            case 1:
                //Chinese
                gameLanguage = "Chinese";
                break;

            case 2:
                //Japanese
                gameLanguage = "Japanese";
                break;

            case 3:
                //French
                gameLanguage = "French";
                break;

            case 4:
                //German
                gameLanguage = "German";
                break;

            case 5:
                //Korean
                gameLanguage = "Korean";
                break;
            }

            WriteConsole(ConsoleTypes.Ffxiv, @"Game Language set to " + gameLanguage + @".");

            //Split off MemoryReader to a Task
            MemoryTask = new Task(() =>
            {
                _call = CallFfxivAttach(_attachcts.Token);
            }, _memoryTask.Token);

            MemoryTasks.Add(MemoryTask);
            MemoryTasks.Run(MemoryTask);
        }