-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
You
committed
Oct 14, 2024
1 parent
2099930
commit 57f9189
Showing
10 changed files
with
104 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 18 additions & 69 deletions
87
fabric/src/main/java/io/github/retrooper/packetevents/injector/CustomPipelineUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,35 @@ | ||
package io.github.retrooper.packetevents.injector; | ||
|
||
import com.github.retrooper.packetevents.util.reflection.Reflection; | ||
import io.github.retrooper.packetevents.mixin.CompressionDecoderMixin; | ||
import io.github.retrooper.packetevents.mixin.CompressionEncoderMixin; | ||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CustomPipelineUtil { | ||
private static Method DECODE_METHOD; | ||
private static Method ENCODE_METHOD; | ||
private static Method MTM_DECODE; | ||
private static Method MTM_ENCODE; | ||
|
||
public static void init() { | ||
try { | ||
Class<?> compressionDecoderClass = Reflection.getClassByNameWithoutException("net.minecraft.network.CompressionDecoder"); | ||
DECODE_METHOD = compressionDecoderClass.getDeclaredMethod("decode", ChannelHandlerContext.class, ByteBuf.class, List.class); | ||
DECODE_METHOD.setAccessible(true); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
Class<?> compressionDecoderClass = Reflection.getClassByNameWithoutException("net.minecraft.network.CompressionEncoder"); | ||
ENCODE_METHOD = compressionDecoderClass.getDeclaredMethod("encode", ChannelHandlerContext.class, ByteBuf.class, ByteBuf.class); | ||
ENCODE_METHOD.setAccessible(true); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
Class<?> messageToMessageDecoderClass = Reflection.getClassByNameWithoutException("io.netty.handler.codec.MessageToMessageDecoder"); | ||
MTM_DECODE = messageToMessageDecoderClass.getDeclaredMethod("decode", ChannelHandlerContext.class, Object.class, List.class); | ||
MTM_DECODE.setAccessible(true); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
Class<?> messageToMessageDecoderClass = Reflection.getClassByNameWithoutException("io.netty.handler.codec.MessageToMessageEncoder"); | ||
MTM_ENCODE = messageToMessageDecoderClass.getDeclaredMethod("encode", ChannelHandlerContext.class, Object.class, List.class); | ||
MTM_ENCODE.setAccessible(true); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static List<Object> callDecode(Object decoder, Object ctx, Object input) throws InvocationTargetException { | ||
public static List<Object> callDecode(CompressionDecoderMixin decoder, ChannelHandlerContext ctx, ByteBuf input) { | ||
List<Object> output = new ArrayList<>(); | ||
try { | ||
CustomPipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
decoder.decode(ctx, input, output); | ||
return output; | ||
} | ||
|
||
public static void callEncode(Object encoder, Object ctx, Object msg, Object output) throws InvocationTargetException { | ||
try { | ||
CustomPipelineUtil.ENCODE_METHOD.invoke(encoder, ctx, msg, output); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static List<Object> callMTMEncode(Object encoder, Object ctx, Object msg) { | ||
List<Object> output = new ArrayList<>(); | ||
try { | ||
MTM_ENCODE.invoke(encoder, ctx, msg, output); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
return output; | ||
public static void callEncode(CompressionEncoderMixin encoder, ChannelHandlerContext ctx, ByteBuf msg, ByteBuf output) { | ||
encoder.encode(ctx, msg, output); | ||
} | ||
|
||
public static List<Object> callMTMDecode(Object decoder, Object ctx, Object msg) throws InvocationTargetException { | ||
List<Object> output = new ArrayList<>(); | ||
try { | ||
MTM_DECODE.invoke(decoder, ctx, msg, output); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
return output; | ||
} | ||
} | ||
// public static List<Object> callMTMEncode(MessageToMessageEncoder<?> encoder, ChannelHandlerContext ctx, Object msg) { | ||
// List<Object> output = new ArrayList<>(); | ||
// encoder.encode(ctx, msg, output); | ||
// return output; | ||
// } | ||
// | ||
// public static List<Object> callMTMDecode(MessageToMessageDecoder<?> decoder, ChannelHandlerContext ctx, Object msg) { | ||
// List<Object> output = new ArrayList<>(); | ||
// decoder.decode(ctx, msg, output); | ||
// return output; | ||
// } | ||
} |
13 changes: 13 additions & 0 deletions
13
fabric/src/main/java/io/github/retrooper/packetevents/mixin/CompressionDecoderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.retrooper.packetevents.mixin; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import java.util.List; | ||
import net.minecraft.network.CompressionDecoder; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(CompressionDecoder.class) | ||
public interface CompressionDecoderMixin { | ||
@Invoker("decode") void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out); | ||
} |
12 changes: 12 additions & 0 deletions
12
fabric/src/main/java/io/github/retrooper/packetevents/mixin/CompressionEncoderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.retrooper.packetevents.mixin; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import net.minecraft.network.CompressionEncoder; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(CompressionEncoder.class) | ||
public interface CompressionEncoderMixin { | ||
@Invoker("encode") void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out); | ||
} |
12 changes: 12 additions & 0 deletions
12
...ic/src/main/java/io/github/retrooper/packetevents/mixin/MessageToMessageDecoderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.retrooper.packetevents.mixin; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.MessageToMessageDecoder; | ||
import java.util.List; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(MessageToMessageDecoder.class) | ||
public interface MessageToMessageDecoderMixin { | ||
@Invoker("decode") void decode(ChannelHandlerContext ctx, Object msg, List<Object> out); | ||
} |
12 changes: 12 additions & 0 deletions
12
...ic/src/main/java/io/github/retrooper/packetevents/mixin/MessageToMessageEncoderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.retrooper.packetevents.mixin; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.MessageToMessageEncoder; | ||
import java.util.List; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Invoker; | ||
|
||
@Mixin(MessageToMessageEncoder.class) | ||
public interface MessageToMessageEncoderMixin { | ||
@Invoker("encode") void encode(ChannelHandlerContext ctx, Object msg, List<Object> out); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters