From 92084d06a5c87338cc988b5bc5868e617213e6b9 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 24 Nov 2019 12:28:53 -0800 Subject: Try/catch, and select seed --- Source/Memory.h | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) (limited to 'Source/Memory.h') diff --git a/Source/Memory.h b/Source/Memory.h index 5332cc3..803a5f1 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -4,11 +4,12 @@ #include #include #include +#include +#include "MemoryException.h" // #define GLOBALS 0x5B28C0 #define GLOBALS 0x62D0A0 -#define HEARTBEAT 0x401 enum class ProcStatus { NotRunning, Running, @@ -24,7 +25,7 @@ class Memory final : public std::enable_shared_from_this { public: Memory(const std::wstring& processName); ~Memory(); - void StartHeartbeat(HWND window, std::chrono::milliseconds beat = std::chrono::milliseconds(1000)); + void StartHeartbeat(HWND window, WPARAM wParam, std::chrono::milliseconds beat = std::chrono::milliseconds(1000)); Memory(const Memory& memory) = delete; Memory& operator=(const Memory& other) = delete; @@ -63,40 +64,25 @@ public: private: template std::vector ReadData(const std::vector& offsets, size_t numItems) { - if (numItems == 0) return {}; + assert(numItems); std::vector data; data.resize(numItems); - void* computedOffset = ComputeOffset(offsets); - for (int i=0; i<5; i++) { - if (ReadProcessMemory(_handle, computedOffset, &data[0], sizeof(T) * numItems, nullptr)) { - if (i != 0) { - int k = 0; - } - return data; - } + if (!ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr)) { + MEMORY_THROW("Failed to read data.", offsets, numItems); } - ThrowError(); - return {}; + return data; } template void WriteData(const std::vector& offsets, const std::vector& data) { - if (data.empty()) return; - void* computedOffset = ComputeOffset(offsets); - for (int i=0; i<5; i++) { - if (WriteProcessMemory(_handle, computedOffset, &data[0], sizeof(T) * data.size(), nullptr)) { - if (i != 0) { - int k = 0; - } - return; - } + assert(data.size()); + if (!WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) { + MEMORY_THROW("Failed to write data.", offsets, data.size()); } - ThrowError(); } - void Heartbeat(HWND window); + void Heartbeat(HWND window, WPARAM wParam); bool Initialize(); - void ThrowError(); void* ComputeOffset(std::vector offsets); int _previousFrame = 0; -- cgit 1.4.1