diff --git a/library/modules/DFSteam.cpp b/library/modules/DFSteam.cpp index c61d996d1..289c22e27 100644 --- a/library/modules/DFSteam.cpp +++ b/library/modules/DFSteam.cpp @@ -88,7 +88,9 @@ void DFSteam::cleanup(color_ostream& out) { } #ifdef WIN32 +#include #include +#include static bool is_running_on_wine() { typedef const char* (CDECL wine_get_version)(void); static wine_get_version* pwine_get_version; @@ -100,12 +102,41 @@ static bool is_running_on_wine() { return !!pwine_get_version; } +static DWORD findProcess(LPWSTR name) { + PROCESSENTRY32W entry; + entry.dwSize = sizeof(PROCESSENTRY32W); + + const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); + + if (!Process32FirstW(snapshot, &entry)) { + CloseHandle(snapshot); + return -1; + } + + do { + std::wstring executableName(entry.szExeFile); + if (executableName == name) { + CloseHandle(snapshot); + return entry.th32ProcessID; + } + } + while (Process32NextW(snapshot, &entry)); + + CloseHandle(snapshot); + return -1; +} + static bool launchDFHack(color_ostream& out) { if (is_running_on_wine()) { DEBUG(dfsteam, out).print("not attempting to re-launch DFHack on wine\n"); return false; } + if (findProcess(L"launchdf.exe") != -1) { + DEBUG(dfsteam, out).print("launchdf.exe already running\n"); + return true; + } + STARTUPINFOW si; PROCESS_INFORMATION pi; diff --git a/package/windows/launchdf.cpp b/package/windows/launchdf.cpp index 8e6536743..f9ed11f66 100644 --- a/package/windows/launchdf.cpp +++ b/package/windows/launchdf.cpp @@ -139,6 +139,9 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, exit(0); } + if (waitForDF()) + exit(0); + if (!SteamAPI_Init()) { // could not initialize steam context, attempt fallback launch @@ -151,9 +154,6 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, exit(0); } - if (waitForDF()) - exit(0); - bool wine = is_running_on_wine(); if (wine)