mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2025-01-01 16:53:01 +05:00
Update ModuleList.hpp
This commit is contained in:
parent
3895f1c738
commit
3ec5663861
2 changed files with 49 additions and 6 deletions
|
@ -8,10 +8,24 @@
|
||||||
class ModuleList
|
class ModuleList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct LazyEnumerateTag {};
|
||||||
|
|
||||||
|
ModuleList()
|
||||||
|
{
|
||||||
|
Enumerate();
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit ModuleList( LazyEnumerateTag )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// Initializes module list
|
// Initializes module list
|
||||||
// Needs to be called before any calls to Get or GetAll
|
// Needs to be called before any calls to Get or GetAll
|
||||||
void Enumerate()
|
void Enumerate()
|
||||||
{
|
{
|
||||||
|
// Cannot enumerate twice without cleaing
|
||||||
|
assert( m_moduleList.size() == 0 );
|
||||||
|
|
||||||
constexpr size_t INITIAL_SIZE = sizeof(HMODULE) * 256;
|
constexpr size_t INITIAL_SIZE = sizeof(HMODULE) * 256;
|
||||||
HMODULE* modules = static_cast<HMODULE*>(malloc( INITIAL_SIZE ));
|
HMODULE* modules = static_cast<HMODULE*>(malloc( INITIAL_SIZE ));
|
||||||
if ( modules != nullptr )
|
if ( modules != nullptr )
|
||||||
|
@ -115,6 +129,38 @@ public:
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gets handle of a loaded module with given prefix, NULL otherwise
|
||||||
|
HMODULE GetByPrefix( const wchar_t* modulePrefix ) const
|
||||||
|
{
|
||||||
|
// If vector is empty then we're trying to call it without calling Enumerate first
|
||||||
|
assert( m_moduleList.size() != 0 );
|
||||||
|
|
||||||
|
const size_t len = wcslen( modulePrefix );
|
||||||
|
auto it = std::find_if( m_moduleList.begin(), m_moduleList.end(), [&]( const auto& e ) {
|
||||||
|
return _wcsnicmp( modulePrefix, e.second.c_str(), len ) == 0;
|
||||||
|
} );
|
||||||
|
return it != m_moduleList.end() ? it->first : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets handles to all loaded modules with given prefix
|
||||||
|
std::vector<HMODULE> GetAllByPrefix( const wchar_t* modulePrefix ) const
|
||||||
|
{
|
||||||
|
// If vector is empty then we're trying to call it without calling Enumerate first
|
||||||
|
assert( m_moduleList.size() != 0 );
|
||||||
|
|
||||||
|
const size_t len = wcslen( modulePrefix );
|
||||||
|
std::vector<HMODULE> results;
|
||||||
|
for ( auto& e : m_moduleList )
|
||||||
|
{
|
||||||
|
if ( _wcsnicmp( modulePrefix, e.second.c_str(), len ) == 0 )
|
||||||
|
{
|
||||||
|
results.push_back( e.first );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void EnumerateInternal( HMODULE* modules, size_t numModules )
|
void EnumerateInternal( HMODULE* modules, size_t numModules )
|
||||||
{
|
{
|
||||||
|
|
|
@ -2345,8 +2345,7 @@ BOOL InjectDelayedPatches_10()
|
||||||
GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension
|
GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension
|
||||||
PathRenameExtensionW(wcModulePath, L".ini");
|
PathRenameExtensionW(wcModulePath, L".ini");
|
||||||
|
|
||||||
ModuleList moduleList;
|
const ModuleList moduleList;
|
||||||
moduleList.Enumerate();
|
|
||||||
|
|
||||||
const bool bHasImVehFt = moduleList.Get(L"ImVehFt") != nullptr;
|
const bool bHasImVehFt = moduleList.Get(L"ImVehFt") != nullptr;
|
||||||
const bool bSAMP = moduleList.Get(L"samp") != nullptr;
|
const bool bSAMP = moduleList.Get(L"samp") != nullptr;
|
||||||
|
@ -2716,8 +2715,7 @@ BOOL InjectDelayedPatches_11()
|
||||||
GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension
|
GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension
|
||||||
PathRenameExtensionW(wcModulePath, L".ini");
|
PathRenameExtensionW(wcModulePath, L".ini");
|
||||||
|
|
||||||
ModuleList moduleList;
|
const ModuleList moduleList;
|
||||||
moduleList.Enumerate();
|
|
||||||
|
|
||||||
bool bHasImVehFt = moduleList.Get(L"ImVehFt") != nullptr;
|
bool bHasImVehFt = moduleList.Get(L"ImVehFt") != nullptr;
|
||||||
bool bSAMP = moduleList.Get(L"samp") != nullptr;
|
bool bSAMP = moduleList.Get(L"samp") != nullptr;
|
||||||
|
@ -2887,8 +2885,7 @@ BOOL InjectDelayedPatches_Steam()
|
||||||
GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension
|
GetModuleFileNameW(hDLLModule, wcModulePath, _countof(wcModulePath) - 3); // Minus max required space for extension
|
||||||
PathRenameExtensionW(wcModulePath, L".ini");
|
PathRenameExtensionW(wcModulePath, L".ini");
|
||||||
|
|
||||||
ModuleList moduleList;
|
const ModuleList moduleList;
|
||||||
moduleList.Enumerate();
|
|
||||||
|
|
||||||
bool bHasImVehFt = moduleList.Get(L"ImVehFt") != nullptr;
|
bool bHasImVehFt = moduleList.Get(L"ImVehFt") != nullptr;
|
||||||
bool bSAMP = moduleList.Get(L"samp") != nullptr;
|
bool bSAMP = moduleList.Get(L"samp") != nullptr;
|
||||||
|
|
Loading…
Reference in a new issue