From 898cba7a728ce30f3e3ecbe90626bad9df85ace4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 21 Aug 2024 12:25:31 +0200 Subject: [PATCH] format + mingw-ify + makefile --- .clangd | 4 ++ .gitignore | 1 + Makefile | 18 +++++++ detect_game.c | 140 ++++++++++++++++++++++++------------------------ detect_game.dll | Bin 11776 -> 0 bytes 5 files changed, 93 insertions(+), 70 deletions(-) create mode 100644 .clangd create mode 100644 Makefile delete mode 100644 detect_game.dll 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 0d7254785c1ace985eefce314ce4ff1b22f4baff..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11776 zcmeHNeRNaDl^@xX5f~#wE$Wa^6e5aKV%JzSF#!h|OXRtcgKNx3!HE#^Gggr$ReA!G zLl^r9H;9M2Zkx1h+vM=kZt2;!hjg>lkesd@v)B$FHS{A+Xj-3Un>=Hhy4fyYY5Vqf z=RIMWwEe3+J=^vj&$}OU=gyrwckay7xNc)N%VmriQB;+&9zc4W{Qak2W&>k0=AE3u zo}YT|?jD2Z+}(|>ftW244R4M5+H8JbC=`}#TSQwl9wq_x zf1~r493Il);~g4(gwqWHe=GIz$3|4|W~}+sdF=G1^UWEVaW>zUpEJYGW`XkojeF1v zSjh1X3}3@@7|Y|V3CKFYAgAKVVVfbUHOheZ(i&&HlCdVV@hoNRAT{31*mZ*Sj1BM( ziNF(K>^^{Q2S+*U554LuFqhfw${EuP|3lJ@l}Tc|gsP)tE)^QPJ`P~~vB9dcXtPi9 zG4`khEa>F2vw8KcmlIu=X=1FB90UfO!Po~;vK}X6>9U9>$j4ZZN|Gzd5(4VPUs*I3 z^#kWV*$jl_K7^9>IJuk{3`3B7M84v3oFInwI2l`+!T(-i55-2`*;|j0Y_b;%$)Me~ zZhiGSq4UZ?OuitSe)3@e$0;GX$KFjG|7Ah`wd0~=&`p17)w<0_a@U2fv}MnKLa8V9 zk)gZ6N;TSrewSS!-wX2hRqIC~*p-&nb7HPWOyOpXxmBx?s~MnXm8vxllB)q$4=V=y|bLto< z7Zj8`E}o$HRjpUC$_06t58@`NIAP>N*<(9Z3U)(}}ni^T=bwGd# zYPw^2E{k6i66yb~lTQn|eV#?>mKMvrJygvs#|u|lj!$QcF2tumwreo{%dU&@dD^T9 z@+*!()jGrt=2O!Z{JpA<%@^b!dE`DpKCfE+=$7}N1H_RY%U7+}=VBj#x!~{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