diff --git a/PC/3DSController.exe b/PC/3DSController.exe index e60e4c6..5b54716 100644 Binary files a/PC/3DSController.exe and b/PC/3DSController.exe differ diff --git a/PC/include/general.h b/PC/include/general.h index 2b7622f..39f4d5f 100644 --- a/PC/include/general.h +++ b/PC/include/general.h @@ -3,3 +3,5 @@ #include void error(const char *functionName); + +int clamp(int val, int min, int max); diff --git a/PC/source/general.c b/PC/source/general.c index bf7e137..402acdc 100644 --- a/PC/source/general.c +++ b/PC/source/general.c @@ -5,14 +5,26 @@ void error(const char *functionName) { char errorMsg[92]; ZeroMemory(errorMsg, 92); - + sprintf(errorMsg, "Call to %s returned error %d!", (char *)functionName, WSAGetLastError()); - + MessageBox(NULL, errorMsg, "socketIndication", MB_OK); - + closesocket(client); closesocket(listener); WSACleanup(); - + exit(0); } + +int clamp (int val, int min, int max) { + if (val < min) { + return min; + } + + if (val > max) { + return max; + } + + return val; +} diff --git a/PC/source/main.c b/PC/source/main.c index 54504b3..959c375 100644 --- a/PC/source/main.c +++ b/PC/source/main.c @@ -200,51 +200,51 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) joyX = 16383; //Halfway between the x joyY = 16383; //Halfway between the y } - + else if(settings.touch == joystick2) { joyRX = 16383; //Halfway between the rx joyRY = 16383; //Halfway between the ry } } - + if(settings.circlePad == mouse) { if(abs(circlePad.x) < settings.mouseSpeed * 3) circlePad.x = 0; if(abs(circlePad.y) < settings.mouseSpeed * 3) circlePad.y = 0; - + POINT p; GetCursorPos(&p); SetCursorPos(p.x + (circlePad.x * settings.mouseSpeed) / 32, p.y - (circlePad.y * settings.mouseSpeed) / 32); } else if(settings.circlePad == joystick1) { - joyX = (circlePad.x + 128) * 128; - joyY = (128 - circlePad.y) * 128; + joyX = clamp((circlePad.x + 128) * 128, 0, 32767); + joyY = clamp((128 - circlePad.y) * 128, 0, 32767); } - + else if(settings.circlePad == joystick2) { - joyRX = (circlePad.x + 128) * 128; - joyRY = (128 - circlePad.y) * 128; + joyRX = clamp((circlePad.x + 128) * 128, 0, 32767); + joyRY = clamp((128 - circlePad.y) * 128, 0, 32767); } - + if(settings.cStick == mouse) { if(abs(cStick.x) < settings.mouseSpeed * 3) cStick.x = 0; if(abs(cStick.y) < settings.mouseSpeed * 3) cStick.y = 0; - + POINT p; GetCursorPos(&p); SetCursorPos(p.x + (cStick.x * settings.mouseSpeed) / 32, p.y - (cStick.y * settings.mouseSpeed) / 32); } - + else if(settings.cStick == joystick1) { - joyX = (cStick.x + 128) * 128; - joyY = (128 - cStick.y) * 128; + joyX = clamp((cStick.x + 128) * 128, 0, 32767); + joyY = clamp((128 - cStick.y) * 128, 0, 32767); } - + else if(settings.cStick == joystick2) { - joyRX = (cStick.x + 128) * 128; - joyRY = (128 - cStick.y) * 128; + joyRX = clamp((cStick.x + 128) * 128, 0, 32767); + joyRY = clamp((128 - cStick.y) * 128, 0, 32767); } - - + + if(settings.dPad == cPov) { if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) { if((currentKeys & KEY_DRIGHT)) {