SHARE
TWEET

Untitled

a guest Sep 15th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "CAutoWall.h"
  2.  
  3. //returninfo c_autowall::autowall(Vector start, Vector end, CBaseEntity* from_ent, CBaseEntity* to_ent, int hitgroup) {
  4. //  returninfo rt;
  5. //
  6. //  fbdata bullet;
  7. //  bullet.start = start;
  8. //  bullet.end = end;
  9. //  bullet.pos = start;
  10. //  bullet.thickness = 0.f;
  11. //  bullet.walls = 4;
  12. //
  13. //  Utilities->Math_AngleVectors(Utilities->Math_CalcAngle(start, end), bullet.dir);
  14. //
  15. //  auto flt_player = CTraceFilterOneEntity();
  16. //  flt_player.pEntity = to_ent;
  17. //
  18. //  auto flt_self = CTraceFilter();
  19. //  flt_self.pSkip1 = from_ent;
  20. //
  21. //  if (to_ent)
  22. //      bullet.filter = &flt_player;
  23. //  else
  24. //      bullet.filter = &flt_self;
  25. //
  26. //  auto wep = from_ent->GetActiveWeapon();
  27. //  if (!wep)
  28. //      return rt;
  29. //
  30. //  auto inf = wep->get_full_info();
  31. //  if (!inf)
  32. //      return rt;
  33. //
  34. //  end = start + bullet.dir * (wep->is_knife() ? 45.f : inf->range);
  35. //  bullet.damage = inf->damage;
  36. //
  37. //  while (bullet.damage > 0 && bullet.walls > 0) {
  38. //      rt.walls = bullet.walls;
  39. //
  40. //      Ray_t ray;
  41. //      ray.Init(bullet.pos, end);
  42. //
  43. //      CTraceFilter filter;
  44. //      filter.pSkip1 = from_ent;
  45. //
  46. //      Interfaces::Trace->TraceRay(ray, MASK_SHOT | CONTENTS_GRATE, &filter, &bullet.trace);
  47. //      this->clip_trace_to_player(bullet.pos, bullet.pos + bullet.dir * 40.f, to_ent, MASK_SHOT | CONTENTS_GRATE, bullet.filter, &bullet.trace);
  48. //
  49. //      bullet.damage *= powf(inf->range_modifier, (bullet.trace.end - start).Length() / 500.f);
  50. //
  51. //      if (bullet.trace.fraction == 1.f) {
  52. //          if (to_ent && hitgroup != -1) {
  53. //              this->scale_damage(to_ent, inf, hitgroup, bullet.damage);
  54. //
  55. //              rt.damage = bullet.damage;
  56. //              rt.hitgroup = hitgroup;
  57. //              rt.end = bullet.trace.end;
  58. //              rt.ent = to_ent;
  59. //          }
  60. //          else {
  61. //              rt.damage = bullet.damage;
  62. //              rt.hitgroup = -1;
  63. //              rt.end = bullet.trace.end;
  64. //              rt.ent = nullptr;
  65. //          }
  66. //      }
  67. //
  68. //      if (bullet.trace.hitGroup > 0 && bullet.trace.hitGroup <= 7) {
  69. //          if (to_ent && bullet.trace.m_pEnt != to_ent ||
  70. //              bullet.trace.m_pEnt->GetTeam() == from_ent->GetTeam()) {
  71. //              rt.damage = -1;
  72. //
  73. //              return rt;
  74. //          }
  75. //
  76. //          if (hitgroup != -1)
  77. //              scale_damage(bullet.trace.m_pEnt, inf, hitgroup, bullet.damage);
  78. //          else
  79. //              scale_damage(bullet.trace.m_pEnt, inf, bullet.trace.hitGroup, bullet.damage);
  80. //
  81. //          rt.damage = bullet.damage;
  82. //          rt.hitgroup = bullet.trace.hitGroup;
  83. //          rt.end = bullet.trace.end;
  84. //          rt.ent = bullet.trace.m_pEnt;
  85. //
  86. //          break;
  87. //      }
  88. //
  89. //      if (!this->handle_bullet_penetration(inf, bullet))
  90. //          break;
  91. //
  92. //      rt.did_penetrate_wall = true;
  93. //  }
  94. //
  95. //  rt.walls = bullet.walls;
  96. //  return rt;
  97. //}
  98.  // new
  99.  
  100.  
  101.  
  102. void c_autowall::scale_damage(CBaseEntity * ent, CSWeaponInfo * inf, int& hitgroup, float& damage) {
  103.     auto armor_value = ent->GetArmor();
  104.     auto is_armored = false;
  105.  
  106.     if (hitgroup == HITGROUP_HEAD)
  107.         is_armored = ent->HasHelmet();
  108.     else
  109.         is_armored = armor_value > 0;
  110.  
  111.     switch (hitgroup) {
  112.     case HITGROUP_HEAD:
  113.         damage *= 4.f;
  114.         break;
  115.     case HITGROUP_STOMACH:
  116.         damage *= 1.25f;
  117.         break;
  118.     case HITGROUP_LEFTLEG:
  119.     case HITGROUP_RIGHTLEG:
  120.         damage *= 0.75f;
  121.         break;
  122.     default:
  123.         break;
  124.     }
  125.  
  126.     if (is_armored) {
  127.         float bonus_value = 1.f, armor_bonus_ratio = 0.5f, armor_ratio = inf->armor_ratio / 2.f;
  128.  
  129.         if (ent->HasHeavyArmor()) {
  130.             armor_bonus_ratio = 0.33f;
  131.             armor_ratio *= 0.5f;
  132.             bonus_value = 0.33f;
  133.         }
  134.  
  135.         auto new_damage = damage * armor_ratio;
  136.  
  137.         if (ent->HasHeavyArmor())
  138.             new_damage *= 0.85f;
  139.  
  140.         if (((damage - (damage * armor_ratio)) * (bonus_value * armor_bonus_ratio)) > armor_value)
  141.             new_damage = damage - (armor_value / armor_bonus_ratio);
  142.  
  143.         damage = new_damage;
  144.  
  145.         float v47 = 1.f, ArmorBonusRatio = 0.5f, ArmorRatio = inf->armor_ratio * 0.5f;
  146.  
  147.         auto NewDamage = damage * ArmorRatio;
  148.  
  149.         if (((damage - (damage * ArmorRatio)) * (v47 * ArmorBonusRatio)) > armor_value)
  150.             NewDamage = damage - (damage / ArmorBonusRatio);
  151.  
  152.         damage = NewDamage;
  153.     }
  154. }
  155.  
  156. float GetHitgroupDamageMult(int iHitGroup)
  157. {
  158.     switch (iHitGroup)
  159.     {
  160.     case HITGROUP_HEAD:
  161.         return 4.f;
  162.     case HITGROUP_STOMACH:
  163.         return 1.25f;
  164.     case HITGROUP_LEFTLEG:
  165.     case HITGROUP_RIGHTLEG:
  166.         return 0.75f;
  167.     }
  168.  
  169.     return 1.0f;
  170. }
  171.  
  172. void ScaleDamage(int hitgroup, CBaseEntity* enemy, float weapon_armor_ratio, float& current_damage)
  173. {
  174.     current_damage *= GetHitgroupDamageMult(hitgroup);
  175.  
  176.     if (enemy->GetArmor > 0.0f && hitgroup < HITGROUP_LEFTLEG)
  177.     {
  178.         if (hitgroup == HITGROUP_HEAD && !enemy->HasHelmet())
  179.             return;
  180.  
  181.         float armorscaled = (weapon_armor_ratio * 0.5f) * current_damage;
  182.         if ((current_damage - armorscaled) * 0.5f > enemy->GetArmor())
  183.             armorscaled = current_damage - (enemy->GetArmor() * 2.0f);
  184.         current_damage = armorscaled;
  185.     }
  186. }
  187.  
  188. void TraceLine(Vector& vecAbsStart, Vector& vecAbsEnd, unsigned int mask, CBaseEntity* ignore, CTrace* ptr)
  189. {
  190.     CTraceFilter filter(ignore);
  191.     Interfaces::Trace->TraceRay(Ray_t(vecAbsStart, vecAbsEnd), mask, &filter, ptr);
  192. }
  193.  
  194.  
  195. bool TraceToExitalt(Vector& end, CTrace& tr, Vector start, Vector vEnd, CTrace* trace)
  196. {
  197.     typedef bool(__fastcall * TraceToExitFn)(Vector&, CTrace&, float, float, float, float, float, float, CTrace*);
  198.     static TraceToExitFn oTraceToExit = (TraceToExitFn)Utilities->Memory_PatternScan("client_panorama.dll", "55 8B EC 83 EC 30 F3 0F 10 75");
  199.  
  200.     if (!oTraceToExit)
  201.         return false;
  202.  
  203.     return oTraceToExit(end, tr, start.x, start.y, start.z, vEnd.x, vEnd.y, vEnd.z, trace);
  204. }
  205.  
  206.  
  207. bool c_autowall::handle_bullet_penetration(CSWeaponInfo* wpn_data, FireBulletData& data, bool extracheck = false, Vector point = Vector(0, 0, 0), CBaseEntity* pEnt = nullptr)
  208. {
  209.     surfacedata_t* enter_surface_data = g_pSurfaceData->GetSurfaceData(data.enter_trace.surface.surfaceProps);
  210.     int enter_material = enter_surface_data->game.material;
  211.     float enter_surf_penetration_mod = enter_surface_data->game.flPenetrationModifier;
  212.     data.trace_length += data.enter_trace.flFraction * data.trace_length_remaining;
  213.     data.current_damage *= pow(wpn_data->range_modifier, (data.trace_length * 0.002));
  214.     if ((data.trace_length > 3000.f) || (enter_surf_penetration_mod < 0.1f))
  215.         data.penetrate_count = 0;
  216.     if (data.penetrate_count <= 0)
  217.         return false;
  218.     Vector dummy;
  219.     CTrace trace_exit;
  220.     if (!TraceToExitalt(dummy, data.enter_trace, data.enter_trace.TraceRay, data.direction, &trace_exit))
  221.         return false;
  222.     surfacedata_t * exit_surface_data = g_pSurfaceData->GetSurfaceData(trace_exit.surface.surfaceProps);
  223.     int exit_material = exit_surface_data->game.material;
  224.     float exit_surf_penetration_mod = exit_surface_data->game.flPenetrationModifier;
  225.     float final_damage_modifier = 0.16f;
  226.     float combined_penetration_modifier = 0.0f;
  227.     if (((data.enter_trace.contents & contents_grate) != 0) || (enter_material == 89) || (enter_material == 71))
  228.     {
  229.         combined_penetration_modifier = 3.0f;
  230.         final_damage_modifier = 0.05f;
  231.     }
  232.     else
  233.         combined_penetration_modifier = (enter_surf_penetration_mod + exit_surf_penetration_mod) * 0.5f;
  234.     if (enter_material == exit_material)
  235.     {
  236.         if (exit_material == 87 || exit_material == 85)combined_penetration_modifier = 3.0f;
  237.         else if (exit_material == 76)combined_penetration_modifier = 2.0f;
  238.     }
  239.     float v34 = fmaxf(0.f, 1.0f / combined_penetration_modifier);
  240.     float v35 = (data.current_damage * final_damage_modifier) + v34 * 3.0f * fmaxf(0.0f, (3.0f / wpn_data->penetration) * 1.25f);
  241.     float thickness = VectorLength(trace_exit.TraceRay - data.enter_trace.TraceRay);
  242.     if (extracheck)
  243.         if (!c_autowall::get().VectortoVectorVisible(trace_exit.TraceRay, point, pEnt))
  244.             return false;
  245.     thickness *= thickness;
  246.     thickness *= v34;
  247.     thickness /= 24.0f;
  248.     float lost_damage = fmaxf(0.0f, v35 + thickness);
  249.     if (lost_damage > data.current_damage)
  250.         return false;
  251.     if (lost_damage >= 0.0f)
  252.         data.current_damage -= lost_damage;
  253.     if (data.current_damage < 1.0f)
  254.         return false;
  255.     data.src = trace_exit.TraceRay; // .end #1 possible missunderstand by kert (xd)
  256.     data.penetrate_count--;
  257.  
  258.     return true;
  259. }
  260.  
  261.  
  262. void c_autowall::clip_trace_to_player(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, ITraceFilter* filter, CTrace* tr) // sig is most likely out of date
  263. {
  264.     static DWORD dwAddress = Utilities->Memory_PatternScan("client_panorama.dll", "\x53\x8B\xDC\x83\xEC\x08\x83\xE4\xF0\x83\xC4\x04\x55\x8B\x6B\x04\x89\x6C\x24\x04\x8B\xEC\x81\xEC\x00\x00\x00\x00\x8B\x43\x10"); // (BYTE*)
  265.  
  266.     if (!dwAddress)
  267.         return;
  268.  
  269.     _asm
  270.     {
  271.         MOV     EAX, filter
  272.         LEA     ECX, tr
  273.         PUSH    ECX
  274.         PUSH    EAX
  275.         PUSH    mask
  276.         LEA     EDX, vecAbsEnd
  277.         LEA     ECX, vecAbsStart
  278.         CALL    dwAddress
  279.         ADD     ESP, 0xC
  280.     }
  281. }
  282.  
  283. bool SimulateFireBullet(CBaseEntity* local, CBaseWeapon* weapon, FireBulletData& data)
  284. {
  285.     data.penetrate_count = 4;
  286.     data.trace_length = 0.0f;
  287.     auto wpn_data = weapon->get_full_info;// GetCSWpnData
  288.     data.current_damage = (float)wpn_data->damage;
  289.     while ((data.penetrate_count > 0) && (data.current_damage >= 1.0f))
  290.     {
  291.         data.trace_length_remaining = wpn_data->range - data.trace_length;
  292.         Vector End_Point = data.src + data.direction * data.trace_length_remaining;
  293.         TraceLine(data.src, End_Point, 0x4600400B, local, &data.enter_trace);
  294.         c_autowall::clip_trace_to_player(data.src, End_Point * 40.f, 0x4600400B, &data.filter, &data.enter_trace);
  295.         if (data.enter_trace.flFraction == 1.0f)
  296.             break;
  297.         if ((data.enter_trace.hitGroup <= 7) && (data.enter_trace.hitGroup > 0) && (local->GetTeam() != data.enter_trace.m_pEnt->GetTeam()))
  298.         {
  299.             data.trace_length += data.enter_trace.flFraction * data.trace_length_remaining;
  300.             data.current_damage *= pow(wpn_data->range_modifier, data.trace_length * 0.002);
  301.             ScaleDamage(data.enter_trace.hitGroup, data.enter_trace.m_pEnt, wpn_data->armor_ratio, data.current_damage);
  302.             return true;
  303.         }
  304.         if (!handle_bullet_penetration(wpn_data, data))
  305.             break;
  306.     }
  307.     return false;
  308. }
  309.  
  310. float c_autowall::Damage(const Vector& point)
  311. {
  312.     auto data = FireBulletData(g::pLocalEntity->GetEyePosition(), g::pLocalEntity);
  313.  
  314.     Vector angles;
  315.     angles = Utilities->Math_CalcAngle(data.src, point);
  316.     Utilities->Math_AngleVectors(angles, &data.direction);
  317.     &Vector::NormalizeAngles(data.direction);
  318.  
  319.     if (SimulateFireBullet(g::pLocalEntity, g::pLocalEntity->GetActiveWeapon(), data))
  320.         return data.current_damage;
  321.  
  322.     return 0.f;
  323. }
  324.  
  325. bool c_autowall::VectortoVectorVisible(Vector src, Vector point, CBaseEntity* pEnt)
  326. {
  327.     //mask_solid
  328.     CTrace TraceInit;
  329.     TraceInit.m_pEnt = NULL;
  330.     CTraceFilter filter1(g::pLocalEntity);
  331.     g_pTrace->TraceRay(Ray_t(src, point), MASK_SOLID, &filter1, &TraceInit);
  332.  
  333.     if (TraceInit.flFraction == 1.0f)
  334.         return true;
  335.  
  336.     if (pEnt != nullptr && TraceInit.m_pEnt == pEnt)
  337.         return true;
  338.  
  339.     return false;
  340. }
  341.  
  342. bool c_autowall::CanHitFloatingPoint(const Vector& point, const Vector& source, CBaseEntity* pEnt) // ez
  343. {
  344.     if (!g::pLocalEntity)
  345.         return false;
  346.  
  347.     FireBulletData data = FireBulletData(source, g::pLocalEntity);
  348.  
  349.     Vector angles = Utilities->Math_CalcAngle(data.src, point);
  350.     g_Math.AngleVectors(angles, &data.direction);
  351.     VectorNormalize(data.direction);
  352.  
  353.     CBaseWeapon* pWeapon = (CBaseWeapon*)g::pLocalEntity->GetActiveWeapon();
  354.  
  355.     if (!pWeapon)
  356.         return false;
  357.  
  358.     data.penetrate_count = 1;
  359.     data.trace_length = 0.0f;
  360.  
  361.     CSWeaponInfo* weaponData = pWeapon->get_full_info();
  362.  
  363.     if (!weaponData)
  364.         return false;
  365.  
  366.     data.current_damage = (float)weaponData->damage;
  367.     data.trace_length_remaining = weaponData->range - data.trace_length;
  368.     Vector end = data.src + (data.direction * data.trace_length_remaining);
  369.     TraceLine(data.src, end, MASK_SHOT | CONTENTS_HITBOX, G::LocalPlayer, &data.enter_trace);
  370.  
  371.     if (VectortoVectorVisible(data.src, point, pEnt) || HandleBulletPenetration(weaponData, data, true, point))
  372.         return true;
  373.  
  374.     return false;
  375. }
  376.  
  377.  
  378. // end
  379.  
  380. //bool c_autowall::is_breakable(CBaseEntity * e) {
  381. //  using func = bool(__fastcall*)(CBaseEntity*);
  382. //  static auto fn = reinterpret_cast<func>(Utilities->Memory_PatternScan("client_panorama.dll", "55 8B EC 51 56 8B F1 85 F6 74 68 83 BE"));
  383. //
  384. //  if (!e || !e->GetIndex())
  385. //      return false;
  386. //
  387. //  auto take_damage{ (char*)((uintptr_t)e + *(size_t*)((uintptr_t)fn + 38)) };
  388. //  auto take_damage_backup{ *take_damage };
  389. //
  390. //  auto * cclass = Interfaces::Client->GetAllClasses();
  391. //
  392. //  if ((cclass->m_pNetworkName[1]) != 'F'
  393. //      || (cclass->m_pNetworkName[4]) != 'c'
  394. //      || (cclass->m_pNetworkName[5]) != 'B'
  395. //      || (cclass->m_pNetworkName[9]) != 'h')
  396. //      * take_damage = 2;
  397. //
  398. //  bool breakable = fn(e);
  399. //  *take_damage = take_damage_backup;
  400. //
  401. //  return breakable;
  402. //}
  403. //
  404. //float c_autowall::get_point_damage(Vector point, CBaseEntity * e) {
  405. //  return this->autowall(G::LocalPlayer->GetEyePosition(), point, G::LocalPlayer, e).damage;
  406. //}
  407.  
  408.  
  409.  
  410.  
  411. //float c_autowall::get_estimated_point_damage(Vector point) {
  412. //  if (!G::LocalPlayer)
  413. //      return -1.f;
  414. //
  415. //  fbdata bullet;
  416. //  auto filter = CTraceFilter();
  417. //  filter.pSkip1 = G::LocalPlayer;
  418. //
  419. //  bullet.filter = &filter;
  420. //  bullet.start = G::LocalPlayer->GetEyePosition();
  421. //  bullet.end = point;
  422. //  bullet.pos = G::LocalPlayer->GetEyePosition();
  423. //  Utilities->Math_AngleVectors(Utilities->Math_CalcAngle(bullet.start, point), bullet.dir);
  424. //  bullet.trace.start = bullet.start;
  425. //  bullet.trace.end = point;
  426. //
  427. //  auto wep = G::LocalPlayer->GetActiveWeapon();
  428. //  if (!wep)
  429. //      return -2.f;
  430. //
  431. //  bullet.walls = 1;
  432. //  bullet.thickness = 0.f;
  433. //
  434. //  auto inf = wep->get_full_info();
  435. //  if (!inf)
  436. //      return -3.f;
  437. //
  438. //  bullet.damage = inf->damage;
  439. //
  440. //  Ray_t ray;
  441. //  ray.Init(bullet.start, bullet.end);
  442. //
  443. //  Interfaces::Trace->TraceRay(ray, MASK_SHOT | CONTENTS_GRATE, &filter, &bullet.trace);
  444. //
  445. //  if (bullet.trace.fraction == 1.f)
  446. //      return -4.f;
  447. //
  448. //  if (this->handle_bullet_penetration(inf, bullet))
  449. //      return bullet.damage;
  450. //
  451. //  return -5.f;
  452. //}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top