Пример #1
0
        public static EliteBinds getBinds(ref Dictionary <string, object> state, ref Dictionary <string, string> textValues, ref Dictionary <string, bool?> booleanValues, Elite.MessageBus messageBus)
        {
            EliteBinds eliteBinds = null;

            if (needsBindsReload(ref state, ref textValues, ref booleanValues) == true)
            {
                Tuple <string, string> tResponse = Elite.getBindsFilename();
                string bindsPreset = tResponse.Item1;
                string bindsFile   = tResponse.Item2;

                if (bindsPreset != null && bindsFile != null)
                {
                    Debug.Write("Current Binds file: " + bindsFile);
                    var bindsTree = XElement.Load(bindsFile);
                    state["VAEDbindsFile"]           = bindsFile;
                    state["VAEDbindsPreset"]         = bindsPreset;
                    state["VAEDlastPresetTimestamp"] = File.GetLastWriteTime(bindsPreset);
                    state["VAEDlastBindsTimestamp"]  = File.GetLastWriteTime(bindsFile);
                    XElement keyboardLayout = bindsTree.Element("KeyboardLayout");
                    string   lang           = keyboardLayout.Value.ToString();
                    Debug.Write("Elite key bindings language set to: " + lang);
                    state["VAEDbindsLanguage"] = lang;

                    eliteBinds = new EliteBinds(bindsTree, lang);

                    state["VAEDeliteBinds"] = eliteBinds;
                }
            }
            else
            {
                eliteBinds = (EliteBinds)state["VAEDeliteBinds"];
            }
            return(eliteBinds);
        }
