Пример #1
0
void DetourDXGI(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetDXGIModule();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"DXGI", base, module))
  {
    auto& render_helper = GetRenderHelperInterface();
    auto const render_offsets = render_helper.GetRenderOffsets();
    auto const dxgi_offsets = &render_offsets->dxgi_offsets_;
    auto const offset_base = reinterpret_cast<std::uint8_t*>(base);

    if (!dxgi_offsets->present_)
    {
      HADESMEM_DETAIL_TRACE_FORMAT_A(
        "WARNING! No DXGI offsets. Skipping hooks.");
      return;
    }

    auto const present_fn = offset_base + dxgi_offsets->present_;
    DetourFunc(process,
               "IDXGISwapChain::Present",
               GetIDXGISwapChainPresentDetour(),
               reinterpret_cast<IDXGISwapChain_Present_Fn>(present_fn),
               IDXGISwapChain_Present_Detour);

    auto const resize_buffers_fn = offset_base + dxgi_offsets->resize_buffers_;
    DetourFunc(
      process,
      "IDXGISwapChain::ResizeBuffers",
      GetIDXGISwapChainResizeBuffersDetour(),
      reinterpret_cast<IDXGISwapChain_ResizeBuffers_Fn>(resize_buffers_fn),
      IDXGISwapChain_ResizeBuffers_Detour);

    auto const present_1_fn = offset_base + dxgi_offsets->present_1_;
    DetourFunc(process,
               "IDXGISwapChain1::Present1",
               GetIDXGISwapChain1Present1Detour(),
               reinterpret_cast<IDXGISwapChain1_Present1_Fn>(present_1_fn),
               IDXGISwapChain1_Present1_Detour);
  }
}
Пример #2
0
void DetourD3D9(HMODULE base)
{
  auto const& process = GetThisProcess();
  auto& module = GetD3D9Module();
  auto& helper = GetHelperInterface();
  if (helper.CommonDetourModule(process, L"D3D9", base, module))
  {
    auto& render_helper = GetRenderHelperInterface();
    auto const render_offsets = render_helper.GetRenderOffsets();
    auto const d3d9_offsets = &render_offsets->d3d9_offsets_;
    auto const offset_base = reinterpret_cast<std::uint8_t*>(base);

    if (!d3d9_offsets->add_ref_)
    {
      HADESMEM_DETAIL_TRACE_FORMAT_A(
        "WARNING! No D3D9 offsets. Skipping hooks.");
      return;
    }

    auto const add_ref_fn = offset_base + d3d9_offsets->add_ref_;
    DetourFunc(process,
               "IDirect3DDevice9::AddRef",
               GetIDirect3DDevice9AddRefDetour(),
               reinterpret_cast<IDirect3DDevice9_AddRef_Fn>(add_ref_fn),
               IDirect3DDevice9_AddRef_Detour);

    auto const release_fn = offset_base + d3d9_offsets->release_;
    DetourFunc(process,
               "IDirect3DDevice9::Release",
               GetIDirect3DDevice9ReleaseDetour(),
               reinterpret_cast<IDirect3DDevice9_Release_Fn>(release_fn),
               IDirect3DDevice9_Release_Detour);

    auto const present_fn = offset_base + d3d9_offsets->present_;
    DetourFunc(process,
               "IDirect3DDevice9::Present",
               GetIDirect3DDevice9PresentDetour(),
               reinterpret_cast<IDirect3DDevice9_Present_Fn>(present_fn),
               IDirect3DDevice9_Present_Detour);

    auto const reset_fn = offset_base + d3d9_offsets->reset_;
    DetourFunc(process,
               "IDirect3DDevice9::Reset",
               GetIDirect3DDevice9ResetDetour(),
               reinterpret_cast<IDirect3DDevice9_Reset_Fn>(reset_fn),
               IDirect3DDevice9_Reset_Detour);

    auto const end_scene_fn = offset_base + d3d9_offsets->end_scene_;
    DetourFunc(process,
               "IDirect3DDevice9::EndScene",
               GetIDirect3DDevice9EndSceneDetour(),
               reinterpret_cast<IDirect3DDevice9_EndScene_Fn>(end_scene_fn),
               IDirect3DDevice9_EndScene_Detour);

    auto const present_ex_fn = offset_base + d3d9_offsets->present_ex_;
    DetourFunc(process,
               "IDirect3DDevice9Ex::PresentEx",
               GetIDirect3DDevice9ExPresentExDetour(),
               reinterpret_cast<IDirect3DDevice9Ex_PresentEx_Fn>(present_ex_fn),
               IDirect3DDevice9Ex_PresentEx_Detour);

    auto const reset_ex_fn = offset_base + d3d9_offsets->reset_ex_;
    DetourFunc(process,
               "IDirect3DDevice9Ex::ResetEx",
               GetIDirect3DDevice9ExResetExDetour(),
               reinterpret_cast<IDirect3DDevice9Ex_ResetEx_Fn>(reset_ex_fn),
               IDirect3DDevice9Ex_ResetEx_Detour);

    auto const swap_chain_present_fn =
      offset_base + d3d9_offsets->swap_chain_present_;
    DetourFunc(
      process,
      "IDirect3DSwapChain9::Present",
      GetIDirect3DSwapChain9PresentDetour(),
      reinterpret_cast<IDirect3DSwapChain9_Present_Fn>(swap_chain_present_fn),
      IDirect3DSwapChain9_Present_Detour);
  }
}