Esempio n. 1
0
        public void Launcher()
        {
            //So, for some reason, Steam is now stopping in-home streaming if the launched app is minimized, so not hiding UWPHook's window is doing the trick for now
            if (Properties.Settings.Default.StreamMode)
            {
                this.Show();
                this.WindowStyle         = WindowStyle.None;
                this.WindowState         = WindowState.Maximized;
                this.Title               = "UWPHook: Streaming a game";
                this.labelStatus.Content = "UWPHook is streaming your game, fasten your seatbelts.";

                //The user is trying to Stream his game probably, so let's start to emulate his controller
                //Steam's in-home streaming treats UWPHook with it's "Desktop mode" config, causing all types of
                //Weird conflicts, every time a button on the remote computer's controller is pressed, the client
                //Receives a keyboard button instead. This should be a good approach
                KeyboardToController Joystick = null;

                if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json"))
                {
                    File.Create(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json");
                    this.listJoystick = new List <KeyboardToController>();
                    //TODO: Launch joystick setup for this game
                }
                else
                {
                    this.listJoystick = JsonConvert.DeserializeObject <List <KeyboardToController> >(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json"));
                    //Try to load the config for this game
                    Joystick = listJoystick.FirstOrDefault(x => x.Game == "X" /*Environment.GetCommandLineArgs()[1]*/);
                }

                var json = JsonConvert.SerializeObject(listJoystick);
                File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json", json);


                if (Joystick == null)
                {
                    //TODO: Launch joystick setup for this game
                }

                hook = new EventsHook(Joystick);
                hook.StartHooking();

                Thread.Sleep(10000);
            }
            else
            {
                this.Title = "UWPHook: Playing a game";
                this.Hide();
            }

            //Hide the window so the app is launched seamless making UWPHook run in the background without bothering the user
            string currentLanguage = CultureInfo.CurrentCulture.ToString();

            try
            {
                //Some apps have their language locked to the UI language of the system, so overriding it might change the language of the game
                //I my self couldn't get this to work on neither Forza Horizon 3 or Halo 5 Forge, @AbGedreht reported it works tho
                if (Properties.Settings.Default.ChangeLanguage && !String.IsNullOrEmpty(Properties.Settings.Default.TargetLanguage))
                {
                    ScriptManager.RunScript("Set-WinUILanguageOverride " + Properties.Settings.Default.TargetLanguage);
                }

                //The only other parameter Steam will send is the app AUMID
                AppManager.LaunchUWPApp(Environment.GetCommandLineArgs()[1]);

                //While the current launched app is running, sleep for n seconds and then check again
                while (AppManager.IsRunning())
                {
                    Thread.Sleep(Properties.Settings.Default.Seconds * 1000);
                }
            }
            catch (Exception e)
            {
                this.Show();
                MessageBox.Show(e.Message, "UWPHook", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            finally
            {
                if (Properties.Settings.Default.ChangeLanguage && !String.IsNullOrEmpty(Properties.Settings.Default.TargetLanguage))
                {
                    ScriptManager.RunScript("Set - WinUILanguageOverride " + currentLanguage);
                }

                if (Properties.Settings.Default.StreamMode)
                {
                    hook.StopHooking();
                }

                //The user has probably finished using the app, so let's close UWPHook to keep the experience clean
                this.Close();
                App.icon.Close();
            }
        }
Esempio n. 2
0
 public EventsHook(KeyboardToController _keyboardToController)
 {
     keyboardToController = _keyboardToController;
 }