From 4ad724eaae7be3780b5fb891b391bbf4ef26f410 Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sun, 9 Dec 2018 11:48:17 -0800 Subject: Improve internals of sigscanning, fix a small overwrite bug --- Source/Memory.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'Source/Memory.cpp') 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() return ReadData({SCRIPT_FRAMES}, 1)[0]; } -void Memory::SigScan(std::function& data)> scanFunc) +void Memory::AddSigScan(const std::vector& scanBytes, const std::function& scanFunc) +{ + _sigScans[scanBytes] = {scanFunc, false}; +} + +int find(const std::vector &data, const std::vector& search, size_t startIndex = 0) { + for (size_t i=startIndex; i(i); + } + return -1; +} + +int Memory::ExecuteSigScans() { for (int i=0; i<0x200000; i+=0x1000) { std::vector data = ReadData({i}, 0x1100); - scanFunc(i, data); + + for (auto& [scanBytes, sigScan] : _sigScans) { + if (sigScan.found) continue; + int index = find(data, scanBytes); + if (index == -1) continue; + sigScan.scanFunc(i + index); + sigScan.found = true; + } + } + + int notFound = 0; + for (auto it : _sigScans) { + if (it.second.found == false) notFound++; } + return notFound; } void Memory::ThrowError() { -- cgit 1.4.1