1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-14 22:03:27 +01:00

remove dinputhook setting

This commit is contained in:
FunkyFr3sh 2023-08-02 17:09:01 +02:00
parent 1452bbe598
commit ad1a35aa84
9 changed files with 146 additions and 122 deletions

View File

@ -14,6 +14,8 @@ typedef HRESULT(WINAPI* DIDSETCOOPERATIVELEVELPROC)(IDirectInputDeviceA*, HWND,
typedef HRESULT(WINAPI* DIDGETDEVICEDATAPROC)(IDirectInputDeviceA*, DWORD, LPDIDEVICEOBJECTDATA, LPDWORD, DWORD);
typedef HRESULT(WINAPI* DIDGETDEVICESTATEPROC)(IDirectInputDeviceA*, DWORD, LPVOID);
extern BOOL g_dinput_hook_active;
extern DIRECTINPUTCREATEAPROC real_DirectInputCreateA;
extern DIRECTINPUTCREATEWPROC real_DirectInputCreateW;
extern DIRECTINPUTCREATEEXPROC real_DirectInputCreateEx;
@ -24,4 +26,7 @@ HRESULT WINAPI fake_DirectInputCreateW(HINSTANCE hinst, DWORD dwVersion, LPDIREC
HRESULT WINAPI fake_DirectInputCreateEx(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPDIRECTINPUT7A* ppvOut, LPUNKNOWN punkOuter);
HRESULT WINAPI fake_DirectInput8Create(HINSTANCE hinst, DWORD dwVersion, REFIID riidltf, LPDIRECTINPUT8* ppvOut, LPUNKNOWN punkOuter);
void dinput_hook_init();
void dinput_hook_exit();
#endif

View File

@ -99,10 +99,9 @@ extern COCREATEINSTANCEPROC real_CoCreateInstance;
extern SETUNHANDLEDEXCEPTIONFILTERPROC real_SetUnhandledExceptionFilter;
extern int g_hook_method;
extern BOOL g_hook_dinput;
extern BOOL g_hook_active;
void hook_init();
void hook_init(BOOL initial_hook);
void hook_exit();
void hook_patch_iat(HMODULE hmod, BOOL unhook, char* module_name, char* function_name, PROC new_function);
void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks);

View File

@ -76,8 +76,6 @@ void cfg_load()
g_config.save_settings = cfg_get_int("savesettings", 1);
g_hook_dinput = cfg_get_bool("dinputhook", FALSE);
g_ddraw->render.maxfps = cfg_get_int("maxfps", -1);
g_ddraw->render.minfps = cfg_get_int("minfps", 0);
@ -351,7 +349,6 @@ static void cfg_create_ini()
"lock_surfaces=false\n"
"releasealt=false\n"
"allow_wmactivate=false\n"
"dinputhook=false\n"
"flipclear=false\n"
"fixmousehook=false\n"
"rgb555=false\n"
@ -735,14 +732,6 @@ static void cfg_create_ini()
"maxgameticks=60\n"
"fixnotresponding=true\n"
"\n"
"; Fallout\n"
"[falloutw]\n"
"dinputhook=true\n"
"\n"
"; Fallout 2\n"
"[FALLOUT2]\n"
"dinputhook=true\n"
"\n"
"; Fairy Tale About Father Frost, Ivan and Nastya\n"
"[mrazik]\n"
"guard_lines=0\n"
@ -878,13 +867,8 @@ static void cfg_create_ini()
"[Mech3]\n"
"nonexclusive=true\n"
"\n"
"; Moorhuhn\n"
"[Moorhuhn]\n"
"dinputhook=true\n"
"\n"
"; Moorhuhn 2\n"
"[Moorhuhn2]\n"
"dinputhook=true\n"
"releasealt=true\n"
"\n"
"; New Robinson\n"

View File

@ -924,7 +924,7 @@ HRESULT dd_SetCooperativeLevel(HWND hwnd, DWORD dwFlags)
if (!g_ddraw->wndproc)
{
hook_init();
hook_init(FALSE);
g_ddraw->wndproc = (WNDPROC)real_SetWindowLongA(g_ddraw->hwnd, GWL_WNDPROC, (LONG)fake_WndProc);
g_ddraw->gui_thread_id = GetWindowThreadProcessId(g_ddraw->hwnd, NULL);

View File

@ -1,4 +1,3 @@
#include <windows.h>
#include <initguid.h>
#include "directinput.h"
@ -7,6 +6,11 @@
#include "dd.h"
#include "mouse.h"
#ifdef _MSC_VER
#include "detours.h"
#endif
BOOL g_dinput_hook_active;
DIRECTINPUTCREATEAPROC real_DirectInputCreateA;
DIRECTINPUTCREATEWPROC real_DirectInputCreateW;
@ -317,3 +321,95 @@ HRESULT WINAPI fake_DirectInput8Create(
return result;
}
void dinput_hook_init()
{
#ifdef _MSC_VER
if (!g_dinput_hook_active)
{
g_dinput_hook_active = TRUE;
real_DirectInputCreateA = (void*)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateA");
if (real_DirectInputCreateA && real_DirectInputCreateA != fake_DirectInputCreateA)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInputCreateA, (PVOID)fake_DirectInputCreateA);
DetourTransactionCommit();
}
real_DirectInputCreateW = (void*)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateW");
if (real_DirectInputCreateW && real_DirectInputCreateW != fake_DirectInputCreateW)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInputCreateW, (PVOID)fake_DirectInputCreateW);
DetourTransactionCommit();
}
real_DirectInputCreateEx = (void*)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateEx");
if (real_DirectInputCreateEx && real_DirectInputCreateEx != fake_DirectInputCreateEx)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInputCreateEx, (PVOID)fake_DirectInputCreateEx);
DetourTransactionCommit();
}
real_DirectInput8Create = (void*)GetProcAddress(LoadLibraryA("dinput8.dll"), "DirectInput8Create");
if (real_DirectInput8Create && real_DirectInput8Create != fake_DirectInput8Create)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInput8Create, (PVOID)fake_DirectInput8Create);
DetourTransactionCommit();
}
}
#endif
}
void dinput_hook_exit()
{
#ifdef _MSC_VER
if (g_dinput_hook_active)
{
if (real_DirectInputCreateA)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInputCreateA, (PVOID)fake_DirectInputCreateA);
DetourTransactionCommit();
}
if (real_DirectInputCreateW)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInputCreateW, (PVOID)fake_DirectInputCreateW);
DetourTransactionCommit();
}
if (real_DirectInputCreateEx)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInputCreateEx, (PVOID)fake_DirectInputCreateEx);
DetourTransactionCommit();
}
if (real_DirectInput8Create)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInput8Create, (PVOID)fake_DirectInput8Create);
DetourTransactionCommit();
}
g_dinput_hook_active = FALSE;
}
#endif
}

