diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..ed52819 --- /dev/null +++ b/.clangd @@ -0,0 +1,4 @@ +CompileFlags: + Add: [ + --target=x86_64-w64-mingw32-gcc, + ] diff --git a/.gitignore b/.gitignore index 0cbcaa3..8ca3735 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ luac.out *.so *.so.* *.dylib +*.dll # Executables *.out diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..43b6843 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CC = x86_64-w64-mingw32-gcc +RM = rm + +CFLAGS = -shared -lpsapi -luser32 + +EXES = detect_game +EXT = .dll + +all: $(EXES) + +$(EXES): %: %.c $(DEPS) + $(CC) $^ -o $@$(EXT) $(CFLAGS) + +%.o: %.c + $(CC) -c $< -o $@ $(CFLAGS) + +clean: + @$(RM) *.o $(addsuffix $(EXT), $(EXES)) 2>/dev/null |: diff --git a/detect_game.c b/detect_game.c index 35ba7fe..a43decf 100644 --- a/detect_game.c +++ b/detect_game.c @@ -1,95 +1,95 @@ -#include "pch.h" +#include -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; +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 -#include -#include +#include #include +#include #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); + 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); +void ConvertTCHARToChar(const TCHAR *source, char *dest, size_t destSize) { +#ifdef _UNICODE + wcstombs_s(NULL, dest, destSize, source, _TRUNCATE); #else - wcstombs(dest, source, destSize); + strncpy_s(dest, destSize, source, _TRUNCATE); #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); +__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); + DWORD processId; + GetWindowThreadProcessId(hwnd, &processId); - HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId); - if (hProcess == NULL) { - return 1; - } + 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; - } + 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]); + CloseHandle(hProcess); + size_t exe_bufferSize = + sizeof(executablePath) / sizeof(executablePath[0]); - char* charPath = (char*)malloc(exe_bufferSize); + char *charPath = (char *)malloc(exe_bufferSize); - ConvertTCHARToChar(executablePath, charPath, exe_bufferSize); - int result = strncmp(charPath, prefix, 11); - if (result == 0) { - continue; - } + 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; + result = strcmp(charPath + strlen(charPath) - 11, gameBarExe); + if (result == 0) { + continue; + } - } - } - return 1; + // Use charPath as a regular char array + strcpy_s(buffer, bufferSize, charPath); + free(charPath); + return 0; + } + } + return 1; } diff --git a/detect_game.dll b/detect_game.dll deleted file mode 100644 index 0d72547..0000000 Binary files a/detect_game.dll and /dev/null differ