@ -29,111 +29,73 @@ decltype(wglMakeCurrent)* _wglMakeCurrent;
HRESULT STDMETHODCALLTYPE Hook_Manager : : MyIDXGISwapChain_Present ( IDXGISwapChain * _this , UINT SyncInterval , UINT Flags )
HRESULT STDMETHODCALLTYPE Hook_Manager : : MyIDXGISwapChain_Present ( IDXGISwapChain * _this , UINT SyncInterval , UINT Flags )
{
{
IUnknown * pDevice ;
Hook_Manager & inst = Hook_Manager : : Inst ( ) ;
_this - > GetDevice ( __uuidof ( ID3D10Device ) , ( void * * ) & pDevice ) ;
if ( ! inst . stop_retry ( ) )
{
IUnknown * pDevice ;
_this - > GetDevice ( __uuidof ( ID3D10Device ) , ( void * * ) & pDevice ) ;
if ( pDevice )
if ( pDevice )
{
{
Hook_Manager : : Inst ( ) . UnHookAllRendererDetector ( ) ;
DX10_Hook * hook = DX10_Hook : : Inst ( ) ;
DX10_Hook * hook = DX10_Hook : : Inst ( ) ;
if ( ! hook - > start_hook ( ) )
if ( hook - > start_hook ( ) )
{
inst . AddHook ( hook ) ;
// Hook failed, start over
delete static_cast < Base_Hook * > ( hook ) ;
Hook_Manager : : Inst ( ) . HookRenderer ( ) ;
}
else
{
Hook_Manager : : Inst ( ) . AddHook ( hook ) ;
}
}
}
else
else
{
{
_this - > GetDevice ( __uuidof ( ID3D11Device ) , ( void * * ) & pDevice ) ;
_this - > GetDevice ( __uuidof ( ID3D11Device ) , ( void * * ) & pDevice ) ;
if ( pDevice )
if ( pDevice )
{
{
Hook_Manager : : Inst ( ) . UnHookAllRendererDetector ( ) ;
DX11_Hook * hook = DX11_Hook : : Inst ( ) ;
DX11_Hook * hook = DX11_Hook : : Inst ( ) ;
if ( ! hook - > start_hook ( ) )
if ( hook - > start_hook ( ) )
{
inst . AddHook ( hook ) ;
// Hook failed, start over
delete static_cast < Base_Hook * > ( hook ) ;
Hook_Manager : : Inst ( ) . HookRenderer ( ) ;
}
else
{
Hook_Manager : : Inst ( ) . AddHook ( hook ) ;
}
}
}
else
else
{
{
_this - > GetDevice ( __uuidof ( ID3D12Device ) , ( void * * ) & pDevice ) ;
_this - > GetDevice ( __uuidof ( ID3D12Device ) , ( void * * ) & pDevice ) ;
DX12_Hook * hook = DX12_Hook : : Inst ( ) ;
DX12_Hook * hook = DX12_Hook : : Inst ( ) ;
if ( ! hook - > start_hook ( ) )
if ( hook - > start_hook ( ) )
{
inst . AddHook ( hook ) ;
// Hook failed, start over
delete static_cast < Base_Hook * > ( hook ) ;
Hook_Manager : : Inst ( ) . HookRenderer ( ) ;
}
else
{
Hook_Manager : : Inst ( ) . AddHook ( hook ) ;
}
}
}
}
}
if ( pDevice ) pDevice - > Release ( ) ;
if ( pDevice ) pDevice - > Release ( ) ;
}
return ( _this - > * _IDXGISwapChain_Present ) ( SyncInterval , Flags ) ;
return ( _this - > * _IDXGISwapChain_Present ) ( SyncInterval , Flags ) ;
}
}
HRESULT STDMETHODCALLTYPE Hook_Manager : : MyPresent ( IDirect3DDevice9 * _this , CONST RECT * pSourceRect , CONST RECT * pDestRect , HWND hDestWindowOverride , CONST RGNDATA * pDirtyRegion )
HRESULT STDMETHODCALLTYPE Hook_Manager : : MyPresent ( IDirect3DDevice9 * _this , CONST RECT * pSourceRect , CONST RECT * pDestRect , HWND hDestWindowOverride , CONST RGNDATA * pDirtyRegion )
{
{
Hook_Manager : : Inst ( ) . UnHookAllRendererDetector ( ) ;
Hook_Manager & inst = Hook_Manager : : Inst ( ) ;
DX9_Hook * hook = DX9_Hook : : Inst ( ) ;
if ( ! inst . stop_retry ( ) )
if ( ! hook - > start_hook ( ) )
{
{
// Hook failed, start over
DX9_Hook * hook = DX9_Hook : : Inst ( ) ;
delete static_cast < Base_Hook * > ( hook ) ;
if ( hook - > start_hook ( ) )
Hook_Manager : : Inst ( ) . HookRenderer ( ) ;
inst . AddHook ( hook ) ;
}
else
{
Hook_Manager : : Inst ( ) . AddHook ( hook ) ;
}
}
return ( _this - > * _IDirect3DDevice9_Present ) ( pSourceRect , pDestRect , hDestWindowOverride , pDirtyRegion ) ;
return ( _this - > * _IDirect3DDevice9_Present ) ( pSourceRect , pDestRect , hDestWindowOverride , pDirtyRegion ) ;
}
}
HRESULT STDMETHODCALLTYPE Hook_Manager : : MyPresentEx ( IDirect3DDevice9Ex * _this , CONST RECT * pSourceRect , CONST RECT * pDestRect , HWND hDestWindowOverride , CONST RGNDATA * pDirtyRegion , DWORD dwFlags )
HRESULT STDMETHODCALLTYPE Hook_Manager : : MyPresentEx ( IDirect3DDevice9Ex * _this , CONST RECT * pSourceRect , CONST RECT * pDestRect , HWND hDestWindowOverride , CONST RGNDATA * pDirtyRegion , DWORD dwFlags )
{
{
Hook_Manager : : Inst ( ) . UnHookAllRendererDetector ( ) ;
Hook_Manager & inst = Hook_Manager : : Inst ( ) ;
DX9_Hook * hook = DX9_Hook : : Inst ( ) ;
if ( ! inst . stop_retry ( ) )
if ( ! hook - > start_hook ( ) )
{
{
// Hook failed, start over
DX9_Hook * hook = DX9_Hook : : Inst ( ) ;
delete static_cast < Base_Hook * > ( hook ) ;
if ( hook - > start_hook ( ) )
Hook_Manager : : Inst ( ) . HookRenderer ( ) ;
inst . AddHook ( hook ) ;
}
else
{
Hook_Manager : : Inst ( ) . AddHook ( hook ) ;
}
}
return ( _this - > * _IDirect3DDevice9Ex_PresentEx ) ( pSourceRect , pDestRect , hDestWindowOverride , pDirtyRegion , dwFlags ) ;
return ( _this - > * _IDirect3DDevice9Ex_PresentEx ) ( pSourceRect , pDestRect , hDestWindowOverride , pDirtyRegion , dwFlags ) ;
}
}
BOOL WINAPI Hook_Manager : : MywglMakeCurrent ( HDC hDC , HGLRC hGLRC )
BOOL WINAPI Hook_Manager : : MywglMakeCurrent ( HDC hDC , HGLRC hGLRC )
{
{
Hook_Manager : : Inst ( ) . UnHookAllRendererDetector ( ) ;
Hook_Manager & inst = Hook_Manager : : Inst ( ) ;
OpenGL_Hook * hook = OpenGL_Hook : : Inst ( ) ;
if ( ! inst . stop_retry ( ) )
if ( ! hook - > start_hook ( ) )
{
// Hook failed, start over
delete static_cast < Base_Hook * > ( hook ) ;
Hook_Manager : : Inst ( ) . HookRenderer ( ) ;
}
else
{
{
Hook_Manager : : Inst ( ) . AddHook ( hook ) ;
OpenGL_Hook * hook = OpenGL_Hook : : Inst ( ) ;
if ( hook - > start_hook ( ) )
inst . AddHook ( hook ) ;
}
}
return _wglMakeCurrent ( hDC , hGLRC ) ;
return _wglMakeCurrent ( hDC , hGLRC ) ;
}
}
@ -369,6 +331,20 @@ HMODULE WINAPI Hook_Manager::MyLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFil
return res ;
return res ;
}
}
bool Hook_Manager : : stop_retry ( )
{
// Retry 200 times, we look for rendering functions so its actually: "retry for 200 frames"
bool stop = + + _hook_retries > = 200 ;
if ( stop )
{
PRINT_DEBUG ( " We found a renderer but couldn't hook it, aborting overlay hook. \n " ) ;
FoundRenderer ( nullptr ) ;
}
return stop ;
}
void Hook_Manager : : HookLoadLibrary ( )
void Hook_Manager : : HookLoadLibrary ( )
{
{
if ( ! _renderer_found & & ! _loadlibrary_hooked )
if ( ! _renderer_found & & ! _loadlibrary_hooked )
@ -393,24 +369,8 @@ void Hook_Manager::HookLoadLibrary()
# endif
# endif
void Hook_Manager : : UnHookAllRendererDetector ( )
{
auto it = std : : find ( _hooks . begin ( ) , _hooks . end ( ) , rendererdetect_hook ) ;
if ( it ! = _hooks . end ( ) )
{
_hooks . erase ( it ) ;
delete rendererdetect_hook ;
rendererdetect_hook = nullptr ;
}
_loadlibrary_hooked = false ;
_ogl_hooked = false ;
# ifdef STEAM_WIN32
_dxgi_hooked = _dx9_hooked = false ;
# endif
}
Hook_Manager : : Hook_Manager ( ) :
Hook_Manager : : Hook_Manager ( ) :
_hook_retries ( 0 ) ,
# ifdef STEAM_WIN32
# ifdef STEAM_WIN32
_loadlibrary_hooked ( false ) ,
_loadlibrary_hooked ( false ) ,
_dxgi_hooked ( false ) ,
_dxgi_hooked ( false ) ,