mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-23 20:38:07 +01:00
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:
parent
3a0d9c55c1
commit
7137fae413
4 changed files with 85 additions and 57 deletions
|
@ -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);
|
||||||
|
|
||||||
|
if (pDevice != nullptr && pSwapChain != nullptr)
|
||||||
|
{
|
||||||
|
PRINT_DEBUG("Hooked DirectX 10\n");
|
||||||
loadFunctions(pDevice, pSwapChain);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
if (pDevice != nullptr && pSwapChain != nullptr)
|
||||||
|
{
|
||||||
|
PRINT_DEBUG("Hooked DirectX 11\n");
|
||||||
loadFunctions(pDevice, pSwapChain);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,9 +35,12 @@ void DX9_Hook::hook_dx9(UINT SDKVersion)
|
||||||
|
|
||||||
pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, ¶ms, NULL, &pDeviceEx);
|
pD3D->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, ¶ms, NULL, &pDeviceEx);
|
||||||
|
|
||||||
|
if (pDeviceEx != nullptr)
|
||||||
|
{
|
||||||
|
PRINT_DEBUG("Hooked DirectX 9\n");
|
||||||
loadFunctions(pDeviceEx);
|
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),
|
||||||
|
@ -47,9 +49,15 @@ void DX9_Hook::hook_dx9(UINT SDKVersion)
|
||||||
//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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,14 @@ 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)
|
|
||||||
{
|
|
||||||
/* Problem: glewInit failed, something is seriously wrong. */
|
|
||||||
PRINT_DEBUG("Error: %s\n", glewGetErrorString(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (err == GLEW_OK)
|
||||||
|
{
|
||||||
|
PRINT_DEBUG("Hooked OpenGL\n");
|
||||||
UnhookAll();
|
UnhookAll();
|
||||||
BeginHook();
|
BeginHook();
|
||||||
HookFuncs(
|
HookFuncs(
|
||||||
|
@ -37,6 +34,14 @@ void OpenGL_Hook::hook_ogl()
|
||||||
);
|
);
|
||||||
EndHook();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGL_Hook::resetRenderState()
|
void OpenGL_Hook::resetRenderState()
|
||||||
|
|
Loading…
Reference in a new issue