From 695d0e12950b9df248ea7b84f8434e32acc84f11 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Mon, 18 Nov 2019 08:43:27 -0800 Subject: actually free memory --- Source/Memory.cpp | 33 --------------------------------- Source/Memory.h | 4 ++-- 2 files changed, 2 insertions(+), 35 deletions(-) (limited to 'Source') 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 offsets) { } return reinterpret_cast(cumulativeAddress + final_offset); } - -uintptr_t Memory::Allocate(size_t bytes) { -/* -uintptr_t ForeignProcessMemory::AllocateMemory(size_t Size, DWORD Flags) const { - if (!ProcessHandle) { - return 0; - } - return (uintptr_t)VirtualAllocEx(ProcessHandle, nullptr, Size, MEM_RESERVE | MEM_COMMIT, Flags); -} - -void ForeignProcessMemory::DeallocateMemory(uintptr_t Addr) const { - if (!ProcessHandle || Addr == 0) { - return; - } - VirtualFreeEx(ProcessHandle, (void*)Addr, 0, MEM_RELEASE); -} -*/ - uintptr_t current = _freeMem; - _freeMem += bytes; - - if (_freeMem > _freeMemEnd) { - // If we don't have enough space at our current location, go allocate some more space. - // Note that the remaining space in our current page is unused. Oh well. - _freeMem = reinterpret_cast(::VirtualAllocEx(_handle, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); - _freeMemEnd = _freeMem + 0x1000; - - current = _freeMem; - _freeMem += bytes; - assert(_freeMem <= _freeMemEnd); // Don't allocate data > 0x1000 at a time. Duh. - } - - return current; -} 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: template void WriteNewArray(int id, int offset, const std::vector& data) { - uintptr_t addr = VirtualAllocEx(_handle, nullptr, data.size() * sizeof(T), MEM_RESERVE | MEM_COMMIT, MEM_READWRITE); + uintptr_t addr = (uintptr_t)VirtualAllocEx(_handle, nullptr, data.size() * sizeof(T), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); _allocations.emplace_back(addr); - WriteEntityData(id, offset, addr); + WriteEntityData(id, offset, {addr}); WriteArray(id, offset, data); } -- cgit 1.4.1