Fixed memory leak

merge-requests/28/head
Nemirtingas 2019-08-25 21:22:25 +02:00
parent 42a22dd4bb
commit cd8c5fc2ea
7 changed files with 20 additions and 11 deletions

View File

@ -12,6 +12,7 @@
#include <Windows.h> #include <Windows.h>
Base_Hook::Base_Hook(): Base_Hook::Base_Hook():
_library(nullptr),
_hooked(false) _hooked(false)
{} {}

View File

@ -12,6 +12,7 @@ DX10_Hook* DX10_Hook::_inst = nullptr;
bool DX10_Hook::start_hook() bool DX10_Hook::start_hook()
{ {
bool res = true;
if (!_hooked) if (!_hooked)
{ {
if (!Windows_Hook::Inst().start_hook()) if (!Windows_Hook::Inst().start_hook())
@ -63,12 +64,12 @@ bool DX10_Hook::start_hook()
else else
{ {
PRINT_DEBUG("Failed to hook DirectX 10\n"); PRINT_DEBUG("Failed to hook DirectX 10\n");
return false; res = false;
} }
if(pDevice)pDevice->Release(); if(pDevice)pDevice->Release();
if(pSwapChain)pSwapChain->Release(); if(pSwapChain)pSwapChain->Release();
} }
return true; return res;
} }
void DX10_Hook::resetRenderState() void DX10_Hook::resetRenderState()

View File

@ -22,6 +22,7 @@ HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11Device**
bool DX11_Hook::start_hook() bool DX11_Hook::start_hook()
{ {
bool res = true;
if (!_hooked) if (!_hooked)
{ {
if (!Windows_Hook::Inst().start_hook()) if (!Windows_Hook::Inst().start_hook())
@ -73,13 +74,13 @@ bool DX11_Hook::start_hook()
else else
{ {
PRINT_DEBUG("Failed to hook DirectX 11\n"); PRINT_DEBUG("Failed to hook DirectX 11\n");
return false; res = false;
} }
if(pDevice) pDevice->Release(); if(pDevice) pDevice->Release();
if(pSwapChain) pSwapChain->Release(); if(pSwapChain) pSwapChain->Release();
} }
return true; return res;
} }
void DX11_Hook::resetRenderState() void DX11_Hook::resetRenderState()

View File

@ -14,6 +14,7 @@ DX12_Hook* DX12_Hook::_inst = nullptr;
bool DX12_Hook::start_hook() bool DX12_Hook::start_hook()
{ {
bool res = true;
if (!_hooked) if (!_hooked)
{ {
if (!Windows_Hook::Inst().start_hook()) if (!Windows_Hook::Inst().start_hook())
@ -79,7 +80,7 @@ bool DX12_Hook::start_hook()
else else
{ {
PRINT_DEBUG("Failed to hook DirectX 12\n"); PRINT_DEBUG("Failed to hook DirectX 12\n");
return false; res = false;
} }
} }
} }
@ -89,7 +90,7 @@ bool DX12_Hook::start_hook()
if (pCommandQueue) pCommandQueue->Release(); if (pCommandQueue) pCommandQueue->Release();
if (pDevice) pDevice->Release(); if (pDevice) pDevice->Release();
} }
return true; return res;
} }
void DX12_Hook::resetRenderState() void DX12_Hook::resetRenderState()

View File

@ -14,6 +14,7 @@ DX9_Hook* DX9_Hook::_inst = nullptr;
bool DX9_Hook::start_hook() bool DX9_Hook::start_hook()
{ {
bool res = true;
if (!_hooked) if (!_hooked)
{ {
if (!Windows_Hook::Inst().start_hook()) if (!Windows_Hook::Inst().start_hook())
@ -60,13 +61,13 @@ bool DX9_Hook::start_hook()
else else
{ {
PRINT_DEBUG("Failed to DirectX 9\n"); PRINT_DEBUG("Failed to DirectX 9\n");
return false; res = false;
} }
if(pDeviceEx)pDeviceEx->Release(); if(pDeviceEx)pDeviceEx->Release();
if(pD3D)pD3D->Release(); if(pD3D)pD3D->Release();
} }
return true; return res;
} }
void DX9_Hook::resetRenderState() void DX9_Hook::resetRenderState()

View File

@ -16,6 +16,7 @@ OpenGL_Hook* OpenGL_Hook::_inst = nullptr;
bool OpenGL_Hook::start_hook() bool OpenGL_Hook::start_hook()
{ {
bool res = true;
if (!_hooked) if (!_hooked)
{ {
if (!Windows_Hook::Inst().start_hook()) if (!Windows_Hook::Inst().start_hook())
@ -46,7 +47,7 @@ bool OpenGL_Hook::start_hook()
PRINT_DEBUG("Failed to hook OpenGL\n"); 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));
return false; res = false;
} }
} }
return true; return true;

View File

@ -37,6 +37,7 @@ HWND GetGameWindow()
bool Windows_Hook::start_hook() bool Windows_Hook::start_hook()
{ {
bool res = true;
if (!_hooked) if (!_hooked)
{ {
GetRawInputBuffer = ::GetRawInputBuffer; GetRawInputBuffer = ::GetRawInputBuffer;
@ -51,7 +52,7 @@ bool Windows_Hook::start_hook()
_hooked = true; _hooked = true;
} }
return true; return res;
} }
void Windows_Hook::resetRenderState() void Windows_Hook::resetRenderState()
@ -171,7 +172,7 @@ Windows_Hook::Windows_Hook() :
GetRawInputBuffer(nullptr), GetRawInputBuffer(nullptr),
GetRawInputData(nullptr) GetRawInputData(nullptr)
{ {
//_library = LoadLibrary(DLL_NAME);
} }
Windows_Hook::~Windows_Hook() Windows_Hook::~Windows_Hook()
@ -179,6 +180,8 @@ Windows_Hook::~Windows_Hook()
PRINT_DEBUG("Windows Hook removed\n"); PRINT_DEBUG("Windows Hook removed\n");
resetRenderState(); resetRenderState();
//FreeLibrary(reinterpret_cast<HMODULE>(_library));
} }
Windows_Hook& Windows_Hook::Inst() Windows_Hook& Windows_Hook::Inst()