Skip to content

Commit e02fc9b

Browse files
committed
impl: Implemented interfaces for Valve functions
1 parent 59c6f00 commit e02fc9b

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed

src/interfaces/color.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************************
2+
* @file color.hpp
3+
* @brief Source Engine color interface.
4+
* @author Orsell, Nullderef
5+
* @date 07 2025
6+
*********************************************************************/
7+
8+
#pragma once
9+
10+
#ifndef COLOR_HPP
11+
#define COLOR_HPP
12+
13+
#include <cstdint>
14+
15+
struct Color
16+
{
17+
Color(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a = 255) : r(r), g(g), b(b), a(a) {}
18+
uint8_t r, g, b, a;
19+
};
20+
21+
#endif

src/interfaces/gameevents.hpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*******************************************************************
2+
* @file gameevents.hpp
3+
* @brief Source Engine game events interface.
4+
* @author Orsell
5+
* @date 07 2025
6+
*********************************************************************/
7+
8+
#pragma once
9+
10+
#ifndef GAMEEVENT_HPP
11+
#define GAMEEVENT_HPP
12+
13+
#include <cstdint>
14+
15+
class bf_write;
16+
17+
class IGameEventVisitor2
18+
{
19+
public:
20+
virtual bool VisitLocal(const char* name, const void* value) { return true; }
21+
virtual bool VisitString(const char* name, const char* value) { return true; }
22+
virtual bool VisitFloat(const char* name, float value) { return true; }
23+
virtual bool VisitInt(const char* name, int value) { return true; }
24+
virtual bool VisitUint64(const char* name, uint64_t value) { return true; }
25+
virtual bool VisitWString(const char* name, const wchar_t* value) { return true; }
26+
virtual bool VisitBool(const char* name, bool value) { return true; }
27+
};
28+
29+
class IGameEvent
30+
{
31+
public:
32+
virtual ~IGameEvent() = default;
33+
virtual const char* GetName() const = 0;
34+
35+
virtual bool IsReliable() const = 0;
36+
virtual bool IsLocal() const = 0;
37+
virtual bool IsEmpty(const char* keyName = nullptr) const = 0;
38+
39+
virtual bool GetBool(const char* keyName = nullptr, bool defaultValue = false) const = 0;
40+
virtual int GetInt(const char* keyName = nullptr, int defaultValue = 0) const = 0;
41+
virtual uint64_t GetUint64(const char* keyName = nullptr, uint64_t defaultValue = 0) const = 0;
42+
virtual float GetFloat(const char* keyName = nullptr, float defaultValue = 0.0f) const = 0;
43+
virtual const char* GetString(const char* keyName = nullptr, const char* defaultValue = "") const = 0;
44+
virtual const wchar_t* GetWString(const char* keyName = nullptr, const wchar_t* defaultValue = L"") const = 0;
45+
virtual const void* GetPtr(const char* keyName = nullptr) const = 0;
46+
47+
virtual void SetBool(const char* keyName, bool value) = 0;
48+
virtual void SetInt(const char* keyName, int value) = 0;
49+
virtual void SetUint64(const char* keyName, uint64_t value) = 0;
50+
virtual void SetFloat(const char* keyName, float value) = 0;
51+
virtual void SetString(const char* keyName, const char* value) = 0;
52+
virtual void SetWString(const char* keyName, const wchar_t* value) = 0;
53+
virtual void SetPtr(const char* keyName, const void* value) = 0;
54+
55+
virtual bool ForEventData(IGameEventVisitor2* event) const = 0;
56+
};
57+
58+
#define EVENT_DEBUG_ID_INIT 42
59+
#define EVENT_DEBUG_ID_SHUTDOWN 13
60+
61+
class IGameEventListener2
62+
{
63+
public:
64+
virtual ~IGameEventListener2() = default;
65+
66+
virtual void FireGameEvent(IGameEvent* event) = 0;
67+
virtual int GetEventDebugID() = 0;
68+
};
69+
70+
class IGameEventManager2
71+
{
72+
public:
73+
virtual ~IGameEventManager2() = default;
74+
virtual int LoadEventsFromFile(const char* filename) = 0;
75+
virtual void Reset() = 0;
76+
77+
virtual bool AddListener(IGameEventListener2* listener, const char* name, bool bServerSide) = 0;
78+
virtual bool FindListener(IGameEventListener2* listener, const char* name) = 0;
79+
virtual void RemoveListener(IGameEventListener2* listener) = 0;
80+
virtual bool AddListenerGlobal(IGameEventListener2* listener, bool bServerSide) = 0;
81+
82+
virtual IGameEvent* CreateEvent(const char* name, bool bForce = false, int* pCookie = nullptr) = 0;
83+
virtual bool FireEvent(IGameEvent* event, bool bDontBroadcast = false) = 0;
84+
virtual bool FireEventClientSide(IGameEvent* event) = 0;
85+
virtual IGameEvent* DuplicateEvent(IGameEvent* event) = 0;
86+
virtual void FreeEvent(IGameEvent* event) = 0;
87+
88+
virtual bool SerializeEvent(IGameEvent* event, bf_write* eventMsg) = 0;
89+
virtual IGameEvent* UnserializeEvent(const bf_write& eventMsg) = 0;
90+
};
91+
92+
#endif

