Skip to content
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
20 changes: 20 additions & 0 deletions common/src/main/java/com/lambda/mixin/ClientConnectionMixin.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.lambda.mixin;

import com.lambda.event.EventFlow;
import com.lambda.event.events.ConnectionEvent;
import com.lambda.event.events.PacketEvent;
import io.netty.channel.ChannelHandlerContext;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.NetworkSide;
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.c2s.handshake.ConnectionIntent;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -53,4 +57,20 @@ private void receivingPacketPost(

EventFlow.post(new PacketEvent.Receive.Post(packet));
}

@Inject(method = "connect(Ljava/lang/String;ILnet/minecraft/network/listener/PacketListener;Lnet/minecraft/network/packet/c2s/handshake/ConnectionIntent;)V", at = @At("HEAD"))
private void onConnect(
String address,
int port,
PacketListener listener,
ConnectionIntent intent,
CallbackInfo ci
) {
EventFlow.post(new ConnectionEvent.Connect(address, port, listener, intent));
}

@Inject(method = "disconnect(Lnet/minecraft/text/Text;)V", at = @At("HEAD"))
private void onDisconnect(Text reason, CallbackInfo ci) {
EventFlow.post(new ConnectionEvent.Disconnect(reason));
}
}
18 changes: 18 additions & 0 deletions common/src/main/java/com/lambda/mixin/DebugHudMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.lambda.mixin;

import com.lambda.util.DebugInfoHud;
import net.minecraft.client.gui.hud.DebugHud;
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.callback.CallbackInfoReturnable;

import java.util.List;

@Mixin(DebugHud.class)
public class DebugHudMixin {
@Inject(method = "getRightText", at = @At(value = "TAIL"))
private void onGetRightText(CallbackInfoReturnable<List<String>> cir) {
DebugInfoHud.addDebugInfo(cir.getReturnValue());
}
}
16 changes: 16 additions & 0 deletions common/src/main/java/com/lambda/mixin/GameRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lambda.mixin;

import com.lambda.interaction.RotationManager;
import net.minecraft.client.render.GameRenderer;
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.callback.CallbackInfo;

