Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Denellyne committed Feb 28, 2024
1 parent 0095e3d commit e61ec41
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 126 deletions.
2 changes: 2 additions & 0 deletions DualSenseToXInput.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ xcopy "$(SolutionDir)\images" "$(TargetDir)\images" /y /i
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\Misc\benchmark.cpp" />
<ClCompile Include="src\Misc\util.cpp" />
<ClCompile Include="src\Startup\startup.cpp" />
<ClCompile Include="src\Updater\update.cpp" />
<ClCompile Include="src\User Settings\Adaptive Triggers\Adaptive Triggers.cpp" />
<ClCompile Include="src\User Settings\Button Mappings\button Mappings.cpp" />
Expand Down Expand Up @@ -389,6 +390,7 @@ xcopy "$(SolutionDir)\images" "$(TargetDir)\images" /y /i
<ClInclude Include="src\main.h" />
<ClInclude Include="src\Misc\benchmark.h" />
<ClInclude Include="src\Misc\util.h" />
<ClInclude Include="src\Startup\startup.h" />
<ClInclude Include="src\Updater\update.h" />
<ClInclude Include="src\User Settings\Adaptive Triggers\Adaptive Triggers.h" />
<ClInclude Include="src\User Settings\Button Mappings\button Mappings.h" />
Expand Down
9 changes: 9 additions & 0 deletions DualSenseToXInput.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
<Filter Include="Source Files\Backend\Controller\Controller IO\Dualshock4">
<UniqueIdentifier>{7a7b1cd1-4ea8-41b8-906c-61579602154e}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Backend\Startup">
<UniqueIdentifier>{bfda5203-4f58-4af8-abdf-e31e9a6b54b1}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\main.cpp">
Expand Down Expand Up @@ -153,6 +156,9 @@
<ClCompile Include="src\ControllerIO\Dualshock4\dualshock4.cpp">
<Filter>Source Files\Backend\Controller\Controller IO\Dualshock4</Filter>
</ClCompile>
<ClCompile Include="src\Startup\startup.cpp">
<Filter>Source Files\Backend\Startup</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource1.h">
Expand Down Expand Up @@ -251,6 +257,9 @@
<ClInclude Include="src\ControllerIO\Dualshock4\dualshock4.h">
<Filter>Source Files\Backend\Controller\Controller IO\Dualshock4</Filter>
</ClInclude>
<ClInclude Include="src\Startup\startup.h">
<Filter>Source Files\Backend\Startup</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="PCXSense.rc">
Expand Down
23 changes: 13 additions & 10 deletions src/ControllerIO/Controller Connections/controllerConnections.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "controllerConnections.h"
#include <mutex>

