Skip to content

Commit

Permalink
AntiToS - Now censors item, entity, & inventory screen names.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xTas committed May 26, 2024
1 parent 14d99fb commit 3e20431
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 35 deletions.
3 changes: 1 addition & 2 deletions src/main/java/dev/stardust/mixin/BookScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import meteordevelopment.meteorclient.systems.modules.Modules;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;


/**
* @author Tas [@0xTas] <[email protected]>
**/
Expand Down Expand Up @@ -96,7 +95,7 @@ private void mixinInit(CallbackInfo ci) {
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()) {
if (antiToS.isActive()) {
List<String> filtered = new ArrayList<>();
for (String page : pages) {
if (antiToS.containsBlacklistedText(page)) {
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/dev/stardust/mixin/BossBarHudMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.stardust.mixin;

import net.minecraft.text.Text;
import dev.stardust.modules.AntiToS;
import net.minecraft.entity.boss.BossBar;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.BossBarHud;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import meteordevelopment.meteorclient.systems.modules.Modules;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* @author Tas [0xTas] <[email protected]>
**/
@Mixin(BossBarHud.class)
public class BossBarHudMixin {

// See AntiToS.java
@Inject(method = "renderBossBar(Lnet/minecraft/client/gui/DrawContext;IILnet/minecraft/entity/boss/BossBar;)V", at = @At("HEAD"))
private void censorBossBar(DrawContext context, int x, int y, BossBar bossBar, CallbackInfo ci) {
Modules modules = Modules.get();
if (modules == null) return;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive()) return;

if (antiToS.containsBlacklistedText(bossBar.getName().getString())) {
bossBar.setName(Text.literal(antiToS.censorText(bossBar.getName().getString()).formatted(bossBar.getName().getStyle())));
}
}
}
18 changes: 15 additions & 3 deletions src/main/java/dev/stardust/mixin/ChatHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import net.minecraft.text.Text;
import dev.stardust.modules.AntiToS;
import net.minecraft.text.MutableText;
import org.spongepowered.asm.mixin.Mixin;
import net.minecraft.client.gui.hud.ChatHud;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import meteordevelopment.meteorclient.systems.modules.Modules;

import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* @author Tas [0xTas] <[email protected]>
Expand All @@ -25,7 +27,17 @@ private Text censorChatMessage(Text message) {
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);
if (!antiToS.isActive()) return message;
MutableText mText = Text.literal(antiToS.censorText(message.getString()));
return (antiToS.containsBlacklistedText(message.getString()) ? mText.setStyle(message.getStyle()) : message);
}

@Inject(method = "addMessage(Lnet/minecraft/text/Text;)V", at = @At("HEAD"), cancellable = true)
private void maybeCancelAddMessage(Text message, CallbackInfo ci) {
Modules modules = Modules.get();
if (modules == null) return;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive()) return;
if (antiToS.chatMode.get() == AntiToS.ChatMode.Remove && antiToS.containsBlacklistedText(message.getString())) ci.cancel();
}
}
28 changes: 28 additions & 0 deletions src/main/java/dev/stardust/mixin/EntityRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.stardust.mixin;

import net.minecraft.text.Text;
import dev.stardust.modules.AntiToS;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import net.minecraft.client.render.entity.EntityRenderer;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import meteordevelopment.meteorclient.systems.modules.Modules;

/**
* @author Tas [0xTas] <[email protected]>
**/
@Mixin(EntityRenderer.class)
public abstract class EntityRendererMixin {

// See AntiToS.java
@ModifyVariable(method = "renderLabelIfPresent", at = @At("HEAD"), argsOnly = true)
private Text censorEntityName(Text name) {
Modules modules = Modules.get();
if (modules == null) return name;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive()) return name;

if (!antiToS.containsBlacklistedText(name.getString())) return name;
return Text.literal(antiToS.censorText(name.getString())).setStyle(name.getStyle());
}
}
43 changes: 43 additions & 0 deletions src/main/java/dev/stardust/mixin/InGameHudMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dev.stardust.mixin;

