diff --git a/.gitignore b/.gitignore
index 1bc915c..6d113f2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -97,7 +97,7 @@ publish/
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
-#packages/
+packages/
# Windows Azure Build Output
csx
@@ -154,3 +154,6 @@ $RECYCLE.BIN/
# Mac desktop service store files
.DS_Store
+
+.vs/
+
diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config
deleted file mode 100644
index c2abfb4..0000000
--- a/.vs/config/applicationhost.config
+++ /dev/null
@@ -1,1030 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/DS4Windows.sln b/DS4Windows.sln
index 916f340..24fbce3 100644
--- a/DS4Windows.sln
+++ b/DS4Windows.sln
@@ -9,18 +9,24 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
+ Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|x64.ActiveCfg = Debug|Any CPU
- {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|x64.Build.0 = Debug|Any CPU
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|x64.ActiveCfg = Debug|x64
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|x64.Build.0 = Debug|x64
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|x86.ActiveCfg = Debug|x86
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Debug|x86.Build.0 = Debug|x86
{7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|Any CPU.Build.0 = Release|Any CPU
- {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|x64.ActiveCfg = Release|Any CPU
- {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|x64.Build.0 = Release|Any CPU
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|x64.ActiveCfg = Release|x64
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|x64.Build.0 = Release|x64
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|x86.ActiveCfg = Release|x86
+ {7B9354BF-AF82-4CCB-A83D-4BEB1E9D8C96}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/DS4Windows/DS4Control/ControlSerivce.cs b/DS4Windows/DS4Control/ControlSerivce.cs
deleted file mode 100644
index 28759a7..0000000
--- a/DS4Windows/DS4Control/ControlSerivce.cs
+++ /dev/null
@@ -1,851 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using System.IO;
-using System.Reflection;
-using System.Media;
-using System.Threading.Tasks;
-using static DS4Windows.Global;
-namespace DS4Windows
-{
- public class ControlService
- {
- public X360Device x360Bus;
- public DS4Device[] DS4Controllers = new DS4Device[4];
- public Mouse[] touchPad = new Mouse[4];
- private bool running = false;
- private DS4State[] MappedState = new DS4State[4];
- private DS4State[] CurrentState = new DS4State[4];
- private DS4State[] PreviousState = new DS4State[4];
- public DS4StateExposed[] ExposedState = new DS4StateExposed[4];
- public bool recordingMacro = false;
- public event EventHandler Debug = null;
- public bool eastertime = false;
- private int eCode = 0;
- bool[] buttonsdown = { false, false, false, false };
- List dcs = new List();
- bool[] held = new bool[4];
- int[] oldmouse = new int[4] { -1, -1, -1, -1 };
- SoundPlayer sp = new SoundPlayer();
-
- private class X360Data
- {
- public byte[] Report = new byte[28];
- public byte[] Rumble = new byte[8];
- }
- private X360Data[] processingData = new X360Data[4];
-
- public ControlService()
- {
- sp.Stream = Properties.Resources.EE;
- x360Bus = new X360Device();
- AddtoDS4List();
- for (int i = 0; i < DS4Controllers.Length; i++)
- {
- processingData[i] = new X360Data();
- MappedState[i] = new DS4State();
- CurrentState[i] = new DS4State();
- PreviousState[i] = new DS4State();
- ExposedState[i] = new DS4StateExposed(CurrentState[i]);
- }
- }
-
- void AddtoDS4List()
- {
- dcs.Add(DS4Controls.Cross);
- dcs.Add(DS4Controls.Cross);
- dcs.Add(DS4Controls.Circle);
- dcs.Add(DS4Controls.Square);
- dcs.Add(DS4Controls.Triangle);
- dcs.Add(DS4Controls.Options);
- dcs.Add(DS4Controls.Share);
- dcs.Add(DS4Controls.DpadUp);
- dcs.Add(DS4Controls.DpadDown);
- dcs.Add(DS4Controls.DpadLeft);
- dcs.Add(DS4Controls.DpadRight);
- dcs.Add(DS4Controls.PS);
- dcs.Add(DS4Controls.L1);
- dcs.Add(DS4Controls.R1);
- dcs.Add(DS4Controls.L2);
- dcs.Add(DS4Controls.R2);
- dcs.Add(DS4Controls.L3);
- dcs.Add(DS4Controls.R3);
- dcs.Add(DS4Controls.LXPos);
- dcs.Add(DS4Controls.LXNeg);
- dcs.Add(DS4Controls.LYPos);
- dcs.Add(DS4Controls.LYNeg);
- dcs.Add(DS4Controls.RXPos);
- dcs.Add(DS4Controls.RXNeg);
- dcs.Add(DS4Controls.RYPos);
- dcs.Add(DS4Controls.RYNeg);
- dcs.Add(DS4Controls.SwipeUp);
- dcs.Add(DS4Controls.SwipeDown);
- dcs.Add(DS4Controls.SwipeLeft);
- dcs.Add(DS4Controls.SwipeRight);
- }
-
- private async void WarnExclusiveModeFailure(DS4Device device)
- {
- if (DS4Devices.isExclusiveMode && !device.IsExclusive)
- {
- await System.Threading.Tasks.Task.Delay(5);
- String message = Properties.Resources.CouldNotOpenDS4.Replace("*Mac address*", device.MacAddress) + " " + Properties.Resources.QuitOtherPrograms;
- LogDebug(message, true);
- Log.LogToTray(message, true);
- }
- }
- public bool Start(bool showlog = true)
- {
- if (x360Bus.Open() && x360Bus.Start())
- {
- if (showlog)
- LogDebug(Properties.Resources.Starting);
- DS4Devices.isExclusiveMode = UseExclusiveMode;
- if (showlog)
- {
- LogDebug(Properties.Resources.SearchingController);
- LogDebug(DS4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive: Properties.Resources.UsingShared);
- }
- try
- {
- DS4Devices.findControllers();
- IEnumerable devices = DS4Devices.getDS4Controllers();
- int ind = 0;
- DS4LightBar.defualtLight = false;
- foreach (DS4Device device in devices)
- {
- if (showlog)
- LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
- WarnExclusiveModeFailure(device);
- DS4Controllers[ind] = device;
- device.Removal -= DS4Devices.On_Removal;
- device.Removal += this.On_DS4Removal;
- device.Removal += DS4Devices.On_Removal;
- touchPad[ind] = new Mouse(ind, device);
- device.LightBarColor = MainColor[ind];
- if (!DinputOnly[ind])
- x360Bus.Plugin(ind);
- device.Report += this.On_Report;
- TouchPadOn(ind, device);
- //string filename = ProfilePath[ind];
- ind++;
- if (showlog)
- if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[ind-1] + ".xml"))
- {
- string prolog = Properties.Resources.UsingProfile.Replace("*number*", ind.ToString()).Replace("*Profile name*", ProfilePath[ind-1]);
- LogDebug(prolog);
- Log.LogToTray(prolog);
- }
- else
- {
- string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (ind).ToString());
- LogDebug(prolog);
- Log.LogToTray(prolog);
- }
- if (ind >= 4) // out of Xinput devices!
- break;
- }
- }
- catch (Exception e)
- {
- LogDebug(e.Message);
- Log.LogToTray(e.Message);
- }
- running = true;
-
- }
- return true;
- }
-
- public bool Stop(bool showlog = true)
- {
- if (running)
- {
- running = false;
- if (showlog)
- LogDebug(Properties.Resources.StoppingX360);
- bool anyUnplugged = false;
- for (int i = 0; i < DS4Controllers.Length; i++)
- {
- if (DS4Controllers[i] != null)
- {
- if (DCBTatStop && !DS4Controllers[i].Charging && showlog)
- DS4Controllers[i].DisconnectBT();
- else
- {
- DS4LightBar.forcelight[i] = false;
- DS4LightBar.forcedFlash[i] = 0;
- DS4LightBar.defualtLight = true;
- DS4LightBar.updateLightBar(DS4Controllers[i], i, CurrentState[i], ExposedState[i], touchPad[i]);
- System.Threading.Thread.Sleep(50);
- }
- CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
- x360Bus.Unplug(i);
- anyUnplugged = true;
- DS4Controllers[i] = null;
- touchPad[i] = null;
- }
- }
- if (anyUnplugged)
- System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
- x360Bus.UnplugAll();
- x360Bus.Stop();
- if (showlog)
- LogDebug(Properties.Resources.StoppingDS4);
- DS4Devices.stopControllers();
- if (showlog)
- LogDebug(Properties.Resources.StoppedDS4Windows);
- ControllerStatusChanged(this);
- }
- return true;
- }
-
- public bool HotPlug()
- {
- if (running)
- {
- DS4Devices.findControllers();
- IEnumerable devices = DS4Devices.getDS4Controllers();
- foreach (DS4Device device in devices)
- {
- if (device.IsDisconnecting)
- continue;
- if (((Func)delegate
- {
- for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
- if (DS4Controllers[Index] != null && DS4Controllers[Index].MacAddress == device.MacAddress)
- return true;
- return false;
- })())
- continue;
- for (Int32 Index = 0; Index < DS4Controllers.Length; Index++)
- if (DS4Controllers[Index] == null)
- {
- LogDebug(Properties.Resources.FoundController + device.MacAddress + " (" + device.ConnectionType + ")");
- WarnExclusiveModeFailure(device);
- DS4Controllers[Index] = device;
- device.Removal -= DS4Devices.On_Removal;
- device.Removal += this.On_DS4Removal;
- device.Removal += DS4Devices.On_Removal;
- touchPad[Index] = new Mouse(Index, device);
- device.LightBarColor = MainColor[Index];
- device.Report += this.On_Report;
- if (!DinputOnly[Index])
- x360Bus.Plugin(Index);
- TouchPadOn(Index, device);
- //string filename = Path.GetFileName(ProfilePath[Index]);
- if (System.IO.File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
- {
- string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]);
- LogDebug(prolog);
- Log.LogToTray(prolog);
- }
- else
- {
- string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString());
- LogDebug(prolog);
- Log.LogToTray(prolog);
- }
-
- break;
- }
- }
- }
- return true;
- }
-
- public void TouchPadOn(int ind, DS4Device device)
- {
- ITouchpadBehaviour tPad = touchPad[ind];
- device.Touchpad.TouchButtonDown += tPad.touchButtonDown;
- device.Touchpad.TouchButtonUp += tPad.touchButtonUp;
- device.Touchpad.TouchesBegan += tPad.touchesBegan;
- device.Touchpad.TouchesMoved += tPad.touchesMoved;
- device.Touchpad.TouchesEnded += tPad.touchesEnded;
- device.Touchpad.TouchUnchanged += tPad.touchUnchanged;
- device.SixAxis.SixAccelMoved += tPad.sixaxisMoved;
- //LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
- //Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
- ControllerStatusChanged(this);
- }
-
- public void TimeoutConnection(DS4Device d)
- {
- try
- {
- System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
- sw.Start();
- while (!d.IsAlive())
- {
- if (sw.ElapsedMilliseconds < 1000)
- System.Threading.Thread.SpinWait(500);
- //If weve been waiting less than 1 second let the thread keep its processing chunk
- else
- System.Threading.Thread.Sleep(500);
- //If weve been waiting more than 1 second give up some resources
-
- if (sw.ElapsedMilliseconds > 5000) throw new TimeoutException(); //Weve waited long enough
- }
- sw.Reset();
- }
- catch (TimeoutException)
- {
- Stop(false);
- Start(false);
- }
- }
-
- public string getDS4ControllerInfo(int index)
- {
- if (DS4Controllers[index] != null)
- {
- DS4Device d = DS4Controllers[index];
- if (!d.IsAlive())
- //return "Connecting..."; // awaiting the first battery charge indication
- {
- var TimeoutThread = new System.Threading.Thread(() => TimeoutConnection(d));
- TimeoutThread.IsBackground = true;
- TimeoutThread.Name = "TimeoutFor" + d.MacAddress.ToString();
- TimeoutThread.Start();
- return Properties.Resources.Connecting;
- }
- String battery;
- if (d.Charging)
- {
- if (d.Battery >= 100)
- battery = Properties.Resources.Charged;
- else
- battery = Properties.Resources.Charging.Replace("*number*", d.Battery.ToString());
- }
- else
- {
- battery = Properties.Resources.Battery.Replace("*number*", d.Battery.ToString());
- }
- return d.MacAddress + " (" + d.ConnectionType + "), " + battery;
- //return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
- }
- else
- return String.Empty;
- }
-
- public string getDS4MacAddress(int index)
- {
- if (DS4Controllers[index] != null)
- {
- DS4Device d = DS4Controllers[index];
- if (!d.IsAlive())
- //return "Connecting..."; // awaiting the first battery charge indication
- {
- var TimeoutThread = new System.Threading.Thread(() => TimeoutConnection(d));
- TimeoutThread.IsBackground = true;
- TimeoutThread.Name = "TimeoutFor" + d.MacAddress.ToString();
- TimeoutThread.Start();
- return Properties.Resources.Connecting;
- }
- return d.MacAddress;
- }
- else
- return String.Empty;
- }
-
- public string getShortDS4ControllerInfo(int index)
- {
- if (DS4Controllers[index] != null)
- {
- DS4Device d = DS4Controllers[index];
- String battery;
- if (!d.IsAlive())
- battery = "...";
- if (d.Charging)
- {
- if (d.Battery >= 100)
- battery = Properties.Resources.Full;
- else
- battery = d.Battery + "%+";
- }
- else
- {
- battery = d.Battery + "%";
- }
- return (d.ConnectionType + " " + battery);
- }
- else
- return Properties.Resources.NoneText;
- }
-
- public string getDS4Battery(int index)
- {
- if (DS4Controllers[index] != null)
- {
- DS4Device d = DS4Controllers[index];
- String battery;
- if (!d.IsAlive())
- battery = "...";
- if (d.Charging)
- {
- if (d.Battery >= 100)
- battery = Properties.Resources.Full;
- else
- battery = d.Battery + "%+";
- }
- else
- {
- battery = d.Battery + "%";
- }
- return battery;
- }
- else
- return Properties.Resources.NA;
- }
-
- public string getDS4Status(int index)
- {
- if (DS4Controllers[index] != null)
- {
- DS4Device d = DS4Controllers[index];
- return d.ConnectionType+"";
- }
- else
- return Properties.Resources.NoneText;
- }
-
-
- private int XINPUT_UNPLUG_SETTLE_TIME = 250; // Inhibit races that occur with the asynchronous teardown of ScpVBus -> X360 driver instance.
- //Called when DS4 is disconnected or timed out
- protected virtual void On_DS4Removal(object sender, EventArgs e)
- {
- DS4Device device = (DS4Device)sender;
- int ind = -1;
- for (int i = 0; i < DS4Controllers.Length; i++)
- if (DS4Controllers[i] != null && device.MacAddress == DS4Controllers[i].MacAddress)
- ind = i;
- if (ind != -1)
- {
- CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
- x360Bus.Unplug(ind);
- string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind +1).ToString());
- if (DS4Controllers[ind].Battery <= 20 &&
- DS4Controllers[ind].ConnectionType == ConnectionType.BT && !DS4Controllers[ind].Charging)
- removed += ". " + Properties.Resources.ChargeController;
- LogDebug(removed);
- Log.LogToTray(removed);
- System.Threading.Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
- DS4Controllers[ind] = null;
- touchPad[ind] = null;
- ControllerStatusChanged(this);
- }
- }
- public bool[] lag = { false, false, false, false };
- //Called every time the new input report has arrived
- protected virtual void On_Report(object sender, EventArgs e)
- {
-
- DS4Device device = (DS4Device)sender;
-
- int ind = -1;
- for (int i = 0; i < DS4Controllers.Length; i++)
- if (device == DS4Controllers[i])
- ind = i;
-
- if (ind != -1)
- {
- if (FlushHIDQueue[ind])
- device.FlushHID();
- if (!string.IsNullOrEmpty(device.error))
- {
- LogDebug(device.error);
- }
- if (DateTime.UtcNow - device.firstActive > TimeSpan.FromSeconds(5))
- {
- if (device.Latency >= FlashWhenLateAt && !lag[ind])
- LagFlashWarning(ind, true);
- else if (device.Latency < FlashWhenLateAt && lag[ind])
- LagFlashWarning(ind, false);
- }
- device.getExposedState(ExposedState[ind], CurrentState[ind]);
- DS4State cState = CurrentState[ind];
- device.getPreviousState(PreviousState[ind]);
- DS4State pState = PreviousState[ind];
- if (pState.Battery != cState.Battery)
- ControllerStatusChanged(this);
- CheckForHotkeys(ind, cState, pState);
- if (eastertime)
- EasterTime(ind);
- GetInputkeys(ind);
- if (LSCurve[ind] != 0 || RSCurve[ind] != 0 || LSDeadzone[ind] != 0 || RSDeadzone[ind] != 0 ||
- L2Deadzone[ind] != 0 || R2Deadzone[ind] != 0 || LSSens[ind] != 0 || RSSens[ind] != 0 ||
- L2Sens[ind] != 0 || R2Sens[ind] != 0) //if a curve or deadzone is in place
- cState = Mapping.SetCurveAndDeadzone(ind, cState);
- if (!recordingMacro && (!string.IsNullOrEmpty(tempprofilename[ind]) ||
- HasCustomAction(ind) || HasCustomExtras(ind) || ProfileActions[ind].Count > 0))
- {
- Mapping.MapCustom(ind, cState, MappedState[ind], ExposedState[ind], touchPad[ind], this);
- cState = MappedState[ind];
- }
- //if (HasCustomExtras(ind))
- // DoExtras(ind);
-
- // Update the GUI/whatever.
- DS4LightBar.updateLightBar(device, ind, cState, ExposedState[ind], touchPad[ind]);
-
- x360Bus.Parse(cState, processingData[ind].Report, ind);
- // We push the translated Xinput state, and simultaneously we
- // pull back any possible rumble data coming from Xinput consumers.
- if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble))
- {
- Byte Big = (Byte)(processingData[ind].Rumble[3]);
- Byte Small = (Byte)(processingData[ind].Rumble[4]);
-
- if (processingData[ind].Rumble[1] == 0x08)
- {
- setRumble(Big, Small, ind);
- }
- }
-
- // Output any synthetic events.
- Mapping.Commit(ind);
- // Pull settings updates.
- device.IdleTimeout = IdleDisconnectTimeout[ind];
- }
- }
-
- public void LagFlashWarning(int ind, bool on)
- {
- if (on)
- {
- lag[ind] = true;
- LogDebug(Properties.Resources.LatencyOverTen.Replace("*number*", (ind + 1).ToString()), true);
- if (FlashWhenLate)
- {
- DS4Color color = new DS4Color { red = 50, green = 0, blue = 0 };
- DS4LightBar.forcedColor[ind] = color;
- DS4LightBar.forcedFlash[ind] = 2;
- DS4LightBar.forcelight[ind] = true;
- }
- }
- else
- {
- lag[ind] = false;
- LogDebug(Properties.Resources.LatencyNotOverTen.Replace("*number*", (ind + 1).ToString()));
- DS4LightBar.forcelight[ind] = false;
- DS4LightBar.forcedFlash[ind] = 0;
- }
- }
-
- /* private void DoExtras(int ind)
- {
- DS4State cState = CurrentState[ind];
- DS4StateExposed eState = ExposedState[ind];
- Mouse tp = touchPad[ind];
- DS4Controls helddown = DS4Controls.None;
- foreach (KeyValuePair p in getCustomExtras(ind))
- {
- if (Mapping.getBoolMapping(ind, p.Key, cState, eState, tp))
- {
- helddown = p.Key;
- break;
- }
- }
- if (helddown != DS4Controls.None)
- {
- string p = getCustomExtras(ind)[helddown];
- string[] extraS = p.Split(',');
- int[] extras = new int[extraS.Length];
- for (int i = 0; i < extraS.Length; i++)
- {
- int b;
- if (int.TryParse(extraS[i], out b))
- extras[i] = b;
- }
- held[ind] = true;
- try
- {
- if (!(extras[0] == extras[1] && extras[1] == 0))
- setRumble((byte)extras[0], (byte)extras[1], ind);
- if (extras[2] == 1)
- {
- DS4Color color = new DS4Color { red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5] };
- DS4LightBar.forcedColor[ind] = color;
- DS4LightBar.forcedFlash[ind] = (byte)extras[6];
- DS4LightBar.forcelight[ind] = true;
- }
- if (extras[7] == 1)
- {
- if (oldmouse[ind] == -1)
- oldmouse[ind] = ButtonMouseSensitivity[ind];
- ButtonMouseSensitivity[ind] = extras[8];
- }
- }
- catch { }
- }
- else if (held[ind])
- {
- DS4LightBar.forcelight[ind] = false;
- DS4LightBar.forcedFlash[ind] = 0;
- ButtonMouseSensitivity[ind] = oldmouse[ind];
- oldmouse[ind] = -1;
- setRumble(0, 0, ind);
- held[ind] = false;
- }
- }*/
-
-
-
- public void EasterTime(int ind)
- {
- DS4State cState = CurrentState[ind];
- DS4StateExposed eState = ExposedState[ind];
- Mouse tp = touchPad[ind];
-
- bool pb = false;
- foreach (DS4Controls dc in dcs)
- {
- if (Mapping.getBoolMapping(ind, dc, cState, eState, tp))
- {
- pb = true;
- break;
- }
- }
- int temp = eCode;
- //Looks like you found the easter egg code, since you're already cheating,
- //I scrambled the code for you :)
- if (pb && !buttonsdown[ind])
- {
- if (cState.Cross && eCode == 9)
- eCode++;
- else if (!cState.Cross && eCode == 9)
- eCode = 0;
- else if (cState.DpadLeft && eCode == 6)
- eCode++;
- else if (!cState.DpadLeft && eCode == 6)
- eCode = 0;
- else if (cState.DpadRight && eCode == 7)
- eCode++;
- else if (!cState.DpadRight && eCode == 7)
- eCode = 0;
- else if (cState.DpadLeft && eCode == 4)
- eCode++;
- else if (!cState.DpadLeft && eCode == 4)
- eCode = 0;
- else if (cState.DpadDown && eCode == 2)
- eCode++;
- else if (!cState.DpadDown && eCode == 2)
- eCode = 0;
- else if (cState.DpadRight && eCode == 5)
- eCode++;
- else if (!cState.DpadRight && eCode == 5)
- eCode = 0;
- else if (cState.DpadUp && eCode == 1)
- eCode++;
- else if (!cState.DpadUp && eCode == 1)
- eCode = 0;
- else if (cState.DpadDown && eCode == 3)
- eCode++;
- else if (!cState.DpadDown && eCode == 3)
- eCode = 0;
- else if (cState.Circle && eCode == 8)
- eCode++;
- else if (!cState.Circle && eCode == 8)
- eCode = 0;
-
- if (cState.DpadUp && eCode == 0)
- eCode++;
-
- if (eCode == 10)
- {
- string message = "(!)";
- sp.Play();
- LogDebug(message, true);
- eCode = 0;
- }
-
- if (temp != eCode)
- Console.WriteLine(eCode);
- buttonsdown[ind] = true;
- }
- else if (!pb)
- buttonsdown[ind] = false;
- }
-
- public string GetInputkeys(int ind)
- {
- DS4State cState = CurrentState[ind];
- DS4StateExposed eState = ExposedState[ind];
- Mouse tp = touchPad[ind];
- if (DS4Controllers[ind] != null)
- if (Mapping.getBoolMapping(ind, DS4Controls.Cross, cState, eState, tp)) return "Cross";
- else if (Mapping.getBoolMapping(ind, DS4Controls.Circle, cState, eState, tp)) return "Circle";
- else if (Mapping.getBoolMapping(ind, DS4Controls.Triangle, cState, eState, tp)) return "Triangle";
- else if (Mapping.getBoolMapping(ind, DS4Controls.Square, cState, eState, tp)) return "Square";
- else if (Mapping.getBoolMapping(ind, DS4Controls.L1, cState, eState, tp)) return "L1";
- else if (Mapping.getBoolMapping(ind, DS4Controls.R1, cState, eState, tp)) return "R1";
- else if (Mapping.getBoolMapping(ind, DS4Controls.L2, cState, eState, tp)) return "L2";
- else if (Mapping.getBoolMapping(ind, DS4Controls.R2, cState, eState, tp)) return "R2";
- else if (Mapping.getBoolMapping(ind, DS4Controls.L3, cState, eState, tp)) return "L3";
- else if (Mapping.getBoolMapping(ind, DS4Controls.R3, cState, eState, tp)) return "R3";
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadUp, cState, eState, tp)) return "Up";
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadDown, cState, eState, tp)) return "Down";
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadLeft, cState, eState, tp)) return "Left";
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadRight, cState, eState, tp)) return "Right";
- else if (Mapping.getBoolMapping(ind, DS4Controls.Share, cState, eState, tp)) return "Share";
- else if (Mapping.getBoolMapping(ind, DS4Controls.Options, cState, eState, tp)) return "Options";
- else if (Mapping.getBoolMapping(ind, DS4Controls.PS, cState, eState, tp)) return "PS";
- else if (Mapping.getBoolMapping(ind, DS4Controls.LXPos, cState, eState, tp)) return "LS Right";
- else if (Mapping.getBoolMapping(ind, DS4Controls.LXNeg, cState, eState, tp)) return "LS Left";
- else if (Mapping.getBoolMapping(ind, DS4Controls.LYPos, cState, eState, tp)) return "LS Down";
- else if (Mapping.getBoolMapping(ind, DS4Controls.LYNeg, cState, eState, tp)) return "LS Up";
- else if (Mapping.getBoolMapping(ind, DS4Controls.RXPos, cState, eState, tp)) return "RS Right";
- else if (Mapping.getBoolMapping(ind, DS4Controls.RXNeg, cState, eState, tp)) return "RS Left";
- else if (Mapping.getBoolMapping(ind, DS4Controls.RYPos, cState, eState, tp)) return "RS Down";
- else if (Mapping.getBoolMapping(ind, DS4Controls.RYNeg, cState, eState, tp)) return "RS Up";
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchLeft, cState, eState, tp)) return "Touch Left";
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchRight, cState, eState, tp)) return "Touch Right";
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchMulti, cState, eState, tp)) return "Touch Multi";
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchUpper, cState, eState, tp)) return "Touch Upper";
- return "nothing";
- }
-
- public DS4Controls GetInputkeysDS4(int ind)
- {
- DS4State cState = CurrentState[ind];
- DS4StateExposed eState = ExposedState[ind];
- Mouse tp = touchPad[ind];
- if (DS4Controllers[ind] != null)
- if (Mapping.getBoolMapping(ind, DS4Controls.Cross, cState, eState, tp)) return DS4Controls.Cross;
- else if (Mapping.getBoolMapping(ind, DS4Controls.Circle, cState, eState, tp)) return DS4Controls.Circle;
- else if (Mapping.getBoolMapping(ind, DS4Controls.Triangle, cState, eState, tp)) return DS4Controls.Triangle;
- else if (Mapping.getBoolMapping(ind, DS4Controls.Square, cState, eState, tp)) return DS4Controls.Square;
- else if (Mapping.getBoolMapping(ind, DS4Controls.L1, cState, eState, tp)) return DS4Controls.L1;
- else if (Mapping.getBoolMapping(ind, DS4Controls.R1, cState, eState, tp)) return DS4Controls.R1;
- else if (Mapping.getBoolMapping(ind, DS4Controls.L2, cState, eState, tp)) return DS4Controls.L2;
- else if (Mapping.getBoolMapping(ind, DS4Controls.R2, cState, eState, tp)) return DS4Controls.R2;
- else if (Mapping.getBoolMapping(ind, DS4Controls.L3, cState, eState, tp)) return DS4Controls.L3;
- else if (Mapping.getBoolMapping(ind, DS4Controls.R3, cState, eState, tp)) return DS4Controls.R3;
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadUp, cState, eState, tp)) return DS4Controls.DpadUp;
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadDown, cState, eState, tp)) return DS4Controls.DpadDown;
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadLeft, cState, eState, tp)) return DS4Controls.DpadLeft;
- else if (Mapping.getBoolMapping(ind, DS4Controls.DpadRight, cState, eState, tp)) return DS4Controls.DpadRight;
- else if (Mapping.getBoolMapping(ind, DS4Controls.Share, cState, eState, tp)) return DS4Controls.Share;
- else if (Mapping.getBoolMapping(ind, DS4Controls.Options, cState, eState, tp)) return DS4Controls.Options;
- else if (Mapping.getBoolMapping(ind, DS4Controls.PS, cState, eState, tp)) return DS4Controls.PS;
- else if (Mapping.getBoolMapping(ind, DS4Controls.LXPos, cState, eState, tp)) return DS4Controls.LXPos;
- else if (Mapping.getBoolMapping(ind, DS4Controls.LXNeg, cState, eState, tp)) return DS4Controls.LXNeg;
- else if (Mapping.getBoolMapping(ind, DS4Controls.LYPos, cState, eState, tp)) return DS4Controls.LYPos;
- else if (Mapping.getBoolMapping(ind, DS4Controls.LYNeg, cState, eState, tp)) return DS4Controls.LYNeg;
- else if (Mapping.getBoolMapping(ind, DS4Controls.RXPos, cState, eState, tp)) return DS4Controls.RXPos;
- else if (Mapping.getBoolMapping(ind, DS4Controls.RXNeg, cState, eState, tp)) return DS4Controls.RXNeg;
- else if (Mapping.getBoolMapping(ind, DS4Controls.RYPos, cState, eState, tp)) return DS4Controls.RYPos;
- else if (Mapping.getBoolMapping(ind, DS4Controls.RYNeg, cState, eState, tp)) return DS4Controls.RYNeg;
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchLeft, cState, eState, tp)) return DS4Controls.TouchLeft;
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchRight, cState, eState, tp)) return DS4Controls.TouchRight;
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchMulti, cState, eState, tp)) return DS4Controls.TouchMulti;
- else if (Mapping.getBoolMapping(ind, DS4Controls.TouchUpper, cState, eState, tp)) return DS4Controls.TouchUpper;
- return DS4Controls.None;
- }
-
- public bool[] touchreleased = { true, true, true, true }, touchslid = { false, false, false, false };
- public byte[] oldtouchvalue = { 0, 0, 0, 0 };
- public int[] oldscrollvalue = { 0, 0, 0, 0 };
- protected virtual void CheckForHotkeys(int deviceID, DS4State cState, DS4State pState)
- {
- if (!UseTPforControls[deviceID] && cState.Touch1 && pState.PS)
- {
- if (TouchSensitivity[deviceID] > 0 && touchreleased[deviceID])
- {
- oldtouchvalue[deviceID] = TouchSensitivity[deviceID];
- oldscrollvalue[deviceID] = ScrollSensitivity[deviceID];
- TouchSensitivity[deviceID] = 0;
- ScrollSensitivity[deviceID] = 0;
- LogDebug(TouchSensitivity[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff);
- Log.LogToTray(TouchSensitivity[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff);
- touchreleased[deviceID] = false;
- }
- else if (touchreleased[deviceID])
- {
- TouchSensitivity[deviceID] = oldtouchvalue[deviceID];
- ScrollSensitivity[deviceID] = oldscrollvalue[deviceID];
- LogDebug(TouchSensitivity[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff);
- Log.LogToTray(TouchSensitivity[deviceID] > 0 ? Properties.Resources.TouchpadMovementOn : Properties.Resources.TouchpadMovementOff);
- touchreleased[deviceID] = false;
- }
- }
- else
- touchreleased[deviceID] = true;
- }
-
- public virtual void StartTPOff(int deviceID)
- {
- if (deviceID < 4)
- {
- oldtouchvalue[deviceID] = TouchSensitivity[deviceID];
- oldscrollvalue[deviceID] = ScrollSensitivity[deviceID];
- TouchSensitivity[deviceID] = 0;
- ScrollSensitivity[deviceID] = 0;
- }
- }
-
- public virtual string TouchpadSlide(int ind)
- {
- DS4State cState = CurrentState[ind];
- string slidedir = "none";
- if (DS4Controllers[ind] != null && cState.Touch2 && !(touchPad[ind].dragging || touchPad[ind].dragging2))
- if (touchPad[ind].slideright && !touchslid[ind])
- {
- slidedir = "right";
- touchslid[ind] = true;
- }
- else if (touchPad[ind].slideleft && !touchslid[ind])
- {
- slidedir = "left";
- touchslid[ind] = true;
- }
- else if (!touchPad[ind].slideleft && !touchPad[ind].slideright)
- {
- slidedir = "";
- touchslid[ind] = false;
- }
- return slidedir;
- }
- public virtual void LogDebug(String Data, bool warning = false)
- {
- Console.WriteLine(System.DateTime.Now.ToString("G") + "> " + Data);
- if (Debug != null)
- {
- DebugEventArgs args = new DebugEventArgs(Data, warning);
- OnDebug(this, args);
- }
- }
-
- public virtual void OnDebug(object sender, DebugEventArgs args)
- {
- if (Debug != null)
- Debug(this, args);
- }
-
- //sets the rumble adjusted with rumble boost
- public virtual void setRumble(byte heavyMotor, byte lightMotor, int deviceNum)
- {
- byte boost = RumbleBoost[deviceNum];
- uint lightBoosted = ((uint)lightMotor * (uint)boost) / 100;
- if (lightBoosted > 255)
- lightBoosted = 255;
- uint heavyBoosted = ((uint)heavyMotor * (uint)boost) / 100;
- if (heavyBoosted > 255)
- heavyBoosted = 255;
- if (deviceNum < 4)
- if (DS4Controllers[deviceNum] != null)
- DS4Controllers[deviceNum].setRumble((byte)lightBoosted, (byte)heavyBoosted);
- }
-
- public DS4State getDS4State(int ind)
- {
- return CurrentState[ind];
- }
- public DS4State getDS4StateMapped(int ind)
- {
- return MappedState[ind];
- }
- }
-}
diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs
new file mode 100644
index 0000000..3c4ff38
--- /dev/null
+++ b/DS4Windows/DS4Control/ControlService.cs
@@ -0,0 +1,1077 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+using System.Media;
+using System.Threading.Tasks;
+using static DS4Windows.Global;
+using System.Threading;
+using Registry = Microsoft.Win32.Registry;
+
+namespace DS4Windows
+{
+ public class ControlService
+ {
+ public X360Device x360Bus = null;
+ public const int DS4_CONTROLLER_COUNT = 4;
+ public DS4Device[] DS4Controllers = new DS4Device[DS4_CONTROLLER_COUNT];
+ public Mouse[] touchPad = new Mouse[DS4_CONTROLLER_COUNT];
+ private bool running = false;
+ private DS4State[] MappedState = new DS4State[DS4_CONTROLLER_COUNT];
+ private DS4State[] CurrentState = new DS4State[DS4_CONTROLLER_COUNT];
+ private DS4State[] PreviousState = new DS4State[DS4_CONTROLLER_COUNT];
+ private DS4State[] TempState = new DS4State[DS4_CONTROLLER_COUNT];
+ public DS4StateExposed[] ExposedState = new DS4StateExposed[DS4_CONTROLLER_COUNT];
+ public bool recordingMacro = false;
+ public event EventHandler Debug = null;
+ bool[] buttonsdown = new bool[4] { false, false, false, false };
+ bool[] held = new bool[DS4_CONTROLLER_COUNT];
+ int[] oldmouse = new int[DS4_CONTROLLER_COUNT] { -1, -1, -1, -1 };
+ Thread tempThread;
+ public List affectedDevs = new List()
+ {
+ @"HID\VID_054C&PID_05C4",
+ @"HID\VID_054C&PID_09CC&MI_03",
+ @"HID\VID_054C&PID_0BA0&MI_03",
+ @"HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0002054c_PID&05c4",
+ @"HID\{00001124-0000-1000-8000-00805f9b34fb}_VID&0002054c_PID&09cc",
+ };
+ public bool suspending;
+ //SoundPlayer sp = new SoundPlayer();
+
+ private class X360Data
+ {
+ public byte[] Report = new byte[28];
+ public byte[] Rumble = new byte[8];
+ }
+
+ private X360Data[] processingData = new X360Data[4];
+
+ public ControlService()
+ {
+ //sp.Stream = Properties.Resources.EE;
+ // Cause thread affinity to not be tied to main GUI thread
+ tempThread = new Thread(() => { x360Bus = new X360Device(); });
+ tempThread.Priority = ThreadPriority.AboveNormal;
+ tempThread.IsBackground = true;
+ tempThread.Start();
+ while (tempThread.IsAlive)
+ {
+ Thread.SpinWait(500);
+ }
+
+ for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
+ {
+ processingData[i] = new X360Data();
+ MappedState[i] = new DS4State();
+ CurrentState[i] = new DS4State();
+ TempState[i] = new DS4State();
+ PreviousState[i] = new DS4State();
+ ExposedState[i] = new DS4StateExposed(CurrentState[i]);
+ }
+ }
+
+ private void WarnExclusiveModeFailure(DS4Device device)
+ {
+ if (DS4Devices.isExclusiveMode && !device.isExclusive())
+ {
+ string message = Properties.Resources.CouldNotOpenDS4.Replace("*Mac address*", device.getMacAddress()) + " " +
+ Properties.Resources.QuitOtherPrograms;
+ LogDebug(message, true);
+ Log.LogToTray(message, true);
+ }
+ }
+
+ public void createHidGuardKey()
+ {
+ try
+ {
+ Registry.LocalMachine.CreateSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist\" + System.Diagnostics.Process.GetCurrentProcess().Id);
+ }
+ catch { }
+ }
+
+ public void removeHidGuardKey()
+ {
+ try
+ {
+ Registry.LocalMachine.DeleteSubKey(@"SYSTEM\CurrentControlSet\Services\HidGuardian\Parameters\Whitelist\" + System.Diagnostics.Process.GetCurrentProcess().Id);
+ }
+ catch { }
+ }
+
+ public bool PlugXInputController(int index)
+ {
+ int xinputIndex = x360Bus.FirstController + index;
+ LogDebug("Plugging in X360 Controller #" + xinputIndex);
+ bool xinputResult = x360Bus.Plugin(index);
+ if (xinputResult)
+ {
+ useDInputOnly[index] = false;
+ LogDebug("X360 Controller # " + xinputIndex + " connected");
+ }
+ else
+ {
+ useDInputOnly[index] = true;
+ LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
+ }
+
+ return xinputResult;
+ }
+
+ public bool UnplugXInputController(int index)
+ {
+ bool unplugResult = x360Bus.Unplug(index);
+ int xinputIndex = x360Bus.FirstController + index;
+ if (unplugResult)
+ {
+ useDInputOnly[index] = true;
+ LogDebug("X360 Controller # " + xinputIndex + " unplugged");
+ }
+ else
+ {
+ LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
+ }
+
+ return unplugResult;
+ }
+
+ public bool Start(object tempui, bool showlog = true)
+ {
+ if (x360Bus.Open() && x360Bus.Start())
+ {
+ if (showlog)
+ LogDebug(Properties.Resources.Starting);
+
+ LogDebug("Connection to Scp Virtual Bus established");
+
+ DS4Devices.isExclusiveMode = getUseExclusiveMode();
+ if (showlog)
+ {
+ LogDebug(Properties.Resources.SearchingController);
+ LogDebug(DS4Devices.isExclusiveMode ? Properties.Resources.UsingExclusive : Properties.Resources.UsingShared);
+ }
+
+ try
+ {
+ DS4Devices.findControllers();
+ IEnumerable devices = DS4Devices.getDS4Controllers();
+ //int ind = 0;
+ DS4LightBar.defaultLight = false;
+ //foreach (DS4Device device in devices)
+
+ for (int i = 0, devCount = devices.Count(); i < devCount; i++)
+ {
+ DS4Device device = devices.ElementAt(i);
+ if (showlog)
+ LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
+
+ Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
+ task.Start();
+
+ DS4Controllers[i] = device;
+ device.setUiContext(tempui as SynchronizationContext);
+ device.Removal += this.On_DS4Removal;
+ device.Removal += DS4Devices.On_Removal;
+ device.SyncChange += this.On_SyncChange;
+ device.SyncChange += DS4Devices.UpdateSerial;
+ device.SerialChange += this.On_SerialChange;
+ if (device.isValidSerial() && containsLinkedProfile(device.getMacAddress()))
+ {
+ ProfilePath[i] = getLinkedProfile(device.getMacAddress());
+ }
+ else
+ {
+ ProfilePath[i] = OlderProfilePath[i];
+ }
+ LoadProfile(i, false, this, false, false);
+ touchPad[i] = new Mouse(i, device);
+ device.LightBarColor = getMainColor(i);
+
+ if (!getDInputOnly(i) && device.isSynced())
+ {
+ int xinputIndex = x360Bus.FirstController + i;
+ LogDebug("Plugging in X360 Controller #" + xinputIndex);
+ bool xinputResult = x360Bus.Plugin(i);
+ if (xinputResult)
+ {
+ useDInputOnly[i] = false;
+ LogDebug("X360 Controller # " + xinputIndex + " connected");
+ }
+ else
+ {
+ useDInputOnly[i] = true;
+ LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
+ }
+ }
+
+ int tempIdx = i;
+ device.Report += (sender, e) =>
+ {
+ this.On_Report(sender, e, tempIdx);
+ };
+ TouchPadOn(i, device);
+ CheckProfileOptions(i, device, true);
+ device.StartUpdate();
+ //string filename = ProfilePath[ind];
+ //ind++;
+ if (showlog)
+ {
+ if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[i] + ".xml"))
+ {
+ string prolog = Properties.Resources.UsingProfile.Replace("*number*", (i + 1).ToString()).Replace("*Profile name*", ProfilePath[i]);
+ LogDebug(prolog);
+ Log.LogToTray(prolog);
+ }
+ else
+ {
+ string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (i + 1).ToString());
+ LogDebug(prolog);
+ Log.LogToTray(prolog);
+ }
+ }
+
+ if (i >= 4) // out of Xinput devices!
+ break;
+ }
+ }
+ catch (Exception e)
+ {
+ LogDebug(e.Message);
+ Log.LogToTray(e.Message);
+ }
+
+ running = true;
+ }
+ else
+ {
+ string logMessage = "Could not connect to Scp Virtual Bus Driver. Please check the status of the System device in Device Manager";
+ LogDebug(logMessage);
+ Log.LogToTray(logMessage);
+ }
+
+ runHotPlug = true;
+ return true;
+ }
+
+ public bool Stop(bool showlog = true)
+ {
+ if (running)
+ {
+ running = false;
+ runHotPlug = false;
+
+ if (showlog)
+ LogDebug(Properties.Resources.StoppingX360);
+
+ LogDebug("Closing connection to Scp Virtual Bus");
+
+ bool anyUnplugged = false;
+ for (int i = 0, arlength = DS4Controllers.Length; i < arlength; i++)
+ {
+ DS4Device tempDevice = DS4Controllers[i];
+ if (tempDevice != null)
+ {
+ if ((DCBTatStop && !tempDevice.isCharging()) || suspending)
+ {
+ if (tempDevice.getConnectionType() == ConnectionType.BT)
+ {
+ tempDevice.StopUpdate();
+ tempDevice.DisconnectBT(true);
+ }
+ else if (tempDevice.getConnectionType() == ConnectionType.SONYWA)
+ {
+ tempDevice.StopUpdate();
+ tempDevice.DisconnectDongle(true);
+ }
+ }
+ else
+ {
+ DS4LightBar.forcelight[i] = false;
+ DS4LightBar.forcedFlash[i] = 0;
+ DS4LightBar.defaultLight = true;
+ DS4LightBar.updateLightBar(DS4Controllers[i], i);
+ tempDevice.IsRemoved = true;
+ tempDevice.StopUpdate();
+ DS4Devices.RemoveDevice(tempDevice);
+ Thread.Sleep(50);
+ }
+
+ CurrentState[i].Battery = PreviousState[i].Battery = 0; // Reset for the next connection's initial status change.
+ x360Bus.Unplug(i);
+ useDInputOnly[i] = true;
+ anyUnplugged = true;
+ DS4Controllers[i] = null;
+ touchPad[i] = null;
+ lag[i] = false;
+ inWarnMonitor[i] = false;
+ }
+ }
+
+ if (anyUnplugged)
+ Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
+
+ x360Bus.UnplugAll();
+ x360Bus.Stop();
+
+ if (showlog)
+ LogDebug(Properties.Resources.StoppingDS4);
+
+ DS4Devices.stopControllers();
+ if (showlog)
+ LogDebug(Properties.Resources.StoppedDS4Windows);
+ }
+
+ runHotPlug = false;
+ return true;
+ }
+
+ public bool HotPlug(SynchronizationContext uiContext)
+ {
+ if (running)
+ {
+ DS4Devices.findControllers();
+ IEnumerable devices = DS4Devices.getDS4Controllers();
+ //foreach (DS4Device device in devices)
+ for (int i = 0, devlen = devices.Count(); i < devlen; i++)
+ {
+ DS4Device device = devices.ElementAt(i);
+
+ if (device.isDisconnectingStatus())
+ continue;
+
+ if (((Func)delegate
+ {
+ for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++)
+ {
+ if (DS4Controllers[Index] != null &&
+ DS4Controllers[Index].getMacAddress() == device.getMacAddress())
+ return true;
+ }
+
+ return false;
+ })())
+ {
+ continue;
+ }
+
+ for (Int32 Index = 0, arlength = DS4Controllers.Length; Index < arlength; Index++)
+ {
+ if (DS4Controllers[Index] == null)
+ {
+ LogDebug(Properties.Resources.FoundController + device.getMacAddress() + " (" + device.getConnectionType() + ")");
+ Task task = new Task(() => { Thread.Sleep(5); WarnExclusiveModeFailure(device); });
+ task.Start();
+ DS4Controllers[Index] = device;
+ device.setUiContext(uiContext);
+ device.Removal += this.On_DS4Removal;
+ device.Removal += DS4Devices.On_Removal;
+ device.SyncChange += this.On_SyncChange;
+ device.SyncChange += DS4Devices.UpdateSerial;
+ device.SerialChange += this.On_SerialChange;
+ if (device.isValidSerial() && containsLinkedProfile(device.getMacAddress()))
+ {
+ ProfilePath[Index] = getLinkedProfile(device.getMacAddress());
+ }
+ else
+ {
+ ProfilePath[Index] = OlderProfilePath[Index];
+ }
+
+ LoadProfile(Index, false, this, false, false);
+ touchPad[Index] = new Mouse(Index, device);
+ device.LightBarColor = getMainColor(Index);
+
+ int tempIdx = Index;
+ device.Report += (sender, e) =>
+ {
+ this.On_Report(sender, e, tempIdx);
+ };
+ if (!getDInputOnly(Index) && device.isSynced())
+ {
+ int xinputIndex = x360Bus.FirstController + Index;
+ LogDebug("Plugging in X360 Controller #" + xinputIndex);
+ bool xinputResult = x360Bus.Plugin(Index);
+ if (xinputResult)
+ {
+ useDInputOnly[Index] = false;
+ LogDebug("X360 Controller # " + xinputIndex + " connected");
+ }
+ else
+ {
+ useDInputOnly[Index] = true;
+ LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
+ }
+ }
+
+ TouchPadOn(Index, device);
+ CheckProfileOptions(Index, device);
+ device.StartUpdate();
+
+ //string filename = Path.GetFileName(ProfilePath[Index]);
+ if (File.Exists(appdatapath + "\\Profiles\\" + ProfilePath[Index] + ".xml"))
+ {
+ string prolog = Properties.Resources.UsingProfile.Replace("*number*", (Index + 1).ToString()).Replace("*Profile name*", ProfilePath[Index]);
+ LogDebug(prolog);
+ Log.LogToTray(prolog);
+ }
+ else
+ {
+ string prolog = Properties.Resources.NotUsingProfile.Replace("*number*", (Index + 1).ToString());
+ LogDebug(prolog);
+ Log.LogToTray(prolog);
+ }
+
+ break;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ private void CheckProfileOptions(int ind, DS4Device device, bool startUp=false)
+ {
+ device.setIdleTimeout(getIdleDisconnectTimeout(ind));
+ device.setBTPollRate(getBTPollRate(ind));
+ touchPad[ind].ResetTrackAccel(getTrackballFriction(ind));
+
+ if (!startUp)
+ {
+ CheckLauchProfileOption(ind, device);
+ }
+ }
+
+ private void CheckLauchProfileOption(int ind, DS4Device device)
+ {
+ string programPath = LaunchProgram[ind];
+ if (programPath != string.Empty)
+ {
+ System.Diagnostics.Process[] localAll = System.Diagnostics.Process.GetProcesses();
+ bool procFound = false;
+ for (int procInd = 0, procsLen = localAll.Length; !procFound && procInd < procsLen; procInd++)
+ {
+ try
+ {
+ string temp = localAll[procInd].MainModule.FileName;
+ if (temp == programPath)
+ {
+ procFound = true;
+ }
+ }
+ // Ignore any process for which this information
+ // is not exposed
+ catch { }
+ }
+
+ if (!procFound)
+ {
+ Task processTask = new Task(() =>
+ {
+ Thread.Sleep(5000);
+ System.Diagnostics.Process tempProcess = new System.Diagnostics.Process();
+ tempProcess.StartInfo.FileName = programPath;
+ tempProcess.StartInfo.WorkingDirectory = new FileInfo(programPath).Directory.ToString();
+ //tempProcess.StartInfo.UseShellExecute = false;
+ try { tempProcess.Start(); }
+ catch { }
+ });
+
+ processTask.Start();
+ }
+ }
+ }
+
+ public void TouchPadOn(int ind, DS4Device device)
+ {
+ ITouchpadBehaviour tPad = touchPad[ind];
+ device.Touchpad.TouchButtonDown += tPad.touchButtonDown;
+ device.Touchpad.TouchButtonUp += tPad.touchButtonUp;
+ device.Touchpad.TouchesBegan += tPad.touchesBegan;
+ device.Touchpad.TouchesMoved += tPad.touchesMoved;
+ device.Touchpad.TouchesEnded += tPad.touchesEnded;
+ device.Touchpad.TouchUnchanged += tPad.touchUnchanged;
+ //device.Touchpad.PreTouchProcess += delegate { touchPad[ind].populatePriorButtonStates(); };
+ device.Touchpad.PreTouchProcess += (sender, args) => { touchPad[ind].populatePriorButtonStates(); };
+ device.SixAxis.SixAccelMoved += tPad.sixaxisMoved;
+ //LogDebug("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
+ //Log.LogToTray("Touchpad mode for " + device.MacAddress + " is now " + tmode.ToString());
+ }
+
+ public string getDS4ControllerInfo(int index)
+ {
+ DS4Device d = DS4Controllers[index];
+ if (d != null)
+ {
+ if (!d.IsAlive())
+ {
+ return Properties.Resources.Connecting;
+ }
+
+ string battery;
+ if (d.isCharging())
+ {
+ if (d.getBattery() >= 100)
+ battery = Properties.Resources.Charged;
+ else
+ battery = Properties.Resources.Charging.Replace("*number*", d.getBattery().ToString());
+ }
+ else
+ {
+ battery = Properties.Resources.Battery.Replace("*number*", d.getBattery().ToString());
+ }
+
+ return d.getMacAddress() + " (" + d.getConnectionType() + "), " + battery;
+ //return d.MacAddress + " (" + d.ConnectionType + "), Battery is " + battery + ", Touchpad in " + modeSwitcher[index].ToString();
+ }
+ else
+ return string.Empty;
+ }
+
+ public string getDS4MacAddress(int index)
+ {
+ DS4Device d = DS4Controllers[index];
+ if (d != null)
+ {
+ if (!d.IsAlive())
+ {
+ return Properties.Resources.Connecting;
+ }
+
+ return d.getMacAddress();
+ }
+ else
+ return string.Empty;
+ }
+
+ public string getShortDS4ControllerInfo(int index)
+ {
+ DS4Device d = DS4Controllers[index];
+ if (d != null)
+ {
+ string battery;
+ if (!d.IsAlive())
+ battery = "...";
+
+ if (d.isCharging())
+ {
+ if (d.getBattery() >= 100)
+ battery = Properties.Resources.Full;
+ else
+ battery = d.getBattery() + "%+";
+ }
+ else
+ {
+ battery = d.getBattery() + "%";
+ }
+
+ return (d.getConnectionType() + " " + battery);
+ }
+ else
+ return Properties.Resources.NoneText;
+ }
+
+ public string getDS4Battery(int index)
+ {
+ DS4Device d = DS4Controllers[index];
+ if (d != null)
+ {
+ string battery;
+ if (!d.IsAlive())
+ battery = "...";
+
+ if (d.isCharging())
+ {
+ if (d.getBattery() >= 100)
+ battery = Properties.Resources.Full;
+ else
+ battery = d.getBattery() + "%+";
+ }
+ else
+ {
+ battery = d.getBattery() + "%";
+ }
+
+ return battery;
+ }
+ else
+ return Properties.Resources.NA;
+ }
+
+ public string getDS4Status(int index)
+ {
+ DS4Device d = DS4Controllers[index];
+ if (d != null)
+ {
+ return d.getConnectionType() + "";
+ }
+ else
+ return Properties.Resources.NoneText;
+ }
+
+ protected void On_SerialChange(object sender, EventArgs e)
+ {
+ DS4Device device = (DS4Device)sender;
+ int ind = -1;
+ for (int i = 0, arlength = DS4_CONTROLLER_COUNT; ind == -1 && i < arlength; i++)
+ {
+ DS4Device tempDev = DS4Controllers[i];
+ if (tempDev != null && device == tempDev)
+ ind = i;
+ }
+
+ if (ind >= 0)
+ {
+ OnDeviceSerialChange(this, ind, device.getMacAddress());
+ }
+ }
+
+ protected void On_SyncChange(object sender, EventArgs e)
+ {
+ DS4Device device = (DS4Device)sender;
+ int ind = -1;
+ for (int i = 0, arlength = DS4_CONTROLLER_COUNT; ind == -1 && i < arlength; i++)
+ {
+ DS4Device tempDev = DS4Controllers[i];
+ if (tempDev != null && device == tempDev)
+ ind = i;
+ }
+
+ if (ind >= 0)
+ {
+ bool synced = device.isSynced();
+
+ if (!synced)
+ {
+ if (!useDInputOnly[ind])
+ {
+ bool unplugResult = x360Bus.Unplug(ind);
+ int xinputIndex = x360Bus.FirstController + ind;
+ if (unplugResult)
+ {
+ useDInputOnly[ind] = true;
+ LogDebug("X360 Controller # " + xinputIndex + " unplugged");
+ }
+ else
+ {
+ LogDebug("X360 Controller # " + xinputIndex + " failed to unplug");
+ }
+ }
+ }
+ else
+ {
+ if (!getDInputOnly(ind))
+ {
+ int xinputIndex = x360Bus.FirstController + ind;
+ LogDebug("Plugging in X360 Controller #" + xinputIndex);
+ bool xinputResult = x360Bus.Plugin(ind);
+ if (xinputResult)
+ {
+ useDInputOnly[ind] = false;
+ LogDebug("X360 Controller # " + xinputIndex + " connected");
+ }
+ else
+ {
+ useDInputOnly[ind] = true;
+ LogDebug("X360 Controller # " + xinputIndex + " failed. Using DInput only mode");
+ }
+ }
+ }
+ }
+ }
+
+ //Called when DS4 is disconnected or timed out
+ protected virtual void On_DS4Removal(object sender, EventArgs e)
+ {
+ DS4Device device = (DS4Device)sender;
+ int ind = -1;
+ for (int i = 0, arlength = DS4Controllers.Length; ind == -1 && i < arlength; i++)
+ {
+ if (DS4Controllers[i] != null && device.getMacAddress() == DS4Controllers[i].getMacAddress())
+ ind = i;
+ }
+
+ if (ind != -1)
+ {
+ bool removingStatus = false;
+ lock (device.removeLocker)
+ {
+ if (!device.IsRemoving)
+ {
+ removingStatus = true;
+ device.IsRemoving = true;
+ }
+ }
+
+ if (removingStatus)
+ {
+ CurrentState[ind].Battery = PreviousState[ind].Battery = 0; // Reset for the next connection's initial status change.
+ if (!useDInputOnly[ind])
+ {
+ bool unplugResult = x360Bus.Unplug(ind);
+ int xinputIndex = x360Bus.FirstController + ind;
+ LogDebug("X360 Controller # " + xinputIndex + " unplugged");
+ }
+
+ string removed = Properties.Resources.ControllerWasRemoved.Replace("*Mac address*", (ind + 1).ToString());
+ if (device.getBattery() <= 20 &&
+ device.getConnectionType() == ConnectionType.BT && !device.isCharging())
+ {
+ removed += ". " + Properties.Resources.ChargeController;
+ }
+
+ LogDebug(removed);
+ Log.LogToTray(removed);
+ /*Stopwatch sw = new Stopwatch();
+ sw.Start();
+ while (sw.ElapsedMilliseconds < XINPUT_UNPLUG_SETTLE_TIME)
+ {
+ // Use SpinWait to keep control of current thread. Using Sleep could potentially
+ // cause other events to get run out of order
+ System.Threading.Thread.SpinWait(500);
+ }
+ sw.Stop();
+ */
+
+ device.IsRemoved = true;
+ device.Synced = false;
+ DS4Controllers[ind] = null;
+ touchPad[ind] = null;
+ lag[ind] = false;
+ inWarnMonitor[ind] = false;
+ useDInputOnly[ind] = true;
+ OnControllerRemoved(this, ind);
+ Thread.Sleep(XINPUT_UNPLUG_SETTLE_TIME);
+ }
+ }
+ }
+
+ public bool[] lag = new bool[4] { false, false, false, false };
+ public bool[] inWarnMonitor = new bool[4] { false, false, false, false };
+ private byte[] currentBattery = new byte[4] { 0, 0, 0, 0 };
+ private bool[] charging = new bool[4] { false, false, false, false };
+ private string[] tempStrings = new string[4] { string.Empty, string.Empty, string.Empty, string.Empty };
+
+ // Called every time a new input report has arrived
+ protected virtual void On_Report(object sender, EventArgs e, int ind)
+ {
+ DS4Device device = (DS4Device)sender;
+
+ if (ind != -1)
+ {
+ if (getFlushHIDQueue(ind))
+ device.FlushHID();
+
+ string devError = tempStrings[ind] = device.error;
+ if (!string.IsNullOrEmpty(devError))
+ {
+ device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
+ {
+ LogDebug(devError);
+ }), null);
+ }
+
+ if (inWarnMonitor[ind])
+ {
+ int flashWhenLateAt = getFlashWhenLateAt();
+ if (!lag[ind] && device.Latency >= flashWhenLateAt)
+ {
+ lag[ind] = true;
+ device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
+ {
+ LagFlashWarning(ind, true);
+ }), null);
+ }
+ else if (lag[ind] && device.Latency < flashWhenLateAt)
+ {
+ lag[ind] = false;
+ device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
+ {
+ LagFlashWarning(ind, false);
+ }), null);
+ }
+ }
+ else
+ {
+ if (DateTime.UtcNow - device.firstActive > TimeSpan.FromSeconds(5))
+ {
+ inWarnMonitor[ind] = true;
+ }
+ }
+
+ device.getCurrentState(CurrentState[ind]);
+ DS4State cState = CurrentState[ind];
+ DS4State pState = device.getPreviousStateRef();
+ //device.getPreviousState(PreviousState[ind]);
+ //DS4State pState = PreviousState[ind];
+
+ if (device.firstReport && device.IsAlive())
+ {
+ device.firstReport = false;
+ device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
+ {
+ OnDeviceStatusChanged(this, ind);
+ }), null);
+ }
+ else if (pState.Battery != cState.Battery || device.oldCharging != device.isCharging())
+ {
+ byte tempBattery = currentBattery[ind] = cState.Battery;
+ bool tempCharging = charging[ind] = device.isCharging();
+ device.getUiContext()?.Post(new SendOrPostCallback(delegate (object state)
+ {
+ OnBatteryStatusChange(this, ind, tempBattery, tempCharging);
+ }), null);
+ }
+
+ if (getEnableTouchToggle(ind))
+ CheckForTouchToggle(ind, cState, pState);
+
+ cState = Mapping.SetCurveAndDeadzone(ind, cState, TempState[ind]);
+
+ if (!recordingMacro && (!string.IsNullOrEmpty(tempprofilename[ind]) ||
+ containsCustomAction(ind) || containsCustomExtras(ind) ||
+ getProfileActionCount(ind) > 0))
+ {
+ Mapping.MapCustom(ind, cState, MappedState[ind], ExposedState[ind], touchPad[ind], this);
+ cState = MappedState[ind];
+ }
+
+ if (!useDInputOnly[ind])
+ {
+ x360Bus.Parse(cState, processingData[ind].Report, ind);
+ // We push the translated Xinput state, and simultaneously we
+ // pull back any possible rumble data coming from Xinput consumers.
+ if (x360Bus.Report(processingData[ind].Report, processingData[ind].Rumble))
+ {
+ byte Big = processingData[ind].Rumble[3];
+ byte Small = processingData[ind].Rumble[4];
+
+ if (processingData[ind].Rumble[1] == 0x08)
+ {
+ setRumble(Big, Small, ind);
+ }
+ }
+ }
+
+ // Output any synthetic events.
+ Mapping.Commit(ind);
+
+ // Update the GUI/whatever.
+ DS4LightBar.updateLightBar(device, ind);
+ }
+ }
+
+ public void LagFlashWarning(int ind, bool on)
+ {
+ if (on)
+ {
+ lag[ind] = true;
+ LogDebug(Properties.Resources.LatencyOverTen.Replace("*number*", (ind + 1).ToString()), true);
+ if (getFlashWhenLate())
+ {
+ DS4Color color = new DS4Color { red = 50, green = 0, blue = 0 };
+ DS4LightBar.forcedColor[ind] = color;
+ DS4LightBar.forcedFlash[ind] = 2;
+ DS4LightBar.forcelight[ind] = true;
+ }
+ }
+ else
+ {
+ lag[ind] = false;
+ LogDebug(Properties.Resources.LatencyNotOverTen.Replace("*number*", (ind + 1).ToString()));
+ DS4LightBar.forcelight[ind] = false;
+ DS4LightBar.forcedFlash[ind] = 0;
+ }
+ }
+
+ public DS4Controls GetActiveInputControl(int ind)
+ {
+ DS4State cState = CurrentState[ind];
+ DS4StateExposed eState = ExposedState[ind];
+ Mouse tp = touchPad[ind];
+ DS4Controls result = DS4Controls.None;
+
+ if (DS4Controllers[ind] != null)
+ {
+ if (Mapping.getBoolButtonMapping(cState.Cross))
+ result = DS4Controls.Cross;
+ else if (Mapping.getBoolButtonMapping(cState.Circle))
+ result = DS4Controls.Circle;
+ else if (Mapping.getBoolButtonMapping(cState.Triangle))
+ result = DS4Controls.Triangle;
+ else if (Mapping.getBoolButtonMapping(cState.Square))
+ result = DS4Controls.Square;
+ else if (Mapping.getBoolButtonMapping(cState.L1))
+ result = DS4Controls.L1;
+ else if (Mapping.getBoolTriggerMapping(cState.L2))
+ result = DS4Controls.L2;
+ else if (Mapping.getBoolButtonMapping(cState.L3))
+ result = DS4Controls.L3;
+ else if (Mapping.getBoolButtonMapping(cState.R1))
+ result = DS4Controls.R1;
+ else if (Mapping.getBoolTriggerMapping(cState.R2))
+ result = DS4Controls.R2;
+ else if (Mapping.getBoolButtonMapping(cState.R3))
+ result = DS4Controls.R3;
+ else if (Mapping.getBoolButtonMapping(cState.DpadUp))
+ result = DS4Controls.DpadUp;
+ else if (Mapping.getBoolButtonMapping(cState.DpadDown))
+ result = DS4Controls.DpadDown;
+ else if (Mapping.getBoolButtonMapping(cState.DpadLeft))
+ result = DS4Controls.DpadLeft;
+ else if (Mapping.getBoolButtonMapping(cState.DpadRight))
+ result = DS4Controls.DpadRight;
+ else if (Mapping.getBoolButtonMapping(cState.Share))
+ result = DS4Controls.Share;
+ else if (Mapping.getBoolButtonMapping(cState.Options))
+ result = DS4Controls.Options;
+ else if (Mapping.getBoolButtonMapping(cState.PS))
+ result = DS4Controls.PS;
+ else if (Mapping.getBoolAxisDirMapping(cState.LX, true))
+ result = DS4Controls.LXPos;
+ else if (Mapping.getBoolAxisDirMapping(cState.LX, false))
+ result = DS4Controls.LXNeg;
+ else if (Mapping.getBoolAxisDirMapping(cState.LY, true))
+ result = DS4Controls.LYPos;
+ else if (Mapping.getBoolAxisDirMapping(cState.LY, false))
+ result = DS4Controls.LYNeg;
+ else if (Mapping.getBoolAxisDirMapping(cState.RX, true))
+ result = DS4Controls.RXPos;
+ else if (Mapping.getBoolAxisDirMapping(cState.RX, false))
+ result = DS4Controls.RXNeg;
+ else if (Mapping.getBoolAxisDirMapping(cState.RY, true))
+ result = DS4Controls.RYPos;
+ else if (Mapping.getBoolAxisDirMapping(cState.RY, false))
+ result = DS4Controls.RYNeg;
+ else if (Mapping.getBoolTouchMapping(tp.leftDown))
+ result = DS4Controls.TouchLeft;
+ else if (Mapping.getBoolTouchMapping(tp.rightDown))
+ result = DS4Controls.TouchRight;
+ else if (Mapping.getBoolTouchMapping(tp.multiDown))
+ result = DS4Controls.TouchMulti;
+ else if (Mapping.getBoolTouchMapping(tp.upperDown))
+ result = DS4Controls.TouchUpper;
+ }
+
+ return result;
+ }
+
+ public bool[] touchreleased = new bool[4] { true, true, true, true },
+ touchslid = new bool[4] { false, false, false, false };
+
+ public byte[] oldtouchvalue = new byte[4] { 0, 0, 0, 0 };
+ public int[] oldscrollvalue = new int[4] { 0, 0, 0, 0 };
+
+ protected virtual void CheckForTouchToggle(int deviceID, DS4State cState, DS4State pState)
+ {
+ if (!getUseTPforControls(deviceID) && cState.Touch1 && pState.PS)
+ {
+ if (getTouchSensitivity(deviceID) > 0 && touchreleased[deviceID])
+ {
+ oldtouchvalue[deviceID] = getTouchSensitivity(deviceID);
+ oldscrollvalue[deviceID] = getScrollSensitivity(deviceID);
+ getTouchSensitivity()[deviceID] = 0;
+ getScrollSensitivity()[deviceID] = 0;
+ LogDebug(Properties.Resources.TouchpadMovementOff);
+ Log.LogToTray(Properties.Resources.TouchpadMovementOff);
+ touchreleased[deviceID] = false;
+ }
+ else if (touchreleased[deviceID])
+ {
+ getTouchSensitivity()[deviceID] = oldtouchvalue[deviceID];
+ getScrollSensitivity()[deviceID] = oldscrollvalue[deviceID];
+ LogDebug(Properties.Resources.TouchpadMovementOn);
+ Log.LogToTray(Properties.Resources.TouchpadMovementOn);
+ touchreleased[deviceID] = false;
+ }
+ }
+ else
+ touchreleased[deviceID] = true;
+ }
+
+ public virtual void StartTPOff(int deviceID)
+ {
+ if (deviceID < 4)
+ {
+ oldtouchvalue[deviceID] = getTouchSensitivity(deviceID);
+ oldscrollvalue[deviceID] = getScrollSensitivity(deviceID);
+ TouchSensitivity[deviceID] = 0;
+ ScrollSensitivity[deviceID] = 0;
+ }
+ }
+
+ public virtual string TouchpadSlide(int ind)
+ {
+ DS4State cState = CurrentState[ind];
+ string slidedir = "none";
+ if (DS4Controllers[ind] != null && cState.Touch2 &&
+ !(touchPad[ind].dragging || touchPad[ind].dragging2))
+ {
+ if (touchPad[ind].slideright && !touchslid[ind])
+ {
+ slidedir = "right";
+ touchslid[ind] = true;
+ }
+ else if (touchPad[ind].slideleft && !touchslid[ind])
+ {
+ slidedir = "left";
+ touchslid[ind] = true;
+ }
+ else if (!touchPad[ind].slideleft && !touchPad[ind].slideright)
+ {
+ slidedir = "";
+ touchslid[ind] = false;
+ }
+ }
+
+ return slidedir;
+ }
+
+ public virtual void LogDebug(String Data, bool warning = false)
+ {
+ //Console.WriteLine(System.DateTime.Now.ToString("G") + "> " + Data);
+ if (Debug != null)
+ {
+ DebugEventArgs args = new DebugEventArgs(Data, warning);
+ OnDebug(this, args);
+ }
+ }
+
+ public virtual void OnDebug(object sender, DebugEventArgs args)
+ {
+ if (Debug != null)
+ Debug(this, args);
+ }
+
+ //sets the rumble adjusted with rumble boost
+ public virtual void setRumble(byte heavyMotor, byte lightMotor, int deviceNum)
+ {
+ byte boost = getRumbleBoost(deviceNum);
+ uint lightBoosted = ((uint)lightMotor * (uint)boost) / 100;
+ if (lightBoosted > 255)
+ lightBoosted = 255;
+ uint heavyBoosted = ((uint)heavyMotor * (uint)boost) / 100;
+ if (heavyBoosted > 255)
+ heavyBoosted = 255;
+
+ if (deviceNum < 4)
+ {
+ DS4Device device = DS4Controllers[deviceNum];
+ if (device != null)
+ device.setRumble((byte)lightBoosted, (byte)heavyBoosted);
+ }
+ }
+
+ public DS4State getDS4State(int ind)
+ {
+ return CurrentState[ind];
+ }
+
+ public DS4State getDS4StateMapped(int ind)
+ {
+ return MappedState[ind];
+ }
+ }
+}
diff --git a/DS4Windows/DS4Control/DS4LightBar.cs b/DS4Windows/DS4Control/DS4LightBar.cs
index 98483a3..d06b91c 100644
--- a/DS4Windows/DS4Control/DS4LightBar.cs
+++ b/DS4Windows/DS4Control/DS4LightBar.cs
@@ -1,10 +1,9 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Drawing;
using static System.Math;
using static DS4Windows.Global;
+using System.Diagnostics;
+
namespace DS4Windows
{
public class DS4LightBar
@@ -19,128 +18,222 @@ namespace DS4Windows
{ 140, 140 },
{ 168, 112 },
{ 196, 84 },
- { 224, 56}, // on 80% of the time at 80, etc.
+ { 224, 56 }, // on 80% of the time at 80, etc.
{ 252, 28 } // on 90% of the time at 90
};
+
static double[] counters = new double[4] { 0, 0, 0, 0 };
- public static double[] fadetimer = new double[4] { 0, 0, 0, 0 };
+ public static Stopwatch[] fadewatches = new Stopwatch[4]
+ { new Stopwatch(), new Stopwatch(), new Stopwatch(), new Stopwatch() };
+
static bool[] fadedirection = new bool[4] { false, false, false, false };
- static DateTime oldnow = DateTime.UtcNow;
+ static DateTime[] oldnow = new DateTime[4]
+ { DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow, DateTime.UtcNow };
+
public static bool[] forcelight = new bool[4] { false, false, false, false };
public static DS4Color[] forcedColor = new DS4Color[4];
public static byte[] forcedFlash = new byte[4];
- public static void updateLightBar(DS4Device device, int deviceNum, DS4State cState, DS4StateExposed eState, Mouse tp)
+ internal const int PULSE_FLASH_DURATION = 2000;
+ internal const double PULSE_FLASH_SEGMENTS = PULSE_FLASH_DURATION / 40;
+ internal const int PULSE_CHARGING_DURATION = 4000;
+ internal const double PULSE_CHARGING_SEGMENTS = (PULSE_CHARGING_DURATION / 40) - 2;
+
+ public static void updateLightBar(DS4Device device, int deviceNum)
{
DS4Color color;
- if (!defualtLight && !forcelight[deviceNum])
+ if (!defaultLight && !forcelight[deviceNum])
{
- if (UseCustomLed[deviceNum])
+ if (getUseCustomLed(deviceNum))
{
- if (LedAsBatteryIndicator[deviceNum])
+ if (getLedAsBatteryIndicator(deviceNum))
{
- DS4Color fullColor = CustomColor[deviceNum];
- DS4Color lowColor = LowColor[deviceNum];
-
- color = getTransitionedColor(lowColor, fullColor, device.Battery);
+ DS4Color fullColor = getCustomColor(deviceNum);
+ DS4Color lowColor = getLowColor(deviceNum);
+ color = getTransitionedColor(lowColor, fullColor, device.getBattery());
}
else
- color = CustomColor[deviceNum];
+ color = getCustomColor(deviceNum);
}
else
{
- if (Rainbow[deviceNum] > 0)
- {// Display rainbow
+ double rainbow = getRainbow(deviceNum);
+ if (rainbow > 0)
+ {
+ // Display rainbow
DateTime now = DateTime.UtcNow;
- if (now >= oldnow + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
+ if (now >= oldnow[deviceNum] + TimeSpan.FromMilliseconds(10)) //update by the millisecond that way it's a smooth transtion
{
- oldnow = now;
- if (device.Charging)
- counters[deviceNum] -= 1.5 * 3 / Rainbow[deviceNum];
+ oldnow[deviceNum] = now;
+ if (device.isCharging())
+ counters[deviceNum] -= 1.5 * 3 / rainbow;
else
- counters[deviceNum] += 1.5 * 3 / Rainbow[deviceNum];
+ counters[deviceNum] += 1.5 * 3 / rainbow;
}
+
if (counters[deviceNum] < 0)
counters[deviceNum] = 180000;
- if (counters[deviceNum] > 180000)
+ else if (counters[deviceNum] > 180000)
counters[deviceNum] = 0;
- if (LedAsBatteryIndicator[deviceNum])
- color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(2.55 * device.Battery));
+
+ if (getLedAsBatteryIndicator(deviceNum))
+ color = HuetoRGB((float)counters[deviceNum] % 360, (byte)(device.getBattery() * 2.55));
else
color = HuetoRGB((float)counters[deviceNum] % 360, 255);
}
- else if (LedAsBatteryIndicator[deviceNum])
+ else if (getLedAsBatteryIndicator(deviceNum))
{
- //if (device.Charging == false || device.Battery >= 100) // when charged, don't show the charging animation
- {
- DS4Color fullColor = MainColor[deviceNum];
- DS4Color lowColor = LowColor[deviceNum];
-
- color = getTransitionedColor(lowColor, fullColor, (uint)device.Battery);
- }
+ DS4Color fullColor = getMainColor(deviceNum);
+ DS4Color lowColor = getLowColor(deviceNum);
+ color = getTransitionedColor(lowColor, fullColor, device.getBattery());
}
else
{
- color = MainColor[deviceNum];
+ color = getMainColor(deviceNum);
}
-
}
- if (device.Battery <= FlashAt[deviceNum] && !defualtLight && !device.Charging)
+ if (device.getBattery() <= getFlashAt(deviceNum) && !defaultLight && !device.isCharging())
{
- if (!(FlashColor[deviceNum].red == 0 &&
- FlashColor[deviceNum].green == 0 &&
- FlashColor[deviceNum].blue == 0))
- color = FlashColor[deviceNum];
- if (FlashType[deviceNum] == 1)
+ DS4Color flashColor = getFlashColor(deviceNum);
+ if (!(flashColor.red == 0 &&
+ flashColor.green == 0 &&
+ flashColor.blue == 0))
+ color = flashColor;
+
+ if (getFlashType(deviceNum) == 1)
{
- if (fadetimer[deviceNum] <= 0)
- fadedirection[deviceNum] = true;
- else if (fadetimer[deviceNum] >= 100)
- fadedirection[deviceNum] = false;
- if (fadedirection[deviceNum])
- fadetimer[deviceNum] += 1;
+ double ratio = 0.0;
+
+ if (!fadewatches[deviceNum].IsRunning)
+ {
+ bool temp = fadedirection[deviceNum];
+ fadedirection[deviceNum] = !temp;
+ fadewatches[deviceNum].Restart();
+ ratio = temp ? 100.0 : 0.0;
+ }
else
- fadetimer[deviceNum] -= 1;
- color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
+ {
+ long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;
+
+ if (fadedirection[deviceNum])
+ {
+ if (elapsed < PULSE_FLASH_DURATION)
+ {
+ elapsed = elapsed / 40;
+ ratio = 100.0 * (elapsed / PULSE_FLASH_SEGMENTS);
+ }
+ else
+ {
+ ratio = 100.0;
+ fadewatches[deviceNum].Stop();
+ }
+ }
+ else
+ {
+ if (elapsed < PULSE_FLASH_DURATION)
+ {
+ elapsed = elapsed / 40;
+ ratio = (0 - 100.0) * (elapsed / PULSE_FLASH_SEGMENTS) + 100.0;
+ }
+ else
+ {
+ ratio = 0.0;
+ fadewatches[deviceNum].Stop();
+ }
+ }
+ }
+
+ color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio);
}
}
- if (IdleDisconnectTimeout[deviceNum] > 0 && LedAsBatteryIndicator[deviceNum] && (!device.Charging || device.Battery >= 100))
- {//Fade lightbar by idle time
+ int idleDisconnectTimeout = getIdleDisconnectTimeout(deviceNum);
+ if (idleDisconnectTimeout > 0 && getLedAsBatteryIndicator(deviceNum) &&
+ (!device.isCharging() || device.getBattery() >= 100))
+ {
+ //Fade lightbar by idle time
TimeSpan timeratio = new TimeSpan(DateTime.UtcNow.Ticks - device.lastActive.Ticks);
double botratio = timeratio.TotalMilliseconds;
- double topratio = TimeSpan.FromSeconds(IdleDisconnectTimeout[deviceNum]).TotalMilliseconds;
- double ratio = ((botratio / topratio) * 100);
- if (ratio >= 50 && ratio <= 100)
- color = getTransitionedColor(color, new DS4Color(0, 0, 0), (uint)((ratio - 50) * 2));
- else if (ratio >= 100)
- color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100);
+ double topratio = TimeSpan.FromSeconds(idleDisconnectTimeout).TotalMilliseconds;
+ double ratio = 100.0 * (botratio / topratio), elapsed = ratio;
+ if (ratio >= 50.0 && ratio < 100.0)
+ {
+ color = getTransitionedColor(color, new DS4Color(0, 0, 0),
+ (uint)(-100.0 * (elapsed = 0.02 * (ratio - 50.0)) * (elapsed - 2.0)));
+ }
+ else if (ratio >= 100.0)
+ color = getTransitionedColor(color, new DS4Color(0, 0, 0), 100.0);
}
- if (device.Charging && device.Battery < 100)
- switch (ChargingType[deviceNum])
+
+ if (device.isCharging() && device.getBattery() < 100)
+ {
+ switch (getChargingType(deviceNum))
{
case 1:
- if (fadetimer[deviceNum] <= 0)
- fadedirection[deviceNum] = true;
- else if (fadetimer[deviceNum] >= 105)
- fadedirection[deviceNum] = false;
- if (fadedirection[deviceNum])
- fadetimer[deviceNum] += .1;
+ {
+ double ratio = 0.0;
+
+ if (!fadewatches[deviceNum].IsRunning)
+ {
+ bool temp = fadedirection[deviceNum];
+ fadedirection[deviceNum] = !temp;
+ fadewatches[deviceNum].Restart();
+ ratio = temp ? 100.0 : 0.0;
+ }
else
- fadetimer[deviceNum] -= .1;
- color = getTransitionedColor(color, new DS4Color(0, 0, 0), fadetimer[deviceNum]);
+ {
+ long elapsed = fadewatches[deviceNum].ElapsedMilliseconds;
+
+ if (fadedirection[deviceNum])
+ {
+ if (elapsed < PULSE_CHARGING_DURATION)
+ {
+ elapsed = elapsed / 40;
+ if (elapsed > PULSE_CHARGING_SEGMENTS)
+ elapsed = (long)PULSE_CHARGING_SEGMENTS;
+ ratio = 100.0 * (elapsed / PULSE_CHARGING_SEGMENTS);
+ }
+ else
+ {
+ ratio = 100.0;
+ fadewatches[deviceNum].Stop();
+ }
+ }
+ else
+ {
+ if (elapsed < PULSE_CHARGING_DURATION)
+ {
+ elapsed = elapsed / 40;
+ if (elapsed > PULSE_CHARGING_SEGMENTS)
+ elapsed = (long)PULSE_CHARGING_SEGMENTS;
+ ratio = (0 - 100.0) * (elapsed / PULSE_CHARGING_SEGMENTS) + 100.0;
+ }
+ else
+ {
+ ratio = 0.0;
+ fadewatches[deviceNum].Stop();
+ }
+ }
+ }
+
+ color = getTransitionedColor(color, new DS4Color(0, 0, 0), ratio);
break;
+ }
case 2:
- counters[deviceNum] += .167;
+ {
+ counters[deviceNum] += 0.167;
color = HuetoRGB((float)counters[deviceNum] % 360, 255);
break;
+ }
case 3:
- color = ChargingColor[deviceNum];
- break;
- default:
+ {
+ color = getChargingColor(deviceNum);
break;
+ }
+ default: break;
}
+ }
}
else if (forcelight[deviceNum])
{
@@ -150,25 +243,30 @@ namespace DS4Windows
color = new DS4Color(0, 0, 0);
else
{
- if (device.ConnectionType == ConnectionType.BT)
+ if (device.getConnectionType() == ConnectionType.BT)
color = new DS4Color(32, 64, 64);
else
color = new DS4Color(0, 0, 0);
}
- bool distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance"));
- if (distanceprofile && !defualtLight)
- { //Thing I did for Distance
- float rumble = device.LeftHeavySlowRumble / 2.55f;
+
+ bool distanceprofile = DistanceProfiles[deviceNum] || tempprofileDistance[deviceNum];
+ //distanceprofile = (ProfilePath[deviceNum].ToLower().Contains("distance") || tempprofilename[deviceNum].ToLower().Contains("distance"));
+ if (distanceprofile && !defaultLight)
+ {
+ // Thing I did for Distance
+ float rumble = device.getLeftHeavySlowRumble() / 2.55f;
byte max = Max(color.red, Max(color.green, color.blue));
- if (device.LeftHeavySlowRumble > 100)
+ if (device.getLeftHeavySlowRumble() > 100)
color = getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), rumble);
else
- color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.LeftHeavySlowRumble);
+ color = getTransitionedColor(color, getTransitionedColor(new DS4Color(max, max, 0), new DS4Color(255, 0, 0), 39.6078f), device.getLeftHeavySlowRumble());
}
+
DS4HapticState haptics = new DS4HapticState
{
LightBarColor = color
};
+
if (haptics.IsLightBarSet())
{
if (forcelight[deviceNum] && forcedFlash[deviceNum] > 0)
@@ -176,17 +274,18 @@ namespace DS4Windows
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)(25 - forcedFlash[deviceNum]);
haptics.LightBarExplicitlyOff = true;
}
- else if (device.Battery <= FlashAt[deviceNum] && FlashType[deviceNum] == 0 && !defualtLight && !device.Charging)
+ else if (device.getBattery() <= getFlashAt(deviceNum) && getFlashType(deviceNum) == 0 && !defaultLight && !device.isCharging())
{
- int level = device.Battery / 10;
- //if (level >= 10)
- //level = 0; // all values of ~0% or >~100% are rendered the same
+ int level = device.getBattery() / 10;
+ if (level >= 10)
+ level = 0; // all values of ~0% or >~100% are rendered the same
+
haptics.LightBarFlashDurationOn = BatteryIndicatorDurations[level, 0];
haptics.LightBarFlashDurationOff = BatteryIndicatorDurations[level, 1];
}
- else if (distanceprofile && device.LeftHeavySlowRumble > 155) //also part of Distance
+ else if (distanceprofile && device.getLeftHeavySlowRumble() > 155) //also part of Distance
{
- haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.LeftHeavySlowRumble + 265));
+ haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = (byte)((-device.getLeftHeavySlowRumble() + 265));
haptics.LightBarExplicitlyOff = true;
}
else
@@ -200,14 +299,15 @@ namespace DS4Windows
{
haptics.LightBarExplicitlyOff = true;
}
- if (device.LightBarOnDuration != haptics.LightBarFlashDurationOn && device.LightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
+
+ byte tempLightBarOnDuration = device.getLightBarOnDuration();
+ if (tempLightBarOnDuration != haptics.LightBarFlashDurationOn && tempLightBarOnDuration != 1 && haptics.LightBarFlashDurationOn == 0)
haptics.LightBarFlashDurationOff = haptics.LightBarFlashDurationOn = 1;
- if (device.LightBarOnDuration == 1) //helps better reset the color
- System.Threading.Thread.Sleep(5);
- device.pushHapticState(haptics);
+
+ device.pushHapticState(ref haptics);
}
- public static bool defualtLight = false, shuttingdown = false;
+ public static bool defaultLight = false, shuttingdown = false;
public static DS4Color HuetoRGB(float hue, byte sat)
{
diff --git a/DS4Windows/DS4Control/DS4StateFieldMapping.cs b/DS4Windows/DS4Control/DS4StateFieldMapping.cs
new file mode 100644
index 0000000..2eb3daa
--- /dev/null
+++ b/DS4Windows/DS4Control/DS4StateFieldMapping.cs
@@ -0,0 +1,155 @@
+
+namespace DS4Windows
+{
+ public class DS4StateFieldMapping
+ {
+ public enum ControlType: int { Unknown = 0, Button, AxisDir, Trigger, Touch, GyroDir, SwipeDir }
+
+ public bool[] buttons = new bool[(int)DS4Controls.SwipeDown + 1];
+ public byte[] axisdirs = new byte[(int)DS4Controls.SwipeDown + 1];
+ public byte[] triggers = new byte[(int)DS4Controls.SwipeDown + 1];
+ public int[] gryodirs = new int[(int)DS4Controls.SwipeDown + 1];
+ public byte[] swipedirs = new byte[(int)DS4Controls.SwipeDown + 1];
+ public bool[] swipedirbools = new bool[(int)DS4Controls.SwipeDown + 1];
+
+ public static ControlType[] mappedType = new ControlType[38] { ControlType.Unknown, // DS4Controls.None
+ ControlType.AxisDir, // DS4Controls.LXNeg
+ ControlType.AxisDir, // DS4Controls.LXPos
+ ControlType.AxisDir, // DS4Controls.LYNeg
+ ControlType.AxisDir, // DS4Controls.LYPos
+ ControlType.AxisDir, // DS4Controls.RXNeg
+ ControlType.AxisDir, // DS4Controls.RXPos
+ ControlType.AxisDir, // DS4Controls.RYNeg
+ ControlType.AxisDir, // DS4Controls.RYPos
+ ControlType.Button, // DS4Controls.L1
+ ControlType.Trigger, // DS4Controls.L2
+ ControlType.Button, // DS4Controls.L3
+ ControlType.Button, // DS4Controls.R1
+ ControlType.Trigger, // DS4Controls.R2
+ ControlType.Button, // DS4Controls.R3
+ ControlType.Button, // DS4Controls.Square
+ ControlType.Button, // DS4Controls.Triangle
+ ControlType.Button, // DS4Controls.Circle
+ ControlType.Button, // DS4Controls.Cross
+ ControlType.Button, // DS4Controls.DpadUp
+ ControlType.Button, // DS4Controls.DpadRight
+ ControlType.Button, // DS4Controls.DpadDown
+ ControlType.Button, // DS4Controls.DpadLeft
+ ControlType.Button, // DS4Controls.PS
+ ControlType.Touch, // DS4Controls.TouchLeft
+ ControlType.Touch, // DS4Controls.TouchUpper
+ ControlType.Touch, // DS4Controls.TouchMulti
+ ControlType.Touch, // DS4Controls.TouchRight
+ ControlType.Button, // DS4Controls.Share
+ ControlType.Button, // DS4Controls.Options
+ ControlType.GyroDir, // DS4Controls.GyroXPos
+ ControlType.GyroDir, // DS4Controls.GyroXNeg
+ ControlType.GyroDir, // DS4Controls.GyroZPos
+ ControlType.GyroDir, // DS4Controls.GyroZNeg
+ ControlType.SwipeDir, // DS4Controls.SwipeLeft
+ ControlType.SwipeDir, // DS4Controls.SwipeRight
+ ControlType.SwipeDir, // DS4Controls.SwipeUp
+ ControlType.SwipeDir, // DS4Controls.SwipeDown
+ };
+
+ public DS4StateFieldMapping()
+ {
+ }
+
+ public DS4StateFieldMapping(DS4State cState, DS4StateExposed exposeState, Mouse tp, bool priorMouse=false)
+ {
+ populateFieldMapping(cState, exposeState, tp, priorMouse);
+ }
+
+ public void populateFieldMapping(DS4State cState, DS4StateExposed exposeState, Mouse tp, bool priorMouse = false)
+ {
+ axisdirs[(int)DS4Controls.LXNeg] = cState.LX;
+ axisdirs[(int)DS4Controls.LXPos] = cState.LX;
+ axisdirs[(int)DS4Controls.LYNeg] = cState.LY;
+ axisdirs[(int)DS4Controls.LYPos] = cState.LY;
+
+ axisdirs[(int)DS4Controls.RXNeg] = cState.RX;
+ axisdirs[(int)DS4Controls.RXPos] = cState.RX;
+ axisdirs[(int)DS4Controls.RYNeg] = cState.RY;
+ axisdirs[(int)DS4Controls.RYPos] = cState.RY;
+
+ triggers[(int)DS4Controls.L2] = cState.L2;
+ triggers[(int)DS4Controls.R2] = cState.R2;
+
+ buttons[(int)DS4Controls.L1] = cState.L1;
+ buttons[(int)DS4Controls.L3] = cState.L3;
+ buttons[(int)DS4Controls.R1] = cState.R1;
+ buttons[(int)DS4Controls.R3] = cState.R3;
+
+ buttons[(int)DS4Controls.Cross] = cState.Cross;
+ buttons[(int)DS4Controls.Triangle] = cState.Triangle;
+ buttons[(int)DS4Controls.Circle] = cState.Circle;
+ buttons[(int)DS4Controls.Square] = cState.Square;
+ buttons[(int)DS4Controls.PS] = cState.PS;
+ buttons[(int)DS4Controls.Options] = cState.Options;
+ buttons[(int)DS4Controls.Share] = cState.Share;
+
+ buttons[(int)DS4Controls.DpadUp] = cState.DpadUp;
+ buttons[(int)DS4Controls.DpadRight] = cState.DpadRight;
+ buttons[(int)DS4Controls.DpadDown] = cState.DpadDown;
+ buttons[(int)DS4Controls.DpadLeft] = cState.DpadLeft;
+
+ buttons[(int)DS4Controls.TouchLeft] = tp != null ? (!priorMouse ? tp.leftDown : tp.priorLeftDown) : false;
+ buttons[(int)DS4Controls.TouchRight] = tp != null ? (!priorMouse ? tp.rightDown : tp.priorRightDown) : false;
+ buttons[(int)DS4Controls.TouchUpper] = tp != null ? (!priorMouse ? tp.upperDown : tp.priorUpperDown) : false;
+ buttons[(int)DS4Controls.TouchMulti] = tp != null ? (!priorMouse ? tp.multiDown : tp.priorMultiDown) : false;
+
+ int sixAxisX = -exposeState.getOutputAccelX();
+ gryodirs[(int)DS4Controls.GyroXPos] = sixAxisX > 0 ? sixAxisX : 0;
+ gryodirs[(int)DS4Controls.GyroXNeg] = sixAxisX < 0 ? sixAxisX : 0;
+
+ int sixAxisZ = exposeState.getOutputAccelZ();
+ gryodirs[(int)DS4Controls.GyroZPos] = sixAxisZ > 0 ? sixAxisZ : 0;
+ gryodirs[(int)DS4Controls.GyroZNeg] = sixAxisZ < 0 ? sixAxisZ : 0;
+
+ swipedirs[(int)DS4Controls.SwipeLeft] = tp != null ? (!priorMouse ? tp.swipeLeftB : tp.priorSwipeLeftB) : (byte)0;
+ swipedirs[(int)DS4Controls.SwipeRight] = tp != null ? (!priorMouse ? tp.swipeRightB : tp.priorSwipeRightB) : (byte)0;
+ swipedirs[(int)DS4Controls.SwipeUp] = tp != null ? (!priorMouse ? tp.swipeUpB : tp.priorSwipeUpB) : (byte)0;
+ swipedirs[(int)DS4Controls.SwipeDown] = tp != null ? (!priorMouse ? tp.swipeDownB : tp.priorSwipeDownB) : (byte)0;
+
+ swipedirbools[(int)DS4Controls.SwipeLeft] = tp != null ? (!priorMouse ? tp.swipeLeft : tp.priorSwipeLeft) : false;
+ swipedirbools[(int)DS4Controls.SwipeRight] = tp != null ? (!priorMouse ? tp.swipeRight : tp.priorSwipeRight) : false;
+ swipedirbools[(int)DS4Controls.SwipeUp] = tp != null ? (!priorMouse ? tp.swipeUp : tp.priorSwipeUp) : false;
+ swipedirbools[(int)DS4Controls.SwipeDown] = tp != null ? (!priorMouse ? tp.swipeDown : tp.priorSwipeDown) : false;
+ }
+
+ public void populateState(DS4State state)
+ {
+ state.LX = axisdirs[(int)DS4Controls.LXNeg];
+ state.LX = axisdirs[(int)DS4Controls.LXPos];
+ state.LY = axisdirs[(int)DS4Controls.LYNeg];
+ state.LY = axisdirs[(int)DS4Controls.LYPos];
+
+ state.RX = axisdirs[(int)DS4Controls.RXNeg];
+ state.RX = axisdirs[(int)DS4Controls.RXPos];
+ state.RY = axisdirs[(int)DS4Controls.RYNeg];
+ state.RY = axisdirs[(int)DS4Controls.RYPos];
+
+ state.L2 = triggers[(int)DS4Controls.L2];
+ state.R2 = triggers[(int)DS4Controls.R2];
+
+ state.L1 = buttons[(int)DS4Controls.L1];
+ state.L3 = buttons[(int)DS4Controls.L3];
+ state.R1 = buttons[(int)DS4Controls.R1];
+ state.R3 = buttons[(int)DS4Controls.R3];
+
+ state.Cross = buttons[(int)DS4Controls.Cross];
+ state.Triangle = buttons[(int)DS4Controls.Triangle];
+ state.Circle = buttons[(int)DS4Controls.Circle];
+ state.Square = buttons[(int)DS4Controls.Square];
+ state.PS = buttons[(int)DS4Controls.PS];
+ state.Options = buttons[(int)DS4Controls.Options];
+ state.Share = buttons[(int)DS4Controls.Share];
+
+ state.DpadUp = buttons[(int)DS4Controls.DpadUp];
+ state.DpadRight = buttons[(int)DS4Controls.DpadRight];
+ state.DpadDown = buttons[(int)DS4Controls.DpadDown];
+ state.DpadLeft = buttons[(int)DS4Controls.DpadLeft];
+ }
+ }
+}
diff --git a/DS4Windows/DS4Control/ITouchpadBehaviour.cs b/DS4Windows/DS4Control/ITouchpadBehaviour.cs
index 24a5ee7..d175391 100644
--- a/DS4Windows/DS4Control/ITouchpadBehaviour.cs
+++ b/DS4Windows/DS4Control/ITouchpadBehaviour.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace DS4Windows
{
diff --git a/DS4Windows/DS4Control/InputMethods.cs b/DS4Windows/DS4Control/InputMethods.cs
index 278f86e..c90516c 100644
--- a/DS4Windows/DS4Control/InputMethods.cs
+++ b/DS4Windows/DS4Control/InputMethods.cs
@@ -1,14 +1,13 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Runtime.InteropServices;
+
namespace DS4Windows
{
class InputMethods
{
private static INPUT[] sendInputs = new INPUT[2]; // will allow for keyboard + mouse/tablet input within one SendInput call, or two mouse events
private static object lockob = new object();
+
public static void MoveCursorBy(int x, int y)
{
lock (lockob)
@@ -43,6 +42,7 @@ namespace DS4Windows
sendInputs[inputs].Data.Mouse.Y = 0;
inputs++;
}
+
if (horizontal != 0)
{
sendInputs[inputs].Type = INPUT_MOUSE;
@@ -54,6 +54,7 @@ namespace DS4Windows
sendInputs[inputs].Data.Mouse.Y = 0;
inputs++;
}
+
SendInput(inputs, sendInputs, (int)inputs * Marshal.SizeOf(sendInputs[0]));
}
}
@@ -88,69 +89,6 @@ namespace DS4Windows
}
}
- public static void performLeftClick()
- {
- lock (lockob)
- {
- sendInputs[0].Type = INPUT_MOUSE;
- sendInputs[0].Data.Mouse.ExtraInfo = IntPtr.Zero;
- sendInputs[0].Data.Mouse.Flags = 0;
- sendInputs[0].Data.Mouse.Flags |= MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;
- sendInputs[0].Data.Mouse.MouseData = 0;
- sendInputs[0].Data.Mouse.Time = 0;
- sendInputs[0].Data.Mouse.X = 0;
- sendInputs[0].Data.Mouse.Y = 0;
- uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
- }
- }
-
- public static void performRightClick()
- {
- lock (lockob)
- {
- sendInputs[0].Type = INPUT_MOUSE;
- sendInputs[0].Data.Mouse.ExtraInfo = IntPtr.Zero;
- sendInputs[0].Data.Mouse.Flags = 0;
- sendInputs[0].Data.Mouse.Flags |= MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP;
- sendInputs[0].Data.Mouse.MouseData = 0;
- sendInputs[0].Data.Mouse.Time = 0;
- sendInputs[0].Data.Mouse.X = 0;
- sendInputs[0].Data.Mouse.Y = 0;
- uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
- }
- }
-
- public static void performMiddleClick()
- {
- lock (lockob)
- {
- sendInputs[0].Type = INPUT_MOUSE;
- sendInputs[0].Data.Mouse.ExtraInfo = IntPtr.Zero;
- sendInputs[0].Data.Mouse.Flags = 0;
- sendInputs[0].Data.Mouse.Flags |= MOUSEEVENTF_MIDDLEDOWN | MOUSEEVENTF_MIDDLEUP;
- sendInputs[0].Data.Mouse.MouseData = 0;
- sendInputs[0].Data.Mouse.Time = 0;
- sendInputs[0].Data.Mouse.X = 0;
- sendInputs[0].Data.Mouse.Y = 0;
- uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
- }
- }
-
- public static void performFourthClick()
- {
- lock (lockob)
- {
- sendInputs[0].Type = INPUT_MOUSE;
- sendInputs[0].Data.Mouse.ExtraInfo = IntPtr.Zero;
- sendInputs[0].Data.Mouse.Flags = 0;
- sendInputs[0].Data.Mouse.Flags |= MOUSEEVENTF_XBUTTONDOWN | MOUSEEVENTF_XBUTTONUP;
- sendInputs[0].Data.Mouse.MouseData = 1;
- sendInputs[0].Data.Mouse.Time = 0;
- sendInputs[0].Data.Mouse.X = 0;
- sendInputs[0].Data.Mouse.Y = 0;
- uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
- }
- }
public static void performSCKeyPress(ushort key)
{
lock (lockob)
@@ -169,10 +107,16 @@ namespace DS4Windows
{
lock (lockob)
{
+ ushort scancode = scancodeFromVK(key);
+ bool extended = (scancode & 0x100) != 0;
+ uint curflags = extended ? KEYEVENTF_EXTENDEDKEY : 0;
+
sendInputs[0].Type = INPUT_KEYBOARD;
sendInputs[0].Data.Keyboard.ExtraInfo = IntPtr.Zero;
- sendInputs[0].Data.Keyboard.Flags = 1;
- sendInputs[0].Data.Keyboard.Scan = 0;
+ sendInputs[0].Data.Keyboard.Flags = curflags;
+ sendInputs[0].Data.Keyboard.Scan = scancode;
+ //sendInputs[0].Data.Keyboard.Flags = 1;
+ //sendInputs[0].Data.Keyboard.Scan = 0;
sendInputs[0].Data.Keyboard.Time = 0;
sendInputs[0].Data.Keyboard.Vk = key;
uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
@@ -197,16 +141,71 @@ namespace DS4Windows
{
lock (lockob)
{
+ ushort scancode = scancodeFromVK(key);
+ bool extended = (scancode & 0x100) != 0;
+ uint curflags = extended ? KEYEVENTF_EXTENDEDKEY : 0;
+
sendInputs[0].Type = INPUT_KEYBOARD;
sendInputs[0].Data.Keyboard.ExtraInfo = IntPtr.Zero;
- sendInputs[0].Data.Keyboard.Flags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
- sendInputs[0].Data.Keyboard.Scan = 0;
+ sendInputs[0].Data.Keyboard.Flags = curflags | KEYEVENTF_KEYUP;
+ sendInputs[0].Data.Keyboard.Scan = scancode;
+ //sendInputs[0].Data.Keyboard.Flags = KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP;
+ //sendInputs[0].Data.Keyboard.Scan = 0;
sendInputs[0].Data.Keyboard.Time = 0;
sendInputs[0].Data.Keyboard.Vk = key;
uint result = SendInput(1, sendInputs, Marshal.SizeOf(sendInputs[0]));
}
}
+ private static ushort scancodeFromVK(uint vkey)
+ {
+ ushort scancode = 0;
+ if (vkey == VK_PAUSE)
+ {
+ // MapVirtualKey does not work with VK_PAUSE
+ scancode = 0x45;
+ }
+ else
+ {
+ scancode = MapVirtualKey(vkey, MAPVK_VK_TO_VSC);
+ }
+
+ switch (vkey)
+ {
+ case VK_LEFT:
+ case VK_UP:
+ case VK_RIGHT:
+ case VK_DOWN:
+ case VK_PRIOR:
+ case VK_NEXT:
+ case VK_END:
+ case VK_HOME:
+ case VK_INSERT:
+ case VK_DELETE:
+ case VK_DIVIDE:
+ case VK_NUMLOCK:
+ case VK_RCONTROL:
+ case VK_RMENU:
+ case VK_VOLUME_MUTE:
+ case VK_VOLUME_DOWN:
+ case VK_VOLUME_UP:
+ case VK_MEDIA_NEXT_TRACK:
+ case VK_MEDIA_PREV_TRACK:
+ case VK_LAUNCH_MEDIA_SELECT:
+ case VK_BROWSER_HOME:
+ case VK_LAUNCH_MAIL:
+ case VK_LAUNCH_APP1:
+ case VK_LAUNCH_APP2:
+ case VK_APPS:
+ {
+ scancode |= (ushort)EXTENDED_FLAG; // set extended bit
+ break;
+ }
+ }
+
+ return scancode;
+ }
+
///
/// http://msdn.microsoft.com/en-us/library/windows/desktop/ms646270(v=vs.85).aspx
///
@@ -277,7 +276,14 @@ namespace DS4Windows
MOUSEEVENTF_XBUTTONDOWN = 128, MOUSEEVENTF_XBUTTONUP = 256,
KEYEVENTF_EXTENDEDKEY = 1, KEYEVENTF_KEYUP = 2, MOUSEEVENTF_WHEEL = 0x0800, MOUSEEVENTF_HWHEEL = 0x1000,
MOUSEEVENTF_MIDDLEWDOWN = 0x0020, MOUSEEVENTF_MIDDLEWUP = 0x0040,
- KEYEVENTF_SCANCODE = 0x0008, MAPVK_VK_TO_VSC = 0, KEYEVENTF_UNICODE = 0x0004;
+ KEYEVENTF_SCANCODE = 0x0008, MAPVK_VK_TO_VSC = 0, KEYEVENTF_UNICODE = 0x0004, EXTENDED_FLAG = 0x100;
+
+ internal const uint VK_PAUSE = 0x13, VK_LEFT = 0x25, VK_UP = 0x26, VK_RIGHT = 0x27, VK_DOWN = 0x28,
+ VK_PRIOR = 0x21, VK_NEXT = 0x22, VK_END = 0x23, VK_HOME = 0x24, VK_INSERT = 0x2D, VK_DELETE = 0x2E, VK_APPS = 0x5D,
+ VK_DIVIDE = 0x6F, VK_NUMLOCK = 0x90, VK_RCONTROL = 0xA3, VK_RMENU = 0xA5, VK_BROWSER_HOME = 0xAC,
+ VK_VOLUME_MUTE = 0xAD, VK_VOLUME_DOWN = 0xAE, VK_VOLUME_UP = 0xAF,
+ VK_MEDIA_NEXT_TRACK = 0xB0, VK_MEDIA_PREV_TRACK = 0xB1, VK_MEDIA_STOP = 0xB2, VK_MEDIA_PLAY_PAUSE = 0xB3,
+ VK_LAUNCH_MAIL = 0xB4, VK_LAUNCH_MEDIA_SELECT = 0xB5, VK_LAUNCH_APP1 = 0xB6, VK_LAUNCH_APP2 = 0xB7;
[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputs);
@@ -285,6 +291,7 @@ namespace DS4Windows
private static extern ushort MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", SetLastError = true)]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
+
//Not used, just here
public static void DownKeys(ushort key)
{
@@ -301,5 +308,5 @@ namespace DS4Windows
keybd_event((byte)key, 0, (int)KEYEVENTF_KEYUP, 0);
}
}
-
}
+
diff --git a/DS4Windows/DS4Control/Log.cs b/DS4Windows/DS4Control/Log.cs
index f581f77..1eef330 100644
--- a/DS4Windows/DS4Control/Log.cs
+++ b/DS4Windows/DS4Control/Log.cs
@@ -1,7 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
namespace DS4Windows
{
diff --git a/DS4Windows/DS4Control/Mapping.cs b/DS4Windows/DS4Control/Mapping.cs
index 24b06ed..2c6c94d 100644
--- a/DS4Windows/DS4Control/Mapping.cs
+++ b/DS4Windows/DS4Control/Mapping.cs
@@ -1,12 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
-using System.Windows.Forms;
using System.Diagnostics;
using static DS4Windows.Global;
+
namespace DS4Windows
{
public class Mapping
@@ -38,8 +37,12 @@ namespace DS4Windows
previousClicks = currentClicks;
if (performClear)
currentClicks.leftCount = currentClicks.middleCount = currentClicks.rightCount = currentClicks.fourthCount = currentClicks.fifthCount = currentClicks.wUpCount = currentClicks.wDownCount = currentClicks.toggleCount = 0;
- foreach (KeyPresses kp in keyPresses.Values)
+
+ //foreach (KeyPresses kp in keyPresses.Values)
+ Dictionary.ValueCollection keyValues = keyPresses.Values;
+ for (int i = 0, kpCount = keyValues.Count; i < kpCount; i++)
{
+ KeyPresses kp = keyValues.ElementAt(i);
kp.previous = kp.current;
if (performClear)
{
@@ -56,7 +59,24 @@ namespace DS4Windows
}
public static SyntheticState globalState = new SyntheticState();
- public static SyntheticState[] deviceState = { new SyntheticState(), new SyntheticState(), new SyntheticState(), new SyntheticState() };
+ public static SyntheticState[] deviceState = new SyntheticState[4]
+ { new SyntheticState(), new SyntheticState(), new SyntheticState(),
+ new SyntheticState() };
+
+ public static DS4StateFieldMapping[] fieldMappings = new DS4StateFieldMapping[4] {
+ new DS4StateFieldMapping(), new DS4StateFieldMapping(), new DS4StateFieldMapping(),
+ new DS4StateFieldMapping()
+ };
+ public static DS4StateFieldMapping[] outputFieldMappings = new DS4StateFieldMapping[4]
+ {
+ new DS4StateFieldMapping(), new DS4StateFieldMapping(), new DS4StateFieldMapping(),
+ new DS4StateFieldMapping()
+ };
+ public static DS4StateFieldMapping[] previousFieldMappings = new DS4StateFieldMapping[4]
+ {
+ new DS4StateFieldMapping(), new DS4StateFieldMapping(), new DS4StateFieldMapping(),
+ new DS4StateFieldMapping()
+ };
// TODO When we disconnect, process a null/dead state to release any keys or buttons.
public static DateTime oldnow = DateTime.UtcNow;
@@ -64,33 +84,89 @@ namespace DS4Windows
private static int wheel = 0, keyshelddown = 0;
//mapcustom
- public static bool[] pressedonce = new bool[261], macrodone = new bool[34];
+ public static bool[] pressedonce = new bool[261], macrodone = new bool[38];
static bool[] macroControl = new bool[25];
+ static uint macroCount = 0;
//actions
- public static int[] fadetimer = { 0, 0, 0, 0 };
- public static int[] prevFadetimer = { 0, 0, 0, 0 };
+ public static int[] fadetimer = new int[4] { 0, 0, 0, 0 };
+ public static int[] prevFadetimer = new int[4] { 0, 0, 0, 0 };
public static DS4Color[] lastColor = new DS4Color[4];
public static List actionDone = new List();
- //public static List[] actionDone = { new List(), new List(), new List(), new List() };
- //public static bool[,] actionDone = new bool[4, 50];
public static SpecialAction[] untriggeraction = new SpecialAction[4];
public static DateTime[] nowAction = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue };
public static DateTime[] oldnowAction = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue };
- public static int[] untriggerindex = { -1, -1, -1, -1 };
- public static DateTime[] oldnowKeyAct = { DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue };
- private static bool tappedOnce = false, firstTouch = false, secondtouchbegin = false;
- private static DateTime pastTime, firstTap, TimeofEnd;
+ public static int[] untriggerindex = new int[4] { -1, -1, -1, -1 };
+ public static DateTime[] oldnowKeyAct = new DateTime[4] { DateTime.MinValue,
+ DateTime.MinValue, DateTime.MinValue, DateTime.MinValue };
- //special macros
+ private static DS4Controls[] shiftTriggerMapping = new DS4Controls[26] { DS4Controls.None, DS4Controls.Cross, DS4Controls.Circle, DS4Controls.Square,
+ DS4Controls.Triangle, DS4Controls.Options, DS4Controls.Share, DS4Controls.DpadUp, DS4Controls.DpadDown,
+ DS4Controls.DpadLeft, DS4Controls.DpadRight, DS4Controls.PS, DS4Controls.L1, DS4Controls.R1, DS4Controls.L2,
+ DS4Controls.R2, DS4Controls.L3, DS4Controls.R3, DS4Controls.TouchLeft, DS4Controls.TouchUpper, DS4Controls.TouchMulti,
+ DS4Controls.TouchRight, DS4Controls.GyroZNeg, DS4Controls.GyroZPos, DS4Controls.GyroXPos, DS4Controls.GyroXNeg,
+ };
+
+ private static int[] ds4ControlMapping = new int[38] { 0, // DS4Control.None
+ 16, // DS4Controls.LXNeg
+ 20, // DS4Controls.LXPos
+ 17, // DS4Controls.LYNeg
+ 21, // DS4Controls.LYPos
+ 18, // DS4Controls.RXNeg
+ 22, // DS4Controls.RXPos
+ 19, // DS4Controls.RYNeg
+ 23, // DS4Controls.RYPos
+ 3, // DS4Controls.L1
+ 24, // DS4Controls.L2
+ 5, // DS4Controls.L3
+ 4, // DS4Controls.R1
+ 25, // DS4Controls.R2
+ 6, // DS4Controls.R3
+ 13, // DS4Controls.Square
+ 14, // DS4Controls.Triangle
+ 15, // DS4Controls.Circle
+ 12, // DS4Controls.Cross
+ 7, // DS4Controls.DpadUp
+ 10, // DS4Controls.DpadRight
+ 8, // DS4Controls.DpadDown
+ 9, // DS4Controls.DpadLeft
+ 11, // DS4Controls.PS
+ 27, // DS4Controls.TouchLeft
+ 29, // DS4Controls.TouchUpper
+ 26, // DS4Controls.TouchMulti
+ 28, // DS4Controls.TouchRight
+ 1, // DS4Controls.Share
+ 2, // DS4Controls.Options
+ 31, // DS4Controls.GyroXPos
+ 30, // DS4Controls.GyroXNeg
+ 33, // DS4Controls.GyroZPos
+ 32, // DS4Controls.GyroZNeg
+ 34, // DS4Controls.SwipeLeft
+ 35, // DS4Controls.SwipeRight
+ 36, // DS4Controls.SwipeUp
+ 37 // DS4Controls.SwipeDown
+ };
+
+ // Define here to save some time processing.
+ // It is enough to feel a difference during gameplay.
+ private static int[] rsOutCurveModeArray = new int[4] { 0, 0, 0, 0 };
+ private static int[] lsOutCurveModeArray = new int[4] { 0, 0, 0, 0 };
+ static bool tempBool = false;
+ private static double[] tempDoubleArray = new double[4] { 0.0, 0.0, 0.0, 0.0 };
+ private static int[] tempIntArray = new int[4] { 0, 0, 0, 0 };
+
+ // Special macros
static bool altTabDone = true;
- static DateTime altTabNow = DateTime.UtcNow, oldAltTabNow = DateTime.UtcNow - TimeSpan.FromSeconds(1);
+ static DateTime altTabNow = DateTime.UtcNow,
+ oldAltTabNow = DateTime.UtcNow - TimeSpan.FromSeconds(1);
- //mouse
+ // Mouse
public static int mcounter = 34;
public static int mouseaccel = 0;
public static int prevmouseaccel = 0;
private static double horizontalRemainder = 0.0, verticalRemainder = 0.0;
+ private const int MOUSESPEEDFACTOR = 48;
+ private const double MOUSESTICKOFFSET = 0.032;
public static void Commit(int device)
{
@@ -163,18 +239,18 @@ namespace DS4Windows
if (globalState.currentClicks.wUpCount != 0 && globalState.previousClicks.wUpCount == 0)
{
- InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_WHEEL, 100);
+ InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_WHEEL, 120);
oldnow = DateTime.UtcNow;
- wheel = 100;
+ wheel = 120;
}
else if (globalState.currentClicks.wUpCount == 0 && globalState.previousClicks.wUpCount != 0)
wheel = 0;
if (globalState.currentClicks.wDownCount != 0 && globalState.previousClicks.wDownCount == 0)
{
- InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_WHEEL, -100);
+ InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_WHEEL, -120);
oldnow = DateTime.UtcNow;
- wheel = -100;
+ wheel = -120;
}
if (globalState.currentClicks.wDownCount == 0 && globalState.previousClicks.wDownCount != 0)
wheel = 0;
@@ -193,58 +269,63 @@ namespace DS4Windows
// Merge and synthesize all key presses/releases that are present in this device's mapping.
// TODO what about the rest? e.g. repeat keys really ought to be on some set schedule
- foreach (KeyValuePair kvp in state.keyPresses)
+ Dictionary.KeyCollection kvpKeys = state.keyPresses.Keys;
+ //foreach (KeyValuePair kvp in state.keyPresses)
+ for (int i = 0, keyCount = kvpKeys.Count; i < keyCount; i++)
{
+ UInt16 kvpKey = kvpKeys.ElementAt(i);
+ SyntheticState.KeyPresses kvpValue = state.keyPresses[kvpKey];
+
SyntheticState.KeyPresses gkp;
- if (globalState.keyPresses.TryGetValue(kvp.Key, out gkp))
+ if (globalState.keyPresses.TryGetValue(kvpKey, out gkp))
{
- gkp.current.vkCount += kvp.Value.current.vkCount - kvp.Value.previous.vkCount;
- gkp.current.scanCodeCount += kvp.Value.current.scanCodeCount - kvp.Value.previous.scanCodeCount;
- gkp.current.repeatCount += kvp.Value.current.repeatCount - kvp.Value.previous.repeatCount;
- gkp.current.toggle = kvp.Value.current.toggle;
- gkp.current.toggleCount += kvp.Value.current.toggleCount - kvp.Value.previous.toggleCount;
+ gkp.current.vkCount += kvpValue.current.vkCount - kvpValue.previous.vkCount;
+ gkp.current.scanCodeCount += kvpValue.current.scanCodeCount - kvpValue.previous.scanCodeCount;
+ gkp.current.repeatCount += kvpValue.current.repeatCount - kvpValue.previous.repeatCount;
+ gkp.current.toggle = kvpValue.current.toggle;
+ gkp.current.toggleCount += kvpValue.current.toggleCount - kvpValue.previous.toggleCount;
}
else
{
gkp = new SyntheticState.KeyPresses();
- gkp.current = kvp.Value.current;
- globalState.keyPresses[kvp.Key] = gkp;
+ gkp.current = kvpValue.current;
+ globalState.keyPresses[kvpKey] = gkp;
}
if (gkp.current.toggleCount != 0 && gkp.previous.toggleCount == 0 && gkp.current.toggle)
{
if (gkp.current.scanCodeCount != 0)
- InputMethods.performSCKeyPress(kvp.Key);
+ InputMethods.performSCKeyPress(kvpKey);
else
- InputMethods.performKeyPress(kvp.Key);
+ InputMethods.performKeyPress(kvpKey);
}
else if (gkp.current.toggleCount != 0 && gkp.previous.toggleCount == 0 && !gkp.current.toggle)
{
if (gkp.previous.scanCodeCount != 0) // use the last type of VK/SC
- InputMethods.performSCKeyRelease(kvp.Key);
+ InputMethods.performSCKeyRelease(kvpKey);
else
- InputMethods.performKeyRelease(kvp.Key);
+ InputMethods.performKeyRelease(kvpKey);
}
else if (gkp.current.vkCount + gkp.current.scanCodeCount != 0 && gkp.previous.vkCount + gkp.previous.scanCodeCount == 0)
{
if (gkp.current.scanCodeCount != 0)
{
oldnow = DateTime.UtcNow;
- InputMethods.performSCKeyPress(kvp.Key);
+ InputMethods.performSCKeyPress(kvpKey);
pressagain = false;
- keyshelddown = kvp.Key;
+ keyshelddown = kvpKey;
}
else
{
oldnow = DateTime.UtcNow;
- InputMethods.performKeyPress(kvp.Key);
+ InputMethods.performKeyPress(kvpKey);
pressagain = false;
- keyshelddown = kvp.Key;
+ keyshelddown = kvpKey;
}
}
else if (gkp.current.toggleCount != 0 || gkp.previous.toggleCount != 0 || gkp.current.repeatCount != 0 || // repeat or SC/VK transition
((gkp.previous.scanCodeCount == 0) != (gkp.current.scanCodeCount == 0))) //repeat keystroke after 500ms
{
- if (keyshelddown == kvp.Key)
+ if (keyshelddown == kvpKey)
{
DateTime now = DateTime.UtcNow;
if (now >= oldnow + TimeSpan.FromMilliseconds(500) && !pressagain)
@@ -258,7 +339,7 @@ namespace DS4Windows
if (now >= oldnow + TimeSpan.FromMilliseconds(25) && pressagain)
{
oldnow = now;
- InputMethods.performSCKeyPress(kvp.Key);
+ InputMethods.performSCKeyPress(kvpKey);
}
}
else if (pressagain)
@@ -267,7 +348,7 @@ namespace DS4Windows
if (now >= oldnow + TimeSpan.FromMilliseconds(25) && pressagain)
{
oldnow = now;
- InputMethods.performKeyPress(kvp.Key);
+ InputMethods.performKeyPress(kvpKey);
}
}
}
@@ -276,12 +357,12 @@ namespace DS4Windows
{
if (gkp.previous.scanCodeCount != 0) // use the last type of VK/SC
{
- InputMethods.performSCKeyRelease(kvp.Key);
+ InputMethods.performSCKeyRelease(kvpKey);
pressagain = false;
}
else
{
- InputMethods.performKeyRelease(kvp.Key);
+ InputMethods.performKeyRelease(kvpKey);
pressagain = false;
}
}
@@ -290,6 +371,7 @@ namespace DS4Windows
}
state.SavePrevious(true);
}
+
public enum Click { None, Left, Middle, Right, Fourth, Fifth, WUP, WDOWN };
public static void MapClick(int device, Click mouseClick)
{
@@ -316,48 +398,19 @@ namespace DS4Windows
case Click.WDOWN:
deviceState[device].currentClicks.wDownCount++;
break;
+ default: break;
}
}
public static int DS4ControltoInt(DS4Controls ctrl)
{
- switch (ctrl)
+ int result = 0;
+ if (ctrl >= DS4Controls.None && ctrl <= DS4Controls.SwipeDown)
{
- case DS4Controls.Share: return 1;
- case DS4Controls.Options: return 2;
- case DS4Controls.L1: return 3;
- case DS4Controls.R1: return 4;
- case DS4Controls.L3: return 5;
- case DS4Controls.R3: return 6;
- case DS4Controls.DpadUp: return 7;
- case DS4Controls.DpadDown: return 8;
- case DS4Controls.DpadLeft: return 9;
- case DS4Controls.DpadRight: return 10;
- case DS4Controls.PS: return 11;
- case DS4Controls.Cross: return 12;
- case DS4Controls.Square: return 13;
- case DS4Controls.Triangle: return 14;
- case DS4Controls.Circle: return 15;
- case DS4Controls.LXNeg: return 16;
- case DS4Controls.LYNeg: return 17;
- case DS4Controls.RXNeg: return 18;
- case DS4Controls.RYNeg: return 19;
- case DS4Controls.LXPos: return 20;
- case DS4Controls.LYPos: return 21;
- case DS4Controls.RXPos: return 22;
- case DS4Controls.RYPos: return 23;
- case DS4Controls.L2: return 24;
- case DS4Controls.R2: return 25;
- case DS4Controls.TouchMulti: return 26;
- case DS4Controls.TouchLeft: return 27;
- case DS4Controls.TouchRight: return 28;
- case DS4Controls.TouchUpper: return 29;
- case DS4Controls.GyroXNeg: return 30;
- case DS4Controls.GyroXPos: return 31;
- case DS4Controls.GyroZNeg: return 32;
- case DS4Controls.GyroZPos: return 33;
+ result = ds4ControlMapping[(int)ctrl];
}
- return 0;
+
+ return result;
}
static double TValue(double value1, double value2, double percent)
@@ -365,37 +418,44 @@ namespace DS4Windows
percent /= 100f;
return value1 * percent + value2 * (1 - percent);
}
- static double Clamp(double min, double value, double max)
+
+ private static int ClampInt(int min, int value, int max)
{
- if (value > max)
- return max;
- else if (value < min)
- return min;
- else
- return value;
+ return (value < min) ? min : (value > max) ? max : value;
}
- public static DS4State SetCurveAndDeadzone(int device, DS4State cState)
+ public static DS4State SetCurveAndDeadzone(int device, DS4State cState, DS4State dState)
{
- DS4State dState = new DS4State(cState);
+ double rotation = tempDoubleArray[device] = getLSRotation(device);
+ if (rotation > 0.0 || rotation < 0.0)
+ cState.rotateLSCoordinates(rotation);
+
+ double rotationRS = tempDoubleArray[device] = getRSRotation(device);
+ if (rotationRS > 0.0 || rotationRS < 0.0)
+ cState.rotateRSCoordinates(rotationRS);
+
+ cState.CopyTo(dState);
+ //DS4State dState = new DS4State(cState);
int x;
int y;
int curve;
- if (LSCurve[device] > 0)
+
+ /* TODO: Look into curve options and make sure maximum axes values are being respected */
+ int lsCurve = getLSCurve(device);
+ if (lsCurve > 0)
{
x = cState.LX;
y = cState.LY;
float max = x + y;
double curvex;
double curvey;
- curve = LSCurve[device];
+ curve = lsCurve;
double multimax = TValue(382.5, max, curve);
double multimin = TValue(127.5, max, curve);
if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
{
curvex = (x > 127.5f ? Math.Min(x, (x / max) * multimax) : Math.Max(x, (x / max) * multimin));
curvey = (y > 127.5f ? Math.Min(y, (y / max) * multimax) : Math.Max(y, (y / max) * multimin));
- //btnLSTrack.Location = new Point((int)(dpix * curvex / 2.09 + lbLSTrack.Location.X), (int)(dpiy * curvey / 2.09 + lbLSTrack.Location.Y));
}
else
{
@@ -410,17 +470,21 @@ namespace DS4Windows
curvey = Math.Min(y, (y / max) * multimax);
}
}
+
dState.LX = (byte)Math.Round(curvex, 0);
dState.LY = (byte)Math.Round(curvey, 0);
}
- if (RSCurve[device] > 0)
+
+ /* TODO: Look into curve options and make sure maximum axes values are being respected */
+ int rsCurve = getRSCurve(device);
+ if (rsCurve > 0)
{
x = cState.RX;
y = cState.RY;
float max = x + y;
double curvex;
double curvey;
- curve = RSCurve[device];
+ curve = rsCurve;
double multimax = TValue(382.5, max, curve);
double multimin = TValue(127.5, max, curve);
if ((x > 127.5f && y > 127.5f) || (x < 127.5f && y < 127.5f))
@@ -441,94 +505,556 @@ namespace DS4Windows
curvey = Math.Min(y, (y / max) * multimax);
}
}
+
dState.RX = (byte)Math.Round(curvex, 0);
dState.RY = (byte)Math.Round(curvey, 0);
}
- double ls = Math.Sqrt(Math.Pow(cState.LX - 127.5f, 2) + Math.Pow(cState.LY - 127.5f, 2));
- //deadzones
- if (LSDeadzone[device] > 0 && ls < LSDeadzone[device])
+
+ int lsDeadzone = getLSDeadzone(device);
+ int lsAntiDead = getLSAntiDeadzone(device);
+ int lsMaxZone = getLSMaxzone(device);
+ if (lsDeadzone > 0 || lsAntiDead > 0 || lsMaxZone != 100)
{
- dState.LX = 127;
- dState.LY = 127;
+ double lsSquared = Math.Pow(cState.LX - 127.5f, 2) + Math.Pow(cState.LY - 127.5f, 2);
+ double lsDeadzoneSquared = Math.Pow(lsDeadzone, 2);
+ if (lsDeadzone > 0 && lsSquared <= lsDeadzoneSquared)
+ {
+ dState.LX = 127;
+ dState.LY = 127;
+ }
+ else if ((lsDeadzone > 0 && lsSquared > lsDeadzoneSquared) || lsAntiDead > 0 || lsMaxZone != 100)
+ {
+ double r = Math.Atan2(-(dState.LY - 127.5), (dState.LX - 127.5));
+ double maxXValue = dState.LX >= 127.5 ? 127.5 : -127.5;
+ double maxYValue = dState.LY >= 127.5 ? 127.5 : -127.5;
+ double ratio = lsMaxZone / 100.0;
+
+ double maxZoneXNegValue = (ratio * -127.5) + 127.5;
+ double maxZoneXPosValue = (ratio * 127.5) + 127.5;
+ double maxZoneYNegValue = maxZoneXNegValue;
+ double maxZoneYPosValue = maxZoneXPosValue;
+ double maxZoneX = dState.LX >= 127.5 ? (maxZoneXPosValue - 127.5) : (maxZoneXNegValue - 127.5);
+ double maxZoneY = dState.LY >= 127.5 ? (maxZoneYPosValue - 127.5) : (maxZoneYNegValue - 127.5);
+
+ double tempLsXDead = 0.0, tempLsYDead = 0.0;
+ double tempOutputX = 0.0, tempOutputY = 0.0;
+ if (lsDeadzone > 0)
+ {
+ tempLsXDead = Math.Abs(Math.Cos(r)) * (lsDeadzone / 127.0) * maxXValue;
+ tempLsYDead = Math.Abs(Math.Sin(r)) * (lsDeadzone / 127.0) * maxYValue;
+
+ if (lsSquared > lsDeadzoneSquared)
+ {
+ double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue);
+ double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue);
+ tempOutputX = ((currentX - 127.5 - tempLsXDead) / (maxZoneX - tempLsXDead));
+ tempOutputY = ((currentY - 127.5 - tempLsYDead) / (maxZoneY - tempLsYDead));
+ }
+ }
+ else
+ {
+ double currentX = Global.Clamp(maxZoneXNegValue, dState.LX, maxZoneXPosValue);
+ double currentY = Global.Clamp(maxZoneYNegValue, dState.LY, maxZoneYPosValue);
+ tempOutputX = (currentX - 127.5) / maxZoneX;
+ tempOutputY = (currentY - 127.5) / maxZoneY;
+ }
+
+ double tempLsXAntiDeadPercent = 0.0, tempLsYAntiDeadPercent = 0.0;
+ if (lsAntiDead > 0)
+ {
+ tempLsXAntiDeadPercent = (lsAntiDead * 0.01) * Math.Abs(Math.Cos(r));
+ tempLsYAntiDeadPercent = (lsAntiDead * 0.01) * Math.Abs(Math.Sin(r));
+ }
+
+ if (tempOutputX > 0.0)
+ {
+ dState.LX = (byte)((((1.0 - tempLsXAntiDeadPercent) * tempOutputX + tempLsXAntiDeadPercent)) * maxXValue + 127.5);
+ }
+ else
+ {
+ dState.LX = 127;
+ }
+
+ if (tempOutputY > 0.0)
+ {
+ dState.LY = (byte)((((1.0 - tempLsYAntiDeadPercent) * tempOutputY + tempLsYAntiDeadPercent)) * maxYValue + 127.5);
+ }
+ else
+ {
+ dState.LY = 127;
+ }
+ }
}
- else if (LSDeadzone[device] < 0 && ls > 127.5f + LSDeadzone[device])
+
+ int rsDeadzone = getRSDeadzone(device);
+ int rsAntiDead = getRSAntiDeadzone(device);
+ int rsMaxZone = getRSMaxzone(device);
+ if (rsDeadzone > 0 || rsAntiDead > 0 || rsMaxZone != 100)
{
- double r = Math.Atan2((dState.LY - 127.5f), (dState.LX - 127.5f));
- dState.LX = (byte)(Math.Cos(r) * (127.5f + LSDeadzone[device]) + 127.5f);
- dState.LY = (byte)(Math.Sin(r) * (127.5f + LSDeadzone[device]) + 127.5f);
+ double rsSquared = Math.Pow(cState.RX - 127.5, 2) + Math.Pow(cState.RY - 127.5, 2);
+ double rsDeadzoneSquared = Math.Pow(rsDeadzone, 2);
+ if (rsDeadzone > 0 && rsSquared <= rsDeadzoneSquared)
+ {
+ dState.RX = 127;
+ dState.RY = 127;
+ }
+ else if ((rsDeadzone > 0 && rsSquared > rsDeadzoneSquared) || rsAntiDead > 0 || rsMaxZone != 100)
+ {
+ double r = Math.Atan2(-(dState.RY - 127.5), (dState.RX - 127.5));
+ double maxXValue = dState.RX >= 127.5 ? 127.5 : -127.5;
+ double maxYValue = dState.RY >= 127.5 ? 127.5 : -127.5;
+ double ratio = rsMaxZone / 100.0;
+
+ double maxZoneXNegValue = (ratio * -127.5) + 127.5;
+ double maxZoneXPosValue = (ratio * 127.5) + 127.5;
+ double maxZoneYNegValue = maxZoneXNegValue;
+ double maxZoneYPosValue = maxZoneXPosValue;
+ double maxZoneX = dState.RX >= 127.5 ? (maxZoneXPosValue - 127.5) : (maxZoneXNegValue - 127.5);
+ double maxZoneY = dState.RY >= 127.5 ? (maxZoneYPosValue - 127.5) : (maxZoneYNegValue - 127.5);
+
+ double tempRsXDead = 0.0, tempRsYDead = 0.0;
+ double tempOutputX = 0.0, tempOutputY = 0.0;
+ if (rsDeadzone > 0)
+ {
+ tempRsXDead = Math.Abs(Math.Cos(r)) * (rsDeadzone / 127.0) * maxXValue;
+ tempRsYDead = Math.Abs(Math.Sin(r)) * (rsDeadzone / 127.0) * maxYValue;
+
+ if (rsSquared > rsDeadzoneSquared)
+ {
+ double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue);
+ double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue);
+
+ tempOutputX = ((currentX - 127.5 - tempRsXDead) / (maxZoneX - tempRsXDead));
+ tempOutputY = ((currentY - 127.5 - tempRsYDead) / (maxZoneY - tempRsYDead));
+ }
+ }
+ else
+ {
+ double currentX = Global.Clamp(maxZoneXNegValue, dState.RX, maxZoneXPosValue);
+ double currentY = Global.Clamp(maxZoneYNegValue, dState.RY, maxZoneYPosValue);
+
+ tempOutputX = (currentX - 127.5) / maxZoneX;
+ tempOutputY = (currentY - 127.5) / maxZoneY;
+ }
+
+ double tempRsXAntiDeadPercent = 0.0, tempRsYAntiDeadPercent = 0.0;
+ if (rsAntiDead > 0)
+ {
+ tempRsXAntiDeadPercent = (rsAntiDead * 0.01) * Math.Abs(Math.Cos(r));
+ tempRsYAntiDeadPercent = (rsAntiDead * 0.01) * Math.Abs(Math.Sin(r));
+ }
+
+ if (tempOutputX > 0.0)
+ {
+ dState.RX = (byte)((((1.0 - tempRsXAntiDeadPercent) * tempOutputX + tempRsXAntiDeadPercent)) * maxXValue + 127.5);
+ }
+ else
+ {
+ dState.RX = 127;
+ }
+
+ if (tempOutputY > 0.0)
+ {
+ dState.RY = (byte)((((1.0 - tempRsYAntiDeadPercent) * tempOutputY + tempRsYAntiDeadPercent)) * maxYValue + 127.5);
+ }
+ else
+ {
+ dState.RY = 127;
+ }
+ }
}
- //Console.WriteLine
- double rs = Math.Sqrt(Math.Pow(cState.RX - 127.5f, 2) + Math.Pow(cState.RY - 127.5f, 2));
- if (RSDeadzone[device] > 0 && rs < LSDeadzone[device])
+
+ byte l2Deadzone = getL2Deadzone(device);
+ int l2AntiDeadzone = getL2AntiDeadzone(device);
+ int l2Maxzone = getL2Maxzone(device);
+ if (l2Deadzone > 0 || l2AntiDeadzone > 0 || l2Maxzone != 100)
{
- dState.RX = 127;
- dState.RY = 127;
+ double tempL2Output = cState.L2 / 255.0;
+ double tempL2AntiDead = 0.0;
+ double ratio = l2Maxzone / 100.0;
+ double maxValue = 255.0 * ratio;
+
+ if (l2Deadzone > 0)
+ {
+ if (cState.L2 > l2Deadzone)
+ {
+ double current = Global.Clamp(0, dState.L2, maxValue);
+ tempL2Output = (current - l2Deadzone) / (maxValue - l2Deadzone);
+ }
+ else
+ {
+ tempL2Output = 0.0;
+ }
+ }
+
+ if (l2AntiDeadzone > 0)
+ {
+ tempL2AntiDead = l2AntiDeadzone * 0.01;
+ }
+
+ if (tempL2Output > 0.0)
+ {
+ dState.L2 = (byte)(((1.0 - tempL2AntiDead) * tempL2Output + tempL2AntiDead) * 255.0);
+ }
+ else
+ {
+ dState.L2 = 0;
+ }
}
- else if (RSDeadzone[device] < 0 && rs > 127.5f + RSDeadzone[device])
+
+ byte r2Deadzone = getR2Deadzone(device);
+ int r2AntiDeadzone = getR2AntiDeadzone(device);
+ int r2Maxzone = getR2Maxzone(device);
+ if (r2Deadzone > 0 || r2AntiDeadzone > 0 || r2Maxzone != 100)
{
- double r = Math.Atan2((dState.RY - 127.5f), (dState.RX - 127.5f));
- dState.RX = (byte)(Math.Cos(r) * (127.5f + RSDeadzone[device]) + 127.5f);
- dState.RY = (byte)(Math.Sin(r) * (127.5f + RSDeadzone[device]) + 127.5f);
+ double tempR2Output = cState.R2 / 255.0;
+ double tempR2AntiDead = 0.0;
+ double ratio = r2Maxzone / 100.0;
+ double maxValue = 255 * ratio;
+
+ if (r2Deadzone > 0)
+ {
+ if (cState.R2 > r2Deadzone)
+ {
+ double current = Global.Clamp(0, dState.R2, maxValue);
+ tempR2Output = (current - r2Deadzone) / (maxValue - r2Deadzone);
+ }
+ else
+ {
+ tempR2Output = 0.0;
+ }
+ }
+
+ if (r2AntiDeadzone > 0)
+ {
+ tempR2AntiDead = r2AntiDeadzone * 0.01;
+ }
+
+ if (tempR2Output > 0.0)
+ {
+ dState.R2 = (byte)(((1.0 - tempR2AntiDead) * tempR2Output + tempR2AntiDead) * 255.0);
+ }
+ else
+ {
+ dState.R2 = 0;
+ }
}
- if (L2Deadzone[device] > 0 && cState.L2 < L2Deadzone[device])
- dState.L2 = 0;
- if (R2Deadzone[device] > 0 && cState.R2 < R2Deadzone[device])
- dState.R2 = 0;
- if (LSSens[device] != 1)
+
+ double lsSens = getLSSens(device);
+ if (lsSens != 1.0)
{
- dState.LX = (byte)Clamp(0, LSSens[device] * (dState.LX - 127) + 127, 255);
- dState.LY = (byte)Clamp(0, LSSens[device] * (dState.LY - 127) + 127, 255);
+ dState.LX = (byte)Global.Clamp(0, lsSens * (dState.LX - 127.5) + 127.5, 255);
+ dState.LY = (byte)Global.Clamp(0, lsSens * (dState.LY - 127.5) + 127.5, 255);
}
- if (RSSens[device] != 1)
+
+ double rsSens = getRSSens(device);
+ if (rsSens != 1.0)
{
- dState.RX = (byte)Clamp(0, RSSens[device] * (dState.RX - 127) + 127, 255);
- dState.RY = (byte)Clamp(0, RSSens[device] * (dState.RY - 127) + 127, 255);
+ dState.RX = (byte)Global.Clamp(0, rsSens * (dState.RX - 127.5) + 127.5, 255);
+ dState.RY = (byte)Global.Clamp(0, rsSens * (dState.RY - 127.5) + 127.5, 255);
}
- if (L2Sens[device] != 1)
- dState.L2 = (byte)Clamp(0, L2Sens[device] * dState.L2, 255);
- if (R2Sens[device] != 1)
- dState.R2 = (byte)Clamp(0, R2Sens[device] * dState.R2, 255);
+
+ double l2Sens = getL2Sens(device);
+ if (l2Sens != 1.0)
+ dState.L2 = (byte)Global.Clamp(0, l2Sens * dState.L2, 255);
+
+ double r2Sens = getR2Sens(device);
+ if (r2Sens != 1.0)
+ dState.R2 = (byte)Global.Clamp(0, r2Sens * dState.R2, 255);
+
+ int lsOutCurveMode = lsOutCurveModeArray[device] = getLsOutCurveMode(device);
+ if (lsOutCurveMode > 0)
+ {
+ double tempX = (dState.LX - 127.5) / 127.5;
+ double tempY = (dState.LY - 127.5) / 127.5;
+ double signX = tempX >= 0.0 ? 1.0 : -1.0;
+ double signY = tempY >= 0.0 ? 1.0 : -1.0;
+
+ if (lsOutCurveMode == 1)
+ {
+ double absX = Math.Abs(tempX);
+ double absY = Math.Abs(tempY);
+ double outputX = 0.0;
+ double outputY = 0.0;
+
+ if (absX <= 0.4)
+ {
+ outputX = 0.43 * absX;
+ }
+ else if (absX <= 0.75)
+ {
+ outputX = absX - 0.228;
+ }
+ else if (absX > 0.75)
+ {
+ outputX = (absX * 1.912) - 0.912;
+ }
+
+ if (absY <= 0.4)
+ {
+ outputY = 0.43 * absY;
+ }
+ else if (absY <= 0.75)
+ {
+ outputY = absY - 0.228;
+ }
+ else if (absY > 0.75)
+ {
+ outputY = (absY * 1.912) - 0.912;
+ }
+
+ dState.LX = (byte)(outputX * signX * 127.5 + 127.5);
+ dState.LY = (byte)(outputY * signY * 127.5 + 127.5);
+ }
+ else if (lsOutCurveMode == 2)
+ {
+ double outputX = tempX * tempX;
+ double outputY = tempY * tempY;
+ dState.LX = (byte)(outputX * signX * 127.5 + 127.5);
+ dState.LY = (byte)(outputY * signY * 127.5 + 127.5);
+ }
+ else if (lsOutCurveMode == 3)
+ {
+ double outputX = tempX * tempX * tempX;
+ double outputY = tempY * tempY * tempY;
+ dState.LX = (byte)(outputX * 127.5 + 127.5);
+ dState.LY = (byte)(outputY * 127.5 + 127.5);
+ }
+ }
+
+ int rsOutCurveMode = rsOutCurveModeArray[device] = getRsOutCurveMode(device);
+ if (rsOutCurveMode > 0)
+ {
+ double tempX = (dState.RX - 127.5) / 127.5;
+ double tempY = (dState.RY - 127.5) / 127.5;
+ double signX = tempX >= 0.0 ? 1.0 : -1.0;
+ double signY = tempY >= 0.0 ? 1.0 : -1.0;
+
+ if (rsOutCurveMode == 1)
+ {
+ double absX = Math.Abs(tempX);
+ double absY = Math.Abs(tempY);
+ double outputX = 0.0;
+ double outputY = 0.0;
+
+ if (absX <= 0.4)
+ {
+ outputX = 0.414 * absX;
+ }
+ else if (absX <= 0.75)
+ {
+ outputX = absX - 0.24;
+ }
+ else if (absX > 0.75)
+ {
+ outputX = (absX * 1.9376) - 0.9376;
+ }
+
+ if (absY <= 0.4)
+ {
+ outputY = 0.414 * absY;
+ }
+ else if (absY <= 0.75)
+ {
+ outputY = absY - 0.24;
+ }
+ else if (absY > 0.75)
+ {
+ outputY = (absY * 1.9376) - 0.9376;
+ }
+
+ dState.RX = (byte)(outputX * signX * 127.5 + 127.5);
+ dState.RY = (byte)(outputY * signY * 127.5 + 127.5);
+ }
+ else if (rsOutCurveMode == 2)
+ {
+ double outputX = tempX * tempX;
+ double outputY = tempY * tempY;
+ dState.RX = (byte)(outputX * signX * 127.5 + 127.5);
+ dState.RY = (byte)(outputY * signY * 127.5 + 127.5);
+ }
+ else if (rsOutCurveMode == 3)
+ {
+ double outputX = tempX * tempX * tempX;
+ double outputY = tempY * tempY * tempY;
+ dState.RX = (byte)(outputX * 127.5 + 127.5);
+ dState.RY = (byte)(outputY * 127.5 + 127.5);
+ }
+ }
+
+ int l2OutCurveMode = tempIntArray[device] = getL2OutCurveMode(device);
+ if (l2OutCurveMode > 0)
+ {
+ double temp = dState.L2 / 255.0;
+ if (l2OutCurveMode == 1)
+ {
+ double output = temp * temp;
+ dState.L2 = (byte)(output * 255.0);
+ }
+ else if (l2OutCurveMode == 2)
+ {
+ double output = temp * temp * temp;
+ dState.L2 = (byte)(output * 255.0);
+ }
+ }
+
+ int r2OutCurveMode = tempIntArray[device] = getR2OutCurveMode(device);
+ if (r2OutCurveMode > 0)
+ {
+ double temp = dState.R2 / 255.0;
+ if (r2OutCurveMode == 1)
+ {
+ double output = temp * temp;
+ dState.R2 = (byte)(output * 255.0);
+ }
+ else if (r2OutCurveMode == 2)
+ {
+ double output = temp * temp * temp;
+ dState.R2 = (byte)(output * 255.0);
+ }
+ }
+
+ bool sOff = tempBool = isUsingSAforMouse(device);
+ if (sOff == false)
+ {
+ int SXD = (int)(128d * getSXDeadzone(device));
+ int SZD = (int)(128d * getSZDeadzone(device));
+ double SXMax = getSXMaxzone(device);
+ double SZMax = getSZMaxzone(device);
+ double sxAntiDead = getSXAntiDeadzone(device);
+ double szAntiDead = getSZAntiDeadzone(device);
+ double sxsens = getSXSens(device);
+ double szsens = getSZSens(device);
+ int result = 0;
+
+ int gyroX = cState.Motion.accelX, gyroZ = cState.Motion.accelZ;
+ int absx = Math.Abs(gyroX), absz = Math.Abs(gyroZ);
+
+ if (SXD > 0 || SXMax < 1.0 || sxAntiDead > 0)
+ {
+ int maxValue = (int)(SXMax * 128d);
+ if (absx > SXD)
+ {
+ double ratioX = absx < maxValue ? (absx - SXD) / (double)(maxValue - SXD) : 1.0;
+ dState.Motion.outputAccelX = Math.Sign(gyroX) *
+ (int)Math.Min(128d, sxsens * 128d * ((1.0 - sxAntiDead) * ratioX + sxAntiDead));
+ }
+ else
+ {
+ dState.Motion.outputAccelX = 0;
+ }
+ }
+ else
+ {
+ dState.Motion.outputAccelX = Math.Sign(gyroX) *
+ (int)Math.Min(128d, sxsens * 128d * (absx / 128d));
+ }
+
+ if (SZD > 0 || SZMax < 1.0 || szAntiDead > 0)
+ {
+ int maxValue = (int)(SZMax * 128d);
+ if (absz > SZD)
+ {
+ double ratioZ = absz < maxValue ? (absz - SZD) / (double)(maxValue - SZD) : 1.0;
+ dState.Motion.outputAccelZ = Math.Sign(gyroZ) *
+ (int)Math.Min(128d, szsens * 128d * ((1.0 - szAntiDead) * ratioZ + szAntiDead));
+ }
+ else
+ {
+ dState.Motion.outputAccelZ = 0;
+ }
+ }
+ else
+ {
+ dState.Motion.outputAccelZ = Math.Sign(gyroZ) *
+ (int)Math.Min(128d, szsens * 128d * (absz / 128d));
+ }
+
+ int sxOutCurveMode = tempIntArray[device] = getSXOutCurveMode(device);
+ if (sxOutCurveMode > 0)
+ {
+ double temp = dState.Motion.outputAccelX / 128.0;
+ double sign = Math.Sign(temp);
+ if (sxOutCurveMode == 1)
+ {
+ double output = temp * temp;
+ result = (int)(output * sign * 128.0);
+ dState.Motion.outputAccelX = result;
+ }
+ else if (sxOutCurveMode == 2)
+ {
+ double output = temp * temp * temp;
+ result = (int)(output * 128.0);
+ dState.Motion.outputAccelX = result;
+ }
+ }
+
+ int szOutCurveMode = tempIntArray[device] = getSZOutCurveMode(device);
+ if (szOutCurveMode > 0)
+ {
+ double temp = dState.Motion.outputAccelZ / 128.0;
+ double sign = Math.Sign(temp);
+ if (szOutCurveMode == 1)
+ {
+ double output = temp * temp;
+ result = (int)(output * sign * 128.0);
+ dState.Motion.outputAccelZ = result;
+ }
+ else if (szOutCurveMode == 2)
+ {
+ double output = temp * temp * temp;
+ result = (int)(output * 128.0);
+ dState.Motion.outputAccelZ = result;
+ }
+ }
+ }
+
return dState;
}
+ /* TODO: Possibly remove usage of this version of the method */
private static bool ShiftTrigger(int trigger, int device, DS4State cState, DS4StateExposed eState, Mouse tp)
{
- switch (trigger)
+ bool result = false;
+ if (trigger == 0)
{
- case 1: return getBoolMapping(device, DS4Controls.Cross, cState, eState, tp);
- case 2: return getBoolMapping(device, DS4Controls.Circle, cState, eState, tp);
- case 3: return getBoolMapping(device, DS4Controls.Square, cState, eState, tp);
- case 4: return getBoolMapping(device, DS4Controls.Triangle, cState, eState, tp);
- case 5: return getBoolMapping(device, DS4Controls.Options, cState, eState, tp);
- case 6: return getBoolMapping(device, DS4Controls.Share, cState, eState, tp);
- case 7: return getBoolMapping(device, DS4Controls.DpadUp, cState, eState, tp);
- case 8: return getBoolMapping(device, DS4Controls.DpadDown, cState, eState, tp);
- case 9: return getBoolMapping(device, DS4Controls.DpadLeft, cState, eState, tp);
- case 10: return getBoolMapping(device, DS4Controls.DpadRight, cState, eState, tp);
- case 11: return getBoolMapping(device, DS4Controls.PS, cState, eState, tp);
- case 12: return getBoolMapping(device, DS4Controls.L1, cState, eState, tp);
- case 13: return getBoolMapping(device, DS4Controls.R1, cState, eState, tp);
- case 14: return getBoolMapping(device, DS4Controls.L2, cState, eState, tp);
- case 15: return getBoolMapping(device, DS4Controls.R2, cState, eState, tp);
- case 16: return getBoolMapping(device, DS4Controls.L3, cState, eState, tp);
- case 17: return getBoolMapping(device, DS4Controls.R3, cState, eState, tp);
- case 18: return getBoolMapping(device, DS4Controls.TouchLeft, cState, eState, tp);
- case 19: return getBoolMapping(device, DS4Controls.TouchUpper, cState, eState, tp);
- case 20: return getBoolMapping(device, DS4Controls.TouchMulti, cState, eState, tp);
- case 21: return getBoolMapping(device, DS4Controls.TouchRight, cState, eState, tp);
- case 22: return getBoolMapping(device, DS4Controls.GyroZNeg, cState, eState, tp);
- case 23: return getBoolMapping(device, DS4Controls.GyroZPos, cState, eState, tp);
- case 24: return getBoolMapping(device, DS4Controls.GyroXPos, cState, eState, tp);
- case 25: return getBoolMapping(device, DS4Controls.GyroXNeg, cState, eState, tp);
- case 26: return cState.Touch1;
- default: return false;
+ result = false;
}
+ else
+ {
+ DS4Controls ds = shiftTriggerMapping[trigger];
+ result = getBoolMapping(device, ds, cState, eState, tp);
+ }
+
+ return result;
}
+
+ private static bool ShiftTrigger2(int trigger, int device, DS4State cState, DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMapping)
+ {
+ bool result = false;
+ if (trigger == 0)
+ {
+ result = false;
+ }
+ else if (trigger < 26)
+ {
+ DS4Controls ds = shiftTriggerMapping[trigger];
+ result = getBoolMapping2(device, ds, cState, eState, tp, fieldMapping);
+ }
+ else if (trigger == 26)
+ {
+ result = cState.Touch1Finger;
+ }
+
+ return result;
+ }
+
private static X360Controls getX360ControlsByName(string key)
{
X360Controls x3c;
if (Enum.TryParse(key, true, out x3c))
return x3c;
+
switch (key)
{
case "Back": return X360Controls.Back;
@@ -572,8 +1098,9 @@ namespace DS4Windows
case "Mouse Left": return X360Controls.MouseLeft;
case "Mouse Right": return X360Controls.MouseRight;
case "Unbound": return X360Controls.Unbound;
-
+ default: break;
}
+
return X360Controls.Unbound;
}
@@ -582,55 +1109,46 @@ namespace DS4Windows
///
static bool[] held = new bool[4];
static int[] oldmouse = new int[4] { -1, -1, -1, -1 };
- public static void MapCustom(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
+ public static void MapCustom(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState,
+ Mouse tp, ControlService ctrl)
{
-
+ /* TODO: This method is slow sauce. Find ways to speed up action execution */
MappedState.LX = 127;
MappedState.LY = 127;
MappedState.RX = 127;
MappedState.RY = 127;
- int MouseDeltaX = 0;
- int MouseDeltaY = 0;
-
+ double tempMouseDeltaX = 0.0;
+ double tempMouseDeltaY = 0.0;
+ int mouseDeltaX = 0;
+ int mouseDeltaY = 0;
+
+ cState.calculateStickAngles();
+ DS4StateFieldMapping fieldMapping = fieldMappings[device];
+ fieldMapping.populateFieldMapping(cState, eState, tp);
+ DS4StateFieldMapping outputfieldMapping = outputFieldMappings[device];
+ outputfieldMapping.populateFieldMapping(cState, eState, tp);
+ //DS4StateFieldMapping fieldMapping = new DS4StateFieldMapping(cState, eState, tp);
+ //DS4StateFieldMapping outputfieldMapping = new DS4StateFieldMapping(cState, eState, tp);
+
SyntheticState deviceState = Mapping.deviceState[device];
- if (GetActions().Count > 0 && (ProfileActions[device].Count > 0 || !string.IsNullOrEmpty(tempprofilename[device])))
- MapCustomAction(device, cState, MappedState, eState, tp, ctrl);
+ if (getProfileActionCount(device) > 0 || !string.IsNullOrEmpty(tempprofilename[device]))
+ MapCustomAction(device, cState, MappedState, eState, tp, ctrl, fieldMapping, outputfieldMapping);
if (ctrl.DS4Controllers[device] == null) return;
cState.CopyTo(MappedState);
- List Cross = new List();
- List Circle = new List();
- List Square = new List();
- List Triangle = new List();
- List Options = new List();
- List Share = new List();
- List DpadUp = new List();
- List DpadDown = new List();
- List DpadLeft = new List();
- List DpadRight = new List();
- List PS = new List();
- List L1 = new List();
- List R1 = new List();
- List L2 = new List();
- List R2 = new List();
- List L3 = new List();
- List R3 = new List();
- List LXN = new List();
- List LXP = new List();
- List LYN = new List();
- List LYP = new List();
- List RXN = new List();
- List RXP = new List();
- List RYN = new List();
- List RYP = new List();
+ Dictionary tempControlDict = new Dictionary();
+ //MultiValueDict tempControlDict = new MultiValueDict();
DS4Controls usingExtra = DS4Controls.None;
- foreach (DS4ControlSettings dcs in getDS4CSettings(device))
+ List tempSettingsList = getDS4CSettings(device);
+ //foreach (DS4ControlSettings dcs in getDS4CSettings(device))
+ for (int settingIndex = 0, arlen = tempSettingsList.Count; settingIndex < arlen; settingIndex++)
{
+ DS4ControlSettings dcs = tempSettingsList[settingIndex];
object action = null;
DS4ControlSettings.ActionType actionType = 0;
DS4KeyType keyType = DS4KeyType.None;
- if (dcs.shiftAction != null && ShiftTrigger(dcs.shiftTrigger, device, cState, eState, tp))
+ if (dcs.shiftAction != null && ShiftTrigger2(dcs.shiftTrigger, device, cState, eState, tp, fieldMapping))
{
action = dcs.shiftAction;
actionType = dcs.shiftActionType;
@@ -642,178 +1160,12 @@ namespace DS4Windows
actionType = dcs.actionType;
keyType = dcs.keyType;
}
- if (action != null)
- {
- if (actionType == DS4ControlSettings.ActionType.Macro)
- {
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- {
- resetToDefaultValue(dcs.control, MappedState);
- PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType);
- }
- else if (!getBoolMapping(device, dcs.control, cState, eState, tp))
- {
- EndMacro(device, macroControl, string.Join("/", (int[])action), dcs.control);
- }
- }
- else if (actionType == DS4ControlSettings.ActionType.Key)
- {
- ushort value = ushort.Parse(action.ToString());
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- {
- resetToDefaultValue(dcs.control, MappedState);
- SyntheticState.KeyPresses kp;
- if (!deviceState.keyPresses.TryGetValue(value, out kp))
- deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses();
- if (keyType.HasFlag(DS4KeyType.ScanCode))
- kp.current.scanCodeCount++;
- else
- kp.current.vkCount++;
- if (keyType.HasFlag(DS4KeyType.Toggle))
- {
- if (!pressedonce[value])
- {
- kp.current.toggle = !kp.current.toggle;
- pressedonce[value] = true;
- }
- kp.current.toggleCount++;
- }
- kp.current.repeatCount++;
- }
- else
- pressedonce[value] = false;
- }
- else if (actionType == DS4ControlSettings.ActionType.Button)
- {
- int keyvalue = 0;
- bool isAnalog = dcs.control.ToString().Contains("LX") ||
- dcs.control.ToString().Contains("RX") ||
- dcs.control.ToString().Contains("LY") ||
- dcs.control.ToString().Contains("LY") ||
- dcs.control.ToString().Contains("R2") ||
- dcs.control.ToString().Contains("L2") ||
- dcs.control.ToString().Contains("Gyro");
- switch (getX360ControlsByName(action.ToString()))
- {
- case X360Controls.A: Cross.Add(dcs.control); break;
- case X360Controls.B: Circle.Add(dcs.control); break;
- case X360Controls.X: Square.Add(dcs.control); break;
- case X360Controls.Y: Triangle.Add(dcs.control); break;
- case X360Controls.LB: L1.Add(dcs.control); break;
- case X360Controls.LS: L3.Add(dcs.control); break;
- case X360Controls.RB: R1.Add(dcs.control); break;
- case X360Controls.RS: R3.Add(dcs.control); break;
- case X360Controls.DpadUp: DpadUp.Add(dcs.control); break;
- case X360Controls.DpadDown: DpadDown.Add(dcs.control); break;
- case X360Controls.DpadLeft: DpadLeft.Add(dcs.control); break;
- case X360Controls.DpadRight: DpadRight.Add(dcs.control); break;
- case X360Controls.Start: Options.Add(dcs.control); break;
- case X360Controls.Guide: PS.Add(dcs.control); break;
- case X360Controls.Back: Share.Add(dcs.control); break;
- case X360Controls.LXNeg: LXN.Add(dcs.control); break;
- case X360Controls.LYNeg: LYN.Add(dcs.control); break;
- case X360Controls.RXNeg: RXN.Add(dcs.control); break;
- case X360Controls.RYNeg: RYN.Add(dcs.control); break;
- case X360Controls.LXPos: LXP.Add(dcs.control); break;
- case X360Controls.LYPos: LYP.Add(dcs.control); break;
- case X360Controls.RXPos: RXP.Add(dcs.control); break;
- case X360Controls.RYPos: RYP.Add(dcs.control); break;
- case X360Controls.LT: L2.Add(dcs.control); break;
- case X360Controls.RT: R2.Add(dcs.control); break;
- case X360Controls.LeftMouse:
- keyvalue = 256;
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- deviceState.currentClicks.leftCount++;
- break;
- case X360Controls.RightMouse:
- keyvalue = 257;
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- deviceState.currentClicks.rightCount++;
- break;
- case X360Controls.MiddleMouse:
- keyvalue = 258;
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- deviceState.currentClicks.middleCount++;
- break;
- case X360Controls.FourthMouse:
- keyvalue = 259;
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- deviceState.currentClicks.fourthCount++;
- break;
- case X360Controls.FifthMouse:
- keyvalue = 260;
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- deviceState.currentClicks.fifthCount++;
- break;
- case X360Controls.WUP:
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- if (isAnalog)
- getMouseWheelMapping(device, dcs.control, cState, eState, tp, false);
- else
- deviceState.currentClicks.wUpCount++;
- break;
- case X360Controls.WDOWN:
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- if (isAnalog)
- getMouseWheelMapping(device, dcs.control, cState, eState, tp, true);
- else
- deviceState.currentClicks.wDownCount++;
- break;
- case X360Controls.MouseUp:
- if (MouseDeltaY == 0)
- {
- MouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 0);
- MouseDeltaY = -Math.Abs((MouseDeltaY == -2147483648 ? 0 : MouseDeltaY));
- }
- break;
- case X360Controls.MouseDown:
- if (MouseDeltaY == 0)
- {
- MouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, 1);
- MouseDeltaY = Math.Abs((MouseDeltaY == -2147483648 ? 0 : MouseDeltaY));
- }
- break;
- case X360Controls.MouseLeft:
- if (MouseDeltaX == 0)
- {
- MouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 2);
- MouseDeltaX = -Math.Abs((MouseDeltaX == -2147483648 ? 0 : MouseDeltaX));
- }
- break;
- case X360Controls.MouseRight:
- if (MouseDeltaX == 0)
- {
- MouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, 3);
- MouseDeltaX = Math.Abs((MouseDeltaX == -2147483648 ? 0 : MouseDeltaX));
- }
- break;
- }
- if (keyType.HasFlag(DS4KeyType.Toggle))
- {
- if (getBoolMapping(device, dcs.control, cState, eState, tp))
- {
- resetToDefaultValue(dcs.control, MappedState);
- if (!pressedonce[keyvalue])
- {
- deviceState.currentClicks.toggle = !deviceState.currentClicks.toggle;
- pressedonce[keyvalue] = true;
- }
- deviceState.currentClicks.toggleCount++;
- }
- else
- {
- pressedonce[keyvalue] = false;
- }
- }
- resetToDefaultValue(dcs.control, MappedState); // erase default mappings for things that are remapped
- }
- }
if (usingExtra == DS4Controls.None || usingExtra == dcs.control)
{
- bool shiftE = dcs.shiftExtras != "0,0,0,0,0,0,0,0" && dcs.shiftExtras != "" && ShiftTrigger(dcs.shiftTrigger, device, cState, eState, tp);
- bool regE = dcs.extras != "0,0,0,0,0,0,0,0" && dcs.extras != "";
- if ((regE || shiftE) && getBoolMapping(device, dcs.control, cState, eState, tp))
+ bool shiftE = !string.IsNullOrEmpty(dcs.shiftExtras) && ShiftTrigger2(dcs.shiftTrigger, device, cState, eState, tp, fieldMapping);
+ bool regE = !string.IsNullOrEmpty(dcs.extras);
+ if ((regE || shiftE) && getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
{
usingExtra = dcs.control;
string p;
@@ -821,19 +1173,23 @@ namespace DS4Windows
p = dcs.shiftExtras;
else
p = dcs.extras;
+
string[] extraS = p.Split(',');
- int[] extras = new int[extraS.Length];
- for (int i = 0; i < extraS.Length; i++)
+ int extrasSLen = extraS.Length;
+ int[] extras = new int[extrasSLen];
+ for (int i = 0; i < extrasSLen; i++)
{
int b;
if (int.TryParse(extraS[i], out b))
extras[i] = b;
}
+
held[device] = true;
try
{
if (!(extras[0] == extras[1] && extras[1] == 0))
ctrl.setRumble((byte)extras[0], (byte)extras[1], device);
+
if (extras[2] == 1)
{
DS4Color color = new DS4Color { red = (byte)extras[3], green = (byte)extras[4], blue = (byte)extras[5] };
@@ -841,6 +1197,7 @@ namespace DS4Windows
DS4LightBar.forcedFlash[device] = (byte)extras[6];
DS4LightBar.forcelight[device] = true;
}
+
if (extras[7] == 1)
{
if (oldmouse[device] == -1)
@@ -854,197 +1211,505 @@ namespace DS4Windows
{
DS4LightBar.forcelight[device] = false;
DS4LightBar.forcedFlash[device] = 0;
- ButtonMouseSensitivity[device] = oldmouse[device];
- oldmouse[device] = -1;
+ if (oldmouse[device] != -1)
+ {
+ ButtonMouseSensitivity[device] = oldmouse[device];
+ oldmouse[device] = -1;
+ }
+
ctrl.setRumble(0, 0, device);
held[device] = false;
usingExtra = DS4Controls.None;
}
}
- }
- if (macroControl[00]) MappedState.Cross = true;
- if (macroControl[01]) MappedState.Circle = true;
- if (macroControl[02]) MappedState.Square = true;
- if (macroControl[03]) MappedState.Triangle = true;
- if (macroControl[04]) MappedState.Options = true;
- if (macroControl[05]) MappedState.Share = true;
- if (macroControl[06]) MappedState.DpadUp = true;
- if (macroControl[07]) MappedState.DpadDown = true;
- if (macroControl[08]) MappedState.DpadLeft = true;
- if (macroControl[09]) MappedState.DpadRight = true;
- if (macroControl[10]) MappedState.PS = true;
- if (macroControl[11]) MappedState.L1 = true;
- if (macroControl[12]) MappedState.R1 = true;
- if (macroControl[13]) MappedState.L2 = 255;
- if (macroControl[14]) MappedState.R2 = 255;
- if (macroControl[15]) MappedState.L3 = true;
- if (macroControl[16]) MappedState.R3 = true;
- if (macroControl[17]) MappedState.LX = 255;
- if (macroControl[18]) MappedState.LX = 0;
- if (macroControl[19]) MappedState.LY = 255;
- if (macroControl[20]) MappedState.LY = 0;
- if (macroControl[21]) MappedState.RX = 255;
- if (macroControl[22]) MappedState.RX = 0;
- if (macroControl[23]) MappedState.RY = 255;
- if (macroControl[24]) MappedState.RY = 0;
- foreach (DS4Controls dc in Cross)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.Cross = true;
- foreach (DS4Controls dc in Circle)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.Circle = true;
- foreach (DS4Controls dc in Square)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.Square = true;
- foreach (DS4Controls dc in Triangle)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.Triangle = true;
- foreach (DS4Controls dc in L1)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.L1 = true;
- foreach (DS4Controls dc in L2)
- if (getByteMapping(device, dc, cState, eState, tp) > 5)
- MappedState.L2 = getByteMapping(device, dc, cState, eState, tp);
- foreach (DS4Controls dc in L3)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.L3 = true;
- foreach (DS4Controls dc in R1)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.R1 = true;
- foreach (DS4Controls dc in R2)
- if (getByteMapping(device, dc, cState, eState, tp) > 5)
- MappedState.R2 = getByteMapping(device, dc, cState, eState, tp);
- foreach (DS4Controls dc in R3)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.R3 = true;
- foreach (DS4Controls dc in DpadUp)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.DpadUp = true;
- foreach (DS4Controls dc in DpadRight)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.DpadRight = true;
- foreach (DS4Controls dc in DpadLeft)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.DpadLeft = true;
- foreach (DS4Controls dc in DpadDown)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.DpadDown = true;
- foreach (DS4Controls dc in Options)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.Options = true;
- foreach (DS4Controls dc in Share)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.Share = true;
- foreach (DS4Controls dc in PS)
- if (getBoolMapping(device, dc, cState, eState, tp))
- MappedState.PS = true;
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.LXNeg.ToString()), device, cState, eState, tp), DS4Controls.LXNeg))
- LXN.Add(DS4Controls.LXNeg);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.LXPos.ToString()), device, cState, eState, tp), DS4Controls.LXPos))
- LXP.Add(DS4Controls.LXPos);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.LYNeg.ToString()), device, cState, eState, tp), DS4Controls.LYNeg))
- LYN.Add(DS4Controls.LYNeg);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.LYPos.ToString()), device, cState, eState, tp), DS4Controls.LYPos))
- LYP.Add(DS4Controls.LYPos);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.RXNeg.ToString()), device, cState, eState, tp), DS4Controls.RXNeg))
- RXN.Add(DS4Controls.RXNeg);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.RXPos.ToString()), device, cState, eState, tp), DS4Controls.RXPos))
- RXP.Add(DS4Controls.RXPos);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.RYNeg.ToString()), device, cState, eState, tp), DS4Controls.RYNeg))
- RYN.Add(DS4Controls.RYNeg);
-
- if (IfAxisIsNotModified(device, ShiftTrigger(GetDS4STrigger(device, DS4Controls.RYPos.ToString()), device, cState, eState, tp), DS4Controls.RYPos))
- RYP.Add(DS4Controls.RYPos);
-
- if (Math.Abs(MappedState.LX - 127) < 10)
- if (LXN.Count > 0 || LXP.Count > 0)
+ if (action != null)
{
- foreach (DS4Controls dc in LXP)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
- MappedState.LX = getXYAxisMapping(device, dc, cState, eState, tp, true);
- foreach (DS4Controls dc in LXN)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
- MappedState.LX = getXYAxisMapping(device, dc, cState, eState, tp);
+ if (actionType == DS4ControlSettings.ActionType.Macro)
+ {
+ bool active = getBoolMapping2(device, dcs.control, cState, eState, tp, fieldMapping);
+ if (active)
+ {
+ PlayMacro(device, macroControl, string.Join("/", (int[])action), dcs.control, keyType);
+ }
+ else
+ {
+ EndMacro(device, macroControl, string.Join("/", (int[])action), dcs.control);
+ }
+
+ // erase default mappings for things that are remapped
+ resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
+ }
+ else if (actionType == DS4ControlSettings.ActionType.Key)
+ {
+ ushort value = Convert.ToUInt16(action);
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ {
+ SyntheticState.KeyPresses kp;
+ if (!deviceState.keyPresses.TryGetValue(value, out kp))
+ deviceState.keyPresses[value] = kp = new SyntheticState.KeyPresses();
+
+ if (keyType.HasFlag(DS4KeyType.ScanCode))
+ kp.current.scanCodeCount++;
+ else
+ kp.current.vkCount++;
+
+ if (keyType.HasFlag(DS4KeyType.Toggle))
+ {
+ if (!pressedonce[value])
+ {
+ kp.current.toggle = !kp.current.toggle;
+ pressedonce[value] = true;
+ }
+ kp.current.toggleCount++;
+ }
+ kp.current.repeatCount++;
+ }
+ else
+ pressedonce[value] = false;
+
+ // erase default mappings for things that are remapped
+ resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
+ }
+ else if (actionType == DS4ControlSettings.ActionType.Button)
+ {
+ int keyvalue = 0;
+ bool isAnalog = false;
+
+ if (dcs.control >= DS4Controls.LXNeg && dcs.control <= DS4Controls.RYPos)
+ {
+ isAnalog = true;
+ }
+ else if (dcs.control == DS4Controls.L2 || dcs.control == DS4Controls.R2)
+ {
+ isAnalog = true;
+ }
+ else if (dcs.control >= DS4Controls.GyroXPos && dcs.control <= DS4Controls.GyroZNeg)
+ {
+ isAnalog = true;
+ }
+
+ X360Controls xboxControl = X360Controls.None;
+ if (action is X360Controls)
+ {
+ xboxControl = (X360Controls)action;
+ }
+ else if (action is string)
+ {
+ xboxControl = getX360ControlsByName(action.ToString());
+ }
+
+ if (xboxControl >= X360Controls.LXNeg && xboxControl <= X360Controls.Start)
+ {
+ DS4Controls tempDS4Control = reverseX360ButtonMapping[(int)xboxControl];
+ tempControlDict.Add(dcs.control, tempDS4Control);
+ }
+ else if (xboxControl >= X360Controls.LeftMouse && xboxControl <= X360Controls.WDOWN)
+ {
+ switch (xboxControl)
+ {
+ case X360Controls.LeftMouse:
+ {
+ keyvalue = 256;
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ deviceState.currentClicks.leftCount++;
+
+ break;
+ }
+ case X360Controls.RightMouse:
+ {
+ keyvalue = 257;
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ deviceState.currentClicks.rightCount++;
+
+ break;
+ }
+ case X360Controls.MiddleMouse:
+ {
+ keyvalue = 258;
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ deviceState.currentClicks.middleCount++;
+
+ break;
+ }
+ case X360Controls.FourthMouse:
+ {
+ keyvalue = 259;
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ deviceState.currentClicks.fourthCount++;
+
+ break;
+ }
+ case X360Controls.FifthMouse:
+ {
+ keyvalue = 260;
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ deviceState.currentClicks.fifthCount++;
+
+ break;
+ }
+ case X360Controls.WUP:
+ {
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ {
+ if (isAnalog)
+ getMouseWheelMapping(device, dcs.control, cState, eState, tp, false);
+ else
+ deviceState.currentClicks.wUpCount++;
+ }
+
+ break;
+ }
+ case X360Controls.WDOWN:
+ {
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ {
+ if (isAnalog)
+ getMouseWheelMapping(device, dcs.control, cState, eState, tp, true);
+ else
+ deviceState.currentClicks.wDownCount++;
+ }
+
+ break;
+ }
+
+ default: break;
+ }
+ }
+ else if (xboxControl >= X360Controls.MouseUp && xboxControl <= X360Controls.MouseRight)
+ {
+ switch (xboxControl)
+ {
+ case X360Controls.MouseUp:
+ {
+ if (tempMouseDeltaY == 0)
+ {
+ tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 0, ctrl);
+ tempMouseDeltaY = -Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
+ }
+
+ break;
+ }
+ case X360Controls.MouseDown:
+ {
+ if (tempMouseDeltaY == 0)
+ {
+ tempMouseDeltaY = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 1, ctrl);
+ tempMouseDeltaY = Math.Abs((tempMouseDeltaY == -2147483648 ? 0 : tempMouseDeltaY));
+ }
+
+ break;
+ }
+ case X360Controls.MouseLeft:
+ {
+ if (tempMouseDeltaX == 0)
+ {
+ tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 2, ctrl);
+ tempMouseDeltaX = -Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
+ }
+
+ break;
+ }
+ case X360Controls.MouseRight:
+ {
+ if (tempMouseDeltaX == 0)
+ {
+ tempMouseDeltaX = getMouseMapping(device, dcs.control, cState, eState, fieldMapping, 3, ctrl);
+ tempMouseDeltaX = Math.Abs((tempMouseDeltaX == -2147483648 ? 0 : tempMouseDeltaX));
+ }
+
+ break;
+ }
+
+ default: break;
+ }
+ }
+
+ if (keyType.HasFlag(DS4KeyType.Toggle))
+ {
+ if (getBoolActionMapping2(device, dcs.control, cState, eState, tp, fieldMapping))
+ {
+ resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
+ if (!pressedonce[keyvalue])
+ {
+ deviceState.currentClicks.toggle = !deviceState.currentClicks.toggle;
+ pressedonce[keyvalue] = true;
+ }
+ deviceState.currentClicks.toggleCount++;
+ }
+ else
+ {
+ pressedonce[keyvalue] = false;
+ }
+ }
+
+ // erase default mappings for things that are remapped
+ resetToDefaultValue2(dcs.control, MappedState, outputfieldMapping);
+ }
}
- //else
- //MappedState.LX = cState.LX;
- if (Math.Abs(MappedState.LY - 127) < 10)
- if (LYN.Count > 0 || LYP.Count > 0)
+ }
+
+ outputfieldMapping.populateState(MappedState);
+
+ if (macroCount > 0)
+ {
+ if (macroControl[00]) MappedState.Cross = true;
+ if (macroControl[01]) MappedState.Circle = true;
+ if (macroControl[02]) MappedState.Square = true;
+ if (macroControl[03]) MappedState.Triangle = true;
+ if (macroControl[04]) MappedState.Options = true;
+ if (macroControl[05]) MappedState.Share = true;
+ if (macroControl[06]) MappedState.DpadUp = true;
+ if (macroControl[07]) MappedState.DpadDown = true;
+ if (macroControl[08]) MappedState.DpadLeft = true;
+ if (macroControl[09]) MappedState.DpadRight = true;
+ if (macroControl[10]) MappedState.PS = true;
+ if (macroControl[11]) MappedState.L1 = true;
+ if (macroControl[12]) MappedState.R1 = true;
+ if (macroControl[13]) MappedState.L2 = 255;
+ if (macroControl[14]) MappedState.R2 = 255;
+ if (macroControl[15]) MappedState.L3 = true;
+ if (macroControl[16]) MappedState.R3 = true;
+ if (macroControl[17]) MappedState.LX = 255;
+ if (macroControl[18]) MappedState.LX = 0;
+ if (macroControl[19]) MappedState.LY = 255;
+ if (macroControl[20]) MappedState.LY = 0;
+ if (macroControl[21]) MappedState.RX = 255;
+ if (macroControl[22]) MappedState.RX = 0;
+ if (macroControl[23]) MappedState.RY = 255;
+ if (macroControl[24]) MappedState.RY = 0;
+ }
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.LXNeg), device, cState, eState, tp, fieldMapping), DS4Controls.LXNeg))
+ tempControlDict[DS4Controls.LXNeg] = DS4Controls.LXNeg;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.LXPos), device, cState, eState, tp, fieldMapping), DS4Controls.LXPos))
+ tempControlDict[DS4Controls.LXPos] = DS4Controls.LXPos;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.LYNeg), device, cState, eState, tp, fieldMapping), DS4Controls.LYNeg))
+ tempControlDict[DS4Controls.LYNeg] = DS4Controls.LYNeg;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.LYPos), device, cState, eState, tp, fieldMapping), DS4Controls.LYPos))
+ tempControlDict[DS4Controls.LYPos] = DS4Controls.LYPos;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.RXNeg), device, cState, eState, tp, fieldMapping), DS4Controls.RXNeg))
+ tempControlDict[DS4Controls.RXNeg] = DS4Controls.RXNeg;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.RXPos), device, cState, eState, tp, fieldMapping), DS4Controls.RXPos))
+ tempControlDict[DS4Controls.RXPos] = DS4Controls.RXPos;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.RYNeg), device, cState, eState, tp, fieldMapping), DS4Controls.RYNeg))
+ tempControlDict[DS4Controls.RYNeg] = DS4Controls.RYNeg;
+
+ if (IfAxisIsNotModified(device, ShiftTrigger2(GetDS4STrigger(device, DS4Controls.RYPos), device, cState, eState, tp, fieldMapping), DS4Controls.RYPos))
+ tempControlDict[DS4Controls.RYPos] = DS4Controls.RYPos;
+
+ Dictionary.KeyCollection controlKeys = tempControlDict.Keys;
+ //Dictionary>.KeyCollection controlKeys = tempControlDict.Keys;
+
+ //foreach (KeyValuePair entry in tempControlDict)
+ for (int i = 0, keyCount = controlKeys.Count; i < keyCount; i++)
+ {
+ DS4Controls key = controlKeys.ElementAt(i);
+ DS4Controls dc = tempControlDict[key];
+ //DS4Controls key = entry.Key;
+ //DS4Controls dc = entry.Value;
+
+ if (getBoolActionMapping2(device, key, cState, eState, tp, fieldMapping, true))
{
- foreach (DS4Controls dc in LYN)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
- MappedState.LY = getXYAxisMapping(device, dc, cState, eState, tp);
- foreach (DS4Controls dc in LYP)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
- MappedState.LY = getXYAxisMapping(device, dc, cState, eState, tp, true);
+ if (dc >= DS4Controls.Square && dc <= DS4Controls.Cross)
+ {
+ switch (dc)
+ {
+ case DS4Controls.Cross: MappedState.Cross = true; break;
+ case DS4Controls.Circle: MappedState.Circle = true; break;
+ case DS4Controls.Square: MappedState.Square = true; break;
+ case DS4Controls.Triangle: MappedState.Triangle = true; break;
+ default: break;
+ }
+ }
+ else if (dc >= DS4Controls.L1 && dc <= DS4Controls.R3)
+ {
+ switch (dc)
+ {
+ case DS4Controls.L1: MappedState.L1 = true; break;
+ case DS4Controls.L2: MappedState.L2 = getByteMapping2(device, key, cState, eState, tp, fieldMapping); break;
+ case DS4Controls.L3: MappedState.L3 = true; break;
+ case DS4Controls.R1: MappedState.R1 = true; break;
+ case DS4Controls.R2: MappedState.R2 = getByteMapping2(device, key, cState, eState, tp, fieldMapping); break;
+ case DS4Controls.R3: MappedState.R3 = true; break;
+ default: break;
+ }
+ }
+ else if (dc >= DS4Controls.DpadUp && dc <= DS4Controls.DpadLeft)
+ {
+ switch (dc)
+ {
+ case DS4Controls.DpadUp: MappedState.DpadUp = true; break;
+ case DS4Controls.DpadRight: MappedState.DpadRight = true; break;
+ case DS4Controls.DpadLeft: MappedState.DpadLeft = true; break;
+ case DS4Controls.DpadDown: MappedState.DpadDown = true; break;
+ default: break;
+ }
+ }
+ else if (dc >= DS4Controls.LXNeg && dc <= DS4Controls.RYPos)
+ {
+ switch (dc)
+ {
+ case DS4Controls.LXNeg:
+ case DS4Controls.LXPos:
+ {
+ if (MappedState.LX == 127)
+ {
+ if (dc == DS4Controls.LXNeg)
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping);
+ MappedState.LX = axisMapping;
+ }
+ else
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping, true);
+ MappedState.LX = axisMapping;
+ }
+ }
+
+ break;
+ }
+ case DS4Controls.LYNeg:
+ case DS4Controls.LYPos:
+ {
+ if (MappedState.LY == 127)
+ {
+ if (dc == DS4Controls.LYNeg)
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping);
+ MappedState.LY = axisMapping;
+ }
+ else
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping, true);
+ MappedState.LY = axisMapping;
+ }
+ }
+
+ break;
+ }
+ case DS4Controls.RXNeg:
+ case DS4Controls.RXPos:
+ {
+ if (MappedState.RX == 127)
+ {
+ if (dc == DS4Controls.RXNeg)
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping);
+ MappedState.RX = axisMapping;
+ }
+ else
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping, true);
+ MappedState.RX = axisMapping;
+ }
+ }
+
+ break;
+ }
+ case DS4Controls.RYNeg:
+ case DS4Controls.RYPos:
+ {
+ if (MappedState.RY == 127)
+ {
+ if (dc == DS4Controls.RYNeg)
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping);
+ MappedState.RY = axisMapping;
+ }
+ else
+ {
+ byte axisMapping = getXYAxisMapping2(device, key, cState, eState, tp, fieldMapping, true);
+ MappedState.RY = axisMapping;
+ }
+ }
+
+ break;
+ }
+ default: break;
+ }
+ }
+ else
+ {
+ switch (dc)
+ {
+ case DS4Controls.Options: MappedState.Options = true; break;
+ case DS4Controls.Share: MappedState.Share = true; break;
+ case DS4Controls.PS: MappedState.PS = true; break;
+ default: break;
+ }
+ }
}
- //else
- //MappedState.LY = cState.LY;
- if (Math.Abs(MappedState.RX - 127) < 10)
- if (RXN.Count > 0 || RXP.Count > 0)
- {
- foreach (DS4Controls dc in RXN)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
- MappedState.RX = getXYAxisMapping(device, dc, cState, eState, tp);
- foreach (DS4Controls dc in RXP)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
- MappedState.RX = getXYAxisMapping(device, dc, cState, eState, tp, true);
- }
- //else
- // MappedState.RX = cState.RX;
- if (Math.Abs(MappedState.RY - 127) < 10)
- if (RYN.Count > 0 || RYP.Count > 0)
- {
- foreach (DS4Controls dc in RYN)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp)) > 5)
- MappedState.RY = getXYAxisMapping(device, dc, cState, eState, tp);
- foreach (DS4Controls dc in RYP)
- if (Math.Abs(127 - getXYAxisMapping(device, dc, cState, eState, tp, true)) > 5)
- MappedState.RY = getXYAxisMapping(device, dc, cState, eState, tp, true);
- }
- // else
- // MappedState.RY = cState.RY;
- InputMethods.MoveCursorBy(MouseDeltaX, MouseDeltaY);
+ }
+
+ calculateFinalMouseMovement(ref tempMouseDeltaX, ref tempMouseDeltaY,
+ out mouseDeltaX, out mouseDeltaY);
+ if (mouseDeltaX != 0 || mouseDeltaY != 0)
+ {
+ InputMethods.MoveCursorBy(mouseDeltaX, mouseDeltaY);
+ }
}
private static bool IfAxisIsNotModified(int device, bool shift, DS4Controls dc)
{
- return shift ? false : GetDS4Action(device, dc.ToString(), false) == null;
+ return shift ? false : GetDS4Action(device, dc, false) == null;
}
- public static async void MapCustomAction(int device, DS4State cState, DS4State MappedState, DS4StateExposed eState, Mouse tp, ControlService ctrl)
+
+ private static async void MapCustomAction(int device, DS4State cState, DS4State MappedState,
+ DS4StateExposed eState, Mouse tp, ControlService ctrl, DS4StateFieldMapping fieldMapping, DS4StateFieldMapping outputfieldMapping)
{
- try {
- foreach (string actionname in ProfileActions[device])
+ /* TODO: This method is slow sauce. Find ways to speed up action execution */
+ try
+ {
+ int actionDoneCount = actionDone.Count;
+ int totalActionCount = GetActions().Count;
+ DS4StateFieldMapping previousFieldMapping = null;
+ List profileActions = getProfileActions(device);
+ //foreach (string actionname in profileActions)
+ for (int actionIndex = 0, profileListLen = profileActions.Count;
+ actionIndex < profileListLen; actionIndex++)
{
//DS4KeyType keyType = getShiftCustomKeyType(device, customKey.Key);
- SpecialAction action = GetAction(actionname);
- int index = GetActionIndexOf(actionname);
- if (actionDone.Count < index + 1)
+ //SpecialAction action = GetAction(actionname);
+ //int index = GetActionIndexOf(actionname);
+ string actionname = profileActions[actionIndex];
+ SpecialAction action = GetProfileAction(device, actionname);
+ int index = GetProfileActionIndexOf(device, actionname);
+
+ if (actionDoneCount < index + 1)
+ {
actionDone.Add(new ActionState());
- else if (actionDone.Count > GetActions().Count())
- actionDone.RemoveAt(actionDone.Count - 1);
- double time;
+ actionDoneCount++;
+ }
+ else if (actionDoneCount > totalActionCount)
+ {
+ actionDone.RemoveAt(actionDoneCount - 1);
+ actionDoneCount--;
+ }
+
+ double time = 0.0;
//If a key or button is assigned to the trigger, a key special action is used like
//a quick tap to use and hold to use the regular custom button/key
- bool triggerToBeTapped = action.type == "Key" && action.trigger.Count == 1 &&
- GetDS4Action(device, action.trigger[0].ToString(), false) == null;
- if (!(action.name == "null" || index < 0))
+ bool triggerToBeTapped = action.typeID == SpecialAction.ActionTypeId.None && action.trigger.Count == 1 &&
+ GetDS4Action(device, action.trigger[0], false) == null;
+ if (!(action.typeID == SpecialAction.ActionTypeId.None || index < 0))
{
bool triggeractivated = true;
- if (action.delayTime > 0)
+ if (action.delayTime > 0.0)
{
triggeractivated = false;
bool subtriggeractivated = true;
- foreach (DS4Controls dc in action.trigger)
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{
- if (!getBoolMapping(device, dc, cState, eState, tp))
+ DS4Controls dc = action.trigger[i];
+ if (!getBoolMapping2(device, dc, cState, eState, tp, fieldMapping))
{
subtriggeractivated = false;
break;
@@ -1064,9 +1729,11 @@ namespace DS4Windows
{
triggeractivated = false;
bool subtriggeractivated = true;
- foreach (DS4Controls dc in action.trigger)
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{
- if (!getBoolMapping(device, dc, cState, eState, tp))
+ DS4Controls dc = action.trigger[i];
+ if (!getBoolMapping2(device, dc, cState, eState, tp, fieldMapping))
{
subtriggeractivated = false;
break;
@@ -1081,9 +1748,11 @@ namespace DS4Windows
{
triggeractivated = false;
bool subtriggeractivated = true;
- foreach (DS4Controls dc in action.trigger)
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{
- if (!getBoolMapping(device, dc, cState, eState, tp))
+ DS4Controls dc = action.trigger[i];
+ if (!getBoolMapping2(device, dc, cState, eState, tp, fieldMapping))
{
subtriggeractivated = false;
break;
@@ -1100,21 +1769,28 @@ namespace DS4Windows
oldnowKeyAct[device] = DateTime.MinValue;
}
else
- foreach (DS4Controls dc in action.trigger)
+ {
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{
- if (!getBoolMapping(device, dc, cState, eState, tp))
+ DS4Controls dc = action.trigger[i];
+ if (!getBoolMapping2(device, dc, cState, eState, tp, fieldMapping))
{
triggeractivated = false;
break;
}
}
+ }
bool utriggeractivated = true;
- if (action.type == "Key" && action.uTrigger.Count > 0)
+ int uTriggerCount = action.uTrigger.Count;
+ if (action.typeID == SpecialAction.ActionTypeId.Key && uTriggerCount > 0)
{
- foreach (DS4Controls dc in action.uTrigger)
+ //foreach (DS4Controls dc in action.uTrigger)
+ for (int i = 0, arlen = action.uTrigger.Count; i < arlen; i++)
{
- if (!getBoolMapping(device, dc, cState, eState, tp))
+ DS4Controls dc = action.uTrigger[i];
+ if (!getBoolMapping2(device, dc, cState, eState, tp, fieldMapping))
{
utriggeractivated = false;
break;
@@ -1123,274 +1799,368 @@ namespace DS4Windows
if (action.pressRelease) utriggeractivated = !utriggeractivated;
}
- if (triggeractivated && action.type == "Program")
+ bool actionFound = false;
+ if (triggeractivated)
{
- if (!actionDone[index].dev[device])
+ if (action.typeID == SpecialAction.ActionTypeId.Program)
{
- actionDone[index].dev[device] = true;
- if (!string.IsNullOrEmpty(action.extra))
- Process.Start(action.details, action.extra);
- else
- Process.Start(action.details);
- }
- }
- else if (triggeractivated && action.type == "Profile")
- {
- if (!actionDone[index].dev[device] && string.IsNullOrEmpty(tempprofilename[device]))
- {
- actionDone[index].dev[device] = true;
- untriggeraction[device] = action;
- untriggerindex[device] = index;
- foreach (DS4Controls dc in action.trigger)
- {
- DS4ControlSettings dcs = getDS4CSetting(device, dc.ToString());
- if (dcs.action != null)
- {
- if (dcs.actionType == DS4ControlSettings.ActionType.Key)
- InputMethods.performKeyRelease(ushort.Parse(action.ToString()));
- else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
- {
- int[] keys = (int[])dcs.action;
- for (int i = 0; i < keys.Length; i++)
- InputMethods.performKeyRelease((ushort)keys[i]);
- }
- }
- }
- LoadTempProfile(device, action.details, true, ctrl);
- return;
- }
- }
- else if (triggeractivated && action.type == "Macro")
- {
- if (!actionDone[index].dev[device])
- {
- DS4KeyType keyType = action.keyType;
- actionDone[index].dev[device] = true;
- foreach (DS4Controls dc in action.trigger)
- resetToDefaultValue(dc, MappedState);
- PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType);
- }
- else
- EndMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None);
- }
- else if (triggeractivated && action.type == "Key")
- {
- if (action.uTrigger.Count == 0 || (action.uTrigger.Count > 0 && untriggerindex[device] == -1 && !actionDone[index].dev[device]))
- {
- actionDone[index].dev[device] = true;
- untriggerindex[device] = index;
- ushort key;
- ushort.TryParse(action.details, out key);
- if (action.uTrigger.Count == 0)
- {
- SyntheticState.KeyPresses kp;
- if (!deviceState[device].keyPresses.TryGetValue(key, out kp))
- deviceState[device].keyPresses[key] = kp = new SyntheticState.KeyPresses();
- if (action.keyType.HasFlag(DS4KeyType.ScanCode))
- kp.current.scanCodeCount++;
- else
- kp.current.vkCount++;
- kp.current.repeatCount++;
- }
- else if (action.keyType.HasFlag(DS4KeyType.ScanCode))
- InputMethods.performSCKeyPress(key);
- else
- InputMethods.performKeyPress(key);
- }
- }
- else if (action.uTrigger.Count > 0 && utriggeractivated && action.type == "Key")
- {
- if (untriggerindex[device] > -1 && !actionDone[index].dev[device])
- {
- actionDone[index].dev[device] = true;
- untriggerindex[device] = -1;
- ushort key;
- ushort.TryParse(action.details, out key);
- if (action.keyType.HasFlag(DS4KeyType.ScanCode))
- InputMethods.performSCKeyRelease(key);
- else
- InputMethods.performKeyRelease(key);
- }
- }
- else if (triggeractivated && action.type == "DisconnectBT")
- {
- DS4Device d = ctrl.DS4Controllers[device];
- if (!d.Charging)
- {
- d.DisconnectBT();
- foreach (DS4Controls dc in action.trigger)
- {
- DS4ControlSettings dcs = getDS4CSetting(device, dc.ToString());
- if (dcs.action != null)
- {
- if (dcs.actionType == DS4ControlSettings.ActionType.Key)
- InputMethods.performKeyRelease((ushort)dcs.action);
- else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
- {
- int[] keys = (int[])dcs.action;
- for (int i = 0; i < keys.Length; i++)
- InputMethods.performKeyRelease((ushort)keys[i]);
- }
- }
- }
- return;
- }
- }
- else if (triggeractivated && action.type == "BatteryCheck")
- {
- string[] dets = action.details.Split('|');
- if (dets.Length == 1)
- dets = action.details.Split(',');
- if (bool.Parse(dets[1]) && !actionDone[index].dev[device])
- {
- Log.LogToTray("Controller " + (device + 1) + ": " +
- ctrl.getDS4Battery(device), true);
- }
- if (bool.Parse(dets[2]))
- {
- DS4Device d = ctrl.DS4Controllers[device];
+ actionFound = true;
+
if (!actionDone[index].dev[device])
{
- lastColor[device] = d.LightBarColor;
- DS4LightBar.forcelight[device] = true;
+ actionDone[index].dev[device] = true;
+ if (!string.IsNullOrEmpty(action.extra))
+ Process.Start(action.details, action.extra);
+ else
+ Process.Start(action.details);
}
- DS4Color empty = new DS4Color(byte.Parse(dets[3]), byte.Parse(dets[4]), byte.Parse(dets[5]));
- DS4Color full = new DS4Color(byte.Parse(dets[6]), byte.Parse(dets[7]), byte.Parse(dets[8]));
- DS4Color trans = getTransitionedColor(empty, full, d.Battery);
- if (fadetimer[device] < 100)
- DS4LightBar.forcedColor[device] = getTransitionedColor(lastColor[device], trans, fadetimer[device] += 2);
}
- actionDone[index].dev[device] = true;
- }
- else if (!triggeractivated && action.type == "BatteryCheck")
- {
- if (actionDone[index].dev[device])
+ else if (action.typeID == SpecialAction.ActionTypeId.Profile)
{
- fadetimer[device] = 0;
- /*if (prevFadetimer[device] == fadetimer[device])
- {
- prevFadetimer[device] = 0;
- fadetimer[device] = 0;
- }
- else
- prevFadetimer[device] = fadetimer[device];*/
- DS4LightBar.forcelight[device] = false;
- actionDone[index].dev[device] = false;
- }
- }
- else if (action.type == "XboxGameDVR" || action.type == "MultiAction")
- {
- /*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound)
- getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound;
- if (getCustomMacro(device, action.trigger[0]) != "0")
- getCustomMacros(device).Remove(action.trigger[0]);
- if (getCustomKey(device, action.trigger[0]) != 0)
- getCustomMacros(device).Remove(action.trigger[0]);*/
- string[] dets = action.details.Split(',');
- DS4Device d = ctrl.DS4Controllers[device];
- //cus
- if (getBoolMapping(device, action.trigger[0], cState, eState, tp) && !getBoolMapping(device, action.trigger[0], d.getPreviousState(), eState, tp))
- {//pressed down
- pastTime = DateTime.UtcNow;
- if (DateTime.UtcNow <= (firstTap + TimeSpan.FromMilliseconds(150)))
- {
- tappedOnce = false;
- secondtouchbegin = true;
- }
- else
- firstTouch = true;
- }
- else if (!getBoolMapping(device, action.trigger[0], cState, eState, tp) && getBoolMapping(device, action.trigger[0], d.getPreviousState(), eState, tp))
- {//released
- if (secondtouchbegin)
- {
- firstTouch = false;
- secondtouchbegin = false;
- }
- else if (firstTouch)
- {
- firstTouch = false;
- if (DateTime.UtcNow <= (pastTime + TimeSpan.FromMilliseconds(200)) && !tappedOnce)
- {
- tappedOnce = true;
- firstTap = DateTime.UtcNow;
- TimeofEnd = DateTime.UtcNow;
- }
- }
- }
+ actionFound = true;
- int type = 0;
- string macro = "";
- if (tappedOnce) //single tap
- {
- if (action.type == "MultiAction")
+ if (!actionDone[index].dev[device] && string.IsNullOrEmpty(tempprofilename[device]))
{
- macro = dets[0];
- }
- else if (int.TryParse(dets[0], out type))
- {
- switch (type)
+ actionDone[index].dev[device] = true;
+ untriggeraction[device] = action;
+ untriggerindex[device] = index;
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{
- case 0: macro = "91/71/71/91"; break;
- case 1: macro = "91/164/82/82/164/91"; break;
- case 2: macro = "91/164/44/44/164/91"; break;
- case 3: macro = dets[3] + "/" + dets[3]; break;
- case 4: macro = "91/164/71/71/164/91"; break;
+ DS4Controls dc = action.trigger[i];
+ DS4ControlSettings dcs = getDS4CSetting(device, dc);
+ if (dcs.action != null)
+ {
+ if (dcs.actionType == DS4ControlSettings.ActionType.Key)
+ InputMethods.performKeyRelease(ushort.Parse(dcs.action.ToString()));
+ else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
+ {
+ int[] keys = (int[])dcs.action;
+ for (int j = 0, keysLen = keys.Length; j < keysLen; j++)
+ InputMethods.performKeyRelease((ushort)keys[j]);
+ }
+ }
}
+ LoadTempProfile(device, action.details, true, ctrl);
+ return;
}
- if ((DateTime.UtcNow - TimeofEnd) > TimeSpan.FromMilliseconds(150))
- {
- if (macro != "")
- PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
- tappedOnce = false;
- }
- //if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work)
}
- else if (firstTouch && (DateTime.UtcNow - pastTime) > TimeSpan.FromMilliseconds(1000)) //helddown
+ else if (action.typeID == SpecialAction.ActionTypeId.Macro)
{
- if (action.type == "MultiAction")
+ actionFound = true;
+
+ if (!actionDone[index].dev[device])
{
- macro = dets[1];
- }
- else if (int.TryParse(dets[1], out type))
- {
- switch (type)
+ DS4KeyType keyType = action.keyType;
+ actionDone[index].dev[device] = true;
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
{
- case 0: macro = "91/71/71/91"; break;
- case 1: macro = "91/164/82/82/164/91"; break;
- case 2: macro = "91/164/44/44/164/91"; break;
- case 3: macro = dets[3] + "/" + dets[3]; break;
- case 4: macro = "91/164/71/71/164/91"; break;
+ DS4Controls dc = action.trigger[i];
+ resetToDefaultValue2(dc, MappedState, outputfieldMapping);
}
+
+ PlayMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None, keyType);
}
- if (macro != "")
- PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
- firstTouch = false;
+ else
+ EndMacro(device, macroControl, String.Join("/", action.macro), DS4Controls.None);
}
- else if (secondtouchbegin) //if double tap
+ else if (action.typeID == SpecialAction.ActionTypeId.Key)
{
- if (action.type == "MultiAction")
+ actionFound = true;
+
+ if (uTriggerCount == 0 || (uTriggerCount > 0 && untriggerindex[device] == -1 && !actionDone[index].dev[device]))
{
- macro = dets[2];
- }
- else if (int.TryParse(dets[2], out type))
- {
- switch (type)
+ actionDone[index].dev[device] = true;
+ untriggerindex[device] = index;
+ ushort key;
+ ushort.TryParse(action.details, out key);
+ if (uTriggerCount == 0)
{
- case 0: macro = "91/71/71/91"; break;
- case 1: macro = "91/164/82/82/164/91"; break;
- case 2: macro = "91/164/44/44/164/91"; break;
- case 3: macro = dets[3] + "/" + dets[3]; break;
- case 4: macro = "91/164/71/71/164/91"; break;
+ SyntheticState.KeyPresses kp;
+ if (!deviceState[device].keyPresses.TryGetValue(key, out kp))
+ deviceState[device].keyPresses[key] = kp = new SyntheticState.KeyPresses();
+ if (action.keyType.HasFlag(DS4KeyType.ScanCode))
+ kp.current.scanCodeCount++;
+ else
+ kp.current.vkCount++;
+ kp.current.repeatCount++;
}
+ else if (action.keyType.HasFlag(DS4KeyType.ScanCode))
+ InputMethods.performSCKeyPress(key);
+ else
+ InputMethods.performKeyPress(key);
}
- if (macro != "")
- PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
- secondtouchbegin = false;
+ }
+ else if (action.typeID == SpecialAction.ActionTypeId.DisconnectBT)
+ {
+ actionFound = true;
+
+ DS4Device d = ctrl.DS4Controllers[device];
+ bool synced = tempBool = d.isSynced();
+ if (synced && !d.isCharging())
+ {
+ ConnectionType deviceConn = d.getConnectionType();
+ bool exclusive = tempBool = d.isExclusive();
+ if (deviceConn == ConnectionType.BT)
+ {
+ d.DisconnectBT();
+ }
+ else if (deviceConn == ConnectionType.SONYWA && exclusive)
+ {
+ d.DisconnectDongle();
+ }
+
+ //foreach (DS4Controls dc in action.trigger)
+ for (int i = 0, arlen = action.trigger.Count; i < arlen; i++)
+ {
+ DS4Controls dc = action.trigger[i];
+ DS4ControlSettings dcs = getDS4CSetting(device, dc);
+ if (dcs.action != null)
+ {
+ if (dcs.actionType == DS4ControlSettings.ActionType.Key)
+ InputMethods.performKeyRelease((ushort)dcs.action);
+ else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
+ {
+ int[] keys = (int[])dcs.action;
+ for (int j = 0, keysLen = keys.Length; j < keysLen; j++)
+ InputMethods.performKeyRelease((ushort)keys[j]);
+ }
+ }
+ }
+ return;
+ }
+ }
+ else if (action.typeID == SpecialAction.ActionTypeId.BatteryCheck)
+ {
+ actionFound = true;
+
+ string[] dets = action.details.Split('|');
+ if (dets.Length == 1)
+ dets = action.details.Split(',');
+ if (bool.Parse(dets[1]) && !actionDone[index].dev[device])
+ {
+ Log.LogToTray("Controller " + (device + 1) + ": " +
+ ctrl.getDS4Battery(device), true);
+ }
+ if (bool.Parse(dets[2]))
+ {
+ DS4Device d = ctrl.DS4Controllers[device];
+ if (!actionDone[index].dev[device])
+ {
+ lastColor[device] = d.LightBarColor;
+ DS4LightBar.forcelight[device] = true;
+ }
+ DS4Color empty = new DS4Color(byte.Parse(dets[3]), byte.Parse(dets[4]), byte.Parse(dets[5]));
+ DS4Color full = new DS4Color(byte.Parse(dets[6]), byte.Parse(dets[7]), byte.Parse(dets[8]));
+ DS4Color trans = getTransitionedColor(empty, full, d.Battery);
+ if (fadetimer[device] < 100)
+ DS4LightBar.forcedColor[device] = getTransitionedColor(lastColor[device], trans, fadetimer[device] += 2);
+ }
+ actionDone[index].dev[device] = true;
}
}
else
- actionDone[index].dev[device] = false;
+ {
+ if (action.typeID == SpecialAction.ActionTypeId.BatteryCheck)
+ {
+ actionFound = true;
+ if (actionDone[index].dev[device])
+ {
+ fadetimer[device] = 0;
+ /*if (prevFadetimer[device] == fadetimer[device])
+ {
+ prevFadetimer[device] = 0;
+ fadetimer[device] = 0;
+ }
+ else
+ prevFadetimer[device] = fadetimer[device];*/
+ DS4LightBar.forcelight[device] = false;
+ actionDone[index].dev[device] = false;
+ }
+ }
+ else if (action.typeID != SpecialAction.ActionTypeId.Key &&
+ action.typeID != SpecialAction.ActionTypeId.XboxGameDVR &&
+ action.typeID != SpecialAction.ActionTypeId.MultiAction)
+ {
+ // Ignore
+ actionFound = true;
+ actionDone[index].dev[device] = false;
+ }
+ }
+
+ if (!actionFound)
+ {
+ if (uTriggerCount > 0 && utriggeractivated && action.typeID == SpecialAction.ActionTypeId.Key)
+ {
+ actionFound = true;
+
+ if (untriggerindex[device] > -1 && !actionDone[index].dev[device])
+ {
+ actionDone[index].dev[device] = true;
+ untriggerindex[device] = -1;
+ ushort key;
+ ushort.TryParse(action.details, out key);
+ if (action.keyType.HasFlag(DS4KeyType.ScanCode))
+ InputMethods.performSCKeyRelease(key);
+ else
+ InputMethods.performKeyRelease(key);
+ }
+ }
+ else if (action.typeID == SpecialAction.ActionTypeId.XboxGameDVR || action.typeID == SpecialAction.ActionTypeId.MultiAction)
+ {
+ actionFound = true;
+
+ bool tappedOnce = action.tappedOnce, firstTouch = action.firstTouch,
+ secondtouchbegin = action.secondtouchbegin;
+ //DateTime pastTime = action.pastTime, firstTap = action.firstTap,
+ // TimeofEnd = action.TimeofEnd;
+
+ /*if (getCustomButton(device, action.trigger[0]) != X360Controls.Unbound)
+ getCustomButtons(device)[action.trigger[0]] = X360Controls.Unbound;
+ if (getCustomMacro(device, action.trigger[0]) != "0")
+ getCustomMacros(device).Remove(action.trigger[0]);
+ if (getCustomKey(device, action.trigger[0]) != 0)
+ getCustomMacros(device).Remove(action.trigger[0]);*/
+ string[] dets = action.details.Split(',');
+ DS4Device d = ctrl.DS4Controllers[device];
+ //cus
+
+ DS4State tempPrevState = d.getPreviousStateRef();
+ // Only create one instance of previous DS4StateFieldMapping in case more than one multi-action
+ // button is assigned
+ if (previousFieldMapping == null)
+ {
+ previousFieldMapping = previousFieldMappings[device];
+ previousFieldMapping.populateFieldMapping(tempPrevState, eState, tp, true);
+ //previousFieldMapping = new DS4StateFieldMapping(tempPrevState, eState, tp, true);
+ }
+
+ bool activeCur = getBoolMapping2(device, action.trigger[0], cState, eState, tp, fieldMapping);
+ bool activePrev = getBoolMapping2(device, action.trigger[0], tempPrevState, eState, tp, previousFieldMapping);
+ if (activeCur && !activePrev)
+ {
+ // pressed down
+ action.pastTime = DateTime.UtcNow;
+ if (action.pastTime <= (action.firstTap + TimeSpan.FromMilliseconds(100)))
+ {
+ action.tappedOnce = tappedOnce = false;
+ action.secondtouchbegin = secondtouchbegin = true;
+ //tappedOnce = false;
+ //secondtouchbegin = true;
+ }
+ else
+ action.firstTouch = firstTouch = true;
+ //firstTouch = true;
+ }
+ else if (!activeCur && activePrev)
+ {
+ // released
+ if (secondtouchbegin)
+ {
+ action.firstTouch = firstTouch = false;
+ action.secondtouchbegin = secondtouchbegin = false;
+ //firstTouch = false;
+ //secondtouchbegin = false;
+ }
+ else if (firstTouch)
+ {
+ action.firstTouch = firstTouch = false;
+ //firstTouch = false;
+ if (DateTime.UtcNow <= (action.pastTime + TimeSpan.FromMilliseconds(150)) && !tappedOnce)
+ {
+ action.tappedOnce = tappedOnce = true;
+ //tappedOnce = true;
+ action.firstTap = DateTime.UtcNow;
+ action.TimeofEnd = DateTime.UtcNow;
+ }
+ }
+ }
+
+ int type = 0;
+ string macro = "";
+ if (tappedOnce) //single tap
+ {
+ if (action.typeID == SpecialAction.ActionTypeId.MultiAction)
+ {
+ macro = dets[0];
+ }
+ else if (int.TryParse(dets[0], out type))
+ {
+ switch (type)
+ {
+ case 0: macro = "91/71/71/91"; break;
+ case 1: macro = "91/164/82/82/164/91"; break;
+ case 2: macro = "91/164/44/44/164/91"; break;
+ case 3: macro = dets[3] + "/" + dets[3]; break;
+ case 4: macro = "91/164/71/71/164/91"; break;
+ }
+ }
+
+ if ((DateTime.UtcNow - action.TimeofEnd) > TimeSpan.FromMilliseconds(150))
+ {
+ if (macro != "")
+ PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
+
+ tappedOnce = false;
+ action.tappedOnce = false;
+ }
+ //if it fails the method resets, and tries again with a new tester value (gives tap a delay so tap and hold can work)
+ }
+ else if (firstTouch && (DateTime.UtcNow - action.pastTime) > TimeSpan.FromMilliseconds(500)) //helddown
+ {
+ if (action.typeID == SpecialAction.ActionTypeId.MultiAction)
+ {
+ macro = dets[1];
+ }
+ else if (int.TryParse(dets[1], out type))
+ {
+ switch (type)
+ {
+ case 0: macro = "91/71/71/91"; break;
+ case 1: macro = "91/164/82/82/164/91"; break;
+ case 2: macro = "91/164/44/44/164/91"; break;
+ case 3: macro = dets[3] + "/" + dets[3]; break;
+ case 4: macro = "91/164/71/71/164/91"; break;
+ }
+ }
+
+ if (macro != "")
+ PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
+
+ firstTouch = false;
+ action.firstTouch = false;
+ }
+ else if (secondtouchbegin) //if double tap
+ {
+ if (action.typeID == SpecialAction.ActionTypeId.MultiAction)
+ {
+ macro = dets[2];
+ }
+ else if (int.TryParse(dets[2], out type))
+ {
+ switch (type)
+ {
+ case 0: macro = "91/71/71/91"; break;
+ case 1: macro = "91/164/82/82/164/91"; break;
+ case 2: macro = "91/164/44/44/164/91"; break;
+ case 3: macro = dets[3] + "/" + dets[3]; break;
+ case 4: macro = "91/164/71/71/164/91"; break;
+ }
+ }
+
+ if (macro != "")
+ PlayMacro(device, macroControl, macro, DS4Controls.None, DS4KeyType.None);
+
+ secondtouchbegin = false;
+ action.secondtouchbegin = false;
+ }
+ }
+ else
+ {
+ actionDone[index].dev[device] = false;
+ }
+ }
}
}
}
@@ -1401,25 +2171,30 @@ namespace DS4Windows
SpecialAction action = untriggeraction[device];
int index = untriggerindex[device];
bool utriggeractivated = true;
- foreach (DS4Controls dc in action.uTrigger)
+ //foreach (DS4Controls dc in action.uTrigger)
+ for (int i = 0, uTrigLen = action.uTrigger.Count; i < uTrigLen; i++)
{
- if (!getBoolMapping(device, dc, cState, eState, tp))
+ DS4Controls dc = action.uTrigger[i];
+ if (!getBoolMapping2(device, dc, cState, eState, tp, fieldMapping))
{
utriggeractivated = false;
break;
}
}
- if (utriggeractivated && action.type == "Profile")
+ if (utriggeractivated && action.typeID == SpecialAction.ActionTypeId.Profile)
{
if ((action.controls == action.ucontrols && !actionDone[index].dev[device]) || //if trigger and end trigger are the same
action.controls != action.ucontrols)
+ {
if (!string.IsNullOrEmpty(tempprofilename[device]))
{
- foreach (DS4Controls dc in action.uTrigger)
+ //foreach (DS4Controls dc in action.uTrigger)
+ for (int i = 0, arlen = action.uTrigger.Count; i < arlen; i++)
{
+ DS4Controls dc = action.uTrigger[i];
actionDone[index].dev[device] = true;
- DS4ControlSettings dcs = getDS4CSetting(device, dc.ToString());
+ DS4ControlSettings dcs = getDS4CSetting(device, dc);
if (dcs.action != null)
{
if (dcs.actionType == DS4ControlSettings.ActionType.Key)
@@ -1427,17 +2202,21 @@ namespace DS4Windows
else if (dcs.actionType == DS4ControlSettings.ActionType.Macro)
{
int[] keys = (int[])dcs.action;
- for (int i = 0; i < keys.Length; i++)
- InputMethods.performKeyRelease((ushort)keys[i]);
+ for (int j = 0, keysLen = keys.Length; j < keysLen; j++)
+ InputMethods.performKeyRelease((ushort)keys[j]);
}
}
}
+
untriggeraction[device] = null;
LoadProfile(device, false, ctrl);
}
+ }
}
else
+ {
actionDone[index].dev[device] = false;
+ }
}
}
@@ -1516,31 +2295,31 @@ namespace DS4Windows
else if (i == 258) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEDOWN);
else if (i == 259) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONDOWN, 1);
else if (i == 260) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONDOWN, 2);
- else if (i == 261) macroControl[0] = true;
- else if (i == 262) macroControl[1] = true;
- else if (i == 263) macroControl[2] = true;
- else if (i == 264) macroControl[3] = true;
- else if (i == 265) macroControl[4] = true;
- else if (i == 266) macroControl[5] = true;
- else if (i == 267) macroControl[6] = true;
- else if (i == 268) macroControl[7] = true;
- else if (i == 269) macroControl[8] = true;
- else if (i == 270) macroControl[9] = true;
- else if (i == 271) macroControl[10] = true;
- else if (i == 272) macroControl[11] = true;
- else if (i == 273) macroControl[12] = true;
- else if (i == 274) macroControl[13] = true;
- else if (i == 275) macroControl[14] = true;
- else if (i == 276) macroControl[15] = true;
- else if (i == 277) macroControl[16] = true;
- else if (i == 278) macroControl[17] = true;
- else if (i == 279) macroControl[18] = true;
- else if (i == 280) macroControl[19] = true;
- else if (i == 281) macroControl[20] = true;
- else if (i == 282) macroControl[21] = true;
- else if (i == 283) macroControl[22] = true;
- else if (i == 284) macroControl[23] = true;
- else if (i == 285) macroControl[24] = true;
+ else if (i == 261) { macroControl[0] = true; macroCount++; }
+ else if (i == 262) { macroControl[1] = true; macroCount++; }
+ else if (i == 263) { macroControl[2] = true; macroCount++; }
+ else if (i == 264) { macroControl[3] = true; macroCount++; }
+ else if (i == 265) { macroControl[4] = true; macroCount++; }
+ else if (i == 266) { macroControl[5] = true; macroCount++; }
+ else if (i == 267) { macroControl[6] = true; macroCount++; }
+ else if (i == 268) { macroControl[7] = true; macroCount++; }
+ else if (i == 269) { macroControl[8] = true; macroCount++; }
+ else if (i == 270) { macroControl[9] = true; macroCount++; }
+ else if (i == 271) { macroControl[10] = true; macroCount++; }
+ else if (i == 272) { macroControl[11] = true; macroCount++; }
+ else if (i == 273) { macroControl[12] = true; macroCount++; }
+ else if (i == 274) { macroControl[13] = true; macroCount++; }
+ else if (i == 275) { macroControl[14] = true; macroCount++; }
+ else if (i == 276) { macroControl[15] = true; macroCount++; }
+ else if (i == 277) { macroControl[16] = true; macroCount++; }
+ else if (i == 278) { macroControl[17] = true; macroCount++; }
+ else if (i == 279) { macroControl[18] = true; macroCount++; }
+ else if (i == 280) { macroControl[19] = true; macroCount++; }
+ else if (i == 281) { macroControl[20] = true; macroCount++; }
+ else if (i == 282) { macroControl[21] = true; macroCount++; }
+ else if (i == 283) { macroControl[22] = true; macroCount++; }
+ else if (i == 284) { macroControl[23] = true;macroCount++; }
+ else if (i == 285) { macroControl[24] = true; macroCount++; }
else if (keyType.HasFlag(DS4KeyType.ScanCode))
InputMethods.performSCKeyPress((ushort)i);
else
@@ -1554,31 +2333,31 @@ namespace DS4Windows
else if (i == 258) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEUP);
else if (i == 259) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 1);
else if (i == 260) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 2);
- else if (i == 261) macroControl[0] = false;
- else if (i == 262) macroControl[1] = false;
- else if (i == 263) macroControl[2] = false;
- else if (i == 264) macroControl[3] = false;
- else if (i == 265) macroControl[4] = false;
- else if (i == 266) macroControl[5] = false;
- else if (i == 267) macroControl[6] = false;
- else if (i == 268) macroControl[7] = false;
- else if (i == 269) macroControl[8] = false;
- else if (i == 270) macroControl[9] = false;
- else if (i == 271) macroControl[10] = false;
- else if (i == 272) macroControl[11] = false;
- else if (i == 273) macroControl[12] = false;
- else if (i == 274) macroControl[13] = false;
- else if (i == 275) macroControl[14] = false;
- else if (i == 276) macroControl[15] = false;
- else if (i == 277) macroControl[16] = false;
- else if (i == 278) macroControl[17] = false;
- else if (i == 279) macroControl[18] = false;
- else if (i == 280) macroControl[19] = false;
- else if (i == 281) macroControl[20] = false;
- else if (i == 282) macroControl[21] = false;
- else if (i == 283) macroControl[22] = false;
- else if (i == 284) macroControl[23] = false;
- else if (i == 285) macroControl[24] = false;
+ else if (i == 261) { macroControl[0] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 262) { macroControl[1] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 263) { macroControl[2] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 264) { macroControl[3] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 265) { macroControl[4] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 266) { macroControl[5] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 267) { macroControl[6] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 268) { macroControl[7] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 269) { macroControl[8] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 270) { macroControl[9] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 271) { macroControl[10] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 272) { macroControl[11] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 273) { macroControl[12] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 274) { macroControl[13] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 275) { macroControl[14] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 276) { macroControl[15] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 277) { macroControl[16] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 278) { macroControl[17] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 279) { macroControl[18] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 280) { macroControl[19] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 281) { macroControl[20] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 282) { macroControl[21] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 283) { macroControl[22] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 284) { macroControl[23] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 285) { macroControl[24] = false; if (macroCount > 0) macroCount--; }
else if (keyType.HasFlag(DS4KeyType.ScanCode))
InputMethods.performSCKeyRelease((ushort)i);
else
@@ -1586,44 +2365,47 @@ namespace DS4Windows
keydown[i] = false;
}
}
- for (ushort i = 0; i < keydown.Length; i++)
+ for (int i = 0, arlength = keydown.Length; i < arlength; i++)
{
if (keydown[i])
+ {
if (i == 256) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_LEFTUP); //anything above 255 is not a keyvalue
else if (i == 257) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_RIGHTUP);
else if (i == 258) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_MIDDLEUP);
else if (i == 259) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 1);
else if (i == 260) InputMethods.MouseEvent(InputMethods.MOUSEEVENTF_XBUTTONUP, 2);
- else if (i == 261) macroControl[0] = false;
- else if (i == 262) macroControl[1] = false;
- else if (i == 263) macroControl[2] = false;
- else if (i == 264) macroControl[3] = false;
- else if (i == 265) macroControl[4] = false;
- else if (i == 266) macroControl[5] = false;
- else if (i == 267) macroControl[6] = false;
- else if (i == 268) macroControl[7] = false;
- else if (i == 269) macroControl[8] = false;
- else if (i == 270) macroControl[9] = false;
- else if (i == 271) macroControl[10] = false;
- else if (i == 272) macroControl[11] = false;
- else if (i == 273) macroControl[12] = false;
- else if (i == 274) macroControl[13] = false;
- else if (i == 275) macroControl[14] = false;
- else if (i == 276) macroControl[15] = false;
- else if (i == 277) macroControl[16] = false;
- else if (i == 278) macroControl[17] = false;
- else if (i == 279) macroControl[18] = false;
- else if (i == 280) macroControl[19] = false;
- else if (i == 281) macroControl[20] = false;
- else if (i == 282) macroControl[21] = false;
- else if (i == 283) macroControl[22] = false;
- else if (i == 284) macroControl[23] = false;
- else if (i == 285) macroControl[24] = false;
+ else if (i == 261) { macroControl[0] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 262) { macroControl[1] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 263) { macroControl[2] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 264) { macroControl[3] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 265) { macroControl[4] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 266) { macroControl[5] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 267) { macroControl[6] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 268) { macroControl[7] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 269) { macroControl[8] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 270) { macroControl[9] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 271) { macroControl[10] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 272) { macroControl[11] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 273) { macroControl[12] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 274) { macroControl[13] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 275) { macroControl[14] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 276) { macroControl[15] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 277) { macroControl[16] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 278) { macroControl[17] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 279) { macroControl[18] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 280) { macroControl[19] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 281) { macroControl[20] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 282) { macroControl[21] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 283) { macroControl[22] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 284) { macroControl[23] = false; if (macroCount > 0) macroCount--; }
+ else if (i == 285) { macroControl[24] = false; if (macroCount > 0) macroCount--; }
else if (keyType.HasFlag(DS4KeyType.ScanCode))
- InputMethods.performSCKeyRelease(i);
+ InputMethods.performSCKeyRelease((ushort)i);
else
- InputMethods.performKeyRelease(i);
+ InputMethods.performKeyRelease((ushort)i);
+ }
}
+
DS4LightBar.forcedFlash[device] = 0;
DS4LightBar.forcelight[device] = false;
Program.rootHub.DS4Controllers[device].setRumble(0, 0);
@@ -1641,9 +2423,11 @@ namespace DS4Windows
{
if ((macro.StartsWith("164/9/9/164") || macro.StartsWith("18/9/9/18")) && !altTabDone)
AltTabSwappingRelease();
+
if (control != DS4Controls.None)
macrodone[DS4ControltoInt(control)] = false;
}
+
private static void AltTabSwapping(int wait, int device)
{
if (altTabDone)
@@ -1675,7 +2459,8 @@ namespace DS4Windows
}
}
- private static void getMouseWheelMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool down)
+ private static void getMouseWheelMapping(int device, DS4Controls control, DS4State cState,
+ DS4StateExposed eState, Mouse tp, bool down)
{
DateTime now = DateTime.UtcNow;
if (now >= oldnow + TimeSpan.FromMilliseconds(10) && !pressagain)
@@ -1685,342 +2470,1307 @@ namespace DS4Windows
}
}
- private static int getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, int mnum)
+ private static double getMouseMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState,
+ DS4StateFieldMapping fieldMapping, int mnum, ControlService ctrl)
{
int controlnum = DS4ControltoInt(control);
- double SXD = SXDeadzone[device];
- double SZD = SZDeadzone[device];
- int deadzoneL = 3;
- int deadzoneR = 3;
- if (LSDeadzone[device] >= 3)
- deadzoneL = 0;
- if (RSDeadzone[device] >= 3)
- deadzoneR = 0;
- double value = 0;
- int speed = ButtonMouseSensitivity[device] + 15;
+
+ int deadzoneL = 0;
+ int deadzoneR = 0;
+ if (getLSDeadzone(device) == 0)
+ deadzoneL = 3;
+ if (getRSDeadzone(device) == 0)
+ deadzoneR = 3;
+
+ double value = 0.0;
+ int speed = ButtonMouseSensitivity[device];
double root = 1.002;
double divide = 10000d;
//DateTime now = mousenow[mnum];
- switch (control)
+
+ int controlNum = (int)control;
+ DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
+ //long timeElapsed = ctrl.DS4Controllers[device].getLastTimeElapsed();
+ double timeElapsed = ctrl.DS4Controllers[device].lastTimeElapsedDouble;
+ //double mouseOffset = 0.025;
+ double tempMouseOffsetX = 0.0, tempMouseOffsetY = 0.0;
+
+ if (controlType == DS4StateFieldMapping.ControlType.Button)
{
- case DS4Controls.LXNeg:
- if (cState.LX - 127.5f < -deadzoneL)
- value = -(cState.LX - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.LXPos:
- if (cState.LX - 127.5f > deadzoneL)
- value = (cState.LX - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.RXNeg:
- if (cState.RX - 127.5f < -deadzoneR)
- value = -(cState.RX - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.RXPos:
- if (cState.RX - 127.5f > deadzoneR)
- value = (cState.RX - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.LYNeg:
- if (cState.LY - 127.5f < -deadzoneL)
- value = -(cState.LY - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.LYPos:
- if (cState.LY - 127.5f > deadzoneL)
- value = (cState.LY - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.RYNeg:
- if (cState.RY - 127.5f < -deadzoneR)
- value = -(cState.RY - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.RYPos:
- if (cState.RY - 127.5f > deadzoneR)
- value = (cState.RY - 127.5f) / 2550d * speed;
- break;
- case DS4Controls.Share: value = (cState.Share ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.Options: value = (cState.Options ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.L1: value = (cState.L1 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.R1: value = (cState.R1 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.L3: value = (cState.L3 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.R3: value = (cState.R3 ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.DpadUp: value = (cState.DpadUp ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.DpadDown: value = (cState.DpadDown ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.DpadLeft: value = (cState.DpadLeft ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.DpadRight: value = (cState.DpadRight ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.PS: value = (cState.PS ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.Cross: value = (cState.Cross ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.Square: value = (cState.Square ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.Triangle: value = (cState.Triangle ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.Circle: value = (cState.Circle ? Math.Pow(root + speed / divide, 100) - 1 : 0); break;
- case DS4Controls.L2: value = Math.Pow(root + speed / divide, cState.L2 / 2d) - 1; break;
- case DS4Controls.R2: value = Math.Pow(root + speed / divide, cState.R2 / 2d) - 1; break;
- case DS4Controls.GyroXPos: return (byte)(eState.GyroX > SXD * 10 ?
- Math.Pow(root + speed / divide, eState.GyroX) : 0);
- case DS4Controls.GyroXNeg: return (byte)(eState.GyroX < -SXD * 10 ?
- Math.Pow(root + speed / divide, -eState.GyroX) : 0);
- case DS4Controls.GyroZPos: return (byte)(eState.GyroZ > SZD * 10 ?
- Math.Pow(root + speed / divide, eState.GyroZ) : 0);
- case DS4Controls.GyroZNeg: return (byte)(eState.GyroZ < -SZD * 10 ?
- Math.Pow(root + speed / divide, -eState.GyroZ) : 0);
+ bool active = fieldMapping.buttons[controlNum];
+ value = (active ? Math.Pow(root + speed / divide, 100) - 1 : 0);
}
- bool LXChanged = (Math.Abs(127 - cState.LX) < deadzoneL);
- bool LYChanged = (Math.Abs(127 - cState.LY) < deadzoneL);
- bool RXChanged = (Math.Abs(127 - cState.RX) < deadzoneR);
- bool RYChanged = (Math.Abs(127 - cState.RY) < deadzoneR);
- bool contains = (control.ToString().Contains("LX") ||
- control.ToString().Contains("LY") ||
- control.ToString().Contains("RX") ||
- control.ToString().Contains("RY"));
- if (MouseAccel[device])
+ else if (controlType == DS4StateFieldMapping.ControlType.AxisDir)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg:
+ {
+ if (cState.LX < 127 - deadzoneL)
+ {
+ double diff = -(cState.LX - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
+ //tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
+ //tempMouseOffsetX = MOUSESTICKOFFSET;
+ tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + (tempMouseOffsetX * -1.0);
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = -(cState.LX - 127 - deadzoneL) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.LXPos:
+ {
+ if (cState.LX > 127 + deadzoneL)
+ {
+ double diff = (cState.LX - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
+ tempMouseOffsetX = cState.LXUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetX = Math.Abs(Math.Cos(cState.LSAngleRad)) * MOUSESTICKOFFSET;
+ //tempMouseOffsetX = MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = (cState.LX - 127 + deadzoneL) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.RXNeg:
+ {
+ if (cState.RX < 127 - deadzoneR)
+ {
+ double diff = -(cState.RX - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
+ tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetX = MOUSESTICKOFFSET;
+ //tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + (tempMouseOffsetX * -1.0);
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = -(cState.RX - 127 - deadzoneR) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.RXPos:
+ {
+ if (cState.RX > 127 + deadzoneR)
+ {
+ double diff = (cState.RX - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
+ tempMouseOffsetX = cState.RXUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetX = MOUSESTICKOFFSET;
+ //tempMouseOffsetX = Math.Abs(Math.Cos(cState.RSAngleRad)) * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetX) * diff + tempMouseOffsetX;
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = (cState.RX - 127 + deadzoneR) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.LYNeg:
+ {
+ if (cState.LY < 127 - deadzoneL)
+ {
+ double diff = -(cState.LY - 127 - deadzoneL) / (double)(0 - 127 - deadzoneL);
+ tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetY = MOUSESTICKOFFSET;
+ //tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + (tempMouseOffsetY * -1.0);
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = -(cState.LY - 127 - deadzoneL) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.LYPos:
+ {
+ if (cState.LY > 127 + deadzoneL)
+ {
+ double diff = (cState.LY - 127 + deadzoneL) / (double)(255 - 127 + deadzoneL);
+ tempMouseOffsetY = cState.LYUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetY = MOUSESTICKOFFSET;
+ //tempMouseOffsetY = Math.Abs(Math.Sin(cState.LSAngleRad)) * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = (cState.LY - 127 + deadzoneL) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.RYNeg:
+ {
+ if (cState.RY < 127 - deadzoneR)
+ {
+ double diff = -(cState.RY - 127 - deadzoneR) / (double)(0 - 127 - deadzoneR);
+ tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetY = MOUSESTICKOFFSET;
+ //tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + (tempMouseOffsetY * -1.0);
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = -(cState.RY - 127 - deadzoneR) / 2550d * speed;
+ }
+
+ break;
+ }
+ case DS4Controls.RYPos:
+ {
+ if (cState.RY > 127 + deadzoneR)
+ {
+ double diff = (cState.RY - 127 + deadzoneR) / (double)(255 - 127 + deadzoneR);
+ tempMouseOffsetY = cState.RYUnit * MOUSESTICKOFFSET;
+ //tempMouseOffsetY = MOUSESTICKOFFSET;
+ //tempMouseOffsetY = Math.Abs(Math.Sin(cState.RSAngleRad)) * MOUSESTICKOFFSET;
+ value = ((speed * MOUSESPEEDFACTOR * (timeElapsed * 0.001)) - tempMouseOffsetY) * diff + tempMouseOffsetY;
+ //value = diff * MOUSESPEEDFACTOR * (timeElapsed * 0.001) * speed;
+ //value = (cState.RY - 127 + deadzoneR) / 2550d * speed;
+ }
+
+ break;
+ }
+
+ default: break;
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
+ {
+ byte trigger = fieldMapping.triggers[controlNum];
+ value = Math.Pow(root + speed / divide, trigger / 2d) - 1;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.GyroDir)
+ {
+ //double SXD = getSXDeadzone(device);
+ //double SZD = getSZDeadzone(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos:
+ {
+ int gyroX = fieldMapping.gryodirs[controlNum];
+ value = (byte)(gyroX > 0 ? Math.Pow(root + speed / divide, gyroX) : 0);
+ break;
+ }
+ case DS4Controls.GyroXNeg:
+ {
+ int gyroX = fieldMapping.gryodirs[controlNum];
+ value = (byte)(gyroX < 0 ? Math.Pow(root + speed / divide, -gyroX) : 0);
+ break;
+ }
+ case DS4Controls.GyroZPos:
+ {
+ int gyroZ = fieldMapping.gryodirs[controlNum];
+ value = (byte)(gyroZ > 0 ? Math.Pow(root + speed / divide, gyroZ) : 0);
+ break;
+ }
+ case DS4Controls.GyroZNeg:
+ {
+ int gyroZ = fieldMapping.gryodirs[controlNum];
+ value = (byte)(gyroZ < 0 ? Math.Pow(root + speed / divide, -gyroZ) : 0);
+ break;
+ }
+ default: break;
+ }
+ }
+
+ if (getMouseAccel(device))
{
if (value > 0)
{
mcounter = 34;
mouseaccel++;
}
+
if (mouseaccel == prevmouseaccel)
{
mcounter--;
}
+
if (mcounter <= 0)
{
mouseaccel = 0;
mcounter = 34;
}
- value *= 1 + (double)Math.Min(20000, (mouseaccel)) / 10000d;
+
+ value *= 1 + Math.Min(20000, (mouseaccel)) / 10000d;
prevmouseaccel = mouseaccel;
}
- int intValue;
- if (mnum > 1)
+
+ return value;
+ }
+
+ private static void calculateFinalMouseMovement(ref double rawMouseX, ref double rawMouseY,
+ out int mouseX, out int mouseY)
+ {
+ if ((rawMouseX > 0.0 && horizontalRemainder > 0.0) || (rawMouseX < 0.0 && horizontalRemainder < 0.0))
{
- if ((value > 0.0 && horizontalRemainder > 0.0) || (value < 0.0 && horizontalRemainder < 0.0))
- value += horizontalRemainder;
- intValue = (int)value;
- horizontalRemainder = value - intValue;
+ rawMouseX += horizontalRemainder;
}
else
{
- if ((value > 0.0 && verticalRemainder > 0.0) || (value < 0.0 && verticalRemainder < 0.0))
- value += verticalRemainder;
- intValue = (int)value;
- verticalRemainder = value - intValue;
+ horizontalRemainder = 0.0;
}
- return intValue;
+
+ //double mouseXTemp = rawMouseX - (Math.IEEERemainder(rawMouseX * 1000.0, 1.0) / 1000.0);
+ double mouseXTemp = rawMouseX - (remainderCutoff(rawMouseX * 1000.0, 1.0) / 1000.0);
+ //double mouseXTemp = rawMouseX - (rawMouseX * 1000.0 - (1.0 * (int)(rawMouseX * 1000.0 / 1.0)));
+ mouseX = (int)mouseXTemp;
+ horizontalRemainder = mouseXTemp - mouseX;
+ //mouseX = (int)rawMouseX;
+ //horizontalRemainder = rawMouseX - mouseX;
+
+ if ((rawMouseY > 0.0 && verticalRemainder > 0.0) || (rawMouseY < 0.0 && verticalRemainder < 0.0))
+ {
+ rawMouseY += verticalRemainder;
+ }
+ else
+ {
+ verticalRemainder = 0.0;
+ }
+
+ //double mouseYTemp = rawMouseY - (Math.IEEERemainder(rawMouseY * 1000.0, 1.0) / 1000.0);
+ double mouseYTemp = rawMouseY - (remainderCutoff(rawMouseY * 1000.0, 1.0) / 1000.0);
+ mouseY = (int)mouseYTemp;
+ verticalRemainder = mouseYTemp - mouseY;
+ //mouseY = (int)rawMouseY;
+ //verticalRemainder = rawMouseY - mouseY;
+ }
+
+ private static double remainderCutoff(double dividend, double divisor)
+ {
+ return dividend - (divisor * (int)(dividend / divisor));
}
public static bool compare(byte b1, byte b2)
{
+ bool result = true;
if (Math.Abs(b1 - b2) > 10)
{
- return false;
+ result = false;
}
- return true;
+
+ return result;
+ }
+
+ private static byte getByteMapping2(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp,
+ DS4StateFieldMapping fieldMap)
+ {
+ byte result = 0;
+
+ int controlNum = (int)control;
+ DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
+ if (controlType == DS4StateFieldMapping.ControlType.Button)
+ {
+ result = (byte)(fieldMap.buttons[controlNum] ? 255 : 0);
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.AxisDir)
+ {
+ byte axisValue = fieldMap.axisdirs[controlNum];
+
+ switch (control)
+ {
+ case DS4Controls.LXNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break;
+ case DS4Controls.LYNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break;
+ case DS4Controls.RXNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break;
+ case DS4Controls.RYNeg: result = (byte)(axisValue - 127.5f > 0 ? 0 : -(axisValue - 127.5f) * 2); break;
+ default: result = (byte)(axisValue - 127.5f < 0 ? 0 : (axisValue - 127.5f) * 2); break;
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
+ {
+ result = fieldMap.triggers[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Touch)
+ {
+ result = (byte)(tp != null && fieldMap.buttons[controlNum] ? 255 : 0);
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.SwipeDir)
+ {
+ result = (byte)(tp != null ? fieldMap.swipedirs[controlNum] : 0);
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.GyroDir)
+ {
+ bool sOff = isUsingSAforMouse(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos:
+ {
+ int gyroX = fieldMap.gryodirs[controlNum];
+ result = (byte)(sOff == false ? Math.Min(255, gyroX * 2) : 0);
+ break;
+ }
+ case DS4Controls.GyroXNeg:
+ {
+ int gyroX = fieldMap.gryodirs[controlNum];
+ result = (byte)(sOff == false ? Math.Min(255, -gyroX * 2) : 0);
+ break;
+ }
+ case DS4Controls.GyroZPos:
+ {
+ int gyroZ = fieldMap.gryodirs[controlNum];
+ result = (byte)(sOff == false ? Math.Min(255, gyroZ * 2) : 0);
+ break;
+ }
+ case DS4Controls.GyroZNeg:
+ {
+ int gyroZ = fieldMap.gryodirs[controlNum];
+ result = (byte)(sOff == false ? Math.Min(255, -gyroZ * 2) : 0);
+ break;
+ }
+ default: break;
+ }
+ }
+
+ return result;
}
public static byte getByteMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
{
- double SXD = SXDeadzone[device];
- double SZD = SZDeadzone[device];
- bool sOff = UseSAforMouse[device];
- switch (control)
- {
- case DS4Controls.Share: return (byte)(cState.Share ? 255 : 0);
- case DS4Controls.Options: return (byte)(cState.Options ? 255 : 0);
- case DS4Controls.L1: return (byte)(cState.L1 ? 255 : 0);
- case DS4Controls.R1: return (byte)(cState.R1 ? 255 : 0);
- case DS4Controls.L3: return (byte)(cState.L3 ? 255 : 0);
- case DS4Controls.R3: return (byte)(cState.R3 ? 255 : 0);
- case DS4Controls.DpadUp: return (byte)(cState.DpadUp ? 255 : 0);
- case DS4Controls.DpadDown: return (byte)(cState.DpadDown ? 255 : 0);
- case DS4Controls.DpadLeft: return (byte)(cState.DpadLeft ? 255 : 0);
- case DS4Controls.DpadRight: return (byte)(cState.DpadRight ? 255 : 0);
- case DS4Controls.PS: return (byte)(cState.PS ? 255 : 0);
- case DS4Controls.Cross: return (byte)(cState.Cross ? 255 : 0);
- case DS4Controls.Square: return (byte)(cState.Square ? 255 : 0);
- case DS4Controls.Triangle: return (byte)(cState.Triangle ? 255 : 0);
- case DS4Controls.Circle: return (byte)(cState.Circle ? 255 : 0);
- case DS4Controls.TouchLeft: return (byte)(tp != null && tp.leftDown ? 255 : 0);
- case DS4Controls.TouchRight: return (byte)(tp != null && tp.rightDown ? 255 : 0);
- case DS4Controls.TouchMulti: return (byte)(tp != null && tp.multiDown ? 255 : 0);
- case DS4Controls.TouchUpper: return (byte)(tp != null && tp.upperDown ? 255 : 0);
- case DS4Controls.LXNeg: return (byte)(cState.LX - 127.5f > 0 ? 0 : -(cState.LX - 127.5f) * 2);
- case DS4Controls.LYNeg: return (byte)(cState.LY - 127.5f > 0 ? 0 : -(cState.LY - 127.5f) * 2);
- case DS4Controls.RXNeg: return (byte)(cState.RX - 127.5f > 0 ? 0 : -(cState.RX - 127.5f) * 2);
- case DS4Controls.RYNeg: return (byte)(cState.RY - 127.5f > 0 ? 0 : -(cState.RY - 127.5f) * 2);
- case DS4Controls.LXPos: return (byte)(cState.LX - 127.5f < 0 ? 0 : (cState.LX - 127.5f) * 2);
- case DS4Controls.LYPos: return (byte)(cState.LY - 127.5f < 0 ? 0 : (cState.LY - 127.5f) * 2);
- case DS4Controls.RXPos: return (byte)(cState.RX - 127.5f < 0 ? 0 : (cState.RX - 127.5f) * 2);
- case DS4Controls.RYPos: return (byte)(cState.RY - 127.5f < 0 ? 0 : (cState.RY - 127.5f) * 2);
- case DS4Controls.L2: return cState.L2;
- case DS4Controls.R2: return cState.R2;
- case DS4Controls.GyroXPos: return (byte)(!sOff && SXSens[device] * eState.GyroX > SXD * 10 ? Math.Min(255, SXSens[device] * eState.GyroX * 2) : 0);
- case DS4Controls.GyroXNeg: return (byte)(!sOff && SXSens[device] * eState.GyroX < -SXD * 10 ? Math.Min(255, SXSens[device] * -eState.GyroX * 2) : 0);
- case DS4Controls.GyroZPos: return (byte)(!sOff && SZSens[device] * eState.GyroZ > SZD * 10 ? Math.Min(255, SZSens[device] * eState.GyroZ * 2) : 0);
- case DS4Controls.GyroZNeg: return (byte)(!sOff && SZSens[device] * eState.GyroZ < -SZD * 10 ? Math.Min(255, SZSens[device] * -eState.GyroZ * 2) : 0);
- case DS4Controls.SwipeUp: return (byte)(tp != null ? tp.swipeUpB : 0);
- case DS4Controls.SwipeDown: return (byte)(tp != null ? tp.swipeDownB: 0);
- case DS4Controls.SwipeLeft: return (byte)(tp != null ? tp.swipeLeftB: 0);
- case DS4Controls.SwipeRight: return (byte)(tp != null ? tp.swipeRightB : 0);
- }
- return 0;
- }
+ byte result = 0;
- public static bool getBoolMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
- {
- bool sOff = UseSAforMouse[device];
- switch (control)
- {
- case DS4Controls.Share: return cState.Share;
- case DS4Controls.Options: return cState.Options;
- case DS4Controls.L1: return cState.L1;
- case DS4Controls.R1: return cState.R1;
- case DS4Controls.L3: return cState.L3;
- case DS4Controls.R3: return cState.R3;
- case DS4Controls.DpadUp: return cState.DpadUp;
- case DS4Controls.DpadDown: return cState.DpadDown;
- case DS4Controls.DpadLeft: return cState.DpadLeft;
- case DS4Controls.DpadRight: return cState.DpadRight;
- case DS4Controls.PS: return cState.PS;
- case DS4Controls.Cross: return cState.Cross;
- case DS4Controls.Square: return cState.Square;
- case DS4Controls.Triangle: return cState.Triangle;
- case DS4Controls.Circle: return cState.Circle;
- case DS4Controls.TouchLeft: return (tp != null ? tp.leftDown : false);
- case DS4Controls.TouchRight: return (tp != null ? tp.rightDown : false);
- case DS4Controls.TouchMulti: return (tp != null ? tp.multiDown : false);
- case DS4Controls.TouchUpper: return (tp != null ? tp.upperDown : false);
- case DS4Controls.LXNeg: return cState.LX < 127 - 55;
- case DS4Controls.LYNeg: return cState.LY < 127 - 55;
- case DS4Controls.RXNeg: return cState.RX < 127 - 55;
- case DS4Controls.RYNeg: return cState.RY < 127 - 55;
- case DS4Controls.LXPos: return cState.LX > 127 + 55;
- case DS4Controls.LYPos: return cState.LY > 127 + 55;
- case DS4Controls.RXPos: return cState.RX > 127 + 55;
- case DS4Controls.RYPos: return cState.RY > 127 + 55;
- case DS4Controls.L2: return cState.L2 > 100;
- case DS4Controls.R2: return cState.R2 > 100;
- case DS4Controls.GyroXPos: return !sOff ? SXSens[device] * eState.GyroX > 67 : false;
- case DS4Controls.GyroXNeg: return !sOff ? SXSens[device] * eState.GyroX < -67 : false;
- case DS4Controls.GyroZPos: return !sOff ? SZSens[device] * eState.GyroZ > 67 : false;
- case DS4Controls.GyroZNeg: return !sOff ? SZSens[device] * eState.GyroZ < -67 : false;
- case DS4Controls.SwipeUp: return (tp != null && tp.swipeUp);
- case DS4Controls.SwipeDown: return (tp != null && tp.swipeDown);
- case DS4Controls.SwipeLeft: return (tp != null && tp.swipeLeft);
- case DS4Controls.SwipeRight: return (tp != null && tp.swipeRight);
- }
- return false;
- }
-
- public static byte getXYAxisMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool alt = false)
- {
- byte trueVal = 0;
- byte falseVal = 127;
- double SXD = SXDeadzone[device];
- double SZD = SZDeadzone[device];
- bool sOff = UseSAforMouse[device];
- if (alt)
- trueVal = 255;
- switch (control)
- {
- case DS4Controls.Share: return (byte)(cState.Share ? trueVal : falseVal);
- case DS4Controls.Options: return (byte)(cState.Options ? trueVal : falseVal);
- case DS4Controls.L1: return (byte)(cState.L1 ? trueVal : falseVal);
- case DS4Controls.R1: return (byte)(cState.R1 ? trueVal : falseVal);
- case DS4Controls.L3: return (byte)(cState.L3 ? trueVal : falseVal);
- case DS4Controls.R3: return (byte)(cState.R3 ? trueVal : falseVal);
- case DS4Controls.DpadUp: return (byte)(cState.DpadUp ? trueVal : falseVal);
- case DS4Controls.DpadDown: return (byte)(cState.DpadDown ? trueVal : falseVal);
- case DS4Controls.DpadLeft: return (byte)(cState.DpadLeft ? trueVal : falseVal);
- case DS4Controls.DpadRight: return (byte)(cState.DpadRight ? trueVal : falseVal);
- case DS4Controls.PS: return (byte)(cState.PS ? trueVal : falseVal);
- case DS4Controls.Cross: return (byte)(cState.Cross ? trueVal : falseVal);
- case DS4Controls.Square: return (byte)(cState.Square ? trueVal : falseVal);
- case DS4Controls.Triangle: return (byte)(cState.Triangle ? trueVal : falseVal);
- case DS4Controls.Circle: return (byte)(cState.Circle ? trueVal : falseVal);
- case DS4Controls.TouchLeft: return (byte)(tp != null && tp.leftDown ? trueVal : falseVal);
- case DS4Controls.TouchRight: return (byte)(tp != null && tp.rightDown ? trueVal : falseVal);
- case DS4Controls.TouchMulti: return (byte)(tp != null && tp.multiDown ? trueVal : falseVal);
- case DS4Controls.TouchUpper: return (byte)(tp != null && tp.upperDown ? trueVal : falseVal);
- case DS4Controls.L2: if (alt) return (byte)(127.5f + cState.L2 / 2f); else return (byte)(127.5f - cState.L2 / 2f);
- case DS4Controls.R2: if (alt) return (byte)(127.5f + cState.R2 / 2f); else return (byte)(127.5f - cState.R2 / 2f);
- case DS4Controls.SwipeUp: if (alt) return (byte)(tp != null ? 127.5f + tp.swipeUpB / 2f : 0); else return (byte)(tp != null ? 127.5f - tp.swipeUpB / 2f : 0);
- case DS4Controls.SwipeDown: if (alt) return (byte)(tp != null ? 127.5f + tp.swipeDownB / 2f : 0); else return (byte)(tp != null ? 127.5f - tp.swipeDownB / 2f : 0);
- case DS4Controls.SwipeLeft: if (alt) return (byte)(tp != null ? 127.5f + tp.swipeLeftB / 2f : 0); else return (byte)(tp != null ? 127.5f - tp.swipeLeftB / 2f : 0);
- case DS4Controls.SwipeRight: if (alt) return (byte)(tp != null ? 127.5f + tp.swipeRightB / 2f : 0); else return (byte)(tp != null ? 127.5f - tp.swipeRightB / 2f : 0);
- case DS4Controls.GyroXPos: if (!sOff && eState.GyroX > SXD * 10)
- if (alt) return (byte)Math.Min(255, 127 + SXSens[device] * eState.GyroX); else return (byte)Math.Max(0, 127 - SXSens[device] * eState.GyroX);
- else return falseVal;
- case DS4Controls.GyroXNeg: if (!sOff && eState.GyroX < -SXD * 10)
- if (alt) return (byte)Math.Min(255, 127 + SXSens[device] * -eState.GyroX); else return (byte)Math.Max(0, 127 - SXSens[device] * -eState.GyroX);
- else return falseVal;
- case DS4Controls.GyroZPos: if (!sOff && eState.GyroZ > SZD * 10)
- if (alt) return (byte)Math.Min(255, 127 + SZSens[device] * eState.GyroZ); else return (byte)Math.Max(0, 127 - SZSens[device] * eState.GyroZ);
- else return falseVal;
- case DS4Controls.GyroZNeg: if (!sOff && eState.GyroZ < -SZD * 10)
- if (alt) return (byte)Math.Min(255, 127 + SZSens[device] * -eState.GyroZ); else return (byte)Math.Max(0, 127 - SZSens[device] * -eState.GyroZ);
- else return falseVal;
- }
- if (!alt)
+ if (control >= DS4Controls.Square && control <= DS4Controls.Cross)
{
switch (control)
{
- case DS4Controls.LXNeg: return cState.LX;
- case DS4Controls.LYNeg: return cState.LY;
- case DS4Controls.RXNeg: return cState.RX;
- case DS4Controls.RYNeg: return cState.RY;
- case DS4Controls.LXPos: return (byte)(255 - cState.LX);
- case DS4Controls.LYPos: return (byte)(255 - cState.LY);
- case DS4Controls.RXPos: return (byte)(255 - cState.RX);
- case DS4Controls.RYPos: return (byte)(255 - cState.RY);
+ case DS4Controls.Cross: result = (byte)(cState.Cross ? 255 : 0); break;
+ case DS4Controls.Square: result = (byte)(cState.Square ? 255 : 0); break;
+ case DS4Controls.Triangle: result = (byte)(cState.Triangle ? 255 : 0); break;
+ case DS4Controls.Circle: result = (byte)(cState.Circle ? 255 : 0); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.L1 && control <= DS4Controls.R3)
+ {
+ switch (control)
+ {
+ case DS4Controls.L1: result = (byte)(cState.L1 ? 255 : 0); break;
+ case DS4Controls.L2: result = cState.L2; break;
+ case DS4Controls.L3: result = (byte)(cState.L3 ? 255 : 0); break;
+ case DS4Controls.R1: result = (byte)(cState.R1 ? 255 : 0); break;
+ case DS4Controls.R2: result = cState.R2; break;
+ case DS4Controls.R3: result = (byte)(cState.R3 ? 255 : 0); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft)
+ {
+ switch (control)
+ {
+ case DS4Controls.DpadUp: result = (byte)(cState.DpadUp ? 255 : 0); break;
+ case DS4Controls.DpadDown: result = (byte)(cState.DpadDown ? 255 : 0); break;
+ case DS4Controls.DpadLeft: result = (byte)(cState.DpadLeft ? 255 : 0); break;
+ case DS4Controls.DpadRight: result = (byte)(cState.DpadRight ? 255 : 0); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg: result = (byte)(cState.LX - 127.5f > 0 ? 0 : -(cState.LX - 127.5f) * 2); break;
+ case DS4Controls.LYNeg: result = (byte)(cState.LY - 127.5f > 0 ? 0 : -(cState.LY - 127.5f) * 2); break;
+ case DS4Controls.RXNeg: result = (byte)(cState.RX - 127.5f > 0 ? 0 : -(cState.RX - 127.5f) * 2); break;
+ case DS4Controls.RYNeg: result = (byte)(cState.RY - 127.5f > 0 ? 0 : -(cState.RY - 127.5f) * 2); break;
+ case DS4Controls.LXPos: result = (byte)(cState.LX - 127.5f < 0 ? 0 : (cState.LX - 127.5f) * 2); break;
+ case DS4Controls.LYPos: result = (byte)(cState.LY - 127.5f < 0 ? 0 : (cState.LY - 127.5f) * 2); break;
+ case DS4Controls.RXPos: result = (byte)(cState.RX - 127.5f < 0 ? 0 : (cState.RX - 127.5f) * 2); break;
+ case DS4Controls.RYPos: result = (byte)(cState.RY - 127.5f < 0 ? 0 : (cState.RY - 127.5f) * 2); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.TouchLeft && control <= DS4Controls.TouchRight)
+ {
+ switch (control)
+ {
+ case DS4Controls.TouchLeft: result = (byte)(tp != null && tp.leftDown ? 255 : 0); break;
+ case DS4Controls.TouchRight: result = (byte)(tp != null && tp.rightDown ? 255 : 0); break;
+ case DS4Controls.TouchMulti: result = (byte)(tp != null && tp.multiDown ? 255 : 0); break;
+ case DS4Controls.TouchUpper: result = (byte)(tp != null && tp.upperDown ? 255 : 0); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.SwipeLeft && control <= DS4Controls.SwipeDown)
+ {
+ switch (control)
+ {
+ case DS4Controls.SwipeUp: result = (byte)(tp != null ? tp.swipeUpB : 0); break;
+ case DS4Controls.SwipeDown: result = (byte)(tp != null ? tp.swipeDownB : 0); break;
+ case DS4Controls.SwipeLeft: result = (byte)(tp != null ? tp.swipeLeftB : 0); break;
+ case DS4Controls.SwipeRight: result = (byte)(tp != null ? tp.swipeRightB : 0); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
+ {
+ double SXD = getSXDeadzone(device);
+ double SZD = getSZDeadzone(device);
+ bool sOff = isUsingSAforMouse(device);
+ double sxsens = getSXSens(device);
+ double szsens = getSZSens(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos:
+ {
+ int gyroX = -eState.AccelX;
+ result = (byte)(!sOff && sxsens * gyroX > SXD * 10 ? Math.Min(255, sxsens * gyroX * 2) : 0);
+ break;
+ }
+ case DS4Controls.GyroXNeg:
+ {
+ int gyroX = -eState.AccelX;
+ result = (byte)(!sOff && sxsens * gyroX < -SXD * 10 ? Math.Min(255, sxsens * -gyroX * 2) : 0);
+ break;
+ }
+ case DS4Controls.GyroZPos:
+ {
+ int gyroZ = eState.AccelZ;
+ result = (byte)(!sOff && szsens * gyroZ > SZD * 10 ? Math.Min(255, szsens * gyroZ * 2) : 0);
+ break;
+ }
+ case DS4Controls.GyroZNeg:
+ {
+ int gyroZ = eState.AccelZ;
+ result = (byte)(!sOff && szsens * gyroZ < -SZD * 10 ? Math.Min(255, szsens * -gyroZ * 2) : 0);
+ break;
+ }
+ default: break;
}
}
else
{
switch (control)
{
- case DS4Controls.LXNeg: return (byte)(255 - cState.LX);
- case DS4Controls.LYNeg: return (byte)(255 - cState.LY);
- case DS4Controls.RXNeg: return (byte)(255 - cState.RX);
- case DS4Controls.RYNeg: return (byte)(255 - cState.RY);
- case DS4Controls.LXPos: return cState.LX;
- case DS4Controls.LYPos: return cState.LY;
- case DS4Controls.RXPos: return cState.RX;
- case DS4Controls.RYPos: return cState.RY;
+ case DS4Controls.Share: result = (byte)(cState.Share ? 255 : 0); break;
+ case DS4Controls.Options: result = (byte)(cState.Options ? 255 : 0); break;
+ case DS4Controls.PS: result = (byte)(cState.PS ? 255 : 0); break;
+ default: break;
}
}
- return 0;
+
+ return result;
}
+ /* TODO: Possibly remove usage of this version of the method */
+ public static bool getBoolMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp)
+ {
+ bool result = false;
+
+ if (control >= DS4Controls.Square && control <= DS4Controls.Cross)
+ {
+ switch (control)
+ {
+ case DS4Controls.Cross: result = cState.Cross; break;
+ case DS4Controls.Square: result = cState.Square; break;
+ case DS4Controls.Triangle: result = cState.Triangle; break;
+ case DS4Controls.Circle: result = cState.Circle; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.L1 && control <= DS4Controls.R3)
+ {
+ switch (control)
+ {
+ case DS4Controls.L1: result = cState.L1; break;
+ case DS4Controls.R1: result = cState.R1; break;
+ case DS4Controls.L2: result = cState.L2 > 100; break;
+ case DS4Controls.R2: result = cState.R2 > 100; break;
+ case DS4Controls.L3: result = cState.L3; break;
+ case DS4Controls.R3: result = cState.R3; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft)
+ {
+ switch (control)
+ {
+ case DS4Controls.DpadUp: result = cState.DpadUp; break;
+ case DS4Controls.DpadDown: result = cState.DpadDown; break;
+ case DS4Controls.DpadLeft: result = cState.DpadLeft; break;
+ case DS4Controls.DpadRight: result = cState.DpadRight; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg: result = cState.LX < 127 - 55; break;
+ case DS4Controls.LYNeg: result = cState.LY < 127 - 55; break;
+ case DS4Controls.RXNeg: result = cState.RX < 127 - 55; break;
+ case DS4Controls.RYNeg: result = cState.RY < 127 - 55; break;
+ case DS4Controls.LXPos: result = cState.LX > 127 + 55; break;
+ case DS4Controls.LYPos: result = cState.LY > 127 + 55; break;
+ case DS4Controls.RXPos: result = cState.RX > 127 + 55; break;
+ case DS4Controls.RYPos: result = cState.RY > 127 + 55; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.TouchLeft && control <= DS4Controls.TouchRight)
+ {
+ switch (control)
+ {
+ case DS4Controls.TouchLeft: result = (tp != null ? tp.leftDown : false); break;
+ case DS4Controls.TouchRight: result = (tp != null ? tp.rightDown : false); break;
+ case DS4Controls.TouchMulti: result = (tp != null ? tp.multiDown : false); break;
+ case DS4Controls.TouchUpper: result = (tp != null ? tp.upperDown : false); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.SwipeLeft && control <= DS4Controls.SwipeDown)
+ {
+ switch (control)
+ {
+ case DS4Controls.SwipeUp: result = (tp != null && tp.swipeUp); break;
+ case DS4Controls.SwipeDown: result = (tp != null && tp.swipeDown); break;
+ case DS4Controls.SwipeLeft: result = (tp != null && tp.swipeLeft); break;
+ case DS4Controls.SwipeRight: result = (tp != null && tp.swipeRight); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
+ {
+ bool sOff = isUsingSAforMouse(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos: result = !sOff ? SXSens[device] * -eState.AccelX > 67 : false; break;
+ case DS4Controls.GyroXNeg: result = !sOff ? SXSens[device] * -eState.AccelX < -67 : false; break;
+ case DS4Controls.GyroZPos: result = !sOff ? SZSens[device] * eState.AccelZ > 67 : false; break;
+ case DS4Controls.GyroZNeg: result = !sOff ? SZSens[device] * eState.AccelZ < -67 : false; break;
+ default: break;
+ }
+ }
+ else
+ {
+ switch (control)
+ {
+ case DS4Controls.PS: result = cState.PS; break;
+ case DS4Controls.Share: result = cState.Share; break;
+ case DS4Controls.Options: result = cState.Options; break;
+ default: break;
+ }
+ }
+
+ return result;
+ }
+
+ private static bool getBoolMapping2(int device, DS4Controls control,
+ DS4State cState, DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap)
+ {
+ bool result = false;
+
+ int controlNum = (int)control;
+ DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
+ if (controlType == DS4StateFieldMapping.ControlType.Button)
+ {
+ result = fieldMap.buttons[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.AxisDir)
+ {
+ byte axisValue = fieldMap.axisdirs[controlNum];
+
+ switch (control)
+ {
+ case DS4Controls.LXNeg: result = cState.LX < 127 - 55; break;
+ case DS4Controls.LYNeg: result = cState.LY < 127 - 55; break;
+ case DS4Controls.RXNeg: result = cState.RX < 127 - 55; break;
+ case DS4Controls.RYNeg: result = cState.RY < 127 - 55; break;
+ default: result = axisValue > 127 + 55; break;
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
+ {
+ result = fieldMap.triggers[controlNum] > 100;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Touch)
+ {
+ result = fieldMap.buttons[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.SwipeDir)
+ {
+ result = fieldMap.swipedirbools[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.GyroDir)
+ {
+ bool sOff = isUsingSAforMouse(device);
+ bool safeTest = false;
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos: safeTest = fieldMap.gryodirs[controlNum] > 0; break;
+ case DS4Controls.GyroXNeg: safeTest = fieldMap.gryodirs[controlNum] < -0; break;
+ case DS4Controls.GyroZPos: safeTest = fieldMap.gryodirs[controlNum] > 0; break;
+ case DS4Controls.GyroZNeg: safeTest = fieldMap.gryodirs[controlNum] < -0; break;
+ default: break;
+ }
+
+ result = sOff == false ? safeTest : false;
+ }
+
+ return result;
+ }
+
+ private static bool getBoolActionMapping2(int device, DS4Controls control,
+ DS4State cState, DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap, bool analog = false)
+ {
+ bool result = false;
+
+ int controlNum = (int)control;
+ DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
+ if (controlType == DS4StateFieldMapping.ControlType.Button)
+ {
+ result = fieldMap.buttons[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.AxisDir)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg:
+ {
+ double angle = cState.LSAngle;
+ result = cState.LX < 127 && (angle >= 112.5 && angle <= 247.5);
+ break;
+ }
+ case DS4Controls.LYNeg:
+ {
+ double angle = cState.LSAngle;
+ result = cState.LY < 127 && (angle >= 22.5 && angle <= 157.5);
+ break;
+ }
+ case DS4Controls.RXNeg:
+ {
+ double angle = cState.RSAngle;
+ result = cState.RX < 127 && (angle >= 112.5 && angle <= 247.5);
+ break;
+ }
+ case DS4Controls.RYNeg:
+ {
+ double angle = cState.RSAngle;
+ result = cState.RY < 127 && (angle >= 22.5 && angle <= 157.5);
+ break;
+ }
+ case DS4Controls.LXPos:
+ {
+ double angle = cState.LSAngle;
+ result = cState.LX > 127 && (angle <= 67.5 || angle >= 292.5);
+ break;
+ }
+ case DS4Controls.LYPos:
+ {
+ double angle = cState.LSAngle;
+ result = cState.LY > 127 && (angle >= 202.5 && angle <= 337.5);
+ break;
+ }
+ case DS4Controls.RXPos:
+ {
+ double angle = cState.RSAngle;
+ result = cState.RX > 127 && (angle <= 67.5 || angle >= 292.5);
+ break;
+ }
+ case DS4Controls.RYPos:
+ {
+ double angle = cState.RSAngle;
+ result = cState.RY > 127 && (angle >= 202.5 && angle <= 337.5);
+ break;
+ }
+ default: break;
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
+ {
+ result = fieldMap.triggers[controlNum] > 0;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Touch)
+ {
+ result = fieldMap.buttons[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.SwipeDir)
+ {
+ result = fieldMap.swipedirbools[controlNum];
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.GyroDir)
+ {
+ bool sOff = isUsingSAforMouse(device);
+ bool safeTest = false;
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos: safeTest = fieldMap.gryodirs[controlNum] > 0; break;
+ case DS4Controls.GyroXNeg: safeTest = fieldMap.gryodirs[controlNum] < 0; break;
+ case DS4Controls.GyroZPos: safeTest = fieldMap.gryodirs[controlNum] > 0; break;
+ case DS4Controls.GyroZNeg: safeTest = fieldMap.gryodirs[controlNum] < 0; break;
+ default: break;
+ }
+
+ result = sOff == false ? safeTest : false;
+ }
+
+ return result;
+ }
+
+ /* TODO: Possibly remove usage of this version of the method */
+ public static bool getBoolActionMapping(int device, DS4Controls control,
+ DS4State cState, DS4StateExposed eState, Mouse tp, bool analog=false)
+ {
+ bool result = false;
+
+ if (control >= DS4Controls.Square && control <= DS4Controls.Cross)
+ {
+ switch (control)
+ {
+ case DS4Controls.Cross: result = cState.Cross; break;
+ case DS4Controls.Square: result = cState.Square; break;
+ case DS4Controls.Triangle: result = cState.Triangle; break;
+ case DS4Controls.Circle: result = cState.Circle; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.L1 && control <= DS4Controls.R3)
+ {
+ switch (control)
+ {
+ case DS4Controls.L1: result = cState.L1; break;
+ case DS4Controls.R1: result = cState.R1; break;
+ case DS4Controls.L2: result = cState.L2 > 0; break;
+ case DS4Controls.R2: result = cState.R2 > 0; break;
+ case DS4Controls.L3: result = cState.L3; break;
+ case DS4Controls.R3: result = cState.R3; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft)
+ {
+ switch (control)
+ {
+ case DS4Controls.DpadUp: result = cState.DpadUp; break;
+ case DS4Controls.DpadDown: result = cState.DpadDown; break;
+ case DS4Controls.DpadLeft: result = cState.DpadLeft; break;
+ case DS4Controls.DpadRight: result = cState.DpadRight; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg:
+ {
+ if (!analog)
+ {
+ double angle = cState.LSAngle;
+ result = cState.LX < 127 && (angle >= 112.5 && angle <= 247.5);
+ }
+ else
+ {
+ result = cState.LX < 127;
+ }
+
+ break;
+ }
+ case DS4Controls.LYNeg:
+ {
+ if (!analog)
+ {
+ double angle = cState.LSAngle;
+ result = cState.LY < 127 && (angle >= 22.5 && angle <= 157.5);
+ }
+ else
+ {
+ result = cState.LY < 127;
+ }
+
+ break;
+ }
+ case DS4Controls.RXNeg:
+ {
+ if (!analog)
+ {
+ double angle = cState.RSAngle;
+ result = cState.RX < 127 && (angle >= 112.5 && angle <= 247.5);
+ }
+ else
+ {
+ result = cState.RX < 127;
+ }
+
+ break;
+ }
+ case DS4Controls.RYNeg:
+ {
+ if (!analog)
+ {
+ double angle = cState.RSAngle;
+ result = cState.RY < 127 && (angle >= 22.5 && angle <= 157.5);
+ }
+ else
+ {
+ result = cState.RY < 127;
+ }
+
+ break;
+ }
+ case DS4Controls.LXPos:
+ {
+ if (!analog)
+ {
+ double angle = cState.LSAngle;
+ result = cState.LX > 127 && (angle <= 67.5 || angle >= 292.5);
+ }
+ else
+ {
+ result = cState.LX > 127;
+ }
+
+ break;
+ }
+ case DS4Controls.LYPos:
+ {
+ if (!analog)
+ {
+ double angle = cState.LSAngle;
+ result = cState.LY > 127 && (angle >= 202.5 && angle <= 337.5);
+ }
+ else
+ {
+ result = cState.LY > 127;
+ }
+
+ break;
+ }
+ case DS4Controls.RXPos:
+ {
+ if (!analog)
+ {
+ double angle = cState.RSAngle;
+ result = cState.RX > 127 && (angle <= 67.5 || angle >= 292.5);
+ }
+ else
+ {
+ result = cState.RX > 127;
+ }
+
+ break;
+ }
+ case DS4Controls.RYPos:
+ {
+ if (!analog)
+ {
+ double angle = cState.RSAngle;
+ result = cState.RY > 127 && (angle >= 202.5 && angle <= 337.5);
+ }
+ else
+ {
+ result = cState.RY > 127;
+ }
+
+ break;
+ }
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.TouchLeft && control <= DS4Controls.TouchRight)
+ {
+ switch (control)
+ {
+ case DS4Controls.TouchLeft: result = (tp != null ? tp.leftDown : false); break;
+ case DS4Controls.TouchRight: result = (tp != null ? tp.rightDown : false); break;
+ case DS4Controls.TouchMulti: result = (tp != null ? tp.multiDown : false); break;
+ case DS4Controls.TouchUpper: result = (tp != null ? tp.upperDown : false); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.SwipeLeft && control <= DS4Controls.SwipeDown)
+ {
+ switch (control)
+ {
+ case DS4Controls.SwipeUp: result = (tp != null && tp.swipeUp); break;
+ case DS4Controls.SwipeDown: result = (tp != null && tp.swipeDown); break;
+ case DS4Controls.SwipeLeft: result = (tp != null && tp.swipeLeft); break;
+ case DS4Controls.SwipeRight: result = (tp != null && tp.swipeRight); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
+ {
+ bool sOff = isUsingSAforMouse(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos: result = !sOff ? SXSens[device] * eState.AccelX > 67 : false; break;
+ case DS4Controls.GyroXNeg: result = !sOff ? SXSens[device] * eState.AccelX < -67 : false; break;
+ case DS4Controls.GyroZPos: result = !sOff ? SZSens[device] * eState.AccelZ > 67 : false; break;
+ case DS4Controls.GyroZNeg: result = !sOff ? SZSens[device] * eState.AccelZ < -67 : false; break;
+ default: break;
+ }
+ }
+ else
+ {
+ switch (control)
+ {
+ case DS4Controls.PS: result = cState.PS; break;
+ case DS4Controls.Share: result = cState.Share; break;
+ case DS4Controls.Options: result = cState.Options; break;
+ default: break;
+ }
+ }
+
+ return result;
+ }
+
+ public static bool getBoolButtonMapping(bool stateButton)
+ {
+ return stateButton;
+ }
+
+ public static bool getBoolAxisDirMapping(byte stateAxis, bool positive)
+ {
+ return positive ? stateAxis > 127 + 55 : stateAxis < 127 - 55;
+ }
+
+ public static bool getBoolTriggerMapping(byte stateAxis)
+ {
+ return stateAxis > 100;
+ }
+
+ public static bool getBoolTouchMapping(bool touchButton)
+ {
+ return touchButton;
+ }
+
+ private static byte getXYAxisMapping2(int device, DS4Controls control, DS4State cState,
+ DS4StateExposed eState, Mouse tp, DS4StateFieldMapping fieldMap, bool alt = false)
+ {
+ byte result = 0;
+ byte trueVal = 0;
+ byte falseVal = 127;
+
+ if (alt)
+ trueVal = 255;
+
+ int controlNum = (int)control;
+ DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
+
+ if (controlType == DS4StateFieldMapping.ControlType.Button)
+ {
+ result = fieldMap.buttons[controlNum] ? trueVal : falseVal;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.AxisDir)
+ {
+ byte axisValue = fieldMap.axisdirs[controlNum];
+
+ switch (control)
+ {
+ case DS4Controls.LXNeg: if (!alt) result = cState.LX; else result = (byte)(255 - cState.LX); break;
+ case DS4Controls.LYNeg: if (!alt) result = cState.LY; else result = (byte)(255 - cState.LY); break;
+ case DS4Controls.RXNeg: if (!alt) result = cState.RX; else result = (byte)(255 - cState.RX); break;
+ case DS4Controls.RYNeg: if (!alt) result = cState.RY; else result = (byte)(255 - cState.RY); break;
+ default: if (!alt) result = (byte)(255 - axisValue); else result = axisValue; break;
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
+ {
+ if (alt)
+ {
+ result = (byte)(127.5f + fieldMap.triggers[controlNum] / 2f);
+ }
+ else
+ {
+ result = (byte)(127.5f - fieldMap.triggers[controlNum] / 2f);
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Touch)
+ {
+ result = fieldMap.buttons[controlNum] ? trueVal : falseVal;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.SwipeDir)
+ {
+ if (alt)
+ {
+ result = (byte)(tp != null ? 127.5f + fieldMap.swipedirs[controlNum] / 2f : 0);
+ }
+ else
+ {
+ result = (byte)(tp != null ? 127.5f - fieldMap.swipedirs[controlNum] / 2f : 0);
+ }
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.GyroDir)
+ {
+ bool sOff = isUsingSAforMouse(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos:
+ {
+ if (sOff == false && fieldMap.gryodirs[controlNum] > 0)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + fieldMap.gryodirs[controlNum]); else result = (byte)Math.Max(0, 127 - fieldMap.gryodirs[controlNum]);
+ }
+ else result = falseVal;
+ break;
+ }
+ case DS4Controls.GyroXNeg:
+ {
+ if (sOff == false && fieldMap.gryodirs[controlNum] < 0)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + -fieldMap.gryodirs[controlNum]); else result = (byte)Math.Max(0, 127 - -fieldMap.gryodirs[controlNum]);
+ }
+ else result = falseVal;
+ break;
+ }
+ case DS4Controls.GyroZPos:
+ {
+ if (sOff == false && fieldMap.gryodirs[controlNum] > 0)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + fieldMap.gryodirs[controlNum]); else result = (byte)Math.Max(0, 127 - fieldMap.gryodirs[controlNum]);
+ }
+ else return falseVal;
+ break;
+ }
+ case DS4Controls.GyroZNeg:
+ {
+ if (sOff == false && fieldMap.gryodirs[controlNum] < 0)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + -fieldMap.gryodirs[controlNum]); else result = (byte)Math.Max(0, 127 - -fieldMap.gryodirs[controlNum]);
+ }
+ else result = falseVal;
+ break;
+ }
+ default: break;
+ }
+ }
+
+ return result;
+ }
+
+ public static byte getXYAxisMapping(int device, DS4Controls control, DS4State cState, DS4StateExposed eState, Mouse tp, bool alt = false)
+ {
+ byte result = 0;
+ byte trueVal = 0;
+ byte falseVal = 127;
+
+ if (alt)
+ trueVal = 255;
+
+ if (control >= DS4Controls.Square && control <= DS4Controls.Cross)
+ {
+ switch (control)
+ {
+ case DS4Controls.Cross: result = (byte)(cState.Cross ? trueVal : falseVal); break;
+ case DS4Controls.Square: result = (byte)(cState.Square ? trueVal : falseVal); break;
+ case DS4Controls.Triangle: result = (byte)(cState.Triangle ? trueVal : falseVal); break;
+ case DS4Controls.Circle: result = (byte)(cState.Circle ? trueVal : falseVal); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.L1 && control <= DS4Controls.R3)
+ {
+ switch (control)
+ {
+ case DS4Controls.L1: result = (byte)(cState.L1 ? trueVal : falseVal); break;
+ case DS4Controls.L2: if (alt) result = (byte)(127.5f + cState.L2 / 2f); else result = (byte)(127.5f - cState.L2 / 2f); break;
+ case DS4Controls.L3: result = (byte)(cState.L3 ? trueVal : falseVal); break;
+ case DS4Controls.R1: result = (byte)(cState.R1 ? trueVal : falseVal); break;
+ case DS4Controls.R2: if (alt) result = (byte)(127.5f + cState.R2 / 2f); else result = (byte)(127.5f - cState.R2 / 2f); break;
+ case DS4Controls.R3: result = (byte)(cState.R3 ? trueVal : falseVal); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft)
+ {
+ switch (control)
+ {
+ case DS4Controls.DpadUp: result = (byte)(cState.DpadUp ? trueVal : falseVal); break;
+ case DS4Controls.DpadDown: result = (byte)(cState.DpadDown ? trueVal : falseVal); break;
+ case DS4Controls.DpadLeft: result = (byte)(cState.DpadLeft ? trueVal : falseVal); break;
+ case DS4Controls.DpadRight: result = (byte)(cState.DpadRight ? trueVal : falseVal); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg: if (!alt) result = cState.LX; else result = (byte)(255 - cState.LX); break;
+ case DS4Controls.LYNeg: if (!alt) result = cState.LY; else result = (byte)(255 - cState.LY); break;
+ case DS4Controls.RXNeg: if (!alt) result = cState.RX; else result = (byte)(255 - cState.RX); break;
+ case DS4Controls.RYNeg: if (!alt) result = cState.RY; else result = (byte)(255 - cState.RY); break;
+ case DS4Controls.LXPos: if (!alt) result = (byte)(255 - cState.LX); else result = cState.LX; break;
+ case DS4Controls.LYPos: if (!alt) result = (byte)(255 - cState.LY); else result = cState.LY; break;
+ case DS4Controls.RXPos: if (!alt) result = (byte)(255 - cState.RX); else result = cState.RX; break;
+ case DS4Controls.RYPos: if (!alt) result = (byte)(255 - cState.RY); else result = cState.RY; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.TouchLeft && control <= DS4Controls.TouchRight)
+ {
+ switch (control)
+ {
+ case DS4Controls.TouchLeft: result = (byte)(tp != null && tp.leftDown ? trueVal : falseVal); break;
+ case DS4Controls.TouchRight: result = (byte)(tp != null && tp.rightDown ? trueVal : falseVal); break;
+ case DS4Controls.TouchMulti: result = (byte)(tp != null && tp.multiDown ? trueVal : falseVal); break;
+ case DS4Controls.TouchUpper: result = (byte)(tp != null && tp.upperDown ? trueVal : falseVal); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.SwipeLeft && control <= DS4Controls.SwipeDown)
+ {
+ switch (control)
+ {
+ case DS4Controls.SwipeUp: if (alt) result = (byte)(tp != null ? 127.5f + tp.swipeUpB / 2f : 0); else result = (byte)(tp != null ? 127.5f - tp.swipeUpB / 2f : 0); break;
+ case DS4Controls.SwipeDown: if (alt) result = (byte)(tp != null ? 127.5f + tp.swipeDownB / 2f : 0); else result = (byte)(tp != null ? 127.5f - tp.swipeDownB / 2f : 0); break;
+ case DS4Controls.SwipeLeft: if (alt) result = (byte)(tp != null ? 127.5f + tp.swipeLeftB / 2f : 0); else result = (byte)(tp != null ? 127.5f - tp.swipeLeftB / 2f : 0); break;
+ case DS4Controls.SwipeRight: if (alt) result = (byte)(tp != null ? 127.5f + tp.swipeRightB / 2f : 0); else result = (byte)(tp != null ? 127.5f - tp.swipeRightB / 2f : 0); break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.GyroXPos && control <= DS4Controls.GyroZNeg)
+ {
+ double SXD = getSXDeadzone(device);
+ double SZD = getSZDeadzone(device);
+ bool sOff = isUsingSAforMouse(device);
+
+ switch (control)
+ {
+ case DS4Controls.GyroXPos:
+ {
+ if (!sOff && -eState.AccelX > SXD * 10)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + SXSens[device] * -eState.AccelX); else result = (byte)Math.Max(0, 127 - SXSens[device] * -eState.AccelX);
+ }
+ else result = falseVal;
+ break;
+ }
+ case DS4Controls.GyroXNeg:
+ {
+ if (!sOff && -eState.AccelX < -SXD * 10)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + SXSens[device] * eState.AccelX); else result = (byte)Math.Max(0, 127 - SXSens[device] * eState.AccelX);
+ }
+ else result = falseVal;
+ break;
+ }
+ case DS4Controls.GyroZPos:
+ {
+ if (!sOff && eState.AccelZ > SZD * 10)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + SZSens[device] * eState.AccelZ); else result = (byte)Math.Max(0, 127 - SZSens[device] * eState.AccelZ);
+ }
+ else return falseVal;
+ break;
+ }
+ case DS4Controls.GyroZNeg:
+ {
+ if (!sOff && eState.AccelZ < -SZD * 10)
+ {
+ if (alt) result = (byte)Math.Min(255, 127 + SZSens[device] * -eState.AccelZ); else result = (byte)Math.Max(0, 127 - SZSens[device] * -eState.AccelZ);
+ }
+ else result = falseVal;
+ break;
+ }
+ default: break;
+ }
+ }
+ else
+ {
+ switch (control)
+ {
+ case DS4Controls.Share: result = (byte)(cState.Share ? trueVal : falseVal); break;
+ case DS4Controls.Options: result = (byte)(cState.Options ? trueVal : falseVal); break;
+ case DS4Controls.PS: result = (byte)(cState.PS ? trueVal : falseVal); break;
+ default: break;
+ }
+ }
+
+ return result;
+ }
+
+ /* TODO: Possibly remove usage of this version of the method */
//Returns false for any bool,
//if control is one of the xy axis returns 127
//if its a trigger returns 0
public static void resetToDefaultValue(DS4Controls control, DS4State cState)
{
- switch (control)
+ if (control >= DS4Controls.Square && control <= DS4Controls.Cross)
{
- case DS4Controls.Share: cState.Share = false; break;
- case DS4Controls.Options: cState.Options = false; break;
- case DS4Controls.L1: cState.L1 = false; break;
- case DS4Controls.R1: cState.R1 = false; break;
- case DS4Controls.L3: cState.L3 = false; break;
- case DS4Controls.R3: cState.R3 = false; break;
- case DS4Controls.DpadUp: cState.DpadUp = false; break;
- case DS4Controls.DpadDown: cState.DpadDown = false; break;
- case DS4Controls.DpadLeft: cState.DpadLeft = false; break;
- case DS4Controls.DpadRight: cState.DpadRight = false; break;
- case DS4Controls.PS: cState.PS = false; break;
- case DS4Controls.Cross: cState.Cross = false; break;
- case DS4Controls.Square: cState.Square = false; break;
- case DS4Controls.Triangle: cState.Triangle = false; break;
- case DS4Controls.Circle: cState.Circle = false; break;
- case DS4Controls.LXNeg: cState.LX = 127; break;
- case DS4Controls.LYNeg: cState.LY = 127; break;
- case DS4Controls.RXNeg: cState.RX = 127; break;
- case DS4Controls.RYNeg: cState.RY = 127; break;
- case DS4Controls.LXPos: cState.LX = 127; break;
- case DS4Controls.LYPos: cState.LY = 127; break;
- case DS4Controls.RXPos: cState.RX = 127; break;
- case DS4Controls.RYPos: cState.RY = 127; break;
- case DS4Controls.L2: cState.L2 = 0; break;
- case DS4Controls.R2: cState.R2 = 0; break;
+ switch (control)
+ {
+ case DS4Controls.Cross: cState.Cross = false; break;
+ case DS4Controls.Square: cState.Square = false; break;
+ case DS4Controls.Triangle: cState.Triangle = false; break;
+ case DS4Controls.Circle: cState.Circle = false; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.L1 && control <= DS4Controls.R3)
+ {
+ switch (control)
+ {
+ case DS4Controls.L1: cState.L1 = false; break;
+ case DS4Controls.L2: cState.L2 = 0; break;
+ case DS4Controls.L3: cState.L3 = false; break;
+ case DS4Controls.R1: cState.R1 = false; break;
+ case DS4Controls.R2: cState.R2 = 0; break;
+ case DS4Controls.R3: cState.R3 = false; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.DpadUp && control <= DS4Controls.DpadLeft)
+ {
+ switch (control)
+ {
+ case DS4Controls.DpadUp: cState.DpadUp = false; break;
+ case DS4Controls.DpadDown: cState.DpadDown = false; break;
+ case DS4Controls.DpadLeft: cState.DpadLeft = false; break;
+ case DS4Controls.DpadRight: cState.DpadRight = false; break;
+ default: break;
+ }
+ }
+ else if (control >= DS4Controls.LXNeg && control <= DS4Controls.RYPos)
+ {
+ switch (control)
+ {
+ case DS4Controls.LXNeg: cState.LX = 127; break;
+ case DS4Controls.LYNeg: cState.LY = 127; break;
+ case DS4Controls.RXNeg: cState.RX = 127; break;
+ case DS4Controls.RYNeg: cState.RY = 127; break;
+ case DS4Controls.LXPos: cState.LX = 127; break;
+ case DS4Controls.LYPos: cState.LY = 127; break;
+ case DS4Controls.RXPos: cState.RX = 127; break;
+ case DS4Controls.RYPos: cState.RY = 127; break;
+ default: break;
+ }
+ }
+ else
+ {
+ switch (control)
+ {
+ case DS4Controls.Share: cState.Share = false; break;
+ case DS4Controls.Options: cState.Options = false; break;
+ case DS4Controls.PS: cState.PS = false; break;
+ default: break;
+ }
+ }
+ }
+
+ private static void resetToDefaultValue2(DS4Controls control, DS4State cState,
+ DS4StateFieldMapping fieldMap)
+ {
+ int controlNum = (int)control;
+ DS4StateFieldMapping.ControlType controlType = DS4StateFieldMapping.mappedType[controlNum];
+ if (controlType == DS4StateFieldMapping.ControlType.Button)
+ {
+ fieldMap.buttons[controlNum] = false;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.AxisDir)
+ {
+ fieldMap.axisdirs[controlNum] = 127;
+ int controlRelation = (controlNum % 2 == 0 ? controlNum - 1 : controlNum + 1);
+ fieldMap.axisdirs[controlRelation] = 127;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Trigger)
+ {
+ fieldMap.triggers[controlNum] = 0;
+ }
+ else if (controlType == DS4StateFieldMapping.ControlType.Touch)
+ {
+ fieldMap.buttons[controlNum] = false;
}
}
}
diff --git a/DS4Windows/DS4Control/Mouse.cs b/DS4Windows/DS4Control/Mouse.cs
index bd90856..126eeb5 100644
--- a/DS4Windows/DS4Control/Mouse.cs
+++ b/DS4Windows/DS4Control/Mouse.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Runtime.InteropServices;
namespace DS4Windows
{
@@ -17,35 +13,83 @@ namespace DS4Windows
private readonly MouseWheel wheel;
private bool tappedOnce = false, secondtouchbegin = false;
public bool swipeLeft, swipeRight, swipeUp, swipeDown;
+ public bool priorSwipeLeft, priorSwipeRight, priorSwipeUp, priorSwipeDown;
public byte swipeLeftB, swipeRightB, swipeUpB, swipeDownB, swipedB;
+ public byte priorSwipeLeftB, priorSwipeRightB, priorSwipeUpB, priorSwipeDownB, priorSwipedB;
public bool slideleft, slideright;
+ public bool priorSlideLeft, priorSlideright;
// touch area stuff
public bool leftDown, rightDown, upperDown, multiDown;
+ public bool priorLeftDown, priorRightDown, priorUpperDown, priorMultiDown;
protected DS4Controls pushed = DS4Controls.None;
protected Mapping.Click clicked = Mapping.Click.None;
+ internal const int TRACKBALL_INIT_FICTION = 10;
+ internal const int TRACKBALL_MASS = 45;
+ internal const double TRACKBALL_RADIUS = 0.0245;
+
+ private double TRACKBALL_INERTIA = 2.0 * (TRACKBALL_MASS * TRACKBALL_RADIUS * TRACKBALL_RADIUS) / 5.0;
+ private double TRACKBALL_SCALE = 0.004;
+ private const int TRACKBALL_BUFFER_LEN = 8;
+ private double[] trackballXBuffer = new double[TRACKBALL_BUFFER_LEN];
+ private double[] trackballYBuffer = new double[TRACKBALL_BUFFER_LEN];
+ private int trackballBufferTail = 0;
+ private int trackballBufferHead = 0;
+ private double trackballAccel = 0.0;
+ private double trackballXVel = 0.0;
+ private double trackballYVel = 0.0;
+ private bool trackballActive = false;
+ private double trackballDXRemain = 0.0;
+ private double trackballDYRemain = 0.0;
+
public Mouse(int deviceID, DS4Device d)
{
deviceNum = deviceID;
dev = d;
cursor = new MouseCursor(deviceNum);
wheel = new MouseWheel(deviceNum);
+ trackballAccel = TRACKBALL_RADIUS * TRACKBALL_INIT_FICTION / TRACKBALL_INERTIA;
+ firstTouch = new Touch(0, 0, 0, null);
}
+ public void ResetTrackAccel(double friction)
+ {
+ trackballAccel = TRACKBALL_RADIUS * friction / TRACKBALL_INERTIA;
+ }
+
+ bool triggeractivated = false;
+ bool useReverseRatchet = false;
+
public virtual void sixaxisMoved(object sender, SixAxisEventArgs arg)
{
- if (Global.UseSAforMouse[deviceNum] && Global.GyroSensitivity[deviceNum] > 0)
+ if (Global.isUsingSAforMouse(deviceNum) && Global.getGyroSensitivity(deviceNum) > 0)
{
- bool triggeractivated = true;
+ s = dev.getCurrentStateRef();
+
+ triggeractivated = true;
+ useReverseRatchet = Global.getGyroTriggerTurns(deviceNum);
int i = 0;
- string[] ss = Global.SATriggers[deviceNum].Split(',');
+ string[] ss = Global.getSATriggers(deviceNum).Split(',');
if (!string.IsNullOrEmpty(ss[0]))
- foreach (string s in ss)
+ {
+ string s = string.Empty;
+ for (int index = 0, arlen = ss.Length;
+ triggeractivated && index < arlen; index++)
+ {
+ s = ss[index];
if (!(int.TryParse(s, out i) && getDS4ControlsByName(i)))
+ {
triggeractivated = false;
- if (triggeractivated)
+ }
+ }
+ }
+
+ if (useReverseRatchet && triggeractivated)
cursor.sixaxisMoved(arg);
- dev.getCurrentState(s);
+ else if (!useReverseRatchet && !triggeractivated)
+ cursor.sixaxisMoved(arg);
+ else
+ cursor.mouseRemainderReset();
}
}
@@ -68,20 +112,43 @@ namespace DS4Windows
case 11: return s.DpadRight;
case 12: return s.L3;
case 13: return s.R3;
- case 14: return s.Touch1;
- case 15: return s.Touch2;
+ case 14: return s.Touch1Finger;
+ case 15: return s.Touch2Fingers;
case 16: return s.Options;
case 17: return s.Share;
case 18: return s.PS;
+ default: break;
}
+
return false;
}
+ private bool tempBool = false;
public virtual void touchesMoved(object sender, TouchpadEventArgs arg)
{
- if (!Global.UseTPforControls[deviceNum])
+ s = dev.getCurrentStateRef();
+
+ if (Global.getUseTPforControls(deviceNum) == false)
{
- cursor.touchesMoved(arg, dragging || dragging2);
+ int[] disArray = Global.getTouchDisInvertTriggers(deviceNum);
+ tempBool = true;
+ for (int i = 0, arlen = disArray.Length; tempBool && i < arlen; i++)
+ {
+ if (getDS4ControlsByName(disArray[i]) == false)
+ tempBool = false;
+ }
+
+ if (Global.getTrackballMode(deviceNum))
+ {
+ int iIndex = trackballBufferTail;
+ trackballXBuffer[iIndex] = (arg.touches[0].deltaX * TRACKBALL_SCALE) / dev.getCurrentStateRef().elapsedTime;
+ trackballYBuffer[iIndex] = (arg.touches[0].deltaY * TRACKBALL_SCALE) / dev.getCurrentStateRef().elapsedTime;
+ trackballBufferTail = (iIndex + 1) % TRACKBALL_BUFFER_LEN;
+ if (trackballBufferHead == trackballBufferTail)
+ trackballBufferHead = (trackballBufferHead + 1) % TRACKBALL_BUFFER_LEN;
+ }
+
+ cursor.touchesMoved(arg, dragging || dragging2, tempBool);
wheel.touchesMoved(arg, dragging || dragging2);
}
else
@@ -93,54 +160,78 @@ namespace DS4Windows
if (arg.touches[0].hwY - firstTouch.hwY > 300) swipeDown = true;
if (arg.touches[0].hwY - firstTouch.hwY < -300) swipeUp = true;
}
+
swipeUpB = (byte)Math.Min(255, Math.Max(0, (firstTouch.hwY - arg.touches[0].hwY) * 1.5f));
swipeDownB = (byte)Math.Min(255, Math.Max(0, (arg.touches[0].hwY - firstTouch.hwY) * 1.5f));
swipeLeftB = (byte)Math.Min(255, Math.Max(0, firstTouch.hwX - arg.touches[0].hwX));
swipeRightB = (byte)Math.Min(255, Math.Max(0, arg.touches[0].hwX - firstTouch.hwX));
}
+
if (Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 50 && arg.touches.Length == 2)
+ {
if (arg.touches[0].hwX - firstTouch.hwX > 200 && !slideleft)
slideright = true;
else if (firstTouch.hwX - arg.touches[0].hwX > 200 && !slideright)
slideleft = true;
- dev.getCurrentState(s);
+ }
+
synthesizeMouseButtons();
}
+
public virtual void touchesBegan(object sender, TouchpadEventArgs arg)
{
if (!Global.UseTPforControls[deviceNum])
{
+ Array.Clear(trackballXBuffer, 0, TRACKBALL_BUFFER_LEN);
+ Array.Clear(trackballXBuffer, 0, TRACKBALL_BUFFER_LEN);
+ trackballXVel = 0.0;
+ trackballYVel = 0.0;
+ trackballActive = false;
+ trackballBufferTail = 0;
+ trackballBufferHead = 0;
+ trackballDXRemain = 0.0;
+ trackballDYRemain = 0.0;
+
cursor.touchesBegan(arg);
wheel.touchesBegan(arg);
}
+
pastTime = arg.timeStamp;
- firstTouch = arg.touches[0];
- if (Global.DoubleTap[deviceNum])
+ firstTouch.populate(arg.touches[0].hwX, arg.touches[0].hwY, arg.touches[0].touchID,
+ arg.touches[0].previousTouch);
+
+ if (Global.getDoubleTap(deviceNum))
{
DateTime test = arg.timeStamp;
if (test <= (firstTap + TimeSpan.FromMilliseconds((double)Global.TapSensitivity[deviceNum] * 1.5)) && !arg.touchButtonPressed)
secondtouchbegin = true;
}
- dev.getCurrentState(s);
+
+ s = dev.getCurrentStateRef();
synthesizeMouseButtons();
}
+
public virtual void touchesEnded(object sender, TouchpadEventArgs arg)
{
+ s = dev.getCurrentStateRef();
slideright = slideleft = false;
swipeUp = swipeDown = swipeLeft = swipeRight = false;
swipeUpB = swipeDownB = swipeLeftB = swipeRightB = 0;
- if (Global.TapSensitivity[deviceNum] != 0 && !Global.UseTPforControls[deviceNum])
+ byte tapSensitivity = Global.getTapSensitivity(deviceNum);
+ if (tapSensitivity != 0 && !Global.getUseTPforControls(deviceNum))
{
-
if (secondtouchbegin)
{
tappedOnce = false;
secondtouchbegin = false;
}
+
DateTime test = arg.timeStamp;
- if (test <= (pastTime + TimeSpan.FromMilliseconds((double)Global.TapSensitivity[deviceNum] * 2)) && !arg.touchButtonPressed && !tappedOnce)
+ if (test <= (pastTime + TimeSpan.FromMilliseconds((double)tapSensitivity * 2)) && !arg.touchButtonPressed && !tappedOnce)
+ {
if (Math.Abs(firstTouch.hwX - arg.touches[0].hwX) < 10 && Math.Abs(firstTouch.hwY - arg.touches[0].hwY) < 10)
- if (Global.DoubleTap[deviceNum])
+ {
+ if (Global.getDoubleTap(deviceNum))
{
tappedOnce = true;
firstTap = arg.timeStamp;
@@ -148,8 +239,97 @@ namespace DS4Windows
}
else
Mapping.MapClick(deviceNum, Mapping.Click.Left); //this way no delay if disabled
+ }
+ }
}
- dev.getCurrentState(s);
+ else
+ {
+ if (Global.getUseTPforControls(deviceNum) == false)
+ {
+ int[] disArray = Global.getTouchDisInvertTriggers(deviceNum);
+ tempBool = true;
+ for (int i = 0, arlen = disArray.Length; tempBool && i < arlen; i++)
+ {
+ if (getDS4ControlsByName(disArray[i]) == false)
+ tempBool = false;
+ }
+
+ if (Global.getTrackballMode(deviceNum))
+ {
+ if (!trackballActive)
+ {
+ double currentWeight = 1.0;
+ double finalWeight = 0.0;
+ double x_out = 0.0, y_out = 0.0;
+ int idx = -1;
+ for (int i = 0; i < TRACKBALL_BUFFER_LEN && idx != trackballBufferHead; i++)
+ {
+ idx = (trackballBufferTail - i - 1 + TRACKBALL_BUFFER_LEN) % TRACKBALL_BUFFER_LEN;
+ x_out += trackballXBuffer[idx] * currentWeight;
+ y_out += trackballYBuffer[idx] * currentWeight;
+ finalWeight += currentWeight;
+ currentWeight *= 1.0;
+ }
+
+ x_out /= finalWeight;
+ trackballXVel = x_out;
+ y_out /= finalWeight;
+ trackballYVel = y_out;
+
+ trackballActive = true;
+ }
+
+ double tempAngle = Math.Atan2(-trackballYVel, trackballXVel);
+ double normX = Math.Abs(Math.Cos(tempAngle));
+ double normY = Math.Abs(Math.Sin(tempAngle));
+ int signX = Math.Sign(trackballXVel);
+ int signY = Math.Sign(trackballYVel);
+
+ double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.elapsedTime * normX);
+ double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.elapsedTime * normY);
+ double xVNew = trackballXVel - (trackXvDecay * signX);
+ double yVNew = trackballYVel - (trackYvDecay * signY);
+ double xMotion = (xVNew * s.elapsedTime) / TRACKBALL_SCALE;
+ double yMotion = (yVNew * s.elapsedTime) / TRACKBALL_SCALE;
+ if (xMotion != 0.0)
+ {
+ xMotion += trackballDXRemain;
+ }
+ else
+ {
+ trackballDXRemain = 0.0;
+ }
+
+ int dx = (int)xMotion;
+ trackballDXRemain = xMotion - dx;
+
+ if (yMotion != 0.0)
+ {
+ yMotion += trackballDYRemain;
+ }
+ else
+ {
+ trackballDYRemain = 0.0;
+ }
+
+ int dy = (int)yMotion;
+ trackballDYRemain = yMotion - dy;
+
+ trackballXVel = xVNew;
+ trackballYVel = yVNew;
+
+ if (dx == 0 && dy == 0)
+ {
+ trackballActive = false;
+ }
+ else
+ {
+ cursor.TouchMoveCursor(dx, dy, tempBool);
+ }
+ }
+ }
+ }
+
synthesizeMouseButtons();
}
@@ -165,28 +345,95 @@ namespace DS4Windows
public virtual void touchUnchanged(object sender, EventArgs unused)
{
- dev.getCurrentState(s);
- //if (s.Touch1 || s.Touch2 || s.TouchButton)
- synthesizeMouseButtons();
+ s = dev.getCurrentStateRef();
+
+ if (trackballActive)
+ {
+ if (Global.getUseTPforControls(deviceNum) == false)
+ {
+ int[] disArray = Global.getTouchDisInvertTriggers(deviceNum);
+ tempBool = true;
+ for (int i = 0, arlen = disArray.Length; tempBool && i < arlen; i++)
+ {
+ if (getDS4ControlsByName(disArray[i]) == false)
+ tempBool = false;
+ }
+
+ double tempAngle = Math.Atan2(-trackballYVel, trackballXVel);
+ double normX = Math.Abs(Math.Cos(tempAngle));
+ double normY = Math.Abs(Math.Sin(tempAngle));
+ int signX = Math.Sign(trackballXVel);
+ int signY = Math.Sign(trackballYVel);
+ double trackXvDecay = Math.Min(Math.Abs(trackballXVel), trackballAccel * s.elapsedTime * normX);
+ double trackYvDecay = Math.Min(Math.Abs(trackballYVel), trackballAccel * s.elapsedTime * normY);
+ double xVNew = trackballXVel - (trackXvDecay * signX);
+ double yVNew = trackballYVel - (trackYvDecay * signY);
+ double xMotion = (xVNew * s.elapsedTime) / TRACKBALL_SCALE;
+ double yMotion = (yVNew * s.elapsedTime) / TRACKBALL_SCALE;
+ if (xMotion != 0.0)
+ {
+ xMotion += trackballDXRemain;
+ }
+ else
+ {
+ trackballDXRemain = 0.0;
+ }
+
+ int dx = (int)xMotion;
+ trackballDXRemain = xMotion - dx;
+
+ if (yMotion != 0.0)
+ {
+ yMotion += trackballDYRemain;
+ }
+ else
+ {
+ trackballDYRemain = 0.0;
+ }
+
+ int dy = (int)yMotion;
+ trackballDYRemain = yMotion - dy;
+
+ trackballXVel = xVNew;
+ trackballYVel = yVNew;
+
+ if (dx == 0 && dy == 0)
+ {
+ trackballActive = false;
+ }
+ else
+ {
+ cursor.TouchMoveCursor(dx, dy, tempBool);
+ }
+ }
+ }
+
+ if (s.TouchButton)
+ synthesizeMouseButtons();
}
- private DS4State remapped = new DS4State();
public bool dragging, dragging2;
private void synthesizeMouseButtons()
{
- if (Global.GetDS4Action(deviceNum, DS4Controls.TouchLeft.ToString(), false) == null && leftDown)
+ if (Global.GetDS4Action(deviceNum, DS4Controls.TouchLeft, false) == null && leftDown)
{
Mapping.MapClick(deviceNum, Mapping.Click.Left);
dragging2 = true;
}
else
+ {
dragging2 = false;
- if (Global.GetDS4Action(deviceNum, DS4Controls.TouchUpper.ToString(), false) == null && upperDown)
+ }
+
+ if (Global.GetDS4Action(deviceNum, DS4Controls.TouchUpper, false) == null && upperDown)
Mapping.MapClick(deviceNum, Mapping.Click.Middle);
- if (Global.GetDS4Action(deviceNum, DS4Controls.TouchRight.ToString(), false) == null && rightDown)
+
+ if (Global.GetDS4Action(deviceNum, DS4Controls.TouchRight, false) == null && rightDown)
Mapping.MapClick(deviceNum, Mapping.Click.Left);
- if (Global.GetDS4Action(deviceNum, DS4Controls.TouchMulti.ToString(), false) == null && multiDown)
+
+ if (Global.GetDS4Action(deviceNum, DS4Controls.TouchMulti, false) == null && multiDown)
Mapping.MapClick(deviceNum, Mapping.Click.Right);
+
if (!Global.UseTPforControls[deviceNum])
{
if (tappedOnce)
@@ -205,10 +452,10 @@ namespace DS4Windows
dragging = true;
}
else
+ {
dragging = false;
+ }
}
- s = remapped;
- //remapped.CopyTo(s);
}
public virtual void touchButtonUp(object sender, TouchpadEventArgs arg)
@@ -216,7 +463,7 @@ namespace DS4Windows
pushed = DS4Controls.None;
upperDown = leftDown = rightDown = multiDown = false;
dev.setRumble(0, 0);
- dev.getCurrentState(s);
+ s = dev.getCurrentStateRef();
if (s.Touch1 || s.Touch2)
synthesizeMouseButtons();
}
@@ -231,15 +478,30 @@ namespace DS4Windows
{
if ((Global.LowerRCOn[deviceNum] && arg.touches[0].hwX > (1920 * 3) / 4 && arg.touches[0].hwY > (960 * 3) / 4))
Mapping.MapClick(deviceNum, Mapping.Click.Right);
+
if (isLeft(arg.touches[0]))
leftDown = true;
else if (isRight(arg.touches[0]))
rightDown = true;
}
- dev.getCurrentState(s);
+
+ s = dev.getCurrentStateRef();
synthesizeMouseButtons();
}
+ public void populatePriorButtonStates()
+ {
+ priorUpperDown = upperDown;
+ priorLeftDown = leftDown;
+ priorRightDown = rightDown;
+ priorMultiDown = multiDown;
+
+ priorSwipeLeft = swipeLeft; priorSwipeRight = swipeRight;
+ priorSwipeUp = swipeUp; priorSwipeDown = swipeDown;
+ priorSwipeLeftB = swipeLeftB; priorSwipeRightB = swipeRightB; priorSwipeUpB = swipeUpB;
+ priorSwipeDownB = swipeDownB; priorSwipedB = swipedB;
+ }
+
public DS4State getDS4State()
{
return s;
diff --git a/DS4Windows/DS4Control/MouseCursor.cs b/DS4Windows/DS4Control/MouseCursor.cs
index 0a5870d..e437403 100644
--- a/DS4Windows/DS4Control/MouseCursor.cs
+++ b/DS4Windows/DS4Control/MouseCursor.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
namespace DS4Windows
{
@@ -20,32 +16,164 @@ namespace DS4Windows
/** Indicate x/y direction for doing jitter compensation, etc. */
public enum Direction { Negative, Neutral, Positive }
// Track direction vector separately and very trivially for now.
- private Direction horizontalDirection = Direction.Neutral, verticalDirection = Direction.Neutral;
+ private Direction horizontalDirection = Direction.Neutral,
+ verticalDirection = Direction.Neutral;
private Direction hDirection = Direction.Neutral, vDirection = Direction.Neutral;
+ private const double GYRO_MOUSE_COEFFICIENT = 0.0095;
+ private const int GYRO_MOUSE_DEADZONE = 10;
+ private const double GYRO_MOUSE_OFFSET = 0.1463;
+ private const double GYRO_SMOOTH_MOUSE_OFFSET = 0.14698;
+ private const double TOUCHPAD_MOUSE_OFFSET = 0.015;
+
+ private const int SMOOTH_BUFFER_LEN = 3;
+ private double[] xSmoothBuffer = new double[SMOOTH_BUFFER_LEN];
+ private double[] ySmoothBuffer = new double[SMOOTH_BUFFER_LEN];
+ private int smoothBufferTail = 0;
+
+
+
+ double coefficient = 0.0;
+ double verticalScale = 0.0;
+ bool gyroSmooth = false;
+
+ int tempInt = 0;
+ double tempDouble = 0.0;
+ bool tempBool = false;
+
public virtual void sixaxisMoved(SixAxisEventArgs arg)
{
int deltaX = 0, deltaY = 0;
- deltaX = -arg.sixAxis.accelX;
- deltaY = -arg.sixAxis.accelY;
- //Console.WriteLine(arg.sixAxis.deltaX);
+ deltaX = Global.getGyroMouseHorizontalAxis(deviceNumber) == 0 ? arg.sixAxis.gyroYawFull :
+ arg.sixAxis.gyroRollFull;
+ deltaY = -arg.sixAxis.gyroPitchFull;
+ //tempDouble = arg.sixAxis.elapsed * 0.001 * 200.0; // Base default speed on 5 ms
+ tempDouble = arg.sixAxis.elapsed * 200.0; // Base default speed on 5 ms
- double coefficient = Global.GyroSensitivity[deviceNumber] / 100f;
- //Collect rounding errors instead of losing motion.
- double xMotion = coefficient * deltaX;
- xMotion += hRemainder;
- int xAction = (int)xMotion;
- hRemainder += xMotion - xAction;
- hRemainder -= (int)hRemainder;
- double yMotion = coefficient * deltaY;
- yMotion += vRemainder;
- int yAction = (int)yMotion;
- vRemainder += yMotion - yAction;
- vRemainder -= (int)vRemainder;
- if (Global.GyroInvert[deviceNumber] == 2 || Global.GyroInvert[deviceNumber] == 3)
+ gyroSmooth = Global.getGyroSmoothing(deviceNumber);
+ double gyroSmoothWeight = 0.0;
+
+ coefficient = (Global.getGyroSensitivity(deviceNumber) * 0.01) * GYRO_MOUSE_COEFFICIENT;
+ double offset = GYRO_MOUSE_OFFSET;
+ if (gyroSmooth)
+ {
+ gyroSmoothWeight = Global.getGyroSmoothingWeight(deviceNumber);
+ if (gyroSmoothWeight > 0.0)
+ {
+ offset = GYRO_SMOOTH_MOUSE_OFFSET;
+ }
+ }
+
+ double tempAngle = Math.Atan2(-deltaY, deltaX);
+ double normX = Math.Abs(Math.Cos(tempAngle));
+ double normY = Math.Abs(Math.Sin(tempAngle));
+ int signX = Math.Sign(deltaX);
+ int signY = Math.Sign(deltaY);
+
+ if (deltaX == 0 || (hRemainder > 0 != deltaX > 0))
+ {
+ hRemainder = 0.0;
+ }
+
+ if (deltaY == 0 || (vRemainder > 0 != deltaY > 0))
+ {
+ vRemainder = 0.0;
+ }
+
+ int deadzoneX = (int)Math.Abs(normX * GYRO_MOUSE_DEADZONE);
+ int deadzoneY = (int)Math.Abs(normY * GYRO_MOUSE_DEADZONE);
+
+ if (Math.Abs(deltaX) > deadzoneX)
+ {
+ deltaX -= signX * deadzoneX;
+ }
+ else
+ {
+ deltaX = 0;
+ }
+
+ if (Math.Abs(deltaY) > deadzoneY)
+ {
+ deltaY -= signY * deadzoneY;
+ }
+ else
+ {
+ deltaY = 0;
+ }
+
+ double xMotion = deltaX != 0 ? coefficient * (deltaX * tempDouble)
+ + (normX * (offset * signX)) : 0;
+
+ int xAction = 0;
+ if (xMotion != 0.0)
+ {
+ xMotion += hRemainder;
+ }
+ else
+ {
+ hRemainder = 0.0;
+ }
+
+ verticalScale = Global.getGyroSensVerticalScale(deviceNumber) * 0.01;
+ double yMotion = deltaY != 0 ? (coefficient * verticalScale) * (deltaY * tempDouble)
+ + (normY * (offset * signY)) : 0;
+
+ int yAction = 0;
+ if (yMotion != 0.0)
+ {
+ yMotion += vRemainder;
+ }
+ else
+ {
+ vRemainder = 0.0;
+ }
+
+ if (gyroSmooth)
+ {
+ int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN;
+ xSmoothBuffer[iIndex] = xMotion;
+ ySmoothBuffer[iIndex] = yMotion;
+ smoothBufferTail = iIndex + 1;
+
+ double currentWeight = 1.0;
+ double finalWeight = 0.0;
+ double x_out = 0.0, y_out = 0.0;
+ int idx = 0;
+ for (int i = 0; i < SMOOTH_BUFFER_LEN; i++)
+ {
+ idx = (smoothBufferTail - i - 1 + SMOOTH_BUFFER_LEN) % SMOOTH_BUFFER_LEN;
+ x_out += xSmoothBuffer[idx] * currentWeight;
+ y_out += ySmoothBuffer[idx] * currentWeight;
+ finalWeight += currentWeight;
+ currentWeight *= gyroSmoothWeight;
+ }
+
+ x_out /= finalWeight;
+ xMotion = x_out;
+ y_out /= finalWeight;
+ yMotion = y_out;
+ }
+
+ hRemainder = vRemainder = 0.0;
+ if (xMotion != 0.0)
+ {
+ xAction = (int)xMotion;
+ hRemainder = xMotion - xAction;
+ }
+
+ if (yMotion != 0.0)
+ {
+ yAction = (int)yMotion;
+ vRemainder = yMotion - yAction;
+ }
+
+ int gyroInvert = Global.getGyroInvert(deviceNumber);
+ if ((gyroInvert & 0x02) == 2)
xAction *= -1;
- if (Global.GyroInvert[deviceNumber] == 1 || Global.GyroInvert[deviceNumber] == 3)
+
+ if ((gyroInvert & 0x01) == 1)
yAction *= -1;
+
if (yAction != 0 || xAction != 0)
InputMethods.MoveCursorBy(xAction, yAction);
@@ -53,21 +181,33 @@ namespace DS4Windows
vDirection = yMotion > 0.0 ? Direction.Positive : yMotion < 0.0 ? Direction.Negative : Direction.Neutral;
}
+ public void mouseRemainderReset()
+ {
+ hRemainder = vRemainder = 0.0;
+ int iIndex = smoothBufferTail % SMOOTH_BUFFER_LEN;
+ xSmoothBuffer[iIndex] = 0.0;
+ ySmoothBuffer[iIndex] = 0.0;
+ smoothBufferTail = iIndex + 1;
+ }
+
public void touchesBegan(TouchpadEventArgs arg)
{
if (arg.touches.Length == 1)
{
horizontalRemainder = verticalRemainder = 0.0;
horizontalDirection = verticalDirection = Direction.Neutral;
+
}
}
private byte lastTouchID;
- public void touchesMoved(TouchpadEventArgs arg, bool dragging)
+ public void touchesMoved(TouchpadEventArgs arg, bool dragging, bool disableInvert = false)
{
- if ((!dragging && arg.touches.Length != 1) || (dragging && arg.touches.Length < 1))
+ int touchesLen = arg.touches.Length;
+ if ((!dragging && touchesLen != 1) || (dragging && touchesLen < 1))
return;
- int deltaX, deltaY;
+
+ int deltaX = 0, deltaY = 0;
if (arg.touches[0].touchID != lastTouchID)
{
deltaX = deltaY = 0;
@@ -75,59 +215,9 @@ namespace DS4Windows
horizontalDirection = verticalDirection = Direction.Neutral;
lastTouchID = arg.touches[0].touchID;
}
- else if (Global.TouchpadJitterCompensation[deviceNumber])
- {
- // Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter...
-
- if (dragging && arg.touches.Length > 1)
- {
- deltaX = arg.touches[1].deltaX;
- deltaY = arg.touches[1].deltaY;
- }
- else
- {
- deltaX = arg.touches[0].deltaX;
- deltaY = arg.touches[0].deltaY;
- }
- // allow only very fine, slow motions, when changing direction, even from neutral
- // TODO maybe just consume it completely?
- if (deltaX <= -1)
- {
- if (horizontalDirection != Direction.Negative)
- {
- deltaX = -1;
- horizontalRemainder = 0.0;
- }
- }
- else if (deltaX >= 1)
- {
- if (horizontalDirection != Direction.Positive)
- {
- deltaX = 1;
- horizontalRemainder = 0.0;
- }
- }
-
- if (deltaY <= -1)
- {
- if (verticalDirection != Direction.Negative)
- {
- deltaY = -1;
- verticalRemainder = 0.0;
- }
- }
- else if (deltaY >= 1)
- {
- if (verticalDirection != Direction.Positive)
- {
- deltaY = 1;
- verticalRemainder = 0.0;
- }
- }
- }
else
{
- if (dragging && arg.touches.Length > 1)
+ if (dragging && touchesLen > 1)
{
deltaX = arg.touches[1].deltaX;
deltaY = arg.touches[1].deltaY;
@@ -139,36 +229,73 @@ namespace DS4Windows
}
}
- double coefficient = Global.TouchSensitivity[deviceNumber] / 100.0;
- // Collect rounding errors instead of losing motion.
- double xMotion = coefficient * deltaX;
- if (xMotion > 0.0)
+ TouchMoveCursor(deltaX, deltaY, disableInvert);
+ }
+
+ public void TouchMoveCursor(int dx, int dy, bool disableInvert = false)
+ {
+ double tempAngle = Math.Atan2(-dy, dx);
+ double normX = Math.Abs(Math.Cos(tempAngle));
+ double normY = Math.Abs(Math.Sin(tempAngle));
+ int signX = Math.Sign(dx);
+ int signY = Math.Sign(dy);
+ double coefficient = Global.getTouchSensitivity(deviceNumber) * 0.01;
+ bool jitterCompenstation = Global.getTouchpadJitterCompensation(deviceNumber);
+
+ double xMotion = dx != 0 ?
+ coefficient * dx + (normX * (TOUCHPAD_MOUSE_OFFSET * signX)) : 0.0;
+
+ double yMotion = dy != 0 ?
+ coefficient * dy + (normY * (TOUCHPAD_MOUSE_OFFSET * signY)) : 0.0;
+
+ if (jitterCompenstation)
{
- if (horizontalRemainder > 0.0)
- xMotion += horizontalRemainder;
+ double absX = Math.Abs(xMotion);
+ if (absX <= normX * 0.15)
+ {
+ xMotion = signX * Math.Pow(absX / 0.15f, 1.408) * 0.15;
+ }
+
+ double absY = Math.Abs(yMotion);
+ if (absY <= normY * 0.15)
+ {
+ yMotion = signY * Math.Pow(absY / 0.15f, 1.408) * 0.15;
+ }
}
- else if (xMotion < 0.0)
+
+ // Collect rounding errors instead of losing motion.
+ if (xMotion > 0.0 && horizontalRemainder > 0.0)
{
- if (horizontalRemainder < 0.0)
- xMotion += horizontalRemainder;
+ xMotion += horizontalRemainder;
+ }
+ else if (xMotion < 0.0 && horizontalRemainder < 0.0)
+ {
+ xMotion += horizontalRemainder;
}
int xAction = (int)xMotion;
horizontalRemainder = xMotion - xAction;
- double yMotion = coefficient * deltaY;
- if (yMotion > 0.0)
+ if (yMotion > 0.0 && verticalRemainder > 0.0)
{
- if (verticalRemainder > 0.0)
- yMotion += verticalRemainder;
+ yMotion += verticalRemainder;
}
- else if (yMotion < 0.0)
+ else if (yMotion < 0.0 && verticalRemainder < 0.0)
{
- if (verticalRemainder < 0.0)
- yMotion += verticalRemainder;
+ yMotion += verticalRemainder;
}
int yAction = (int)yMotion;
verticalRemainder = yMotion - yAction;
+ if (disableInvert == false)
+ {
+ int touchpadInvert = tempInt = Global.getTouchpadInvert(deviceNumber);
+ if ((touchpadInvert & 0x02) == 2)
+ xAction *= -1;
+
+ if ((touchpadInvert & 0x01) == 1)
+ yAction *= -1;
+ }
+
if (yAction != 0 || xAction != 0)
InputMethods.MoveCursorBy(xAction, yAction);
diff --git a/DS4Windows/DS4Control/MouseWheel.cs b/DS4Windows/DS4Control/MouseWheel.cs
index d237731..e17ba13 100644
--- a/DS4Windows/DS4Control/MouseWheel.cs
+++ b/DS4Windows/DS4Control/MouseWheel.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
namespace DS4Windows
{
@@ -27,6 +23,7 @@ namespace DS4Windows
{
if (arg.touches.Length != 2 || dragging)
return;
+
Touch lastT0 = arg.touches[0].previousTouch;
Touch lastT1 = arg.touches[1].previousTouch;
Touch T0 = arg.touches[0];
diff --git a/DS4Windows/DS4Control/ScpDevice.cs b/DS4Windows/DS4Control/ScpDevice.cs
index ae27617..8055616 100644
--- a/DS4Windows/DS4Control/ScpDevice.cs
+++ b/DS4Windows/DS4Control/ScpDevice.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Windows.Forms;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
@@ -522,7 +521,7 @@ namespace DS4Windows
protected virtual Boolean GetDeviceHandle(String Path)
{
- m_FileHandle = CreateFile(Path, (GENERIC_WRITE | GENERIC_READ), FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0);
+ m_FileHandle = CreateFile(Path, (GENERIC_WRITE | GENERIC_READ), FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED | 0x20000000 | 0x80000000, 0);
return !m_FileHandle.IsInvalid;
}
diff --git a/DS4Windows/DS4Control/ScpUtil.cs b/DS4Windows/DS4Control/ScpUtil.cs
index 2b23fcb..91d917e 100644
--- a/DS4Windows/DS4Control/ScpUtil.cs
+++ b/DS4Windows/DS4Control/ScpUtil.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Text;
+using System.Linq;
using System.IO;
using System.Reflection;
@@ -8,10 +8,14 @@ using System.Xml;
using System.Drawing;
using System.Security.Principal;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Globalization;
+
namespace DS4Windows
{
[Flags]
- public enum DS4KeyType : byte { None = 0, ScanCode = 1, Toggle = 2, Unbound = 4, Macro = 8, HoldMacro = 16, RepeatMacro = 32 }; //Increment by exponents of 2*, starting at 2^0
+ public enum DS4KeyType : byte { None = 0, ScanCode = 1, Toggle = 2, Unbound = 4, Macro = 8, HoldMacro = 16, RepeatMacro = 32 }; // Increment by exponents of 2*, starting at 2^0
public enum Ds3PadId : byte { None = 0xFF, One = 0x00, Two = 0x01, Three = 0x02, Four = 0x03, All = 0x04 };
public enum DS4Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, L1, L2, L3, R1, R2, R3, Square, Triangle, Circle, Cross, DpadUp, DpadRight, DpadDown, DpadLeft, PS, TouchLeft, TouchUpper, TouchMulti, TouchRight, Share, Options, GyroXPos, GyroXNeg, GyroZPos, GyroZNeg, SwipeLeft, SwipeRight, SwipeUp, SwipeDown };
public enum X360Controls : byte { None, LXNeg, LXPos, LYNeg, LYPos, RXNeg, RXPos, RYNeg, RYPos, LB, LT, LS, RB, RT, RS, X, Y, B, A, DpadUp, DpadRight, DpadDown, DpadLeft, Guide, Back, Start, LeftMouse, RightMouse, MiddleMouse, FourthMouse, FifthMouse, WUP, WDOWN, MouseUp, MouseDown, MouseLeft, MouseRight, Unbound };
@@ -19,7 +23,7 @@ namespace DS4Windows
public class DS4ControlSettings
{
public DS4Controls control;
- public string extras = "0,0,0,0,0,0,0,0";
+ public string extras = null;
public DS4KeyType keyType = DS4KeyType.None;
public enum ActionType : byte { Default, Key, Button, Macro };
public ActionType actionType = ActionType.Default;
@@ -27,7 +31,7 @@ namespace DS4Windows
public ActionType shiftActionType = ActionType.Default;
public object shiftAction = null;
public int shiftTrigger = 0;
- public string shiftExtras = "0,0,0,0,0,0,0,0";
+ public string shiftExtras = null;
public DS4KeyType shiftKeyType = DS4KeyType.None;
public DS4ControlSettings(DS4Controls ctrl)
@@ -37,17 +41,17 @@ namespace DS4Windows
public void Reset()
{
- extras = "0,0,0,0,0,0,0,0";
+ extras = null;
keyType = DS4KeyType.None;
actionType = ActionType.Default;
action = null;
shiftActionType = ActionType.Default;
shiftAction = null;
shiftTrigger = 0;
- shiftExtras = "0,0,0,0,0,0,0,0";
+ shiftExtras = null;
shiftKeyType = DS4KeyType.None;
}
-
+
internal void UpdateSettings(bool shift, object act, string exts, DS4KeyType kt, int trigger = 0)
{
if (!shift)
@@ -60,6 +64,7 @@ namespace DS4Windows
actionType = ActionType.Macro;
else
actionType = ActionType.Default;
+
action = act;
extras = exts;
keyType = kt;
@@ -74,6 +79,7 @@ namespace DS4Windows
shiftActionType = ActionType.Macro;
else
shiftActionType = ActionType.Default;
+
shiftAction = act;
shiftExtras = exts;
shiftKeyType = kt;
@@ -85,16 +91,16 @@ namespace DS4Windows
public class DebugEventArgs : EventArgs
{
protected DateTime m_Time = DateTime.Now;
- protected String m_Data = String.Empty;
+ protected string m_Data = string.Empty;
protected bool warning = false;
- public DebugEventArgs(String Data, bool warn)
+ public DebugEventArgs(string Data, bool warn)
{
m_Data = Data;
warning = warn;
}
public DateTime Time => m_Time;
- public String Data => m_Data;
+ public string Data => m_Data;
public bool Warning => warning;
}
@@ -113,7 +119,7 @@ namespace DS4Windows
public class ReportEventArgs : EventArgs
{
protected Ds3PadId m_Pad = Ds3PadId.None;
- protected Byte[] m_Report = new Byte[64];
+ protected byte[] m_Report = new byte[64];
public ReportEventArgs()
{
@@ -136,20 +142,138 @@ namespace DS4Windows
}
}
+ public class BatteryReportArgs : EventArgs
+ {
+ private int index;
+ private int level;
+ private bool charging;
+
+ public BatteryReportArgs(int index, int level, bool charging)
+ {
+ this.index = index;
+ this.level = level;
+ this.charging = charging;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public int getLevel()
+ {
+ return level;
+ }
+
+ public bool isCharging()
+ {
+ return charging;
+ }
+ }
+
+ public class ControllerRemovedArgs : EventArgs
+ {
+ private int index;
+
+ public ControllerRemovedArgs(int index)
+ {
+ this.index = index;
+ }
+
+ public int getIndex()
+ {
+ return this.index;
+ }
+ }
+
+ public class DeviceStatusChangeEventArgs : EventArgs
+ {
+ private int index;
+
+ public DeviceStatusChangeEventArgs(int index)
+ {
+ this.index = index;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+ }
+
+ public class SerialChangeArgs : EventArgs
+ {
+ private int index;
+ private string serial;
+
+ public SerialChangeArgs(int index, string serial)
+ {
+ this.index = index;
+ this.serial = serial;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public string getSerial()
+ {
+ return serial;
+ }
+ }
+
public class Global
{
protected static BackingStore m_Config = new BackingStore();
protected static Int32 m_IdleTimeout = 600000;
- static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName;
+ public static string exepath = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName;
public static string appdatapath;
+ public static bool firstRun = false;
+ public static bool multisavespots = false;
+ public static bool oldappdatafail = false;
+ public static string appDataPpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows";
+ public static string oldappdatapath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool";
+ public static bool runHotPlug = false;
+ public const int XINPUT_UNPLUG_SETTLE_TIME = 250; // Inhibit races that occur with the asynchronous teardown of ScpVBus -> X360 driver instance.
public static string[] tempprofilename = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
+ public static bool[] tempprofileDistance = new bool[5] { false, false, false, false, false };
+ public static bool[] useDInputOnly = new bool[5] { true, true, true, true, true };
+ public static bool[] linkedProfileCheck = new bool[4] { true, true, true, true };
+
+ public static X360Controls[] defaultButtonMapping = { X360Controls.None, X360Controls.LXNeg, X360Controls.LXPos,
+ X360Controls.LYNeg, X360Controls.LYPos, X360Controls.RXNeg, X360Controls.RXPos, X360Controls.RYNeg, X360Controls.RYPos,
+ X360Controls.LB, X360Controls.LT, X360Controls.LS, X360Controls.RB, X360Controls.RT, X360Controls.RS, X360Controls.X,
+ X360Controls.Y, X360Controls.B, X360Controls.A, X360Controls.DpadUp, X360Controls.DpadRight, X360Controls.DpadDown,
+ X360Controls.DpadLeft, X360Controls.Guide, X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None,
+ X360Controls.Back, X360Controls.Start, X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None,
+ X360Controls.None, X360Controls.None, X360Controls.None, X360Controls.None
+ };
+
+ // Create mapping array at runtime
+ public static DS4Controls[] reverseX360ButtonMapping = new Func(() =>
+ {
+ DS4Controls[] temp = new DS4Controls[defaultButtonMapping.Length];
+ for (int i = 0, arlen = defaultButtonMapping.Length; i < arlen; i++)
+ {
+ X360Controls mapping = defaultButtonMapping[i];
+ if (mapping != X360Controls.None)
+ {
+ temp[(int)mapping] = (DS4Controls)i;
+ }
+ }
+
+ return temp;
+ })();
public static void SaveWhere(string path)
{
appdatapath = path;
m_Config.m_Profile = appdatapath + "\\Profiles.xml";
m_Config.m_Actions = appdatapath + "\\Actions.xml";
+ m_Config.m_linkedProfiles = Global.appdatapath + "\\LinkedProfiles.xml";
}
+
///
/// Check if Admin Rights are needed to write in Appliplation Directory
///
@@ -175,6 +299,83 @@ namespace DS4Windows
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
+ public static bool IsScpVBusInstalled()
+ {
+ bool result = false;
+ Guid sysGuid = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}");
+ NativeMethods.SP_DEVINFO_DATA deviceInfoData = new NativeMethods.SP_DEVINFO_DATA();
+ deviceInfoData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData);
+ var dataBuffer = new byte[4096];
+ ulong propertyType = 0;
+ var requiredSize = 0;
+ IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref sysGuid, null, 0, 0);
+ for (int i = 0; !result && NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, i, ref deviceInfoData); i++)
+ {
+ if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref NativeMethods.DEVPKEY_Device_HardwareIds, ref propertyType,
+ dataBuffer, dataBuffer.Length, ref requiredSize, 0))
+ {
+ string hardwareId = dataBuffer.ToUTF16String();
+ //if (hardwareIds.Contains("Scp Virtual Bus Driver"))
+ // result = true;
+ if (hardwareId.Equals(@"root\ScpVBus"))
+ result = true;
+ }
+ }
+
+ if (deviceInfoSet.ToInt64() != NativeMethods.INVALID_HANDLE_VALUE)
+ {
+ NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
+ }
+
+ return result;
+ }
+
+ public static void FindConfigLocation()
+ {
+ if (File.Exists(exepath + "\\Auto Profiles.xml")
+ && File.Exists(appDataPpath + "\\Auto Profiles.xml"))
+ {
+ Global.firstRun = true;
+ Global.multisavespots = true;
+ }
+ else if (File.Exists(exepath + "\\Auto Profiles.xml"))
+ SaveWhere(exepath);
+ else if (File.Exists(appDataPpath + "\\Auto Profiles.xml"))
+ SaveWhere(appDataPpath);
+ else if (File.Exists(oldappdatapath + "\\Auto Profiles.xml"))
+ {
+ try
+ {
+ if (Directory.Exists(appDataPpath))
+ Directory.Move(appDataPpath, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Windows Old");
+ Directory.Move(oldappdatapath, appDataPpath);
+ SaveWhere(appDataPpath);
+ }
+ catch
+ {
+ Global.oldappdatafail = true;
+ }
+ }
+ else if (!File.Exists(exepath + "\\Auto Profiles.xml")
+ && !File.Exists(appDataPpath + "\\Auto Profiles.xml"))
+ {
+ Global.firstRun = true;
+ Global.multisavespots = false;
+ }
+ }
+
+ public static void SetCulture(string culture)
+ {
+ try
+ {
+ Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture);
+ CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo(culture);
+ }
+ catch { /* Skip setting culture that we cannot set */ }
+ }
+
+
+
public static event EventHandler ControllerStatusChange; // called when a controller is added/removed/battery or touchpad mode changes/etc.
public static void ControllerStatusChanged(object sender)
{
@@ -182,13 +383,58 @@ namespace DS4Windows
ControllerStatusChange(sender, EventArgs.Empty);
}
- //general values
+ public static event EventHandler BatteryStatusChange;
+ public static void OnBatteryStatusChange(object sender, int index, int level, bool charging)
+ {
+ if (BatteryStatusChange != null)
+ {
+ BatteryReportArgs args = new BatteryReportArgs(index, level, charging);
+ BatteryStatusChange(sender, args);
+ }
+ }
+
+ public static event EventHandler ControllerRemoved;
+ public static void OnControllerRemoved(object sender, int index)
+ {
+ if (ControllerRemoved != null)
+ {
+ ControllerRemovedArgs args = new ControllerRemovedArgs(index);
+ ControllerRemoved(sender, args);
+ }
+ }
+
+ public static event EventHandler DeviceStatusChange;
+ public static void OnDeviceStatusChanged(object sender, int index)
+ {
+ if (DeviceStatusChange != null)
+ {
+ DeviceStatusChangeEventArgs args = new DeviceStatusChangeEventArgs(index);
+ DeviceStatusChange(sender, args);
+ }
+ }
+
+ public static event EventHandler DeviceSerialChange;
+ public static void OnDeviceSerialChange(object sender, int index, string serial)
+ {
+ if (DeviceSerialChange != null)
+ {
+ SerialChangeArgs args = new SerialChangeArgs(index, serial);
+ DeviceSerialChange(sender, args);
+ }
+ }
+
+ // general values
public static bool UseExclusiveMode
{
set { m_Config.useExclusiveMode = value; }
get { return m_Config.useExclusiveMode; }
}
+ public static bool getUseExclusiveMode()
+ {
+ return m_Config.useExclusiveMode;
+ }
+
public static DateTime LastChecked
{
set { m_Config.lastChecked = value; }
@@ -200,146 +446,630 @@ namespace DS4Windows
set { m_Config.CheckWhen = value; }
get { return m_Config.CheckWhen; }
}
+
public static int Notifications
{
set { m_Config.notifications = value; }
get { return m_Config.notifications; }
}
+
public static bool DCBTatStop
{
set { m_Config.disconnectBTAtStop = value; }
get { return m_Config.disconnectBTAtStop; }
}
+
public static bool SwipeProfiles
{
set { m_Config.swipeProfiles = value; }
get { return m_Config.swipeProfiles; }
}
+
public static bool DS4Mapping
{
set { m_Config.ds4Mapping = value; }
get { return m_Config.ds4Mapping; }
}
+
public static bool QuickCharge
{
set { m_Config.quickCharge = value; }
get { return m_Config.quickCharge; }
}
+
+ public static bool getQuickCharge()
+ {
+ return m_Config.quickCharge;
+ }
+
public static int FirstXinputPort
{
set { m_Config.firstXinputPort = value; }
get { return m_Config.firstXinputPort; }
}
+
public static bool CloseMini
{
set { m_Config.closeMini = value; }
get { return m_Config.closeMini; }
}
+
public static bool StartMinimized
{
set { m_Config.startMinimized = value; }
get { return m_Config.startMinimized; }
}
+
+ public static bool MinToTaskbar
+ {
+ set { m_Config.minToTaskbar = value; }
+ get { return m_Config.minToTaskbar; }
+ }
+
public static int FormWidth
{
set { m_Config.formWidth = value; }
- get { return m_Config.formWidth;}
+ get { return m_Config.formWidth; }
}
+
public static int FormHeight
{
set { m_Config.formHeight = value; }
get { return m_Config.formHeight; }
}
+
+ public static int FormLocationX
+ {
+ set { m_Config.formLocationX = value; }
+ get { return m_Config.formLocationX; }
+ }
+
+ public static int FormLocationY
+ {
+ set { m_Config.formLocationY = value; }
+ get { return m_Config.formLocationY; }
+ }
+
+ public static string UseLang
+ {
+ set { m_Config.useLang = value; }
+ get { return m_Config.useLang; }
+ }
+
public static bool DownloadLang
{
set { m_Config.downloadLang = value; }
get { return m_Config.downloadLang; }
}
+
public static bool FlashWhenLate
{
set { m_Config.flashWhenLate = value; }
get { return m_Config.flashWhenLate; }
}
+
+ public static bool getFlashWhenLate()
+ {
+ return m_Config.flashWhenLate;
+ }
+
public static int FlashWhenLateAt
{
set { m_Config.flashWhenLateAt = value; }
get { return m_Config.flashWhenLateAt; }
}
+
+ public static int getFlashWhenLateAt()
+ {
+ return m_Config.flashWhenLateAt;
+ }
+
public static bool UseWhiteIcon
{
set { m_Config.useWhiteIcon = value; }
get { return m_Config.useWhiteIcon; }
}
- //controller/profile specfic values
+ // controller/profile specfic values
public static int[] ButtonMouseSensitivity => m_Config.buttonMouseSensitivity;
- public static byte[] RumbleBoost => m_Config.rumble;
+
+ public static byte[] RumbleBoost => m_Config.rumble;
+ public static byte getRumbleBoost(int index)
+ {
+ return m_Config.rumble[index];
+ }
+
public static double[] Rainbow => m_Config.rainbow;
+ public static double getRainbow(int index)
+ {
+ return m_Config.rainbow[index];
+ }
+
public static bool[] FlushHIDQueue => m_Config.flushHIDQueue;
- public static int[] IdleDisconnectTimeout => m_Config.idleDisconnectTimeout;
+ public static bool getFlushHIDQueue(int index)
+ {
+ return m_Config.flushHIDQueue[index];
+ }
+
+ public static bool[] EnableTouchToggle => m_Config.enableTouchToggle;
+ public static bool getEnableTouchToggle(int index)
+ {
+ return m_Config.enableTouchToggle[index];
+ }
+
+ public static int[] IdleDisconnectTimeout => m_Config.idleDisconnectTimeout;
+ public static int getIdleDisconnectTimeout(int index)
+ {
+ return m_Config.idleDisconnectTimeout[index];
+ }
+
public static byte[] TouchSensitivity => m_Config.touchSensitivity;
+ public static byte[] getTouchSensitivity()
+ {
+ return m_Config.touchSensitivity;
+ }
+
+ public static byte getTouchSensitivity(int index)
+ {
+ return m_Config.touchSensitivity[index];
+ }
+
public static byte[] FlashType => m_Config.flashType;
+ public static byte getFlashType(int index)
+ {
+ return m_Config.flashType[index];
+ }
+
public static int[] FlashAt => m_Config.flashAt;
+ public static int getFlashAt(int index)
+ {
+ return m_Config.flashAt[index];
+ }
+
public static bool[] LedAsBatteryIndicator => m_Config.ledAsBattery;
+ public static bool getLedAsBatteryIndicator(int index)
+ {
+ return m_Config.ledAsBattery[index];
+ }
+
public static int[] ChargingType => m_Config.chargingType;
- public static bool[] DinputOnly => m_Config.dinputOnly;
- public static bool[] StartTouchpadOff => m_Config.startTouchpadOff;
+ public static int getChargingType(int index)
+ {
+ return m_Config.chargingType[index];
+ }
+
+ public static bool[] DinputOnly => m_Config.dinputOnly;
+ public static bool getDInputOnly(int index)
+ {
+ return m_Config.dinputOnly[index];
+ }
+
+ public static bool[] StartTouchpadOff => m_Config.startTouchpadOff;
+
public static bool[] UseTPforControls => m_Config.useTPforControls;
+ public static bool getUseTPforControls(int index)
+ {
+ return m_Config.useTPforControls[index];
+ }
+
public static bool[] UseSAforMouse => m_Config.useSAforMouse;
+ public static bool isUsingSAforMouse(int index)
+ {
+ return m_Config.useSAforMouse[index];
+ }
+
public static string[] SATriggers => m_Config.sATriggers;
+ public static string getSATriggers(int index)
+ {
+ return m_Config.sATriggers[index];
+ }
+
+ public static int[][] TouchDisInvertTriggers => m_Config.touchDisInvertTriggers;
+ public static int[] getTouchDisInvertTriggers(int index)
+ {
+ return m_Config.touchDisInvertTriggers[index];
+ }
+
public static int[] GyroSensitivity => m_Config.gyroSensitivity;
+ public static int getGyroSensitivity(int index)
+ {
+ return m_Config.gyroSensitivity[index];
+ }
+
+ public static int[] GyroSensVerticalScale => m_Config.gyroSensVerticalScale;
+ public static int getGyroSensVerticalScale(int index)
+ {
+ return m_Config.gyroSensVerticalScale[index];
+ }
+
public static int[] GyroInvert => m_Config.gyroInvert;
- public static DS4Color[] MainColor => m_Config.m_Leds;
+ public static int getGyroInvert(int index)
+ {
+ return m_Config.gyroInvert[index];
+ }
+
+ public static bool[] GyroTriggerTurns => m_Config.gyroTriggerTurns;
+ public static bool getGyroTriggerTurns(int index)
+ {
+ return m_Config.gyroTriggerTurns[index];
+ }
+
+ public static bool[] GyroSmoothing => m_Config.gyroSmoothing;
+ public static bool getGyroSmoothing(int index)
+ {
+ return m_Config.gyroSmoothing[index];
+ }
+
+ public static double[] GyroSmoothingWeight => m_Config.gyroSmoothWeight;
+ public static double getGyroSmoothingWeight(int index)
+ {
+ return m_Config.gyroSmoothWeight[index];
+ }
+
+ public static int[] GyroMouseHorizontalAxis => m_Config.gyroMouseHorizontalAxis;
+ public static int getGyroMouseHorizontalAxis(int index)
+ {
+ return m_Config.gyroMouseHorizontalAxis[index];
+ }
+
+ public static DS4Color[] MainColor => m_Config.m_Leds;
+ public static DS4Color getMainColor(int index)
+ {
+ return m_Config.m_Leds[index];
+ }
+
public static DS4Color[] LowColor => m_Config.m_LowLeds;
+ public static DS4Color getLowColor(int index)
+ {
+ return m_Config.m_LowLeds[index];
+ }
+
public static DS4Color[] ChargingColor => m_Config.m_ChargingLeds;
+ public static DS4Color getChargingColor(int index)
+ {
+ return m_Config.m_ChargingLeds[index];
+ }
+
public static DS4Color[] CustomColor => m_Config.m_CustomLeds;
+ public static DS4Color getCustomColor(int index)
+ {
+ return m_Config.m_CustomLeds[index];
+ }
+
public static bool[] UseCustomLed => m_Config.useCustomLeds;
+ public static bool getUseCustomLed(int index)
+ {
+ return m_Config.useCustomLeds[index];
+ }
+
+ public static DS4Color[] FlashColor => m_Config.m_FlashLeds;
+ public static DS4Color getFlashColor(int index)
+ {
+ return m_Config.m_FlashLeds[index];
+ }
- public static DS4Color[] FlashColor => m_Config.m_FlashLeds;
public static byte[] TapSensitivity => m_Config.tapSensitivity;
- public static bool[] DoubleTap => m_Config.doubleTap;
- public static int[] ScrollSensitivity => m_Config.scrollSensitivity;
- public static bool[] LowerRCOn => m_Config.lowerRCOn;
- public static bool[] TouchpadJitterCompensation => m_Config.touchpadJitterCompensation;
+ public static byte getTapSensitivity(int index)
+ {
+ return m_Config.tapSensitivity[index];
+ }
+
+ public static bool[] DoubleTap => m_Config.doubleTap;
+ public static bool getDoubleTap(int index)
+ {
+ return m_Config.doubleTap[index];
+ }
+
+ public static int[] ScrollSensitivity => m_Config.scrollSensitivity;
+ public static int[] getScrollSensitivity()
+ {
+ return m_Config.scrollSensitivity;
+ }
+ public static int getScrollSensitivity(int index)
+ {
+ return m_Config.scrollSensitivity[index];
+ }
+
+ public static bool[] LowerRCOn => m_Config.lowerRCOn;
+ public static bool[] TouchpadJitterCompensation => m_Config.touchpadJitterCompensation;
+ public static bool getTouchpadJitterCompensation(int index)
+ {
+ return m_Config.touchpadJitterCompensation[index];
+ }
+
+ public static int[] TouchpadInvert => m_Config.touchpadInvert;
+ public static int getTouchpadInvert(int index)
+ {
+ return m_Config.touchpadInvert[index];
+ }
+
+ public static byte[] L2Deadzone => m_Config.l2Deadzone;
+ public static byte getL2Deadzone(int index)
+ {
+ return m_Config.l2Deadzone[index];
+ }
- public static byte[] L2Deadzone => m_Config.l2Deadzone;
public static byte[] R2Deadzone => m_Config.r2Deadzone;
+ public static byte getR2Deadzone(int index)
+ {
+ return m_Config.r2Deadzone[index];
+ }
+
public static double[] SXDeadzone => m_Config.SXDeadzone;
+ public static double getSXDeadzone(int index)
+ {
+ return m_Config.SXDeadzone[index];
+ }
+
public static double[] SZDeadzone => m_Config.SZDeadzone;
+ public static double getSZDeadzone(int index)
+ {
+ return m_Config.SZDeadzone[index];
+ }
+
public static int[] LSDeadzone => m_Config.LSDeadzone;
+ public static int getLSDeadzone(int index)
+ {
+ return m_Config.LSDeadzone[index];
+ }
+
public static int[] RSDeadzone => m_Config.RSDeadzone;
+ public static int getRSDeadzone(int index)
+ {
+ return m_Config.RSDeadzone[index];
+ }
+
+ public static int[] LSAntiDeadzone => m_Config.LSAntiDeadzone;
+ public static int getLSAntiDeadzone(int index)
+ {
+ return m_Config.LSAntiDeadzone[index];
+ }
+
+ public static int[] RSAntiDeadzone => m_Config.RSAntiDeadzone;
+ public static int getRSAntiDeadzone(int index)
+ {
+ return m_Config.RSAntiDeadzone[index];
+ }
+
+ public static double[] SXAntiDeadzone => m_Config.SXAntiDeadzone;
+ public static double getSXAntiDeadzone(int index)
+ {
+ return m_Config.SXAntiDeadzone[index];
+ }
+
+ public static double[] SZAntiDeadzone => m_Config.SZAntiDeadzone;
+ public static double getSZAntiDeadzone(int index)
+ {
+ return m_Config.SZAntiDeadzone[index];
+ }
+
+ public static int[] LSMaxzone => m_Config.LSMaxzone;
+ public static int getLSMaxzone(int index)
+ {
+ return m_Config.LSMaxzone[index];
+ }
+
+ public static int[] RSMaxzone => m_Config.RSMaxzone;
+ public static int getRSMaxzone(int index)
+ {
+ return m_Config.RSMaxzone[index];
+ }
+
+ public static double[] SXMaxzone => m_Config.SXMaxzone;
+ public static double getSXMaxzone(int index)
+ {
+ return m_Config.SXMaxzone[index];
+ }
+
+ public static double[] SZMaxzone => m_Config.SZMaxzone;
+ public static double getSZMaxzone(int index)
+ {
+ return m_Config.SZMaxzone[index];
+ }
+
+ public static int[] L2AntiDeadzone => m_Config.l2AntiDeadzone;
+ public static int getL2AntiDeadzone(int index)
+ {
+ return m_Config.l2AntiDeadzone[index];
+ }
+
+ public static int[] R2AntiDeadzone => m_Config.r2AntiDeadzone;
+ public static int getR2AntiDeadzone(int index)
+ {
+ return m_Config.r2AntiDeadzone[index];
+ }
+
+ public static int[] L2Maxzone => m_Config.l2Maxzone;
+ public static int getL2Maxzone(int index)
+ {
+ return m_Config.l2Maxzone[index];
+ }
+
+ public static int[] R2Maxzone => m_Config.r2Maxzone;
+ public static int getR2Maxzone(int index)
+ {
+ return m_Config.r2Maxzone[index];
+ }
+
public static int[] LSCurve => m_Config.lsCurve;
+ public static int getLSCurve(int index)
+ {
+ return m_Config.lsCurve[index];
+ }
+
public static int[] RSCurve => m_Config.rsCurve;
+ public static int getRSCurve(int index)
+ {
+ return m_Config.rsCurve[index];
+ }
+
+ public static double[] LSRotation => m_Config.LSRotation;
+ public static double getLSRotation(int index)
+ {
+ return m_Config.LSRotation[index];
+ }
+
+ public static double[] RSRotation => m_Config.RSRotation;
+ public static double getRSRotation(int index)
+ {
+ return m_Config.RSRotation[index];
+ }
+
public static double[] L2Sens => m_Config.l2Sens;
+ public static double getL2Sens(int index)
+ {
+ return m_Config.l2Sens[index];
+ }
+
public static double[] R2Sens => m_Config.r2Sens;
+ public static double getR2Sens(int index)
+ {
+ return m_Config.r2Sens[index];
+ }
+
public static double[] SXSens => m_Config.SXSens;
+ public static double getSXSens(int index)
+ {
+ return m_Config.SXSens[index];
+ }
+
public static double[] SZSens => m_Config.SZSens;
+ public static double getSZSens(int index)
+ {
+ return m_Config.SZSens[index];
+ }
+
public static double[] LSSens => m_Config.LSSens;
+ public static double getLSSens(int index)
+ {
+ return m_Config.LSSens[index];
+ }
+
public static double[] RSSens => m_Config.RSSens;
+ public static double getRSSens(int index)
+ {
+ return m_Config.RSSens[index];
+ }
+
public static bool[] MouseAccel => m_Config.mouseAccel;
+ public static bool getMouseAccel(int device)
+ {
+ return m_Config.mouseAccel[device];
+ }
+
+ public static int[] BTPollRate => m_Config.btPollRate;
+ public static int getBTPollRate(int index)
+ {
+ return m_Config.btPollRate[index];
+ }
+
+ public static int[] lsOutCurveMode => m_Config.lsOutCurveMode;
+ public static int getLsOutCurveMode(int index)
+ {
+ return m_Config.lsOutCurveMode[index];
+ }
+
+ public static int[] rsOutCurveMode => m_Config.rsOutCurveMode;
+ public static int getRsOutCurveMode(int index)
+ {
+ return m_Config.rsOutCurveMode[index];
+ }
+
+ public static int[] l2OutCurveMode => m_Config.l2OutCurveMode;
+ public static int getL2OutCurveMode(int index)
+ {
+ return m_Config.l2OutCurveMode[index];
+ }
+
+ public static int[] r2OutCurveMode => m_Config.r2OutCurveMode;
+ public static int getR2OutCurveMode(int index)
+ {
+ return m_Config.r2OutCurveMode[index];
+ }
+
+ public static int[] sxOutCurveMode => m_Config.sxOutCurveMode;
+ public static int getSXOutCurveMode(int index)
+ {
+ return m_Config.sxOutCurveMode[index];
+ }
+
+ public static int[] szOutCurveMode => m_Config.szOutCurveMode;
+ public static int getSZOutCurveMode(int index)
+ {
+ return m_Config.szOutCurveMode[index];
+ }
+
+ public static bool[] TrackballMode => m_Config.trackballMode;
+ public static bool getTrackballMode(int index)
+ {
+ return m_Config.trackballMode[index];
+ }
+
+ public static double[] TrackballFriction => m_Config.trackballFriction;
+ public static double getTrackballFriction(int index)
+ {
+ return m_Config.trackballFriction[index];
+ }
+
public static string[] LaunchProgram => m_Config.launchProgram;
public static string[] ProfilePath => m_Config.profilePath;
+ public static string[] OlderProfilePath => m_Config.olderProfilePath;
+ public static bool[] DistanceProfiles = m_Config.distanceProfiles;
+
public static List[] ProfileActions => m_Config.profileActions;
+ public static int getProfileActionCount(int index)
+ {
+ return m_Config.profileActionCount[index];
+ }
+
+ public static void calculateProfileActionCount(int index)
+ {
+ m_Config.profileActionCount[index] = m_Config.profileActions[index].Count;
+ }
+
+ public static List getProfileActions(int index)
+ {
+ return m_Config.profileActions[index];
+ }
public static void UpdateDS4CSetting (int deviceNum, string buttonName, bool shift, object action, string exts, DS4KeyType kt, int trigger = 0)
{
m_Config.UpdateDS4CSetting(deviceNum, buttonName, shift, action, exts, kt, trigger);
+ m_Config.containsCustomAction[deviceNum] = m_Config.HasCustomActions(deviceNum);
+ m_Config.containsCustomExtras[deviceNum] = m_Config.HasCustomExtras(deviceNum);
}
+
public static void UpdateDS4Extra(int deviceNum, string buttonName, bool shift, string exts)
{
m_Config.UpdateDS4CExtra(deviceNum, buttonName, shift, exts);
+ m_Config.containsCustomAction[deviceNum] = m_Config.HasCustomActions(deviceNum);
+ m_Config.containsCustomExtras[deviceNum] = m_Config.HasCustomExtras(deviceNum);
}
- public static object GetDS4Action(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Action(deviceNum, buttonName, shift);
+ public static object GetDS4Action(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Action(deviceNum, buttonName, shift);
+ public static object GetDS4Action(int deviceNum, DS4Controls control, bool shift) => m_Config.GetDS4Action(deviceNum, control, shift);
public static DS4KeyType GetDS4KeyType(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4KeyType(deviceNum, buttonName, shift);
public static string GetDS4Extra(int deviceNum, string buttonName, bool shift) => m_Config.GetDS4Extra(deviceNum, buttonName, shift);
public static int GetDS4STrigger(int deviceNum, string buttonName) => m_Config.GetDS4STrigger(deviceNum, buttonName);
+ public static int GetDS4STrigger(int deviceNum, DS4Controls control) => m_Config.GetDS4STrigger(deviceNum, control);
public static List getDS4CSettings(int device) => m_Config.ds4settings[device];
public static DS4ControlSettings getDS4CSetting(int deviceNum, string control) => m_Config.getDS4CSetting(deviceNum, control);
- public static bool HasCustomAction(int deviceNum) => m_Config.HasCustomActions(deviceNum);
+ public static DS4ControlSettings getDS4CSetting(int deviceNum, DS4Controls control) => m_Config.getDS4CSetting(deviceNum, control);
+ public static bool HasCustomActions(int deviceNum) => m_Config.HasCustomActions(deviceNum);
public static bool HasCustomExtras(int deviceNum) => m_Config.HasCustomExtras(deviceNum);
- public static void SaveAction(string name, string controls, int mode, string details, bool edit, string extras = "")
+ public static bool containsCustomAction(int deviceNum)
+ {
+ return m_Config.containsCustomAction[deviceNum];
+ }
+
+ public static bool containsCustomExtras(int deviceNum)
+ {
+ return m_Config.containsCustomExtras[deviceNum];
+ }
+
+ public static void SaveAction(string name, string controls, int mode,
+ string details, bool edit, string extras = "")
{
m_Config.SaveAction(name, controls, mode, details, edit, extras);
Mapping.actionDone.Add(new Mapping.ActionState());
@@ -356,66 +1086,129 @@ namespace DS4Windows
public static int GetActionIndexOf(string name)
{
- for (int i = 0; i < m_Config.actions.Count; i++)
+ for (int i = 0, actionCount = m_Config.actions.Count; i < actionCount; i++)
+ {
if (m_Config.actions[i].name == name)
return i;
+ }
+
return -1;
}
+ public static int GetProfileActionIndexOf(int device, string name)
+ {
+ int index = -1;
+ m_Config.profileActionIndexDict[device].TryGetValue(name, out index);
+ return index;
+ }
+
public static SpecialAction GetAction(string name)
{
- foreach (SpecialAction sA in m_Config.actions)
+ //foreach (SpecialAction sA in m_Config.actions)
+ for (int i=0, actionCount = m_Config.actions.Count; i < actionCount; i++)
+ {
+ SpecialAction sA = m_Config.actions[i];
if (sA.name == name)
return sA;
+ }
+
return new SpecialAction("null", "null", "null", "null");
}
-
- /*public static X360Controls getCustomButton(int device, DS4Controls controlName) => m_Config.GetCustomButton(device, controlName);
-
- public static ushort getCustomKey(int device, DS4Controls controlName) => m_Config.GetCustomKey(device, controlName);
-
- public static string getCustomMacro(int device, DS4Controls controlName) => m_Config.GetCustomMacro(device, controlName);
-
- public static string getCustomExtras(int device, DS4Controls controlName) => m_Config.GetCustomExtras(device, controlName);
-
- public static DS4KeyType getCustomKeyType(int device, DS4Controls controlName) => m_Config.GetCustomKeyType(device, controlName);
-
- public static bool getHasCustomKeysorButtons(int device) => m_Config.customMapButtons[device].Count > 0
- || m_Config.customMapKeys[device].Count > 0;
-
- public static bool getHasCustomExtras(int device) => m_Config.customMapExtras[device].Count > 0;
- public static Dictionary getCustomButtons(int device) => m_Config.customMapButtons[device];
- public static Dictionary getCustomKeys(int device) => m_Config.customMapKeys[device];
- public static Dictionary getCustomMacros(int device) => m_Config.customMapMacros[device];
- public static Dictionary getCustomExtras(int device) => m_Config.customMapExtras[device];
- public static Dictionary getCustomKeyTypes(int device) => m_Config.customMapKeyTypes[device];
-
- public static X360Controls getShiftCustomButton(int device, DS4Controls controlName) => m_Config.GetShiftCustomButton(device, controlName);
- public static ushort getShiftCustomKey(int device, DS4Controls controlName) => m_Config.GetShiftCustomKey(device, controlName);
- public static string getShiftCustomMacro(int device, DS4Controls controlName) => m_Config.GetShiftCustomMacro(device, controlName);
- public static string getShiftCustomExtras(int device, DS4Controls controlName) => m_Config.GetShiftCustomExtras(device, controlName);
- public static DS4KeyType getShiftCustomKeyType(int device, DS4Controls controlName) => m_Config.GetShiftCustomKeyType(device, controlName);
- public static bool getHasShiftCustomKeysorButtons(int device) => m_Config.shiftCustomMapButtons[device].Count > 0
- || m_Config.shiftCustomMapKeys[device].Count > 0;
- public static bool getHasShiftCustomExtras(int device) => m_Config.shiftCustomMapExtras[device].Count > 0;
- public static Dictionary getShiftCustomButtons(int device) => m_Config.shiftCustomMapButtons[device];
- public static Dictionary getShiftCustomKeys(int device) => m_Config.shiftCustomMapKeys[device];
- public static Dictionary getShiftCustomMacros(int device) => m_Config.shiftCustomMapMacros[device];
- public static Dictionary getShiftCustomExtras(int device) => m_Config.shiftCustomMapExtras[device];
- public static Dictionary getShiftCustomKeyTypes(int device) => m_Config.shiftCustomMapKeyTypes[device]; */
- public static bool Load() => m_Config.Load();
-
- public static void LoadProfile(int device, bool launchprogram, ControlService control)
+ public static SpecialAction GetProfileAction(int device, string name)
{
- m_Config.LoadProfile(device, launchprogram, control);
- tempprofilename[device] = string.Empty;
+ SpecialAction sA = null;
+ m_Config.profileActionDict[device].TryGetValue(name, out sA);
+ return sA;
}
- public static void LoadTempProfile(int device, string name, bool launchprogram, ControlService control)
+ public static void calculateProfileActionDicts(int device)
+ {
+ m_Config.profileActionDict[device].Clear();
+ m_Config.profileActionIndexDict[device].Clear();
+
+ foreach (string actionname in m_Config.profileActions[device])
+ {
+ m_Config.profileActionDict[device][actionname] = GetAction(actionname);
+ m_Config.profileActionIndexDict[device][actionname] = GetActionIndexOf(actionname);
+ }
+ }
+
+ public static void cacheProfileCustomsFlags(int device)
+ {
+ m_Config.containsCustomAction[device] = HasCustomActions(device);
+ m_Config.containsCustomExtras[device] = HasCustomExtras(device);
+ }
+
+ public static X360Controls getX360ControlsByName(string key)
+ {
+ return m_Config.getX360ControlsByName(key);
+ }
+
+ public static string getX360ControlString(X360Controls key)
+ {
+ return m_Config.getX360ControlString(key);
+ }
+
+ public static DS4Controls getDS4ControlsByName(string key)
+ {
+ return m_Config.getDS4ControlsByName(key);
+ }
+
+ public static X360Controls getDefaultX360ControlBinding(DS4Controls dc)
+ {
+ return defaultButtonMapping[(int)dc];
+ }
+
+ public static bool containsLinkedProfile(string serial)
+ {
+ string tempSerial = serial.Replace(":", string.Empty);
+ return m_Config.linkedProfiles.ContainsKey(tempSerial);
+ }
+
+ public static string getLinkedProfile(string serial)
+ {
+ string temp = string.Empty;
+ string tempSerial = serial.Replace(":", string.Empty);
+ if (m_Config.linkedProfiles.ContainsKey(tempSerial))
+ {
+ temp = m_Config.linkedProfiles[tempSerial];
+ }
+
+ return temp;
+ }
+
+ public static void changeLinkedProfile(string serial, string profile)
+ {
+ string tempSerial = serial.Replace(":", string.Empty);
+ m_Config.linkedProfiles[tempSerial] = profile;
+ }
+
+ public static void removeLinkedProfile(string serial)
+ {
+ string tempSerial = serial.Replace(":", string.Empty);
+ if (m_Config.linkedProfiles.ContainsKey(tempSerial))
+ {
+ m_Config.linkedProfiles.Remove(tempSerial);
+ }
+ }
+
+ public static bool Load() => m_Config.Load();
+
+ public static void LoadProfile(int device, bool launchprogram, ControlService control,
+ bool xinputChange = true, bool postLoad = true)
+ {
+ m_Config.LoadProfile(device, launchprogram, control, "", xinputChange, postLoad);
+ tempprofilename[device] = string.Empty;
+ tempprofileDistance[device] = false;
+ }
+
+ public static void LoadTempProfile(int device, string name, bool launchprogram,
+ ControlService control, bool xinputChange = true)
{
m_Config.LoadProfile(device, launchprogram, control, appdatapath + @"\Profiles\" + name + ".xml");
tempprofilename[device] = name;
+ tempprofileDistance[device] = name.ToLower().Contains("distance");
}
public static bool Save()
@@ -428,17 +1221,29 @@ namespace DS4Windows
m_Config.SaveProfile(device, propath);
}
+ public static bool SaveLinkedProfiles()
+ {
+ return m_Config.SaveLinkedProfiles();
+ }
+
+ public static bool LoadLinkedProfiles()
+ {
+ return m_Config.LoadLinkedProfiles();
+ }
+
private static byte applyRatio(byte b1, byte b2, double r)
{
- if (r > 100)
- r = 100;
- else if (r < 0)
- r = 0;
- r /= 100f;
- return (byte)Math.Round((b1 * (1 - r) + b2 *r),0);
+ if (r > 100.0)
+ r = 100.0;
+ else if (r < 0.0)
+ r = 0.0;
+
+ r /= 100.0;
+ return (byte)Math.Round((b1 * (1 - r) + b2 * r), 0);
}
+
public static DS4Color getTransitionedColor(DS4Color c1, DS4Color c2, double ratio)
- {//;
+ {
//Color cs = Color.FromArgb(c1.red, c1.green, c1.blue);
c1.red = applyRatio(c1.red, c2.red, ratio);
c1.green = applyRatio(c1.green, c2.green, ratio);
@@ -463,6 +1268,7 @@ namespace DS4Windows
csR = HuetoRGB(hue2,sat2,bri2 - br*ratio);
else
csR = HuetoRGB(hue2 - hr * ratio, sat2 - sr * ratio, bri2 - br * ratio);
+
return csR;
}
@@ -473,68 +1279,114 @@ namespace DS4Windows
float m = bri - C / 2;
float R, G, B;
if (0 <= hue && hue < 60)
- { R = C; G = X; B = 0;}
+ {
+ R = C; G = X; B = 0;
+ }
else if (60 <= hue && hue < 120)
- {R = X; G = C; B = 0; }
+ {
+ R = X; G = C; B = 0;
+ }
else if (120 <= hue && hue < 180)
- { R = 0; G = C; B = X; }
+ {
+ R = 0; G = C; B = X;
+ }
else if (180 <= hue && hue < 240)
- { R = 0; G = X; B = C; }
+ {
+ R = 0; G = X; B = C;
+ }
else if (240 <= hue && hue < 300)
- { R = X; G = 0; B = C; }
+ {
+ R = X; G = 0; B = C;
+ }
else if (300 <= hue && hue < 360)
- { R = C; G = 0; B = X; }
+ {
+ R = C; G = 0; B = X;
+ }
else
- { R = 255; G = 0; B = 0; }
+ {
+ R = 255; G = 0; B = 0;
+ }
+
R += m; G += m; B += m;
- R *= 255; G *= 255; B *= 255;
+ R *= 255.0f; G *= 255.0f; B *= 255.0f;
return Color.FromArgb((int)R, (int)G, (int)B);
}
+ public static double Clamp(double min, double value, double max)
+ {
+ return (value < min) ? min : (value > max) ? max : value;
+ }
+
+ private static int ClampInt(int min, int value, int max)
+ {
+ return (value < min) ? min : (value > max) ? max : value;
+ }
}
-
-
public class BackingStore
{
//public String m_Profile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DS4Tool" + "\\Profiles.xml";
public String m_Profile = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName + "\\Profiles.xml";
public String m_Actions = Global.appdatapath + "\\Actions.xml";
+ public string m_linkedProfiles = Global.appdatapath + "\\LinkedProfiles.xml";
protected XmlDocument m_Xdoc = new XmlDocument();
- //fifth value used to for options, not fifth controller
- public int[] buttonMouseSensitivity = { 25, 25, 25, 25, 25 };
+ // fifth value used for options, not fifth controller
+ public int[] buttonMouseSensitivity = new int[5] { 25, 25, 25, 25, 25 };
- public bool[] flushHIDQueue = { true, true, true, true, true };
- public int[] idleDisconnectTimeout = { 0, 0, 0, 0, 0 };
- public Boolean[] touchpadJitterCompensation = { true, true, true, true, true };
- public Boolean[] lowerRCOn = { false, false, false, false, false };
- public Boolean[] ledAsBattery = { false, false, false, false, false };
- public Byte[] flashType = { 0, 0, 0, 0, 0 };
- public String[] profilePath = { String.Empty, String.Empty, String.Empty, String.Empty, String.Empty };
- public Byte[] rumble = { 100, 100, 100, 100, 100 };
- public Byte[] touchSensitivity = { 100, 100, 100, 100, 100 };
- public Byte[] l2Deadzone = { 0, 0, 0, 0, 0 }, r2Deadzone = { 0, 0, 0, 0, 0 };
- public int[] LSDeadzone = { 0, 0, 0, 0, 0 }, RSDeadzone = { 0, 0, 0, 0, 0 };
- public double[] SXDeadzone = { 0.25, 0.25, 0.25, 0.25, 0.25 }, SZDeadzone = { 0.25, 0.25, 0.25, 0.25, 0.25 };
- public double[] l2Sens = { 1, 1, 1, 1, 1 }, r2Sens = { 1, 1, 1, 1, 1 };
- public double[] LSSens = { 1, 1, 1, 1, 1 }, RSSens = { 1, 1, 1, 1, 1 };
- public double[] SXSens = { 1, 1, 1, 1, 1 }, SZSens = { 1, 1, 1, 1, 1 };
- public Byte[] tapSensitivity = { 0, 0, 0, 0, 0 };
- public bool[] doubleTap = { false, false, false, false, false };
- public int[] scrollSensitivity = { 0, 0, 0, 0, 0 };
- public double[] rainbow = { 0, 0, 0, 0, 0 };
- public int[] flashAt = { 0, 0, 0, 0, 0 };
- public bool[] mouseAccel = { true, true, true, true, true };
- public DS4Color[] m_LowLeds = new DS4Color[]
+ public bool[] flushHIDQueue = new bool[5] { false, false, false, false, false };
+ public bool[] enableTouchToggle = new bool[5] { true, true, true, true, true };
+ public int[] idleDisconnectTimeout = new int[5] { 0, 0, 0, 0, 0 };
+ public bool[] touchpadJitterCompensation = new bool[5] { true, true, true, true, true };
+ public bool[] lowerRCOn = new bool[5] { false, false, false, false, false };
+ public bool[] ledAsBattery = new bool[5] { false, false, false, false, false };
+ public byte[] flashType = new byte[5] { 0, 0, 0, 0, 0 };
+ public string[] profilePath = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
+ public string[] olderProfilePath = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
+ public Dictionary linkedProfiles = new Dictionary();
+ // Cache properties instead of performing a string comparison every frame
+ public bool[] distanceProfiles = new bool[5] { false, false, false, false, false };
+ public Byte[] rumble = new Byte[5] { 100, 100, 100, 100, 100 };
+ public Byte[] touchSensitivity = new Byte[5] { 100, 100, 100, 100, 100 };
+ public Byte[] l2Deadzone = new Byte[5] { 0, 0, 0, 0, 0 }, r2Deadzone = new Byte[5] { 0, 0, 0, 0, 0 };
+ public int[] LSDeadzone = new int[5] { 0, 0, 0, 0, 0 }, RSDeadzone = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] LSAntiDeadzone = new int[5] { 0, 0, 0, 0, 0 }, RSAntiDeadzone = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] LSMaxzone = new int[5] { 100, 100, 100, 100, 100 }, RSMaxzone = new int[5] { 100, 100, 100, 100, 100 };
+ public int[] l2AntiDeadzone = new int[5] { 0, 0, 0, 0, 0 }, r2AntiDeadzone = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] l2Maxzone = new int[5] { 100, 100, 100, 100, 100 }, r2Maxzone = new int[5] { 100, 100, 100, 100, 100 };
+ public double[] LSRotation = new double[5] { 0.0, 0.0, 0.0, 0.0, 0.0 }, RSRotation = new double[5] { 0.0, 0.0, 0.0, 0.0, 0.0 };
+ public double[] SXDeadzone = new double[5] { 0.02, 0.02, 0.02, 0.02, 0.02 }, SZDeadzone = new double[5] { 0.02, 0.02, 0.02, 0.02, 0.02 };
+ public double[] SXMaxzone = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 },
+ SZMaxzone = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 };
+ public double[] SXAntiDeadzone = new double[5] { 0.0, 0.0, 0.0, 0.0, 0.0 },
+ SZAntiDeadzone = new double[5] { 0.0, 0.0, 0.0, 0.0, 0.0 };
+ public double[] l2Sens = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 }, r2Sens = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 };
+ public double[] LSSens = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 }, RSSens = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 };
+ public double[] SXSens = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 }, SZSens = new double[5] { 1.0, 1.0, 1.0, 1.0, 1.0 };
+ public Byte[] tapSensitivity = new Byte[5] { 0, 0, 0, 0, 0 };
+ public bool[] doubleTap = new bool[5] { false, false, false, false, false };
+ public int[] scrollSensitivity = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] touchpadInvert = new int[5] { 0, 0, 0, 0, 0 };
+ public double[] rainbow = new double[5] { 0.0, 0.0, 0.0, 0.0, 0.0 };
+ public int[] flashAt = new int[5] { 0, 0, 0, 0, 0 };
+ public bool[] mouseAccel = new bool[5] { true, true, true, true, true };
+ public int[] btPollRate = new int[5] { 4, 4, 4, 4, 4 };
+ public int[] lsOutCurveMode = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] rsOutCurveMode = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] l2OutCurveMode = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] r2OutCurveMode = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] sxOutCurveMode = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] szOutCurveMode = new int[5] { 0, 0, 0, 0, 0 };
+
+ public DS4Color[] m_LowLeds = new DS4Color[5]
{
- new DS4Color(Color.Black),
+ new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
- public DS4Color[] m_Leds = new DS4Color[]
+ public DS4Color[] m_Leds = new DS4Color[5]
{
new DS4Color(Color.Blue),
new DS4Color(Color.Red),
@@ -542,43 +1394,50 @@ namespace DS4Windows
new DS4Color(Color.Pink),
new DS4Color(Color.White)
};
- public DS4Color[] m_ChargingLeds = new DS4Color[]
+ public DS4Color[] m_ChargingLeds = new DS4Color[5]
{
- new DS4Color(Color.Black),
+ new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
- public DS4Color[] m_FlashLeds = new DS4Color[]
+ public DS4Color[] m_FlashLeds = new DS4Color[5]
{
- new DS4Color(Color.Black),
+ new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black),
new DS4Color(Color.Black)
};
- public bool[] useCustomLeds = new bool[] { false, false, false, false };
- public DS4Color[] m_CustomLeds = new DS4Color[]
+ public bool[] useCustomLeds = new bool[5] { false, false, false, false, false };
+ public DS4Color[] m_CustomLeds = new DS4Color[5]
{
- new DS4Color(Color.Black),
- new DS4Color(Color.Black),
- new DS4Color(Color.Black),
- new DS4Color(Color.Black)
+ new DS4Color(Color.Blue),
+ new DS4Color(Color.Blue),
+ new DS4Color(Color.Blue),
+ new DS4Color(Color.Blue),
+ new DS4Color(Color.Blue)
};
- public int[] chargingType = { 0, 0, 0, 0, 0 };
- public string[] launchProgram = { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
- public bool[] dinputOnly = { false, false, false, false, false };
- public bool[] startTouchpadOff = { false, false, false, false, false };
- public bool[] useTPforControls = { false, false, false, false, false };
- public bool[] useSAforMouse = { false, false, false, false, false };
- public string[] sATriggers = { "", "", "", "", "" };
- public int[] lsCurve = { 0, 0, 0, 0, 0 };
- public int[] rsCurve = { 0, 0, 0, 0, 0 };
+
+ public int[] chargingType = new int[5] { 0, 0, 0, 0, 0 };
+ public string[] launchProgram = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
+ public bool[] dinputOnly = new bool[5] { false, false, false, false, false };
+ public bool[] startTouchpadOff = new bool[5] { false, false, false, false, false };
+ public bool[] useTPforControls = new bool[5] { false, false, false, false, false };
+ public bool[] useSAforMouse = new bool[5] { false, false, false, false, false };
+ public string[] sATriggers = new string[5] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
+ public int[][] touchDisInvertTriggers = new int[5][] { new int[1] { -1 }, new int[1] { -1 }, new int[1] { -1 },
+ new int[1] { -1 }, new int[1] { -1 } };
+ public int[] lsCurve = new int[5] { 0, 0, 0, 0, 0 };
+ public int[] rsCurve = new int[5] { 0, 0, 0, 0, 0 };
public Boolean useExclusiveMode = false;
public Int32 formWidth = 782;
public Int32 formHeight = 550;
+ public int formLocationX = 0;
+ public int formLocationY = 0;
public Boolean startMinimized = false;
+ public Boolean minToTaskbar = false;
public DateTime lastChecked;
public int CheckWhen = 1;
public int notifications = 2;
@@ -589,118 +1448,116 @@ namespace DS4Windows
public int firstXinputPort = 1;
public bool closeMini = false;
public List actions = new List();
- public List[] ds4settings = { new List(), new List(), new List(), new List(), new List() };
- /*public Dictionary[] customMapKeyTypes = { null, null, null, null, null };
- public Dictionary[] customMapKeys = { null, null, null, null, null };
- public Dictionary[] customMapMacros = { null, null, null, null, null };
- public Dictionary[] customMapButtons = { null, null, null, null, null };
- public Dictionary[] customMapExtras = { null, null, null, null, null };
+ public List[] ds4settings = new List[5]
+ { new List(), new List(), new List(),
+ new List(), new List() };
- public Dictionary[] shiftCustomMapKeyTypes = { null, null, null, null, null };
- public Dictionary[] shiftCustomMapKeys = { null, null, null, null, null };
- public Dictionary[] shiftCustomMapMacros = { null, null, null, null, null };
- public Dictionary[] shiftCustomMapButtons = { null, null, null, null, null };
- public Dictionary[] shiftCustomMapExtras = { null, null, null, null, null };*/
- public List[] profileActions = { null, null, null, null, null };
+ public List[] profileActions = new List[5] { null, null, null, null, null };
+ public int[] profileActionCount = new int[5] { 0, 0, 0, 0, 0 };
+ public Dictionary[] profileActionDict = new Dictionary[5]
+ { new Dictionary(), new Dictionary(), new Dictionary(),
+ new Dictionary(), new Dictionary() };
+
+ public Dictionary[] profileActionIndexDict = new Dictionary[5]
+ { new Dictionary(), new Dictionary(), new Dictionary(),
+ new Dictionary(), new Dictionary() };
+
+ public string useLang = "";
public bool downloadLang = true;
public bool useWhiteIcon;
public bool flashWhenLate = true;
- public int flashWhenLateAt = 10;
- public int[] gyroSensitivity = { 100, 100, 100, 100, 100 };
- public int[] gyroInvert = { 0, 0, 0, 0, 0 };
+ public int flashWhenLateAt = 20;
+ // Cache whether profile has custom action
+ public bool[] containsCustomAction = new bool[5] { false, false, false, false, false };
+
+ // Cache whether profile has custom extras
+ public bool[] containsCustomExtras = new bool[5] { false, false, false, false, false };
+
+ public int[] gyroSensitivity = new int[5] { 100, 100, 100, 100, 100 };
+ public int[] gyroSensVerticalScale = new int[5] { 100, 100, 100, 100, 100 };
+ public int[] gyroInvert = new int[5] { 0, 0, 0, 0, 0 };
+ public bool[] gyroTriggerTurns = new bool[5] { true, true, true, true, true };
+ public bool[] gyroSmoothing = new bool[5] { false, false, false, false, false };
+ public double[] gyroSmoothWeight = new double[5] { 0.5, 0.5, 0.5, 0.5, 0.5 };
+ public int[] gyroMouseHorizontalAxis = new int[5] { 0, 0, 0, 0, 0 };
+ public bool[] trackballMode = new bool[5] { false, false, false, false, false };
+ public double[] trackballFriction = new double[5] { 10.0, 10.0, 10.0, 10.0, 10.0 };
+
+ bool tempBool = false;
public BackingStore()
{
for (int i = 0; i < 5; i++)
{
foreach (DS4Controls dc in Enum.GetValues(typeof(DS4Controls)))
+ {
if (dc != DS4Controls.None)
ds4settings[i].Add(new DS4ControlSettings(dc));
- /*customMapKeyTypes[i] = new Dictionary();
- customMapKeys[i] = new Dictionary();
- customMapMacros[i] = new Dictionary();
- customMapButtons[i] = new Dictionary();
- customMapExtras[i] = new Dictionary();
+ }
- shiftCustomMapKeyTypes[i] = new Dictionary();
- shiftCustomMapKeys[i] = new Dictionary();
- shiftCustomMapMacros[i] = new Dictionary();
- shiftCustomMapButtons[i] = new Dictionary();
- shiftCustomMapExtras[i] = new Dictionary();*/
profileActions[i] = new List();
profileActions[i].Add("Disconnect Controller");
+ profileActionCount[i] = profileActions[i].Count;
}
}
- /*public X360Controls GetCustomButton(int device, DS4Controls controlName)
+ private string stickOutputCurveString(int id)
{
- if (customMapButtons[device].ContainsKey(controlName))
- return customMapButtons[device][controlName];
- else return X360Controls.None;
- }
- public UInt16 GetCustomKey(int device, DS4Controls controlName)
- {
- if (customMapKeys[device].ContainsKey(controlName))
- return customMapKeys[device][controlName];
- else return 0;
- }
- public string GetCustomMacro(int device, DS4Controls controlName)
- {
- if (customMapMacros[device].ContainsKey(controlName))
- return customMapMacros[device][controlName];
- else return "0";
- }
- public string GetCustomExtras(int device, DS4Controls controlName)
- {
- if (customMapExtras[device].ContainsKey(controlName))
- return customMapExtras[device][controlName];
- else return "0";
- }
- public DS4KeyType GetCustomKeyType(int device, DS4Controls controlName)
- {
- try
+ string result = "linear";
+ switch (id)
{
- if (customMapKeyTypes[device].ContainsKey(controlName))
- return customMapKeyTypes[device][controlName];
- else return 0;
+ case 0: break;
+ case 1: result = "enhanced-precision"; break;
+ case 2: result = "quadratic"; break;
+ case 3: result = "cubic"; break;
+ default: break;
}
- catch { return 0; }
+
+ return result;
}
- public X360Controls GetShiftCustomButton(int device, DS4Controls controlName)
+ private int stickOutputCurveId(string name)
{
- if (shiftCustomMapButtons[device].ContainsKey(controlName))
- return shiftCustomMapButtons[device][controlName];
- else return X360Controls.None;
- }
- public UInt16 GetShiftCustomKey(int device, DS4Controls controlName)
- {
- if (shiftCustomMapKeys[device].ContainsKey(controlName))
- return shiftCustomMapKeys[device][controlName];
- else return 0;
- }
- public string GetShiftCustomMacro(int device, DS4Controls controlName)
- {
- if (shiftCustomMapMacros[device].ContainsKey(controlName))
- return shiftCustomMapMacros[device][controlName];
- else return "0";
- }
- public string GetShiftCustomExtras(int device, DS4Controls controlName)
- {
- if (customMapExtras[device].ContainsKey(controlName))
- return customMapExtras[device][controlName];
- else return "0";
- }
- public DS4KeyType GetShiftCustomKeyType(int device, DS4Controls controlName)
- {
- try
+ int id = 0;
+ switch (name)
{
- if (shiftCustomMapKeyTypes[device].ContainsKey(controlName))
- return shiftCustomMapKeyTypes[device][controlName];
- else return 0;
+ case "linear": id = 0; break;
+ case "enhanced-precision": id = 1; break;
+ case "quadratic": id = 2; break;
+ case "cubic": id = 3; break;
+ default: break;
}
- catch { return 0; }
- }*/
+
+ return id;
+ }
+
+ private string axisOutputCurveString(int id)
+ {
+ string result = "linear";
+ switch (id)
+ {
+ case 0: break;
+ case 1: result = "quadratic"; break;
+ case 2: result = "cubic"; break;
+ default: break;
+ }
+
+ return result;
+ }
+
+ private int axisOutputCurveId(string name)
+ {
+ int id = 0;
+ switch (name)
+ {
+ case "linear": id = 0; break;
+ case "quadratic": id = 1; break;
+ case "cubic": id = 2; break;
+ default: break;
+ }
+
+ return id;
+ }
public bool SaveProfile(int device, string propath)
{
@@ -725,6 +1582,7 @@ namespace DS4Windows
Node = m_Xdoc.CreateNode(XmlNodeType.Element, "DS4Windows", null);
XmlNode xmlFlushHIDQueue = m_Xdoc.CreateNode(XmlNodeType.Element, "flushHIDQueue", null); xmlFlushHIDQueue.InnerText = flushHIDQueue[device].ToString(); Node.AppendChild(xmlFlushHIDQueue);
+ XmlNode xmlTouchToggle = m_Xdoc.CreateNode(XmlNodeType.Element, "touchToggle", null); xmlTouchToggle.InnerText = enableTouchToggle[device].ToString(); Node.AppendChild(xmlTouchToggle);
XmlNode xmlIdleDisconnectTimeout = m_Xdoc.CreateNode(XmlNodeType.Element, "idleDisconnectTimeout", null); xmlIdleDisconnectTimeout.InnerText = idleDisconnectTimeout[device].ToString(); Node.AppendChild(xmlIdleDisconnectTimeout);
XmlNode xmlColor = m_Xdoc.CreateNode(XmlNodeType.Element, "Color", null);
xmlColor.InnerText = m_Leds[device].red.ToString() + "," + m_Leds[device].green.ToString() + "," + m_Leds[device].blue.ToString();
@@ -750,13 +1608,31 @@ namespace DS4Windows
XmlNode xmlScrollSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "scrollSensitivity", null); xmlScrollSensitivity.InnerText = scrollSensitivity[device].ToString(); Node.AppendChild(xmlScrollSensitivity);
XmlNode xmlLeftTriggerMiddle = m_Xdoc.CreateNode(XmlNodeType.Element, "LeftTriggerMiddle", null); xmlLeftTriggerMiddle.InnerText = l2Deadzone[device].ToString(); Node.AppendChild(xmlLeftTriggerMiddle);
XmlNode xmlRightTriggerMiddle = m_Xdoc.CreateNode(XmlNodeType.Element, "RightTriggerMiddle", null); xmlRightTriggerMiddle.InnerText = r2Deadzone[device].ToString(); Node.AppendChild(xmlRightTriggerMiddle);
+ XmlNode xmlTouchpadInvert = m_Xdoc.CreateNode(XmlNodeType.Element, "TouchpadInvert", null); xmlTouchpadInvert.InnerText = touchpadInvert[device].ToString(); Node.AppendChild(xmlTouchpadInvert);
+ XmlNode xmlL2AD = m_Xdoc.CreateNode(XmlNodeType.Element, "L2AntiDeadZone", null); xmlL2AD.InnerText = l2AntiDeadzone[device].ToString(); Node.AppendChild(xmlL2AD);
+ XmlNode xmlR2AD = m_Xdoc.CreateNode(XmlNodeType.Element, "R2AntiDeadZone", null); xmlR2AD.InnerText = r2AntiDeadzone[device].ToString(); Node.AppendChild(xmlR2AD);
+ XmlNode xmlL2Maxzone = m_Xdoc.CreateNode(XmlNodeType.Element, "L2MaxZone", null); xmlL2Maxzone.InnerText = l2Maxzone[device].ToString(); Node.AppendChild(xmlL2Maxzone);
+ XmlNode xmlR2Maxzone = m_Xdoc.CreateNode(XmlNodeType.Element, "R2MaxZone", null); xmlR2Maxzone.InnerText = r2Maxzone[device].ToString(); Node.AppendChild(xmlR2Maxzone);
XmlNode xmlButtonMouseSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "ButtonMouseSensitivity", null); xmlButtonMouseSensitivity.InnerText = buttonMouseSensitivity[device].ToString(); Node.AppendChild(xmlButtonMouseSensitivity);
XmlNode xmlRainbow = m_Xdoc.CreateNode(XmlNodeType.Element, "Rainbow", null); xmlRainbow.InnerText = rainbow[device].ToString(); Node.AppendChild(xmlRainbow);
XmlNode xmlLSD = m_Xdoc.CreateNode(XmlNodeType.Element, "LSDeadZone", null); xmlLSD.InnerText = LSDeadzone[device].ToString(); Node.AppendChild(xmlLSD);
XmlNode xmlRSD = m_Xdoc.CreateNode(XmlNodeType.Element, "RSDeadZone", null); xmlRSD.InnerText = RSDeadzone[device].ToString(); Node.AppendChild(xmlRSD);
+ XmlNode xmlLSAD = m_Xdoc.CreateNode(XmlNodeType.Element, "LSAntiDeadZone", null); xmlLSAD.InnerText = LSAntiDeadzone[device].ToString(); Node.AppendChild(xmlLSAD);
+ XmlNode xmlRSAD = m_Xdoc.CreateNode(XmlNodeType.Element, "RSAntiDeadZone", null); xmlRSAD.InnerText = RSAntiDeadzone[device].ToString(); Node.AppendChild(xmlRSAD);
+ XmlNode xmlLSMaxZone = m_Xdoc.CreateNode(XmlNodeType.Element, "LSMaxZone", null); xmlLSMaxZone.InnerText = LSMaxzone[device].ToString(); Node.AppendChild(xmlLSMaxZone);
+ XmlNode xmlRSMaxZone = m_Xdoc.CreateNode(XmlNodeType.Element, "RSMaxZone", null); xmlRSMaxZone.InnerText = RSMaxzone[device].ToString(); Node.AppendChild(xmlRSMaxZone);
+ XmlNode xmlLSRotation = m_Xdoc.CreateNode(XmlNodeType.Element, "LSRotation", null); xmlLSRotation.InnerText = Convert.ToInt32(LSRotation[device] * 180.0 / Math.PI).ToString(); Node.AppendChild(xmlLSRotation);
+ XmlNode xmlRSRotation = m_Xdoc.CreateNode(XmlNodeType.Element, "RSRotation", null); xmlRSRotation.InnerText = Convert.ToInt32(RSRotation[device] * 180.0 / Math.PI).ToString(); Node.AppendChild(xmlRSRotation);
+
XmlNode xmlSXD = m_Xdoc.CreateNode(XmlNodeType.Element, "SXDeadZone", null); xmlSXD.InnerText = SXDeadzone[device].ToString(); Node.AppendChild(xmlSXD);
XmlNode xmlSZD = m_Xdoc.CreateNode(XmlNodeType.Element, "SZDeadZone", null); xmlSZD.InnerText = SZDeadzone[device].ToString(); Node.AppendChild(xmlSZD);
+ XmlNode xmlSXMaxzone = m_Xdoc.CreateNode(XmlNodeType.Element, "SXMaxZone", null); xmlSXMaxzone.InnerText = Convert.ToInt32(SXMaxzone[device] * 100.0).ToString(); Node.AppendChild(xmlSXMaxzone);
+ XmlNode xmlSZMaxzone = m_Xdoc.CreateNode(XmlNodeType.Element, "SZMaxZone", null); xmlSZMaxzone.InnerText = Convert.ToInt32(SZMaxzone[device] * 100.0).ToString(); Node.AppendChild(xmlSZMaxzone);
+
+ XmlNode xmlSXAntiDeadzone = m_Xdoc.CreateNode(XmlNodeType.Element, "SXAntiDeadZone", null); xmlSXAntiDeadzone.InnerText = Convert.ToInt32(SXAntiDeadzone[device] * 100.0).ToString(); Node.AppendChild(xmlSXAntiDeadzone);
+ XmlNode xmlSZAntiDeadzone = m_Xdoc.CreateNode(XmlNodeType.Element, "SZAntiDeadZone", null); xmlSZAntiDeadzone.InnerText = Convert.ToInt32(SZAntiDeadzone[device] * 100.0).ToString(); Node.AppendChild(xmlSZAntiDeadzone);
+
XmlNode xmlSens = m_Xdoc.CreateNode(XmlNodeType.Element, "Sensitivity", null);
xmlSens.InnerText = $"{LSSens[device]}|{RSSens[device]}|{l2Sens[device]}|{r2Sens[device]}|{SXSens[device]}|{SZSens[device]}";
Node.AppendChild(xmlSens);
@@ -770,11 +1646,34 @@ namespace DS4Windows
XmlNode xmlUseTPforControls = m_Xdoc.CreateNode(XmlNodeType.Element, "UseTPforControls", null); xmlUseTPforControls.InnerText = useTPforControls[device].ToString(); Node.AppendChild(xmlUseTPforControls);
XmlNode xmlUseSAforMouse = m_Xdoc.CreateNode(XmlNodeType.Element, "UseSAforMouse", null); xmlUseSAforMouse.InnerText = useSAforMouse[device].ToString(); Node.AppendChild(xmlUseSAforMouse);
XmlNode xmlSATriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "SATriggers", null); xmlSATriggers.InnerText = sATriggers[device].ToString(); Node.AppendChild(xmlSATriggers);
+
+ XmlNode xmlTouchDisInvTriggers = m_Xdoc.CreateNode(XmlNodeType.Element, "TouchDisInvTriggers", null);
+ string tempTouchDisInv = string.Join(",", touchDisInvertTriggers[device]);
+ xmlTouchDisInvTriggers.InnerText = tempTouchDisInv;
+ Node.AppendChild(xmlTouchDisInvTriggers);
+
XmlNode xmlGyroSensitivity = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroSensitivity", null); xmlGyroSensitivity.InnerText = gyroSensitivity[device].ToString(); Node.AppendChild(xmlGyroSensitivity);
+ XmlNode xmlGyroSensVerticalScale = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroSensVerticalScale", null); xmlGyroSensVerticalScale.InnerText = gyroSensVerticalScale[device].ToString(); Node.AppendChild(xmlGyroSensVerticalScale);
XmlNode xmlGyroInvert = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroInvert", null); xmlGyroInvert.InnerText = gyroInvert[device].ToString(); Node.AppendChild(xmlGyroInvert);
+ XmlNode xmlGyroTriggerTurns = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroTriggerTurns", null); xmlGyroTriggerTurns.InnerText = gyroTriggerTurns[device].ToString(); Node.AppendChild(xmlGyroTriggerTurns);
+ XmlNode xmlGyroSmoothWeight = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroSmoothingWeight", null); xmlGyroSmoothWeight.InnerText = Convert.ToInt32(gyroSmoothWeight[device] * 100).ToString(); Node.AppendChild(xmlGyroSmoothWeight);
+ XmlNode xmlGyroSmoothing = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroSmoothing", null); xmlGyroSmoothing.InnerText = gyroSmoothing[device].ToString(); Node.AppendChild(xmlGyroSmoothing);
+ XmlNode xmlGyroMouseHAxis = m_Xdoc.CreateNode(XmlNodeType.Element, "GyroMouseHAxis", null); xmlGyroMouseHAxis.InnerText = gyroMouseHorizontalAxis[device].ToString(); Node.AppendChild(xmlGyroMouseHAxis);
XmlNode xmlLSC = m_Xdoc.CreateNode(XmlNodeType.Element, "LSCurve", null); xmlLSC.InnerText = lsCurve[device].ToString(); Node.AppendChild(xmlLSC);
XmlNode xmlRSC = m_Xdoc.CreateNode(XmlNodeType.Element, "RSCurve", null); xmlRSC.InnerText = rsCurve[device].ToString(); Node.AppendChild(xmlRSC);
XmlNode xmlProfileActions = m_Xdoc.CreateNode(XmlNodeType.Element, "ProfileActions", null); xmlProfileActions.InnerText = string.Join("/", profileActions[device]); Node.AppendChild(xmlProfileActions);
+ XmlNode xmlBTPollRate = m_Xdoc.CreateNode(XmlNodeType.Element, "BTPollRate", null); xmlBTPollRate.InnerText = btPollRate[device].ToString(); Node.AppendChild(xmlBTPollRate);
+ XmlNode xmlLsOutputCurveMode = m_Xdoc.CreateNode(XmlNodeType.Element, "LSOutputCurveMode", null); xmlLsOutputCurveMode.InnerText = stickOutputCurveString(lsOutCurveMode[device]); Node.AppendChild(xmlLsOutputCurveMode);
+ XmlNode xmlRsOutputCurveMode = m_Xdoc.CreateNode(XmlNodeType.Element, "RSOutputCurveMode", null); xmlRsOutputCurveMode.InnerText = stickOutputCurveString(rsOutCurveMode[device]); Node.AppendChild(xmlRsOutputCurveMode);
+
+ XmlNode xmlL2OutputCurveMode = m_Xdoc.CreateNode(XmlNodeType.Element, "L2OutputCurveMode", null); xmlL2OutputCurveMode.InnerText = axisOutputCurveString(l2OutCurveMode[device]); Node.AppendChild(xmlL2OutputCurveMode);
+ XmlNode xmlR2OutputCurveMode = m_Xdoc.CreateNode(XmlNodeType.Element, "R2OutputCurveMode", null); xmlR2OutputCurveMode.InnerText = axisOutputCurveString(r2OutCurveMode[device]); Node.AppendChild(xmlR2OutputCurveMode);
+
+ XmlNode xmlSXOutputCurveMode = m_Xdoc.CreateNode(XmlNodeType.Element, "SXOutputCurveMode", null); xmlSXOutputCurveMode.InnerText = axisOutputCurveString(sxOutCurveMode[device]); Node.AppendChild(xmlSXOutputCurveMode);
+ XmlNode xmlSZOutputCurveMode = m_Xdoc.CreateNode(XmlNodeType.Element, "SZOutputCurveMode", null); xmlSZOutputCurveMode.InnerText = axisOutputCurveString(szOutCurveMode[device]); Node.AppendChild(xmlSZOutputCurveMode);
+
+ XmlNode xmlTrackBallMode = m_Xdoc.CreateNode(XmlNodeType.Element, "TrackballMode", null); xmlTrackBallMode.InnerText = trackballMode[device].ToString(); Node.AppendChild(xmlTrackBallMode);
+ XmlNode xmlTrackBallFriction = m_Xdoc.CreateNode(XmlNodeType.Element, "TrackballFriction", null); xmlTrackBallFriction.InnerText = trackballFriction[device].ToString(); Node.AppendChild(xmlTrackBallFriction);
XmlNode NodeControl = m_Xdoc.CreateNode(XmlNodeType.Element, "Control", null);
XmlNode Key = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null);
@@ -799,16 +1698,21 @@ namespace DS4Windows
string keyType = string.Empty;
if (dcs.action is string)
+ {
if (dcs.action.ToString() == "Unbound")
keyType += DS4KeyType.Unbound;
+ }
+
if (dcs.keyType.HasFlag(DS4KeyType.HoldMacro))
keyType += DS4KeyType.HoldMacro;
- if (dcs.keyType.HasFlag(DS4KeyType.Macro))
+ else if (dcs.keyType.HasFlag(DS4KeyType.Macro))
keyType += DS4KeyType.Macro;
+
if (dcs.keyType.HasFlag(DS4KeyType.Toggle))
keyType += DS4KeyType.Toggle;
if (dcs.keyType.HasFlag(DS4KeyType.ScanCode))
keyType += DS4KeyType.ScanCode;
+
if (keyType != string.Empty)
{
buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
@@ -828,21 +1732,31 @@ namespace DS4Windows
buttonNode.InnerText = dcs.action.ToString();
Key.AppendChild(buttonNode);
}
- else if (dcs.action is string || dcs.action is X360Controls)
+ else if (dcs.action is string)
{
buttonNode.InnerText = dcs.action.ToString();
Button.AppendChild(buttonNode);
}
+ else if (dcs.action is X360Controls)
+ {
+ buttonNode.InnerText = getX360ControlString((X360Controls)dcs.action);
+ Button.AppendChild(buttonNode);
+ }
}
bool hasvalue = false;
if (!string.IsNullOrEmpty(dcs.extras))
+ {
foreach (string s in dcs.extras.Split(','))
+ {
if (s != "0")
{
hasvalue = true;
break;
}
+ }
+ }
+
if (hasvalue)
{
XmlNode extraNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
@@ -856,8 +1770,11 @@ namespace DS4Windows
string keyType = string.Empty;
if (dcs.shiftAction is string)
+ {
if (dcs.shiftAction.ToString() == "Unbound")
keyType += DS4KeyType.Unbound;
+ }
+
if (dcs.shiftKeyType.HasFlag(DS4KeyType.HoldMacro))
keyType += DS4KeyType.HoldMacro;
if (dcs.shiftKeyType.HasFlag(DS4KeyType.Macro))
@@ -866,6 +1783,7 @@ namespace DS4Windows
keyType += DS4KeyType.Toggle;
if (dcs.shiftKeyType.HasFlag(DS4KeyType.ScanCode))
keyType += DS4KeyType.ScanCode;
+
if (keyType != string.Empty)
{
buttonNode = m_Xdoc.CreateElement(dcs.control.ToString());
@@ -892,14 +1810,20 @@ namespace DS4Windows
ShiftButton.AppendChild(buttonNode);
}
}
+
hasvalue = false;
if (!string.IsNullOrEmpty(dcs.shiftExtras))
+ {
foreach (string s in dcs.shiftExtras.Split(','))
+ {
if (s != "0")
{
hasvalue = true;
break;
}
+ }
+ }
+
if (hasvalue)
{
XmlNode extraNode = m_Xdoc.CreateNode(XmlNodeType.Element, dcs.control.ToString(), null);
@@ -907,6 +1831,7 @@ namespace DS4Windows
ShiftExtras.AppendChild(extraNode);
}
}
+
Node.AppendChild(NodeControl);
if (Button.HasChildNodes)
NodeControl.AppendChild(Button);
@@ -932,104 +1857,7 @@ namespace DS4Windows
NodeShiftControl.AppendChild(ShiftKeyType);
if (ShiftExtras.HasChildNodes)
NodeShiftControl.AppendChild(ShiftExtras);
- /*else if (xmlControls != null)
- {
- Node.AppendChild(xmlControls);
- }*/
- /*if (shiftModifier[device] > 0)
- {
- XmlNode NodeShiftControl = m_Xdoc.CreateNode(XmlNodeType.Element, "ShiftControl", null);
-
- XmlNode ShiftKey = m_Xdoc.CreateNode(XmlNodeType.Element, "Key", null);
- XmlNode ShiftMacro = m_Xdoc.CreateNode(XmlNodeType.Element, "Macro", null);
- XmlNode ShiftKeyType = m_Xdoc.CreateNode(XmlNodeType.Element, "KeyType", null);
- XmlNode ShiftButton = m_Xdoc.CreateNode(XmlNodeType.Element, "Button", null);
- XmlNode ShiftExtras = m_Xdoc.CreateNode(XmlNodeType.Element, "Extras", null);
- if (shiftbuttons != null)
- {
- foreach (var button in shiftbuttons)
- {
- // Save even if string (for xbox controller buttons)
- if (button.Tag != null)
- {
- XmlNode buttonNode;
- string keyType = String.Empty;
- if (button.Tag is KeyValuePair)
- if (((KeyValuePair)button.Tag).Key == "Unbound")
- keyType += DS4KeyType.Unbound;
-
- if (button.Font.Strikeout)
- keyType += DS4KeyType.HoldMacro;
- if (button.Font.Underline)
- keyType += DS4KeyType.Macro;
- if (button.Font.Italic)
- keyType += DS4KeyType.Toggle;
- if (button.Font.Bold)
- keyType += DS4KeyType.ScanCode;
- if (keyType != String.Empty)
- {
- buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, button.Name, null);
- buttonNode.InnerText = keyType;
- ShiftKeyType.AppendChild(buttonNode);
- }
-
- string[] extras;
- buttonNode = m_Xdoc.CreateNode(XmlNodeType.Element, button.Name, null);
- if (button.Tag is KeyValuePair, string> || button.Tag is KeyValuePair || button.Tag is KeyValuePair)
- {
- KeyValuePair tag = (KeyValuePair)button.Tag;
- int[] ii = tag.Key;
- buttonNode.InnerText = string.Join("/", ii);
- ShiftMacro.AppendChild(buttonNode);
- extras = tag.Value.Split(',');
- }
- else if (button.Tag is KeyValuePair || button.Tag is KeyValuePair || button.Tag is KeyValuePair)
- {
- KeyValuePair tag = (KeyValuePair)button.Tag;
- buttonNode.InnerText = tag.Key.ToString();
- ShiftKey.AppendChild(buttonNode);
- extras = tag.Value.Split(',');
- }
- else if (button.Tag is KeyValuePair)
- {
- KeyValuePair tag = (KeyValuePair)button.Tag;
- buttonNode.InnerText = tag.Key;
- ShiftButton.AppendChild(buttonNode);
- extras = tag.Value.Split(',');
- }
- else
- {
- KeyValuePair