From a6872421454c59f51a5fa55a1411ef4f1c405ddf Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Tue, 7 Jun 2022 22:07:03 +0200 Subject: [PATCH] fix device disconnect --- Project64Savestater/MainForm.cs | 282 +++++++++++++++++--------------- 1 file changed, 148 insertions(+), 134 deletions(-) diff --git a/Project64Savestater/MainForm.cs b/Project64Savestater/MainForm.cs index a29a880..19135f8 100644 --- a/Project64Savestater/MainForm.cs +++ b/Project64Savestater/MainForm.cs @@ -80,169 +80,183 @@ namespace PJ64Savestater { var inputCodes = new List(); var state = new JoystickState(); - curPad.Poll(); - curPad.GetCurrentState(ref state); + bool success; - for (int i = 0, loopTo = state.Buttons.Length - 1; i <= loopTo; i++) + try { - if (state.Buttons[i]) - inputCodes.Add("Button " + i); + curPad.Poll(); + curPad.GetCurrentState(ref state); + success = true; + } + catch (SharpDX.SharpDXException) + { + success = false; } - for (int i = 0, loopTo1 = state.PointOfViewControllers.Length - 1; i <= loopTo1; i++) + if (success) { - int val = state.PointOfViewControllers[i]; - if (val > -1) - inputCodes.Add("Point " + i + " " + val); - } - for (int i = 0, loopTo2 = state.Sliders.Length - 1; i <= loopTo2; i++) - { - int val = state.Sliders[i]; - if (val > toleranceOffset) - inputCodes.Add("Slider " + i + " +"); - if (val < -toleranceOffset) - inputCodes.Add("Slider " + i + " -"); - } + for (int i = 0, loopTo = state.Buttons.Length - 1; i <= loopTo; i++) + { + if (state.Buttons[i]) + inputCodes.Add("Button " + i); + } - for (int i = 0, loopTo3 = state.AccelerationSliders.Length - 1; i <= loopTo3; i++) - { - int val = state.AccelerationSliders[i]; - if (val > toleranceOffset) - inputCodes.Add("ASlider " + i + " +"); - if (val < -toleranceOffset) - inputCodes.Add("ASlider " + i + " -"); - } + for (int i = 0, loopTo1 = state.PointOfViewControllers.Length - 1; i <= loopTo1; i++) + { + int val = state.PointOfViewControllers[i]; + if (val > -1) + inputCodes.Add("Point " + i + " " + val); + } - for (int i = 0, loopTo4 = state.ForceSliders.Length - 1; i <= loopTo4; i++) - { - int val = state.ForceSliders[i]; - if (val > toleranceOffset) - inputCodes.Add("FSlider " + i + " +"); - if (val < -toleranceOffset) - inputCodes.Add("FSlider " + i + " -"); - } + for (int i = 0, loopTo2 = state.Sliders.Length - 1; i <= loopTo2; i++) + { + int val = state.Sliders[i]; + if (val > toleranceOffset) + inputCodes.Add("Slider " + i + " +"); + if (val < -toleranceOffset) + inputCodes.Add("Slider " + i + " -"); + } - for (int i = 0, loopTo5 = state.VelocitySliders.Length - 1; i <= loopTo5; i++) - { - int val = state.VelocitySliders[i]; - if (val > toleranceOffset) - inputCodes.Add("VSlider " + i + " +"); - if (val < -toleranceOffset) - inputCodes.Add("VSlider " + i + " -"); - } + for (int i = 0, loopTo3 = state.AccelerationSliders.Length - 1; i <= loopTo3; i++) + { + int val = state.AccelerationSliders[i]; + if (val > toleranceOffset) + inputCodes.Add("ASlider " + i + " +"); + if (val < -toleranceOffset) + inputCodes.Add("ASlider " + i + " -"); + } - if (state.X > toleranceOffset) - inputCodes.Add("X +"); - if (state.X < -toleranceOffset) - inputCodes.Add("X -"); + for (int i = 0, loopTo4 = state.ForceSliders.Length - 1; i <= loopTo4; i++) + { + int val = state.ForceSliders[i]; + if (val > toleranceOffset) + inputCodes.Add("FSlider " + i + " +"); + if (val < -toleranceOffset) + inputCodes.Add("FSlider " + i + " -"); + } - if (state.Y > toleranceOffset) - inputCodes.Add("Y +"); - if (state.Y < -toleranceOffset) - inputCodes.Add("Y -"); + for (int i = 0, loopTo5 = state.VelocitySliders.Length - 1; i <= loopTo5; i++) + { + int val = state.VelocitySliders[i]; + if (val > toleranceOffset) + inputCodes.Add("VSlider " + i + " +"); + if (val < -toleranceOffset) + inputCodes.Add("VSlider " + i + " -"); + } - if (state.Z > toleranceOffset) - inputCodes.Add("Z +"); - if (state.Z < -toleranceOffset) - inputCodes.Add("Z -"); + if (state.X > toleranceOffset) + inputCodes.Add("X +"); + if (state.X < -toleranceOffset) + inputCodes.Add("X -"); - if (state.AccelerationX > toleranceOffset) - inputCodes.Add("AX +"); - if (state.AccelerationX < -toleranceOffset) - inputCodes.Add("AX -"); + if (state.Y > toleranceOffset) + inputCodes.Add("Y +"); + if (state.Y < -toleranceOffset) + inputCodes.Add("Y -"); - if (state.AccelerationY > toleranceOffset) - inputCodes.Add("AY +"); - if (state.AccelerationY < -toleranceOffset) - inputCodes.Add("AY -"); + if (state.Z > toleranceOffset) + inputCodes.Add("Z +"); + if (state.Z < -toleranceOffset) + inputCodes.Add("Z -"); - if (state.AccelerationZ > toleranceOffset) - inputCodes.Add("AZ +"); - if (state.AccelerationZ < -toleranceOffset) - inputCodes.Add("AZ -"); + if (state.AccelerationX > toleranceOffset) + inputCodes.Add("AX +"); + if (state.AccelerationX < -toleranceOffset) + inputCodes.Add("AX -"); - if (state.AngularAccelerationX > toleranceOffset) - inputCodes.Add("AAX +"); - if (state.AngularAccelerationX < -toleranceOffset) - inputCodes.Add("AAX -"); + if (state.AccelerationY > toleranceOffset) + inputCodes.Add("AY +"); + if (state.AccelerationY < -toleranceOffset) + inputCodes.Add("AY -"); - if (state.AngularAccelerationY > toleranceOffset) - inputCodes.Add("AAY +"); - if (state.AngularAccelerationY < -toleranceOffset) - inputCodes.Add("AAY -"); + if (state.AccelerationZ > toleranceOffset) + inputCodes.Add("AZ +"); + if (state.AccelerationZ < -toleranceOffset) + inputCodes.Add("AZ -"); - if (state.AngularAccelerationZ > toleranceOffset) - inputCodes.Add("AAZ +"); - if (state.AngularAccelerationZ < -toleranceOffset) - inputCodes.Add("AAZ -"); + if (state.AngularAccelerationX > toleranceOffset) + inputCodes.Add("AAX +"); + if (state.AngularAccelerationX < -toleranceOffset) + inputCodes.Add("AAX -"); - if (state.ForceX > toleranceOffset) - inputCodes.Add("FX +"); - if (state.ForceX < -toleranceOffset) - inputCodes.Add("FX -"); + if (state.AngularAccelerationY > toleranceOffset) + inputCodes.Add("AAY +"); + if (state.AngularAccelerationY < -toleranceOffset) + inputCodes.Add("AAY -"); - if (state.ForceY > toleranceOffset) - inputCodes.Add("FY +"); - if (state.ForceY < -toleranceOffset) - inputCodes.Add("FY -"); + if (state.AngularAccelerationZ > toleranceOffset) + inputCodes.Add("AAZ +"); + if (state.AngularAccelerationZ < -toleranceOffset) + inputCodes.Add("AAZ -"); - if (state.ForceZ > toleranceOffset) - inputCodes.Add("FZ +"); - if (state.ForceZ < -toleranceOffset) - inputCodes.Add("FZ -"); + if (state.ForceX > toleranceOffset) + inputCodes.Add("FX +"); + if (state.ForceX < -toleranceOffset) + inputCodes.Add("FX -"); - if (state.RotationX > toleranceOffset) - inputCodes.Add("RX +"); - if (state.RotationX < -toleranceOffset) - inputCodes.Add("RX -"); + if (state.ForceY > toleranceOffset) + inputCodes.Add("FY +"); + if (state.ForceY < -toleranceOffset) + inputCodes.Add("FY -"); - if (state.RotationY > toleranceOffset) - inputCodes.Add("RY +"); - if (state.RotationY < -toleranceOffset) - inputCodes.Add("RY -"); + if (state.ForceZ > toleranceOffset) + inputCodes.Add("FZ +"); + if (state.ForceZ < -toleranceOffset) + inputCodes.Add("FZ -"); - if (state.RotationZ > toleranceOffset) - inputCodes.Add("RZ +"); - if (state.RotationZ < -toleranceOffset) - inputCodes.Add("RZ -"); + if (state.RotationX > toleranceOffset) + inputCodes.Add("RX +"); + if (state.RotationX < -toleranceOffset) + inputCodes.Add("RX -"); - if (state.TorqueX > toleranceOffset) - inputCodes.Add("TX +"); - if (state.TorqueX < -toleranceOffset) - inputCodes.Add("TX -"); + if (state.RotationY > toleranceOffset) + inputCodes.Add("RY +"); + if (state.RotationY < -toleranceOffset) + inputCodes.Add("RY -"); - if (state.TorqueY > toleranceOffset) - inputCodes.Add("TY +"); - if (state.TorqueY < -toleranceOffset) - inputCodes.Add("TY -"); + if (state.RotationZ > toleranceOffset) + inputCodes.Add("RZ +"); + if (state.RotationZ < -toleranceOffset) + inputCodes.Add("RZ -"); - if (state.TorqueZ > toleranceOffset) - inputCodes.Add("TZ +"); - if (state.TorqueZ < -toleranceOffset) - inputCodes.Add("TZ -"); + if (state.TorqueX > toleranceOffset) + inputCodes.Add("TX +"); + if (state.TorqueX < -toleranceOffset) + inputCodes.Add("TX -"); - if (state.VelocityX > toleranceOffset) - inputCodes.Add("VX +"); - if (state.VelocityX < -toleranceOffset) - inputCodes.Add("VX -"); + if (state.TorqueY > toleranceOffset) + inputCodes.Add("TY +"); + if (state.TorqueY < -toleranceOffset) + inputCodes.Add("TY -"); - if (state.VelocityY > toleranceOffset) - inputCodes.Add("VY +"); - if (state.VelocityY < -toleranceOffset) - inputCodes.Add("VY -"); + if (state.TorqueZ > toleranceOffset) + inputCodes.Add("TZ +"); + if (state.TorqueZ < -toleranceOffset) + inputCodes.Add("TZ -"); - if (state.VelocityZ > toleranceOffset) - inputCodes.Add("VZ +"); - if (state.VelocityZ < -toleranceOffset) - inputCodes.Add("VZ -"); + if (state.VelocityX > toleranceOffset) + inputCodes.Add("VX +"); + if (state.VelocityX < -toleranceOffset) + inputCodes.Add("VX -"); - if (inputCodes.Any()) - { - if (focuesTextBox is object) - focuesTextBox.Text = inputCodes.Last(); - else if (enableActionExecution) - CheckForActions(inputCodes.ToArray()); + if (state.VelocityY > toleranceOffset) + inputCodes.Add("VY +"); + if (state.VelocityY < -toleranceOffset) + inputCodes.Add("VY -"); + + if (state.VelocityZ > toleranceOffset) + inputCodes.Add("VZ +"); + if (state.VelocityZ < -toleranceOffset) + inputCodes.Add("VZ -"); + + if (inputCodes.Any()) + { + if (focuesTextBox is object) + focuesTextBox.Text = inputCodes.Last(); + else if (enableActionExecution) + CheckForActions(inputCodes.ToArray()); + } } } } @@ -595,7 +609,7 @@ namespace PJ64Savestater private void radButton3_Click(object sender, EventArgs e) { - var sfd_SaveInputProfile = new SaveFileDialog + var sfd_SaveInputProfile = new RadSaveFileDialog { Filter = FILTER_INPUTPROFILE }; @@ -605,7 +619,7 @@ namespace PJ64Savestater private void radButton4_Click(object sender, EventArgs e) { - var ofd_SaveInputProfile = new OpenFileDialog + var ofd_SaveInputProfile = new RadOpenFileDialog { Filter = FILTER_INPUTPROFILE };