-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBacktrack.h
197 lines (168 loc) · 4.86 KB
/
Backtrack.h
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
#pragma once
#include "Hacks.h"
#include <deque>
extern int cmd_tick_count;
namespace Globals
{
extern CUserCmd* UserCmd;
extern IClientEntity* Target;
extern int Shots;
extern bool change;
extern int TargetID;
extern int getShotsFired;
}
struct LagRecord_t {
float m_flSimulationTime;
bool m_bValidRecord;
QAngle m_vecAngles;
Vector m_vecEyeAngles;
Vector m_vecOrigin;
Vector m_vecVelocity;
Vector m_vecMins;
Vector m_vecMaxs;
float m_flLowerBodyYawTarget;
Vector headSpot;
std::array<float, 24> m_flPoseParameter;
int m_flags;
float m_flCycle;
int m_nSequence;
void Store(IClientEntity* pEnt) {
m_vecOrigin = pEnt->GetAbsOrigin();
m_vecAngles = pEnt->GetAbsAngles();
m_vecEyeAngles = *pEnt->GetEyeAnglesXY();
m_vecVelocity = pEnt->GetVelocity();
//m_vecMins = pEnt->GetCollideable();
//m_vecMaxs = pEnt->GetCollideable()->OBBMaxs();
m_flSimulationTime = pEnt->GetSimulationTime();
m_flLowerBodyYawTarget = pEnt->GetLowerBodyYaw();
headSpot = pEnt->GetBonePos(8);
m_flPoseParameter = pEnt->GetPoseParameters();
m_flags = pEnt->GetFlags();
m_flCycle = pEnt->getCycle();
m_nSequence = pEnt->getSequence();
};
void Store(LagRecord_t record) {
m_vecOrigin = record.m_vecOrigin;
m_vecAngles = record.m_vecAngles;
m_vecEyeAngles = record.m_vecEyeAngles;
m_vecVelocity = record.m_vecVelocity;
//m_vecMins = record.m_vecMins;
//m_vecMaxs = record.m_vecMaxs;
m_flSimulationTime = record.m_flSimulationTime;
m_flLowerBodyYawTarget = record.m_flLowerBodyYawTarget;
headSpot = record.headSpot;
m_flPoseParameter = record.m_flPoseParameter;
m_flags = record.m_flags;
m_flCycle = record.m_flCycle;
m_nSequence = record.m_nSequence;
m_bValidRecord = true;
};
void Init() {
m_vecAngles = Vector(0, 0, 0);
m_flags = 0;
m_nSequence = 0;
m_flCycle = 0;
m_vecOrigin = Vector(0, 0, 0);
m_vecVelocity = Vector(0, 0, 0);
m_vecEyeAngles = QAngle(0, 0, 0);
headSpot = Vector(0, 0, 0);
//m_vecMins = Vector(0, 0, 0);
//m_vecMaxs = Vector(0, 0, 0);
m_flLowerBodyYawTarget = 0.0f;
m_flSimulationTime = 0.0f;
std::array<float, 24> m_flPoseParameter = {};
}
};
class CBackTrack {
public:
void Inititalise();
void Run(CUserCmd* pCmd, IClientEntity* pEnt);
void RestoreEntity(IClientEntity* pEnt);
void StoreEntity(IClientEntity* local, IClientEntity* pEntity);
bool FindOldestRecord(IClientEntity * pEntity);
bool IsValidTick(IClientEntity* pEnt, float simTime);
float m_flTeleportDistanceSqr;
int m_iTicks;
struct BackTrackData_s {
std::deque<LagRecord_t> m_PlayerRecords;
void Init() {
m_PlayerRecords.erase(m_PlayerRecords.begin(), m_PlayerRecords.end());
};
};
BackTrackData_s m_BackTrackData[65];
LagRecord_t m_PlayerTable;
LagRecord_t m_RestoreData[65];
ConVar* pInterpVar;
ConVar* pRatioVar;
ConVar* pUpdateVar;
ConVar* pUnlagVar;
ConVar* pInterpolateVar;
template< class T, class Y >
T clamp(T const &val, Y const &minVal, Y const &maxVal) {
if (val < minVal)
return minVal;
else if (val > maxVal)
return maxVal;
else
return val;
}
private:
bool m_bInitialized = false;
};
extern std::unique_ptr<CBackTrack> pBackTrack;
enum PRIORITY : int
{
PRIORITY_NONE = 0,
PRIORITY_LOW = 1,
PRIORITY_MEDIUM,
PRIORITY_HIGH
};
struct LagRecord_tT
{
int m_iTargetTickcount;
int m_iPrevBullets;
int m_iPrevFlags;
int RecordPriorityFlag;
bool m_bHasBetterRecord;
bool m_bIsValidRecord;
bool IsHeadVisible;
std::array<float, 24> m_flAPoseParameters = {};
float m_flSimulationTime;
float m_flPreviousSimulationTime;
float m_flBaseTime;
Vector m_vecOrigin;
Vector m_vecAngles;
Vector m_vecPreviousOrigin;
Vector m_vecPreviousAngles;
public:
void InvalidateRecord() {
m_bIsValidRecord = false;
};
void SaveInfo(IClientEntity* pEnt) {
m_vecOrigin = pEnt->GetOrigin();
m_vecAngles = *pEnt->GetEyeAnglesXY();
m_flSimulationTime = pEnt->GetSimulationTime();
m_flAPoseParameters = pEnt->GetPoseParameters();
m_bIsValidRecord = false;
};
};
class CTimeSimulator
{
public:
LagRecord_tT m_PlayerTable[65];
float OldLowerBodyYaw[65]; //not sure about array or other container
float OldPoses[65]; //but as it doesn't complain about anything fuck it
LagRecord_tT m_PrevPlayerTable[65];
LagRecord_tT m_BacktrackedPlayerTable[65];
std::deque<LagRecord_tT> m_PlayerGoodRecords[65];
void UpdatePlayerTable(IClientEntity* pEntity);
bool IsRecordValid(IClientEntity* pEntity, LagRecord_tT& Record);
float lerpTime();
bool IsTickValid(int Tick);
bool LBYShouldUpdate(IClientEntity* pEntity);
bool ProcessCmd(int iTargetIndex, CUserCmd* pCmd);
void Cache();
bool FindBestRecord(IClientEntity* pEntity);
bool FindOldestRecord(IClientEntity* pEntity);
};
extern std::unique_ptr<CTimeSimulator> newtestBacktrack;