Skip to content
Proyek

Tentang

Framework hooking API DirectX

Gim dan emulasi

Cara angka ini diukur

Yang dapat Anda lakukan

  • 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.

Pertumbuhan bintang terukur

dalam 24 jam
0
dalam 7 hari
+1
dalam 15 hari
+1
dalam 1 bulan
Mengumpulkan riwayat

Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.

README.md

Asli

HydraHook

API-Hooking and rendering framework for DirectX-based games.

Build status Documentation GitHub All Releases Discord Website GitHub followers Mastodon Follow

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 FreeLibrary when 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. The FreeLibrary hook stops and destroys the engine before entering the loader, then exits the unloading thread via FreeLibraryAndExitThread(..., TRUE) so remote-thread ejectors observe a TRUE result.

  • 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.

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

  1. Clone the repository and initialize submodules: git submodule update --init --recursive
  2. From the repository root, run prepare-deps.bat (both x86 and x64), prepare-deps.bat x64, or prepare-deps.bat Win32. With no arguments the script locates Visual Studio via vswhere and sets up the compiler itself.
  3. Open HydraHook.slnx and build Release_LIB (static library, samples, and tests) or Release (standalone HydraHook.dll). Release_LIB writes the static library to bin\Release_LIB\<arch>\HydraHook.lib; Release writes bin\<arch>\HydraHook.dll. The outputs do not collide.

Static library vs. DLL

  • Static library (Release_LIB, recommended for injection): link HydraHook.lib into your host DLL. The engine lives inside that one DLL, so you inject a single file. No separate HydraHook.dll has to be shipped, loaded first, or kept in sync with your host. All samples use this route.
  • DLL (Release): your host DLL imports HydraHook.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's ResettableInitGuard (once-only init, reset, retry-on-failure, concurrent callers) and WindowProcHook (validation, forwarding, destroy cleanup, external subclass chaining, re-entrancy, cross-thread hook churn). HookActivityTracker::reset, ResettableOnce, Hook re-apply, and the HydraHookEngineUnhook/HydraHookEngineRehook handle 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 with d3d12.dll preloaded alongside d3d11.dll. It loads HydraHookTestHost.dll (which enables D3D10, D3D11, and D3D12 hooking) from the same directory, checks GameVersion, Present / Present1 / ResizeBuffers callbacks, verifies unhooked Present / ResizeBuffers calls still succeed after HydraHookEngineUnhook, and completes a full HydraHookEngineRehook cycle 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 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

Half-Life 2 Demo

DirectX 9 Ex

Castlevania: Lords of Shadow, 32-Bit

Castlevania: Lords of Shadow Demo

DirectX 10

Bioshock 2, 32-Bit

Bioshock 2 Demo

DirectX 11

Road Redemption, 64-Bit

Road Redemption Demo

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

BEHEMOTH Demo

Sources

Dependencies

This project uses the following libraries (via vcpkg):

Core library only:

Sample projects only:

References & inspiration

License

MIT. See LICENSE.

Jelajahi proyek terkait

Memuat…