diff options
Diffstat (limited to 'Source/Memory.cpp')
-rw-r--r-- | Source/Memory.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
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 @@ | |||
2 | #include <psapi.h> | 2 | #include <psapi.h> |
3 | #include <tlhelp32.h> | 3 | #include <tlhelp32.h> |
4 | #include <iostream> | 4 | #include <iostream> |
5 | #include <cassert> | ||
5 | 6 | ||
6 | #undef PROCESSENTRY32 | 7 | #undef PROCESSENTRY32 |
7 | #undef Process32Next | 8 | #undef Process32Next |
@@ -53,15 +54,15 @@ Memory::~Memory() { | |||
53 | } | 54 | } |
54 | } | 55 | } |
55 | 56 | ||
56 | int Memory::GetCurrentFrame() | 57 | int Memory::GetCurrentFrame() { |
57 | { | ||
58 | int SCRIPT_FRAMES; | 58 | int SCRIPT_FRAMES; |
59 | if (GLOBALS == 0x5B28C0) { | 59 | if (GLOBALS == 0x5B28C0) { |
60 | SCRIPT_FRAMES = 0x5BE3B0; | 60 | SCRIPT_FRAMES = 0x5BE3B0; |
61 | } else if (GLOBALS == 0x62D0A0) { | 61 | } else if (GLOBALS == 0x62D0A0) { |
62 | SCRIPT_FRAMES = 0x63651C; | 62 | SCRIPT_FRAMES = 0x63954C; |
63 | } else { | 63 | } else { |
64 | throw std::exception("Unknown value for Globals!"); | 64 | assert(false); |
65 | return 0x7FFFFFFF; | ||
65 | } | 66 | } |
66 | return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | 67 | return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; |
67 | } | 68 | } |
@@ -108,14 +109,15 @@ int Memory::ExecuteSigScans() | |||
108 | } | 109 | } |
109 | 110 | ||
110 | void Memory::ThrowError() { | 111 | void Memory::ThrowError() { |
111 | std::string message(256, '\0'); | 112 | std::wstring message(256, '\0'); |
112 | int length = FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.size()), nullptr); | 113 | int length = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.size()), nullptr); |
113 | message.resize(length); | 114 | message.resize(length); |
114 | throw std::exception(message.c_str()); | 115 | #ifndef NDEBUG |
116 | MessageBox(NULL, message.c_str(), L"Please tell darkid about this", MB_OK); | ||
117 | #endif | ||
115 | } | 118 | } |
116 | 119 | ||
117 | void* Memory::ComputeOffset(std::vector<int> offsets) | 120 | void* Memory::ComputeOffset(std::vector<int> offsets) { |
118 | { | ||
119 | // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. | 121 | // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. |
120 | int final_offset = offsets.back(); | 122 | int final_offset = offsets.back(); |
121 | offsets.pop_back(); | 123 | offsets.pop_back(); |
@@ -128,7 +130,10 @@ void* Memory::ComputeOffset(std::vector<int> offsets) | |||
128 | if (search == std::end(_computedAddresses)) { | 130 | if (search == std::end(_computedAddresses)) { |
129 | // If the address is not yet computed, then compute it. | 131 | // If the address is not yet computed, then compute it. |
130 | uintptr_t computedAddress = 0; | 132 | uintptr_t computedAddress = 0; |
131 | if (!ReadProcessMemory(_handle, reinterpret_cast<LPVOID>(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { | 133 | if (bool result = !ReadProcessMemory(_handle, reinterpret_cast<LPVOID>(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { |
134 | if (GetLastError() == ERROR_PARTIAL_COPY) { | ||
135 | int k = 1; | ||
136 | } | ||
132 | ThrowError(); | 137 | ThrowError(); |
133 | } | 138 | } |
134 | _computedAddresses[cumulativeAddress] = computedAddress; | 139 | _computedAddresses[cumulativeAddress] = computedAddress; |