VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
EngineInterfaces.cpp
Go to the documentation of this file.
2
4#include <engine2/inetworkserverservice.h>
5#include <engine2/isource2server.h>
6#include <engine2/ivengineserver2.h>
7#include <filesystem/ifilesystem.h>
8#include <format>
9#include <icvar.h>
10#include <interfaces/interfaces.h>
11#include <networksystem/inetworkmessages.h>
12#include <schemasystem/schemasystem.h>
13
14namespace VoltMod
15{
16
17/** Naming the version is the point: a game update is what breaks one. */
18template <class Iface>
19static Status Find(Iface*& target, InterfaceFactory factory, const char* version)
20{
21 target = static_cast<Iface*>(factory(version, nullptr));
22 if (target == nullptr)
23 {
24 return std::unexpected(Error::Engine(std::format("could not find interface: {}", version)));
25 }
26 return {};
27}
28
29template <class Iface>
30static void FindOptional(Iface*& target, InterfaceFactory factory, const char* version)
31{
32 if (Status found = Find(target, factory, version); !found)
33 {
34 Log::Error("{}", found.error().Detail);
35 }
36}
37
39{
40 const InterfaceFactory engine = start.EngineFactory;
41 const InterfaceFactory server = start.ServerFactory;
42 EngineInterfaces found;
43
44 for (const Status& required : {
45 Find(found.ServerGameDll, server, INTERFACEVERSION_SERVERGAMEDLL),
46 Find(found.ServerGameClients, server, INTERFACEVERSION_SERVERGAMECLIENTS),
47 Find(found.NetworkServerService, engine, NETWORKSERVERSERVICE_INTERFACE_VERSION),
48 Find(found.GameEntities, server, INTERFACEVERSION_SERVERGAMEENTS),
49 Find(found.Cvar, engine, CVAR_INTERFACE_VERSION),
50 Find(found.Engine, engine, INTERFACEVERSION_VENGINESERVER),
51 })
52 {
53 if (!required)
54 {
55 return std::unexpected(required.error());
56 }
57 }
58
59 FindOptional(found.Schema, engine, SCHEMASYSTEM_INTERFACE_VERSION);
60 FindOptional(found.Resources, engine, GAMERESOURCESERVICESERVER_INTERFACE_VERSION);
61 // The SDK's ::GameEntitySystem() reads it.
62 g_pGameResourceServiceServer = found.Resources;
63 FindOptional(found.Files, engine, FILESYSTEM_INTERFACE_VERSION);
64 FindOptional(found.NetworkMessages, engine, NETWORKMESSAGES_INTERFACE_VERSION);
65 return found;
66}
67
68} // namespace VoltMod
void Error(std::format_string< Args... > fmt, Args &&... args)
Definition Log.hpp:97
void *(*)(const char *name, int *returnCode) InterfaceFactory
static Status Find(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
Result< EngineInterfaces > ResolveEngineInterfaces(const LoaderHandoff &start)
static void FindOptional(Iface *&target, InterfaceFactory factory, const char *version)
ISource2GameClients * ServerGameClients
IGameResourceService * Resources
INetworkMessages * NetworkMessages
ISource2GameEntities * GameEntities
INetworkServerService * NetworkServerService
static Error Engine(std::string detail)
Definition Result.hpp:58
InterfaceFactory EngineFactory
InterfaceFactory ServerFactory
the game's own server library, never a loader in front of it