Skip to content

Instantly share code, notes, and snippets.

@Ryochan7
Last active March 4, 2021 00:20
Show Gist options
  • Select an option

  • Save Ryochan7/736cbd9c488e6b6409fa4757b08f0aaf to your computer and use it in GitHub Desktop.

Select an option

Save Ryochan7/736cbd9c488e6b6409fa4757b08f0aaf to your computer and use it in GitHub Desktop.
diff --git a/DS4Windows/DS4Control/ControlService.cs b/DS4Windows/DS4Control/ControlService.cs
index a47dfb0b..b7aec6c8 100644
--- a/DS4Windows/DS4Control/ControlService.cs
+++ b/DS4Windows/DS4Control/ControlService.cs
@@ -31,6 +31,8 @@ namespace DS4Windows
public bool running = false;
public bool loopControllers = true;
public bool inServiceTask = false;
+ private ReaderWriterLockSlim[] inputMergeLock = new ReaderWriterLockSlim[MAX_DS4_CONTROLLER_COUNT];
+ private DS4State[] tempInputMappedState = new DS4State[MAX_DS4_CONTROLLER_COUNT];
private DS4State[] MappedState = new DS4State[MAX_DS4_CONTROLLER_COUNT];
private DS4State[] CurrentState = new DS4State[MAX_DS4_CONTROLLER_COUNT];
private DS4State[] PreviousState = new DS4State[MAX_DS4_CONTROLLER_COUNT];
@@ -206,6 +208,8 @@ namespace DS4Windows
CurrentState[i] = new DS4State();
TempState[i] = new DS4State();
PreviousState[i] = new DS4State();
+ tempInputMappedState[i] = new DS4State();
+ inputMergeLock[i] = new ReaderWriterLockSlim();
ExposedState[i] = new DS4StateExposed(CurrentState[i]);
int tempDev = i;
@@ -631,11 +635,22 @@ namespace DS4Windows
if (contType == OutContType.X360)
{
Xbox360OutDevice tempXbox = outDevice as Xbox360OutDevice;
+ using (WriteLocker locker = new WriteLocker(tempXbox.feedbackDevColLock))
+ {
+ tempXbox.receiveFeedbackDevices.Add(device);
+ }
+
Nefarius.ViGEm.Client.Targets.Xbox360FeedbackReceivedEventHandler p = (sender, args) =>
{
//Console.WriteLine("Rumble ({0}, {1}) {2}",
// args.LargeMotor, args.SmallMotor, DateTime.Now.ToString("hh:mm:ss.FFFF"));
- SetDevRumble(device, args.LargeMotor, args.SmallMotor, devIndex);
+ using (ReadLocker locker = new ReadLocker(tempXbox.feedbackDevColLock))
+ {
+ foreach (DS4Device tmpdevice in tempXbox.receiveFeedbackDevices)
+ {
+ SetDevRumble(tmpdevice, args.LargeMotor, args.SmallMotor, tmpdevice.DeviceSlotNumber);
+ }
+ }
};
tempXbox.cont.FeedbackReceived += p;
tempXbox.forceFeedbackCall = p;
@@ -1030,7 +1045,15 @@ namespace DS4Windows
if (!getDInputOnly(i) && device.isSynced())
{
//useDInputOnly[i] = false;
- PluginOutDev(i, device);
+ if (i == 0)
+ {
+ PluginOutDev(i, device);
+ }
+ else
+ {
+ Xbox360OutDevice tempXbox = outputDevices[0] as Xbox360OutDevice;
+ tempXbox.receiveFeedbackDevices.Add(device);
+ }
}
else
{
@@ -1368,7 +1391,18 @@ namespace DS4Windows
if (!getDInputOnly(Index) && device.isSynced())
{
//useDInputOnly[Index] = false;
- PluginOutDev(Index, device);
+ if (Index == 0)
+ {
+ PluginOutDev(Index, device);
+ }
+ else
+ {
+ Xbox360OutDevice tempXbox = outputDevices[0] as Xbox360OutDevice;
+ using (WriteLocker locker = new WriteLocker(tempXbox.feedbackDevColLock))
+ {
+ tempXbox.receiveFeedbackDevices.Add(device);
+ }
+ }
}
else
{
@@ -1921,8 +1955,24 @@ namespace DS4Windows
containsCustomAction(ind) || containsCustomExtras(ind) ||
getProfileActionCount(ind) > 0))
{
- DS4State tempMapState = MappedState[ind];
- Mapping.MapCustom(ind, cState, tempMapState, ExposedState[ind], touchPad[ind], this);
+ DS4State tempMapState;
+
+ if (device.DeviceType == InputDevices.InputDeviceType.JoyConL ||
+ device.DeviceType == InputDevices.InputDeviceType.JoyConR)
+ {
+ using (WriteLocker locker = new WriteLocker(inputMergeLock[0]))
+ {
+ tempMapState = MappedState[0];
+ DS4State tempInputState = tempInputMappedState[0];
+ MergeStateData(device, cState, tempInputState);
+ Mapping.MapCustom(ind, tempInputState, tempMapState, ExposedState[ind], touchPad[ind], this);
+ }
+ }
+ else
+ {
+ tempMapState = MappedState[ind];
+ Mapping.MapCustom(ind, cState, tempMapState, ExposedState[ind], touchPad[ind], this);
+ }
// Copy current Touchpad and Gyro data
tempMapState.Motion = cState.Motion;
@@ -2204,5 +2254,41 @@ namespace DS4Windows
{
return TempState[ind];
}
+
+ public void MergeStateData(DS4Device inputDevice, DS4State cState,
+ DS4State dState)
+ {
+ if (inputDevice.DeviceType == InputDevices.InputDeviceType.JoyConL)
+ {
+ dState.LX = cState.LX;
+ dState.LY = cState.LY;
+ dState.L1 = cState.L1;
+ dState.L2 = cState.L2;
+ dState.L3 = cState.L3;
+ dState.L2Btn = cState.L2Btn;
+ dState.DpadUp = cState.DpadUp;
+ dState.DpadDown = cState.DpadDown;
+ dState.DpadLeft = cState.DpadLeft;
+ dState.DpadRight = cState.DpadRight;
+ dState.Share = cState.Share;
+ dState.Motion = cState.Motion;
+ }
+ else if (inputDevice.DeviceType == InputDevices.InputDeviceType.JoyConR)
+ {
+ dState.RX = cState.RX;
+ dState.RY = cState.RY;
+ dState.R1 = cState.R1;
+ dState.R2 = cState.R2;
+ dState.R3 = cState.R3;
+ dState.R2Btn = cState.R2Btn;
+ dState.Cross = cState.Cross;
+ dState.Circle = cState.Circle;
+ dState.Triangle = cState.Triangle;
+ dState.Square = cState.Square;
+ dState.PS = cState.PS;
+ dState.Options = cState.Options;
+ dState.Motion = cState.Motion;
+ }
+ }
}
}
diff --git a/DS4Windows/DS4Control/Xbox360OutDevice.cs b/DS4Windows/DS4Control/Xbox360OutDevice.cs
index 6c4df1fc..b5d0acab 100644
--- a/DS4Windows/DS4Control/Xbox360OutDevice.cs
+++ b/DS4Windows/DS4Control/Xbox360OutDevice.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Nefarius.ViGEm.Client;
using Nefarius.ViGEm.Client.Targets;
@@ -20,6 +21,8 @@ namespace DS4Windows
public IXbox360Controller cont;
public Xbox360FeedbackReceivedEventHandler forceFeedbackCall;
+ public List<DS4Device> receiveFeedbackDevices = new List<DS4Device>();
+ public ReaderWriterLockSlim feedbackDevColLock = new ReaderWriterLockSlim();
public Xbox360OutDevice(ViGEmClient client)
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment