about summary refs log tree commit diff stats
path: root/Source/Memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Memory.cpp')
-rw-r--r--Source/Memory.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 43cb9b3..2d0d4a9 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp
@@ -63,12 +63,45 @@ int Memory::GetCurrentFrame()
63 return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; 63 return ReadData<int>({SCRIPT_FRAMES}, 1)[0];
64} 64}
65 65
66void Memory::SigScan(std::function<void(int offset, const std::vector<byte>& data)> scanFunc) 66void Memory::AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc)
67{
68 _sigScans[scanBytes] = {scanFunc, false};
69}
70
71int find(const std::vector<byte> &data, const std::vector<byte>& search, size_t startIndex = 0) {
72 for (size_t i=startIndex; i<data.size() - search.size(); i++) {
73 bool match = true;
74 for (size_t j=0; j<search.size(); j++) {
75 if (data[i+j] == search[j]) {
76 continue;
77 }
78 match = false;
79 break;
80 }
81 if (match) return static_cast<int>(i);
82 }
83 return -1;
84}
85
86int Memory::ExecuteSigScans()
67{ 87{
68 for (int i=0; i<0x200000; i+=0x1000) { 88 for (int i=0; i<0x200000; i+=0x1000) {
69 std::vector<byte> data = ReadData<byte>({i}, 0x1100); 89 std::vector<byte> data = ReadData<byte>({i}, 0x1100);
70 scanFunc(i, data); 90
91 for (auto& [scanBytes, sigScan] : _sigScans) {
92 if (sigScan.found) continue;
93 int index = find(data, scanBytes);
94 if (index == -1) continue;
95 sigScan.scanFunc(i + index);
96 sigScan.found = true;
97 }
98 }
99
100 int notFound = 0;
101 for (auto it : _sigScans) {
102 if (it.second.found == false) notFound++;
71 } 103 }
104 return notFound;
72} 105}
73 106
74void Memory::ThrowError() { 107void Memory::ThrowError() {