chore: upgraded patches to lillero-processor 0.5

This commit is contained in:
zaaarf 2023-03-28 14:26:36 +02:00
parent ed0d7d9621
commit d90f2ca4d9
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
11 changed files with 131 additions and 97 deletions

View file

@ -4,8 +4,8 @@ gitVersion = "0.13.0"
minecraft = "1.16.5" minecraft = "1.16.5"
forge = "1.16.5-36.2.34" forge = "1.16.5-36.2.34"
autoService = "1.0.1" autoService = "1.0.1"
lillero = "0.3.4" lillero = "0.4.0"
lilleroProcessor = "0.4.2" lilleroProcessor = "0.5.0"
checkerFramework = "0.6.24" checkerFramework = "0.6.24"
[plugins] [plugins]

View file

@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.PatternMatcher;
import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
@ -34,15 +34,19 @@ public class BackgroundPatch implements ICommons {
} }
} }
@Patch(value = Screen.class, reason = "add hook to cancel background on some screens") @Patch(Screen.class)
public abstract static class BackgroundOverride implements Opcodes { public abstract static class BackgroundOverride implements Opcodes {
@Find(parent = BackgroundPatch.class) @Find(BackgroundPatch.class)
abstract MethodProxy shouldDrawBackground(); MethodProxy shouldDrawBackground;
@Target
@Target(of = "shouldDrawBackground")
abstract boolean shouldDrawBackground(Screen screen);
@Target(of = "injectCancelBackgroundHook")
abstract void renderBackground(MatrixStack stack, int x); abstract void renderBackground(MatrixStack stack, int x);
@Injector @Injector(reason = "add hook to cancel background on some screens")
public void inject(ClassNode clazz, MethodNode main) { public void injectCancelBackgroundHook(ClassNode clazz, MethodNode main) {
AbstractInsnNode found = PatternMatcher.builder() AbstractInsnNode found = PatternMatcher.builder()
.opcodes(ALOAD, ALOAD, ICONST_0, ICONST_0) .opcodes(ALOAD, ALOAD, ICONST_0, ICONST_0)
.ignoreFrames() .ignoreFrames()
@ -55,7 +59,7 @@ public class BackgroundPatch implements ICommons {
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 0)); is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldDrawBackground())); is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldDrawBackground));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);

View file

@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity;
@ -24,19 +24,22 @@ public class BlockPushPatch {
return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent()); return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent());
} }
@Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel block collisions") @Patch(ClientPlayerEntity.class)
public abstract static class BlockCollisionsOverride implements Opcodes { public abstract static class BlockCollisionsOverride implements Opcodes {
@Find(parent = BlockPushPatch.class) @Find(BlockPushPatch.class)
abstract MethodProxy shouldCancelBlockCollisions(); MethodProxy shouldCancelBlockCollisions;
@Target @Target(of = "shouldCancelBlockCollisions")
abstract boolean shouldCancelBlockCollisions();
@Target(of = "injectCancelCollisionsHook")
abstract void moveTowardsClosestSpace(double x, double z); abstract void moveTowardsClosestSpace(double x, double z);
@Injector @Injector(reason = "add hook to cancel block collisions")
public void inject(ClassNode clazz, MethodNode main) { public void injectCancelCollisionsHook(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelBlockCollisions())); is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelBlockCollisions));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);

View file

