Better quit_hard
This commit is contained in:
@ -15,9 +15,9 @@ namespace Utils
|
||||
}
|
||||
}
|
||||
|
||||
bool Library::valid()
|
||||
bool Library::is_valid() const
|
||||
{
|
||||
return (this->getModule() != nullptr);
|
||||
return this->_module != nullptr;
|
||||
}
|
||||
|
||||
HMODULE Library::getModule()
|
||||
@ -27,7 +27,7 @@ namespace Utils
|
||||
|
||||
void Library::free()
|
||||
{
|
||||
if (this->valid())
|
||||
if (this->is_valid())
|
||||
{
|
||||
FreeLibrary(this->getModule());
|
||||
}
|
||||
|
@ -9,18 +9,45 @@ namespace Utils
|
||||
Library(const std::string& buffer, bool freeOnDestroy = true);
|
||||
~Library();
|
||||
|
||||
bool valid();
|
||||
bool is_valid() const;
|
||||
HMODULE getModule();
|
||||
|
||||
template <typename T>
|
||||
std::function<T> get(const std::string& process)
|
||||
T get_proc(const std::string& process) const
|
||||
{
|
||||
if (!this->valid())
|
||||
{
|
||||
throw std::runtime_error("Library not loaded!");
|
||||
}
|
||||
if (!this->is_valid()) T{};
|
||||
return reinterpret_cast<T>(GetProcAddress(this->_module, process.data()));
|
||||
}
|
||||
|
||||
return reinterpret_cast<T*>(GetProcAddress(this->getModule(), process.data()));
|
||||
template <typename T>
|
||||
std::function<T> get(const std::string& process) const
|
||||
{
|
||||
if (!this->is_valid()) return std::function<T>();
|
||||
return static_cast<T*>(this->get_proc<void*>(process));
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__cdecl)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_pascal(const std::string& process, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__stdcall)(Args ...)>(process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
template <typename T, typename... Args>
|
||||
T invoke_this(const std::string& process, void* this_ptr, Args ... args) const
|
||||
{
|
||||
auto method = this->get<T(__thiscall)(void*, Args ...)>(this_ptr, process);
|
||||
if (method) return method(args...);
|
||||
return T();
|
||||
}
|
||||
|
||||
void free();
|
||||
|
Reference in New Issue
Block a user