-
Notifications
You must be signed in to change notification settings - Fork 2
/
detect_game.c
95 lines (80 loc) · 2.31 KB
/
detect_game.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "pch.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#include <Windows.h>
#include <Psapi.h>
#include <tchar.h>
#include <stdlib.h>
#define MAX_TITLE_LENGTH 256
static const char prefix[] = "C:\\Windows\\";
static const char gameBarExe[] = "GameBar.exe";
BOOL TestFullscreen(HWND hwnd) {
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
if (!GetWindowPlacement(hwnd, &wp))
return FALSE;
if (IsZoomed(hwnd))
return TRUE;
RECT rcDesktop;
GetClientRect(GetDesktopWindow(), &rcDesktop);
return (wp.rcNormalPosition.left <= rcDesktop.left &&
wp.rcNormalPosition.top <= rcDesktop.top &&
wp.rcNormalPosition.right >= rcDesktop.right &&
wp.rcNormalPosition.bottom >= rcDesktop.bottom);
}
void ConvertTCHARToChar(const TCHAR* source, char* dest, size_t destSize) {
#ifdef _WIN32
wcstombs_s(NULL, dest, destSize, source, _TRUNCATE);
#else
wcstombs(dest, source, destSize);
#endif
}
__declspec(dllexport) int get_running_fullscreen_game_path(char* buffer, int bufferSize) {
HWND hwnd = NULL;
while ((hwnd = FindWindowEx(NULL, hwnd, NULL, NULL)) != NULL) {
if (TestFullscreen(hwnd)) {
TCHAR windowTitle[MAX_TITLE_LENGTH];
GetWindowText(hwnd, windowTitle, MAX_TITLE_LENGTH);
DWORD processId;
GetWindowThreadProcessId(hwnd, &processId);
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
if (hProcess == NULL) {
return 1;
}
TCHAR executablePath[MAX_PATH];
if (GetModuleFileNameEx(hProcess, NULL, executablePath, MAX_PATH) == 0) {
CloseHandle(hProcess);
return 1;
}
CloseHandle(hProcess);
size_t exe_bufferSize = sizeof(executablePath) / sizeof(executablePath[0]);
char* charPath = (char*)malloc(exe_bufferSize);
ConvertTCHARToChar(executablePath, charPath, exe_bufferSize);
int result = strncmp(charPath, prefix, 11);
if (result == 0) {
continue;
}
result = strcmp(charPath + strlen(charPath) - 11, gameBarExe);
if (result == 0) {
continue;
}
strcpy_s(buffer, bufferSize, charPath); // Use charPath as a regular char array
free(charPath);
return 0;
}
}
return 1;
}