Advertisement
Guest User

うんちぶりぶり

a guest
Jan 11th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 12.42 KB | None | 0 0
  1. package com.hazuku.avox.module.modules.combat
  2.  
  3. import com.hazuku.avox.event.EventTarget
  4. import com.hazuku.avox.event.events.EventPostMotionUpdate
  5. import com.hazuku.avox.event.events.EventPreMotionUpdate
  6. import com.hazuku.avox.module.internal.Module
  7. import com.hazuku.avox.module.internal.ModuleCategory
  8. import com.hazuku.avox.util.*
  9. import net.minecraft.entity.Entity
  10. import net.minecraft.entity.EntityLivingBase
  11. import net.minecraft.entity.monster.EntityMob
  12. import net.minecraft.entity.passive.EntityAnimal
  13. import net.minecraft.entity.passive.EntityVillager
  14. import net.minecraft.entity.player.EntityPlayer
  15. import net.minecraft.item.ItemSword
  16. import net.minecraft.network.play.client.C02PacketUseEntity
  17. import net.minecraft.network.play.client.C03PacketPlayer
  18. import net.minecraft.network.play.client.C0APacketAnimation
  19. import net.minecraft.util.MathHelper
  20. import net.minecraft.util.Vec3
  21. import penner.easing.Cubic
  22. import java.util.concurrent.LinkedBlockingQueue
  23. import kotlin.math.roundToInt
  24. import kotlin.random.Random
  25.  
  26. class KillAura(name: String, description: String, category: ModuleCategory) : Module(name, description, category) {
  27.  
  28.     init {
  29.         addSettingOf("AntiBot", "WatchDoge", listOf("OFF", "WatchDoge"))
  30.         addSettingOf("Max Reach", 3.8, 1.0, 12.0, 0.1)
  31.         addSettingOf("Min Reach", 3.4, 1.0, 12.0, 0.1)
  32.         addSettingOf("Min CPS", 8.0, 1.0, 30.0)
  33.         addSettingOf("Max CPS", 12.0, 1.0, 30.0)
  34.         addSettingOf("Min Switch Delay", (20).toDouble(), 1.0, 200.0, 10.0)
  35.         addSettingOf("Max Switch Delay", (40).toDouble(), 1.0, 200.0, 10.0)
  36.         addSettingOf("Min Rotation Duration", (10).toDouble(), 1.0, 200.0, 10.0)
  37.         addSettingOf("Max Rotation Duration", (20).toDouble(), 1.0, 200.0, 10.0)
  38.         addSettingOf("Ticks Existed", 5.0, 0.0, 100.0, 2.0)
  39.         addSettingOf("Crack Size", 1.0, 0.0, 20.0, 1.0)
  40.         addSettingOf("Block Rate", 80.0, 0.0, 100.0, 1.0)
  41.         addSettingOf("FOV", 360.0, 0.0, 360.0, 10.0)
  42.         addSettingOf("Max Targets", 4.0, 1.0, 10.0)
  43.         addSettingOf("Block", true)
  44.         addSettingOf("NoSwing", false)
  45.         addSettingOf("Legit", true)
  46.         addSettingOf("Players", true)
  47.         addSettingOf("Mobs", false)
  48.         addSettingOf("Animals", false)
  49.         addSettingOf("Villagers", false)
  50.         addSettingOf("Invisible", false)
  51.         addSettingOf("Teams", true)
  52.         addSettingOf("Target Mode", "Switch", listOf("Single", "Switch"))
  53.         addSettingOf("Priority Mode", "Angle", listOf("Health", "Distance", "Angle", "Random"))
  54.     }
  55.  
  56.     var targets = LinkedBlockingQueue<EntityLivingBase>()
  57.     var target: EntityLivingBase? = null
  58.  
  59.     var reach = 4.0
  60.     var nextCPS = 1.0
  61.  
  62.     var currentSwitchDelay = 10
  63.     var nextSwitchDelay = 10
  64.     var rotationDuration = 0f
  65.  
  66.     var current: Long = 0
  67.     var last: Long = 0
  68.  
  69.     var yaw = 0f
  70.     var pitch = 0f
  71.  
  72.     var targetYaw = 0f
  73.     var targetPitch = 0f
  74.     var count = 0f
  75.  
  76.     var canAttack = false
  77.  
  78.     override fun onEnable() {
  79.         super.onEnable()
  80.         targets = LinkedBlockingQueue<EntityLivingBase>()
  81.         target = null
  82.         reach = 4.0
  83.         nextCPS = 1.0
  84.         currentSwitchDelay = 10
  85.         nextSwitchDelay = 10
  86.         rotationDuration = 0f
  87.         current = 0
  88.         last = 0
  89.         yaw = 0f
  90.         pitch = 0f
  91.         targetYaw = 0f
  92.         targetPitch = 0f
  93.         count = 0f
  94.         canAttack = false
  95.     }
  96.  
  97.     override fun onDisable() {
  98.         super.onDisable()
  99.         targets = LinkedBlockingQueue<EntityLivingBase>()
  100.         target = null
  101.         reach = 4.0
  102.         nextCPS = 1.0
  103.         currentSwitchDelay = 10
  104.         nextSwitchDelay = 10
  105.         rotationDuration = 0f
  106.         current = 0
  107.         last = 0
  108.         yaw = 0f
  109.         pitch = 0f
  110.         targetYaw = 0f
  111.         targetPitch = 0f
  112.         count = 0f
  113.         canAttack = false
  114.     }
  115.  
  116.     //えいむ
  117.     @EventTarget
  118.     fun onPre(event: EventPreMotionUpdate) {
  119.         reach = getRandom(getNumberSetting("Min Reach") ?: 0.0, getNumberSetting("Max Reach") ?: 0.0)
  120.         var entities = getAroundEntities(reach).filter { it.isEntityAlive && it.canAttack() && !it.isBot() }
  121.         if (entities.isEmpty()) return
  122.         entities = entities.applyPriority()
  123.         targets.addAll(entities.filter { !targets.contains(it) })
  124.         targets = LinkedBlockingQueue(targets.toList().filter { it.isEntityAlive && it.canAttack() && !it.isBot() }.applyPriority())
  125.         when (getOptionableSetting("Target Mode").toLowerCase()) {
  126.             "switch" -> {
  127.                 currentSwitchDelay++
  128.                 if (currentSwitchDelay > nextSwitchDelay) {
  129.                     nextSwitchDelay = getRandom(getNumberSetting("Min Switch Delay")
  130.                             ?: 0.0, getNumberSetting("Max Switch Delay") ?: 0.0).toInt()
  131.                     try {
  132.                         targets.add(targets.poll())
  133.                     } catch (e: Exception) {
  134.  
  135.                     }
  136.                     currentSwitchDelay = 0
  137.                 }
  138.             }
  139.         }
  140.  
  141.         if (targets.firstOrNull()?.uniqueID ?: "HOGE" != target?.uniqueID ?: "PIYO") {
  142.             count = 0f
  143.             rotationDuration = getRandom(
  144.                     getNumberSetting("Min Rotation Duration") ?: 0.0,
  145.                     getNumberSetting("Max Rotation Duration") ?: 0.0
  146.             ).toFloat()
  147.             target = targets.firstOrNull()
  148.         }
  149.  
  150.         val t = target ?: return
  151.  
  152.         val rotation = t.getRotations()
  153.         targetYaw = try {
  154.             rotation.first()
  155.         } catch (e: Exception) {
  156.             return
  157.         }
  158.         targetPitch = try {
  159.             rotation[1]
  160.         } catch (e: Exception) {
  161.             return
  162.         }
  163.  
  164.         if (count > rotationDuration)
  165.             count = 0f
  166.  
  167.  
  168.         yaw = (yaw % 360)
  169.         val a = when {
  170.             targetYaw - yaw <= 180 -> targetYaw - yaw
  171.             else -> {
  172.                 if (targetYaw >= 0) {
  173.                     (targetYaw - (-180)) + (180 - yaw)
  174.                 } else {
  175.                     -1 * ((yaw - (-180)) + (180 - targetYaw))
  176.                 }
  177.             }
  178.         }
  179.  
  180.         yaw = Cubic.easeOut(count, yaw, a, rotationDuration)
  181.         pitch = Cubic.easeOut(count, pitch, targetPitch - pitch, rotationDuration)
  182.         yaw %= 360
  183.         count++
  184.  
  185.         if (getBooleanSetting("Legit")) {
  186.             getPlayer().rotationYaw = yaw
  187.             getPlayer().rotationPitch = pitch
  188.         }
  189.  
  190.         canAttack = diff(yaw, targetYaw) < 10f && diff(pitch, targetPitch) < 10f
  191.  
  192.         sendPacket(C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, getPlayer().onGround))
  193.     }
  194.  
  195.     private fun diff(x: Float, y: Float) = when {
  196.         x > y -> x - y
  197.         y > x -> y - x
  198.         else -> 0f
  199.     }
  200.  
  201.     var ezAttack = false
  202.  
  203.     //あたっく
  204.     @EventTarget
  205.     fun onPost(event: EventPostMotionUpdate) {
  206.         ezAttack = canAttack && target != null && targets.isNotEmpty() && target?.isEntityAlive == true && target?.canAttack() == true && target?.isBot() == false
  207.         if (ezAttack)
  208.             target?.attack()
  209.     }
  210.  
  211.     private fun EntityLivingBase.attack() {
  212.         updateTime()
  213.         if (current - last > 1000 / nextCPS) {
  214.             resetTime()
  215.             nextCPS = getRandom(getNumberSetting("Min CPS") ?: 0.0, getNumberSetting("Max CPS") ?: 0.0)
  216.  
  217.             for (i in 0..(getNumberSetting("Crack Size") ?: 0.0).roundToInt()) getPlayer().onCriticalHit(this)
  218.  
  219.             sendPacket(C02PacketUseEntity(this, C02PacketUseEntity.Action.ATTACK))
  220.             if (getBooleanSetting("Block")
  221.                     && getPlayer().heldItem?.item != null
  222.                     && getPlayer().heldItem?.item is ItemSword
  223.                     && this.getDistanceToEntity(getPlayer()) < 8F
  224.                     && getNumberSetting("Block Rate") ?: 80.0 >= Math.random() * 100)
  225.                 getMinecraft().playerController.sendUseItem(getPlayer(), getWorld(), com.hazuku.avox.util.getInventory().getCurrentItem())
  226.             if (!getBooleanSetting("NoSwing"))
  227.                 getPlayer().swingItem()
  228.             else
  229.                 sendPacket(C0APacketAnimation())
  230.         }
  231.     }
  232.  
  233.     private fun getAroundEntities(range: Double) = getLoadedEntities()
  234.             .filter { it.inRange(range, getPlayer()) }
  235.             .filter { it is EntityLivingBase }
  236.             .map { it as EntityLivingBase }
  237.  
  238.     private fun List<EntityLivingBase>.applyPriority() = when (getOptionableSetting("Priority Mode").toLowerCase()) {
  239.         "health" -> sortedBy { it.health }
  240.  
  241.         "distance" -> sortedBy { getPlayer().getDistanceToEntity(it) }
  242.  
  243.         "angle" -> sortedBy { getAngleDifference(getPlayer().rotationYaw, getRotations(it.posX, it.posY, it.posZ)[0]) }
  244.  
  245.         "random" -> {
  246.             random()
  247.             this
  248.         }
  249.  
  250.         else -> this
  251.     }
  252.  
  253.     private fun Entity.getRotations(): FloatArray {
  254.         val diffX = posX - getPlayer().posX
  255.         val diffZ = posZ - getPlayer().posZ
  256.         var bestPos = Vec3(posX, posY, posZ)
  257.         val eyePos = Vec3(getPlayer().posX, getPlayer().posY + getPlayer().eyeHeight, getPlayer().posZ)
  258.         var i = entityBoundingBox.minY + 0.7
  259.         while (i < entityBoundingBox.maxY - 0.1) {
  260.             if (eyePos.distanceTo(Vec3(posX, i, posZ)) < eyePos.distanceTo(bestPos)) {
  261.                 bestPos = Vec3(posX, i, posZ)
  262.             }
  263.             i += 0.1
  264.         }
  265.         val diffY = bestPos.yCoord - (getPlayer().posY + getPlayer().eyeHeight)
  266.         val dist = MathHelper.sqrt_double(diffX * diffX + diffZ * diffZ).toDouble()
  267.         val yaw = (Math.atan2(diffZ, diffX) * 180.0 / 3.141592653589793).toFloat() - 90.0f
  268.         val pitch = (-(Math.atan2(diffY, dist) * 180.0 / 3.141592653589793)).toFloat()
  269.         return floatArrayOf(yaw, pitch)
  270.     }
  271.  
  272.     private fun updateTime() {
  273.         current = System.nanoTime() / 1000000L
  274.     }
  275.  
  276.     private fun resetTime() {
  277.         last = System.nanoTime() / 1000000L
  278.     }
  279.  
  280.     private fun getRandom(min: Double, max: Double) = Random(1919810).nextDouble(min, max)
  281.     private fun Entity.inRange(range: Double, target: Entity) = getDistanceToEntity(target) <= range
  282.     private fun Entity.isBot() = when (getOptionableSetting("AntiBot")) {
  283.         "WatchDoge" -> (getMinecraft().netHandler.getPlayerInfo(uniqueID)?.responseTime ?: 0) <= 5
  284.         else -> false
  285.     }
  286.  
  287.  
  288.     private fun EntityLivingBase.canAttack(): Boolean {
  289.         if (this is EntityPlayer || this is EntityAnimal || this is EntityMob || this is EntityVillager) {
  290.             if (this is EntityPlayer && !getBooleanSetting("Players"))
  291.                 return false
  292.             if (this is EntityAnimal && !getBooleanSetting("Animals"))
  293.                 return false
  294.             if (this is EntityMob && !getBooleanSetting("Mobs"))
  295.                 return false
  296.             if (this is EntityVillager && !getBooleanSetting("Villagers"))
  297.                 return false
  298.         }
  299.         if (this.isOnSameTeam(getPlayer()) && getBooleanSetting("Teams"))
  300.             return false
  301.         if (this.isInvisible && !getBooleanSetting("Invisible"))
  302.             return false
  303.         return if (!this.isInFOV(getNumberSetting("FOV") ?: 0.0))
  304.             false
  305.         else this !== getPlayer()
  306.                 && this.isEntityAlive && getPlayer().getDistanceToEntity(this) <= getMinecraft().playerController.blockReachDistance
  307.                 && this.ticksExisted > getNumberSetting("Ticks Existed") ?: 0.0
  308.     }
  309.  
  310.     private fun Entity.isInFOV(angle: Double): Boolean {
  311.         var an = angle
  312.         an *= .5
  313.         val angleDiff = getAngleDifference(getPlayer().rotationYaw, getRotations(posX, posY, posZ)[0])
  314.         return angleDiff > 0 && angleDiff < an || -an < angleDiff && angleDiff < 0
  315.     }
  316.  
  317.     private fun getRotations(x: Double, y: Double, z: Double): FloatArray {
  318.         val diffX = x + .5 - getPlayer().posX
  319.         val diffY = (y + .5) / 2.0 - (getPlayer().posY + getPlayer().eyeHeight)
  320.         val diffZ = z + .5 - getPlayer().posZ
  321.  
  322.         val dist = MathHelper.sqrt_double(diffX * diffX + diffZ * diffZ).toDouble()
  323.         val yaw = (Math.atan2(diffZ, diffX) * 180.0 / Math.PI).toFloat() - 90f
  324.         val pitch = (-(Math.atan2(diffY, dist) * 180.0 / Math.PI)).toFloat()
  325.  
  326.         return floatArrayOf(yaw, pitch)
  327.     }
  328.  
  329.     private fun getAngleDifference(dir: Float, yaw: Float): Float {
  330.         val f = Math.abs(yaw - dir) % 360f
  331.         return if (f > 180f) 360f - f else f
  332.     }
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement