nefarius/HydraHook
소개
DirectX API 후킹 프레임워크
게임 및 에뮬레이션What you can do
- Unhook and rehook without unloading — HydraHookEngineUnhook removes all hooks and keeps the DLL loaded; HydraHookEngineRehook reinstalls them and fires EvtHydraHookGameHooked again. Registered callback tables survive the cycle. Do not call either from DllMain, a hook callback, or the worker thread.
- Performance-focused — Lock-free hot path for hook callbacks (atomic counters only; no mutex, no kernel transition). Shutdown uses loader-lock-safe remove_nothrow to avoid deadlocks during process exit. See Present-path performance for benchmark results and guidance on reducing work in render callbacks.
- No external dependencies at runtime — Everything needed is statically linked in. Just drop the DLL into the target process; no redistributables or runtime packages required.
- Core Audio — Optional IAudioRenderClient buffer hooks alongside the Direct3D pipeline.
측정된 스타 증가
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- +1
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
HydraHook
API-Hooking and rendering framework for DirectX-based games.
About
HydraHook consists of a self-contained library (DLL) which exposes a minimalistic API for rendering custom content in foreign processes eliminating the need for in-depth knowledge about Direct3D and API-hooking. The most common use-case might be drawing custom overlays on top of your games. The framework takes care about pesky tasks like detecting the DirectX version the game was built for.
[!CAUTION] Use caution when injecting HydraHook into any game protected by anti-cheat software. API hooking and DLL injection are commonly detected by anti-cheat systems and may result in permanent bans from online services. Use only with games you own and in environments where such use is permitted.
[!NOTE] The authors of this project do not condone the use of HydraHook in cheating software. The project's motivation has been curiosity and education entirely.
Features
Runtime injection and ejection — No launcher required. Inject into any running DirectX process and eject via
FreeLibrarywhen done. For D3D12 games already running, the core can verify the current back buffer’s queue on supported x64 DXGI builds. Other builds retain the recorded associations and the device-scoped fallback. TheFreeLibraryhook stops and destroys the engine before entering the loader, then exits the unloading thread viaFreeLibraryAndExitThread(..., TRUE)so remote-thread ejectors observe aTRUEresult.Unhook and rehook without unloading —
HydraHookEngineUnhookremoves all hooks and keeps the DLL loaded;HydraHookEngineRehookreinstalls them and firesEvtHydraHookGameHookedagain. Registered callback tables survive the cycle. Do not call either fromDllMain, a hook callback, or the worker thread.Performance-focused — Lock-free hot path for hook callbacks (atomic counters only; no mutex, no kernel transition). Shutdown uses loader-lock-safe
remove_nothrowto avoid deadlocks during process exit. See Present-path performance for benchmark results and guidance on reducing work in render callbacks.No external dependencies at runtime — Everything needed is statically linked in. Just drop the DLL into the target process; no redistributables or runtime packages required.
Core Audio — Optional
IAudioRenderClientbuffer hooks alongside the Direct3D pipeline.
Supported platforms
- Windows 10 and Windows 11
- x86 and x64
- Direct3D 12 hooking is built for x86 and x64. The D3D12 ImGui overlay is x64-only
- ARM and UWP are not supported
Supported DirectX versions
- DirectX 9.0
- DirectX 9.0 Extended (Vista+)
- DirectX 10
- DirectX 11
- DirectX 12
How to build
Prerequisites
- Visual Studio 2026 (18.x) with the v145 toolset and C++23 (
/std:c++23, MSVC 14.52 / VS 18.12 or newer; earlier 14.51 maps it to/std:c++23preview) (Community Edition is free) - Windows SDK
Build steps
- Clone the repository and initialize submodules:
git submodule update --init --recursive - From the repository root, run
prepare-deps.bat(both x86 and x64),prepare-deps.bat x64, orprepare-deps.bat Win32. With no arguments the script locates Visual Studio viavswhereand sets up the compiler itself. - Open
HydraHook.slnxand buildRelease_LIB(static library, samples, and tests) orRelease(standaloneHydraHook.dll).Release_LIBwrites the static library tobin\Release_LIB\<arch>\HydraHook.lib;Releasewritesbin\<arch>\HydraHook.dll. The outputs do not collide.
Static library vs. DLL
- Static library (
Release_LIB, recommended for injection): linkHydraHook.libinto your host DLL. The engine lives inside that one DLL, so you inject a single file. No separateHydraHook.dllhas to be shipped, loaded first, or kept in sync with your host. All samples use this route. - DLL (
Release): your host DLL importsHydraHook.dll. You must deploy and load both files, and they must come from the same build.
Dependencies (spdlog, detours, imgui, directxtk, opencv4) are declared in vcpkg.json and installed via vcpkg (included as a submodule). The manifest baseline is pinned in vcpkg-configuration.json. Overlay triplets in triplets/ keep the x86-windows-static and x64-windows-static names and trim OpenCV to the modules the OpenCV sample links (core, imgproc, flann, features2d, calib3d, video) with baseline SIMD only. GitHub Actions uses .github/vcpkg-triplets/, the same trim with Release packages only. Actions builds core/tests, the ImGui/FPS/DirectXTK samples, and the OpenCV sample in separate jobs. The OpenCV job installs and caches its own vcpkg archives per architecture. Publishing those packages to GitHub Packages requires the VCPKG_NUGET_TOKEN secret, a PAT with read:packages and write:packages. The workflow token cannot create packages under a personal account.
Tests
Release_LIB builds the C++ tests for the selected platform. Executables are written to bin\x64 or bin\x86:
HydraHookTests.exe— public API helpers, engine handle checks (including null config and disabled logging), the Detours wrapper, shutdown tracking, crash-handler refcounting and snapshot promotion, the FPS sampler, and the ImGui sample'sResettableInitGuard(once-only init, reset, retry-on-failure, concurrent callers) andWindowProcHook(validation, forwarding, destroy cleanup, external subclass chaining, re-entrancy, cross-thread hook churn).HookActivityTracker::reset,ResettableOnce,Hookre-apply, and theHydraHookEngineUnhook/HydraHookEngineRehookhandle checks are covered too. No test exercises a real game hook/unhook/rehook cycle; the WARP smoke test covers a synthetic D3D11 one.HydraHookWarpSmokeTests.exe— headless D3D11 WARP device withd3d12.dllpreloaded alongsided3d11.dll. It loadsHydraHookTestHost.dll(which enables D3D10, D3D11, and D3D12 hooking) from the same directory, checksGameVersion, Present / Present1 / ResizeBuffers callbacks, verifies unhooked Present / ResizeBuffers calls still succeed afterHydraHookEngineUnhook, and completes a fullHydraHookEngineRehookcycle on the same DLL
bin\x64\HydraHookTests.exe
bin\x64\HydraHookWarpSmokeTests.exe
API reference
The reference covers the public C API and the engine sources. It is not required to build the DLL.
- Doxygen 1.18.0
- Theme: Doxygen Awesome 2.5.0 (MIT), vendored in
docs/doxygen-awesome/
doxygen Doxyfile
Open docs/html/index.html. Generated HTML is not committed.
Published reference: https://nefarius.github.io/HydraHook/
Pull requests upload that HTML as an artifact. A push to master publishes the same build to GitHub Pages.
Releases
A vX.Y.Z tag (for example v4.2.0) builds, tests, signs, and publishes a stable GitHub Release. A vX.Y.Z-preN tag (for example v4.2.0-pre1, where N is one or more digits) publishes a prerelease. Rerunning a tag that already has a published release returns that release to draft before the archives are replaced, and publishes it again only after both uploads succeed. Signing requires the SIGN_RELAY_CI_TOKEN repository secret. SIGN_RELAY_SERVER is optional and defaults to https://signrelay.api.nefarius.systems/.
Pre-built binaries
Signed x86 and x64 archives are published on GitHub Releases. Each archive contains HydraHook.dll and the sample host DLLs. The x64 archive also contains the signed HydraHook-Locksmith.dll for Gothic 1 Remake. Inject them with Injector or HydraHookManager.
How to use
For a ready-to-use FPS counter, build the HydraHook-FPS sample.
The public D3D12 readback API provides nonblocking submission, CPU-owned native frames, and bounded teardown. Locksmith, the diagnostic probe, and OpenCV use it.
The core CI job runs a D3D12 WARP capture test, checks uniform and mixed presentation queues for ResizeBuffers1, and builds an x64 diagnostic probe for live capture tests. It also builds the Locksmith offline lab, runs its solver, vision, and guidance tests, and checks synthetic and transcribed puzzle fixtures. The x64 ImGui sample job builds the Locksmith overlay as a separate test artifact.
Inject the resulting host library (e.g. HydraHook-ImGui.dll) into the target process with Injector or HydraHookManager. The following example loads the imgui sample:
.\Injector -n hl2.exe -i HydraHook-ImGui.dll
Just make sure your host library doesn't require any external dependencies not present in the process context or you'll get a LoadLibrary failed error.
Diagnostics
The core library logs its progress and potential errors to HydraHook.log. It tries to write in this order: (1) the directory of the process executable, (2) the directory of the HydraHook DLL, (3) %TEMP% if both prior locations fail (e.g. no write permissions).
Support
Report defects and compatibility problems on the issue tracker. Usage questions belong on Discord. Anti-cheat enforcement is outside the scope of this project; see the caution above.
Demos
The following demo videos show imgui being rendered in foreign processes using different versions of DirectX. Click a thumbnail to watch the video.
DirectX 9
Half-Life 2, 32-Bit
DirectX 9 Ex
Castlevania: Lords of Shadow, 32-Bit
DirectX 10
Bioshock 2, 32-Bit
DirectX 11
Road Redemption, 64-Bit
DirectX 12
Core Direct3D 12 hooking is built for x86 and x64. Use HydraHookEngineGetVerifiedD3D12CommandQueue in pre-present when submitting GPU work requires an exact back-buffer queue. D3D12 pre-resize callbacks can defer resize through HydraHookEngineDeferD3D12Resize while outstanding work drains. A startup host can set Shutdown.DisableThreadQuitMonitoring when a splash thread can exit before the game does. Initialize HYDRAHOOK_ENGINE_CONFIG with HYDRAHOOK_ENGINE_CONFIG_INIT to set its size. The addition of Size changes the binary layout, so rebuild consumers compiled against the earlier config before using them with this release. The ImGui sample's D3D12 overlay is x64-only.
BEHEMOTH, 64-Bit
Sources
Dependencies
This project uses the following libraries (via vcpkg):
Core library only:
- spdlog – Fast C++ logging library
- Microsoft Detours – API hooking library
Sample projects only:
- Dear ImGui – Immediate mode GUI
- DirectXTK – DirectX Toolkit
- OpenCV – Computer vision library
References & inspiration
- DX9-Overlay-API
- Creating a render target in DirectX 11
- ion RE Library
- C# – Screen capture and overlays for Direct3D 9, 10 and 11 using API hooks
- HelloD3D12
- Doxygen Awesome 2.5.0 — HTML theme (MIT). Stylesheets and license:
docs/doxygen-awesome/
License
MIT. See LICENSE.
관련 프로젝트 살펴보기
불러오는 중…