Advertisement
Guest User

Resolver.h

a guest
Nov 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.20 KB | None | 0 0
  1. #pragma once
  2.  
  3. namespace sdk
  4. {
  5. class CUserCmd;
  6. class CBaseEntity;
  7. class CBaseWeapon;
  8. }
  9.  
  10. struct Info
  11. {
  12. Info() {}
  13.  
  14. SDK::CAnimationLayer backup_layer, prev_layer;
  15. Vector last_lby, inverse, inverse_right, inverse_left, lby, back, left, right, backtrack;
  16. float stored_simtime, last_move_time, pre_anim_lby;
  17. int last_ammo;
  18. bool breaking_lby, reset_state, could_be_faking;
  19. std::vector<float> unresolved_yaw, lby_deltas;
  20.  
  21. bool lby_changed;
  22. bool could_be_slowmo;
  23. bool is_moving;
  24. bool is_dormant;
  25. bool is_last_moving_lby_valid;
  26. bool is_standing;
  27. bool is_fakewalking;
  28. bool is_jumping;
  29. bool is_crouching;
  30. bool lby_updated;
  31. bool using_fake_angles;
  32. float last_moving_lby;
  33. float stored_lby;
  34. float next_lby_update_time;
  35. float can_predict;
  36. int stored_missed;
  37. };
  38.  
  39.  
  40. class CResolver
  41. {
  42. public:
  43. Info player_info[65];
  44. void record(SDK::CBaseEntity * entity, float new_yaw);
  45. bool AntiFreestanding(SDK::CBaseEntity * entity, float & yaw);
  46. int GetResolveTypeIndex(unsigned short resolve_type);
  47. std::string TranslateResolveRecord(unsigned short resolve_type);
  48. CColor GetResolveColor(unsigned short resolve_type);
  49. void ResolveYawBruteforce(SDK::CBaseEntity * entity);
  50. bool breaking_lby(SDK::CBaseEntity * entity);
  51. float ResolvePitch(SDK::CBaseEntity * pPlayer, float org_pitch);
  52. void resolve(SDK::CBaseEntity* entity);
  53. bool playerStoppedMoving(SDK::CBaseEntity * entity);
  54. void resolve2(SDK::CBaseEntity* entity);
  55. struct ResolverData
  56. {
  57. //ints
  58. int right_damage = 0, left_damage = 0;
  59. int stored_missed;
  60. int missed;
  61. int shotaimangles;
  62. //ints
  63.  
  64. //floats
  65. float lastlbystand;
  66. float right_fraction = 0.f, left_fraction = 0.f;
  67. float last_moving_lby;
  68. float stored_lby;
  69. float next_lby_update;
  70. float lby1, nextlbyup;
  71. float lastmovinglby;
  72. float flick;
  73. float lastlby;
  74. //floats
  75.  
  76. //bools
  77. bool is_moving;
  78. bool is_jumping;
  79. bool is_crouching;
  80. bool using_fake_angles;
  81. bool bfakeangle, bfakewalk, playerhurtcalled, weaponfirecalled;
  82. bool lbywasupdated;
  83. //bools
  84.  
  85. //vectors
  86. SDK::CAnimationLayer anim_layers[15];
  87. //vectors
  88.  
  89.  
  90. } pResolverData[64];
  91.  
  92.  
  93. void ProcessSnapShots();
  94.  
  95. bool IsFakewalking2(SDK::CBaseEntity * player);
  96.  
  97.  
  98. public:
  99. /// resolve types, they're "flags" so to speak since a player can have more than 1 resolve type at once
  100. /// if angles overlap
  101. static const unsigned int RESOLVE_TYPE_NUM = 8;
  102. static const unsigned short RESOLVE_TYPE_OVERRIDE = 0b00000001,
  103. RESOLVE_TYPE_NO_FAKE = 0b00000010,
  104. RESOLVE_TYPE_LBY = 0b00000100,
  105. RESOLVE_TYPE_LBY_UPDATE = 0b00001000,
  106. RESOLVE_TYPE_PREDICTED_LBY_UPDATE = 0b00010000,
  107. RESOLVE_TYPE_LAST_MOVING_LBY = 0b00100000,
  108. RESOLVE_TYPE_NOT_BREAKING_LBY = 0b01000000,
  109. RESOLVE_TYPE_BRUTEFORCE = 0b10000000,
  110. RESOLVE_TYPE_LAST_MOVING_LBY_DELTA = 0b100000000,
  111. RESOLVE_TYPE_ANTI_FREESTANDING = 0b1000000000;
  112.  
  113. public:
  114. /// a struct holding info the resolver needs, updated every frame for every player
  115. class PlayerResolveRecord
  116. {
  117. public:
  118. PlayerResolveRecord()
  119. {
  120. resolve_type = 0;
  121. shots_missed_moving_lby = 0;
  122. shots_missed_moving_lby_delta = 0;
  123.  
  124. last_balance_adjust_trigger_time = 0.f;
  125. last_moving_lby_delta = 0.f;
  126. last_time_moving = 0.f;
  127. last_time_down_pitch = 0.f;
  128. next_predicted_lby_update = 0.f;
  129.  
  130. has_fake = false;
  131. is_dormant = false, is_last_moving_lby_delta_valid = false;
  132. is_last_moving_lby_valid = false, is_fakewalking = false;
  133. is_balance_adjust_triggered = false, is_balance_adjust_playing = false;
  134. did_lby_flick = false, did_predicted_lby_flick = false;
  135.  
  136. for (int i = 0; i < RESOLVE_TYPE_NUM; i++)
  137. {
  138. shots_hit[i] = 0;
  139. shots_fired[i] = 0;
  140. }
  141. }
  142.  
  143. public:
  144. struct AntiFreestandingRecord
  145. {
  146. int right_damage = 0, left_damage = 0;
  147. float right_fraction = 0.f, left_fraction = 0.f;
  148. };
  149.  
  150. public:
  151. SDK::CAnimationLayer anim_layers[15];
  152. AntiFreestandingRecord anti_freestanding_record;
  153.  
  154. Vector resolved_angles, networked_angles;
  155. Vector velocity, origin;
  156.  
  157. int shots_hit[RESOLVE_TYPE_NUM], shots_fired[RESOLVE_TYPE_NUM];
  158. int shots_missed_moving_lby, shots_missed_moving_lby_delta;
  159. unsigned short resolve_type;
  160.  
  161. float lower_body_yaw;
  162. float last_moving_lby;
  163. float last_moving_lby_delta;
  164. float last_balance_adjust_trigger_time;
  165. float last_time_moving;
  166. float last_time_down_pitch;
  167. float next_predicted_lby_update;
  168.  
  169. bool is_dormant;
  170. bool last_lby_update;
  171. bool is_last_moving_lby_valid;
  172. bool is_fakewalking;
  173. bool is_last_moving_lby_delta_valid;
  174. bool is_balance_adjust_triggered, is_balance_adjust_playing;
  175. bool did_lby_flick, did_predicted_lby_flick;
  176. bool has_fake;
  177. };
  178. struct STickRecord {
  179.  
  180. bool operator==(STickRecord &other) {
  181. return other.m_flSimulationTime == m_flSimulationTime;
  182. }
  183.  
  184. float m_flVelocity = 0.f;
  185. Vector m_vecVelocity = Vector(0, 0, 0);
  186. float m_flSimulationTime = 0.f;
  187. float m_flLowerBodyYawTarget = 0.f;
  188. //std::array<float, 24> m_flPoseParameter = {};
  189. float m_flCurTime = 0.f;
  190. int m_nFlags = 0;
  191.  
  192. int m_iLayerCount = 0;
  193. SDK::CAnimationLayer animationLayer[15];
  194. };
  195. struct SResolveInfo
  196. {
  197. std::deque<STickRecord> arr_tickRecords;
  198.  
  199. STickRecord curTickRecord;
  200. STickRecord prevtickrec;
  201. float_t m_flLowerBodyYawTarget;
  202.  
  203. float m_flLastLbyTime = 0.f;
  204.  
  205. float_t m_flLbyDelta;
  206.  
  207. int32_t m_nCorrectedFakewalkIdxs;
  208.  
  209. float_t m_flStandingTime;
  210. float_t m_flMovingLBY;
  211. bool m_bIsMoving;
  212.  
  213. QAngle m_angDirectionFirstMoving = QAngle(0, 0, 0);
  214. };
  215. struct ResolveInfo
  216. {
  217. ResolveInfo()
  218. {
  219. m_bActive = false;
  220.  
  221. m_flVelocity = 0.f;
  222. m_vecVelocity = Vector(0, 0, 0);
  223. m_angEyeAngles = QAngle(0, 0, 0);
  224. m_flSimulationTime = 0.f;
  225. m_flLowerBodyYawTarget = 0.f;
  226.  
  227. m_angDirectionFirstMoving = QAngle(0, 0, 0);
  228. m_nCorrectedFakewalkIdx = 0;
  229. }
  230.  
  231. void SaveRecord(SDK::CBaseEntity *player)
  232. {
  233. m_iLayerCount = player->GetNumAnimOverlays();
  234. for (int i = 0; i < m_iLayerCount; i++)
  235. animationLayer[i] = player->GetAnimOverlays()[i];
  236. }
  237.  
  238. bool operator==(const ResolveInfo &other)
  239. {
  240. return other.m_flSimulationTime == m_flSimulationTime;
  241. }
  242.  
  243. bool m_bActive;
  244.  
  245. float_t m_flVelocity;
  246. Vector m_vecVelocity;
  247. QAngle m_angEyeAngles;
  248. float_t m_flSimulationTime;
  249. float_t m_flLowerBodyYawTarget;
  250.  
  251. int32_t m_iLayerCount = 0;
  252. SDK::CAnimationLayer animationLayer[15];
  253.  
  254. QAngle m_angDirectionFirstMoving;
  255. int32_t m_nCorrectedFakewalkIdx;
  256.  
  257. int32_t m_nShotsMissed = 0;
  258. };
  259. /// a snapshot holding info about the moment you shot, used to count shots missed / hit
  260. struct ShotSnapshot
  261. {
  262. SDK::CBaseEntity* entity; /// person we shot at
  263. PlayerResolveRecord resolve_record; /// their resolve record when we shot
  264.  
  265. float time; /// time when snapshot was created
  266. float first_processed_time; /// time when the shot was first processed
  267. bool was_shot_processed;
  268. int hitgroup_hit;
  269. };
  270.  
  271. private:
  272. PlayerResolveRecord player_resolve_records[64];
  273. std::vector<ShotSnapshot> shot_snapshots;
  274. std::vector<Vector> last_eye_positions;
  275.  
  276. public:
  277. PlayerResolveRecord & GetPlayerResolveInfo(SDK::CBaseEntity* entity)
  278. {
  279. return player_resolve_records[entity->GetIndex()];
  280. }
  281.  
  282. void Nospread(SDK::CBaseEntity * entity);
  283.  
  284. void UpdateResolveRecord(SDK::CBaseEntity * entity);
  285.  
  286. // std::string TranslateResolveRecord(unsigned short resolve_type);
  287. // CColor GetResolveColor(unsigned short resolve_type);
  288. //int GetShotsMissed(SDK::CBaseEntity* entity, unsigned short resolve_type);
  289.  
  290. bool IsResolved(const unsigned short& resolve_type)
  291. {
  292. if (resolve_type & RESOLVE_TYPE_NO_FAKE ||
  293. resolve_type & RESOLVE_TYPE_LBY_UPDATE ||
  294. resolve_type & RESOLVE_TYPE_PREDICTED_LBY_UPDATE)
  295. return true;
  296.  
  297. return false;
  298. }
  299.  
  300. bool IsFakewalking(SDK::CBaseEntity* entity)
  301. {
  302. return player_resolve_records[entity->GetIndex()].is_fakewalking;
  303. }
  304.  
  305. bool IsMovingOnGround(SDK::CBaseEntity* entity)
  306. {
  307. return player_resolve_records[entity->GetIndex()].velocity.Length2D() > 0.5f && entity->GetFlags() & FL_ONGROUND;
  308. }
  309.  
  310.  
  311. /// pushback a record onto the shot snapshot queue
  312.  
  313.  
  314. //void EventCallback(SDK::IGameEventManager game_event);
  315.  
  316. private:
  317. // void ProcessSnapShots();
  318.  
  319.  
  320. };
  321.  
  322. extern CResolver* resolver;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement