-
Notifications
You must be signed in to change notification settings - Fork 0
/
Backtrack.cpp
294 lines (235 loc) · 7.9 KB
/
Backtrack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "Hooks.h"
#include "Features.h"
bool animation::is_valid(float range = .2f, float max_unlag = .2f)
{
if (!interfaces.engine->GetNetChannelInfo() || !valid)
return false;
const auto correct = std::clamp(interfaces.engine->GetNetChannelInfo()->GetLatency(FLOW_INCOMING)
+ interfaces.engine->GetNetChannelInfo()->GetLatency(FLOW_OUTGOING)
+ g_Ragebot->LerpTime(), 0.f, max_unlag);
float curtime = csgo->local->isAlive() ? TICKS_TO_TIME(csgo->fixed_tickbase) : interfaces.global_vars->curtime;
return fabsf(correct - (curtime - sim_time)) < range && correct < 1.f;
}
animation::animation(IBasePlayer* player)
{
const auto weapon = player->GetWeapon();
safepoints = false;
this->player = player;
index = player->GetIndex();
dormant = player->IsDormant();
velocity = player->GetVelocity();
origin = player->GetOrigin();
abs_origin = player->GetAbsOrigin();
obb_mins = player->GetMins();
obb_maxs = player->GetMaxs();
std::memcpy(layers, player->GetAnimOverlays(), sizeof(CAnimationLayer) * 13);
poses = player->m_flPoseParameter();
anim_state = player->GetPlayerAnimState();
sim_time = player->GetSimulationTime();
interp_time = 0.f;
priority = -1;
came_from_dormant = -1;
last_shot_time = weapon ? weapon->GetLastShotTime() : 0.f;
duck = player->GetDuckAmount();
lby = player->GetLBY();
eye_angles = player->GetEyeAngles();
abs_ang = player->GetAbsAngles();
flags = player->GetFlags();
eflags = player->GetEFlags();
effects = player->GetEffects();
land_time = 0.0f;
is_landed = false;
land_in_cycle = false;
didshot = false;
valid = true;
}
animation::animation(IBasePlayer* player, Vector last_reliable_angle) : animation(player)
{
this->last_reliable_angle = last_reliable_angle;
}
void animation::restore(IBasePlayer* player) const
{
player->GetVelocity() = velocity;
player->GetFlagsPtr() = flags;
player->GetEFlags() = eflags;
player->GetDuckAmount() = duck;
std::memcpy(player->GetAnimOverlays(), layers, sizeof(CAnimationLayer) * 13);
player->GetLBY() = lby;
player->GetOrigin() = origin;
player->SetAbsOrigin(abs_origin);
}
void animation::apply(IBasePlayer* player) const
{
player->SetPoseParameter(poses);
player->GetVelocity() = velocity;
player->GetFlagsPtr() = flags;
player->GetEFlags() = eflags;
player->GetDuckAmount() = duck;
std::memcpy(player->GetAnimOverlays(), layers, sizeof(CAnimationLayer) * 13);
player->GetLBY() = lby;
player->GetOrigin() = origin;
player->SetAbsOrigin(abs_origin);
if (player->GetPlayerAnimState())
player->SetAnimState(anim_state);
}
void CAnimationFix::UpdatePlayers()
{
if (!interfaces.engine->IsInGame())
return;
const auto local = csgo->local;
// erase outdated entries
for (auto it = animation_infos.begin(); it != animation_infos.end();) {
auto player = reinterpret_cast<IBasePlayer*>(interfaces.ent_list->GetClientEntityFromHandle(it->first));
if (!player || player != it->second->player || !player->isAlive()
|| !local)
{
if (player)
player->GetClientSideAnims() = true;
it = animation_infos.erase(it);
}
else
it = next(it);
}
if (!local)
{
for (auto i = 1; i <= interfaces.engine->GetMaxClients(); ++i) {
const auto entity = interfaces.ent_list->GetClientEntity(i);
if (entity && entity->IsPlayer())
entity->GetClientSideAnims() = true;
}
}
for (auto i = 1; i <= interfaces.engine->GetMaxClients(); ++i) {
const auto entity = interfaces.ent_list->GetClientEntity(i);
if (!entity || !entity->IsPlayer())
continue;
if (!entity->isAlive())
continue;
if (entity->IsDormant()) {
csgo->CameFromDormant[entity->EntIndex()] = -1;
continue;
}
if (entity == local)
continue;
if (entity != local && entity->GetTeam() == local->GetTeam()) {
csgo->EnableBones = entity->GetClientSideAnims() = true;
continue;
}
if (animation_infos.find(entity->GetRefEHandle()) == animation_infos.end())
animation_infos.insert_or_assign(entity->GetRefEHandle(), new animation_info(entity, {}));
}
// run post update
for (auto& info : animation_infos)
{
auto& _animation = info.second;
const auto player = _animation->player;
for (auto it = _animation->frames.rbegin(); it != _animation->frames.rend();) {
if (!it->is_valid(0.2f + TICKS_TO_TIME(17)))
it = decltype(it) {
info.second->frames.erase(next(it).base())
};
else
it = next(it);
}
if (g_Resolver->Do(_animation->player)) {
if (auto state = player->GetPlayerAnimState(); state != nullptr)
state->m_abs_yaw = g_Resolver->ResolverInfo[player->EntIndex()].ResolvedAngle;
}
else {
if (auto state = player->GetPlayerAnimState(); state != nullptr)
g_Resolver->ResolverInfo[player->EntIndex()].ResolvedAngle = state->m_abs_yaw;
}
// have we already seen this update?
if (player->GetSimulationTime() != player->CameFromDormantTime()) {
if (player->GetSimulationTime() <= player->GetOldSimulationTime())
continue;
}
// reset animstate
if (_animation->last_spawn_time != player->GetSpawnTime())
{
const auto state = player->GetPlayerAnimState();
if (state)
player->ResetAnimationState(state);
_animation->last_spawn_time = player->GetSpawnTime();
}
// grab previous
animation* previous = nullptr;
if (!_animation->frames.empty() && !_animation->frames.front().dormant
&& TIME_TO_TICKS(player->GetSimulationTime() - _animation->frames.front().sim_time) <= 17)
previous = &_animation->frames.front();
// store server record
auto& record = _animation->frames.emplace_front(player, info.second->last_reliable_angle);
animation* backup = new animation(player);
backup->apply(player);
record.build_inversed_bones(player);
record.build_unresolved_bones(player);
_animation->UpdateAnims(&record, previous);
record.build_server_bones(player);
backup->restore(player);
delete backup;
}
}
CAnimationFix::animation_info* CAnimationFix::get_animation_info(IBasePlayer* player)
{
auto info = animation_infos.find(player->GetRefEHandle());
if (info == animation_infos.end())
return nullptr;
return info->second;
}
bool animation::is_valid_extended()
{
return is_valid();
}
animation* CAnimationFix::get_latest_animation(IBasePlayer* player)
{
const auto info = animation_infos.find(player->GetRefEHandle());
if (info == animation_infos.end() || info->second->frames.empty())
return nullptr;
for (auto it = info->second->frames.begin(); it != info->second->frames.end(); it = next(it)) {
if ((it)->is_valid_extended()) {
return &*it;
}
}
return nullptr;
}
std::vector<animation*> CAnimationFix::get_valid_animations(IBasePlayer* player)
{
const auto info = animation_infos.find(player->GetRefEHandle());
std::vector<animation*> ret = {};
if (info == animation_infos.end() || info->second->frames.empty())
return ret;
Vector last_origin = Vector(0, 0, 0);
for (auto it = info->second->frames.begin(); it != info->second->frames.end(); it = next(it)) {
if ((it)->is_valid_extended()) {
float diff = 0.f;
if (it != info->second->frames.begin() && last_origin != Vector(0, 0, 0)) {
diff = it->origin.DistTo(last_origin);
}
if (diff > 25.f || it->eye_angles.x <= 25.f)
ret.emplace_back(&*it);
last_origin = it->origin;
}
}
return ret;
}
animation* CAnimationFix::get_oldest_animation(IBasePlayer* player)
{
const auto info = animation_infos.find(player->GetRefEHandle());
if (info == animation_infos.end() || info->second->frames.empty())
return nullptr;
for (auto it = info->second->frames.rbegin(); it != info->second->frames.rend(); it = next(it)) {
if ((it)->is_valid_extended()) {
return &*it;
}
}
return nullptr;
}
animation* CAnimationFix::get_latest_firing_animation(IBasePlayer* player)
{
const auto info = animation_infos.find(player->GetRefEHandle());
if (info == animation_infos.end() || info->second->frames.empty())
return nullptr;
for (auto it = info->second->frames.begin(); it != info->second->frames.end(); it = next(it))
if ((it)->is_valid_extended() && (it)->didshot)
return &*it;
return nullptr;
}