VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Loader.hpp
Go to the documentation of this file.
1#pragma once
2
4
6#include <filesystem>
7#include <string>
8#include <string_view>
9
10/** The engine loads this module as `server_valve` and asks it for the game server's interfaces. */
11extern "C" VOLTMOD_EXPORT void* CreateInterface(const char* name, int* returnCode);
12
13namespace VoltMod
14{
15
16// CMake passes the host's file name and bin directory, so they cannot drift from the build.
17inline constexpr std::string_view PlatformDir = VOLTMOD_BIN_DIR;
18inline constexpr std::string_view HostFile = VOLTMOD_HOST_FILE;
19#if defined(_WIN32)
20inline constexpr std::string_view ServerFile = "server.dll";
21#else
22inline constexpr std::string_view ServerFile = "libserver.so";
23#endif
24
25// Loader.windows.cpp and Loader.linux.cpp each implement these for their platform.
26
27/** Null on failure, with the reason in @ref LastError. */
28void* OpenModule(const std::filesystem::path& path);
29void* FindExport(void* module, const char* name);
30/** Why the last OpenModule or FindExport failed. */
31std::string LastError();
32
33/** This module's own file. */
34std::filesystem::path OwnPath();
35
36/** `CreateInterface` of the loaded module whose image holds @p address. */
38
39} // namespace VoltMod
VOLTMOD_EXPORT void * CreateInterface(const char *name, int *returnCode)
Definition Loader.cpp:207
#define VOLTMOD_EXPORT
constexpr std::string_view HostFile
Definition Loader.hpp:18
static std::string LastError()
constexpr std::string_view PlatformDir
Definition Loader.hpp:17
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 void * FindExport(void *handle, const char *name)
constexpr std::string_view ServerFile
Definition Loader.hpp:22