int initializeFakeController(PVIGEM_TARGET& emulateX360, VIGEM_ERROR& target, PVIGEM_CLIENT& client) {

Expand All @@ -23,18 +22,19 @@ bool isDualShock4Connected(controller& x360Controller) {
return false;
}


x360Controller.bluetooth = hid_get_device_info(x360Controller.deviceHandle)->interface_number == -1;
x360Controller.hidOffset = hid_get_device_info(x360Controller.deviceHandle)->interface_number == -1;
x360Controller.isConnected = true;

if (x360Controller.bluetooth) { //Bluetooth
x360Controller.bluetooth = 0;
if (x360Controller.hidOffset) { //Bluetooth
x360Controller.hidOffset = 0;
x360Controller.bufferSize = 547;
x360Controller.inputBuffer[0] = 0x11; //Data report code
return true;
}
//USB
x360Controller.bluetooth = 1; //Usb has a 2 offset from bluetooth


x360Controller.hidOffset = 1; //Usb has a 2 offset from bluetooth
x360Controller.bufferSize = 64;
x360Controller.inputBuffer[0] = 0x01; //Data report code
return true;
Expand All @@ -49,15 +49,18 @@ bool isDualsenseConnected(controller& x360Controller){
return false;
}

x360Controller.bluetooth = hid_get_device_info(x360Controller.deviceHandle)->interface_number == -1;
x360Controller.hidOffset = hid_get_device_info(x360Controller.deviceHandle)->interface_number == -1;
x360Controller.isConnected = true;

if (x360Controller.bluetooth) { //Bluetooth
if (x360Controller.hidOffset) { //Bluetooth
x360Controller.bufferSize = 78;
x360Controller.inputBuffer[0] = 0x31; //Data report code
return true;
}
//USB

//disconnectBluetooth(x360Controller.deviceHandle, serialAddress);

x360Controller.bufferSize = 64;
x360Controller.inputBuffer[0] = 0x01; //Data report code
return true;
Expand All @@ -73,11 +76,11 @@ bool isDualsenseEdgeConnected(controller& x360Controller) {
return false;
}

x360Controller.bluetooth = hid_get_device_info(x360Controller.deviceHandle)->interface_number == -1;
x360Controller.hidOffset = hid_get_device_info(x360Controller.deviceHandle)->interface_number == -1;

x360Controller.isConnected = true;

if (x360Controller.bluetooth) { //Bluetooth
if (x360Controller.hidOffset) { //Bluetooth
x360Controller.bufferSize = 78;
x360Controller.inputBuffer[0] = 0x31; //Data report code
return true;
Expand Down
99 changes: 50 additions & 49 deletions src/ControllerIO/Dualsense/dualsense.cpp

Large diffs are not rendered by default.

77 changes: 39 additions & 38 deletions src/ControllerIO/Dualshock4/dualshock4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@

extern bool gameProfileSet;

#define isSelectPressed (buttonMapping[11])*(!(x360Controller.inputBuffer[37- x360Controller.bluetooth * 2] & (1 << 7)) & ((((x360Controller.inputBuffer[39- x360Controller.bluetooth * 2] & 0x0f) << 8) | (x360Controller.inputBuffer[38- x360Controller.bluetooth * 2])) < 800)) ^ (x360Controller.inputBuffer[8- x360Controller.bluetooth * 2] & (1 << 4))
#define isStartPressed (buttonMapping[11])*(!(x360Controller.inputBuffer[37- x360Controller.bluetooth * 2] & (1 << 7)) & ((((x360Controller.inputBuffer[39- x360Controller.bluetooth * 2] & 0x0F) << 8) | (x360Controller.inputBuffer[38- x360Controller.bluetooth * 2])) >= 800)) ^ (x360Controller.inputBuffer[8- x360Controller.bluetooth * 2] & (1 << 5))
#define isSelectPressed (buttonMapping[11])*(!(x360Controller.inputBuffer[37- x360Controller.hidOffset * 2] & (1 << 7)) & ((((x360Controller.inputBuffer[39- x360Controller.hidOffset * 2] & 0x0f) << 8) | (x360Controller.inputBuffer[38- x360Controller.hidOffset * 2])) < 800)) ^ (x360Controller.inputBuffer[8- x360Controller.hidOffset * 2] & (1 << 4))
#define isStartPressed (buttonMapping[11])*(!(x360Controller.inputBuffer[37- x360Controller.hidOffset * 2] & (1 << 7)) & ((((x360Controller.inputBuffer[39- x360Controller.hidOffset * 2] & 0x0F) << 8) | (x360Controller.inputBuffer[38- x360Controller.hidOffset * 2])) >= 800)) ^ (x360Controller.inputBuffer[8- x360Controller.hidOffset * 2] & (1 << 5))

extern "C" int returnSmaller(int x); //Assembly Function in src/Assembly Functions/assemblyFunctions.s
constexpr DWORD TITLE_SIZE = 1024;
void inline static setButtons(controller& x360Controller) {

// Normal Order
x360Controller.ControllerState.Gamepad.wButtons = (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 4)) ? XINPUT_GAMEPAD_X : 0; //Square
x360Controller.ControllerState.Gamepad.wButtons = (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 4)) ? XINPUT_GAMEPAD_X : 0; //Square

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 5)) ? XINPUT_GAMEPAD_A : 0; //Cross
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 5)) ? XINPUT_GAMEPAD_A : 0; //Cross

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 6)) ? XINPUT_GAMEPAD_B : 0; //Circle
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 6)) ? XINPUT_GAMEPAD_B : 0; //Circle

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 7)) ? XINPUT_GAMEPAD_Y : 0; //Triangle
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 7)) ? XINPUT_GAMEPAD_Y : 0; //Triangle

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 0)) ? XINPUT_GAMEPAD_LEFT_SHOULDER : 0; //Left Shoulder
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 0)) ? XINPUT_GAMEPAD_LEFT_SHOULDER : 0; //Left Shoulder

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 1)) ? XINPUT_GAMEPAD_RIGHT_SHOULDER : 0; //Right Shoulder
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 1)) ? XINPUT_GAMEPAD_RIGHT_SHOULDER : 0; //Right Shoulder

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 4)) ? XINPUT_GAMEPAD_BACK : 0; //Select
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 4)) ? XINPUT_GAMEPAD_BACK : 0; //Select

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 5)) ? XINPUT_GAMEPAD_START : 0; //Start
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 5)) ? XINPUT_GAMEPAD_START : 0; //Start

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 6)) ? XINPUT_GAMEPAD_LEFT_THUMB : 0; //Left Thumb
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 6)) ? XINPUT_GAMEPAD_LEFT_THUMB : 0; //Left Thumb

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 7)) ? XINPUT_GAMEPAD_RIGHT_THUMB : 0; //Right thumb
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 7)) ? XINPUT_GAMEPAD_RIGHT_THUMB : 0; //Right thumb

