From 627150b57049aa321c8d4dfe17824c7867ef6bc9 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 19 Feb 2023 20:20:31 +0100 Subject: [PATCH 1/4] feat: initial boatfly, but kinda broken --- src/main/java/ftbsc/bscv/BoSCoVicino.java | 1 + .../ftbsc/bscv/modules/motion/BoatFly.java | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/modules/motion/BoatFly.java diff --git a/src/main/java/ftbsc/bscv/BoSCoVicino.java b/src/main/java/ftbsc/bscv/BoSCoVicino.java index 60735c3..c5c397c 100644 --- a/src/main/java/ftbsc/bscv/BoSCoVicino.java +++ b/src/main/java/ftbsc/bscv/BoSCoVicino.java @@ -72,6 +72,7 @@ public class BoSCoVicino implements ICommons { BoSCoVicino.mods.add(new AutoFish(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new AutoTool(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new Freecam(cfg, dp).done(cfg)); + BoSCoVicino.mods.add(new BoatFly(cfg, dp).done(cfg)); BoSCoVicino.spec = cfg.build(); diff --git a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java new file mode 100644 index 0000000..3724c72 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java @@ -0,0 +1,59 @@ +package ftbsc.bscv.modules.motion; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.DoubleArgumentType; + +import ftbsc.bscv.ICommons; +import ftbsc.bscv.modules.Module; +import ftbsc.bscv.tools.Keyboard; +import net.minecraft.command.CommandSource; +import net.minecraft.entity.Entity; +import net.minecraft.entity.item.BoatEntity; +import net.minecraft.util.math.vector.Vector2f; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.event.TickEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class BoatFly extends Module implements ICommons { + + public final ForgeConfigSpec.ConfigValue speed; + public final ForgeConfigSpec.ConfigValue rise; + + public BoatFly(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { + super("BoatFly", Group.MOTION, builder, dispatcher); + + this.speed = this.option( + "speed", "magnitude of boat movement", 1., + DoubleArgumentType.doubleArg(), Double.class, + builder, dispatcher + ); + + this.rise = this.option( + "rise", "vertical speed", 0.5, + DoubleArgumentType.doubleArg(), Double.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + // if (event.phase == Phase.END) return; + if (MC.player == null) { + this.disable(); + return; + } + Entity vehicle = MC.player.getVehicle(); + if (vehicle == null) return; + if (vehicle instanceof BoatEntity) { + + } + + if (Keyboard.isMoving()) { + Vector2f motion = MC.player.input.getMoveVector(); + double rise = MC.options.keyJump.isDown() ? this.rise.get() : 0.; + double speed = this.speed.get(); + vehicle.setDeltaMovement(motion.x * speed, rise, motion.y * speed); + } + } + +} From ac4a18a428d32fe4af9606672f66d713c0965de1 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 19 Feb 2023 20:20:47 +0100 Subject: [PATCH 2/4] chore: some boilerplate for boat patch --- .../java/ftbsc/bscv/events/BoatEvent.java | 12 ++++ .../java/ftbsc/bscv/patches/BoatPatch.java | 59 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/main/java/ftbsc/bscv/events/BoatEvent.java create mode 100644 src/main/java/ftbsc/bscv/patches/BoatPatch.java diff --git a/src/main/java/ftbsc/bscv/events/BoatEvent.java b/src/main/java/ftbsc/bscv/events/BoatEvent.java new file mode 100644 index 0000000..32eeb37 --- /dev/null +++ b/src/main/java/ftbsc/bscv/events/BoatEvent.java @@ -0,0 +1,12 @@ +package ftbsc.bscv.events; + +import net.minecraftforge.eventbus.api.Cancelable; +import net.minecraftforge.eventbus.api.Event; + +public class BoatEvent { + + @Cancelable + public class Control extends Event { + public Control() {} + } +} diff --git a/src/main/java/ftbsc/bscv/patches/BoatPatch.java b/src/main/java/ftbsc/bscv/patches/BoatPatch.java new file mode 100644 index 0000000..3d7f13d --- /dev/null +++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java @@ -0,0 +1,59 @@ +package ftbsc.bscv.patches; + +import net.minecraft.network.IPacket; +import net.minecraftforge.common.MinecraftForge; + +import org.objectweb.asm.Opcodes; +import org.objectweb.asm.tree.AbstractInsnNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.JumpInsnNode; +import org.objectweb.asm.tree.LabelNode; +import org.objectweb.asm.tree.MethodInsnNode; +import org.objectweb.asm.tree.MethodNode; +import org.objectweb.asm.tree.VarInsnNode; + +import ftbsc.bscv.events.BoatEvent; +import ftbsc.bscv.events.PacketEvent; +import ftbsc.lll.IInjector; +import ftbsc.lll.tools.InsnSequence; +import ftbsc.lll.tools.PatternMatcher; + +public class BoatPatch { + + public static class BoatHook { + public static boolean boatControl(IPacket pkt) { + return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); + } + + public static boolean pktOut(IPacket pkt) { + return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, true)); + } + } + + public static class BoatControlOverride implements IInjector, Opcodes { + public String name() { return "BoatControlOverride"; } + public String reason() { return "add hook to cancel vanilla boat controls"; } + public String targetClass() { return "net.minecraft.entity.item.BoatEntity"; } + public String methodName() { return "func_184443_x"; } // void controlBoat() + public String methodDesc() { return "()V"; } + + public void inject(ClassNode clazz, MethodNode main) { + // Hook at method start + LabelNode skip = new LabelNode(); + InsnSequence is = new InsnSequence(); + is.add(new VarInsnNode(ALOAD, 2)); + is.add(new MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/BoatPatch$BoatHook", + "boatControl", + "(Lnet/minecraft/network/IPacket;)Z" + )); + is.add(new JumpInsnNode(IFEQ, skip)); + is.add(new InsnNode(RETURN)); + is.add(skip); + + main.instructions.insert(is); + } + } +} From eb9e15e004823f0efbdb3d24d4a055579b1996cc Mon Sep 17 00:00:00 2001 From: ftbsc Date: Sun, 19 Feb 2023 20:29:04 +0100 Subject: [PATCH 3/4] fix: working boat event --- src/main/java/ftbsc/bscv/events/BoatEvent.java | 4 ++-- src/main/java/ftbsc/bscv/modules/motion/BoatFly.java | 8 ++++++++ src/main/java/ftbsc/bscv/patches/BoatPatch.java | 9 +-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/ftbsc/bscv/events/BoatEvent.java b/src/main/java/ftbsc/bscv/events/BoatEvent.java index 32eeb37..3633bdc 100644 --- a/src/main/java/ftbsc/bscv/events/BoatEvent.java +++ b/src/main/java/ftbsc/bscv/events/BoatEvent.java @@ -6,7 +6,7 @@ import net.minecraftforge.eventbus.api.Event; public class BoatEvent { @Cancelable - public class Control extends Event { - public Control() {} + public static class Control extends Event { + public Control() { super(); } } } diff --git a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java index 3724c72..9506e5a 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java +++ b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.DoubleArgumentType; import ftbsc.bscv.ICommons; +import ftbsc.bscv.events.BoatEvent; import ftbsc.bscv.modules.Module; import ftbsc.bscv.tools.Keyboard; import net.minecraft.command.CommandSource; @@ -35,6 +36,13 @@ public class BoatFly extends Module implements ICommons { ); } + @SubscribeEvent + public void onBoatControl(BoatEvent.Control event) { + if (MC.player != null && MC.player.getVehicle() != null) { + event.setCanceled(true); + } + } + @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { // if (event.phase == Phase.END) return; diff --git a/src/main/java/ftbsc/bscv/patches/BoatPatch.java b/src/main/java/ftbsc/bscv/patches/BoatPatch.java index 3d7f13d..09478f6 100644 --- a/src/main/java/ftbsc/bscv/patches/BoatPatch.java +++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java @@ -4,7 +4,6 @@ import net.minecraft.network.IPacket; import net.minecraftforge.common.MinecraftForge; import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.JumpInsnNode; @@ -14,10 +13,8 @@ import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; import ftbsc.bscv.events.BoatEvent; -import ftbsc.bscv.events.PacketEvent; import ftbsc.lll.IInjector; import ftbsc.lll.tools.InsnSequence; -import ftbsc.lll.tools.PatternMatcher; public class BoatPatch { @@ -25,10 +22,6 @@ public class BoatPatch { public static boolean boatControl(IPacket pkt) { return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); } - - public static boolean pktOut(IPacket pkt) { - return MinecraftForge.EVENT_BUS.post(new PacketEvent(pkt, true)); - } } public static class BoatControlOverride implements IInjector, Opcodes { @@ -47,7 +40,7 @@ public class BoatPatch { INVOKESTATIC, "ftbsc/bscv/patches/BoatPatch$BoatHook", "boatControl", - "(Lnet/minecraft/network/IPacket;)Z" + "()Z" )); is.add(new JumpInsnNode(IFEQ, skip)); is.add(new InsnNode(RETURN)); From e5f1fdb4752a068e3f4c143f3acc5285d1311f12 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 19 Feb 2023 23:43:40 +0100 Subject: [PATCH 4/4] feat: working basic boatfly --- .../java/ftbsc/bscv/events/BoatEvent.java | 10 +++ .../ftbsc/bscv/modules/motion/BoatFly.java | 34 +++++++-- .../java/ftbsc/bscv/patches/BoatPatch.java | 71 +++++++++++++++++-- .../META-INF/services/ftbsc.lll.IInjector | 3 + 4 files changed, 108 insertions(+), 10 deletions(-) diff --git a/src/main/java/ftbsc/bscv/events/BoatEvent.java b/src/main/java/ftbsc/bscv/events/BoatEvent.java index 3633bdc..1bef3a6 100644 --- a/src/main/java/ftbsc/bscv/events/BoatEvent.java +++ b/src/main/java/ftbsc/bscv/events/BoatEvent.java @@ -9,4 +9,14 @@ public class BoatEvent { public static class Control extends Event { public Control() { super(); } } + + @Cancelable + public static class ClampRotation extends Event { + public ClampRotation() { super(); } + } + + @Cancelable + public static class Gravity extends Event { + public Gravity() { super(); } + } } diff --git a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java index 9506e5a..d158f9a 100644 --- a/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java +++ b/src/main/java/ftbsc/bscv/modules/motion/BoatFly.java @@ -1,6 +1,7 @@ package ftbsc.bscv.modules.motion; import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.DoubleArgumentType; import ftbsc.bscv.ICommons; @@ -9,16 +10,18 @@ import ftbsc.bscv.modules.Module; import ftbsc.bscv.tools.Keyboard; import net.minecraft.command.CommandSource; import net.minecraft.entity.Entity; -import net.minecraft.entity.item.BoatEntity; import net.minecraft.util.math.vector.Vector2f; +import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.common.ForgeConfigSpec; import net.minecraftforge.event.TickEvent; +import net.minecraftforge.event.TickEvent.Phase; import net.minecraftforge.eventbus.api.SubscribeEvent; public class BoatFly extends Module implements ICommons { public final ForgeConfigSpec.ConfigValue speed; public final ForgeConfigSpec.ConfigValue rise; + public final ForgeConfigSpec.ConfigValue gravity; public BoatFly(ForgeConfigSpec.Builder builder, CommandDispatcher dispatcher) { super("BoatFly", Group.MOTION, builder, dispatcher); @@ -34,6 +37,12 @@ public class BoatFly extends Module implements ICommons { DoubleArgumentType.doubleArg(), Double.class, builder, dispatcher ); + + this.gravity = this.option( + "gravity", "toggle boat gravity", true, + BoolArgumentType.bool(), Boolean.class, + builder, dispatcher + ); } @SubscribeEvent @@ -43,24 +52,37 @@ public class BoatFly extends Module implements ICommons { } } + @SubscribeEvent + public void onBoatClampRotation(BoatEvent.ClampRotation event) { + if (MC.player != null && MC.player.getVehicle() != null) { + event.setCanceled(true); + } + } + + @SubscribeEvent + public void onBoatGravity(BoatEvent.Gravity event) { + if (!this.gravity.get() && MC.player != null && MC.player.getVehicle() != null) { + event.setCanceled(true); + } + } + @SubscribeEvent public void onTick(TickEvent.ClientTickEvent event) { - // if (event.phase == Phase.END) return; + if (event.phase == Phase.END) return; if (MC.player == null) { this.disable(); return; } Entity vehicle = MC.player.getVehicle(); if (vehicle == null) return; - if (vehicle instanceof BoatEntity) { - } + vehicle.yRot = MC.player.yRot; if (Keyboard.isMoving()) { Vector2f motion = MC.player.input.getMoveVector(); - double rise = MC.options.keyJump.isDown() ? this.rise.get() : 0.; double speed = this.speed.get(); - vehicle.setDeltaMovement(motion.x * speed, rise, motion.y * speed); + Vector3d delta = new Vector3d(motion.x * speed, MC.options.keyJump.isDown() ? this.rise.get() : 0., motion.y * speed); + vehicle.setDeltaMovement(delta.yRot((float) -(MC.player.yRot * (Math.PI / 180F)))); } } diff --git a/src/main/java/ftbsc/bscv/patches/BoatPatch.java b/src/main/java/ftbsc/bscv/patches/BoatPatch.java index 09478f6..1283b88 100644 --- a/src/main/java/ftbsc/bscv/patches/BoatPatch.java +++ b/src/main/java/ftbsc/bscv/patches/BoatPatch.java @@ -1,6 +1,6 @@ package ftbsc.bscv.patches; -import net.minecraft.network.IPacket; +import net.minecraft.entity.Entity; import net.minecraftforge.common.MinecraftForge; import org.objectweb.asm.Opcodes; @@ -12,16 +12,28 @@ import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; +import ftbsc.bscv.ICommons; import ftbsc.bscv.events.BoatEvent; import ftbsc.lll.IInjector; import ftbsc.lll.tools.InsnSequence; public class BoatPatch { - public static class BoatHook { - public static boolean boatControl(IPacket pkt) { + public static class BoatHook implements ICommons { + public static boolean boatControl() { return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control()); } + + public static boolean boatClampRotation() { + return MinecraftForge.EVENT_BUS.post(new BoatEvent.ClampRotation()); + } + + public static boolean boatGravityCheck(Entity entity) { + if (MC.player == null) return false; + if (MC.player.getVehicle() == null) return false; + if (MC.player.getVehicle() != entity) return false; + return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity()); + } } public static class BoatControlOverride implements IInjector, Opcodes { @@ -35,7 +47,6 @@ public class BoatPatch { // Hook at method start LabelNode skip = new LabelNode(); InsnSequence is = new InsnSequence(); - is.add(new VarInsnNode(ALOAD, 2)); is.add(new MethodInsnNode( INVOKESTATIC, "ftbsc/bscv/patches/BoatPatch$BoatHook", @@ -49,4 +60,56 @@ public class BoatPatch { main.instructions.insert(is); } } + + public static class BoatClampOverride implements IInjector, Opcodes { + public String name() { return "BoatClampOverride"; } + public String reason() { return "add hook to cancel vanilla boat rotation clamping"; } + public String targetClass() { return "net.minecraft.entity.item.BoatEntity"; } + public String methodName() { return "func_184454_a"; } // void clampRotation(Entity e) + public String methodDesc() { return "(Lnet/minecraft/entity/Entity;)V"; } + + public void inject(ClassNode clazz, MethodNode main) { + // Hook at method start + LabelNode skip = new LabelNode(); + InsnSequence is = new InsnSequence(); + is.add(new MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/BoatPatch$BoatHook", + "boatClampRotation", + "()Z" + )); + is.add(new JumpInsnNode(IFEQ, skip)); + is.add(new InsnNode(RETURN)); + is.add(skip); + + main.instructions.insert(is); + } + } + + public static class BoatGravityOverride implements IInjector, Opcodes { + public String name() { return "BoatGravityOverride"; } + public String reason() { return "add hook to alter vanilla boat gravity"; } + public String targetClass() { return "net.minecraft.entity.Entity"; } + public String methodName() { return "func_189652_ae"; } // boolean isNoGravity() + public String methodDesc() { return "()Z"; } + + public void inject(ClassNode clazz, MethodNode main) { + // Hook at method start + LabelNode skip = new LabelNode(); + InsnSequence is = new InsnSequence(); + is.add(new VarInsnNode(ALOAD, 0)); + is.add(new MethodInsnNode( + INVOKESTATIC, + "ftbsc/bscv/patches/BoatPatch$BoatHook", + "boatGravityCheck", + "(Lnet/minecraft/entity/Entity;)Z" + )); + is.add(new JumpInsnNode(IFEQ, skip)); + is.add(new InsnNode(ICONST_1)); + is.add(new InsnNode(IRETURN)); + is.add(skip); + + main.instructions.insert(is); + } + } } diff --git a/src/main/resources/META-INF/services/ftbsc.lll.IInjector b/src/main/resources/META-INF/services/ftbsc.lll.IInjector index bda5738..b80faa2 100644 --- a/src/main/resources/META-INF/services/ftbsc.lll.IInjector +++ b/src/main/resources/META-INF/services/ftbsc.lll.IInjector @@ -1,2 +1,5 @@ ftbsc.bscv.patches.PacketPatch$IncomingPacketInterceptor ftbsc.bscv.patches.PacketPatch$OutgoingPacketInterceptor +ftbsc.bscv.patches.BoatPatch$BoatControlOverride +ftbsc.bscv.patches.BoatPatch$BoatClampOverride +ftbsc.bscv.patches.BoatPatch$BoatGravityOverride