Skip to content

Commit

Permalink
Improvements: icon, exit button & fix button names
Browse files Browse the repository at this point in the history
  • Loading branch information
r57zone committed Mar 5, 2021
1 parent e578273 commit e06727a
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 131 deletions.
34 changes: 18 additions & 16 deletions README.RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
------------ | -------------
Uncharted 3: Иллюзии Дрейка (2011) | Кнопка "Share" (F12) дублирует нажатие левой части тачпада.

Свайпы тачпада пока не поддерживаются, вы не сможете поиграть в такие игры, как: Until Dawn.

## Гироскоп
Эмуляция гироскопа не поддерживается.

Expand All @@ -32,23 +34,23 @@ Uncharted 3: Иллюзии Дрейка (2011) | Кнопка "Share" (F12) д

DualShock 4 | Клавиатура и мышь
------------ | -------------
LEFT TRIGGER | Правая кнопка мыши
RIGHT TRIGGER | Левая кнопка мыши
LEFT SHOULDER | Control
RIGHT SHOULDER | Alt
DPAD UP | 1
DPAD LEFT | 2
DPAD RIGHT | 3
DPAD DOWN | 4
LEFT THUMB | Shift
RIGHT THUMB | Средняя кнопка мыши
TRIANGLE | Q
SQUARE | E
CIRCLE | R
CROSS | Space
TOUCHPAD | Enter
OPTIONS | Tab
L1 | Control
R2 | Alt
L2 | Правая кнопка мыши
R2 | Левая кнопка мыши
SHARE | F12
TOUCHPAD (нажатие тачпада) | Enter
OPTIONS | Tab
DPAD UP (стрелка вверх) | 1
DPAD LEFT (стрелка влево) | 2
DPAD RIGHT (стрелка вправо) | 3
DPAD DOWN (стрелка вниз) | 4
TRIANGLE (треугольник) | Q
SQUARE (квадрат) | E
CIRCLE (круг) | R
CROSS (крестик) | Space
L3 (нажатие стика) | Shift
R3 (нажатие стика) | Средняя кнопка мыши

В конфигурационном файле "Config.ini" можно заменить привязки кнопок. Коды кнопок можно найти [здесь](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.RU.md).

Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Game | Action
------------ | -------------
Uncharted 3: Drake’s Deception (2011) | The "Share" button (F12) duplicates pressing the left side of the touchpad.

Touchpad swipes are not yet supported, you will not be able to play games like: Until Dawn.

## Gyroscope
Gyro emulation is not supported.

Expand All @@ -32,23 +34,23 @@ By default, the mouse and keyboard only work in "PlayStation Now". You can enabl

DualShock 4 | Keyboard and mouse
------------ | -------------
LEFT TRIGGER | Right mouse button
RIGHT TRIGGER | Left mouse button
LEFT SHOULDER | Control
RIGHT SHOULDER | Alt
L1 | Control
R1 | Alt
L2 | Right mouse button
R2 | Left mouse button
SHARE | F12
TOUCHPAD (pressing) | Enter
OPTIONS | Tab
DPAD UP | 1
DPAD LEFT | 2
DPAD RIGHT | 3
DPAD DOWN | 4
LEFT THUMB | Shift
RIGHT THUMB | Middle mouse button
TRIANGLE | Q
SQUARE | E
CIRCLE | R
CROSS | Space
TOUCHPAD | Enter
OPTIONS | Tab
SHARE | F12
L3 (pressing the stick) | Shift
R3 (pressing the stick) | Middle mouse button

