9#include <cs_usercmd.pb.h>
10#include <entityhandle.h>
39 Log::Warn(
"Player commands: no 'CUserCmdBase::cmdNum' offset; command numbers read 0.");
43Status PlayerCommands::Install()
47 return std::unexpected(
Error::Unsupported(
"the RunCommand slot or the usercmd offset did not bind"));
51 const auto afterCommand = [
this](EngineMovementServices&,
void*) { After(); };
55 return std::unexpected(
hook.error());
57 _hook = std::move(*
hook);
72void PlayerCommands::After()
80void PlayerCommands::Decode(
const void*
userCmd)
89 const auto& base =
pb->base();
100 _input.
ViewYaw = base.viewangles().y();
101 _input.
ViewRoll = base.viewangles().z();
105 if (base.has_buttons_pb())
107 _input.
ButtonsHeld = base.buttons_pb().buttonstate1();
110 _input.
MouseDx = base.mousedx();
111 _input.
MouseDy = base.mousedy();
118 const auto&
move = base.subtick_moves(
i);
120 .Button =
move.button(),
121 .Pressed =
move.pressed(),
123 .PitchDelta =
move.pitch_delta(),
124 .YawDelta =
move.yaw_delta(),
132 const auto&
entry =
pb->input_history(
i);
135 if (
entry.has_view_angles())
137 sample.HasViewAngles =
true;
const void * Ptr(const void *base) const
T Read(const void *base) const
PlayerCommands(const Bindings &bindings, PluginRegistry ®istry)
The loaded plugins and the engine events raised on them, one per process.
bool HasCommandListeners() const
void RaisePlayerCommand(int slot, const PlayerInput &input)
void RaisePlayerCommandDone(int slot, const PlayerInput &input)
EntityRef ControllerRef() const
::CEntityInstance * OwnerEntity() const
void Warn(std::format_string< Args... > fmt, Args &&... args)
Result< Subscription > HookVirtual(std::string_view name, const VirtualFn< Ret(Object *, Args...)> &function, Before &&before, After &&after=nullptr)
Hook a gamedata-bound virtual function on objects sharing its class vtable.
static std::string ReadFile(const std::filesystem::path &path)
constexpr bool IsValidSlot(int slot)
std::expected< void, Error > Status
static int OwnerSlot(void *movementServices)
Offset< int32_t > UserCmdNumber
Offset< void > UserCmdProto
VirtualFn< void *(EngineMovementServices *, void *)> RunCommand
static Error Unsupported(std::string detail)