VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
EngineInterfaces.cpp
Go to the documentation of this file.
2
4#include <eiface.h>
5#include <filesystem.h>
6#include <format>
7#include <icvar.h>
8#include <interfaces/interfaces.h>
9#include <iserver.h>
10#include <networksystem/inetworkmessages.h>
11#include <schemasystem/schemasystem.h>
12
13namespace VoltMod
14{
15
16/** Naming the version is the point: a game update is what breaks one. */
17template <class Iface>
18static Status Find(Iface*& target, InterfaceFactory factory, const char* version)
19{
20 target = static_cast<Iface*>(factory(version, nullptr));
21 if (target == nullptr)
22 {
23 return std::unexpected(Error::Engine(std::format("could not find interface: {}", version)));
24 }
25 return {};
26}
27
28template <class Iface>
29static void FindOptional(Iface*& target, InterfaceFactory factory, const char* version)
30{
31 if (Status found = Find(target, factory, version); !found)
32 {
33 Log::Error("{}", found.error().Detail);
34 }
35}
36
38{
39 const InterfaceFactory engine = start.EngineFactory;
40 const InterfaceFactory server = start.ServerFactory;
42
43 for (const Status& required : {
44 Find(found.ServerGameDll, server, INTERFACEVERSION_SERVERGAMEDLL),
45 Find(found.ServerGameClients, server, INTERFACEVERSION_SERVERGAMECLIENTS),
47 Find(found.GameEntities, server, INTERFACEVERSION_SERVERGAMEENTS),
50 })
51 {
52 if (!required)
53 {
54 return std::unexpected(required.error());
55 }
56 }
57
62 return found;
63}
64
65} // namespace VoltMod
void Error(std::format_string< Args... > fmt, Args &&... args)
Definition Log.hpp:97
static Status Find(Iface *&target, InterfaceFactory factory, const char *version)
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
void *(*)(const char *name, int *returnCode) InterfaceFactory
Result< EngineInterfaces > ResolveEngineInterfaces(const LoaderHandoff &start)
static void FindOptional(Iface *&target, InterfaceFactory factory, const char *version)
std::expected< void, Error > Status
Definition Result.hpp:67
std::expected< T, Error > Result
Definition Result.hpp:64
static Error Engine(std::string detail)
Definition Result.hpp:58