Compare commits

..

No commits in common. "c22b3cd3d3639a154cff9a77e6080dde13c1c915" and "1ad2818e28013bf5d27aa29660f4806670810887" have entirely different histories.

20 changed files with 124 additions and 298 deletions

View File

@ -128,26 +128,13 @@ STEAMAPI_API ISteamClient *g_pSteamClientGameServer;
ISteamClient *g_pSteamClientGameServer;
#endif
static Steam_Client *client;
Steam_Client *get_steam_client()
{
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (!client) {
client = new Steam_Client();
}
static Steam_Client *client = new Steam_Client();
return client;
}
void destroy_client()
{
std::lock_guard<std::recursive_mutex> lock(global_mutex);
if (client) {
delete client;
client = NULL;
}
}
Steam_Client *get_steam_client_old()
{
return get_steam_client();
@ -311,9 +298,6 @@ STEAMAPI_API void S_CALLTYPE SteamAPI_Shutdown()
old_video_instance = NULL;
old_parental_instance = NULL;
old_unified_instance = NULL;
if (global_counter == 0) {
destroy_client();
}
}
// SteamAPI_RestartAppIfNecessary ensures that your executable was launched through Steam.
@ -623,14 +607,11 @@ STEAMAPI_API ISteamClient *SteamGameServerClient();
STEAMAPI_API steam_bool S_CALLTYPE SteamInternal_GameServer_Init( uint32 unIP, uint16 usPort, uint16 usGamePort, uint16 usQueryPort, EServerMode eServerMode, const char *pchVersionString )
{
PRINT_DEBUG("SteamInternal_GameServer_Init %u %hu %hu %hu %u %s\n", unIP, usPort, usGamePort, usQueryPort, eServerMode, pchVersionString);
if (!server_steam_pipe) {
load_old_interface_versions();
get_steam_client()->CreateLocalUser(&server_steam_pipe, k_EAccountTypeGameServer);
++global_counter;
//g_pSteamClientGameServer is only used in pre 1.37 (where the interface versions are not provided by the game)
g_pSteamClientGameServer = SteamGameServerClient();
}
load_old_interface_versions();
get_steam_client()->CreateLocalUser(&server_steam_pipe, k_EAccountTypeGameServer);
++global_counter;
//g_pSteamClientGameServer is only used in pre 1.37 (where the interface versions are not provided by the game)
g_pSteamClientGameServer = SteamGameServerClient();
uint32 unFlags = 0;
if (eServerMode == eServerModeAuthenticationAndSecure) unFlags = k_unServerFlagSecure;
return get_steam_client()->steam_gameserver->InitGameServer(unIP, usGamePort, usQueryPort, unFlags, 0, pchVersionString);
@ -697,10 +678,6 @@ STEAMAPI_API void SteamGameServer_Shutdown()
old_gamserver_ugc_instance = NULL;
old_gamserver_apps_instance = NULL;
old_gamserver_masterupdater_instance = NULL;
if (global_counter == 0) {
destroy_client();
}
}
STEAMAPI_API void SteamGameServer_RunCallbacks()

View File

