diff --git a/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java b/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java index 5f8cc1f8..13edb1f3 100644 --- a/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java @@ -77,6 +77,7 @@ public class LoadingConfig { public boolean fixNetHandlerPlayClientHandleSetSlot; public boolean fixNetherLeavesFaceRendering; public boolean fixNorthWestBias; + public boolean fixNettyNPE; public boolean fixOptifineChunkLoadingCrash; public boolean fixPerspectiveCamera; public boolean fixPlayerSkinFetching; @@ -269,6 +270,7 @@ public LoadingConfig(File file) { fixNetHandlerPlayClientHandleSetSlot = config.get(Category.FIXES.toString(), "fixNetHandlerPlayClientHandleSetSlot", true, "Prevents crash if server sends itemStack with index larger than client's container").getBoolean(); fixNetherLeavesFaceRendering = config.get(Category.FIXES.toString(), "fixNetherLeavesFaceRendering", true, "If fancy graphics are enabled, Nether Leaves render sides with other Nether Leaves adjacent too").getBoolean(); fixNorthWestBias = config.get(Category.FIXES.toString(), "fixNorthWestBias", true, "Fix northwest bias on RandomPositionGenerator").getBoolean(); + fixNettyNPE = config.get(Category.FIXES.toString(), "fixNettyNPE", true, "Fix NPE in Netty's Bootstrap class").getBoolean(); fixOptifineChunkLoadingCrash = config.get(Category.FIXES.toString(), "fixOptifineChunkLoadingCrash", true, "Forces the chunk loading option from optifine to default since other values can crash the game").getBoolean(); fixPerspectiveCamera = config.get(Category.FIXES.toString(), "fixPerspectiveCamera", true, "Prevent tall grass and such to affect the perspective camera").getBoolean(); fixPlayerSkinFetching = config.get(Category.FIXES.toString(), "fixPlayerSkinFetching", true, "Allow some mods to properly fetch the player skin").getBoolean(); diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index 1b605c37..d030e939 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -269,6 +269,9 @@ public enum Mixins { COMPACT_CHAT(new Builder("Compact chat").setPhase(Phase.EARLY) .addMixinClasses("minecraft.MixinGuiNewChat_CompactChat").setSide(Side.CLIENT) .setApplyIf(() -> Common.config.compactChat).addTargetedMod(TargetedMod.VANILLA)), + NETTY_PATCH(new Builder("Fix NPE in Netty's Bootstrap class").addMixinClasses("netty.MixinBootstrap") + .setPhase(Phase.EARLY).setSide(Side.CLIENT).setApplyIf(() -> Common.config.fixNettyNPE) + .addTargetedMod(TargetedMod.VANILLA)), // Ic2 adjustments IC2_UNPROTECTED_GET_BLOCK_FIX( diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/netty/MixinBootstrap.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/netty/MixinBootstrap.java new file mode 100644 index 00000000..8d41ab45 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/netty/MixinBootstrap.java @@ -0,0 +1,33 @@ +package com.mitchej123.hodgepodge.mixins.early.netty; + +import java.net.InetAddress; +import java.net.SocketAddress; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.ChannelFuture; + +@Mixin(Bootstrap.class) +public class MixinBootstrap { + + @Inject( + method = "checkAddress", + remap = false, + at = @At( + value = "INVOKE", + target = "Ljava/net/InetAddress;getHostAddress()Ljava/lang/String;", + shift = At.Shift.BEFORE), + locals = LocalCapture.CAPTURE_FAILSOFT, + cancellable = true) + private void hodgpodge$fixNPE(SocketAddress remoteAddress, CallbackInfoReturnable cir, + InetAddress address) { + if (address == null) { + cir.setReturnValue(null); + } + } +}