diff --git a/build.gradle b/build.gradle index cc85438..914df4c 100644 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ tasks.named('jar', Jar).configure { 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), - 'MixinConfigs': 'mixins.duble.json' + 'MixinConfigs': 'mixins.packetdoubler.json' ]) } diff --git a/gradle.properties b/gradle.properties index 34fdce2..89c581d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,12 +48,12 @@ mod_name=Packet size doubler InCube # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=MIT # The mod version. See https://semver.org/ -mod_version=0.1 +mod_version=1.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html mod_group_id=ru.vkprofi.packetDoubler # The authors of the mod. This is a simple text string that is used for display purposes in the mod list. -mod_authors=VkProfi +mod_authors=VkProfi, Silke # The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. -mod_description=Мод добавляющий отпечатки пальца в игру маинкрафт \ No newline at end of file +mod_description=Мод увеличивающий размер пакетов \ No newline at end of file diff --git a/src/main/java/ru/vkprofi/packetDoubler/ExampleMod.java b/src/main/java/ru/vkprofi/packetDoubler/ExampleMod.java deleted file mode 100644 index a8da1b5..0000000 --- a/src/main/java/ru/vkprofi/packetDoubler/ExampleMod.java +++ /dev/null @@ -1,23 +0,0 @@ -package ru.vkprofi.packetDoubler; - -import com.mojang.logging.LogUtils; -import net.minecraftforge.event.server.ServerStartingEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.common.Mod; -import org.slf4j.Logger; - -// The value here should match an entry in the META-INF/mods.toml file -@Mod(ExampleMod.MODID) -public class ExampleMod { - // Define mod id in a common place for everything to reference - public static final String MODID = "Fingerprint"; - // Directly reference a slf4j logger - private static final Logger LOGGER = LogUtils.getLogger(); - - // You can use SubscribeEvent and let the Event Bus discover methods to call - @SubscribeEvent - public void onServerStarting(ServerStartingEvent event) { - // Do something when the server starts - LOGGER.info("HELLO from server starting"); - } -} diff --git a/src/main/java/ru/vkprofi/packetDoubler/Main.java b/src/main/java/ru/vkprofi/packetDoubler/Main.java new file mode 100644 index 0000000..0da0553 --- /dev/null +++ b/src/main/java/ru/vkprofi/packetDoubler/Main.java @@ -0,0 +1,18 @@ +package ru.vkprofi.packetdoubler; + +import com.mojang.logging.LogUtils; +import net.minecraftforge.event.server.ServerStartingEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; +import org.slf4j.Logger; + +@Mod(Main.MODID) +public class Main { + public static final String MODID = "PackerDoubler"; + private static final Logger LOGGER = LogUtils.getLogger(); + + @SubscribeEvent + public void onServerStarting(ServerStartingEvent event) { + LOGGER.info(MODID + " started"); + } +} diff --git a/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketDecoderMixin.java b/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketDecoderMixin.java new file mode 100644 index 0000000..658dd43 --- /dev/null +++ b/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketDecoderMixin.java @@ -0,0 +1,55 @@ +package ru.vkprofi.packetdoubler.mixin; + +import com.mojang.logging.LogUtils; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import net.minecraft.network.Connection; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.PacketDecoder; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.PacketFlow; +import net.minecraft.util.profiling.jfr.JvmProfiler; +import org.slf4j.Logger; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; + +import java.io.IOException; +import java.util.List; + +@Mixin(PacketDecoder.class) +public abstract class PacketDecoderMixin extends ByteToMessageDecoder { + @Unique + private static final Logger LOGGER = LogUtils.getLogger(); + + @Final @Shadow + private PacketFlow flow; + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { + int i = in.readableBytes(); + if (i != 0) { + FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(in); + int j = friendlybytebuf.readVarInt(); + Packet packet = ctx.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().createPacket(this.flow, j, friendlybytebuf); + if (packet == null) { + throw new IOException("Bad packet id " + j); + } else { + int k = ctx.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().getId(); + JvmProfiler.INSTANCE.onPacketReceived(k, j, ctx.channel().remoteAddress(), i); + if (friendlybytebuf.readableBytes() > 0) { + // Разрешаем пакеты с большим количеством читаемых байтов + if (friendlybytebuf.readableBytes() > 83886080) { + throw new IOException("Packet " + ctx.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get().getId() + "/" + j + " (" + packet.getClass().getSimpleName() + ") was larger than I expected, found " + friendlybytebuf.readableBytes() + " bytes extra whilst reading packet " + j); + } + } + out.add(packet); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(Connection.PACKET_RECEIVED_MARKER, " IN: [{}:{}] {}", ctx.channel().attr(Connection.ATTRIBUTE_PROTOCOL).get(), j, packet.getClass().getName()); + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketEncoderMixin.java b/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketEncoderMixin.java index 936d380..bb26938 100644 --- a/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketEncoderMixin.java +++ b/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketEncoderMixin.java @@ -1,4 +1,4 @@ -package ru.vkprofi.packetDoubler.mixin; +package ru.vkprofi.packetdoubler.mixin; import net.minecraft.network.PacketEncoder; import org.spongepowered.asm.mixin.Mixin; @@ -7,9 +7,8 @@ @Mixin(PacketEncoder.class) public class PacketEncoderMixin { - @ModifyConstant(method = "encode(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;Lio/netty/buffer/ByteBuf;)V", constant = @Constant(intValue = 8388608)) + @ModifyConstant(method = "encode(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/protocol/Packet;Lio/netty/buffer/ByteBuf;)V", constant = @Constant(intValue = 8388608)) private int injected(int value) { return value * 10; } - } diff --git a/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketInflaterMixin.java b/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketInflaterMixin.java deleted file mode 100644 index d56c0df..0000000 --- a/src/main/java/ru/vkprofi/packetDoubler/mixin/PacketInflaterMixin.java +++ /dev/null @@ -1,14 +0,0 @@ -package ru.vkprofi.packetDoubler.mixin; - -import net.minecraft.network.PacketDecoder; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Constant; -import org.spongepowered.asm.mixin.injection.ModifyConstant; - -@Mixin(PacketDecoder.class) -public class PacketInflaterMixin { - @ModifyConstant(method = "decode", constant = @Constant(intValue = 8388608)) - private int injected(int value) { - return value * 10; - } -} diff --git a/src/main/resources/mixins.duble.json b/src/main/resources/mixins.packetdoubler.json similarity index 70% rename from src/main/resources/mixins.duble.json rename to src/main/resources/mixins.packetdoubler.json index 8496d1d..c1cfff1 100644 --- a/src/main/resources/mixins.duble.json +++ b/src/main/resources/mixins.packetdoubler.json @@ -1,15 +1,15 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "ru.vkprofi.packetDoubler.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "PacketEncoderMixin", - "PacketInflaterMixin" - ], - "client": [ - ], - "injectors": { - "defaultRequire": 1 - } +{ + "required": true, + "minVersion": "0.8", + "package": "ru.vkprofi.packetdoubler.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "PacketEncoderMixin", + "PacketDecoderMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } } \ No newline at end of file