Added error checks for renderer hooks

Added errors checks but there are no error correction, If it fails your won't have any overlay at all.
This commit is contained in:
Nemirtingas 2019-08-02 09:07:53 +02:00
parent 3a0d9c55c1
commit 7137fae413
4 changed files with 85 additions and 57 deletions

View File

@ -13,19 +13,18 @@ void DX10_Hook::hook_dx10(UINT SDKVersion)
{ {
if (!_hooked) if (!_hooked)
{ {
PRINT_DEBUG("Hooked DirectX 10\n");
_hooked = true; _hooked = true;
Hook_Manager::Inst().FoundHook(this); Hook_Manager::Inst().FoundHook(this);
IDXGISwapChain* pSwapChain; IDXGISwapChain* pSwapChain;
ID3D10Device* pDevice; ID3D10Device* pDevice;
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {}; DXGI_SWAP_CHAIN_DESC SwapChainDesc = {};
SwapChainDesc.BufferCount = 2; SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Width = 800; SwapChainDesc.BufferDesc.Width = 1;
SwapChainDesc.BufferDesc.Height = 600; SwapChainDesc.BufferDesc.Height = 1;
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60; SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1; SwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.OutputWindow = GetForegroundWindow(); SwapChainDesc.OutputWindow = GetForegroundWindow();
SwapChainDesc.SampleDesc.Count = 1; SwapChainDesc.SampleDesc.Count = 1;
@ -34,19 +33,27 @@ void DX10_Hook::hook_dx10(UINT SDKVersion)
D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, SDKVersion, &SwapChainDesc, &pSwapChain, &pDevice); D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, SDKVersion, &SwapChainDesc, &pSwapChain, &pDevice);
loadFunctions(pDevice, pSwapChain); if (pDevice != nullptr && pSwapChain != nullptr)
{
PRINT_DEBUG("Hooked DirectX 10\n");
loadFunctions(pDevice, pSwapChain);
UnhookAll(); UnhookAll();
BeginHook(); BeginHook();
HookFuncs( HookFuncs(
std::make_pair<void**, void*>(&(PVOID&)DX10_Hook::Present , &DX10_Hook::MyPresent), std::make_pair<void**, void*>(&(PVOID&)DX10_Hook::Present, &DX10_Hook::MyPresent),
std::make_pair<void**, void*>(&(PVOID&)DX10_Hook::ResizeTarget , &DX10_Hook::MyResizeTarget), std::make_pair<void**, void*>(&(PVOID&)DX10_Hook::ResizeTarget, &DX10_Hook::MyResizeTarget),
std::make_pair<void**, void*>(&(PVOID&)DX10_Hook::ResizeBuffers, &DX10_Hook::MyResizeBuffers) std::make_pair<void**, void*>(&(PVOID&)DX10_Hook::ResizeBuffers, &DX10_Hook::MyResizeBuffers)
); );
EndHook(); EndHook();
}
pDevice->Release(); else
pSwapChain->Release(); {
PRINT_DEBUG("Failed to hook DirectX 10\n");
_hooked = false;
}
if(pDevice)pDevice->Release();
if(pSwapChain)pSwapChain->Release();
} }
} }

View File

@ -23,19 +23,18 @@ void DX11_Hook::hook_dx11(UINT SDKVersion)
{ {
if (!_hooked) if (!_hooked)
{ {
PRINT_DEBUG("Hooked DirectX 11\n");
_hooked = true; _hooked = true;
Hook_Manager::Inst().FoundHook(this); Hook_Manager::Inst().FoundHook(this);
IDXGISwapChain* pSwapChain; IDXGISwapChain* pSwapChain;
ID3D11Device* pDevice; ID3D11Device* pDevice;
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {}; DXGI_SWAP_CHAIN_DESC SwapChainDesc = {};
SwapChainDesc.BufferCount = 2; SwapChainDesc.BufferCount = 1;
SwapChainDesc.BufferDesc.Width = 800; SwapChainDesc.BufferDesc.Width = 1;
SwapChainDesc.BufferDesc.Height = 600; SwapChainDesc.BufferDesc.Height = 1;
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60; SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1; SwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.OutputWindow = GetForegroundWindow(); SwapChainDesc.OutputWindow = GetForegroundWindow();
SwapChainDesc.SampleDesc.Count = 1; SwapChainDesc.SampleDesc.Count = 1;
@ -44,19 +43,28 @@ void DX11_Hook::hook_dx11(UINT SDKVersion)
D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, NULL, SDKVersion, &SwapChainDesc, &pSwapChain, &pDevice, NULL, NULL); D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, NULL, SDKVersion, &SwapChainDesc, &pSwapChain, &pDevice, NULL, NULL);
loadFunctions(pDevice, pSwapChain); if (pDevice != nullptr && pSwapChain != nullptr)
{
PRINT_DEBUG("Hooked DirectX 11\n");
loadFunctions(pDevice, pSwapChain);
UnhookAll(); UnhookAll();
BeginHook(); BeginHook();
HookFuncs( HookFuncs(
std::make_pair<void**, void*>(&(PVOID&)DX11_Hook::Present , &DX11_Hook::MyPresent), std::make_pair<void**, void*>(&(PVOID&)DX11_Hook::Present, &DX11_Hook::MyPresent),
std::make_pair<void**, void*>(&(PVOID&)DX11_Hook::ResizeTarget , &DX11_Hook::MyResizeTarget), std::make_pair<void**, void*>(&(PVOID&)DX11_Hook::ResizeTarget, &DX11_Hook::MyResizeTarget),
std::make_pair<void**, void*>(&(PVOID&)DX11_Hook::ResizeBuffers, &DX11_Hook::MyResizeBuffers) std::make_pair<void**, void*>(&(PVOID&)DX11_Hook::ResizeBuffers, &DX11_Hook::MyResizeBuffers)
); );
EndHook(); EndHook();
}
else
{
PRINT_DEBUG("Failed to hook DirectX 11\n");
_hooked = false;
}
pDevice->Release(); if(pDevice) pDevice->Release();
pSwapChain->Release(); if(pSwapChain) pSwapChain->Release();
} }
} }

