From 5d4b4371f3d2edaf411fcb837ce8d96a77a7ca2e Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Fri, 16 Aug 2019 19:21:30 +0200 Subject: [PATCH] Fixed everything that I've forgot --- overlay_experimental/DX10_Hook.cpp | 30 +++++++++----------- overlay_experimental/DX10_Hook.h | 2 ++ overlay_experimental/DX11_Hook.cpp | 30 +++++++++----------- overlay_experimental/DX11_Hook.h | 2 ++ overlay_experimental/DX12_Hook.cpp | 29 ++++++++++--------- overlay_experimental/DX12_Hook.h | 2 ++ overlay_experimental/DX9_Hook.cpp | 45 ++++++++++++------------------ overlay_experimental/DX9_Hook.h | 2 ++ 8 files changed, 66 insertions(+), 76 deletions(-) diff --git a/overlay_experimental/DX10_Hook.cpp b/overlay_experimental/DX10_Hook.cpp index a71135a..3897902 100644 --- a/overlay_experimental/DX10_Hook.cpp +++ b/overlay_experimental/DX10_Hook.cpp @@ -9,8 +9,7 @@ #include #include -// This is created by DX10_Hook::Create, and deleted by the Hook_Manager if not used -static DX10_Hook* hook; +DX10_Hook* DX10_Hook::_inst = nullptr; bool DX10_Hook::start_hook() { @@ -146,20 +145,20 @@ void DX10_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) HRESULT STDMETHODCALLTYPE DX10_Hook::MyPresent(IDXGISwapChain *_this, UINT SyncInterval, UINT Flags) { - hook->prepareForOverlay(_this); - return (_this->*hook->Present)(SyncInterval, Flags); + DX10_Hook::Inst()->prepareForOverlay(_this); + return (_this->*DX10_Hook::Inst()->Present)(SyncInterval, Flags); } HRESULT STDMETHODCALLTYPE DX10_Hook::MyResizeTarget(IDXGISwapChain* _this, const DXGI_MODE_DESC* pNewTargetParameters) { - hook->resetRenderState(); - return (_this->*hook->ResizeTarget)(pNewTargetParameters); + DX10_Hook::Inst()->resetRenderState(); + return (_this->*DX10_Hook::Inst()->ResizeTarget)(pNewTargetParameters); } HRESULT STDMETHODCALLTYPE DX10_Hook::MyResizeBuffers(IDXGISwapChain* _this, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) { - hook->resetRenderState(); - return (_this->*hook->ResizeBuffers)(BufferCount, Width, Height, NewFormat, SwapChainFlags); + DX10_Hook::Inst()->resetRenderState(); + return (_this->*DX10_Hook::Inst()->ResizeBuffers)(BufferCount, Width, Height, NewFormat, SwapChainFlags); } DX10_Hook::DX10_Hook(): @@ -189,18 +188,15 @@ DX10_Hook::~DX10_Hook() if (_hooked) resetRenderState(); - hook = nullptr; + _inst = nullptr; } -void DX10_Hook::Create() +DX10_Hook* DX10_Hook::Inst() { - if (hook == nullptr) - { - hook = new DX10_Hook; - hook->start_hook(); - // Register the hook to the Hook Manager - Hook_Manager::Inst().AddHook(hook); - } + if (_inst == nullptr) + _inst = new DX10_Hook; + + return _inst; } void DX10_Hook::loadFunctions(ID3D10Device *pDevice, IDXGISwapChain *pSwapChain) diff --git a/overlay_experimental/DX10_Hook.h b/overlay_experimental/DX10_Hook.h index ecea403..e66e840 100644 --- a/overlay_experimental/DX10_Hook.h +++ b/overlay_experimental/DX10_Hook.h @@ -13,6 +13,8 @@ public: static constexpr const char *DLL_NAME = "d3d10.dll"; private: + static DX10_Hook* _inst; + // Variables bool initialized; ID3D10Device* pDevice; diff --git a/overlay_experimental/DX11_Hook.cpp b/overlay_experimental/DX11_Hook.cpp index 951fb23..2bde2c0 100644 --- a/overlay_experimental/DX11_Hook.cpp +++ b/overlay_experimental/DX11_Hook.cpp @@ -9,8 +9,7 @@ #include #include -// This is created by DX11_Hook::Create, and deleted by the Hook_Manager if not used -static DX11_Hook* hook; +DX11_Hook* DX11_Hook::_inst = nullptr; HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device** ppDevice, ID3D11DeviceContext** ppContext) { @@ -163,21 +162,21 @@ void DX11_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) HRESULT STDMETHODCALLTYPE DX11_Hook::MyPresent(IDXGISwapChain *_this, UINT SyncInterval, UINT Flags) { - hook->prepareForOverlay(_this); + DX11_Hook::Inst()->prepareForOverlay(_this); - return (_this->*hook->Present)(SyncInterval, Flags); + return (_this->*DX11_Hook::Inst()->Present)(SyncInterval, Flags); } HRESULT STDMETHODCALLTYPE DX11_Hook::MyResizeTarget(IDXGISwapChain* _this, const DXGI_MODE_DESC* pNewTargetParameters) { - hook->resetRenderState(); - return (_this->*hook->ResizeTarget)(pNewTargetParameters); + DX11_Hook::Inst()->resetRenderState(); + return (_this->*DX11_Hook::Inst()->ResizeTarget)(pNewTargetParameters); } HRESULT STDMETHODCALLTYPE DX11_Hook::MyResizeBuffers(IDXGISwapChain* _this, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) { - hook->resetRenderState(); - return (_this->*hook->ResizeBuffers)(BufferCount, Width, Height, NewFormat, SwapChainFlags); + DX11_Hook::Inst()->resetRenderState(); + return (_this->*DX11_Hook::Inst()->ResizeBuffers)(BufferCount, Width, Height, NewFormat, SwapChainFlags); } DX11_Hook::DX11_Hook(): @@ -207,18 +206,15 @@ DX11_Hook::~DX11_Hook() if (_hooked) resetRenderState(); - hook = nullptr; + _inst = nullptr; } -void DX11_Hook::Create() +DX11_Hook* DX11_Hook::Inst() { - if (hook == nullptr) - { - hook = new DX11_Hook; - hook->start_hook(); - // Register the hook to the Hook Manager - Hook_Manager::Inst().AddHook(hook); - } + if (_inst == nullptr) + _inst = new DX11_Hook; + + return _inst; } void DX11_Hook::loadFunctions(ID3D11Device *pDevice, IDXGISwapChain *pSwapChain) diff --git a/overlay_experimental/DX11_Hook.h b/overlay_experimental/DX11_Hook.h index c238167..207252f 100644 --- a/overlay_experimental/DX11_Hook.h +++ b/overlay_experimental/DX11_Hook.h @@ -13,6 +13,8 @@ public: static constexpr const char *DLL_NAME = "d3d11.dll"; private: + static DX11_Hook* _inst; + // Variables bool initialized; ID3D11DeviceContext* pContext; diff --git a/overlay_experimental/DX12_Hook.cpp b/overlay_experimental/DX12_Hook.cpp index af6548f..6f3951a 100644 --- a/overlay_experimental/DX12_Hook.cpp +++ b/overlay_experimental/DX12_Hook.cpp @@ -9,6 +9,8 @@ #include #include +DX12_Hook* DX12_Hook::_inst = nullptr; + bool DX12_Hook::start_hook() { if (!_hooked) @@ -112,21 +114,21 @@ void DX12_Hook::prepareForOverlay(IDXGISwapChain* pSwapChain) HRESULT STDMETHODCALLTYPE DX12_Hook::MyPresent(IDXGISwapChain *_this, UINT SyncInterval, UINT Flags) { - hook->prepareForOverlay(_this); + DX12_Hook::Inst()->prepareForOverlay(_this); - return (_this->*hook->Present)(SyncInterval, Flags); + return (_this->*DX12_Hook::Inst()->Present)(SyncInterval, Flags); } HRESULT STDMETHODCALLTYPE DX12_Hook::MyResizeTarget(IDXGISwapChain* _this, const DXGI_MODE_DESC* pNewTargetParameters) { - hook->resetRenderState(); - return (_this->*hook->ResizeTarget)(pNewTargetParameters); + DX12_Hook::Inst()->resetRenderState(); + return (_this->*DX12_Hook::Inst()->ResizeTarget)(pNewTargetParameters); } HRESULT STDMETHODCALLTYPE DX12_Hook::MyResizeBuffers(IDXGISwapChain* _this, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) { - hook->resetRenderState(); - return (_this->*hook->ResizeBuffers)(BufferCount, Width, Height, NewFormat, SwapChainFlags); + DX12_Hook::Inst()->resetRenderState(); + return (_this->*DX12_Hook::Inst()->ResizeBuffers)(BufferCount, Width, Height, NewFormat, SwapChainFlags); } DX12_Hook::DX12_Hook(): @@ -157,18 +159,15 @@ DX12_Hook::~DX12_Hook() if (_hooked) resetRenderState(); - hook = nullptr; + _inst = nullptr; } -void DX12_Hook::Create() +DX12_Hook* DX12_Hook::Inst() { - if (hook == nullptr) - { - hook = new DX12_Hook; - hook->start_hook(); - // Register the hook to the Hook Manager - Hook_Manager::Inst().AddHook(hook); - } + if (_inst == nullptr) + _inst = new DX12_Hook(); + + return _inst; } void DX12_Hook::loadFunctions(ID3D12Device *pDevice, IDXGISwapChain *pSwapChain) diff --git a/overlay_experimental/DX12_Hook.h b/overlay_experimental/DX12_Hook.h index 2d07fd0..d4e5681 100644 --- a/overlay_experimental/DX12_Hook.h +++ b/overlay_experimental/DX12_Hook.h @@ -13,6 +13,8 @@ public: static constexpr const char *DLL_NAME = "d3d12.dll"; private: + static DX12_Hook* _inst; + // Variables bool initialized; ID3D12CommandAllocator* pCmdAlloc; diff --git a/overlay_experimental/DX9_Hook.cpp b/overlay_experimental/DX9_Hook.cpp index 64f1cbe..26285c3 100644 --- a/overlay_experimental/DX9_Hook.cpp +++ b/overlay_experimental/DX9_Hook.cpp @@ -10,13 +10,7 @@ #include "steam_overlay.h" -static DX9_Hook* hook; - -////////////////////////////////////////////////////////////////// -///////// ///////// -///////// This hook doesn't support game resize for now ///////// -///////// ///////// -////////////////////////////////////////////////////////////////// +DX9_Hook* DX9_Hook::_inst = nullptr; bool DX9_Hook::start_hook() { @@ -144,29 +138,29 @@ void DX9_Hook::prepareForOverlay(IDirect3DDevice9 *pDevice) HRESULT STDMETHODCALLTYPE DX9_Hook::MyReset(IDirect3DDevice9* _this, D3DPRESENT_PARAMETERS* pPresentationParameters) { - hook->resetRenderState(); - return (_this->*hook->Reset)(pPresentationParameters); + DX9_Hook::Inst()->resetRenderState(); + return (_this->*DX9_Hook::Inst()->Reset)(pPresentationParameters); } HRESULT STDMETHODCALLTYPE DX9_Hook::MyEndScene(IDirect3DDevice9* _this) { - if( !hook->uses_present ) - hook->prepareForOverlay(_this); - return (_this->*hook->EndScene)(); + if( !DX9_Hook::Inst()->uses_present ) + DX9_Hook::Inst()->prepareForOverlay(_this); + return (_this->*DX9_Hook::Inst()->EndScene)(); } HRESULT STDMETHODCALLTYPE DX9_Hook::MyPresent(IDirect3DDevice9* _this, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion) { - hook->uses_present = true; - hook->prepareForOverlay(_this); - return (_this->*hook->Present)(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); + DX9_Hook::Inst()->uses_present = true; + DX9_Hook::Inst()->prepareForOverlay(_this); + return (_this->*DX9_Hook::Inst()->Present)(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion); } HRESULT STDMETHODCALLTYPE DX9_Hook::MyPresentEx(IDirect3DDevice9Ex* _this, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) { - hook->uses_present = true; - hook->prepareForOverlay(_this); - return (_this->*hook->PresentEx)(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); + DX9_Hook::Inst()->uses_present = true; + DX9_Hook::Inst()->prepareForOverlay(_this); + return (_this->*DX9_Hook::Inst()->PresentEx)(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags); } DX9_Hook::DX9_Hook(): @@ -204,18 +198,15 @@ DX9_Hook::~DX9_Hook() ImGui::DestroyContext(); } - hook = nullptr; + _inst = nullptr; } -void DX9_Hook::Create() +DX9_Hook* DX9_Hook::Inst() { - if( hook == nullptr ) - { - hook = new DX9_Hook; - hook->start_hook(); - // Register the hook to the Hook Manager - Hook_Manager::Inst().AddHook(hook); - } + if( _inst == nullptr ) + _inst = new DX9_Hook; + + return _inst; } void DX9_Hook::loadFunctions(IDirect3DDevice9Ex* pDeviceEx) diff --git a/overlay_experimental/DX9_Hook.h b/overlay_experimental/DX9_Hook.h index fb1e623..c795fe3 100644 --- a/overlay_experimental/DX9_Hook.h +++ b/overlay_experimental/DX9_Hook.h @@ -13,6 +13,8 @@ public: static constexpr const char *DLL_NAME = "d3d9.dll"; private: + static DX9_Hook* _inst; + // Variables bool initialized; bool uses_present;