mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-25 01:57:47 +01:00
experimental dinput hook
This commit is contained in:
parent
7ec7f853d2
commit
6a2674e372
1
Makefile
1
Makefile
@ -15,6 +15,7 @@ FILES = src/debug.c \
|
|||||||
src/screenshot.c \
|
src/screenshot.c \
|
||||||
src/settings.c \
|
src/settings.c \
|
||||||
src/lodepng.c \
|
src/lodepng.c \
|
||||||
|
src/dinput.c \
|
||||||
src/opengl.c
|
src/opengl.c
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\clipper.c" />
|
<ClCompile Include="src\clipper.c" />
|
||||||
<ClCompile Include="src\debug.c" />
|
<ClCompile Include="src\debug.c" />
|
||||||
|
<ClCompile Include="src\dinput.c" />
|
||||||
<ClCompile Include="src\lodepng.c" />
|
<ClCompile Include="src\lodepng.c" />
|
||||||
<ClCompile Include="src\main.c" />
|
<ClCompile Include="src\main.c" />
|
||||||
<ClCompile Include="src\mouse.c" />
|
<ClCompile Include="src\mouse.c" />
|
||||||
|
@ -54,6 +54,9 @@
|
|||||||
<ClCompile Include="src\lodepng.c">
|
<ClCompile Include="src\lodepng.c">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\dinput.c">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="inc\clipper.h">
|
<ClInclude Include="inc\clipper.h">
|
||||||
|
71
src/dinput.c
Normal file
71
src/dinput.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
#include <dinput.h>
|
||||||
|
|
||||||
|
void HookIAT(HMODULE hMod, char *moduleName, char *functionName, PROC newFunction);
|
||||||
|
|
||||||
|
typedef HRESULT (WINAPI *DInputCreateA)(HINSTANCE, DWORD, LPDIRECTINPUTA*, LPUNKNOWN);
|
||||||
|
typedef HRESULT (WINAPI *DICreateDevice)(IDirectInputA*, REFGUID, LPDIRECTINPUTDEVICEA *, LPUNKNOWN);
|
||||||
|
typedef HRESULT (WINAPI *DIDSetCooperativeLevel)(IDirectInputDeviceA *, HWND, DWORD);
|
||||||
|
|
||||||
|
static DInputCreateA DInputCreateA_;
|
||||||
|
static DICreateDevice DICreateDevice_;
|
||||||
|
static DIDSetCooperativeLevel DIDSetCooperativeLevel_;
|
||||||
|
|
||||||
|
static PROC HookFunc(PROC *orgFunc, PROC newFunc)
|
||||||
|
{
|
||||||
|
PROC org = *orgFunc;
|
||||||
|
DWORD oldProtect;
|
||||||
|
MEMORY_BASIC_INFORMATION mbi;
|
||||||
|
|
||||||
|
if (VirtualQuery(orgFunc, &mbi, sizeof(MEMORY_BASIC_INFORMATION)))
|
||||||
|
{
|
||||||
|
if (VirtualProtect(mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &oldProtect))
|
||||||
|
{
|
||||||
|
*orgFunc = newFunc;
|
||||||
|
VirtualProtect(mbi.BaseAddress, mbi.RegionSize, oldProtect, &oldProtect);
|
||||||
|
return org;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT WINAPI fake_DIDSetCooperativeLevel(IDirectInputDeviceA *This, HWND hwnd, DWORD dwFlags)
|
||||||
|
{
|
||||||
|
return DIDSetCooperativeLevel_(This, hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT WINAPI fake_DICreateDevice(IDirectInputA *This, REFGUID rguid, LPDIRECTINPUTDEVICEA * lplpDIDevice, LPUNKNOWN pUnkOuter)
|
||||||
|
{
|
||||||
|
HRESULT result = DICreateDevice_(This, rguid, lplpDIDevice, pUnkOuter);
|
||||||
|
|
||||||
|
if (SUCCEEDED(result) && !DIDSetCooperativeLevel_)
|
||||||
|
{
|
||||||
|
DIDSetCooperativeLevel_ =
|
||||||
|
(DIDSetCooperativeLevel)HookFunc(
|
||||||
|
(PROC *)&(*lplpDIDevice)->lpVtbl->SetCooperativeLevel, (PROC)fake_DIDSetCooperativeLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static HRESULT WINAPI fake_DirectInputCreateA(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUTA* lplpDirectInput, LPUNKNOWN punkOuter)
|
||||||
|
{
|
||||||
|
DInputCreateA_ = (DInputCreateA)GetProcAddress(GetModuleHandle("dinput.dll"), "DirectInputCreateA");
|
||||||
|
if (!DInputCreateA_)
|
||||||
|
return DIERR_GENERIC;
|
||||||
|
|
||||||
|
HRESULT result = DInputCreateA_(hinst, dwVersion, lplpDirectInput, punkOuter);
|
||||||
|
|
||||||
|
if (SUCCEEDED(result) && !DICreateDevice_)
|
||||||
|
{
|
||||||
|
DICreateDevice_ =
|
||||||
|
(DICreateDevice)HookFunc((PROC *)&(*lplpDirectInput)->lpVtbl->CreateDevice, (PROC)fake_DICreateDevice);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dinput_init()
|
||||||
|
{
|
||||||
|
HookIAT(GetModuleHandle(NULL), "dinput.dll", "DirectInputCreateA", (PROC)fake_DirectInputCreateA);
|
||||||
|
}
|
@ -30,16 +30,15 @@
|
|||||||
|
|
||||||
#define IDR_MYMENU 93
|
#define IDR_MYMENU 93
|
||||||
|
|
||||||
/* from mouse.c */
|
|
||||||
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint);
|
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint);
|
||||||
void mouse_init();
|
void mouse_init();
|
||||||
void mouse_lock();
|
void mouse_lock();
|
||||||
void mouse_unlock();
|
void mouse_unlock();
|
||||||
|
|
||||||
/* from screenshot.c */
|
|
||||||
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
BOOL screenshot(struct IDirectDrawSurfaceImpl *);
|
||||||
void Settings_Load();
|
void Settings_Load();
|
||||||
void Settings_Save(RECT *lpRect, int windowState);
|
void Settings_Save(RECT *lpRect, int windowState);
|
||||||
|
void dinput_init();
|
||||||
|
|
||||||
IDirectDrawImpl *ddraw = NULL;
|
IDirectDrawImpl *ddraw = NULL;
|
||||||
|
|
||||||
@ -89,6 +88,7 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeBeginPeriod(1);
|
timeBeginPeriod(1);
|
||||||
|
dinput_init();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user