From fea87ef301e55428609976eb6386a52811a4272b Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Mon, 10 Oct 2022 16:09:58 +0200 Subject: [PATCH] removing cheat manager well, that was funny but it was also a terrible use of CPU ressources. --- HandheldCompanion/Managers/CheatManager.cs | 119 ------------------ .../Views/Pages/OverlayPage.xaml | 2 +- .../Views/Pages/OverlayPage.xaml.cs | 8 -- .../Views/Windows/MainWindow.xaml.cs | 15 --- 4 files changed, 1 insertion(+), 143 deletions(-) delete mode 100644 HandheldCompanion/Managers/CheatManager.cs diff --git a/HandheldCompanion/Managers/CheatManager.cs b/HandheldCompanion/Managers/CheatManager.cs deleted file mode 100644 index 6a69506bd..000000000 --- a/HandheldCompanion/Managers/CheatManager.cs +++ /dev/null @@ -1,119 +0,0 @@ -using ControllerCommon; -using ControllerCommon.Managers; -using SharpDX.XInput; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace HandheldCompanion.Managers -{ - public class CheatManager : Manager - { - // Gamepad vars - private MultimediaTimer UpdateTimer; - private ControllerEx controllerEx; - private Gamepad Gamepad; - private Gamepad prevGamepad; - private State GamepadState; - - public event CheatedEventHandler Cheated; - public delegate void CheatedEventHandler(string cheat); - - public CheatManager() : base() - { - // initialize timers - UpdateTimer = new MultimediaTimer(10); - } - - public override void Start() - { - UpdateTimer.Tick += UpdateReport; - UpdateTimer.Start(); - - base.Start(); - } - - public override void Stop() - { - if (!IsInitialized) - return; - - UpdateTimer.Tick -= UpdateReport; - UpdateTimer.Stop(); - - base.Stop(); - } - - public void UpdateController(ControllerEx controllerEx) - { - this.controllerEx = controllerEx; - } - - private List inputs = new() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - private int inputs_idx = 0; - - private static List listened = new() - { - GamepadButtonFlags.DPadLeft, - GamepadButtonFlags.DPadUp, - GamepadButtonFlags.DPadDown, - GamepadButtonFlags.DPadRight, - GamepadButtonFlags.A, - GamepadButtonFlags.B, - GamepadButtonFlags.X, - GamepadButtonFlags.Y - }; - - private static Dictionary, string> cheats = new Dictionary, string>() - { - // Konami code - { new List() { - GamepadButtonFlags.DPadUp, GamepadButtonFlags.DPadUp, - GamepadButtonFlags.DPadDown, GamepadButtonFlags.DPadDown, - GamepadButtonFlags.DPadLeft, GamepadButtonFlags.DPadLeft, - GamepadButtonFlags.DPadRight, GamepadButtonFlags.DPadRight, - GamepadButtonFlags.B, GamepadButtonFlags.A - }, "OverlayControllerFisherPrice" } - }; - - private void UpdateReport(object? sender, EventArgs e) - { - // get current gamepad state - if (controllerEx != null && controllerEx.IsConnected()) - { - GamepadState = controllerEx.GetState(); - Gamepad = GamepadState.Gamepad; - } - - if (prevGamepad.Equals(Gamepad)) - return; - else - prevGamepad = Gamepad; - - foreach (var button in listened) - { - if (Gamepad.Buttons.HasFlag(button)) - { - inputs[inputs_idx] = button; - - if (inputs_idx < inputs.Count - 1) - inputs_idx++; - else - inputs_idx = 0; - } - } - - foreach (var cheat in cheats) - { - if (cheat.Key.OrderBy(a => a).SequenceEqual(inputs.OrderBy(b => b))) - { - Properties.Settings.Default[cheat.Value] = true; - inputs = new() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // reset - - controllerEx?.Identify(); - Cheated?.Invoke(cheat.Value); - } - } - } - } -} diff --git a/HandheldCompanion/Views/Pages/OverlayPage.xaml b/HandheldCompanion/Views/Pages/OverlayPage.xaml index 2053c4b4d..84ff55c64 100644 --- a/HandheldCompanion/Views/Pages/OverlayPage.xaml +++ b/HandheldCompanion/Views/Pages/OverlayPage.xaml @@ -95,7 +95,7 @@ - + diff --git a/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs b/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs index 43a0ad180..3711cada5 100644 --- a/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs +++ b/HandheldCompanion/Views/Pages/OverlayPage.xaml.cs @@ -89,14 +89,6 @@ public void Page_Closed() { } - public void UnlockToyController() - { - this.Dispatcher.Invoke(() => - { - ToyControllerRadio.IsEnabled = true; - }); - } - private void UpdateUI_TrackpadsPosition(int trackpadsAlignment) { foreach (Button button in OverlayTrackpadsAlignment.Children) diff --git a/HandheldCompanion/Views/Windows/MainWindow.xaml.cs b/HandheldCompanion/Views/Windows/MainWindow.xaml.cs index aee1a79e2..99538a0e6 100644 --- a/HandheldCompanion/Views/Windows/MainWindow.xaml.cs +++ b/HandheldCompanion/Views/Windows/MainWindow.xaml.cs @@ -67,7 +67,6 @@ public partial class MainWindow : Window public static ServiceManager serviceManager; public static ProfileManager profileManager; public static TaskManager taskManager; - public static CheatManager cheatManager; public static PowerManager powerManager; public static UpdateManager updateManager; @@ -244,7 +243,6 @@ private void loadPages() }; controllerPage.ControllerChanged += (Controller) => { - cheatManager.UpdateController(Controller); // update me InputsManager.UpdateController(Controller); }; @@ -279,7 +277,6 @@ private void loadManagers() profileManager = new(); serviceManager = new ServiceManager("ControllerService", Properties.Resources.ServiceName, Properties.Resources.ServiceDescription); taskManager = new TaskManager("HandheldCompanion", CurrentExe); - cheatManager = new(); powerManager = new(); updateManager = new(); @@ -289,7 +286,6 @@ private void loadManagers() _managers.Add(profileManager); _managers.Add(serviceManager); _managers.Add(taskManager); - _managers.Add(cheatManager); _managers.Add(powerManager); _managers.Add(updateManager); @@ -319,16 +315,6 @@ private void loadManagers() _ = Dialog.ShowAsync($"{Properties.Resources.MainWindow_ServiceManager}", $"{Properties.Resources.MainWindow_ServiceManagerStopIssue}", ContentDialogButton.Primary, null, $"{Properties.Resources.MainWindow_OK}"); }; - cheatManager.Cheated += (cheat) => - { - switch (cheat) - { - case "OverlayControllerFisherPrice": - overlayPage?.UnlockToyController(); - break; - } - }; - SystemManager.SerialArrived += SystemManager_Updated; SystemManager.SerialRemoved += SystemManager_Updated; @@ -619,7 +605,6 @@ private void Window_Closed(object sender, EventArgs e) if (pipeClient.connected) pipeClient.Close(); - cheatManager.Stop(); InputsManager.Stop(); SystemManager.Stop();