switch ((int)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & 0x0F)) {
switch ((int)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & 0x0F)) {
case 0: x360Controller.ControllerState.Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_UP; break;

case 1: x360Controller.ControllerState.Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_UP + XINPUT_GAMEPAD_DPAD_RIGHT; break;
Expand All @@ -58,33 +58,33 @@ void inline static setButtonsGameProfile(controller& x360Controller) {
extern int buttonMapping[19];

// Normal Order
x360Controller.ControllerState.Gamepad.wButtons = (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 4)) ? buttonMapping[0] : 0; //Square
x360Controller.ControllerState.Gamepad.wButtons = (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 4)) ? buttonMapping[0] : 0; //Square

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 5)) ? buttonMapping[1] : 0; //Cross
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 5)) ? buttonMapping[1] : 0; //Cross

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 6)) ? buttonMapping[2] : 0; //Circle
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 6)) ? buttonMapping[2] : 0; //Circle

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & (1 << 7)) ? buttonMapping[3] : 0; //Triangle
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & (1 << 7)) ? buttonMapping[3] : 0; //Triangle

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 0)) ? buttonMapping[4] : 0; //Left Shoulder
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 0)) ? buttonMapping[4] : 0; //Left Shoulder

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 1)) ? buttonMapping[5] : 0; //Right Shoulder
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 1)) ? buttonMapping[5] : 0; //Right Shoulder

x360Controller.ControllerState.Gamepad.wButtons |= isSelectPressed ? buttonMapping[6] : 0;

x360Controller.ControllerState.Gamepad.wButtons |= isStartPressed ? buttonMapping[7] : 0;

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 6)) ? buttonMapping[8] : 0; //Left Thumb
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 6)) ? buttonMapping[8] : 0; //Left Thumb

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.bluetooth * 2] & (1 << 7)) ? buttonMapping[9] : 0; //Right thumb
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[8 - x360Controller.hidOffset * 2] & (1 << 7)) ? buttonMapping[9] : 0; //Right thumb

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[9 - x360Controller.bluetooth * 2] & (1 << 1)) ? buttonMapping[12] : 0; //Touchpad Button
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[9 - x360Controller.hidOffset * 2] & (1 << 1)) ? buttonMapping[12] : 0; //Touchpad Button

x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[9 - x360Controller.bluetooth * 2] & (1 << 0)) ? buttonMapping[13] : 0; //PS Button
x360Controller.ControllerState.Gamepad.wButtons |= (bool)(x360Controller.inputBuffer[9 - x360Controller.hidOffset * 2] & (1 << 0)) ? buttonMapping[13] : 0; //PS Button

