Skip to content

Commit

Permalink
move hook to gatherEnvironmentDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
Ecdcaeb authored Dec 14, 2024
1 parent ac4f302 commit 47bf523
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
22 changes: 22 additions & 0 deletions src/main/java/com/cleanroommc/fugue/helper/HookHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import org.objectweb.asm.Opcodes;
import org.lwjgl.opengl.GL11;
import oshi.SystemInfo;
import top.outlands.foundation.TransformerDelegate;
import top.outlands.foundation.boot.ActualClassLoader;

Expand Down Expand Up @@ -209,6 +211,26 @@ public static void addToClasspath(File file) {
} catch (MalformedURLException ignored) {}
}

public static HashMap<String, Object> essential$gatherEnvironmentDetails() {
HashMap<String, String> hardwareMap = new HashMap<>();
try {
hardwareMap.put("cpu", new SystemInfo().getHardware().getProcessor().getProcessorIdentifier().getName());
}
catch (Throwable e) {
hardwareMap.putIfAbsent("cpu", "UNKNOWN");
}
hardwareMap.put("gpu", GL11.glGetString(GL11.GL_RENDERER));
hardwareMap.put("allocatedMemory", (Runtime.getRuntime().maxMemory() / 1024L / 1024L));
try {
hardwareMap.put("os", System.getProperty("os.name", "UNKNOWN"));
hardwareMap.put("osVersion", System.getProperty("os.version", "UNKNOWN"));
}
catch (Throwable e) {
hardwareMap.putIfAbsent("os", "UNKNOWN");
hardwareMap.putIfAbsent("osVersion", "UNKNOWN");
}
}

public static String[] listToArray(List<String> list) {
return list.toArray(new String[0]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
import org.objectweb.asm.Label;
import org.objectweb.asm.tree.*;

import org.lwjgl.opengl.GL11;

import java.util.HashMap;
import oshi.SystemInfo;
import top.outlands.foundation.IExplicitTransformer;

import java.util.ListIterator;
Expand All @@ -33,34 +29,14 @@ public byte[] transform(byte[] bytes) {
method.visitTypeInsn(NEW, "gg/essential/connectionmanager/common/packet/telemetry/ClientTelemetryPacket");
method.visitInsn(DUP);
method.visitLdcInsn("HARDWARE_V2");
method.visitMethodInsn(INVOKESTATIC, "com/cleanroommc/fugue/transformer/essential/EssentialTelemetryManagerTransformer", "sendHardwareAndOSTelemetryImpl", "()Ljava/util/HashMap;", false);
method.visitMethodInsn(INVOKESTATIC, "com/cleanroommc/fugue/helper/HookHelper", "essential$gatherEnvironmentDetails", "()Ljava/util/HashMap;", false);
method.visitMethodInsn(INVOKESPECIAL, "gg/essential/connectionmanager/common/packet/telemetry/ClientTelemetryPacket", "<init>", "(Ljava/lang/String;Ljava/util/Map;)V", false);
method.visitMethodInsn(INVOKEVIRTUAL, "gg/essential/network/connectionmanager/telemetry/TelemetryManager", "enqueue", "(Lgg/essential/connectionmanager/common/packet/telemetry/ClientTelemetryPacket;)V", false);
method.visitInsn(RETURN);
}
}
}

public static HashMap<String, Object> sendHardwareAndOSTelemetryImpl() {
HashMap<String, String> hardwareMap = new HashMap<>();
try {
hardwareMap.put("cpu", new SystemInfo().getHardware().getProcessor().getProcessorIdentifier().getName());
}
catch (Throwable e) {
hardwareMap.putIfAbsent("cpu", "UNKNOWN");
}
hardwareMap.put("gpu", GL11.glGetString(GL11.GL_RENDERER));
hardwareMap.put("allocatedMemory", (Runtime.getRuntime().maxMemory() / 1024L / 1024L));
try {
hardwareMap.put("os", System.getProperty("os.name", "UNKNOWN"));
hardwareMap.put("osVersion", System.getProperty("os.version", "UNKNOWN"));
}
catch (Throwable e) {
hardwareMap.putIfAbsent("os", "UNKNOWN");
hardwareMap.putIfAbsent("osVersion", "UNKNOWN");
}
}

@Override
public int getPriority() {
return 0;
Expand Down

0 comments on commit 47bf523

Please sign in to comment.