2019-07-26 05:21:03 +08:00
|
|
|
#ifndef __INCLUDED_HOOK_BASE_H__
|
|
|
|
#define __INCLUDED_HOOK_BASE_H__
|
|
|
|
|
2019-08-14 20:55:31 +08:00
|
|
|
#include "Base_Hook.h"
|
|
|
|
|
2019-08-14 21:09:57 +08:00
|
|
|
#ifndef NO_OVERLAY
|
2019-08-14 20:55:31 +08:00
|
|
|
|
2019-08-26 22:38:01 +08:00
|
|
|
#include <set>
|
2019-08-20 00:57:55 +08:00
|
|
|
#include <thread>
|
2019-07-26 05:21:03 +08:00
|
|
|
|
2019-08-16 16:36:44 +08:00
|
|
|
#if defined(_WIN32) || defined(WIN32)
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
struct IDXGISwapChain;
|
|
|
|
struct IDirect3DDevice9;
|
|
|
|
struct IDirect3DDevice9Ex;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*/
|
2019-07-26 05:21:03 +08:00
|
|
|
class Hook_Manager
|
|
|
|
{
|
|
|
|
friend class Base_Hook;
|
|
|
|
public:
|
|
|
|
using overlayProc_t = void(*)(int,int);
|
|
|
|
using hookReady_t = void(*)(void*);
|
|
|
|
|
|
|
|
protected:
|
2019-08-16 16:36:44 +08:00
|
|
|
// TODO: If needed, create a second vector with only the renderers hook
|
|
|
|
// Cause actually, a call to FoundRenderer will unhook everything registered except the renderer hook
|
|
|
|
// If you do that, you should consider moving the renderer hooks to its own class and keep this one generic ?
|
2019-08-26 22:38:01 +08:00
|
|
|
std::set<Base_Hook*> _hooks;
|
2019-07-26 05:21:03 +08:00
|
|
|
|
2019-08-20 00:57:55 +08:00
|
|
|
std::thread *_hook_thread;
|
2019-08-18 23:12:57 +08:00
|
|
|
unsigned int _hook_retries;
|
2019-08-16 16:36:44 +08:00
|
|
|
bool _renderer_found; // Is the renderer hooked ?
|
|
|
|
bool _ogl_hooked; // wglMakeCurrent is hooked ? (opengl)
|
|
|
|
Base_Hook* rendererdetect_hook;
|
2019-08-26 22:38:01 +08:00
|
|
|
Base_Hook* game_renderer;
|
2019-07-26 05:21:03 +08:00
|
|
|
class Steam_Overlay* overlay;
|
|
|
|
|
|
|
|
Hook_Manager();
|
|
|
|
virtual ~Hook_Manager();
|
2019-08-16 16:36:44 +08:00
|
|
|
|
2019-08-17 01:10:12 +08:00
|
|
|
// Setup opengl device
|
2019-08-16 16:36:44 +08:00
|
|
|
void hook_opengl();
|
|
|
|
|
2019-08-18 23:12:57 +08:00
|
|
|
bool stop_retry();
|
2019-08-20 00:57:55 +08:00
|
|
|
//void HookLoadLibrary();
|
2019-08-16 16:36:44 +08:00
|
|
|
|
|
|
|
#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64)
|
|
|
|
bool _loadlibrary_hooked; // Are the LoadLibrary functions hooked ?
|
|
|
|
bool _dx9_hooked; // DX9 Present and PresentEx Hooked ?
|
|
|
|
bool _dxgi_hooked; // DXGI Present is hooked ? (DX10, DX11, DX12)
|
|
|
|
|
2019-08-17 01:10:12 +08:00
|
|
|
// DXGIPresent will be used to detect if DX10, DX11 or DX12 should be used for overlay
|
2019-08-26 22:38:01 +08:00
|
|
|
void HookDXGIPresent(IDXGISwapChain* pSwapChain);
|
2019-08-17 01:10:12 +08:00
|
|
|
// DX9 Present and PresentEx will be used to detect if DX9 should be used for overlay
|
2019-08-26 22:38:01 +08:00
|
|
|
void HookDX9Present(IDirect3DDevice9* pDevice, bool ex);
|
2019-08-17 01:10:12 +08:00
|
|
|
// wglMakeCurrent will be used to detect if OpenGL3 should be used for overlay
|
2019-08-27 01:36:07 +08:00
|
|
|
void HookwglMakeCurrent(BOOL (WINAPI *wglMakeCurrent)(HDC, HGLRC));
|
2019-08-17 01:10:12 +08:00
|
|
|
// Setup DX9 Device and get vtable
|
2019-08-16 16:36:44 +08:00
|
|
|
void hook_dx9();
|
2019-08-17 01:10:12 +08:00
|
|
|
// Setup DX10 Device and get vtable
|
2019-08-16 16:36:44 +08:00
|
|
|
void hook_dx10();
|
2019-08-17 01:10:12 +08:00
|
|
|
// Setup DX11 Device and get vtable
|
2019-08-16 16:36:44 +08:00
|
|
|
void hook_dx11();
|
2019-08-17 01:10:12 +08:00
|
|
|
// Setup DX12 Device and get vtable
|
2019-08-16 16:36:44 +08:00
|
|
|
void hook_dx12();
|
2019-08-17 01:10:12 +08:00
|
|
|
|
2019-08-20 00:57:55 +08:00
|
|
|
void create_hook(const char* libname);
|
|
|
|
//void create_hookW(const wchar_t* libname);
|
2019-08-16 16:36:44 +08:00
|
|
|
|
2019-08-20 00:57:55 +08:00
|
|
|
static void find_renderer(Hook_Manager* _this);
|
|
|
|
|
|
|
|
//static HMODULE WINAPI MyLoadLibraryA(LPCTSTR lpLibFileName);
|
|
|
|
//static HMODULE WINAPI MyLoadLibraryW(LPCWSTR lpLibFileName);
|
|
|
|
//static HMODULE WINAPI MyLoadLibraryExA(LPCTSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
|
|
|
|
//static HMODULE WINAPI MyLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
|
2019-08-17 01:10:12 +08:00
|
|
|
// If this is called, then DX10, DX11 or DX12 will be used to render overlay
|
2019-08-16 16:36:44 +08:00
|
|
|
static HRESULT STDMETHODCALLTYPE MyIDXGISwapChain_Present(IDXGISwapChain* _this, UINT SyncInterval, UINT Flags);
|
2019-08-17 01:10:12 +08:00
|
|
|
// If any of theses is called, then DX9 will be used to render overlay
|
2019-08-16 16:36:44 +08:00
|
|
|
static HRESULT STDMETHODCALLTYPE MyPresent(IDirect3DDevice9* _this, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion);
|
|
|
|
static HRESULT STDMETHODCALLTYPE MyPresentEx(IDirect3DDevice9Ex* _this, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags);
|
2019-08-17 01:10:12 +08:00
|
|
|
// If this is called, then OpenGL 3 will be used to render overlay
|
2019-08-16 16:36:44 +08:00
|
|
|
static BOOL WINAPI MywglMakeCurrent(HDC hDC, HGLRC hGLRC);
|
|
|
|
|
|
|
|
#elif defined(__linux__)
|
|
|
|
|
|
|
|
#endif
|
2019-07-26 05:21:03 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static Hook_Manager& Inst();
|
|
|
|
|
2019-08-18 22:22:07 +08:00
|
|
|
void HookRenderer();
|
2019-07-26 05:21:03 +08:00
|
|
|
|
|
|
|
// Set the found hook and free all other hooks
|
2019-08-16 16:36:44 +08:00
|
|
|
void FoundRenderer(Base_Hook *hook);
|
2019-07-26 05:21:03 +08:00
|
|
|
|
2019-08-26 22:38:01 +08:00
|
|
|
inline void AddHook(Base_Hook* hook) { _hooks.insert(hook); }
|
|
|
|
|
|
|
|
inline Base_Hook* get_renderer() const { return game_renderer; }
|
2019-07-26 05:21:03 +08:00
|
|
|
};
|
|
|
|
|
2019-08-14 21:09:57 +08:00
|
|
|
#endif//NO_OVERLAY
|
2019-07-26 05:21:03 +08:00
|
|
|
|
|
|
|
#endif//__INCLUDED_HOOK_BASE_H__
|