Hi Guys,
I am stuck by one issue again. Can anyone shed me a light on it? Please take a look at the following breakdown.
-
Hook the API DirectInput8Create to create the my own object CXGLDirectInput8W. My target game now is GTA5. I'm pretty sure that the game is using the UNICODE version.
hr = pDInputHook->DirectInput8Create(hInst, dwVersion, riidltf, ppvOut, punkOuter);
if (SUCCEEDED(hr) && ppvOut && *ppvOut)
{
if (riidltf == IID_IDirectInput8A)
{
XGLLog(L"ANSI version interface");
}
else if (riidltf == IID_IDirectInput8W)
{
XGLLog(L"UNICODE version interface");
*ppvOut = new CXGLDirectInput8W(reinterpret_cast<LPDIRECTINPUT8W>(*ppvOut));
}
else
{
XGLLog(L"The request IID isn't supported yet!");
}
}
2. Pass through all other callings of the class method except the method EnumDevices and CreateDevice. Implement the method EnumDevices to record all the enumerated devices instance into a vector and add a fake xbox 360 controller to the enumeration callback function. Implement the method CreateDevice to exclude those recorded device instances except the fake xbox 360 controller. Since now on, the fake xbox 360 controller takes over all the calling of the game.
if (IsEqualGUID(rguid, XGL_GUID_INSTANCE_SIM) == TRUE)
{
*device = new CXGLDirectInputDevice8W;
hr = DI_OK;
}
3. Implement all the methods of the class CXGLDirectInputDevice8W that the game calls. The following piece is extracted from the log file.
[3484 2268]<<CXGLDInputImpl::DirectInput8Create - hr:0x0
[3484 2268]CXGLDirectInput8W::AddRef
[3484 2268]CXGLDirectInput8W::CreateDevice - guid:{6F1D2B61-D5A0-11CF-BFC7-444553540000}
[3484 2268]>>CXGLRawInputImpl::RegisterRawInputDevices - number:1 size:16
[3484 2268][0]- page:0x1, usage:0x6, flags:0x100, hwnd:0x0000000000010562
[3484 2268]<<CXGLRawInputImpl::RegisterRawInputDevices - bRetVal:1
[3484 2268]CXGLDirectInput8W::EnumDevices - devType:0x4, flags:0x1
[3484 2268]CXGLDirectInput8W::CreateDevice - guid:{F46EFEB8-86FE-4478-872D-8868EA20FB42}
[3484 2268]CXGLDirectInputDevice8W::CXGLDirectInputDevice8W - 0x0000000000000000
[3484 2268]CXGLDirectInputDevice8W::QueryInterface - guid:{54D41081-DC15-4833-A41B-748F73A38179}
[3484 2268]CXGLDirectInputDevice8W::AddRef - count:2
[3484 2268]CXGLDirectInputDevice8W::Release - count:1
[3484 2268]CXGLDirectInputDevice8W::GetDeviceInfo
[3484 2268]>>CXGLDirectInputDevice8W::EnumObjects - flags:0x0
[3484 2268]>>CXGLDirectInputDevice8W::GetProperty - property:4
[3484 2268]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::GetProperty - property:4
[3484 2268]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::GetProperty - property:4
[3484 2268]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::GetProperty - property:4
[3484 2268]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::GetProperty - property:4
[3484 2268]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[3484 2268]<<CXGLDirectInputDevice8W::EnumObjects - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::EnumObjects - flags:0x3
[3484 2268]<<CXGLDirectInputDevice8W::EnumObjects - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::SetDataFormat
[3484 2268]<<CXGLDirectInputDevice8W::SetDataFormat - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::SetCooperativeLevel - HWND:0x0000000000020548 level:0x5
[3484 2268]<<CXGLDirectInputDevice8W::SetCooperativeLevel - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::GetCapabilities
[3484 2268]size:24, axes:0, buttons:0, type:0x0, ffdv:0x447886fe, ffmtr:0xcccccccc, ffsp:0xcccccccc, fmv:0x44c, flags:0x0, hwr:0xf46efeb8, pov:0
[3484 2268]<<CXGLDirectInputDevice8W::GetCapabilities - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::Acquire
[3484 2268]<<CXGLDirectInputDevice8W::Acquire - hr:0x0
[3484 2268]>>CXGLDirectInputDevice8W::Poll
[3484 2268]<<CXGLDirectInputDevice8W::Poll - hr:0x1
[3484 2268]>>CXGLDirectInputDevice8W::GetDeviceState - size:272
[3484 2268]<<CXGLDirectInputDevice8W::GetDeviceState - hr:0x0
4. Everything seems to work now except that the game never calls the hooked XInput APIs. Using the real Xbox 360 controller, it shows the similar log but it calls the hooked XInput APIs. The following piece is extracted from the log of the real Xbox 360 controller. Why???
[4476 4820]UNICODE version interface
[4476 4820]CXGLDirectInput8W::CXGLDirectInput8W
[4476 4820]<<CXGLDInputImpl::DirectInput8Create - hr:0x0
[4476] [4476 4820]CXGLDirectInput8W::AddRef
[4476] [4476 4820]CXGLDirectInput8W::CreateDevice - guid:{6F1D2B61-D5A0-11CF-BFC7-444553540000}
[4476 4820]CXGLDirectInput8W::EnumDevices - devType:0x4, flags:0x1
[4476 4820]CXGLDirectInput8W::CreateDevice - guid:{1AF440E0-DBD9-11E6-8001-444553540000}
[4476 4820]CXGLDirectInputDevice8W::CXGLDirectInputDevice8W - 0x00000000518F8958
[4476 4820]CXGLDirectInputDevice8W::QueryInterface - guid:{54D41081-DC15-4833-A41B-748F73A38179}
[4476 4820]CXGLDirectInputDevice8W::Release - count:1
[4476 4820]CXGLDirectInputDevice8W::GetDeviceInfo
[4476 4820]>>CXGLDirectInputDevice8W::EnumObjects - flags:0x0
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:0, type:258, guid:{A36D02E1-C9F3-11CF-BFC7-444553540000}, name:Y Axis, col:1, index:0, exp:0, reportid:0, usage:0x31, page:0x1
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]size:24, header:16, obj:0x102, how:0x2, min:0, max:65535
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:4, type:2, guid:{A36D02E0-C9F3-11CF-BFC7-444553540000}, name:X Axis, col:1, index:0, exp:0, reportid:0, usage:0x30, page:0x1
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]size:24, header:16, obj:0x2, how:0x2, min:0, max:65535
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:8, type:1026, guid:{A36D02F5-C9F3-11CF-BFC7-444553540000}, name:Y Rotation, col:2, index:0, exp:0, reportid:0, usage:0x34, page:0x1
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]size:24, header:16, obj:0x402, how:0x2, min:0, max:65535
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:12, type:770, guid:{A36D02F4-C9F3-11CF-BFC7-444553540000}, name:X Rotation, col:2, index:0, exp:0, reportid:0, usage:0x33, page:0x1
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]size:24, header:16, obj:0x302, how:0x2, min:0, max:65535
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:16, type:514, guid:{A36D02E2-C9F3-11CF-BFC7-444553540000}, name:Z Axis, col:3, index:0, exp:0, reportid:0, usage:0x32, page:0x1
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]size:24, header:16, obj:0x202, how:0x2, min:0, max:65535
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:24, type:4, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 0, col:0, index:0, exp:0, reportid:0, usage:0x1, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:25, type:260, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 1, col:0, index:0, exp:0, reportid:0, usage:0x2, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:26, type:516, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 2, col:0, index:0, exp:0, reportid:0, usage:0x3, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:27, type:772, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 3, col:0, index:0, exp:0, reportid:0, usage:0x4, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:28, type:1028, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 4, col:0, index:0, exp:0, reportid:0, usage:0x5, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:29, type:1284, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 5, col:0, index:0, exp:0, reportid:0, usage:0x6, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:30, type:1540, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 6, col:0, index:0, exp:0, reportid:0, usage:0x7, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:31, type:1796, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 7, col:0, index:0, exp:0, reportid:0, usage:0x8, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:32, type:2052, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 8, col:0, index:0, exp:0, reportid:0, usage:0x9, page:0x9
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:33, type:2308, guid:{A36D02F0-C9F3-11CF-BFC7-444553540000}, name:Button 9, col:0, index:0, exp:0, reportid:0, usage:0xa, page:0x9
[4476 4820]size:576, dim:14, fffr:0, ffmf:0, flags:0, ofs:20, type:16, guid:{A36D02F2-C9F3-11CF-BFC7-444553540000}, name:Hat Switch, col:0, index:0, exp:0, reportid:0, usage:0x39, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:0, type:192, guid:{A36D02F3-C9F3-11CF-BFC7-444553540000}, name:Collection 0 - Game Pad, col:0, index:0, exp:0, reportid:0, usage:0x5, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:0, type:448, guid:{A36D02F3-C9F3-11CF-BFC7-444553540000}, name:Collection 1, col:0, index:0, exp:0, reportid:0, usage:0x0, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:0, type:704, guid:{A36D02F3-C9F3-11CF-BFC7-444553540000}, name:Collection 2, col:0, index:0, exp:0, reportid:0, usage:0x0, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:0, ofs:0, type:960, guid:{A36D02F3-C9F3-11CF-BFC7-444553540000}, name:Collection 3, col:0, index:0, exp:0, reportid:0, usage:0x0, page:0x1
[4476 4820]<<CXGLDirectInputDevice8W::EnumObjects - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::EnumObjects - flags:0x3
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:0, type:258, guid:{A36D02E1-C9F3-11CF-BFC7-444553540000}, name:Y Axis, col:1, index:0, exp:0, reportid:0, usage:0x31, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:4, type:2, guid:{A36D02E0-C9F3-11CF-BFC7-444553540000}, name:X Axis, col:1, index:0, exp:0, reportid:0, usage:0x30, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:8, type:1026, guid:{A36D02F5-C9F3-11CF-BFC7-444553540000}, name:Y Rotation, col:2, index:0, exp:0, reportid:0, usage:0x34, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:12, type:770, guid:{A36D02F4-C9F3-11CF-BFC7-444553540000}, name:X Rotation, col:2, index:0, exp:0, reportid:0, usage:0x33, page:0x1
[4476 4820]size:576, dim:0, fffr:0, ffmf:0, flags:256, ofs:16, type:514, guid:{A36D02E2-C9F3-11CF-BFC7-444553540000}, name:Z Axis, col:3, index:0, exp:0, reportid:0, usage:0x32, page:0x1
[4476 4820]<<CXGLDirectInputDevice8W::EnumObjects - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::SetDataFormat
[4476 4820]<<CXGLDirectInputDevice8W::SetDataFormat - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::SetCooperativeLevel - HWND:0x000000000004055A level:0x5
[4476 4820]>>CXGLDirectInputDevice8W::GetCapabilities
[4476 4820]size:24, axes:5, buttons:10, type:0x10215, ffdv:0x11e6dbd9, ffmtr:0x7fe, ffsp:0xe9454965, fmv:0x44c, flags:0x5, hwr:0x1af440e0, pov:1
[4476 4820]<<CXGLDirectInputDevice8W::GetCapabilities - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::Acquire
[4476 4820]<<CXGLDirectInputDevice8W::Acquire - hr:0x80070005
[4476 4820]CXGLDirectInput8W::CreateDevice - guid:{F46EFEB8-86FE-4478-872D-8868EA20FB42}
[4476 4820]CXGLDirectInputDevice8W::CXGLDirectInputDevice8W - 0x0000000000000000
[4476 4820]CXGLDirectInputDevice8W::QueryInterface - guid:{54D41081-DC15-4833-A41B-748F73A38179}
[4476 4820]CXGLDirectInputDevice8W::AddRef - count:2
[4476 4820]CXGLDirectInputDevice8W::Release - count:1
[4476 4820]CXGLDirectInputDevice8W::GetDeviceInfo
[4476 4820]>>CXGLDirectInputDevice8W::EnumObjects - flags:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetProperty - property:4
[4476 4820]<<CXGLDirectInputDevice8W::GetProperty - hr:0x0
[4476 4820]<<CXGLDirectInputDevice8W::EnumObjects - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::EnumObjects - flags:0x3
[4476 4820]<<CXGLDirectInputDevice8W::EnumObjects - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::SetDataFormat
[4476 4820]<<CXGLDirectInputDevice8W::SetDataFormat - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::SetCooperativeLevel - HWND:0x000000000004055A level:0x5
[4476 4820]<<CXGLDirectInputDevice8W::SetCooperativeLevel - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetCapabilities
[4476 4820]size:24, axes:0, buttons:0, type:0x0, ffdv:0x447886fe, ffmtr:0x7fe, ffsp:0xe9454965, fmv:0x44c, flags:0x0, hwr:0xf46efeb8, pov:0
[4476 4820]<<CXGLDirectInputDevice8W::GetCapabilities - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::Acquire
[4476 4820]<<CXGLDirectInputDevice8W::Acquire - hr:0x80070005
[4476 4820]>>CXGLDirectInputDevice8W::Poll
[4476 4820]<<CXGLDirectInputDevice8W::Poll - hr:0x8007000c
[4476 4820]>>CXGLDirectInputDevice8W::Poll
[4476 4820]<<CXGLDirectInputDevice8W::Poll - hr:0x8007000c
…
…
[4476 4820]>>CXGLDirectInputDevice8W::GetDeviceState - size:272
[4476 4820]<<CXGLDirectInputDevice8W::GetDeviceState - hr:0x0
[4476 4820]>>CXGLDirectInputDevice8W::GetDeviceState - size:272
[4476 4820]<<CXGLDirectInputDevice8W::GetDeviceState - hr:0x0
[4476 4820]>>CXGLXInputImpl::GetState - 0
[4476 4820]<<CXGLXInputImpl::GetState - 0 0
[4476 4820]>>CXGLXInputImpl::GetState - 0
[4476 4820]<<CXGLXInputImpl::GetState - 0 0
Does anyone know what I'm missing? I'm stuck here for a whole week. The game doesn't call the WMI (IWbemLocater) to discriminate the Xbox controller and normal joystick. It doesn't call SetupApi to enumerate the devices. Any ideas are appreciated.
Thanks,
Marshall