Пример #2
0
        public static void VA_Invoke1(String context, ref Dictionary <string, object> state, ref Dictionary <string, Int16?> shortIntValues, ref Dictionary <string, string> textValues, ref Dictionary <string, int?> intValues, ref Dictionary <string, decimal?> decimalValues, ref Dictionary <string, bool?> booleanValues, ref Dictionary <string, object> extendedValues)
        {
            try
            {
                Elite.MessageBus messageBus = (Elite.MessageBus)state["VAEDmessageBus"];
                messageBus.loggedinState = (string)state["VAEDloggedIn"];
                if (state.ContainsKey("VAEDcookieContainer"))
                {
                    messageBus.cookies = (CookieContainer)state["VAEDcookieContainer"];
                }
                Debug.Write("COMMAND:  " + context);
                switch (context.ToLower())
                {
                case "check for upgrade":
                    if (Upgrade.needUpgradeWithCooldown(ref state))
                    {
                        booleanValues["VAEDupgradeAvailable"] = true;
                        state["VAEDupgradeAvailable"]         = true;
                    }
                    else
                    {
                        booleanValues["VAEDupgradeAvailable"] = false;
                        state["VAEDupgradeAvailable"]         = false;
                    }
                    break;

                case "distance from here":
                    string currentSystem = messageBus.currentSystem;
                    if (currentSystem == null)     // If we don't have it from netlog then go get it from the profile
                    {
                        Dictionary <string, dynamic> companion = Companion.getProfile((messageBus));
                        if (companion.ContainsKey("lastSystem") && companion["lastSystem"].ContainsKey("name"))
                        {
                            currentSystem            = currentSystem = companion["lastSystem"]["name"];
                            messageBus.currentSystem = currentSystem;
                            // We didn't have current system from netlog, so erase out x,y,z

                            messageBus.haveSystemCoords = false;
                        }
                    }

                    decimalValues["VAEDdecimalDistance"] = null;
                    decimalValues["VAEDintDistance"]     = null;
                    if (currentSystem != null)
                    {
                        int distance = Atlas.calcDistanceFromHere(messageBus, textValues["VAEDtargetSystem"]);
                        if (distance < 0)
                        {
                            //Cound not find destination system
                            Debug.Write("Error:  Could not determine distance to target system");
                            booleanValues["VAEDerrorTargetSystem"] = true;
                            break;
                        }
                        // Found the system - return distance
                        intValues["VAEDintDistance"]           = distance;
                        booleanValues["VAEDerrorTargetSystem"] = false;
                        booleanValues["VAEDerrorSourceSystem"] = false;
                        break;
                    }
                    //Can't find the System
                    Debug.Write("Error:  Could not determine current location for command 'distance from here'");
                    booleanValues["VAEDerrorSourceSystem"]      = true;
                    booleanValues["VAEDerrorDestinationSystem"] = false;
                    break;

                case "dictate system":
                    booleanValues["VAEDrecognitionNotLoaded"] = false;
                    if (messageBus.grammarLoaded)
                    {
                        SpeechRecognitionEngine recognitionEngine = messageBus.recognitionEngine;

                        Tuple <string, string> tSystemNames = EliteGrammar.dictateSystem(recognitionEngine, (List <String>)state["VAEDtrackedSystems"]);
                        textValues["VAEDdictateSystem"]         = tSystemNames.Item1;
                        textValues["VAEDdictateSystemPhonetic"] = tSystemNames.Item2;
                        break;
                    }
                    else
                    {
                        booleanValues["VAEDrecognitionNotLoaded"] = true;
                        Debug.Write("Error:  Speech Engine not yet Initialized.  (Possibly still loading)");
                    }
                    textValues["VAEDdictateSystem"]         = null;
                    textValues["VAEDdictateSystemPhonetic"] = null;
                    break;

                case "press key bind":
                    // If the Binds file changes then reload the binds.

                    string[]   parts      = textValues["VAEDkeyBinding"].Split(new char[] { ':' }, 2);
                    EliteBinds eliteBinds = EliteBinds.getBinds(ref state, ref textValues, ref booleanValues, messageBus);
                    if (eliteBinds != null)
                    {
                        string keyboardLanguage;
                        if (state.ContainsKey("VAEDbindsLanguage"))
                        {
                            keyboardLanguage = (string)state["VAEDbindsLanguage"];
                        }
                        else
                        {
                            keyboardLanguage = "en-US";
                        }
                        List <uint> scanCodeExs = KeyMouse.MapVkToScanCodeExs(eliteBinds.GetCodes(parts[1], keyboardLanguage));
                        if (scanCodeExs.Count == 0)
                        {
                            Debug.Write("Warning: No key binding found for: " + textValues["VAEDkeyBinding"]);
                            booleanValues["VAEDkeyBindingError"] = true;
                            break;
                        }



                        switch (parts[0])
                        {
                        // For now we only "best effort" focus the game before keypressing.  Igorning the setFocus return code.
                        case "KEYPRESS":
                            Debug.Write("Key Press " + parts[1]);
                            User32.setFocus(eliteWindowTitle);
                            KeyMouse.KeyPress(scanCodeExs);
                            booleanValues["VAEDkeyBindingError"] = false;
                            break;

                        case "KEYUP":
                            Debug.Write("Key up " + parts[1]);
                            User32.setFocus(eliteWindowTitle);
                            KeyMouse.KeyUp(scanCodeExs);
                            booleanValues["VAEDkeyBindingError"] = false;
                            break;

                        case "KEYDOWN":
                            Debug.Write("Key down " + parts[1]);
                            User32.setFocus(eliteWindowTitle);
                            KeyMouse.KeyDown(scanCodeExs);
                            booleanValues["VAEDkeyBindingError"] = false;
                            break;

                        default:
                            booleanValues["VAEDkeyBindingError"] = true;
                            break;
                        }
                    }
                    else
                    {
                        Debug.Write("Error:  Binds not loaded, unable to perform keypress");
                    }
                    break;

                case "clear debug":
                    Debug.Clear();
                    break;

                case "get debug":
                    string tempDebug = Debug.Path();
                    textValues["VAEDdebugFile"] = tempDebug;
                    break;

                case "export for ed shipyard":
                    Companion.updateProfile(messageBus, ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues);

                    if (state.ContainsKey("VAEDshipObj"))
                    {
                        Ship.Components shipObj = (Ship.Components)state["VAEDshipObj"];
                        StringBuilder   export  = EDShipyard.export(shipObj);
                        if (export != null)
                        {
                            booleanValues["VAEDexportEDShipyardError"] = false;
                            Clipboard.SetText(export.ToString());
                            break;
                        }
                    }
                    Debug.Write("Error:  Unable to form ED Shipyard.com Export");
                    Clipboard.Clear();
                    booleanValues["VAEDexportEDShipyuardError"] = true;
                    break;

                case "export for coriolis":
                    Companion.updateProfile(messageBus, ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues);
                    if (state.ContainsKey("VAEDshipObj"))
                    {
                        Ship.Components shipObj = (Ship.Components)state["VAEDshipObj"];
                        string          json    = Coriolis.export(shipObj);
                        if (json != null)
                        {
                            booleanValues["VAEDexportCoriolisError"] = false;
                            Clipboard.SetText(json);
                            break;
                        }
                    }
                    Debug.Write("Error:  Unable to form Coriolis.io JSON");
                    Clipboard.Clear();
                    booleanValues["VAEDexportCoriolisError"] = true;
                    break;

                case "edit web variable sources":
                    bool foundWindow = false;
                    foreach (Form form in Application.OpenForms)
                    {
                        if (form.GetType().Name == "EditWebVars")
                        {
                            Debug.Write("Edit Web Variable Sources window is already open");
                            foundWindow = true;
                        }
                    }
                    if (!foundWindow)
                    {
                        var webVarsForm = new WebVars.EditWebVars();
                        webVarsForm.ShowDialog();
                    }
                    break;

                case "get web variables":
                    GetWebVars.readWebVars(ref state, ref textValues, ref intValues, ref booleanValues);
                    break;

                case "get file variables":
                    FileVar.readFileVars(ref state, ref textValues, ref intValues, ref booleanValues);
                    break;

                case "get clipboard":
                    if (Clipboard.ContainsText(TextDataFormat.Text))
                    {
                        textValues.Add("VAEDclipboard", Clipboard.GetText());
                    }
                    break;

                case "get frontier credentials":
                    var configureForm = new ConfigureForm.Configuration((string)state["VAEDloggedIn"]);
                    configureForm.ShowDialog();
                    CookieContainer loginCookies = configureForm.Cookie;
                    state["VAEDcookieContainer"] = loginCookies;
                    string loginResponse = configureForm.LoginResponse;
                    Debug.Write("Frontier Login Response: " + loginResponse);
                    textValues["VAEDloggedIn"] = loginResponse;
                    break;

                case "get frontier verification":
                    CookieContainer verifyCookies = new CookieContainer();
                    if (state.ContainsKey("VAEDcookieContainer"))
                    {
                        verifyCookies = (CookieContainer)state["VAEDcookieContainer"];
                    }
                    var verificationForm = new VerificationCode.Validate();
                    verificationForm.Cookie = verifyCookies;
                    verificationForm.ShowDialog();
                    verifyCookies = verificationForm.Cookie;
                    string verifyResponse = verificationForm.VerifyResponse;
                    state["VAEDloggedIn"]        = verifyResponse;
                    state["VAEDcookieContainer"] = verifyCookies;
                    textValues["VAEDloggedIn"]   = verifyResponse;
                    if (verifyResponse == "ok")
                    {
                        Web.WriteCookiesToDisk(Config.CookiePath(), verifyCookies);
                    }
                    break;

                case "update profile and eddn":
                    if (state["VAEDloggedIn"].ToString() == "ok" && state.ContainsKey("VAEDcookieContainer"))
                    {
                        Companion.updateProfile(messageBus, ref state, ref shortIntValues, ref textValues, ref intValues, ref decimalValues, ref booleanValues);
                    }
                    else     // Not logged in
                    {
                        textValues["VAEDprofileStatus"] = "credentials";
                    }
                    break;

                default:
                    Debug.Write("ERROR: unknown command");
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }
Пример #3
0
        public static void VA_Init1(ref Dictionary <string, object> state, ref Dictionary <string, Int16?> shortIntValues, ref Dictionary <string, string> textValues, ref Dictionary <string, int?> intValues, ref Dictionary <string, decimal?> decimalValues, ref Dictionary <string, bool?> booleanValues, ref Dictionary <string, object> extendedValues)
        {
            try
            {
                Debug.Write("---------------------- Ocellus Plugin " + pluginVersion + " Initializing ----------------------");
                string configPath = Config.Path();
                string drive      = configPath.Substring(0, 2);
                Debug.Write("Current culture set to: " + Thread.CurrentThread.CurrentCulture.ToString());

                // Cleanup
                string oldGrammar = Path.Combine(configPath, "systems_grammar.xml");
                if (File.Exists(oldGrammar))
                {
                    File.Delete(oldGrammar);
                }
                string oldEddb = Path.Combine(configPath, "eddb_index.txt");
                if (File.Exists(oldEddb))
                {
                    File.Delete(oldEddb);
                }
                string oldAtlas = Path.Combine(configPath, "atlas_index.txt");
                if (File.Exists(oldAtlas))
                {
                    File.Delete(oldAtlas);
                }

                Utilities.ReportFreeSpace(drive);
                Elite.MessageBus messageBus = new Elite.MessageBus();

                int registryCheck = PluginRegistry.checkRegistry();

                // Load System Index into memory
                SystemIndex.loadSystemIndex(ref messageBus);

                // Spin up Speech announcer thread
                Task.Run(() => Announcements.speak(messageBus));

                // Setup Speech engine
                try
                {
                    CultureInfo             currCulture       = Thread.CurrentThread.CurrentCulture;
                    SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine(currCulture);
                    messageBus.recognitionEngine     = recognitionEngine;
                    messageBus.recognitionEngineLang = currCulture;
                }
                catch
                {
                    messageBus.recognitionEngineLang = new CultureInfo("en-US");
                    SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine(messageBus.recognitionEngineLang);
                    messageBus.recognitionEngine = recognitionEngine;
                    Debug.Write("Warning:  Falling back to default language for recognition engine");
                }

                Task.Run(() => EliteGrammar.loadGrammar(messageBus));

                // Setup plugin storage directory - used for cookies and debug logs
                string appPath    = Config.Path();
                string cookieFile = Config.CookiePath();
                string debugFile  = Config.DebugPath();
                textValues["VAEDdebugPath"] = debugFile;

                // Determine Elite Dangerous directories
                string gameStartString = PluginRegistry.getStringValue("startPath");
                string gameStartParams = PluginRegistry.getStringValue("startParams");
                textValues["VAEDgameStartString"] = gameStartString;
                textValues["VAEDgameStartParams"] = gameStartParams;

                // Load Tracked Systems into memory
                TrackSystems.Load(ref state);

                CookieContainer cookieJar = new CookieContainer();
                if (File.Exists(cookieFile))
                {
                    // If we have cookies then we are likely already logged in
                    cookieJar = Web.ReadCookiesFromDisk(cookieFile);
                    Tuple <CookieContainer, string> tAuthentication = Companion.loginToAPI(cookieJar);
                    if (tAuthentication.Item2 == "ok")
                    {
                        cookieJar = tAuthentication.Item1;
                        state["VAEDcookieContainer"] = cookieJar;
                        state["VAEDloggedIn"]        = "ok";
                    }
                    else
                    {
                        state.Add("VAEDloggedIn", "no");
                    }
                }
                else
                {
                    state.Add("VAEDloggedIn", "no");
                }

                EliteBinds.getBinds(ref state, ref textValues, ref booleanValues, messageBus);

                messageBus.cookies       = cookieJar;
                messageBus.loggedinState = (string)state["VAEDloggedIn"];

                state["VAEDmessageBus"] = messageBus;

                Task.Run(() => Announcements.startupNotifications(messageBus, registryCheck));

                //Watch the netlog for docked and system change information
                Task.Run(() => Elite.tailNetLog(messageBus));
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }
Пример #4
0
        public static void VA_Init1(ref Dictionary <string, object> state, ref Dictionary <string, Int16?> shortIntValues, ref Dictionary <string, string> textValues, ref Dictionary <string, int?> intValues, ref Dictionary <string, decimal?> decimalValues, ref Dictionary <string, bool?> booleanValues, ref Dictionary <string, object> extendedValues)
        {
            try
            {
                Debug.Write("---------------------- Ocellus Plugin Initializing ----------------------");
                // Setup Speech engine
                if (EliteGrammar.downloadGrammar())
                {
                    SpeechRecognitionEngine recognitionEngine = new SpeechRecognitionEngine();
                    recognitionEngine.SetInputToDefaultAudioDevice();
                    Grammar grammar = new Grammar(Path.Combine(Config.Path(), "systems_grammar.xml"));
                    Task.Run(() => recognitionEngine.LoadGrammar(grammar));
                    state.Add("VAEDrecognitionEngine", recognitionEngine);
                }

                // Setup plugin storage directory - used for cookies and debug logs
                string appPath    = Config.Path();
                string cookieFile = Config.CookiePath();
                string debugFile  = Config.DebugPath();
                textValues["VAEDdebugPath"] = debugFile;

                // Determine Elite Dangerous directories
                string gamePath        = Elite.getGamePath();
                string gameStartString = PluginRegistry.getStringValue("startPath");
                string gameStartParams = PluginRegistry.getStringValue("startParams");
                state.Add("VAEDgamePath", gamePath);
                textValues["VAEDgameStartString"] = gameStartString;
                textValues["VAEDgameStartParams"] = gameStartParams;

                // Load EDDB Index into memory
                Eddb.loadEddbIndex(ref state);

                // Load Atlas Index into memory
                Atlas.loadAtlasIndex(ref state);

                Dictionary <string, dynamic> tempAtlas = (Dictionary <string, dynamic>)state["VAEDatlasIndex"];

                // Load Tracked Systems into memory
                TrackSystems.Load(ref state);

                CookieContainer cookieJar = new CookieContainer();
                if (File.Exists(cookieFile))
                {
                    // If we have cookies then we are likely already logged in
                    cookieJar = Web.ReadCookiesFromDisk(cookieFile);
                    Tuple <CookieContainer, string> tAuthentication = Companion.loginToAPI(cookieJar);
                    if (tAuthentication.Item2 == "ok")
                    {
                        cookieJar = tAuthentication.Item1;
                        state.Add("VAEDcookieContainer", cookieJar);
                        state["VAEDloggedIn"] = "ok";
                    }
                }
                else
                {
                    state.Add("VAEDloggedIn", "no");
                }

                EliteBinds eliteBinds = new EliteBinds();
                state.Add("VAEDeliteBinds", eliteBinds);
                string   bindsFile = Elite.getBindsFilename();
                DateTime fileTime  = File.GetLastWriteTime(bindsFile);
                state.Add("VAEDbindsFile", bindsFile);
                state.Add("VAEDbindsTimestamp", fileTime);
            }
            catch (Exception ex)
            {
                Debug.Write(ex.ToString());
            }
        }