View File

@ -20,7 +20,6 @@ void DX9_Hook::hook_dx9(UINT SDKVersion)
{ {
if (!_hooked) if (!_hooked)
{ {
PRINT_DEBUG("Hooked DirectX 9\n");
_hooked = true; _hooked = true;
Hook_Manager::Inst().FoundHook(this); Hook_Manager::Inst().FoundHook(this);
@ -36,20 +35,29 @@ void DX9_Hook::hook_dx9(UINT SDKVersion)
pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, NULL, &pDeviceEx); pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, NULL, &pDeviceEx);
loadFunctions(pDeviceEx); if (pDeviceEx != nullptr)
{
PRINT_DEBUG("Hooked DirectX 9\n");
loadFunctions(pDeviceEx);
//UnhookAll(); UnhookAll();
BeginHook(); BeginHook();
HookFuncs( HookFuncs(
std::make_pair<void**, void*>(&(PVOID&)Reset, &DX9_Hook::MyReset), std::make_pair<void**, void*>(&(PVOID&)Reset, &DX9_Hook::MyReset),
std::make_pair<void**, void*>(&(PVOID&)Present, &DX9_Hook::MyPresent), std::make_pair<void**, void*>(&(PVOID&)Present, &DX9_Hook::MyPresent),
std::make_pair<void**, void*>(&(PVOID&)PresentEx, &DX9_Hook::MyPresentEx) std::make_pair<void**, void*>(&(PVOID&)PresentEx, &DX9_Hook::MyPresentEx)
//std::make_pair<void**, void*>(&(PVOID&)EndScene, &DX9_Hook::MyEndScene) //std::make_pair<void**, void*>(&(PVOID&)EndScene, &DX9_Hook::MyEndScene)
); );
EndHook(); EndHook();
}
else
{
PRINT_DEBUG("Failed to DirectX 9\n");
_hooked = false;
}
pDeviceEx->Release(); if(pDeviceEx)pDeviceEx->Release();
pD3D->Release(); if(pD3D)pD3D->Release();
} }
} }

View File

@ -19,23 +19,28 @@ void OpenGL_Hook::hook_ogl()
{ {
if (!_hooked) if (!_hooked)
{ {
PRINT_DEBUG("Hooked OpenGL\n");
_hooked = true; _hooked = true;
Hook_Manager::Inst().FoundHook(this); Hook_Manager::Inst().FoundHook(this);
GLenum err = glewInit(); GLenum err = glewInit();
if (GLEW_OK != err)
if (err == GLEW_OK)
{ {
PRINT_DEBUG("Hooked OpenGL\n");
UnhookAll();
BeginHook();
HookFuncs(
std::make_pair<void**, void*>(&(PVOID&)wglSwapBuffers, &OpenGL_Hook::MywglSwapBuffers)
);
EndHook();
}
else
{
PRINT_DEBUG("Failed to hook OpenGL\n");
/* Problem: glewInit failed, something is seriously wrong. */ /* Problem: glewInit failed, something is seriously wrong. */
PRINT_DEBUG("Error: %s\n", glewGetErrorString(err)); PRINT_DEBUG("Error: %s\n", glewGetErrorString(err));
_hooked = false;
} }
UnhookAll();
BeginHook();
HookFuncs(
std::make_pair<void**, void*>(&(PVOID&)wglSwapBuffers, &OpenGL_Hook::MywglSwapBuffers)
);
EndHook();
} }
} }