Merge branch 'processor5' into dev

This commit is contained in:
əlemi 2023-06-20 23:54:17 +02:00
commit 954a8c806f
Signed by: alemi
GPG key ID: A4895B84D311642C
12 changed files with 161 additions and 152 deletions

View file

@ -66,7 +66,7 @@ dependencies {
} }
compileJava { //mappings for lillero-processor compileJava { //mappings for lillero-processor
options.compilerArgs << '-AmappingsFile=https://data.fantabos.co/output.tsrg' options.compilerArgs << '-AmappingsFile=https://data.fantabos.co/1.16.5.tsrg'
} }
jar { jar {

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.1"
lilleroProcessor = "0.4.2" lilleroProcessor = "0.5.2"
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;
@ -20,11 +20,6 @@ import org.objectweb.asm.tree.*;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
public class BackgroundPatch implements ICommons { public class BackgroundPatch implements ICommons {
public static boolean shouldDrawBackground(Screen screen) {
return MinecraftForge.EVENT_BUS.post(new RenderBackgroundEvent(screen));
}
@Cancelable @Cancelable
public static class RenderBackgroundEvent extends Event { public static class RenderBackgroundEvent extends Event {
public final Screen screen; public final Screen screen;
@ -34,15 +29,21 @@ 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(BackgroundOverride.class)
abstract MethodProxy shouldDrawBackground(); MethodProxy shouldDrawBackground;
@Target
@Target(of = "shouldDrawBackground")
public static boolean shouldDrawBackground(Screen screen) {
return MinecraftForge.EVENT_BUS.post(new RenderBackgroundEvent(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 +56,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;
@ -20,23 +20,24 @@ public class BlockPushPatch {
@Cancelable @Cancelable
public static class PlayerBlockPushEvent extends Event {} public static class PlayerBlockPushEvent extends Event {}
public static boolean shouldCancelBlockCollisions() { @Patch(ClientPlayerEntity.class)
return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent());
}
@Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel block collisions")
public abstract static class BlockCollisionsOverride implements Opcodes { public abstract static class BlockCollisionsOverride implements Opcodes {
@Find(parent = BlockPushPatch.class) @Find(BlockCollisionsOverride.class)
abstract MethodProxy shouldCancelBlockCollisions(); MethodProxy shouldCancelBlockCollisions;
@Target @Target(of = "shouldCancelBlockCollisions")
public static boolean shouldCancelBlockCollisions() {
return MinecraftForge.EVENT_BUS.post(new PlayerBlockPushEvent());
}
@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;
@ -30,35 +30,25 @@ public class BoatPatch implements ICommons {
public static class Gravity extends Event { } public static class Gravity extends Event { }
} }
public static boolean boatControl() { @Patch(BoatEntity.class)
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());
}
@Patch(value = BoatEntity.class, reason = "add hook to cancel vanilla boat controls")
public abstract static class BoatControlOverride implements Opcodes { public abstract static class BoatControlOverride implements Opcodes {
@Find(parent = BoatPatch.class) @Find(BoatControlOverride.class)
abstract MethodProxy boatControl(); MethodProxy boatControl;
@Target @Target(of = "boatControl")
public static boolean boatControl() {
return MinecraftForge.EVENT_BUS.post(new BoatEvent.Control());
}
@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 +57,25 @@ 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(BoatClampOverride.class)
abstract MethodProxy boatClampRotation(); MethodProxy boatClampRotation;
@Target @Target(of = "boatClampRotation")
public static boolean boatClampRotation() {
return MinecraftForge.EVENT_BUS.post(new BoatEvent.ClampRotation());
}
@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 +84,29 @@ 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(BoatGravityOverride.class)
abstract MethodProxy boatGravityCheck(); MethodProxy boatGravityCheck;
@Target @Target(of = "boatGravityCheck")
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());
}
@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;
@ -30,21 +30,21 @@ public class CommandsPatch {
} }
} }
public static void cmdBuilt(CommandDispatcher<CommandSource> dispatcher) { @Patch(ClientPlayNetHandler.class)
MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(dispatcher));
}
@Patch(value = ClientPlayNetHandler.class, reason = "add hook to insert our command suggestions")
public abstract static class CommandsDispatcherCatcher implements Opcodes { public abstract static class CommandsDispatcherCatcher implements Opcodes {
@Find(parent = CommandsPatch.class) @Find(CommandsDispatcherCatcher.class)
abstract MethodProxy cmdBuilt(); MethodProxy cmdBuilt;
@Target @Target(of = "cmdBuilt")
public static void cmdBuilt(CommandDispatcher<CommandSource> dispatcher) {
MinecraftForge.EVENT_BUS.post(new CommandsBuiltEvent(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 +56,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;
@ -21,27 +21,28 @@ public class EntityPushPatch implements ICommons {
@Cancelable @Cancelable
public static class PlayerEntityPushEvent extends Event {} public static class PlayerEntityPushEvent extends Event {}
public static boolean shouldCancelEntityCollisions(Entity e) { @Patch(Entity.class)
if (e.equals(MC.player)) {
return MinecraftForge.EVENT_BUS.post(new PlayerEntityPushEvent());
}
return false;
}
@Patch(value = Entity.class, reason = "add hook to cancel entity collisions")
public abstract static class EntityCollisionsOverride implements Opcodes { public abstract static class EntityCollisionsOverride implements Opcodes {
@Find(parent = EntityPushPatch.class) @Find(EntityCollisionsOverride.class)
abstract MethodProxy shouldCancelEntityCollisions(); MethodProxy shouldCancelEntityCollisions;
@Target @Target(of = "shouldCancelEntityCollisions")
public static boolean shouldCancelEntityCollisions(Entity e) {
if (e.equals(MC.player)) {
return MinecraftForge.EVENT_BUS.post(new PlayerEntityPushEvent());
}
return false;
}
@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;
@ -21,27 +21,28 @@ public class LiquidPushPatch implements ICommons {
@Cancelable @Cancelable
public static class PlayerLiquidPushEvent extends Event {} public static class PlayerLiquidPushEvent extends Event {}
public static boolean shouldCancelLiquidCollisions(PlayerEntity player) { @Patch(PlayerEntity.class)
if (player.equals(MC.player)) {
return MinecraftForge.EVENT_BUS.post(new PlayerLiquidPushEvent());
}
return false;
}
@Patch(value = PlayerEntity.class, reason = "add hook to cancel liquid collisions")
public abstract static class LiquidCollisionsOverride implements Opcodes { public abstract static class LiquidCollisionsOverride implements Opcodes {
@Find(parent = LiquidPushPatch.class) @Find(LiquidCollisionsOverride.class)
abstract MethodProxy shouldCancelLiquidCollisions(); MethodProxy shouldCancelLiquidCollisions;
@Target @Target(of = "shouldCancelLiquidCollisions")
public static boolean shouldCancelLiquidCollisions(PlayerEntity player) {
if (player.equals(MC.player)) {
return MinecraftForge.EVENT_BUS.post(new PlayerLiquidPushEvent());
}
return false;
}
@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;
@ -21,21 +21,22 @@ public class NoSlowPatch {
@Cancelable @Cancelable
public static class PlayerSlowDownEvent extends Event { } public static class PlayerSlowDownEvent extends Event { }
public static boolean shouldSlowPlayer() { @Patch(ClientPlayerEntity.class)
return MinecraftForge.EVENT_BUS.post(new PlayerSlowDownEvent());
}
@Patch(value = ClientPlayerEntity.class, reason = "add hook to cancel slowing down effect of using items")
public abstract static class SlowDownOverride implements Opcodes { public abstract static class SlowDownOverride implements Opcodes {
@Find(parent = NoSlowPatch.class) @Find(SlowDownOverride.class)
abstract MethodProxy shouldSlowPlayer(); MethodProxy shouldSlowPlayer;
@Target @Target(of = "shouldSlowPlayer")
public static boolean shouldSlowPlayer() {
return MinecraftForge.EVENT_BUS.post(new PlayerSlowDownEvent());
}
@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 +57,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;
@ -43,24 +43,21 @@ public class PacketPatch {
} }
} }
public static boolean pktIn(IPacket<?> pkt) { @Patch(NetworkManager.class)
return MinecraftForge.EVENT_BUS.post(new PacketEvent.Incoming(pkt));
}
public static boolean pktOut(IPacket<?> pkt) {
return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(pkt));
}
@Patch(value = NetworkManager.class, reason = "add hook to intercept and alter/cancel incoming packets")
public abstract static class IncomingPacketInterceptor implements Opcodes { public abstract static class IncomingPacketInterceptor implements Opcodes {
@Find(parent = PacketPatch.class) @Find(IncomingPacketInterceptor.class)
abstract MethodProxy pktIn(); MethodProxy pktIn;
@Target @Target(of = "pktIn")
public abstract void channelRead0(ChannelHandlerContext ctx, IPacket<?> pak); public static boolean pktIn(IPacket<?> pkt) {
return MinecraftForge.EVENT_BUS.post(new PacketEvent.Incoming(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 +70,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 +79,26 @@ 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(OutgoingPacketInterceptor.class)
abstract MethodProxy pktOut(); MethodProxy pktOut;
@Target @Target(of = "pktOut")
public static boolean pktOut(IPacket<?> pkt) {
return MinecraftForge.EVENT_BUS.post(new PacketEvent.Outgoing(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();