├── LICENSE ├── README.md ├── build.gradle └── src └── main └── java └── net └── kohi └── tcpnodelaymod ├── ClassTransformer.java ├── NetworkManagerInnerVisitor.java └── TcpNoDelayTweaker.java /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | Copyright (c) 2016 Kohi Network 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TcpNoDelayMod 2 | 3 | A forge mod for minecraft 1.7.2, 1.7.10 and 1.8 that sets TCP_NODELAY to true, instead of the regular false. This reduces ingame latency and gives a smoother gameplay experience. 4 | 5 | This mod is not needed in 1.8.1 and later as minecraft already has this change. 6 | 7 | The mod transforms an inner class of `net.minecraft.network.NetworkManager`, essentially doing the following: 8 | ```diff 9 | protected void initChannel(Channel p_initChannel_1_) 10 | { 11 | try 12 | { 13 | p_initChannel_1_.config().setOption(ChannelOption.IP_TOS, Integer.valueOf(24)); 14 | } 15 | catch (ChannelException var4) 16 | { 17 | ; 18 | } 19 | 20 | try 21 | { 22 | - p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(false)); 23 | + p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true)); 24 | } 25 | catch (ChannelException var3) 26 | { 27 | ; 28 | } 29 | 30 | p_initChannel_1_.pipeline().addLast("timeout", new ReadTimeoutHandler(20)).addLast("splitter", new MessageDeserializer2()).addLast("decoder", new MessageDeserializer(NetworkManager.field_152462_h)).addLast("prepender", new MessageSerializer2()).addLast("encoder", new MessageSerializer(NetworkManager.field_152462_h)).addLast("packet_handler", var2); 31 | } 32 | ``` 33 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { 5 | name = "forge" 6 | url = "http://files.minecraftforge.net/maven" 7 | } 8 | maven { 9 | name = "sonatype" 10 | url = "https://oss.sonatype.org/content/repositories/snapshots/" 11 | } 12 | } 13 | dependencies { 14 | classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' 15 | } 16 | } 17 | 18 | apply plugin: 'forge' 19 | 20 | compileJava { 21 | sourceCompatibility = 1.6 22 | targetCompatibility = 1.6 23 | } 24 | 25 | version = "2.0" 26 | group = "net.kohi" 27 | 28 | minecraft { 29 | version = "1.7.10-10.13.4.1558-1.7.10" 30 | runDir = "eclipse" 31 | } 32 | 33 | dependencies { 34 | 35 | } 36 | 37 | jar { 38 | manifest { 39 | attributes("TweakClass": "net.kohi.tcpnodelaymod.TcpNoDelayTweaker") 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/net/kohi/tcpnodelaymod/ClassTransformer.java: -------------------------------------------------------------------------------- 1 | package net.kohi.tcpnodelaymod; 2 | 3 | import net.minecraft.launchwrapper.IClassTransformer; 4 | import org.objectweb.asm.ClassReader; 5 | import org.objectweb.asm.ClassVisitor; 6 | import org.objectweb.asm.ClassWriter; 7 | 8 | public class ClassTransformer implements IClassTransformer { 9 | 10 | @Override 11 | public byte[] transform(String name, String transformedName, byte[] bytes) { 12 | if (bytes == null) { 13 | return null; 14 | } 15 | // check for any inner classes of NetworkManager. It differes between mc versions 16 | if (transformedName.startsWith("net.minecraft.network.NetworkManager$")) { 17 | try { 18 | ClassReader classReader = new ClassReader(bytes); 19 | ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES); 20 | ClassVisitor classVisitor = new NetworkManagerInnerVisitor(classWriter); 21 | classReader.accept(classVisitor, ClassReader.SKIP_FRAMES); 22 | return classWriter.toByteArray(); 23 | } catch (Exception ex) { 24 | throw new RuntimeException(ex); 25 | } 26 | } 27 | return bytes; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/kohi/tcpnodelaymod/NetworkManagerInnerVisitor.java: -------------------------------------------------------------------------------- 1 | package net.kohi.tcpnodelaymod; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.objectweb.asm.ClassVisitor; 5 | import org.objectweb.asm.MethodVisitor; 6 | import org.objectweb.asm.Opcodes; 7 | 8 | public class NetworkManagerInnerVisitor extends ClassVisitor { 9 | 10 | public NetworkManagerInnerVisitor(ClassVisitor classVisitor) { 11 | super(Opcodes.ASM4, classVisitor); 12 | } 13 | 14 | @Override 15 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 16 | MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); 17 | if (name.equals("initChannel")) { 18 | return new MethodVisitor(Opcodes.ASM4, mv) { 19 | private String option; 20 | 21 | @Override 22 | public void visitFieldInsn(int opcode, String owner, String name, String desc) { 23 | if (opcode == Opcodes.GETSTATIC && 24 | owner.equals("io/netty/channel/ChannelOption") && 25 | desc.equals("Lio/netty/channel/ChannelOption;")) { 26 | option = name; 27 | } 28 | mv.visitFieldInsn(opcode, owner, name, desc); 29 | } 30 | 31 | @Override 32 | public void visitMethodInsn(int opcode, String owner, String name, String desc) { 33 | if (opcode == Opcodes.INVOKEINTERFACE && 34 | owner.equals("io/netty/channel/ChannelConfig") && 35 | name.equals("setOption") && 36 | desc.equals("(Lio/netty/channel/ChannelOption;Ljava/lang/Object;)Z")) { 37 | if (option.equals("TCP_NODELAY")) { 38 | LogManager.getLogger("TcpNoDelayMod").info("Setting TCP_NODELAY to true"); 39 | mv.visitInsn(Opcodes.POP); 40 | mv.visitInsn(Opcodes.ICONST_1); 41 | mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;"); 42 | mv.visitMethodInsn(opcode, owner, name, desc); 43 | return; 44 | } 45 | } 46 | mv.visitMethodInsn(opcode, owner, name, desc); 47 | } 48 | }; 49 | } 50 | return mv; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/kohi/tcpnodelaymod/TcpNoDelayTweaker.java: -------------------------------------------------------------------------------- 1 | package net.kohi.tcpnodelaymod; 2 | 3 | import net.minecraft.launchwrapper.ITweaker; 4 | import net.minecraft.launchwrapper.LaunchClassLoader; 5 | 6 | import java.io.File; 7 | import java.util.List; 8 | 9 | public class TcpNoDelayTweaker implements ITweaker { 10 | 11 | @Override 12 | public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { 13 | } 14 | 15 | @Override 16 | public void injectIntoClassLoader(LaunchClassLoader classLoader) { 17 | classLoader.registerTransformer(ClassTransformer.class.getName()); 18 | } 19 | 20 | @Override 21 | public String getLaunchTarget() { 22 | return null; 23 | } 24 | 25 | @Override 26 | public String[] getLaunchArguments() { 27 | return new String[0]; 28 | } 29 | } 30 | --------------------------------------------------------------------------------