From b69e4fc995a6be2f0fc60f7ea6929979d596ecbe Mon Sep 17 00:00:00 2001 From: jchung01 Date: Wed, 19 Jun 2024 15:21:23 -0700 Subject: [PATCH 1/5] Implement CCL packet fix --- build.gradle | 2 +- .../universaltweaks/core/UTMixinLoader.java | 2 + .../mixin/UTPacketCustomClientMixin.java | 25 ++++++ .../mixin/UTPacketCustomReleaseMixin.java | 26 ++++++ .../mixin/UTPacketCustomRetainMixin.java | 90 +++++++++++++++++++ .../mixin/UTPacketCustomServerMixin.java | 25 ++++++ .../resources/mixins.mods.codechickenlib.json | 7 ++ 7 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomClientMixin.java create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomReleaseMixin.java create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomServerMixin.java create mode 100644 src/main/resources/mixins.mods.codechickenlib.json diff --git a/build.gradle b/build.gradle index 21534757..46a7ca56 100644 --- a/build.gradle +++ b/build.gradle @@ -142,6 +142,7 @@ dependencies { compileOnly rfg.deobf('curse.maven:ceramics-250617:3158763') compileOnly rfg.deobf('curse.maven:chameleon-230497:2450900') compileOnly rfg.deobf('curse.maven:chickens-241941:2537643') + compileOnly rfg.deobf('curse.maven:codechickenlib-242818:2779848') compileOnly rfg.deobf('curse.maven:collective-342584:3533131') compileOnly rfg.deobf('curse.maven:cqrepoured-303422:3953103') compileOnly rfg.deobf('curse.maven:elementary-staffs-346007:2995593') @@ -177,7 +178,6 @@ dependencies { compileOnly 'curse.maven:arcanearchives-311357:3057332' compileOnly 'curse.maven:bewitchment-285439:3044569' compileOnly 'curse.maven:chisel-235279:2915375' - compileOnly 'curse.maven:codechickenlib-242818:2779848' compileOnly 'curse.maven:cofhworld-271384:2920434' compileOnly 'curse.maven:compactmachines-224218:2707509' compileOnly 'curse.maven:effortlessbuilding-302113:2847346' diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 7baab647..8d772bf3 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -46,6 +46,8 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.cbmultipart.json", () -> loaded("forgemultipartcbe") && UTConfigMods.CB_MULTIPART.utMemoryLeakFixToggle); put("mixins.mods.ceramics.json", () -> loaded("ceramics")); put("mixins.mods.chisel.tcomplement.dupes.json", () -> loaded("chisel") && loaded("tcomplement") && UTConfigMods.CHISEL.utDuplicationFixesToggle); + // TODO: add config + put("mixins.mods.codechickenlib.json", () -> loaded("codechickenlib")); put("mixins.mods.cofhcore.json", () -> loaded("cofhcore")); put("mixins.mods.collective.json", () -> loaded("collective")); put("mixins.mods.cqrepoured.json", () -> loaded("cqrepoured")); diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomClientMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomClientMixin.java new file mode 100644 index 00000000..07199d00 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomClientMixin.java @@ -0,0 +1,25 @@ +package mod.acgaming.universaltweaks.mods.codechickenlib.mixin; + +import codechicken.lib.packet.PacketCustom; +import net.minecraft.network.INetHandler; +import org.apache.commons.lang3.Validate; +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.CallbackInfo; + +// Courtesy of jchung01 +@Mixin(value = PacketCustom.ClientInboundHandler.class, remap = false) +public class UTPacketCustomClientMixin +{ + /** + * This releases the COPIED ByteBuf that was created and assigned to PacketCustom.buf in the ctor. + * @reason Release wrapped ByteBuf after whatever mod has handled the packet. + */ + @Inject(method = "handle", at = @At(value = "INVOKE", target = "Lcodechicken/lib/packet/ICustomPacketHandler$IClientPacketHandler;handlePacket(Lcodechicken/lib/packet/PacketCustom;Lnet/minecraft/client/Minecraft;Lnet/minecraft/network/play/INetHandlerPlayClient;)V", shift = At.Shift.AFTER)) + private void utReleaseClientBuf(INetHandler netHandler, String channel, PacketCustom packet, CallbackInfo ci) + { + Validate.isTrue(packet.refCnt() == 1); + packet.release(); + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomReleaseMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomReleaseMixin.java new file mode 100644 index 00000000..4f92dfce --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomReleaseMixin.java @@ -0,0 +1,26 @@ +package mod.acgaming.universaltweaks.mods.codechickenlib.mixin; + +import codechicken.lib.packet.PacketCustom; +import io.netty.channel.ChannelHandlerContext; +import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; +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.CallbackInfo; + +// Courtesy of jchung01 +@Mixin(value = PacketCustom.CustomInboundHandler.class, remap = false) +public class UTPacketCustomReleaseMixin +{ + /** + * This releases the ORIGINAL FMLProxyPacket payload that was passed into and copied by PacketCustom's constructor. + *

+ * For S->C packets, some are reused and sent to multiple clients, so those packets are retained in {@link UTPacketCustomRetainMixin}. + * @reason Release the message's payload after everything has been handled. + */ + @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraftforge/fml/common/network/internal/FMLProxyPacket;)V", at = @At(value = "TAIL")) + private void utReleasePayload(ChannelHandlerContext ctx, FMLProxyPacket msg, CallbackInfo ci) + { + msg.payload().release(); + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java new file mode 100644 index 00000000..ea584ec1 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java @@ -0,0 +1,90 @@ +package mod.acgaming.universaltweaks.mods.codechickenlib.mixin; + +import java.util.List; +import java.util.function.Predicate; +import codechicken.lib.packet.PacketCustom; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.network.INetHandler; +import net.minecraft.network.Packet; +import net.minecraft.server.management.PlayerChunkMapEntry; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +/** + * This mixin retains PacketCustom payloads, increasing the ref count by the number of players + * that are to receive the packet. This is necessary as the payload is shared between all receivers + * and each receiver releases the payload in {@link UTPacketCustomReleaseMixin}. + * @author jchung01 + */ +@Mixin(value = PacketCustom.class, remap = false) +public abstract class UTPacketCustomRetainMixin +{ + @Shadow + public abstract boolean release(); + + @Inject(method = "sendToClients(Lnet/minecraft/network/Packet;)V", at = @At(value = "HEAD")) + private static void utRetainForAllClients(Packet packet, CallbackInfo ci) + { + ut$retainForPlayers(packet, player -> true); + } + + @Inject(method = "sendToAllAround", at = @At(value = "HEAD")) + private static void utRetainForAllAround(Packet packet, double x, double y, double z, double range, int dim, CallbackInfo ci) + { + ut$retainForPlayers(packet, player -> { + if (player.dimension != dim) return false; + double dx = player.posX - x; + double dy = player.posY - y; + double dz = player.posZ - z; + return dx * dx + dy * dy + dz * dz < range * range; + }); + } + + @Inject(method = "sendToDimension(Lnet/minecraft/network/Packet;I)V", at = @At(value = "HEAD")) + private static void utRetainForAllInDimension(Packet packet, int dim, CallbackInfo ci) + { + ut$retainForPlayers(packet, player -> player.dimension == dim); + } + + @Inject(method = "sendToChunk(Lnet/minecraft/network/Packet;Lnet/minecraft/world/World;II)V", at = @At(value = "HEAD")) + private static void utRetainForAllInChunk(Packet packet, World world, int chunkX, int chunkZ, CallbackInfo ci) + { + PlayerChunkMapEntry playersInChunk = ((WorldServer) world).getPlayerChunkMap().getEntry(chunkX, chunkZ); + if (playersInChunk != null) ut$retainForPlayers(packet, playersInChunk::containsPlayer); + } + + @Inject(method = "sendToOps(Lnet/minecraft/network/Packet;)V", at = @At(value = "HEAD")) + private static void utRetainForOps(Packet packet, CallbackInfo ci) + { + ut$retainForPlayers(packet, player -> FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().canSendCommands(player.getGameProfile())); + } + + /** + * Release this buf after copying it, just to be safe. + */ + @Inject(method = "toPacket", at = @At(value = "RETURN")) + private void utReleaseOriginal(CallbackInfoReturnable cir) + { + this.release(); + } + + @Unique + private static void ut$retainForPlayers(Packet packet, Predicate condition) + { + if (packet instanceof FMLProxyPacket) + { + List playerList = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers(); + int retainCount = (int) (playerList.stream().filter(condition).count() - 1); + if (retainCount > 0) ((FMLProxyPacket) packet).payload().retain(retainCount); + } + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomServerMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomServerMixin.java new file mode 100644 index 00000000..7bcc520c --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomServerMixin.java @@ -0,0 +1,25 @@ +package mod.acgaming.universaltweaks.mods.codechickenlib.mixin; + +import codechicken.lib.packet.PacketCustom; +import net.minecraft.network.INetHandler; +import org.apache.commons.lang3.Validate; +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.CallbackInfo; + +// Courtesy of jchung01 +@Mixin(value = PacketCustom.ServerInboundHandler.class, remap = false) +public class UTPacketCustomServerMixin +{ + /** + * This releases the COPIED ByteBuf that was created and assigned to PacketCustom.buf in the ctor. + * @reason Release wrapped ByteBuf after whatever mod has handled the packet. + */ + @Inject(method = "handle", at = @At(value = "INVOKE", target = "Lcodechicken/lib/packet/ICustomPacketHandler$IServerPacketHandler;handlePacket(Lcodechicken/lib/packet/PacketCustom;Lnet/minecraft/entity/player/EntityPlayerMP;Lnet/minecraft/network/play/INetHandlerPlayServer;)V", shift = At.Shift.AFTER)) + private void utReleaseServerBuf(INetHandler netHandler, String channel, PacketCustom packet, CallbackInfo ci) + { + Validate.isTrue(packet.refCnt() == 1); + packet.release(); + } +} diff --git a/src/main/resources/mixins.mods.codechickenlib.json b/src/main/resources/mixins.mods.codechickenlib.json new file mode 100644 index 00000000..f734c18c --- /dev/null +++ b/src/main/resources/mixins.mods.codechickenlib.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.codechickenlib.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTPacketCustomRetainMixin", "UTPacketCustomReleaseMixin", "UTPacketCustomClientMixin", "UTPacketCustomServerMixin"] +} \ No newline at end of file From 4bccf54b1b94ffc1865afb756923767298661328 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Wed, 19 Jun 2024 15:25:00 -0700 Subject: [PATCH 2/5] Implement EnderStorage fix for duplicate Frequencies in tank visibility set - Frequency overrode hashCode(), but not equals(), violating the Object equality contract --- build.gradle | 1 + .../universaltweaks/core/UTMixinLoader.java | 2 + .../enderstorage/mixin/UTFrequencyMixin.java | 45 +++++++++++++++++++ .../resources/mixins.mods.enderstorage.json | 7 +++ 4 files changed, 55 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/enderstorage/mixin/UTFrequencyMixin.java create mode 100644 src/main/resources/mixins.mods.enderstorage.json diff --git a/build.gradle b/build.gradle index 46a7ca56..1476f4bf 100644 --- a/build.gradle +++ b/build.gradle @@ -183,6 +183,7 @@ dependencies { compileOnly 'curse.maven:effortlessbuilding-302113:2847346' compileOnly 'curse.maven:endercore-231868:2972849' compileOnly 'curse.maven:enderio-64578:2989201' + compileOnly 'curse.maven:enderstorage-245174:2755787' compileOnly 'curse.maven:extrautilities-225561:2678374' compileOnly 'curse.maven:forgemultipartcbe-258426:2755790' // aka "CB Multipart" compileOnly 'curse.maven:guideapi-228832:2645992' diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 8d772bf3..d1018060 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -54,6 +54,8 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.effortlessbuilding.json", () -> loaded("effortlessbuilding")); put("mixins.mods.elementarystaffs.json", () -> loaded("element")); put("mixins.mods.elenaidodge2.json", () -> loaded("elenaidodge2")); + // TODO: add config + put("mixins.mods.enderstorage.json", () -> loaded("enderstorage")); put("mixins.mods.epicsiegemod.json", () -> loaded("epicsiegemod")); put("mixins.mods.erebus.cabbage.json", () -> loaded("erebus") && UTConfigMods.EREBUS.utCabbageDrop); put("mixins.mods.erebus.json", () -> loaded("erebus")); diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/enderstorage/mixin/UTFrequencyMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/enderstorage/mixin/UTFrequencyMixin.java new file mode 100644 index 00000000..d9342a56 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/enderstorage/mixin/UTFrequencyMixin.java @@ -0,0 +1,45 @@ +package mod.acgaming.universaltweaks.mods.enderstorage.mixin; + +import java.util.Objects; +import codechicken.enderstorage.api.Frequency; +import codechicken.lib.colour.EnumColour; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +// Courtesy of jchung01 +@Mixin(value = Frequency.class, remap = false) +public class UTFrequencyMixin +{ + @Shadow + public EnumColour left; + @Shadow + public EnumColour middle; + @Shadow + public EnumColour right; + @Shadow + public String owner; + + /** + * Add equals() override to fulfill Object equality contract. + */ + @Override + public boolean equals(Object o) + { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Frequency that = (Frequency) o; + return left == that.left && middle == that.middle && right == that.right && Objects.equals(owner, that.owner); + } + + /** + * @author jchung01 + * @reason Use a more proper hashCode method. + */ + @Override + @Overwrite + public int hashCode() + { + return Objects.hash(left, middle, right, owner); + } +} diff --git a/src/main/resources/mixins.mods.enderstorage.json b/src/main/resources/mixins.mods.enderstorage.json new file mode 100644 index 00000000..e92af765 --- /dev/null +++ b/src/main/resources/mixins.mods.enderstorage.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.enderstorage.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTFrequencyMixin"] +} \ No newline at end of file From a3e06cbef1fdf74de8117b4558677515780b8585 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Thu, 20 Jun 2024 13:08:14 -0700 Subject: [PATCH 3/5] Implement OC packet fix --- build.gradle | 1 + .../universaltweaks/core/UTMixinLoader.java | 2 ++ .../mixin/UTPacketHandlerMixin.java | 23 +++++++++++++++++++ .../resources/mixins.mods.opencomputers.json | 7 ++++++ 4 files changed, 33 insertions(+) create mode 100644 src/main/java/mod/acgaming/universaltweaks/mods/opencomputers/mixin/UTPacketHandlerMixin.java create mode 100644 src/main/resources/mixins.mods.opencomputers.json diff --git a/build.gradle b/build.gradle index 1476f4bf..a3d4226d 100644 --- a/build.gradle +++ b/build.gradle @@ -152,6 +152,7 @@ dependencies { compileOnly rfg.deobf('curse.maven:modtweaker-220954:3840577') compileOnly rfg.deobf('curse.maven:nuclearcraft-226254:3784145') compileOnly rfg.deobf('curse.maven:openblocks-228816:2699056') + implementation rfg.deobf('curse.maven:opencomputers-223008:5274236') compileOnly rfg.deobf('curse.maven:reborn-core-237903:3330308') compileOnly rfg.deobf('curse.maven:reskillable-286382:2815686') compileOnly rfg.deobf('curse.maven:requious-frakto-336748:3218640') diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index d1018060..2b131938 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -82,6 +82,8 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.netherrocks.json", () -> loaded("netherrocks")); put("mixins.mods.nuclearcraft.json", () -> loaded("nuclearcraft")); put("mixins.mods.openblocks.json", () -> loaded("openblocks") && UTConfigMods.OPEN_BLOCKS.utLastStandFixToggle); + // TODO: add config + put("mixins.mods.opencomputers.json", () -> loaded("opencomputers")); put("mixins.mods.quark.dupes.json", () -> loaded("quark") && UTConfigMods.QUARK.utDuplicationFixesToggle); put("mixins.mods.requiousfrakto.json", () -> loaded("requious") && UTConfigMods.REQUIOUS_FRAKTO.utParticleFixesToggle); put("mixins.mods.reskillable.json", () -> loaded("reskillable")); diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/opencomputers/mixin/UTPacketHandlerMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/opencomputers/mixin/UTPacketHandlerMixin.java new file mode 100644 index 00000000..172e0dd7 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/mods/opencomputers/mixin/UTPacketHandlerMixin.java @@ -0,0 +1,23 @@ +package mod.acgaming.universaltweaks.mods.opencomputers.mixin; + +import java.io.InputStream; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufInputStream; +import li.cil.oc.common.PacketHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +// Courtesy of jchung01 +@Mixin(value = PacketHandler.class, remap = false) +public class UTPacketHandlerMixin +{ + /** + * @reason The original constructor doesn't release the ByteBuf when {@link InputStream#close()} is called. + */ + @Redirect(method = "li$cil$oc$common$PacketHandler$$process", at = @At(value = "NEW", target = "(Lio/netty/buffer/ByteBuf;)Lio/netty/buffer/ByteBufInputStream;")) + private ByteBufInputStream utReleasePayloadOnClose(ByteBuf buffer) + { + return new ByteBufInputStream(buffer, true); + } +} diff --git a/src/main/resources/mixins.mods.opencomputers.json b/src/main/resources/mixins.mods.opencomputers.json new file mode 100644 index 00000000..1836e274 --- /dev/null +++ b/src/main/resources/mixins.mods.opencomputers.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.mods.opencomputers.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": ["UTPacketHandlerMixin"] +} \ No newline at end of file From 9cc3969deada4d48d6e8c12a7ab6168cbbd42d40 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Thu, 20 Jun 2024 14:01:46 -0700 Subject: [PATCH 4/5] Check for null NetworkDispatcher --- .../mixin/UTPacketCustomRetainMixin.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java index ea584ec1..a553a65c 100644 --- a/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java +++ b/src/main/java/mod/acgaming/universaltweaks/mods/codechickenlib/mixin/UTPacketCustomRetainMixin.java @@ -10,6 +10,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher; import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -23,6 +24,11 @@ * This mixin retains PacketCustom payloads, increasing the ref count by the number of players * that are to receive the packet. This is necessary as the payload is shared between all receivers * and each receiver releases the payload in {@link UTPacketCustomReleaseMixin}. + *

+ * CCL doesn't fully utilize Forge's built-in networking, so this mixin adds the missing behavior that + * {@link net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget#selectNetworks} and + * {@link net.minecraftforge.fml.common.network.FMLOutboundHandler#write} + * would normally do to clean up packets. * @author jchung01 */ @Mixin(value = PacketCustom.class, remap = false) @@ -78,12 +84,14 @@ private void utReleaseOriginal(CallbackInfoReturnable cir) } @Unique - private static void ut$retainForPlayers(Packet packet, Predicate condition) + private static void ut$retainForPlayers(Packet packet, Predicate condition) { if (packet instanceof FMLProxyPacket) { List playerList = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayers(); - int retainCount = (int) (playerList.stream().filter(condition).count() - 1); + // Check for null dispatchers like Forge's FMLOutboundHandler.OutboundTarget#selectNetworks does. + Predicate hasNetworkDispatcher = player -> player.connection.netManager.channel().attr(NetworkDispatcher.FML_DISPATCHER).get() != null; + int retainCount = (int) (playerList.stream().filter(condition.and(hasNetworkDispatcher)).count() - 1); if (retainCount > 0) ((FMLProxyPacket) packet).payload().retain(retainCount); } } From 0c746d37b4a0183eaa4b725c77db1db9e436a895 Mon Sep 17 00:00:00 2001 From: jchung01 Date: Thu, 20 Jun 2024 15:06:01 -0700 Subject: [PATCH 5/5] Update configs/readme --- README.md | 6 ++++ build.gradle | 2 +- .../universaltweaks/config/UTConfigMods.java | 36 +++++++++++++++++++ .../universaltweaks/core/UTMixinLoader.java | 9 ++--- .../assets/universaltweaks/lang/en_us.lang | 3 ++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1527076a..a418305e 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,8 @@ All changes are toggleable via config files. * **Duplication Fixes:** Fixes various duplication exploits * **Chocolate Quest Repoured** * **Legacy Golden Feather:** Restores the golden feather behavior from the original Better Dungeons mod +* **CodeChicken Lib** + * **Packet Leak Fix:** Fixes network ByteBuf leaks from PacketCustom * **CoFH Core** * **Vorpal Enchantment Damage:** Sets the damage multiplier of the Vorpal enchantment * **Compact Machines** @@ -304,6 +306,8 @@ All changes are toggleable via config files. * **Extinguishing Dodges:** Chance per dodge to extinguish the player when burning * **Feathers Helper API Fix:** Fixes server-sided crashes when the Feathers Helper API is utilized * **Sprinting Integration:** Configurable consumption of feathers when the player is sprinting +* **Ender Storage** + * **Fix Frequency Tracking:** Fixes storage frequencies being tracked multiple times * **Epic Siege Mod** * **Disable Digger AI Debug:** Disables leftover debug logging inside the digger AI of the beta builds * **Extra Utilities 2** @@ -347,6 +351,8 @@ All changes are toggleable via config files. * **Radiation Environment Map:** Changes the data table of the radiation environment handler to improve tick time * **OpenBlocks** * **Last Stand Trigger Fix:** Fixes the Last Stand enchantment triggering too early on pre-mitigation damage (before enchants, potions, etc), instead of on post-mitigation damage. +* **OpenComputers** + * **Packet Leak Fix:** Fixes network ByteBuf leaks from PacketHandler * **ProjectRed** * **Duplication Fixes:** Fixes various duplication exploits * **Quark** diff --git a/build.gradle b/build.gradle index a3d4226d..e6ddebb5 100644 --- a/build.gradle +++ b/build.gradle @@ -152,7 +152,7 @@ dependencies { compileOnly rfg.deobf('curse.maven:modtweaker-220954:3840577') compileOnly rfg.deobf('curse.maven:nuclearcraft-226254:3784145') compileOnly rfg.deobf('curse.maven:openblocks-228816:2699056') - implementation rfg.deobf('curse.maven:opencomputers-223008:5274236') + compileOnly rfg.deobf('curse.maven:opencomputers-223008:5274236') compileOnly rfg.deobf('curse.maven:reborn-core-237903:3330308') compileOnly rfg.deobf('curse.maven:reskillable-286382:2815686') compileOnly rfg.deobf('curse.maven:requious-frakto-336748:3218640') diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java index 15ecaa20..cf89a54e 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigMods.java @@ -51,6 +51,10 @@ public class UTConfigMods @Config.Name("CB Multipart/Forge Multipart CBE") public static final CBMultipartCategory CB_MULTIPART = new CBMultipartCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.ccl") + @Config.Name("CodeChicken Lib") + public static final CodeChickenLibCategory CCL = new CodeChickenLibCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.chisel") @Config.Name("Chisel") public static final ChiselCategory CHISEL = new ChiselCategory(); @@ -79,6 +83,10 @@ public class UTConfigMods @Config.Name("Elenai Dodge 2") public static final ElenaiDodge2Category ELENAI_DODGE_2 = new ElenaiDodge2Category(); + @Config.LangKey("cfg.universaltweaks.modintegration.enderstorage") + @Config.Name("Ender Storage") + public static final EnderStorageCategory ENDER_STORAGE = new EnderStorageCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.esm") @Config.Name("Epic Siege Mod") public static final EpicSiegeModCategory EPIC_SIEGE_MOD = new EpicSiegeModCategory(); @@ -147,6 +155,10 @@ public class UTConfigMods @Config.Name("OpenBlocks") public static final OpenBlocksCategory OPEN_BLOCKS = new OpenBlocksCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.opencomputers") + @Config.Name("OpenComputers") + public static final OpenComputersCategory OPEN_COMPUTERS = new OpenComputersCategory(); + @Config.LangKey("cfg.universaltweaks.modintegration.projectred") @Config.Name("ProjectRed") public static final ProjectRedCategory PROJECTRED = new ProjectRedCategory(); @@ -354,6 +366,14 @@ public static class ChocolateQuestCategory public boolean utCQRGoldenFeatherToggle = true; } + public static class CodeChickenLibCategory + { + @Config.RequiresMcRestart + @Config.Name("Packet Leak Fix") + @Config.Comment("Fixes network ByteBuf leaks from PacketCustom") + public boolean utPacketLeakFixToggle = true; + } + public static class CoFHCoreCategory { @Config.Name("Vorpal Enchantment Damage") @@ -411,6 +431,14 @@ public static class ElenaiDodge2Category public int utED2SprintingFeatherRequirement = 6; } + public static class EnderStorageCategory + { + @Config.RequiresMcRestart + @Config.Name("Fix Frequency Tracking") + @Config.Comment("Fixes storage frequencies being tracked multiple times") + public boolean utFrequencyTrackFixToggle = true; + } + public static class EpicSiegeModCategory { @Config.RequiresMcRestart @@ -647,6 +675,14 @@ public static class OpenBlocksCategory public boolean utLastStandFixToggle = true; } + public static class OpenComputersCategory + { + @Config.RequiresMcRestart + @Config.Name("Packet Leak Fix") + @Config.Comment("Fixes network ByteBuf leaks from PacketHandler") + public boolean utPacketLeakFixToggle = true; + } + public static class ProjectRedCategory { @Config.RequiresMcRestart diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java index 2b131938..443600f3 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTMixinLoader.java @@ -46,16 +46,14 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.cbmultipart.json", () -> loaded("forgemultipartcbe") && UTConfigMods.CB_MULTIPART.utMemoryLeakFixToggle); put("mixins.mods.ceramics.json", () -> loaded("ceramics")); put("mixins.mods.chisel.tcomplement.dupes.json", () -> loaded("chisel") && loaded("tcomplement") && UTConfigMods.CHISEL.utDuplicationFixesToggle); - // TODO: add config - put("mixins.mods.codechickenlib.json", () -> loaded("codechickenlib")); + put("mixins.mods.codechickenlib.json", () -> loaded("codechickenlib") && UTConfigMods.CCL.utPacketLeakFixToggle); put("mixins.mods.cofhcore.json", () -> loaded("cofhcore")); put("mixins.mods.collective.json", () -> loaded("collective")); put("mixins.mods.cqrepoured.json", () -> loaded("cqrepoured")); put("mixins.mods.effortlessbuilding.json", () -> loaded("effortlessbuilding")); put("mixins.mods.elementarystaffs.json", () -> loaded("element")); put("mixins.mods.elenaidodge2.json", () -> loaded("elenaidodge2")); - // TODO: add config - put("mixins.mods.enderstorage.json", () -> loaded("enderstorage")); + put("mixins.mods.enderstorage.json", () -> loaded("enderstorage") && UTConfigMods.ENDER_STORAGE.utFrequencyTrackFixToggle); put("mixins.mods.epicsiegemod.json", () -> loaded("epicsiegemod")); put("mixins.mods.erebus.cabbage.json", () -> loaded("erebus") && UTConfigMods.EREBUS.utCabbageDrop); put("mixins.mods.erebus.json", () -> loaded("erebus")); @@ -82,8 +80,7 @@ public class UTMixinLoader implements ILateMixinLoader put("mixins.mods.netherrocks.json", () -> loaded("netherrocks")); put("mixins.mods.nuclearcraft.json", () -> loaded("nuclearcraft")); put("mixins.mods.openblocks.json", () -> loaded("openblocks") && UTConfigMods.OPEN_BLOCKS.utLastStandFixToggle); - // TODO: add config - put("mixins.mods.opencomputers.json", () -> loaded("opencomputers")); + put("mixins.mods.opencomputers.json", () -> loaded("opencomputers") && UTConfigMods.OPEN_COMPUTERS.utPacketLeakFixToggle); put("mixins.mods.quark.dupes.json", () -> loaded("quark") && UTConfigMods.QUARK.utDuplicationFixesToggle); put("mixins.mods.requiousfrakto.json", () -> loaded("requious") && UTConfigMods.REQUIOUS_FRAKTO.utParticleFixesToggle); put("mixins.mods.reskillable.json", () -> loaded("reskillable")); diff --git a/src/main/resources/assets/universaltweaks/lang/en_us.lang b/src/main/resources/assets/universaltweaks/lang/en_us.lang index 7924d0e0..84114c6d 100644 --- a/src/main/resources/assets/universaltweaks/lang/en_us.lang +++ b/src/main/resources/assets/universaltweaks/lang/en_us.lang @@ -57,6 +57,7 @@ cfg.universaltweaks.modintegration.bm=Blood Magic cfg.universaltweaks.modintegration.bop=Biomes O' Plenty cfg.universaltweaks.modintegration.botania=Botania cfg.universaltweaks.modintegration.cbmultipart=CB Multipart/Forge Multipart CBE +cfg.universaltweaks.modintegration.ccl=CodeChicken Lib cfg.universaltweaks.modintegration.chisel=Chisel cfg.universaltweaks.modintegration.cofhcore=CoFH Core cfg.universaltweaks.modintegration.compactmachines=Compact Machines @@ -64,6 +65,7 @@ cfg.universaltweaks.modintegration.cqrepoured=Chocolate Quest Repoured cfg.universaltweaks.modintegration.effortlessbuilding=Effortless Building cfg.universaltweaks.modintegration.elementarystaffs=Elementary Staffs cfg.universaltweaks.modintegration.elenaidodge2=Elenai Dodge 2 +cfg.universaltweaks.modintegration.enderstorage=Ender Storage cfg.universaltweaks.modintegration.erebus=The Erebus cfg.universaltweaks.modintegration.esm=Epic Siege Mod cfg.universaltweaks.modintegration.extrautilities=Extra Utilities 2 @@ -81,6 +83,7 @@ cfg.universaltweaks.modintegration.netherchest=Nether Chest cfg.universaltweaks.modintegration.netherrocks=Netherrocks cfg.universaltweaks.modintegration.nuclearcraft=NuclearCraft cfg.universaltweaks.modintegration.openblocks=OpenBlocks +cfg.universaltweaks.modintegration.opencomputers=OpenComputers cfg.universaltweaks.modintegration.projectred=ProjectRed cfg.universaltweaks.modintegration.quark=Quark cfg.universaltweaks.modintegration.rftoolsdimensions=RFTools Dimensions