@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -45,20 +45,23 @@ public class BoatPatch implements ICommons {
return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity()); return MinecraftForge.EVENT_BUS.post(new BoatEvent.Gravity());
} }
@Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat controls") @Patch(BoatEntity.class)
public abstract static class BoatControlOverride implements Opcodes { public abstract static class BoatControlOverride implements Opcodes {
@Find(parent = BoatPatch.class) @Find(BoatPatch.class)
abstract MethodProxy boatControl(); MethodProxy boatControl;
@Target @Target(of = "boatControl")
abstract boolean boatControl();
@Target(of = "injectBoatControlHook")
public abstract void controlBoat(); public abstract void controlBoat();
@Injector @Injector(reason = "add hook to cancel vanilla boat controls")
public void inject(ClassNode clazz, MethodNode main) { public void injectBoatControlHook(ClassNode clazz, MethodNode main) {
// Hook at method start // Hook at method start
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new MethodProxyInsnNode(INVOKESTATIC, boatControl())); is.add(new MethodProxyInsnNode(INVOKESTATIC, boatControl));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);
@ -67,20 +70,23 @@ public class BoatPatch implements ICommons {
} }
} }
@Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat rotation clamping") @Patch(BoatEntity.class)
public abstract static class BoatClampOverride implements Opcodes { public abstract static class BoatClampOverride implements Opcodes {
@Find(parent = BoatPatch.class) @Find(BoatPatch.class)
abstract MethodProxy boatClampRotation(); MethodProxy boatClampRotation;
@Target @Target(of = "boatClampRotation")
abstract boolean boatClampRotation();
@Target(of = "injectRotationClampingHook")
public abstract void clampRotation(Entity e); public abstract void clampRotation(Entity e);
@Injector @Injector(reason = "add hook to cancel vanilla boat rotation clamping")
public void inject(ClassNode clazz, MethodNode main) { public void injectRotationClampingHook(ClassNode clazz, MethodNode main) {
// Hook at method start // Hook at method start
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new MethodProxyInsnNode(INVOKESTATIC, boatClampRotation())); is.add(new MethodProxyInsnNode(INVOKESTATIC, boatClampRotation));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);
@ -89,21 +95,24 @@ public class BoatPatch implements ICommons {
} }
} }
@Patch(value = Entity.class, reason = "add hook to alter vanilla boat gravity") @Patch(Entity.class)
public abstract static class BoatGravityOverride implements Opcodes { public abstract static class BoatGravityOverride implements Opcodes {
@Find(parent = BoatPatch.class) @Find(BoatPatch.class)
abstract MethodProxy boatGravityCheck(); MethodProxy boatGravityCheck;
@Target @Target(of = "boatGravityCheck")
abstract boolean boatGravityCheck(Entity entity);
@Target(of = "injectGravityHook")
public abstract boolean isNoGravity(); public abstract boolean isNoGravity();
@Injector @Injector(reason = "add hook to alter vanilla boat gravity")
public void inject(ClassNode clazz, MethodNode main) { public void injectGravityHook(ClassNode clazz, MethodNode main) {
// Hook at method start // Hook at method start
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 0)); is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodProxyInsnNode(INVOKESTATIC, boatGravityCheck())); is.add(new MethodProxyInsnNode(INVOKESTATIC, boatGravityCheck));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(ICONST_1)); is.add(new InsnNode(ICONST_1));
is.add(new InsnNode(IRETURN)); is.add(new InsnNode(IRETURN));

View file

@ -14,16 +14,16 @@ import org.objectweb.asm.tree.*;
public class ChatPatch { public class ChatPatch {
@Patch(value = Minecraft.class, reason = "add hook to prevent chat from being cleared") @Patch(Minecraft.class)
public abstract static class ChatClearInterceptor implements Opcodes { public abstract static class ChatClearInterceptor implements Opcodes {
// TODO this should be optional // TODO this should be optional
@Target @Target(of = "injectClearChatHook")
abstract void setScreen(Screen screen); abstract void setScreen(Screen screen);
@Injector @Injector(reason = "skips chat clearing")
public void inject(ClassNode clazz, MethodNode main) { public void injectClearChatHook(ClassNode clazz, MethodNode main) {
InsnSequence match = PatternMatcher.builder() InsnSequence match = PatternMatcher.builder()
.opcodes(ALOAD, GETFIELD, INVOKEVIRTUAL, ICONST_1, INVOKEVIRTUAL) .opcodes(ALOAD, GETFIELD, INVOKEVIRTUAL, ICONST_1, INVOKEVIRTUAL)
.ignoreLineNumbers() .ignoreLineNumbers()

View file

@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.PatternMatcher;
import ftbsc.lll.tools.debug.BytecodePrinter; import ftbsc.lll.tools.debug.BytecodePrinter;
@ -34,17 +34,20 @@ public class CommandsPatch {
MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher)); MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher));
} }
@Patch(value = ClientPlayNetHandler.class, reason = "add hook to insert our command suggestions") @Patch(ClientPlayNetHandler.class)
public abstract static class CommandsDispatcherCatcher implements Opcodes { public abstract static class CommandsDispatcherCatcher implements Opcodes {
@Find(parent = CommandsPatch.class) @Find(CommandsPatch.class)
abstract MethodProxy cmdBuilt(); MethodProxy cmdBuilt;
@Target
@Target(of = "cmdBuilt")
abstract void cmdBuilt(CommandDispatcher<CommandSource> dispatcher);
@Target(of = "injectCommandHandler")
abstract void handleCommands(SCommandListPacket pkt); abstract void handleCommands(SCommandListPacket pkt);
@Injector @Injector(reason = "add hook to insert our command suggestions")
public void inject(ClassNode clazz, MethodNode main) { public void injectCommandHandler(ClassNode clazz, MethodNode main) {
BytecodePrinter.logAsmMethod(main, "pre.log");
AbstractInsnNode found = PatternMatcher.builder() AbstractInsnNode found = PatternMatcher.builder()
.opcodes(ALOAD, INVOKEVIRTUAL, INVOKESPECIAL) .opcodes(ALOAD, INVOKEVIRTUAL, INVOKESPECIAL)
.ignoreFrames() .ignoreFrames()
@ -56,10 +59,9 @@ public class CommandsPatch {
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new InsnNode(DUP)); is.add(new InsnNode(DUP));
is.add(new MethodProxyInsnNode(INVOKESTATIC, cmdBuilt())); is.add(new MethodProxyInsnNode(INVOKESTATIC, cmdBuilt));
main.instructions.insert(found, is); main.instructions.insert(found, is);
BytecodePrinter.logAsmMethod(main, "post.log");
} }
} }
} }

View file

@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -28,20 +28,23 @@ public class EntityPushPatch implements ICommons {
return false; return false;
} }
@Patch(value = Entity.class, reason = "add hook to cancel entity collisions") @Patch(Entity.class)
public abstract static class EntityCollisionsOverride implements Opcodes { public abstract static class EntityCollisionsOverride implements Opcodes {
@Find(parent = EntityPushPatch.class) @Find(EntityPushPatch.class)
abstract MethodProxy shouldCancelEntityCollisions(); MethodProxy shouldCancelEntityCollisions;
@Target @Target(of = "shouldCancelEntityCollisions")
abstract boolean shouldCancelEntityCollisions(Entity e);
@Target(of = "injectEntityCollisionHook")
abstract void push(double x, double y, double z); abstract void push(double x, double y, double z);
@Injector @Injector(reason = "add hook to cancel entity collisions")
public void inject(ClassNode clazz, MethodNode main) { public void injectEntityCollisionHook(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 0)); is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelEntityCollisions())); is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelEntityCollisions));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);

View file

@ -5,7 +5,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -28,20 +28,23 @@ public class LiquidPushPatch implements ICommons {
return false; return false;
} }
@Patch(value = PlayerEntity.class, reason = "add hook to cancel liquid collisions") @Patch(PlayerEntity.class)
public abstract static class LiquidCollisionsOverride implements Opcodes { public abstract static class LiquidCollisionsOverride implements Opcodes {
@Find(parent = LiquidPushPatch.class) @Find(LiquidPushPatch.class)
abstract MethodProxy shouldCancelLiquidCollisions(); MethodProxy shouldCancelLiquidCollisions;
@Target @Target(of = "shouldCancelLiquidCollisions")
abstract boolean shouldCancelLiquidCollisions(PlayerEntity player);
@Target(of = "injectLiquidCollisionHook")
abstract boolean isPushedByFluid(); abstract boolean isPushedByFluid();
@Injector @Injector(reason = "add hook to cancel liquid collisions")
public void inject(ClassNode clazz, MethodNode main) { public void injectLiquidCollisionHook(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 0)); is.add(new VarInsnNode(ALOAD, 0));
is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelLiquidCollisions())); is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldCancelLiquidCollisions));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(ICONST_0)); is.add(new InsnNode(ICONST_0));
is.add(new InsnNode(IRETURN)); is.add(new InsnNode(IRETURN));

View file