Сan replace button bindings in the "Config.ini" configuration file. Button codes can be found [here](https://github.com/r57zone/Half-Life-Alyx-novr/blob/master/BINDINGS.md). B

Expand Down
101 changes: 42 additions & 59 deletions Source/DS4Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <mutex>
#include "IniReader\IniReader.h"

//XInput headers
// XInput headers
#define XINPUT_GAMEPAD_DPAD_UP 0x0001
#define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
#define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
Expand All @@ -27,7 +27,7 @@
#define ERROR_DEVICE_NOT_CONNECTED 1167
#define ERROR_SUCCESS 0

//XInput structures
// XInput structures
typedef struct _XINPUT_GAMEPAD
{
WORD wButtons;
Expand Down Expand Up @@ -86,25 +86,6 @@ DWORD XboxUserIndex = 0;

static std::mutex m;

//Key bindings
int KEY_ID_LEFT_TRIGGER;
int KEY_ID_RIGHT_TRIGGER;
int KEY_ID_LEFT_SHOULDER;
int KEY_ID_RIGHT_SHOULDER;
int KEY_ID_DPAD_UP;
int KEY_ID_DPAD_DOWN;
int KEY_ID_DPAD_LEFT;
int KEY_ID_DPAD_RIGHT;
int KEY_ID_LEFT_THUMB;
int KEY_ID_RIGHT_THUMB;
int KEY_ID_TRIANGLE;
int KEY_ID_SQUARE;
int KEY_ID_CIRCLE;
int KEY_ID_CROSS;
int KEY_ID_TOUCHPAD;
int KEY_ID_OPTIONS;
int KEY_ID_SHARE;

int m_HalfWidth = 1920 / 2;
int m_HalfHeight = 1080 / 2;
float mouseSensetiveY;
Expand Down Expand Up @@ -166,8 +147,10 @@ int main(int argc, char **argv)
#define KBMode 0
int EmulationMode = KBMode;

//Config
// Config
CIniReader IniFile("Config.ini");
int KEY_ID_EXIT = IniFile.ReadInteger("Main", "ExitBtn", 192); // "~" by default

bool InvertX = IniFile.ReadBoolean("DS4", "InvertX", false);
bool InvertY = IniFile.ReadBoolean("DS4", "InvertY", false);

Expand All @@ -185,23 +168,23 @@ int main(int argc, char **argv)
mouseSensetiveX = IniFile.ReadFloat("KeyboardMouse", "SensX", 15);
mouseSensetiveY = IniFile.ReadFloat("KeyboardMouse", "SensY", 15);

KEY_ID_LEFT_TRIGGER = IniFile.ReadInteger("Keys", "LEFT_TRIGGER", VK_RBUTTON);
KEY_ID_RIGHT_TRIGGER = IniFile.ReadInteger("Keys", "RIGHT_TRIGGER", VK_LBUTTON);
KEY_ID_LEFT_SHOULDER = IniFile.ReadInteger("Keys", "LEFT_SHOULDER", VK_CONTROL);
KEY_ID_RIGHT_SHOULDER = IniFile.ReadInteger("Keys", "RIGHT_SHOULDER", VK_MENU);
KEY_ID_DPAD_UP = IniFile.ReadInteger("Keys", "DPAD_UP", '1');
KEY_ID_DPAD_LEFT = IniFile.ReadInteger("Keys", "DPAD_LEFT", '2');
KEY_ID_DPAD_RIGHT = IniFile.ReadInteger("Keys", "DPAD_RIGHT", '3');
KEY_ID_DPAD_DOWN = IniFile.ReadInteger("Keys", "DPAD_DOWN", '4');
KEY_ID_LEFT_THUMB = IniFile.ReadInteger("Keys", "LEFT_THUMB", VK_LSHIFT);
KEY_ID_RIGHT_THUMB = IniFile.ReadInteger("Keys", "RIGHT_THUMB", VK_MBUTTON);
KEY_ID_TRIANGLE = IniFile.ReadInteger("Keys", "TRIANGLE", 'Q');
KEY_ID_SQUARE = IniFile.ReadInteger("Keys", "SQUARE", 'E');
KEY_ID_CIRCLE = IniFile.ReadInteger("Keys", "CIRCLE", 'R');
KEY_ID_CROSS = IniFile.ReadInteger("Keys", "CROSS", VK_SPACE);
KEY_ID_TOUCHPAD = IniFile.ReadInteger("Keys", "TOUCHPAD", VK_RETURN);
KEY_ID_OPTIONS = IniFile.ReadInteger("Keys", "OPTIONS", VK_TAB);
KEY_ID_SHARE = IniFile.ReadInteger("Keys", "SHARE", VK_F12);
int KEY_ID_LEFT_TRIGGER = IniFile.ReadInteger("Keys", "L2", VK_RBUTTON);
int KEY_ID_RIGHT_TRIGGER = IniFile.ReadInteger("Keys", "R2", VK_LBUTTON);
int KEY_ID_LEFT_SHOULDER = IniFile.ReadInteger("Keys", "L1", VK_CONTROL);
int KEY_ID_RIGHT_SHOULDER = IniFile.ReadInteger("Keys", "R1", VK_MENU);
int KEY_ID_DPAD_UP = IniFile.ReadInteger("Keys", "DPAD_UP", '1');
int KEY_ID_DPAD_LEFT = IniFile.ReadInteger("Keys", "DPAD_LEFT", '2');
int KEY_ID_DPAD_RIGHT = IniFile.ReadInteger("Keys", "DPAD_RIGHT", '3');
int KEY_ID_DPAD_DOWN = IniFile.ReadInteger("Keys", "DPAD_DOWN", '4');
int KEY_ID_LEFT_THUMB = IniFile.ReadInteger("Keys", "L3", VK_LSHIFT);
int KEY_ID_RIGHT_THUMB = IniFile.ReadInteger("Keys", "R3", VK_MBUTTON);
int KEY_ID_TRIANGLE = IniFile.ReadInteger("Keys", "TRIANGLE", 'Q');
int KEY_ID_SQUARE = IniFile.ReadInteger("Keys", "SQUARE", 'E');
int KEY_ID_CIRCLE = IniFile.ReadInteger("Keys", "CIRCLE", 'R');
int KEY_ID_CROSS = IniFile.ReadInteger("Keys", "CROSS", VK_SPACE);
int KEY_ID_TOUCHPAD = IniFile.ReadInteger("Keys", "TOUCHPAD", VK_RETURN);
int KEY_ID_OPTIONS = IniFile.ReadInteger("Keys", "OPTIONS", VK_TAB);
int KEY_ID_SHARE = IniFile.ReadInteger("Keys", "SHARE", VK_F12);

const auto client = vigem_alloc();
auto ret = vigem_connect(client);
Expand All @@ -213,8 +196,8 @@ int main(int argc, char **argv)

printf("Press \"~\" key to exit\r\n");

//Load library and scan Xbox gamepads only in Xbox mode (default)
hDll = LoadLibrary("xinput1_3.dll"); //x360ce support
// Load library and scan Xbox gamepads
hDll = LoadLibrary("xinput1_3.dll"); // x360ce support
if (hDll != NULL) {
MyXInputGetState = (_XInputGetState)GetProcAddress(hDll, "XInputGetState");
MyXInputSetState = (_XInputSetState)GetProcAddress(hDll, "XInputSetState");
Expand All @@ -236,36 +219,36 @@ int main(int argc, char **argv)
m_HalfHeight = GetSystemMetrics(SM_CYSCREEN) / 2;
}

//Title
// Title
if (EmulationMode == XboxMode)
SetConsoleTitle("DS4Emulator: Xbox controller mode");
else
SetConsoleTitle("DS4Emulator: keyboard and mouse mode");

while (!(GetAsyncKeyState(192) & 0x8000)) //~
while (!(GetAsyncKeyState(KEY_ID_EXIT) & 0x8000)) // "~" by default
{
DS4_REPORT_INIT(&report);

//Xbox mode
// Xbox mode
if (EmulationMode == XboxMode) {
DWORD myStatus = ERROR_DEVICE_NOT_CONNECTED;
if (hDll != NULL)
myStatus = MyXInputGetState(XboxUserIndex, &myPState);

if (myStatus == ERROR_SUCCESS) {

//Convert axis from - https://github.com/sam0x17/XJoy/blob/236b5539cc15ea1c83e1e5f0260937f69a78866d/Include/ViGEmUtil.h
// Convert axis from - https://github.com/sam0x17/XJoy/blob/236b5539cc15ea1c83e1e5f0260937f69a78866d/Include/ViGEmUtil.h
report.bThumbLX = ((myPState.Gamepad.sThumbLX + ((USHRT_MAX / 2) + 1)) / 257);
report.bThumbLY = (-(myPState.Gamepad.sThumbLY + ((USHRT_MAX / 2) - 1)) / 257);
report.bThumbLY = (report.bThumbLY == 0) ? 0xFF : report.bThumbLY;

//Inverting X
// Inverting X
if (InvertX == false)
report.bThumbRX = ((myPState.Gamepad.sThumbRX + ((USHRT_MAX / 2) + 1)) / 257);
else
report.bThumbRX = ((-myPState.Gamepad.sThumbRX + ((USHRT_MAX / 2) + 1)) / 257);

//Inverting Y
// Inverting Y
if (InvertY == false)
report.bThumbRY = (-(myPState.Gamepad.sThumbRY + ((USHRT_MAX / 2) + 1)) / 257);
else
Expand All @@ -276,7 +259,7 @@ int main(int argc, char **argv)
if (myPState.Gamepad.wButtons & XINPUT_GAMEPAD_START)
report.wButtons |= DS4_BUTTON_OPTIONS;

//Swap share and touchpad
// Swap share and touchpad
if (SwapShareTouchPad == false) {
if ((GetAsyncKeyState(KEY_ID_SHARE) & 0x8000) != 0)
report.wButtons |= DS4_BUTTON_SHARE;
Expand Down Expand Up @@ -304,7 +287,7 @@ int main(int argc, char **argv)
if (myPState.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB)
report.wButtons |= DS4_BUTTON_THUMB_RIGHT;

//Swap triggers and shoulders
// Swap triggers and shoulders
if (SwapTriggersShoulders == false) {
if (myPState.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)
report.wButtons |= DS4_BUTTON_SHOULDER_LEFT;
Expand All @@ -325,10 +308,9 @@ int main(int argc, char **argv)
report.bTriggerR = 255;
}

//Strange specific of DualShock
if (report.bTriggerL > 0)
if (report.bTriggerL > 0) // Specific of DualShock
report.wButtons |= DS4_BUTTON_TRIGGER_LEFT;
if (report.bTriggerR > 0)
if (report.bTriggerR > 0) // Specific of DualShock
report.wButtons |= DS4_BUTTON_TRIGGER_RIGHT;

if (myPState.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP)
Expand All @@ -350,7 +332,7 @@ int main(int argc, char **argv)
DS4_SET_DPAD(&report, DS4_BUTTON_DPAD_SOUTHEAST);
}
}
//Mouse and keyboard mode
// Mouse and keyboard mode
else if (EmulationMode == KBMode) {

PSNowWindow = FindWindow(NULL, WindowTitle.c_str());
Expand All @@ -364,7 +346,7 @@ int main(int argc, char **argv)
if (InvertY)
DeltaMouseY = DeltaMouseY * -1;

//Are there better options? / Åñòü âàðèàíò ëó÷øå?
// Are there better options? / Åñòü âàðèàíò ëó÷øå?
if (DeltaMouseX > 0)
report.bThumbRX = 128 + round( Clamp( DeltaMouseX * mouseSensetiveX, 0, 127) );
if (DeltaMouseX < 0)
Expand All @@ -386,14 +368,14 @@ int main(int argc, char **argv)
if ((GetAsyncKeyState(KEY_ID_RIGHT_TRIGGER) & 0x8000) != 0)
report.bTriggerR = 255;
}
else { //With emulate analog triggers
else { // With emulate analog triggers

if ((GetAsyncKeyState(KEY_ID_LEFT_TRIGGER) & 0x8000) != 0) {
if (LeftTriggerValue < 255)
LeftTriggerValue += StepTriggerValue;
}
else {
//LeftTriggerValue = 0;
// LeftTriggerValue = 0;
if (LeftTriggerValue > 0)
LeftTriggerValue -= StepTriggerValue;
}
Expand All @@ -405,17 +387,18 @@ int main(int argc, char **argv)
RightTriggerValue += StepTriggerValue;
}
else {
//RightTriggerValue = 0;
// RightTriggerValue = 0;
if (RightTriggerValue > 0)
RightTriggerValue -= StepTriggerValue;
}

report.bTriggerR = Clamp(round(RightTriggerValue), 0, 255);
}

if (report.bTriggerL > 0) //Strange specific of DualShock

if (report.bTriggerL > 0) // Specific of DualShock
report.wButtons |= DS4_BUTTON_TRIGGER_LEFT;
if (report.bTriggerR > 0) //Strange specific of DualShock
if (report.bTriggerR > 0) // Specific of DualShock
report.wButtons |= DS4_BUTTON_TRIGGER_RIGHT;

if ((GetAsyncKeyState(KEY_ID_OPTIONS) & 0x8000) != 0)
Expand Down
9 changes: 9 additions & 0 deletions Source/DS4Emulator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@
<Project>{7db06674-1f4f-464b-8e1c-172e9587f9dc}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Image Include="Icon.ico" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
Binary file added Source/Icon.ico
Binary file not shown.
47 changes: 0 additions & 47 deletions Source/IniReader/README.md

This file was deleted.

Binary file added Source/Resource.aps
Binary file not shown.
Binary file added Source/Resource.rc
Binary file not shown.
Loading

0 comments on commit e06727a

Please sign in to comment.