mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-23 19:25:35 +08:00
Use LoadLibrary instead of LoadModule
LoadLibrary increase the reference count to the library. So we make sure this library is still loaded when we shut down the hook.
This commit is contained in:
parent
fdeb5912d3
commit
f096a2d8a2
@ -7,6 +7,10 @@
|
||||
|
||||
#include "../detours/detours.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define VC_EXTRALEAN
|
||||
#include <Windows.h>
|
||||
|
||||
Base_Hook::Base_Hook():
|
||||
_hooked(false)
|
||||
{}
|
||||
|
@ -5,10 +5,6 @@
|
||||
|
||||
#ifndef NO_OVERLAY
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define VC_EXTRALEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
@ -17,7 +13,7 @@ class Base_Hook
|
||||
protected:
|
||||
std::vector<std::pair<void**, void*>> _hooked_funcs;
|
||||
|
||||
HMODULE _dll;
|
||||
void* _library;
|
||||
bool _hooked;
|
||||
|
||||
Base_Hook(const Base_Hook&) = delete;
|
||||
|
@ -166,7 +166,7 @@ DX10_Hook::DX10_Hook():
|
||||
pDevice(nullptr),
|
||||
mainRenderTargetView(nullptr)
|
||||
{
|
||||
_dll = GetModuleHandle(DLL_NAME);
|
||||
_library = LoadLibrary(DLL_NAME);
|
||||
|
||||
// Hook to D3D10CreateDevice and D3D10CreateDeviceAndSwapChain so we know when it gets called.
|
||||
// If its called, then DX10 will be used to render the overlay.
|
||||
@ -185,8 +185,9 @@ DX10_Hook::~DX10_Hook()
|
||||
{
|
||||
PRINT_DEBUG("DX10 Hook removed\n");
|
||||
|
||||
if (_hooked)
|
||||
resetRenderState();
|
||||
resetRenderState();
|
||||
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(_library));
|
||||
|
||||
_inst = nullptr;
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ DX11_Hook::DX11_Hook():
|
||||
pContext(nullptr),
|
||||
mainRenderTargetView(nullptr)
|
||||
{
|
||||
_dll = GetModuleHandle(DLL_NAME);
|
||||
_library = LoadLibrary(DLL_NAME);
|
||||
|
||||
// Hook to D3D11CreateDevice and D3D11CreateDeviceAndSwapChain so we know when it gets called.
|
||||
// If its called, then DX11 will be used to render the overlay.
|
||||
@ -203,8 +203,9 @@ DX11_Hook::~DX11_Hook()
|
||||
{
|
||||
PRINT_DEBUG("DX11 Hook removed\n");
|
||||
|
||||
if (_hooked)
|
||||
resetRenderState();
|
||||
resetRenderState();
|
||||
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(_library));
|
||||
|
||||
_inst = nullptr;
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ DX12_Hook::DX12_Hook():
|
||||
pCmdList(nullptr),
|
||||
pDescriptorHeap(nullptr)
|
||||
{
|
||||
_dll = GetModuleHandle(DLL_NAME);
|
||||
_library = GetModuleHandle(DLL_NAME);
|
||||
|
||||
PRINT_DEBUG("Trying to hook DX12 but DX12_Hook is not implemented yet, please report to DEV with the game name.");
|
||||
|
||||
@ -156,8 +156,9 @@ DX12_Hook::~DX12_Hook()
|
||||
{
|
||||
PRINT_DEBUG("DX12 Hook removed\n");
|
||||
|
||||
if (_hooked)
|
||||
resetRenderState();
|
||||
resetRenderState();
|
||||
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(_library));
|
||||
|
||||
_inst = nullptr;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ bool DX9_Hook::start_hook()
|
||||
|
||||
IDirect3D9Ex* pD3D;
|
||||
IDirect3DDevice9Ex* pDeviceEx;
|
||||
decltype(Direct3DCreate9Ex)* Direct3DCreate9Ex = (decltype(Direct3DCreate9Ex))GetProcAddress(_dll, "Direct3DCreate9Ex");
|
||||
decltype(Direct3DCreate9Ex)* Direct3DCreate9Ex = (decltype(Direct3DCreate9Ex))GetProcAddress(reinterpret_cast<HMODULE>(_library), "Direct3DCreate9Ex");
|
||||
|
||||
Direct3DCreate9Ex(D3D_SDK_VERSION, &pD3D);
|
||||
|
||||
@ -171,7 +171,7 @@ DX9_Hook::DX9_Hook():
|
||||
PresentEx(nullptr),
|
||||
Reset(nullptr)
|
||||
{
|
||||
_dll = GetModuleHandle(DLL_NAME);
|
||||
_library = LoadLibrary(DLL_NAME);
|
||||
// Hook to Direct3DCreate9 and Direct3DCreate9Ex so we know when it gets called.
|
||||
// If its called, then DX9 will be used to render the overlay.
|
||||
//Direct3DCreate9 = (decltype(Direct3DCreate9))GetProcAddress(_dll, "Direct3DCreate9");
|
||||
@ -189,7 +189,8 @@ DX9_Hook::~DX9_Hook()
|
||||
{
|
||||
PRINT_DEBUG("DX9 Hook removed\n");
|
||||
|
||||
if (_hooked)
|
||||
//resetRenderState();
|
||||
if (initialized)
|
||||
{
|
||||
//ImGui_ImplDX9_Shutdown(); This makes some games hang when Releasing the D3D9 device (pDevice->Release())
|
||||
// maybe because D3D is already shut down when we try to free the device?
|
||||
@ -198,6 +199,8 @@ DX9_Hook::~DX9_Hook()
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(_library));
|
||||
|
||||
_inst = nullptr;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ OpenGL_Hook::OpenGL_Hook():
|
||||
initialized(false),
|
||||
wglSwapBuffers(nullptr)
|
||||
{
|
||||
_dll = GetModuleHandle(DLL_NAME);
|
||||
_library = LoadLibrary(DLL_NAME);
|
||||
// Hook to wglMakeCurrent so we know when it gets called.
|
||||
// If its called, then OpenGL will be used to render the overlay.
|
||||
//wglMakeCurrent = (decltype(wglMakeCurrent))GetProcAddress(_dll, "wglMakeCurrent");
|
||||
@ -132,12 +132,9 @@ OpenGL_Hook::~OpenGL_Hook()
|
||||
{
|
||||
PRINT_DEBUG("OpenGL Hook removed\n");
|
||||
|
||||
if (_hooked)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplWin32_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
resetRenderState();
|
||||
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(_library));
|
||||
|
||||
_inst = nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user