mirror of
https://github.com/Mylloon/obs-replay-folders.git
synced 2024-11-12 19:17:01 +01:00
format + mingw-ify + makefile
This commit is contained in:
parent
9eede46b61
commit
898cba7a72
5 changed files with 93 additions and 70 deletions
4
.clangd
Normal file
4
.clangd
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add: [
|
||||||
|
--target=x86_64-w64-mingw32-gcc,
|
||||||
|
]
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -32,6 +32,7 @@ luac.out
|
||||||
*.so
|
*.so
|
||||||
*.so.*
|
*.so.*
|
||||||
*.dylib
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
*.out
|
*.out
|
||||||
|
|
18
Makefile
Normal file
18
Makefile
Normal file
|
@ -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 |:
|
|
@ -1,12 +1,8 @@
|
||||||
#include "pch.h"
|
#include <windows.h>
|
||||||
|
|
||||||
BOOL APIENTRY DllMain( HMODULE hModule,
|
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call,
|
||||||
DWORD ul_reason_for_call,
|
LPVOID lpReserved) {
|
||||||
LPVOID lpReserved
|
switch (ul_reason_for_call) {
|
||||||
)
|
|
||||||
{
|
|
||||||
switch (ul_reason_for_call)
|
|
||||||
{
|
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
case DLL_THREAD_ATTACH:
|
case DLL_THREAD_ATTACH:
|
||||||
case DLL_THREAD_DETACH:
|
case DLL_THREAD_DETACH:
|
||||||
|
@ -16,10 +12,9 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <psapi.h>
|
||||||
#include <Psapi.h>
|
|
||||||
#include <tchar.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <tchar.h>
|
||||||
|
|
||||||
#define MAX_TITLE_LENGTH 256
|
#define MAX_TITLE_LENGTH 256
|
||||||
static const char prefix[] = "C:\\Windows\\";
|
static const char prefix[] = "C:\\Windows\\";
|
||||||
|
@ -28,10 +23,12 @@ static const char gameBarExe[] = "GameBar.exe";
|
||||||
BOOL TestFullscreen(HWND hwnd) {
|
BOOL TestFullscreen(HWND hwnd) {
|
||||||
WINDOWPLACEMENT wp;
|
WINDOWPLACEMENT wp;
|
||||||
wp.length = sizeof(WINDOWPLACEMENT);
|
wp.length = sizeof(WINDOWPLACEMENT);
|
||||||
if (!GetWindowPlacement(hwnd, &wp))
|
if (!GetWindowPlacement(hwnd, &wp)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (IsZoomed(hwnd))
|
}
|
||||||
|
if (IsZoomed(hwnd)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
}
|
||||||
RECT rcDesktop;
|
RECT rcDesktop;
|
||||||
GetClientRect(GetDesktopWindow(), &rcDesktop);
|
GetClientRect(GetDesktopWindow(), &rcDesktop);
|
||||||
return (wp.rcNormalPosition.left <= rcDesktop.left &&
|
return (wp.rcNormalPosition.left <= rcDesktop.left &&
|
||||||
|
@ -41,14 +38,15 @@ BOOL TestFullscreen(HWND hwnd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConvertTCHARToChar(const TCHAR *source, char *dest, size_t destSize) {
|
void ConvertTCHARToChar(const TCHAR *source, char *dest, size_t destSize) {
|
||||||
#ifdef _WIN32
|
#ifdef _UNICODE
|
||||||
wcstombs_s(NULL, dest, destSize, source, _TRUNCATE);
|
wcstombs_s(NULL, dest, destSize, source, _TRUNCATE);
|
||||||
#else
|
#else
|
||||||
wcstombs(dest, source, destSize);
|
strncpy_s(dest, destSize, source, _TRUNCATE);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
__declspec(dllexport) int get_running_fullscreen_game_path(char* buffer, int bufferSize) {
|
__declspec(dllexport) int get_running_fullscreen_game_path(char *buffer,
|
||||||
|
int bufferSize) {
|
||||||
HWND hwnd = NULL;
|
HWND hwnd = NULL;
|
||||||
while ((hwnd = FindWindowEx(NULL, hwnd, NULL, NULL)) != NULL) {
|
while ((hwnd = FindWindowEx(NULL, hwnd, NULL, NULL)) != NULL) {
|
||||||
if (TestFullscreen(hwnd)) {
|
if (TestFullscreen(hwnd)) {
|
||||||
|
@ -58,7 +56,8 @@ __declspec(dllexport) int get_running_fullscreen_game_path(char* buffer, int buf
|
||||||
DWORD processId;
|
DWORD processId;
|
||||||
GetWindowThreadProcessId(hwnd, &processId);
|
GetWindowThreadProcessId(hwnd, &processId);
|
||||||
|
|
||||||
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
|
HANDLE hProcess =
|
||||||
|
OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
|
||||||
if (hProcess == NULL) {
|
if (hProcess == NULL) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +69,8 @@ __declspec(dllexport) int get_running_fullscreen_game_path(char* buffer, int buf
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
size_t exe_bufferSize = sizeof(executablePath) / sizeof(executablePath[0]);
|
size_t exe_bufferSize =
|
||||||
|
sizeof(executablePath) / sizeof(executablePath[0]);
|
||||||
|
|
||||||
char *charPath = (char *)malloc(exe_bufferSize);
|
char *charPath = (char *)malloc(exe_bufferSize);
|
||||||
|
|
||||||
|
@ -85,10 +85,10 @@ __declspec(dllexport) int get_running_fullscreen_game_path(char* buffer, int buf
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy_s(buffer, bufferSize, charPath); // Use charPath as a regular char array
|
// Use charPath as a regular char array
|
||||||
|
strcpy_s(buffer, bufferSize, charPath);
|
||||||
free(charPath);
|
free(charPath);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
BIN
detect_game.dll
BIN
detect_game.dll
Binary file not shown.
Loading…
Reference in a new issue