@ -751,6 +751,7 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set<IP_PORT>
{
tcp_port = udp_port = port;
own_ip = 0x7F000001;
alive = true;
last_run = std::chrono::high_resolution_clock::now();
this->appid = appid;
@ -842,21 +843,6 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set<IP_PORT>
reset_last_error();
}
Networking::~Networking()
{
for (auto &c : connections) {
kill_tcp_socket(c.tcp_socket_incoming);
kill_tcp_socket(c.tcp_socket_outgoing);
}
for (auto &c : accepted) {
kill_tcp_socket(c);
}
kill_socket(udp_socket);
kill_socket(tcp_socket);
}
Common_Message Networking::create_announce(bool request)
{
Announce *announce = new Announce();
@ -1279,3 +1265,13 @@ uint32 Networking::getOwnIP()
{
return own_ip;
}
void Networking::shutDown()
{
alive = false;
}
bool Networking::isAlive()
{
return alive;
}

View File

@ -90,6 +90,7 @@ struct Connection {
class Networking {
bool enabled = false;
bool alive;
std::chrono::high_resolution_clock::time_point last_run;
sock_t udp_socket, tcp_socket;
uint16 udp_port, tcp_port;
@ -125,7 +126,6 @@ public:
//ex: 127.0.0.1 should be passed as 0x7F000001
static std::set<IP_PORT> resolve_ip(std::string dns);
Networking(CSteamID id, uint32 appid, uint16 port, std::set<IP_PORT> *custom_broadcasts, bool disable_sockets);
~Networking();
void addListenId(CSteamID id);
void setAppID(uint32 appid);
void Run();
@ -137,6 +137,9 @@ public:
bool setCallback(Callback_Ids id, CSteamID steam_id, void (*message_callback)(void *object, Common_Message *msg), void *object);
uint32 getIP(CSteamID id);
uint32 getOwnIP();
void shutDown();
bool isAlive();
};
#endif

View File

@ -173,8 +173,6 @@ void Steam_Apps::RequestAppProofOfPurchaseKey( AppId_t nAppID )
bool Steam_Apps::GetCurrentBetaName( char *pchName, int cchNameBufferSize )
{
PRINT_DEBUG("GetCurrentBetaName %i\n", cchNameBufferSize);
if (!pchName) return false;
if (sizeof("public") > cchNameBufferSize) {
return false;
}

View File

@ -18,21 +18,19 @@
#include "steam_client.h"
#include "settings_parser.h"
static std::mutex kill_background_thread_mutex;
static std::condition_variable kill_background_thread_cv;
static bool kill_background_thread;
static std::atomic_bool kill_background_thread;
static void background_thread(Steam_Client *client)
{
PRINT_DEBUG("background thread starting\n");
std::mutex mtx;
std::unique_lock<std::mutex> lck(mtx);
while (1) {
{
std::unique_lock<std::mutex> lck(kill_background_thread_mutex);
if (kill_background_thread || kill_background_thread_cv.wait_for(lck, std::chrono::seconds(1)) != std::cv_status::timeout) {
if (kill_background_thread) {
PRINT_DEBUG("background thread exit\n");
return;
}
if (kill_background_thread || kill_background_thread_cv.wait_for(lck, std::chrono::seconds(1)) != std::cv_status::timeout) {
if (kill_background_thread) {
PRINT_DEBUG("background thread exit\n");
return;
}
}
@ -124,59 +122,7 @@ Steam_Client::Steam_Client()
Steam_Client::~Steam_Client()
{
delete steam_gameserver;
delete steam_gameserver_utils;
delete steam_gameserverstats;
delete steam_gameserver_networking;
delete steam_gameserver_http;
delete steam_gameserver_inventory;
delete steam_gameserver_ugc;
delete steam_gameserver_apps;
delete steam_gameserver_networking_sockets;
delete steam_gameserver_networking_sockets_serialized;
delete steam_gameserver_networking_messages;
delete steam_gameserver_game_coordinator;
delete steam_masterserver_updater;
delete steam_matchmaking;
delete steam_matchmaking_servers;
delete steam_user_stats;
delete steam_apps;
delete steam_networking;
delete steam_remote_storage;
delete steam_screenshots;
delete steam_http;
delete steam_controller;
delete steam_ugc;
delete steam_applist;
delete steam_music;
delete steam_musicremote;
delete steam_HTMLsurface;
delete steam_inventory;
delete steam_video;
delete steam_parental;
delete steam_networking_sockets;
delete steam_networking_sockets_serialized;
delete steam_networking_messages;
delete steam_game_coordinator;
delete steam_networking_utils;
delete steam_unified_messages;
delete steam_game_search;
delete steam_parties;
delete steam_remoteplay;
delete steam_tv;
delete steam_utils;
delete steam_friends;
delete steam_user;
delete steam_overlay;
delete run_every_runcb;
delete callbacks_server;
delete callbacks_client;
delete callback_results_server;
delete callback_results_client;
delete network;
network->shutDown();
}
void Steam_Client::userLogIn()
@ -879,9 +825,7 @@ bool Steam_Client::BShutdownIfAllPipesClosed()
if (!steam_pipes.size()) {
bool joinable = background_keepalive.joinable();
if (joinable) {
kill_background_thread_mutex.lock();
kill_background_thread = true;
kill_background_thread_mutex.unlock();
kill_background_thread_cv.notify_one();
}

View File

@ -25,7 +25,6 @@
#include "System/String.hpp"
#include "System/System.h"
#include "System/Library.h"
#include "System/ScopedLock.hpp"
#if defined(WIN64) || defined(_WIN64) || defined(__MINGW64__) \
|| defined(WIN32) || defined(_WIN32) || defined(__MINGW32__)
@ -78,6 +77,10 @@ public:
delete vulkan_hook;
}
bool force_stop_detection;
std::condition_variable detect_renderer_thread_cv;
std::mutex destroy_render_thread_mutex;
private:
Renderer_Detector():
dxgi_hooked(false),
@ -95,7 +98,8 @@ private:
dx12_hook(nullptr),
opengl_hook(nullptr),
vulkan_hook(nullptr),
detection_done(false)
detection_done(false),
force_stop_detection(false)
{
std::wstring tmp(4096, L'\0');
tmp.resize(GetSystemDirectoryW(&tmp[0], tmp.size()));
@ -143,8 +147,6 @@ private:
Vulkan_Hook* vulkan_hook;
bool detection_done;
std::condition_variable stop_detection_cv;
std::mutex stop_detection_mutex;
HWND dummyWindow = nullptr;
std::wstring _WindowClassName;
@ -429,14 +431,14 @@ private:
}
void HookDX9Present(IDirect3DDevice9* pDevice, bool ex, IDirect3DSwapChain9* pSwapChain,
void*& pfnPresent,
void*& pfnReset,
void*& pfnPresentEx,
void*& pfnSwapChainPresent)
decltype(&IDirect3DDevice9::Present)& pfnPresent,
decltype(&IDirect3DDevice9::Reset)& pfnReset,
decltype(&IDirect3DDevice9Ex::PresentEx)& pfnPresentEx,
decltype(&IDirect3DSwapChain9::Present)& pfnSwapChainPresent)
{
void** vTable = *reinterpret_cast<void***>(pDevice);
pfnPresent = vTable[(int)IDirect3DDevice9VTable::Present];
pfnReset = vTable[(int)IDirect3DDevice9VTable::Reset];
(void*&)pfnPresent = vTable[(int)IDirect3DDevice9VTable::Present];
(void*&)pfnReset = vTable[(int)IDirect3DDevice9VTable::Reset];
(void*&)IDirect3DDevice9Present = vTable[(int)IDirect3DDevice9VTable::Present];
@ -446,7 +448,7 @@ private:
if (ex)
{
pfnPresentEx = vTable[(int)IDirect3DDevice9VTable::PresentEx];
(void*&)pfnPresentEx = vTable[(int)IDirect3DDevice9VTable::PresentEx];
(void*&)IDirect3DDevice9ExPresentEx = vTable[(int)IDirect3DDevice9VTable::PresentEx];
detection_hooks.BeginHook();
@ -461,9 +463,9 @@ private:
if (pSwapChain != nullptr)
{
vTable = *reinterpret_cast<void***>(pSwapChain);
pfnSwapChainPresent = vTable[(int)IDirect3DSwapChain9VTable::Present];
(void*&)IDirect3DSwapChain9Present = vTable[(int)IDirect3DSwapChain9VTable::Present];
IDirect3DSwapChain9VTable* vTable = *reinterpret_cast<IDirect3DSwapChain9VTable**>(pSwapChain);
pfnSwapChainPresent = vTable->pPresent;
IDirect3DSwapChain9Present = vTable->pPresent;
detection_hooks.BeginHook();
detection_hooks.HookFunc(std::pair<void**, void*>{ (void**)&IDirect3DSwapChain9Present, (void*)&MyDX9SwapChainPresent });
@ -551,7 +553,7 @@ private:
decltype(&IDirect3DDevice9Ex::PresentEx) pfnPresentEx;
decltype(&IDirect3DSwapChain9::Present) pfnSwapChainPresent;
HookDX9Present(pDevice, Direct3DCreate9Ex != nullptr, pSwapChain, (void*&)pfnPresent, (void*&)pfnReset, (void*&)pfnPresentEx, (void*&)pfnSwapChainPresent);
HookDX9Present(pDevice, Direct3DCreate9Ex != nullptr, pSwapChain, pfnPresent, pfnReset, pfnPresentEx, pfnSwapChainPresent);
dx9_hook = DX9_Hook::Inst();
dx9_hook->LibraryName = library_path;
@ -1043,10 +1045,7 @@ public:
std::lock_guard<std::mutex> lk(renderer_mutex);
if (detection_done)
{
if (renderer_hook != nullptr)
return renderer_hook;
detection_done = false;
return renderer_hook;
}
if (CreateHWND() == nullptr)
@ -1070,9 +1069,8 @@ public:
auto start_time = std::chrono::steady_clock::now();
do
{
std::unique_lock<std::mutex> lck(stop_detection_mutex);
if (detection_done)
break;
std::unique_lock<std::mutex> lck(destroy_render_thread_mutex);
if (force_stop_detection) break;
for (auto const& library : libraries)
{
@ -1085,7 +1083,9 @@ public:
}
}
stop_detection_cv.wait_for(lck, std::chrono::milliseconds{ 100 });
detect_renderer_thread_cv.wait_for(lck, std::chrono::milliseconds(100));
if (force_stop_detection) break;
} while (!detection_done && (timeout.count() == -1 || (std::chrono::steady_clock::now() - start_time) <= timeout));
{
@ -1093,38 +1093,19 @@ public:
DestroyHWND();
detection_done = true;
detection_hooks.UnhookAll();
dxgi_hooked = false;
dxgi1_2_hooked = false;
dx12_hooked = false;
dx11_hooked = false;
dx10_hooked = false;
dx9_hooked = false;
opengl_hooked = false;
vulkan_hooked = false;
delete dx9_hook ; dx9_hook = nullptr;
delete dx10_hook ; dx10_hook = nullptr;
delete dx11_hook ; dx11_hook = nullptr;
delete dx12_hook ; dx12_hook = nullptr;
delete opengl_hook; opengl_hook = nullptr;
delete vulkan_hook; vulkan_hook = nullptr;
detection_hooks.UnhookAll();
}
SPDLOG_TRACE("Renderer detection done {}.", (void*)renderer_hook);
return renderer_hook;
}
void stop_detection()
{
{
System::scoped_lock lk(renderer_mutex, stop_detection_mutex);
detection_done = true;
}
stop_detection_cv.notify_all();
}
};
Renderer_Detector* Renderer_Detector::instance = nullptr;
@ -1177,8 +1158,6 @@ private:
OpenGLX_Hook* openglx_hook;
bool detection_done;
std::condition_variable stop_detection_cv;
std::mutex stop_detection_mutex;
static void MyglXSwapBuffers(Display* dpy, GLXDrawable drawable)
{
@ -1252,12 +1231,7 @@ public:
{
std::lock_guard<std::mutex> lk(renderer_mutex);
if (detection_done)
{
if (renderer_hook != nullptr)
return renderer_hook;
detection_done = false;
}
return renderer_hook;
}
SPDLOG_TRACE("Started renderer detection.");
@ -1265,10 +1239,6 @@ public:
auto start_time = std::chrono::steady_clock::now();
do
{
std::unique_lock<std::mutex> lck(stop_detection_mutex);
if (detection_done)
break;
for (auto const& library : libraries)
{
void* lib_handle = System::Library::GetLibraryHandle(library.first);
@ -1279,18 +1249,12 @@ public:
(this->*library.second)(lib_path);
}
}
stop_detection_cv.wait_for(lck, std::chrono::milliseconds{ 100 });
std::this_thread::sleep_for(std::chrono::milliseconds{ 100 });
} while (!detection_done && (timeout.count() == -1 || (std::chrono::steady_clock::now() - start_time) <= timeout));
{
std::lock_guard<std::mutex> lk(renderer_mutex);
detection_done = true;
detection_hooks.UnhookAll();
openglx_hooked = false;
delete openglx_hook; openglx_hook = nullptr;
//delete vulkan_hook; vulkan_hook = nullptr;
}
@ -1299,15 +1263,6 @@ public:
return renderer_hook;
}
void stop_detection()
{
{
System::scoped_lock lk(renderer_mutex, stop_detection_mutex);
detection_done = true;
}
stop_detection_cv.notify_all();
}
};
Renderer_Detector* Renderer_Detector::instance = nullptr;
@ -1356,8 +1311,6 @@ private:
OpenGL_Hook* opengl_hook;
bool detection_done;
std::condition_variable stop_detection_cv;
std::mutex stop_detection_mutex;
static int64_t MyCGLFlushDrawable(CGLDrawable_t* glDrawable)
{
@ -1431,12 +1384,7 @@ public:
{
std::lock_guard<std::mutex> lk(renderer_mutex);
if (detection_done)
{
if (renderer_hook != nullptr)
return renderer_hook;
detection_done = false;
}
return renderer_hook;
}
SPDLOG_TRACE("Started renderer detection.");
@ -1444,10 +1392,6 @@ public:
auto start_time = std::chrono::steady_clock::now();
do
{
std::unique_lock<std::mutex> lck(stop_detection_mutex);
if (detection_done)
break;
for (auto const& library : libraries)
{
void* lib_handle = System::Library::GetLibraryHandle(library.first);
@ -1458,18 +1402,12 @@ public:
(this->*library.second)(lib_path);
}
}
stop_detection_cv.wait_for(lck, std::chrono::milliseconds{ 100 });
std::this_thread::sleep_for(std::chrono::milliseconds{ 100 });
} while (!detection_done && (timeout.count() == -1 || (std::chrono::steady_clock::now() - start_time) <= timeout));
{
std::lock_guard<std::mutex> lk(renderer_mutex);
detection_done = true;
detection_hooks.UnhookAll();
opengl_hooked = false;
delete opengl_hook; opengl_hook = nullptr;
//delete vulkan_hook; vulkan_hook = nullptr;
}
@ -1478,31 +1416,21 @@ public:
return renderer_hook;
}
void stop_detection()
{
{
System::scoped_lock lk(renderer_mutex, stop_detection_mutex);
detection_done = true;
}
stop_detection_cv.notify_all();
}
};
Renderer_Detector* Renderer_Detector::instance = nullptr;
#endif
namespace ingame_overlay {
std::future<Renderer_Hook*> DetectRenderer(std::chrono::milliseconds timeout)
std::future<Renderer_Hook*> detect_renderer(std::chrono::milliseconds timeout)
{
return std::async(std::launch::async, &Renderer_Detector::detect_renderer, Renderer_Detector::Inst(), timeout);
}
void StopRendererDetection()
void stop_renderer_detector()
{
Renderer_Detector::Inst()->stop_detection();
Renderer_Detector::Inst()->destroy_render_thread_mutex.lock();
Renderer_Detector::Inst()->force_stop_detection = true;
Renderer_Detector::Inst()->destroy_render_thread_mutex.unlock();
Renderer_Detector::Inst()->detect_renderer_thread_cv.notify_all();
}
}

View File

@ -27,9 +27,5 @@
#include "Renderer_Hook.h"
namespace ingame_overlay {
std::future<Renderer_Hook*> DetectRenderer(std::chrono::milliseconds timeout = std::chrono::milliseconds{ -1 });
void StopRendererDetection();
}
std::future<Renderer_Hook*> detect_renderer(std::chrono::milliseconds timeout = std::chrono::milliseconds{-1});
void stop_renderer_detector();

View File

@ -110,8 +110,6 @@ void OpenGLX_Hook::_PrepareForOverlay(Display* display, GLXDrawable drawable)
_Display = display;
X11_Hook::Inst()->SetInitialWindowSize(_Display, (Window)drawable);
_Initialized = true;
OverlayHookReady(true);
}

View File

@ -83,18 +83,6 @@ void X11_Hook::ResetRenderState()
}
}
void X11_Hook::SetInitialWindowSize(Display* display, Window wnd)
{
unsigned int width, height;
Window unused_window;
int unused_int;
unsigned int unused_unsigned_int;
XGetGeometry(display, wnd, &unused_window, &unused_int, &unused_int, &width, &height, &unused_unsigned_int, &unused_unsigned_int);
ImGui::GetIO().DisplaySize = ImVec2((float)width, (float)height);
}
bool X11_Hook::PrepareForOverlay(Display *display, Window wnd)
{
if(!_Hooked)

View File

@ -60,7 +60,6 @@ public:
virtual ~X11_Hook();
void ResetRenderState();
void SetInitialWindowSize(Display* display, Window wnd);
bool PrepareForOverlay(Display *display, Window wnd);
Window GetGameWnd() const{ return _GameWnd; }

View File

@ -196,14 +196,14 @@ void Steam_Overlay::SetupOverlay()
if (!setup_overlay_called)
{
setup_overlay_called = true;
future_renderer = ingame_overlay::DetectRenderer();
future_renderer = detect_renderer();
}
}
void Steam_Overlay::UnSetupOverlay()
{
ingame_overlay::StopRendererDetection();
stop_renderer_detector();
if (!Ready() && future_renderer.valid()) {
if (future_renderer.wait_for(std::chrono::milliseconds{500}) == std::future_status::ready) {
future_renderer.get();

View File

@ -82,7 +82,7 @@ void DX10_Hook::_ResetRenderState()
OverlayHookReady(false);
ImGui_ImplDX10_Shutdown();
Windows_Hook::Inst()->ResetRenderState();
Windows_Hook::Inst()->_ResetRenderState();
ImGui::DestroyContext();
SafeRelease(mainRenderTargetView);
@ -118,13 +118,11 @@ void DX10_Hook::_PrepareForOverlay(IDXGISwapChain* pSwapChain)
ImGui::CreateContext();
ImGui_ImplDX10_Init(pDevice);
Windows_Hook::Inst()->SetInitialWindowSize(desc.OutputWindow);
_Initialized = true;
OverlayHookReady(true);
}
if (ImGui_ImplDX10_NewFrame() && Windows_Hook::Inst()->PrepareForOverlay(desc.OutputWindow))
if (ImGui_ImplDX10_NewFrame() && Windows_Hook::Inst()->_PrepareForOverlay(desc.OutputWindow))
{
ImGui::NewFrame();

View File

@ -92,7 +92,7 @@ void DX11_Hook::_ResetRenderState()
OverlayHookReady(false);
ImGui_ImplDX11_Shutdown();
Windows_Hook::Inst()->ResetRenderState();
Windows_Hook::Inst()->_ResetRenderState();
//ImGui::DestroyContext();
SafeRelease(mainRenderTargetView);
@ -151,13 +151,11 @@ void DX11_Hook::_PrepareForOverlay(IDXGISwapChain* pSwapChain)
ImGui_ImplDX11_Init(pDevice, pContext);
Windows_Hook::Inst()->SetInitialWindowSize(desc.OutputWindow);
_Initialized = true;
OverlayHookReady(true);
}
if (ImGui_ImplDX11_NewFrame() && Windows_Hook::Inst()->PrepareForOverlay(desc.OutputWindow))
if (ImGui_ImplDX11_NewFrame() && Windows_Hook::Inst()->_PrepareForOverlay(desc.OutputWindow))
{
ImGui::NewFrame();

View File

@ -137,7 +137,7 @@ void DX12_Hook::_ResetRenderState()
OverlayHookReady(false);
ImGui_ImplDX12_Shutdown();
Windows_Hook::Inst()->ResetRenderState();
Windows_Hook::Inst()->_ResetRenderState();
ImGui::DestroyContext();
OverlayFrames.clear();
@ -271,13 +271,11 @@ void DX12_Hook::_PrepareForOverlay(IDXGISwapChain* pSwapChain, ID3D12CommandQueu
//heaps.cpu_handle,
//heaps.gpu_handle);
Windows_Hook::Inst()->SetInitialWindowSize(sc_desc.OutputWindow);
_Initialized = true;
OverlayHookReady(true);
}
if (ImGui_ImplDX12_NewFrame() && Windows_Hook::Inst()->PrepareForOverlay(sc_desc.OutputWindow))
if (ImGui_ImplDX12_NewFrame() && Windows_Hook::Inst()->_PrepareForOverlay(sc_desc.OutputWindow))
{
ImGui::NewFrame();

View File

@ -88,7 +88,7 @@ void DX9_Hook::_ResetRenderState()
OverlayHookReady(false);
ImGui_ImplDX9_Shutdown();
Windows_Hook::Inst()->ResetRenderState();
Windows_Hook::Inst()->_ResetRenderState();
ImGui::DestroyContext();
SafeRelease(_pDevice);
@ -137,14 +137,11 @@ void DX9_Hook::_PrepareForOverlay(IDirect3DDevice9 *pDevice, HWND destWindow)
ImGui_ImplDX9_Init(pDevice);
_LastWindow = destWindow;
Windows_Hook::Inst()->SetInitialWindowSize(destWindow);
_Initialized = true;
OverlayHookReady(true);
}
if (ImGui_ImplDX9_NewFrame() && Windows_Hook::Inst()->PrepareForOverlay(destWindow))
if (ImGui_ImplDX9_NewFrame() && Windows_Hook::Inst()->_PrepareForOverlay(destWindow))
{
ImGui::NewFrame();

View File

@ -464,24 +464,43 @@ enum class IDirect3DDevice9VTable
GetDisplayModeEx,
};
enum class IDirect3DSwapChain9VTable
struct IDirect3DSwapChain9VTable
{
// IUnknown
QueryInterface,
AddRef,
Release,
enum class Index
{
// IUnknown
QueryInterface,
AddRef,
Release,
// IDirect3DSwapChain9
Present,
GetFrontBufferData,
GetBackBuffer,
GetRasterStatus,
GetDisplayMode,
GetDevice,
GetPresentParameters,
// IDirect3DSwapChain9
Present,
GetFrontBufferData,
GetBackBuffer,
GetRasterStatus,
GetDisplayMode,
GetDevice,
GetPresentParameters,
// IDirect3DSwapChain9Ex
GetLastPresentCount,
GetPresentStats,
GetDisplayModeEx,
// IDirect3DSwapChain9Ex
GetLastPresentCount,
GetPresentStats,
GetDisplayModeEx,
};
decltype(&IDirect3DSwapChain9::QueryInterface) pQueryInterface;
decltype(&IDirect3DSwapChain9::AddRef) pAddRef;
decltype(&IDirect3DSwapChain9::Release) pRelease;
decltype(&IDirect3DSwapChain9::Present) pPresent;
decltype(&IDirect3DSwapChain9::GetFrontBufferData) pGetFrontBufferData;
decltype(&IDirect3DSwapChain9::GetBackBuffer) pGetBackBuffer;
decltype(&IDirect3DSwapChain9::GetRasterStatus) pGetRasterStatus;
decltype(&IDirect3DSwapChain9::GetDisplayMode) pGetDisplayMode;
decltype(&IDirect3DSwapChain9::GetDevice) pGetDevice;
decltype(&IDirect3DSwapChain9::GetPresentParameters) pGetPresentParameters;
decltype(&IDirect3DSwapChain9Ex::GetLastPresentCount) pGetLastPresentCount;
decltype(&IDirect3DSwapChain9Ex::GetPresentStats) pGetPresentStats;
decltype(&IDirect3DSwapChain9Ex::GetDisplayModeEx) pGetDisplayModeEx;
};

View File

@ -68,10 +68,10 @@ void OpenGL_Hook::_ResetRenderState()
OverlayHookReady(false);
ImGui_ImplOpenGL3_Shutdown();
Windows_Hook::Inst()->ResetRenderState();
Windows_Hook::Inst()->_ResetRenderState();
ImGui::DestroyContext();
_LastWindow = nullptr;
last_window = nullptr;
_Initialized = false;
}
}
@ -81,7 +81,7 @@ void OpenGL_Hook::_PrepareForOverlay(HDC hDC)
{
HWND hWnd = WindowFromDC(hDC);
if (hWnd != _LastWindow)
if (hWnd != last_window)
_ResetRenderState();
if (!_Initialized)
@ -89,15 +89,12 @@ void OpenGL_Hook::_PrepareForOverlay(HDC hDC)
ImGui::CreateContext();
ImGui_ImplOpenGL3_Init();
_LastWindow = hWnd;
Windows_Hook::Inst()->SetInitialWindowSize(hWnd);
last_window = hWnd;
_Initialized = true;
OverlayHookReady(true);
}
if (ImGui_ImplOpenGL3_NewFrame() && Windows_Hook::Inst()->PrepareForOverlay(hWnd))
if (ImGui_ImplOpenGL3_NewFrame() && Windows_Hook::Inst()->_PrepareForOverlay(hWnd))
{
ImGui::NewFrame();
@ -120,7 +117,7 @@ OpenGL_Hook::OpenGL_Hook():
_Hooked(false),
_WindowsHooked(false),
_Initialized(false),
_LastWindow(nullptr),
last_window(nullptr),
wglSwapBuffers(nullptr)
{
}

View File

@ -37,7 +37,7 @@ private:
bool _Hooked;
bool _WindowsHooked;
bool _Initialized;
HWND _LastWindow;
HWND last_window;
std::set<std::shared_ptr<uint64_t>> _ImageResources;
// Functions

View File

@ -88,7 +88,7 @@ bool Windows_Hook::StartHook(std::function<bool(bool)>& _key_combination_callbac
return true;
}
void Windows_Hook::ResetRenderState()
void Windows_Hook::_ResetRenderState()
{
if (_Initialized)
{
@ -100,17 +100,10 @@ void Windows_Hook::ResetRenderState()
}
}
void Windows_Hook::SetInitialWindowSize(HWND hWnd)
{
RECT rect = { 0, 0, 0, 0 };
::GetClientRect(hWnd, &rect);
ImGui::GetIO().DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
}
bool Windows_Hook::PrepareForOverlay(HWND hWnd)
bool Windows_Hook::_PrepareForOverlay(HWND hWnd)
{
if (_GameHwnd != hWnd)
ResetRenderState();
_ResetRenderState();
if (!_Initialized)
{
@ -381,7 +374,7 @@ Windows_Hook::~Windows_Hook()
{
SPDLOG_INFO("Windows Hook removed");
ResetRenderState();
_ResetRenderState();
_inst = nullptr;
}

View File

@ -68,9 +68,8 @@ public:
virtual ~Windows_Hook();
void ResetRenderState();
void SetInitialWindowSize(HWND hWnd);
bool PrepareForOverlay(HWND hWnd);
void _ResetRenderState();
bool _PrepareForOverlay(HWND hWnd);
HWND GetGameHwnd() const;
WNDPROC GetGameWndProc() const;