Skip to content

Commit

Permalink
Move NettyPatcher fix to Hodgepodge (GTNewHorizons#265)
Browse files Browse the repository at this point in the history
* translate NettyPatch to mixins
  • Loading branch information
Alexdoru authored Oct 22, 2023
1 parent fec9b71 commit a79c638
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ChannelFuture> cir,
InetAddress address) {
if (address == null) {
cir.setReturnValue(null);
}
}
}

0 comments on commit a79c638

Please sign in to comment.