diff --git a/SilentPatch/Patterns.h b/SilentPatch/Patterns.h index 0663c60..98823cf 100644 --- a/SilentPatch/Patterns.h +++ b/SilentPatch/Patterns.h @@ -89,16 +89,6 @@ namespace hook }; protected: - inline pattern(void* module) - : m_module(module), m_rangeEnd(0) - { - } - - inline pattern(uintptr_t begin, uintptr_t end) - : m_rangeStart(begin), m_rangeEnd(end) - { - } - void Initialize(std::string_view pattern); private: @@ -111,6 +101,16 @@ namespace hook return m_matches[index]; } + inline pattern(void* module) + : m_module(module), m_rangeEnd(0) + { + } + + inline pattern(uintptr_t begin, uintptr_t end) + : m_rangeStart(begin), m_rangeEnd(end) + { + } + public: template pattern(const char (&pattern)[Len]) @@ -119,6 +119,20 @@ namespace hook Initialize(std::string_view(pattern, Len-1)); } + template + inline pattern(void* module, const char (&pattern)[Len]) + : pattern(module) + { + Initialize(std::string_view(pattern, Len-1)); + } + + template + inline pattern(uintptr_t begin, uintptr_t end, const char (&pattern)[Len]) + : m_rangeStart(begin), m_rangeEnd(end) + { + Initialize(std::string_view(pattern, Len-1)); + } + inline pattern&& count(uint32_t expected) { EnsureMatches(expected); @@ -184,30 +198,17 @@ namespace hook #endif }; - class module_pattern - : public pattern + template + pattern make_module_pattern(void* module, const char (&bytes)[Len]) { - public: - template - module_pattern(void* module, const char(&pattern)[Len]) - : pattern(module) - { - Initialize(pattern, Len-1); - } - }; + return pattern(module, bytes); + } - class range_pattern - : public pattern + template + pattern make_range_pattern(uintptr_t begin, uintptr_t end, const char(&bytes)[Len]) { - public: - template - range_pattern(uintptr_t begin, uintptr_t end, const char(&pattern)[Len]) - : pattern(begin, end) - { - Initialize(std::string_view(pattern, Len-1)); - } - }; - + return pattern(begin, end, bytes); + } template auto get_pattern(const char(&pattern_string)[Len], ptrdiff_t offset = 0)