Make use tcp server

This commit is contained in:
Astatin3
2024-07-14 13:24:00 -06:00
parent f3ac8ec63c
commit a13c585310
15 changed files with 68 additions and 36 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
View File
@@ -2,6 +2,8 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/com.astatin3.no-more-render.main.iml" filepath="$PROJECT_DIR$/.idea/modules/com.astatin3.no-more-render.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.client.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.client.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.main.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.test.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.test.iml" />
</modules>
+4
View File
@@ -14,4 +14,8 @@
<component name="McpModuleSettings">
<option name="srgType" value="SRG" />
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+10 -12
View File
@@ -1,16 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" factoryName="Application" name="Minecraft Client" type="Application">
<option name="MAIN_CLASS_NAME" value="net.fabricmc.devlaunchinjector.Main"/>
<module name="no-more-render.main"/>
<option name="PROGRAM_PARAMETERS" value=""/>
<option name="VM_PARAMETERS" value="-Dfabric.dli.config=/home/astatin3/GitHub/no-more-render/.gradle/loom-cache/launch.cfg -Dfabric.dli.env=client -Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotClient"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/"/>
<configuration default="false" name="Minecraft Client" type="Application" factoryName="Application">
<option name="ALTERNATIVE_JRE_PATH" value="/usr/lib/jvm/temurin-22-jdk-amd64" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
<option name="MAIN_CLASS_NAME" value="net.fabricmc.devlaunchinjector.Main" />
<module name="no-more-render.main" />
<shortenClasspath name="ARGS_FILE" />
<option name="VM_PARAMETERS" value="-Dfabric.dli.config=$USER_HOME$/GitHub/no-more-render/.gradle/loom-cache/launch.cfg -Dfabric.dli.env=client -Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotClient" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/" />
<method v="2">
<option enabled="true" name="Make"/>
<option name="Make" enabled="true" />
</method>
<envs>
</envs>
<shortenClasspath name="ARGS_FILE"/>
<classpathModifications/></configuration>
</configuration>
</component>
+1 -1
View File
@@ -12,5 +12,5 @@
</envs>
<shortenClasspath name="ARGS_FILE"/>
<classpathModifications><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.26.0/659feffdd12280201c8aacb8f7be94f9a883c824/commons-compress-1.26.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.16/51cf043c87253c9f58b539c9f7e44c8894223850/httpcore-4.4.16.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-freetype/3.3.3/a0db6c84a8becc8ca05f9dbfa985edc348a824c7/lwjgl-freetype-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.3.3/2f6b0147078396a58979125a4c947664e98293a/lwjgl-opengl-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.3.3/82d755ca94b102e9ca77283b9e2dc46d1b15fbe5/lwjgl-tinyfd-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.3.3/efa1eb78c5ccd840e9f329717109b5e892d72f8e/lwjgl-glfw-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.17.9/3cad216e3a7f0c19b4b394388bc9ffc446f13b14/text2speech-1.17.9.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.16.0/4e3eb3d79888d76b54e28b350915b5dc3919c9de/commons-codec-1.16.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/73.2/61ad4ef7f9131fcf6d25c34b817f90d6da06c9e9/icu4j-73.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.3.3/25dd6161988d7e65f71d5065c99902402ee32746/lwjgl-stb-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.3.3/b543467b7ff3c6920539a88ee602d34098628be5/lwjgl-jemalloc-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.3.3/daada81ceb5fc0c291fbfdd4433cb8d9423577f2/lwjgl-openal-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.jcraft/jorbis/0.0.17/8872d22b293e8f5d7d56ff92be966e6dc28ebdc6/jorbis-0.0.17.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.3.3/29589b5f87ed335a6c7e7ee6a5775f81f97ecb84/lwjgl-3.3.3.jar"/></classpathModifications></configuration>
<classpathModifications><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.16.0/4e3eb3d79888d76b54e28b350915b5dc3919c9de/commons-codec-1.16.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.3.3/2f6b0147078396a58979125a4c947664e98293a/lwjgl-opengl-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.16/51cf043c87253c9f58b539c9f7e44c8894223850/httpcore-4.4.16.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.3.3/29589b5f87ed335a6c7e7ee6a5775f81f97ecb84/lwjgl-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.3.3/daada81ceb5fc0c291fbfdd4433cb8d9423577f2/lwjgl-openal-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/73.2/61ad4ef7f9131fcf6d25c34b817f90d6da06c9e9/icu4j-73.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.3.3/82d755ca94b102e9ca77283b9e2dc46d1b15fbe5/lwjgl-tinyfd-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.17.9/3cad216e3a7f0c19b4b394388bc9ffc446f13b14/text2speech-1.17.9.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-freetype/3.3.3/a0db6c84a8becc8ca05f9dbfa985edc348a824c7/lwjgl-freetype-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.26.0/659feffdd12280201c8aacb8f7be94f9a883c824/commons-compress-1.26.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.jcraft/jorbis/0.0.17/8872d22b293e8f5d7d56ff92be966e6dc28ebdc6/jorbis-0.0.17.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.3.3/25dd6161988d7e65f71d5065c99902402ee32746/lwjgl-stb-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.3.3/efa1eb78c5ccd840e9f329717109b5e892d72f8e/lwjgl-glfw-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.3.3/b543467b7ff3c6920539a88ee602d34098628be5/lwjgl-jemalloc-3.3.3.jar"/></classpathModifications></configuration>
</component>
@@ -18,8 +18,9 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
@@ -34,6 +35,9 @@ public class HeadlessMinecraftClient {
// System.out.println("#########################################");
// }
BufferedReader reader;
PrintWriter writer;
@Shadow private Thread thread;
@Inject(method = "<init>", at = @At("TAIL"))
@@ -46,12 +50,36 @@ public class HeadlessMinecraftClient {
private void startCommandThread() {
Thread commandThread = new Thread(() -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line;
try {
while ((line = reader.readLine()) != null) {
parseCommand(line);
ServerSocket serverSocket = new ServerSocket(65000);
System.out.println("Server is listening on port " + 65000);
while (true) {
Socket socket = serverSocket.accept();
System.out.println("New client connected");
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
reader = new BufferedReader(new InputStreamReader(input));
writer = new PrintWriter(output, true);
// line = reader.readLine();
do {
line = reader.readLine();
parseCommand(line);
} while (!line.equals("bye"));
socket.close();
// reader.next
}
} catch (Exception e) {
e.printStackTrace();
}
@@ -103,7 +131,7 @@ public class HeadlessMinecraftClient {
}
break;
default:
System.out.println("Unknown command: " + command);
writer.println("Unknown command: " + command);
}
}catch(Exception e){
e.printStackTrace();
@@ -113,7 +141,7 @@ public class HeadlessMinecraftClient {
private void listElements() {
Screen currentScreen = self.currentScreen;
if (currentScreen == null) {
System.out.println("No screen is currently open.");
writer.println("No screen is currently open.");
return;
}
@@ -125,10 +153,10 @@ public class HeadlessMinecraftClient {
private void printElements(List<? extends Element> elements, int depth, AtomicInteger index) {
String indent = " ".repeat(depth);
for (Element element : elements) {
System.out.printf("%s%d: %s%n", indent, index.getAndIncrement(), describeElement(element));
writer.printf("%s%d: %s%n", indent, index.getAndIncrement(), describeElement(element));
if (element instanceof ClickableWidget) {
ClickableWidget widget = (ClickableWidget) element;
System.out.printf("%s Message: %s%n", indent, widget.getMessage().getString());
writer.printf("%s Message: %s%n", indent, widget.getMessage().getString());
}
if (element instanceof net.minecraft.client.gui.ParentElement pe) {
printElements(pe.children(), depth + 1, index);
@@ -147,7 +175,7 @@ public class HeadlessMinecraftClient {
private Element findElement(int targetIndex) {
Screen currentScreen = self.currentScreen;
if (currentScreen == null) {
System.out.println("No screen is currently open.");
writer.println("No screen is currently open.");
return null;
}
@@ -159,7 +187,7 @@ public class HeadlessMinecraftClient {
Element targetElement = findElement(targetIndex);
if (targetElement == null) {
System.out.println("Invalid element index.");
writer.println("Invalid element index.");
return;
}
@@ -167,12 +195,12 @@ public class HeadlessMinecraftClient {
self.execute(() -> {
widget.onClick(widget.getX(), widget.getY());
});
System.out.println("Clicked element: " + describeElement(widget));
writer.println("Clicked element: " + describeElement(widget));
if (widget.getMessage() != null) {
System.out.println("Message: " + widget.getMessage().getString());
writer.println("Message: " + widget.getMessage().getString());
}
} else {
System.out.println("Element is not clickable: " + describeElement(targetElement));
writer.println("Element is not clickable: " + describeElement(targetElement));
}
}
@@ -180,7 +208,7 @@ public class HeadlessMinecraftClient {
Element targetElement = findElement(targetIndex);
if (targetElement == null) {
System.out.println("Invalid element index.");
writer.println("Invalid element index.");
return;
}
@@ -191,9 +219,9 @@ public class HeadlessMinecraftClient {
widget.setText("");
widget.write(text);
});
System.out.println("Wrote in element: " + describeElement(widget));
writer.println("Wrote in element: " + describeElement(widget));
} else {
System.out.println("Element is not a TextFieldWidget: " + describeElement(targetElement));
writer.println("Element is not a TextFieldWidget: " + describeElement(targetElement));
}
}
@@ -222,9 +250,9 @@ public class HeadlessMinecraftClient {
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_PRESS, 0);
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_RELEASE, 0);
});
System.out.println("Pressed key: " + keyName);
writer.println("Pressed key: " + keyName);
} else {
System.out.println("Unknown key: " + keyName);
writer.println("Unknown key: " + keyName);
}
}
@@ -235,9 +263,9 @@ public class HeadlessMinecraftClient {
self.execute(() -> {
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_PRESS, 0);
});
System.out.println("Key down: " + keyName);
writer.println("Key down: " + keyName);
} else {
System.out.println("Unknown key: " + keyName);
writer.println("Unknown key: " + keyName);
}
}
@@ -248,9 +276,9 @@ public class HeadlessMinecraftClient {
self.execute(() -> {
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_RELEASE, 0);
});
System.out.println("Key up: " + keyName);
writer.println("Key up: " + keyName);
} else {
System.out.println("Unknown key: " + keyName);
writer.println("Unknown key: " + keyName);
}
}