2014-12-06 13:29:38 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
2014-12-10 18:52:43 +00:00
|
|
|
#include "wireless.h"
|
|
|
|
|
2014-12-06 13:29:38 +00:00
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
struct settings settings;
|
|
|
|
|
|
|
|
struct settings defaultSettings = {
|
2014-12-13 19:20:11 +00:00
|
|
|
throttle: 20,
|
2014-12-06 13:29:38 +00:00
|
|
|
circlePad: joystick,
|
|
|
|
touch: mouse,
|
|
|
|
A: 'A',
|
|
|
|
B: 'B',
|
|
|
|
X: 'X',
|
|
|
|
Y: 'Y',
|
|
|
|
L: 'L',
|
|
|
|
R: 'R',
|
|
|
|
Left: VK_LEFT,
|
|
|
|
Right: VK_RIGHT,
|
|
|
|
Up: VK_UP,
|
|
|
|
Down: VK_DOWN,
|
|
|
|
Start: VK_RETURN,
|
|
|
|
Select: VK_BACK,
|
|
|
|
Tap: 'T',
|
|
|
|
};
|
|
|
|
|
2014-12-07 15:07:13 +00:00
|
|
|
static bool getSetting(char *name, char *src, char *dest) {
|
2014-12-10 18:52:43 +00:00
|
|
|
char *start = strstr(src, name);
|
2014-12-07 15:07:13 +00:00
|
|
|
|
|
|
|
if(start) {
|
2014-12-10 18:52:43 +00:00
|
|
|
start += strlen(name);
|
|
|
|
|
2014-12-07 15:07:13 +00:00
|
|
|
char *end = start + strlen(start);
|
2014-12-07 15:48:08 +00:00
|
|
|
if(strstr(start, "\n") - 1 < end) end = strstr(start, "\n") - 1;
|
2014-12-07 15:07:13 +00:00
|
|
|
size_t size = (size_t)end - (size_t)start;
|
|
|
|
|
|
|
|
strncpy(dest, start, size);
|
|
|
|
dest[size] = '\0';
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-07 15:32:49 +00:00
|
|
|
static int getButton(char *string) {
|
|
|
|
if(strcmp(string, "SPACE") == 0) return VK_SPACE;
|
2014-12-11 08:50:12 +00:00
|
|
|
else if(strcmp(string, "CLICK") == 0) return VK_LBUTTON;
|
|
|
|
else if(strcmp(string, "RIGHT CLICK") == 0) return VK_RBUTTON;
|
2014-12-07 15:32:49 +00:00
|
|
|
else if(strcmp(string, "ENTER") == 0) return VK_RETURN;
|
|
|
|
else if(strcmp(string, "BACKSPACE") == 0) return VK_BACK;
|
2014-12-11 08:50:12 +00:00
|
|
|
else if(strcmp(string, "SHIFT") == 0) return VK_SHIFT;
|
|
|
|
else if(strcmp(string, "TAB") == 0) return VK_TAB;
|
2014-12-07 15:32:49 +00:00
|
|
|
else if(strcmp(string, "LEFT") == 0) return VK_LEFT;
|
|
|
|
else if(strcmp(string, "RIGHT") == 0) return VK_RIGHT;
|
|
|
|
else if(strcmp(string, "UP") == 0) return VK_UP;
|
|
|
|
else if(strcmp(string, "DOWN") == 0) return VK_DOWN;
|
2014-12-11 08:50:12 +00:00
|
|
|
else if(strcmp(string, "PAGE UP") == 0) return VK_PRIOR;
|
|
|
|
else if(strcmp(string, "PAGE DOWN") == 0) return VK_NEXT;
|
|
|
|
else if(strcmp(string, "WINDOWS") == 0) return VK_LWIN;
|
2014-12-12 18:07:20 +00:00
|
|
|
else if(strcmp(string, "NONE") == 0) return 0;
|
2014-12-07 15:48:08 +00:00
|
|
|
|
|
|
|
return (int)string[0];
|
2014-12-07 15:32:49 +00:00
|
|
|
}
|
|
|
|
|
2014-12-06 13:29:38 +00:00
|
|
|
bool readSettings(void) {
|
2014-12-07 13:48:14 +00:00
|
|
|
FILE *f;
|
|
|
|
size_t len = 0;
|
|
|
|
char *buffer = NULL;
|
|
|
|
|
2014-12-06 13:29:38 +00:00
|
|
|
memcpy(&settings, &defaultSettings, sizeof(struct settings));
|
2014-12-07 13:48:14 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-12-07 15:07:13 +00:00
|
|
|
fread(buffer, 1, len, f);
|
|
|
|
|
2014-12-07 15:32:49 +00:00
|
|
|
char setting[64] = { '\0' };
|
2014-12-07 15:07:13 +00:00
|
|
|
|
2014-12-13 19:20:11 +00:00
|
|
|
if(getSetting("Throttle: ", buffer, setting)) {
|
|
|
|
sscanf(setting, "%d", &settings.throttle);
|
|
|
|
}
|
|
|
|
|
2014-12-10 18:52:43 +00:00
|
|
|
if(getSetting("Port: ", buffer, setting)) {
|
|
|
|
sscanf(setting, "%d", &port);
|
|
|
|
}
|
|
|
|
|
2014-12-10 18:43:06 +00:00
|
|
|
if(getSetting("Circle Pad: ", buffer, setting)) {
|
|
|
|
if(strcmp(setting, "MOUSE") == 0) settings.circlePad = mouse;
|
|
|
|
else if(strcmp(setting, "JOYSTICK") == 0) settings.circlePad = joystick;
|
|
|
|
}
|
2014-12-07 15:07:13 +00:00
|
|
|
|
2014-12-10 18:43:06 +00:00
|
|
|
if(getSetting("Touch: ", buffer, setting)) {
|
|
|
|
if(strcmp(setting, "MOUSE") == 0) settings.touch = mouse;
|
|
|
|
else if(strcmp(setting, "JOYSTICK") == 0) settings.touch = joystick;
|
|
|
|
}
|
2014-12-07 13:48:14 +00:00
|
|
|
|
2014-12-07 15:32:49 +00:00
|
|
|
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("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);
|
2014-12-07 13:48:14 +00:00
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
2014-12-06 13:29:38 +00:00
|
|
|
return true;
|
|
|
|
}
|