Updated block connection update packet spam fix

This commit is contained in:
Lenni0451 2023-03-06 20:45:35 +01:00
parent e225383f51
commit 0cb63c3e24
2 changed files with 36 additions and 19 deletions

View File

@ -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;
}
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}