Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
2,861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.05 KB | None | 0 0
  1. #include "Resolver.h"
  2. #include "md5.h"
  3. #include "cvars.h"
  4.  
  5.  
  6. CResolver::CResolver(void)
  7. {
  8.  
  9. }
  10.  
  11. bool CResolver::m_bUpdateTick(CBaseEntity* pBaseEntity)
  12. {
  13. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  14.  
  15. auto *m_flLowerBodyYawTarget = reinterpret_cast<float*>(reinterpret_cast<DWORD>(pBaseEntity) + Offsets::m_flLowerBodyYawTarget);
  16.  
  17. if (pBaseEntity->GetChokedTicks() <= 1)
  18. FillSimulationInfo(pBaseEntity, false);
  19.  
  20. if (fabs(currenttickdata.m_flLowerBodyYawTarget - *m_flLowerBodyYawTarget) > 5.f)
  21. {
  22. currenttickdata.m_fLowerBodyYawArray.push_back(*m_flLowerBodyYawTarget);
  23. currenttickdata.m_flLowerBodyYawTarget = *m_flLowerBodyYawTarget;
  24. currenttickdata.m_iLowerbodyTick = TIME_TO_TICKS(g_pGlobalVarsBase->curtime);
  25. }
  26.  
  27. currenttickdata.m_BFlags.push_back(pBaseEntity->GetFlags());
  28. //currenttickdata.m_nSequence.push_back(pBaseEntity->m_nSequence());
  29. //currenttickdata.m_flCycle.push_back(pBaseEntity->m_flCycle());
  30. //for (int i = 0; i < 23; i++) { currenttickdata.m_flPoseParameter[i].push_front(pBaseEntity->get_pose_parameter(i)); }
  31. currenttickdata.m_vecOriginArray.push_back(pBaseEntity->m_vecNetworkOrigin());
  32. currenttickdata.m_vecAbsOriginArray.push_back(pBaseEntity->m_vecNetworkOrigin());
  33. currenttickdata.m_angEyeAngles = pBaseEntity->GetEyeAngles();
  34. currenttickdata.m_flSimulationTime.push_back(pBaseEntity->m_flSimulationTime());
  35. currenttickdata.m_fAllLowerBodyYawArray.push_back(*m_flLowerBodyYawTarget);
  36. currenttickdata.tickcount = TIME_TO_TICKS(g_pGlobalVarsBase->curtime);
  37. currenttickdata.m_flPitch = pBaseEntity->GetEyeAngles().x;
  38. currenttickdata.m_flYaw = pBaseEntity->GetEyeAngles().y;
  39. currenttickdata.m_iChokedTicks.push_back(pBaseEntity->GetChokedTicks());
  40. currenttickdata.m_vecNetworkOrigin = pBaseEntity->m_vecNetworkOrigin();
  41. return true;
  42. }
  43.  
  44.  
  45. template<class T, class U>
  46. T clamp(T in, U low, U high)
  47. {
  48. if (in <= low)
  49. return low;
  50.  
  51. if (in >= high)
  52. return high;
  53.  
  54. return in;
  55. }
  56.  
  57. float CResolver::m_fLerpTime()
  58. {
  59. float updaterate = g_pICvar->FindVar("cl_updaterate")->GetFloat();
  60. ConVar* minupdate = g_pICvar->FindVar("sv_minupdaterate");
  61. ConVar* maxupdate = g_pICvar->FindVar("sv_maxupdaterate");
  62.  
  63. if (minupdate && maxupdate)
  64. updaterate = clamp(updaterate, minupdate->GetFloat(), maxupdate->GetFloat());//maxupdate->GetFloat();
  65.  
  66. float ratio = g_pICvar->FindVar("cl_interp_ratio")->GetFloat();
  67.  
  68. if (ratio == 0)
  69. ratio = 1.0f;
  70.  
  71. float lerp = g_pICvar->FindVar("cl_interp")->GetFloat();
  72. ConVar* cmin = g_pICvar->FindVar("sv_client_min_interp_ratio");
  73. ConVar* cmax = g_pICvar->FindVar("sv_client_max_interp_ratio");
  74.  
  75. if (cmin && cmax && cmin->GetFloat() != 1)
  76. ratio = clamp(ratio, cmin->GetFloat(), cmax->GetFloat());
  77.  
  78. return max(lerp, ratio / updaterate);
  79. }
  80.  
  81.  
  82. bool CResolver::m_bEmptyAtRecord(CBaseEntity* pBaseEntity, int m_iRecordDest)
  83. {
  84. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  85. currenttickdata.m_vecOriginArray.erase(currenttickdata.m_vecOriginArray.begin() + m_iRecordDest);
  86. currenttickdata.m_vecAbsOriginArray.erase(currenttickdata.m_vecAbsOriginArray.begin() + m_iRecordDest);
  87. currenttickdata.m_flSimulationTime.erase(currenttickdata.m_flSimulationTime.begin() + m_iRecordDest);
  88. currenttickdata.m_fLowerBodyYawArray.erase(currenttickdata.m_fLowerBodyYawArray.begin() + m_iRecordDest);
  89. currenttickdata.m_iChokedTicks.erase(currenttickdata.m_iChokedTicks.begin() + m_iRecordDest);
  90. currenttickdata.m_fAllLowerBodyYawArray.erase(currenttickdata.m_fAllLowerBodyYawArray.begin() + m_iRecordDest);
  91. currenttickdata.m_nSequence.erase(currenttickdata.m_nSequence.begin() + m_iRecordDest);
  92. currenttickdata.m_flCycle.erase(currenttickdata.m_flCycle.begin() + m_iRecordDest);
  93. currenttickdata.m_BFlags.erase(currenttickdata.m_BFlags.begin() + m_iRecordDest);
  94. //for (int i = 0; i < 23; i++) { currenttickdata.m_flPoseParameter[i].pop_back(); }
  95. }
  96.  
  97. bool CResolver::m_bEmptyAllRecord(CBaseEntity* pBaseEntity)
  98. {
  99. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  100. currenttickdata.m_vecOriginArray.clear();
  101. currenttickdata.m_vecAbsOriginArray.clear();
  102. currenttickdata.m_flSimulationTime.clear();
  103. currenttickdata.m_fLowerBodyYawArray.clear();
  104. currenttickdata.m_iChokedTicks.clear();
  105. currenttickdata.m_fAllLowerBodyYawArray.clear();
  106. }
  107.  
  108. //bool CResolver::m_bIsEntitySimulated(CBaseEntity* pBaseEntity)
  109. //{
  110. // return m_bBacktracked[pBaseEntity->GetIndex()];
  111. //}
  112.  
  113. bool CResolver::m_bIsEntityBacktracked(CBaseEntity* pBaseEntity)
  114. {
  115. return m_bBacktracked[pBaseEntity->GetIndex()];
  116. }
  117.  
  118. bool CResolver::m_iBacktrackedTick(CBaseEntity* pBaseEntity)
  119. {
  120. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  121. if (m_bIsEntityBacktracked(pBaseEntity) && !currenttickdata.m_bBreakingLagComp && !m_bSimulated[pBaseEntity->GetIndex()])
  122. return m_bBacktrackedTick[pBaseEntity->GetIndex()];
  123. else
  124. return g_pGlobalVarsBase->curtime;
  125. }
  126.  
  127. bool CResolver::FillSimulationInfo(CBaseEntity* pBaseEntity, bool m_bStoreLowerBodyYaw)
  128. {
  129. auto &simdata = CurrentTickPlayerTrack[pBaseEntity->GetIndex()];
  130. auto &oldsimdata = LastTickPlayerTrack[pBaseEntity->GetIndex()];
  131.  
  132. oldsimdata.velocity = simdata.velocity;
  133. oldsimdata.basevelocity = simdata.basevelocity;
  134. oldsimdata.flags = simdata.flags;
  135. oldsimdata.m_pEntity = simdata.m_pEntity;
  136. oldsimdata.origin = simdata.origin;
  137. oldsimdata.networkorigin = simdata.networkorigin;
  138. oldsimdata.m_bLog = simdata.m_bLog;
  139.  
  140. simdata.velocity = pBaseEntity->GetVelocity();
  141. simdata.basevelocity = pBaseEntity->GetBaseVelocity();
  142. simdata.flags = pBaseEntity->GetFlags();
  143. simdata.m_pEntity = pBaseEntity;
  144. simdata.origin = pBaseEntity->m_vecNetworkOrigin();
  145. simdata.networkorigin = pBaseEntity->m_vecNetworkOrigin();
  146. simdata.m_bLog = true;
  147. }
  148.  
  149. void CResolver::SimulateMovement(SimulationData& data, bool in_air)
  150. {
  151. auto mins = data.m_pEntity->GetCollideable()->OBBMins();
  152. auto maxs = data.m_pEntity->GetCollideable()->OBBMaxs();
  153.  
  154. auto src = data.networkorigin;
  155. auto end = src + (data.velocity * g_pGlobalVarsBase->interval_per_tick);
  156.  
  157. SDK::IEngineTrace::Ray_t ray;
  158. ray.Init(src, end, mins, maxs);
  159.  
  160. SDK::IEngineTrace::trace_t trace;
  161. SDK::IEngineTrace::CTraceFilter filter;
  162. filter.pSkip = (IHandleEntity*)data.m_pEntity;
  163. g_pEngineTrace->TraceRay(ray, CONTENTS_SOLID, &filter, &trace);
  164.  
  165. if (trace.fraction != 1.f)
  166. {
  167. for (int i = 0; i < 2; ++i)
  168. {
  169. data.velocity -= trace.plane.normal * data.velocity.Dot(trace.plane.normal);
  170.  
  171. auto dot = data.velocity.Dot(trace.plane.normal);
  172. if (dot < 0.f)
  173. {
  174. data.velocity.x -= dot * trace.plane.normal.x;
  175. data.velocity.y -= dot * trace.plane.normal.y;
  176. data.velocity.z -= dot * trace.plane.normal.z;
  177. }
  178.  
  179. end = trace.endpos + (data.velocity * (g_pGlobalVarsBase->interval_per_tick * (1.f - trace.fraction)));
  180. ray.Init(trace.endpos, end, mins, maxs);
  181. g_pEngineTrace->TraceRay(ray, CONTENTS_SOLID, &filter, &trace);
  182.  
  183. if (trace.fraction == 1.f)
  184. break;
  185. }
  186. }
  187.  
  188. data.networkorigin = trace.endpos;
  189. end = trace.endpos;
  190. end.z -= 2.f;
  191.  
  192. ray.Init(data.networkorigin, end, mins, maxs);
  193. g_pEngineTrace->TraceRay(ray, CONTENTS_SOLID, &filter, &trace);
  194.  
  195. data.flags &= ~FL_ONGROUND;
  196.  
  197. if (trace.fraction != 1.f && trace.plane.normal.z > 0.7f)
  198. data.flags |= FL_ONGROUND;
  199. }
  200.  
  201. void CResolver::ExtrapolateEntityData(CBaseEntity* pBaseEntity)
  202. {
  203. auto &data = CurrentTickPlayerTrack[pBaseEntity->GetIndex()];
  204. auto &olddata = LastTickPlayerTrack[pBaseEntity->GetIndex()];
  205.  
  206. if (!olddata.m_pEntity->IsValid())
  207. return;
  208.  
  209. if (!olddata.m_bLog)
  210. return;
  211.  
  212. Vector originalOrigin = pBaseEntity->m_vecNetworkOrigin();
  213.  
  214. INetChannelInfo *nci = g_pIVEngineClient->GetNetChannelInfo();
  215.  
  216. float flTickInterval = 1.f / g_pGlobalVarsBase->interval_per_tick;
  217.  
  218. int iTickCount = TIME_TO_TICKS(g_pGlobalVarsBase->curtime);
  219.  
  220. float flDeltaTime = ((floorf(((nci->GetAvgLatency(FLOW_INCOMING) + nci->GetAvgLatency(FLOW_OUTGOING)) * flTickInterval) + 0.5)
  221. + iTickCount
  222. + 1)
  223. * g_pGlobalVarsBase->interval_per_tick)
  224. - pBaseEntity->m_flSimulationTime();
  225.  
  226. if (flDeltaTime > 1.f)
  227. flDeltaTime = 1.f;
  228.  
  229. float velocityDegree = RAD2DEG(atan2(data.velocity.x, data.velocity.y));
  230. int deltaTicks = floorf((flTickInterval * flDeltaTime) + 0.5);
  231. float velocityAngle = velocityDegree - RAD2DEG(atan2(olddata.velocity.x, olddata.velocity.y));
  232.  
  233. if (velocityAngle <= 180.0)
  234. {
  235. if (velocityAngle < -180.0)
  236. velocityAngle = velocityAngle + 360.0;
  237. }
  238. else
  239. {
  240. velocityAngle = velocityAngle - 360.0;
  241. }
  242.  
  243. //flNewVelocityAngle = Utils::NormalizeYaw(flNewVelocityAngle);
  244. float m_flSimTimeDelta = pBaseEntity->m_flSimulationTime() - pBaseEntity->m_flOldSimulationTime();
  245.  
  246. // How many ticks the entity is choking
  247. int iSimulationTicks = clamp(floorf((m_flSimTimeDelta * flTickInterval) + 0.5f), 1, 15);
  248. // How many ticks since entity was last simulated
  249. int iDeltaTicks = TIME_TO_TICKS(flDeltaTime);
  250. // How many ticks have passed since sim time - how many ticks they will choke
  251. int iSimulationDif = iDeltaTicks - iSimulationTicks;
  252. // Total angle difference divided by time = angle per unit of time (in this case seconds)
  253. float flAnglePerSec = velocityAngle / m_flSimTimeDelta;
  254. //flAnglePerSec = Utils::NormalizeYaw(flAnglePerSec);
  255.  
  256. // Just velocity length
  257. float flVelocityLength2D = data.velocity.Length2D();
  258.  
  259. if (iSimulationDif < 0)
  260. {
  261. data.networkorigin = originalOrigin;
  262. }
  263. else
  264. {
  265. do
  266. {
  267. if (iSimulationTicks > 0)
  268. {
  269. int counter = iSimulationTicks;
  270. do
  271. {
  272.  
  273. // Add on the estimated angle difference
  274. float flExtrapolated = velocityDegree + (g_pGlobalVarsBase->interval_per_tick * flAnglePerSec);
  275.  
  276. // Calculate the new velocity
  277. data.velocity.x = cosf(DEG2RAD(flExtrapolated)) * flVelocityLength2D;
  278. data.velocity.y = sinf(DEG2RAD(flExtrapolated)) * flVelocityLength2D;
  279.  
  280. // Check if entity is in air
  281. bool InAir = !(pBaseEntity->GetFlags() & FL_ONGROUND);
  282.  
  283. if (!(data.flags & FL_ONGROUND))
  284. data.velocity.z -= (g_pGlobalVarsBase->interval_per_tick * g_pICvar->FindVar("sv_gravity")->GetFloat());
  285. else if (InAir)
  286. data.velocity.z = sqrt(91200.f);
  287.  
  288. // Simulate the movement calculated
  289. SimulateMovement(data, InAir);
  290.  
  291. // Store the new velocity angle
  292. velocityDegree = flExtrapolated;
  293.  
  294. // One tick has been simulated, subtract this from the count
  295. --counter;
  296. } while (counter);
  297. }
  298. iSimulationDif -= iSimulationTicks;
  299. } while (iSimulationDif >= 0);
  300. }
  301.  
  302. if (std::isfinite(data.networkorigin.x) && std::isfinite(data.networkorigin.y) && std::isfinite(data.networkorigin.z))
  303. {
  304. data.m_vLastFix = data.networkorigin;
  305. pBaseEntity->SetAbsOrigin(data.networkorigin);
  306. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  307. m_bBacktracked[pBaseEntity->GetIndex()] = false;
  308. m_bSimulated[pBaseEntity->GetIndex()] = true;
  309. }
  310. else
  311. {
  312. m_bBacktracked[pBaseEntity->GetIndex()] = false;
  313. m_bSimulated[pBaseEntity->GetIndex()] = false;
  314. }
  315. }
  316.  
  317. bool CResolver::m_bMoveEntityToValidRecord(CBaseEntity* pBaseEntity)
  318. {
  319. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  320.  
  321. if (m_bFindValidRecord(pBaseEntity))
  322. {
  323. if (m_iBestTick[pBaseEntity->GetIndex()] = -1)
  324. return false;
  325.  
  326. auto *m_angEyeAnglesY = reinterpret_cast<float*>(reinterpret_cast<DWORD>(pBaseEntity) + Offsets::m_angEyeAnglesY);
  327.  
  328. if (Cvars.Aimbot_AntiAimCorrection)
  329. *m_angEyeAnglesY = currenttickdata.m_fAllLowerBodyYawArray.at(m_iBestTick[pBaseEntity->GetIndex()]);
  330.  
  331. if (std::isfinite(currenttickdata.m_vecAbsOriginArray.at(m_iBestTick[pBaseEntity->GetIndex()]).x) && std::isfinite(currenttickdata.m_vecAbsOriginArray.at(m_iBestTick[pBaseEntity->GetIndex()]).y) && std::isfinite(currenttickdata.m_vecAbsOriginArray.at(m_iBestTick[pBaseEntity->GetIndex()]).z))
  332. pBaseEntity->SetAbsOrigin(currenttickdata.m_vecAbsOriginArray.at(m_iBestTick[pBaseEntity->GetIndex()]));
  333. else
  334. {
  335. m_bBacktracked[pBaseEntity->GetIndex()] = false;
  336.  
  337. m_bSimulated[pBaseEntity->GetIndex()] = false;
  338.  
  339. return false;
  340. }
  341.  
  342. m_bBacktrackedTick[pBaseEntity->GetIndex()] = currenttickdata.m_flSimulationTime.at(m_iBestTick[pBaseEntity->GetIndex()]);
  343.  
  344. m_bBacktracked[pBaseEntity->GetIndex()] = true;
  345.  
  346. m_bSimulated[pBaseEntity->GetIndex()] = false;
  347.  
  348. return true;
  349. }
  350. //else
  351. //{
  352.  
  353. //if (Cvars.Aimbot_AccuracyBoostLevelType > 1)
  354. // ExtrapolateEntityData(pBaseEntity);
  355.  
  356. // m_bBacktracked[pBaseEntity->GetIndex()] = false;
  357. //}
  358.  
  359. return m_bBacktracked[pBaseEntity->GetIndex()];
  360. }
  361.  
  362. bool CResolver::m_bFindValidRecord(CBaseEntity* pBaseEntity)
  363. {
  364. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  365.  
  366. if (currenttickdata.m_vecOriginArray.size() < 2)
  367. return false;
  368.  
  369. auto nci = g_pIVEngineClient->GetNetChannelInfo();
  370.  
  371. if (!nci)
  372. return false;
  373.  
  374. int iLerpTicks = TIME_TO_TICKS(m_fLerpTime());
  375. float flCorrect = nci->GetAvgLatency(FLOW_OUTGOING) + TICKS_TO_TIME(iLerpTicks);
  376. float flServerTime = TIME_TO_TICKS(g_pGlobalVarsBase->curtime) * g_pGlobalVarsBase->interval_per_tick;
  377. static auto sv_maxunlag = g_pICvar->FindVar("sv_maxunlag");
  378. flCorrect = clamp(flCorrect, 0.f, sv_maxunlag->GetFloat());
  379. bool bFoundRecord = false;
  380.  
  381. for (auto i = 0; i < currenttickdata.m_vecOriginArray.size(); i++)
  382. {
  383. // If the server lost track, we can't backtrack past here.
  384. if (((currenttickdata.m_vecOriginArray.at(i)) - pBaseEntity->m_vecNetworkOrigin()).Length() > 64.f)
  385. {
  386.  
  387. m_bEmptyAtRecord(pBaseEntity, i);
  388. i--;
  389. break;
  390. }
  391. // Calculate delta time like server.
  392. float flDeltaTime = flCorrect - (flServerTime - currenttickdata.m_flSimulationTime.at(i));
  393. // If the delta time is too large, we can't backtrack past here.
  394. if (fabs(flDeltaTime) > 0.2f)
  395. {
  396. m_bEmptyAtRecord(pBaseEntity, i);
  397. i--;
  398. break;
  399. }
  400.  
  401. if (currenttickdata.m_iChokedTicks.at(i) <= 1)
  402. {
  403. m_iBestTick[pBaseEntity->GetIndex()] = i;
  404. bFoundRecord = true;
  405. break;
  406. }
  407. }
  408.  
  409. if (!bFoundRecord)
  410. m_iBestTick[pBaseEntity->GetIndex()] = -1;
  411.  
  412. return bFoundRecord;
  413. }
  414.  
  415. bool CResolver::m_bResolveEntity(CBaseEntity* pBaseEntity)
  416. {
  417. auto &currenttickdata = m_ResolverTrack[pBaseEntity->GetIndex()];
  418. int m_iLastPushDifference = abs(currenttickdata.m_iLowerbodyTick - TIME_TO_TICKS(g_pGlobalVarsBase->curtime));
  419. auto *m_angEyeAnglesX = reinterpret_cast<float*>(reinterpret_cast<DWORD>(pBaseEntity) + Offsets::m_angEyeAnglesX);
  420. auto *m_angEyeAnglesY = reinterpret_cast<float*>(reinterpret_cast<DWORD>(pBaseEntity) + Offsets::m_angEyeAnglesY);
  421. auto *m_flLowerBodyYawTarget = reinterpret_cast<float*>(reinterpret_cast<DWORD>(pBaseEntity) + Offsets::m_flLowerBodyYawTarget);
  422. int maxupdate = TIME_TO_TICKS(1.1);
  423. int doubledupdate = TIME_TO_TICKS(2.2);
  424. float yaw[] = { 90.f, -90.f, -180.f, 45.f, -45.f };
  425.  
  426. //checks
  427. bool m_bMoving = pBaseEntity->GetVelocity().Length() > 0.0f;
  428. bool m_bDucking = pBaseEntity->GetFlags() & FL_DUCKING;
  429. bool m_bOnGround = pBaseEntity->GetFlags() & FL_ONGROUND;
  430. bool m_bUpdateIsOld = m_iLastPushDifference > maxupdate;
  431. bool m_bUpdateIsTooOld = m_iLastPushDifference > doubledupdate;
  432. //inc junk logic
  433.  
  434. //entity appears to be walking across the ground which should give us a constant update on their angles
  435. if (m_bOnGround && m_bMoving && !m_bUpdateIsOld)
  436. *m_angEyeAnglesY = *m_flLowerBodyYawTarget;
  437. //entity isnt moving but lby hasnt updated in awhile which tells us their angles probably havent changed much if at all
  438. if (m_bOnGround && !m_bMoving && m_bUpdateIsOld)
  439. *m_angEyeAnglesY = *m_flLowerBodyYawTarget;
  440. //shouldnt ever happen but whatever
  441. if (!m_bOnGround && !m_bMoving && !m_bUpdateIsOld)
  442. *m_angEyeAnglesY = *m_flLowerBodyYawTarget + Cvars.m_bShotFiredSwitch ? 15.f : 15.f;
  443. //entity is moving and is in the air, expand your search
  444. if (!m_bOnGround && !m_bMoving && m_bUpdateIsOld && !m_bUpdateIsTooOld)
  445. *m_angEyeAnglesY = *m_flLowerBodyYawTarget + Cvars.m_bShotFiredSwitch ? 45.f : 45.f;
  446. //entity is moving and our update is way too old expand to reasonable angles
  447. if (!m_bOnGround && !m_bMoving && m_bUpdateIsOld && m_bUpdateIsTooOld)
  448. *m_angEyeAnglesY = yaw[Cvars.m_iShotsFired];
  449.  
  450. return true;
  451. }
  452.  
  453. CResolver* ResolvePlayer = nullptr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement