VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::LazyHook Class Reference

An engine hook that exists only while one of its events has handlers. More...

#include <LazyHook.hpp>

Public Member Functions

 LazyHook (std::string name, std::function< Result< Subscription >()> install)
 ~LazyHook ()
 LazyHook (const LazyHook &)=delete
LazyHook & operator= (const LazyHook &)=delete
EventLifecycle MakeLifecycle ()
bool Installed () const noexcept
int ListeningEvents () const noexcept

Detailed Description

An engine hook that exists only while one of its events has handlers.

The first event to gain a handler calls install and keeps the hook it returns; the last one to go quiet removes it. An install error is logged under name and refuses that subscription, so a later subscriber retries.

: _hook("Damage", [this] { return HookFunction("Damage", _bindings.TakeDamage, ...); }),
Before(_hook.MakeLifecycle())
Damage(EntitySystem &entities, const Bindings &bindings, Interfaces &interfaces, GameEvents &events)
Definition Damage.cpp:37
Result< Subscription > HookFunction(std::string_view name, const Fn< Ret(Object *, Args...)> &function, Before &&before, After &&after=nullptr)
Hook a signature-bound function at its entry.
Definition Hook.hpp:232

Adapters borrow this object, so declare it before the events they belong to. Destroying it with handlers still attached is an ownership error that can leave a hook in an unloading module; the destructor logs it.

Definition at line 29 of file LazyHook.hpp.

Constructor & Destructor Documentation

◆ LazyHook() [1/2]

VoltMod::LazyHook::LazyHook ( std::string name,
std::function< Result< Subscription >()> install )

Definition at line 8 of file LazyHook.cpp.

Referenced by LazyHook(), and operator=().

◆ ~LazyHook()

VoltMod::LazyHook::~LazyHook ( )

Definition at line 12 of file LazyHook.cpp.

References VoltMod::Log::Error().

◆ LazyHook() [2/2]

VoltMod::LazyHook::LazyHook ( const LazyHook & )
delete

References LazyHook().

Member Function Documentation

◆ Installed()

bool VoltMod::LazyHook::Installed ( ) const
inlinenoexcept

Definition at line 40 of file LazyHook.hpp.

◆ ListeningEvents()

int VoltMod::LazyHook::ListeningEvents ( ) const
inlinenoexcept

Number of adapted events with at least one handler. For diagnostics and tests only.

Definition at line 43 of file LazyHook.hpp.

◆ MakeLifecycle()

EventLifecycle VoltMod::LazyHook::MakeLifecycle ( )

Definition at line 21 of file LazyHook.cpp.

◆ operator=()

LazyHook & VoltMod::LazyHook::operator= ( const LazyHook & )
delete

References LazyHook().


The documentation for this class was generated from the following files: