44 lines
No EOL
1.1 KiB
C++
44 lines
No EOL
1.1 KiB
C++
// services/GameMonitor.h
|
|
#pragma once
|
|
#include "core/WinApi.h"
|
|
#include <tlhelp32.h>
|
|
#include <string_view>
|
|
|
|
namespace GameMonitor
|
|
{
|
|
[[nodiscard]] inline bool IsGameRunning() noexcept
|
|
{
|
|
WinApi::UniqueHandle snapshot{ CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) };
|
|
if (!snapshot || snapshot.get() == INVALID_HANDLE_VALUE)
|
|
return false;
|
|
|
|
PROCESSENTRY32W entry{ sizeof(entry) };
|
|
if (!Process32FirstW(snapshot.get(), &entry))
|
|
return false;
|
|
|
|
do
|
|
{
|
|
if (_wcsicmp(entry.szExeFile, L"EscapeFromTarkov.exe") == 0)
|
|
return true;
|
|
} while (Process32NextW(snapshot.get(), &entry));
|
|
|
|
return false;
|
|
}
|
|
|
|
[[nodiscard]] inline bool WaitForGame(DWORD maxWaitMs = 30 * 60 * 1000) noexcept
|
|
{
|
|
DWORD elapsed = 0;
|
|
const DWORD stepMs = 1000;
|
|
|
|
while (elapsed < maxWaitMs)
|
|
{
|
|
if (IsGameRunning())
|
|
return true;
|
|
|
|
Sleep(stepMs);
|
|
elapsed += stepMs;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |