Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(legacy): small cleanups #3982

Merged
merged 6 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object GiveCommand : Command("give", "item", "i", "get") {
* Execute commands with provided [args]
*/
override fun execute(args: Array<String>) {
val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return
val usedAlias = args[0].lowercase()

if (args.size <= 1) {
Expand All @@ -37,7 +37,7 @@ object GiveCommand : Command("give", "item", "i", "get") {
return
}

val emptySlot = thePlayer.inventory.firstEmptyStack
val emptySlot = player.inventory.firstEmptyStack

if (emptySlot != -1) {
sendPacket(C10PacketCreativeInventoryAction(emptySlot, itemStack))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object Aimbot : Module("Aimbot", Category.COMBAT, hideModule = false) {
fun onMotion(event: MotionEvent) {
if (event.eventState != EventState.POST) return

val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return
val theWorld = mc.theWorld ?: return

// Clicking delay
Expand All @@ -120,13 +120,13 @@ object Aimbot : Module("Aimbot", Category.COMBAT, hideModule = false) {

Backtrack.runWithNearestTrackedDistance(it) {
result = isSelected(it, true)
&& thePlayer.canEntityBeSeen(it)
&& thePlayer.getDistanceToEntityBox(it) <= range
&& player.canEntityBeSeen(it)
&& player.getDistanceToEntityBox(it) <= range
&& getRotationDifference(it) <= fov
}

result
}.minByOrNull { thePlayer.getDistanceToEntityBox(it) } ?: return
}.minByOrNull { player.getDistanceToEntityBox(it) } ?: return

// Should it always keep trying to lock on the enemy or just try to assist you?
if (!lock && isFaced(entity, range.toDouble())) return
Expand All @@ -147,11 +147,11 @@ object Aimbot : Module("Aimbot", Category.COMBAT, hideModule = false) {
// Some players do jitter on their mouses causing them to shake around. This is trying to simulate this behavior.
if (jitter) {
if (random.nextBoolean()) {
thePlayer.fixedSensitivityYaw += ((random.nextGaussian() - 0.5f) * yawJitterMultiplier).toFloat()
player.fixedSensitivityYaw += ((random.nextGaussian() - 0.5f) * yawJitterMultiplier).toFloat()
}

if (random.nextBoolean()) {
thePlayer.fixedSensitivityPitch += ((random.nextGaussian() - 0.5f) * pitchJitterMultiplier).toFloat()
player.fixedSensitivityPitch += ((random.nextGaussian() - 0.5f) * pitchJitterMultiplier).toFloat()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ object AutoArmor: Module("AutoArmor", Category.COMBAT, hideModule = false) {
return
}

val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return

var hasClickedHotbar = false

val stacks = thePlayer.openContainer.inventory
val stacks = player.openContainer.inventory

val bestArmorSet = getBestArmorSet(stacks) ?: return

Expand All @@ -106,7 +106,7 @@ object AutoArmor: Module("AutoArmor", Category.COMBAT, hideModule = false) {
val armorPos = getArmorPosition(stack) - 1

// Check if target armor slot isn't occupied
if (thePlayer.inventory.armorInventory[armorPos] != null)
if (player.inventory.armorInventory[armorPos] != null)
continue

hasClickedHotbar = true
Expand All @@ -122,8 +122,8 @@ object AutoArmor: Module("AutoArmor", Category.COMBAT, hideModule = false) {
)

// Instantly update inventory on client-side to prevent repetitive clicking because of ping
thePlayer.inventory.armorInventory[armorPos] = stack
thePlayer.inventory.mainInventory[hotbarIndex] = null
player.inventory.armorInventory[armorPos] = stack
player.inventory.mainInventory[hotbarIndex] = null
}

if (delayedSlotSwitch)
Expand All @@ -141,7 +141,7 @@ object AutoArmor: Module("AutoArmor", Category.COMBAT, hideModule = false) {

// Sync selected slot next tick
if (hasClickedHotbar)
TickScheduler += { serverSlot = thePlayer.inventory.currentItem }
TickScheduler += { serverSlot = player.inventory.currentItem }
}

suspend fun equipFromInventory() {
Expand All @@ -151,7 +151,7 @@ object AutoArmor: Module("AutoArmor", Category.COMBAT, hideModule = false) {
return
}

val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return

for (armorType in 0..3) {
if (!shouldOperate()) {
Expand All @@ -160,7 +160,7 @@ object AutoArmor: Module("AutoArmor", Category.COMBAT, hideModule = false) {
return
}

val stacks = thePlayer.openContainer.inventory
val stacks = player.openContainer.inventory

val armorSet = getBestArmorSet(stacks) ?: continue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ object AutoBow : Module("AutoBow", Category.COMBAT, subjective = true, hideModul

@EventTarget
fun onUpdate(event: UpdateEvent) {
val thePlayer = mc.thePlayer
val player = mc.thePlayer

if (thePlayer.isUsingItem && thePlayer.heldItem?.item is ItemBow &&
thePlayer.itemInUseDuration > 20 && (!waitForBowAimbot || !BowAimbot.handleEvents() || BowAimbot.hasTarget())) {
thePlayer.stopUsingItem()
if (player.isUsingItem && player.heldItem?.item is ItemBow &&
player.itemInUseDuration > 20 && (!waitForBowAimbot || !BowAimbot.handleEvents() || BowAimbot.hasTarget())) {
player.stopUsingItem()
sendPacket(C07PacketPlayerDigging(RELEASE_USE_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ object AutoClicker : Module("AutoClicker", Category.COMBAT, hideModule = false)

@EventTarget
fun onRender3D(event: Render3DEvent) {
mc.thePlayer?.let { thePlayer ->
mc.thePlayer?.let { player ->
val time = System.currentTimeMillis()
val doubleClick = if (simulateDoubleClicking) RandomUtils.nextInt(-1, 1) else 0

if (block && thePlayer.swingProgress > 0 && !mc.gameSettings.keyBindUseItem.isKeyDown) {
if (block && player.swingProgress > 0 && !mc.gameSettings.keyBindUseItem.isKeyDown) {
mc.gameSettings.keyBindUseItem.pressTime = 0
}

Expand Down Expand Up @@ -105,12 +105,12 @@ object AutoClicker : Module("AutoClicker", Category.COMBAT, hideModule = false)

@EventTarget
fun onTick(event: UpdateEvent) {
mc.thePlayer?.let { thePlayer ->
shouldJitter = !mc.objectMouseOver.typeOfHit.isBlock && (thePlayer.isSwingInProgress || mc.gameSettings.keyBindAttack.pressTime != 0)
mc.thePlayer?.let { player ->
shouldJitter = !mc.objectMouseOver.typeOfHit.isBlock && (player.isSwingInProgress || mc.gameSettings.keyBindAttack.pressTime != 0)

if (jitter && ((left && shouldAutoClick && shouldJitter) || (right && !mc.thePlayer.isUsingItem && mc.gameSettings.keyBindUseItem.isKeyDown))) {
if (nextBoolean()) thePlayer.fixedSensitivityYaw += nextFloat(-1F, 1F)
if (nextBoolean()) thePlayer.fixedSensitivityPitch += nextFloat(-1F, 1F)
if (nextBoolean()) player.fixedSensitivityYaw += nextFloat(-1F, 1F)
if (nextBoolean()) player.fixedSensitivityPitch += nextFloat(-1F, 1F)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ object AutoLeave : Module("AutoLeave", Category.COMBAT, subjective = true, hideM

@EventTarget
fun onUpdate(event: UpdateEvent) {
val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return

if (thePlayer.health <= health && !thePlayer.capabilities.isCreativeMode && !mc.isIntegratedServerRunning) {
if (player.health <= health && !player.capabilities.isCreativeMode && !mc.isIntegratedServerRunning) {
when (mode.lowercase()) {
"quit" -> mc.theWorld.sendQuittingDisconnectingPacket()
"invalidpacket" -> sendPacket(C04PacketPlayerPosition(Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, !mc.thePlayer.onGround))
"selfhurt" -> sendPacket(C02PacketUseEntity(mc.thePlayer, ATTACK))
"illegalchat" -> thePlayer.sendChatMessage(nextInt().toString() + "§§§" + nextInt())
"illegalchat" -> player.sendChatMessage(nextInt().toString() + "§§§" + nextInt())
}

state = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,34 +60,34 @@ object AutoPot : Module("AutoPot", Category.COMBAT, hideModule = false) {
if (!msTimer.hasTimePassed(delay) || mc.playerController.isInCreativeMode)
return

val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return

when (motionEvent.eventState) {
PRE -> {
// Hotbar Potion
val potionInHotbar = findPotion(36, 45)

if (potionInHotbar != null) {
if (thePlayer.onGround) {
if (player.onGround) {
when (mode.lowercase()) {
"jump" -> thePlayer.tryJump()
"port" -> thePlayer.moveEntity(0.0, 0.42, 0.0)
"jump" -> player.tryJump()
"port" -> player.moveEntity(0.0, 0.42, 0.0)
}
}

// Prevent throwing potions into the void
val fallingPlayer = FallingPlayer(thePlayer)
val fallingPlayer = FallingPlayer(player)

val collisionBlock = fallingPlayer.findCollision(20)?.pos

if (thePlayer.posY - (collisionBlock?.y ?: return) - 1 > groundDistance)
if (player.posY - (collisionBlock?.y ?: return) - 1 > groundDistance)
return

potion = potionInHotbar
sendPacket(C09PacketHeldItemChange(potion - 36))

if (thePlayer.rotationPitch <= 80F) {
setTargetRotation(Rotation(thePlayer.rotationYaw, nextFloat(80F, 90F)).fixedSensitivity(),
if (player.rotationPitch <= 80F) {
setTargetRotation(Rotation(player.rotationYaw, nextFloat(80F, 90F)).fixedSensitivity(),
immediate = true
)
}
Expand All @@ -103,7 +103,7 @@ object AutoPot : Module("AutoPot", Category.COMBAT, hideModule = false) {
if (simulateInventory)
serverOpenInventory = true

mc.playerController.windowClick(0, potionInInventory, 0, 1, thePlayer)
mc.playerController.windowClick(0, potionInInventory, 0, 1, player)

if (simulateInventory && mc.currentScreen !is GuiInventory)
serverOpenInventory = false
Expand All @@ -114,12 +114,12 @@ object AutoPot : Module("AutoPot", Category.COMBAT, hideModule = false) {

POST -> {
if (potion >= 0 && serverRotation.pitch >= 75F) {
val itemStack = thePlayer.inventoryContainer.getSlot(potion).stack
val itemStack = player.inventoryContainer.getSlot(potion).stack

if (itemStack != null) {
sendPackets(
C08PacketPlayerBlockPlacement(itemStack),
C09PacketHeldItemChange(thePlayer.inventory.currentItem)
C09PacketHeldItemChange(player.inventory.currentItem)
)

msTimer.reset()
Expand All @@ -132,41 +132,41 @@ object AutoPot : Module("AutoPot", Category.COMBAT, hideModule = false) {
}

private fun findPotion(startSlot: Int, endSlot: Int): Int? {
val thePlayer = mc.thePlayer
val player = mc.thePlayer

for (i in startSlot until endSlot) {
val stack = thePlayer.inventoryContainer.getSlot(i).stack
val stack = player.inventoryContainer.getSlot(i).stack

if (stack == null || stack.item !is ItemPotion || !stack.isSplashPotion())
continue

val itemPotion = stack.item as ItemPotion

for (potionEffect in itemPotion.getEffects(stack))
if (thePlayer.health <= health && healPotion && potionEffect.potionID == Potion.heal.id)
if (player.health <= health && healPotion && potionEffect.potionID == Potion.heal.id)
return i

if (!thePlayer.isPotionActive(Potion.regeneration))
if (!player.isPotionActive(Potion.regeneration))
for (potionEffect in itemPotion.getEffects(stack))
if (thePlayer.health <= health && regenerationPotion && potionEffect.potionID == Potion.regeneration.id)
if (player.health <= health && regenerationPotion && potionEffect.potionID == Potion.regeneration.id)
return i

if (!thePlayer.isPotionActive(Potion.fireResistance))
if (!player.isPotionActive(Potion.fireResistance))
for (potionEffect in itemPotion.getEffects(stack))
if (fireResistancePotion && potionEffect.potionID == Potion.fireResistance.id)
return i

if (!thePlayer.isPotionActive(Potion.moveSpeed))
if (!player.isPotionActive(Potion.moveSpeed))
for (potionEffect in itemPotion.getEffects(stack))
if (speedPotion && potionEffect.potionID == Potion.moveSpeed.id)
return i

if (!thePlayer.isPotionActive(Potion.jump))
if (!player.isPotionActive(Potion.jump))
for (potionEffect in itemPotion.getEffects(stack))
if (jumpPotion && potionEffect.potionID == Potion.jump.id)
return i

if (!thePlayer.isPotionActive(Potion.damageBoost))
if (!player.isPotionActive(Potion.damageBoost))
for (potionEffect in itemPotion.getEffects(stack))
if (strengthPotion && potionEffect.potionID == Potion.damageBoost.id)
return i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ object AutoSoup : Module("AutoSoup", Category.COMBAT, hideModule = false) {

@EventTarget
fun onUpdate(event: UpdateEvent) {
val thePlayer = mc.thePlayer ?: return
val player = mc.thePlayer ?: return

if (!timer.hasTimePassed(delay))
return

val soupInHotbar = InventoryUtils.findItem(36, 44, Items.mushroom_stew)

if (thePlayer.health <= health && soupInHotbar != null) {
if (player.health <= health && soupInHotbar != null) {
sendPacket(C09PacketHeldItemChange(soupInHotbar - 36))

thePlayer.sendUseItem(thePlayer.inventory.mainInventory[serverSlot])
player.sendUseItem(player.inventory.mainInventory[serverSlot])

// Schedule slot switch the next tick as we violate vanilla logic if we do it now.
TickScheduler += {
if (bowl == "Drop")
sendPacket(C07PacketPlayerDigging(DROP_ITEM, BlockPos.ORIGIN, EnumFacing.DOWN))

TickScheduler += {
serverSlot = thePlayer.inventory.currentItem
serverSlot = player.inventory.currentItem
}
}

Expand All @@ -88,7 +88,7 @@ object AutoSoup : Module("AutoSoup", Category.COMBAT, hideModule = false) {
var bowlMovable = false

for (i in 9..36) {
val itemStack = thePlayer.inventory.getStackInSlot(i)
val itemStack = player.inventory.getStackInSlot(i)

if (itemStack == null || (itemStack.item == Items.bowl && itemStack.stackSize < 64)) {
bowlMovable = true
Expand All @@ -100,7 +100,7 @@ object AutoSoup : Module("AutoSoup", Category.COMBAT, hideModule = false) {
if (simulateInventory)
serverOpenInventory = true

mc.playerController.windowClick(0, bowlInHotbar, 0, 1, thePlayer)
mc.playerController.windowClick(0, bowlInHotbar, 0, 1, player)
}
}

Expand All @@ -127,7 +127,7 @@ object AutoSoup : Module("AutoSoup", Category.COMBAT, hideModule = false) {
if (simulateInventory)
serverOpenInventory = true

mc.playerController.windowClick(0, soupInInventory, 0, 1, thePlayer)
mc.playerController.windowClick(0, soupInInventory, 0, 1, player)

if (simulateInventory && mc.currentScreen !is GuiInventory)
serverOpenInventory = false
Expand Down
Loading