From 4e5a6d235813bee61331fb2198f5e95a3621c4b4 Mon Sep 17 00:00:00 2001 From: _Sakura <97910292+0x-FADED@users.noreply.github.com> Date: Wed, 4 Jan 2023 18:28:16 +0900 Subject: [PATCH] fix get_module_pattern throwing compiler warnings and some tweaks --- PoolManager/PoolManager.toml | 2 +- PoolManager/include/Hooking.h | 16 ++++++++++------ PoolManager/poolmanager.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PoolManager/PoolManager.toml b/PoolManager/PoolManager.toml index 6311525..116b219 100644 --- a/PoolManager/PoolManager.toml +++ b/PoolManager/PoolManager.toml @@ -1,5 +1,5 @@ [POOL_SETTINGS] -#BOOLS: 0 = false / 1 = true +#BOOLS: 0 = FALSE / 1 = TRUE #TYPE BOOL: This logs pool value total amounts during startup to PoolManager_Startup.log LogInitialPoolAmounts = 1 diff --git a/PoolManager/include/Hooking.h b/PoolManager/include/Hooking.h index f160c42..c182c6f 100644 --- a/PoolManager/include/Hooking.h +++ b/PoolManager/include/Hooking.h @@ -13,13 +13,17 @@ namespace hook { //find patterns in external module template - inline auto get_module_pattern(const char* modulename, std::string_view pattern_string, ptrdiff_t offset = 0) + inline auto get_module_pattern(std::string_view moduleName, std::string_view pattern_string, ptrdiff_t offset = 0) { - auto moduleHandle = GetModuleHandle(modulename); - - if (moduleHandle != nullptr) + auto moduleHandle = GetModuleHandle(moduleName.data()); + auto match = pattern(moduleHandle, std::move(pattern_string)).get_first(offset); + if ((moduleHandle != nullptr) && (match != nullptr)) + { + return match; + } + else { - return pattern(moduleHandle, std::move(pattern_string)).get_first(offset); + throw std::runtime_error("pattern not found!"); } } @@ -65,7 +69,7 @@ namespace hook LPVOID funcStub = AllocateFunctionStub((void*)GetModuleHandle(NULL), get_func_ptr::get(func), Register); put(address, 0xE8); - put((uintptr_t)address + 1, (intptr_t)funcStub - (intptr_t)address - 5); + put((uintptr_t)address + 1, (intptr_t)funcStub - (intptr_t)uintptr_t(address) - 5); } template diff --git a/PoolManager/poolmanager.cpp b/PoolManager/poolmanager.cpp index 58c5235..ab34187 100644 --- a/PoolManager/poolmanager.cpp +++ b/PoolManager/poolmanager.cpp @@ -56,9 +56,9 @@ class RageHashList ankerl::unordered_dense::map m_lookupList; }; -int LogPercentUsageWarning = GetPrivateProfileInt("POOL_SETTINGS", "LogPercentUsageWarning", 0, ".\\PoolManager.toml"); +BOOL LogPercentUsageWarning = GetPrivateProfileInt("POOL_SETTINGS", "LogPercentUsageWarning", FALSE, ".\\PoolManager.toml"); int LogPercentUsageWarningAmount = GetPrivateProfileInt("POOL_SETTINGS", "LogPercentUsageWarningAmount", 50, ".\\PoolManager.toml"); -int LogInitialPoolAmounts = GetPrivateProfileInt("POOL_SETTINGS", "LogInitialPoolAmounts ", 0, ".\\PoolManager.toml"); +BOOL LogInitialPoolAmounts = GetPrivateProfileInt("POOL_SETTINGS", "LogInitialPoolAmounts ", FALSE, ".\\PoolManager.toml"); static std::string LastPoolLogged; static int LastSizeLogged; @@ -69,14 +69,14 @@ static void cleanUpLogs() { if (!clearedLogs) { - if (LogInitialPoolAmounts != 0) + if (LogInitialPoolAmounts != FALSE) { std::ofstream outfile; outfile.open("PoolManager_Startup.log", std::ofstream::out | std::ofstream::trunc); outfile.close(); } - if (LogPercentUsageWarning != 0) + if (LogPercentUsageWarning != FALSE) { std::ofstream outfile; outfile.open("PoolManager_UsageWarning.log", std::ofstream::out | std::ofstream::trunc); @@ -643,7 +643,7 @@ std::int32_t* PoolAllocateWrap(rage::fwBasePool* pool, uint64_t unk) auto value = g_origPoolAllocate(pool, unk); - if (LogPercentUsageWarning != 0) + if (LogPercentUsageWarning == TRUE) { if ((float)pool->GetCount() / (float)pool->GetSize() * 100.00f > LogPercentUsageWarningAmount) { @@ -762,7 +762,7 @@ std::uint32_t GetSizeOfPool(VOID* _this, std::uint32_t poolHash, std::uint32_t d if (it == g_intPools.end()) { g_intPools.insert({ poolName, value }); - if (LogInitialPoolAmounts != 0) + if (LogInitialPoolAmounts == TRUE) { if (poolName == poolNameHash) {