コード例 #1
0
static void diMouseInit(bool exclusive)
{

    IDirectInput8A* input = PSGLOBAL(diInterface);
    HRESULT res = input->CreateDevice(GUID_SysMouse, &PSGLOBAL(diMouse), NULL);
    if (SUCCEEDED(res))
    {
        IDirectInputDevice8A* mouse = PSGLOBAL(diMouse);
        res = mouse->SetDataFormat(&DIMouseDataFormat);
        if (SUCCEEDED(res))
        {
            res = mouse->SetCooperativeLevel(PSGLOBAL(window), DISCL_FOREGROUND | (exclusive ? (DISCL_EXCLUSIVE) : DISCL_NONEXCLUSIVE));
            if (SUCCEEDED(res))
            {
                res = mouse->Acquire();
            }
        }
    }
}
コード例 #2
0
ファイル: HackInput.cpp プロジェクト: IgorYunusov/mylibs
bool HookDInput2()
{
	IDirectInput8A* pDInputA;
	IDirectInputDevice8A* pDeviceA;

	//IDirectInput8W* pDInputW;
	//IDirectInputDevice8W* pDeviceW;

	HRESULT hr = ::DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
		IID_IDirectInput8A, (PVOID* )&pDInputA, NULL);

	if (!SUCCEEDED(hr)) {
		// log error
		return false;
	}	

	hr = pDInputA->CreateDevice(GUID_SysKeyboard, &pDeviceA, NULL);

	if (!SUCCEEDED(hr)) {
		// log error
		return false;
	}

	/*
	hr = ::DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, 
		IID_IDirectInput8W, (PVOID* )&pDInputW, NULL);

	if (!SUCCEEDED(hr)) {
		// log error
		return false;
	}

	hr = pDInputW->CreateDevice(GUID_SysKeyboard, &pDeviceW, NULL);

	int index = GetVirFuncIndex(&(PVOID &)IDirectInputDevice8A::GetDeviceState, ConvStdCall);

	PVOID fn1 = GetVirFuncAddr(pDeviceA, index);
	PVOID fn2 = GetVirFuncAddr(pDeviceW, index);
	*/
	int index = GetVirFuncIndex(&(PVOID &)IDirectInputDevice8A::GetDeviceState, ConvStdCall);

	bool result = HookVirFunc2(pDeviceA, index, &IDirectInputDevice8DetourA::Mine_GetDeviceState, 
		Real_IDirectInputDevice8_GetDeviceStateA);

	if (result) {

		index = GetVirFuncIndex(&(PVOID &)IDirectInputDevice8A::GetDeviceData, ConvStdCall);

		result = HookVirFunc2(pDeviceA, index, &IDirectInputDevice8DetourA::Mine_GetDeviceData, 
			Real_IDirectInputDevice8_GetDeviceDataA);
	}

	if (result) {

		index = GetVirFuncIndex(&(PVOID &)IDirectInputDevice8A::Acquire, ConvStdCall);

		result = HookVirFunc2(pDeviceA, index, &IDirectInputDevice8DetourA::Mine_Acquire, 
			Real_IDirectInputDevice8_Acquire);
	}

	// HookVirFunc2(pDeviceW, index, &IDirectInputDevice8DetourW::Mine_GetDeviceState, 
	//	Real_IDirectInputDevice8_GetDeviceStateW);

	//CHAR BUF[256];
	//pDeviceA->GetDeviceState(256, BUF);
	//pDInputW->GetDeviceState(0, NULL);

	pDeviceA->Release();
	
	return result;
}