VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Loader.windows.cpp
Go to the documentation of this file.
1#include "Loader/Loader.hpp"
2
3#include <windows.h>
4
5#include <iterator>
6#include <system_error>
7
8namespace VoltMod
9{
10
11void* OpenModule(const std::filesystem::path& path)
12{
13 return LoadLibraryW(path.c_str());
14}
15
16void* FindExport(void* module, const char* name)
17{
18 return reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(module), name));
19}
20
21std::string LastError()
22{
23 return std::system_category().message(static_cast<int>(GetLastError()));
24}
25
26/** The loaded module whose image holds @p address, without taking a reference to it. */
27static HMODULE ModuleAt(const void* address)
28{
29 HMODULE module = nullptr;
31 static_cast<LPCWSTR>(address), &module);
32 return module;
33}
34
35std::filesystem::path OwnPath()
36{
37 static const char inThisModule = 0;
38 wchar_t path[4096];
39 const DWORD length = GetModuleFileNameW(ModuleAt(&inThisModule), path, static_cast<DWORD>(std::size(path)));
40 return std::filesystem::path(path, path + length);
41}
42
44{
45 HMODULE module = ModuleAt(address);
46 return module != nullptr ? reinterpret_cast<InterfaceFactory>(GetProcAddress(module, "CreateInterface")) : nullptr;
47}
48
49} // namespace VoltMod
static std::string LastError()
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
void *(*)(const char *name, int *returnCode) InterfaceFactory
std::filesystem::path OwnPath()
InterfaceFactory FactoryAt(const void *address)
void * OpenModule(const std::filesystem::path &path)
static HMODULE ModuleAt(const void *address)
static void * FindExport(void *handle, const char *name)