VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PlayerInput.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <array>
4
#include <cstdint>
5
#include <optional>
6
#include <span>
7
#include <type_traits>
8
9
namespace
VoltMod
10
{
11
12
/** One CSubtickMoveStep from the usercmd: a sub-tick input change with its intra-tick time. */
13
struct
SubtickMove
14
{
15
uint64_t
Button
= 0;
// button bit(s) this step toggles; 0 for pure aim steps
16
bool
Pressed
=
false
;
// press vs release when Button != 0
17
float
When
= 0.0f;
// intra-tick fraction [0,1)
18
float
PitchDelta
= 0.0f;
19
float
YawDelta
= 0.0f;
20
};
21
22
/**
23
* One CSGOInputHistoryEntryPB. ViewYaw/ViewPitch is the angle the bullet was fired along, which
24
* a cheat can diverge from the visible viewangles (the silent-aim signature).
25
*/
26
struct
InputHistorySample
27
{
28
bool
HasViewAngles
=
false
;
29
float
ViewPitch
= 0.0f;
// view_angles.x
30
float
ViewYaw
= 0.0f;
// view_angles.y
31
int32_t
TargetEntIndex
= -1;
// entity the client claims it hit, -1 if none
32
};
33
34
/**
35
* @brief Protobuf-free snapshot of the CUserCmd handed to
36
* CPlayer_MovementServices::RunCommand, decoded once per command by @ref Movement.
37
*
38
* Valid is false when the usercmd pointer was null or the "CUserCmd::CSGOUserCmdPB" gamedata
39
* offset is missing - fields then hold their defaults and must not be trusted.
40
*/
41
struct
PlayerInput
42
{
43
bool
Valid
=
false
;
44
int32_t
ClientTick
= 0;
45
46
// Client command counter from gamedata "CUserCmdBase::cmdNum". Missing gamedata falls
47
// back to legacy_command_number, which live clients leave at zero.
48
int32_t
CommandNumber
= 0;
49
50
/** False when the client omitted viewangles: the three fields below then hold defaults rather
51
* than a reading, so treat the angles as untrusted. */
52
bool
HasViewAngles
=
false
;
53
54
// CBaseUserCmdPB.viewangles (x = pitch, y = yaw, z = roll)
55
float
ViewPitch
= 0.0f;
56
float
ViewYaw
= 0.0f;
57
float
ViewRoll
= 0.0f;
58
59
float
ForwardMove
= 0.0f;
60
float
LeftMove
= 0.0f;
61
62
// CInButtonStatePB words: held and changed-this-tick button masks
63
uint64_t
ButtonsHeld
= 0;
64
uint64_t
ButtonsChanged
= 0;
65
66
// Raw mouse movement the client reported for this command
67
int32_t
MouseDx
= 0;
68
int32_t
MouseDy
= 0;
69
70
// Sub-tick shooting bookkeeping (-1 = no attack started this command)
71
int32_t
Attack1StartHistoryIndex
= -1;
72
int32_t
Attack2StartHistoryIndex
= -1;
73
74
static
constexpr
int
MaxSubtickMoves
= 12;
75
int
SubtickMoveCount
= 0;
// clamped to MaxSubtickMoves
76
std::array<SubtickMove, MaxSubtickMoves>
SubtickMoves
{};
77
78
// Fired-view samples, capped at MaxInputHistory. Attack indices address the
79
// full client list, so an index beyond this snapshot names a discarded sample.
80
static
constexpr
int
MaxInputHistory
= 16;
81
int
InputHistoryCount
= 0;
// clamped to MaxInputHistory
82
/** Entries the client actually sent, before the MaxInputHistory cap. Greater than
83
* InputHistoryCount means the tail was capped away. */
84
int
InputHistorySent
= 0;
85
std::array<InputHistorySample, MaxInputHistory>
InputHistorySamples
{};
86
87
/** The decoded sub-tick steps. */
88
std::span<const SubtickMove>
Subticks
()
const
89
{
90
return
{
SubtickMoves
.data(),
static_cast<
size_t
>
(
SubtickMoveCount
)};
91
}
92
93
/** The decoded fired-view samples. */
94
std::span<const InputHistorySample>
InputHistory
()
const
95
{
96
return
{
InputHistorySamples
.data(),
static_cast<
size_t
>
(
InputHistoryCount
)};
97
}
98
99
/** The decoded entry at @p index, or nullopt when @p index is negative or was capped away. */
100
std::optional<InputHistorySample>
SampleAt
(
int
index)
const
101
{
102
if
(
index < 0 || index >
=
InputHistoryCount
)
103
{
104
return
std::nullopt;
105
}
106
return
InputHistorySamples
[index];
107
}
108
};
109
110
// The host hands it to every plugin, whose allocators differ, so it must own nothing.
111
static_assert
(std::is_trivially_copyable_v<PlayerInput>);
112
113
}
// namespace VoltMod
VoltMod
Definition
Options.hpp:13
VoltMod::ReadFile
static std::string ReadFile(const std::filesystem::path &path)
Definition
Loader.cpp:56
VoltMod::InputHistorySample
Definition
PlayerInput.hpp:27
VoltMod::InputHistorySample::HasViewAngles
bool HasViewAngles
Definition
PlayerInput.hpp:28
VoltMod::InputHistorySample::TargetEntIndex
int32_t TargetEntIndex
Definition
PlayerInput.hpp:31
VoltMod::InputHistorySample::ViewYaw
float ViewYaw
Definition
PlayerInput.hpp:30
VoltMod::InputHistorySample::ViewPitch
float ViewPitch
Definition
PlayerInput.hpp:29
VoltMod::PlayerInput
Protobuf-free snapshot of the CUserCmd handed to CPlayer_MovementServices::RunCommand,...
Definition
PlayerInput.hpp:42
VoltMod::PlayerInput::CommandNumber
int32_t CommandNumber
Definition
PlayerInput.hpp:48
VoltMod::PlayerInput::ViewYaw
float ViewYaw
Definition
PlayerInput.hpp:56
VoltMod::PlayerInput::SubtickMoveCount
int SubtickMoveCount
Definition
PlayerInput.hpp:75
VoltMod::PlayerInput::ButtonsHeld
uint64_t ButtonsHeld
Definition
PlayerInput.hpp:63
VoltMod::PlayerInput::MaxInputHistory
static constexpr int MaxInputHistory
Definition
PlayerInput.hpp:80
VoltMod::PlayerInput::Attack1StartHistoryIndex
int32_t Attack1StartHistoryIndex
Definition
PlayerInput.hpp:71
VoltMod::PlayerInput::InputHistory
std::span< const InputHistorySample > InputHistory() const
Definition
PlayerInput.hpp:94
VoltMod::PlayerInput::InputHistorySent
int InputHistorySent
Definition
PlayerInput.hpp:84
VoltMod::PlayerInput::LeftMove
float LeftMove
Definition
PlayerInput.hpp:60
VoltMod::PlayerInput::ClientTick
int32_t ClientTick
Definition
PlayerInput.hpp:44
VoltMod::PlayerInput::HasViewAngles
bool HasViewAngles
Definition
PlayerInput.hpp:52
VoltMod::PlayerInput::Subticks
std::span< const SubtickMove > Subticks() const
Definition
PlayerInput.hpp:88
VoltMod::PlayerInput::ViewPitch
float ViewPitch
Definition
PlayerInput.hpp:55
VoltMod::PlayerInput::ViewRoll
float ViewRoll
Definition
PlayerInput.hpp:57
VoltMod::PlayerInput::MaxSubtickMoves
static constexpr int MaxSubtickMoves
Definition
PlayerInput.hpp:74
VoltMod::PlayerInput::ForwardMove
float ForwardMove
Definition
PlayerInput.hpp:59
VoltMod::PlayerInput::SubtickMoves
std::array< SubtickMove, MaxSubtickMoves > SubtickMoves
Definition
PlayerInput.hpp:76
VoltMod::PlayerInput::InputHistoryCount
int InputHistoryCount
Definition
PlayerInput.hpp:81
VoltMod::PlayerInput::InputHistorySamples
std::array< InputHistorySample, MaxInputHistory > InputHistorySamples
Definition
PlayerInput.hpp:85
VoltMod::PlayerInput::Valid
bool Valid
Definition
PlayerInput.hpp:43
VoltMod::PlayerInput::ButtonsChanged
uint64_t ButtonsChanged
Definition
PlayerInput.hpp:64
VoltMod::PlayerInput::MouseDx
int32_t MouseDx
Definition
PlayerInput.hpp:67
VoltMod::PlayerInput::Attack2StartHistoryIndex
int32_t Attack2StartHistoryIndex
Definition
PlayerInput.hpp:72
VoltMod::PlayerInput::MouseDy
int32_t MouseDy
Definition
PlayerInput.hpp:68
VoltMod::PlayerInput::SampleAt
std::optional< InputHistorySample > SampleAt(int index) const
Definition
PlayerInput.hpp:100
VoltMod::SubtickMove
Definition
PlayerInput.hpp:14
VoltMod::SubtickMove::YawDelta
float YawDelta
Definition
PlayerInput.hpp:19
VoltMod::SubtickMove::When
float When
Definition
PlayerInput.hpp:17
VoltMod::SubtickMove::Pressed
bool Pressed
Definition
PlayerInput.hpp:16
VoltMod::SubtickMove::Button
uint64_t Button
Definition
PlayerInput.hpp:15
VoltMod::SubtickMove::PitchDelta
float PitchDelta
Definition
PlayerInput.hpp:18
include
VoltMod
Engine
PlayerInput.hpp
Generated by
1.9.8