LilyPad: Hack to put save state number in window title, can set sensitivity of multiple bindings at once, fixed issues with displaying disconnected devices, some random code cleanup.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@475 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
mattmenke 2009-02-11 20:47:41 +00:00
parent fd4f5bab0b
commit 2521bd2f1d
21 changed files with 383 additions and 571 deletions

View File

@ -1,4 +1,7 @@
#include "global.h" #include "Global.h"
#include <Dbt.h>
#include <commctrl.h>
#include "Config.h" #include "Config.h"
#include "PS2Edefs.h" #include "PS2Edefs.h"
#include "Resource.h" #include "Resource.h"
@ -11,8 +14,9 @@
#include "InputManager.h" #include "InputManager.h"
#include "KeyboardQueue.h" #include "KeyboardQueue.h"
#include "WndProcEater.h" #include "WndProcEater.h"
#include <Dbt.h>
#include <commctrl.h> // Needed to know if raw input is available. It requires XP or higher.
#include "RawInput.h"
GeneralConfig config; GeneralConfig config;
@ -20,11 +24,6 @@ HWND hWndProp = 0;
int selected = 0; int selected = 0;
_RegisterRawInputDevices pRegisterRawInputDevices = 0;
_GetRawInputDeviceInfo pGetRawInputDeviceInfo = 0;
_GetRawInputData pGetRawInputData = 0;
_GetRawInputDeviceList pGetRawInputDeviceList = 0;
HWND hWnds[2] = {0,0}; HWND hWnds[2] = {0,0};
HWND hWndGeneral = 0; HWND hWndGeneral = 0;
@ -264,38 +263,69 @@ void SelChanged(int pad) {
int disableFlip = 0; int disableFlip = 0;
wchar_t temp[3][1000]; wchar_t temp[3][1000];
Device *dev; Device *dev;
Binding *b; int bFound = 0;
int ffbFound = 0;
ForceFeedbackBinding *ffb = 0; ForceFeedbackBinding *ffb = 0;
if (i == 1) { if (i >= 1) {
int index = ListView_GetNextItem(hWndList, -1, LVNI_SELECTED); int index = -1;
LVITEMW item; int flipped = 0;
item.iItem = index; Binding *b;
item.mask = LVIF_TEXT; while (1) {
for (j=0; j<3; j++) { index = ListView_GetNextItem(hWndList, index, LVNI_SELECTED);
item.pszText = temp[j]; if (index < 0) break;
item.iSubItem = j; LVITEMW item;
item.cchTextMax = sizeof(temp[0])/sizeof(temp[0][0]); item.iItem = index;
if (!ListView_GetItem(hWndList, &item)) break; item.mask = LVIF_TEXT;
} for (j=0; j<3; j++) {
if (j == 3) { item.pszText = temp[j];
devName = temp[0]; item.iSubItem = j;
key = temp[1]; item.cchTextMax = sizeof(temp[0])/sizeof(temp[0][0]);
command = temp[2]; if (!ListView_GetItem(hWndList, &item)) break;
if (GetBinding(pad, index, dev, b, ffb)) { }
if (b) { if (j == 3) {
VirtualControl *control = &dev->virtualControls[b->controlIndex]; devName = temp[0];
// Ignore key = temp[1];
if (b->command != 0x7F) { command = temp[2];
turbo = b->turbo; if (GetBinding(pad, index, dev, b, ffb)) {
sensitivity = b->sensitivity; if (b) {
// Only relative axes can't have negative sensitivity. bFound ++;
if (((control->uid >> 16) & 0xFF) == RELAXIS) { VirtualControl *control = &dev->virtualControls[b->controlIndex];
disableFlip = 1; // Ignore
if (b->command != 0x7F) {
// Only relative axes can't have negative sensitivity.
if (((control->uid >> 16) & 0xFF) == RELAXIS) {
disableFlip = 1;
}
turbo += b->turbo;
if (b->sensitivity < 0) {
flipped ++;
sensitivity -= b->sensitivity;
}
else {
sensitivity += b->sensitivity;
}
} }
else disableFlip = 1;
} }
else ffbFound++;
} }
} }
} }
if ((bFound && ffbFound) || ffbFound > 1) {
ffb = 0;
turbo = -1;
sensitivity = 0;
disableFlip = 1;
bFound = ffbFound = 0;
}
else if (bFound) {
turbo++;
sensitivity /= bFound;
if (bFound > 1) disableFlip = 1;
else if (flipped) {
sensitivity = -sensitivity;
}
}
} }
for (i=IDC_SLIDER1; i<ID_DELETE; i++) { for (i=IDC_SLIDER1; i<ID_DELETE; i++) {
@ -335,7 +365,7 @@ void SelChanged(int pad) {
ShowWindow(hWndTemp, enable); ShowWindow(hWndTemp, enable);
} }
} }
if (!ffb) { if (!ffb) {
SetWindowText(GetDlgItem(hWnd, IDC_AXIS_DEVICE1), devName); SetWindowText(GetDlgItem(hWnd, IDC_AXIS_DEVICE1), devName);
SetWindowText(GetDlgItem(hWnd, IDC_AXIS1), key); SetWindowText(GetDlgItem(hWnd, IDC_AXIS1), key);
SetWindowText(GetDlgItem(hWnd, IDC_AXIS_CONTROL1), command); SetWindowText(GetDlgItem(hWnd, IDC_AXIS_CONTROL1), command);
@ -345,7 +375,14 @@ void SelChanged(int pad) {
if (disableFlip) EnableWindow(GetDlgItem(hWnd, IDC_FLIP1), 0); if (disableFlip) EnableWindow(GetDlgItem(hWnd, IDC_FLIP1), 0);
EnableWindow(GetDlgItem(hWnd, IDC_TURBO), turbo >= 0); EnableWindow(GetDlgItem(hWnd, IDC_TURBO), turbo >= 0);
CheckDlgButton(hWnd, IDC_TURBO, BST_CHECKED * (turbo>0)); if (turbo > 0 && turbo < bFound) {
SendMessage(GetDlgItem(hWnd, IDC_TURBO), BM_SETSTYLE, BS_AUTO3STATE, 0);
CheckDlgButton(hWnd, IDC_TURBO, BST_INDETERMINATE);
}
else {
SendMessage(GetDlgItem(hWnd, IDC_TURBO), BM_SETSTYLE, BS_AUTOCHECKBOX, 0);
CheckDlgButton(hWnd, IDC_TURBO, BST_CHECKED * (bFound && turbo == bFound));
}
} }
else { else {
wchar_t temp2[2000]; wchar_t temp2[2000];
@ -450,34 +487,36 @@ int ListBoundEffect(int pad, Device *dev, ForceFeedbackBinding *b) {
return index; return index;
} }
// Only for use with control bindings. // Only for use with control bindings. Affects all highlighted bindings.
void ChangeValue(int pad, int *newSensitivity, int *turbo) { void ChangeValue(int pad, int *newSensitivity, int *turbo) {
if (!hWnds[pad]) return; if (!hWnds[pad]) return;
HWND hWndList = GetDlgItem(hWnds[pad], IDC_LIST); HWND hWndList = GetDlgItem(hWnds[pad], IDC_LIST);
int i = ListView_GetSelectedCount(hWndList); int count = ListView_GetSelectedCount(hWndList);
if (i != 1) return; if (count < 1) return;
int index = ListView_GetNextItem(hWndList, -1, LVNI_SELECTED); int index = -1;
Device *dev; while (1) {
Binding *b; index = ListView_GetNextItem(hWndList, index, LVNI_SELECTED);
ForceFeedbackBinding *ffb; if (index < 0) break;
if (!GetBinding(pad, index, dev, b, ffb) || ffb) return; Device *dev;
if (newSensitivity) { Binding *b;
b->sensitivity = *newSensitivity; ForceFeedbackBinding *ffb;
if (!GetBinding(pad, index, dev, b, ffb) || ffb) return;
if (newSensitivity) {
// Don't change flip state when modifying multiple controls.
if (count > 1 && b->sensitivity < 0)
b->sensitivity = -*newSensitivity;
else
b->sensitivity = *newSensitivity;
}
if (turbo) {
b->turbo = *turbo;
}
} }
if (turbo) {
b->turbo = *turbo;
}
// Use this because it validates values. May inline just what I need later.
// index = BindCommand(dev, dev->virtualControls[b->controlIndex].uid, pad, b->command, sensitivity, b->flip2);
//if (index >= 0) {
PropSheet_Changed(hWndProp, hWnds[pad]); PropSheet_Changed(hWndProp, hWnds[pad]);
SelChanged(pad); SelChanged(pad);
/* UnselectAll(hWndList);
ListView_SetItemState(hWndList, index, LVIS_SELECTED, LVIS_SELECTED);
}//*/
} }
// Only for use with control bindings. // Only for use with effect bindings.
void ChangeEffect(int pad, int id, int *newForce, unsigned int *newEffectType) { void ChangeEffect(int pad, int id, int *newForce, unsigned int *newEffectType) {
if (!hWnds[pad]) return; if (!hWnds[pad]) return;
HWND hWndList = GetDlgItem(hWnds[pad], IDC_LIST); HWND hWndList = GetDlgItem(hWnds[pad], IDC_LIST);
@ -593,6 +632,8 @@ int SaveSettings(wchar_t *file = 0) {
WritePrivateProfileInt(L"General Settings", L"XInput", config.gameApis.xInput, file); WritePrivateProfileInt(L"General Settings", L"XInput", config.gameApis.xInput, file);
WritePrivateProfileInt(L"General Settings", L"Multiple Bindings", config.multipleBinding, file); WritePrivateProfileInt(L"General Settings", L"Multiple Bindings", config.multipleBinding, file);
WritePrivateProfileInt(L"General Settings", L"Save State in Title", config.saveStateTitle, file);
WritePrivateProfileInt(L"Pad1", L"Guitar", config.guitar[0], file); WritePrivateProfileInt(L"Pad1", L"Guitar", config.guitar[0], file);
WritePrivateProfileInt(L"Pad2", L"Guitar", config.guitar[1], file); WritePrivateProfileInt(L"Pad2", L"Guitar", config.guitar[1], file);
WritePrivateProfileInt(L"Pad1", L"Auto Analog", config.AutoAnalog[0], file); WritePrivateProfileInt(L"Pad1", L"Auto Analog", config.AutoAnalog[0], file);
@ -703,7 +744,9 @@ int LoadSettings(int force, wchar_t *file) {
config.gameApis.directInput = GetPrivateProfileBool(L"General Settings", L"DirectInput Game Devices", 1, file); config.gameApis.directInput = GetPrivateProfileBool(L"General Settings", L"DirectInput Game Devices", 1, file);
config.gameApis.xInput = GetPrivateProfileBool(L"General Settings", L"XInput", 1, file); config.gameApis.xInput = GetPrivateProfileBool(L"General Settings", L"XInput", 1, file);
if (pGetRawInputDeviceInfo==0) { config.saveStateTitle = GetPrivateProfileBool(L"General Settings", L"Save State in Title", 1, file);
if (!InitializeRawInput()) {
if (config.keyboardApi == RAW) config.keyboardApi = WM; if (config.keyboardApi == RAW) config.keyboardApi = WM;
if (config.mouseApi == RAW) config.mouseApi = WM; if (config.mouseApi == RAW) config.mouseApi = WM;
} }
@ -1078,7 +1121,6 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
switch (msg) { switch (msg) {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
//UnregisterDeviceNotification
ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER); ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
LVCOLUMN c; LVCOLUMN c;
c.mask = LVCF_TEXT | LVCF_WIDTH; c.mask = LVCF_TEXT | LVCF_WIDTH;
@ -1100,7 +1142,6 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
EnableWindow(GetDlgItem(hWnd, ID_IGNORE), 0); EnableWindow(GetDlgItem(hWnd, ID_IGNORE), 0);
Populate(pad); Populate(pad);
//ShowScrollBar(hWndList, SB_VERT, 1);
} }
break; break;
case WM_DEVICECHANGE: case WM_DEVICECHANGE:
@ -1116,8 +1157,6 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
EndBinding(hWnd); EndBinding(hWnd);
} }
else { else {
//int inst;
//int index;
unsigned int uid; unsigned int uid;
int value; int value;
InitInfo info = {selected==0x7F, hWndProp, hWnd, GetDlgItem(hWnd, selected)}; InitInfo info = {selected==0x7F, hWndProp, hWnd, GetDlgItem(hWnd, selected)};
@ -1242,21 +1281,17 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
switch(n->hdr.code) { switch(n->hdr.code) {
case PSN_QUERYCANCEL: case PSN_QUERYCANCEL:
case PSN_KILLACTIVE: case PSN_KILLACTIVE:
//if (selected) EndBinding(hWnd); EndBinding(hWnd);
return 0; return 0;
case PSN_SETACTIVE: case PSN_SETACTIVE:
//selected = 0;
//InitInput(GetType(), hWndProp);
return 0; return 0;
case PSN_APPLY: case PSN_APPLY:
EndBinding(hWnd);
SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_NOERROR); SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_NOERROR);
//selected = 0;
//if (SaveSettings() == -1) return 0;
return 1; return 1;
} }
} }
else if (n->hdr.idFrom == IDC_LIST) { else if (n->hdr.idFrom == IDC_LIST) {
static int NeedUpdate = 0;
if (n->hdr.code == LVN_KEYDOWN) { if (n->hdr.code == LVN_KEYDOWN) {
NMLVKEYDOWN *key = (NMLVKEYDOWN *) n; NMLVKEYDOWN *key = (NMLVKEYDOWN *) n;
if (key->wVKey == VK_DELETE || if (key->wVKey == VK_DELETE ||
@ -1266,7 +1301,15 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
PropSheet_Changed(hWndProp, hWnds[0]); PropSheet_Changed(hWndProp, hWnds[0]);
} }
} }
// Update sensitivity and motor/binding display on redraw
// rather than on itemchanged. This reduces blinking, as
// I get 3 LVN_ITEMCHANGED messages, and first is sent before
// the new item is set as being selected.
else if (n->hdr.code == LVN_ITEMCHANGED) { else if (n->hdr.code == LVN_ITEMCHANGED) {
NeedUpdate = 1;
}
else if (n->hdr.code == NM_CUSTOMDRAW && NeedUpdate) {
NeedUpdate = 0;
SelChanged(pad); SelChanged(pad);
} }
EndBinding(hWnd); EndBinding(hWnd);
@ -1383,10 +1426,15 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
dm->PostRead(); dm->PostRead();
SetTimer(hWnd, 1, 100, 0); SetTimer(hWnd, 1, 100, 0);
} }
else if (cmd == IDC_FLIP1 || cmd == IDC_TURBO) { if (cmd == IDC_TURBO) {
// Don't allow setting it back to indeterminate.
SendMessage(GetDlgItem(hWnd, IDC_TURBO), BM_SETSTYLE, BS_AUTOCHECKBOX, 0);
int turbo = (IsDlgButtonChecked(hWnd, IDC_TURBO) == BST_CHECKED); int turbo = (IsDlgButtonChecked(hWnd, IDC_TURBO) == BST_CHECKED);
ChangeValue(pad, 0, &turbo);
}
else if (cmd == IDC_FLIP1 || cmd == IDC_TURBO) {
int val = GetLogSliderVal(hWnd, IDC_SLIDER1); int val = GetLogSliderVal(hWnd, IDC_SLIDER1);
ChangeValue(pad, &val, &turbo); ChangeValue(pad, &val, 0);
} }
else if (cmd >= IDC_FF_AXIS1_ENABLED && cmd < IDC_FF_AXIS8_ENABLED + 16) { else if (cmd >= IDC_FF_AXIS1_ENABLED && cmd < IDC_FF_AXIS8_ENABLED + 16) {
int index = (cmd - IDC_FF_AXIS1_ENABLED)/16; int index = (cmd - IDC_FF_AXIS1_ENABLED)/16;
@ -1446,7 +1494,6 @@ HPROPSHEETPAGE CreateGeneralPage() {
INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam) { INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam) {
int i; int i;
//int enableAxisButtons;
switch (msg) { switch (msg) {
case WM_INITDIALOG: case WM_INITDIALOG:
{ {
@ -1476,6 +1523,7 @@ INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, L
CheckDlgButton(hWnd, IDC_DISABLE_SCREENSAVER, BST_CHECKED * config.disableScreenSaver); CheckDlgButton(hWnd, IDC_DISABLE_SCREENSAVER, BST_CHECKED * config.disableScreenSaver);
CheckDlgButton(hWnd, IDC_GH2_HACK, BST_CHECKED * config.GH2); CheckDlgButton(hWnd, IDC_GH2_HACK, BST_CHECKED * config.GH2);
CheckDlgButton(hWnd, IDC_SAVE_STATE_TITLE, BST_CHECKED * config.saveStateTitle);
CheckDlgButton(hWnd, IDC_GUITAR1, BST_CHECKED * config.guitar[0]); CheckDlgButton(hWnd, IDC_GUITAR1, BST_CHECKED * config.guitar[0]);
CheckDlgButton(hWnd, IDC_GUITAR2, BST_CHECKED * config.guitar[1]); CheckDlgButton(hWnd, IDC_GUITAR2, BST_CHECKED * config.guitar[1]);
@ -1485,13 +1533,16 @@ INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, L
CheckDlgButton(hWnd, IDC_AXIS_BUTTONS, BST_CHECKED * config.axisButtons); CheckDlgButton(hWnd, IDC_AXIS_BUTTONS, BST_CHECKED * config.axisButtons);
CheckDlgButton(hWnd, IDC_MULTIPLE_BINDING, BST_CHECKED * config.multipleBinding); CheckDlgButton(hWnd, IDC_MULTIPLE_BINDING, BST_CHECKED * config.multipleBinding);
if (config.keyboardApi < 0 || config.keyboardApi > 3) config.keyboardApi = NO_API; if (config.keyboardApi < 0 || config.keyboardApi > 3) config.keyboardApi = NO_API;
CheckRadioButton(hWnd, IDC_KB_DISABLE, IDC_KB_RAW, IDC_KB_DISABLE + config.keyboardApi); CheckRadioButton(hWnd, IDC_KB_DISABLE, IDC_KB_RAW, IDC_KB_DISABLE + config.keyboardApi);
if (config.mouseApi < 0 || config.mouseApi > 3) config.mouseApi = NO_API; if (config.mouseApi < 0 || config.mouseApi > 3) config.mouseApi = NO_API;
CheckRadioButton(hWnd, IDC_M_DISABLE, IDC_M_RAW, IDC_M_DISABLE + config.mouseApi); CheckRadioButton(hWnd, IDC_M_DISABLE, IDC_M_RAW, IDC_M_DISABLE + config.mouseApi);
CheckDlgButton(hWnd, IDC_G_DI, BST_CHECKED * config.gameApis.directInput); CheckDlgButton(hWnd, IDC_G_DI, BST_CHECKED * config.gameApis.directInput);
CheckDlgButton(hWnd, IDC_G_XI, BST_CHECKED * config.gameApis.xInput); CheckDlgButton(hWnd, IDC_G_XI, BST_CHECKED * config.gameApis.xInput);
if (pGetRawInputDeviceInfo == 0) {
if (!InitializeRawInput()) {
EnableWindow(GetDlgItem(hWnd, IDC_KB_RAW), 0); EnableWindow(GetDlgItem(hWnd, IDC_KB_RAW), 0);
EnableWindow(GetDlgItem(hWnd, IDC_M_RAW), 0); EnableWindow(GetDlgItem(hWnd, IDC_M_RAW), 0);
} }
@ -1563,6 +1614,7 @@ INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, L
config.disableScreenSaver = (IsDlgButtonChecked(hWnd, IDC_DISABLE_SCREENSAVER) == BST_CHECKED); config.disableScreenSaver = (IsDlgButtonChecked(hWnd, IDC_DISABLE_SCREENSAVER) == BST_CHECKED);
config.GH2 = (IsDlgButtonChecked(hWnd, IDC_GH2_HACK) == BST_CHECKED); config.GH2 = (IsDlgButtonChecked(hWnd, IDC_GH2_HACK) == BST_CHECKED);
config.saveStateTitle = (IsDlgButtonChecked(hWnd, IDC_SAVE_STATE_TITLE) == BST_CHECKED);
unsigned int needUpdate = 0; unsigned int needUpdate = 0;
unsigned int disablePad1New = (IsDlgButtonChecked(hWnd, IDC_DISABLE_PAD1) == BST_CHECKED); unsigned int disablePad1New = (IsDlgButtonChecked(hWnd, IDC_DISABLE_PAD1) == BST_CHECKED);
@ -1651,8 +1703,7 @@ INT_PTR CALLBACK GeneralDialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, L
switch(n->hdr.code) { switch(n->hdr.code) {
case PSN_QUERYCANCEL: case PSN_QUERYCANCEL:
case PSN_KILLACTIVE: case PSN_KILLACTIVE:
//selected = 0; EndBinding(hWnd);
//EndBinding(hWnd);
return 0; return 0;
case PSN_SETACTIVE: case PSN_SETACTIVE:
//selected = 0; //selected = 0;

View File

@ -1,18 +1,8 @@
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
typedef BOOL (CALLBACK *_RegisterRawInputDevices)(PCRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize);
typedef UINT (CALLBACK *_GetRawInputDeviceInfo)(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize);
typedef UINT (CALLBACK *_GetRawInputData)(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader);
typedef UINT (CALLBACK *_GetRawInputDeviceList)(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize);
extern _RegisterRawInputDevices pRegisterRawInputDevices;
extern _GetRawInputDeviceInfo pGetRawInputDeviceInfo;
extern _GetRawInputData pGetRawInputData;
extern _GetRawInputDeviceList pGetRawInputDeviceList;
#include "global.h"
#include "InputManager.h" #include "InputManager.h"
#include "PS2Etypes.h"
struct GeneralConfig { struct GeneralConfig {
public: public:
@ -44,6 +34,8 @@ public:
u8 guitar[2]; u8 guitar[2];
u8 AutoAnalog[2]; u8 AutoAnalog[2];
u8 saveStateTitle;
wchar_t lastSaveConfigPath[MAX_PATH+1]; wchar_t lastSaveConfigPath[MAX_PATH+1];
wchar_t lastSaveConfigFileName[MAX_PATH+1]; wchar_t lastSaveConfigFileName[MAX_PATH+1];
}; };

View File

@ -1,4 +1,4 @@
#include "global.h" #include "Global.h"
#include "DeviceEnumerator.h" #include "DeviceEnumerator.h"
#include "InputManager.h" #include "InputManager.h"
#include "WindowsMessaging.h" #include "WindowsMessaging.h"

View File

@ -4,6 +4,7 @@
#include "resource.h" #include "resource.h"
#include "KeyboardQueue.h" #include "KeyboardQueue.h"
#include <math.h> #include <math.h>
#include <commctrl.h>
Device *dev; Device *dev;

View File

@ -1,10 +1,13 @@
#include "global.h" #define DIRECTINPUT_VERSION 0x0800
#include "Global.h"
#include "VKey.h" #include "VKey.h"
#include "DirectInput.h" #include "DirectInput.h"
#include <dinput.h> #include <dinput.h>
#include "InputManager.h" #include "InputManager.h"
#include "DeviceEnumerator.h" #include "DeviceEnumerator.h"
#include "PS2Etypes.h"
#include <stdio.h>
inline static u16 flipShort(u16 s) { inline static u16 flipShort(u16 s) {
return (s>>8) | (s<<8); return (s>>8) | (s<<8);
@ -121,11 +124,7 @@ public:
DICONSTANTFORCE constant; DICONSTANTFORCE constant;
}; };
//cf.lMagnitude = 0;
//memset(&dieffect, 0, sizeof(dieffect));
dieffect.dwSize = sizeof(dieffect); dieffect.dwSize = sizeof(dieffect);
//dieffect.lpEnvelope = 0;
dieffect.dwStartDelay = 0;
dieffect.lpvTypeSpecificParams = &periodic; dieffect.lpvTypeSpecificParams = &periodic;
int magnitude = abs((int)((force*10000*(__int64)diEffects[index].scale)/BASE_SENSITIVITY/255)); int magnitude = abs((int)((force*10000*(__int64)diEffects[index].scale)/BASE_SENSITIVITY/255));
if (magnitude > 10000) magnitude = 10000; if (magnitude > 10000) magnitude = 10000;
@ -315,20 +314,6 @@ BOOL CALLBACK EnumDeviceObjectsCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOI
DirectInputDevice * did = (DirectInputDevice*) pvRef; DirectInputDevice * did = (DirectInputDevice*) pvRef;
if (lpddoi->dwType & DIDFT_FFACTUATOR) { if (lpddoi->dwType & DIDFT_FFACTUATOR) {
did->AddFFAxis(lpddoi->tszName, lpddoi->dwType); did->AddFFAxis(lpddoi->tszName, lpddoi->dwType);
/*
void * t = realloc(DI->actuators, sizeof(DIActuator) * (DI->numActuators+1));
if (t) {
DI->actuators = (DIActuator*) t;
int i = DI->numActuators;
while (i > 0 && (lpddoi->dwType & 0xFFFF00) < (DI->actuators[i-1].id & 0xFFFF00)) {
DI->actuators[i] = DI->actuators[i-1];
i--;
}
DI->actuators[i].maxForce = lpddoi->dwFFMaxForce;
DI->actuators[i].id = lpddoi->dwType;
DI->numActuators++;
}
//*/
} }
ControlType type; ControlType type;

View File

@ -1,3 +1,6 @@
// Includes Windows.h, has inlined versions of memory allocation and
// string comparison functions needed to avoid using CRT. This reduces
// dll size by over 100k while avoiding any dependencies on updated CRT dlls.
#pragma once #pragma once
#ifndef _DEBUG #ifndef _DEBUG
@ -10,66 +13,19 @@
#define UNICODE #define UNICODE
#define PADdefs
//#define SIOdefs
#define WM_XBUTTONDOWN 0x020B
#define WM_XBUTTONUP 0x020C
#define WM_XBUTTONDBLCLK 0x020D
#define XBUTTON1 0x0001
#define XBUTTON2 0x0002
#define WM_MOUSEHWHEEL 0x020E
//#define WIN32_LEAN_AND_MEAN
//#define NOGDI
#define _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE
// Actually works with 0x0400, but need this to get raw input structures. // Actually works with 0x0400, but need 0x500 to get XBUTTON defines,
#define WINVER 0x0501 // 0x501 to get raw input structures, and 0x0600 to get WM_MOUSEHWHEEL.
#define WINVER 0x0600
#define _WIN32_WINNT WINVER #define _WIN32_WINNT WINVER
#define __MSCW32__ #define __MSCW32__
#include <stdio.h>
#include <stdlib.h>
#ifdef NDEBUG
#if (_MSC_VER<1300)
#pragma comment(linker,"/RELEASE")
#pragma comment(linker,"/opt:nowin98")
#endif
#endif
#define DIRECTINPUT_VERSION 0x0800
#include <windows.h> #include <windows.h>
#include <commctrl.h>
extern HINSTANCE hInst; extern HINSTANCE hInst;
#include "resource.h"
#include "PS2Etypes.h"
/*
inline void Log(char *s) {
FILE *out2 = fopen("logs\\padLog.txt", "ab");
if (out2) {
fprintf(out2, "%s\n", s);
fclose(out2);
}
int w = GetCurrentThreadId();
char junk[1000];
sprintf(junk, "logs\\padLog%i.txt", w);
out2 = fopen(junk, "ab");
if (out2) {
fprintf(out2, "%s\n", s);
fclose(out2);
}
}
//*/
#ifdef NO_CRT #ifdef NO_CRT
inline void * malloc(size_t size) { inline void * malloc(size_t size) {
return HeapAlloc(GetProcessHeap(), 0, size); return HeapAlloc(GetProcessHeap(), 0, size);
} }
@ -105,18 +61,18 @@ inline wchar_t * __cdecl wcsdup(const wchar_t *in) {
return out; return out;
} }
__forceinline void * __cdecl operator new(size_t lSize) { inline void * __cdecl operator new(size_t lSize) {
return HeapAlloc(GetProcessHeap(), 0, lSize); return HeapAlloc(GetProcessHeap(), 0, lSize);
} }
__forceinline void __cdecl operator delete(void *pBlock) { inline void __cdecl operator delete(void *pBlock) {
HeapFree(GetProcessHeap(), 0, pBlock); HeapFree(GetProcessHeap(), 0, pBlock);
} }
#endif inline int __cdecl wcsicmp(const wchar_t *s1, const wchar_t *s2) {
__forceinline int __cdecl wcsicmp(const wchar_t *s1, const wchar_t *s2) {
int res = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, s1, -1, s2, -1); int res = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, s1, -1, s2, -1);
if (res) return res-2; if (res) return res-2;
return res; return res;
} }
#endif

View File

@ -332,18 +332,6 @@ wchar_t *Device::GetPhysicalControlName(PhysicalControl *control) {
return GetDefaultControlName(control->id, control->type); return GetDefaultControlName(control->id, control->type);
} }
/*wchar_t *Device::GetControlNameByIndex(int index) {
static wchar_t name[20];
if (type & BUTTON) {
wsprintfW(name, "Button %i", controls);
}
else if (type & AXIS) {
wsprintfW(name, "Button %i", index);
}
else return L"Unknown";
return name;
}//*/
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; devices[numDevices++] = d;

View File

@ -1,27 +1,43 @@
#include "global.h" #include "Global.h"
#include "PS2Edefs.h"
#include "Config.h"
#include <math.h> #include <math.h>
#include <Dbt.h>
#include <stdio.h>
#define PADdefs
#include "PS2Etypes.h"
#include "PS2Edefs.h"
#include "Config.h"
#include "InputManager.h" #include "InputManager.h"
#include "DeviceEnumerator.h" #include "DeviceEnumerator.h"
#include "WndProcEater.h" #include "WndProcEater.h"
#include "KeyboardQueue.h" #include "KeyboardQueue.h"
#include <Dbt.h> #include "resource.h"
// Used so don't read input and cleanup input devices at the same time. // Used to prevent reading input and cleaning up input devices at the same time.
// Only an issue when not reading input in GS thread and disabling devices due to
// lost focus.
CRITICAL_SECTION readInputCriticalSection; CRITICAL_SECTION readInputCriticalSection;
HINSTANCE hInst; HINSTANCE hInst;
HWND hWnd; HWND hWnd;
// Used to toggle mouse binding.
u8 miceEnabled; u8 miceEnabled;
// 2 when both pads are initialized, 1 for one pad, etc.
int openCount = 0; int openCount = 0;
HMODULE user32 = 0;
int activeWindow = 0; int activeWindow = 0;
int bufSize = 0;
static unsigned char outBuf[50];
static unsigned char inBuf[50];
#define MODE_DIGITAL 0x41
#define MODE_ANALOG 0x73
#define MODE_DS2_NATIVE 0x79
int IsWindowMaximized (HWND hWnd) { int IsWindowMaximized (HWND hWnd) {
RECT rect; RECT rect;
@ -42,11 +58,6 @@ int IsWindowMaximized (HWND hWnd) {
return 0; return 0;
} }
#include <stdio.h>
int bufSize = 0;
static unsigned char outBuf[50];
static unsigned char inBuf[50];
void DEBUG_NEW_SET() { void DEBUG_NEW_SET() {
if (config.debug) { if (config.debug) {
HANDLE hFile = CreateFileA("logs\\padLog.txt", GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0); HANDLE hFile = CreateFileA("logs\\padLog.txt", GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_ALWAYS, 0, 0);
@ -74,16 +85,12 @@ void DEBUG_NEW_SET() {
} }
inline void DEBUG_IN(unsigned char c) { inline void DEBUG_IN(unsigned char c) {
if (bufSize < 40) inBuf[bufSize] = c; if (bufSize < sizeof(inBuf)-1) inBuf[bufSize] = c;
} }
inline void DEBUG_OUT(unsigned char c) { inline void DEBUG_OUT(unsigned char c) {
if (bufSize < 40) outBuf[bufSize++] = c; if (bufSize < sizeof(outBuf)-1) outBuf[bufSize++] = c;
} }
#define MODE_DIGITAL 0x41
#define MODE_ANALOG 0x73
#define MODE_FULL_ANALOG 0x79
struct Stick { struct Stick {
int horiz; int horiz;
int vert; int vert;
@ -179,35 +186,14 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, void* lpvReserved) {
hInst = hInstance; hInst = hInstance;
if (fdwReason == DLL_PROCESS_ATTACH) { if (fdwReason == DLL_PROCESS_ATTACH) {
InitializeCriticalSection(&readInputCriticalSection); InitializeCriticalSection(&readInputCriticalSection);
//safeShutdown = 0;
user32 = GetModuleHandle(L"user32.dll");
if (user32) {
pRegisterRawInputDevices = (_RegisterRawInputDevices) GetProcAddress(user32, "RegisterRawInputDevices");
pGetRawInputDeviceInfo = (_GetRawInputDeviceInfo) GetProcAddress(user32, "GetRawInputDeviceInfoW");
pGetRawInputData = (_GetRawInputData) GetProcAddress(user32, "GetRawInputData");
pGetRawInputDeviceList = (_GetRawInputDeviceList) GetProcAddress(user32, "GetRawInputDeviceList");
if (!pRegisterRawInputDevices ||
!pGetRawInputDeviceInfo ||
!pGetRawInputData ||
!pGetRawInputDeviceList) {
pRegisterRawInputDevices = 0;
pGetRawInputDeviceInfo = 0;
pGetRawInputData = 0;
pGetRawInputDeviceList = 0;
}
}
DisableThreadLibraryCalls(hInstance); DisableThreadLibraryCalls(hInstance);
} }
else if (fdwReason == DLL_PROCESS_DETACH) { else if (fdwReason == DLL_PROCESS_DETACH) {
DeleteCriticalSection(&readInputCriticalSection); DeleteCriticalSection(&readInputCriticalSection);
//safeShutdown = 1;
//Sleep(20);
activeWindow = 0; activeWindow = 0;
while (openCount) while (openCount)
PADclose(); PADclose();
PADshutdown(); PADshutdown();
//CleanupInput();
} }
return 1; return 1;
} }
@ -618,8 +604,36 @@ struct QueryInfo {
u8 response[22]; u8 response[22];
} query = {0,0,0,0, 0,0xFF, 0xF3}; } query = {0,0,0,0, 0,0xFF, 0xF3};
int saveStateIndex = 0;
ExtraWndProcResult HackWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) { ExtraWndProcResult HackWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) {
switch (uMsg) { switch (uMsg) {
case WM_SETTEXT:
if (config.saveStateTitle) {
wchar_t *text;
int len;
if (IsWindowUnicode(hWnd)) {
text = wcsdup((wchar_t*) lParam);
}
else {
char *ascii = (char*) lParam;
len = (int)strlen(ascii)+1;
text = (wchar_t*) calloc(len, sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, 0, ascii, -1, text, len);
}
if (!wcsstr(text, L"State")) {
int len = wcslen(text);
if (len < 150) {
wchar_t newTitle[200];
wsprintfW(newTitle, L"%s | State %i", text, saveStateIndex);
free(text);
SetWindowText(hWnd, newTitle);
return NO_WND_PROC;
}
}
free(text);
}
break;
case WM_DEVICECHANGE: case WM_DEVICECHANGE:
if (wParam == DBT_DEVNODES_CHANGED) { if (wParam == DBT_DEVNODES_CHANGED) {
// Need to do this when not reading input from gs thread. // Need to do this when not reading input from gs thread.
@ -806,18 +820,15 @@ u8 CALLBACK PADpoll(u8 value) {
query.response[3] = b1; query.response[3] = b1;
query.response[4] = b2; query.response[4] = b2;
if (pad->mode == MODE_DIGITAL) { query.numBytes = 5;
query.numBytes = 5; if (pad->mode != MODE_DIGITAL) {
}
else {
query.response[5] = Cap((sum->sticks[1].horiz+255)/2); query.response[5] = Cap((sum->sticks[1].horiz+255)/2);
query.response[6] = Cap((sum->sticks[1].vert+255)/2); query.response[6] = Cap((sum->sticks[1].vert+255)/2);
query.response[7] = Cap((sum->sticks[2].horiz+255)/2); query.response[7] = Cap((sum->sticks[2].horiz+255)/2);
query.response[8] = Cap((sum->sticks[2].vert+255)/2); query.response[8] = Cap((sum->sticks[2].vert+255)/2);
if (pad->mode == MODE_ANALOG) {
query.numBytes = 9; query.numBytes = 9;
} if (pad->mode != MODE_ANALOG) {
else {
// Good idea? No clue. // Good idea? No clue.
//query.response[3] &= pad->mask[0]; //query.response[3] &= pad->mask[0];
//query.response[4] &= pad->mask[1]; //query.response[4] &= pad->mask[1];
@ -841,21 +852,14 @@ u8 CALLBACK PADpoll(u8 value) {
} }
query.lastByte=1; query.lastByte=1;
//if (!pad->config) { DEBUG_OUT(pad->mode);
DEBUG_OUT(pad->mode); return pad->mode;
return pad->mode;
/*}
else {
DEBUG_OUT(0xF3);
return 0xF3;
}//*/
// SET_VREF_PARAM // SET_VREF_PARAM
case 0x40: case 0x40:
SET_FINAL_RESULT(noclue); SET_FINAL_RESULT(noclue);
break; break;
// QUERY_DS2_ANALOG_MODE // QUERY_DS2_ANALOG_MODE
case 0x41: case 0x41:
//if (pad->mode == MODE_FULL_ANALOG) {
if (pad->mode == MODE_DIGITAL) { if (pad->mode == MODE_DIGITAL) {
queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0; queryMaskMode[1] = queryMaskMode[2] = queryMaskMode[3] = 0;
queryMaskMode[6] = 0x00; queryMaskMode[6] = 0x00;
@ -865,14 +869,10 @@ u8 CALLBACK PADpoll(u8 value) {
queryMaskMode[2] = pad->umask[1]; queryMaskMode[2] = pad->umask[1];
queryMaskMode[3] = 0x03; queryMaskMode[3] = 0x03;
// Not entirely sure about this. // Not entirely sure about this.
//queryMaskMode[3] = 0x01 | (pad->mode == MODE_FULL_ANALOG)*2; //queryMaskMode[3] = 0x01 | (pad->mode == MODE_DS2_NATIVE)*2;
queryMaskMode[6] = 0x5A; queryMaskMode[6] = 0x5A;
} }
SET_FINAL_RESULT(queryMaskMode); SET_FINAL_RESULT(queryMaskMode);
/*}
else {
SET_FINAL_RESULT(DSNonNativeMode);
}//*/
break; break;
// SET_MODE_AND_LOCK // SET_MODE_AND_LOCK
case 0x44: case 0x44:
@ -881,7 +881,6 @@ u8 CALLBACK PADpoll(u8 value) {
break; break;
// QUERY_MODEL_AND_MODE // QUERY_MODEL_AND_MODE
case 0x45: case 0x45:
//queryModel[1] = 3 - 2*activeConfigs[query.pad]->guitar;
if (!config.guitar[query.pad] || config.GH2) SET_FINAL_RESULT(queryModelDS2) if (!config.guitar[query.pad] || config.GH2) SET_FINAL_RESULT(queryModelDS2)
else SET_FINAL_RESULT(queryModelDS1); else SET_FINAL_RESULT(queryModelDS1);
query.response[5] = pad->mode != MODE_DIGITAL; query.response[5] = pad->mode != MODE_DIGITAL;
@ -931,10 +930,6 @@ u8 CALLBACK PADpoll(u8 value) {
// CONFIG_MODE // CONFIG_MODE
case 0x43: case 0x43:
if (query.lastByte == 3) { if (query.lastByte == 3) {
// If leaving config mode, return all 0's.
/*if (value == 0) {
SET_RESULT(setMode);
}//*/
query.queryDone = 1; query.queryDone = 1;
pad->config = value; pad->config = value;
} }
@ -1002,7 +997,7 @@ u8 CALLBACK PADpoll(u8 value) {
pad->mode = MODE_ANALOG; pad->mode = MODE_ANALOG;
} }
else { else {
pad->mode = MODE_FULL_ANALOG; pad->mode = MODE_DS2_NATIVE;
} }
} }
break; break;
@ -1060,10 +1055,24 @@ ExtraWndProcResult KillFullScreenProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
return CONTINUE_BLISSFULLY_AND_RELEASE_PROC; return CONTINUE_BLISSFULLY_AND_RELEASE_PROC;
} }
DWORD WINAPI RenameWindowThreadProc(void *lpParameter) {
wchar_t newTitle[200];
if (hWnd) {
int len = GetWindowTextW(hWnd, newTitle, 200);
if (len > 0 && len < 199) {
wchar_t *end;
if (end = wcsstr(newTitle, L" | State ")) *end = 0;
SetWindowTextW(hWnd, newTitle);
}
}
return 0;
}
keyEvent* CALLBACK PADkeyEvent() { keyEvent* CALLBACK PADkeyEvent() {
if (!config.GSThreadUpdates) { if (!config.GSThreadUpdates) {
Update(2); Update(2);
} }
static int shiftDown = 0;
static keyEvent ev; static keyEvent ev;
if (!GetQueuedKeyEvent(&ev)) return 0; if (!GetQueuedKeyEvent(&ev)) return 0;
if (ev.key == VK_ESCAPE && ev.event == KEYPRESS && config.escapeFullscreenHack) { if (ev.key == VK_ESCAPE && ev.event == KEYPRESS && config.escapeFullscreenHack) {
@ -1073,8 +1082,24 @@ keyEvent* CALLBACK PADkeyEvent() {
} }
} }
if (ev.key == VK_LSHIFT || ev.key == VK_RSHIFT) { if (ev.key == VK_F2 && ev.event == KEYPRESS) {
if (shiftDown)
saveStateIndex--;
else
saveStateIndex++;
saveStateIndex = (saveStateIndex+10)%10;
if (config.saveStateTitle) {
HANDLE hThread = CreateThread(0, 0, RenameWindowThreadProc, 0, 0, 0);
if (hThread) CloseHandle(hThread);
}
}
if (ev.key == VK_LSHIFT || ev.key == VK_RSHIFT || ev.key == VK_SHIFT) {
ev.key = VK_SHIFT; ev.key = VK_SHIFT;
if (ev.event == KEYPRESS)
shiftDown = 1;
else
shiftDown = 0;
} }
else if (ev.key == VK_LCONTROL || ev.key == VK_RCONTROL) { else if (ev.key == VK_LCONTROL || ev.key == VK_RCONTROL) {
ev.key = VK_CONTROL; ev.key = VK_CONTROL;
@ -1123,7 +1148,7 @@ char* CALLBACK PSEgetLibName() {
return PS2EgetLibName(); return PS2EgetLibName();
} }
// Littly funkiness to handle rounding floating points to ints. // Little funkiness to handle rounding floating points to ints without the C runtime.
// Unfortunately, means I can't use /GL optimization option. // Unfortunately, means I can't use /GL optimization option.
#ifdef NO_CRT #ifdef NO_CRT
extern "C" long _cdecl _ftol(); extern "C" long _cdecl _ftol();

View File

@ -268,8 +268,9 @@ BEGIN
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,247,97,10 "Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,247,97,10
CONTROL "Always hide cursor",IDC_FORCE_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,259,71,10 CONTROL "Always hide cursor",IDC_FORCE_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,259,71,10
CONTROL "Disable screensaver",IDC_DISABLE_SCREENSAVER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,271,80,10 CONTROL "Disable screensaver",IDC_DISABLE_SCREENSAVER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,224,271,80,10
CONTROL "Guitar Hero 2",IDC_GH2_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,333,223,59,10 CONTROL "Guitar Hero 2 Hack",IDC_GH2_HACK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,333,223,76,10
CONTROL "Use GS thread",IDC_GS_THREAD_INPUT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,333,235,62,10 CONTROL "Use GS thread",IDC_GS_THREAD_INPUT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,333,235,62,10
CONTROL "Save state in title",IDC_SAVE_STATE_TITLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,333,247,72,10
GROUPBOX "Debugging",IDC_STATIC,216,285,79,25 GROUPBOX "Debugging",IDC_STATIC,216,285,79,25
CONTROL "Enable logging",IDC_DEBUG_FILE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,223,296,63,10 CONTROL "Enable logging",IDC_DEBUG_FILE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,223,296,63,10
PUSHBUTTON "Save",ID_SAVE,369,295,48,15 PUSHBUTTON "Save",ID_SAVE,369,295,48,15

View File

@ -545,50 +545,6 @@
RelativePath="resource.h" RelativePath="resource.h"
> >
</File> </File>
<File
RelativePath="VKey.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
FavorSizeOrSpeed="2"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
FavorSizeOrSpeed="2"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="VKey.h"
>
</File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"
@ -726,6 +682,50 @@
RelativePath=".\InputManager.h" RelativePath=".\InputManager.h"
> >
</File> </File>
<File
RelativePath="VKey.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|x64"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
FavorSizeOrSpeed="2"
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
FavorSizeOrSpeed="2"
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="VKey.h"
>
</File>
<File <File
RelativePath=".\WndProcEater.cpp" RelativePath=".\WndProcEater.cpp"
> >

View File

@ -1,4 +1,4 @@
#include "global.h" #include "Global.h"
#include "WindowsMessaging.h" #include "WindowsMessaging.h"
#include "VKey.h" #include "VKey.h"
#include "DeviceEnumerator.h" #include "DeviceEnumerator.h"
@ -8,6 +8,16 @@
#include "Config.h" #include "Config.h"
typedef BOOL (CALLBACK *_RegisterRawInputDevices)(PCRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize);
typedef UINT (CALLBACK *_GetRawInputDeviceInfo)(HANDLE hDevice, UINT uiCommand, LPVOID pData, PUINT pcbSize);
typedef UINT (CALLBACK *_GetRawInputData)(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader);
typedef UINT (CALLBACK *_GetRawInputDeviceList)(PRAWINPUTDEVICELIST pRawInputDeviceList, PUINT puiNumDevices, UINT cbSize);
_RegisterRawInputDevices pRegisterRawInputDevices = 0;
_GetRawInputDeviceInfo pGetRawInputDeviceInfo = 0;
_GetRawInputData pGetRawInputData = 0;
_GetRawInputDeviceList pGetRawInputDeviceList = 0;
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) { int GetRawKeyboards(HWND hWnd) {
@ -122,7 +132,7 @@ public:
active = 1; active = 1;
// HAve to be careful with order. At worst, one unmatched call to ReleaseRawMice on // Have to be careful with order. At worst, one unmatched call to ReleaseRawMice on
// EatWndProc fail. In all other cases, no unmatched initialization/cleanup // EatWndProc fail. In all other cases, no unmatched initialization/cleanup
// lines. // lines.
if (!rawMouseActivatedCount++) { if (!rawMouseActivatedCount++) {
@ -163,55 +173,6 @@ public:
} }
} }
} }
/*
int Activate(void *d) {
InitInfo *info = (InitInfo*)d;
// Redundant. Should match the next line.
// Deactivate();
if (wmm) wmm->Deactivate();
HWND hWnd = info->hWnd;
if (info->hWndButton) {
hWnd = info->hWndButton;
}
if (GetFocus() != hWnd) return 0;
if (!EatWndProc(hWnd, WindowsMessagingWndProc)) {
Deactivate();
return 0;
}
SetCapture(hWnd);
ShowCursor(0);
GetCursorPos(&origCursorPos);
active = 1;
RECT r;
GetWindowRect(hWnd, &r);
ClipCursor(&r);
center.x = (r.left + r.right)/2;
center.y = (r.top + r.bottom)/2;
SetCursorPos(center.x, center.y);
wmm = this;
AllocState();
return 1;
}
void Deactivate() {
FreeState();
if (active) {
ClipCursor(0);
ReleaseCapture();
ShowCursor(1);
SetCursorPos(origCursorPos.x, origCursorPos.y);
if (!wmk)
ReleaseExtraProc(WindowsMessagingWndProc);
active = 0;
wmm = 0;
}
// hWndDlg = 0;
}//*/
}; };
ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) { ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *output) {
@ -275,9 +236,28 @@ ExtraWndProcResult RawInputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
return CONTINUE_BLISSFULLY; return CONTINUE_BLISSFULLY;
} }
int InitializeRawInput() {
static int RawInputFailed = 0;
if (RawInputFailed) return 0;
if (!pGetRawInputDeviceList) {
HMODULE user32 = LoadLibrary(L"user32.dll");
if (user32) {
if (!(pRegisterRawInputDevices = (_RegisterRawInputDevices) GetProcAddress(user32, "RegisterRawInputDevices")) ||
!(pGetRawInputDeviceInfo = (_GetRawInputDeviceInfo) GetProcAddress(user32, "GetRawInputDeviceInfoW")) ||
!(pGetRawInputData = (_GetRawInputData) GetProcAddress(user32, "GetRawInputData")) ||
!(pGetRawInputDeviceList = (_GetRawInputDeviceList) GetProcAddress(user32, "GetRawInputDeviceList"))) {
FreeLibrary(user32);
RawInputFailed = 1;
return 0;
}
}
}
return 1;
}
void EnumRawInputDevices() { void EnumRawInputDevices() {
UINT count = 0; UINT count = 0;
if (pGetRawInputDeviceList && pGetRawInputDeviceList(0, &count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1) { if (InitializeRawInput() && pGetRawInputDeviceList(0, &count, sizeof(RAWINPUTDEVICELIST)) != (UINT)-1) {
wchar_t *instanceID = (wchar_t *) malloc(41000*sizeof(wchar_t)); wchar_t *instanceID = (wchar_t *) malloc(41000*sizeof(wchar_t));
wchar_t *keyName = instanceID + 11000; wchar_t *keyName = instanceID + 11000;
wchar_t *displayName = keyName + 10000; wchar_t *displayName = keyName + 10000;

View File

@ -3,3 +3,4 @@
// Can't enumerate raw devices, can only detect them when // Can't enumerate raw devices, can only detect them when
// receiving data from them, so just use the list from before. // receiving data from them, so just use the list from before.
void EnumRawInputDevices(); void EnumRawInputDevices();
int InitializeRawInput();

View File

@ -1,215 +1,60 @@
//#include "global.h"
#include "VKey.h" #include "VKey.h"
#include "Global.h"
char *GetMouseString(unsigned char button) { #include <stdio.h>
switch(button) {
case 0x01: return "Left button";
case 0x02: return "Right button";
case 0x03: return "Middle button";
case 0x04: return "Button 4";
case 0x05: return "Button 5";
case 0x06: return "X-axis";
case 0x07: return "Y-axis";
case 0x08: return "Wheel";
case 0x09: return "Wheel 2";
default:
break;
}
static char t[8];
sprintf(t, "%i", button);
return t;
}
#ifndef MAPVK_VK_TO_VSC
#define MAPVK_VK_TO_VSC 0
#endif
wchar_t *GetVKStringW(unsigned char vk) { wchar_t *GetVKStringW(unsigned char vk) {
int flag; int flag;
static wchar_t t[20]; static wchar_t t[20];
/*
for (int i=0x90; i<0xFF; i++) {
int res = MapVirtualKey(i, MAPVK_VK_TO_VSC);
static char t[20] ={0};
static char t2[20] ={0};
if (res && (GetKeyNameText((res<<16) + (0<<24), t, 20) || GetKeyNameText((res<<16) + (0<<24), t2, 20))) {
t[19] = 0;
}
}//*/
//char *s1, *s2;
switch(vk) { switch(vk) {
//case 0x01: return L"Left button"; case 0x0C: return L"Clear";
//case 0x02: return L"Right button"; case 0x13: return L"Pause";
//case 0x03: return "Control-break";
//case 0x04: return L"Middle button";
//case 0x08: return "Backspace";
//case 0x09: return "Tab";
case 0x0C: return L"Clear";
//case 0x0D: return "Enter";
//case 0x10: return "Shift";
//case 0x11: return "Ctrl";
//case 0x12: return "Alt";
case 0x13: return L"Pause";
//case 0x14: return "Caps Lock";
//case 0x1B: return "Esc";
//case 0x20: return "Space";
case 0x21:// return "Page Up"; case 0x21:// return "Page Up";
case 0x22:// return "Page Down"; case 0x22:// return "Page Down";
case 0x23:// return "End"; case 0x23:// return "End";
case 0x24:// return "Home"; case 0x24:// return "Home";
case 0x25:// return "Left"; case 0x25:// return "Left";
case 0x26:// return "Up"; case 0x26:// return "Up";
case 0x27:// return "Right"; case 0x27:// return "Right";
case 0x28:// return "Down"; case 0x28:// return "Down";
case 0x2D:// return "Insert"; case 0x2D:// return "Insert";
case 0x2E:// return "Delete"; case 0x2E:// return "Delete";
case 0x5B:// return "Left Windows"; case 0x5B:// return "Left Windows";
case 0x5C:// return "Right Windows"; case 0x5C:// return "Right Windows";
case 0x5D:// return "Application"; case 0x5D:// return "Application";
case 0x6F:// return "Num /"; case 0x6F:// return "Num /";
flag = 1<<24; flag = 1<<24;
break; break;
case 0x29: return L"Select"; case 0x29: return L"Select";
case 0x2A: return L"Print"; case 0x2A: return L"Print";
case 0x2B: return L"Execute"; case 0x2B: return L"Execute";
case 0x2C: return L"Prnt Scrn"; case 0x2C: return L"Prnt Scrn";
case 0x2F: return L"Help"; case 0x2F: return L"Help";
/*
case 0x30: return "0";
case 0x31: return "1";
case 0x32: return "2";
case 0x33: return "3";
case 0x34: return "4";
case 0x35: return "5";
case 0x36: return "6";
case 0x37: return "7";
case 0x38: return "8";
case 0x39: return "9";
case 0x41: return "A";
case 0x42: return "B";
case 0x43: return "C";
case 0x44: return "D";
case 0x45: return "E";
case 0x46: return "F";
case 0x47: return "G";
case 0x48: return "H";
case 0x49: return "I";
case 0x4A: return "J";
case 0x4B: return "K";
case 0x4C: return "L";
case 0x4D: return "M";
case 0x4E: return "N";
case 0x4F: return "O";
case 0x50: return "P";
case 0x51: return "Q";
case 0x52: return "R";
case 0x53: return "S";
case 0x54: return "T";
case 0x55: return "U";
case 0x56: return "V";
case 0x57: return "W";
case 0x58: return "X";
case 0x59: return "Y";
case 0x5A: return "Z";
//*/
/*
case 0x60: return "Num 0";
case 0x61: return "Num 1";
case 0x62: return "Num 2";
case 0x63: return "Num 3";
case 0x64: return "Num 4";
case 0x65: return "Num 5";
case 0x66: return "Num 6";
case 0x67: return "Num 7";
case 0x68: return "Num 8";
case 0x69: return "Num 9";
//*/
//case 0x6A: return "Num Mul";
//case 0x6B: return "Num Add";
case 0x6C: return L"|";
//case 0x6D: return "Num Sub";
//case 0x6E: return "Num Del";
/*
case 0x70: return "F1";
case 0x71: return "F2";
case 0x72: return "F3";
case 0x73: return "F4";
case 0x74: return "F5";
case 0x75: return "F6";
case 0x76: return "F7";
case 0x77: return "F8";
case 0x78: return "F9";
case 0x79: return "F10";
case 0x7A: return "F11";
case 0x7B: return "F12";
case 0x7C: return "F13";
case 0x7D: return "F14";
case 0x7E: return "F15";
case 0x7F: return "F16";
case 0x80: return "F17";
case 0x81: return "F18";
case 0x82: return "F19";
case 0x83: return "F20";
case 0x84: return "F21";
case 0x85: return "F22";
case 0x86: return "F23";
case 0x87: return "F24";
//*/
//case VK_EQUALS: return "=";
case 0x90: return L"Num Lock";
//case 0x91: return "Scroll Lock";
/*
case 0xA0:
case 0xA1:
s2 = "Shift";
goto skip;
case 0xA2:
case 0xA3:
s2 = "Ctrl";
goto skip;
case 0xA4:
case 0xA5:
s2 = "Alt";
skip:
s1 = "Left";
if (vk&1) s1 = "Right";
sprintf(t, "%s %s", s1, s2);
return t;
/*/ case 0x6C: return L"|";
case 0xA0: return L"Left Shift"; case 0x90: return L"Num Lock";
case 0xA1: return L"Right Shift";
case 0xA2: return L"Left Ctrl"; case 0xA0: return L"Left Shift";
case 0xA3: return L"Right Ctrl"; case 0xA1: return L"Right Shift";
case 0xA4: return L"Left Alt"; case 0xA2: return L"Left Ctrl";
case 0xA5: return L"Right Alt"; case 0xA3: return L"Right Ctrl";
//*/ case 0xA4: return L"Left Alt";
case 0xA6: return L"Back"; case 0xA5: return L"Right Alt";
case 0xA7: return L"Forward";
case 0xA8: return L"Refresh"; case 0xA6: return L"Back";
case 0xA9: return L"Stop"; case 0xA7: return L"Forward";
case 0xAA: return L"Search"; case 0xA8: return L"Refresh";
case 0xAB: return L"Favorites"; case 0xA9: return L"Stop";
case 0xAC: return L"Browser"; case 0xAA: return L"Search";
//case 0xBA: return ":"; case 0xAB: return L"Favorites";
//case 0xBB: return "="; case 0xAC: return L"Browser";
//case 0xBC: return ",";
//case 0xBD: return "-"; case 0xFA: return L"Play";
//case 0xBE: return "."; case 0xFB: return L"Zoom";
//case 0xBF: return "/"; default:
//case 0xC0: return "`"; flag = 0;
//case 0xDB: return "["; break;
//case 0xDC: return "\\";
//case 0xDD: return "]";
//case 0xDE: return "'";
//case 0xE2: return "\\";
case 0xFA: return L"Play";
case 0xFB: return L"Zoom";
default:
flag = 0;
break;
} }
int res = MapVirtualKey(vk, MAPVK_VK_TO_VSC); int res = MapVirtualKey(vk, MAPVK_VK_TO_VSC);
if (res && GetKeyNameText((res<<16) | flag, t, 20)) { if (res && GetKeyNameText((res<<16) | flag, t, 20)) {

View File

@ -1,4 +1,2 @@
#include "global.h" // Maps virtual key codes to strings.
char *GetMouseString(unsigned char button);
wchar_t *GetVKStringW(unsigned char vk); wchar_t *GetVKStringW(unsigned char vk);

View File

@ -1,4 +1,4 @@
#include "global.h" #include "Global.h"
#include "VKey.h" #include "VKey.h"
#include "WindowsKeyboard.h" #include "WindowsKeyboard.h"
#include "KeyboardQueue.h" #include "KeyboardQueue.h"

View File

@ -1,4 +1,3 @@
#include "Global.h"
#include "InputManager.h" #include "InputManager.h"
// Shared functionality for WM and RAW keyboards. // Shared functionality for WM and RAW keyboards.

View File

@ -1,4 +1,4 @@
#include "global.h" #include "Global.h"
#include "WindowsMessaging.h" #include "WindowsMessaging.h"
#include "VKey.h" #include "VKey.h"
#include "DeviceEnumerator.h" #include "DeviceEnumerator.h"

View File

@ -1,4 +1,4 @@
#include "global.h" #include "Global.h"
#include "VKey.h" #include "VKey.h"
#include "WindowsMouse.h" #include "WindowsMouse.h"

View File

@ -1,4 +1,3 @@
#include "Global.h"
#include "InputManager.h" #include "InputManager.h"
// Shared functionality for WM and RAW keyboards. // Shared functionality for WM and RAW keyboards.

View File

@ -1,4 +1,4 @@
#include "global.h" #include "Global.h"
#include "VKey.h" #include "VKey.h"
#include "DirectInput.h" #include "DirectInput.h"
#include <xinput.h> #include <xinput.h>
@ -20,7 +20,7 @@ static int xInputActiveCount = 0;
__forceinline int ShortToAxis(int v) { __forceinline int ShortToAxis(int v) {
// If positive and at least 1 << 14, increment. // If positive and at least 1 << 14, increment.
v += (!((v>>15)&1)) & ((v>>14)&1); v += (!((v>>15)&1)) & ((v>>14)&1);
// Not just double. // Just double.
return v << 1; return v << 1;
} }
@ -44,8 +44,7 @@ public:
AddPhysicalControl(PSHBTN, i + 2*(i > 9), 0); AddPhysicalControl(PSHBTN, i + 2*(i > 9), 0);
} }
for (; i<20; i++) { for (; i<20; i++) {
// The i > 9 accounts for the 2 bit skip in button flags. AddPhysicalControl(ABSAXIS, i + 2, 0);
AddPhysicalControl(ABSAXIS, i + 2*(i > 9), 0);
} }
AddFFAxis(L"Slow Motor", 0); AddFFAxis(L"Slow Motor", 0);
AddFFAxis(L"Fast Motor", 1); AddFFAxis(L"Fast Motor", 1);
@ -96,7 +95,6 @@ public:
int Update() { int Update() {
if (!active) return 0; if (!active) return 0;
XINPUT_STATE state; XINPUT_STATE state;
// memset(&state, 0, sizeof(state));
if (ERROR_SUCCESS != pXInputGetState(index, &state)) { if (ERROR_SUCCESS != pXInputGetState(index, &state)) {
Deactivate(); Deactivate();
return 0; return 0;
@ -107,12 +105,6 @@ public:
} }
physicalControlState[14] = (((int)state.Gamepad.bLeftTrigger) + (state.Gamepad.bLeftTrigger>>7)) << 8; physicalControlState[14] = (((int)state.Gamepad.bLeftTrigger) + (state.Gamepad.bLeftTrigger>>7)) << 8;
physicalControlState[15] = (((int)state.Gamepad.bRightTrigger) + (state.Gamepad.bRightTrigger>>7)) << 8; physicalControlState[15] = (((int)state.Gamepad.bRightTrigger) + (state.Gamepad.bRightTrigger>>7)) << 8;
/*
state.Gamepad.sThumbLX = 0x8000;
state.Gamepad.sThumbLY = 0x7FFF;
state.Gamepad.sThumbRX = 0x3FFF;
state.Gamepad.sThumbRY = 0;
/*/
physicalControlState[16] = ShortToAxis(state.Gamepad.sThumbLX); physicalControlState[16] = ShortToAxis(state.Gamepad.sThumbLX);
physicalControlState[17] = ShortToAxis(state.Gamepad.sThumbLY); physicalControlState[17] = ShortToAxis(state.Gamepad.sThumbLY);
physicalControlState[18] = ShortToAxis(state.Gamepad.sThumbRX); physicalControlState[18] = ShortToAxis(state.Gamepad.sThumbRX);
@ -126,8 +118,9 @@ public:
for (int p=0; p<2; p++) { for (int p=0; p<2; p++) {
for (int i=0; i<pads[p].numFFBindings; i++) { for (int i=0; i<pads[p].numFFBindings; i++) {
// Technically should also be a *65535/BASE_SENSITIVITY, but that's close enough to 1 for me. // Technically should also be a *65535/BASE_SENSITIVITY, but that's close enough to 1 for me.
newVibration[0] += (int)((pads[p].ffBindings[i].axes[0].force * (__int64)ps2Vibration[p][pads[p].ffBindings[i].motor]) / 255); ForceFeedbackBinding *ffb = &pads[p].ffBindings[i];
newVibration[1] += (int)((pads[p].ffBindings[i].axes[1].force * (__int64)ps2Vibration[p][pads[p].ffBindings[i].motor]) / 255); newVibration[0] += (int)((ffb->axes[0].force * (__int64)ps2Vibration[p][ffb->motor]) / 255);
newVibration[1] += (int)((ffb->axes[1].force * (__int64)ps2Vibration[p][ffb->motor]) / 255);
} }
} }
newVibration[0] = abs(newVibration[0]); newVibration[0] = abs(newVibration[0]);
@ -147,15 +140,11 @@ public:
} }
void SetEffect(ForceFeedbackBinding *binding, unsigned char force) { void SetEffect(ForceFeedbackBinding *binding, unsigned char force) {
PadBindings p[2]; PadBindings pBackup = pads[0];
p[0] = pads[0];
p[1] = pads[1];
pads[0].ffBindings = binding; pads[0].ffBindings = binding;
pads[0].numFFBindings = 1; pads[0].numFFBindings = 1;
pads[1].numFFBindings = 0;
SetEffects(0, binding->motor, 255); SetEffects(0, binding->motor, 255);
pads[0] = p[0]; pads[0] = pBackup;
pads[1] = p[1];
} }
void Deactivate() { void Deactivate() {

View File

@ -45,6 +45,8 @@
#define IDC_DISABLE_SCREENSAVER4 1127 #define IDC_DISABLE_SCREENSAVER4 1127
#define IDC_FORCEFEEDBACK_HACK2 1127 #define IDC_FORCEFEEDBACK_HACK2 1127
#define IDC_GS_THREAD_INPUT 1128 #define IDC_GS_THREAD_INPUT 1128
#define IDC_GS_THREAD_INPUT2 1129
#define IDC_SAVE_STATE_TITLE 1129
#define IDC_SLIDER1 0x1000 #define IDC_SLIDER1 0x1000
#define IDC_FLIP1 0x1001 #define IDC_FLIP1 0x1001
#define IDC_AXIS1 0x1002 #define IDC_AXIS1 0x1002
@ -53,9 +55,9 @@
#define IDC_TURBO 0x1005 #define IDC_TURBO 0x1005
#define IDC_AXIS_DEVICE1 0x1006 #define IDC_AXIS_DEVICE1 0x1006
#define ID_SENSITIVITY 0x1007 #define ID_SENSITIVITY 0x1007
#define ID_DPAD 0x1008 #define ID_DPAD 0x1008
#define ID_LSTICK 0x1009 #define ID_LSTICK 0x1009
#define ID_RSTICK 0x100A #define ID_RSTICK 0x100A
#define ID_GUITAR_HERO 0x10FB #define ID_GUITAR_HERO 0x10FB
#define ID_LOCK_BUTTONS 0x10FC #define ID_LOCK_BUTTONS 0x10FC
#define ID_LOCK 0x10FD #define ID_LOCK 0x10FD