VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
NetMessage.cpp
Go to the documentation of this file.
2
4#include <engine/igameeventsystem.h>
5#include <networksystem/inetworkmessages.h>
6#include <networksystem/netmessage.h>
7#include <string>
8
9namespace VoltMod
10{
11
13 IRecipientFilter& filter, const std::function<bool(CNetMessage*)>& fill)
14{
15 if (!interfaces.GameEventSystem || !interfaces.NetworkMessages)
16 {
17 return false;
18 }
19
20 if (!cached)
21 {
22 cached = interfaces.NetworkMessages->FindNetworkMessagePartial(std::string(partialName).c_str());
23 }
24 if (!cached)
25 {
26 return false;
27 }
28
29 CNetMessage* message = cached->AllocateMessage();
30 if (!message)
31 {
32 return false;
33 }
34
35 bool posted = false;
36 if (fill(message))
37 {
38 interfaces.GameEventSystem->PostEventAbstract(-1, false, &filter, cached, message, 0);
39 posted = true;
40 }
41
42 interfaces.NetworkMessages->DeallocateNetMessageAbstract(cached, message);
43 return posted;
44}
45
46} // namespace VoltMod
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
bool PostUserMessage(Interfaces &interfaces, INetworkMessageInternal *&cached, std::string_view partialName, IRecipientFilter &filter, const std::function< bool(CNetMessage *)> &fill)
Centralized holder for all HL2SDK interface pointers.