From e6183e29f7d0482ebc26576b124d7363b38b5b5b Mon Sep 17 00:00:00 2001 From: Brian Lima Date: Tue, 14 Nov 2017 11:53:05 -0200 Subject: [PATCH] Storing and retrieving the list of configs --- UWPHook/App.xaml.cs | 6 ----- UWPHook/EventsHook.cs | 6 ++++- UWPHook/GamesWindow.xaml.cs | 46 ++++++++++++++++++++++++++++++++- UWPHook/KeyboardToController.cs | 4 +-- UWPHook/UWPHook.csproj | 3 +++ UWPHook/packages.config | 1 + 6 files changed, 56 insertions(+), 10 deletions(-) diff --git a/UWPHook/App.xaml.cs b/UWPHook/App.xaml.cs index 7481560..de67503 100644 --- a/UWPHook/App.xaml.cs +++ b/UWPHook/App.xaml.cs @@ -9,16 +9,10 @@ namespace UWPHook public partial class App : Application { public static TrayIcon icon; - public static EventsHook eventsHook; private void Application_Startup(object sender, StartupEventArgs e) { icon = new TrayIcon(); - - eventsHook = new EventsHook(); - - eventsHook.StartHooking(); - } } diff --git a/UWPHook/EventsHook.cs b/UWPHook/EventsHook.cs index 54c2f04..4e918aa 100644 --- a/UWPHook/EventsHook.cs +++ b/UWPHook/EventsHook.cs @@ -15,6 +15,11 @@ namespace UWPHook private byte[] _outputReport = new byte[8]; KeyboardToController keyboardToController; + public EventsHook(KeyboardToController _keyboardToController) + { + keyboardToController = _keyboardToController; + } + public void StartHooking() { KeyboardWatcher.Start(); @@ -36,7 +41,6 @@ namespace UWPHook throw; } - } private void MouseWatcher_OnMouseInput(object sender, MouseEventArgs e) diff --git a/UWPHook/GamesWindow.xaml.cs b/UWPHook/GamesWindow.xaml.cs index 873cdbe..91e48e8 100644 --- a/UWPHook/GamesWindow.xaml.cs +++ b/UWPHook/GamesWindow.xaml.cs @@ -1,4 +1,6 @@ -using SharpSteam; +using Newtonsoft.Json; +using ScpDriverInterface; +using SharpSteam; using System; using System.Collections.Generic; using System.ComponentModel; @@ -19,6 +21,8 @@ namespace UWPHook { AppEntryModel Apps; BackgroundWorker bwrLoad, bwrSave; + EventsHook hook; + List listJoystick; public GamesWindow() { @@ -47,6 +51,41 @@ namespace UWPHook this.Title = "UWPHook: Streaming a game"; this.label.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 + KeyboardToController Joystick = null; + + if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json")) + { + File.Create(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json"); + this.listJoystick = new List(); + //TODO: Launch joystick setup for this game + } + else + { + this.listJoystick = JsonConvert.DeserializeObject>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json")); + //Try to load the config for this game + foreach (var item in listJoystick) + { + if (item.Game == Environment.GetCommandLineArgs()[1]) + { + Joystick = item; + break; + } + } + //Joystick = (KeyboardToController)(listJoystick.q(x => x.Game == "X"/*Environment.GetCommandLineArgs()[1]*/)[0]); + } + + 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); } @@ -89,6 +128,11 @@ namespace UWPHook 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(); diff --git a/UWPHook/KeyboardToController.cs b/UWPHook/KeyboardToController.cs index d326a6c..0c72843 100644 --- a/UWPHook/KeyboardToController.cs +++ b/UWPHook/KeyboardToController.cs @@ -4,7 +4,7 @@ using ScpDriverInterface; namespace UWPHook { - class KeyboardToController + public class KeyboardToController { private string _game; @@ -23,7 +23,7 @@ namespace UWPHook } } - class KeyToXboxButton + public class KeyToXboxButton { private string _key; diff --git a/UWPHook/UWPHook.csproj b/UWPHook/UWPHook.csproj index f44e51c..61ec121 100644 --- a/UWPHook/UWPHook.csproj +++ b/UWPHook/UWPHook.csproj @@ -69,6 +69,9 @@ ..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + ..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll diff --git a/UWPHook/packages.config b/UWPHook/packages.config index 6abe2ae..e3752b8 100644 --- a/UWPHook/packages.config +++ b/UWPHook/packages.config @@ -4,6 +4,7 @@ + \ No newline at end of file