mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2025-12-05 11:44:53 +01:00
Update Nemirtingas overlay to latest.
This commit is contained in:
parent
df94c38b0f
commit
c17fb0c931
82 changed files with 48737 additions and 59872 deletions
|
|
@ -1,151 +1,164 @@
|
|||
/*
|
||||
* Copyright (C) 2019-2020 Nemirtingas
|
||||
* This file is part of the ingame overlay project
|
||||
*
|
||||
* The ingame overlay project is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* The ingame overlay project is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the ingame overlay project; if not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glad/gl.h>
|
||||
|
||||
#include "OpenGLX_Hook.h"
|
||||
#include "X11_Hook.h"
|
||||
#include "../Renderer_Detector.h"
|
||||
#include "../dll/dll.h"
|
||||
|
||||
#ifdef __LINUX__
|
||||
#ifdef EMU_OVERLAY
|
||||
|
||||
#include <imgui.h>
|
||||
#include <impls/imgui_impl_opengl3.h>
|
||||
|
||||
#include "../steam_overlay.h"
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
|
||||
OpenGLX_Hook* OpenGLX_Hook::_inst = nullptr;
|
||||
|
||||
bool OpenGLX_Hook::start_hook()
|
||||
constexpr decltype(OpenGLX_Hook::DLL_NAME) OpenGLX_Hook::DLL_NAME;
|
||||
|
||||
bool OpenGLX_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
{
|
||||
bool res = true;
|
||||
if (!hooked)
|
||||
if (!_Hooked)
|
||||
{
|
||||
if (!X11_Hook::Inst()->start_hook())
|
||||
if (glXSwapBuffers == nullptr)
|
||||
{
|
||||
SPDLOG_WARN("Failed to hook OpenGLX: Rendering functions missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!X11_Hook::Inst()->StartHook(key_combination_callback))
|
||||
return false;
|
||||
|
||||
GLenum err = glewInit();
|
||||
_X11Hooked = true;
|
||||
|
||||
if (err == GLEW_OK)
|
||||
{
|
||||
PRINT_DEBUG("Hooked OpenGLX\n");
|
||||
SPDLOG_INFO("Hooked OpenGLX");
|
||||
|
||||
hooked = true;
|
||||
Renderer_Detector::Inst().renderer_found(this);
|
||||
_Hooked = true;
|
||||
|
||||
/*
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
std::make_pair<void**, void*>(&(void*&)_glXSwapBuffers, (void*)&OpenGLX_Hook::MyglXSwapBuffers)
|
||||
);
|
||||
EndHook();
|
||||
*/
|
||||
|
||||
get_steam_client()->steam_overlay->HookReady();
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT_DEBUG("Failed to hook OpenGLX\n");
|
||||
/* Problem: glewInit failed, something is seriously wrong. */
|
||||
PRINT_DEBUG("Error: %s\n", glewGetErrorString(err));
|
||||
res = false;
|
||||
}
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
std::make_pair<void**, void*>((void**)&glXSwapBuffers, (void*)&OpenGLX_Hook::MyglXSwapBuffers)
|
||||
);
|
||||
EndHook();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenGLX_Hook::resetRenderState()
|
||||
bool OpenGLX_Hook::IsStarted()
|
||||
{
|
||||
if (initialized)
|
||||
return _Hooked;
|
||||
}
|
||||
|
||||
void OpenGLX_Hook::_ResetRenderState()
|
||||
{
|
||||
if (_Initialized)
|
||||
{
|
||||
OverlayHookReady(false);
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
X11_Hook::Inst()->resetRenderState();
|
||||
X11_Hook::Inst()->ResetRenderState();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
glXDestroyContext(display, context);
|
||||
display = nullptr;
|
||||
initialized = false;
|
||||
glXDestroyContext(_Display, _Context);
|
||||
_Display = nullptr;
|
||||
_Initialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Try to make this function and overlay's proc as short as possible or it might affect game's fps.
|
||||
void OpenGLX_Hook::prepareForOverlay(Display* display, GLXDrawable drawable)
|
||||
void OpenGLX_Hook::_PrepareForOverlay(Display* display, GLXDrawable drawable)
|
||||
{
|
||||
PRINT_DEBUG("Called SwapBuffer hook");
|
||||
|
||||
if( (Window)drawable != X11_Hook::Inst()->get_game_wnd() )
|
||||
X11_Hook::Inst()->resetRenderState();
|
||||
|
||||
if( ! initialized )
|
||||
if( !_Initialized )
|
||||
{
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.IniFilename = NULL;
|
||||
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
int attributes[] = { //can't be const b/c X11 doesn't like it. Not sure if that's intentional or just stupid.
|
||||
GLX_RGBA, //apparently nothing comes after this?
|
||||
GLX_RED_SIZE, 8,
|
||||
GLX_GREEN_SIZE, 8,
|
||||
GLX_BLUE_SIZE, 8,
|
||||
GLX_ALPHA_SIZE, 8,
|
||||
//Ideally, the size would be 32 (or at least 24), but I have actually seen
|
||||
// this size (on a modern OS even).
|
||||
GLX_DEPTH_SIZE, 16,
|
||||
GLX_DOUBLEBUFFER, True,
|
||||
None
|
||||
};
|
||||
//int attributes[] = { //can't be const b/c X11 doesn't like it. Not sure if that's intentional or just stupid.
|
||||
// GLX_RGBA, //apparently nothing comes after this?
|
||||
// GLX_RED_SIZE, 8,
|
||||
// GLX_GREEN_SIZE, 8,
|
||||
// GLX_BLUE_SIZE, 8,
|
||||
// GLX_ALPHA_SIZE, 8,
|
||||
// //Ideally, the size would be 32 (or at least 24), but I have actually seen
|
||||
// // this size (on a modern OS even).
|
||||
// GLX_DEPTH_SIZE, 16,
|
||||
// GLX_DOUBLEBUFFER, True,
|
||||
// None
|
||||
//};
|
||||
//
|
||||
//XVisualInfo* visual_info = glXChooseVisual(_Display, DefaultScreen(_Display), attributes);
|
||||
//if (visual_info == nullptr)
|
||||
// return;
|
||||
//
|
||||
//_Context = glXCreateContext(_Display, visual_info, nullptr, True);
|
||||
//if (_Context == nullptr)
|
||||
// return;
|
||||
|
||||
XVisualInfo* visual_info = glXChooseVisual(display, DefaultScreen(display), attributes);
|
||||
_Display = display;
|
||||
|
||||
context = glXCreateContext(display, visual_info, nullptr, True);
|
||||
this->display = display;
|
||||
|
||||
get_steam_client()->steam_overlay->CreateFonts();
|
||||
|
||||
initialized = true;
|
||||
_Initialized = true;
|
||||
OverlayHookReady(true);
|
||||
}
|
||||
|
||||
auto oldContext = glXGetCurrentContext();
|
||||
//auto oldContext = glXGetCurrentContext();
|
||||
|
||||
glXMakeCurrent(display, drawable, context);
|
||||
//glXMakeCurrent(_Display, drawable, _Context);
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
X11_Hook::Inst()->prepareForOverlay(display, (Window)drawable);
|
||||
if (ImGui_ImplOpenGL3_NewFrame() && X11_Hook::Inst()->PrepareForOverlay(_Display, (Window)drawable))
|
||||
{
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
OverlayProc();
|
||||
|
||||
get_steam_client()->steam_overlay->OverlayProc();
|
||||
ImGui::Render();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
glXMakeCurrent(display, drawable, oldContext);
|
||||
//glXMakeCurrent(_Display, drawable, oldContext);
|
||||
}
|
||||
|
||||
void OpenGLX_Hook::MyglXSwapBuffers(Display* display, GLXDrawable drawable)
|
||||
{
|
||||
OpenGLX_Hook::Inst()->prepareForOverlay(display, drawable);
|
||||
OpenGLX_Hook::Inst()->_glXSwapBuffers(display, drawable);
|
||||
OpenGLX_Hook::Inst()->_PrepareForOverlay(display, drawable);
|
||||
OpenGLX_Hook::Inst()->glXSwapBuffers(display, drawable);
|
||||
}
|
||||
|
||||
OpenGLX_Hook::OpenGLX_Hook():
|
||||
initialized(false),
|
||||
hooked(false),
|
||||
_glXSwapBuffers(nullptr)
|
||||
_Initialized(false),
|
||||
_Hooked(false),
|
||||
_X11Hooked(false),
|
||||
glXSwapBuffers(nullptr)
|
||||
{
|
||||
//_library = dlopen(DLL_NAME);
|
||||
}
|
||||
|
||||
OpenGLX_Hook::~OpenGLX_Hook()
|
||||
{
|
||||
PRINT_DEBUG("OpenGLX Hook removed\n");
|
||||
SPDLOG_INFO("OpenGLX Hook removed");
|
||||
|
||||
if (initialized)
|
||||
if (_X11Hooked)
|
||||
delete X11_Hook::Inst();
|
||||
|
||||
if (_Initialized)
|
||||
{
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
glXDestroyContext(display, context);
|
||||
glXDestroyContext(_Display, _Context);
|
||||
}
|
||||
|
||||
//dlclose(_library);
|
||||
|
|
@ -161,15 +174,62 @@ OpenGLX_Hook* OpenGLX_Hook::Inst()
|
|||
return _inst;
|
||||
}
|
||||
|
||||
const char* OpenGLX_Hook::get_lib_name() const
|
||||
std::string OpenGLX_Hook::GetLibraryName() const
|
||||
{
|
||||
return DLL_NAME;
|
||||
return LibraryName;
|
||||
}
|
||||
|
||||
void OpenGLX_Hook::loadFunctions(decltype(glXSwapBuffers)* pfnglXSwapBuffers)
|
||||
void OpenGLX_Hook::LoadFunctions(decltype(::glXSwapBuffers)* pfnglXSwapBuffers)
|
||||
{
|
||||
_glXSwapBuffers = pfnglXSwapBuffers;
|
||||
glXSwapBuffers = pfnglXSwapBuffers;
|
||||
}
|
||||
|
||||
#endif//EMU_OVERLAY
|
||||
#endif//__LINUX__
|
||||
std::weak_ptr<uint64_t> OpenGLX_Hook::CreateImageResource(const void* image_data, uint32_t width, uint32_t height)
|
||||
{
|
||||
GLuint* texture = new GLuint(0);
|
||||
glGenTextures(1, texture);
|
||||
if (glGetError() != GL_NO_ERROR)
|
||||
{
|
||||
delete texture;
|
||||
return std::shared_ptr<uint64_t>(nullptr);
|
||||
}
|
||||
|
||||
// Save old texture id
|
||||
GLint oldTex;
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldTex);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, *texture);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
// Upload pixels into texture
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, oldTex);
|
||||
|
||||
auto ptr = std::shared_ptr<uint64_t>((uint64_t*)texture, [](uint64_t* handle)
|
||||
{
|
||||
if (handle != nullptr)
|
||||
{
|
||||
GLuint* texture = (GLuint*)handle;
|
||||
glDeleteTextures(1, texture);
|
||||
delete texture;
|
||||
}
|
||||
});
|
||||
|
||||
_ImageResources.emplace(ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void OpenGLX_Hook::ReleaseImageResource(std::weak_ptr<uint64_t> resource)
|
||||
{
|
||||
auto ptr = resource.lock();
|
||||
if (ptr)
|
||||
{
|
||||
auto it = _ImageResources.find(ptr);
|
||||
if (it != _ImageResources.end())
|
||||
_ImageResources.erase(it);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,33 @@
|
|||
#ifndef __INCLUDED_OPENGLX_HOOK_H__
|
||||
#define __INCLUDED_OPENGLX_HOOK_H__
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Nemirtingas
|
||||
* This file is part of the ingame overlay project
|
||||
*
|
||||
* The ingame overlay project is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* The ingame overlay project is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the ingame overlay project; if not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../Base_Hook.h"
|
||||
#pragma once
|
||||
|
||||
#include <ingame_overlay/Renderer_Hook.h>
|
||||
|
||||
#include "../internal_includes.h"
|
||||
|
||||
#ifdef __LINUX__
|
||||
#ifdef EMU_OVERLAY
|
||||
#include <GL/glew.h>
|
||||
#include <GL/glx.h>
|
||||
|
||||
class OpenGLX_Hook : public Base_Hook
|
||||
class OpenGLX_Hook :
|
||||
public Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
static constexpr const char *DLL_NAME = "libGLX.so";
|
||||
|
|
@ -17,33 +36,35 @@ private:
|
|||
static OpenGLX_Hook* _inst;
|
||||
|
||||
// Variables
|
||||
bool hooked;
|
||||
bool initialized;
|
||||
Display *display;
|
||||
GLXContext context;
|
||||
bool _Hooked;
|
||||
bool _X11Hooked;
|
||||
bool _Initialized;
|
||||
Display *_Display;
|
||||
GLXContext _Context;
|
||||
std::set<std::shared_ptr<uint64_t>> _ImageResources;
|
||||
|
||||
// Functions
|
||||
OpenGLX_Hook();
|
||||
|
||||
void resetRenderState();
|
||||
void prepareForOverlay(Display* display, GLXDrawable drawable);
|
||||
void _ResetRenderState();
|
||||
void _PrepareForOverlay(Display* display, GLXDrawable drawable);
|
||||
|
||||
// Hook to render functions
|
||||
|
||||
|
||||
decltype(glXSwapBuffers)* _glXSwapBuffers;
|
||||
decltype(::glXSwapBuffers)* glXSwapBuffers;
|
||||
|
||||
public:
|
||||
std::string LibraryName;
|
||||
|
||||
static void MyglXSwapBuffers(Display* display, GLXDrawable drawable);
|
||||
|
||||
virtual ~OpenGLX_Hook();
|
||||
|
||||
bool start_hook();
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool IsStarted();
|
||||
static OpenGLX_Hook* Inst();
|
||||
virtual const char* get_lib_name() const;
|
||||
void loadFunctions(decltype(glXSwapBuffers)* pfnglXSwapBuffers);
|
||||
};
|
||||
virtual std::string GetLibraryName() const;
|
||||
void LoadFunctions(decltype(::glXSwapBuffers)* pfnglXSwapBuffers);
|
||||
|
||||
#endif//EMU_OVERLAY
|
||||
#endif//__LINUX__
|
||||
#endif//__INCLUDED_OPENGLX_HOOK_H__
|
||||
virtual std::weak_ptr<uint64_t> CreateImageResource(const void* image_data, uint32_t width, uint32_t height);
|
||||
virtual void ReleaseImageResource(std::weak_ptr<uint64_t> resource);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,54 +1,107 @@
|
|||
#include "X11_Hook.h"
|
||||
#include "../Renderer_Detector.h"
|
||||
#include "../dll/dll.h"
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Nemirtingas
|
||||
* This file is part of the ingame overlay project
|
||||
*
|
||||
* The ingame overlay project is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* The ingame overlay project is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the ingame overlay project; if not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef __LINUX__
|
||||
#ifdef EMU_OVERLAY
|
||||
#include "X11_Hook.h"
|
||||
|
||||
#include <imgui.h>
|
||||
#include <impls/linux/imgui_impl_x11.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include <backends/imgui_impl_x11.h>
|
||||
#include <System/Library.h>
|
||||
|
||||
extern int ImGui_ImplX11_EventHandler(XEvent &event);
|
||||
|
||||
constexpr decltype(X11_Hook::DLL_NAME) X11_Hook::DLL_NAME;
|
||||
|
||||
X11_Hook* X11_Hook::_inst = nullptr;
|
||||
|
||||
bool X11_Hook::start_hook()
|
||||
bool X11_Hook::StartHook(std::function<bool(bool)>& _key_combination_callback)
|
||||
{
|
||||
bool res = true;
|
||||
if (!hooked)
|
||||
if (!_Hooked)
|
||||
{
|
||||
PRINT_DEBUG("Hooked X11\n");
|
||||
hooked = true;
|
||||
void* hX11 = System::Library::GetLibraryHandle(DLL_NAME);
|
||||
if (hX11 == nullptr)
|
||||
{
|
||||
SPDLOG_WARN("Failed to hook X11: Cannot find {}", DLL_NAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
System::Library::Library libX11;
|
||||
LibraryName = System::Library::GetLibraryPath(hX11);
|
||||
|
||||
if (!libX11.OpenLibrary(LibraryName, false))
|
||||
{
|
||||
SPDLOG_WARN("Failed to hook X11: Cannot load {}", LibraryName);
|
||||
return false;
|
||||
}
|
||||
|
||||
XEventsQueued = libX11.GetSymbol<decltype(::XEventsQueued)>("XEventsQueued");
|
||||
XPending = libX11.GetSymbol<decltype(::XPending)>("XPending");
|
||||
|
||||
if (XPending == nullptr || XEventsQueued == nullptr)
|
||||
{
|
||||
SPDLOG_WARN("Failed to hook X11: Cannot load functions.({}, {})", DLL_NAME, (void*)XEventsQueued, (void*)XPending);
|
||||
return false;
|
||||
}
|
||||
SPDLOG_INFO("Hooked X11");
|
||||
|
||||
_KeyCombinationCallback = std::move(_key_combination_callback);
|
||||
_Hooked = true;
|
||||
|
||||
UnhookAll();
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
std::make_pair<void**, void*>(&(void*&)XEventsQueued, (void*)&X11_Hook::MyXEventsQueued),
|
||||
std::make_pair<void**, void*>(&(void*&)XPending, (void*)&X11_Hook::MyXPending)
|
||||
);
|
||||
EndHook();
|
||||
}
|
||||
return res;
|
||||
return true;
|
||||
}
|
||||
|
||||
void X11_Hook::resetRenderState()
|
||||
void X11_Hook::ResetRenderState()
|
||||
{
|
||||
if (initialized)
|
||||
if (_Initialized)
|
||||
{
|
||||
game_wnd = 0;
|
||||
initialized = false;
|
||||
_GameWnd = 0;
|
||||
_Initialized = false;
|
||||
ImGui_ImplX11_Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
void X11_Hook::prepareForOverlay(Display *display, Window wnd)
|
||||
bool X11_Hook::PrepareForOverlay(Display *display, Window wnd)
|
||||
{
|
||||
if (!initialized)
|
||||
if(!_Hooked)
|
||||
return false;
|
||||
|
||||
if (_GameWnd != wnd)
|
||||
ResetRenderState();
|
||||
|
||||
if (!_Initialized)
|
||||
{
|
||||
ImGui_ImplX11_Init(display, (void*)wnd);
|
||||
_GameWnd = wnd;
|
||||
|
||||
game_wnd = wnd;
|
||||
|
||||
initialized = true;
|
||||
_Initialized = true;
|
||||
}
|
||||
|
||||
ImGui_ImplX11_NewFrame();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -63,65 +116,56 @@ bool IgnoreEvent(XEvent &event)
|
|||
case ButtonPress: case ButtonRelease:
|
||||
// Mouse move
|
||||
case MotionNotify:
|
||||
// Copy to clipboard request
|
||||
case SelectionRequest:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int X11_Hook::check_for_overlay(Display *d, int num_events)
|
||||
int X11_Hook::_CheckForOverlay(Display *d, int num_events)
|
||||
{
|
||||
static Time prev_time = {};
|
||||
|
||||
X11_Hook* inst = Inst();
|
||||
|
||||
if( inst->initialized )
|
||||
if( inst->_Initialized )
|
||||
{
|
||||
XEvent event;
|
||||
while(num_events)
|
||||
{
|
||||
//inst->_XPeekEvent(d, &event);
|
||||
XPeekEvent(d, &event);
|
||||
bool skip_input = inst->_KeyCombinationCallback(false);
|
||||
|
||||
XPeekEvent(d, &event);
|
||||
ImGui_ImplX11_EventHandler(event);
|
||||
|
||||
Steam_Overlay* overlay = get_steam_client()->steam_overlay;
|
||||
bool show = overlay->ShowOverlay();
|
||||
// Is the event is a key press
|
||||
if (event.type == KeyPress)
|
||||
{
|
||||
// Tab is pressed and was not pressed before
|
||||
//if (event.xkey.keycode == inst->_XKeysymToKeycode(d, XK_Tab) && event.xkey.state & ShiftMask)
|
||||
if (event.xkey.keycode == XKeysymToKeycode(d, XK_Tab) && event.xkey.state & ShiftMask)
|
||||
{
|
||||
// if key TAB is held, don't make the overlay flicker :p
|
||||
if( event.xkey.time != prev_time)
|
||||
if (event.xkey.time != prev_time)
|
||||
{
|
||||
overlay->ShowOverlay(!overlay->ShowOverlay());
|
||||
|
||||
if (overlay->ShowOverlay())
|
||||
show = true;
|
||||
skip_input = true;
|
||||
inst->_KeyCombinationCallback(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//else if(event.type == KeyRelease && event.xkey.keycode == inst->_XKeysymToKeycode(d, XK_Tab))
|
||||
else if(event.type == KeyRelease && event.xkey.keycode == XKeysymToKeycode(d, XK_Tab))
|
||||
{
|
||||
prev_time = event.xkey.time;
|
||||
}
|
||||
|
||||
if (show)
|
||||
if (!skip_input || !IgnoreEvent(event))
|
||||
{
|
||||
ImGui_ImplX11_EventHandler(event);
|
||||
|
||||
if (IgnoreEvent(event))
|
||||
{
|
||||
//inst->_XNextEvent(d, &event);
|
||||
XNextEvent(d, &event);
|
||||
--num_events;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
else
|
||||
if(num_events)
|
||||
num_events = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
XNextEvent(d, &event);
|
||||
--num_events;
|
||||
}
|
||||
}
|
||||
return num_events;
|
||||
|
|
@ -131,33 +175,23 @@ int X11_Hook::MyXEventsQueued(Display *display, int mode)
|
|||
{
|
||||
X11_Hook* inst = X11_Hook::Inst();
|
||||
|
||||
int res = inst->_XEventsQueued(display, mode);
|
||||
int res = inst->XEventsQueued(display, mode);
|
||||
|
||||
if( res )
|
||||
{
|
||||
res = inst->check_for_overlay(display, res);
|
||||
res = inst->_CheckForOverlay(display, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int X11_Hook::MyXNextEvent(Display* display, XEvent *event)
|
||||
{
|
||||
return Inst()->_XNextEvent(display, event);
|
||||
}
|
||||
|
||||
int X11_Hook::MyXPeekEvent(Display* display, XEvent *event)
|
||||
{
|
||||
return Inst()->_XPeekEvent(display, event);
|
||||
}
|
||||
|
||||
int X11_Hook::MyXPending(Display* display)
|
||||
{
|
||||
int res = Inst()->_XPending(display);
|
||||
int res = Inst()->XPending(display);
|
||||
|
||||
if( res )
|
||||
{
|
||||
res = Inst()->check_for_overlay(display, res);
|
||||
res = Inst()->_CheckForOverlay(display, res);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
@ -166,24 +200,19 @@ int X11_Hook::MyXPending(Display* display)
|
|||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
X11_Hook::X11_Hook() :
|
||||
initialized(false),
|
||||
hooked(false),
|
||||
game_wnd(0),
|
||||
_XEventsQueued(nullptr),
|
||||
_XPeekEvent(nullptr),
|
||||
_XNextEvent(nullptr),
|
||||
_XPending(nullptr)
|
||||
_Initialized(false),
|
||||
_Hooked(false),
|
||||
_GameWnd(0),
|
||||
XEventsQueued(nullptr),
|
||||
XPending(nullptr)
|
||||
{
|
||||
//_library = dlopen(DLL_NAME, RTLD_NOW);
|
||||
}
|
||||
|
||||
X11_Hook::~X11_Hook()
|
||||
{
|
||||
PRINT_DEBUG("X11 Hook removed\n");
|
||||
SPDLOG_INFO("X11 Hook removed");
|
||||
|
||||
resetRenderState();
|
||||
|
||||
//dlclose(_library);
|
||||
ResetRenderState();
|
||||
|
||||
_inst = nullptr;
|
||||
}
|
||||
|
|
@ -196,10 +225,7 @@ X11_Hook* X11_Hook::Inst()
|
|||
return _inst;
|
||||
}
|
||||
|
||||
const char* X11_Hook::get_lib_name() const
|
||||
std::string X11_Hook::GetLibraryName() const
|
||||
{
|
||||
return DLL_NAME;
|
||||
return LibraryName;
|
||||
}
|
||||
|
||||
#endif//EMU_OVERLAY
|
||||
#endif//#__LINUX__
|
||||
|
|
|
|||
|
|
@ -1,63 +1,70 @@
|
|||
#ifndef __INCLUDED_X11_HOOK_H__
|
||||
#define __INCLUDED_X11_HOOK_H__
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Nemirtingas
|
||||
* This file is part of the ingame overlay project
|
||||
*
|
||||
* The ingame overlay project is free software; you can redistribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* The ingame overlay project is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with the ingame overlay project; if not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../Base_Hook.h"
|
||||
#pragma once
|
||||
|
||||
#ifdef __LINUX__
|
||||
#ifdef EMU_OVERLAY
|
||||
#include <ingame_overlay/Renderer_Hook.h>
|
||||
|
||||
#include "../internal_includes.h"
|
||||
|
||||
#include <X11/X.h> // XEvent types
|
||||
#include <X11/Xlib.h> // XEvent structure
|
||||
#include <X11/Xutil.h> // XEvent keysym
|
||||
|
||||
extern "C" int XEventsQueued(Display *display, int mode);
|
||||
extern "C" int XPending(Display *display);
|
||||
|
||||
class X11_Hook : public Base_Hook
|
||||
class X11_Hook :
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
friend int XEventsQueued(Display *display, int mode);
|
||||
friend int XPending(Display *display);
|
||||
static constexpr const char* DLL_NAME = "libX11.so";
|
||||
|
||||
private:
|
||||
static X11_Hook* _inst;
|
||||
|
||||
// Variables
|
||||
bool hooked;
|
||||
bool initialized;
|
||||
Window game_wnd;
|
||||
bool _Hooked;
|
||||
bool _Initialized;
|
||||
Window _GameWnd;
|
||||
|
||||
// Functions
|
||||
X11_Hook();
|
||||
int check_for_overlay(Display *d, int num_events);
|
||||
int _CheckForOverlay(Display *d, int num_events);
|
||||
|
||||
// Hook to X11 window messages
|
||||
decltype(XEventsQueued)* _XEventsQueued;
|
||||
decltype(XPeekEvent)* _XPeekEvent;
|
||||
decltype(XNextEvent)* _XNextEvent;
|
||||
decltype(XPending)* _XPending;
|
||||
//decltype(XKeysymToKeycode)* _XKeysymToKeycode;
|
||||
//decltype(XLookupKeysym)* _XLookupKeysym;
|
||||
//decltype(XGetGeometry)* _XGetGeometry;
|
||||
decltype(::XEventsQueued)* XEventsQueued;
|
||||
decltype(::XPending)* XPending;
|
||||
|
||||
static int MyXEventsQueued(Display * display, int mode);
|
||||
static int MyXNextEvent(Display* display, XEvent *event);
|
||||
static int MyXPeekEvent(Display* display, XEvent *event);
|
||||
static int MyXPending(Display* display);
|
||||
|
||||
std::function<bool(bool)> _KeyCombinationCallback;
|
||||
|
||||
public:
|
||||
std::string LibraryName;
|
||||
|
||||
virtual ~X11_Hook();
|
||||
|
||||
void resetRenderState();
|
||||
void prepareForOverlay(Display *display, Window wnd);
|
||||
void ResetRenderState();
|
||||
bool PrepareForOverlay(Display *display, Window wnd);
|
||||
|
||||
Window get_game_wnd() const{ return game_wnd; }
|
||||
Window GetGameWnd() const{ return _GameWnd; }
|
||||
|
||||
bool start_hook();
|
||||
bool StartHook(std::function<bool(bool)>& key_combination_callback);
|
||||
static X11_Hook* Inst();
|
||||
virtual const char* get_lib_name() const;
|
||||
virtual std::string GetLibraryName() const;
|
||||
};
|
||||
|
||||
#endif//EMU_OVERLAY
|
||||
#endif//__LINUX__
|
||||
#endif//__INCLUDED_X11_HOOK_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue