This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/BigBaseV2/src/memory/pattern_batch.cpp

45 lines
1.0 KiB
C++
Raw Normal View History

2019-03-21 20:18:31 +01:00
#include "../common.hpp"
#include "../logger.hpp"
#include "pattern_batch.hpp"
#include "range.hpp"
namespace memory
{
void pattern_batch::add(std::string name, pattern pattern, std::function<void(handle)> callback)
{
m_entries.emplace_back(std::move(name), std::move(pattern), std::move(callback));
}
void pattern_batch::run(range region)
{
bool all_found = true;
for (auto& entry : m_entries)
2019-03-21 20:18:31 +01:00
{
if (auto result = region.scan(entry.m_pattern))
{
if (entry.m_callback)
{
std::invoke(std::move(entry.m_callback), result);
LOG(big::INFO_TO_FILE) << "Found '" << entry.m_name << "' GTA5.exe+" << HEX_TO_UPPER(result.as<DWORD64>() - region.begin().as<DWORD64>());
2019-03-21 20:18:31 +01:00
}
else
{
all_found = false;
LOG(WARNING) << "Failed to find '" << entry.m_name << "'.";
2019-03-21 20:18:31 +01:00
}
}
else
{
all_found = false;
LOG(WARNING) << "Failed to find '" << entry.m_name << "'.";
}
2019-03-21 20:18:31 +01:00
}
m_entries.clear();
if (!all_found)
{
throw std::runtime_error("Failed to find some patterns.");
}
}
}