src/interfaces/serverplugin.hpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*******************************************************************
2+
* @file serverplugin.hpp
3+
* @brief Source Engine server plugin interface.
4+
* @author Orsell
5+
* @date 07 2025
6+
*********************************************************************/
7+
8+
#pragma once
9+
10+
typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode);
11+
12+
struct Edict;
13+
class CCommand;
14+
15+
enum class PluginResult
16+
{
17+
Continue = 0, // keep going
18+
Override, // run the game dll function but use our return value instead
19+
Stop, // don't run the game dll function at all
20+
};
21+
22+
typedef int QueryCvarCookie;
23+
enum class QueryCvarValueStatus
24+
{
25+
ValueIntact = 0, // It got the value fine.
26+
CvarNotFound,
27+
NotACvar, // There's a ConCommand, but it's not a ConVar.
28+
CvarProtected // The cvar was marked with FCVAR_SERVER_CAN_NOT_QUERY, so the server is not allowed to have its value.
29+
};
30+
31+
class IServerPluginCallbacks
32+
{
33+
public:
34+
virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory) = 0;
35+
virtual void Unload() = 0;
36+
virtual void Pause() = 0;
37+
virtual void UnPause() = 0;
38+
virtual const char* GetPluginDescription() = 0;
39+
virtual void LevelInit(const char* mapName) = 0;
40+
virtual void ServerActivate(Edict* edictList, int edictCount, int clientMax) = 0;
41+
virtual void GameFrame(bool simulating) = 0;
42+
virtual void LevelShutdown() = 0;
43+
virtual void ClientActive(Edict* edict) = 0;
44+
virtual void ClientFullyConnect(Edict* edict) = 0;
45+
virtual void ClientDisconnect(Edict* edict) = 0;
46+
virtual void ClientPutInServer(Edict* edict, char const* playerName) = 0;
47+
virtual void SetCommandClient(int index) = 0;
48+
virtual void ClientSettingsChanged(Edict* edict) = 0;
49+
virtual PluginResult ClientConnect(bool* allowConnect, Edict* edict, const char* name, const char* ipAddress, char* reject, int maxRejectLen) = 0;
50+
virtual PluginResult ClientCommand(Edict* edict, const CCommand& args) = 0;
51+
virtual PluginResult NetworkIDValidated(const char* username, const char* networkID) = 0;
52+
virtual void OnQueryCvarValueFinished(QueryCvarCookie cookie, Edict* edict, QueryCvarValueStatus status, const char* cvarName, const char* cvarValue) = 0;
53+
virtual void OnEdictAllocated(Edict* edict) = 0;
54+
virtual void OnEdictFreed(const Edict* edict) = 0;
55+
};

0 commit comments

Comments
 (0)