import net.minecraft.text.Text;
import dev.stardust.modules.AntiToS;
import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import net.minecraft.client.gui.DrawContext;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.gui.hud.InGameHud;
import org.spongepowered.asm.mixin.injection.At;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import org.spongepowered.asm.mixin.injection.Inject;
import meteordevelopment.meteorclient.systems.modules.Modules;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* @author Tas [0xTas] <[email protected]>
**/
@Mixin(InGameHud.class)
public class InGameHudMixin {
@Shadow
private ItemStack currentStack;

// See AntiToS.java
@Inject(
method = "renderHeldItemTooltip",
at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;hasCustomName()Z", shift = At.Shift.BEFORE)
)
private void censorItemTooltip(DrawContext context, CallbackInfo ci, @Local LocalRef<MutableText> itemName) {
if (this.currentStack.isEmpty()) return;

Modules modules = Modules.get();
if (modules == null) return;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive()) return;

if (antiToS.containsBlacklistedText(itemName.get().getString())) {
itemName.set(Text.empty().append(antiToS.censorText(itemName.get().getString())).formatted(this.currentStack.getRarity().formatting));
}
}
}
53 changes: 53 additions & 0 deletions src/main/java/dev/stardust/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package dev.stardust.mixin;

import java.util.List;
import net.minecraft.text.Text;
import net.minecraft.util.Rarity;
import dev.stardust.modules.AntiToS;
import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.jetbrains.annotations.Nullable;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import meteordevelopment.meteorclient.systems.modules.Modules;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

