diff --git a/src/openonyx/protocol/RotationConfig.java b/src/openonyx/protocol/RotationConfig.java new file mode 100644 index 0000000..582320d --- /dev/null +++ b/src/openonyx/protocol/RotationConfig.java @@ -0,0 +1,76 @@ +package openonyx.protocol; + +import java.util.List; +import net.minecraft.entity.Entity; +import openonyx.history.ModeSetting; +import openonyx.history.SettingGroup; +import openonyx.history.internal.EnumSetting; +import openonyx.history.internal.NumberSetting; +import openonyx.protocol.group_m.Angles; +import openonyx.protocol.internal.MovementFixMode; +import openonyx.protocol.internal.internal.internal.SmoothingMode; +import openonyx.protocol.internal.internal.internal.internal.AccelerationSmoothing; +import openonyx.protocol.internal.internal.internal.internal.LinearSmoothing; +import openonyx.protocol.internal.internal.internal.internal.SigmoidSmoothing; +import openonyx.utilities.ConditionalAction; + +public class RotationConfig extends SettingGroup { + private final ModeSetting modeSetting; + private final EnumSetting movementCorrection; + private final NumberSetting resetThreshold; + private final NumberSetting ticksUntilReset; + + public RotationConfig(MovementFixMode movementFixMode) { + RotationConfig rotationConfig1 = this; + rotationConfig1./* $VF: Unable to resugar constructor */("Rotations"); + LinearSmoothing linearSmoothing = new LinearSmoothing(); + SmoothingMode[] smoothingModes = new SmoothingMode[3]; + boolean bl = true; + smoothingModes[0] = linearSmoothing; + smoothingModes[1] = new AccelerationSmoothing(); + smoothingModes[2] = new SigmoidSmoothing(); + rotationConfig1.modeSetting = new ModeSetting<>("Angle smooth", linearSmoothing, smoothingModes); + rotationConfig1.movementCorrection = new EnumSetting<>("Movement correction", movementFixMode); + rotationConfig1.resetThreshold = new NumberSetting("Reset threshold", 2.0, 1.0, 180.0, 1.0) + .withSuffix("°") + .describe("How close the aim has to get to your real look while easing back before control snaps to you"); + rotationConfig1.ticksUntilReset = new NumberSetting("Ticks until reset", 5.0, 1.0, 30.0, 1.0) + .withSuffix(" ticks") + .describe("How long the last aim is held after the module stops updating it, before it eases back"); + } + + public RotationRequest L(Angles angles, Entity entity, boolean bl, ConditionalAction conditionalAction) { + RotationConfig rotationConfig1 = this; + List list = List.of(rotationConfig1.modeSetting.getValue()); + return new RotationRequest( + angles, + entity, + list, + (int)Math.round(rotationConfig1.ticksUntilReset.getValue()), + rotationConfig1.resetThreshold.getValue().floatValue(), + bl, + rotationConfig1.movementCorrection.getValue(), + conditionalAction + ); + } + + public RotationConfig() { + this(MovementFixMode.SILENT); + } + + public int L(Angles angles) { + return this.modeSetting.getValue().L(RotationHandler.INSTANCE.getAngles(), angles); + } + + public RotationRequest L(Angles angles) { + return this.L(angles, null, false, null); + } + + public MovementFixMode L() { + return this.movementCorrection.getValue(); + } + + public RotationRequest L(Angles angles, boolean bl) { + return this.L(angles, null, bl, null); + } +} diff --git a/src/openonyx/protocol/RotationHandler.java b/src/openonyx/protocol/RotationHandler.java new file mode 100644 index 0000000..291c891 --- /dev/null +++ b/src/openonyx/protocol/RotationHandler.java @@ -0,0 +1,279 @@ +package openonyx.protocol; + +import meteordevelopment.orbit.EventHandler; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.Entity; +import net.minecraft.network.Packet; +import net.minecraft.network.play.client.C03PacketPlayer; +import net.minecraft.network.play.server.S08PacketPlayerPosLook; +import openonyx.configuration.internal.PacketEvent; +import openonyx.configuration.internal.PreTickEvent; +import openonyx.configuration.internal.RotationTickEvent; +import openonyx.configuration.internal.StrafeEvent; +import openonyx.core.MinecraftAccess; +import openonyx.core.OnyxClient; +import openonyx.events.RotationManager; +import openonyx.protocol.group_d.RotationAngleMath; +import openonyx.protocol.group_m.Angles; +import openonyx.protocol.internal.MovementFixMode; +import openonyx.utilities.ConditionalAction; +import openonyx.utilities.ContainerTracker; +import openonyx.utilities.ItemPriority; +import openonyx.utilities.PlayerUtils; +import openonyx.utilities.RequestQueue; +import openonyx.utilities.RequestQueuePart; +import openonyx.utilities.RotationRequester; + +public class RotationHandler implements MinecraftAccess { + private Angles angles; + private final RequestQueue requestQueue = new RequestQueue<>(); + public static final RotationHandler INSTANCE = new RotationHandler(); + private Angles angles2; + private Angles angles3; + private Angles angles4; + private RotationRequest rotationRequest; + private Angles angles5; + + public void L(Angles angles) { + RotationHandler rotationHandler1; + if (anglesx == null) { + this.angles2 = null; + rotationHandler1 = this; + } else if (this.angles3 != null) { + this.angles2 = this.angles3; + rotationHandler1 = this; + } else { + this.angles2 = mc.thePlayer != null ? PlayerUtils.L((Entity)mc.thePlayer) : Angles.INSTANCE; + rotationHandler1 = this; + } + + rotationHandler1.angles3 = anglesx; + } + + public Angles getAngles() { + return this.angles; + } + + public boolean L(RotationRequest rotationRequest) { + if (!this.d()) { + return false; + } else { + return !rotationRequestx.L() ? true : !ContainerTracker.INSTANCE.L() && !(mc.currentScreen instanceof GuiContainer); + } + } + + public RotationRequest getRotationRequest() { + return this.rotationRequest; + } + + public RotationRequest d() { + RotationHandler rotationHandler1 = this; + RotationRequest rotationRequestx; + return (rotationRequestx = rotationHandler1.L()) != null ? rotationRequestx : rotationHandler1.rotationRequest; + } + + private boolean D() { + return mc.thePlayer != null && mc.theWorld != null; + } + + private RotationRequest L() { + return this.requestQueue.L(); + } + + public Angles getAngles5() { + return this.angles; + } + + public Angles getAngles3() { + return this.angles3; + } + + @EventHandler(priority = -10) + private void onStrafe(StrafeEvent strafeEvent) { + RotationHandler rotationHandler1 = this; + if (rotationHandler1.D()) { + if (!RotationManager.d()) { + RotationRequest rotationRequestx; + if ((rotationRequestx = rotationHandler1.d()) == null || rotationRequestx.getMovementFixMode() != MovementFixMode.OFF) { + if (rotationHandler1.angles3 != null) { + strafeEvent.L(PlayerUtils.L(strafeEvent.getVec32(), strafeEvent.L(), rotationHandler1.angles3.yaw2())); + } + } + } + } + } + + public void L(float f) { + RotationHandler rotationHandler1 = this; + if (rotationHandler1.D()) { + RotationRequest rotationRequestx; + if ((rotationRequestx = rotationHandler1.d()) != null) { + if (rotationHandler1.L(rotationRequestx) && rotationRequestx.getMovementFixMode() == MovementFixMode.CHANGE_LOOK) { + if (rotationHandler1.angles4 != null && rotationHandler1.angles3 != null) { + RotationAngleMath.L(mc.thePlayer, rotationHandler1.angles4.L(rotationHandler1.angles3, f)); + } + } + } + } + } + + public void L(double d, double e) { + RotationHandler rotationHandler1 = this; + if (rotationHandler1.D()) { + RotationRequest rotationRequestx; + if ((rotationRequestx = rotationHandler1.d()) != null) { + if (rotationHandler1.L(rotationRequestx) && rotationRequestx.getMovementFixMode() == MovementFixMode.CHANGE_LOOK) { + if (rotationHandler1.angles4 != null) { + rotationHandler1.angles4 = RotationAngleMath.L(rotationHandler1.angles4, d, e); + } + + if (rotationHandler1.angles3 != null) { + rotationHandler1.L(RotationAngleMath.L(rotationHandler1.angles3, d, e)); + } + } + } + } + } + + public void L() { + RotationHandler rotationHandler1 = this; + Angles anglesx = PlayerUtils.L((Entity)mc.thePlayer); + rotationHandler1.angles4 = anglesx; + RotationRequest rotationRequest1; + if ((rotationRequest1 = rotationHandler1.d()) != null) { + RotationHandler rotationHandler2; + label57: { + RotationRequest rotationRequestx = rotationHandler1.L(); + if (rotationHandler1.L(rotationRequest1)) { + Angles angles1 = rotationHandler1.angles3 != null ? rotationHandler1.angles3 : anglesx; + angles1 = rotationRequest1.L(angles1, rotationRequestx == null).L(); + float f = angles1.L(anglesx); + if (rotationRequestx == null + && ( + rotationRequest1.getMovementFixMode() == MovementFixMode.CHANGE_LOOK + || rotationRequest1.getRotationSmoothers().isEmpty() + || f <= rotationRequest1.L() + )) { + if (rotationHandler1.angles3 != null) { + mc.thePlayer.rotationYaw = RotationAngleMath.L(mc.thePlayer, rotationHandler1.angles3); + mc.thePlayer.renderArmYaw = mc.thePlayer.rotationYaw; + mc.thePlayer.prevRenderArmYaw = mc.thePlayer.rotationYaw; + } + + rotationHandler2 = rotationHandler1; + rotationHandler1.L((Angles)null); + rotationHandler1.rotationRequest = null; + break label57; + } + + rotationHandler1.L(angles1); + rotationHandler1.rotationRequest = rotationRequest1; + if (rotationRequestx != null && rotationRequestx.getConditionalAction() != null) { + rotationRequestx.getConditionalAction().L(); + } + } + + rotationHandler2 = rotationHandler1; + } + + rotationHandler2.requestQueue.L(); + } + } + + @EventHandler(priority = -1000) + private void onPacket(PacketEvent packetEvent) { + RotationHandler rotationHandler1 = this; + Packet packet = packetEvent.getPacket(); + Angles anglesx; + PacketEvent packetEvent1; + switch (packet) { + case C03PacketPlayer c03PacketPlayer1: + while (false) { + } + + C03PacketPlayer c03PacketPlayer; + if (!(c03PacketPlayer = (C03PacketPlayer)packet).getRotating()) { + return; + } + + anglesx = new Angles(c03PacketPlayer.getYaw(), c03PacketPlayer.getPitch(), true); + packetEvent1 = packetEvent; + break; + case S08PacketPlayerPosLook s08PacketPlayerPosLook: + anglesx = new Angles(s08PacketPlayerPosLook.getYaw(), s08PacketPlayerPosLook.getPitch(), true); + packetEvent1 = packetEvent; + break; + default: + return; + } + + if (!packetEvent1.isCancelled()) { + RotationManager.L((rotationHandler1.angles = anglesx).yaw2(), anglesx.pitch2()); + } + + rotationHandler1.angles5 = anglesx; + } + + private RotationHandler() { + this.angles = Angles.INSTANCE; + this.angles5 = Angles.INSTANCE; + } + + public void L( + Angles angles, + boolean bl, + RotationConfig rotationConfig, + ItemPriority itemPriority, + RotationRequester rotationRequester, + ConditionalAction conditionalAction + ) { + this.L(rotationConfig.L(anglesx, null, bl, conditionalAction), itemPriority, rotationRequester); + } + + private boolean d() { + return true; + } + + public Angles getAngles4() { + return this.angles4; + } + + public Angles getAngles2() { + return this.angles2; + } + + public boolean L() { + if (mc.thePlayer == null) { + return false; + } else { + return this.angles3 != null ? this.angles3.equals(this.angles2) : PlayerUtils.L((Entity)mc.thePlayer).equals(PlayerUtils.d((Entity)mc.thePlayer)); + } + } + + @EventHandler(priority = 1000) + private void onPreTick(PreTickEvent preTickEvent) { + if (this.D()) { + OnyxClient.EVENT_BUS.post(new RotationTickEvent()); + this.L(); + } + } + + public void L(RotationRequest rotationRequest, ItemPriority itemPriority, RotationRequester rotationRequester) { + if (this.d()) { + RequestQueue requestQueuex = this.requestQueue; + RequestQueuePart requestQueuePart = new RequestQueuePart; + int i; + ItemPriority itemPriority1; + if (rotationRequestx.getMovementFixMode() == MovementFixMode.CHANGE_LOOK) { + i = 1; + itemPriority1 = itemPriority; + } else { + i = rotationRequestx.L(); + itemPriority1 = itemPriority; + } + + requestQueuePart./* $VF: Unable to resugar constructor */(i, itemPriority1.L(), rotationRequester, rotationRequestx); + requestQueuex.L(requestQueuePart); + } + } +} diff --git a/src/openonyx/protocol/RotationRequest.java b/src/openonyx/protocol/RotationRequest.java new file mode 100644 index 0000000..97f14a3 --- /dev/null +++ b/src/openonyx/protocol/RotationRequest.java @@ -0,0 +1,102 @@ +package openonyx.protocol; + +import java.util.Iterator; +import java.util.List; +import net.minecraft.entity.Entity; +import openonyx.core.MinecraftAccess; +import openonyx.protocol.group_m.Angles; +import openonyx.protocol.internal.MovementFixMode; +import openonyx.protocol.internal.internal.RotationSmoother; +import openonyx.utilities.ConditionalAction; +import openonyx.utilities.PlayerUtils; + +public class RotationRequest implements MinecraftAccess { + private final Angles angles; + private final int l; + private final float I; + private final List rotationSmoothers; + private Entity entity; + private final boolean f; + private final MovementFixMode movementFixMode; + private final ConditionalAction conditionalAction; + + private Angles L(Angles angles, Angles angles1) { + if (this.rotationSmoothers.isEmpty()) { + return angles1; + } + + angles1 = angles1; + + Iterator iterator; + for (Iterator iterator1 = iterator = this.rotationSmoothers.iterator(); iterator1.hasNext(); iterator1 = iterator) { + angles1 = ((RotationSmoother)iterator.next()).L(this, anglesx, angles1); + } + + return angles1; + } + + public Angles getAngles() { + return this.angles; + } + + public void L(Entity entity) { + this.entity = entityx; + } + + public ConditionalAction getConditionalAction() { + return this.conditionalAction; + } + + public Entity getEntity() { + return this.entity; + } + + public int L() { + return this.l; + } + + public MovementFixMode getMovementFixMode() { + return this.movementFixMode; + } + + public RotationRequest( + Angles angles, + Entity entity, + List list, + int i, + float f, + boolean bl, + MovementFixMode movementFixMode, + ConditionalAction conditionalAction + ) { + this.angles = anglesx; + this.entity = entityx; + this.rotationSmoothers = list; + this.l = i; + this.I = fx; + this.f = bl; + this.movementFixMode = movementFixModex; + this.conditionalAction = conditionalActionx; + } + + public List getRotationSmoothers() { + return this.rotationSmoothers; + } + + public Angles L(Angles angles, boolean bl) { + if (bl) { + this.entity = null; + return this.L(anglesx, PlayerUtils.L((Entity)mc.thePlayer)); + } else { + return this.L(anglesx, this.angles); + } + } + + public boolean L() { + return this.f; + } + + public float L() { + return this.I; + } +}