mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-12-29 15:23:02 +05:00
III/VC can use non-serializable (local session only) hints
This commit is contained in:
parent
4b934419bf
commit
51fa496658
4 changed files with 29 additions and 23 deletions
|
@ -37,8 +37,8 @@ struct basic_fnv_1
|
|||
}
|
||||
};
|
||||
|
||||
const std::uint64_t fnv_prime = 1099511628211u;
|
||||
const std::uint64_t fnv_offset_basis = 14695981039346656037u;
|
||||
static constexpr std::uint64_t fnv_prime = 1099511628211u;
|
||||
static constexpr std::uint64_t fnv_offset_basis = 14695981039346656037u;
|
||||
|
||||
typedef basic_fnv_1<fnv_prime, fnv_offset_basis> fnv_1;
|
||||
|
||||
|
@ -56,7 +56,11 @@ namespace hook
|
|||
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
static std::multimap<uint64_t, uintptr_t> g_hints;
|
||||
static auto& getHints()
|
||||
{
|
||||
static std::multimap<uint64_t, uintptr_t> hints;
|
||||
return hints;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void TransformPattern(std::string_view pattern, std::string& data, std::string& mask)
|
||||
|
@ -148,13 +152,13 @@ void pattern::Initialize(const char* pattern, size_t length)
|
|||
// if there's hints, try those first
|
||||
if (m_module == GetModuleHandle(nullptr))
|
||||
{
|
||||
auto range = g_hints.equal_range(m_hash);
|
||||
auto range = getHints().equal_range(m_hash);
|
||||
|
||||
if (range.first != range.second)
|
||||
{
|
||||
std::for_each(range.first, range.second, [&] (const std::pair<uint64_t, uintptr_t>& hint)
|
||||
{
|
||||
ConsiderMatch(hint.second);
|
||||
ConsiderHint(hint.second);
|
||||
});
|
||||
|
||||
// if the hints succeeded, we don't need to do anything more
|
||||
|
@ -181,7 +185,7 @@ void pattern::EnsureMatches(uint32_t maxCount)
|
|||
auto matchSuccess = [&] (uintptr_t address)
|
||||
{
|
||||
#if PATTERNS_USE_HINTS
|
||||
g_hints.emplace(m_hash, address);
|
||||
getHints().emplace(m_hash, address);
|
||||
#else
|
||||
(void)address;
|
||||
#endif
|
||||
|
@ -229,13 +233,14 @@ void pattern::EnsureMatches(uint32_t maxCount)
|
|||
m_matched = true;
|
||||
}
|
||||
|
||||
bool pattern::ConsiderMatch(uintptr_t offset)
|
||||
bool pattern::ConsiderHint(uintptr_t offset)
|
||||
{
|
||||
char* ptr = reinterpret_cast<char*>(offset);
|
||||
|
||||
#if PATTERNS_CAN_SERIALIZE_HINTS
|
||||
const char* pattern = m_bytes.c_str();
|
||||
const char* mask = m_mask.c_str();
|
||||
|
||||
char* ptr = reinterpret_cast<char*>(offset);
|
||||
|
||||
for (size_t i = 0, j = m_mask.size(); i < j; i++)
|
||||
{
|
||||
if (mask[i] == '?')
|
||||
|
@ -248,18 +253,21 @@ bool pattern::ConsiderMatch(uintptr_t offset)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
m_matches.emplace_back(ptr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if PATTERNS_USE_HINTS
|
||||
#if PATTERNS_USE_HINTS && PATTERNS_CAN_SERIALIZE_HINTS
|
||||
void pattern::hint(uint64_t hash, uintptr_t address)
|
||||
{
|
||||
auto range = g_hints.equal_range(hash);
|
||||
auto& hints = getHints();
|
||||
|
||||
for (auto it = range.first; it != range.second; it++)
|
||||
auto range = hints.equal_range(hash);
|
||||
|
||||
for (auto it = range.first; it != range.second; ++it)
|
||||
{
|
||||
if (it->second == address)
|
||||
{
|
||||
|
@ -267,7 +275,7 @@ void pattern::hint(uint64_t hash, uintptr_t address)
|
|||
}
|
||||
}
|
||||
|
||||
g_hints.emplace(hash, address);
|
||||
hints.emplace(hash, address);
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -13,8 +13,6 @@
|
|||
#pragma warning(push)
|
||||
#pragma warning(disable:4201)
|
||||
|
||||
#define PATTERNS_USE_HINTS 0
|
||||
|
||||
namespace hook
|
||||
{
|
||||
extern ptrdiff_t baseAddressDifference;
|
||||
|
@ -103,7 +101,7 @@ namespace hook
|
|||
void Initialize(const char* pattern, size_t length);
|
||||
|
||||
private:
|
||||
bool ConsiderMatch(uintptr_t offset);
|
||||
bool ConsiderHint(uintptr_t offset);
|
||||
|
||||
void EnsureMatches(uint32_t maxCount);
|
||||
|
||||
|
@ -179,7 +177,7 @@ namespace hook
|
|||
}
|
||||
|
||||
public:
|
||||
#if PATTERNS_USE_HINTS
|
||||
#if PATTERNS_USE_HINTS && PATTERNS_CAN_SERIALIZE_HINTS
|
||||
// define a hint
|
||||
static void hint(uint64_t hash, uintptr_t address);
|
||||
#endif
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_GTA_III;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;PATTERNS_USE_HINTS=1;_GTA_III;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\SilentPatch</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
|
||||
|
@ -134,7 +134,7 @@
|
|||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_GTA_III;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;PATTERNS_USE_HINTS=1;_GTA_III;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\SilentPatch</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
|
||||
|
@ -171,7 +171,7 @@
|
|||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<OmitFramePointers>true</OmitFramePointers>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_GTA_III;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;PATTERNS_USE_HINTS=1;_GTA_III;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>..\SilentPatch</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>StdAfx.h</PrecompiledHeaderFile>
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_GTA_VC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;PATTERNS_USE_HINTS=1;_GTA_VC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<AdditionalIncludeDirectories>..\SilentPatch</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
|
@ -103,7 +103,7 @@
|
|||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_GTA_VC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;PATTERNS_USE_HINTS=1;_GTA_VC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
|
@ -138,7 +138,7 @@
|
|||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;_GTA_VC;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_HAS_EXCEPTIONS=0;PATTERNS_USE_HINTS=1;_GTA_VC;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
||||
|
|
Loading…
Reference in a new issue