19w02a, experimental splitterhandler optimization

This commit is contained in:
creeper123123321 2019-01-12 14:38:52 -02:00
parent b4f69a6e8e
commit fa5dbe6f08
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
6 changed files with 92 additions and 11 deletions

View File

@ -35,17 +35,17 @@ configurations {
}
dependencies {
shade('us.myles:viaversion:2.0.0-18w50a') {
shade('us.myles:viaversion:2.0.0-19w02a') {
transitive = false
changing = true
}
minecraft "com.mojang:minecraft:18w50a"
mappings "net.fabricmc:yarn:18w50a.64"
modCompile "net.fabricmc:fabric-loader:0.3.0.74"
minecraft "com.mojang:minecraft:19w02a"
mappings "net.fabricmc:yarn:19w02a.12"
modCompile "net.fabricmc:fabric-loader:0.3.2.92"
// Fabric API. This is technically optional, but you probably want it anyway.
modCompile "net.fabricmc:fabric:0.1.2.63"
modCompile "net.fabricmc:fabric:0.1.4.71"
}
jar {

View File

@ -100,9 +100,9 @@ public class VRDecodeHandler extends ByteToMessageDecoder {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
//try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
super.channelRead(ctx, msg);
}
//}
}
@Override

View File

@ -110,8 +110,8 @@ public class VREncodeHandler extends MessageToByteEncoder {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
//try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
super.write(ctx, msg, promise);
}
//}
}
}

View File

@ -0,0 +1,80 @@
/*
* MIT License
*
* Copyright (c) 2018 creeper123123321 and contributors
*
* 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:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* 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.
*/
package com.github.creeper123123321.viafabric.mixin.client;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.CorruptedFrameException;
import net.minecraft.network.SplitterHandler;
import net.minecraft.util.PacketByteBuf;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import us.myles.ViaVersion.api.type.Type;
import java.util.List;
@Mixin(SplitterHandler.class)
public class MixinSplitterHandler {
/**
* Based on https://github.com/VelocityPowered/Velocity/blob/master/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftVarintFrameDecoder.java
*
* @reason optimization
* @author creeper123123321
*/
@Overwrite(remap = false)
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (!in.isReadable()) {
return;
}
int origReaderIndex = in.readerIndex();
for (int i = 0; i < 3; i++) {
if (!in.isReadable()) {
in.readerIndex(origReaderIndex);
return;
}
byte read = in.readByte();
if (read >= 0) {
// Make sure reader index of length buffer is returned to the beginning
in.readerIndex(origReaderIndex);
int packetLength = Type.VAR_INT.read(in);
if (packetLength == 0) {
return;
}
if (in.readableBytes() < packetLength) {
in.readerIndex(origReaderIndex);
return;
}
out.add(in.readRetainedSlice(packetLength));
return;
}
}
throw new CorruptedFrameException("VarInt too big");
}
}

View File

@ -24,7 +24,7 @@
package com.github.creeper123123321.viafabric.platform;
import net.minecraft.client.settings.ServerEntry;
import net.minecraft.client.options.ServerEntry;
import us.myles.ViaVersion.api.platform.ViaInjector;
public class VRInjector implements ViaInjector {

View File

@ -6,7 +6,8 @@
],
"client": [
"client.MixinClientConnectionChInit",
"client.MixinMultiplayerGui"
"client.MixinMultiplayerGui",
"client.MixinSplitterHandler"
],
"injectors": {
"defaultRequire": 1