From efe2e56cb5dabf2397b9003b2be88ae28b7f9c56 Mon Sep 17 00:00:00 2001 From: blackilykat Date: Tue, 27 Jun 2023 23:13:34 +0200 Subject: [PATCH] Renamed TextMixin to TextSerializerMixin and fixed decorated pot crash + empty name crash --- .../chipmunk/chipmunkmod/mixin/TextMixin.java | 27 ++++++++++--------- .../mixin/TextSerializerMixin.java | 22 +++++++++++++++ 2 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/TextSerializerMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java index 4eb60bb..97a083f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java @@ -1,22 +1,25 @@ package land.chipmunk.chipmunkmod.mixin; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonElement; -import net.minecraft.text.MutableText; +import net.minecraft.text.StringVisitable; +import net.minecraft.text.Style; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; 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 org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import java.lang.reflect.Type; +import java.util.Iterator; +import java.util.Optional; -@Mixin(Text.Serializer.class) -public class TextMixin { - @Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/text/MutableText;", at = @At("HEAD"), cancellable = true) - private void testclient$preventChatOverflowExploit(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext, CallbackInfoReturnable cir) { - Throwable throwable = new Throwable(); - if(throwable.getStackTrace().length >= 1000 && throwable.getStackTrace()[999].getMethodName().equals("deserialize")) cir.setReturnValue(Text.literal("TestClient prevented a text overflow exploit i think ("+throwable.getStackTrace().length+")").formatted(Formatting.GOLD)); - } +@Mixin(Text.class) +public interface TextMixin { + @Inject(method = "visit(Lnet/minecraft/text/StringVisitable$Visitor;)Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;visit(Lnet/minecraft/text/StringVisitable$Visitor;)Ljava/util/Optional;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + private void testclient$preventVisitMethodCrash(StringVisitable.Visitor visitor, CallbackInfoReturnable> cir, Optional optional, Iterator var3, Text text) { + if(text == null) cir.setReturnValue(Optional.empty()); + } + @Inject(method = "visit(Lnet/minecraft/text/StringVisitable$StyledVisitor;Lnet/minecraft/text/Style;)Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;visit(Lnet/minecraft/text/StringVisitable$StyledVisitor;Lnet/minecraft/text/Style;)Ljava/util/Optional;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + private void testclient$preventVisitMethodCrash2(StringVisitable.StyledVisitor styledVisitor, Style style, CallbackInfoReturnable> cir, Style style2, Optional optional, Iterator var5, Text text) { + if(text == null) cir.setReturnValue(Optional.empty()); + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/TextSerializerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextSerializerMixin.java new file mode 100644 index 0000000..7b08a0a --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextSerializerMixin.java @@ -0,0 +1,22 @@ +package land.chipmunk.chipmunkmod.mixin; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonElement; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +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 java.lang.reflect.Type; + +@Mixin(Text.Serializer.class) +public class TextSerializerMixin { + @Inject(method = "deserialize(Lcom/google/gson/JsonElement;Ljava/lang/reflect/Type;Lcom/google/gson/JsonDeserializationContext;)Lnet/minecraft/text/MutableText;", at = @At("HEAD"), cancellable = true) + private void testclient$preventChatOverflowExploit(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext, CallbackInfoReturnable cir) { + Throwable throwable = new Throwable(); + if(throwable.getStackTrace().length >= 1000 && throwable.getStackTrace()[999].getMethodName().equals("deserialize")) cir.setReturnValue(Text.literal("TestClient prevented a text overflow exploit i think ("+throwable.getStackTrace().length+")").formatted(Formatting.GOLD)); + } +}