Renamed TextMixin to TextSerializerMixin and fixed decorated pot crash + empty name crash

This commit is contained in:
blackilykat 2023-06-27 23:13:34 +02:00
parent 914c9d9075
commit efe2e56cb5
2 changed files with 37 additions and 12 deletions

View file

@ -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<MutableText> 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 <T> void testclient$preventVisitMethodCrash(StringVisitable.Visitor<T> visitor, CallbackInfoReturnable<Optional<T>> 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 <T> void testclient$preventVisitMethodCrash2(StringVisitable.StyledVisitor<T> styledVisitor, Style style, CallbackInfoReturnable<Optional<T>> cir, Style style2, Optional optional, Iterator var5, Text text) {
if(text == null) cir.setReturnValue(Optional.empty());
}
}

View file

@ -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<MutableText> 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));
}
}