mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-15 06:04:49 +01:00
improve dinput hooks with hook=3
This commit is contained in:
parent
1923e2bb0c
commit
3bc8fffe81
@ -1,7 +1,21 @@
|
||||
#ifndef DINPUTINPUT_H
|
||||
#define DINPUTINPUT_H
|
||||
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#include <dinput.h>
|
||||
|
||||
typedef HRESULT(WINAPI* DIRECTINPUTCREATEAPROC)(HINSTANCE, DWORD, LPDIRECTINPUTA*, LPUNKNOWN);
|
||||
typedef HRESULT(WINAPI* DIRECTINPUT8CREATEPROC)(HINSTANCE, DWORD, REFIID, LPDIRECTINPUT8*, LPUNKNOWN);
|
||||
typedef HRESULT(WINAPI* DICREATEDEVICEPROC)(IDirectInputA*, REFGUID, LPDIRECTINPUTDEVICEA*, LPUNKNOWN);
|
||||
typedef HRESULT(WINAPI* DIDSETCOOPERATIVELEVELPROC)(IDirectInputDeviceA*, HWND, DWORD);
|
||||
typedef HRESULT(WINAPI* DIDGETDEVICEDATAPROC)(IDirectInputDeviceA*, DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD);
|
||||
|
||||
extern DIRECTINPUTCREATEAPROC real_DirectInputCreateA;
|
||||
extern DIRECTINPUT8CREATEPROC real_DirectInput8Create;
|
||||
|
||||
void dinput_hook();
|
||||
void dinput_unhook();
|
||||
HRESULT WINAPI fake_DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA* lplpDirectInput, LPUNKNOWN punkOuter);
|
||||
HRESULT WINAPI fake_DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPDIRECTINPUT8* ppvOut, LPUNKNOWN punkOuter);
|
||||
|
||||
#endif
|
||||
|
@ -1,18 +1,14 @@
|
||||
|
||||
#include <windows.h>
|
||||
#include <dinput.h>
|
||||
#include "directinput.h"
|
||||
#include "debug.h"
|
||||
#include "hook.h"
|
||||
#include "dd.h"
|
||||
|
||||
typedef HRESULT (WINAPI *DIRECTINPUTCREATEAPROC)(HINSTANCE, DWORD, LPDIRECTINPUTA*, LPUNKNOWN);
|
||||
typedef HRESULT (WINAPI *DIRECTINPUT8CREATEPROC)(HINSTANCE, DWORD, REFIID, LPDIRECTINPUT8*, LPUNKNOWN);
|
||||
typedef HRESULT (WINAPI *DICREATEDEVICEPROC)(IDirectInputA*, REFGUID, LPDIRECTINPUTDEVICEA *, LPUNKNOWN);
|
||||
typedef HRESULT (WINAPI *DIDSETCOOPERATIVELEVELPROC)(IDirectInputDeviceA *, HWND, DWORD);
|
||||
typedef HRESULT (WINAPI *DIDGETDEVICEDATAPROC)(IDirectInputDeviceA*, DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD);
|
||||
|
||||
static DIRECTINPUTCREATEAPROC real_DirectInputCreateA;
|
||||
static DIRECTINPUT8CREATEPROC real_DirectInput8Create;
|
||||
DIRECTINPUTCREATEAPROC real_DirectInputCreateA;
|
||||
DIRECTINPUT8CREATEPROC real_DirectInput8Create;
|
||||
|
||||
static DICREATEDEVICEPROC real_di_CreateDevice;
|
||||
static DIDSETCOOPERATIVELEVELPROC real_did_SetCooperativeLevel;
|
||||
static DIDGETDEVICEDATAPROC real_did_GetDeviceData;
|
||||
@ -68,12 +64,15 @@ static HRESULT WINAPI fake_di_CreateDevice(IDirectInputA *This, REFGUID rguid, L
|
||||
return result;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI fake_DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA* lplpDirectInput, LPUNKNOWN punkOuter)
|
||||
HRESULT WINAPI fake_DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA* lplpDirectInput, LPUNKNOWN punkOuter)
|
||||
{
|
||||
dprintf("DirectInputCreateA\n");
|
||||
|
||||
real_DirectInputCreateA =
|
||||
(DIRECTINPUTCREATEAPROC)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateA");
|
||||
if (!real_DirectInputCreateA)
|
||||
{
|
||||
real_DirectInputCreateA =
|
||||
(DIRECTINPUTCREATEAPROC)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateA");
|
||||
}
|
||||
|
||||
if (!real_DirectInputCreateA)
|
||||
return DIERR_GENERIC;
|
||||
@ -93,8 +92,11 @@ HRESULT WINAPI fake_DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID
|
||||
{
|
||||
dprintf("DirectInput8Create\n");
|
||||
|
||||
real_DirectInput8Create =
|
||||
(DIRECTINPUT8CREATEPROC)GetProcAddress(GetModuleHandle("dinput8.dll"), "DirectInput8Create");
|
||||
if (!real_DirectInput8Create)
|
||||
{
|
||||
real_DirectInput8Create =
|
||||
(DIRECTINPUT8CREATEPROC)GetProcAddress(GetModuleHandle("dinput8.dll"), "DirectInput8Create");
|
||||
}
|
||||
|
||||
if (!real_DirectInput8Create)
|
||||
return DIERR_GENERIC;
|
||||
|
46
src/hook.c
46
src/hook.c
@ -2,6 +2,7 @@
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <psapi.h>
|
||||
#include "directinput.h"
|
||||
#include "dd.h"
|
||||
#include "winapi_hooks.h"
|
||||
#include "hook.h"
|
||||
@ -367,21 +368,31 @@ void hook_init()
|
||||
#ifdef _MSC_VER
|
||||
if (!g_hook_active && g_hook_method == 3)
|
||||
{
|
||||
FARPROC proc = GetProcAddress(GetModuleHandle("kernelbase.dll"), "LoadLibraryExW");
|
||||
real_DirectInputCreateA = (DIRECTINPUTCREATEAPROC)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateA");
|
||||
|
||||
if (proc)
|
||||
real_LoadLibraryExW = (LOADLIBRARYEXWPROC)proc;
|
||||
if (real_DirectInputCreateA)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach((PVOID*)&real_DirectInputCreateA, (PVOID)fake_DirectInputCreateA);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach((PVOID*)&real_LoadLibraryExW, (PVOID)fake_LoadLibraryExW);
|
||||
DetourTransactionCommit();
|
||||
real_DirectInput8Create = (DIRECTINPUT8CREATEPROC)GetProcAddress(LoadLibraryA("dinput8.dll"), "DirectInput8Create");
|
||||
|
||||
if (real_DirectInput8Create)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourAttach((PVOID*)&real_DirectInput8Create, (PVOID)fake_DirectInput8Create);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
g_hook_active = TRUE;
|
||||
|
||||
if (g_hook_method == 4)
|
||||
if (g_hook_method == 3 || g_hook_method == 4)
|
||||
{
|
||||
for (int i = 0; g_hooks[i].module_name[0]; i++)
|
||||
{
|
||||
@ -405,10 +416,21 @@ void hook_exit()
|
||||
#ifdef _MSC_VER
|
||||
if (g_hook_method == 3)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach((PVOID*)&real_LoadLibraryExW, (PVOID)fake_LoadLibraryExW);
|
||||
DetourTransactionCommit();
|
||||
if (real_DirectInputCreateA)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach((PVOID*)&real_DirectInputCreateA, (PVOID)fake_DirectInputCreateA);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
|
||||
if (real_DirectInput8Create)
|
||||
{
|
||||
DetourTransactionBegin();
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
DetourDetach((PVOID*)&real_DirectInput8Create, (PVOID)fake_DirectInput8Create);
|
||||
DetourTransactionCommit();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user