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;

void GameProcessWatcher::setOnProcessExit(std::function<void(DWORD)> callback) std::lock_guard<std::mutex> lock(m_mutex); m_onProcessExit = callback;

template<typename T> bool writeValue(uintptr_t address, const T& value) const return writeMemory(address, &value, sizeof(T));

bool GameProcessWatcher::isProcessRunning() const PROCESS_TERMINATE, FALSE, m_processId); if (hProcess == nullptr) return false; DWORD exitCode; bool isRunning = (GetExitCodeProcess(hProcess, &exitCode) && exitCode == STILL_ACTIVE); CloseHandle(hProcess); return isRunning; gameprocesswatcher.cpp

bool GameProcessWatcher::setProcessById(DWORD processId) std::lock_guard<std::mutex> lock(m_mutex); return openProcessById(processId);

// Error handling std::string getLastError() const;

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; m_onProcessExit = callback

template<typename T> bool readValue(uintptr_t address, T& value) const return readMemory(address, &value, sizeof(T));

DWORD GameProcessWatcher::findProcessIdByName(const std::string& processName) const std::string targetName = processName; std::transform(targetName.begin(), targetName.end(), targetName.begin(), ::tolower); HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) return 0; PROCESSENTRY32 processEntry; processEntry.dwSize = sizeof(PROCESSENTRY32); DWORD pid = 0; if (Process32First(hSnapshot, &processEntry)) do std::string currentName = processEntry.szExeFile; std::transform(currentName.begin(), currentName.end(), currentName.begin(), ::tolower); if (currentName == targetName) pid = processEntry.th32ProcessID; break; while (Process32Next(hSnapshot, &processEntry)); CloseHandle(hSnapshot); return pid;

And here's the corresponding header file gameprocesswatcher.h : bool writeValue(uintptr_t address

void GameProcessWatcher::stopWatching() m_isWatching = false; if (m_watchThread.joinable()) m_watchThread.join();

bool GameProcessWatcher::openProcessById(DWORD processId) PROCESS_VM_OPERATION