From e3ad8bb63e2af25ef611911cd28dfe09579633d8 Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 21 Sep 2024 02:20:36 +0200 Subject: [PATCH 1/3] fix array out of bounds caused by the GameSettings.getKeyDisplayString method --- .../hodgepodge/config/FixesConfig.java | 9 +++++++- .../mitchej123/hodgepodge/mixins/Mixins.java | 4 ++++ ...MixinGameSettings_FixArrayOutOfBounds.java | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGameSettings_FixArrayOutOfBounds.java diff --git a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java index db7e2023..50c82146 100644 --- a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java @@ -5,7 +5,7 @@ @Config(modid = "hodgepodge", category = "fixes") public class FixesConfig { - // Minecraft + /* ====== Minecraft fixes start ===== */ @Config.Comment("Modify the maximum NBT size limit when received as a network packet, to avoid large NBT-related crashes") @Config.DefaultBoolean(true) @@ -358,6 +358,13 @@ public class FixesConfig { // settings public static int limitRecursiveBlockUpdateDepth; + @Config.Comment("Fix an array out of bounds caused by the GameSettings getKeyDisplayString method") + @Config.DefaultBoolean(true) + @Config.RequiresMcRestart + public static boolean fixGameSettingsArrayOutOfBounds; + + /* ====== Minecraft fixes end ===== */ + // affecting multiple mods @Config.Comment("Remove old/stale/outdated update checks.") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index 7089dfab..17c56555 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -420,6 +420,10 @@ public enum Mixins { FIX_CASE_COMMAND(new Builder("Fix the command handler not allowing you to run commands typed in any case") .setPhase(Phase.EARLY).setSide(Side.BOTH).addTargetedMod(TargetedMod.VANILLA) .addMixinClasses("minecraft.MixinCommandHandler_CommandFix").setApplyIf(() -> FixesConfig.fixCaseCommands)), + FIX_GAMESETTINGS_OUTOFBOUNDS(new Builder("Fix array out of bound error in GameSettings menu").setPhase(Phase.EARLY) + .setSide(Side.CLIENT).addTargetedMod(TargetedMod.VANILLA) + .addMixinClasses("minecraft.MixinGameSettings_FixArrayOutOfBounds") + .setApplyIf(() -> FixesConfig.fixGameSettingsArrayOutOfBounds).addExcludedMod(TargetedMod.LWJGL3IFY)), LIMIT_RECURSIVE_BLOCK_UPDATE_DEPTH(new Builder( "Limit the number of recursive cascading block updates during world generation to prevent stack overflow crashes") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGameSettings_FixArrayOutOfBounds.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGameSettings_FixArrayOutOfBounds.java new file mode 100644 index 00000000..3db23849 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGameSettings_FixArrayOutOfBounds.java @@ -0,0 +1,22 @@ +package com.mitchej123.hodgepodge.mixins.early.minecraft; + +import net.minecraft.client.settings.GameSettings; +import net.minecraft.util.EnumChatFormatting; + +import org.lwjgl.input.Keyboard; +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; + +@Mixin(GameSettings.class) +public class MixinGameSettings_FixArrayOutOfBounds { + + @Inject(method = "getKeyDisplayString", at = @At("HEAD"), cancellable = true) + private static void hodgepodge$fixArrayOutOFBounds(int keycode, CallbackInfoReturnable cir) { + if (keycode > Keyboard.KEYBOARD_SIZE - 1) { + cir.setReturnValue(EnumChatFormatting.RED + "ERROR"); + } + } + +} From 3e3560eda597ec84b23f5540a8d85aa5be3752db Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 21 Sep 2024 03:17:50 +0200 Subject: [PATCH 2/3] transfer gt++ asm fix for thaumcraft's ItemWispEssence to mixins --- .../hodgepodge/config/FixesConfig.java | 5 ++++ .../mitchej123/hodgepodge/mixins/Mixins.java | 6 +++++ .../thaumcraft/MixinItemWispEssence_Both.java | 23 +++++++++++++++++++ .../MixinItemWispEssence_Client.java | 22 ++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Both.java create mode 100644 src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Client.java diff --git a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java index 50c82146..a19450b9 100644 --- a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java @@ -640,6 +640,11 @@ public class FixesConfig { @Config.RequiresMcRestart public static boolean fixWandPedestalVisDuplication; + @Config.Comment("Fix handling of null stacks in ItemWispEssence") + @Config.DefaultBoolean(true) + @Config.RequiresMcRestart + public static boolean fixNullHandlingItemWispEssence; + // Thermal Dynamics @Config.Comment("Prevent crash with Thermal Dynamics from Negative Array Exceptions from item duct transfers") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index 17c56555..bbaef53e 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -541,6 +541,12 @@ public enum Mixins { FIX_THAUMCRAFT_VIS_DUPLICATION(new Builder("Fix Thaumcraft Vis Duplication") .addMixinClasses("thaumcraft.MixinTileWandPedestal_VisDuplication").setPhase(Phase.LATE).setSide(Side.BOTH) .setApplyIf(() -> FixesConfig.fixWandPedestalVisDuplication).addTargetedMod(TargetedMod.THAUMCRAFT)), + FIX_NULL_HANDLING_ITEMWISPESSENCE_CLIENT(new Builder("Fix handling of null stacks in ItemWispEssence") + .addMixinClasses("thaumcraft.MixinItemWispEssence_Client").setPhase(Phase.LATE).setSide(Side.CLIENT) + .setApplyIf(() -> FixesConfig.fixNullHandlingItemWispEssence).addTargetedMod(TargetedMod.THAUMCRAFT)), + FIX_NULL_HANDLING_ITEMWISPESSENCE_BOTH(new Builder("Fix handling of null stacks in ItemWispEssence") + .addMixinClasses("thaumcraft.MixinItemWispEssence_Both").setPhase(Phase.LATE).setSide(Side.BOTH) + .setApplyIf(() -> FixesConfig.fixNullHandlingItemWispEssence).addTargetedMod(TargetedMod.THAUMCRAFT)), // BOP FIX_QUICKSAND_XRAY(new Builder("Fix Xray through block without collision boundingBox").setPhase(Phase.LATE) diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Both.java b/src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Both.java new file mode 100644 index 00000000..80c874d0 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Both.java @@ -0,0 +1,23 @@ +package com.mitchej123.hodgepodge.mixins.late.thaumcraft; + +import net.minecraft.item.ItemStack; + +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 thaumcraft.api.aspects.AspectList; +import thaumcraft.common.items.ItemWispEssence; + +@Mixin(ItemWispEssence.class) +public class MixinItemWispEssence_Both { + + @Inject(method = "getAspects", at = @At("HEAD"), cancellable = true, remap = false) + private void hodgpodge$fixNullAspect(ItemStack stack, CallbackInfoReturnable cir) { + if (stack == null) { + cir.setReturnValue(null); + } + } + +} diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Client.java b/src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Client.java new file mode 100644 index 00000000..b81b53a4 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/late/thaumcraft/MixinItemWispEssence_Client.java @@ -0,0 +1,22 @@ +package com.mitchej123.hodgepodge.mixins.late.thaumcraft; + +import net.minecraft.item.ItemStack; + +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 thaumcraft.common.items.ItemWispEssence; + +@Mixin(ItemWispEssence.class) +public class MixinItemWispEssence_Client { + + @Inject(method = "getColorFromItemStack", at = @At("HEAD"), cancellable = true) + private void hodgpodge$fixNullColor(ItemStack stack, int par2, CallbackInfoReturnable cir) { + if (stack == null) { + cir.setReturnValue(0); + } + } + +} From 2725d06baf8fde63e99a664955d076609ef26d4f Mon Sep 17 00:00:00 2001 From: Alexdoru <57050655+Alexdoru@users.noreply.github.com> Date: Sat, 21 Sep 2024 03:50:12 +0200 Subject: [PATCH 3/3] transfer gt++ asm fix for COFH's OreDictionaryArbiter to mixins --- .../hodgepodge/config/FixesConfig.java | 7 ++++++ .../mitchej123/hodgepodge/mixins/Mixins.java | 3 +++ .../cofhcore/MixinOreDictionaryArbiter.java | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/main/java/com/mitchej123/hodgepodge/mixins/early/cofhcore/MixinOreDictionaryArbiter.java diff --git a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java index a19450b9..8bde91a5 100644 --- a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java @@ -425,6 +425,13 @@ public class FixesConfig { @Config.RequiresMcRestart public static boolean fixCandycraftBlockSugarNPE; + // Cofh + + @Config.Comment("Fix NPE in COFH's oredict") + @Config.DefaultBoolean(true) + @Config.RequiresMcRestart + public static boolean fixCofhOreDictNPE; + // Extra TiC @Config.Comment("Disable ExtraTic's Integration with Metallurgy 3 Precious Materials Module: (Brass, Silver, Electrum & Platinum)") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index bbaef53e..5698e624 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -585,6 +585,9 @@ public enum Mixins { .addMixinClasses("thermalexpansion.MixinTileInventoryTileLightFalse") .addTargetedMod(TargetedMod.THERMALEXPANSION).setApplyIf(() -> ASMConfig.cofhWorldTransformer) .setPhase(Phase.LATE).setSide(Side.BOTH)), + FIX_ORE_DICT_NPE(new Builder("Fix NPE in OreDictionaryArbiter") + .addMixinClasses("cofhcore.MixinOreDictionaryArbiter").setPhase(Phase.EARLY).setSide(Side.BOTH) + .addTargetedMod(TargetedMod.COFH_CORE).setApplyIf(() -> FixesConfig.fixCofhOreDictNPE)), // Immersive engineering JAVA12_IMMERSIVE_ENGINERRING(new Builder("Immersive Engineering Java-12 safe potion array resizing") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/cofhcore/MixinOreDictionaryArbiter.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/cofhcore/MixinOreDictionaryArbiter.java new file mode 100644 index 00000000..000c7a88 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/cofhcore/MixinOreDictionaryArbiter.java @@ -0,0 +1,22 @@ +package com.mitchej123.hodgepodge.mixins.early.cofhcore; + +import net.minecraft.item.ItemStack; + +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; + +import cofh.core.util.oredict.OreDictionaryArbiter; + +@Mixin(OreDictionaryArbiter.class) +public class MixinOreDictionaryArbiter { + + @Inject(method = "registerOreDictionaryEntry", at = @At("HEAD"), cancellable = true, remap = false) + private static void hodgepodge$fixNPE(ItemStack stack, String s, CallbackInfo ci) { + if (stack == null) { + ci.cancel(); + } + } + +}