Gameprocesswatcher.cpp ✧
bool GameProcessWatcher::openProcessById(DWORD processId) closeProcessHandle(); m_hProcess = OpenProcess(PROCESS_VM_READ
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; ;
bool GameProcessWatcher::readMemory(uintptr_t address, void* buffer, size_t size) const if (m_hProcess == nullptr) return false; SIZE_T bytesRead; if (!ReadProcessMemory(m_hProcess, (LPCVOID)address, buffer, size, &bytesRead)) return false; return bytesRead == size; gameprocesswatcher.cpp
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;
bool GameProcessWatcher::startWatching(int intervalMs) if (m_processId == 0 m_hProcess = OpenProcess(PROCESS_VM_READ HANDLE m_hProcess
// Error handling std::string getLastError() const;
// Getters DWORD getProcessId() const return m_processId; bool isWatching() const return m_isWatching; private: DWORD findProcessIdByName(const std::string& processName) const; bool openProcessById(DWORD processId); void closeProcessHandle(); void watchLoop(); mutable std::mutex m_mutex
And here's the corresponding header file gameprocesswatcher.h :
void GameProcessWatcher::setOnProcessExit(std::function<void(DWORD)> callback) std::lock_guard<std::mutex> lock(m_mutex); m_onProcessExit = callback;