Xhook Crossfire Better -
Here are a few different types of content depending on what exactly you are looking for.
4.2. Fixing the "Flicker" Bug
Standard Crossfire flickers because the front buffer is rendered on GPU0 but presented on GPU1. Use XHook to intercept Present: xhook crossfire better
- Calculate the frame ID.
- On odd frames, call
Presenton GPU0. - On even frames, call
Presenton GPU1. - Better yet: Synchronize using
D3D11_QUERY_EVENT.
5. No malloc in Signal Handler
Original XHook may call dladdr/malloc inside hook stub → unsafe.
Improved version pre-allocates stack-safe buffers. Here are a few different types of content
3.2. Implement a "Sleep-Bypass" for Input Hooking
Most recoil scripts using GetCursorPos hooking cause input lag. To make XHook better: Calculate the frame ID
- Do not hook inside
WM_INPUTorGetAsyncKeyState. - Do hook
RtlUserThreadStartto insert a low-latency fiber. - Use MinHook (a superior alternative to older XHook) which supports
JMP_RELoptimizations.
3.1. Move from Inline Hooking to VTable Hooking
Standard XHook uses mprotect (Linux) or VirtualProtect (Windows) to change page permissions. This is slow and triggers anti-cheat.
The "Better" Way: Hook the VTable of the DirectX device instead.
// Instead of hooking EndScene directly via trampoline:
// Better: Swap the VTable entry.
DWORD* vTable = (DWORD*)pDevice;
vTable[42] = (DWORD)MyEndScene; // VTable hook - faster, fewer page faults.
This reduces overhead by ~40% because you aren't detouring every single call.
2. Safe Trampoline Generation
- Pre-allocate a pool of executable memory (no
mmapduring hook). - Use relative jumps where possible (PC-relative).
- Ensure trampoline preserves all registers, including FP/SIMD.