View File

@ -2,6 +2,7 @@
#include "ddraw.h"
#include <stdio.h>
#include "dllmain.h"
#include "directinput.h"
#include "IDirectDraw.h"
#include "dd.h"
#include "ddclipper.h"
@ -102,7 +103,7 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
timeBeginPeriod(1);
g_hook_method = cfg_get_int("hook", 4);
hook_init();
hook_init(TRUE);
break;
}
case DLL_PROCESS_DETACH:
@ -112,6 +113,7 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
cfg_save();
timeEndPeriod(1);
dinput_hook_exit();
hook_exit();
break;
}

View File

@ -15,7 +15,6 @@
#endif
BOOL g_hook_active;
BOOL g_hook_dinput;
int g_hook_method = 1;
GETCURSORPOSPROC real_GetCursorPos = GetCursorPos;
@ -536,66 +535,13 @@ void hook_revert(HOOKLIST* hooks)
}
}
void hook_init()
void hook_init(BOOL initial_hook)
{
if (!g_hook_active || g_hook_method == 3 || g_hook_method == 4)
{
BOOL initial_hook = !g_hook_active;
#ifdef _MSC_VER
if (initial_hook && cfg_get_bool("dinputhook", FALSE))
{
real_DirectInputCreateA =
(DIRECTINPUTCREATEAPROC)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateA");
if (real_DirectInputCreateA)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInputCreateA, (PVOID)fake_DirectInputCreateA);
DetourTransactionCommit();
}
real_DirectInputCreateW =
(DIRECTINPUTCREATEWPROC)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateW");
if (real_DirectInputCreateW)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInputCreateW, (PVOID)fake_DirectInputCreateW);
DetourTransactionCommit();
}
real_DirectInputCreateEx =
(DIRECTINPUTCREATEEXPROC)GetProcAddress(LoadLibraryA("dinput.dll"), "DirectInputCreateEx");
if (real_DirectInputCreateEx)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInputCreateEx, (PVOID)fake_DirectInputCreateEx);
DetourTransactionCommit();
}
real_DirectInput8Create =
(DIRECTINPUT8CREATEPROC)GetProcAddress(LoadLibraryA("dinput8.dll"), "DirectInput8Create");
if (real_DirectInput8Create)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_DirectInput8Create, (PVOID)fake_DirectInput8Create);
DetourTransactionCommit();
}
}
#endif
#if defined(_DEBUG) && defined(_MSC_VER)
if (initial_hook)
{
hook_patch_iat(GetModuleHandle(NULL), FALSE, "kernel32.dll", "SetUnhandledExceptionFilter", (PROC)fake_SetUnhandledExceptionFilter);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((PVOID*)&real_SetUnhandledExceptionFilter, (PVOID)fake_SetUnhandledExceptionFilter);
@ -608,9 +554,9 @@ void hook_init()
hook_patch_iat(GetModuleHandle("AcGenral"), FALSE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA);
}
g_hook_active = TRUE;
hook_create((HOOKLIST*)&g_hooks, initial_hook);
g_hook_active = TRUE;
}
}
@ -620,43 +566,6 @@ void hook_exit()
{
g_hook_active = FALSE;
#ifdef _MSC_VER
if (cfg_get_bool("dinputhook", FALSE))
{
if (real_DirectInputCreateA)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInputCreateA, (PVOID)fake_DirectInputCreateA);
DetourTransactionCommit();
}
if (real_DirectInputCreateW)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInputCreateW, (PVOID)fake_DirectInputCreateW);
DetourTransactionCommit();
}
if (real_DirectInputCreateEx)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInputCreateEx, (PVOID)fake_DirectInputCreateEx);
DetourTransactionCommit();
}
if (real_DirectInput8Create)
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach((PVOID*)&real_DirectInput8Create, (PVOID)fake_DirectInput8Create);
DetourTransactionCommit();
}
}
#endif
hook_revert((HOOKLIST*)&g_hooks);
}
@ -666,8 +575,6 @@ void hook_exit()
DetourDetach((PVOID*)&real_SetUnhandledExceptionFilter, (PVOID)fake_SetUnhandledExceptionFilter);
DetourTransactionCommit();
hook_patch_iat(GetModuleHandle(NULL), TRUE, "kernel32.dll", "SetUnhandledExceptionFilter", (PROC)fake_SetUnhandledExceptionFilter);
real_SetUnhandledExceptionFilter(g_dbg_exception_filter);
#endif

