diff --git a/src/platform/platform.h b/src/platform/platform.h index 491c07d39c..0929c215e3 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -90,6 +90,8 @@ extern int gNumResolutions; extern resolution *gResolutions; extern SDL_Window *gWindow; +extern bool gSteamOverlayActive; + // Platform shared definitions void platform_update_fullscreen_resolutions(); void platform_get_closest_resolution(int inWidth, int inHeight, int *outWidth, int *outHeight); @@ -143,7 +145,7 @@ uint16 platform_get_locale_language(); uint8 platform_get_locale_measurement_format(); uint8 platform_get_locale_temperature_format(); -bool platform_is_steam_overlay_attached(); +bool platform_check_steam_overlay_attached(); // Windows specific definitions #ifdef _WIN32 diff --git a/src/platform/shared.c b/src/platform/shared.c index d6d3fad15e..cdf9ecf854 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -59,6 +59,8 @@ SDL_PixelFormat *gBufferTextureFormat = NULL; SDL_Color gPalette[256]; uint32 gPaletteHWMapped[256]; +bool gSteamOverlayActive = false; + static SDL_Surface *_surface; static SDL_Palette *_palette; @@ -188,12 +190,12 @@ static void read_center_pixel(int width, int height, uint32 *pixel) { } // Should be called before SDL_RenderPresent to capture frame buffer before Steam overlay is drawn. -static void overlay_pre_render(int width, int height) { +static void overlay_pre_render_check(int width, int height) { read_center_pixel(width, height, &_pixelBeforeOverlay); } // Should be called after SDL_RenderPresent, when Steam overlay has had the chance to be drawn. -static void overlay_post_render(int width, int height) { +static void overlay_post_render_check(int width, int height) { static bool overlayActive = false; static bool pausedBeforeOverlay = false; @@ -201,10 +203,7 @@ static void overlay_post_render(int width, int height) { // Detect an active Steam overlay by checking if the center pixel is changed by the gray fade. // Will not be triggered by applications rendering to corners, like FRAPS, MSI Afterburner and Friends popups. - bool newOverlayActive = - _pixelBeforeOverlay != _pixelAfterOverlay && - platform_is_steam_overlay_attached() && - gConfigGeneral.steam_overlay_pause; + bool newOverlayActive = _pixelBeforeOverlay != _pixelAfterOverlay; // Toggle game pause state consistently with base pause state if (!overlayActive && newOverlayActive) { @@ -255,11 +254,15 @@ void platform_draw() SDL_RenderCopy(gRenderer, gBufferTexture, NULL, NULL); - overlay_pre_render(width, height); + if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { + overlay_pre_render_check(width, height); + } SDL_RenderPresent(gRenderer); - overlay_post_render(width, height); + if (gSteamOverlayActive && gConfigGeneral.steam_overlay_pause) { + overlay_post_render_check(width, height); + } } else { // Lock the surface before setting its pixels @@ -687,6 +690,9 @@ static void platform_create_window() platform_update_fullscreen_resolutions(); platform_set_fullscreen_mode(gConfigGeneral.fullscreen_mode); + + // Check if steam overlay renderer is loaded into the process + gSteamOverlayActive = platform_check_steam_overlay_attached(); } int platform_scancode_to_rct_keycode(int sdl_key) diff --git a/src/platform/unix.c b/src/platform/unix.c index 6401814e14..956828364e 100644 --- a/src/platform/unix.c +++ b/src/platform/unix.c @@ -56,7 +56,7 @@ struct dummy { struct dummy* ptr; }; -bool platform_is_steam_overlay_attached() { +bool platform_check_steam_overlay_attached() { void* processHandle = dlopen(NULL, RTLD_NOW); struct dummy* p = (struct dummy*) processHandle; diff --git a/src/platform/windows.c b/src/platform/windows.c index b0a26b45a0..5856582f0b 100644 --- a/src/platform/windows.c +++ b/src/platform/windows.c @@ -841,7 +841,7 @@ uint8 platform_get_locale_temperature_format() } } -bool platform_is_steam_overlay_attached() +bool platform_check_steam_overlay_attached() { return GetModuleHandle("GameOverlayRenderer.dll") != NULL; }