-
Notifications
You must be signed in to change notification settings - Fork 3
/
Backtracking Rage.cpp
166 lines (124 loc) · 4.72 KB
/
Backtracking Rage.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
#include "Backtracking Rage.h"
#include "CommonIncludes.h"
#include "RageBot.h"
#define MODULATIONFACOTR 1500
cPrediction DataManager;
void cPrediction::ReportMove(Vector vOrigin, int iIndex)
{
if (iIndex >= 128 || iIndex < 0)
return;
IClientEntity* pBaseEntity = Interfaces::EntList->GetClientEntity(iIndex);
if (!pBaseEntity) return;
IClientEntity* pLocalPlayer = hackManager.pLocal();
if (!pLocalPlayer) return;
if (pBaseEntity->GetIndex() == pLocalPlayer->GetIndex()) return;
if (!pBaseEntity->GetHealth()) return;
matrixentry_t& Matrix = m_Matrix[iIndex];
Matrix.dwFraction = timeGetTime() - Matrix.dwTime;
Matrix.dwTime = timeGetTime();
Matrix.vOrigin = vOrigin;
Matrix.vecOrigins.push_back(vOrigin);
}
bool cPrediction::bGetCurOrigin(Vector& vOrigin, int iIndex)
{
return bGetOrigin(vOrigin, iIndex, timeGetTime());
}
float get_network_latency()
{
INetChannelInfo* nci = Interfaces::Engine->GetNetChannelInfo();
if (nci != nullptr)
return nci->GetAvgLatency(FLOW_OUTGOING);
return 0.f;
}
int get_choked_ticks(int tickbase)
{
float diff = Interfaces::Globals->curtime - tickbase;
float latency = get_network_latency();
return max(0.0f, diff);
}
Vector Acceleration[64];
Vector OldNetworkPos[64];
Vector OldVelocity[64];
void cPrediction::UpdatePlayerPos()
{
for (int s = 1; s <= Interfaces::Globals->maxClients; ++s)
{
IClientEntity* pEntity = Interfaces::EntList->GetClientEntity(s);
auto pLocal = hackManager.pLocal();
if (!pEntity)
continue;
if (!OldNetworkPos[s]) OldNetworkPos[s] = Vector(0, 0, 0);
if (!OldVelocity[s]) OldVelocity[s] = Vector(0, 0, 0);
if (!Acceleration[s]) Acceleration[s] = Vector(0, 0, 0);
if (!OldNetworkPos[s] && pEntity->GetVelocity().Length() > 0) OldNetworkPos[s] = pEntity->GetAbsOrigin();
if (!OldVelocity[s] && pEntity->GetVelocity().Length() > 0) OldVelocity[s] = pEntity->GetVelocity();
if (!Acceleration[s] && pEntity->GetVelocity().Length() > 0) Acceleration[s] = Vector(0, 0, 0);
if ((OldNetworkPos[s] != pEntity->GetAbsOrigin()) && pEntity->GetVelocity().Length() > 0)
{
Vector CurrentVelocity = pEntity->GetAbsOrigin() - OldNetworkPos[s];
Acceleration[s] = CurrentVelocity - OldVelocity[s];
if (pEntity != pLocal)
(pEntity->GetVelocity()) = CurrentVelocity;
OldNetworkPos[s] = pEntity->GetAbsOrigin();
OldVelocity[s] = CurrentVelocity;
}
if (pEntity != pLocal)
if (pEntity->GetChokedTicks() && pEntity->GetVelocity().Length() > 0)
*pEntity->GetOriginPtr() = pEntity->GetAbsOrigin() + (pEntity->GetVelocity() + Acceleration[s]) * (pEntity->GetChokedTicks());
}
}
bool cPrediction::bGetOrigin(Vector& vOrigin, int iIndex, DWORD dwTime)
{
if (iIndex >= 128 || iIndex < 0)
return false;
IClientEntity* pBaseEntity = Interfaces::EntList->GetClientEntity(iIndex);
if (!pBaseEntity) return false;
IClientEntity* pLocalPlayer = hackManager.pLocal();
if (!pLocalPlayer) return false;
if (pBaseEntity->GetIndex() == pLocalPlayer->GetIndex()) return false;
if (!pBaseEntity->GetHealth()) return false;
matrixentry_t& Matrix = m_Matrix[iIndex];
if (Matrix.vecOrigins.size() == 0 || Matrix.dwFraction > MODULATIONFACOTR)
{
Matrix.dwFraction = 0;
return false;
}
DWORD dwInterfraction = dwTime - Matrix.dwFraction;
if (Matrix.vecOrigins.size() == 1)
{
vOrigin = Matrix.vOrigin;
return true;
}
int iSize = (int)Matrix.vecOrigins.size();
Vector vCurDistance = Matrix.vOrigin - Matrix.vecOrigins[iSize - 1];
Vector vLastDistance = Matrix.vecOrigins[iSize - 1] - Matrix.vecOrigins[iSize - 2];
float flInterp = vCurDistance.Length() - vLastDistance.Length();
if (flInterp == 0.0)
{
return true;
}
int iRecords = iSize - 1;
float flAcceleration[2];
float flAbsAcceleration = 1.0f;
Vector vecAcceleration = vCurDistance - vLastDistance;
if (iRecords >= 2)
{
Vector vOldDistance = Matrix.vecOrigins[iSize - 2] - Matrix.vecOrigins[iSize - 3];
flAcceleration[0] = vCurDistance.Length() - vLastDistance.Length();
flAcceleration[1] = vLastDistance.Length() - vOldDistance.Length();
flAbsAcceleration = (flAcceleration[0] + flAcceleration[1]) / 2;
}
Interfaces::CVar->ConsoleColorPrintf(Color(201, 201, 201, 255), "Backtracked Information: Acceleration X: %i Acceleration Y: %i Choked Ticks: %i \n", flAcceleration[0], flAcceleration[1], pBaseEntity->GetChokedTicks());
pBaseEntity->GetAbsOrigin() += ((vecAcceleration * (6)));
printf("%i", get_choked_ticks(pBaseEntity->GetTickBase()));
return true;
}
void cPrediction::Reset(void)
{
for (int i = 0; i < 128; i++)
{
m_Matrix[i].vecOrigins.clear();
m_Matrix[i].dwFraction = 0;
m_Matrix[i].dwTime = 0;
}
}