Gameprocesswatcher.cpp Review
bool GameProcessWatcher::setProcessById(DWORD processId) std::lock_guard<std::mutex> lock(m_mutex); return openProcessById(processId);
std::vector<ProcessInfo> GameProcessWatcher::getAllProcesses() const std::vector<ProcessInfo> processes; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) return processes; PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32); if (Process32First(hSnapshot, &processEntry)) do ProcessInfo info; info.processId = processEntry.th32ProcessID; info.processName = processEntry.szExeFile; info.threadCount = processEntry.cntThreads; info.parentProcessId = processEntry.th32ParentProcessID; processes.push_back(info); while (Process32Next(hSnapshot, &processEntry)); CloseHandle(hSnapshot); return processes;
class GameProcessWatcher public: GameProcessWatcher(); ~GameProcessWatcher(); gameprocesswatcher.cpp
HANDLE m_hProcess; DWORD m_processId; std::atomic<bool> m_isWatching; int m_checkInterval; std::thread m_watchThread; mutable std::mutex m_mutex; std::function<void(DWORD)> m_onProcessExit; mutable std::string m_lastError; ;
template<typename T> bool readValue(uintptr_t address, T& value) const return readMemory(address, &value, sizeof(T)); GameProcessWatcher::getAllProcesses() const std::vector<
#include "gameprocesswatcher.h" #include <windows.h> #include <tlhelp32.h> #include <algorithm> #include <cstring>
void GameProcessWatcher::setOnProcessExit(std::function<void(DWORD)> callback) std::lock_guard<std::mutex> lock(m_mutex); m_onProcessExit = callback; if (hSnapshot == INVALID_HANDLE_VALUE) return processes
bool GameProcessWatcher::terminateProcess() if (m_hProcess == nullptr) return false; if (!TerminateProcess(m_hProcess, 0)) m_lastError = "Failed to terminate process. Error: " + std::to_string(GetLastError()); return false; closeProcessHandle(); return true;