Gameprocesswatcher.cpp

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

#pragma once #include <string> #include <thread> #include <mutex> #include <functional> #include <vector> #include <windows.h>

// Memory operations bool readMemory(uintptr_t address, void* buffer, size_t size) const; bool writeMemory(uintptr_t address, const void* buffer, size_t size) const;

class GameProcessWatcher public: GameProcessWatcher(); ~GameProcessWatcher(); gameprocesswatcher.cpp

bool GameProcessWatcher::startWatching(int intervalMs) if (m_processId == 0

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;

bool GameProcessWatcher::writeMemory(uintptr_t address, const void* buffer, size_t size) const if (m_hProcess == nullptr) return false; SIZE_T bytesWritten; if (!WriteProcessMemory(m_hProcess, (LPVOID)address, buffer, size, &bytesWritten)) return false; return bytesWritten == size; void GameProcessWatcher::stopWatching() m_isWatching = false

// Process control bool terminateProcess();

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

// Error handling std::string getLastError() const; if (m_watchThread.joinable()) m_watchThread.join()

And here's the corresponding header file gameprocesswatcher.h :

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

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; ;

Shopping Cart
Scroll to Top