Beispiel #1
0
        // Checks periodically if the currently focussed window is a different linked process to the previously focussed + linked process
        // The aim is to only switch lighting effects when we refocus to another linked process, otherwise we let the last linked process keep its profile running
        private static void UpdateProcessLinkedProfiles()
        {
            string currentFocus = GetFocussedProcess();

            // If we have switched focus to another process
            // Note:    If a controller is manually launched (e.g. the documentation Javascript), refocussing to a linked process WILL NOT trigger AutoSetGame.
            //          This is by design to allow switching between unlinked processes without interupting lighting. We could trigger AutoSetGame whenever we
            //          refocus, however this unfortunently causes an undesirable flickering effect. Therefore use unlinked/manual controllers at your own risk.
            if (currentFocus != currentLinkedProcess)
            {
                // Is the new process another linked process
                if (Settings.processControllers.ContainsKey(currentFocus))
                {
                    Console.WriteLine(pre + "Switched focus to linked process: {0}", currentFocus);

                    if (!String.IsNullOrWhiteSpace(currentLinkedProcess) && activeControllers.ContainsKey(currentLinkedProcess) && Settings.processControllers[currentLinkedProcess].closeOnProfileSwitch)
                    {
                        KillController(currentLinkedProcess);
                    }

                    StartController(currentFocus);

                    // If we should AutoSetGame, do it now
                    if (!String.IsNullOrWhiteSpace(Settings.processControllers[currentFocus].autoSetGame))
                    {
                        StateTracking.SetGame(Settings.processControllers[currentFocus].autoSetGame);
                    }

                    // If we should enable LockSetGame
                    if (!String.IsNullOrWhiteSpace(Settings.processControllers[currentFocus].lockSetGame))
                    {
                        StateTracking.LockGame(Settings.processControllers[currentFocus].lockSetGame, true);
                    }

                    currentLinkedProcess = currentFocus;
                }
                // Switched to an unlinked process
                else
                {
                    // Nothing to do here... wait... Default controllers are AIDS!!
                }
            }
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            Console.WriteLine(pre + "Starting up iCUE (unofficial) Game Integration");

            // If any required files are missing, alert the user of which ones and terminate the application
            if (!CheckRequiredFiles())
            {
                Console.WriteLine(pre + "Missing Files or Privilege, press any key to exit...");
                Console.ReadKey();
                return;
            }

            // Setup logic for handling of closing the window
            exitHandler += new EventHandler(OnAppExit);
            SetConsoleCtrlHandler(exitHandler, true);

            // Load the settings file to the static fields of Settings.cs
            Settings.LoadSettings();

            // Start all of the threads responsible for the program:
            // - linkCheck keeps track of currently open processes, used for linking controllers to processes
            // - pipeServer establishes a connection to the CgSDK Handler program which interacts with CgSDK and by extension iCUE
            // - httpServer handles http requests made by controllers (or the user) to control profiles
            isRunning = true;

            Thread linkCheck = new Thread(new ThreadStart(Linker.Run));

            linkCheck.Start();

            Thread pipeServer = new Thread(new ThreadStart(PipeServer.Run));

            pipeServer.Start();

            Thread httpServer = new Thread(new ThreadStart(Server.Run));

            httpServer.Start();

            StateTracking.SetGame("iCUE");
        }
        public static void Run()
        {
            // Connect to iCUE using CgSDK -- Now done via the pipe server
            //StateTracking.SetupCgSDK();

            // Setup and start the listener, add more prefixes for multiple access points
            HttpListener listener = new HttpListener();
            string       prefix   = string.Format("http://{0}:{1}/", boundIP, port);

            listener.Prefixes.Add(prefix);
            listener.Start();

            Console.WriteLine(pre + "HTTP Server listening to {0}", prefix);

            // Core processing loop for HTTP Requests
            while (Program.isRunning)
            {
                try
                {
                    HttpListenerContext  context  = listener.GetContext();
                    HttpListenerRequest  request  = context.Request;
                    HttpListenerResponse response = context.Response;

                    // Process Request
                    //ShowRequestProperties(request);

                    // Extract information from url
                    Dictionary <string, string> parameters = new Dictionary <string, string>();
                    List <string> suburls = new List <string>();

                    foreach (string key in request.QueryString.AllKeys)
                    {
                        parameters.Add(key, request.QueryString.Get(key));
                    }

                    // Splitting the url up by '/' characters
                    Regex           rx      = new Regex(@"(?:\/([^\/^\?]+))");
                    MatchCollection matches = rx.Matches(request.RawUrl);
                    foreach (Match match in matches)
                    {
                        GroupCollection groups = match.Groups;
                        suburls.Add(groups[1].Value);
                    }

                    // Logic for handling the request
                    string responseString = ProcessRequest(suburls, parameters);

                    // Send the appropriate response
                    byte[] buffer = Encoding.UTF8.GetBytes(responseString);

                    response.ContentLength64 = buffer.Length;
                    System.IO.Stream output = response.OutputStream;
                    output.Write(buffer, 0, buffer.Length);

                    output.Close();
                }
                catch (HttpListenerException e)
                {
                    // Do f**k all, we don't really care, but it probably will break the program
                }
            }

            listener.Stop();

            StateTracking.ReleaseControl();
            Console.WriteLine(pre + "Disconnecting from iCUE");
        }
        static string HandleICue(Dictionary <string, string> paramaters)
        {
            switch (paramaters["func"].ToLower())
            {
            case "getgame":
                if (StateTracking.Games.Keys.Count > 0 && !String.IsNullOrWhiteSpace(StateTracking.CurrentGame))
                {
                    string gameName = (paramaters.ContainsKey("game")) ? paramaters["game"] : StateTracking.CurrentGame;
                    if (StateTracking.Games.ContainsKey(gameName))
                    {
                        return(JsonConvert.SerializeObject(StateTracking.Games[gameName], Formatting.Indented));
                    }
                }
                break;

            case "getallgames":
                if (StateTracking.Games.Keys.Count > 0)
                {
                    return(JsonConvert.SerializeObject(StateTracking.Games, Formatting.Indented));
                }
                break;

            case "setgame":
                if (paramaters.ContainsKey("game"))
                {
                    if (StateTracking.SetGame(paramaters["game"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "reset":
                if (paramaters.ContainsKey("game"))
                {
                    if (StateTracking.ResetGame(paramaters["game"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "lock":
                if (paramaters.ContainsKey("game"))
                {
                    if (StateTracking.LockGame(paramaters["game"], true))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "unlock":
                if (paramaters.ContainsKey("game"))
                {
                    if (StateTracking.LockGame(paramaters["game"], false))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "setstate":
                if (paramaters.ContainsKey("game") && paramaters.ContainsKey("state"))
                {
                    if (StateTracking.SetState(paramaters["game"], paramaters["state"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "clearstate":
                if (paramaters.ContainsKey("game") && paramaters.ContainsKey("state"))
                {
                    if (StateTracking.ClearState(paramaters["game"], paramaters["state"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "clearallstates":
                if (paramaters.ContainsKey("game"))
                {
                    if (StateTracking.ClearAllStates(paramaters["game"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "setevent":
                if (paramaters.ContainsKey("game") && paramaters.ContainsKey("event"))
                {
                    if (StateTracking.SetEvent(paramaters["game"], paramaters["event"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            case "clearallevents":
                if (paramaters.ContainsKey("game"))
                {
                    if (StateTracking.ClearAllEvents(paramaters["game"]))
                    {
                        return(StateTracking.ErrorToString(0));
                    }
                    else
                    {
                        return(StateTracking.GetLastErrorString());
                    }
                }
                break;

            default:
                // No function provided
                Console.WriteLine(pre + "Error - No valid function provided, requested funtion ({0})", paramaters["func"].ToLower());
                return(StateTracking.ErrorToString(5));
            }

            return("");
        }