From af6a6bb8be5eb46a9ee5a0958b8f4e48b51b319c Mon Sep 17 00:00:00 2001 From: Alexander Overvoorde Date: Sun, 4 Oct 2015 16:43:22 +0200 Subject: [PATCH] Rewrite platform_is_steam_overlay_attached for Unix to detect all possible situations --- src/platform/unix.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/platform/unix.c b/src/platform/unix.c index 7ee7d9a8da..6401814e14 100644 --- a/src/platform/unix.c +++ b/src/platform/unix.c @@ -43,8 +43,35 @@ char platform_get_path_separator() } */ +// See http://syprog.blogspot.ru/2011/12/listing-loaded-shared-objects-in-linux.html +struct lmap { + void* base_address; + char* path; + void* unused; + struct lmap *next, *prev; +}; + +struct dummy { + void* pointers[3]; + struct dummy* ptr; +}; + bool platform_is_steam_overlay_attached() { - return dlopen("gameoverlayrenderer.so", RTLD_NOW | RTLD_NOLOAD) != NULL; + void* processHandle = dlopen(NULL, RTLD_NOW); + + struct dummy* p = (struct dummy*) processHandle; + p = p->ptr; + + struct lmap* pl = (struct lmap*) p->ptr; + + while (pl != NULL) { + if (strstr(pl->path, "gameoverlayrenderer.so") != NULL) { + return true; + } + pl = pl->next; + } + + return false; } #endif