From 14d99fbc8a2d7011738e80d48c3a889a3a3f90e5 Mon Sep 17 00:00:00 2001 From: 0xTas Date: Sat, 20 Apr 2024 14:31:29 -0700 Subject: [PATCH] Added null checks to Modules.get() calls in mixins. This should prevent startup crashes when using Meteor's Baritone. --- .../stardust/mixin/AbstractSignEditScreenMixin.java | 7 +++++-- .../java/dev/stardust/mixin/BookEditScreenMixin.java | 8 ++++++-- src/main/java/dev/stardust/mixin/BookScreenMixin.java | 10 +++++----- src/main/java/dev/stardust/mixin/ChatHudMixin.java | 4 +++- .../dev/stardust/mixin/ClientPlayerEntityMixin.java | 4 +++- .../mixin/ClientPlayerInteractionManagerMixin.java | 4 +++- src/main/java/dev/stardust/mixin/DoorBlockMixin.java | 5 ++++- src/main/java/dev/stardust/mixin/DrawContextMixin.java | 4 +++- .../dev/stardust/mixin/ElytraSoundInstanceMixin.java | 4 +++- .../java/dev/stardust/mixin/GoatHornItemMixin.java | 4 +++- .../java/dev/stardust/mixin/MinecraftClientMixin.java | 8 ++++++-- .../java/dev/stardust/mixin/MusicTrackerMixin.java | 4 +++- .../java/dev/stardust/mixin/NarratorManagerMixin.java | 4 +++- .../stardust/mixin/SignBlockEntityRendererMixin.java | 4 +++- src/main/java/dev/stardust/mixin/SoundSystemMixin.java | 5 +++-- .../java/dev/stardust/mixin/TridentBoostMixin.java | 8 ++++++-- src/main/java/dev/stardust/mixin/TridentItemMixin.java | 4 +++- .../java/dev/stardust/mixin/WeightedSoundSetMixin.java | 4 +++- src/main/java/dev/stardust/mixin/WorldMixin.java | 4 +++- 19 files changed, 71 insertions(+), 28 deletions(-) diff --git a/src/main/java/dev/stardust/mixin/AbstractSignEditScreenMixin.java b/src/main/java/dev/stardust/mixin/AbstractSignEditScreenMixin.java index aa16e51..247386e 100644 --- a/src/main/java/dev/stardust/mixin/AbstractSignEditScreenMixin.java +++ b/src/main/java/dev/stardust/mixin/AbstractSignEditScreenMixin.java @@ -45,8 +45,11 @@ public abstract class AbstractSignEditScreenMixin extends Screen { @Inject(method = "init", at = @At("TAIL")) public void stardustMixinInit(CallbackInfo ci) { if (this.client == null) return; - SignHistorian signHistorian = Modules.get().get(SignHistorian.class); - SignatureSign signatureSign = Modules.get().get(SignatureSign.class); + Modules modules = Modules.get(); + + if (modules == null) return; + SignHistorian signHistorian = modules.get(SignHistorian.class); + SignatureSign signatureSign = modules.get(SignatureSign.class); if (!signatureSign.isActive() && !signHistorian.isActive()) return; SignText restoration = signHistorian.getRestoration(this.blockEntity); diff --git a/src/main/java/dev/stardust/mixin/BookEditScreenMixin.java b/src/main/java/dev/stardust/mixin/BookEditScreenMixin.java index 0db9bfc..905c958 100644 --- a/src/main/java/dev/stardust/mixin/BookEditScreenMixin.java +++ b/src/main/java/dev/stardust/mixin/BookEditScreenMixin.java @@ -93,7 +93,9 @@ private String uCC() { @Inject(method = "init", at = @At("TAIL")) private void mixinInit(CallbackInfo ci) { - BookTools bookTools = Modules.get().get(BookTools.class); + Modules modules = Modules.get(); + if (modules == null) return; + BookTools bookTools = modules.get(BookTools.class); if (bookTools.skipFormatting()) return; int offset = 0; @@ -188,7 +190,9 @@ private void mixinChangePage(CallbackInfo ci) { @Inject(method = "updateButtons", at = @At("TAIL")) private void mixinUpdateButtons(CallbackInfo ci) { - BookTools bookTools = Modules.get().get(BookTools.class); + Modules modules = Modules.get(); + if (modules == null) return; + BookTools bookTools = modules.get(BookTools.class); if (bookTools.skipFormatting()) return; for (ButtonWidget btn : this.buttons) { diff --git a/src/main/java/dev/stardust/mixin/BookScreenMixin.java b/src/main/java/dev/stardust/mixin/BookScreenMixin.java index 7bb1627..7a137a8 100644 --- a/src/main/java/dev/stardust/mixin/BookScreenMixin.java +++ b/src/main/java/dev/stardust/mixin/BookScreenMixin.java @@ -2,7 +2,6 @@ import java.util.List; import java.util.ArrayList; -import dev.stardust.Stardust; import net.minecraft.text.Text; import dev.stardust.modules.AntiToS; import dev.stardust.util.StardustUtil; @@ -72,7 +71,6 @@ private void deobfuscateBook(ButtonWidget btn) { @Unique private void reobfuscateBook(ButtonWidget btn) { - Stardust.LOG.debug("[Stardust] Reobfuscated book contents."); if (contents instanceof BookScreen.WrittenBookContents) { btn.setAlpha(1f); btn.setTooltip(Tooltip.of(Text.of("§8Reveal this tome's secrets.."))); @@ -92,10 +90,12 @@ private void reobfuscateBook(ButtonWidget btn) { private void mixinInit(CallbackInfo ci) { if (!(this.contents instanceof BookScreen.WrittenBookContents)) return; - List pages = ((WrittenBookContentsAccessor) this.contents).getPages(); - AntiToS antiToS = Modules.get().get(AntiToS.class); - BookTools bookTools = Modules.get().get(BookTools.class); + Modules modules = Modules.get(); + if (modules == null) return; + List pages = ((WrittenBookContentsAccessor) this.contents).getPages(); + AntiToS antiToS = modules.get(AntiToS.class); + BookTools bookTools = modules.get(BookTools.class); if (antiToS.isActive() && antiToS.booksSetting.get()) { List filtered = new ArrayList<>(); for (String page : pages) { diff --git a/src/main/java/dev/stardust/mixin/ChatHudMixin.java b/src/main/java/dev/stardust/mixin/ChatHudMixin.java index 00a2b5f..530ffc6 100644 --- a/src/main/java/dev/stardust/mixin/ChatHudMixin.java +++ b/src/main/java/dev/stardust/mixin/ChatHudMixin.java @@ -22,7 +22,9 @@ public class ChatHudMixin { argsOnly = true ) private Text censorChatMessage(Text message) { - AntiToS antiToS = Modules.get().get(AntiToS.class); + Modules modules = Modules.get(); + if (modules == null) return message; + AntiToS antiToS = modules.get(AntiToS.class); if (!antiToS.isActive() || !antiToS.chatSetting.get()) return message; return (antiToS.containsBlacklistedText(message.getString()) ? Text.of(antiToS.censorText(message.getString())) : message); } diff --git a/src/main/java/dev/stardust/mixin/ClientPlayerEntityMixin.java b/src/main/java/dev/stardust/mixin/ClientPlayerEntityMixin.java index 0c7b069..ca1529b 100644 --- a/src/main/java/dev/stardust/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/dev/stardust/mixin/ClientPlayerEntityMixin.java @@ -21,7 +21,9 @@ public class ClientPlayerEntityMixin { // See RocketMan.java @Inject(method = "playSound(Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V", at = @At("HEAD"), cancellable = true) private void mixinPlaySound(SoundEvent sound, SoundCategory category, float volume, float pitch, CallbackInfo ci) { - RocketMan rocketMan = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null) return; + RocketMan rocketMan = modules.get(RocketMan.class); if (rocketMan.isActive() && sound == SoundEvents.ITEM_ELYTRA_FLYING) { if (rocketMan.shouldMuteElytra()) ci.cancel(); } diff --git a/src/main/java/dev/stardust/mixin/ClientPlayerInteractionManagerMixin.java b/src/main/java/dev/stardust/mixin/ClientPlayerInteractionManagerMixin.java index ca686b8..c3c5be2 100644 --- a/src/main/java/dev/stardust/mixin/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/dev/stardust/mixin/ClientPlayerInteractionManagerMixin.java @@ -18,7 +18,9 @@ public class ClientPlayerInteractionManagerMixin { // See RocketMan.java @Inject(method = "stopUsingItem", at = @At("HEAD"), cancellable = true) private void preventTridentUseResetOnScreenChange(CallbackInfo ci) { - RocketMan rm = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null) return; + RocketMan rm = modules.get(RocketMan.class); if (!rm.isActive() || !rm.tridentBoost.get() || !rm.chargingTrident) return; ci.cancel(); } diff --git a/src/main/java/dev/stardust/mixin/DoorBlockMixin.java b/src/main/java/dev/stardust/mixin/DoorBlockMixin.java index a4b1be5..bc08895 100644 --- a/src/main/java/dev/stardust/mixin/DoorBlockMixin.java +++ b/src/main/java/dev/stardust/mixin/DoorBlockMixin.java @@ -22,8 +22,11 @@ public DoorBlockMixin(Settings settings) { // See AutoDoors.java @Inject(method = "playOpenCloseSound", at = @At("HEAD"), cancellable = true) private void mixinPlayOpenCloseSound(CallbackInfo ci) { - AutoDoors autoDoors = Modules.get().get(AutoDoors.class); + Modules modules = Modules.get(); + if (modules == null) return; + AutoDoors autoDoors = modules.get(AutoDoors.class); + if (autoDoors == null) return; if (autoDoors.shouldMute()) ci.cancel(); } } diff --git a/src/main/java/dev/stardust/mixin/DrawContextMixin.java b/src/main/java/dev/stardust/mixin/DrawContextMixin.java index ab8fb7b..1596206 100644 --- a/src/main/java/dev/stardust/mixin/DrawContextMixin.java +++ b/src/main/java/dev/stardust/mixin/DrawContextMixin.java @@ -24,7 +24,9 @@ public abstract class DrawContextMixin { // See LoreLocator.java @Inject(method = "drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V", at = @At(value = "HEAD")) private void highlightNamedItems(TextRenderer textRenderer, ItemStack stack, int x, int y, @Nullable String countOverride, CallbackInfo ci) { - LoreLocator ll = Modules.get().get(LoreLocator.class); + Modules modules = Modules.get(); + if (modules == null) return; + LoreLocator ll = modules.get(LoreLocator.class); if (!ll.isActive() || !ll.shouldHighlightSlot(stack)) return; this.fill(x, y, x + 16, y + 16, ll.color.get().getPacked()); } diff --git a/src/main/java/dev/stardust/mixin/ElytraSoundInstanceMixin.java b/src/main/java/dev/stardust/mixin/ElytraSoundInstanceMixin.java index f348d33..1da0a01 100644 --- a/src/main/java/dev/stardust/mixin/ElytraSoundInstanceMixin.java +++ b/src/main/java/dev/stardust/mixin/ElytraSoundInstanceMixin.java @@ -25,7 +25,9 @@ protected ElytraSoundInstanceMixin(SoundEvent soundEvent, SoundCategory soundCat // See RocketMan.java @Inject(method = "tick", at = @At("HEAD")) private void mixinTick(CallbackInfo ci) { - RocketMan rocketMan = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null) return; + RocketMan rocketMan = modules.get(RocketMan.class); if (rocketMan.isActive() && rocketMan.shouldMuteElytra()) this.setDone(); } } diff --git a/src/main/java/dev/stardust/mixin/GoatHornItemMixin.java b/src/main/java/dev/stardust/mixin/GoatHornItemMixin.java index d8098b4..d7b9bbd 100644 --- a/src/main/java/dev/stardust/mixin/GoatHornItemMixin.java +++ b/src/main/java/dev/stardust/mixin/GoatHornItemMixin.java @@ -22,7 +22,9 @@ public GoatHornItemMixin(Settings settings) { @Inject(method = "playSound", at = @At("HEAD"), cancellable = true) private static void mixinPlaySound(CallbackInfo ci) { - Honker honker = Modules.get().get(Honker.class); + Modules modules = Modules.get(); + if (modules == null) return; + Honker honker = modules.get(Honker.class); if (honker.shouldMuteHorns()) ci.cancel(); } } diff --git a/src/main/java/dev/stardust/mixin/MinecraftClientMixin.java b/src/main/java/dev/stardust/mixin/MinecraftClientMixin.java index add07a9..4903806 100644 --- a/src/main/java/dev/stardust/mixin/MinecraftClientMixin.java +++ b/src/main/java/dev/stardust/mixin/MinecraftClientMixin.java @@ -27,7 +27,9 @@ private void mixinRender(CallbackInfo ci) { long currentTime = System.nanoTime(); float deltaTime = (currentTime - lastFrameTime) / 10000000f; - RocketMan rocketMan = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null ) return; + RocketMan rocketMan = modules.get(RocketMan.class); if (!rocketMan.isActive() || !rocketMan.shouldTickRotation()) return; MinecraftClient mc = rocketMan.getClientInstance(); @@ -102,7 +104,9 @@ private void mixinRender(CallbackInfo ci) { // See MusicTweaks.java @Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true) public void mixinGetMusicType(CallbackInfoReturnable cir) { - MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); + Modules modules = Modules.get(); + if (modules == null ) return; + MusicTweaks tweaks = modules.get(MusicTweaks.class); if (tweaks == null || !tweaks.isActive()) return; MusicSound type = tweaks.getType(); diff --git a/src/main/java/dev/stardust/mixin/MusicTrackerMixin.java b/src/main/java/dev/stardust/mixin/MusicTrackerMixin.java index 510eeda..d8447df 100644 --- a/src/main/java/dev/stardust/mixin/MusicTrackerMixin.java +++ b/src/main/java/dev/stardust/mixin/MusicTrackerMixin.java @@ -17,7 +17,9 @@ public class MusicTrackerMixin { // See MusicTweaks.java @Inject(method = "tick", at = @At("TAIL")) private void mixinTick(CallbackInfo ci) { - MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); + Modules modules = Modules.get(); + if (modules == null ) return; + MusicTweaks tweaks = modules.get(MusicTweaks.class); if (tweaks == null || !tweaks.isActive()) return; boolean currentlyPlaying = ((MusicTrackerAccessor) this).getCurrent() != null; diff --git a/src/main/java/dev/stardust/mixin/NarratorManagerMixin.java b/src/main/java/dev/stardust/mixin/NarratorManagerMixin.java index 61188c0..f48cda8 100644 --- a/src/main/java/dev/stardust/mixin/NarratorManagerMixin.java +++ b/src/main/java/dev/stardust/mixin/NarratorManagerMixin.java @@ -18,7 +18,9 @@ public class NarratorManagerMixin { // See SoundSystemMixin.java @Inject(method = "narrate(Lnet/minecraft/text/Text;)V", at = @At("HEAD"), cancellable = true) private void mixinNarrate(Text text, CallbackInfo ci) { - MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); + Modules modules = Modules.get(); + if (modules == null ) return; + MusicTweaks tweaks = modules.get(MusicTweaks.class); if (tweaks == null || !tweaks.isActive()) return; if (text.getString().startsWith("Now Playing: ") || text.getString().contains("§2§oNow Playing§r§7: ")) ci.cancel(); diff --git a/src/main/java/dev/stardust/mixin/SignBlockEntityRendererMixin.java b/src/main/java/dev/stardust/mixin/SignBlockEntityRendererMixin.java index 8e2aee6..307be60 100644 --- a/src/main/java/dev/stardust/mixin/SignBlockEntityRendererMixin.java +++ b/src/main/java/dev/stardust/mixin/SignBlockEntityRendererMixin.java @@ -23,7 +23,9 @@ public abstract class SignBlockEntityRendererMixin implements BlockEntityRendere // See AntiToS.java @ModifyVariable(method = "renderText", at = @At("HEAD"), argsOnly = true) private SignText modifyRenderedText(SignText signText) { - AntiToS antiToS = Modules.get().get(AntiToS.class); + Modules modules = Modules.get(); + if (modules == null ) return signText; + AntiToS antiToS = modules.get(AntiToS.class); if (!antiToS.isActive() || !antiToS.signsSetting.get()) return signText; String testText = Arrays.stream(signText.getMessages(false)) diff --git a/src/main/java/dev/stardust/mixin/SoundSystemMixin.java b/src/main/java/dev/stardust/mixin/SoundSystemMixin.java index b5859f0..197aac2 100644 --- a/src/main/java/dev/stardust/mixin/SoundSystemMixin.java +++ b/src/main/java/dev/stardust/mixin/SoundSystemMixin.java @@ -34,8 +34,9 @@ public class SoundSystemMixin { // See MusicTweaks.java @Inject(method = "tick()V", at = @At("TAIL")) private void mixinTick(CallbackInfo ci) { - MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); - if (tweaks == null) return; + Modules modules = Modules.get(); + if (modules == null ) return; + MusicTweaks tweaks = modules.get(MusicTweaks.class); boolean playing = false; @Nullable String songID = null; diff --git a/src/main/java/dev/stardust/mixin/TridentBoostMixin.java b/src/main/java/dev/stardust/mixin/TridentBoostMixin.java index 94ef1d9..d544557 100644 --- a/src/main/java/dev/stardust/mixin/TridentBoostMixin.java +++ b/src/main/java/dev/stardust/mixin/TridentBoostMixin.java @@ -18,14 +18,18 @@ public class TridentBoostMixin { // See RocketMan.java @Inject(method = "getMultiplier", at = @At("RETURN"), cancellable = true) private void configureMultiplier(CallbackInfoReturnable cir) { - RocketMan rm = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null) return; + RocketMan rm = modules.get(RocketMan.class); if (!rm.isActive() || !rm.tridentBoost.get()) return; cir.setReturnValue(1.069); } @Inject(method = "allowOutOfWater", at = @At("RETURN"), cancellable = true) private void doAllowOutOfWater(CallbackInfoReturnable cir) { - RocketMan rm = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null) return; + RocketMan rm = modules.get(RocketMan.class); if (!rm.isActive() || !rm.tridentBoost.get()) return; cir.setReturnValue(true); } diff --git a/src/main/java/dev/stardust/mixin/TridentItemMixin.java b/src/main/java/dev/stardust/mixin/TridentItemMixin.java index 77c149d..ec9d767 100644 --- a/src/main/java/dev/stardust/mixin/TridentItemMixin.java +++ b/src/main/java/dev/stardust/mixin/TridentItemMixin.java @@ -27,7 +27,9 @@ public TridentItemMixin(Settings settings) { // See RocketMan.java @Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/TridentItem;getMaxUseTime(Lnet/minecraft/item/ItemStack;)I", shift = At.Shift.AFTER)) private void bypassTridentChargeTime(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci, @Local(ordinal = 0)LocalIntRef i) { - RocketMan rm = Modules.get().get(RocketMan.class); + Modules modules = Modules.get(); + if (modules == null) return; + RocketMan rm = modules.get(RocketMan.class); if (!rm.isActive() || !rm.tridentBoost.get()) return; i.set(69420); } diff --git a/src/main/java/dev/stardust/mixin/WeightedSoundSetMixin.java b/src/main/java/dev/stardust/mixin/WeightedSoundSetMixin.java index 8d62a2e..76b5f17 100644 --- a/src/main/java/dev/stardust/mixin/WeightedSoundSetMixin.java +++ b/src/main/java/dev/stardust/mixin/WeightedSoundSetMixin.java @@ -29,7 +29,9 @@ public abstract class WeightedSoundSetMixin implements SoundContainer { // See MusicTweaks.java @Inject(method = "getSound(Lnet/minecraft/util/math/random/Random;)Lnet/minecraft/client/sound/Sound;", at = @At("HEAD"), cancellable = true) private void mixinGetSound(net.minecraft.util.math.random.Random random, CallbackInfoReturnable cir) { - MusicTweaks tweaks = Modules.get().get(MusicTweaks.class); + Modules modules = Modules.get(); + if (modules == null) return; + MusicTweaks tweaks = modules.get(MusicTweaks.class); if (tweaks == null || !tweaks.isActive()) return; boolean overwrite = false; diff --git a/src/main/java/dev/stardust/mixin/WorldMixin.java b/src/main/java/dev/stardust/mixin/WorldMixin.java index 6ff0d4e..843684f 100644 --- a/src/main/java/dev/stardust/mixin/WorldMixin.java +++ b/src/main/java/dev/stardust/mixin/WorldMixin.java @@ -22,7 +22,9 @@ public abstract class WorldMixin implements WorldAccess, AutoCloseable { // See StashBrander.java @Inject(method = "playSoundAtBlockCenter", at = @At("HEAD"), cancellable = true) private void mixinPlaySoundAtBlockCenter(BlockPos pos, SoundEvent sound, SoundCategory category, float volume, float pitch, boolean useDistance, CallbackInfo ci) { - StashBrander brander = Modules.get().get(StashBrander.class); + Modules modules = Modules.get(); + if (modules == null) return; + StashBrander brander = modules.get(StashBrander.class); if (!brander.isActive() || !brander.shouldMute()) return; if (sound == SoundEvents.BLOCK_ANVIL_USE || sound == SoundEvents.BLOCK_ANVIL_BREAK) ci.cancel(); }