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..8c168b2 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextSerializerMixin.java @@ -0,0 +1,48 @@ +package land.chipmunk.chipmunkmod.mixin; + +import com.google.gson.JsonArray; +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 deserialize (JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext, CallbackInfoReturnable cir) { + try { + if (!jsonElement.isJsonArray()) return; + + final JsonArray array = jsonElement.getAsJsonArray(); + + if (array.size() == 0) return; + + JsonElement item = array.get(0); + + int depth = 0; + + while (item != null && item.isJsonArray() && depth < 512) { + if (item.getAsJsonArray().size() == 0 && item.getAsJsonArray().get(0) == null) continue; + + depth++; + + item = item.getAsJsonArray().get(0); + } + + if (depth >= 512) { + cir.setReturnValue(Text.literal("Component is too big").formatted(Formatting.RED)); + + cir.cancel(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java index 8bd3d50..81c0ed6 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java @@ -31,8 +31,8 @@ public class SelfCare extends Listener { public String skin; - private Timer timer = new Timer(); - private Timer chatTimer = new Timer(); + private Timer timer; + private Timer chatTimer; private boolean cspy = false; public boolean hasSkin = false; @@ -66,6 +66,9 @@ public class SelfCare extends Listener { } }; + timer = new Timer(); + chatTimer = new Timer(); + timer.schedule(task, interval, interval); chatTimer.schedule(chatTask, chatInterval, chatInterval); } @@ -138,6 +141,8 @@ public class SelfCare extends Listener { } public void packetReceived(PlayerPositionLookS2CPacket packet) { + if (timer == null) return; + positionPacketsPerSecond++; timer.schedule(new TimerTask() { diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 53d3953..d20e865 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -21,7 +21,8 @@ "ClientConnectionInvoker", "ClientConnectionAccessor", "PlayerListEntryAccessor", - "SharedConstantsMixin" + "SharedConstantsMixin", + "TextSerializerMixin" ], "injectors": { "defaultRequire": 1