Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. /*
  2. * Charlatano: Free and open-source (FOSS) cheat for CS:GO/CS:CO
  3. * Copyright (C) 2017 - Thomas G. P. Nappo, Jonathan Beaudoin
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. package com.charlatano.scripts.aim
  20.  
  21. import com.charlatano.game.*
  22. import com.charlatano.game.entity.*
  23. import com.charlatano.game.entity.EntityType.Companion.ccsPlayer
  24. import com.charlatano.settings.*
  25. import com.charlatano.utils.*
  26. import org.jire.arrowhead.keyPressed
  27. import java.util.concurrent.atomic.AtomicBoolean
  28. import java.util.concurrent.atomic.AtomicInteger
  29. import java.util.concurrent.atomic.AtomicLong
  30.  
  31. val target = AtomicLong(-1)
  32. val bone = AtomicInteger(HEAD_BONE)
  33. val perfect = AtomicBoolean() // only applicable for safe aim
  34.  
  35. internal fun reset() {
  36. target.set(-1L)
  37. bone.set(HEAD_BONE)
  38. perfect.set(false)
  39. }
  40.  
  41. internal fun findTarget(position: Angle, angle: Angle, allowPerfect: Boolean,
  42. lockFOV: Int = AIM_FOV, boneID: Int = HEAD_BONE): Player {
  43. var closestDelta = Double.MAX_VALUE
  44. var closestPlayer = -1L
  45.  
  46. var closestFOV = Double.MAX_VALUE
  47.  
  48. forEntities(ccsPlayer) {
  49. val entity = it.entity
  50. if (entity <= 0 || entity == me || !entity.canShoot()) return@forEntities
  51.  
  52. val ePos: Angle = entity.bones(boneID)
  53. val distance = position.distanceTo(ePos)
  54.  
  55. val dest = calculateAngle(me, ePos)
  56.  
  57. val pitchDiff = Math.abs(angle.x - dest.x)
  58. val yawDiff = Math.abs(angle.y - dest.y)
  59. val delta = Math.abs(Math.sin(Math.toRadians(yawDiff)) * distance)
  60. val fovDelta = Math.abs((Math.sin(Math.toRadians(pitchDiff)) + Math.sin(Math.toRadians(yawDiff))) * distance)
  61.  
  62. if (fovDelta <= lockFOV && delta < closestDelta) {
  63. closestDelta = delta
  64. closestPlayer = entity
  65. closestFOV = fovDelta
  66. }
  67. }
  68.  
  69. if (closestDelta == Double.MAX_VALUE || closestDelta < 0 || closestPlayer < 0) return -1
  70.  
  71. if (PERFECT_AIM && allowPerfect && closestFOV <= PERFECT_AIM_FOV && randInt(100 + 1) <= PERFECT_AIM_CHANCE)
  72. perfect.set(true)
  73.  
  74. return closestPlayer
  75. }
  76.  
  77. internal fun Entity.inMyTeam() =
  78. !TEAMMATES_ARE_ENEMIES && if (DANGER_ZONE) {
  79. me.survivalTeam().let { it > -1 && it == this.survivalTeam() }
  80. } else me.team() == team()
  81.  
  82. internal fun Entity.canShoot() = spotted()
  83. && !dormant()
  84. && !dead()
  85. && !inMyTeam()
  86. && !me.dead()
  87.  
  88. internal inline fun <R> aimScript(duration: Int, crossinline precheck: () -> Boolean,
  89. crossinline doAim: (destinationAngle: Angle,
  90. currentAngle: Angle, aimSpeed: Int) -> R) = every(duration) {
  91. if (!precheck()) return@every
  92. if (!me.weaponEntity().canFire()) {
  93. reset()
  94. return@every
  95. }
  96.  
  97. val aim = ACTIVATE_FROM_FIRE_KEY && keyPressed(FIRE_KEY)
  98. val forceAim = keyPressed(FORCE_AIM_KEY)
  99. val pressed = aim or forceAim
  100. var currentTarget = target.get()
  101.  
  102. if (!pressed) {
  103. reset()
  104. return@every
  105. }
  106.  
  107. /*if (!CLASSIC_OFFENSIVE) {
  108. val weapon = me.weapon()
  109. if (!weapon.pistol && !weapon.automatic && !weapon.shotgun && !weapon.sniper) {
  110. reset()
  111. return@every
  112. }
  113. }*/ // good meme
  114.  
  115. val currentAngle = clientState.angle()
  116.  
  117. val position = me.position()
  118. if (currentTarget < 0) {
  119. currentTarget = findTarget(position, currentAngle, aim)
  120. if (currentTarget < 0) {
  121. return@every
  122. }
  123. target.set(currentTarget)
  124. }
  125.  
  126. if (currentTarget == me || !currentTarget.canShoot()) {
  127. reset()
  128. } else {
  129. val boneID = bone.get()
  130. val bonePosition = currentTarget.bones(boneID)
  131.  
  132. val destinationAngle = calculateAngle(me, bonePosition)
  133. if (AIM_ASSIST_MODE) destinationAngle.finalize(currentAngle, AIM_ASSIST_STRICTNESS / 100.0)
  134.  
  135. val aimSpeed = AIM_SPEED_MIN + randInt(AIM_SPEED_MAX - AIM_SPEED_MIN)
  136. doAim(destinationAngle, currentAngle, aimSpeed)
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement