Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Jun 9, 2024
1 parent b0ad615 commit e323efb
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.tonimatas.packetfixer.util.Config;
import dev.tonimatas.packetfixer.util.Hooks;
import dev.tonimatas.packetfixer.util.MixinCheck;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand All @@ -21,14 +22,16 @@ public String getRefMapperConfig() {
return null;
}

@SuppressWarnings("UnreachableCode")
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
boolean connectivity = Hooks.isModLoaded("connectivity");
boolean krypton = Hooks.isModLoaded("krypton") || Hooks.isModLoaded("pluto");

if (mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.CompressionDecoderMixin")) return !connectivity;
if (mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.compat.connectivity.CompressionDecoderMixin")) return connectivity;
if (mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.SplitterHandlerMixin") || mixinClassName.equalsIgnoreCase("dev.tonimatas.packetfixer.mixins.SizePrependerMixin")) return !krypton;
if (MixinCheck.with(mixinClassName, "CompressionDecoderMixin")) return !connectivity;
if (MixinCheck.with(mixinClassName, "compat.connectivity.CompressionDecoderMixin")) return connectivity;
if (MixinCheck.with(mixinClassName, "Varint21FrameDecoderMixin") ||
MixinCheck.with(mixinClassName, "Varint21LengthFieldPrependerMixin")) return !krypton;

return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.tonimatas.packetfixer.mixins;

import dev.tonimatas.packetfixer.util.Config;
import net.minecraft.network.Varint21FrameDecoder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(Varint21FrameDecoder.class)
public class Varint21FrameDecoderMixin {
@ModifyConstant(method = "decode", constant = @Constant(intValue = 3))
private int newSize(int value) {
return Config.getVarInt21Size();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.tonimatas.packetfixer.mixins;

import dev.tonimatas.packetfixer.util.Config;
import net.minecraft.network.Varint21LengthFieldPrepender;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = Varint21LengthFieldPrepender.class, priority = 9999)
public class Varint21LengthFieldPrependerMixin {
@ModifyConstant(method = "encode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Lio/netty/buffer/ByteBuf;)V", constant = @Constant(intValue = 3))
private int newSize(int value) {
return Config.getVarInt21Size();
}
}
46 changes: 38 additions & 8 deletions common/src/main/java/dev/tonimatas/packetfixer/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,37 @@

public class Config {
private static Properties properties = null;


@SuppressWarnings("ResultOfMethodCallIgnored")
public static void runProperties() {
try {
File propertiesFile = new File(new File("config"), "packetfixer.properties");
File configFolder = new File("config");

if (!configFolder.exists()) {
configFolder.mkdirs();
}

File propertiesFile = new File(configFolder, "packetfixer.properties");
properties = new Properties();

if (!propertiesFile.exists()) {
propertiesFile.createNewFile();

properties.setProperty("nbtMaxSize", Long.toString(2097152 * 100));
properties.setProperty("packetSize", Integer.toString(1048576 * 100));
properties.setProperty("decoderSize", Integer.toString(8388608 * 100));
properties.store(Files.newOutputStream(propertiesFile.toPath()),
"Packet Fixer config file.\n" +
"Default values (minecraft default): nbtMaxSize 2097152, packetSize 1048576 and decoderSize 2097152.\n" +
"Max values are " + Integer.MAX_VALUE + " for packetSize/decoderSize and " + Long.MAX_VALUE + " for nbtMaxSize.");
properties.setProperty("varInt21", Integer.toString(8));

save(propertiesFile);
}

properties.load(Files.newInputStream(propertiesFile.toPath()));

checkVariable("nbtMaxSize", Long.toString(2097152 * 100));
checkVariable("packetSize", Integer.toString(1048576 * 100));
checkVariable("decoderSize", Integer.toString(8388608 * 100));
checkVariable("varInt21", Integer.toString(8));
save(propertiesFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -45,4 +57,22 @@ public static int getDecoderSize() {
if (properties == null) runProperties();
return Integer.parseInt(properties.getProperty("decoderSize"));
}

public static int getVarInt21Size() {
if (properties == null) runProperties();
return Integer.parseInt(properties.getProperty("varInt21"));
}

private static void checkVariable(String variable, String defaultValue) {
if (properties.getProperty(variable) == null) {
properties.setProperty(variable, defaultValue);
}
}

private static void save(File propertiesFile) throws IOException {
properties.store(Files.newOutputStream(propertiesFile.toPath()),
"Packet Fixer config file.\n" +
"Default values (minecraft default): nbtMaxSize 2097152, packetSize 1048576, decoderSize 2097152 and varInt21Size 3.\n" +
"Max values are " + Integer.MAX_VALUE + " for packetSize/decoderSize/varInt21 and " + Long.MAX_VALUE + " for nbtMaxSize.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.tonimatas.packetfixer.util;

public class MixinCheck {
public static boolean with(String mixinClassName, String mixinName) {
return mixinClassName.equals("dev.tonimatas.packetfixer.mixins." + mixinName);
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/packetfixer-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"PacketEncoderMixin",
"ServerboundCustomPayloadPacketMixin",
"ServerboundCustomQueryPacketMixin",
"Varint21FrameDecoderMixin",
"Varint21LengthFieldPrependerMixin",
"compat.connectivity.CompressionDecoderMixin"
],
"client": [
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

# Mod Properties
modVersion=1.4.0
modVersion=1.4.1

# Minecraft
minecraftVersion=1.18.2
Expand Down

0 comments on commit e323efb

Please sign in to comment.