mirror of
https://github.com/fedddddd/iw5-gsc-utils.git
synced 2026-08-01 04:40:34 +00:00
add mysql & http funcs
This commit is contained in:
+65
-11
@@ -3,22 +3,76 @@
|
||||
|
||||
#include "plugin.hpp"
|
||||
|
||||
#include "game/game.hpp"
|
||||
|
||||
#include <utils/hook.hpp>
|
||||
#include <utils/binary_resource.hpp>
|
||||
#include <utils/nt.hpp>
|
||||
#include <utils/cryptography.hpp>
|
||||
#include <utils/io.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
utils::hook::detour load_library_hook;
|
||||
|
||||
std::string extract_resource(const std::string& name, const int resource)
|
||||
{
|
||||
const auto data = utils::nt::load_resource(resource);
|
||||
const auto path = std::filesystem::current_path() / "tmp" / name;
|
||||
const auto path_str = path.generic_string();
|
||||
|
||||
if (!utils::io::write_file(path_str, data))
|
||||
{
|
||||
const auto current = utils::io::read_file(path_str);
|
||||
const auto hash_current = utils::cryptography::md5::compute(current);
|
||||
const auto hash_target = utils::cryptography::md5::compute(data);
|
||||
if (hash_target != hash_current)
|
||||
{
|
||||
throw std::runtime_error("failed to extract libmysql.dll!");
|
||||
}
|
||||
}
|
||||
|
||||
return path_str;
|
||||
}
|
||||
|
||||
HMODULE __stdcall load_library_stub(LPCSTR lib_name, HANDLE file, DWORD flags)
|
||||
{
|
||||
if (lib_name == "libmysql.dll"s)
|
||||
{
|
||||
const auto path = extract_resource(lib_name, LIBMYSQL_DLL);
|
||||
const auto handle = load_library_hook.invoke_pascal<HMODULE>(path.data(), file, flags);
|
||||
|
||||
if (handle != nullptr)
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(std::format("failed to load libmysql.dll: {}", GetLastError()));
|
||||
}
|
||||
}
|
||||
|
||||
return load_library_hook.invoke_pascal<HMODULE>(lib_name, file, flags);
|
||||
}
|
||||
}
|
||||
|
||||
PLUTONIUM_API plutonium::sdk::plugin* PLUTONIUM_CALLBACK on_initialize()
|
||||
{
|
||||
return plugin::get();
|
||||
return plugin::get();
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE /*module*/, DWORD reason, LPVOID /*reserved*/)
|
||||
BOOL APIENTRY DllMain(HMODULE module, DWORD ul_reason_for_call, LPVOID /*reserved*/)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
utils::nt::library::set_current_handle(module);
|
||||
load_library_hook.create(LoadLibraryExA, load_library_stub);
|
||||
}
|
||||
|
||||
}
|
||||
if (ul_reason_for_call == DLL_PROCESS_DETACH)
|
||||
{
|
||||
component_loader::on_shutdown();
|
||||
}
|
||||
|
||||
if (reason == DLL_PROCESS_DETACH)
|
||||
{
|
||||
component_loader::on_shutdown();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user