Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

Commit

Permalink
Allow disable vJoy via config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
jixunmoe committed Feb 23, 2016
1 parent 0d31bcc commit c2cde58
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
1 change: 1 addition & 0 deletions PC/include/settings.h
Expand Up @@ -19,6 +19,7 @@ struct settings {
int mouseSpeed;
int triggerAsAxis;
struct keyMapping A, B, X, Y, L, R, ZL, ZR, Left, Right, Up, Down, Start, Select, Tap;
int bEnableJoy;
};

extern struct settings settings;
Expand Down
8 changes: 8 additions & 0 deletions PC/source/keys.c
Expand Up @@ -45,6 +45,10 @@ void simulateKeyNewpress(unsigned int key) {
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0;
ip.ki.dwFlags = KEYEVENTF_SCANCODE;

if (key == VK_UP || key == VK_DOWN || key == VK_LEFT || key == VK_RIGHT) {
ip.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
}
}

SendInput(1, &ip, sizeof(INPUT));
Expand All @@ -68,6 +72,10 @@ void simulateKeyRelease(unsigned int key) {
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0;
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;

if (key == VK_UP || key == VK_DOWN || key == VK_LEFT || key == VK_RIGHT) {
ip.ki.dwFlags |= KEYEVENTF_EXTENDEDKEY;
}
}

SendInput(1, &ip, sizeof(INPUT));
Expand Down
36 changes: 18 additions & 18 deletions PC/source/main.c
Expand Up @@ -18,6 +18,10 @@ int mi_y, ma_y;
bool readSettings_local ();

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) {
if(!readSettings_local()) {
printf("Couldn't read settings file, using default key bindings.\n");
}

printf("3DS Controller Server %.1f\n", VERSION);
printf("Mod by Jixun: ppsspp for windows support\n");

Expand All @@ -27,7 +31,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
double widthMultiplier = screenWidth / 320.0;
double heightMultiplier = screenHeight / 240.0;

bool vJoy = true;
bool vJoy = !!settings.bEnableJoy;
UINT iInterface = 1;

iReport.wAxisX = JOY_MIDDLE;
Expand Down Expand Up @@ -60,10 +64,6 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
vJoy = false;
}

if(!readSettings_local()) {
printf("Couldn't read settings file, using default key bindings.\n");
}

initNetwork();

char nButtons = GetVJDButtonNumber(iInterface);
Expand Down Expand Up @@ -132,22 +132,22 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
handleKey(KEY_SELECT, settings.Select);
handleKey(KEY_START, settings.Start);

/*
handleKey(KEY_DRIGHT, settings.Right);
handleKey(KEY_DLEFT, settings.Left);
handleKey(KEY_DUP, settings.Up);
handleKey(KEY_DDOWN, settings.Down);
*/
// Modify iReport.bHats instead.
iReport.bHats = -1;
handleDPAD(KEY_DUP, 0);
handleDPAD(KEY_DRIGHT, 1);
handleDPAD(KEY_DDOWN, 2);
handleDPAD(KEY_DLEFT, 3);
if (settings.bEnableJoy) {
iReport.bHats = -1;
handleDPAD(KEY_DUP, 0);
handleDPAD(KEY_DRIGHT, 1);
handleDPAD(KEY_DDOWN, 2);
handleDPAD(KEY_DLEFT, 3);
} else {
handleKey(KEY_DRIGHT, settings.Right);
handleKey(KEY_DLEFT, settings.Left);
handleKey(KEY_DUP, settings.Up);
handleKey(KEY_DDOWN, settings.Down);
}

handleKey(KEY_R, settings.R);
handleKey(KEY_L, settings.L);
if (settings.triggerAsAxis) {
if (settings.triggerAsAxis && settings.bEnableJoy) {
// Due to lack support of 9/10th axis emulation,
// It's unable to emulate LT and RT for game
// Ori and the Blind Forest.
Expand Down
23 changes: 14 additions & 9 deletions PC/source/settings.c
Expand Up @@ -17,21 +17,22 @@ struct settings defaultSettings = {
touch: mouse,
mouseSpeed: 4,
triggerAsAxis: 1,
A: { 1, {'A'} },
B: { 1, {'B'} },
X: { 1, {'X'} },
Y: { 1, {'Y'} },
L: { 1, {'L'} },
R: { 1, {'R'} },
ZL: { 1, {'Q'} },
ZR: { 1, {'W'} },
A: { 0, {'A'} },
B: { 0, {'B'} },
X: { 0, {'X'} },
Y: { 0, {'Y'} },
L: { 0, {'L'} },
R: { 0, {'R'} },
ZL: { 0, {'Q'} },
ZR: { 0, {'W'} },
Left: { 0, {VK_LEFT} },
Right: { 0, {VK_RIGHT} },
Up: { 0, {VK_UP} },
Down: { 0, {VK_DOWN} },
Start: { 0, {VK_RETURN} },
Select: { 0, {VK_BACK} },
Tap: { 0, {'T'} },
Tap: { 0, {'T'} },
bEnableJoy: 1
};

unsigned int readNumber (char *str) {
Expand Down Expand Up @@ -162,6 +163,10 @@ bool readSettings(LPSTR lpConfigFile) {
if(getSetting("TriggerAsAxis: ", buffer, setting)) {
sscanf(setting, "%d", &settings.triggerAsAxis);
}

if(getSetting("EnableJoy: ", buffer, setting)) {
sscanf(setting, "%d", &settings.bEnableJoy);
}

if(getSetting("Throttle: ", buffer, setting)) {
sscanf(setting, "%d", &settings.throttle);
Expand Down

0 comments on commit c2cde58

Please sign in to comment.