/**
* @author Tas [0xTas] <[email protected]>
**/
@Mixin(ItemStack.class)
public abstract class ItemStackMixin {
@Shadow
public abstract Rarity getRarity();

// See AntiToS.java
@Inject(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;hasCustomName()Z", shift = At.Shift.BEFORE))
private void censorItemTooltip(@Nullable PlayerEntity player, TooltipContext context, CallbackInfoReturnable<List<Text>> cir, @Local(ordinal = 0)LocalRef<MutableText> name) {
Modules modules = Modules.get();
if (modules == null) return;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive()) return;

if (antiToS.containsBlacklistedText(name.get().getString())) {
name.set(Text.empty().append(antiToS.censorText(name.get().getString()).formatted(this.getRarity().formatting)));
}
}

@Inject(method = "toHoverableText", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;hasCustomName()Z", shift = At.Shift.BEFORE))
private void censorHoveredText(CallbackInfoReturnable<Text> cir, @Local(ordinal = 0)LocalRef<MutableText> name) {
Modules modules = Modules.get();
if (modules == null) return;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive()) return;

if (antiToS.containsBlacklistedText(name.get().getString())) {
name.set(Text.empty().append(antiToS.censorText(name.get().getString())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.SignBlockEntityRenderer;


/**
* @author Tas [0xTas] <[email protected]>
**/
Expand All @@ -26,7 +25,7 @@ private SignText modifyRenderedText(SignText signText) {
Modules modules = Modules.get();
if (modules == null ) return signText;
AntiToS antiToS = modules.get(AntiToS.class);
if (!antiToS.isActive() || !antiToS.signsSetting.get()) return signText;
if (!antiToS.isActive()) return signText;

String testText = Arrays.stream(signText.getMessages(false))
.map(Text::getString)
Expand Down
46 changes: 18 additions & 28 deletions src/main/java/dev/stardust/modules/AntiToS.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import meteordevelopment.meteorclient.settings.*;
import meteordevelopment.meteorclient.systems.modules.Module;


/**
* @author Tas [0xTas] <[email protected]>
**/
Expand All @@ -30,79 +29,66 @@ public enum SignMode {
Censor, Replace
}

public final Setting<Boolean> chatSetting = sgSources.add(
new BoolSetting.Builder()
.name("Chat Messages")
.description("Censor text in chat if it matches the content blacklist.")
.defaultValue(true)
.build()
);

public final Setting<Boolean> booksSetting = sgSources.add(
new BoolSetting.Builder()
.name("Book Text")
.description("Censor text in books if it matches the content blacklist.")
.defaultValue(true)
.build()
);
public enum ChatMode {
Censor, Remove
}

public final Setting<Boolean> signsSetting = sgSources.add(
new BoolSetting.Builder()
.name("Sign Text")
.description("Filter sign text according to the content blacklist.")
.defaultValue(true)
public final Setting<ChatMode> chatMode = sgSources.add(
new EnumSetting.Builder<ChatMode>()
.name("Sign Mode")
.description("Censor or completely replace SignText that matches the filter.")
.defaultValue(ChatMode.Censor)
.build()
);
private final Setting<SignMode> signMode = sgSources.add(
new EnumSetting.Builder<SignMode>()
.name("Sign Mode")
.description("Censor or completely replace SignText that matches the filter.")
.defaultValue(SignMode.Censor)
.visible(signsSetting::get)
.build()
);
private final Setting<String> familyFriendlyLine1 = sgSources.add(
new StringSetting.Builder()
.name("Replacement Line 1")
.defaultValue("Original text")
.visible(() -> signsSetting.get() && signMode.get() == SignMode.Replace)
.visible(() -> signMode.get() == SignMode.Replace)
.build()
);
private final Setting<String> familyFriendlyLine2 = sgSources.add(
new StringSetting.Builder()
.name("Replacement Line 2")
.defaultValue("was replaced by")
.visible(() -> signsSetting.get() && signMode.get() == SignMode.Replace)
.visible(() -> signMode.get() == SignMode.Replace)
.build()
);
private final Setting<String> familyFriendlyLine3 = sgSources.add(
new StringSetting.Builder()
.name("Replacement Line 3")
.defaultValue("Stardust AntiToS")
.visible(() -> signsSetting.get() && signMode.get() == SignMode.Replace)
.visible(() -> signMode.get() == SignMode.Replace)
.build()
);
private final Setting<String> familyFriendlyLine4 = sgSources.add(
new StringSetting.Builder()
.name("Replacement Line 4")
.defaultValue("plz no ban ☺")
.visible(() -> signsSetting.get() && signMode.get() == SignMode.Replace)
.visible(() -> signMode.get() == SignMode.Replace)
.build()
);
private final Setting<DyeColor> familyFriendlyColor = sgSources.add(
new EnumSetting.Builder<DyeColor>()
.name("Replacement Color")
.description("Render replacement SignText with the selected dye color.")
.defaultValue(DyeColor.RED)
.visible(() -> signsSetting.get() && signMode.get() == SignMode.Replace)
.visible(() -> signMode.get() == SignMode.Replace)
.build()
);
private final Setting<Boolean> familyFriendlyGlowing = sgSources.add(
new BoolSetting.Builder()
.name("Replacement Glowing")
.description("Render replacement SignText with glowing text.")
.defaultValue(true)
.visible(() -> signsSetting.get() && signMode.get() == SignMode.Replace)
.visible(() -> signMode.get() == SignMode.Replace)
.build()
);

Expand Down Expand Up @@ -141,7 +127,11 @@ private void initBlacklistText() {
}

// See ChatHudMixin.java
// && ItemStackMixin.java
// && InGameHudMixin.java
// && BookScreenMixin.java
// && TextRendererMixin.java
// && EntityRendererMixin.java
// && SignBlockEntityRendererMixin.java
public boolean containsBlacklistedText(String text) {
return blacklisted.stream().anyMatch(line -> text.trim().toLowerCase().contains(line.trim().toLowerCase()));
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/stardust.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
"compatibilityLevel": "JAVA_17",
"client": [
"ChatHudMixin",
"InGameHudMixin",
"BossBarHudMixin",
"BookScreenMixin",
"DrawContextMixin",
"SoundSystemMixin",
"TitleScreenMixin",
"MusicTrackerMixin",
"EntityRendererMixin",
"AnvilScreenAccessor",
"BookEditScreenMixin",
"GameOptionsAccessor",
Expand All @@ -32,6 +35,7 @@
},
"mixins": [
"WorldMixin",
"ItemStackMixin",
"DoorBlockMixin",
"TridentItemMixin",
"GoatHornItemMixin",
Expand Down

0 comments on commit 3e20431

Please sign in to comment.