BOOL FAR PASCAL HookDI::HookEnumCallbackW(LPCDIDEVICEINSTANCEW lpddi, LPVOID pvRef) { if (!InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_DI)) return TrueCallbackW(lpddi, pvRef); PrintLog("EnumCallbackW"); if (!DeviceCheck(lpddi)) return TrueCallbackW(lpddi, pvRef); if (InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_STOP)) return DIENUM_STOP; for (auto padcfg = InputHookManager::Get().GetInputHook().begin(); padcfg != InputHookManager::Get().GetInputHook().end(); ++padcfg) { if (IsEqualGUID(padcfg->GetProductGUID(), lpddi->guidProduct)) { DIDEVICEINSTANCEW fakedev = *lpddi; if (InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_PIDVID)) { std::wstring strTrueguidProduct; std::wstring strHookguidProduct; GUIDtoString(&strTrueguidProduct, fakedev.guidProduct); fakedev.guidProduct.Data1 = InputHookManager::Get().GetInputHook().GetFakePIDVID(); GUIDtoString(&strHookguidProduct, fakedev.guidProduct); PrintLog("GUID change:"); PrintLog("%ls", strTrueguidProduct.c_str()); PrintLog("%ls", strHookguidProduct.c_str()); } // This should not be required // fakedev.dwDevType = (MAKEWORD(DI8DEVTYPE_GAMEPAD, DI8DEVTYPEGAMEPAD_STANDARD) | DIDEVTYPE_HID); //66069 == 0x00010215 // fakedev.wUsage = 0x05; // fakedev.wUsagePage = 0x01; if (InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_NAME)) { std::wstring OldProductName(fakedev.tszProductName); std::wstring OldInstanceName(fakedev.tszInstanceName); wcscpy_s(fakedev.tszProductName, L"XBOX 360 For Windows (Controller)"); wcscpy_s(fakedev.tszInstanceName, L"XBOX 360 For Windows (Controller)"); PrintLog("Product Name change:"); PrintLog("\"%ls\"", OldProductName.c_str()); PrintLog("\"%ls\"", fakedev.tszProductName); PrintLog("Instance Name change:"); PrintLog("\"%ls\"", OldInstanceName.c_str()); PrintLog("\"%ls\"", fakedev.tszInstanceName); } return TrueCallbackW(&fakedev, pvRef); } } return TrueCallbackW(lpddi, pvRef); }
HRESULT STDMETHODCALLTYPE HookDI::HookGetDeviceInfoW(LPDIRECTINPUTDEVICE8W This, LPDIDEVICEINSTANCEW pdidi) { HRESULT hr = TrueGetDeviceInfoW(This, pdidi); if (!InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_DI)) return hr; PrintLog("IDirectInputDevice8W::GetDeviceInfoW"); if (!DeviceCheck(pdidi)) return TrueGetDeviceInfoW(This, pdidi); for (auto padcfg = InputHookManager::Get().GetInputHook().begin(); padcfg != InputHookManager::Get().GetInputHook().end(); ++padcfg) { if (IsEqualGUID(padcfg->GetProductGUID(), pdidi->guidProduct)) { if (InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_PIDVID)) { std::wstring strTrueguidProduct; std::wstring strHookguidProduct; GUIDtoString(&strTrueguidProduct, pdidi->guidProduct); pdidi->guidProduct.Data1 = InputHookManager::Get().GetInputHook().GetFakePIDVID(); GUIDtoString(&strHookguidProduct, pdidi->guidProduct); PrintLog("GUID change:"); PrintLog("%ls", strTrueguidProduct.c_str()); PrintLog("%ls", strHookguidProduct.c_str()); } // This should not be required //pdidi->dwDevType = (MAKEWORD(DI8DEVTYPE_GAMEPAD, DI8DEVTYPEGAMEPAD_STANDARD) | DIDEVTYPE_HID); //66069 == 0x00010215 //pdidi->wUsage = 0x05; //pdidi->wUsagePage = 0x01; if (InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_NAME)) { std::wstring OldProductName(pdidi->tszProductName); std::wstring OldInstanceName(pdidi->tszInstanceName); wcscpy_s(pdidi->tszProductName, L"XBOX 360 For Windows (Controller)"); wcscpy_s(pdidi->tszInstanceName, L"XBOX 360 For Windows (Controller)"); PrintLog("Product Name change:"); PrintLog("\"%ls\"", OldProductName.c_str()); PrintLog("\"%ls\"", pdidi->tszProductName); PrintLog("Instance Name change:"); PrintLog("\"%ls\"", OldInstanceName.c_str()); PrintLog("\"%ls\"", pdidi->tszInstanceName); } } } return hr; }
BOOL CALLBACK EnumDevicesCallback(LPCDIDEVICEINSTANCE pInst, VOID* pContext) { if (pInst) { std::string guidProduct; std::string guidInstance; GUIDtoString(&guidProduct, pInst->guidProduct); GUIDtoString(&guidInstance, pInst->guidInstance); PrintLog("ProductName : %s\nInstanceName: %s", pInst->tszProductName, pInst->tszInstanceName); PrintLog("guidProduct : %s\nguidInstance: %s", guidProduct.c_str(), guidInstance.c_str()); PrintLog("DevType : 0x%08X 0x%08X", LOBYTE(pInst->dwDevType), HIBYTE(pInst->dwDevType)); PrintLog("\n"); } return DIENUM_CONTINUE; }
std::string VideoCaptureDirectShow2::mediaFormatFormatTypeToString(GUID type) { if(type == FORMAT_DvInfo) { return "FORMAT_DvInfo"; } else if(type == FORMAT_MPEG2Video) { return "FORMAT_MPEG2Video"; } else if(type == FORMAT_MPEGStreams) { return "FORMAT_MPEGStreams"; } else if(type == FORMAT_MPEGVideo) { return "FORMAT_MPEGVideo"; } else if(type == FORMAT_None) { return "FORMAT_None"; } else if(type == FORMAT_VideoInfo) { return "FORMAT_VideoInfo"; } else if(type == FORMAT_VideoInfo2) { return "FORMAT_VideoInfo2"; } else if(type == FORMAT_WaveFormatEx) { return "FORMAT_WaveFormatEx"; } else if(type == GUID_NULL) { return "GUID_NULL"; } else { std::string str = GUIDtoString(type); return "OTHER FORMAT WITH GUID " +str; } }
std::string VideoCaptureDirectShow2::mediaFormatMajorTypeToString(GUID type) { if(type == MEDIATYPE_AnalogAudio) { return "MEDIATYPE_AnalogAudio"; } else if(type == MEDIATYPE_AnalogVideo) { return "MEDIATYPE_AnalogVideo"; } else if(type == MEDIATYPE_Audio) { return "MEDIATYPE_Audio"; } else if(type == MEDIATYPE_AUXLine21Data) { return "MEDIATYPE_AUXLine21Data"; } else if(type == MEDIATYPE_File) { return "MEDIATYPE_File"; } else if(type == MEDIATYPE_Interleaved) { return "MEDIATYPE_Interleaved"; } else if(type == MEDIATYPE_LMRT) { return "MEDIATYPE_LMRT"; } else if(type == MEDIATYPE_Midi) { return "MEDIATYPE_Midi"; } else if(type == MEDIATYPE_MPEG2_PES) { return "MEDIATYPE_MPEG2_PES"; } else if(type == MEDIATYPE_MPEG2_SECTIONS){ return "MEDIATYPE_MPEG2_SECTIONS"; } else if(type == MEDIATYPE_ScriptCommand) { return "MEDIATYPE_ScriptCommand"; } else if(type == MEDIATYPE_Stream) { return "MEDIATYPE_Stream"; } else if(type == MEDIATYPE_Text) { return "MEDIATYPE_Text"; } else if(type == MEDIATYPE_Timecode) { return "MEDIATYPE_Timecode"; } else if(type == MEDIATYPE_URL_STREAM) { return "MEDIATYPE_URL_STREAM"; } else if(type == MEDIATYPE_VBI) { return "MEDIATYPE_VBI"; } else if(type == MEDIATYPE_Video) { return "MEDIATYPE_Video"; } std::string str = GUIDtoString(type); return "OTHER SUBTYPE WITH GUID " +str; }
DWORD Controller::CreateDevice() { bool bHookDI = InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_DI); bool bHookSA = InputHookManager::Get().GetInputHook().GetState(InputHook::HOOK_SA); if (bHookDI) InputHookManager::Get().GetInputHook().DisableHook(InputHook::HOOK_DI); if (bHookSA) InputHookManager::Get().GetInputHook().DisableHook(InputHook::HOOK_SA); IDirectInputDevice8A* device; HRESULT hr = ControllerManager::Get().GetDirectInput()->CreateDevice(m_instanceid, &device, NULL); if (FAILED(hr)) { std::string strInstance; if (GUIDtoString(&strInstance, m_instanceid)) PrintLog("[PAD%d] InstanceGUID %s is incorrect trying ProductGUID", m_user + 1, strInstance.c_str()); hr = ControllerManager::Get().GetDirectInput()->CreateDevice(m_productid, &device, NULL); if (FAILED(hr)) return ERROR_DEVICE_NOT_CONNECTED; } m_pDevice.reset(device); if (bHookSA) InputHookManager::Get().GetInputHook().EnableHook(InputHook::HOOK_SA); if (bHookDI) InputHookManager::Get().GetInputHook().EnableHook(InputHook::HOOK_DI); if (!m_pDevice) return ERROR_DEVICE_NOT_CONNECTED; else PrintLog("[PAD%d] Device created", m_user + 1); hr = m_pDevice->SetDataFormat(&c_dfDIJoystick2); if (FAILED(hr)) PrintLog("[PAD%d] SetDataFormat failed with code HR = %X", m_user + 1, hr); HRESULT setCooperativeLevelResult = m_pDevice->SetCooperativeLevel(ControllerManager::Get().GetWindow(), DISCL_EXCLUSIVE | DISCL_BACKGROUND); if (FAILED(setCooperativeLevelResult)) { m_useforce = false; PrintLog("Cannot get exclusive device access, disabling ForceFeedback"); setCooperativeLevelResult = m_pDevice->SetCooperativeLevel(ControllerManager::Get().GetWindow(), DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); if (FAILED(setCooperativeLevelResult)) PrintLog("[PAD%d] SetCooperativeLevel failed with code HR = %X", m_user + 1, setCooperativeLevelResult); } DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = DIPROPAUTOCENTER_ON; m_pDevice->SetProperty(DIPROP_AUTOCENTER, &dipdw.diph); hr = m_pDevice->EnumObjects(EnumObjectsCallback, (VOID*)this, DIDFT_AXIS); if (FAILED(hr)) PrintLog("[PAD%d] EnumObjects failed with code HR = %X", m_user + 1, hr); else PrintLog("[PAD%d] Detected axis count: %d", m_user + 1, m_axiscount); if (m_useforce) m_useforce = m_ForceFeedback->IsSupported(); hr = m_pDevice->Acquire(); if (SUCCEEDED(hr)) { return ERROR_SUCCESS; } else { return ERROR_DEVICE_NOT_CONNECTED; } }
DEBUG_LOCAL OSStatus ListNameSpaces( void ) { OSStatus err; WSADATA wsd; bool started; int n; int i; DWORD size; WSANAMESPACE_INFO * array; char s[ 256 ]; array = NULL; started = false; err = WSAStartup( MAKEWORD( 2, 2 ), &wsd ); err = translate_errno( err == 0, errno_compat(), WSAEINVAL ); require_noerr( err, exit ); started = true; // Build an array of all the NSPs. Call it first with NULL to get the size, allocate a buffer, then get them into it. size = 0; n = WSAEnumNameSpaceProviders( &size, NULL ); err = translate_errno( n != SOCKET_ERROR, (OSStatus) GetLastError(), kUnknownErr ); require_action( err == WSAEFAULT, exit, err = kUnknownErr ); array = (WSANAMESPACE_INFO *) malloc( size ); require_action( array, exit, err = kNoMemoryErr ); n = WSAEnumNameSpaceProviders( &size, array ); err = translate_errno( n != SOCKET_ERROR, (OSStatus) GetLastError(), kUnknownErr ); require_noerr( err, exit ); fprintf( stdout, "\n" ); for( i = 0; i < n; ++i ) { fprintf( stdout, "Name Space %d\n", i + 1 ); fprintf( stdout, " NSProviderId: %s\n", GUIDtoString( &array[ i ].NSProviderId, sizeof( s ), s ) ); fprintf( stdout, " dwNameSpace: %d\n", array[ i ].dwNameSpace ); fprintf( stdout, " fActive: %s\n", array[ i ].fActive ? "YES" : "NO" ); fprintf( stdout, " dwVersion: %d\n", array[ i ].dwVersion ); fprintf( stdout, " lpszIdentifier: \"%s\"\n", array[ i ].lpszIdentifier ); fprintf( stdout, "\n" ); } err = kNoErr; exit: if( array ) { free( array ); } if( started ) { WSACleanup(); } if( err != kNoErr ) { fprintf( stderr, "### FAILED (%d) to list Name Space Providers\n", err ); } return( err ); }
std::string VideoCaptureDirectShow2::mediaFormatSubTypeToString(GUID type) { if(type == MEDIASUBTYPE_RGB1) { return "MEDIASUBTYPE_RGB1"; } else if(type == MEDIASUBTYPE_RGB4) { return "MEDIASUBTYPE_RGB4"; } else if(type == MEDIASUBTYPE_RGB8) { return "MEDIASUBTYPE_RGB8"; } else if(type == MEDIASUBTYPE_RGB555) { return "MEDIASUBTYPE_RGB555"; } else if(type == MEDIASUBTYPE_RGB565) { return "MEDIASUBTYPE_RGB565"; } else if(type == MEDIASUBTYPE_RGB24) { return "MEDIASUBTYPE_RGB24"; } else if(type == MEDIASUBTYPE_RGB32) { return "MEDIASUBTYPE_RGB32"; } else if(type == MEDIASUBTYPE_ARGB1555) { return "MEDIASUBTYPE_ARGB1555"; } else if(type == MEDIASUBTYPE_ARGB32) { return "MEDIASUBTYPE_ARGB32"; } else if(type == MEDIASUBTYPE_ARGB4444) { return "MEDIASUBTYPE_ARGB4444"; } else if(type == MEDIASUBTYPE_A2R10G10B10) { return "MEDIASUBTYPE_A2R10G10B10"; } else if(type == MEDIASUBTYPE_A2B10G10R10) { return "MEDIASUBTYPE_A2B10G10R10"; } // http://msdn.microsoft.com/en-us/library/windows/desktop/dd391027(v=vs.85).aspx else if(type == MEDIASUBTYPE_AYUV) { return "MEDIASUBTYPE_AYUV"; } else if(type == MEDIASUBTYPE_YUY2) { return "MEDIASUBTYPE_YUY2"; } else if(type == MEDIASUBTYPE_UYVY) { return "MEDIASUBTYPE_UYVY"; } else if(type == MEDIASUBTYPE_IMC1) { return "MEDIASUBTYPE_IMC1"; } else if(type == MEDIASUBTYPE_IMC3) { return "MEDIASUBTYPE_IMC3"; } else if(type == MEDIASUBTYPE_IMC2) { return "MEDIASUBTYPE_IMC2"; } else if(type == MEDIASUBTYPE_IMC4) { return "MEDIASUBTYPE_IMC4"; } else if(type == MEDIASUBTYPE_YV12) { return "MEDIASUBTYPE_YV12"; } else if(type == MEDIASUBTYPE_NV12) { return "MEDIASUBTYPE_NV12"; } else if(type == MEDIASUBTYPE_IF09) { return "MEDIASUBTYPE_IF09"; } else if(type == MEDIASUBTYPE_IYUV) { return "MEDIASUBTYPE_IYUV"; } else if(type == MEDIASUBTYPE_I420) { return "MEDIASUBTYPE_I420"; } else if(type == MEDIASUBTYPE_Y211) { return "MEDIASUBTYPE_Y211"; } else if(type == MEDIASUBTYPE_Y411) { return "MEDIASUBTYPE_Y411"; } else if(type == MEDIASUBTYPE_Y41P) { return "MEDIASUBTYPE_Y41P"; } else if(type == MEDIASUBTYPE_YVU9) { return "MEDIASUBTYPE_YVU9"; } else if(type == MEDIASUBTYPE_YVYU) { return "MEDIASUBTYPE_YVYU"; } // http://msdn.microsoft.com/en-us/library/windows/desktop/dd757808(v=vs.85).aspx, wmcodecdsp.h * defined in SDK 7.1 else if(type == MEDIASUBTYPE_H264) { return "MEDIASUBTYPE_H264"; } // http://msdn.microsoft.com/en-us/library/windows/desktop/dd390688(v=vs.85).aspx else if(type == MEDIASUBTYPE_CFCC) { return "MEDIASUBTYPE_CFCC"; } else if(type == MEDIASUBTYPE_CLJR) { return "MEDIASUBTYPE_CLJR"; } else if(type == MEDIASUBTYPE_CPLA) { return "MEDIASUBTYPE_CPLA"; } else if(type == MEDIASUBTYPE_CLPL) { return "MEDIASUBTYPE_CLPL"; } else if(type == MEDIASUBTYPE_IJPG) { return "MEDIASUBTYPE_IJPG"; } else if(type == MEDIASUBTYPE_MDVF) { return "MEDIASUBTYPE_MDVF"; } else if(type == MEDIASUBTYPE_MJPG) { return "MEDIASUBTYPE_MJPG"; } else if(type == MEDIASUBTYPE_Overlay) { return "MEDIASUBTYPE_Overlay"; } else if(type == MEDIASUBTYPE_Plum) { return "MEDIASUBTYPE_Plum"; } else if(type == MEDIASUBTYPE_QTJpeg) { return "MEDIASUBTYPE_QTJpeg"; } else if(type == MEDIASUBTYPE_QTMovie) { return "MEDIASUBTYPE_QTMovie"; } else if(type == MEDIASUBTYPE_QTRle) { return "MEDIASUBTYPE_QTRle"; } else if(type == MEDIASUBTYPE_QTRpza) { return "MEDIASUBTYPE_QTRpza"; } else if(type == MEDIASUBTYPE_QTSmc) { return "MEDIASUBTYPE_QTSmc"; } else if(type == MEDIASUBTYPE_TVMJ) { return "MEDIASUBTYPE_TVMJ"; } else if(type == MEDIASUBTYPE_VPVBI) { return "MEDIASUBTYPE_VPVBI"; } else if(type == MEDIASUBTYPE_VPVideo) { return "MEDIASUBTYPE_VPVideo"; } else if(type == MEDIASUBTYPE_WAKE) { return "MEDIASUBTYPE_WAKE"; } // http://msdn.microsoft.com/en-us/library/windows/desktop/dd390712(v=vs.85).aspx else if(type == MEDIASUBTYPE_MPEG1System) { return "MEDIASUBTYPE_MPEG1System"; } else if(type == MEDIASUBTYPE_MPEG1VideoCD) { return "MEDIASUBTYPE_MPEG1VideoCD"; } else if(type == MEDIASUBTYPE_MPEG1Packet) { return "MEDIASUBTYPE_MPEG1Packet"; } else if(type == MEDIASUBTYPE_MPEG1Payload) { return "MEDIASUBTYPE_MPEG1Payload"; } else if(type == MEDIASUBTYPE_MPEG1Packet) { return "MEDIASUBTYPE_MPEG1Packet"; } else if(type == MEDIASUBTYPE_MPEG1Video) { return "MEDIASUBTYPE_ MPEG1Video"; } else if(type == MEDIASUBTYPE_MPEG1Audio) { return "MEDIASUBTYPE_ MPEG1Audio"; } else if(type == MEDIASUBTYPE_MPEG2_VIDEO) { return "MEDIASUBTYPE_MPEG2_VIDEO"; } else if(type == MEDIASUBTYPE_DOLBY_AC3) { return "MEDIASUBTYPE_DOLBY_AC3"; } else if(type == MEDIASUBTYPE_MPEG2_AUDIO) { return "MEDIASUBTYPE_MPEG2_AUDIO"; } else { std::string str = GUIDtoString(type); return "OTHER SUBTYPE WITH GUID " +str; } }