Skip to content

Commit

Permalink
debug unwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeRNG committed Apr 9, 2024
1 parent 1e4415e commit b888c77
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 136 deletions.
3 changes: 2 additions & 1 deletion src/main/java/dev/dfonline/codeclient/CodeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ public static void clean() {
CodeClient.location = null;
BuildPhaser.disableClipping();
Commands.confirm = null;
Debug.clean();
}

/**
* As much as possible, set CodeClient to it's startup state.
* As much as possible, set CodeClient to its startup state.
*/
public static void reset() {
clean();
Expand Down
115 changes: 51 additions & 64 deletions src/main/java/dev/dfonline/codeclient/dev/Debug/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.dfonline.codeclient.CodeClient;
import dev.dfonline.codeclient.OverlayManager;
import dev.dfonline.codeclient.Utility;
import dev.dfonline.codeclient.config.Config;
import dev.dfonline.codeclient.location.Plot;
import net.minecraft.client.render.VertexConsumerProvider;
Expand All @@ -10,78 +11,78 @@
import net.minecraft.network.listener.PacketListener;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
import net.minecraft.text.PlainTextContent;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Vec3d;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class Debug {
public static boolean active = false;
private static Double CPU = null;
private static List<Text> text = null;
private static boolean active = false;

public static Variables variables = new Variables();
public static Double CPU = null;
private static Variable variable;
public static void clean() {
CPU = null;
text = null;
active = false;
}

public static <T extends PacketListener> boolean handlePacket(Packet<T> packet) {
if(!Config.getConfig().CCDBUG) return false;
if(packet instanceof OverlayMessageS2CPacket overlay) {
String message = overlay.getMessage().getString();
String[] args = message.split(" ");
if(args.length > 0 && args[0].equals("ccdbug")) {
if(args.length > 1) {
if(args[1].equals("hello")) {
active = true;
if(args.length > 3 && CodeClient.location instanceof Plot plot) {
plot.setOrigin(Integer.parseInt(args[2]), Integer.parseInt(args[3]));
}
}
if(args.length > 2 && args[1].equals("var")) {
if(args[2].equals("set")) {
variable = new Variable(message.replaceFirst("^ccdbug var set ",""));
}
if(args[2].equals("type")) {
Variable.ValueType type = Variable.ValueType.valueTypeMap.get(message.replaceFirst("^ccdbug var type ",""));
variable.type = type;
if(type == Variable.ValueType.Dead) {
variables.addOrUpdate(variable);
variable = null;
}
}
if(args[2].equals("value") && variable != null) {
variable.value = message.replaceFirst("^ccdbug var value ", "");
variables.addOrUpdate(variable);
variable = null;
}
var txt = overlay.getMessage();
if(Text.empty().equals(txt)) {
Utility.debug("empty");
return false;
}
var siblings = txt.getSiblings();
if(siblings.isEmpty()) {
Utility.debug("no siblings");
return false;
}
var command = siblings.get(0);
if(!Objects.equals(command.getStyle().getColor(), TextColor.fromRgb(0x00ccdb))) return false;
if(command.getContent().equals(new PlainTextContent.Literal("ccdbug text"))) {
boolean first = true;
text = new ArrayList<>();
for (var part: siblings) {
if(first) {
first = false;
continue;
}
text.add(part);
}
// updateDisplay();
return true;
}
if(active && message.matches("^CPU Usage: \\[▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\([\\d.]+%\\)$")) {
CPU = Double.parseDouble(message.replaceAll("(^CPU Usage: \\[▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\(|%\\)$)",""));
return true;
}
active = true;
return true;
// if(command) {
// if(siblings.size() > 1) {
// text = siblings.get(1);
// }
// else {
// text = Text.empty();
// }
// updateDisplay();
// }
}
return false;
}

public static void updateDisplay() {
if(!active) return;
if(text == null) return;
OverlayManager.setOverlayText();
OverlayManager.addOverlayText(Text.literal("CCDBUG").formatted(Formatting.YELLOW,Formatting.BOLD));
OverlayManager.addOverlayText(Text.empty().append(Text.literal("CCDBUG").formatted(Formatting.YELLOW,Formatting.BOLD)).append(" (/abort to hide)"));
if(CPU != null) {
OverlayManager.addOverlayText(Text.literal("CPU Usage: ").formatted(Formatting.GOLD).append(Text.literal(String.valueOf(CPU)).formatted(Formatting.AQUA)));
OverlayManager.addOverlayText(Text.empty());
}
OverlayManager.addOverlayText(Text.empty());
List<Variable> variableList = List.copyOf(variables.variables);
for (Variable variable: variableList) {
MutableText text = Text.literal(variable.type.name).fillStyle(Style.EMPTY.withColor(variable.type.color)).append(" ").append(Text.literal(variable.name).formatted(Formatting.YELLOW));
if(variable.value != null) {
text.append(" ").append(Text.literal(variable.value).formatted(Formatting.AQUA));
}
OverlayManager.addOverlayText(text);
for(var line: text) {
OverlayManager.addOverlayText(line);
}
}

Expand All @@ -90,25 +91,11 @@ public static void tick() {
updateDisplay();
}
else {
active = false;
variables.clear();
CPU = null;
}
}

public static void render(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers) {
for (Variable variable: variables.variables) {
if(variable.type == Variable.ValueType.Loc && CodeClient.location instanceof Plot plot) {
try {
String[] posmaker = variable.value.replaceAll("^\\[|,|]$","").split(" ");
Vec3d pos = new Vec3d(
Double.parseDouble(posmaker[0]),
Double.parseDouble(posmaker[1]),
Double.parseDouble(posmaker[2]))
.add(plot.getX(),0, plot.getZ());
DebugRenderer.drawString(matrices,vertexConsumers, variable.name, pos.x,pos.y,pos.z, 0xFFFFFF, 0.02F, true, 0, true);
} catch (Exception ignored) {}
}
}
if(active) DebugRenderer.drawString(matrices,vertexConsumers, "womp womp", CodeClient.MC.player.getX(),CodeClient.MC.player.getY(),CodeClient.MC.player.getZ(), 0, 0.02F, true, 0, true);
}
}
48 changes: 0 additions & 48 deletions src/main/java/dev/dfonline/codeclient/dev/Debug/Variable.java

This file was deleted.

23 changes: 0 additions & 23 deletions src/main/java/dev/dfonline/codeclient/dev/Debug/Variables.java

This file was deleted.

0 comments on commit b888c77

Please sign in to comment.