@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.PatternMatcher;
import ftbsc.lll.tools.nodes.MethodProxyInsnNode; import ftbsc.lll.tools.nodes.MethodProxyInsnNode;
@ -25,17 +25,20 @@ public class NoSlowPatch {
return MinecraftForge.EVENT_BUS.post(new PlayerSlowDownEvent()); return MinecraftForge.EVENT_BUS.post(new PlayerSlowDownEvent());
} }
@Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel slowing down effect of using items") @Patch(ClientPlayerEntity.class)
public abstract static class SlowDownOverride implements Opcodes { public abstract static class SlowDownOverride implements Opcodes {
@Find(parent = NoSlowPatch.class) @Find(NoSlowPatch.class)
abstract MethodProxy shouldSlowPlayer(); MethodProxy shouldSlowPlayer;
@Target @Target(of = "shouldSlowPlayer")
abstract boolean shouldSlowPlayer();
@Target(of = "injectNoSlowHook")
abstract void aiStep(); abstract void aiStep();
@Injector @Injector(reason = "add hook to cancel slowing down effect of using items")
public void inject(ClassNode clazz, MethodNode main) { public void injectNoSlowHook(ClassNode clazz, MethodNode main) {
AbstractInsnNode found = PatternMatcher.builder() AbstractInsnNode found = PatternMatcher.builder()
.opcodes(ALOAD, INVOKEVIRTUAL, IFEQ, ALOAD, INVOKEVIRTUAL, IFNE) .opcodes(ALOAD, INVOKEVIRTUAL, IFEQ, ALOAD, INVOKEVIRTUAL, IFNE)
.ignoreFrames() .ignoreFrames()
@ -56,7 +59,7 @@ public class NoSlowPatch {
LabelNode skip = new LabelNode(); // TODO can we get the label that the original IF is jumping to without adding one ourselves? LabelNode skip = new LabelNode(); // TODO can we get the label that the original IF is jumping to without adding one ourselves?
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldSlowPlayer())); is.add(new MethodProxyInsnNode(INVOKESTATIC, shouldSlowPlayer));
is.add(new JumpInsnNode(IFNE, skip)); is.add(new JumpInsnNode(IFNE, skip));
main.instructions.insert(found, is); main.instructions.insert(found, is);

View file

@ -4,7 +4,7 @@ import ftbsc.lll.processor.annotations.Find;
import ftbsc.lll.processor.annotations.Injector; import ftbsc.lll.processor.annotations.Injector;
import ftbsc.lll.processor.annotations.Patch; import ftbsc.lll.processor.annotations.Patch;
import ftbsc.lll.processor.annotations.Target; import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.proxies.MethodProxy; import ftbsc.lll.proxies.impl.MethodProxy;
import ftbsc.lll.tools.InsnSequence; import ftbsc.lll.tools.InsnSequence;
import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.PatternMatcher;
import ftbsc.lll.tools.debug.BytecodePrinter; import ftbsc.lll.tools.debug.BytecodePrinter;
@ -51,16 +51,19 @@ public class PacketPatch {
return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(pkt)); return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(pkt));
} }
@Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel incoming packets") @Patch(NetworkManager.class)
public abstract static class IncomingPacketInterceptor implements Opcodes { public abstract static class IncomingPacketInterceptor implements Opcodes {
@Find(parent = PacketPatch.class) @Find(PacketPatch.class)
abstract MethodProxy pktIn(); MethodProxy pktIn;
@Target @Target(of = "pktIn")
public abstract void channelRead0(ChannelHandlerContext ctx, IPacket<?> pak); abstract boolean pktIn(IPacket<?> pkt);
@Injector @Target(of = "injectIncomingInterceptor")
public void inject(ClassNode clazz, MethodNode main) { abstract void channelRead0(ChannelHandlerContext ctx, IPacket<?> pak);
@Injector(reason = "add hook to intercept and alter/cancel incoming packets")
public void injectIncomingInterceptor(ClassNode clazz, MethodNode main) {
AbstractInsnNode found = PatternMatcher.builder() AbstractInsnNode found = PatternMatcher.builder()
.opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ) .opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ)
.ignoreFrames() .ignoreFrames()
@ -73,7 +76,7 @@ public class PacketPatch {
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 2)); is.add(new VarInsnNode(ALOAD, 2));
is.add(new MethodProxyInsnNode(INVOKESTATIC, pktIn())); is.add(new MethodProxyInsnNode(INVOKESTATIC, pktIn));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);
@ -82,21 +85,25 @@ public class PacketPatch {
} }
} }
@Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel outgoing packets") @Patch(NetworkManager.class)
public abstract static class OutgoingPacketInterceptor implements Opcodes { public abstract static class OutgoingPacketInterceptor implements Opcodes {
@Find(parent = PacketPatch.class) @Find(PacketPatch.class)
abstract MethodProxy pktOut(); MethodProxy pktOut;
@Target @Target(of = "pktOut")
abstract boolean pktOut(IPacket<?> pkt);
@Target(of = "injectOutgoingInterceptor")
public abstract void sendPacket(IPacket<?> pak, GenericFutureListener<? extends Future<? super Void>> gfl); public abstract void sendPacket(IPacket<?> pak, GenericFutureListener<? extends Future<? super Void>> gfl);
@Injector @Injector(reason = "add hook to intercept and alter/cancel outgoing packets")
public void inject(ClassNode clazz, MethodNode main) { public void injectOutgoingInterceptor(ClassNode clazz, MethodNode main) {
// hook at the top // hook at the top
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();
InsnSequence is = new InsnSequence(); InsnSequence is = new InsnSequence();
is.add(new VarInsnNode(ALOAD, 1)); is.add(new VarInsnNode(ALOAD, 1));
is.add(new MethodProxyInsnNode(INVOKESTATIC, pktOut())); is.add(new MethodProxyInsnNode(INVOKESTATIC, pktOut));
is.add(new JumpInsnNode(IFEQ, skip)); is.add(new JumpInsnNode(IFEQ, skip));
is.add(new InsnNode(RETURN)); is.add(new InsnNode(RETURN));
is.add(skip); is.add(skip);

View file

@ -13,12 +13,12 @@ import ftbsc.lll.processor.annotations.Target;
import ftbsc.lll.tools.PatternMatcher; import ftbsc.lll.tools.PatternMatcher;
import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.entity.player.ClientPlayerEntity;
@Patch(value = ClientPlayerEntity.class, reason = "prevent minecraft from force closing guis when entering portals") @Patch(ClientPlayerEntity.class)
public abstract class PortalGuiPatch implements Opcodes { public abstract class PortalGuiPatch implements Opcodes {
@Target @Target(of = "inject")
abstract void handleNetherPortalClient(); abstract void handleNetherPortalClient();
@Injector @Injector(reason = "prevent minecraft from force closing guis when entering portals")
public void inject(ClassNode clazz, MethodNode main) { public void inject(ClassNode clazz, MethodNode main) {
LabelNode skip = new LabelNode(); LabelNode skip = new LabelNode();