feat: initial work on packet patch
This commit is contained in:
parent
0591511859
commit
382e57a2cf
4 changed files with 78 additions and 54 deletions
|
@ -88,7 +88,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }
|
|||
|
||||
dependencies {
|
||||
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
|
||||
implementation 'ftbsc:lll:0.0.3'
|
||||
implementation 'ftbsc:lll:0.1.1'
|
||||
}
|
||||
|
||||
jar {
|
||||
|
|
76
src/main/java/ftbsc/bscv/patches/PacketPatch.java
Normal file
76
src/main/java/ftbsc/bscv/patches/PacketPatch.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
package ftbsc.bscv.patches;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import ftbsc.bscv.BoSCoVicino;
|
||||
import ftbsc.lll.IInjector;
|
||||
import ftbsc.lll.tools.DescriptorBuilder;
|
||||
import ftbsc.lll.tools.InsnSequence;
|
||||
import ftbsc.lll.tools.PatternMatcher;
|
||||
import net.minecraft.network.IPacket;
|
||||
|
||||
public class PacketPatch {
|
||||
|
||||
public static class LazyPacketCatcher {
|
||||
private static LazyPacketCatcher INSTANCE = new LazyPacketCatcher();
|
||||
|
||||
public static LazyPacketCatcher getInstance() {
|
||||
return LazyPacketCatcher.INSTANCE;
|
||||
}
|
||||
|
||||
public void debug_pkt(IPacket<?> pkt) {
|
||||
BoSCoVicino.LOGGER.info("got pkt : {}", pkt.toString());
|
||||
}
|
||||
|
||||
public static void debug_static_pkt(IPacket<?> pkt) {
|
||||
BoSCoVicino.LOGGER.info("got pkt : {}", pkt.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class IncomingPacketInterceptor implements IInjector, Opcodes {
|
||||
public String name() { return "IncomingPacketInterceptor"; }
|
||||
public String reason() { return "add hook to intercept and alter/cancel incoming packets"; }
|
||||
public String targetClass() { return "net.minecraft.network.NetworkManager"; }
|
||||
public String methodName() { return "channelRead0"; }
|
||||
public String methodDesc() {
|
||||
return
|
||||
new DescriptorBuilder()
|
||||
.setReturnType(void.class)
|
||||
.addParameter("io.netty.channel.ChannelHandlerContext")
|
||||
.addParameter("net.minecraft.network.IPacket")
|
||||
.build();
|
||||
}
|
||||
|
||||
public void inject(ClassNode clazz, MethodNode main) {
|
||||
// ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ
|
||||
AbstractInsnNode found = PatternMatcher.builder()
|
||||
.opcodes(ALOAD, GETFIELD, INVOKEINTERFACE, IFEQ)
|
||||
.ignoreFrames()
|
||||
.ignoreLabels()
|
||||
.ignoreLineNumbers()
|
||||
.build()
|
||||
.find(main)
|
||||
.getLast();
|
||||
|
||||
InsnSequence is = new InsnSequence();
|
||||
is.add(new VarInsnNode(ALOAD, 2));
|
||||
is.add(new MethodInsnNode(
|
||||
INVOKESTATIC,
|
||||
"ftbsc/bscv/patches/PacketPatch$LazyPacketCatcher",
|
||||
"debug_static_pkt",
|
||||
new DescriptorBuilder().addParameter("net.minecraft.network.IPacket").build()
|
||||
));
|
||||
|
||||
main.instructions.insert(found, is);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package ftbsc.bscv.patches;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import ftbsc.lll.IInjector;
|
||||
|
||||
/**
|
||||
* When working as intended, this patch will crash the game
|
||||
* as soon it finished loading with a NegativeArraySizeException.
|
||||
*/
|
||||
public class TestPatch {
|
||||
|
||||
public static class FramerateFix implements IInjector, Opcodes {
|
||||
public String name() { return "FramerateFix"; }
|
||||
public String targetClass() { return "net.minecraft.client.Minecraft"; }
|
||||
public String methodName() { return "func_213243_aC"; } // getFramerateLimit()
|
||||
public String methodDesc() { return "()I"; }
|
||||
|
||||
public void inject(ClassNode clazz, MethodNode main) {
|
||||
// InsnList insnList = new InsnList();
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// main.instructions.insert(insnList);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class TickPatch implements IInjector, Opcodes {
|
||||
public String name() { return "TickPatch"; }
|
||||
public String targetClass() { return "net.minecraft.client.Minecraft"; }
|
||||
public String methodName() { return "func_71407_l"; } // tick()
|
||||
public String methodDesc() { return "()V"; }
|
||||
|
||||
public void inject(ClassNode clazz, MethodNode main) {
|
||||
// InsnList insnList = new InsnList();
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// insnList.add(new InsnNode(POP));
|
||||
// main.instructions.insert(insnList);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,2 +1 @@
|
|||
ftbsc.bscv.patches.TestPatch$FramerateFix
|
||||
ftbsc.bscv.patches.TestPatch$TickPatch
|
||||
ftbsc.bscv.patches.PacketPatch$IncomingPacketInterceptor
|
||||
|
|
Loading…
Reference in a new issue