Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

277 lines
9.4 KiB

  1. #include "common.hpp"
  2. #define TOW(a) L##a
  3. static const GUID g_AppGuid =
  4. { 0x238d8220, 0x7a5d, 0x11d3, { 0x8f, 0xb2, 0x0, 0xc0, 0x4f, 0x8e, 0xc6, 0x27 } };
  5. static const GUID GUID_DIConfigAppEditLayout =
  6. { 0xfd4ace13, 0x7044, 0x4204, { 0x8b, 0x15, 0x9, 0x52, 0x86, 0xb1, 0x2e, 0xad } };
  7. //for axes commands: AXIS_LR and AXIS_UD
  8. #define AXIS_MASK 0x80000000l
  9. #define AXIS_LR (AXIS_MASK | 1)
  10. #define AXIS_UD (AXIS_MASK | 2)
  11. // "Keyboard" commands
  12. #define KEY_STOP 0x00000001l
  13. #define KEY_DOWN 0x00000002l
  14. #define KEY_LEFT 0x00000004l
  15. #define KEY_RIGHT 0x00000008l
  16. #define KEY_UP 0x00000010l
  17. #define KEY_FIRE 0x00000020l
  18. #define KEY_THROW 0x00000040l
  19. #define KEY_SHIELD 0x00000080l
  20. #define KEY_DISPLAY 0x00000100l
  21. #define KEY_QUIT 0x00000200l
  22. #define KEY_EDIT 0x00000400l
  23. DIACTIONFORMATW *GetTestActionFormats()
  24. {
  25. static DIACTIONW g_rgGameAction1[] = {
  26. {AXIS_UD, DIAXIS_FPS_MOVE, 0, TOW("Forward"),},
  27. {AXIS_LR, DIAXIS_FPS_ROTATE, 0, TOW("Rotate"),},
  28. {KEY_FIRE, DIBUTTON_FPS_FIRE, 0, TOW("Fire"),},
  29. {KEY_THROW, DIBUTTON_FPS_WEAPONS, 0, TOW("Change Weapon"),},
  30. {KEY_SHIELD, DIBUTTON_FPS_APPLY, 0, TOW("Shield"),},
  31. {KEY_STOP, DIBUTTON_FPS_SELECT, 0, TOW("Pause"),},
  32. {KEY_THROW, DIBUTTON_FPS_CROUCH, 0, TOW("Hyper space"),},
  33. {KEY_THROW, DIBUTTON_FPS_JUMP, 0, TOW("Launch Probe"),},
  34. {KEY_DISPLAY,DIBUTTON_FPS_DISPLAY, 0, TOW("Display"),},
  35. {KEY_QUIT, DIBUTTON_FPS_MENU, 0, TOW("Quit Game"),},
  36. {KEY_EDIT, DIBUTTON_FPS_DODGE, 0, TOW("Edit Configuration"),},
  37. {KEY_LEFT, DIKEYBOARD_LEFT, 0, TOW("Turn +"),},
  38. {KEY_RIGHT, DIKEYBOARD_RIGHT, 0, TOW("Turn -"),},
  39. {KEY_UP, DIKEYBOARD_UP, 0, TOW("Move Up"),},
  40. {KEY_DOWN, DIKEYBOARD_DOWN, 0, TOW("Move Down"),},
  41. {KEY_STOP, DIKEYBOARD_S, 0, TOW("Stop Game"),},
  42. {KEY_FIRE, DIKEYBOARD_SPACE, 0, TOW("Shoot"),},
  43. {KEY_THROW, DIKEYBOARD_T, 0, TOW("Throw"),},
  44. {KEY_SHIELD, DIKEYBOARD_H, 0, TOW("Shield"),},
  45. {KEY_DISPLAY,DIKEYBOARD_D, 0, TOW("Display"),},
  46. {KEY_QUIT, DIKEYBOARD_Q, 0, TOW("Quit Game"),},
  47. {KEY_EDIT, DIKEYBOARD_E, 0, TOW("Edit Configuration"),},
  48. {AXIS_LR, DIMOUSE_XAXIS, 0, TOW("Turn"), },
  49. {AXIS_UD, DIMOUSE_YAXIS, 0, TOW("Move"), },
  50. {KEY_FIRE, DIMOUSE_BUTTON0, 0, TOW("Fire"), },
  51. {KEY_SHIELD, DIMOUSE_BUTTON1, 0, TOW("Shield"),},
  52. {KEY_THROW, DIMOUSE_BUTTON2, 0, TOW("Change Weapon"),},
  53. };
  54. const int g_nGameActions1 = sizeof(g_rgGameAction1) / sizeof(DIACTIONW);
  55. static DIACTIONW g_rgGameAction2[] = {
  56. {AXIS_UD, DIAXIS_FPS_MOVE, 0, TOW("FORWARD"),},
  57. {AXIS_LR, DIAXIS_FPS_ROTATE, 0, TOW("ROTATE"),},
  58. {KEY_FIRE, DIBUTTON_FPS_FIRE, 0, TOW("FIRE"),},
  59. {KEY_SHIELD, DIBUTTON_FPS_APPLY, 0, TOW("SHIELD"),},
  60. {KEY_STOP, DIBUTTON_FPS_SELECT, 0, TOW("PAUSE"),},
  61. {KEY_DISPLAY,DIBUTTON_FPS_DISPLAY, 0, TOW("DISPLAY"),},
  62. {KEY_QUIT, DIBUTTON_FPS_MENU, 0, TOW("QUIT GAME"),},
  63. {KEY_EDIT, DIBUTTON_FPS_DODGE, 0, TOW("EDIT CONFIGURATION"),},
  64. {KEY_LEFT, DIKEYBOARD_LEFT, 0, TOW("TURN +"),},
  65. {KEY_RIGHT, DIKEYBOARD_RIGHT, 0, TOW("TURN -"),},
  66. {KEY_UP, DIKEYBOARD_UP, 0, TOW("MOVE UP"),},
  67. {KEY_DOWN, DIKEYBOARD_DOWN, 0, TOW("MOVE DOWN"),},
  68. {KEY_STOP, DIKEYBOARD_S, 0, TOW("STOP GAME"),},
  69. {KEY_FIRE, DIKEYBOARD_SPACE, 0, TOW("SHOOT"),},
  70. {KEY_SHIELD, DIKEYBOARD_H, 0, TOW("SHIELD"),},
  71. {KEY_DISPLAY,DIKEYBOARD_D, 0, TOW("DISPLAY"),},
  72. {KEY_QUIT, DIKEYBOARD_Q, 0, TOW("QUIT GAME"),},
  73. {KEY_EDIT, DIKEYBOARD_E, 0, TOW("EDIT CONFIGURATION"),},
  74. {AXIS_LR, DIMOUSE_XAXIS, 0, TOW("TURN"), },
  75. {AXIS_UD, DIMOUSE_YAXIS, 0, TOW("MOVE"), },
  76. {KEY_FIRE, DIMOUSE_BUTTON0, 0, TOW("FIRE"), },
  77. {KEY_SHIELD, DIMOUSE_BUTTON1, 0, TOW("SHIELD"),},
  78. };
  79. const int g_nGameActions2 = sizeof(g_rgGameAction2) / sizeof(DIACTIONW);
  80. static DIACTIONW g_rgGameAction3[] = {
  81. {AXIS_UD, DIAXIS_FPS_MOVE, 0, TOW("Forward"),},
  82. {AXIS_LR, DIAXIS_FPS_ROTATE, 0, TOW("Rotate"),},
  83. {KEY_FIRE, DIBUTTON_FPS_FIRE, 0, TOW("Fire"),},
  84. {KEY_SHIELD, DIBUTTON_FPS_APPLY, 0, TOW("Shield"),},
  85. {KEY_STOP, DIBUTTON_FPS_SELECT, 0, TOW("PausePausePausePausePausePausePausePausePausePausePausePausePausePausePausePause"),},
  86. {KEY_DISPLAY,DIBUTTON_FPS_DISPLAY, 0, TOW("Display"),},
  87. {KEY_QUIT, DIBUTTON_FPS_MENU, 0, TOW("Quit Game"),},
  88. {KEY_LEFT, DIKEYBOARD_LEFT, 0, TOW("Turn +"),},
  89. {KEY_RIGHT, DIKEYBOARD_RIGHT, 0, TOW("Turn -"),},
  90. {KEY_UP, DIKEYBOARD_UP, 0, TOW("Move Up"),},
  91. {KEY_DOWN, DIKEYBOARD_DOWN, 0, TOW("Move Down"),},
  92. {KEY_STOP, DIKEYBOARD_S, 0, TOW("Stop Game"),},
  93. {KEY_FIRE, DIKEYBOARD_SPACE, 0, TOW("Shoot"),},
  94. {KEY_SHIELD, DIKEYBOARD_H, 0, TOW("Shield"),},
  95. {KEY_DISPLAY,DIKEYBOARD_D, 0, TOW("Display"),},
  96. {KEY_QUIT, DIKEYBOARD_Q, 0, TOW("Quit Game"),},
  97. {AXIS_LR, DIMOUSE_XAXIS, 0, TOW("Turn"), },
  98. {AXIS_UD, DIMOUSE_YAXIS, 0, TOW("Move"), },
  99. {KEY_FIRE, DIMOUSE_BUTTON0, 0, TOW("Fire"), },
  100. {KEY_SHIELD, DIMOUSE_BUTTON1, 0, TOW("Shield"),},
  101. };
  102. const int g_nGameActions3 = sizeof(g_rgGameAction3) / sizeof(DIACTIONW);
  103. static struct _ACTIONARRAYELEMENT {
  104. DIACTIONW *rgActions;
  105. int nActions;
  106. LPCWSTR name;
  107. } g_rgActionArray[] = {
  108. {g_rgGameAction1, g_nGameActions1, TOW("Genre 1")},
  109. {g_rgGameAction2, g_nGameActions2, TOW("Genre 2")},
  110. {g_rgGameAction3, g_nGameActions3, TOW("Genre 3")},
  111. };
  112. const int g_nActionArrays = sizeof(g_rgActionArray) / sizeof(_ACTIONARRAYELEMENT);
  113. const int nMaxFormats = g_nActionArrays;
  114. static DIACTIONFORMATW af[nMaxFormats];
  115. for (int i = 0; i < nMaxFormats; i++)
  116. {
  117. ZeroMemory(&(af[i]), sizeof(DIACTIONFORMATW));
  118. af[i].dwSize = sizeof(DIACTIONFORMATW);
  119. af[i].dwActionSize = sizeof(DIACTIONW);
  120. wcscpy(af[i].tszActionMap, g_rgActionArray[i].name);
  121. af[i].guidActionMap = g_AppGuid;
  122. af[i].dwGenre = DIVIRTUAL_FIGHTING_FPS;
  123. af[i].dwNumActions = (DWORD)g_rgActionArray[i].nActions;
  124. af[i].dwDataSize = af[i].dwNumActions * sizeof(DWORD);
  125. af[i].rgoAction = g_rgActionArray[i].rgActions;
  126. af[i].lAxisMin = -100;
  127. af[i].lAxisMax = 100;
  128. af[i].dwBufferSize = 16;
  129. }
  130. return af;
  131. }
  132. HRESULT RunDFTest(LPTESTCONFIGUIPARAMS params)
  133. {
  134. if (params == NULL || params->dwSize != sizeof(TESTCONFIGUIPARAMS))
  135. return E_INVALIDARG;
  136. HRESULT ret_hr = S_OK;
  137. HINSTANCE hInstance = GetModuleHandle(0);
  138. LPWSTR wszUserNames = NULL;
  139. DICONFIGUREDEVICESPARAMSW p;
  140. DWORD dwFlags = 0;
  141. #define FAIL(e,s) \
  142. { \
  143. CopyStr(params->wszErrorText, s, MAX_PATH); \
  144. ret_hr = e; \
  145. goto cleanup; \
  146. }
  147. if (params->eDisplay != TUI_DISPLAY_GDI)
  148. FAIL(E_NOTIMPL, "Only display type GDI is implemented.");
  149. if (params->nNumAcFors < 1 || params->nNumAcFors > 3)
  150. FAIL(E_INVALIDARG, "Only 1 to 3 Action Formats supported.");
  151. switch (params->eConfigType)
  152. {
  153. case TUI_CONFIGTYPE_VIEW:
  154. dwFlags |= DICD_DEFAULT;
  155. break;
  156. case TUI_CONFIGTYPE_EDIT:
  157. dwFlags |= DICD_EDIT;
  158. break;
  159. default:
  160. FAIL(E_INVALIDARG, "Unknown ConfigType.");
  161. }
  162. ZeroMemory(&p, sizeof(DICONFIGUREDEVICESPARAMSW));
  163. p.dwSize = sizeof(DICONFIGUREDEVICESPARAMSW);
  164. ZeroMemory(&p.dics, sizeof(DICOLORSET));
  165. p.dics.dwSize = sizeof(DICOLORSET);
  166. switch (params->nColorScheme)
  167. {
  168. case 1:
  169. p.dics.cTextFore = ((D3DCOLOR)RGB(255,255,255));
  170. p.dics.cTextHighlight = ((D3DCOLOR)RGB(255,150,255));
  171. p.dics.cCalloutLine = ((D3DCOLOR)RGB(191,191,0));
  172. p.dics.cCalloutHighlight = ((D3DCOLOR)RGB(255,255,0));
  173. p.dics.cBorder = ((D3DCOLOR)RGB(0,0,191));
  174. p.dics.cControlFill = ((D3DCOLOR)RGB(0,127,255));
  175. p.dics.cHighlightFill = ((D3DCOLOR)RGB(0,0,100));
  176. p.dics.cAreaFill = ((D3DCOLOR)RGB(0,0,0));
  177. break;
  178. }
  179. if (params->lpwszUserNames != NULL)
  180. {
  181. p.dwcUsers = CountSubStrings(params->lpwszUserNames);
  182. if (p.dwcUsers >= 1)
  183. wszUserNames = DupSuperString(params->lpwszUserNames);
  184. }
  185. else
  186. p.dwcUsers = 0;
  187. p.lptszUserNames = wszUserNames;
  188. p.dwcFormats = (DWORD)params->nNumAcFors;
  189. p.lprgFormats = GetTestActionFormats();
  190. if (params->bEditLayout)
  191. p.lprgFormats[0].guidActionMap = GUID_DIConfigAppEditLayout;
  192. p.hwnd = NULL;
  193. //p.dics = ;
  194. p.lpUnkDDSTarget = NULL;
  195. switch (params->eVia)
  196. {
  197. case TUI_VIA_DI:
  198. {
  199. //set up DInput and call ConfigureDevices
  200. IDirectInput8W* pDInput = NULL;
  201. DWORD dwVer = DIRECTINPUT_VERSION;
  202. HRESULT hres = DirectInput8Create(hInstance, dwVer, IID_IDirectInput8W, (LPVOID *)&pDInput, NULL);
  203. if (FAILED(hres))
  204. FAIL(hres, "DirectInput8Create() failed.");
  205. hres = pDInput->ConfigureDevices(NULL, &p, dwFlags, NULL);
  206. pDInput->Release();
  207. if (FAILED(hres))
  208. FAIL(hres, "ConfigureDevices() failed.");
  209. break;
  210. }
  211. case TUI_VIA_CCI:
  212. {
  213. IDirectInputActionFramework* pIFrame = NULL;
  214. HINSTANCE hInst = NULL;
  215. HRESULT hres = PrivCreateInstance(CLSID_CDirectInputActionFramework, NULL, CLSCTX_INPROC_SERVER, IID_IDIActionFramework, (LPVOID*)&pIFrame, &hInst);
  216. if (FAILED(hres))
  217. FAIL(hres, "PrivCreateInstance() failed.");
  218. hres = pIFrame->ConfigureDevices(NULL, &p, dwFlags, NULL);
  219. pIFrame->Release();
  220. if (hInst != NULL)
  221. FreeLibrary(hInst);
  222. hInst = NULL;
  223. if (FAILED(hres))
  224. FAIL(hres, "ConfigureDevices() failed.");
  225. break;
  226. }
  227. default:
  228. FAIL(E_INVALIDARG, "Unknown Via type.");
  229. }
  230. cleanup:
  231. if (wszUserNames != NULL)
  232. free(wszUserNames);
  233. wszUserNames = NULL;
  234. return ret_hr;
  235. }