PAD: windows: clang-format

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2020-12-12 09:51:22 +01:00 committed by lightningterror
parent 9cdc963c97
commit 8067a480c7
31 changed files with 7710 additions and 6618 deletions

View File

@ -36,7 +36,7 @@ void EnumDevices(int hideDXXinput)
{
// Needed for enumeration of some device types.
dm->ReleaseInput();
InputDeviceManager *oldDm = dm;
InputDeviceManager* oldDm = dm;
dm = new InputDeviceManager();
#ifdef _MSC_VER

View File

@ -22,16 +22,19 @@
#include "InputManager.h"
#include "WndProcEater.h"
Device *dev;
Device* dev;
INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
{
int i;
HWND hWndList = GetDlgItem(hWnd, IDC_DIAG_LIST);
static int fullRefresh;
if (dev) {
switch (uMsg) {
case WM_INITDIALOG: {
if (dev)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
fullRefresh = 1;
SetWindowText(hWnd, dev->displayName);
LVCOLUMNW c;
@ -46,7 +49,8 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
LVITEM item;
item.mask = LVIF_TEXT;
item.iSubItem = 0;
for (i = 0; i < dev->numVirtualControls; i++) {
for (i = 0; i < dev->numVirtualControls; i++)
{
item.pszText = dev->GetVirtualControlName(dev->virtualControls + i);
item.iItem = i;
ListView_InsertItem(hWndList, &item);
@ -54,7 +58,8 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
SetTimer(hWnd, 1, 200, 0);
}
//break;
case WM_TIMER: {
case WM_TIMER:
{
hWndButtonProc.SetWndHandle(hWndList);
InitInfo info = {0, 1, hWnd, &hWndButtonProc};
dm->Update(&info);
@ -63,29 +68,40 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
item.iSubItem = 1;
//ShowWindow(hWndList, 0);
//LockWindowUpdate(hWndList);
if (!dev->active) {
if (!dev->active)
{
item.pszText = L"N/A";
for (i = 0; i < dev->numVirtualControls; i++) {
for (i = 0; i < dev->numVirtualControls; i++)
{
item.iItem = i;
ListView_SetItem(hWndList, &item);
}
fullRefresh = 1;
} else {
for (i = 0; i < dev->numVirtualControls; i++) {
if (fullRefresh || dev->virtualControlState[i] != dev->oldVirtualControlState[i]) {
}
else
{
for (i = 0; i < dev->numVirtualControls; i++)
{
if (fullRefresh || dev->virtualControlState[i] != dev->oldVirtualControlState[i])
{
VirtualControl *c = dev->virtualControls + i;
VirtualControl* c = dev->virtualControls + i;
wchar_t temp[50];
int val = dev->virtualControlState[i];
if (c->uid & (UID_POV)) {
if (c->uid & (UID_POV))
{
wsprintfW(temp, L"%i", val);
} else {
wchar_t *sign = L"";
if (val < 0) {
}
else
{
wchar_t* sign = L"";
if (val < 0)
{
sign = L"-";
val = -val;
}
if ((c->uid & UID_AXIS) && val) {
if ((c->uid & UID_AXIS) && val)
{
val = val;
}
val = (int)floor(0.5 + val * 1000.0 / (double)FULLY_DOWN);
@ -102,9 +118,11 @@ INT_PTR CALLBACK DiagDialog(HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM
//LockWindowUpdate(0);
//ShowWindow(hWndList, 1);
//UpdateWindow(hWnd);
} break;
case WM_NOTIFY: {
NMLVKEYDOWN *n = (NMLVKEYDOWN *)lParam;
}
break;
case WM_NOTIFY:
{
NMLVKEYDOWN* n = (NMLVKEYDOWN*)lParam;
// Don't always get the notification when testing DirectInput non-keyboard devices.
// Don't get it (Or want it) when testing keyboards.
if (n->hdr.idFrom != IDC_DIAG_LIST || n->hdr.code != LVN_KEYDOWN || n->wVKey != VK_ESCAPE)
@ -132,7 +150,8 @@ void Diagnose(int id, HWND hWnd)
{
// init = 0;
dev = dm->devices[id];
for (int i = 0; i < dm->numDevices; i++) {
for (int i = 0; i < dm->numDevices; i++)
{
if (i != id)
dm->DisableDevice(i);
// Shouldn't be needed.

View File

@ -34,7 +34,8 @@
#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p) \
{ \
if (p) { \
if (p) \
{ \
(p)->Release(); \
(p) = NULL; \
} \
@ -53,28 +54,29 @@ inline static u32 flipLong(u32 l)
return (((u32)flipShort((u16)l)) << 16) | flipShort((u16)(l >> 16));
}
static void GUIDtoString(wchar_t *data, const GUID *pg)
static void GUIDtoString(wchar_t* data, const GUID* pg)
{
wsprintfW(data, L"%08X-%04X-%04X-%04X-%04X%08X",
pg->Data1, (u32)pg->Data2, (u32)pg->Data3,
flipShort(((u16 *)pg->Data4)[0]),
flipShort(((u16 *)pg->Data4)[1]),
flipLong(((u32 *)pg->Data4)[1]));
flipShort(((u16*)pg->Data4)[0]),
flipShort(((u16*)pg->Data4)[1]),
flipLong(((u32*)pg->Data4)[1]));
}
struct DirectInput8Data
{
IDirectInput8 *lpDI8;
IDirectInput8* lpDI8;
int refCount;
int deviceCount;
};
DirectInput8Data di8d = {0, 0, 0};
IDirectInput8 *GetDirectInput()
IDirectInput8* GetDirectInput()
{
if (!di8d.lpDI8) {
if (FAILED(DirectInput8Create(hInst, 0x800, IID_IDirectInput8, (void **)&di8d.lpDI8, 0)))
if (!di8d.lpDI8)
{
if (FAILED(DirectInput8Create(hInst, 0x800, IID_IDirectInput8, (void**)&di8d.lpDI8, 0)))
return 0;
}
di8d.refCount++;
@ -82,22 +84,25 @@ IDirectInput8 *GetDirectInput()
}
void ReleaseDirectInput()
{
if (di8d.refCount) {
if (di8d.refCount)
{
di8d.refCount--;
if (!di8d.refCount) {
if (!di8d.refCount)
{
di8d.lpDI8->Release();
di8d.lpDI8 = 0;
}
}
}
static int StringToGUID(GUID *pg, wchar_t *dataw)
static int StringToGUID(GUID* pg, wchar_t* dataw)
{
char data[100];
if (wcslen(dataw) > 50)
return 0;
int w = 0;
while (dataw[w]) {
while (dataw[w])
{
data[w] = (char)dataw[w];
w++;
}
@ -108,16 +113,16 @@ static int StringToGUID(GUID *pg, wchar_t *dataw)
temp + 2, temp + 3, temp + 4);
pg->Data2 = (u16)temp[0];
pg->Data3 = (u16)temp[1];
((u16 *)pg->Data4)[0] = flipShort((u16)temp[2]);
((u16 *)pg->Data4)[1] = flipShort((u16)temp[3]);
((u32 *)pg->Data4)[1] = flipLong(temp[4]);
((u16*)pg->Data4)[0] = flipShort((u16)temp[2]);
((u16*)pg->Data4)[1] = flipShort((u16)temp[3]);
((u32*)pg->Data4)[1] = flipLong(temp[4]);
return 1;
}
struct DI8Effect
{
IDirectInputEffect *die;
IDirectInputEffect* die;
int scale;
};
@ -126,11 +131,11 @@ BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef);
class DirectInputDevice : public Device
{
public:
DI8Effect *diEffects;
DI8Effect* diEffects;
IDirectInputDevice8 *did;
IDirectInputDevice8* did;
GUID guidInstance;
DirectInputDevice(DeviceType type, IDirectInputDevice8 *did, wchar_t *displayName, wchar_t *instanceID, wchar_t *productID, GUID guid)
DirectInputDevice(DeviceType type, IDirectInputDevice8* did, wchar_t* displayName, wchar_t* instanceID, wchar_t* productID, GUID guid)
: Device(DI, type, displayName, instanceID, productID)
{
diEffects = 0;
@ -141,17 +146,21 @@ public:
did->Release();
}
void SetEffect(ForceFeedbackBinding *binding, unsigned char force)
void SetEffect(ForceFeedbackBinding* binding, unsigned char force)
{
int index = 0;
if (!diEffects) {
if (!diEffects)
{
return;
}
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
int padtype = config.padConfigs[port][slot].type;
unsigned int diff = binding - pads[port][slot][padtype].ffBindings;
if (diff < (unsigned int)pads[port][slot][padtype].numFFBindings) {
if (diff < (unsigned int)pads[port][slot][padtype].numFFBindings)
{
index += diff;
port = 2;
break;
@ -159,8 +168,9 @@ public:
index += pads[port][slot][padtype].numFFBindings;
}
}
IDirectInputEffect *die = diEffects[index].die;
if (die) {
IDirectInputEffect* die = diEffects[index].die;
if (die)
{
DIEFFECT dieffect;
memset(&dieffect, 0, sizeof(dieffect));
union
@ -176,16 +186,21 @@ public:
if (magnitude > 10000)
magnitude = 10000;
int type = ffEffectTypes[binding->effectIndex].type;
if (type == EFFECT_CONSTANT) {
if (type == EFFECT_CONSTANT)
{
dieffect.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
constant.lMagnitude = magnitude;
} else if (type == EFFECT_PERIODIC) {
}
else if (type == EFFECT_PERIODIC)
{
dieffect.cbTypeSpecificParams = sizeof(DIPERIODIC);
periodic.dwMagnitude = 0;
periodic.lOffset = magnitude;
periodic.dwPhase = 0;
periodic.dwPeriod = 2000000;
} else if (type == EFFECT_RAMP) {
}
else if (type == EFFECT_RAMP)
{
dieffect.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
ramp.lEnd = ramp.lStart = magnitude;
}
@ -195,22 +210,24 @@ public:
}
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
int i;
IDirectInput8 *di8 = GetDirectInput();
IDirectInput8* di8 = GetDirectInput();
Deactivate();
if (!di8)
return 0;
if (DI_OK != di8->CreateDevice(guidInstance, &did, 0)) {
if (DI_OK != di8->CreateDevice(guidInstance, &did, 0))
{
ReleaseDirectInput();
did = 0;
return 0;
}
{
DIOBJECTDATAFORMAT *formats = (DIOBJECTDATAFORMAT *)calloc(numPhysicalControls, sizeof(DIOBJECTDATAFORMAT));
for (i = 0; i < numPhysicalControls; i++) {
DIOBJECTDATAFORMAT* formats = (DIOBJECTDATAFORMAT*)calloc(numPhysicalControls, sizeof(DIOBJECTDATAFORMAT));
for (i = 0; i < numPhysicalControls; i++)
{
formats[i].dwType = physicalControls[i].type | DIDFT_MAKEINSTANCE(physicalControls[i].id);
formats[i].dwOfs = 4 * i;
}
@ -222,8 +239,10 @@ public:
format.dwNumObjs = numPhysicalControls;
format.rgodf = formats;
int res = did->SetDataFormat(&format);
for (i = 0; i < numPhysicalControls; i++) {
if (physicalControls[i].type == ABSAXIS) {
for (i = 0; i < numPhysicalControls; i++)
{
if (physicalControls[i].type == ABSAXIS)
{
DIPROPRANGE prop;
prop.diph.dwHeaderSize = sizeof(DIPROPHEADER);
prop.diph.dwSize = sizeof(DIPROPRANGE);
@ -251,14 +270,20 @@ public:
free(formats);
}
// Note: Have to use hWndTop to properly hide cursor for mouse device.
if (type == OTHER) {
if (type == OTHER)
{
did->SetCooperativeLevel(initInfo->hWndTop, DISCL_BACKGROUND | DISCL_EXCLUSIVE);
} else if (type == KEYBOARD) {
}
else if (type == KEYBOARD)
{
did->SetCooperativeLevel(initInfo->hWndTop, DISCL_FOREGROUND);
} else {
}
else
{
did->SetCooperativeLevel(initInfo->hWndTop, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
}
if (did->Acquire() != DI_OK) {
if (did->Acquire() != DI_OK)
{
did->Release();
did = 0;
ReleaseDirectInput();
@ -266,16 +291,19 @@ public:
}
AllocState();
int count = GetFFBindingCount();
diEffects = (DI8Effect *)calloc(count, sizeof(DI8Effect));
diEffects = (DI8Effect*)calloc(count, sizeof(DI8Effect));
i = 0;
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
int padtype = config.padConfigs[port][slot].type;
int subIndex = i;
for (int j = 0; j < pads[port][slot][padtype].numFFBindings; j++) {
ForceFeedbackBinding *b = 0;
for (int j = 0; j < pads[port][slot][padtype].numFFBindings; j++)
{
ForceFeedbackBinding* b = 0;
b = &pads[port][slot][padtype].ffBindings[i - subIndex];
ForceFeedbackEffectType *eff = ffEffectTypes + b->effectIndex;
ForceFeedbackEffectType* eff = ffEffectTypes + b->effectIndex;
GUID guid;
if (!StringToGUID(&guid, eff->effectID))
continue;
@ -294,26 +322,34 @@ public:
DICONSTANTFORCE constant;
} stuff = {0, 0, 0, 0};
if (eff->type == EFFECT_CONSTANT) {
if (eff->type == EFFECT_CONSTANT)
{
dieffect.cbTypeSpecificParams = sizeof(DICONSTANTFORCE);
} else if (eff->type == EFFECT_PERIODIC) {
}
else if (eff->type == EFFECT_PERIODIC)
{
dieffect.cbTypeSpecificParams = sizeof(DIPERIODIC);
} else if (eff->type == EFFECT_RAMP) {
}
else if (eff->type == EFFECT_RAMP)
{
dieffect.cbTypeSpecificParams = sizeof(DIRAMPFORCE);
}
dieffect.lpvTypeSpecificParams = &stuff;
int maxForce = 0;
int numAxes = 0;
int *axes = (int *)malloc(sizeof(int) * 3 * numFFAxes);
DWORD *axisIDs = (DWORD *)(axes + numFFAxes);
LONG *dirList = (LONG *)(axisIDs + numFFAxes);
int* axes = (int*)malloc(sizeof(int) * 3 * numFFAxes);
DWORD* axisIDs = (DWORD*)(axes + numFFAxes);
LONG* dirList = (LONG*)(axisIDs + numFFAxes);
dieffect.rgdwAxes = axisIDs;
dieffect.rglDirection = dirList;
for (int k = 0; k < numFFAxes; k++) {
if (b->axes[k].force) {
for (int k = 0; k < numFFAxes; k++)
{
if (b->axes[k].force)
{
int force = abs(b->axes[k].force);
if (force > maxForce) {
if (force > maxForce)
{
maxForce = force;
}
axes[numAxes] = k;
@ -322,13 +358,15 @@ public:
numAxes++;
}
}
if (!numAxes) {
if (!numAxes)
{
free(axes);
continue;
}
dieffect.cAxes = numAxes;
diEffects[i].scale = maxForce;
if (!SUCCEEDED(did->CreateEffect(guid, &dieffect, &diEffects[i].die, 0))) {
if (!SUCCEEDED(did->CreateEffect(guid, &dieffect, &diEffects[i].die, 0)))
{
diEffects[i].die = 0;
diEffects[i].scale = 0;
}
@ -347,18 +385,24 @@ public:
{
if (!active)
return 0;
if (numPhysicalControls) {
if (numPhysicalControls)
{
HRESULT res = did->Poll();
// ??
if ((res != DI_OK && res != DI_NOEFFECT) ||
DI_OK != did->GetDeviceState(4 * numPhysicalControls, physicalControlState)) {
DI_OK != did->GetDeviceState(4 * numPhysicalControls, physicalControlState))
{
Deactivate();
return 0;
}
for (int i = 0; i < numPhysicalControls; i++) {
if (physicalControls[i].type & RELAXIS) {
for (int i = 0; i < numPhysicalControls; i++)
{
if (physicalControls[i].type & RELAXIS)
{
physicalControlState[i] *= (FULLY_DOWN / 3);
} else if (physicalControls[i].type & BUTTON) {
}
else if (physicalControls[i].type & BUTTON)
{
physicalControlState[i] = (physicalControlState[i] & 0x80) * FULLY_DOWN / 128;
}
}
@ -369,8 +413,10 @@ public:
int GetFFBindingCount()
{
int count = 0;
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
int padtype = config.padConfigs[port][slot].type;
count += pads[port][slot][padtype].numFFBindings;
}
@ -381,10 +427,13 @@ public:
void Deactivate()
{
FreeState();
if (diEffects) {
if (diEffects)
{
int count = GetFFBindingCount();
for (int i = 0; i < count; i++) {
if (diEffects[i].die) {
for (int i = 0; i < count; i++)
{
if (diEffects[i].die)
{
diEffects[i].die->Stop();
diEffects[i].die->Release();
}
@ -392,7 +441,8 @@ public:
free(diEffects);
diEffects = 0;
}
if (active) {
if (active)
{
did->Unacquire();
did->Release();
ReleaseDirectInput();
@ -408,16 +458,23 @@ public:
BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef)
{
DirectInputDevice *did = (DirectInputDevice *)pvRef;
DirectInputDevice* did = (DirectInputDevice*)pvRef;
EffectType type;
int diType = DIEFT_GETTYPE(pdei->dwEffType);
if (diType == DIEFT_CONSTANTFORCE) {
if (diType == DIEFT_CONSTANTFORCE)
{
type = EFFECT_CONSTANT;
} else if (diType == DIEFT_RAMPFORCE) {
}
else if (diType == DIEFT_RAMPFORCE)
{
type = EFFECT_RAMP;
} else if (diType == DIEFT_PERIODIC) {
}
else if (diType == DIEFT_PERIODIC)
{
type = EFFECT_PERIODIC;
} else {
}
else
{
return DIENUM_CONTINUE;
}
wchar_t guidString[50];
@ -429,8 +486,9 @@ BOOL CALLBACK EnumEffectsCallback(LPCDIEFFECTINFOW pdei, LPVOID pvRef)
BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
DirectInputDevice *did = (DirectInputDevice *)pvRef;
if (lpddoi->dwType & DIDFT_FFACTUATOR) {
DirectInputDevice* did = (DirectInputDevice*)pvRef;
if (lpddoi->dwType & DIDFT_FFACTUATOR)
{
did->AddFFAxis(lpddoi->tszName, lpddoi->dwType);
}
@ -449,14 +507,17 @@ BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID
else
return DIENUM_CONTINUE;
// If too many objects, ignore extra buttons.
if ((did->numPhysicalControls > 255 && DIDFT_GETINSTANCE(lpddoi->dwType) > 255) && (type & (DIDFT_PSHBUTTON | DIDFT_TGLBUTTON))) {
if ((did->numPhysicalControls > 255 && DIDFT_GETINSTANCE(lpddoi->dwType) > 255) && (type & (DIDFT_PSHBUTTON | DIDFT_TGLBUTTON)))
{
int i;
for (i = did->numPhysicalControls - 1; i > did->numPhysicalControls - 4; i--) {
for (i = did->numPhysicalControls - 1; i > did->numPhysicalControls - 4; i--)
{
if (!lpddoi->tszName[0])
break;
const wchar_t *s1 = lpddoi->tszName;
const wchar_t *s2 = did->physicalControls[i].name;
while (*s1 && *s1 == *s2) {
const wchar_t* s1 = lpddoi->tszName;
const wchar_t* s2 = did->physicalControls[i].name;
while (*s1 && *s1 == *s2)
{
s1++;
s2++;
}
@ -467,11 +528,13 @@ BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID
while (s1 != lpddoi->tszName && (s1[-1] >= '0' && s1[-1] <= '9'))
s1--;
int check = 0;
while (*s1 >= '0' && *s1 <= '9') {
while (*s1 >= '0' && *s1 <= '9')
{
check = check * 10 + *s1 - '0';
s1++;
}
while (*s2 >= '0' && *s2 <= '9') {
while (*s2 >= '0' && *s2 <= '9')
{
s2++;
}
// If perfect match other than final number > 30, then break.
@ -479,16 +542,20 @@ BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID
if (!*s1 && !*s2 && check > 30)
break;
}
if (i != did->numPhysicalControls - 4) {
if (i != did->numPhysicalControls - 4)
{
return DIENUM_CONTINUE;
}
}
int vkey = 0;
if (lpddoi->tszName[0] && did->type == KEYBOARD) {
for (u32 i = 0; i < 256; i++) {
wchar_t *t = GetVKStringW((u8)i);
if (!wcsicmp(lpddoi->tszName, t)) {
if (lpddoi->tszName[0] && did->type == KEYBOARD)
{
for (u32 i = 0; i < 256; i++)
{
wchar_t* t = GetVKStringW((u8)i);
if (!wcsicmp(lpddoi->tszName, t))
{
vkey = i;
break;
}
@ -500,12 +567,12 @@ BOOL CALLBACK EnumDeviceObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID
// Evil code from MS's site. If only they'd just made a way to get
// an XInput device's GUID directly in the first place...
BOOL IsXInputDevice(const GUID *pGuidProductFromDirectInput)
BOOL IsXInputDevice(const GUID* pGuidProductFromDirectInput)
{
IWbemLocator *pIWbemLocator = NULL;
IEnumWbemClassObject *pEnumDevices = NULL;
IWbemClassObject *pDevices[20] = {0};
IWbemServices *pIWbemServices = NULL;
IWbemLocator* pIWbemLocator = NULL;
IEnumWbemClassObject* pEnumDevices = NULL;
IWbemClassObject* pDevices[20] = {0};
IWbemServices* pIWbemServices = NULL;
BSTR bstrNamespace = NULL;
BSTR bstrDeviceID = NULL;
BSTR bstrClassName = NULL;
@ -524,7 +591,7 @@ BOOL IsXInputDevice(const GUID *pGuidProductFromDirectInput)
NULL,
CLSCTX_INPROC_SERVER,
__uuidof(IWbemLocator),
(LPVOID *)&pIWbemLocator);
(LPVOID*)&pIWbemLocator);
if (FAILED(hr) || pIWbemLocator == NULL)
goto LCleanup;
@ -553,7 +620,8 @@ BOOL IsXInputDevice(const GUID *pGuidProductFromDirectInput)
goto LCleanup;
// Loop over all devices
for (;;) {
for (;;)
{
// Get 20 at a time
hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned);
if (FAILED(hr))
@ -561,27 +629,33 @@ BOOL IsXInputDevice(const GUID *pGuidProductFromDirectInput)
if (uReturned == 0)
break;
for (iDevice = 0; iDevice < uReturned; iDevice++) {
for (iDevice = 0; iDevice < uReturned; iDevice++)
{
// For each device, get its device ID
hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL) {
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL)
{
// Check if the device ID contains "IG_". If it does, then it's an XInput device
// This information can not be found from DirectInput
if (wcsstr(var.bstrVal, L"IG_")) {
if (wcsstr(var.bstrVal, L"IG_"))
{
// If it does, then get the VID/PID from var.bstrVal
DWORD dwPid = 0, dwVid = 0;
WCHAR *strVid = wcsstr(var.bstrVal, L"VID_");
if (strVid) {
WCHAR* strVid = wcsstr(var.bstrVal, L"VID_");
if (strVid)
{
dwVid = wcstoul(strVid + 4, 0, 16);
}
WCHAR *strPid = wcsstr(var.bstrVal, L"PID_");
if (strPid) {
WCHAR* strPid = wcsstr(var.bstrVal, L"PID_");
if (strPid)
{
dwPid = wcstoul(strPid + 4, 0, 16);
}
// Compare the VID/PID to the DInput device
DWORD dwVidPid = MAKELONG(dwVid, dwPid);
if (dwVidPid == pGuidProductFromDirectInput->Data1) {
if (dwVidPid == pGuidProductFromDirectInput->Data1)
{
bIsXinputDevice = true;
goto LCleanup;
}
@ -613,43 +687,55 @@ LCleanup:
struct DeviceEnumInfo
{
IDirectInput8 *di8;
IDirectInput8* di8;
int ignoreXInput;
};
BOOL CALLBACK EnumCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
IDirectInput8 *di8 = ((DeviceEnumInfo *)pvRef)->di8;
const wchar_t *name;
IDirectInput8* di8 = ((DeviceEnumInfo*)pvRef)->di8;
const wchar_t* name;
wchar_t temp[40];
//if (((DeviceEnumInfo*)pvRef)->ignoreXInput && lpddi->
if (lpddi->tszInstanceName[0]) {
if (lpddi->tszInstanceName[0])
{
name = lpddi->tszInstanceName;
} else if (lpddi->tszProductName[0]) {
}
else if (lpddi->tszProductName[0])
{
name = lpddi->tszProductName;
} else {
}
else
{
wsprintfW(temp, L"Device %i", di8d.deviceCount);
name = temp;
}
di8d.deviceCount++;
wchar_t *fullName = (wchar_t *)malloc((wcslen(name) + 4) * sizeof(wchar_t));
wchar_t* fullName = (wchar_t*)malloc((wcslen(name) + 4) * sizeof(wchar_t));
wsprintf(fullName, L"DX %s", name);
wchar_t instanceID[100];
wchar_t productID[100];
GUIDtoString(instanceID, &lpddi->guidInstance);
GUIDtoString(productID, &lpddi->guidProduct);
DeviceType type = OTHER;
if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_KEYBOARD) {
if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_KEYBOARD)
{
type = KEYBOARD;
} else if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_MOUSE) {
}
else if ((lpddi->dwDevType & 0xFF) == DI8DEVTYPE_MOUSE)
{
type = MOUSE;
}
IDirectInputDevice8 *did;
if (DI_OK == di8->CreateDevice(lpddi->guidInstance, &did, 0)) {
DirectInputDevice *dev = new DirectInputDevice(type, did, fullName, instanceID, productID, lpddi->guidInstance);
if (dev->numPhysicalControls || dev->numFFAxes) {
IDirectInputDevice8* did;
if (DI_OK == di8->CreateDevice(lpddi->guidInstance, &did, 0))
{
DirectInputDevice* dev = new DirectInputDevice(type, did, fullName, instanceID, productID, lpddi->guidInstance);
if (dev->numPhysicalControls || dev->numFFAxes)
{
dm->AddDevice(dev);
} else {
}
else
{
delete dev;
}
}

View File

@ -41,15 +41,15 @@
unsigned int lastDS3Check = 0;
unsigned int lastDS3Enum = 0;
typedef void(__cdecl *_usb_init)(void);
typedef int(__cdecl *_usb_close)(usb_dev_handle *dev);
typedef int(__cdecl *_usb_get_string_simple)(usb_dev_handle *dev, int index, char *buf, size_t buflen);
typedef usb_dev_handle *(__cdecl *_usb_open)(struct usb_device *dev);
typedef int(__cdecl *_usb_find_busses)(void);
typedef int(__cdecl *_usb_find_devices)(void);
typedef struct usb_bus *(__cdecl *_usb_get_busses)(void);
typedef usb_dev_handle *(__cdecl *_usb_open)(struct usb_device *dev);
typedef int(__cdecl *_usb_control_msg)(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);
typedef void(__cdecl* _usb_init)(void);
typedef int(__cdecl* _usb_close)(usb_dev_handle* dev);
typedef int(__cdecl* _usb_get_string_simple)(usb_dev_handle* dev, int index, char* buf, size_t buflen);
typedef usb_dev_handle*(__cdecl* _usb_open)(struct usb_device* dev);
typedef int(__cdecl* _usb_find_busses)(void);
typedef int(__cdecl* _usb_find_devices)(void);
typedef struct usb_bus*(__cdecl* _usb_get_busses)(void);
typedef usb_dev_handle*(__cdecl* _usb_open)(struct usb_device* dev);
typedef int(__cdecl* _usb_control_msg)(usb_dev_handle* dev, int requesttype, int request, int value, int index, char* bytes, int size, int timeout);
_usb_init pusb_init;
_usb_close pusb_close;
@ -64,18 +64,22 @@ HMODULE hModLibusb = 0;
void UninitLibUsb()
{
if (hModLibusb) {
if (hModLibusb)
{
FreeLibrary(hModLibusb);
hModLibusb = 0;
}
}
void TryInitDS3(usb_device *dev)
void TryInitDS3(usb_device* dev)
{
while (dev) {
if (dev->descriptor.idVendor == VID && dev->descriptor.idProduct == PID) {
usb_dev_handle *handle = pusb_open(dev);
if (handle) {
while (dev)
{
if (dev->descriptor.idVendor == VID && dev->descriptor.idProduct == PID)
{
usb_dev_handle* handle = pusb_open(dev);
if (handle)
{
char junk[20];
// This looks like HidD_GetFeature with a feature report id of 0xF2 to me and a length of 17.
// That doesn't work, however, and 17 is shorter than the report length.
@ -83,8 +87,10 @@ void TryInitDS3(usb_device *dev)
pusb_close(handle);
}
}
if (dev->num_children) {
for (int i = 0; i < dev->num_children; i++) {
if (dev->num_children)
{
for (int i = 0; i < dev->num_children; i++)
{
TryInitDS3(dev->children[i]);
}
}
@ -94,7 +100,8 @@ void TryInitDS3(usb_device *dev)
void DS3Enum(unsigned int time)
{
if (time - lastDS3Enum < DOUBLE_ENUM_DELAY) {
if (time - lastDS3Enum < DOUBLE_ENUM_DELAY)
{
return;
}
lastDS3Enum = time;
@ -104,16 +111,19 @@ void DS3Enum(unsigned int time)
void DS3Check(unsigned int time)
{
if (time - lastDS3Check < DOUBLE_CHECK_DELAY) {
if (time - lastDS3Check < DOUBLE_CHECK_DELAY)
{
return;
}
if (!lastDS3Check) {
if (!lastDS3Check)
{
DS3Enum(time);
}
lastDS3Check = time;
usb_bus *bus = pusb_get_busses();
while (bus) {
usb_bus* bus = pusb_get_busses();
while (bus)
{
TryInitDS3(bus->devices);
bus = bus->next;
}
@ -121,11 +131,13 @@ void DS3Check(unsigned int time)
int InitLibUsb()
{
if (hModLibusb) {
if (hModLibusb)
{
return 1;
}
hModLibusb = LoadLibraryA("C:\\windows\\system32\\libusb0.dll");
if (hModLibusb) {
if (hModLibusb)
{
if ((pusb_init = (_usb_init)GetProcAddress(hModLibusb, "usb_init")) &&
(pusb_close = (_usb_close)GetProcAddress(hModLibusb, "usb_close")) &&
(pusb_get_string_simple = (_usb_get_string_simple)GetProcAddress(hModLibusb, "usb_get_string_simple")) &&
@ -133,7 +145,8 @@ int InitLibUsb()
(pusb_find_busses = (_usb_find_busses)GetProcAddress(hModLibusb, "usb_find_busses")) &&
(pusb_find_devices = (_usb_find_devices)GetProcAddress(hModLibusb, "usb_find_devices")) &&
(pusb_get_busses = (_usb_get_busses)GetProcAddress(hModLibusb, "usb_get_busses")) &&
(pusb_control_msg = (_usb_control_msg)GetProcAddress(hModLibusb, "usb_control_msg"))) {
(pusb_control_msg = (_usb_control_msg)GetProcAddress(hModLibusb, "usb_control_msg")))
{
pusb_init();
return 1;
}
@ -227,7 +240,8 @@ public:
void QueueWrite()
{
// max of 2 queued writes allowed, one for either motor.
if (writeQueued < 2) {
if (writeQueued < 2)
{
writeQueued++;
StartWrite();
}
@ -235,7 +249,8 @@ public:
int StartWrite()
{
if (!writing && writeQueued) {
if (!writing && writeQueued)
{
lastWrite = GetTickCount();
writing++;
writeQueued--;
@ -248,7 +263,8 @@ public:
sendState.motors[1].force = (unsigned char)bigForce;
sendState.motors[0].force = (unsigned char)(vibration[1] >= FULLY_DOWN / 2);
// Can't seem to have them both non-zero at once.
if (sendState.motors[writeCount & 1].force) {
if (sendState.motors[writeCount & 1].force)
{
sendState.motors[(writeCount & 1) ^ 1].force = 0;
sendState.motors[(writeCount & 1) ^ 1].duration = 0;
}
@ -260,7 +276,7 @@ public:
return 1;
}
DualShock3Device(int index, wchar_t *name, wchar_t *path)
DualShock3Device(int index, wchar_t* name, wchar_t* path)
: Device(DS3, OTHER, name, path, L"DualShock 3")
{
writeCount = 0;
@ -279,14 +295,19 @@ public:
vibration[0] = vibration[1] = 0;
this->index = index;
int i;
for (i = 0; i < 16; i++) {
if (i != 14 && i != 15 && i != 8 && i != 9) {
for (i = 0; i < 16; i++)
{
if (i != 14 && i != 15 && i != 8 && i != 9)
{
AddPhysicalControl(PRESSURE_BTN, i, 0);
} else {
}
else
{
AddPhysicalControl(PSHBTN, i, 0);
}
}
for (; i < 23; i++) {
for (; i < 23; i++)
{
AddPhysicalControl(ABSAXIS, i, 0);
}
AddFFAxis(L"Big Motor", 0);
@ -295,9 +316,9 @@ public:
hFile = INVALID_HANDLE_VALUE;
}
wchar_t *GetPhysicalControlName(PhysicalControl *c)
wchar_t* GetPhysicalControlName(PhysicalControl* c)
{
const static wchar_t *names[] = {
const static wchar_t* names[] = {
L"Square",
L"Cross",
L"Circle",
@ -323,13 +344,14 @@ public:
L"???",
};
unsigned int i = (unsigned int)(c - physicalControls);
if (i < sizeof(names) / sizeof(names[0])) {
return (wchar_t *)names[i];
if (i < sizeof(names) / sizeof(names[0]))
{
return (wchar_t*)names[i];
}
return Device::GetPhysicalControlName(c);
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
if (active)
Deactivate();
@ -339,7 +361,8 @@ public:
writeop.hEvent = CreateEvent(0, 0, 0, 0);
hFile = CreateFileW(instanceID, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (!readop.hEvent || !writeop.hEvent || hFile == INVALID_HANDLE_VALUE ||
!StartRead()) {
!StartRead())
{
Deactivate();
return 0;
}
@ -356,14 +379,18 @@ public:
readop.hEvent,
writeop.hEvent};
unsigned int time = GetTickCount();
if (time - lastWrite > UPDATE_INTERVAL) {
if (time - lastWrite > UPDATE_INTERVAL)
{
QueueWrite();
}
while (1) {
while (1)
{
DWORD res = WaitForMultipleObjects(2, h, 0, 0);
if (res == WAIT_OBJECT_0) {
if (res == WAIT_OBJECT_0)
{
dataLastReceived = time;
if (!StartRead()) {
if (!StartRead())
{
Deactivate();
return 0;
}
@ -392,18 +419,26 @@ public:
physicalControlState[21] = CharToAxis(getState[44] + 128);
physicalControlState[22] = CharToAxis(getState[46] + 128);
continue;
} else if (res == WAIT_OBJECT_0 + 1) {
}
else if (res == WAIT_OBJECT_0 + 1)
{
writing = 0;
if (!writeQueued && (vibration[0] | vibration[1])) {
if (!writeQueued && (vibration[0] | vibration[1]))
{
QueueWrite();
}
if (!StartWrite()) {
if (!StartWrite())
{
Deactivate();
return 0;
}
} else {
if (time - dataLastReceived >= DEVICE_CHECK_DELAY) {
if (time - dataLastReceived >= DEVICE_ENUM_DELAY) {
}
else
{
if (time - dataLastReceived >= DEVICE_CHECK_DELAY)
{
if (time - dataLastReceived >= DEVICE_ENUM_DELAY)
{
DS3Enum(time);
}
DS3Check(time);
@ -419,12 +454,15 @@ public:
{
ps2Vibration[port][slot][motor] = force;
vibration[0] = vibration[1] = 0;
for (int p = 0; p < 2; p++) {
for (int s = 0; s < 4; s++) {
for (int p = 0; p < 2; p++)
{
for (int s = 0; s < 4; s++)
{
int padtype = config.padConfigs[p][s].type;
for (int i = 0; i < pads[p][s][padtype].numFFBindings; i++) {
for (int i = 0; i < pads[p][s][padtype].numFFBindings; i++)
{
// Technically should also be a *65535/BASE_SENSITIVITY, but that's close enough to 1 for me.
ForceFeedbackBinding *ffb = &pads[p][s][padtype].ffBindings[i];
ForceFeedbackBinding* ffb = &pads[p][s][padtype].ffBindings[i];
vibration[0] += (int)((ffb->axes[0].force * (__int64)ps2Vibration[p][s][ffb->motor]) / 255);
vibration[1] += (int)((ffb->axes[1].force * (__int64)ps2Vibration[p][s][ffb->motor]) / 255);
}
@ -435,7 +473,7 @@ public:
QueueWrite();
}
void SetEffect(ForceFeedbackBinding *binding, unsigned char force)
void SetEffect(ForceFeedbackBinding* binding, unsigned char force)
{
PadBindings pBackup = pads[0][0][0];
pads[0][0][0].ffBindings = binding;
@ -446,15 +484,18 @@ public:
void Deactivate()
{
if (hFile != INVALID_HANDLE_VALUE) {
if (hFile != INVALID_HANDLE_VALUE)
{
CancelIo(hFile);
CloseHandle(hFile);
hFile = INVALID_HANDLE_VALUE;
}
if (readop.hEvent) {
if (readop.hEvent)
{
CloseHandle(readop.hEvent);
}
if (writeop.hEvent) {
if (writeop.hEvent)
{
CloseHandle(writeop.hEvent);
}
writing = 0;
@ -476,16 +517,18 @@ void EnumDualShock3s()
if (!InitLibUsb())
return;
HidDeviceInfo *foundDevs = 0;
HidDeviceInfo* foundDevs = 0;
int numDevs = FindHids(&foundDevs, VID, PID);
if (!numDevs)
return;
int index = 0;
for (int i = 0; i < numDevs; i++) {
for (int i = 0; i < numDevs; i++)
{
if (foundDevs[i].caps.FeatureReportByteLength == 49 &&
foundDevs[i].caps.InputReportByteLength == 49 &&
foundDevs[i].caps.OutputReportByteLength == 49) {
foundDevs[i].caps.OutputReportByteLength == 49)
{
wchar_t temp[100];
wsprintfW(temp, L"DualShock 3 #%i", index + 1);
dm->AddDevice(new DualShock3Device(index, temp, foundDevs[i].path));

View File

@ -45,7 +45,7 @@ typedef int64_t __int64;
#include <cstdarg>
template <typename Array>
void wsprintfW(Array &buf, const wchar_t *format, ...)
void wsprintfW(Array& buf, const wchar_t* format, ...)
{
va_list a;
va_start(a, format);
@ -56,7 +56,7 @@ void wsprintfW(Array &buf, const wchar_t *format, ...)
}
template <typename Array>
void wsprintf(Array &buf, const wchar_t *format, ...)
void wsprintf(Array& buf, const wchar_t* format, ...)
{
va_list a;
va_start(a, format);
@ -66,7 +66,7 @@ void wsprintf(Array &buf, const wchar_t *format, ...)
va_end(a);
}
static inline int wcsicmp(const wchar_t *w1, const wchar_t *w2)
static inline int wcsicmp(const wchar_t* w1, const wchar_t* w2)
{
// I didn't find a way to put ignore case ...
return wcscmp(w1, w2);
@ -87,7 +87,7 @@ static inline unsigned int timeGetTime()
#include <X11/Xutil.h>
extern Display *GSdsp;
extern Display* GSdsp;
extern Window GSwin;
#endif
@ -134,4 +134,4 @@ extern Window GSwin;
extern HINSTANCE hInst;
#endif
// Needed for config screen
void GetNameAndVersionString(wchar_t *out);
void GetNameAndVersionString(wchar_t* out);

View File

@ -19,23 +19,25 @@
#include <setupapi.h>
#include <hidsdi.h>
int FindHids(HidDeviceInfo **foundDevs, int vid, int pid)
int FindHids(HidDeviceInfo** foundDevs, int vid, int pid)
{
GUID GUID_DEVINTERFACE_HID;
int numFoundDevs = 0;
*foundDevs = 0;
HidD_GetHidGuid(&GUID_DEVINTERFACE_HID);
HDEVINFO hdev = SetupDiGetClassDevs(&GUID_DEVINTERFACE_HID, 0, 0, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (hdev != INVALID_HANDLE_VALUE) {
if (hdev != INVALID_HANDLE_VALUE)
{
SP_DEVICE_INTERFACE_DATA devInterfaceData;
devInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
for (int i = 0; SetupDiEnumDeviceInterfaces(hdev, 0, &GUID_DEVINTERFACE_HID, i, &devInterfaceData); i++) {
for (int i = 0; SetupDiEnumDeviceInterfaces(hdev, 0, &GUID_DEVINTERFACE_HID, i, &devInterfaceData); i++)
{
DWORD size = 0;
SetupDiGetDeviceInterfaceDetail(hdev, &devInterfaceData, 0, 0, &size, 0);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER || !size)
continue;
SP_DEVICE_INTERFACE_DETAIL_DATA *devInterfaceDetails = (SP_DEVICE_INTERFACE_DETAIL_DATA *)malloc(size);
SP_DEVICE_INTERFACE_DETAIL_DATA* devInterfaceDetails = (SP_DEVICE_INTERFACE_DETAIL_DATA*)malloc(size);
if (!devInterfaceDetails)
continue;
@ -47,19 +49,25 @@ int FindHids(HidDeviceInfo **foundDevs, int vid, int pid)
continue;
HANDLE hfile = CreateFile(devInterfaceDetails->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
if (hfile != INVALID_HANDLE_VALUE) {
if (hfile != INVALID_HANDLE_VALUE)
{
HIDD_ATTRIBUTES attributes;
attributes.Size = sizeof(attributes);
if (HidD_GetAttributes(hfile, &attributes)) {
if (attributes.VendorID == vid && attributes.ProductID == pid) {
if (HidD_GetAttributes(hfile, &attributes))
{
if (attributes.VendorID == vid && attributes.ProductID == pid)
{
PHIDP_PREPARSED_DATA pData;
HIDP_CAPS caps;
if (HidD_GetPreparsedData(hfile, &pData)) {
if (HidP_GetCaps(pData, &caps) == HIDP_STATUS_SUCCESS) {
if (numFoundDevs % 32 == 0) {
*foundDevs = (HidDeviceInfo *)realloc(*foundDevs, sizeof(HidDeviceInfo) * (32 + numFoundDevs));
if (HidD_GetPreparsedData(hfile, &pData))
{
if (HidP_GetCaps(pData, &caps) == HIDP_STATUS_SUCCESS)
{
if (numFoundDevs % 32 == 0)
{
*foundDevs = (HidDeviceInfo*)realloc(*foundDevs, sizeof(HidDeviceInfo) * (32 + numFoundDevs));
}
HidDeviceInfo *dev = &foundDevs[0][numFoundDevs++];
HidDeviceInfo* dev = &foundDevs[0][numFoundDevs++];
dev->caps = caps;
dev->vid = attributes.VendorID;
dev->pid = attributes.ProductID;

View File

@ -21,11 +21,11 @@
struct HidDeviceInfo
{
HIDP_CAPS caps;
wchar_t *path;
wchar_t* path;
unsigned short vid;
unsigned short pid;
};
int FindHids(HidDeviceInfo **foundDevs, int vid, int pid);
int FindHids(HidDeviceInfo** foundDevs, int vid, int pid);
#endif

View File

@ -19,7 +19,7 @@
#include "KeyboardQueue.h"
#include "PADConfig.h"
InputDeviceManager *dm = 0;
InputDeviceManager* dm = 0;
InputDeviceManager::InputDeviceManager()
{
@ -28,7 +28,8 @@ InputDeviceManager::InputDeviceManager()
void InputDeviceManager::ClearDevices()
{
for (int i = 0; i < numDevices; i++) {
for (int i = 0; i < numDevices; i++)
{
delete devices[i];
}
free(devices);
@ -41,7 +42,7 @@ InputDeviceManager::~InputDeviceManager()
ClearDevices();
}
Device::Device(DeviceAPI api, DeviceType d, const wchar_t *displayName, const wchar_t *instanceID, const wchar_t *productID)
Device::Device(DeviceAPI api, DeviceType d, const wchar_t* displayName, const wchar_t* instanceID, const wchar_t* productID)
{
memset(pads, 0, sizeof(pads));
this->api = api;
@ -92,11 +93,15 @@ Device::~Device()
// Generally called by deactivate, but just in case...
FreeState();
int i;
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int padtype = 0; padtype < numPadTypes; padtype++) {
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
for (int padtype = 0; padtype < numPadTypes; padtype++)
{
free(pads[port][slot][padtype].bindings);
for (i = 0; i < pads[port][slot][padtype].numFFBindings; i++) {
for (i = 0; i < pads[port][slot][padtype].numFFBindings; i++)
{
free(pads[port][slot][padtype].ffBindings[i].axes);
}
free(pads[port][slot][padtype].ffBindings);
@ -105,7 +110,8 @@ Device::~Device()
}
free(virtualControls);
for (i = numPhysicalControls - 1; i >= 0; i--) {
for (i = numPhysicalControls - 1; i >= 0; i--)
{
if (physicalControls[i].name)
free(physicalControls[i].name);
}
@ -114,14 +120,18 @@ Device::~Device()
free(displayName);
free(instanceID);
free(productID);
if (ffAxes) {
for (i = 0; i < numFFAxes; i++) {
if (ffAxes)
{
for (i = 0; i < numFFAxes; i++)
{
free(ffAxes[i].displayName);
}
free(ffAxes);
}
if (ffEffectTypes) {
for (i = 0; i < numFFEffectTypes; i++) {
if (ffEffectTypes)
{
for (i = 0; i < numFFEffectTypes; i++)
{
free(ffEffectTypes[i].displayName);
free(ffEffectTypes[i].effectID);
}
@ -129,28 +139,32 @@ Device::~Device()
}
}
void Device::AddFFEffectType(const wchar_t *displayName, const wchar_t *effectID, EffectType type)
void Device::AddFFEffectType(const wchar_t* displayName, const wchar_t* effectID, EffectType type)
{
ffEffectTypes = (ForceFeedbackEffectType *)realloc(ffEffectTypes, sizeof(ForceFeedbackEffectType) * (numFFEffectTypes + 1));
ffEffectTypes = (ForceFeedbackEffectType*)realloc(ffEffectTypes, sizeof(ForceFeedbackEffectType) * (numFFEffectTypes + 1));
ffEffectTypes[numFFEffectTypes].displayName = wcsdup(displayName);
ffEffectTypes[numFFEffectTypes].effectID = wcsdup(effectID);
ffEffectTypes[numFFEffectTypes].type = type;
numFFEffectTypes++;
}
void Device::AddFFAxis(const wchar_t *displayName, int id)
void Device::AddFFAxis(const wchar_t* displayName, int id)
{
ffAxes = (ForceFeedbackAxis *)realloc(ffAxes, sizeof(ForceFeedbackAxis) * (numFFAxes + 1));
ffAxes = (ForceFeedbackAxis*)realloc(ffAxes, sizeof(ForceFeedbackAxis) * (numFFAxes + 1));
ffAxes[numFFAxes].id = id;
ffAxes[numFFAxes].displayName = wcsdup(displayName);
numFFAxes++;
int bindingsExist = 0;
for (int port = 0; port < 2; port++) {
for (int slot = 0; slot < 4; slot++) {
for (int padtype = 0; padtype < numPadTypes; padtype++) {
for (int i = 0; i < pads[port][slot][padtype].numFFBindings; i++) {
ForceFeedbackBinding *b = pads[port][slot][padtype].ffBindings + i;
b->axes = (AxisEffectInfo *)realloc(b->axes, sizeof(AxisEffectInfo) * (numFFAxes));
for (int port = 0; port < 2; port++)
{
for (int slot = 0; slot < 4; slot++)
{
for (int padtype = 0; padtype < numPadTypes; padtype++)
{
for (int i = 0; i < pads[port][slot][padtype].numFFBindings; i++)
{
ForceFeedbackBinding* b = pads[port][slot][padtype].ffBindings + i;
b->axes = (AxisEffectInfo*)realloc(b->axes, sizeof(AxisEffectInfo) * (numFFAxes));
memset(b->axes + (numFFAxes - 1), 0, sizeof(AxisEffectInfo));
bindingsExist = 1;
}
@ -158,10 +172,12 @@ void Device::AddFFAxis(const wchar_t *displayName, int id)
}
}
// Generally the case when not loading a binding file.
if (!bindingsExist) {
if (!bindingsExist)
{
int i = numFFAxes - 1;
ForceFeedbackAxis temp = ffAxes[i];
while (i && temp.id < ffAxes[i - 1].id) {
while (i && temp.id < ffAxes[i - 1].id)
{
ffAxes[i] = ffAxes[i - 1];
i--;
}
@ -172,7 +188,7 @@ void Device::AddFFAxis(const wchar_t *displayName, int id)
void Device::AllocState()
{
FreeState();
virtualControlState = (int *)calloc(numVirtualControls + numVirtualControls + numPhysicalControls, sizeof(int));
virtualControlState = (int*)calloc(numVirtualControls + numVirtualControls + numPhysicalControls, sizeof(int));
oldVirtualControlState = virtualControlState + numVirtualControls;
physicalControlState = oldVirtualControlState + numVirtualControls;
}
@ -189,23 +205,30 @@ void Device::PostRead()
void Device::CalcVirtualState()
{
for (int i = 0; i < numPhysicalControls; i++) {
PhysicalControl *c = physicalControls + i;
for (int i = 0; i < numPhysicalControls; i++)
{
PhysicalControl* c = physicalControls + i;
int index = c->baseVirtualControlIndex;
int val = physicalControlState[i];
if (c->type & BUTTON) {
if (c->type & BUTTON)
{
virtualControlState[index] = val;
// DirectInput keyboard events only.
if (this->api == DI && this->type == KEYBOARD) {
if (!(virtualControlState[index] >> 15) != !(oldVirtualControlState[index] >> 15) && c->vkey) {
if (this->api == DI && this->type == KEYBOARD)
{
if (!(virtualControlState[index] >> 15) != !(oldVirtualControlState[index] >> 15) && c->vkey)
{
// Check for alt-F4 to avoid toggling skip mode incorrectly.
if (c->vkey == VK_F4) {
if (c->vkey == VK_F4)
{
int i;
for (i = 0; i < numPhysicalControls; i++) {
for (i = 0; i < numPhysicalControls; i++)
{
if (virtualControlState[physicalControls[i].baseVirtualControlIndex] &&
(physicalControls[i].vkey == VK_MENU ||
physicalControls[i].vkey == VK_RMENU ||
physicalControls[i].vkey == VK_LMENU)) {
physicalControls[i].vkey == VK_LMENU))
{
break;
}
}
@ -218,24 +241,31 @@ void Device::CalcVirtualState()
QueueKeyEvent(c->vkey, event);
}
}
} else if (c->type & ABSAXIS) {
}
else if (c->type & ABSAXIS)
{
virtualControlState[index] = (val + FULLY_DOWN) / 2;
// Positive. Overkill.
virtualControlState[index + 1] = (val & ~(val >> 31));
// Negative
virtualControlState[index + 2] = (-val & (val >> 31));
} else if (c->type & RELAXIS) {
}
else if (c->type & RELAXIS)
{
int delta = val - oldVirtualControlState[index];
virtualControlState[index] = val;
// Positive
virtualControlState[index + 1] = (delta & ~(delta >> 31));
// Negative
virtualControlState[index + 2] = (-delta & (delta >> 31));
} else if (c->type & POV) {
}
else if (c->type & POV)
{
virtualControlState[index] = val;
int iSouth = 0;
int iEast = 0;
if ((unsigned int)val <= 37000) {
if ((unsigned int)val <= 37000)
{
double angle = val * (3.141592653589793 / 18000.0);
double East = sin(angle);
double South = -cos(angle);
@ -257,24 +287,26 @@ void Device::CalcVirtualState()
}
}
VirtualControl *Device::GetVirtualControl(unsigned int uid)
VirtualControl* Device::GetVirtualControl(unsigned int uid)
{
for (int i = 0; i < numVirtualControls; i++) {
for (int i = 0; i < numVirtualControls; i++)
{
if (virtualControls[i].uid == uid)
return virtualControls + i;
}
return 0;
}
VirtualControl *Device::AddVirtualControl(unsigned int uid, int physicalControlIndex)
VirtualControl* Device::AddVirtualControl(unsigned int uid, int physicalControlIndex)
{
// Not really necessary, as always call AllocState when activated, but doesn't hurt.
FreeState();
if (numVirtualControls % 16 == 0) {
virtualControls = (VirtualControl *)realloc(virtualControls, sizeof(VirtualControl) * (numVirtualControls + 16));
if (numVirtualControls % 16 == 0)
{
virtualControls = (VirtualControl*)realloc(virtualControls, sizeof(VirtualControl) * (numVirtualControls + 16));
}
VirtualControl *c = virtualControls + numVirtualControls;
VirtualControl* c = virtualControls + numVirtualControls;
c->uid = uid;
c->physicalControlIndex = physicalControlIndex;
@ -283,15 +315,16 @@ VirtualControl *Device::AddVirtualControl(unsigned int uid, int physicalControlI
return c;
}
PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id, unsigned short vkey, const wchar_t *name)
PhysicalControl* Device::AddPhysicalControl(ControlType type, unsigned short id, unsigned short vkey, const wchar_t* name)
{
// Not really necessary, as always call AllocState when activated, but doesn't hurt.
FreeState();
if (numPhysicalControls % 16 == 0) {
physicalControls = (PhysicalControl *)realloc(physicalControls, sizeof(PhysicalControl) * (numPhysicalControls + 16));
if (numPhysicalControls % 16 == 0)
{
physicalControls = (PhysicalControl*)realloc(physicalControls, sizeof(PhysicalControl) * (numPhysicalControls + 16));
}
PhysicalControl *control = physicalControls + numPhysicalControls;
PhysicalControl* control = physicalControls + numPhysicalControls;
memset(control, 0, sizeof(PhysicalControl));
control->type = type;
@ -300,14 +333,19 @@ PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id,
control->name = wcsdup(name);
control->baseVirtualControlIndex = numVirtualControls;
unsigned int uid = id | (type << 16);
if (type & BUTTON) {
if (type & BUTTON)
{
AddVirtualControl(uid, numPhysicalControls);
control->vkey = vkey;
} else if (type & AXIS) {
}
else if (type & AXIS)
{
AddVirtualControl(uid | UID_AXIS, numPhysicalControls);
AddVirtualControl(uid | UID_AXIS_POS, numPhysicalControls);
AddVirtualControl(uid | UID_AXIS_NEG, numPhysicalControls);
} else if (type & POV) {
}
else if (type & POV)
{
AddVirtualControl(uid | UID_POV, numPhysicalControls);
AddVirtualControl(uid | UID_POV_N, numPhysicalControls);
AddVirtualControl(uid | UID_POV_E, numPhysicalControls);
@ -321,40 +359,51 @@ PhysicalControl *Device::AddPhysicalControl(ControlType type, unsigned short id,
void Device::SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force)
{
int padtype = config.padConfigs[port][slot].type;
for (int i = 0; i < pads[port][slot][padtype].numFFBindings; i++) {
ForceFeedbackBinding *binding = pads[port][slot][padtype].ffBindings + i;
if (binding->motor == motor) {
for (int i = 0; i < pads[port][slot][padtype].numFFBindings; i++)
{
ForceFeedbackBinding* binding = pads[port][slot][padtype].ffBindings + i;
if (binding->motor == motor)
{
SetEffect(binding, force);
}
}
}
wchar_t *GetDefaultControlName(unsigned short id, int type)
wchar_t* GetDefaultControlName(unsigned short id, int type)
{
static wchar_t name[20];
if (type & BUTTON) {
if (type & BUTTON)
{
wsprintfW(name, L"Button %i", id);
} else if (type & AXIS) {
}
else if (type & AXIS)
{
wsprintfW(name, L"Axis %i", id);
} else if (type & POV) {
}
else if (type & POV)
{
wsprintfW(name, L"POV %i", id);
} else {
}
else
{
wcscpy(name, L"Unknown");
}
return name;
}
wchar_t *Device::GetVirtualControlName(VirtualControl *control)
wchar_t* Device::GetVirtualControlName(VirtualControl* control)
{
static wchar_t temp[100];
wchar_t *baseName = 0;
if (control->physicalControlIndex >= 0) {
wchar_t* baseName = 0;
if (control->physicalControlIndex >= 0)
{
baseName = physicalControls[control->physicalControlIndex].name;
if (!baseName)
baseName = GetPhysicalControlName(&physicalControls[control->physicalControlIndex]);
}
unsigned int uid = control->uid;
if (!baseName) {
if (!baseName)
{
baseName = GetDefaultControlName(uid & 0xFFFF, (uid >> 16) & 0x1F);
}
uid &= 0xFF000000;
@ -363,45 +412,60 @@ wchar_t *Device::GetVirtualControlName(VirtualControl *control)
len = 99;
memcpy(temp, baseName, len * sizeof(wchar_t));
temp[len] = 0;
if (uid) {
if (uid)
{
if (len > 95)
len = 95;
wchar_t *out = temp + len;
if (uid == UID_AXIS_POS) {
wchar_t* out = temp + len;
if (uid == UID_AXIS_POS)
{
wcscpy(out, L" +");
} else if (uid == UID_AXIS_NEG) {
}
else if (uid == UID_AXIS_NEG)
{
wcscpy(out, L" -");
} else if (uid == UID_POV_N) {
}
else if (uid == UID_POV_N)
{
wcscpy(out, L" N");
} else if (uid == UID_POV_E) {
}
else if (uid == UID_POV_E)
{
wcscpy(out, L" E");
} else if (uid == UID_POV_S) {
}
else if (uid == UID_POV_S)
{
wcscpy(out, L" S");
} else if (uid == UID_POV_W) {
}
else if (uid == UID_POV_W)
{
wcscpy(out, L" W");
}
}
return temp;
}
wchar_t *Device::GetPhysicalControlName(PhysicalControl *control)
wchar_t* Device::GetPhysicalControlName(PhysicalControl* control)
{
if (control->name)
return control->name;
return GetDefaultControlName(control->id, control->type);
}
void InputDeviceManager::AddDevice(Device *d)
void InputDeviceManager::AddDevice(Device* d)
{
devices = (Device **)realloc(devices, sizeof(Device *) * (numDevices + 1));
devices = (Device**)realloc(devices, sizeof(Device*) * (numDevices + 1));
devices[numDevices++] = d;
}
void InputDeviceManager::Update(InitInfo *info)
void InputDeviceManager::Update(InitInfo* info)
{
for (int i = 0; i < numDevices; i++) {
if (devices[i]->enabled) {
if (!devices[i]->active) {
for (int i = 0; i < numDevices; i++)
{
if (devices[i]->enabled)
{
if (!devices[i]->active)
{
if (!devices[i]->Activate(info) || !devices[i]->Update())
continue;
devices[i]->CalcVirtualState();
@ -415,50 +479,63 @@ void InputDeviceManager::Update(InitInfo *info)
void InputDeviceManager::PostRead()
{
for (int i = 0; i < numDevices; i++) {
for (int i = 0; i < numDevices; i++)
{
if (devices[i]->active)
devices[i]->PostRead();
}
}
Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, int *index, int *value)
Device* InputDeviceManager::GetActiveDevice(InitInfo* info, unsigned int* uid, int* index, int* value)
{
int i, j;
Update(info);
int bestDiff = FULLY_DOWN / 2;
Device *bestDevice = 0;
for (i = 0; i < numDevices; i++) {
if (devices[i]->active) {
for (j = 0; j < devices[i]->numVirtualControls; j++) {
Device* bestDevice = 0;
for (i = 0; i < numDevices; i++)
{
if (devices[i]->active)
{
for (j = 0; j < devices[i]->numVirtualControls; j++)
{
if (devices[i]->virtualControlState[j] == devices[i]->oldVirtualControlState[j])
continue;
if (devices[i]->virtualControls[j].uid & UID_POV)
continue;
// Fix for releasing button used to click on bind button
if (!((devices[i]->virtualControls[j].uid >> 16) & (POV | RELAXIS | ABSAXIS))) {
if (abs(devices[i]->oldVirtualControlState[j]) > abs(devices[i]->virtualControlState[j])) {
if (!((devices[i]->virtualControls[j].uid >> 16) & (POV | RELAXIS | ABSAXIS)))
{
if (abs(devices[i]->oldVirtualControlState[j]) > abs(devices[i]->virtualControlState[j]))
{
devices[i]->oldVirtualControlState[j] = 0;
}
}
int diff = abs(devices[i]->virtualControlState[j] - devices[i]->oldVirtualControlState[j]);
// Make it require a bit more work to bind relative axes.
if (((devices[i]->virtualControls[j].uid >> 16) & 0xFF) == RELAXIS) {
if (((devices[i]->virtualControls[j].uid >> 16) & 0xFF) == RELAXIS)
{
diff = diff / 4 + 1;
}
// Less pressure needed to bind DS3/SCP buttons.
if ((devices[i]->api == DS3 || devices[i]->api == XINPUT) && (((devices[i]->virtualControls[j].uid >> 16) & 0xFF) & BUTTON)) {
if ((devices[i]->api == DS3 || devices[i]->api == XINPUT) && (((devices[i]->virtualControls[j].uid >> 16) & 0xFF) & BUTTON))
{
diff *= 4;
}
if (diff > bestDiff) {
if (devices[i]->virtualControls[j].uid & UID_AXIS) {
if (diff > bestDiff)
{
if (devices[i]->virtualControls[j].uid & UID_AXIS)
{
if ((((devices[i]->virtualControls[j].uid >> 16) & 0xFF) != ABSAXIS))
continue;
// Very picky when binding entire axes. Prefer binding half-axes.
if (!((devices[i]->oldVirtualControlState[j] < FULLY_DOWN / 32 && devices[i]->virtualControlState[j] > FULLY_DOWN / 8) ||
(devices[i]->oldVirtualControlState[j] > 31 * FULLY_DOWN / 32 && devices[i]->virtualControlState[j] < 7 * FULLY_DOWN / 8))) {
(devices[i]->oldVirtualControlState[j] > 31 * FULLY_DOWN / 32 && devices[i]->virtualControlState[j] < 7 * FULLY_DOWN / 8)))
{
continue;
}
} else if ((((devices[i]->virtualControls[j].uid >> 16) & 0xFF) == ABSAXIS)) {
}
else if ((((devices[i]->virtualControls[j].uid >> 16) & 0xFF) == ABSAXIS))
{
if (devices[i]->oldVirtualControlState[j] > 15 * FULLY_DOWN / 16)
continue;
}
@ -466,10 +543,14 @@ Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, i
*uid = devices[i]->virtualControls[j].uid;
*index = j;
bestDevice = devices[i];
if (value) {
if ((devices[i]->virtualControls[j].uid >> 16) & RELAXIS) {
if (value)
{
if ((devices[i]->virtualControls[j].uid >> 16) & RELAXIS)
{
*value = devices[i]->virtualControlState[j] - devices[i]->oldVirtualControlState[j];
} else {
}
else
{
*value = devices[i]->virtualControlState[j];
}
}
@ -484,7 +565,8 @@ Device *InputDeviceManager::GetActiveDevice(InitInfo *info, unsigned int *uid, i
void InputDeviceManager::ReleaseInput()
{
for (int i = 0; i < numDevices; i++) {
for (int i = 0; i < numDevices; i++)
{
if (devices[i]->active)
devices[i]->Deactivate();
}
@ -492,8 +574,10 @@ void InputDeviceManager::ReleaseInput()
void InputDeviceManager::EnableDevices(DeviceType type, DeviceAPI api)
{
for (int i = 0; i < numDevices; i++) {
if (devices[i]->api == api && devices[i]->type == type) {
for (int i = 0; i < numDevices; i++)
{
if (devices[i]->api == api && devices[i]->type == type)
{
EnableDevice(i);
}
}
@ -501,7 +585,8 @@ void InputDeviceManager::EnableDevices(DeviceType type, DeviceAPI api)
void InputDeviceManager::DisableAllDevices()
{
for (int i = 0; i < numDevices; i++) {
for (int i = 0; i < numDevices; i++)
{
DisableDevice(i);
}
}
@ -509,46 +594,56 @@ void InputDeviceManager::DisableAllDevices()
void InputDeviceManager::DisableDevice(int index)
{
devices[index]->enabled = 0;
if (devices[index]->active) {
if (devices[index]->active)
{
devices[index]->Deactivate();
}
}
ForceFeedbackEffectType *Device::GetForcefeedbackEffect(wchar_t *id)
ForceFeedbackEffectType* Device::GetForcefeedbackEffect(wchar_t* id)
{
for (int i = 0; i < numFFEffectTypes; i++) {
if (!wcsicmp(id, ffEffectTypes[i].effectID)) {
for (int i = 0; i < numFFEffectTypes; i++)
{
if (!wcsicmp(id, ffEffectTypes[i].effectID))
{
return &ffEffectTypes[i];
}
}
return 0;
}
ForceFeedbackAxis *Device::GetForceFeedbackAxis(int id)
ForceFeedbackAxis* Device::GetForceFeedbackAxis(int id)
{
for (int i = 0; i < numFFAxes; i++) {
for (int i = 0; i < numFFAxes; i++)
{
if (ffAxes[i].id == id)
return &ffAxes[i];
}
return 0;
}
void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices)
void InputDeviceManager::CopyBindings(int numOldDevices, Device** oldDevices)
{
int *oldMatches = (int *)malloc(sizeof(int) * numOldDevices);
int *matches = (int *)malloc(sizeof(int) * numDevices);
int* oldMatches = (int*)malloc(sizeof(int) * numOldDevices);
int* matches = (int*)malloc(sizeof(int) * numDevices);
int i, j, port, slot;
Device *old, *dev;
for (i = 0; i < numDevices; i++) {
for (i = 0; i < numDevices; i++)
{
matches[i] = -1;
}
for (i = 0; i < numOldDevices; i++) {
for (i = 0; i < numOldDevices; i++)
{
oldMatches[i] = -2;
old = oldDevices[i];
for (port = 0; port < 2; port++) {
for (slot = 0; slot < 4; slot++) {
for (int padtype = 0; padtype < numPadTypes; padtype++) {
if (old->pads[port][slot][padtype].numBindings + old->pads[port][slot][padtype].numFFBindings) {
for (port = 0; port < 2; port++)
{
for (slot = 0; slot < 4; slot++)
{
for (int padtype = 0; padtype < numPadTypes; padtype++)
{
if (old->pads[port][slot][padtype].numBindings + old->pads[port][slot][padtype].numFFBindings)
{
// Means that there are bindings.
oldMatches[i] = -1;
}
@ -557,20 +652,26 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices)
}
}
// Loops through ids looking for match, from most specific to most general.
for (int id = 0; id < 3; id++) {
for (i = 0; i < numOldDevices; i++) {
for (int id = 0; id < 3; id++)
{
for (i = 0; i < numOldDevices; i++)
{
if (oldMatches[i] >= 0)
continue;
for (j = 0; j < numDevices; j++) {
if (matches[j] >= 0) {
for (j = 0; j < numDevices; j++)
{
if (matches[j] >= 0)
{
continue;
}
wchar_t *id1 = devices[j]->IDs[id];
wchar_t *id2 = oldDevices[i]->IDs[id];
if (!id1 || !id2) {
wchar_t* id1 = devices[j]->IDs[id];
wchar_t* id2 = oldDevices[i]->IDs[id];
if (!id1 || !id2)
{
continue;
}
if (!wcsicmp(id1, id2)) {
if (!wcsicmp(id1, id2))
{
matches[j] = i;
oldMatches[i] = j;
break;
@ -579,61 +680,79 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices)
}
}
for (i = 0; i < numOldDevices; i++) {
for (i = 0; i < numOldDevices; i++)
{
if (oldMatches[i] == -2)
continue;
old = oldDevices[i];
if (oldMatches[i] < 0) {
if (oldMatches[i] < 0)
{
dev = new Device(old->api, old->type, old->displayName, old->instanceID, old->productID);
dev->attached = 0;
AddDevice(dev);
for (j = 0; j < old->numVirtualControls; j++) {
VirtualControl *c = old->virtualControls + j;
for (j = 0; j < old->numVirtualControls; j++)
{
VirtualControl* c = old->virtualControls + j;
dev->AddVirtualControl(c->uid, -1);
}
for (j = 0; j < old->numFFEffectTypes; j++) {
ForceFeedbackEffectType *effect = old->ffEffectTypes + j;
for (j = 0; j < old->numFFEffectTypes; j++)
{
ForceFeedbackEffectType* effect = old->ffEffectTypes + j;
dev->AddFFEffectType(effect->displayName, effect->effectID, effect->type);
}
for (j = 0; j < old->numFFAxes; j++) {
ForceFeedbackAxis *axis = old->ffAxes + j;
for (j = 0; j < old->numFFAxes; j++)
{
ForceFeedbackAxis* axis = old->ffAxes + j;
dev->AddFFAxis(axis->displayName, axis->id);
}
// Just steal the old bindings directly when there's no matching device.
// Indices will be the same.
memcpy(dev->pads, old->pads, sizeof(old->pads));
memset(old->pads, 0, sizeof(old->pads));
} else {
}
else
{
dev = devices[oldMatches[i]];
for (port = 0; port < 2; port++) {
for (slot = 0; slot < 4; slot++) {
for (int padtype = 0; padtype < numPadTypes; padtype++) {
if (old->pads[port][slot][padtype].numBindings) {
dev->pads[port][slot][padtype].bindings = (Binding *)malloc(old->pads[port][slot][padtype].numBindings * sizeof(Binding));
for (int j = 0; j < old->pads[port][slot][padtype].numBindings; j++) {
Binding *bo = old->pads[port][slot][padtype].bindings + j;
Binding *bn = dev->pads[port][slot][padtype].bindings + dev->pads[port][slot][padtype].numBindings;
VirtualControl *cn = dev->GetVirtualControl(old->virtualControls[bo->controlIndex].uid);
if (cn) {
for (port = 0; port < 2; port++)
{
for (slot = 0; slot < 4; slot++)
{
for (int padtype = 0; padtype < numPadTypes; padtype++)
{
if (old->pads[port][slot][padtype].numBindings)
{
dev->pads[port][slot][padtype].bindings = (Binding*)malloc(old->pads[port][slot][padtype].numBindings * sizeof(Binding));
for (int j = 0; j < old->pads[port][slot][padtype].numBindings; j++)
{
Binding* bo = old->pads[port][slot][padtype].bindings + j;
Binding* bn = dev->pads[port][slot][padtype].bindings + dev->pads[port][slot][padtype].numBindings;
VirtualControl* cn = dev->GetVirtualControl(old->virtualControls[bo->controlIndex].uid);
if (cn)
{
*bn = *bo;
bn->controlIndex = cn - dev->virtualControls;
dev->pads[port][slot][padtype].numBindings++;
}
}
}
if (old->pads[port][slot][padtype].numFFBindings) {
dev->pads[port][slot][padtype].ffBindings = (ForceFeedbackBinding *)malloc(old->pads[port][slot][padtype].numFFBindings * sizeof(ForceFeedbackBinding));
for (int j = 0; j < old->pads[port][slot][padtype].numFFBindings; j++) {
ForceFeedbackBinding *bo = old->pads[port][slot][padtype].ffBindings + j;
ForceFeedbackBinding *bn = dev->pads[port][slot][padtype].ffBindings + dev->pads[port][slot][padtype].numFFBindings;
ForceFeedbackEffectType *en = dev->GetForcefeedbackEffect(old->ffEffectTypes[bo->effectIndex].effectID);
if (en) {
if (old->pads[port][slot][padtype].numFFBindings)
{
dev->pads[port][slot][padtype].ffBindings = (ForceFeedbackBinding*)malloc(old->pads[port][slot][padtype].numFFBindings * sizeof(ForceFeedbackBinding));
for (int j = 0; j < old->pads[port][slot][padtype].numFFBindings; j++)
{
ForceFeedbackBinding* bo = old->pads[port][slot][padtype].ffBindings + j;
ForceFeedbackBinding* bn = dev->pads[port][slot][padtype].ffBindings + dev->pads[port][slot][padtype].numFFBindings;
ForceFeedbackEffectType* en = dev->GetForcefeedbackEffect(old->ffEffectTypes[bo->effectIndex].effectID);
if (en)
{
*bn = *bo;
bn->effectIndex = en - dev->ffEffectTypes;
bn->axes = (AxisEffectInfo *)calloc(dev->numFFAxes, sizeof(AxisEffectInfo));
for (int k = 0; k < old->numFFAxes; k++) {
ForceFeedbackAxis *newAxis = dev->GetForceFeedbackAxis(old->ffAxes[k].id);
if (newAxis) {
bn->axes = (AxisEffectInfo*)calloc(dev->numFFAxes, sizeof(AxisEffectInfo));
for (int k = 0; k < old->numFFAxes; k++)
{
ForceFeedbackAxis* newAxis = dev->GetForceFeedbackAxis(old->ffAxes[k].id);
if (newAxis)
{
bn->axes[newAxis - dev->ffAxes] = bo->axes[k];
}
}
@ -652,9 +771,11 @@ void InputDeviceManager::CopyBindings(int numOldDevices, Device **oldDevices)
void InputDeviceManager::SetEffect(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force)
{
for (int i = 0; i < numDevices; i++) {
Device *dev = devices[i];
if (dev->enabled && dev->numFFEffectTypes) {
for (int i = 0; i < numDevices; i++)
{
Device* dev = devices[i];
if (dev->enabled && dev->numFFEffectTypes)
{
dev->SetEffects(port, slot, motor, force);
}
}

View File

@ -31,7 +31,8 @@
* Still more effort than it's worth to port to Linux, however.
*/
enum PadType {
enum PadType
{
DisabledPad,
Dualshock2Pad,
GuitarPad,
@ -44,7 +45,8 @@ enum PadType {
// Mostly match DirectInput8 values. Note that these are for physical controls.
// One physical axis maps to 3 virtual ones, and one physical POV control maps to
// 4 virtual ones.
enum ControlType {
enum ControlType
{
NO_CONTROL = 0,
// Axes are ints. Relative axes are for mice, mice wheels, etc,
// and are always reported relative to their last value.
@ -127,10 +129,11 @@ struct PhysicalControl
// uid for virtual controls.
unsigned short id;
unsigned short vkey;
wchar_t *name;
wchar_t* name;
};
enum DeviceAPI {
enum DeviceAPI
{
NO_API = 0,
DI = 1,
WM = 2,
@ -148,14 +151,16 @@ enum DeviceAPI {
LNX_JOY = 17,
};
enum DeviceType {
enum DeviceType
{
NO_DEVICE = 0,
KEYBOARD = 1,
MOUSE = 2,
OTHER = 3
};
enum EffectType {
enum EffectType
{
EFFECT_CONSTANT,
EFFECT_PERIODIC,
EFFECT_RAMP
@ -172,7 +177,7 @@ struct AxisEffectInfo
struct ForceFeedbackBinding
{
AxisEffectInfo *axes;
AxisEffectInfo* axes;
int effectIndex;
unsigned char motor;
};
@ -181,9 +186,9 @@ struct ForceFeedbackBinding
// indexing effects.
struct ForceFeedbackEffectType
{
wchar_t *displayName;
wchar_t* displayName;
// Because I'm lazy, can only have ASCII characters and no spaces.
wchar_t *effectID;
wchar_t* effectID;
// constant, ramp, or periodic
EffectType type;
};
@ -191,7 +196,7 @@ struct ForceFeedbackEffectType
struct ForceFeedbackAxis
{
wchar_t *displayName;
wchar_t* displayName;
int id;
};
@ -203,9 +208,9 @@ struct ForceFeedbackAxis
struct PadBindings
{
Binding *bindings;
Binding* bindings;
int numBindings;
ForceFeedbackBinding *ffBindings;
ForceFeedbackBinding* ffBindings;
int numFFBindings;
};
@ -224,10 +229,10 @@ struct InitInfo
// For config screen, need to eat button's message handling.
//HWND hWndButton;
WndProcEater *hWndProc;
WndProcEater* hWndProc;
#else
// Linux equivalent to HWND
Display *GSdsp;
Display* GSdsp;
Window GSwin;
#endif
};
@ -248,24 +253,24 @@ public:
#ifdef _MSC_VER
// Not all devices need to subclass the windproc, but most do so might as well
// put it here... --air
WndProcEater *hWndProc;
WndProcEater* hWndProc;
#endif
union
{
// Allows for one loop to compare all 3 in order.
wchar_t *IDs[3];
wchar_t* IDs[3];
struct
{
// Same as DisplayName, when not given. Absolutely must be unique.
// Used for loading/saving controls. If matches, all other strings
// are ignored, so must be unique.
wchar_t *instanceID;
wchar_t* instanceID;
// Not required. Used when a device's instance id changes, doesn't have to
// be unique. For devices that can only have one instance, not needed.
wchar_t *productID;
wchar_t* productID;
wchar_t *displayName;
wchar_t* displayName;
};
};
@ -275,24 +280,24 @@ public:
// values between 0 and 2^16. 2^16 is fully down, 0 is up. Larger values
// are allowed, but *only* for absolute axes (Which don't support the flip checkbox).
// Each control on a device must have a unique id, used for binding.
VirtualControl *virtualControls;
VirtualControl* virtualControls;
int numVirtualControls;
int *virtualControlState;
int *oldVirtualControlState;
int* virtualControlState;
int* oldVirtualControlState;
PhysicalControl *physicalControls;
PhysicalControl* physicalControls;
int numPhysicalControls;
int *physicalControlState;
int* physicalControlState;
ForceFeedbackEffectType *ffEffectTypes;
ForceFeedbackEffectType* ffEffectTypes;
int numFFEffectTypes;
ForceFeedbackAxis *ffAxes;
ForceFeedbackAxis* ffAxes;
int numFFAxes;
void AddFFAxis(const wchar_t *displayName, int id);
void AddFFEffectType(const wchar_t *displayName, const wchar_t *effectID, EffectType type);
void AddFFAxis(const wchar_t* displayName, int id);
void AddFFEffectType(const wchar_t* displayName, const wchar_t* effectID, EffectType type);
Device(DeviceAPI, DeviceType, const wchar_t *displayName, const wchar_t *instanceID = 0, const wchar_t *deviceID = 0);
Device(DeviceAPI, DeviceType, const wchar_t* displayName, const wchar_t* instanceID = 0, const wchar_t* deviceID = 0);
virtual ~Device();
// Allocates memory for old and new state, sets everything to 0.
@ -307,20 +312,20 @@ public:
// Frees state variables.
void FreeState();
ForceFeedbackEffectType *GetForcefeedbackEffect(wchar_t *id);
ForceFeedbackAxis *GetForceFeedbackAxis(int id);
ForceFeedbackEffectType* GetForcefeedbackEffect(wchar_t* id);
ForceFeedbackAxis* GetForceFeedbackAxis(int id);
VirtualControl *GetVirtualControl(unsigned int uid);
VirtualControl* GetVirtualControl(unsigned int uid);
PhysicalControl *AddPhysicalControl(ControlType type, unsigned short id, unsigned short vkey, const wchar_t *name = 0);
VirtualControl *AddVirtualControl(unsigned int uid, int physicalControlIndex);
PhysicalControl* AddPhysicalControl(ControlType type, unsigned short id, unsigned short vkey, const wchar_t* name = 0);
VirtualControl* AddVirtualControl(unsigned int uid, int physicalControlIndex);
virtual wchar_t *GetVirtualControlName(VirtualControl *c);
virtual wchar_t *GetPhysicalControlName(PhysicalControl *c);
virtual wchar_t* GetVirtualControlName(VirtualControl* c);
virtual wchar_t* GetPhysicalControlName(PhysicalControl* c);
void CalcVirtualState();
virtual int Activate(InitInfo *args)
virtual int Activate(InitInfo* args)
{
return 0;
}
@ -343,7 +348,7 @@ public:
// Note: Only used externally for binding, so if override the other one, can assume
// all other forces are currently 0.
inline virtual void SetEffect(ForceFeedbackBinding *binding, unsigned char force) {}
inline virtual void SetEffect(ForceFeedbackBinding* binding, unsigned char force) {}
virtual void SetEffects(unsigned char port, unsigned int slot, unsigned char motor, unsigned char force);
// Called after reading. Basically calls FlipState().
@ -356,7 +361,7 @@ public:
class InputDeviceManager
{
public:
Device **devices;
Device** devices;
int numDevices;
void ClearDevices();
@ -368,15 +373,15 @@ public:
// When old devices are missing, I do a slightly more careful search
// using productIDs and then (in desperation) displayName.
// Finally create new dummy devices if no matches found.
void CopyBindings(int numDevices, Device **devices);
void CopyBindings(int numDevices, Device** devices);
InputDeviceManager();
~InputDeviceManager();
void AddDevice(Device *d);
Device *GetActiveDevice(InitInfo *info, unsigned int *uid, int *index, int *value);
void Update(InitInfo *initInfo);
void AddDevice(Device* d);
Device* GetActiveDevice(InitInfo* info, unsigned int* uid, int* index, int* value);
void Update(InitInfo* initInfo);
// Called after reading state, after Update().
void PostRead();
@ -397,6 +402,6 @@ public:
void DisableAllDevices();
};
extern InputDeviceManager *dm;
extern InputDeviceManager* dm;
#endif

View File

@ -36,7 +36,8 @@ static keyEvent queuedEvents[EVENT_QUEUE_LEN];
void QueueKeyEvent(int key, int event)
{
#ifdef _MSC_VER
if (!csInitialized) {
if (!csInitialized)
{
csInitialized = 1;
InitializeCriticalSection(&cSection);
}
@ -49,10 +50,12 @@ void QueueKeyEvent(int key, int event)
// purposes when a game is killing the emulator for whatever reason.
if (nextQueuedEvent == lastQueuedEvent ||
queuedEvents[nextQueuedEvent].key != VK_ESCAPE ||
queuedEvents[nextQueuedEvent].evt != KEYPRESS) {
queuedEvents[nextQueuedEvent].evt != KEYPRESS)
{
// Clear queue on escape down, bringing escape to front. May do something
// with shift/ctrl/alt and F-keys, later.
if (event == KEYPRESS && key == VK_ESCAPE) {
if (event == KEYPRESS && key == VK_ESCAPE)
{
nextQueuedEvent = lastQueuedEvent;
}
@ -61,7 +64,8 @@ void QueueKeyEvent(int key, int event)
lastQueuedEvent = (lastQueuedEvent + 1) % EVENT_QUEUE_LEN;
// If queue wrapped around, remove last element.
if (nextQueuedEvent == lastQueuedEvent) {
if (nextQueuedEvent == lastQueuedEvent)
{
nextQueuedEvent = (nextQueuedEvent + 1) % EVENT_QUEUE_LEN;
}
}
@ -70,7 +74,7 @@ void QueueKeyEvent(int key, int event)
#endif
}
int GetQueuedKeyEvent(keyEvent *event)
int GetQueuedKeyEvent(keyEvent* event)
{
if (lastQueuedEvent == nextQueuedEvent)
return 0;
@ -92,7 +96,8 @@ void ClearKeyQueue()
{
lastQueuedEvent = nextQueuedEvent;
#ifdef _MSC_VER
if (csInitialized) {
if (csInitialized)
{
DeleteCriticalSection(&cSection);
csInitialized = 0;
}

View File

@ -18,13 +18,13 @@
// but takes little enough effort to be safe...
void QueueKeyEvent(int key, int event);
int GetQueuedKeyEvent(keyEvent *event);
int GetQueuedKeyEvent(keyEvent* event);
// Cleans up as well as clears queue.
void ClearKeyQueue();
#ifdef __linux__
void R_QueueKeyEvent(const keyEvent &event);
int R_GetQueuedKeyEvent(keyEvent *event);
void R_QueueKeyEvent(const keyEvent& event);
int R_GetQueuedKeyEvent(keyEvent* event);
void R_ClearKeyQueue();
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
#ifndef CONFIG_H
#define CONFIG_H
extern const wchar_t *padTypes[numPadTypes];
extern const wchar_t* padTypes[numPadTypes];
struct PadConfig
{
@ -72,7 +72,7 @@ extern GeneralConfig config;
void UnloadConfigs();
int LoadSettings(int force = 0, wchar_t *file = 0);
int LoadSettings(int force = 0, wchar_t* file = 0);
// Refreshes the set of enabled devices.
void RefreshEnabledDevices(int updateDeviceList = 0);

View File

@ -23,7 +23,7 @@
#include "WindowsKeyboard.h"
#include "WindowsMouse.h"
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output);
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* output);
int GetRawKeyboards(HWND hWnd)
{
@ -80,24 +80,26 @@ class RawInputKeyboard : public WindowsKeyboard
public:
HANDLE hDevice;
RawInputKeyboard(HANDLE hDevice, wchar_t *name, wchar_t *instanceID = 0)
RawInputKeyboard(HANDLE hDevice, wchar_t* name, wchar_t* instanceID = 0)
: WindowsKeyboard(RAW, name, instanceID)
{
this->hDevice = hDevice;
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
Deactivate();
hWndProc = initInfo->hWndProc;
active = 1;
if (!rawKeyboardActivatedCount++) {
if (!rawKeyboardActivatedCount++)
{
if (!rawMouseActivatedCount)
hWndProc->Eat(RawInputWndProc, EATPROC_NO_UPDATE_WHILE_UPDATING_DEVICES);
if (!GetRawKeyboards(hWndProc->hWndEaten)) {
if (!GetRawKeyboards(hWndProc->hWndEaten))
{
Deactivate();
return 0;
}
@ -110,10 +112,12 @@ public:
void Deactivate()
{
FreeState();
if (active) {
if (active)
{
active = 0;
rawKeyboardActivatedCount--;
if (!rawKeyboardActivatedCount) {
if (!rawKeyboardActivatedCount)
{
ReleaseRawKeyboards();
if (!rawMouseActivatedCount)
hWndProc->ReleaseExtraProc(RawInputWndProc);
@ -127,13 +131,13 @@ class RawInputMouse : public WindowsMouse
public:
HANDLE hDevice;
RawInputMouse(HANDLE hDevice, wchar_t *name, wchar_t *instanceID = 0, wchar_t *productID = 0)
RawInputMouse(HANDLE hDevice, wchar_t* name, wchar_t* instanceID = 0, wchar_t* productID = 0)
: WindowsMouse(RAW, 0, name, instanceID, productID)
{
this->hDevice = hDevice;
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
Deactivate();
@ -144,12 +148,14 @@ public:
// Have to be careful with order. At worst, one unmatched call to ReleaseRawMice on
// EatWndProc fail. In all other cases, no unmatched initialization/cleanup
// lines.
if (!rawMouseActivatedCount++) {
if (!rawMouseActivatedCount++)
{
GetMouseCapture(hWndProc->hWndEaten);
if (!rawKeyboardActivatedCount)
hWndProc->Eat(RawInputWndProc, EATPROC_NO_UPDATE_WHILE_UPDATING_DEVICES);
if (!GetRawMice(hWndProc->hWndEaten)) {
if (!GetRawMice(hWndProc->hWndEaten))
{
Deactivate();
return 0;
}
@ -162,13 +168,16 @@ public:
void Deactivate()
{
FreeState();
if (active) {
if (active)
{
active = 0;
rawMouseActivatedCount--;
if (!rawMouseActivatedCount) {
if (!rawMouseActivatedCount)
{
ReleaseRawMice();
ReleaseMouseCapture();
if (!rawKeyboardActivatedCount) {
if (!rawKeyboardActivatedCount)
{
hWndProc->ReleaseExtraProc(RawInputWndProc);
}
}
@ -176,30 +185,38 @@ public:
}
};
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output)
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* output)
{
if (uMsg == WM_INPUT) {
if (GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT) {
if (uMsg == WM_INPUT)
{
if (GET_RAWINPUT_CODE_WPARAM(wParam) == RIM_INPUT)
{
RAWINPUT in;
unsigned int size = sizeof(RAWINPUT);
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &in, &size, sizeof(RAWINPUTHEADER)) > 0) {
for (int i = 0; i < dm->numDevices; i++) {
Device *dev = dm->devices[i];
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &in, &size, sizeof(RAWINPUTHEADER)) > 0)
{
for (int i = 0; i < dm->numDevices; i++)
{
Device* dev = dm->devices[i];
if (dev->api != RAW || !dev->active)
continue;
if (in.header.dwType == RIM_TYPEKEYBOARD && dev->type == KEYBOARD) {
RawInputKeyboard *rik = (RawInputKeyboard *)dev;
if (in.header.dwType == RIM_TYPEKEYBOARD && dev->type == KEYBOARD)
{
RawInputKeyboard* rik = (RawInputKeyboard*)dev;
if (rik->hDevice != in.header.hDevice)
continue;
u32 uMsg = in.data.keyboard.Message;
if (!(in.data.keyboard.VKey >> 8))
rik->UpdateKey((u8)in.data.keyboard.VKey, (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN));
} else if (in.header.dwType == RIM_TYPEMOUSE && dev->type == MOUSE) {
RawInputMouse *rim = (RawInputMouse *)dev;
}
else if (in.header.dwType == RIM_TYPEMOUSE && dev->type == MOUSE)
{
RawInputMouse* rim = (RawInputMouse*)dev;
if (rim->hDevice != in.header.hDevice)
continue;
if (in.data.mouse.usFlags) {
if (in.data.mouse.usFlags)
{
// Never been set for me, and specs on what most of them
// actually mean is sorely lacking. Also, specs erroneously
// indicate MOUSE_MOVE_RELATIVE is a flag, when it's really
@ -209,18 +226,22 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
unsigned short buttons = in.data.mouse.usButtonFlags & 0x3FF;
int button = 0;
while (buttons) {
if (buttons & 3) {
while (buttons)
{
if (buttons & 3)
{
// 2 is up, 1 is down. Up takes precedence over down.
rim->UpdateButton(button, !(buttons & 2));
}
button++;
buttons >>= 2;
}
if (in.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) {
if (in.data.mouse.usButtonFlags & RI_MOUSE_WHEEL)
{
rim->UpdateAxis(2, ((short)in.data.mouse.usButtonData) / WHEEL_DELTA);
}
if (in.data.mouse.lLastX || in.data.mouse.lLastY) {
if (in.data.mouse.lLastX || in.data.mouse.lLastY)
{
rim->UpdateAxis(0, in.data.mouse.lLastX);
rim->UpdateAxis(1, in.data.mouse.lLastY);
}
@ -228,14 +249,19 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
}
}
}
} else if (uMsg == WM_ACTIVATE) {
for (int i = 0; i < dm->numDevices; i++) {
Device *dev = dm->devices[i];
}
else if (uMsg == WM_ACTIVATE)
{
for (int i = 0; i < dm->numDevices; i++)
{
Device* dev = dm->devices[i];
if (dev->api != RAW || dev->physicalControlState == 0)
continue;
memset(dev->physicalControlState, 0, sizeof(int) * dev->numPhysicalControls);
}
} else if (uMsg == WM_SIZE && rawMouseActivatedCount) {
}
else if (uMsg == WM_SIZE && rawMouseActivatedCount)
{
// Doesn't really matter for raw mice, as I disable legacy stuff, but shouldn't hurt.
WindowsMouse::WindowResized(hWnd);
}
@ -246,39 +272,45 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
void EnumRawInputDevices()
{
int count = 0;
if (GetRawInputDeviceList(0, (unsigned int *)&count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1 && count > 0) {
wchar_t *instanceID = (wchar_t *)malloc(41000 * sizeof(wchar_t));
wchar_t *keyName = instanceID + 11000;
wchar_t *displayName = keyName + 10000;
wchar_t *productID = displayName + 10000;
if (GetRawInputDeviceList(0, (unsigned int*)&count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1 && count > 0)
{
wchar_t* instanceID = (wchar_t*)malloc(41000 * sizeof(wchar_t));
wchar_t* keyName = instanceID + 11000;
wchar_t* displayName = keyName + 10000;
wchar_t* productID = displayName + 10000;
RAWINPUTDEVICELIST *list = (RAWINPUTDEVICELIST *)malloc(sizeof(RAWINPUTDEVICELIST) * count);
RAWINPUTDEVICELIST* list = (RAWINPUTDEVICELIST*)malloc(sizeof(RAWINPUTDEVICELIST) * count);
int keyboardCount = 1;
int mouseCount = 1;
count = GetRawInputDeviceList(list, (unsigned int *)&count, sizeof(RAWINPUTDEVICELIST));
count = GetRawInputDeviceList(list, (unsigned int*)&count, sizeof(RAWINPUTDEVICELIST));
// Not necessary, but reminder that count is -1 on failure.
if (count > 0) {
for (int i = 0; i < count; i++) {
if (count > 0)
{
for (int i = 0; i < count; i++)
{
if (list[i].dwType != RIM_TYPEKEYBOARD && list[i].dwType != RIM_TYPEMOUSE)
continue;
UINT bufferLen = 10000;
int nameLen = GetRawInputDeviceInfo(list[i].hDevice, RIDI_DEVICENAME, instanceID, &bufferLen);
if (nameLen >= 4) {
if (nameLen >= 4)
{
// nameLen includes terminating null.
nameLen--;
// Strip out GUID parts of instanceID to make it a generic product id,
// and reformat it to point to registry entry containing device description.
wcscpy(productID, instanceID);
wchar_t *temp = 0;
for (int j = 0; j < 3; j++) {
wchar_t *s = wcschr(productID, '#');
wchar_t* temp = 0;
for (int j = 0; j < 3; j++)
{
wchar_t* s = wcschr(productID, '#');
if (!s)
break;
*s = '\\';
if (j == 2) {
if (j == 2)
{
*s = 0;
}
if (j == 1)
@ -290,12 +322,14 @@ void EnumRawInputDevices()
*temp = 0;
int haveDescription = 0;
HKEY hKey;
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey)) {
if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE, &hKey))
{
DWORD type;
DWORD len = 10000 * sizeof(wchar_t);
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE *)displayName, &len) &&
len && type == REG_SZ) {
wchar_t *temp2 = wcsrchr(displayName, ';');
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"DeviceDesc", 0, &type, (BYTE*)displayName, &len) &&
len && type == REG_SZ)
{
wchar_t* temp2 = wcsrchr(displayName, ';');
if (!temp2)
temp2 = displayName;
else
@ -306,13 +340,16 @@ void EnumRawInputDevices()
}
RegCloseKey(hKey);
}
if (list[i].dwType == RIM_TYPEKEYBOARD) {
if (list[i].dwType == RIM_TYPEKEYBOARD)
{
if (!haveDescription)
wsprintfW(displayName, L"Raw Keyboard %i", keyboardCount++);
else
wsprintfW(displayName, L"Raw KB: %s", keyName);
dm->AddDevice(new RawInputKeyboard(list[i].hDevice, displayName, instanceID));
} else if (list[i].dwType == RIM_TYPEMOUSE) {
}
else if (list[i].dwType == RIM_TYPEMOUSE)
{
if (!haveDescription)
wsprintfW(displayName, L"Raw Mouse %i", mouseCount++);
else

View File

@ -17,11 +17,12 @@
#include "Global.h"
#include "resource_pad.h"
LPWSTR dialog_message(int ID, bool *updateText)
LPWSTR dialog_message(int ID, bool* updateText)
{
if (updateText)
*updateText = true;
switch (ID) {
switch (ID)
{
// General tab
case IDC_M_WM:
case IDC_M_RAW:

View File

@ -18,6 +18,6 @@
#include "Global.h"
LPWSTR dialog_message(int ID, bool *updateText = false);
LPWSTR dialog_message(int ID, bool* updateText = false);
#endif

View File

@ -17,11 +17,12 @@
#include "Global.h"
#include "VKey.h"
wchar_t *GetVKStringW(unsigned char vk)
wchar_t* GetVKStringW(unsigned char vk)
{
int flag;
static wchar_t t[20];
switch (vk) {
switch (vk)
{
case 0x0C:
return L"Clear";
case 0x13:
@ -97,10 +98,13 @@ wchar_t *GetVKStringW(unsigned char vk)
break;
}
int res = MapVirtualKey(vk, MAPVK_VK_TO_VSC);
if (res && GetKeyNameText((res << 16) | flag, t, 20)) {
if (res && GetKeyNameText((res << 16) | flag, t, 20))
{
// don't trust windows
t[19] = 0;
} else {
}
else
{
wsprintfW(t, L"Key %i", vk);
}
return t;

View File

@ -14,4 +14,4 @@
*/
// Maps virtual key codes to strings.
wchar_t *GetVKStringW(unsigned char vk);
wchar_t* GetVKStringW(unsigned char vk);

View File

@ -20,19 +20,21 @@
#include "WindowsKeyboard.h"
#include "KeyboardQueue.h"
WindowsKeyboard::WindowsKeyboard(DeviceAPI api, wchar_t *displayName, wchar_t *instanceID, wchar_t *deviceID)
WindowsKeyboard::WindowsKeyboard(DeviceAPI api, wchar_t* displayName, wchar_t* instanceID, wchar_t* deviceID)
: Device(api, KEYBOARD, displayName, instanceID, deviceID)
{
for (int i = 0; i < 256; i++) {
for (int i = 0; i < 256; i++)
{
AddPhysicalControl(PSHBTN, i, i);
}
}
wchar_t *WindowsKeyboard::GetPhysicalControlName(PhysicalControl *control)
wchar_t* WindowsKeyboard::GetPhysicalControlName(PhysicalControl* control)
{
int id = control->id;
if (control->type == PSHBTN && id >= 0 && id < 256) {
wchar_t *w = GetVKStringW(id);
if (control->type == PSHBTN && id >= 0 && id < 256)
{
wchar_t* w = GetVKStringW(id);
if (w)
return w;
}
@ -41,11 +43,14 @@ wchar_t *WindowsKeyboard::GetPhysicalControlName(PhysicalControl *control)
void WindowsKeyboard::UpdateKey(int vkey, int state)
{
if (vkey > 7 && vkey < 256) {
if (vkey > 7 && vkey < 256)
{
int newState = state * FULLY_DOWN;
if (newState != physicalControlState[vkey]) {
if (newState != physicalControlState[vkey])
{
// Check for alt-F4 to avoid toggling skip mode incorrectly.
if (vkey != VK_F4 || !(physicalControlState[VK_MENU] || physicalControlState[VK_RMENU] || physicalControlState[VK_LMENU])) {
if (vkey != VK_F4 || !(physicalControlState[VK_MENU] || physicalControlState[VK_RMENU] || physicalControlState[VK_LMENU]))
{
int event = KEYPRESS;
if (!newState)
event = KEYRELEASE;
@ -59,10 +64,12 @@ void WindowsKeyboard::UpdateKey(int vkey, int state)
void WindowsKeyboard::InitState()
{
AllocState();
for (int vkey = 5; vkey < 256; vkey++) {
for (int vkey = 5; vkey < 256; vkey++)
{
int value = (unsigned short)(((short)GetAsyncKeyState(vkey)) >> 15);
value += value & 1;
if (vkey == VK_CONTROL || vkey == VK_MENU || vkey == VK_SHIFT) {
if (vkey == VK_CONTROL || vkey == VK_MENU || vkey == VK_SHIFT)
{
value = 0;
}
physicalControlState[vkey] = value;

View File

@ -17,8 +17,8 @@
class WindowsKeyboard : public Device
{
public:
WindowsKeyboard(DeviceAPI api, wchar_t *displayName, wchar_t *instanceID = 0, wchar_t *deviceID = 0);
wchar_t *GetPhysicalControlName(PhysicalControl *control);
WindowsKeyboard(DeviceAPI api, wchar_t* displayName, wchar_t* instanceID = 0, wchar_t* deviceID = 0);
wchar_t* GetPhysicalControlName(PhysicalControl* control);
void UpdateKey(int vkey, int state);
// Calls AllocState() and initializes to current keyboard state using
// GetAsyncKeyState().

View File

@ -23,13 +23,13 @@
#include "WindowsKeyboard.h"
#include "WindowsMouse.h"
ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output);
ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* output);
class WindowsMessagingKeyboard;
class WindowsMessagingMouse;
static WindowsMessagingKeyboard *wmk = 0;
static WindowsMessagingMouse *wmm = 0;
static WindowsMessagingKeyboard* wmk = 0;
static WindowsMessagingMouse* wmm = 0;
class WindowsMessagingKeyboard : public WindowsKeyboard
{
@ -39,7 +39,7 @@ public:
{
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
// Redundant. Should match the next line.
// Deactivate();
@ -60,7 +60,8 @@ public:
void Deactivate()
{
if (active) {
if (active)
{
if (!wmm)
hWndProc->ReleaseExtraProc(WindowsMessagingWndProc);
wmk = 0;
@ -84,7 +85,7 @@ public:
{
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
// Redundant. Should match the next line.
// Deactivate();
@ -107,7 +108,8 @@ public:
void Deactivate()
{
if (active) {
if (active)
{
if (!wmk)
hWndProc->ReleaseExtraProc(WindowsMessagingWndProc);
ReleaseMouseCapture();
@ -118,62 +120,90 @@ public:
}
};
ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output)
ExtraWndProcResult WindowsMessagingWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* output)
{
if (wmk) {
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN || uMsg == WM_KEYUP || uMsg == WM_SYSKEYUP) {
if (wParam == VK_SHIFT) {
if (wmk)
{
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN || uMsg == WM_KEYUP || uMsg == WM_SYSKEYUP)
{
if (wParam == VK_SHIFT)
{
wmk->CheckKey(VK_RSHIFT);
wmk->CheckKey(VK_LSHIFT);
} else if (wParam == VK_CONTROL) {
}
else if (wParam == VK_CONTROL)
{
wmk->CheckKey(VK_RCONTROL);
wmk->CheckKey(VK_LCONTROL);
} else if (wParam == VK_MENU) {
}
else if (wParam == VK_MENU)
{
wmk->CheckKey(VK_RMENU);
wmk->CheckKey(VK_LMENU);
} else
}
else
wmk->UpdateKey(wParam, (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN));
return NO_WND_PROC;
}
// Needed to prevent default handling of keys in some situations.
else if (uMsg == WM_CHAR || uMsg == WM_UNICHAR) {
else if (uMsg == WM_CHAR || uMsg == WM_UNICHAR)
{
return NO_WND_PROC;
} else if (uMsg == WM_ACTIVATE) {
}
else if (uMsg == WM_ACTIVATE)
{
// Not really needed, but doesn't hurt.
memset(wmk->physicalControlState, 0, sizeof(int) * wmk->numPhysicalControls);
}
}
if (wmm) {
if (uMsg == WM_MOUSEMOVE) {
if (wmm)
{
if (uMsg == WM_MOUSEMOVE)
{
POINT p;
GetCursorPos(&p);
// Need check to prevent cursor movement cascade.
if (p.x != wmm->center.x || p.y != wmm->center.y) {
if (p.x != wmm->center.x || p.y != wmm->center.y)
{
wmm->UpdateAxis(0, p.x - wmm->center.x);
wmm->UpdateAxis(1, p.y - wmm->center.y);
SetCursorPos(wmm->center.x, wmm->center.y);
}
return NO_WND_PROC;
} else if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) {
}
else if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP)
{
wmm->UpdateButton(0, uMsg == WM_LBUTTONDOWN);
return NO_WND_PROC;
} else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP) {
}
else if (uMsg == WM_RBUTTONDOWN || uMsg == WM_RBUTTONUP)
{
wmm->UpdateButton(1, uMsg == WM_RBUTTONDOWN);
return NO_WND_PROC;
} else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) {
}
else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP)
{
wmm->UpdateButton(2, uMsg == WM_MBUTTONDOWN);
return NO_WND_PROC;
} else if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP) {
}
else if (uMsg == WM_XBUTTONDOWN || uMsg == WM_XBUTTONUP)
{
wmm->UpdateButton(3 + ((wParam >> 16) == XBUTTON2), uMsg == WM_XBUTTONDOWN);
return NO_WND_PROC;
} else if (uMsg == WM_MOUSEWHEEL) {
}
else if (uMsg == WM_MOUSEWHEEL)
{
wmm->UpdateAxis(2, ((int)wParam >> 16) / WHEEL_DELTA);
return NO_WND_PROC;
} else if (uMsg == WM_MOUSEHWHEEL) {
}
else if (uMsg == WM_MOUSEHWHEEL)
{
wmm->UpdateAxis(3, ((int)wParam >> 16) / WHEEL_DELTA);
return NO_WND_PROC;
} else if (uMsg == WM_SIZE && wmm->active) {
}
else if (uMsg == WM_SIZE && wmm->active)
{
WindowsMouse::WindowResized(hWnd);
}
// Taken care of elsewhere. When binding, killing focus means stop reading input.

View File

@ -22,22 +22,24 @@
POINT WindowsMouse::origCursorPos;
POINT WindowsMouse::center;
WindowsMouse::WindowsMouse(DeviceAPI api, int hWheel, wchar_t *displayName, wchar_t *instanceID, wchar_t *deviceID)
WindowsMouse::WindowsMouse(DeviceAPI api, int hWheel, wchar_t* displayName, wchar_t* instanceID, wchar_t* deviceID)
: Device(api, MOUSE, displayName, instanceID, deviceID)
{
int i;
for (i = 0; i < 5; i++) {
for (i = 0; i < 5; i++)
{
AddPhysicalControl(PSHBTN, i, i);
}
for (i = 0; i < 3 + hWheel; i++) {
for (i = 0; i < 3 + hWheel; i++)
{
AddPhysicalControl(RELAXIS, i + 5, i + 5);
}
}
wchar_t *WindowsMouse::GetPhysicalControlName(PhysicalControl *control)
wchar_t* WindowsMouse::GetPhysicalControlName(PhysicalControl* control)
{
wchar_t *names[9] = {
wchar_t* names[9] = {
L"L Button",
L"R Button",
L"M Button",

View File

@ -29,8 +29,8 @@ public:
// hWheel variable lets me display no horizontal wheel for raw input, just to make it clear
// that it's not supported.
WindowsMouse(DeviceAPI api, int hWheel, wchar_t *displayName, wchar_t *instanceID = 0, wchar_t *deviceID = 0);
wchar_t *GetPhysicalControlName(PhysicalControl *control);
WindowsMouse(DeviceAPI api, int hWheel, wchar_t* displayName, wchar_t* instanceID = 0, wchar_t* deviceID = 0);
wchar_t* GetPhysicalControlName(PhysicalControl* control);
// State is 0 for up, 1 for down.
void UpdateButton(unsigned int button, int state);
// 0/1 are x/y. 2 is vert wheel, 3 is horiz wheel.

View File

@ -30,7 +30,8 @@ WndProcEater::WndProcEater()
WndProcEater::~WndProcEater() throw()
{
if (hMutex) {
if (hMutex)
{
ReleaseMutex(hMutex);
CloseHandle(hMutex);
}
@ -44,13 +45,16 @@ void WndProcEater::ReleaseExtraProc(ExtraWndProc proc)
//printf( "(Lilypad) Regurgitating! -> 0x%x\n", proc );
for (int i = 0; i < numExtraProcs; i++) {
if (extraProcs[i].proc == proc) {
for (int i = 0; i < numExtraProcs; i++)
{
if (extraProcs[i].proc == proc)
{
extraProcs[i] = extraProcs[--numExtraProcs];
break;
}
}
if (!numExtraProcs && eatenWndProc) {
if (!numExtraProcs && eatenWndProc)
{
free(extraProcs);
extraProcs = 0;
// As numExtraProcs is 0, won't cause recursion if called from Release().
@ -62,7 +66,8 @@ void WndProcEater::Release()
{
while (numExtraProcs)
ReleaseExtraProc(extraProcs[0].proc);
if (hWndEaten && IsWindow(hWndEaten)) {
if (hWndEaten && IsWindow(hWndEaten))
{
RemoveProp(hWndEaten, L"LilyHaxxor");
SetWindowLongPtr(hWndEaten, GWLP_WNDPROC, (LONG_PTR)eatenWndProc);
hWndEaten = 0;
@ -78,28 +83,35 @@ LRESULT WndProcEater::_OverrideWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
ExtraWndProcResult res = CONTINUE_BLISSFULLY;
LRESULT out = 0;
// Here because want it for binding, even when no keyboard mode is selected.
if (uMsg == WM_GETDLGCODE) {
if (uMsg == WM_GETDLGCODE)
{
return DLGC_WANTALLKEYS | CallWindowProc(eatenWndProc, hWnd, uMsg, wParam, lParam);
}
for (int i = 0; i < numExtraProcs; i++) {
for (int i = 0; i < numExtraProcs; i++)
{
// Note: Second bit of deviceUpdateQueued is only set when I receive a device change
// notification, which is handled in the GS thread in one of the extraProcs, so this
// is all I need to prevent bad things from happening while updating devices. No mutex needed.
// if ((deviceUpdateQueued&2) && (extraProcs[i].flags & EATPROC_NO_UPDATE_WHILE_UPDATING_DEVICES)) continue;
ExtraWndProcResult res2 = extraProcs[i].proc(hWnd, uMsg, wParam, lParam, &out);
if (res2 != res) {
if (res2 == CONTINUE_BLISSFULLY_AND_RELEASE_PROC) {
if (res2 != res)
{
if (res2 == CONTINUE_BLISSFULLY_AND_RELEASE_PROC)
{
ReleaseExtraProc(extraProcs[i].proc);
i--;
} else if (res2 > res)
}
else if (res2 > res)
res = res2;
}
}
if (res != NO_WND_PROC) {
if (out == WM_DESTROY) {
if (res != NO_WND_PROC)
{
if (out == WM_DESTROY)
{
Release();
}
if (res == CONTINUE_BLISSFULLY)
@ -112,7 +124,7 @@ LRESULT WndProcEater::_OverrideWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
static LRESULT CALLBACK OverrideWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WndProcEater *obj = (WndProcEater *)GetProp(hWnd, L"LilyHaxxor");
WndProcEater* obj = (WndProcEater*)GetProp(hWnd, L"LilyHaxxor");
return (obj == NULL) ?
DefWindowProc(hWnd, uMsg, wParam, lParam) :
obj->_OverrideWndProc(hWnd, uMsg, wParam, lParam);
@ -126,7 +138,7 @@ bool WndProcEater::SetWndHandle(HWND hWnd)
//printf( "(Lilypad) (Re)-Setting window handle! -> this=0x%08x, hWnd=0x%08x\n", this, hWnd );
Release();
SetProp(hWnd, L"LilyHaxxor", (HANDLE) this);
SetProp(hWnd, L"LilyHaxxor", (HANDLE)this);
eatenWndProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)OverrideWndProc);
hWndEaten = (eatenWndProc) ? hWnd : 0;
@ -147,7 +159,7 @@ void WndProcEater::Eat(ExtraWndProc proc, DWORD flags)
//printf( "(Lilypad) EatingWndProc! -> 0x%x\n", proc );
extraProcs = (ExtraWndProcInfo *)realloc(extraProcs, sizeof(ExtraWndProcInfo) * (numExtraProcs + 1));
extraProcs = (ExtraWndProcInfo*)realloc(extraProcs, sizeof(ExtraWndProcInfo) * (numExtraProcs + 1));
extraProcs[numExtraProcs].proc = proc;
extraProcs[numExtraProcs].flags = flags;
numExtraProcs++;

View File

@ -17,7 +17,8 @@
/* Need this to let window be subclassed multiple times but still clean up nicely.
*/
enum ExtraWndProcResult {
enum ExtraWndProcResult
{
CONTINUE_BLISSFULLY,
// Calls ReleaseExtraProc without messing up order.
CONTINUE_BLISSFULLY_AND_RELEASE_PROC,
@ -25,7 +26,7 @@ enum ExtraWndProcResult {
NO_WND_PROC
};
typedef ExtraWndProcResult (*ExtraWndProc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *out);
typedef ExtraWndProcResult (*ExtraWndProc)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* out);
struct ExtraWndProcInfo
{
@ -38,7 +39,7 @@ class WndProcEater
public:
HWND hWndEaten;
WNDPROC eatenWndProc;
ExtraWndProcInfo *extraProcs;
ExtraWndProcInfo* extraProcs;
int numExtraProcs;
HANDLE hMutex;

View File

@ -60,10 +60,10 @@ typedef struct
// This way, I don't require that XInput junk be installed.
typedef void(CALLBACK *_XInputEnable)(BOOL enable);
typedef DWORD(CALLBACK *_XInputGetStateEx)(DWORD dwUserIndex, XINPUT_STATE *pState);
typedef DWORD(CALLBACK *_XInputGetExtended)(DWORD dwUserIndex, SCP_EXTN *pPressure);
typedef DWORD(CALLBACK *_XInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration);
typedef void(CALLBACK* _XInputEnable)(BOOL enable);
typedef DWORD(CALLBACK* _XInputGetStateEx)(DWORD dwUserIndex, XINPUT_STATE* pState);
typedef DWORD(CALLBACK* _XInputGetExtended)(DWORD dwUserIndex, SCP_EXTN* pPressure);
typedef DWORD(CALLBACK* _XInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
_XInputEnable pXInputEnable = 0;
_XInputGetStateEx pXInputGetStateEx = 0;
@ -94,17 +94,19 @@ class XInputDevice : public Device
public:
int index;
XInputDevice(int index, wchar_t *displayName)
XInputDevice(int index, wchar_t* displayName)
: Device(XINPUT, OTHER, displayName)
{
memset(ps2Vibration, 0, sizeof(ps2Vibration));
memset(&xInputVibration, 0, sizeof(xInputVibration));
this->index = index;
int i;
for (i = 0; i < 17; i++) { // Skip empty bit
for (i = 0; i < 17; i++)
{ // Skip empty bit
AddPhysicalControl(PRESSURE_BTN, i + (i > 10), 0);
}
for (; i < 21; i++) {
for (; i < 21; i++)
{
AddPhysicalControl(ABSAXIS, i + 2, 0);
}
AddFFAxis(L"Slow Motor", 0);
@ -112,9 +114,9 @@ public:
AddFFEffectType(L"Constant Effect", L"Constant", EFFECT_CONSTANT);
}
wchar_t *GetPhysicalControlName(PhysicalControl *c)
wchar_t* GetPhysicalControlName(PhysicalControl* c)
{
const static wchar_t *names[] = {
const static wchar_t* names[] = {
L"D-pad Up",
L"D-pad Down",
L"D-pad Left",
@ -138,17 +140,19 @@ public:
L"Right Thumb Y",
};
unsigned int i = (unsigned int)(c - physicalControls);
if (i < 21) {
return (wchar_t *)names[i];
if (i < 21)
{
return (wchar_t*)names[i];
}
return Device::GetPhysicalControlName(c);
}
int Activate(InitInfo *initInfo)
int Activate(InitInfo* initInfo)
{
if (active)
Deactivate();
if (!xInputActiveCount) {
if (!xInputActiveCount)
{
pXInputEnable(1);
}
xInputActiveCount++;
@ -162,15 +166,18 @@ public:
if (!active)
return 0;
SCP_EXTN pressure;
if (!pXInputGetExtended || (ERROR_SUCCESS != pXInputGetExtended(index, &pressure))) {
if (!pXInputGetExtended || (ERROR_SUCCESS != pXInputGetExtended(index, &pressure)))
{
XINPUT_STATE state;
if (ERROR_SUCCESS != pXInputGetStateEx(index, &state)) {
if (ERROR_SUCCESS != pXInputGetStateEx(index, &state))
{
Deactivate();
return 0;
}
int buttons = state.Gamepad.wButtons;
for (int i = 0; i < 15; i++) {
for (int i = 0; i < 15; i++)
{
physicalControlState[i] = ((buttons >> physicalControls[i].id) & 1) << 16;
}
physicalControlState[15] = (int)(state.Gamepad.bLeftTrigger * 257.005);
@ -179,7 +186,9 @@ public:
physicalControlState[18] = ShortToAxis(state.Gamepad.sThumbLY);
physicalControlState[19] = ShortToAxis(state.Gamepad.sThumbRX);
physicalControlState[20] = ShortToAxis(state.Gamepad.sThumbRY);
} else {
}
else
{
physicalControlState[0] = (int)(pressure.SCP_UP * FULLY_DOWN);
physicalControlState[1] = (int)(pressure.SCP_DOWN * FULLY_DOWN);
physicalControlState[2] = (int)(pressure.SCP_LEFT * FULLY_DOWN);
@ -209,34 +218,41 @@ public:
{
ps2Vibration[port][slot][motor] = force;
int newVibration[2] = {0, 0};
for (int p = 0; p < 2; p++) {
for (int s = 0; s < 4; s++) {
for (int p = 0; p < 2; p++)
{
for (int s = 0; s < 4; s++)
{
int padtype = config.padConfigs[p][s].type;
for (int i = 0; i < pads[p][s][padtype].numFFBindings; i++) {
for (int i = 0; i < pads[p][s][padtype].numFFBindings; i++)
{
// Technically should also be a *65535/BASE_SENSITIVITY, but that's close enough to 1 for me.
ForceFeedbackBinding *ffb = &pads[p][s][padtype].ffBindings[i];
ForceFeedbackBinding* ffb = &pads[p][s][padtype].ffBindings[i];
newVibration[0] += (int)((ffb->axes[0].force * (__int64)ps2Vibration[p][s][ffb->motor]) / 255);
newVibration[1] += (int)((ffb->axes[1].force * (__int64)ps2Vibration[p][s][ffb->motor]) / 255);
}
}
}
newVibration[0] = abs(newVibration[0]);
if (newVibration[0] > 65535) {
if (newVibration[0] > 65535)
{
newVibration[0] = 65535;
}
newVibration[1] = abs(newVibration[1]);
if (newVibration[1] > 65535) {
if (newVibration[1] > 65535)
{
newVibration[1] = 65535;
}
if (newVibration[0] || newVibration[1] || newVibration[0] != xInputVibration.wLeftMotorSpeed || newVibration[1] != xInputVibration.wRightMotorSpeed) {
if (newVibration[0] || newVibration[1] || newVibration[0] != xInputVibration.wLeftMotorSpeed || newVibration[1] != xInputVibration.wRightMotorSpeed)
{
XINPUT_VIBRATION newv = {(WORD)newVibration[0], (WORD)newVibration[1]};
if (ERROR_SUCCESS == pXInputSetState(index, &newv)) {
if (ERROR_SUCCESS == pXInputSetState(index, &newv))
{
xInputVibration = newv;
}
}
}
void SetEffect(ForceFeedbackBinding *binding, unsigned char force)
void SetEffect(ForceFeedbackBinding* binding, unsigned char force)
{
PadBindings pBackup = pads[0][0][0];
pads[0][0][0].ffBindings = binding;
@ -252,8 +268,10 @@ public:
pXInputSetState(index, &xInputVibration);
FreeState();
if (active) {
if (!--xInputActiveCount) {
if (active)
{
if (!--xInputActiveCount)
{
pXInputEnable(0);
}
active = 0;
@ -268,7 +286,8 @@ public:
void EnumXInputDevices()
{
wchar_t temp[30];
if (!pXInputSetState) {
if (!pXInputSetState)
{
// XInput not installed, so don't repeatedly try to load it.
if (xinputNotInstalled)
return;
@ -278,25 +297,30 @@ void EnumXInputDevices()
// Windows 7 systems have issues with it.
// FIXME: Missing FreeLibrary call.
HMODULE hMod = LoadLibrary(L"xinput1_3.dll");
if (hMod == nullptr && IsWindows8OrGreater()) {
if (hMod == nullptr && IsWindows8OrGreater())
{
hMod = LoadLibraryEx(L"XInput1_4.dll", nullptr, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
}
if (hMod) {
if (hMod)
{
if ((pXInputEnable = (_XInputEnable)GetProcAddress(hMod, "XInputEnable")) &&
((pXInputGetStateEx = (_XInputGetStateEx)GetProcAddress(hMod, (LPCSTR)100)) || // Try Ex version first
(pXInputGetStateEx = (_XInputGetStateEx)GetProcAddress(hMod, "XInputGetState")))) {
(pXInputGetStateEx = (_XInputGetStateEx)GetProcAddress(hMod, "XInputGetState"))))
{
pXInputGetExtended = (_XInputGetExtended)GetProcAddress(hMod, "XInputGetExtended");
pXInputSetState = (_XInputSetState)GetProcAddress(hMod, "XInputSetState");
}
}
if (!pXInputSetState) {
if (!pXInputSetState)
{
xinputNotInstalled = true;
return;
}
}
pXInputEnable(1);
for (int i = 0; i < 4; i++) {
for (int i = 0; i < 4; i++)
{
wsprintfW(temp, L"XInput Pad %i", i);
dm->AddDevice(new XInputDevice(i, temp));
}

View File

@ -120,7 +120,7 @@ struct usb_endpoint_descriptor
unsigned char bRefresh;
unsigned char bSynchAddress;
unsigned char *extra; /* Extra descriptors */
unsigned char* extra; /* Extra descriptors */
int extralen;
};
@ -147,9 +147,9 @@ struct usb_interface_descriptor
unsigned char bInterfaceProtocol;
unsigned char iInterface;
struct usb_endpoint_descriptor *endpoint;
struct usb_endpoint_descriptor* endpoint;
unsigned char *extra; /* Extra descriptors */
unsigned char* extra; /* Extra descriptors */
int extralen;
};
@ -157,7 +157,7 @@ struct usb_interface_descriptor
struct usb_interface
{
struct usb_interface_descriptor *altsetting;
struct usb_interface_descriptor* altsetting;
int num_altsetting;
};
@ -175,9 +175,9 @@ struct usb_config_descriptor
unsigned char bmAttributes;
unsigned char MaxPower;
struct usb_interface *interface;
struct usb_interface* interface;
unsigned char *extra; /* Extra descriptors */
unsigned char* extra; /* Extra descriptors */
int extralen;
};
@ -262,17 +262,17 @@ struct usb_device
char filename[LIBUSB_PATH_MAX];
struct usb_bus *bus;
struct usb_bus* bus;
struct usb_device_descriptor descriptor;
struct usb_config_descriptor *config;
struct usb_config_descriptor* config;
void *dev; /* Darwin support */
void* dev; /* Darwin support */
unsigned char devnum;
unsigned char num_children;
struct usb_device **children;
struct usb_device** children;
};
struct usb_bus
@ -281,10 +281,10 @@ struct usb_bus
char dirname[LIBUSB_PATH_MAX];
struct usb_device *devices;
struct usb_device* devices;
unsigned long location;
struct usb_device *root_dev;
struct usb_device* root_dev;
};
/* Version information, Windows specific */
@ -327,48 +327,48 @@ extern "C" {
/* Function prototypes */
/* usb.c */
usb_dev_handle *usb_open(struct usb_device *dev);
int usb_close(usb_dev_handle *dev);
int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
usb_dev_handle* usb_open(struct usb_device* dev);
int usb_close(usb_dev_handle* dev);
int usb_get_string(usb_dev_handle* dev, int index, int langid, char* buf,
size_t buflen);
int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
int usb_get_string_simple(usb_dev_handle* dev, int index, char* buf,
size_t buflen);
/* descriptors.c */
int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
int usb_get_descriptor_by_endpoint(usb_dev_handle* udev, int ep,
unsigned char type, unsigned char index,
void *buf, int size);
int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
unsigned char index, void *buf, int size);
void* buf, int size);
int usb_get_descriptor(usb_dev_handle* udev, unsigned char type,
unsigned char index, void* buf, int size);
/* <arch>.c */
int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
int usb_bulk_write(usb_dev_handle* dev, int ep, char* bytes, int size,
int timeout);
int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
int usb_bulk_read(usb_dev_handle* dev, int ep, char* bytes, int size,
int timeout);
int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
int usb_interrupt_write(usb_dev_handle* dev, int ep, char* bytes, int size,
int timeout);
int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
int usb_interrupt_read(usb_dev_handle* dev, int ep, char* bytes, int size,
int timeout);
int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
int value, int index, char *bytes, int size,
int usb_control_msg(usb_dev_handle* dev, int requesttype, int request,
int value, int index, char* bytes, int size,
int timeout);
int usb_set_configuration(usb_dev_handle *dev, int configuration);
int usb_claim_interface(usb_dev_handle *dev, int interface);
int usb_release_interface(usb_dev_handle *dev, int interface);
int usb_set_altinterface(usb_dev_handle *dev, int alternate);
int usb_resetep(usb_dev_handle *dev, unsigned int ep);
int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
int usb_reset(usb_dev_handle *dev);
int usb_set_configuration(usb_dev_handle* dev, int configuration);
int usb_claim_interface(usb_dev_handle* dev, int interface);
int usb_release_interface(usb_dev_handle* dev, int interface);
int usb_set_altinterface(usb_dev_handle* dev, int alternate);
int usb_resetep(usb_dev_handle* dev, unsigned int ep);
int usb_clear_halt(usb_dev_handle* dev, unsigned int ep);
int usb_reset(usb_dev_handle* dev);
char *usb_strerror(void);
char* usb_strerror(void);
void usb_init(void);
void usb_set_debug(int level);
int usb_find_busses(void);
int usb_find_devices(void);
struct usb_device *usb_device(usb_dev_handle *dev);
struct usb_bus *usb_get_busses(void);
struct usb_device* usb_device(usb_dev_handle* dev);
struct usb_bus* usb_get_busses(void);
/* Windows specific functions */
@ -384,32 +384,32 @@ void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
LPSTR cmd_line, int cmd_show);
#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
int usb_install_driver_np(const char *inf_file);
int usb_install_driver_np(const char* inf_file);
void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
LPSTR cmd_line, int cmd_show);
#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
int usb_touch_inf_file_np(const char *inf_file);
int usb_touch_inf_file_np(const char* inf_file);
void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
LPSTR cmd_line, int cmd_show);
#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
int usb_install_needs_restart_np(void);
const struct usb_version *usb_get_version(void);
const struct usb_version* usb_get_version(void);
int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,
int usb_isochronous_setup_async(usb_dev_handle* dev, void** context,
unsigned char ep, int pktsize);
int usb_bulk_setup_async(usb_dev_handle *dev, void **context,
int usb_bulk_setup_async(usb_dev_handle* dev, void** context,
unsigned char ep);
int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,
int usb_interrupt_setup_async(usb_dev_handle* dev, void** context,
unsigned char ep);
int usb_submit_async(void *context, char *bytes, int size);
int usb_reap_async(void *context, int timeout);
int usb_reap_async_nocancel(void *context, int timeout);
int usb_cancel_async(void *context);
int usb_free_async(void **context);
int usb_submit_async(void* context, char* bytes, int size);
int usb_reap_async(void* context, int timeout);
int usb_reap_async_nocancel(void* context, int timeout);
int usb_cancel_async(void* context);
int usb_free_async(void** context);
#ifdef __cplusplus

View File

@ -950,9 +950,6 @@
<ItemGroup>
<Manifest Include="..\PCSX2.manifest" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\PAD\Windows\frog.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>

View File

@ -2185,9 +2185,4 @@
<Filter>AppHost\Resources</Filter>
</Manifest>
</ItemGroup>
<ItemGroup>
<Image Include="..\..\PAD\Windows\frog.ico">
<Filter>System\Ps2\PAD</Filter>
</Image>
</ItemGroup>
</Project>