View File

@ -11,7 +11,9 @@
#include "mouse.h"
#include "wndproc.h"
#include "render_gdi.h"
#include "directinput.h"
#include "ddsurface.h"
#include "dllmain.h"
BOOL WINAPI fake_GetCursorPos(LPPOINT lpPoint)
@ -911,7 +913,14 @@ HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName)
}
#endif
hook_init();
if (hmod && hmod != g_ddraw_module && lpLibFileName &&
(_strcmpi(lpLibFileName, "dinput.dll") == 0 || _strcmpi(lpLibFileName, "dinput") == 0 ||
_strcmpi(lpLibFileName, "dinput8.dll") == 0 || _strcmpi(lpLibFileName, "dinput8") == 0))
{
dinput_hook_init();
}
hook_init(FALSE);
return hmod;
}
@ -928,7 +937,14 @@ HMODULE WINAPI fake_LoadLibraryW(LPCWSTR lpLibFileName)
}
#endif
hook_init();
if (hmod && hmod != g_ddraw_module && lpLibFileName &&
(_wcsicmp(lpLibFileName, L"dinput.dll") == 0 || _wcsicmp(lpLibFileName, L"dinput") == 0 ||
_wcsicmp(lpLibFileName, L"dinput8.dll") == 0 || _wcsicmp(lpLibFileName, L"dinput8") == 0))
{
dinput_hook_init();
}
hook_init(FALSE);
return hmod;
}
@ -945,7 +961,14 @@ HMODULE WINAPI fake_LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwF
}
#endif
hook_init();
if (hmod && hmod != g_ddraw_module && lpLibFileName &&
(_strcmpi(lpLibFileName, "dinput.dll") == 0 || _strcmpi(lpLibFileName, "dinput") == 0 ||
_strcmpi(lpLibFileName, "dinput8.dll") == 0 || _strcmpi(lpLibFileName, "dinput8") == 0))
{
dinput_hook_init();
}
hook_init(FALSE);
return hmod;
}
@ -962,7 +985,14 @@ HMODULE WINAPI fake_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dw
}
#endif
hook_init();
if (hmod && hmod != g_ddraw_module && lpLibFileName &&
(_wcsicmp(lpLibFileName, L"dinput.dll") == 0 || _wcsicmp(lpLibFileName, L"dinput") == 0 ||
_wcsicmp(lpLibFileName, L"dinput8.dll") == 0 || _wcsicmp(lpLibFileName, L"dinput8") == 0))
{
dinput_hook_init();
}
hook_init(FALSE);
return hmod;
}

View File

@ -9,6 +9,7 @@
#include "config.h"
#include "screenshot.h"
#include "winapi_hooks.h"
#include "directinput.h"
#include "wndproc.h"
#include "utils.h"
#include "debug.h"
@ -560,7 +561,7 @@ LRESULT CALLBACK fake_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(ip));
if (g_hook_dinput)
if (g_dinput_hook_active)
{
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 56; // LeftAlt