private async void OnShowKeybindDialog(ControllerButton Button) { var bindName = ControllerManager.GetActiveController().Type == ControllerType.DualShock4 ? ControllerData.DS4.ButtonNames[Button] : ControllerData.Xbox.ButtonNames[Button]; _bindDialog = await this.ShowProgressAsync(Properties.Resources.DialogBindKeyTitle, string.Format(Properties.Resources.DialogBindKeyText, bindName), true); await Task.Run((Action) delegate { while (!_bindDialog.IsCanceled) { Thread.Sleep(1); Key?pressedKey = null; foreach (Key key in Enum.GetValues(typeof(Key))) { bool keyDown = false; Application.Current.Dispatcher.Invoke((Action) delegate { try { keyDown = Keyboard.IsKeyDown(key); } catch { } }); if (!keyDown) { continue; } pressedKey = key; break; } var cancel = false; if (!pressedKey.HasValue) { continue; } switch (pressedKey) { case Key.Escape: cancel = true; break; default: break; } if (cancel) { break; } BindingManager.SetKeybind(Button, pressedKey.Value); BindingManager.SaveKeybinds(); break; } }) ; await _bindDialog.CloseAsync(); }
private void MetroWindow_Closed(object sender, EventArgs e) { Keymapper.Stop(); ProcessWatcher.Stop(); HapticManager.Stop(); var aC = ControllerManager.GetActiveController(); aC?.SetLightbar(0, 0, 0); aC?.Stop(); ControllerManager.Stop(); _notifyIcon.Visible = false; _notifyIcon.Dispose(); WindowClosing?.Invoke(); }
private void RefreshControllerList() { listControllers.Items.Clear(); var currentControllers = ControllerManager.CurrentControllers; var activeController = ControllerManager.GetActiveController(); int activeIndex = -1; if (activeController != null) { activeIndex = currentControllers.IndexOf(activeController); } for (int i = 0; i < currentControllers.Count; i++) { BitmapImage displayImage = new BitmapImage(); displayImage.BeginInit(); switch (currentControllers[i].Type) { case ControllerType.DualShock4: displayImage.UriSource = new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/xbox-24.png"); break; default: displayImage = null; break; } displayImage.EndInit(); string Name = currentControllers[i].Type.ToString(); listControllers.Items.Add(new ControllerListItem() { DisplayImage = displayImage, ControllerName = Name, ControllerNumber = string.Format(Properties.Resources.ControllersControllerNumber, i + 1), DisplayID = currentControllers[i].ControllerID, ForeColor = Color.FromArgb(255, 123, 45, 142) }); } listControllers.SelectedIndex = activeIndex; buttonActivateController.IsEnabled = listControllers.SelectedItems.Count == 1 ? true : false; }
public void UpdateBindList() { Dispatcher.Invoke(() => { var selected = listKeybinds.SelectedIndex; listKeybinds.Items.Clear(); var activeController = ControllerManager.GetActiveController(); if (activeController != null) { var binds = BindingManager.GetKeybindList(activeController.Type); foreach (var bind in binds) { listKeybinds.Items.Add(bind); } if (selected < listKeybinds.Items.Count) { listKeybinds.SelectedIndex = selected; } } }); }
private void UpdateUI() { Height = _optionsFlyout.IsOpen ? Settings.Default.SettingsHeight : 350; // Check game status if (ProcessWatcher.GameRunning) { switch (ProcessWatcher.GameArchitecture) { case Enums.GameArchitecture.X86: textWoWStatus.Text = Properties.Resources.MainWindowWowRunning32; break; case Enums.GameArchitecture.X64: textWoWStatus.Text = Properties.Resources.MainWindowWoWRunning64; break; } if (Settings.Default.EnableAdvancedFeatures) { if (MemoryManager.Attached) { var gameState = MemoryManager.GetGameState(); switch (gameState) { case GameState.LoggedIn: var playerInfo = new PlayerInfo(); var success = MemoryManager.GetPlayerInfo(out playerInfo); if (success) { // Color accent by class color if (Settings.Default.AutoClassAccent) { var playerClass = MemoryManager.GetPlayerClass(); SetTheme(playerClass.ToString(), Settings.Default.AppTheme); } else { SetTheme(Settings.Default.AppAccent, Settings.Default.AppTheme); } textWoWStatus2.Text = $"{MemoryManager.GetPlayerName()} [{playerInfo.Level}]: {playerInfo.CurrentHealth}/{playerInfo.MaxHealth}"; } break; case GameState.LoggedOut: textWoWStatus2.Text = Properties.Resources.MainWindowWoWLoggedOut; SetTheme(Settings.Default.AppAccent, Settings.Default.AppTheme); break; case GameState.NotRunning: textWoWStatus2.Text = Properties.Resources.MainWindowWoWError; SetTheme(Settings.Default.AppAccent, Settings.Default.AppTheme); break; } } if (!OffsetManager.OffsetsAvailable) { textWoWStatus2.Text = @"Advanced features unavailable"; } } else { SetTheme(Settings.Default.AppAccent, Settings.Default.AppTheme); textWoWStatus2.Text = string.Empty; } } else { textWoWStatus.Text = Properties.Resources.MainWindowWoWNotRunning; textWoWStatus2.Text = String.Empty; SetTheme(Settings.Default.AppAccent, Settings.Default.AppTheme); } // Check controller status var actiCont = ControllerManager.GetActiveController(); if (actiCont != null) { textControllerStatus.Text = string.Format(Properties.Resources.MainWindowControllerConnected, actiCont.Type); switch (actiCont.ConnectionType) { case ControllerConnectionType.Bluetooth: imageConnectionType.Source = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/ConnectionIcons/UsbLight.png")); } else { imageConnectionType.Source = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Resources/ConnectionIcons/Wireless.png")); break; } switch (actiCont.BatteryState) { case ControllerBatteryState.None: textBatteryStatus.Text = string.Format(Properties.Resources.MainWindowBatteryConnected); break; case ControllerBatteryState.Charging: textBatteryStatus.Text = string.Format(Properties.Resources.MainWindowBatteryCharging, actiCont.Battery); break; case ControllerBatteryState.Discharging: textBatteryStatus.Text = string.Format(Properties.Resources.MainWindowBatteryDischarging, actiCont.Battery); break; case ControllerBatteryState.Full: textBatteryStatus.Text = string.Format(Properties.Resources.MainWindowBatteryConnected); break; default: break; } } else { textControllerStatus.Text = Properties.Resources.MainWindowControllerNotActive; imageConnectionType.Source = null; textBatteryStatus.Text = Properties.Resources.MainWindowControllerBatteryNotConnected; } }
private static void HapticThread() { var mouseLookTimer = 0; var wasMouseLooking = false; _playerHealthCurrent = int.MaxValue; _playerHealthMax = 0; while (true) { var setLightbar = false; var controller = ControllerManager.GetActiveController(); if (controller == null) { continue; } lock (controller) { var state = controller.GetControllerState(); // Color lightbar on low battery if (Settings.Default.EnableColorLightbarBatteryLow) { if (controller.Battery < Settings.Default.LightbarBatteryThreshold && controller.BatteryState == ControllerBatteryState.Discharging) { var color = Settings.Default.LightbarColorBatteryLow; controller.SetLightbar(color.R, color.G, color.B, 1000, 1000); setLightbar = true; } } // Read memory if enabled and update haptics if (Settings.Default.EnableAdvancedFeatures && MemoryManager.Attached && MemoryManager.GetGameState() == GameState.LoggedIn) { var updatedPlayerInfo = MemoryManager.UpdatePlayerData(); if (updatedPlayerInfo) { PlayerInfo playerInfo; var success = MemoryManager.GetPlayerInfo(out playerInfo); var targetGuid = MemoryManager.GetTargetGuid(); var mouseGuid = MemoryManager.GetMouseGuid(); float previousPercent = (float)_playerHealthCurrent / playerInfo.MaxHealth; float currentPercent = (float)playerInfo.CurrentHealth / playerInfo.MaxHealth; var healthDiff = previousPercent - currentPercent; // Vibrate when taking damage if (Settings.Default.EnableVibrateDamage && playerInfo?.CurrentHealth < _playerHealthCurrent && playerInfo.MaxHealth >= _playerHealthMax && playerInfo?.CurrentHealth > 0) { if (healthDiff <= 0.10f) { controller.SendRumble(0x60, 0x60, 250); } if (healthDiff <= 0.25f && healthDiff > 0.10f) { controller.SendRumble(0x90, 0x90, 400); } if (healthDiff <= 0.50f && healthDiff > 0.25f) { controller.SendRumble(0xB0, 0xB0, 650); } if (healthDiff <= 0.75f && healthDiff > 0.50f) { controller.SendRumble(0xD0, 0xD0, 950); } if (healthDiff <= 1.00f && healthDiff > 0.75f) { controller.SendRumble(0xFF, 0xFF, 1200); } } _playerHealthCurrent = (int)playerInfo.CurrentHealth; _playerHealthMax = (int)playerInfo.MaxHealth; // Vibrate when changing target if (Settings.Default.EnableVibrateTarget && targetGuid != null && !_targetGuid.SequenceEqual(targetGuid) && !targetGuid.SequenceEqual(new byte[16])) { controller.SendRumble(0, 255, 150); _targetGuid = targetGuid; } // Color lightbar by health if (Settings.Default.EnableLightbarHealth && !setLightbar) { var critColor = Settings.Default.LightbarHealthCritical; var lowColor = Settings.Default.LightbarHealthLow; var medColor = Settings.Default.LightbarHealthMedium; var highColor = Settings.Default.LightbarHealthHigh; // Color by health if (currentPercent <= 0.90) { if (currentPercent <= 0.20) { controller.SetLightbar(critColor.R, critColor.G, critColor.B); } if (currentPercent <= 0.50 && currentPercent > 0.20) { controller.SetLightbar(lowColor.R, lowColor.G, lowColor.B); } if (currentPercent <= 0.90 && currentPercent > 0.50) { controller.SetLightbar(medColor.R, medColor.G, medColor.B); } setLightbar = true; } // High health color if not class color if (currentPercent > 0.90f && !Settings.Default.EnableLightbarClass) { controller.SetLightbar(highColor.R, highColor.G, highColor.B); setLightbar = true; } } // Color lightbar by class if (Settings.Default.EnableLightbarClass && !setLightbar) { Color color = new Color(); try { color = GameInfo.RaidClassColors[MemoryManager.GetPlayerClass()]; } catch { } controller.SetLightbar(color.R, color.G, color.B); setLightbar = true; } // Auto-center cursor if (Settings.Default.MouselookCenterCursor) { var isMouseLooking = MemoryManager.GetMouselooking(); if (isMouseLooking && !wasMouseLooking) { if (mouseLookTimer > MouselookDelay) { wasMouseLooking = true; mouseLookTimer = 0; Console.WriteLine("Mouselook Set"); } else { mouseLookTimer += 1; } } else if (!isMouseLooking) { if (wasMouseLooking) { // Center cursor var winRect = ProcessWatcher.GameWindowRect; var cur = Cursor.Position; Console.WriteLine($"{cur.X}, {cur.Y}"); var winWidth = winRect.Right - winRect.Left; var winHeight = winRect.Bottom - winRect.Top; cur.X = winRect.Left + (winWidth / 2); cur.Y = winRect.Top + (winHeight / 2); Console.WriteLine($"{cur.X}, {cur.Y}"); Cursor.Position = cur; } wasMouseLooking = false; mouseLookTimer = 0; } } } } // Vibrate on trigger grip if (Settings.Default.EnableVibrateTriggerGrip && Settings.Default.EnableTriggerGrip) { if (state.TriggerLeft >= Settings.Default.ThresholdLeftClick && !_leftGrip) { controller.SendRumble(255, 255, 200); _leftGrip = true; } else if (state.TriggerLeft < Settings.Default.ThresholdLeftClick && _leftGrip) { _leftGrip = false; } if (state.TriggerRight >= Settings.Default.ThresholdRightClick && !_rightGrip) { controller.SendRumble(255, 255, 200); _rightGrip = true; } else if (state.TriggerRight < Settings.Default.ThresholdRightClick && _rightGrip) { _rightGrip = false; } } if (Settings.Default.EnableColorLightbar && !setLightbar) { var color = Settings.Default.LightbarColorDefault; controller.SetLightbar(color.R, color.G, color.B); setLightbar = true; } if (!setLightbar) { controller.SetLightbar(0, 0, 0); } } Thread.Sleep(10); } }
private static void ControllerThread() { while (true) { var controller = ControllerManager.GetActiveController(); if (controller != null) { lock (controller) { var state = controller.GetControllerState(); var cTouch = controller.GetTouchpadState(); // Process button inputs if (state.ShoulderLeft) { ProcessKeyDown(ControllerButton.ShoulderLeft); } if (!state.ShoulderLeft) { ProcessKeyUp(ControllerButton.ShoulderLeft); } if (state.ShoulderRight) { ProcessKeyDown(ControllerButton.ShoulderRight); } if (!state.ShoulderRight) { ProcessKeyUp(ControllerButton.ShoulderRight); } if (state.LFaceUp) { ProcessKeyDown(ControllerButton.LFaceUp); } if (!state.LFaceUp) { ProcessKeyUp(ControllerButton.LFaceUp); } if (state.LFaceRight) { ProcessKeyDown(ControllerButton.LFaceRight); } if (!state.LFaceRight) { ProcessKeyUp(ControllerButton.LFaceRight); } if (state.LFaceDown) { ProcessKeyDown(ControllerButton.LFaceDown); } if (!state.LFaceDown) { ProcessKeyUp(ControllerButton.LFaceDown); } if (state.LFaceLeft) { ProcessKeyDown(ControllerButton.LFaceLeft); } if (!state.LFaceLeft) { ProcessKeyUp(ControllerButton.LFaceLeft); } if (state.RFaceUp) { ProcessKeyDown(ControllerButton.RFaceUp); } if (!state.RFaceUp) { ProcessKeyUp(ControllerButton.RFaceUp); } if (state.RFaceRight) { ProcessKeyDown(ControllerButton.RFaceRight); } if (!state.RFaceRight) { ProcessKeyUp(ControllerButton.RFaceRight); } if (state.RFaceDown) { ProcessKeyDown(ControllerButton.RFaceDown); } if (!state.RFaceDown) { ProcessKeyUp(ControllerButton.RFaceDown); } if (state.RFaceLeft) { ProcessKeyDown(ControllerButton.RFaceLeft); } if (!state.RFaceLeft) { ProcessKeyUp(ControllerButton.RFaceLeft); } if (state.CenterLeft) { ProcessKeyDown(ControllerButton.CenterLeft); } if (!state.CenterLeft && !state.TouchButton) { ProcessKeyUp(ControllerButton.CenterLeft); } if (state.CenterRight) { ProcessKeyDown(ControllerButton.CenterRight); } if (!state.CenterRight && !state.TouchButton) { ProcessKeyUp(ControllerButton.CenterRight); } if (state.CenterMiddle) { ProcessKeyDown(ControllerButton.CenterMiddle); } if (!state.CenterMiddle) { ProcessKeyUp(ControllerButton.CenterMiddle); } if (state.StickLeft) { ProcessKeyDown(ControllerButton.StickLeft); } if (!state.StickLeft) { ProcessKeyUp(ControllerButton.StickLeft); } if (state.StickRight) { ProcessKeyDown(ControllerButton.StickRight); } if (!state.StickRight) { ProcessKeyUp(ControllerButton.StickRight); } switch (Settings.Default.TouchpadMode) { case 0: // Mouse control if (state.TouchLeft && state.TouchButton) { ProcessKeyDown(ControllerButton.TouchLeft); } if (!state.TouchButton) { ProcessKeyUp(ControllerButton.TouchLeft); } if (state.TouchRight && state.TouchButton) { ProcessKeyDown(ControllerButton.TouchRight); } if (!state.TouchButton) { ProcessKeyUp(ControllerButton.TouchRight); } break; case 1: // Share/options if (state.TouchLeft && state.TouchButton) { ProcessKeyDown(ControllerButton.CenterLeft); } if (!state.TouchButton && !state.CenterLeft) { ProcessKeyUp(ControllerButton.CenterLeft); } if (state.TouchRight && state.TouchButton) { ProcessKeyDown(ControllerButton.CenterRight); } if (!state.TouchButton && !state.CenterRight) { ProcessKeyUp(ControllerButton.CenterRight); } break; case 2: // TouchLeft/TouchRight if (state.TouchLeft && state.TouchButton) { ProcessKeyDown(ControllerButton.TouchLeft); } if (!state.TouchButton) { ProcessKeyUp(ControllerButton.TouchLeft); } if (state.TouchRight && state.TouchButton) { ProcessKeyDown(ControllerButton.TouchRight); } if (!state.TouchButton) { ProcessKeyUp(ControllerButton.TouchRight); } break; } if (Properties.Settings.Default.EnableTriggerGrip) { if ((state.TriggerLeft >= Properties.Settings.Default.ThresholdLeft) && (state.TriggerLeft < Properties.Settings.Default.ThresholdLeftClick)) { ProcessKeyDown(ControllerButton.TriggerLeft); } if (!(state.TriggerLeft >= Properties.Settings.Default.ThresholdLeft) || !(state.TriggerLeft < Properties.Settings.Default.ThresholdLeftClick)) { ProcessKeyUp(ControllerButton.TriggerLeft); } if ((state.TriggerRight >= Properties.Settings.Default.ThresholdRight) && (state.TriggerRight < Properties.Settings.Default.ThresholdRightClick)) { ProcessKeyDown(ControllerButton.TriggerRight); } if (!(state.TriggerRight >= Properties.Settings.Default.ThresholdRight) || !(state.TriggerRight < Properties.Settings.Default.ThresholdRightClick)) { ProcessKeyUp(ControllerButton.TriggerRight); } if (state.TriggerLeft >= Properties.Settings.Default.ThresholdLeftClick) { ProcessKeyDown(ControllerButton.TriggerLeft2); } if (state.TriggerRight >= Properties.Settings.Default.ThresholdRightClick) { ProcessKeyDown(ControllerButton.TriggerRight2); } if (state.TriggerLeft < Properties.Settings.Default.ThresholdLeftClick) { ProcessKeyUp(ControllerButton.TriggerLeft2); } if (state.TriggerRight < Properties.Settings.Default.ThresholdRightClick) { ProcessKeyUp(ControllerButton.TriggerRight2); } } else { if (state.TriggerLeft >= Properties.Settings.Default.ThresholdLeft) { ProcessKeyDown(ControllerButton.TriggerLeft); } if (!(state.TriggerLeft >= Properties.Settings.Default.ThresholdLeft)) { ProcessKeyUp(ControllerButton.TriggerLeft); } if (state.TriggerRight >= Properties.Settings.Default.ThresholdLeft) { ProcessKeyDown(ControllerButton.TriggerRight); } if (!(state.TriggerRight >= Properties.Settings.Default.ThresholdLeft)) { ProcessKeyUp(ControllerButton.TriggerRight); } } // Process analog sticks // Left stick/Movement if (state.LeftY < -40) { ProcessKeyDown(ControllerButton.LStickUp); } if (!(state.LeftY < -40)) { ProcessKeyUp(ControllerButton.LStickUp); } if (state.LeftY > 40) { ProcessKeyDown(ControllerButton.LStickDown); } if (!(state.LeftY > 40)) { ProcessKeyUp(ControllerButton.LStickDown); } if (state.LeftX < -40) { ProcessKeyDown(ControllerButton.LStickLeft); } if (!(state.LeftX < -40)) { ProcessKeyUp(ControllerButton.LStickLeft); } if (state.LeftX > 40) { ProcessKeyDown(ControllerButton.LStickRight); } if (!(state.LeftX > 40)) { ProcessKeyUp(ControllerButton.LStickRight); } // Right stick/Mouse Vector2 stickInput = new Vector2(state.RightX, state.RightY); if (stickInput.Magnitude > Settings.Default.RightDeadzone) { stickInput = Vector2.Normalize(stickInput) * ((stickInput.Magnitude - Settings.Default.RightDeadzone) / (127 - Settings.Default.RightDeadzone)); Vector2 mouseMovement = ApplyMouseMath((float)stickInput.X, (float)stickInput.Y); if (state.RightX < 0) { mouseMovement.X = -mouseMovement.X; } if (state.RightY < 0) { mouseMovement.Y = -mouseMovement.Y; } var modX = 1; var modY = 1; if (Settings.Default.EnableAdvancedFeatures) { // Invert cursor option var mouseLook = MemoryManager.GetMouselooking(); if (Settings.Default.InvertCameraHorizontal && mouseLook) { modX = modX * -1; } if (Settings.Default.InvertCameraVertical && mouseLook) { modY = modY * -1; } } var m = Cursor.Position; m.X += (int)mouseMovement.X * modX; m.Y += (int)mouseMovement.Y * modY; Cursor.Position = m; } // Touchpad if (Settings.Default.TouchpadMode == 0) { if (cTouch != null && (cTouch.TouchX != _lastTouchX || cTouch.TouchY != _lastTouchY)) { var m = Cursor.Position; m.X += cTouch.DeltaX; m.Y += cTouch.DeltaY; Cursor.Position = m; _lastTouchX = cTouch.TouchX; _lastTouchY = cTouch.TouchY; } } } } Thread.Sleep(5); } }