From cde0d28c6d879a43c883a83aa8ee0917a510cd38 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 29 Sep 2020 19:21:17 -0400 Subject: [PATCH] Rewrote Freecam (#1375) Co-authored-by: Dominika --- detekt.yml | 5 + .../zeroeightsix/kami/gui/kami/KamiGUI.java | 87 +++--- .../kami/mixin/client/MixinEntity.java | 17 ++ .../mixin/client/MixinEntityPlayerSP.java | 10 + .../mixin/client/MixinEntityRenderer.java | 11 - .../kami/mixin/client/MixinFrustum.java | 2 +- .../client/MixinMovementInputFromOptions.java | 18 ++ .../kami/mixin/client/MixinRenderPlayer.java | 9 + .../module/modules/combat/AutoFeetPlace.kt | 3 - .../kami/module/modules/combat/AutoTrap.java | 4 - .../kami/module/modules/combat/Surround.kt | 41 ++- .../kami/module/modules/misc/AutoTunnel.kt | 3 +- .../kami/module/modules/movement/AutoWalk.kt | 5 +- .../kami/module/modules/movement/Jesus.kt | 11 +- .../kami/module/modules/player/Freecam.kt | 261 +++++++++++------- .../kami/module/modules/player/Scaffold.kt | 1 - .../me/zeroeightsix/kami/util/EntityUtils.kt | 2 +- .../zeroeightsix/kami/util/math/MathUtils.kt | 23 +- 18 files changed, 309 insertions(+), 204 deletions(-) create mode 100644 detekt.yml diff --git a/detekt.yml b/detekt.yml new file mode 100644 index 000000000..f457eec9e --- /dev/null +++ b/detekt.yml @@ -0,0 +1,5 @@ +complexity: + active: true + ComplexMethod: + active: true + threshold: 25 \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index f67fe9370..bacec15a1 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -437,49 +437,52 @@ public class KamiGUI extends GUI { frame.setCloseable(false); frame.setPinnable(true); Label coordsLabel = new Label(""); - coordsLabel.addTickListener(new TickListener() { - final Minecraft mc = Minecraft.getMinecraft(); - - @Override - public void onTick() { - boolean inHell = mc.player.dimension == -1; - - int posX = (int) mc.player.posX; - int posY = (int) mc.player.posY; - int posZ = (int) mc.player.posZ; - - float f = !inHell ? 0.125f : 8; - int hposX = (int) (mc.player.posX * f); - int hposZ = (int) (mc.player.posZ * f); - - /* The 7 and f in the string formatter is the color */ - String colouredSeparator = KamiMod.colour + "7 " + KamiMod.separator + KamiMod.colour + "r"; - String ow = String.format("%sf%,d%s7, %sf%,d%s7, %sf%,d %s7", - KamiMod.colour, - posX, - KamiMod.colour, - KamiMod.colour, - posY, - KamiMod.colour, - KamiMod.colour, - posZ, - KamiMod.colour - ); - String nether = String.format(" (%sf%,d%s7, %sf%,d%s7, %sf%,d%s7)", - KamiMod.colour, - hposX, - KamiMod.colour, - KamiMod.colour, - posY, - KamiMod.colour, - KamiMod.colour, - hposZ, - KamiMod.colour - ); - coordsLabel.setText(""); - coordsLabel.addLine(ow); - coordsLabel.addLine(MathUtils.getPlayerCardinal(mc).cardinalName + colouredSeparator + nether); + coordsLabel.addTickListener(() -> { + EntityPlayer player; + if (Wrapper.getMinecraft().getRenderViewEntity() instanceof EntityPlayer) { + player = (EntityPlayer) Wrapper.getMinecraft().getRenderViewEntity(); + } else { + player = Wrapper.getPlayer(); } + if (player == null) return; + + boolean inHell = player.dimension == -1; + + int posX = (int) player.posX; + int posY = (int) player.posY; + int posZ = (int) player.posZ; + + float f = !inHell ? 0.125f : 8; + int hposX = (int) (player.posX * f); + int hposZ = (int) (player.posZ * f); + + /* The 7 and f in the string formatter is the color */ + String colouredSeparator = KamiMod.colour + "7 " + KamiMod.separator + KamiMod.colour + "r"; + String ow = String.format("%sf%,d%s7, %sf%,d%s7, %sf%,d %s7", + KamiMod.colour, + posX, + KamiMod.colour, + KamiMod.colour, + posY, + KamiMod.colour, + KamiMod.colour, + posZ, + KamiMod.colour + ); + String nether = String.format(" (%sf%,d%s7, %sf%,d%s7, %sf%,d%s7)", + KamiMod.colour, + hposX, + KamiMod.colour, + KamiMod.colour, + posY, + KamiMod.colour, + KamiMod.colour, + hposZ, + KamiMod.colour + ); + coordsLabel.setText(""); + coordsLabel.addLine(ow); + coordsLabel.addLine(MathUtils.getPlayerCardinal(player).cardinalName + colouredSeparator + nether); }); frame.addChild(coordsLabel); coordsLabel.setFontRenderer(fontRenderer); diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntity.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntity.java index 2fa289ba4..e7d21d3f8 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntity.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntity.java @@ -3,15 +3,22 @@ package me.zeroeightsix.kami.mixin.client; import me.zeroeightsix.kami.KamiMod; import me.zeroeightsix.kami.event.events.EntityEvent; import me.zeroeightsix.kami.module.modules.movement.SafeWalk; +import me.zeroeightsix.kami.module.modules.player.Freecam; import me.zeroeightsix.kami.module.modules.player.Scaffold; +import me.zeroeightsix.kami.util.Wrapper; import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = Entity.class, priority = Integer.MAX_VALUE) public class MixinEntity { + @Shadow public int entityId; + @Redirect(method = "applyEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;addVelocity(DDD)V")) public void addVelocity(Entity entity, double x, double y, double z) { EntityEvent.EntityCollision entityCollisionEvent = new EntityEvent.EntityCollision(entity, x, y, z); @@ -29,4 +36,14 @@ public class MixinEntity { public boolean isSneaking(Entity entity) { return SafeWalk.INSTANCE.shouldSafewalk() || Scaffold.INSTANCE.isEnabled() || entity.isSneaking(); } + + // Makes the camera guy instead of original player turn around when we move mouse + @Inject(method = "turn", at = @At("HEAD"), cancellable = true) + public void turn(float yaw, float pitch, CallbackInfo ci) { + if (Wrapper.getPlayer() != null && this.entityId != Wrapper.getPlayer().entityId) return; + if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null) { + Freecam.INSTANCE.getCameraGuy().turn(yaw, pitch); + ci.cancel(); + } + } } diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java index 9dd2016e2..505ff132d 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityPlayerSP.java @@ -8,6 +8,7 @@ import me.zeroeightsix.kami.gui.mc.KamiGuiBeacon; import me.zeroeightsix.kami.module.modules.chat.PortalChat; import me.zeroeightsix.kami.module.modules.misc.BeaconSelector; import me.zeroeightsix.kami.module.modules.movement.Sprint; +import me.zeroeightsix.kami.module.modules.player.Freecam; import me.zeroeightsix.kami.util.math.Vec2f; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.AbstractClientPlayer; @@ -29,6 +30,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(value = EntityPlayerSP.class, priority = Integer.MAX_VALUE) public abstract class MixinEntityPlayerSP extends EntityPlayer { @@ -94,6 +96,14 @@ public abstract class MixinEntityPlayerSP extends EntityPlayer { super.setSprinting(sprinting); } + // We have to return true here so it would still update movement inputs from Baritone and send packets + @Inject(method = "isCurrentViewEntity", at = @At("RETURN"), cancellable = true) + protected void mixinIsCurrentViewEntity(CallbackInfoReturnable cir) { + if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null) { + cir.setReturnValue(mc.getRenderViewEntity() == Freecam.INSTANCE.getCameraGuy()); + } + } + @Inject(method = "onUpdateWalkingPlayer", at = @At("HEAD"), cancellable = true) private void onUpdateWalkingPlayerPre(CallbackInfo ci) { // Setup flags diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityRenderer.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityRenderer.java index 1c0f7687a..599481cf0 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityRenderer.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinEntityRenderer.java @@ -2,14 +2,12 @@ package me.zeroeightsix.kami.mixin.client; import com.google.common.base.Predicate; import me.zeroeightsix.kami.module.modules.movement.ElytraFlight; -import me.zeroeightsix.kami.module.modules.player.Freecam; import me.zeroeightsix.kami.module.modules.player.NoEntityTrace; import me.zeroeightsix.kami.module.modules.render.AntiFog; import me.zeroeightsix.kami.module.modules.render.AntiOverlay; import me.zeroeightsix.kami.module.modules.render.CameraClip; import me.zeroeightsix.kami.module.modules.render.NoHurtCam; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.EntityRenderer; @@ -71,15 +69,6 @@ public class MixinEntityRenderer { return worldClient.getEntitiesInAABBexcluding(entityIn, boundingBox, predicate); } - @Redirect(method = "renderWorldPass", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/entity/EntityPlayerSP;isSpectator()Z")) - public boolean noclipIsSpectator(EntityPlayerSP entityPlayerSP) { - // [WebringOfTheDamned] - // Freecam doesn't actually use spectator mode, but it can go through walls, and only spectator mode is "allowed to" go through walls as far as the renderer is concerned - if (Freecam.INSTANCE.isEnabled()) - return true; - return entityPlayerSP.isSpectator(); - } - @Redirect(method = "orientCamera", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getEyeHeight()F")) public float getEyeHeight(Entity entity) { if (ElytraFlight.INSTANCE.shouldSwing()) { diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinFrustum.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinFrustum.java index 48dc54032..5d7c749a1 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinFrustum.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinFrustum.java @@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Frustum.class) public abstract class MixinFrustum { - @Inject(method = "Lnet/minecraft/client/renderer/culling/Frustum;isBoundingBoxInFrustum(Lnet/minecraft/util/math/AxisAlignedBB;)Z", at = @At("HEAD"), cancellable = true) + @Inject(method = "isBoundingBoxInFrustum(Lnet/minecraft/util/math/AxisAlignedBB;)Z", at = @At("HEAD"), cancellable = true) public void isBoundingBoxEtc(AxisAlignedBB ignore, CallbackInfoReturnable info) { // [WebringOfTheDamned] // This is used because honestly the Mojang frustrum bounding box thing is a mess. diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMovementInputFromOptions.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMovementInputFromOptions.java index fab5d326d..f179f5bea 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMovementInputFromOptions.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinMovementInputFromOptions.java @@ -2,6 +2,7 @@ package me.zeroeightsix.kami.mixin.client; import me.zeroeightsix.kami.KamiMod; import me.zeroeightsix.kami.event.events.PlayerUpdateMoveEvent; +import me.zeroeightsix.kami.module.modules.player.Freecam; import net.minecraft.util.MovementInput; import net.minecraft.util.MovementInputFromOptions; import org.spongepowered.asm.mixin.Mixin; @@ -21,4 +22,21 @@ public abstract class MixinMovementInputFromOptions extends MovementInput { public void updatePlayerMoveStateReturn(CallbackInfo callback) { KamiMod.EVENT_BUS.post(new PlayerUpdateMoveEvent()); } + + // We have to cancel this so original player doesn't move around, also reset movement input when we enable Freecam + @Inject(method = "updatePlayerMoveState", at = @At("HEAD"), cancellable = true) + public void updatePlayerMoveStateHead(CallbackInfo ci) { + if (Freecam.INSTANCE.isEnabled() && Freecam.INSTANCE.getCameraGuy() != null) ci.cancel(); + if (Freecam.INSTANCE.getResetInput()) { + this.moveForward = 0f; + this.moveStrafe = 0f; + this.forwardKeyDown = false; + this.backKeyDown = false; + this.leftKeyDown = false; + this.rightKeyDown = false; + this.jump = false; + this.sneak = false; + Freecam.INSTANCE.setResetInput(false); + } + } } diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinRenderPlayer.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinRenderPlayer.java index 5ea3e1a5c..a1b5dadb8 100644 --- a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinRenderPlayer.java +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinRenderPlayer.java @@ -4,11 +4,15 @@ import me.zeroeightsix.kami.module.modules.movement.ElytraFlight; import me.zeroeightsix.kami.util.Wrapper; import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.entity.RenderManager; import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.entity.Entity; import net.minecraft.util.math.Vec3d; +import org.spongepowered.asm.lib.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; /** @@ -32,4 +36,9 @@ public class MixinRenderPlayer { } } + // Redirect it to the original player so the original player can be renderer correctly + @Redirect(method = "doRender", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/entity/RenderManager;renderViewEntity:Lnet/minecraft/entity/Entity;", opcode = Opcodes.GETFIELD)) + public Entity getRenderViewEntity(RenderManager renderManager) { + return Wrapper.getPlayer(); + } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoFeetPlace.kt b/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoFeetPlace.kt index 9117462d2..4ab8186e2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoFeetPlace.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoFeetPlace.kt @@ -2,7 +2,6 @@ package me.zeroeightsix.kami.module.modules.combat import com.mojang.realmsclient.gui.ChatFormatting import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.player.Freecam import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BlockUtils @@ -74,8 +73,6 @@ object AutoFeetPlace : Module() { } override fun onUpdate() { - if (Freecam.isEnabled) return - if (triggerable.value && totalTicksRunning >= timeoutTicks.value) { totalTicksRunning = 0 disable() diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoTrap.java b/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoTrap.java index c7b5aae34..3033c13ea 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoTrap.java +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/AutoTrap.java @@ -2,7 +2,6 @@ package me.zeroeightsix.kami.module.modules.combat; import com.mojang.realmsclient.gui.ChatFormatting; import me.zeroeightsix.kami.module.Module; -import me.zeroeightsix.kami.module.modules.player.Freecam; import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation; import me.zeroeightsix.kami.setting.Setting; import me.zeroeightsix.kami.setting.Settings; @@ -49,7 +48,6 @@ public class AutoTrap extends Module { private final Setting cage = register(Settings.e("Cage", Cage.TRAP)); private final Setting rotate = register(Settings.b("Rotate", false)); private final Setting noGlitchBlocks = register(Settings.b("NoGlitchBlocks", true)); - private final Setting activeInFreecam = register(Settings.b("ActiveInFreecam", true)); private final Setting selfTrap = register(Settings.b("SelfTrap", false)); private final Setting infoMessage = register(Settings.b("Debug", false)); @@ -125,8 +123,6 @@ public class AutoTrap extends Module { public void onUpdate() { if (mc.player.getHealth() <= 0) return; - if (!activeInFreecam.getValue() && Freecam.INSTANCE.isEnabled()) return; - if (firstRun) { if (findObiInHotbar() == -1) { if (infoMessage.getValue()) { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/combat/Surround.kt b/src/main/java/me/zeroeightsix/kami/module/modules/combat/Surround.kt index 29b91e564..013a3efd5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/combat/Surround.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/combat/Surround.kt @@ -1,7 +1,6 @@ package me.zeroeightsix.kami.module.modules.combat import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.player.Freecam import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings @@ -57,30 +56,28 @@ object Surround : Module() { CenterPlayer.centerPlayer(1.0f) if (debugMsgs.value == DebugMsgs.ALL) MessageSendHelper.sendChatMessage("$chatName Auto centering. Player position is " + mc.player.positionVector.toString()) } else { - if (Freecam.isDisabled) { - if (offsetStep == 0) { - basePos = BlockPos(mc.player.positionVector).down() - playerHotbarSlot = mc.player.inventory.currentItem - if (debugMsgs.value == DebugMsgs.ALL) { - MessageSendHelper.sendChatMessage("$chatName Starting Loop, current Player Slot: $playerHotbarSlot") - } - if (!spoofHotbar.value) { - lastHotbarSlot = mc.player.inventory.currentItem - } + if (offsetStep == 0) { + basePos = BlockPos(mc.player.positionVector).down() + playerHotbarSlot = mc.player.inventory.currentItem + if (debugMsgs.value == DebugMsgs.ALL) { + MessageSendHelper.sendChatMessage("$chatName Starting Loop, current Player Slot: $playerHotbarSlot") } - for (i in 0 until floor(blockPerTick.value).toInt()) { - if (debugMsgs.value == DebugMsgs.ALL) { - MessageSendHelper.sendChatMessage("$chatName Loop iteration: $offsetStep") - } - if (offsetStep >= surroundTargets.size) { - endLoop() - return - } - val offset = surroundTargets[offsetStep] - placeBlock(BlockPos(basePos!!.add(offset.x, offset.y, offset.z))) - ++offsetStep + if (!spoofHotbar.value) { + lastHotbarSlot = mc.player.inventory.currentItem } } + for (i in 0 until floor(blockPerTick.value).toInt()) { + if (debugMsgs.value == DebugMsgs.ALL) { + MessageSendHelper.sendChatMessage("$chatName Loop iteration: $offsetStep") + } + if (offsetStep >= surroundTargets.size) { + endLoop() + return + } + val offset = surroundTargets[offsetStep] + placeBlock(BlockPos(basePos!!.add(offset.x, offset.y, offset.z))) + ++offsetStep + } } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTunnel.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTunnel.kt index 1b30a41da..40663d334 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTunnel.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTunnel.kt @@ -12,6 +12,7 @@ import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.math.MathUtils.CardinalMain import me.zeroeightsix.kami.util.math.MathUtils.getPlayerMainCardinal import me.zeroeightsix.kami.util.text.MessageSendHelper +import net.minecraft.entity.player.EntityPlayer @Module.Info( name = "AutoTunnel", @@ -33,7 +34,7 @@ object AutoTunnel : Module() { } if (AutoWalk.isEnabled) AutoWalk.disable() - startingDirection = getPlayerMainCardinal(mc) + startingDirection = getPlayerMainCardinal(mc.getRenderViewEntity() as? EntityPlayer? ?: mc.player) sendTunnel() } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/movement/AutoWalk.kt b/src/main/java/me/zeroeightsix/kami/module/modules/movement/AutoWalk.kt index 8df1ac4e9..67461a6ad 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/movement/AutoWalk.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/movement/AutoWalk.kt @@ -13,6 +13,7 @@ import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.math.MathUtils import me.zeroeightsix.kami.util.math.MathUtils.Cardinal import me.zeroeightsix.kami.util.text.MessageSendHelper.sendErrorMessage +import net.minecraft.entity.player.EntityPlayer import net.minecraftforge.client.event.InputUpdateEvent @Module.Info( @@ -73,7 +74,7 @@ object AutoWalk : Module() { return } - when (MathUtils.getPlayerCardinal(mc)) { + when (MathUtils.getPlayerCardinal(mc.getRenderViewEntity() as? EntityPlayer? ?: mc.player)) { Cardinal.POS_Z -> BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(mc.player.posX.toInt(), mc.player.posZ.toInt() + border)) Cardinal.NEG_X_POS_Z -> BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(mc.player.posX.toInt() - border, mc.player.posZ.toInt() + border)) Cardinal.NEG_X -> BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(mc.player.posX.toInt() - border, mc.player.posZ.toInt())) @@ -88,7 +89,7 @@ object AutoWalk : Module() { } } - direction = MathUtils.getPlayerCardinal(mc).cardinalName + direction = MathUtils.getPlayerCardinal(mc.getRenderViewEntity() as? EntityPlayer? ?: mc.player).cardinalName } override fun getHudInfo(): String { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/movement/Jesus.kt b/src/main/java/me/zeroeightsix/kami/module/modules/movement/Jesus.kt index 9b8378cf3..c0950b2f9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/movement/Jesus.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/movement/Jesus.kt @@ -8,7 +8,6 @@ import me.zeroeightsix.kami.event.KamiEvent import me.zeroeightsix.kami.event.events.AddCollisionBoxToListEvent import me.zeroeightsix.kami.event.events.PacketEvent import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.player.Freecam import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.EntityUtils import net.minecraft.block.BlockLiquid @@ -34,12 +33,10 @@ object Jesus : Module() { } override fun onUpdate() { - if (!Freecam.isEnabled) { - if (EntityUtils.isInWater(mc.player) && !mc.player.isSneaking) { - mc.player.motionY = 0.1 - if (mc.player.getRidingEntity() != null && mc.player.getRidingEntity() !is EntityBoat) { - mc.player.getRidingEntity()!!.motionY = 0.3 - } + if (EntityUtils.isInWater(mc.player) && !mc.player.isSneaking) { + mc.player.motionY = 0.1 + if (mc.player.getRidingEntity() != null && mc.player.getRidingEntity() !is EntityBoat) { + mc.player.getRidingEntity()!!.motionY = 0.3 } } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt index 011b4a83e..0ec52b6d5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt @@ -3,122 +3,187 @@ package me.zeroeightsix.kami.module.modules.player import me.zero.alpine.listener.EventHandler import me.zero.alpine.listener.EventHook import me.zero.alpine.listener.Listener +import me.zeroeightsix.kami.event.events.ConnectionEvent import me.zeroeightsix.kami.event.events.PacketEvent -import me.zeroeightsix.kami.event.events.PlayerMoveEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.util.BaritoneUtils +import me.zeroeightsix.kami.util.math.RotationUtils import net.minecraft.client.entity.EntityOtherPlayerMP -import net.minecraft.entity.Entity +import net.minecraft.client.entity.EntityPlayerSP +import net.minecraft.entity.MoverType import net.minecraft.entity.player.EntityPlayer -import net.minecraft.network.play.client.CPacketInput -import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketUseEntity -import net.minecraft.network.play.client.CPacketVehicleMove -import net.minecraftforge.client.event.PlayerSPPushOutOfBlocksEvent +import net.minecraft.util.math.Vec3d +import net.minecraftforge.fml.common.gameevent.InputEvent +import org.lwjgl.input.Keyboard +import kotlin.math.abs +import kotlin.math.cos +import kotlin.math.min +import kotlin.math.sin -/** - * Created by 086 on 22/12/2017. - */ @Module.Info( name = "Freecam", category = Module.Category.PLAYER, description = "Leave your body and transcend into the realm of the gods" ) object Freecam : Module() { - private val speed = register(Settings.i("Speed", 5)) // /100 in practice - private val packetCancel = register(Settings.b("PacketCancel", false)) + private val horizontalSpeed = register(Settings.floatBuilder("HorizontalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f)) + private val verticalSpeed = register(Settings.floatBuilder("VerticalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f)) + private val arrowKeyMove = register(Settings.b("ArrowKeyMove", true)) - private var posX = 0.0 - private var posY = 0.0 - private var posZ = 0.0 - private var pitch = 0f - private var yaw = 0f - private var clonedPlayer: EntityOtherPlayerMP? = null - private var isRidingEntity = false - private var ridingEntity: Entity? = null - - override fun onEnable() { - if (mc.player != null) { - isRidingEntity = mc.player.getRidingEntity() != null - if (mc.player.getRidingEntity() == null) { - posX = mc.player.posX - posY = mc.player.posY - posZ = mc.player.posZ - } else { - ridingEntity = mc.player.getRidingEntity() - mc.player.dismountRidingEntity() - } - - pitch = mc.player.rotationPitch - yaw = mc.player.rotationYaw - clonedPlayer = EntityOtherPlayerMP(mc.world, mc.getSession().profile) - clonedPlayer!!.copyLocationAndAnglesFrom(mc.player) - clonedPlayer!!.rotationYawHead = mc.player.rotationYawHead - - mc.world.addEntityToWorld(-100, clonedPlayer) - mc.player.capabilities.isFlying = true - mc.player.capabilities.flySpeed = speed.value / 100f - mc.player.noClip = true - - // WebringOfTheDamned - // This is needed for some reason, as is the converse in onDisable. - mc.renderChunksMany = false - mc.renderGlobal.loadRenderers() - } - } - - override fun onDisable() { - val localPlayer: EntityPlayer? = mc.player - if (localPlayer != null) { - mc.player.setPositionAndRotation(posX, posY, posZ, yaw, pitch) - mc.world.removeEntityFromWorld(-100) - - clonedPlayer = null - posZ = 0.0 - posY = posZ - posX = posY - yaw = 0f - pitch = yaw - - mc.player.capabilities.isFlying = false //getModManager().getMod("ElytraFlight").isEnabled(); - mc.player.capabilities.flySpeed = 0.05f - mc.player.noClip = false - mc.player.motionZ = 0.0 - mc.player.motionY = mc.player.motionZ - mc.player.motionX = mc.player.motionY - - if (isRidingEntity) { - mc.player.startRiding(ridingEntity, true) - } - - // WebringOfTheDamned - // This is needed for some reason, as is the converse in onEnable. - mc.renderChunksMany = true - mc.renderGlobal.loadRenderers() - } - } - - override fun onUpdate() { - mc.player.capabilities.isFlying = true - mc.player.capabilities.flySpeed = speed.value / 100f - mc.player.noClip = true - mc.player.onGround = false - mc.player.fallDistance = 0f - } + private var prevThirdPersonViewSetting = -1 + var cameraGuy: EntityPlayer? = null + private set + var resetInput = false @EventHandler - private val moveListener = Listener(EventHook { event: PlayerMoveEvent? -> mc.player.noClip = true }) - - @EventHandler - private val pushListener = Listener(EventHook { event: PlayerSPPushOutOfBlocksEvent -> event.isCanceled = true }) + private val disconnectListener = Listener(EventHook { event: ConnectionEvent.Disconnect -> + prevThirdPersonViewSetting = -1 + cameraGuy = null + mc.renderChunksMany = true + }) @EventHandler private val sendListener = Listener(EventHook { event: PacketEvent.Send -> - if (event.packet is CPacketPlayer || event.packet is CPacketInput) { - event.cancel() - } - if (packetCancel.value && (event.packet is CPacketUseEntity || event.packet is CPacketVehicleMove)) { - event.cancel() - } + if (mc.world == null || event.packet !is CPacketUseEntity) return@EventHook + // Don't interact with self + if (event.packet.getEntityFromWorld(mc.world) == mc.player) event.cancel() }) + + @EventHandler + private val keyboardListener = Listener(EventHook { event: InputEvent.KeyInputEvent -> + if (mc.world == null || mc.player == null) return@EventHook + // Force it to stay in first person lol + if (mc.gameSettings.keyBindTogglePerspective.isKeyDown) mc.gameSettings.thirdPersonView = 2 + }) + + override fun onDisable() { + if (mc.player == null) return + mc.world.removeEntityFromWorld(-6969420) + mc.setRenderViewEntity(mc.player) + cameraGuy = null + mc.player.rotationYawHead + if (prevThirdPersonViewSetting != -1) mc.gameSettings.thirdPersonView = prevThirdPersonViewSetting + } + + override fun onUpdate() { + if (cameraGuy == null && mc.player.ticksExisted > 20) { + // Create a cloned player + cameraGuy = FakeCamera(mc.player).also { + // Add it to the world + mc.world.addEntityToWorld(-6969420, it) + + // Set the render view entity to our camera guy + mc.setRenderViewEntity(it) + + // Reset player movement input + resetInput = true + + // Stores prev third person view setting + prevThirdPersonViewSetting = mc.gameSettings.thirdPersonView + mc.gameSettings.thirdPersonView = 0 + } + } + + if (arrowKeyMove.value && !BaritoneUtils.isPathing) { + cameraGuy?.let { + val forward = Keyboard.isKeyDown(Keyboard.KEY_UP) to Keyboard.isKeyDown(Keyboard.KEY_DOWN) + val strafe = Keyboard.isKeyDown(Keyboard.KEY_LEFT) to Keyboard.isKeyDown(Keyboard.KEY_RIGHT) + val movementInput = calcMovementInput(forward, strafe, false to false) + + if (movementInput.first != 0f || movementInput.second != 0f) mc.player.rotationYaw = it.rotationYaw + + mc.player.movementInput.moveForward = movementInput.first + mc.player.movementInput.moveStrafe = -movementInput.second + + mc.player.movementInput.forwardKeyDown = forward.first + mc.player.movementInput.backKeyDown = forward.second + mc.player.movementInput.leftKeyDown = strafe.first + mc.player.movementInput.rightKeyDown = strafe.second + + mc.player.movementInput.jump = Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) + } + } + } + + private class FakeCamera(val player: EntityPlayerSP) : EntityOtherPlayerMP(mc.world, mc.session.profile) { + init { + copyLocationAndAnglesFrom(mc.player) + capabilities.allowFlying = true + capabilities.isFlying = true + } + + override fun onLivingUpdate() { + // Update inventory + inventory.copyInventory(player.inventory) + + // Update yaw head + updateEntityActionState() + + // We have to update movement input from key binds because mc.player.movementInput is used by Baritone + val forward = mc.gameSettings.keyBindForward.isKeyDown to mc.gameSettings.keyBindBack.isKeyDown + val strafe = mc.gameSettings.keyBindLeft.isKeyDown to mc.gameSettings.keyBindRight.isKeyDown + val vertical = mc.gameSettings.keyBindJump.isKeyDown to mc.gameSettings.keyBindSneak.isKeyDown + val movementInput = calcMovementInput(forward, strafe, vertical) + + moveForward = movementInput.first + moveStrafing = movementInput.second + moveVertical = movementInput.third + + // Update sprinting + isSprinting = mc.gameSettings.keyBindSprint.isKeyDown + + val yawRad = Math.toRadians(rotationYaw - RotationUtils.getRotationFromVec(Vec3d(moveStrafing.toDouble(), 0.0, moveForward.toDouble())).x) + val speed = (horizontalSpeed.value / 20f) * min(abs(moveForward) + abs(moveStrafing), 1f) + + motionX = -sin(yawRad) * speed + motionY = moveVertical.toDouble() * (verticalSpeed.value / 20f) + motionZ = cos(yawRad) * speed + + if (isSprinting) { + motionX *= 1.5 + motionY *= 1.5 + motionZ *= 1.5 + } + + noClip = true + + move(MoverType.SELF, motionX, motionY, motionZ) + } + + override fun getEyeHeight() = 1.65f + } + + /** + * @param forward + * @param strafe + * @param vertical + * + * @return + */ + private fun calcMovementInput(forward: Pair, strafe: Pair, vertical: Pair): Triple { + // Forward movement input + val moveForward = if (forward.first xor forward.second) { + if (forward.first) 1f else -1f + } else { + 0f + } + + // Strafe movement input + val moveStrafing = if (strafe.first xor strafe.second) { + if (strafe.second) 1f else -1f + } else { + 0f + } + + // Vertical movement input + val moveVertical = if (vertical.first xor vertical.second) { + if (vertical.first) 1f else -1f + } else { + 0f + } + + return Triple(moveForward, moveStrafing, moveVertical) + } } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/Scaffold.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/Scaffold.kt index 75cfe90f9..d094770de 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/Scaffold.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/Scaffold.kt @@ -55,7 +55,6 @@ object Scaffold : Module() { }) override fun onUpdate() { - if (Freecam.isEnabled) return shouldSlow = false val towering = mc.gameSettings.keyBindJump.isKeyDown && tower.value diff --git a/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt b/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt index 75c0744fc..a1b5ad790 100644 --- a/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/EntityUtils.kt @@ -234,7 +234,7 @@ object EntityUtils { for (entity in mc.world.loadedEntityList) { /* Entity type check */ if (!isLiving(entity)) continue - if (entity == mc.player) continue + if (entity.name == mc.player.name) continue if (entity is EntityPlayer) { if (!player[0]) continue if (!playerTypeCheck(entity, player[1], player[2])) continue diff --git a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt index 2c0ed2e05..c9ad0ba51 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt @@ -2,6 +2,7 @@ package me.zeroeightsix.kami.util.math import me.zeroeightsix.kami.util.math.RotationUtils.normalizeAngle import net.minecraft.client.Minecraft +import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.math.BlockPos import kotlin.math.* @@ -48,22 +49,22 @@ object MathUtils { } @JvmStatic - fun getPlayerCardinal(mc: Minecraft): Cardinal { - return if (isBetween(-22.5, 22.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + fun getPlayerCardinal(player: EntityPlayer): Cardinal { + return if (isBetween(-22.5, 22.5, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.POS_Z - } else if (isBetween(22.6, 67.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + } else if (isBetween(22.6, 67.5, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.NEG_X_POS_Z - } else if (isBetween(67.6, 112.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + } else if (isBetween(67.6, 112.5, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.NEG_X - } else if (isBetween(112.6, 157.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + } else if (isBetween(112.6, 157.5, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.NEG_X_NEG_Z - } else if (normalizeAngle(mc.player.rotationYaw.toDouble()) >= 157.6 || normalizeAngle(mc.player.rotationYaw.toDouble()) <= -157.5) { + } else if (normalizeAngle(player.rotationYaw.toDouble()) >= 157.6 || normalizeAngle(player.rotationYaw.toDouble()) <= -157.5) { Cardinal.NEG_Z - } else if (isBetween(-157.6, -112.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + } else if (isBetween(-157.6, -112.5, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.POS_X_NEG_Z - } else if (isBetween(-112.5, -67.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + } else if (isBetween(-112.5, -67.5, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.POS_X - } else if (isBetween(-67.6, -22.6, normalizeAngle(mc.player.rotationYaw.toDouble()))) { + } else if (isBetween(-67.6, -22.6, normalizeAngle(player.rotationYaw.toDouble()))) { Cardinal.POS_X_POS_Z } else { Cardinal.ERROR @@ -71,8 +72,8 @@ object MathUtils { } @JvmStatic - fun getPlayerMainCardinal(mc: Minecraft): CardinalMain { - return when (Character.toUpperCase(mc.player.horizontalFacing.toString()[0])) { + fun getPlayerMainCardinal(player: EntityPlayer): CardinalMain { + return when (Character.toUpperCase(player.horizontalFacing.toString()[0])) { 'N' -> CardinalMain.NEG_Z 'S' -> CardinalMain.POS_Z 'E' -> CardinalMain.POS_X