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
0 commit comments