Moved window hooks to its own class

Every class has a job. Overlay is to show an overlay not to hook windows functions.
Hook_Manager's job is to manage hooks and should not contain a reference to the overlay. (It should not contains any reference to directX or OpenGL either but I'll see that later... Maybe)
This makes the overlay code much cleaner and "could" be used in Linux as well.
This commit is contained in:
Nemirtingas 2019-08-18 16:22:07 +02:00
parent f096a2d8a2
commit 5b0306dccc
11 changed files with 281 additions and 201 deletions

View file

@ -39,7 +39,7 @@ HRESULT STDMETHODCALLTYPE Hook_Manager::MyIDXGISwapChain_Present(IDXGISwapChain*
{
// Hook failed, start over
delete static_cast<Base_Hook*>(hook);
Hook_Manager::Inst().HookRenderer(Hook_Manager::Inst().GetOverlay());
Hook_Manager::Inst().HookRenderer();
}
else
{
@ -57,7 +57,7 @@ HRESULT STDMETHODCALLTYPE Hook_Manager::MyIDXGISwapChain_Present(IDXGISwapChain*
{
// Hook failed, start over
delete static_cast<Base_Hook*>(hook);
Hook_Manager::Inst().HookRenderer(Hook_Manager::Inst().GetOverlay());
Hook_Manager::Inst().HookRenderer();
}
else
{
@ -72,7 +72,7 @@ HRESULT STDMETHODCALLTYPE Hook_Manager::MyIDXGISwapChain_Present(IDXGISwapChain*
{
// Hook failed, start over
delete static_cast<Base_Hook*>(hook);
Hook_Manager::Inst().HookRenderer(Hook_Manager::Inst().GetOverlay());
Hook_Manager::Inst().HookRenderer();
}
else
{
@ -93,7 +93,7 @@ HRESULT STDMETHODCALLTYPE Hook_Manager::MyPresent(IDirect3DDevice9* _this, CONST
{
// Hook failed, start over
delete static_cast<Base_Hook*>(hook);
Hook_Manager::Inst().HookRenderer(Hook_Manager::Inst().GetOverlay());
Hook_Manager::Inst().HookRenderer();
}
else
{
@ -110,7 +110,7 @@ HRESULT STDMETHODCALLTYPE Hook_Manager::MyPresentEx(IDirect3DDevice9Ex* _this, C
{
// Hook failed, start over
delete static_cast<Base_Hook*>(hook);
Hook_Manager::Inst().HookRenderer(Hook_Manager::Inst().GetOverlay());
Hook_Manager::Inst().HookRenderer();
}
else
{
@ -127,7 +127,7 @@ BOOL WINAPI Hook_Manager::MywglMakeCurrent(HDC hDC, HGLRC hGLRC)
{
// Hook failed, start over
delete static_cast<Base_Hook*>(hook);
Hook_Manager::Inst().HookRenderer(Hook_Manager::Inst().GetOverlay());
Hook_Manager::Inst().HookRenderer();
}
else
{
@ -391,16 +391,6 @@ void Hook_Manager::HookLoadLibrary()
}
}
void Hook_Manager::ChangeGameWindow(HWND hWnd) const
{
overlay->HookReady(hWnd);
}
void Hook_Manager::CallOverlayProc(int width, int height) const
{
overlay->OverlayProc(width, height);
}
#endif
void Hook_Manager::UnHookAllRendererDetector()
@ -422,8 +412,6 @@ void Hook_Manager::UnHookAllRendererDetector()
Hook_Manager::Hook_Manager():
#ifdef STEAM_WIN32
_game_hwnd(nullptr),
_game_wndproc(nullptr),
_loadlibrary_hooked(false),
_dxgi_hooked(false),
_dx9_hooked(false),
@ -444,9 +432,8 @@ Hook_Manager& Hook_Manager::Inst()
return hook;
}
void Hook_Manager::HookRenderer(Steam_Overlay *ovlay)
void Hook_Manager::HookRenderer()
{
overlay = ovlay;
#ifdef STEAM_WIN32
HookLoadLibrary();
std::vector<std::string> const libraries = { "opengl32.dll", "d3d12.dll", "d3d11.dll", "d3d10.dll", "d3d9.dll" };