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.merge-requests/28/head
parent
3a0d9c55c1
commit
7137fae413
|
@ -13,19 +13,18 @@ void DX10_Hook::hook_dx10(UINT SDKVersion)
|
|||
{
|
||||
if (!_hooked)
|
||||
{
|
||||
PRINT_DEBUG("Hooked DirectX 10\n");
|
||||
_hooked = true;
|
||||
Hook_Manager::Inst().FoundHook(this);
|
||||
|
||||
IDXGISwapChain* pSwapChain;
|
||||
ID3D10Device* pDevice;
|
||||
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {};
|
||||
SwapChainDesc.BufferCount = 2;
|
||||
SwapChainDesc.BufferDesc.Width = 800;
|
||||
SwapChainDesc.BufferDesc.Height = 600;
|
||||
SwapChainDesc.BufferCount = 1;
|
||||
SwapChainDesc.BufferDesc.Width = 1;
|
||||
SwapChainDesc.BufferDesc.Height = 1;
|
||||
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
|
||||
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
SwapChainDesc.OutputWindow = GetForegroundWindow();
|
||||
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);
|
||||
|
||||
loadFunctions(pDevice, pSwapChain);
|
||||
if (pDevice != nullptr && pSwapChain != nullptr)
|
||||
{
|
||||
PRINT_DEBUG("Hooked DirectX 10\n");
|
||||
loadFunctions(pDevice, pSwapChain);
|
||||
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
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::ResizeBuffers, &DX10_Hook::MyResizeBuffers)
|
||||
);
|
||||
EndHook();
|
||||
|
||||
pDevice->Release();
|
||||
pSwapChain->Release();
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
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::ResizeBuffers, &DX10_Hook::MyResizeBuffers)
|
||||
);
|
||||
EndHook();
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_DEBUG("Failed to hook DirectX 10\n");
|
||||
_hooked = false;
|
||||
}
|
||||
if(pDevice)pDevice->Release();
|
||||
if(pSwapChain)pSwapChain->Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,19 +23,18 @@ void DX11_Hook::hook_dx11(UINT SDKVersion)
|
|||
{
|
||||
if (!_hooked)
|
||||
{
|
||||
PRINT_DEBUG("Hooked DirectX 11\n");
|
||||
_hooked = true;
|
||||
Hook_Manager::Inst().FoundHook(this);
|
||||
|
||||
IDXGISwapChain* pSwapChain;
|
||||
ID3D11Device* pDevice;
|
||||
DXGI_SWAP_CHAIN_DESC SwapChainDesc = {};
|
||||
SwapChainDesc.BufferCount = 2;
|
||||
SwapChainDesc.BufferDesc.Width = 800;
|
||||
SwapChainDesc.BufferDesc.Height = 600;
|
||||
SwapChainDesc.BufferCount = 1;
|
||||
SwapChainDesc.BufferDesc.Width = 1;
|
||||
SwapChainDesc.BufferDesc.Height = 1;
|
||||
SwapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
|
||||
SwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
|
||||
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
SwapChainDesc.OutputWindow = GetForegroundWindow();
|
||||
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);
|
||||
|
||||
loadFunctions(pDevice, pSwapChain);
|
||||
if (pDevice != nullptr && pSwapChain != nullptr)
|
||||
{
|
||||
PRINT_DEBUG("Hooked DirectX 11\n");
|
||||
loadFunctions(pDevice, pSwapChain);
|
||||
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
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::ResizeBuffers, &DX11_Hook::MyResizeBuffers)
|
||||
);
|
||||
EndHook();
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
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::ResizeBuffers, &DX11_Hook::MyResizeBuffers)
|
||||
);
|
||||
EndHook();
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_DEBUG("Failed to hook DirectX 11\n");
|
||||
_hooked = false;
|
||||
}
|
||||
|
||||
pDevice->Release();
|
||||
pSwapChain->Release();
|
||||
if(pDevice) pDevice->Release();
|
||||
if(pSwapChain) pSwapChain->Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ void DX9_Hook::hook_dx9(UINT SDKVersion)
|
|||
{
|
||||
if (!_hooked)
|
||||
{
|
||||
PRINT_DEBUG("Hooked DirectX 9\n");
|
||||
_hooked = true;
|
||||
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, ¶ms, NULL, &pDeviceEx);
|
||||
|
||||
loadFunctions(pDeviceEx);
|
||||
if (pDeviceEx != nullptr)
|
||||
{
|
||||
PRINT_DEBUG("Hooked DirectX 9\n");
|
||||
loadFunctions(pDeviceEx);
|
||||
|
||||
//UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
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&)PresentEx, &DX9_Hook::MyPresentEx)
|
||||
//std::make_pair<void**, void*>(&(PVOID&)EndScene, &DX9_Hook::MyEndScene)
|
||||
);
|
||||
EndHook();
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
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&)PresentEx, &DX9_Hook::MyPresentEx)
|
||||
//std::make_pair<void**, void*>(&(PVOID&)EndScene, &DX9_Hook::MyEndScene)
|
||||
);
|
||||
EndHook();
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_DEBUG("Failed to DirectX 9\n");
|
||||
_hooked = false;
|
||||
}
|
||||
|
||||
pDeviceEx->Release();
|
||||
pD3D->Release();
|
||||
if(pDeviceEx)pDeviceEx->Release();
|
||||
if(pD3D)pD3D->Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,23 +19,28 @@ void OpenGL_Hook::hook_ogl()
|
|||
{
|
||||
if (!_hooked)
|
||||
{
|
||||
PRINT_DEBUG("Hooked OpenGL\n");
|
||||
_hooked = true;
|
||||
Hook_Manager::Inst().FoundHook(this);
|
||||
|
||||
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. */
|
||||
PRINT_DEBUG("Error: %s\n", glewGetErrorString(err));
|
||||
_hooked = false;
|
||||
}
|
||||
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
std::make_pair<void**, void*>(&(PVOID&)wglSwapBuffers, &OpenGL_Hook::MywglSwapBuffers)
|
||||
);
|
||||
EndHook();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue