Skip to content

Commit

Permalink
Added null checks to Modules.get() calls in mixins.
Browse files Browse the repository at this point in the history
This should prevent startup crashes when using Meteor's Baritone.
  • Loading branch information
0xTas committed Apr 20, 2024
1 parent c760b83 commit 14d99fb
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/dev/stardust/mixin/BookEditScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/dev/stardust/mixin/BookScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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..")));
Expand All @@ -92,10 +90,12 @@ private void reobfuscateBook(ButtonWidget btn) {
private void mixinInit(CallbackInfo ci) {
if (!(this.contents instanceof BookScreen.WrittenBookContents)) return;

List<String> 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<String> pages = ((WrittenBookContentsAccessor) this.contents).getPages();
AntiToS antiToS = modules.get(AntiToS.class);
BookTools bookTools = modules.get(BookTools.class);
if (antiToS.isActive() && antiToS.booksSetting.get()) {
List<String> filtered = new ArrayList<>();
for (String page : pages) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/ChatHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/stardust/mixin/DoorBlockMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/DrawContextMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/GoatHornItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
8 changes: 6 additions & 2 deletions src/main/java/dev/stardust/mixin/MinecraftClientMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -102,7 +104,9 @@ private void mixinRender(CallbackInfo ci) {
// See MusicTweaks.java
@Inject(method = "getMusicType", at = @At("HEAD"), cancellable = true)
public void mixinGetMusicType(CallbackInfoReturnable<MusicSound> 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();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/MusicTrackerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/NarratorManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/stardust/mixin/SoundSystemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/dev/stardust/mixin/TridentBoostMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ public class TridentBoostMixin {
// See RocketMan.java
@Inject(method = "getMultiplier", at = @At("RETURN"), cancellable = true)
private void configureMultiplier(CallbackInfoReturnable<Double> 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<Boolean> 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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/TridentItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/WeightedSoundSetMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public abstract class WeightedSoundSetMixin implements SoundContainer<Sound> {
// 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<Sound> 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;
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/stardust/mixin/WorldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 14d99fb

Please sign in to comment.