summary refs log tree commit diff stats
path: root/Source/Memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Memory.h')
-rw-r--r--Source/Memory.h27
1 files changed, 22 insertions, 5 deletions
diff --git a/Source/Memory.h b/Source/Memory.h index 6b8403f..af4f0ae 100644 --- a/Source/Memory.h +++ b/Source/Memory.h
@@ -35,7 +35,14 @@ public:
35 35
36 template <class T> 36 template <class T>
37 void WriteArray(int panel, int offset, const std::vector<T>& data) { 37 void WriteArray(int panel, int offset, const std::vector<T>& data) {
38 WriteData<T>({GLOBALS, 0x18, panel*8, offset, 0}, data); 38 WriteData({GLOBALS, 0x18, panel*8, offset, 0}, data);
39 }
40
41 template <class T>
42 void WriteNewArray(int panel, int offset, const std::vector<T>& data) {
43 std::vector<uintptr_t> newAddr = {Allocate(data.size() * sizeof(T))};
44 WritePanelData(panel, offset, newAddr);
45 WriteArray(panel, offset, data);
39 } 46 }
40 47
41 template <class T> 48 template <class T>
@@ -45,7 +52,7 @@ public:
45 52
46 template <class T> 53 template <class T>
47 void WritePanelData(int panel, int offset, const std::vector<T>& data) { 54 void WritePanelData(int panel, int offset, const std::vector<T>& data) {
48 WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data); 55 WriteData({GLOBALS, 0x18, panel*8, offset}, data);
49 } 56 }
50 57
51 void AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc); 58 void AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc);
@@ -57,9 +64,12 @@ private:
57 if (numItems == 0) return {}; 64 if (numItems == 0) return {};
58 std::vector<T> data; 65 std::vector<T> data;
59 data.resize(numItems); 66 data.resize(numItems);
67 void* computedOffset = ComputeOffset(offsets);
60 for (int i=0; i<5; i++) { 68 for (int i=0; i<5; i++) {
61 if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr)) 69 if (ReadProcessMemory(_handle, computedOffset, &data[0], sizeof(T) * numItems, nullptr)) {
62 { 70 if (i != 0) {
71 int k = 0;
72 }
63 return data; 73 return data;
64 } 74 }
65 } 75 }
@@ -70,8 +80,12 @@ private:
70 template <class T> 80 template <class T>
71 void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { 81 void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) {
72 if (data.empty()) return; 82 if (data.empty()) return;
83 void* computedOffset = ComputeOffset(offsets);
73 for (int i=0; i<5; i++) { 84 for (int i=0; i<5; i++) {
74 if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) { 85 if (WriteProcessMemory(_handle, computedOffset, &data[0], sizeof(T) * data.size(), nullptr)) {
86 if (i != 0) {
87 int k = 0;
88 }
75 return; 89 return;
76 } 90 }
77 } 91 }
@@ -82,6 +96,7 @@ private:
82 bool Initialize(); 96 bool Initialize();
83 void ThrowError(); 97 void ThrowError();
84 void* ComputeOffset(std::vector<int> offsets); 98 void* ComputeOffset(std::vector<int> offsets);
99 uintptr_t Allocate(size_t bytes);
85 100
86 int _previousFrame = 0; 101 int _previousFrame = 0;
87 bool _threadActive = false; 102 bool _threadActive = false;
@@ -90,6 +105,8 @@ private:
90 std::map<uintptr_t, uintptr_t> _computedAddresses; 105 std::map<uintptr_t, uintptr_t> _computedAddresses;
91 uintptr_t _baseAddress = 0; 106 uintptr_t _baseAddress = 0;
92 HANDLE _handle = nullptr; 107 HANDLE _handle = nullptr;
108 uintptr_t _freeMem = 0;
109 uintptr_t _freeMemEnd = 0;
93 struct SigScan { 110 struct SigScan {
94 std::function<void(int)> scanFunc; 111 std::function<void(int)> scanFunc;
95 bool found; 112 bool found;