@Mixin(GameRenderer.class)
public class GameRendererMixin {
@Inject(method = "updateTargetedEntity", at = @At("HEAD"))
private void onUpdateTargetedEntity(CallbackInfo ci) {
RotationManager.updateInterpolated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ boolean injectMultiActon(ClientPlayerInteractionManager instance) {
void injectFastPlace(CallbackInfo ci) {
if (!Interact.INSTANCE.isEnabled()) return;

Lambda.INSTANCE.getMc().itemUseCooldown = Interact.getPlaceDelay();
Lambda.getMc().itemUseCooldown = Interact.getPlaceDelay();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.lambda.mixin.entity;

import com.lambda.Lambda;
import com.lambda.event.EventFlow;
import com.lambda.event.events.MovementEvent;
import com.lambda.interaction.PlayerPacketManager;
import com.lambda.interaction.RotationManager;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.MovementType;
import net.minecraft.util.math.Vec3d;
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;

import java.util.Objects;

@Mixin(value = ClientPlayerEntity.class, priority = Integer.MAX_VALUE)
public abstract class ClientPlayerEntityMixin extends EntityMixin {

@Shadow protected abstract void autoJump(float dx, float dz);

@Shadow public abstract boolean isUsingItem();

@Shadow private boolean autoJumpEnabled;

@Inject(method = "move", at = @At("HEAD"), cancellable = true)
void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
ClientPlayerEntity self = (ClientPlayerEntity) (Object) this;
if (self != Lambda.getMc().player) return;

ci.cancel();

float prevX = (float) self.getX();
float prevZ = (float) self.getZ();

EventFlow.post(new MovementEvent.Pre());
super.move(movementType, self.getVelocity());
EventFlow.post(new MovementEvent.Post());

float currX = (float) self.getX();
float currZ = (float) self.getZ();

this.autoJump(currX - prevX, currZ - prevZ);
}

@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
boolean onSlowDown(ClientPlayerEntity entity) {
if (EventFlow.post(new MovementEvent.SlowDown()).isCanceled()) return false;
return this.isUsingItem();
}

@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick(ZF)V", shift = At.Shift.AFTER))
void processMovement(CallbackInfo ci) {
RotationManager.BaritoneProcessor.processPlayerMovement();
}

@Inject(method = "sendMovementPackets", at = @At(value = "HEAD"), cancellable = true)
void sendBegin(CallbackInfo ci) {
ci.cancel();
PlayerPacketManager.sendPlayerPackets();
autoJumpEnabled = Lambda.getMc().options.getAutoJump().getValue();
}

@Redirect(method = "tickNewAi", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
float fixHeldItemYaw(ClientPlayerEntity instance) {
return Objects.requireNonNullElse(RotationManager.getHandYaw(), instance.getYaw());
}

@Redirect(method = "tickNewAi", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
float fixHeldItemPitch(ClientPlayerEntity instance) {
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
}
}
61 changes: 61 additions & 0 deletions common/src/main/java/com/lambda/mixin/entity/EntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.lambda.mixin.entity;

import com.lambda.Lambda;
import com.lambda.interaction.RotationManager;
import com.lambda.util.math.Vec2d;
import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType;
import net.minecraft.util.math.Vec3d;
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.Redirect;

@Mixin(Entity.class)
public abstract class EntityMixin {
@Shadow public void move(MovementType movementType, Vec3d movement) {}

@Shadow public abstract float getYaw();

@Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
public float velocityYaw(Entity entity) {
if ((Object) this != Lambda.getMc().player) return getYaw();

Float y = RotationManager.getMovementYaw();
if (y == null) return getYaw();

return y;
}

@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
float fixDirectionYaw(Entity entity, float tickDelta) {
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw(tickDelta);

return (float) rot.getX();
}

@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
float fixDirectionPitch(Entity entity, float tickDelta) {
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch(tickDelta);

return (float) rot.getY();
}

@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
float fixDirectionYaw2(Entity entity) {
Vec2d rot = RotationManager.getRotationForVector(1.0);
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw();

return (float) rot.getX();
}

@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
float fixDirectionPitch2(Entity entity) {
Vec2d rot = RotationManager.getRotationForVector(1.0);
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch();

return (float) rot.getY();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.lambda.mixin.entity;

import com.lambda.Lambda;
import com.lambda.event.EventFlow;
import com.lambda.event.events.MovementEvent;
import com.lambda.interaction.RotationManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
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.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends EntityMixin {

@Shadow
protected abstract float getJumpVelocity();

@Inject(method = "jump", at = @At("HEAD"), cancellable = true)
void onJump(CallbackInfo ci) {
LivingEntity self = (LivingEntity) (Object) this;
if (self != Lambda.getMc().player) return;
ci.cancel();

float height = this.getJumpVelocity();
MovementEvent.Jump event = EventFlow.post(new MovementEvent.Jump(height));

if (event.isCanceled()) return;

Vec3d vec3d = self.getVelocity();
self.setVelocity(vec3d.x, event.getHeight(), vec3d.z);

if (self.isSprinting()) {
Float yaw = RotationManager.getMovementYaw();
float f = ((yaw != null) ? yaw : self.getYaw()) * ((float)Math.PI / 180);
self.setVelocity(self.getVelocity().add(-MathHelper.sin(f) * 0.2f, 0.0, MathHelper.cos(f) * 0.2f));
}

self.velocityDirty = true;
}

@Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isImmobile()Z"))
void onTravelH(CallbackInfo ci) {
Entity self = (Entity) (Object) this;
if (self != Lambda.getMc().player) return;

RotationManager.update();
}

@Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F"))
private float hookModifyFallFlyingPitch(LivingEntity entity) {
Float pitch = RotationManager.getMovementPitch();
if (entity != Lambda.getMc().player || pitch == null) return entity.getPitch();

return pitch;
}

@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"), slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F", ordinal = 1)))
private float rotBody(LivingEntity entity) {
if ((Object) this != Lambda.getMc().player) {
return entity.getYaw();
}

Float yaw = RotationManager.getRenderYaw();
return (yaw == null) ? entity.getYaw() : yaw;
}

@Redirect(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
private float rotHead(LivingEntity entity) {
if ((Object) this != Lambda.getMc().player) {
return entity.getYaw();
}

Float yaw = RotationManager.getRenderYaw();
return (yaw == null) ? entity.getYaw() : yaw;
}
}
2 changes: 1 addition & 1 deletion common/src/main/kotlin/com/lambda/Loadable.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.lambda

interface Loadable {
fun load(): String
fun load() = this::class.simpleName?.let { "Loaded $it" } ?: "Loaded"
}
4 changes: 3 additions & 1 deletion common/src/main/kotlin/com/lambda/Loader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.lambda

import com.lambda.Lambda.LOG
import com.lambda.command.CommandManager
import com.lambda.interaction.RotationManager
import com.lambda.module.ModuleRegistry
import kotlin.system.measureTimeMillis

object Loader {
private val loadables = listOf(
ModuleRegistry,
CommandManager
CommandManager,
RotationManager
)

fun initialize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object CommandManager : Configurable(LambdaConfig), Loadable {

val prefix by setting("prefix", ';')

private val commands = mutableSetOf<LambdaCommand>()
val commands = mutableSetOf<LambdaCommand>()
private val dispatcher by lazy { CommandDispatcher<CommandSource>() }
private const val ERROR_PADDING = 10

Expand Down
13 changes: 13 additions & 0 deletions common/src/main/kotlin/com/lambda/config/InteractionSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.lambda.config

import com.lambda.interaction.InteractionConfig
import com.lambda.util.world.raycast.RayCastMask

class InteractionSettings(
c: Configurable,
vis: () -> Boolean = { true }
) : InteractionConfig {
override val reach by c.setting("Reach", 5.0, 0.1..10.0, 0.1, "Players reach / range", vis)
override val resolution by c.setting("Resolution", 10, 1..100, 1, "Raycast resolution", vis)
override val rayCastMask by c.setting("Raycast Mask", RayCastMask.BOTH, "What to raycast against", vis)
}
29 changes: 29 additions & 0 deletions common/src/main/kotlin/com/lambda/config/RotationSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.lambda.config

import com.lambda.interaction.rotation.IRotationConfig
import com.lambda.interaction.rotation.RotationMode
import kotlin.random.Random

class RotationSettings(
c: Configurable,
vis: () -> Boolean = { true }
) : IRotationConfig {
override val rotationMode by c.setting("Mode", RotationMode.LOCK, "SILENT - server-side rotation, SYNC - server-side rotation; client-side movement, LOCK - Lock camera", vis)
override val keepTicks by c.setting("Keep Rotation", 3, 1..10, 1, "Ticks to keep rotation", vis)
override val resetTicks by c.setting("Reset Rotation", 3, 1..10, 1, "Ticks before rotation is reset", vis)

private val r1 by c.setting("Turn Speed 1", 70.0, 1.0..180.0, 0.1, "Rotation Speed 1", vis)
private val r2 by c.setting("Turn Speed 2", 110.0, 1.0..180.0, 0.1, "Rotation Speed 2", vis)

override val turnSpeed get() = Random.nextDouble(r1, r2)

var speedMultiplier = 1.0

fun slowdownIf(flag: Boolean) {
speedMultiplier = (if (flag) 0.0 else 1.0)
.coerceIn(
speedMultiplier - 0.3, // slowdown faster
speedMultiplier + 0.15 // accelerate slower
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.google.gson.*
import com.lambda.util.KeyCode
import java.lang.reflect.Type

// ToDo: Use key lookup table to store actual key names
object KeyCodeSerializer : JsonSerializer<KeyCode>, JsonDeserializer<KeyCode> {
override fun serialize(
src: KeyCode?,
Expand Down
Loading