Loading...
Loading...
Guide for graphics API hooking and rendering techniques for DirectX, OpenGL, and Vulkan. Use this skill when working with graphics hooks, overlay rendering, shader manipulation, or game rendering pipeline analysis.
npx skill4agent add gmh5225/awesome-game-security graphics-api-hooking// Key functions to hook
IDirect3DDevice9::EndScene
IDirect3DDevice9::Reset
IDirect3DDevice9::Present// Key functions to hook
IDXGISwapChain::Present
ID3D11DeviceContext::DrawIndexed
ID3D11DeviceContext::Draw// Key functions to hook
IDXGISwapChain::Present
ID3D12CommandQueue::ExecuteCommandLists// DX11 Example
typedef HRESULT(__stdcall* Present)(IDXGISwapChain*, UINT, UINT);
Present oPresent;
HRESULT __stdcall hkPresent(IDXGISwapChain* swapChain, UINT syncInterval, UINT flags) {
// Render overlay here
return oPresent(swapChain, syncInterval, flags);
}
// Hook via vtable
void* swapChainVtable = *(void**)swapChain;
oPresent = (Present)swapChainVtable[8]; // Present is index 8wglSwapBuffers
glDrawElements
glDrawArrays
glBegin/glEnd (legacy)typedef BOOL(WINAPI* wglSwapBuffers_t)(HDC);
wglSwapBuffers_t owglSwapBuffers;
BOOL WINAPI hkwglSwapBuffers(HDC hdc) {
// Render overlay
return owglSwapBuffers(hdc);
}vkQueuePresentKHR
vkCreateSwapchainKHR
vkCmdDraw
vkCmdDrawIndexed// In Present hook
ImGui_ImplDX11_Init(device, context);
ImGui_ImplWin32_Init(hwnd);
// Render
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
// Your rendering code
ImGui::Begin("Overlay");
// ...
ImGui::End();
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());// Required for ImGui input
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
return true;
return CallWindowProc(oWndProc, hWnd, msg, wParam, lParam);
}1. Create transparent window
2. Set WS_EX_LAYERED | WS_EX_TRANSPARENT
3. Use SetLayeredWindowAttributes
4. Render with GDI+/D2D
5. Position over game window- Hook Desktop Window Manager
- Render in DWM composition
- Higher privilege requirements
- Better anti-detection- Hook Steam's overlay functions
- Use existing overlay infrastructure
- Requires Steam running- Hook GeForce Experience overlay
- Native-looking overlay
- May require specific drivers// Disable depth testing
OMSetDepthStencilState(depthDisabledState, 0);
// Or in pixel shader
float4 PSMain(VS_OUTPUT input) : SV_Target {
// Always pass depth test
return float4(1, 0, 0, 0.5); // Red transparent
}// Replace model shader
float4 PSChams(VS_OUTPUT input) : SV_Target {
if (isEnemy) {
return float4(1, 0, 0, 1); // Red
}
return float4(0, 1, 0, 1); // Green
}D3DXVECTOR3 WorldToScreen(D3DXVECTOR3 pos, D3DXMATRIX viewProjection) {
D3DXVECTOR4 clipCoords;
D3DXVec3Transform(&clipCoords, &pos, &viewProjection);
if (clipCoords.w < 0.1f) return invalid;
D3DXVECTOR3 NDC;
NDC.x = clipCoords.x / clipCoords.w;
NDC.y = clipCoords.y / clipCoords.w;
D3DXVECTOR3 screen;
screen.x = (viewport.Width / 2) * (NDC.x + 1);
screen.y = (viewport.Height / 2) * (1 - NDC.y);
return screen;
}- From device constants
- Pattern scanning
- Engine-specific locations
- Reverse engineered addresses- VTable integrity checks
- Code section verification
- Call stack analysis- Trampoline hooks
- Hardware breakpoints
- Timing obfuscation1. Minimize state changes
2. Batch draw calls
3. Use instancing
4. Cache resources
5. Profile regularly- Flickering: Double buffer sync
- Artifacts: Clear state properly
- Performance: Reduce overdrawhttps://raw.githubusercontent.com/gmh5225/awesome-game-security/refs/heads/main/README.md