diff --git a/3DS/source/main.c b/3DS/source/main.c deleted file mode 100644 index a9c9746..0000000 --- a/3DS/source/main.c +++ /dev/null @@ -1,174 +0,0 @@ -#include -#include -#include -#include - -#include <3ds.h> - -#include "3ds/services/soc.h" -#include "wireless.h" -#include "settings.h" -#include "drawing.h" -#include "input.h" -#include "keyboard.h" - -static jmp_buf exitJmp; - -void hang(char *message) { - while(aptMainLoop()) { - hidScanInput(); - - clearScreen(); - drawString(10, 10, "%s", message); - drawString(10, 20, "Start and Select to exit"); - - u32 kHeld = hidKeysHeld(); - if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) longjmp(exitJmp, 1); - - gfxFlushBuffers(); - gspWaitForVBlank(); - gfxSwapBuffers(); - } -} - -int main(void) { - acInit(); - gfxInitDefault(); - - gfxSetDoubleBuffering(GFX_TOP, true); - gfxSetDoubleBuffering(GFX_BOTTOM, true); - - if(setjmp(exitJmp)) goto exit; - - // preRenderKeyboard(); - - clearScreen(); - drawString(10, 10, "Initing FS..."); - gfxFlushBuffers(); - gfxSwapBuffers(); - - fsInit(); - - clearScreen(); - drawString(10, 10, "Initing SOC..."); - gfxFlushBuffers(); - gfxSwapBuffers(); - - socInit((u32 *)memalign(0x1000, 0x100000), 0x100000); - - u32 wifiStatus = 0; - ACU_GetWifiStatus(&wifiStatus); - if(!wifiStatus) { - hang("No WiFi! Is your wireless slider on?"); - } - - clearScreen(); - drawString(10, 10, "Reading settings..."); - gfxFlushBuffers(); - gfxSwapBuffers(); - - if(!readSettings()) { - hang("Could not read 3DSController.ini!"); - } - - clearScreen(); - drawString(10, 10, "Connecting to %s on port %d...", settings.IPString, settings.port); - gfxFlushBuffers(); - gfxSwapBuffers(); - - openSocket(settings.port); - sendConnectionRequest(); - - // clearScreen(); - gfxFlushBuffers(); - gfxSwapBuffers(); - - disableBacklight(); - - while(aptMainLoop()) { - hidScanInput(); - irrstScanInput(); - - u32 kHeld = hidKeysHeld(); - circlePosition circlePad; - circlePosition cStick; - u8 vol8; - u8* volp = &vol8; //As a test for pointing at things. - hidCstickRead(&cStick); - hidCircleRead(&circlePad); - HIDUSER_GetSoundVolume(volp); - u32 volume = (u32)vol8; //Upscale to 32 for transmission - touchPosition touch; - touchRead(&touch); - - clearScreen(); - - if((kHeld & KEY_L) && (kHeld & KEY_R) && (kHeld & KEY_X)) { - if(keyboardToggle) { - keyboardActive = !keyboardActive; - keyboardToggle = false; - - if(keyboardActive) { - enableBacklight(); - } else { - disableBacklight(); - } - } - } - else keyboardToggle = true; - - if(keyboardActive) { - drawKeyboard(); - - if(touch.px >= 1 && touch.px <= 312 && touch.py >= 78 && touch.py <= 208) { - int x = (int)((float)touch.px * 12.0f / 320.0f); - int y = (int)((float)(touch.py - 78) * 12.0f / 320.0f); - int width = 24; - int height = 24; - - if(keyboardChars[x + y * 12] == ' ') { - while(keyboardChars[(x - 1) + y * 12] == ' ') x--; - - width = (int)(5.0f * 320.0f / 12.0f) - 1; - } - - else if(keyboardChars[x + y * 12] == '\13') { - while(keyboardChars[(x - 1) + y * 12] == '\13') x--; - while(keyboardChars[x + (y - 1) * 12] == '\13') y--; - - width = (int)(2.0f * 320.0f / 12.0f) - 1; - height = (int)(3.0f * 320.0f / 12.0f) - 1; - } - - if(keyboardChars[x + y * 12]) drawBox((int)((float)x * 320.0f / 12.0f) + 1, (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, width, height, 31, 31, 0); - } - } - - sendKeys(kHeld, circlePad, touch, cStick, volume); - //drawString(10, 10, "Volume: %x", volume); - //receiveBuffer(sizeof(struct packet)); - - if((kHeld & KEY_START) && (kHeld & KEY_SELECT)) { - sendKeys(0, circlePad, touch, cStick, volume); - longjmp(exitJmp, 1); - } - - gfxFlushBuffers(); - gspWaitForVBlank(); - gfxSwapBuffers(); - } - - exit: - - enableBacklight(); - - socExit(); - - svcCloseHandle(fileHandle); - fsExit(); - - gfxExit(); - acExit(); - - return 0; -} diff --git a/3DS/source/wireless.c b/3DS/source/wireless.c deleted file mode 100644 index 8abe2c8..0000000 --- a/3DS/source/wireless.c +++ /dev/null @@ -1,50 +0,0 @@ -#include - -#include "keyboard.h" - -#include "wireless.h" - -int sock; -struct sockaddr_in sain, saout; -struct packet outBuf, rcvBuf; - -socklen_t sockaddr_in_sizePtr = (int)sizeof(struct sockaddr_in); - -bool openSocket(int port) { - sock = socket(AF_INET, SOCK_DGRAM, 0); - - saout.sin_family = sain.sin_family = AF_INET; - saout.sin_port = sain.sin_port = htons(port); - sain.sin_addr.s_addr = INADDR_ANY; - - bind(sock, (struct sockaddr *)&sain, sizeof(sain)); - - fcntl(sock, F_SETFL, O_NONBLOCK); - - return true; -} - -void sendBuf(int length) { - sendto(sock, (char *)&outBuf, length, 0, (struct sockaddr *)&saout, sizeof(saout)); -} - -int receiveBuffer(int length) { - return recvfrom(sock, (char *)&rcvBuf, length, 0, (struct sockaddr *)&sain, &sockaddr_in_sizePtr); -} - -void sendConnectionRequest(void) { - outBuf.command = CONNECT; - outBuf.keyboardActive = keyboardActive; - sendBuf(offsetof(struct packet, connectPacket) + sizeof(struct connectPacket)); -} - -void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume) { - outBuf.command = KEYS; - outBuf.keyboardActive = keyboardActive; - memcpy(&outBuf.keys, &keys, 4); - memcpy(&outBuf.circlePad, &circlePad, 4); - memcpy(&outBuf.touch, &touch, 4); - memcpy(&outBuf.cStick, &cStick, 4); - memcpy(&outBuf.volume, &volume, 4); - sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket)); -} diff --git a/3DS_Controller-evdev.py b/3DS_Controller-evdev.py new file mode 100755 index 0000000..543367d --- /dev/null +++ b/3DS_Controller-evdev.py @@ -0,0 +1,232 @@ +#!/usr/bin/env python +# Compatible with python 3.11, NOT TESTED IN OLD VERSIONS OF PYTHON + +from __future__ import print_function +import socket, struct, time +# EVDEV: https://python-evdev.readthedocs.io/en/latest/tutorial.html#specifying-uinput-device-options +import evdev +from evdev import UInput, AbsInfo, ecodes as e + +########################################################## +# CONFIGURABLE REGION START - Don't touch anything above # +########################################################## +port = 42020 +# Set the debug variable to 1 to print Debug information +debug = 1 + +# Valid values can be found in any of these locations on your Linux system (some may not exist): +# /usr/include/linux/input-event-codes.h +# The virtual device is defined on the device variable and the mapping of the keys on btn_map +# RECAP keynames (DO NOT TOUCH) are the keys that we expect commming from the 3ds, device is +# the virtual device that we define and btn_map maps what we recieve with our virtual device +btn_map = { + "A": e.BTN_A, + "B": e.BTN_B, + "X": e.BTN_X, + "Y": e.BTN_Y, + "L": e.BTN_TL, + "R": e.BTN_TR, + "ZL": e.BTN_THUMBL, + "ZR": e.BTN_THUMBR, + "Left": e.BTN_DPAD_LEFT, + "Right": e.BTN_DPAD_RIGHT, + "Up": e.BTN_DPAD_UP, + "Down": e.BTN_DPAD_DOWN, + "Start": e.BTN_START, + "Select": e.BTN_SELECT, + "Tap": e.BTN_MODE +} + +device = { + # EV_ABS is for Absolute movement with static values, + # like the sticks and the volume + e.EV_ABS: [ + (e.ABS_X, AbsInfo(0, -159, 159, 0, 10, 0)), + (e.ABS_Y, AbsInfo(0, -159, 159, 0, 10, 0)), + (e.ABS_RX, AbsInfo(0, -146, 146, 0, 16, 0)), + (e.ABS_RY, AbsInfo(0, -146, 146, 0, 16, 0)), + (e.ABS_VOLUME, AbsInfo(0, 0, 63, 0, 0, 0)), + ], + # The keys lol + e.EV_KEY: [ + e.BTN_A, + e.BTN_B, + e.BTN_X, + e.BTN_Y, + e.BTN_TL, + e.BTN_TR, + e.BTN_THUMBL, + e.BTN_THUMBR, + e.BTN_DPAD_LEFT, + e.BTN_DPAD_RIGHT, + e.BTN_DPAD_UP, + e.BTN_DPAD_DOWN, + e.BTN_START, + e.BTN_SELECT, + e.BTN_MODE, + ], +} + +ui = UInput(device, name="3DS", phys="3ds-uinput", vendor=0x1, version=0x1, product=0x1) + +gyroAxis = { + e.EV_ABS: [ + e.ABS_X, + e.ABS_Y, + e.ABS_Z, + e.ABS_RX, + e.ABS_RY, + e.ABS_RZ + ] +} + +uiGyro = UInput(gyroAxis, name="3DS Gyroscope", phys="3ds-sensors", vendor=0x2, version=0x2, product=0x2, input_props=[6]) + +if (debug): + print (ui) + +######################################################## +# CONFIGURABLE REGION END - Don't touch anything below # +######################################################## + +class x: pass + +command = x() +command.CONNECT = 0 +command.KEYS = 1 +command.SCREENSHOT = 2 + +keynames = [ + "A", "B", "Select", "Start", "Right", "Left", "Up", "Down", + "R", "L", "X", "Y", None, None, "ZL", "ZR", + None, None, None, None, "Tap", None, None, None, + "CSRight", "CSLeft", "CSUp", "CSDown", "CRight", "CLeft", "CUp", "CDown", +] + +keys = x() +keys.A = 1<<0 +keys.B = 1<<1 +keys.Select = 1<<2 +keys.Start = 1<<3 +keys.Right = 1<<4 +keys.Left = 1<<5 +keys.Up = 1<<6 +keys.Down = 1<<7 +keys.R = 1<<8 +keys.L = 1<<9 +keys.X = 1<<10 +keys.Y = 1<<11 +keys.ZL = 1<<14 # (new 3DS only) +keys.ZR = 1<<15 # (new 3DS only) +keys.Tap = 1<<20 # Not actually provided by HID +keys.CSRight = 1<<24 # c-stick (new 3DS only) +keys.CSLeft = 1<<25 # c-stick (new 3DS only) +keys.CSUp = 1<<26 # c-stick (new 3DS only) +keys.CSDown = 1<<27 # c-stick (new 3DS only) +keys.CRight = 1<<28 # circle pad +keys.CLeft = 1<<29 # circle pad +keys.CUp = 1<<30 # circle pad +keys.CDown = 1<<31 # circle pad + +def press_key(key): + ui.write(e.EV_KEY, key, 1) + ui.syn() + +def release_key(key): + ui.write(e.EV_KEY,key, 0) + ui.syn() + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.bind(("", port)) + +prevkeys = 0 + +touch_start = 0 +touch_last_x = 0 +touch_last_y = 0 + +while True: + rawdata, addr = sock.recvfrom(4092) + rawdata = bytearray(rawdata) + # print("Received message", rawdata) + + if rawdata[0]==command.CONNECT: + print("Connected with 3DS at address", addr) + pass # CONNECT packets are empty + + if rawdata[0]==command.KEYS: + # Just to explain this fuckery of struct.unpack: + # struct settings { diff --git a/3DS/include/wireless.h b/3DSsource/include/wireless.h similarity index 66% rename from 3DS/include/wireless.h rename to 3DSsource/include/wireless.h index 6ad6983..3688106 100644 --- a/3DS/include/wireless.h +++ b/3DSsource/include/wireless.h @@ -1,18 +1,17 @@ #pragma once #include - #include <3ds.h> - #include #include #include #include #include - +#include "3ds/services/hid.h" #include "inet_pton.h" +#include "sys/_types.h" -#define SCREENSHOT_CHUNK 4000 +// #define SCREENSHOT_CHUNK 4000 #define DEFAULT_PORT 8889 @@ -43,36 +42,60 @@ struct packet { // KEYS union { struct keysPacket { + //Keys unsigned int keys; + //Cirle Pad struct { short x; short y; } circlePad; + //Touchpad struct { unsigned short x; unsigned short y; } touch; + //cStick struct { short x; short y; } cStick; + //Volume unsigned int volume; //way longer than needed, but it works. + + //Gyroscope + struct { + short x; + short y; + short z; + } gyro; + + unsigned char padding; + + //Accelerometer + struct { + short x; + short y; + short z; + } accel; + + // unsigned int threeD32; }; struct keysPacket keysPacket; }; // SCREENSHOT - union { - struct screenshotPacket { - unsigned short offset; - unsigned char data[SCREENSHOT_CHUNK]; - }; - struct screenshotPacket screenshotPacket; - }; + // union { + // struct screenshotPacket { + // unsigned short offset; + // unsigned char data[SCREENSHOT_CHUNK]; + // }; + // struct screenshotPacket screenshotPacket; + // }; + // This is not even used so... }; }; @@ -86,4 +109,4 @@ bool openSocket(int port); void sendBuf(int length); int receiveBuffer(int length); void sendConnectionRequest(void); -void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume); +void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, circlePosition cStick, unsigned int volume, angularRate gyro, accelVector accel); diff --git a/3DS/source/drawing.c b/3DSsource/source/drawing.c similarity index 99% rename from 3DS/source/drawing.c rename to 3DSsource/source/drawing.c index e248ae2..93eddf7 100644 --- a/3DS/source/drawing.c +++ b/3DSsource/source/drawing.c @@ -169,6 +169,8 @@ void disableBacklight() { GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTSUB, &off, 4); } + + void enableBacklight() { GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTMAIN, &brightnessMain, 4); GSPGPU_WriteHWRegs(REG_LCDBACKLIGHTSUB, &brightnessSub, 4); diff --git a/3DS/source/inet_pton.c b/3DSsource/source/inet_pton.c similarity index 100% rename from 3DS/source/inet_pton.c rename to 3DSsource/source/inet_pton.c diff --git a/3DS/source/input.c b/3DSsource/source/input.c similarity index 100% rename from 3DS/source/input.c rename to 3DSsource/source/input.c diff --git a/3DS/source/keyboard.c b/3DSsource/source/keyboard.c similarity index 100% rename from 3DS/source/keyboard.c rename to 3DSsource/source/keyboard.c diff --git a/3DSsource/source/main.c b/3DSsource/source/main.c new file mode 100644 index 0000000..5da61e6 --- /dev/null +++ b/3DSsource/source/main.c @@ -0,0 +1,198 @@ +#include +#include +#include +#include + +#include <3ds.h> +#include "3ds/services/gsplcd.h" +#include "3ds/services/hid.h" +#include "3ds/services/soc.h" + +#include "drawing.h" +#include "input.h" +#include "keyboard.h" +#include "settings.h" +#include "wireless.h" + +static jmp_buf exitJmp; + +void hang(char *message) { + while (aptMainLoop()) { + hidScanInput(); + + clearScreen(); + drawString(10, 10, "%s", message); + drawString(10, 20, "Start and Select to exit"); + + u32 kHeld = hidKeysHeld(); + if ((kHeld & KEY_START) && (kHeld & KEY_SELECT)) + longjmp(exitJmp, 1); + + gfxFlushBuffers(); + gspWaitForVBlank(); + gfxSwapBuffers(); + } +} + +int main(void) { + acInit(); + gfxInitDefault(); + + gfxSetDoubleBuffering(GFX_TOP, true); + gfxSetDoubleBuffering(GFX_BOTTOM, true); + + if (setjmp(exitJmp)) + goto exit; + + // preRenderKeyboard(); + + // clearScreen(); + drawString(10, 10, "Initing FS..."); + gfxFlushBuffers(); + gfxSwapBuffers(); + + fsInit(); + + // clearScreen(); + drawString(10, 10, "Initing SOC..."); + gfxFlushBuffers(); + gfxSwapBuffers(); + + socInit((u32 *)memalign(0x1000, 0x100000), 0x100000); + + u32 wifiStatus = 0; + ACU_GetWifiStatus(&wifiStatus); + if (!wifiStatus) { + hang("No WiFi! Is your wireless slider on?"); + } + + clearScreen(); + drawString(10, 10, "Reading settings..."); + gfxFlushBuffers(); + gfxSwapBuffers(); + + if (!readSettings()) { + hang("Could not read 3DSController.ini!"); + } + + clearScreen(); + drawString(10, 10, "Connecting to %s on port %d...", settings.IPString, + settings.port); + gfxFlushBuffers(); + gfxSwapBuffers(); + + openSocket(settings.port); + sendConnectionRequest(); + +// clearScreen(); + drawString(10, 10, "Sending data to %s on port %d...", settings.IPString, + settings.port); + gfxFlushBuffers(); + gfxSwapBuffers(); + + GSPLCD_PowerOffAllBacklights(); + + while (aptMainLoop()) { + hidScanInput(); + irrstScanInput(); + + u32 kHeld = hidKeysHeld(); + circlePosition circlePad; + circlePosition cStick; + angularRate gyro; + accelVector accel; + u8 vol8; + u8 *volPointer = &vol8; // As a test for pointing at things. + // u8 threeD; + // u8 *threeDPointer = &threeD; + hidCstickRead(&cStick); + hidCircleRead(&circlePad); + HIDUSER_EnableGyroscope(); + hidGyroRead(&gyro); + HIDUSER_EnableAccelerometer(); + hidAccelRead(&accel); + HIDUSER_GetSoundVolume(volPointer); + // MCUHWC_GetSoundSliderLevel(threeDPointer); + u32 volume = (u32)vol8; // Upscale to 32 for transmission + // u32 threeD32 = (u32)threeD; + touchPosition touch; + touchRead(&touch); + + clearScreen(); + + if ((kHeld & KEY_L) && (kHeld & KEY_R) && (kHeld & KEY_X)) { + if (keyboardToggle) { + keyboardActive = !keyboardActive; + keyboardToggle = false; + + if (keyboardActive) { + GSPLCD_PowerOnAllBacklights(); + } else { + GSPLCD_PowerOffAllBacklights(); + } + } + } else + keyboardToggle = true; + + if (keyboardActive) { + drawKeyboard(); + + if (touch.px >= 1 && touch.px <= 312 && touch.py >= 78 && + touch.py <= 208) { + int x = (int)((float)touch.px * 12.0f / 320.0f); + int y = (int)((float)(touch.py - 78) * 12.0f / 320.0f); + int width = 24; + int height = 24; + + if (keyboardChars[x + y * 12] == ' ') { + while (keyboardChars[(x - 1) + y * 12] == ' ') + x--; + + width = (int)(5.0f * 320.0f / 12.0f) - 1; + } + + else if (keyboardChars[x + y * 12] == '\13') { + while (keyboardChars[(x - 1) + y * 12] == '\13') + x--; + while (keyboardChars[x + (y - 1) * 12] == '\13') + y--; + + width = (int)(2.0f * 320.0f / 12.0f) - 1; + height = (int)(3.0f * 320.0f / 12.0f) - 1; + } + + if (keyboardChars[x + y * 12]) + drawBox((int)((float)x * 320.0f / 12.0f) + 1, + (int)(78.0f + (float)y * 320.0f / 12.0f) + 1, width, height, + 31, 31, 0); + } + } + + sendKeys(kHeld, circlePad, touch, cStick, volume, gyro, accel); + // drawString(10, 10, "Volume: %x", volume); + // receiveBuffer(sizeof(struct packet)); + + if ((kHeld & KEY_START) && (kHeld & KEY_SELECT)) { + sendKeys(0, circlePad, touch, cStick, volume, gyro, accel); + longjmp(exitJmp, 1); + } + + gfxFlushBuffers(); + gspWaitForVBlank(); + gfxSwapBuffers(); + } + +exit: + + GSPLCD_PowerOnAllBacklights(); + + socExit(); + + svcCloseHandle(fileHandle); + fsExit(); + + gfxExit(); + acExit(); + + return 0; +} diff --git a/3DS/source/settings.c b/3DSsource/source/settings.c similarity index 100% rename from 3DS/source/settings.c rename to 3DSsource/source/settings.c diff --git a/3DSsource/source/wireless.c b/3DSsource/source/wireless.c new file mode 100644 index 0000000..931457b --- /dev/null +++ b/3DSsource/source/wireless.c @@ -0,0 +1,60 @@ +#include +#include +#include "keyboard.h" +#include "sys/_types.h" +#include "wireless.h" + +int sock; +struct sockaddr_in sain, saout; +struct packet outBuf, rcvBuf; + +socklen_t sockaddr_in_sizePtr = (int)sizeof(struct sockaddr_in); + +bool openSocket(int port) { + sock = socket(AF_INET, SOCK_DGRAM, 0); + + saout.sin_family = sain.sin_family = AF_INET; + saout.sin_port = sain.sin_port = htons(port); + sain.sin_addr.s_addr = INADDR_ANY; + + bind(sock, (struct sockaddr *)&sain, sizeof(sain)); + + fcntl(sock, F_SETFL, O_NONBLOCK); + + return true; +} + +void sendBuf(int length) { + sendto(sock, (char *)&outBuf, length, 0, (struct sockaddr *)&saout, + sizeof(saout)); +} + +int receiveBuffer(int length) { + return recvfrom(sock, (char *)&rcvBuf, length, 0, (struct sockaddr *)&sain, + &sockaddr_in_sizePtr); +} + +void sendConnectionRequest(void) { + outBuf.command = CONNECT; + outBuf.keyboardActive = keyboardActive; + sendBuf(offsetof(struct packet, connectPacket) + + sizeof(struct connectPacket)); +} + +void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch, + circlePosition cStick, unsigned int volume, + angularRate gyro, accelVector accel) { + outBuf.command = KEYS; + outBuf.keyboardActive = keyboardActive; + memcpy(&outBuf.keys, &keys, 4); + memcpy(&outBuf.circlePad, &circlePad, 4); + memcpy(&outBuf.touch, &touch, 4); + memcpy(&outBuf.cStick, &cStick, 4); + memcpy(&outBuf.volume, &volume, 4); + memcpy(&outBuf.gyro, &gyro, 6); + // Padding to separate gyro from accel, making it less confusing when parsing the data + outBuf.padding = 0; + memcpy(&outBuf.accel, &accel, 6); + // memcpy(&outBuf.threeD32, &threeD32, 4); + sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket)); +} diff --git a/DataDebug.py b/DataDebug.py new file mode 100755 index 0000000..06d2803 --- /dev/null +++ b/DataDebug.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +# Compatible with both Python 2.7.6 and 3.4.3 + +from __future__ import print_function +import socket, struct, time + +########################################################## +# CONFIGURABLE REGION START - Don't touch anything above # +########################################################## +port = 42020 + +######################################################## +# CONFIGURABLE REGION END - Don't touch anything below # +######################################################## + +def pprint(obj): + import pprint + pprint.PrettyPrinter().pprint(obj) + +class x: pass + +command = x() +command.CONNECT = 0 +command.KEYS = 1 +command.SCREENSHOT = 2 + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.bind(("", port)) + +while True: + rawdata, addr = sock.recvfrom(4092) + rawdata = bytearray(rawdata) + print("received message", rawdata) + + if rawdata[0]==command.CONNECT: + print("Connected with 3DS at address",addr) + pass # CONNECT packets are empty + + #pprint(data) + + if rawdata[0]==command.SCREENSHOT: + pass # unused by both 3DS and PC applications diff --git a/PC/3DSController.exe b/PC/3DSController.exe deleted file mode 100644 index 5b54716..0000000 Binary files a/PC/3DSController.exe and /dev/null differ diff --git a/PC/3DSController.ini b/PC/3DSController.ini deleted file mode 100644 index 65265b7..0000000 --- a/PC/3DSController.ini +++ /dev/null @@ -1,59 +0,0 @@ -Default port is 8889, if you change this, you must change it in the 3DS's 3DSController.ini as well, -Throttle controls the delay between checking for new packets (in milliseconds), a high number will have slightly more lag between pressing a button on the 3DS and receiving it on the PC, however will make the application use less CPU. In my experience, 20 is a reasonable throttling amount, -Mouse Speed controls how fast the Circle Pad or Touch Screen moves the mouse. If set to 0 and using the Touch Screen, it will set to the absolute position, rather than moving relatively to last position, -vJoy Device chooses which device to connect to. Set this to 2 in a second instance of 3DSController to use a second 3DS at the same time, perhaps for multiplayer. - - -Circle Pad, C Stick and Touch can be MOUSE, JOYSTICK1, or JOYSTICK2. -JOYSTICK1 uses X and Y. JOYSTICK2 uses Rx and Ry. These are axes 0, 1, 3 and 4 respectively, leaving 2 and 5 unused. -KEYS will enable Pad directions (eg. Pad Left, C Stick Right) to map to regular keys (no vJoy necessary). -D Pad can be KEYS or POV. POV will automatically choose a continuous or 4 directional POV hat depending on what is set in your vJoy Config. KEYS will allow Left, Right and etc. to be buttons as previously. - - -Buttons can be a letter for a keyboard key (like Q, W, E, R, T, or Y), a special keyboard key (like SPACE, CLICK, RIGHT CLICK, ENTER, BACKSPACE, SHIFT, TAB, LEFT, RIGHT, UP, DOWN, PAGE UP, PAGE DOWN, WINDOWS, ESCAPE, CONTROL or ALT), or a joypad button (JOY1, JOY2, JOY3, to JOY16). -If you want to use JOY9 through JOY16 you need to reconfigure vJoy. Search for vJoy Config in your start menu and set buttons to 16. - -Alternatively, you can disable any key by binding it to NONE. - - -Make sure to use a single space, not a tab for seperating settings, - - - - -Port: 8889 -Throttle: 20 -Mouse Speed: 3 -vJoy Device: 1 - -Circle Pad: KEYS -C Stick: MOUSE -D Pad: KEYS -Touch: MOUSE - -A: SPACE -B: E -X: CONTROL -Y: SHIFT -L: CLICK -R: RIGHT CLICK -ZL: CONTROL -ZR: SHIFT -Start: ESCAPE -Select: Q -Tap: NONE - -Left: A -Right: D -Up: W -Down: S - -Pad Left: A -Pad Right: D -Pad Up: W -Pad Down: S - -C Stick Left: NONE -C Stick Right: NONE -C Stick Up: NONE -C Stick Down: NONE \ No newline at end of file diff --git a/PC/Makefile b/PC/Makefile deleted file mode 100644 index 3084134..0000000 --- a/PC/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -CC := gcc -LN := gcc -ODIR := build -SDIR := source -IDIR := include -LDIR := lib -CFLAGS := -I$(IDIR) -fms-extensions -O2 -Wall -LFLAGS := $(LDIR)/vJoyInterface.lib -lws2_32 -lGdi32 -lgdiplus -static-libgcc -CFILES := $(wildcard $(SDIR)/*.c) -OBJS := $(patsubst $(SDIR)/%.c, $(ODIR)/%.o, $(wildcard $(SDIR)/*.c)) - -PLATFORM = $(shell uname) - -ifeq ($(findstring Linux,$(PLATFORM)),Linux) - TARGET=3DSController -endif - -ifeq ($(findstring Darwin,$(PLATFORM)),Darwin) - TARGET=3DSController -endif - -ifeq ($(findstring MINGW,$(PLATFORM)),MINGW) - TARGET=3DSController.exe -endif - -$(TARGET): $(ODIR) $(OBJS) - $(LN) $(ODIR)/*.o -o $(TARGET) $(CFLAGS) $(LFLAGS) - -$(ODIR)/%.o: $(SDIR)/%.c - $(CC) -c -o $@ $< $(CFLAGS) - -$(ODIR): - @mkdir $@ - -.PHONY: clean - -clean: - rm -f $(TARGET) $(ODIR)/*.o diff --git a/PC/include/general.h b/PC/include/general.h deleted file mode 100644 index 39f4d5f..0000000 --- a/PC/include/general.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -void error(const char *functionName); - -int clamp(int val, int min, int max); diff --git a/PC/include/joystick.h b/PC/include/joystick.h deleted file mode 100644 index 6101009..0000000 --- a/PC/include/joystick.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#ifndef WINVER - #define WINVER 0x0500 -#endif - -#include - -#include "public.h" -#include "vjoyinterface.h" - -#define joyX iReport.wAxisX -#define joyY iReport.wAxisY -#define joyRX iReport.wAxisXRot -#define joyRY iReport.wAxisYRot -//#define joyVolume iReport.wSlider -#define joyVolume iReport.wAxisZ -#define povHat iReport.bHats - -#define joyButtons iReport.lButtons - -#define JOY_MIDDLE (128 * 128) - -extern int ContPovNumber; -//extern BOOL ContinuousPOV; - -extern JOYSTICK_POSITION iReport; - -BOOL updateJoystick(int); diff --git a/PC/include/keyboard.h b/PC/include/keyboard.h deleted file mode 100644 index a69601d..0000000 --- a/PC/include/keyboard.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -extern unsigned char keyboardActive; -extern unsigned char keyboardToggle; - -char currentKeyboardKey(void); diff --git a/PC/include/keys.h b/PC/include/keys.h deleted file mode 100644 index cdcb5bc..0000000 --- a/PC/include/keys.h +++ /dev/null @@ -1,109 +0,0 @@ -#pragma once - -#include -#include -#include - -// For some reason, these are not defined in winuser.h like they used to be... -#ifndef VK_OEM_MINUS -#define VK_OEM_MINUS 0xBD -#endif -#ifndef VK_OEM_COMMA -#define VK_OEM_COMMA 0xBC -#endif -#ifndef KEYEVENTF_SCANCODE -#define KEYEVENTF_SCANCODE 0x08 -#endif - -#ifndef MAPVK_VK_TO_VSC -#define MAPVK_VK_TO_VSC 0 -#endif - -#define newpress(key) ((currentKeys & key) && !(lastKeys & key)) -#define release(key) (!(currentKeys & key) && (lastKeys & key)) - -#define handleKey(DSKey, PCKey) do {\ - if(!PCKey.useJoypad) {\ - if(newpress(DSKey)) simulateKeyNewpress(PCKey.virtualKey);\ - if(release(DSKey)) simulateKeyRelease(PCKey.virtualKey);\ - }\ - else if(PCKey.useJoypad == 1) {\ - if(currentKeys & DSKey) joyButtons |= PCKey.joypadButton;\ - else joyButtons &= ~PCKey.joypadButton;\ - }\ - else if(PCKey.useJoypad == 2) {\ - if(currentKeys & DSKey) joyButtons |= PCKey.joypadButton << 8;\ - else joyButtons &= ~(PCKey.joypadButton << 8);\ - }\ -} while(0) - -#define BIT(n) (1 << (n)) - -typedef enum { - KEY_A = BIT(0), - KEY_B = BIT(1), - KEY_SELECT = BIT(2), - KEY_START = BIT(3), - KEY_DRIGHT = BIT(4), - KEY_DLEFT = BIT(5), - KEY_DUP = BIT(6), - KEY_DDOWN = BIT(7), - KEY_R = BIT(8), - KEY_L = BIT(9), - KEY_X = BIT(10), - KEY_Y = BIT(11), - KEY_ZL = BIT(14), // (new 3DS only) - KEY_ZR = BIT(15), // (new 3DS only) - KEY_TOUCH = BIT(20), // Not actually provided by HID - KEY_CSTICK_RIGHT = BIT(24), // c-stick (new 3DS only) - KEY_CSTICK_LEFT = BIT(25), // c-stick (new 3DS only) - KEY_CSTICK_UP = BIT(26), // c-stick (new 3DS only) - KEY_CSTICK_DOWN = BIT(27), // c-stick (new 3DS only) - KEY_CPAD_RIGHT = BIT(28), // circle pad - KEY_CPAD_LEFT = BIT(29), // circle pad - KEY_CPAD_UP = BIT(30), // circle pad - KEY_CPAD_DOWN = BIT(31), // circle pad - - // Generic catch-all directions - KEY_UP = KEY_DUP | KEY_CPAD_UP, - KEY_DOWN = KEY_DDOWN | KEY_CPAD_DOWN, - KEY_LEFT = KEY_DLEFT | KEY_CPAD_LEFT, - KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT, -} KEYPAD_BITS; - -struct keyMapping { - unsigned char useJoypad; // 0 keyboard key, 1 joypad1-8, 2 joypad9-16, 3 hat - union { - unsigned char virtualKey; - unsigned char joypadButton; - }; -}; - -struct circlePad { - short x; - short y; -}; - -struct cStick { - short x; - short y; -}; - -struct touch { - short x; - short y; -}; - -extern unsigned int lastKeys; -extern unsigned int currentKeys; - -extern unsigned int volume; - -extern struct circlePad circlePad; -extern struct cStick cStick; -extern struct touch lastTouch; -extern struct touch currentTouch; - -unsigned int mapVirtualKey(unsigned int key); -void simulateKeyNewpress(unsigned int key); -void simulateKeyRelease(unsigned int key); diff --git a/PC/include/public.h b/PC/include/public.h deleted file mode 100644 index 32dc016..0000000 --- a/PC/include/public.h +++ /dev/null @@ -1,227 +0,0 @@ -/*++ - -Copyright (c) Shaul Eizikovich. All rights reserved. - - THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY - KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR - PURPOSE. - -Module Name: - - public.h - -Abstract: - - Public header file for the vJoy project - Developpers that need to interface with vJoy need to include this file - -Author: - - -Environment: - - kernel mode and User mode - -Notes: - - -Revision History: - - ---*/ -#ifndef _PUBLIC_H -#define _PUBLIC_H - -// Compilation directives -#define PPJOY_MODE -#undef PPJOY_MODE // Comment-out for compatibility mode - -#ifdef PPJOY_MODE -#include "PPJIoctl.h" -#endif - -#include // Definitions for controlling GUID initialization - -// -// Usage example: -// CreateFile(TEXT("\\\\.\\vJoy"), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); -#ifdef PPJOY_MODE -#define DEVICENAME_STRING "PPJoyIOCTL1" -#else -#define DEVICENAME_STRING "vJoy" -#endif -#define NTDEVICE_NAME_STRING "\\Device\\"DEVICENAME_STRING -#define SYMBOLIC_NAME_STRING "\\DosDevices\\"DEVICENAME_STRING -#define DOS_FILE_NAME "\\\\.\\"DEVICENAME_STRING -#define VJOY_INTERFACE L"Device_" - -// Version parts -#define VER_X_ 0 -#define VER_H_ 2 -#define VER_M_ 0 -#define VER_L_ 5 - -#define STRINGIFY_1(x) #x -#define STRINGIFY(x) STRINGIFY_1(x) -#define PASTE(x, y) x##y -#define MAKEWIDE(x) PASTE(L,x) - -// Device Attributes -// -#define VENDOR_N_ID 0x1234 -#define PRODUCT_N_ID 0xBEAD -#define VERSION_N (VER_L_ + 0x10*VER_M_ + 0x100*VER_H_ + 0x1000*VER_X_) - -// Device Strings -// -#define VENDOR_STR_ID L"Shaul Eizikovich" -#define PRODUCT_STR_ID L"vJoy - Virtual Joystick" -#define SERIALNUMBER_STR MAKEWIDE(STRINGIFY(VER_H_)) L"." MAKEWIDE(STRINGIFY(VER_M_)) L"." MAKEWIDE(STRINGIFY(VER_L_)) - -// Function codes; -//#define LOAD_POSITIONS 0x910 -//#define GETATTRIB 0x911 -// #define GET_FFB_DATA 0x00222912 // METHOD_OUT_DIRECT + FILE_DEVICE_UNKNOWN + FILE_ANY_ACCESS -//#define SET_FFB_STAT 0x913 // METHOD_NEITHER -//#define GET_FFB_STAT 0x916 - -#define F_LOAD_POSITIONS 0x910 -#define F_GETATTRIB 0x911 -#define F_GET_FFB_DATA 0x912 -#define F_SET_FFB_STAT 0x913 -#define F_GET_FFB_STAT 0x916 -#define F_GET_DEV_INFO 0x917 -// IO Device Control codes; -#define IOCTL_VJOY_GET_ATTRIB CTL_CODE (FILE_DEVICE_UNKNOWN, GETATTRIB, METHOD_BUFFERED, FILE_WRITE_ACCESS) -#define LOAD_POSITIONS CTL_CODE (FILE_DEVICE_UNKNOWN, F_LOAD_POSITIONS, METHOD_BUFFERED, FILE_WRITE_ACCESS) -#define GET_FFB_DATA CTL_CODE (FILE_DEVICE_UNKNOWN, F_GET_FFB_DATA, METHOD_OUT_DIRECT, FILE_ANY_ACCESS) -#define SET_FFB_STAT CTL_CODE (FILE_DEVICE_UNKNOWN, F_SET_FFB_STAT, METHOD_NEITHER, FILE_ANY_ACCESS) -#define GET_FFB_STAT CTL_CODE (FILE_DEVICE_UNKNOWN, F_GET_FFB_STAT, METHOD_BUFFERED, FILE_ANY_ACCESS) -#define GET_DEV_INFO CTL_CODE (FILE_DEVICE_UNKNOWN, F_GET_DEV_INFO, METHOD_BUFFERED, FILE_ANY_ACCESS) - -#ifndef __HIDPORT_H__ -// Copied from hidport.h -#define IOCTL_HID_SET_FEATURE 0xB0191 -#define IOCTL_HID_WRITE_REPORT 0xB000F - -#define MAX_N_DEVICES 16 // Maximum number of vJoy devices - - -typedef struct _HID_DEVICE_ATTRIBUTES { - - ULONG Size; - // - // sizeof (struct _HID_DEVICE_ATTRIBUTES) - // - - // - // Vendor ids of this hid device - // - USHORT VendorID; - USHORT ProductID; - USHORT VersionNumber; - USHORT Reserved[11]; - -} HID_DEVICE_ATTRIBUTES, * PHID_DEVICE_ATTRIBUTES; -#endif - -// Error levels for status report -enum ERRLEVEL {INFO, WARN, ERR, FATAL, APP}; -// Status report function prototype -#ifdef WINAPI -typedef BOOL (WINAPI *StatusMessageFunc)(void * output, TCHAR * buffer, enum ERRLEVEL level); -#endif - -/////////////////////////////////////////////////////////////// - -/////////////////////// Joystick Position /////////////////////// -// -// This structure holds data that is passed to the device from -// an external application such as SmartPropoPlus. -// -// Usage example: -// JOYSTICK_POSITION iReport; -// : -// DeviceIoControl (hDevice, 100, &iReport, sizeof(HID_INPUT_REPORT), NULL, 0, &bytes, NULL) -typedef struct _JOYSTICK_POSITION -{ - BYTE bDevice; // Index of device. 1-based. - LONG wThrottle; - LONG wRudder; - LONG wAileron; - LONG wAxisX; - LONG wAxisY; - LONG wAxisZ; - LONG wAxisXRot; - LONG wAxisYRot; - LONG wAxisZRot; - LONG wSlider; - LONG wDial; - LONG wWheel; - LONG wAxisVX; - LONG wAxisVY; - LONG wAxisVZ; - LONG wAxisVBRX; - LONG wAxisVBRY; - LONG wAxisVBRZ; - LONG lButtons; // 32 buttons: 0x00000001 means button1 is pressed, 0x80000000 -> button32 is pressed - DWORD bHats; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch - DWORD bHatsEx1; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch - DWORD bHatsEx2; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch - DWORD bHatsEx3; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch -} JOYSTICK_POSITION, *PJOYSTICK_POSITION; - -// Superset of JOYSTICK_POSITION -// Extension of JOYSTICK_POSITION with Buttons 33-128 appended to the end of the structure. -typedef struct _JOYSTICK_POSITION_V2 -{ - /// JOYSTICK_POSITION - BYTE bDevice; // Index of device. 1-based. - LONG wThrottle; - LONG wRudder; - LONG wAileron; - LONG wAxisX; - LONG wAxisY; - LONG wAxisZ; - LONG wAxisXRot; - LONG wAxisYRot; - LONG wAxisZRot; - LONG wSlider; - LONG wDial; - LONG wWheel; - LONG wAxisVX; - LONG wAxisVY; - LONG wAxisVZ; - LONG wAxisVBRX; - LONG wAxisVBRY; - LONG wAxisVBRZ; - LONG lButtons; // 32 buttons: 0x00000001 means button1 is pressed, 0x80000000 -> button32 is pressed - DWORD bHats; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch - DWORD bHatsEx1; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch - DWORD bHatsEx2; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch - DWORD bHatsEx3; // Lower 4 bits: HAT switch or 16-bit of continuous HAT switch LONG lButtonsEx1; // Buttons 33-64 - - /// JOYSTICK_POSITION_V2 Extenssion - LONG lButtonsEx1; // Buttons 33-64 - LONG lButtonsEx2; // Buttons 65-96 - LONG lButtonsEx3; // Buttons 97-128 -} JOYSTICK_POSITION_V2, *PJOYSTICK_POSITION_V2; - - -// HID Descriptor definitions -#define HID_USAGE_X 0x30 -#define HID_USAGE_Y 0x31 -#define HID_USAGE_Z 0x32 -#define HID_USAGE_RX 0x33 -#define HID_USAGE_RY 0x34 -#define HID_USAGE_RZ 0x35 -#define HID_USAGE_SL0 0x36 -#define HID_USAGE_SL1 0x37 -#define HID_USAGE_WHL 0x38 -#define HID_USAGE_POV 0x39 - - -#endif - - diff --git a/PC/include/settings.h b/PC/include/settings.h deleted file mode 100644 index 769eb50..0000000 --- a/PC/include/settings.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include "keys.h" - -enum analogue { - mouse, - joystick1, - joystick2, - keys, -}; - -enum dPad { - key, - pov, - cPov, -}; - -struct settings { - int port; - int throttle; - enum analogue circlePad; - enum analogue cStick; - enum analogue touch; - enum dPad dPad; - int mouseSpeed; - UINT vJoyDevice; - struct keyMapping A, B, X, Y, L, R, ZL, ZR, Start, Select, Tap, Left, Right, Up, Down, PadLeft, PadRight, PadUp, PadDown, CSLeft, CSRight, CSUp, CSDown; -}; - -extern struct settings settings; -extern struct settings defaultSettings; - -bool readSettings(void); diff --git a/PC/include/vjoyinterface.h b/PC/include/vjoyinterface.h deleted file mode 100644 index 0127577..0000000 --- a/PC/include/vjoyinterface.h +++ /dev/null @@ -1,104 +0,0 @@ -// The following ifdef block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the VJOYINTERFACE_EXPORTS -// symbol defined on the command line. this symbol should not be defined on any project -// that uses this DLL. This way any other project whose source files include this file see -// VJOYINTERFACE_API functions as being imported from a DLL, whereas this DLL sees symbols -// defined with this macro as being exported. -#ifdef VJOYINTERFACE_EXPORTS -#define VJOYINTERFACE_API __declspec(dllexport) -#else -#define VJOYINTERFACE_API __declspec(dllimport) -#endif - -///////////////////////////// vJoy device (collection) status //////////////////////////////////////////// -#ifndef VJDSTAT -#define VJDSTAT -enum VjdStat /* Declares an enumeration data type called BOOLEAN */ -{ - VJD_STAT_OWN, // The vJoy Device is owned by this application. - VJD_STAT_FREE, // The vJoy Device is NOT owned by any application (including this one). - VJD_STAT_BUSY, // The vJoy Device is owned by another application. It cannot be acquired by this application. - VJD_STAT_MISS, // The vJoy Device is missing. It either does not exist or the driver is down. - VJD_STAT_UNKN // Unknown -}; - -/* Error codes for some of the functions */ -#define NO_HANDLE_BY_INDEX -1 -#define BAD_PREPARSED_DATA -2 -#define NO_CAPS -3 -#define BAD_N_BTN_CAPS -4 -#define BAD_CALLOC -5 -#define BAD_BTN_CAPS -6 -#define BAD_BTN_RANGE -7 -#define BAD_N_VAL_CAPS -8 -#define BAD_ID_RANGE -9 -#define NO_SUCH_AXIS -10 - -/* Environment Variables */ -#define INTERFACE_LOG_LEVEL "VJOYINTERFACELOGLEVEL" -#define INTERFACE_LOG_FILE "VJOYINTERFACELOGFILE" -#define INTERFACE_DEF_LOG_FILE "vJoyInterface.log" - -struct DEV_INFO { - BYTE DeviceID; // Device ID: Valid values are 1-16 - BYTE nImplemented; // Number of implemented device: Valid values are 1-16 - BYTE isImplemented; // Is this device implemented? - BYTE MaxDevices; // Maximum number of devices that may be implemented (16) - BYTE DriverFFB; // Does this driver support FFB (False) - BYTE DeviceFFB; // Does this device support FFB (False) -} ; - -typedef void (CALLBACK *RemovalCB)(BOOL, BOOL, PVOID); - -#endif -///////////////////////////// vJoy device (collection) Control interface ///////////////////////////////// -/* - These functions allow writing feeders and other applications that interface with vJoy - It is assumed that only one vJoy top-device (= Raw PDO) exists. - This top-level device can have up to 16 siblings (=top-level Reports/collections) - Each sibling is refered to as a "vJoy Device" and is attributed a unique Report ID (Range: 1-16). - - Naming convetion: - VJD = vJoy Device - rID = Report ID -*/ - -///// General driver data -VJOYINTERFACE_API SHORT __cdecl GetvJoyVersion(void); -VJOYINTERFACE_API BOOL __cdecl vJoyEnabled(void); -VJOYINTERFACE_API PVOID __cdecl GetvJoyProductString(void); -VJOYINTERFACE_API PVOID __cdecl GetvJoyManufacturerString(void); -VJOYINTERFACE_API PVOID __cdecl GetvJoySerialNumberString(void); -VJOYINTERFACE_API BOOL __cdecl DriverMatch(WORD * DllVer, WORD * DrvVer); -VJOYINTERFACE_API VOID __cdecl RegisterRemovalCB(RemovalCB cb, PVOID data); - - -///// vJoy Device properties -VJOYINTERFACE_API int __cdecl GetVJDButtonNumber(UINT rID); // Get the number of buttons defined in the specified VDJ -VJOYINTERFACE_API int __cdecl GetVJDDiscPovNumber(UINT rID); // Get the number of descrete-type POV hats defined in the specified VDJ -VJOYINTERFACE_API int __cdecl GetVJDContPovNumber(UINT rID); // Get the number of descrete-type POV hats defined in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl GetVJDAxisExist(UINT rID, UINT Axis); // Test if given axis defined in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl GetVJDAxisMax(UINT rID, UINT Axis, LONG * Max); // Get logical Maximum value for a given axis defined in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl GetVJDAxisMin(UINT rID, UINT Axis, LONG * Min); // Get logical Minimum value for a given axis defined in the specified VDJ - -///// Write access to vJoy Device - Basic -VJOYINTERFACE_API BOOL __cdecl AcquireVJD(UINT rID); // Acquire the specified vJoy Device. -VJOYINTERFACE_API VOID __cdecl RelinquishVJD(UINT rID); // Relinquish the specified vJoy Device. -VJOYINTERFACE_API BOOL __cdecl UpdateVJD(UINT rID, PVOID pData); // Update the position data of the specified vJoy Device. -VJOYINTERFACE_API enum VjdStat __cdecl GetVJDStatus(UINT rID); // Get the status of the specified vJoy Device. - -///// Write access to vJoy Device - Modifyiers -// This group of functions modify the current value of the position data -// They replace the need to create a structure of position data then call UpdateVJD - -//// Reset functions -VJOYINTERFACE_API BOOL __cdecl ResetVJD(UINT rID); // Reset all controls to predefined values in the specified VDJ -VJOYINTERFACE_API VOID __cdecl ResetAll(void); // Reset all controls to predefined values in all VDJ -VJOYINTERFACE_API BOOL __cdecl ResetButtons(UINT rID); // Reset all buttons (To 0) in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl ResetPovs(UINT rID); // Reset all POV Switches (To -1) in the specified VDJ - -// Write data -VJOYINTERFACE_API BOOL __cdecl SetAxis(LONG Value, UINT rID, UINT Axis); // Write Value to a given axis defined in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl SetBtn(BOOL Value, UINT rID, UCHAR nBtn); // Write Value to a given button defined in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl SetDiscPov(int Value, UINT rID, UCHAR nPov); // Write Value to a given descrete POV defined in the specified VDJ -VJOYINTERFACE_API BOOL __cdecl SetContPov(DWORD Value, UINT rID, UCHAR nPov); // Write Value to a given continuous POV defined in the specified VDJ diff --git a/PC/include/wireless.h b/PC/include/wireless.h deleted file mode 100644 index 4bff563..0000000 --- a/PC/include/wireless.h +++ /dev/null @@ -1,84 +0,0 @@ -#pragma once - -#ifndef WINVER - #define WINVER 0x0500 -#endif - -#include -#include - -#include - -#define SCREENSHOT_CHUNK 4000 - -#define IP INADDR_ANY - -enum NET_COMMANDS { - CONNECT, - KEYS, - SCREENSHOT, -}; - -// It is deliberately set up to have an anonymous struct as well as a named struct for convenience, not a mistake! -struct packet { - struct packetHeader { - unsigned char command; - unsigned char keyboardActive; - }; - struct packetHeader packetHeader; - - union { - // CONNECT - struct connectPacket { - }; - struct connectPacket connectPacket; - - // KEYS - struct keysPacket { - unsigned int keys; - - struct { - short x; - short y; - } circlePad; - - struct { - unsigned short x; - unsigned short y; - } touch; - - struct { - short x; - short y; - } cStick; - - unsigned int volume; - }; - struct keysPacket keysPacket; - - // SCREENSHOT - struct screenshotPacket { - unsigned short offset; - unsigned char data[SCREENSHOT_CHUNK]; - }; - struct screenshotPacket screenshotPacket; - }; -}; - -extern SOCKET listener; -extern SOCKET client; - -extern struct sockaddr_in client_in; - -extern int sockaddr_in_sizePtr; - -extern struct packet buffer; -extern char hostName[80]; - -void initNetwork(void); -void printIPs(void); -void startListening(void); -void sendBuffer(int length); -int receiveBuffer(int length); - -void sendScreenshot(void); diff --git a/PC/lib/vJoyInterface.lib b/PC/lib/vJoyInterface.lib deleted file mode 100644 index 7752ec4..0000000 Binary files a/PC/lib/vJoyInterface.lib and /dev/null differ diff --git a/PC/source/general.c b/PC/source/general.c deleted file mode 100644 index 402acdc..0000000 --- a/PC/source/general.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "wireless.h" - -#include "general.h" - -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/joystick.c b/PC/source/joystick.c deleted file mode 100644 index bdf4f2c..0000000 --- a/PC/source/joystick.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -#include "joystick.h" - -int ContPovNumber; -//BOOL ContinuousPOV = FALSE; - -JOYSTICK_POSITION iReport; - -BOOL updateJoystick(iInterface) { - BYTE id = (BYTE)iInterface; - - iReport.bDevice = id; - - if(!UpdateVJD(iInterface, (PVOID)&iReport)) { - /*printf("vJoy device %d failed - try to enable device\n", iInterface); - printf("PRESS ENTER TO CONTINUE\n"); - getchar(); - AcquireVJD(iInterface); - ContinuousPOV = (BOOL)GetVJDContPovNumber(iInterface);*/ - return false; - } - - return true; -} diff --git a/PC/source/keyboard.c b/PC/source/keyboard.c deleted file mode 100644 index a2b52d2..0000000 --- a/PC/source/keyboard.c +++ /dev/null @@ -1,21 +0,0 @@ -#include - -#include "keys.h" - -#include "keyboard.h" - -unsigned char keyboardActive = false; -unsigned char keyboardToggle = true; - -inline char currentKeyboardKey(void) { - const char chars[60] = "!1234567890\x08QWERTYUIOP\13\13ASDFGHJKL-\13\13ZXCVBNM,.?\13\13\0\0\0 \0\0\0\0"; - - if(currentTouch.x >= 1 && currentTouch.x <= 312 && currentTouch.y >= 78 && currentTouch.y <= 208) { - int x = (int)((float)currentTouch.x * 12.0f / 320.0f); - int y = (int)((float)(currentTouch.y - 78) * 12.0f / 320.0f); - - return chars[x + y * 12]; - } - - else return 0; -} diff --git a/PC/source/keys.c b/PC/source/keys.c deleted file mode 100644 index 75b019f..0000000 --- a/PC/source/keys.c +++ /dev/null @@ -1,80 +0,0 @@ -#include "keys.h" -#include "joystick.h" - -// Sideband comunication with vJoy Device -//{781EF630-72B2-11d2-B852-00C04FAD5101} -//DEFINE_GUID(GUID_DEVINTERFACE_VJOY, 0x781EF630, 0x72B2, 0x11d2, 0xB8, 0x52, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x01); - -unsigned int lastKeys; -unsigned int currentKeys; -unsigned int volume; //slider - -struct circlePad circlePad; -struct cStick cStick; -struct touch lastTouch; -struct touch currentTouch; - -inline unsigned int mapVirtualKey(unsigned int key) { - return MapVirtualKey(key, MAPVK_VK_TO_VSC); -} - -void simulateKeyNewpress(unsigned int key) { - if(!key) return; - - unsigned char unshift = 0; - - INPUT ip = { 0 }; - - if(key == VK_LBUTTON || key == VK_RBUTTON) { - ip.type = INPUT_MOUSE; - ip.mi.dwFlags = key == VK_LBUTTON ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_RIGHTDOWN; - } - else { - if(key == '!') { - key = '1'; - simulateKeyNewpress(VK_SHIFT); - unshift = 1; - } - else if(key == '?') { - key = VK_DIVIDE; - simulateKeyNewpress(VK_SHIFT); - unshift = 1; - } - - else if(key == '-') key = VK_OEM_MINUS; - else if(key == ',') key = VK_OEM_COMMA; - else if(key == '\13') key = VK_RETURN; - - ip.type = INPUT_KEYBOARD; - ip.ki.wScan = mapVirtualKey(key); - ip.ki.time = 0; - ip.ki.dwExtraInfo = 0; - ip.ki.wVk = 0; - ip.ki.dwFlags = KEYEVENTF_SCANCODE; - } - - SendInput(1, &ip, sizeof(INPUT)); - - if(unshift) simulateKeyRelease(VK_SHIFT); -} - -void simulateKeyRelease(unsigned int key) { - if(!key) return; - - INPUT ip = { 0 }; - - if(key == VK_LBUTTON || key == VK_RBUTTON) { - ip.type = INPUT_MOUSE; - ip.mi.dwFlags = key == VK_LBUTTON ? MOUSEEVENTF_LEFTUP : MOUSEEVENTF_RIGHTUP; - } - else { - ip.type = INPUT_KEYBOARD; - ip.ki.wScan = mapVirtualKey(key); - ip.ki.time = 0; - ip.ki.dwExtraInfo = 0; - ip.ki.wVk = 0; - ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; - } - - SendInput(1, &ip, sizeof(INPUT)); -} \ No newline at end of file diff --git a/PC/source/main.c b/PC/source/main.c deleted file mode 100644 index 959c375..0000000 --- a/PC/source/main.c +++ /dev/null @@ -1,300 +0,0 @@ -// 3DS Controller Server - -#define VERSION "0.7.2" - -#include -#include -#include - -#include "wireless.h" -#include "keys.h" -#include "general.h" -#include "joystick.h" -#include "settings.h" -#include "keyboard.h" - -int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow) { - printf("3DS Controller Server %s\n", VERSION); - - DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN); - DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN); - - double widthMultiplier = screenWidth / 320.0; - double heightMultiplier = screenHeight / 240.0; - - if(!readSettings()) { - printf("Couldn't read settings file, using default key bindings.\n"); - } - - bool vJoy = true; - UINT iInterface = settings.vJoyDevice; - - iReport.wAxisX = JOY_MIDDLE; - iReport.wAxisY = JOY_MIDDLE; - iReport.wAxisZ = JOY_MIDDLE; - iReport.wAxisXRot = JOY_MIDDLE; - iReport.wAxisYRot = JOY_MIDDLE; - iReport.wAxisZRot = JOY_MIDDLE; - iReport.wSlider = JOY_MIDDLE; - iReport.wDial = JOY_MIDDLE; - iReport.lButtons = 0; - iReport.bHats = -1; - - if(vJoy && !vJoyEnabled()) { - printf("vJoy failed (1)! Buttons will still work, but joy stick won't work.\n"); - vJoy = false; - } - - enum VjdStat status = GetVJDStatus(iInterface); - if(vJoy && (status == VJD_STAT_OWN || (status == VJD_STAT_FREE && !AcquireVJD(iInterface)))) { - printf("vJoy failed (2)! Buttons will still work, but joy stick won't work.\n"); - vJoy = false; - } - - ContPovNumber = GetVJDContPovNumber(iInterface); - //int DiscPovNumber = GetVJDDiscPovNumber(iInterface); - - if((settings.dPad == pov) && !(ContPovNumber == 0)) settings.dPad = cPov; - - if(vJoy && !updateJoystick(iInterface)) { - printf("vJoy failed (3)! Buttons will still work, but joystick won't work.\nIs vJoy device %d configured?\n",iInterface); - vJoy = false; - } else printf("Connected to vJoy device %d\n",iInterface); - - initNetwork(); - - char nButtons = GetVJDButtonNumber(iInterface); - if(vJoy && nButtons <16) printf("Your vJoy has %d buttons, 3DSController supports 16!\n", nButtons); - - printf("Port: %d\n", settings.port); - - printf("Running on: %s\n", hostName); - - printf("Your local IP(s):\n"); - printIPs(); - - printf("\n"); - - startListening(); - - while(1) { - memset(&buffer, 0, sizeof(struct packet)); - - while(receiveBuffer(sizeof(struct packet)) <= 0) { - // Waiting - - Sleep(settings.throttle); - } - - keyboardActive = buffer.keyboardActive; - - switch(buffer.command) { - case CONNECT: - lastKeys = 0; - currentKeys = 0; - circlePad.x = 0; - circlePad.y = 0; - lastTouch.x = 0; - lastTouch.y = 0; - currentTouch.x = 0; - currentTouch.y = 0; - cStick.x = 0; - cStick.y = 0; - - buffer.command = CONNECT; - printf("3DS Connected!\n"); - - Sleep(50); - sendBuffer(1); - - Sleep(50); - sendBuffer(1); - - Sleep(50); - sendBuffer(1); - break; - - case KEYS: - lastKeys = currentKeys; - if(currentKeys & KEY_TOUCH) lastTouch = currentTouch; - - memcpy(¤tKeys, &buffer.keys, 4); - memcpy(&circlePad, &buffer.circlePad, 4); - memcpy(¤tTouch, &buffer.touch, 4); - memcpy(&cStick, &buffer.cStick, 4); - memcpy(&volume, &buffer.volume, 4); - //printf("\rVolume is currently: %x ", volume); //test - - handleKey(KEY_A, settings.A); - handleKey(KEY_B, settings.B); - handleKey(KEY_SELECT, settings.Select); - handleKey(KEY_START, settings.Start); - if(settings.dPad == key) { //Handle normally if not using POV in settings. - 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); - handleKey(KEY_ZR, settings.ZR); - handleKey(KEY_ZL, settings.ZL); - handleKey(KEY_X, settings.X); - handleKey(KEY_Y, settings.Y); - - if(settings.circlePad == keys) { - handleKey(KEY_CPAD_RIGHT, settings.PadRight); - handleKey(KEY_CPAD_LEFT, settings.PadLeft); - handleKey(KEY_CPAD_UP, settings.PadUp); - handleKey(KEY_CPAD_DOWN, settings.PadDown); - } - - if(settings.cStick == keys) { - handleKey(KEY_CSTICK_RIGHT, settings.CSRight); - handleKey(KEY_CSTICK_LEFT, settings.CSLeft); - handleKey(KEY_CSTICK_UP, settings.CSUp); - handleKey(KEY_CSTICK_DOWN, settings.CSDown); - } - - //handleKey(KEY_LID, 'I'); - - if(newpress(KEY_TOUCH)) { - lastTouch.x = currentTouch.x; - lastTouch.y = currentTouch.y; - } - - if((currentKeys & KEY_TOUCH)) { - if(keyboardActive) { - if(newpress(KEY_TOUCH)) { - char letter = currentKeyboardKey(); - if(letter) { - simulateKeyNewpress(letter); - simulateKeyRelease(letter); - } - } - } - else if(settings.touch == mouse) { - if(settings.mouseSpeed) { - POINT p; - GetCursorPos(&p); - SetCursorPos(p.x + (currentTouch.x - lastTouch.x) * settings.mouseSpeed, p.y + (currentTouch.y - lastTouch.y) * settings.mouseSpeed); - } - else { - SetCursorPos((int)((double)currentTouch.x * widthMultiplier), (int)((double)currentTouch.y * heightMultiplier)); - } - } - else if(settings.touch == joystick1) { //made a little bit more accurate to the screen size. - joyX = (int)((float)(currentTouch.x) * 102.3f); - joyY = (int)((float)(currentTouch.y) * 136.5f); - } - - else if(settings.touch == joystick2) { - joyRX = (int)((float)(currentTouch.x) * 102.3f); - joyRY = (int)((float)(currentTouch.y) * 136.5f); - } - else { - handleKey(KEY_TOUCH, settings.Tap); - } - } else { //If we are not touching, move to center (Like if you release the joystick on a normal controller). - if(settings.touch == joystick1) { - 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 = clamp((circlePad.x + 128) * 128, 0, 32767); - joyY = clamp((128 - circlePad.y) * 128, 0, 32767); - } - - else if(settings.circlePad == joystick2) { - 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 = clamp((cStick.x + 128) * 128, 0, 32767); - joyY = clamp((128 - cStick.y) * 128, 0, 32767); - } - - else if(settings.cStick == joystick2) { - 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)) { - povHat = 4500; - } else { - povHat = 0; - } - } else if((currentKeys & KEY_DRIGHT)) { - if((currentKeys & KEY_DDOWN)) { - povHat = 13500; - } else { - povHat = 9000; - } - } else if((currentKeys & KEY_DDOWN)) { - if((currentKeys & KEY_DLEFT)) { - povHat = 22500; - } else { - povHat = 18000; - } - } else if((currentKeys & KEY_DLEFT)) { - if ((currentKeys & KEY_DUP)) { - povHat = 31500; - } else { - povHat = 27000; - } - } - - if(!((currentKeys & KEY_DUP) || (currentKeys & KEY_DRIGHT) || (currentKeys & KEY_DDOWN) || (currentKeys & KEY_DLEFT))) { - //If none are pressed, reset the POV hat - povHat = -1; - } - - } - - else if(settings.dPad == pov) { - if((currentKeys & KEY_DUP) && !(currentKeys & KEY_DLEFT)) iReport.bHats = 0; - else if(currentKeys & KEY_DRIGHT) iReport.bHats = 1; - else if (currentKeys & KEY_DDOWN) iReport.bHats = 2; - else if (currentKeys & KEY_DLEFT) iReport.bHats = 3; - else iReport.bHats = -1; - } - - joyVolume = volume * 512; - - break; - } - - if(vJoy) updateJoystick(iInterface); - } - - error("accept()"); - return 0; -} diff --git a/PC/source/settings.c b/PC/source/settings.c deleted file mode 100644 index 8cb13e7..0000000 --- a/PC/source/settings.c +++ /dev/null @@ -1,201 +0,0 @@ -#include -#include -#include - -#include "keys.h" -#include "wireless.h" - -#include "settings.h" - -struct settings settings; - -struct settings defaultSettings = { - port: 8889, - throttle: 20, - circlePad: joystick1, - cStick: joystick2, - touch: mouse, - mouseSpeed: 4, - vJoyDevice: 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'} }, - Left: { 1, {VK_LEFT} }, - Right: { 1, {VK_RIGHT} }, - Up: { 1, {VK_UP} }, - Down: { 1, {VK_DOWN} }, - Start: { 1, {VK_RETURN} }, - Select: { 1, {VK_BACK} }, - Tap: { 1, {'T'} }, -}; - -static bool getSetting(char *name, char *src, char *dest) { - char *start = strstr(src, name); - - if(start) { - start += strlen(name); - - char *end = start + strlen(start); - if(strstr(start, "\n") - 1 < end) end = strstr(start, "\n") - 1; - size_t size = (size_t)end - (size_t)start; - - strncpy(dest, start, size); - dest[size] = '\0'; - - return true; - } - - return false; -} - -static struct keyMapping getButton(char *string) { - struct keyMapping k = { 1, {0} }; - - k.useJoypad = 0; - if(strcmp(string, "SPACE") == 0) k.virtualKey = VK_SPACE; - else if(strcmp(string, "CLICK") == 0) k.virtualKey = VK_LBUTTON; - else if(strcmp(string, "RIGHT CLICK") == 0) k.virtualKey = VK_RBUTTON; - else if(strcmp(string, "ENTER") == 0) k.virtualKey = VK_RETURN; - else if(strcmp(string, "BACKSPACE") == 0) k.virtualKey = VK_BACK; - else if(strcmp(string, "SHIFT") == 0) k.virtualKey = VK_SHIFT; - else if(strcmp(string, "TAB") == 0) k.virtualKey = VK_TAB; - else if(strcmp(string, "LEFT") == 0) k.virtualKey = VK_LEFT; - else if(strcmp(string, "RIGHT") == 0) k.virtualKey = VK_RIGHT; - else if(strcmp(string, "UP") == 0) k.virtualKey = VK_UP; - else if(strcmp(string, "DOWN") == 0) k.virtualKey = VK_DOWN; - else if(strcmp(string, "PAGE UP") == 0) k.virtualKey = VK_PRIOR; - else if(strcmp(string, "PAGE DOWN") == 0) k.virtualKey = VK_NEXT; - else if(strcmp(string, "WINDOWS") == 0) k.virtualKey = VK_LWIN; - else if(strcmp(string, "ESCAPE") == 0) k.virtualKey = VK_ESCAPE; - else if(strcmp(string, "CONTROL") == 0) k.virtualKey = VK_CONTROL; - else if(strcmp(string, "ALT") == 0) k.virtualKey = VK_MENU; - else if(strcmp(string, "NONE") == 0) k.virtualKey = 0; - - else if(strcmp(string, "JOY1") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 0; } - else if(strcmp(string, "JOY2") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 1; } - else if(strcmp(string, "JOY3") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 2; } - else if(strcmp(string, "JOY4") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 3; } - else if(strcmp(string, "JOY5") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 4; } - else if(strcmp(string, "JOY6") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 5; } - else if(strcmp(string, "JOY7") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 6; } - else if(strcmp(string, "JOY8") == 0) { k.useJoypad = 1; k.joypadButton = 1 << 7; } - else if(strcmp(string, "JOY9") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 0; } - else if(strcmp(string, "JOY10") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 1; } - else if(strcmp(string, "JOY11") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 2; } - else if(strcmp(string, "JOY12") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 3; } - else if(strcmp(string, "JOY13") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 4; } - else if(strcmp(string, "JOY14") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 5; } - else if(strcmp(string, "JOY15") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 6; } - else if(strcmp(string, "JOY16") == 0) { k.useJoypad = 2; k.joypadButton = 1 << 7; } - - else k.virtualKey = (int)string[0]; - - return k; -} - -bool readSettings(void) { - FILE *f; - size_t len = 0; - char *buffer = NULL; - - memcpy(&settings, &defaultSettings, sizeof(struct settings)); - - f = fopen("3DSController.ini", "rb"); - if(!f) { - return false; - } - - fseek(f, 0, SEEK_END); - len = ftell(f); - rewind(f); - - buffer = malloc(len); - if(!buffer) { - fclose(f); - return false; - } - - fread(buffer, 1, len, f); - - char setting[64] = { '\0' }; - - if(getSetting("Port: ", buffer, setting)) { - sscanf(setting, "%d", &settings.port); - } - - if(getSetting("Throttle: ", buffer, setting)) { - sscanf(setting, "%d", &settings.throttle); - } - - if(getSetting("Circle Pad: ", buffer, setting)) { - if(strcmp(setting, "MOUSE") == 0) settings.circlePad = mouse; - else if(strcmp(setting, "JOYSTICK1") == 0) settings.circlePad = joystick1; - else if(strcmp(setting, "JOYSTICK2") == 0) settings.circlePad = joystick2; - else if(strcmp(setting, "KEYS") == 0) settings.circlePad = keys; - } - - if(getSetting("C Stick: ", buffer, setting)) { - if(strcmp(setting, "MOUSE") == 0) settings.cStick = mouse; - else if(strcmp(setting, "JOYSTICK1") == 0) settings.cStick = joystick1; - else if(strcmp(setting, "JOYSTICK2") == 0) settings.cStick = joystick2; - else if(strcmp(setting, "KEYS") == 0) settings.cStick = keys; - } - - if(getSetting("D Pad: ", buffer, setting)) { - if(strcmp(setting, "KEYS") == 0) settings.dPad = key; - if(strcmp(setting, "POV") == 0) settings.dPad = pov; - } - - if(getSetting("Touch: ", buffer, setting)) { - if(strcmp(setting, "MOUSE") == 0) settings.touch = mouse; - else if(strcmp(setting, "JOYSTICK1") == 0) settings.touch = joystick1; - else if(strcmp(setting, "JOYSTICK2") == 0) settings.touch = joystick2; - } - - if(getSetting("Mouse Speed: ", buffer, setting)) { - sscanf(setting, "%d", &settings.mouseSpeed); - } - - if(getSetting("vJoy Device: ", buffer, setting)) { - sscanf(setting, "%d", &settings.vJoyDevice); - } - - if(getSetting("A: ", buffer, setting)) settings.A = getButton(setting); - if(getSetting("B: ", buffer, setting)) settings.B = getButton(setting); - if(getSetting("X: ", buffer, setting)) settings.X = getButton(setting); - if(getSetting("Y: ", buffer, setting)) settings.Y = getButton(setting); - if(getSetting("L: ", buffer, setting)) settings.L = getButton(setting); - if(getSetting("R: ", buffer, setting)) settings.R = getButton(setting); - if(getSetting("ZL: ", buffer, setting)) settings.ZL = getButton(setting); - if(getSetting("ZR: ", buffer, setting)) settings.ZR = getButton(setting); - if(getSetting("Left: ", buffer, setting)) settings.Left = getButton(setting); - if(getSetting("Right: ", buffer, setting)) settings.Right = getButton(setting); - if(getSetting("Up: ", buffer, setting)) settings.Up = getButton(setting); - if(getSetting("Down: ", buffer, setting)) settings.Down = getButton(setting); - if(getSetting("Start: ", buffer, setting)) settings.Start = getButton(setting); - if(getSetting("Select: ", buffer, setting)) settings.Select = getButton(setting); - if(getSetting("Tap: ", buffer, setting)) settings.Tap = getButton(setting); - - if(settings.circlePad == keys) { - if(getSetting("Pad Left: ", buffer, setting)) settings.PadLeft = getButton(setting); - if(getSetting("Pad Right: ", buffer, setting)) settings.PadRight = getButton(setting); - if(getSetting("Pad Up: ", buffer, setting)) settings.PadUp = getButton(setting); - if(getSetting("Pad Down: ", buffer, setting)) settings.PadDown = getButton(setting); - } - - if(settings.cStick == keys) { - if(getSetting("C Stick Left: ", buffer, setting)) settings.CSLeft = getButton(setting); - if(getSetting("C Stick Right: ", buffer, setting)) settings.CSRight = getButton(setting); - if(getSetting("C Stick Up: ", buffer, setting)) settings.CSUp = getButton(setting); - if(getSetting("C Stick Down: ", buffer, setting)) settings.CSDown = getButton(setting); - } - - fclose(f); - - return true; -} diff --git a/PC/source/wireless.c b/PC/source/wireless.c deleted file mode 100644 index 389989a..0000000 --- a/PC/source/wireless.c +++ /dev/null @@ -1,80 +0,0 @@ -#include - -#include "general.h" - -#include "settings.h" - -#include "wireless.h" - -SOCKET listener; -SOCKET client; - -struct sockaddr_in client_in; - -int sockaddr_in_sizePtr = (int)sizeof(struct sockaddr_in); - -struct packet buffer; -char hostName[80]; - -void initNetwork(void) { - WSADATA wsaData; - - WSAStartup(MAKEWORD(2, 2), &wsaData); - - if(gethostname(hostName, sizeof(hostName)) == SOCKET_ERROR) { - error("gethostname()"); - } -} - -void printIPs(void) { - struct hostent *phe = gethostbyname(hostName); - if(phe == 0) { - error("gethostbyname()"); - } - - int i; - for(i = 0; phe->h_addr_list[i] != 0; i++) { - struct in_addr addr; - memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr)); - printf("%s\n", inet_ntoa(addr)); - } - - if(i) { - printf("Usually you want the first one.\n"); - } -} - -void startListening(void) { - int nret; - - listener = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - - if(listener == INVALID_SOCKET) { - error("socket()"); - } - - SOCKADDR_IN serverInfo; - - serverInfo.sin_family = AF_INET; - serverInfo.sin_addr.s_addr = IP; - serverInfo.sin_port = htons(settings.port); - - u_long one = 1; - ioctlsocket(listener, FIONBIO, &one); - - nret = bind(listener, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr)); - - if(nret == SOCKET_ERROR) { - error("bind()"); - } -} - -void sendBuffer(int length) { - if(sendto(listener, (char *)&buffer, length, 0, (struct sockaddr *)&client_in, sizeof(struct sockaddr_in)) != length) { - error("sendto"); - } -} - -int receiveBuffer(int length) { - return recvfrom(listener, (char *)&buffer, length, 0, (struct sockaddr *)&client_in, &sockaddr_in_sizePtr); -} diff --git a/PC/vJoyInterface.dll b/PC/vJoyInterface.dll deleted file mode 100644 index 8832f23..0000000 Binary files a/PC/vJoyInterface.dll and /dev/null differ