summary refs log tree commit diff stats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Memory.cpp33
-rw-r--r--Source/Memory.h4
2 files changed, 2 insertions, 35 deletions
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 26ef7e4..55ef18a 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp
@@ -192,36 +192,3 @@ void* Memory::ComputeOffset(std::vector<int> offsets) {
192 } 192 }
193 return reinterpret_cast<void*>(cumulativeAddress + final_offset); 193 return reinterpret_cast<void*>(cumulativeAddress + final_offset);
194} 194}
195
196uintptr_t Memory::Allocate(size_t bytes) {
197/*
198uintptr_t ForeignProcessMemory::AllocateMemory(size_t Size, DWORD Flags) const {
199 if (!ProcessHandle) {
200 return 0;
201 }
202 return (uintptr_t)VirtualAllocEx(ProcessHandle, nullptr, Size, MEM_RESERVE | MEM_COMMIT, Flags);
203}
204
205void ForeignProcessMemory::DeallocateMemory(uintptr_t Addr) const {
206 if (!ProcessHandle || Addr == 0) {
207 return;
208 }
209 VirtualFreeEx(ProcessHandle, (void*)Addr, 0, MEM_RELEASE);
210}
211*/
212 uintptr_t current = _freeMem;
213 _freeMem += bytes;
214
215 if (_freeMem > _freeMemEnd) {
216 // If we don't have enough space at our current location, go allocate some more space.
217 // Note that the remaining space in our current page is unused. Oh well.
218 _freeMem = reinterpret_cast<uintptr_t>(::VirtualAllocEx(_handle, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
219 _freeMemEnd = _freeMem + 0x1000;
220
221 current = _freeMem;
222 _freeMem += bytes;
223 assert(_freeMem <= _freeMemEnd); // Don't allocate data > 0x1000 at a time. Duh.
224 }
225
226 return current;
227}
diff --git a/Source/Memory.h b/Source/Memory.h index 70a271e..79fbaba 100644 --- a/Source/Memory.h +++ b/Source/Memory.h
@@ -41,9 +41,9 @@ public:
41 41
42 template <class T> 42 template <class T>
43 void WriteNewArray(int id, int offset, const std::vector<T>& data) { 43 void WriteNewArray(int id, int offset, const std::vector<T>& data) {
44 uintptr_t addr = VirtualAllocEx(_handle, nullptr, data.size() * sizeof(T), MEM_RESERVE | MEM_COMMIT, MEM_READWRITE); 44 uintptr_t addr = (uintptr_t)VirtualAllocEx(_handle, nullptr, data.size() * sizeof(T), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
45 _allocations.emplace_back(addr); 45 _allocations.emplace_back(addr);
46 WriteEntityData(id, offset, addr); 46 WriteEntityData<uintptr_t>(id, offset, {addr});
47 WriteArray(id, offset, data); 47 WriteArray(id, offset, data);
48 } 48 }
49 49