forked from ChomeNS/chipmunkmod
patch stack overflow crash (mabe) and fix
This commit is contained in:
parent
82b5259b44
commit
994cbba173
3 changed files with 57 additions and 3 deletions
|
@ -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<MutableText> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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() {
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
"ClientConnectionInvoker",
|
||||
"ClientConnectionAccessor",
|
||||
"PlayerListEntryAccessor",
|
||||
"SharedConstantsMixin"
|
||||
"SharedConstantsMixin",
|
||||
"TextSerializerMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue