Skip to content

Commit

Permalink
fix get_module_pattern throwing compiler warnings and some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
0x-FADED committed Jan 4, 2023
1 parent b918b33 commit 4e5a6d2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion PoolManager/PoolManager.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 10 additions & 6 deletions PoolManager/include/Hooking.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ namespace hook
{
//find patterns in external module
template<typename T = void>
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<T>(offset);
if ((moduleHandle != nullptr) && (match != nullptr))
{
return match;
}
else
{
return pattern(moduleHandle, std::move(pattern_string)).get_first<T>(offset);
throw std::runtime_error("pattern not found!");
}
}

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

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

template <typename T, typename AT>
Expand Down
12 changes: 6 additions & 6 deletions PoolManager/poolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class RageHashList
ankerl::unordered_dense::map<uint32_t, std::string_view> 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;
Expand All @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 4e5a6d2

Please sign in to comment.