From e2c0268d4b82e170605d9cc43e26be7f38f2eb54 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 4 Nov 2019 10:04:49 -0800 Subject: Better, I guess --- Source/Memory.cpp | 25 +++++++++++++++---------- Source/Memory.h | 8 ++++---- 2 files changed, 19 insertions(+), 14 deletions(-) (limited to 'Source') diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 1f1ae0a..d7f0212 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #undef PROCESSENTRY32 #undef Process32Next @@ -53,15 +54,15 @@ Memory::~Memory() { } } -int Memory::GetCurrentFrame() -{ +int Memory::GetCurrentFrame() { int SCRIPT_FRAMES; if (GLOBALS == 0x5B28C0) { SCRIPT_FRAMES = 0x5BE3B0; } else if (GLOBALS == 0x62D0A0) { - SCRIPT_FRAMES = 0x63651C; + SCRIPT_FRAMES = 0x63954C; } else { - throw std::exception("Unknown value for Globals!"); + assert(false); + return 0x7FFFFFFF; } return ReadData({SCRIPT_FRAMES}, 1)[0]; } @@ -108,14 +109,15 @@ int Memory::ExecuteSigScans() } void Memory::ThrowError() { - std::string message(256, '\0'); - int length = FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast(message.size()), nullptr); + std::wstring message(256, '\0'); + int length = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), 1024, &message[0], static_cast(message.size()), nullptr); message.resize(length); - throw std::exception(message.c_str()); +#ifndef NDEBUG + MessageBox(NULL, message.c_str(), L"Please tell darkid about this", MB_OK); +#endif } -void* Memory::ComputeOffset(std::vector offsets) -{ +void* Memory::ComputeOffset(std::vector offsets) { // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. int final_offset = offsets.back(); offsets.pop_back(); @@ -128,7 +130,10 @@ void* Memory::ComputeOffset(std::vector offsets) if (search == std::end(_computedAddresses)) { // If the address is not yet computed, then compute it. uintptr_t computedAddress = 0; - if (!ReadProcessMemory(_handle, reinterpret_cast(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { + if (bool result = !ReadProcessMemory(_handle, reinterpret_cast(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { + if (GetLastError() == ERROR_PARTIAL_COPY) { + int k = 1; + } ThrowError(); } _computedAddresses[cumulativeAddress] = computedAddress; diff --git a/Source/Memory.h b/Source/Memory.h index 9c00dab..f70de6a 100644 --- a/Source/Memory.h +++ b/Source/Memory.h @@ -11,8 +11,7 @@ // http://stackoverflow.com/q/32798185 // http://stackoverflow.com/q/36018838 // http://stackoverflow.com/q/1387064 -class Memory -{ +class Memory { public: Memory(); bool Initialize(const std::wstring& processName); @@ -46,11 +45,12 @@ public: void AddSigScan(const std::vector& scanBytes, const std::function& scanFunc); int ExecuteSigScans(); - void ClearOffsets() {_computedAddresses = std::map();} - private: template std::vector ReadData(const std::vector& offsets, size_t numItems) { + if (GetExitCodeProcess(_process) != STILL_ACTIVE) { + // Signal error, somehow + } std::vector data; data.resize(numItems); for (int i=0; i<5; i++) { -- cgit 1.4.1