diff --git a/LauncherSettings.cs b/LauncherSettings.cs index 78ca355..4982928 100644 --- a/LauncherSettings.cs +++ b/LauncherSettings.cs @@ -12,20 +12,12 @@ namespace WACCALauncher [JsonObject] public class LauncherSettings { - [JsonProperty] - public string DefaultProfile { get; set; } = string.Empty; - - [JsonProperty] - public bool UseWatchdog { get; set; } = true; - - [JsonProperty] - public LauncherTheme Theme { get; set; } = LauncherTheme.Dark; - - [JsonProperty] - public bool StrictMode { get; set; } = true; - - [JsonProperty] - public string ProfileDir { get; set; } = "_profiles"; + [JsonProperty] public string DefaultProfile { get; set; } = string.Empty; + [JsonProperty] public bool UseWatchdog { get; set; } = true; + [JsonProperty] public LauncherTheme Theme { get; set; } = LauncherTheme.Dark; + [JsonProperty] public bool StrictMode { get; set; } = true; + [JsonProperty] public string ProfileDir { get; set; } = "_profiles"; + [JsonProperty] public bool DisableIO4 { get; set; } = false; public static LauncherSettings Load() { diff --git a/MainForm.cs b/MainForm.cs index ec2f08b..d729196 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -6,6 +6,7 @@ using System.Text; using System.Windows.Forms; using System.Timers; using System.Diagnostics; +using LilyConsole; using SharpDX.DirectInput; using Newtonsoft.Json; @@ -37,8 +38,13 @@ namespace WACCALauncher private static Label _versionLabel = new Label(); private static Label _buttonLabel = new Label(); + // legacy SharpInput IO4 private readonly DirectInput _input = new DirectInput(); private Joystick _ioBoard; + + // LilyConsole hardware control + private readonly LightController _consoleLights = new LightController(); + private readonly IO4Controller _io4 = new IO4Controller(); public static readonly List Profiles = new List(); public static Profile DefaultProfile; @@ -132,67 +138,85 @@ namespace WACCALauncher return joystick.GetCurrentState().Buttons[button]; } + private bool ButtonsHeld(Joystick joystick, int[] buttons) + { + var state = joystick.GetCurrentState(); + + foreach (var button in buttons) + { + if (!state.Buttons[button]) return false; + } + + return true; + } + private void Tick(object sender, EventArgs e) { UpdateLoadingText(); - if (_state != LauncherState.Launching && _state != LauncherState.InMenu) return; - - var gamepads = _input.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); - - // set up IO board controls - if (_ioBoard == null && gamepads.Count > 0) + // set up IO board controls if enabled + if (!settings.DisableIO4) { - // it will be the only gamepad on the system - var guid = gamepads[0].InstanceGuid; - _ioBoard = new Joystick(_input, guid); - _ioBoard.Properties.BufferSize = 128; - _ioBoard.Acquire(); - } - else if (gamepads.Count > 0) - { - _ioBoard.Poll(); - var padStates = _ioBoard.GetBufferedData(); - - foreach (var padState in padStates) + if (_ioBoard == null) { - if(padState.Offset >= JoystickOffset.Buttons0 - && padState.Offset < JoystickOffset.Buttons10) - { - var pressed = padState.Value > 0; - - switch (_state) - { - case LauncherState.InMenu: - // vol down - if (ButtonPressed(padState, 0)) _menuManager.CursorDown(); - - // vol up - if (ButtonPressed(padState, 1)) _menuManager.CursorUp(); - - // service - if (ButtonPressed(padState, 6)) _menuManager.CursorDown(); - - // test - if (ButtonPressed(padState, 9)) _menuManager.MenuSelect(); - - break; - case LauncherState.Launching: - // vol up (held) - _skipUpdater = ButtonHeld(_ioBoard, 1); - - // test - if (ButtonPressed(padState, 9)) MenuShow(); - - break; - case LauncherState.Error: - // test - if (ButtonPressed(padState, 9)) Application.Exit(); - - break; - } - } + var gamepads = _input.GetDevices(DeviceClass.GameControl, DeviceEnumerationFlags.AttachedOnly); + + // it will be the only gamepad on the system + var guid = gamepads[0].InstanceGuid; + _ioBoard = new Joystick(_input, guid); + _ioBoard.Properties.BufferSize = 128; + _ioBoard.Acquire(); } + else + { + // TODO: make this behave safer + _ioBoard.Poll(); + var padStates = _ioBoard.GetBufferedData(); + + foreach (var padState in padStates) + { + if(padState.Offset >= JoystickOffset.Buttons0 + && padState.Offset < JoystickOffset.Buttons10) + { + var pressed = padState.Value > 0; + + switch (_state) + { + case LauncherState.InMenu: + // vol down + if (ButtonPressed(padState, 0)) _menuManager.CursorDown(); + + // vol up + if (ButtonPressed(padState, 1)) _menuManager.CursorUp(); + + // service + if (ButtonPressed(padState, 6)) _menuManager.CursorDown(); + + // test + if (ButtonPressed(padState, 9)) _menuManager.MenuSelect(); + + break; + case LauncherState.Launching: + // vol up (held) + _skipUpdater = ButtonHeld(_ioBoard, 1); + + // test + if (ButtonPressed(padState, 9)) MenuShow(); + + break; + case LauncherState.Error: + // test + if (ButtonPressed(padState, 9)) Application.Exit(); + + break; + case LauncherState.GameRunning: + if (ButtonsHeld(_ioBoard,new[] {0, 1, 6, 9})) _gameProcess.Kill(); + + break; + } + } + } + } } } @@ -485,7 +509,7 @@ namespace WACCALauncher var updater = new Process(); updater.StartInfo.FileName = profile.UpdaterPath; - updater.StartInfo.WorkingDirectory = Path.GetDirectoryName(profile.UpdaterPath).ToString(); + updater.StartInfo.WorkingDirectory = Path.GetDirectoryName(profile.UpdaterPath) ?? ""; updater.StartInfo.Arguments = profile.UpdaterArgs; updater.Start(); @@ -579,7 +603,7 @@ namespace WACCALauncher Invoke(new Action(() => _state = LauncherState.GameClosed)); // it will stay open if we don't close it - KillAMDaemon(); + _amdaemonProcess.Kill(); if (settings.UseWatchdog) { @@ -643,9 +667,10 @@ namespace WACCALauncher // select profile for OTL launch public void SelectProfile(Profile profile) { + SelectedProfile = profile; MenuHide(); StopTimer(); - SelectedProfile = profile; + LaunchGame(SelectedProfile); } diff --git a/MenuManager.cs b/MenuManager.cs index 0fa1379..fe9c1c7 100644 --- a/MenuManager.cs +++ b/MenuManager.cs @@ -25,7 +25,6 @@ namespace WACCALauncher var idx = ((_list.SelectedIndex - 1) + _list.Items.Count) % _list.Items.Count; _list.SelectedIndex = idx; if (_list.Items[idx] is MenuSeparator) CursorUp(); - _list.Invalidate(); } public void CursorDown() @@ -34,7 +33,6 @@ namespace WACCALauncher var idx = (_list.SelectedIndex + 1) % _list.Items.Count; _list.SelectedIndex = idx; if (_list.Items[idx] is MenuSeparator) CursorDown(); - _list.Invalidate(); } public void MenuBack() diff --git a/Profile.cs b/Profile.cs index d30aa96..29d0386 100644 --- a/Profile.cs +++ b/Profile.cs @@ -40,6 +40,12 @@ namespace WACCALauncher [JsonProperty] public string UpdaterArgs; + [JsonProperty] + public string ConsoleColor; + + [JsonProperty] + public string PanelColor; + public DirectoryInfo GetBaseDir() { return new DirectoryInfo(BasePath); diff --git a/WACCALauncher.csproj b/WACCALauncher.csproj index b7210b4..2de8061 100644 --- a/WACCALauncher.csproj +++ b/WACCALauncher.csproj @@ -41,6 +41,9 @@ Resources\Dark.ico + + packages\HidSharp.2.6.4\lib\net35\HidSharp.dll + packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll @@ -50,6 +53,9 @@ packages\SharpDX.DirectInput.4.2.0\lib\net45\SharpDX.DirectInput.dll + + lib\LilyConsole.dll + diff --git a/packages.config b/packages.config index b3b7f92..c264464 100644 --- a/packages.config +++ b/packages.config @@ -1,5 +1,6 @@  +