13#include <khook/memory.hpp>
15#include <system_error>
17#include <tier0/icommandline.h>
37 void**
slot = *
static_cast<void***
>(
object) + index;
38 KHook::Memory::SetAccess(
slot,
sizeof(
void*),
39 KHook::Memory::Flags::READ | KHook::Memory::Flags::WRITE | KHook::Memory::Flags::EXECUTE);
48 std::filesystem::path
dir =
OwnPath().parent_path();
56static std::string
ReadFile(
const std::filesystem::path& path)
58 std::ifstream
file(path, std::ios::binary);
59 return {std::istreambuf_iterator<char>(
file), std::istreambuf_iterator<char>()};
76 Warning(
"[VoltMod] Could not read %s, so VoltMod is not loaded.\n",
gameinfo.string().c_str());
84 if (!std::filesystem::is_regular_file(server,
missing))
89 void*
module = OpenModule(server);
90 auto*
factory =
module ? reinterpret_cast<InterfaceFactory>(FindExport(module, "CreateInterface")) : nullptr;
97 Msg(
"[VoltMod] Loader started; forwarding the game server to %s\n", server.string().c_str());
103 Warning(
"[VoltMod] No Game path in %s holds a server library, so VoltMod is not loaded.\n",
123 Warning(
"[VoltMod] The engine and game factories were not found, so VoltMod is not loaded.\n");
144 char error[512] =
"";
147 Warning(
"[VoltMod] The host did not start: %s\n",
error);
189static void Patch(
const char* name,
void*
object)
212 if (returnCode !=
nullptr)
214 *returnCode = IFACE_FAILED;
219 void*
object = next(name, returnCode);
220 if (
object !=
nullptr)
void * CreateInterface(const char *name, int *returnCode)
The loader's KHook, which every module's hooks go through.
static bool OnConnect(void *config, InterfaceFactory engineFactory)
constexpr std::string_view HostFile
static void OnDisconnect(void *config)
static HostStopFn g_stopHost
static InitReturnVal_t(* g_init)(void *server)
static std::string LastError()
constexpr std::string_view PlatformDir
static std::string ReadFile(const std::filesystem::path &path)
void *(*)(const char *name, int *returnCode) InterfaceFactory
constexpr const char * HostStopName
static InterfaceFactory LoadNextServer()
static void OnShutdown(void *server)
std::filesystem::path OwnPath()
constexpr const char * HostStartName
static void(* g_disconnect)(void *config)
static void(* g_shutdown)(void *server)
static LoaderHandoff g_start
static std::filesystem::path GameDir()
std::vector< std::string > GameSearchPaths(std::string_view gameinfo)
The Game values under SearchPaths in a gameinfo.gi, in file order.
InterfaceFactory FactoryAt(const void *address)
void * OpenModule(const std::filesystem::path &path)
static KHookForwarder g_dispatcher
static bool(* g_connect)(void *config, InterfaceFactory engineFactory)
static std::string g_gameDir
static void * FindExport(void *handle, const char *name)
static InterfaceFactory FindNextFactory()
constexpr std::string_view ServerFile
bool(*)(const LoaderHandoff *start, char *error, size_t errorSize) HostStartFn
static InitReturnVal_t OnInit(void *server)
static Fn SwapSlot(void *object, int index, Fn replacement)
InterfaceFactory EngineFactory
const char * GameDir
the absolute csgo directory
InterfaceFactory ServerFactory
the game's own server library, never a loader in front of it
KHook::IKHook * HookDispatcher
the loader's KHook, which every module's hooks go through