From 0cb63c3e24742ab26e174d32f6fb70b2adb6b0d3 Mon Sep 17 00:00:00 2001 From: Lenni0451 <20379977+Lenni0451@users.noreply.github.com> Date: Mon, 6 Mar 2023 20:45:35 +0100 Subject: [PATCH] Updated block connection update packet spam fix --- .../ConnectionDataTransformer.java | 20 +---------- ...ctionData_NeighbourUpdaterTransformer.java | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionData_NeighbourUpdaterTransformer.java diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionDataTransformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionDataTransformer.java index b99d6fb..d75cf94 100644 --- a/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionDataTransformer.java +++ b/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionDataTransformer.java @@ -27,7 +27,7 @@ import org.objectweb.asm.tree.*; public abstract class ConnectionDataTransformer { @CASM("update") - public static void preventBlockChangeSpam1(MethodNode method) { + public static void preventBlockChangeSpam(MethodNode method) { LabelNode continueLabel = new LabelNode(); InsnList checkCode = new InsnList(); checkCode.add(new VarInsnNode(Opcodes.ILOAD, 7)); @@ -48,22 +48,4 @@ public abstract class ConnectionDataTransformer { } } - @CASM("updateBlock") - public static void preventBlockChangeSpam2(MethodNode method) { - LabelNode addLabel = new LabelNode(); - InsnList checkCode = new InsnList(); - checkCode.add(new VarInsnNode(Opcodes.ILOAD, 3)); - checkCode.add(new VarInsnNode(Opcodes.ILOAD, 5)); - checkCode.add(new JumpInsnNode(Opcodes.IF_ICMPNE, addLabel)); - checkCode.add(new InsnNode(Opcodes.RETURN)); - checkCode.add(addLabel); - - for (AbstractInsnNode insn : method.instructions.toArray()) { - if (insn.getOpcode() == Opcodes.INVOKEINTERFACE) { - method.instructions.insertBefore(insn, checkCode); - break; - } - } - } - } diff --git a/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionData_NeighbourUpdaterTransformer.java b/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionData_NeighbourUpdaterTransformer.java new file mode 100644 index 0000000..3378277 --- /dev/null +++ b/src/main/java/net/raphimc/viaproxy/injection/transformer/ConnectionData_NeighbourUpdaterTransformer.java @@ -0,0 +1,35 @@ +/* + * This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy + * Copyright (C) 2023 RK_01/RaphiMC and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package net.raphimc.viaproxy.injection.transformer; + +import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; +import net.lenni0451.classtransform.InjectionCallback; +import net.lenni0451.classtransform.annotations.CLocalVariable; +import net.lenni0451.classtransform.annotations.CTarget; +import net.lenni0451.classtransform.annotations.CTransformer; +import net.lenni0451.classtransform.annotations.injection.CInject; + +@CTransformer(ConnectionData.NeighbourUpdater.class) +public class ConnectionData_NeighbourUpdaterTransformer { + + @CInject(method = "updateBlock", target = @CTarget(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", shift = CTarget.Shift.BEFORE), cancellable = true) + public void preventBlockChangeSpam(InjectionCallback ic, @CLocalVariable(name = "blockState") int blockState, @CLocalVariable(name = "newBlockState") int newBlockState) { + if (blockState == newBlockState) ic.setCancelled(true); + } + +}