2019-07-31 20:19:44 +00:00
|
|
|
#include "../dll/base.h"
|
2019-08-14 12:55:31 +00:00
|
|
|
|
2019-08-14 13:09:57 +00:00
|
|
|
#ifndef NO_OVERLAY
|
2019-08-14 12:55:31 +00:00
|
|
|
|
2019-07-31 20:19:44 +00:00
|
|
|
#include "OpenGL_Hook.h"
|
|
|
|
#include "Hook_Manager.h"
|
|
|
|
|
|
|
|
#include <imgui.h>
|
|
|
|
#include <impls/imgui_impl_win32.h>
|
|
|
|
#include <impls/imgui_impl_opengl3.h>
|
|
|
|
|
|
|
|
#include <GL/glew.h>
|
|
|
|
|
2019-08-16 08:28:23 +00:00
|
|
|
#include "steam_overlay.h"
|
2019-07-31 20:19:44 +00:00
|
|
|
|
2019-08-16 17:10:12 +00:00
|
|
|
OpenGL_Hook* OpenGL_Hook::_inst = nullptr;
|
2019-07-31 20:19:44 +00:00
|
|
|
|
2019-08-16 17:10:12 +00:00
|
|
|
bool OpenGL_Hook::start_hook()
|
2019-07-31 20:19:44 +00:00
|
|
|
{
|
|
|
|
if (!_hooked)
|
|
|
|
{
|
2019-08-16 08:28:23 +00:00
|
|
|
Hook_Manager::Inst().FoundRenderer(this);
|
2019-07-31 20:19:44 +00:00
|
|
|
|
|
|
|
GLenum err = glewInit();
|
2019-08-02 07:07:53 +00:00
|
|
|
|
|
|
|
if (err == GLEW_OK)
|
|
|
|
{
|
2019-08-16 08:28:23 +00:00
|
|
|
_hooked = true;
|
2019-08-02 07:07:53 +00:00
|
|
|
PRINT_DEBUG("Hooked OpenGL\n");
|
|
|
|
UnhookAll();
|
|
|
|
BeginHook();
|
|
|
|
HookFuncs(
|
|
|
|
std::make_pair<void**, void*>(&(PVOID&)wglSwapBuffers, &OpenGL_Hook::MywglSwapBuffers)
|
|
|
|
);
|
|
|
|
EndHook();
|
|
|
|
}
|
|
|
|
else
|
2019-07-31 20:19:44 +00:00
|
|
|
{
|
2019-08-02 07:07:53 +00:00
|
|
|
PRINT_DEBUG("Failed to hook OpenGL\n");
|
2019-07-31 20:19:44 +00:00
|
|
|
/* Problem: glewInit failed, something is seriously wrong. */
|
|
|
|
PRINT_DEBUG("Error: %s\n", glewGetErrorString(err));
|
2019-08-16 17:10:12 +00:00
|
|
|
return false;
|
2019-07-31 20:19:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-16 17:10:12 +00:00
|
|
|
return true;
|
2019-07-31 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenGL_Hook::resetRenderState()
|
|
|
|
{
|
|
|
|
if (initialized)
|
|
|
|
{
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplWin32_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
|
|
|
|
initialized = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 12:55:31 +00:00
|
|
|
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
|
2019-07-31 20:19:44 +00:00
|
|
|
void OpenGL_Hook::prepareForOverlay(HDC hDC)
|
|
|
|
{
|
|
|
|
HWND hWnd = WindowFromDC(hDC);
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
GetClientRect(hWnd, &rect);
|
|
|
|
|
2019-08-16 08:36:44 +00:00
|
|
|
if (hWnd != Hook_Manager::Inst().GetOverlay()->GetGameHwnd())
|
|
|
|
resetRenderState();
|
|
|
|
|
2019-07-31 20:19:44 +00:00
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
ImGui::CreateContext();
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
io.IniFilename = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
ImGui_ImplWin32_Init(hWnd);
|
|
|
|
ImGui_ImplOpenGL3_Init();
|
2019-08-16 16:30:55 +00:00
|
|
|
Hook_Manager::Inst().ChangeGameWindow(hWnd);
|
2019-07-31 20:19:44 +00:00
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
ImGui_ImplWin32_NewFrame();
|
|
|
|
|
|
|
|
ImGui::NewFrame();
|
|
|
|
|
|
|
|
Hook_Manager::Inst().CallOverlayProc(rect.right, rect.bottom);
|
|
|
|
|
|
|
|
ImGui::EndFrame();
|
|
|
|
|
|
|
|
ImGui::Render();
|
|
|
|
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// OpenGL Initialization functions
|
2019-08-16 08:36:44 +00:00
|
|
|
//BOOL WINAPI OpenGL_Hook::MywglMakeCurrent(HDC hDC, HGLRC hGLRC)
|
|
|
|
//{
|
|
|
|
// auto res = hook->wglMakeCurrent(hDC, hGLRC);
|
|
|
|
// hook->hook_ogl();
|
|
|
|
// return res;
|
|
|
|
//}
|
2019-07-31 20:19:44 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
BOOL WINAPI OpenGL_Hook::MywglSwapBuffers(HDC hDC)
|
|
|
|
{
|
2019-08-16 17:10:12 +00:00
|
|
|
OpenGL_Hook::Inst()->prepareForOverlay(hDC);
|
|
|
|
return OpenGL_Hook::Inst()->wglSwapBuffers(hDC);
|
2019-07-31 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OpenGL_Hook::OpenGL_Hook():
|
|
|
|
initialized(false),
|
|
|
|
wglSwapBuffers(nullptr)
|
|
|
|
{
|
|
|
|
_dll = GetModuleHandle(DLL_NAME);
|
|
|
|
// Hook to wglMakeCurrent so we know when it gets called.
|
|
|
|
// If its called, then OpenGL will be used to render the overlay.
|
2019-08-16 08:36:44 +00:00
|
|
|
//wglMakeCurrent = (decltype(wglMakeCurrent))GetProcAddress(_dll, "wglMakeCurrent");
|
|
|
|
//wglSwapBuffers = (decltype(wglSwapBuffers))GetProcAddress(_dll, "wglSwapBuffers");
|
|
|
|
//
|
|
|
|
//BeginHook();
|
|
|
|
//HookFuncs(
|
|
|
|
// std::make_pair<void**, void*>(&(PVOID&)wglMakeCurrent, &OpenGL_Hook::MywglMakeCurrent)
|
|
|
|
//);
|
|
|
|
//EndHook();
|
2019-07-31 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OpenGL_Hook::~OpenGL_Hook()
|
|
|
|
{
|
|
|
|
PRINT_DEBUG("OpenGL Hook removed\n");
|
|
|
|
|
|
|
|
if (_hooked)
|
|
|
|
{
|
|
|
|
ImGui_ImplOpenGL3_Shutdown();
|
|
|
|
ImGui_ImplWin32_Shutdown();
|
|
|
|
ImGui::DestroyContext();
|
|
|
|
}
|
|
|
|
|
2019-08-16 17:10:12 +00:00
|
|
|
_inst = nullptr;
|
2019-07-31 20:19:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 17:10:12 +00:00
|
|
|
OpenGL_Hook* OpenGL_Hook::Inst()
|
2019-07-31 20:19:44 +00:00
|
|
|
{
|
2019-08-16 17:10:12 +00:00
|
|
|
if (_inst == nullptr)
|
|
|
|
_inst = new OpenGL_Hook;
|
|
|
|
|
|
|
|
return _inst;
|
2019-08-14 12:55:31 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 13:09:57 +00:00
|
|
|
#endif//NO_OVERLAY
|