-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnginePrediction.cpp
105 lines (86 loc) · 3.52 KB
/
EnginePrediction.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
#include "EnginePrediction.h"
#include "checksum_md5.h"
#include "AntiAims.h"
#include "netvar_manager.h"
void CNetData::Store() {
if (!csgo->local && !csgo->local->isAlive()) {
Reset();
return;
}
int tickbase;
StoredData_t* data;
tickbase = csgo->local->GetTickBase();
// get current record and store data.
data = &m_data[tickbase % 150];
data->m_tickbase = tickbase;
data->m_punch = csgo->local->GetPunchAngle();
data->m_punch_vel = csgo->local->GetPunchAngleVel();
data->m_view_offset = csgo->local->GetVecViewOffset();
data->m_velocity_modifier = csgo->local->GetVelocityModifier();
}
void CNetData::Apply() {
if (!csgo->local && !csgo->local->isAlive()) {
Reset();
return;
}
int tickbase;
StoredData_t* data;
Vector punch_delta, punch_vel_delta;
Vector view_delta;
float modifier_delta;
tickbase = csgo->local->GetTickBase();
// get current record and validate.
data = &m_data[tickbase % 150];
if (csgo->local->GetTickBase() != data->m_tickbase)
return;
// get deltas.
// note - dex; before, when you stop shooting, punch values would sit around 0.03125 and then goto 0 next update.
// with this fix applied, values slowly decay under 0.03125.
punch_delta = csgo->local->GetPunchAngle() - data->m_punch;
punch_vel_delta = csgo->local->GetPunchAngleVel() - data->m_punch_vel;
view_delta = csgo->local->GetVecViewOffset() - data->m_view_offset;
modifier_delta = csgo->local->GetVelocityModifier() - data->m_velocity_modifier;
// set data.
if (std::abs(punch_delta.x) < 0.03125f &&
std::abs(punch_delta.y) < 0.03125f &&
std::abs(punch_delta.z) < 0.03125f)
csgo->local->GetPunchAngle() = data->m_punch;
if (std::abs(punch_vel_delta.x) < 0.03125f &&
std::abs(punch_vel_delta.y) < 0.03125f &&
std::abs(punch_vel_delta.z) < 0.03125f)
csgo->local->GetPunchAngleVel() = data->m_punch_vel;
if (std::abs(view_delta.x) < 0.03125f &&
std::abs(view_delta.y) < 0.03125f &&
std::abs(view_delta.z) < 0.03125f)
csgo->local->GetVecViewOffset() = data->m_view_offset;
if (std::abs(modifier_delta) < 0.03125f)
csgo->local->GetVelocityModifier() = data->m_velocity_modifier;
}
void CNetData::Reset() {
m_data.fill(StoredData_t());
}
void CNetData::RecordViewmodelValues()
{
this->viewModelData.m_hWeapon = 0;
auto viewmodel = csgo->local->GetViewModel();
if (viewmodel) {
this->viewModelData.m_hWeapon = viewmodel->GetViewmodelWeapon();
this->viewModelData.m_nViewModelIndex = viewmodel->GetViewModelIndex();
this->viewModelData.m_nSequence = viewmodel->GetCurrentSequence();
this->viewModelData.networkedCycle = viewmodel->GetCurrentCycle();
this->viewModelData.m_nAnimationParity = viewmodel->GetAnimationParity();
this->viewModelData.animationTime = viewmodel->GetModelAnimTime();
}
}
void CNetData::ApplyViewmodelValues()
{
auto viewmodel = csgo->local->GetViewModel();
if (viewmodel) {
if (this->viewModelData.m_nSequence == viewmodel->GetCurrentSequence()
&& this->viewModelData.m_hWeapon == viewmodel->GetViewmodelWeapon()
&& this->viewModelData.m_nAnimationParity == viewmodel->GetAnimationParity()) {
viewmodel->GetCurrentCycle() = this->viewModelData.networkedCycle;
viewmodel->GetModelAnimTime() = this->viewModelData.animationTime;
}
}
}