8#include <cstrike15_usermessages.pb.h>
9#include <engine2/serversideclient.h>
11#include <netmessages.pb.h>
12#include <networksystem/inetchannel.h>
13#include <networksystem/inetworkmessages.h>
31 if (
Status installed = Install(engine); !installed)
33 Log::Warn(
"Button presses: {}; presses will not arrive.", installed.error().Detail);
41 _messageId = type->GetMessageId();
48 const auto onMessage = [
this](INetworkMessageProcessingPreFilter& filter,
const CNetMessage* message,
49 INetChannel*) { Queue(message, filter); };
50 auto hook =
HookTable(
"Custom HUD button presses", &INetworkMessageProcessingPreFilter::FilterMessage,
51 _bindings.ClientFilterTable, onMessage);
54 return std::unexpected(hook.error());
56 _hook = std::move(*hook);
63 for (
const Press& press : std::exchange(_queued, {}))
65 _registry.RaiseButtonPress(press.Slot, press.ButtonId);
69void ButtonPresses::Queue(
const CNetMessage* message,
const INetworkMessageProcessingPreFilter& filter)
72 NetMessageInfo_t* info = message ? message->GetNetMessage() :
nullptr;
73 if (!info || info->GetMessageId() != _messageId)
78 const auto* user = message->ToPB<CSVCMsg_UserMessage>();
79 if (user->msg_type() != CS_UM_CustomHudClicked)
85 const int slot =
static_cast<const CServerSideClientBase&
>(filter).GetPlayerSlot().Get();
92 CCSUsrMsg_CustomHudClicked click;
93 if (!click.ParseFromString(user->msg_data()) || !click.has_button_id())
98 if (click.button_id().find(
'\0') != std::string::npos)
103 _queued.push_back({.Slot = slot, .ButtonId = std::move(*click.mutable_button_id())});
106void ButtonPresses::WarnMalformed(
int slot)
112 Log::Warn(
"Button presses: a press from slot {} is not a CustomHudClicked message with a button id.", slot);
The loaded plugins and the engine events raised on them, one per process.
static double MonotonicSeconds()
void Warn(std::format_string< Args... > fmt, Args &&... args)
Result< Subscription > HookTable(std::string_view name, Ret(Object::*method)(Args...), const ClassTable &table, Before &&before, After &&after=nullptr)
Hook an SDK-declared virtual on every object sharing a gamedata-found class table.
std::expected< void, Error > Status
constexpr bool IsValidSlot(int slot)
static constexpr const char * UserMessageName
static constexpr int64_t WarningIntervalSeconds
INetworkMessages * NetworkMessages
static Error Engine(std::string detail)