VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Visibility.hpp
Go to the documentation of this file.
1#pragma once
2
13#include <array>
14#include <functional>
15#include <memory>
16#include <vector>
17
18namespace VoltMod
19{
20
21/** Glow colors and an optional per-slot veto. */
23{
24 Color TerroristColor{255, 128, 0};
25 Color CtColor{0, 160, 255};
26 /** Extra veto on top of the live, team and hidden checks; empty glows everyone. */
27 std::function<bool(int slot)> Filter;
28};
29
30/**
31 * @brief Which clients receive which entities, filtered after CheckTransmit.
32 *
33 * A hidden pawn takes its weapons, wearables and shadow with it but stays visible to whoever
34 * spectates it; a hidden controller loses its scoreboard row and chat attribution. Sounds are
35 * networked separately and are unaffected.
36 */
38{
39public:
40 /** @p slots resets a slot's hiding when it changes hands. All three must outlive this. */
42 Visibility(const Visibility&) = delete;
43 Visibility& operator=(const Visibility&) = delete;
44
45 /** Hide or show `slot`'s pawn from every other client. */
46 void SetPawnHidden(int slot, bool hidden);
47
48 /** Hide or show `slot`'s controller from every other client. */
49 void SetControllerHidden(int slot, bool hidden);
50
51 bool IsPawnHidden(int slot) const;
52
53 /** Network `entity` to `slot` alone. Calling again moves it to another slot. */
55
56 /** Network `entity` to `team` alone, spectators excluded. Calling again moves it. */
58
59 /** Keep `entity` from every client on `team`. Calling again moves it. */
61
62 /** Undo the calls above; a removed entity needs no call. */
64
65 /** A @ref GlowVision for @p viewerSlot alone; its clones go with the last owner. */
66 std::shared_ptr<GlowVision> CreateGlow(int viewerSlot, GlowConfig config = {});
67
68 /** A @ref GlowVision the whole of @p viewerTeam shares. */
69 std::shared_ptr<GlowVision> CreateGlow(Team viewerTeam, GlowConfig config = {});
70
71 /** @internal Called by the framework after ISource2GameEntities::CheckTransmit. */
73
74 /** An error when the CheckTransmitPlayerSlot offset did not bind; every call is then inert. */
75 Status Available() const;
76
77private:
78 struct SlotState
79 {
80 bool PawnHidden = false;
81 bool ControllerHidden = false;
82
83 bool Any() const { return PawnHidden || ControllerHidden; }
84 };
85
86 /** Sent to @ref Viewer alone, else to @ref ShownTo alone, else to everyone off @ref HiddenFrom. */
87 struct PrivateEntity
88 {
89 EntityRef Entity;
90 int Viewer = -1;
91 Team ShownTo = Team::None;
92 Team HiddenFrom = Team::None;
93 int Index = -1; ///< resolved once per snapshot
94
95 bool HiddenFor(int recipient, Team recipientTeam) const;
96 };
97
98 /** Replaces the entry for the same entity, or adds it. */
99 void SetPrivate(const PrivateEntity& entry);
100
101 EntitySystem& _entities;
102 const Bindings& _bindings;
103 std::array<SlotState, MaxPlayers> _state{};
104 std::vector<PrivateEntity> _private;
105 /** Declared last: unregisters before the state it resets. */
106 Subscription _slotListener;
107};
108
109} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
Which clients receive which entities, filtered after CheckTransmit.
void ShowOnlyToTeam(EntityRef entity, Team team)
Visibility(const Visibility &)=delete
Status Available() const
void SetPawnHidden(int slot, bool hidden)
bool IsPawnHidden(int slot) const
void HideFromTeam(EntityRef entity, Team team)
void ShowToEveryone(EntityRef entity)
void SetControllerHidden(int slot, bool hidden)
std::shared_ptr< GlowVision > CreateGlow(int viewerSlot, GlowConfig config={})
void ShowOnlyTo(EntityRef entity, int slot)
void OnCheckTransmit(CCheckTransmitInfo **infoList, int infoCount)
Visibility & operator=(const Visibility &)=delete
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
An RGBA color in the engine's byte order, as m_clrRender and glow colors hold it.
Definition Color.hpp:15
std::function< bool(int slot)> Filter