if (buttonMapping[10] == 1) {

switch ((int)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & 0x0f)) {
switch ((int)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & 0x0f)) {

case 0: x360Controller.ControllerState.Gamepad.sThumbLY = 32767; break; //Up

Expand All @@ -105,7 +105,7 @@ void inline static setButtonsGameProfile(controller& x360Controller) {
return;
}

switch ((int)(x360Controller.inputBuffer[7 - x360Controller.bluetooth * 2] & 0x0F)) {
switch ((int)(x360Controller.inputBuffer[7 - x360Controller.hidOffset * 2] & 0x0F)) {
case 0: x360Controller.ControllerState.Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_UP; break;

case 1: x360Controller.ControllerState.Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_UP + XINPUT_GAMEPAD_DPAD_RIGHT; break;
Expand Down Expand Up @@ -135,17 +135,17 @@ void inline getDualShock4Input(controller& x360Controller) {
return;
}

x360Controller.batteryLevel = (x360Controller.inputBuffer[32 - x360Controller.bluetooth * 2] & 15) * 12.5;
x360Controller.batteryLevel = (x360Controller.inputBuffer[32 - x360Controller.hidOffset * 2] & 15) * 12.5;

x360Controller.batteryLevel = returnSmaller(x360Controller.batteryLevel);

x360Controller.ControllerState.Gamepad.sThumbLX = ((x360Controller.inputBuffer[3 - x360Controller.bluetooth * 2] * 257) - 32768);
x360Controller.ControllerState.Gamepad.sThumbLY = (32767 - (x360Controller.inputBuffer[4 - x360Controller.bluetooth * 2] * 257));
x360Controller.ControllerState.Gamepad.sThumbRX = ((x360Controller.inputBuffer[5 - x360Controller.bluetooth * 2] * 257) - 32768);
x360Controller.ControllerState.Gamepad.sThumbRY = (32767 - (x360Controller.inputBuffer[6 - x360Controller.bluetooth * 2] * 257));
x360Controller.ControllerState.Gamepad.sThumbLX = ((x360Controller.inputBuffer[3 - x360Controller.hidOffset * 2] * 257) - 32768);
x360Controller.ControllerState.Gamepad.sThumbLY = (32767 - (x360Controller.inputBuffer[4 - x360Controller.hidOffset * 2] * 257));
x360Controller.ControllerState.Gamepad.sThumbRX = ((x360Controller.inputBuffer[5 - x360Controller.hidOffset * 2] * 257) - 32768);
x360Controller.ControllerState.Gamepad.sThumbRY = (32767 - (x360Controller.inputBuffer[6 - x360Controller.hidOffset * 2] * 257));

x360Controller.ControllerState.Gamepad.bLeftTrigger = x360Controller.inputBuffer[10 - x360Controller.bluetooth * 2];
x360Controller.ControllerState.Gamepad.bRightTrigger = x360Controller.inputBuffer[11 - x360Controller.bluetooth * 2];
x360Controller.ControllerState.Gamepad.bLeftTrigger = x360Controller.inputBuffer[10 - x360Controller.hidOffset * 2];
x360Controller.ControllerState.Gamepad.bRightTrigger = x360Controller.inputBuffer[11 - x360Controller.hidOffset * 2];

if (gameProfileSet) {
setButtonsGameProfile(x360Controller);
Expand All @@ -161,6 +161,7 @@ void sendDualShock4OutputReport(controller& x360Controller) {
extern bool profileOpen;
extern bool lightbarOpen;
extern bool profileEdit;
extern bool rumbleEnabled;

while (true) {
Sleep(4);
Expand All @@ -169,11 +170,11 @@ void sendDualShock4OutputReport(controller& x360Controller) {

outputHID[1] = (byte)(0xC0);

outputHID[3 - x360Controller.bluetooth * 2] = 0x07;
outputHID[4 - x360Controller.bluetooth * 2] = 0x04;
outputHID[3 - x360Controller.hidOffset * 2] = 0x07;
outputHID[4 - x360Controller.hidOffset * 2] = 0x04;

outputHID[6 - x360Controller.bluetooth * 2] = rumble[0]; //Low Rumble
outputHID[7 - x360Controller.bluetooth * 2] = rumble[1]; //High Rumble
outputHID[6 - x360Controller.hidOffset * 2] = rumble[0] * rumbleEnabled; //Low Rumble
outputHID[7 - x360Controller.hidOffset * 2] = rumble[1] * rumbleEnabled; //High Rumble

switch (x360Controller.batteryLevel + lightbarOpen + gameProfileSet + profileEdit) { //Chooses Lightbar Profile, if any of those editors are open then it breaks and sets itself to the currently being edited profile
case 0: x360Controller.RGB[0].Index = 1; break;
Expand All @@ -189,13 +190,13 @@ void sendDualShock4OutputReport(controller& x360Controller) {
}

for (int i = 0; i < 3; i++) {
outputHID[8 + i - x360Controller.bluetooth * 2] = x360Controller.RGB[x360Controller.RGB[0].Index].colors[i] * 255;
outputHID[8 + i - x360Controller.hidOffset * 2] = x360Controller.RGB[x360Controller.RGB[0].Index].colors[i] * 255;
x360Controller.RGB[0].colors[i] = x360Controller.RGB[x360Controller.RGB[0].Index].colors[i];
}

//Send Output Report
if (x360Controller.threadStop) return;
if (!x360Controller.bluetooth) {
if (!x360Controller.hidOffset) {
outputHID[0] = 0x11;
const UINT32 crc = computeCRC32(outputHID, 74);

Expand Down
2 changes: 1 addition & 1 deletion src/ControllerIO/controllerIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct RGB {
struct controller {

unsigned char inputBuffer[574]{};
bool bluetooth;
bool hidOffset;
bool isConnected{false};
bool threadStop{ false };

Expand Down
Loading

0 comments on commit e61ec41

Please sign in to comment.