Skip to content

Commit 4e5a6d2

Browse files
committed
fix get_module_pattern throwing compiler warnings and some tweaks
1 parent b918b33 commit 4e5a6d2

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

PoolManager/PoolManager.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[POOL_SETTINGS]
2-
#BOOLS: 0 = false / 1 = true
2+
#BOOLS: 0 = FALSE / 1 = TRUE
33

44
#TYPE BOOL: This logs pool value total amounts during startup to PoolManager_Startup.log
55
LogInitialPoolAmounts = 1

PoolManager/include/Hooking.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ namespace hook
1313
{
1414
//find patterns in external module
1515
template<typename T = void>
16-
inline auto get_module_pattern(const char* modulename, std::string_view pattern_string, ptrdiff_t offset = 0)
16+
inline auto get_module_pattern(std::string_view moduleName, std::string_view pattern_string, ptrdiff_t offset = 0)
1717
{
18-
auto moduleHandle = GetModuleHandle(modulename);
19-
20-
if (moduleHandle != nullptr)
18+
auto moduleHandle = GetModuleHandle(moduleName.data());
19+
auto match = pattern(moduleHandle, std::move(pattern_string)).get_first<T>(offset);
20+
if ((moduleHandle != nullptr) && (match != nullptr))
21+
{
22+
return match;
23+
}
24+
else
2125
{
22-
return pattern(moduleHandle, std::move(pattern_string)).get_first<T>(offset);
26+
throw std::runtime_error("pattern not found!");
2327
}
2428
}
2529

@@ -65,7 +69,7 @@ namespace hook
6569
LPVOID funcStub = AllocateFunctionStub((void*)GetModuleHandle(NULL), get_func_ptr<T>::get(func), Register);
6670

6771
put<uint8_t>(address, 0xE8);
68-
put<int>((uintptr_t)address + 1, (intptr_t)funcStub - (intptr_t)address - 5);
72+
put<int>((uintptr_t)address + 1, (intptr_t)funcStub - (intptr_t)uintptr_t(address) - 5);
6973
}
7074

7175
template <typename T, typename AT>

PoolManager/poolmanager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class RageHashList
5656
ankerl::unordered_dense::map<uint32_t, std::string_view> m_lookupList;
5757
};
5858

59-
int LogPercentUsageWarning = GetPrivateProfileInt("POOL_SETTINGS", "LogPercentUsageWarning", 0, ".\\PoolManager.toml");
59+
BOOL LogPercentUsageWarning = GetPrivateProfileInt("POOL_SETTINGS", "LogPercentUsageWarning", FALSE, ".\\PoolManager.toml");
6060
int LogPercentUsageWarningAmount = GetPrivateProfileInt("POOL_SETTINGS", "LogPercentUsageWarningAmount", 50, ".\\PoolManager.toml");
61-
int LogInitialPoolAmounts = GetPrivateProfileInt("POOL_SETTINGS", "LogInitialPoolAmounts ", 0, ".\\PoolManager.toml");
61+
BOOL LogInitialPoolAmounts = GetPrivateProfileInt("POOL_SETTINGS", "LogInitialPoolAmounts ", FALSE, ".\\PoolManager.toml");
6262

6363
static std::string LastPoolLogged;
6464
static int LastSizeLogged;
@@ -69,14 +69,14 @@ static void cleanUpLogs()
6969
{
7070
if (!clearedLogs)
7171
{
72-
if (LogInitialPoolAmounts != 0)
72+
if (LogInitialPoolAmounts != FALSE)
7373
{
7474
std::ofstream outfile;
7575
outfile.open("PoolManager_Startup.log", std::ofstream::out | std::ofstream::trunc);
7676
outfile.close();
7777
}
7878

79-
if (LogPercentUsageWarning != 0)
79+
if (LogPercentUsageWarning != FALSE)
8080
{
8181
std::ofstream outfile;
8282
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)
643643
auto value = g_origPoolAllocate(pool, unk);
644644

645645

646-
if (LogPercentUsageWarning != 0)
646+
if (LogPercentUsageWarning == TRUE)
647647
{
648648
if ((float)pool->GetCount() / (float)pool->GetSize() * 100.00f > LogPercentUsageWarningAmount)
649649
{
@@ -762,7 +762,7 @@ std::uint32_t GetSizeOfPool(VOID* _this, std::uint32_t poolHash, std::uint32_t d
762762
if (it == g_intPools.end())
763763
{
764764
g_intPools.insert({ poolName, value });
765-
if (LogInitialPoolAmounts != 0)
765+
if (LogInitialPoolAmounts == TRUE)
766766
{
767767
if (poolName == poolNameHash)
768768
{

0 commit comments

Comments
 (0)