BEService spoofer refactoring.
This commit is contained in:
parent
444ccad844
commit
4a2dbcad27
6 changed files with 156 additions and 114 deletions
74
service/services/BEService.h
Normal file
74
service/services/BEService.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
// service/BEService.h
|
||||
#pragma once
|
||||
#include "core/WinApi.h"
|
||||
#include "services/GameMonitor.h"
|
||||
#include <windows.h>
|
||||
|
||||
namespace BEService
|
||||
{
|
||||
inline struct State
|
||||
{
|
||||
bool shouldStop = false;
|
||||
SERVICE_STATUS_HANDLE statusHandle = nullptr;
|
||||
|
||||
void ReportRunning() const noexcept
|
||||
{
|
||||
SERVICE_STATUS STATUS
|
||||
{
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_RUNNING,
|
||||
SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN,
|
||||
NO_ERROR, 0, 0, 0
|
||||
};
|
||||
SetServiceStatus(statusHandle, &STATUS);
|
||||
}
|
||||
|
||||
void ReportStopped() const noexcept
|
||||
{
|
||||
SERVICE_STATUS STATUS
|
||||
{
|
||||
SERVICE_WIN32_OWN_PROCESS,
|
||||
SERVICE_STOPPED,
|
||||
0, NO_ERROR, 0, 0, 0
|
||||
};
|
||||
SetServiceStatus(statusHandle, &STATUS);
|
||||
}
|
||||
} g_state;
|
||||
|
||||
VOID WINAPI CtrlHandler(DWORD control) noexcept
|
||||
{
|
||||
if (control == SERVICE_CONTROL_STOP || control == SERVICE_CONTROL_SHUTDOWN)
|
||||
g_state.shouldStop = true;
|
||||
}
|
||||
|
||||
VOID WINAPI ServiceMain(DWORD, LPWSTR*) noexcept
|
||||
{
|
||||
g_state.statusHandle = RegisterServiceCtrlHandlerW(L"BEService", CtrlHandler);
|
||||
if (!g_state.statusHandle)
|
||||
return;
|
||||
|
||||
g_state.ReportRunning();
|
||||
|
||||
if (!GameMonitor::WaitForGame() || g_state.shouldStop)
|
||||
goto cleanup;
|
||||
|
||||
while (!g_state.shouldStop && GameMonitor::IsGameRunning())
|
||||
Sleep(1000);
|
||||
|
||||
if (!g_state.shouldStop)
|
||||
Sleep(5000);
|
||||
|
||||
cleanup:
|
||||
g_state.ReportStopped();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline bool Run() noexcept
|
||||
{
|
||||
SERVICE_TABLE_ENTRYW table[] = {
|
||||
{ const_cast<wchar_t*>(L"BEService"), ServiceMain },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
return StartServiceCtrlDispatcherW(table) != FALSE;
|
||||
}
|
||||
}
|
||||
44
service/services/GameMonitor.h
Normal file
44
service/services/GameMonitor.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
// 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue