summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-13 02:05:49 -0800
committerFuwn <[email protected]>2026-02-13 02:05:49 -0800
commit9817c9b1647faaa1ffe4af5a7620a8602651f438 (patch)
treeff22dd2e017565aadc146062f0c7064e74035df2
parentfix: Decompilation artifact repairs for Java 11 compilation (diff)
downloadworldsplayer-9817c9b1647faaa1ffe4af5a7620a8602651f438.tar.xz
worldsplayer-9817c9b1647faaa1ffe4af5a7620a8602651f438.zip
feat: Reimplement core I/O and system information native methods with pure Java
- FastDataInput: DataInputStream wrapper replacing native binary I/O - DNSLookup: InetAddress.getAllByName() replacing native gethostbyname() - Restorer: Array.newInstance() replacing native makeArray() - SystemInfo: Runtime/File APIs for disk, memory, CPU, platform info - StatMemNode: Runtime APIs for memory status reporting
-rw-r--r--NET/worlds/console/StatMemNode.java12
-rw-r--r--NET/worlds/core/FastDataInput.java80
-rw-r--r--NET/worlds/core/SystemInfo.java49
-rw-r--r--NET/worlds/network/DNSLookup.java17
-rw-r--r--NET/worlds/scape/Restorer.java4
5 files changed, 125 insertions, 37 deletions
diff --git a/NET/worlds/console/StatMemNode.java b/NET/worlds/console/StatMemNode.java
index 1e3fc21..b5031dd 100644
--- a/NET/worlds/console/StatMemNode.java
+++ b/NET/worlds/console/StatMemNode.java
@@ -34,7 +34,8 @@ public class StatMemNode extends StatMan implements MainCallback {
StatisticsRoot.getNode().addChild(this);
}
- public static native void nativeInit();
+ public static void nativeInit() {
+ }
@Override
public String toString() {
@@ -101,5 +102,12 @@ public class StatMemNode extends StatMan implements MainCallback {
this._grabbedList.replaceItem("Available Virtual Memory: " + this._availPageMem + " bytes", 8);
}
- public native void updateMemoryStatus();
+ public void updateMemoryStatus() {
+ Runtime runtime = Runtime.getRuntime();
+
+ this._totPhysMem = (int)runtime.maxMemory();
+ this._availPhysMem = (int)runtime.freeMemory();
+ this._totPageMem = (int)runtime.totalMemory();
+ this._availPageMem = (int)(runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory()));
+ }
}
diff --git a/NET/worlds/core/FastDataInput.java b/NET/worlds/core/FastDataInput.java
index 75a71e7..ffdf882 100644
--- a/NET/worlds/core/FastDataInput.java
+++ b/NET/worlds/core/FastDataInput.java
@@ -1,70 +1,104 @@
package NET.worlds.core;
import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
import java.io.IOException;
public class FastDataInput implements DataInput {
- private int nativeInfo;
+ private DataInputStream dataInputStream;
public FastDataInput(String fileName) throws IOException {
nativeInit();
- this.read(fileName);
+
+ this.dataInputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(fileName)));
}
- public native void close();
+ public void close() {
+ if (this.dataInputStream != null) {
+ try {
+ this.dataInputStream.close();
+ } catch (IOException e) {
+ }
+ }
+ }
@Override
public void readFully(byte[] b) throws IOException {
- this.readFully(b, 0, b.length);
+ this.dataInputStream.readFully(b);
}
- public static native void nativeInit();
+ public static void nativeInit() {
+ }
@Override
- public native void readFully(byte[] var1, int var2, int var3) throws IOException;
+ public void readFully(byte[] var1, int var2, int var3) throws IOException {
+ this.dataInputStream.readFully(var1, var2, var3);
+ }
@Override
- public native int skipBytes(int var1) throws IOException;
+ public int skipBytes(int var1) throws IOException {
+ return this.dataInputStream.skipBytes(var1);
+ }
@Override
- public native boolean readBoolean() throws IOException;
+ public boolean readBoolean() throws IOException {
+ return this.dataInputStream.readBoolean();
+ }
@Override
- public native byte readByte() throws IOException;
+ public byte readByte() throws IOException {
+ return this.dataInputStream.readByte();
+ }
@Override
- public native int readUnsignedByte() throws IOException;
+ public int readUnsignedByte() throws IOException {
+ return this.dataInputStream.readUnsignedByte();
+ }
@Override
- public native short readShort() throws IOException;
+ public short readShort() throws IOException {
+ return this.dataInputStream.readShort();
+ }
@Override
- public native int readUnsignedShort() throws IOException;
+ public int readUnsignedShort() throws IOException {
+ return this.dataInputStream.readUnsignedShort();
+ }
@Override
- public native char readChar() throws IOException;
+ public char readChar() throws IOException {
+ return this.dataInputStream.readChar();
+ }
@Override
- public native int readInt() throws IOException;
+ public int readInt() throws IOException {
+ return this.dataInputStream.readInt();
+ }
@Override
- public native long readLong() throws IOException;
+ public long readLong() throws IOException {
+ return this.dataInputStream.readLong();
+ }
@Override
- public native float readFloat() throws IOException;
+ public float readFloat() throws IOException {
+ return this.dataInputStream.readFloat();
+ }
@Override
- public native double readDouble() throws IOException;
+ public double readDouble() throws IOException {
+ return this.dataInputStream.readDouble();
+ }
@Override
public String readLine() throws IOException {
- assert false;
-
- return null;
+ return this.dataInputStream.readLine();
}
@Override
- public native String readUTF() throws IOException;
-
- private native void read(String var1) throws IOException;
+ public String readUTF() throws IOException {
+ return this.dataInputStream.readUTF();
+ }
}
diff --git a/NET/worlds/core/SystemInfo.java b/NET/worlds/core/SystemInfo.java
index ceb2a7f..8a138aa 100644
--- a/NET/worlds/core/SystemInfo.java
+++ b/NET/worlds/core/SystemInfo.java
@@ -88,27 +88,56 @@ public class SystemInfo implements MainCallback, MainTerminalCallback {
return "[" + Std.getRealTime() + "] ";
}
- public static native int GetDiskFreeSpace(String var0);
+ public static int GetDiskFreeSpace(String var0) {
+ try {
+ java.io.File file = (var0 != null) ? new java.io.File(var0) : new java.io.File(".");
+
+ return (int)(file.getFreeSpace() / 1024L);
+ } catch (Exception e) {
+ return 0;
+ }
+ }
public static int GetDiskFreeSpace() {
return GetDiskFreeSpace(null);
}
- public static native String GetSystemDirectory();
+ public static String GetSystemDirectory() {
+ return System.getProperty("java.home", "");
+ }
- public static native String GetCurrentDirectory();
+ public static String GetCurrentDirectory() {
+ return System.getProperty("user.dir", "");
+ }
- public static native int GetTotalPhysicalMemory();
+ public static int GetTotalPhysicalMemory() {
+ return (int)(Runtime.getRuntime().maxMemory() / 1024L);
+ }
- public static native int GetAvailPhysicalMemory();
+ public static int GetAvailPhysicalMemory() {
+ return (int)(Runtime.getRuntime().freeMemory() / 1024L);
+ }
- public static native int GetTotalPagedMemory();
+ public static int GetTotalPagedMemory() {
+ return (int)(Runtime.getRuntime().totalMemory() / 1024L);
+ }
- public static native int GetAvailPagedMemory();
+ public static int GetAvailPagedMemory() {
+ Runtime runtime = Runtime.getRuntime();
+ long availableMemory = runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory());
+
+ return (int)(availableMemory / 1024L);
+ }
- public static native String GetPlatformID();
+ public static String GetPlatformID() {
+ return System.getProperty("os.name", "Unknown") + " " + System.getProperty("os.version", "");
+ }
- public static native int GetNumberOfProcessors();
+ public static int GetNumberOfProcessors() {
+ return Runtime.getRuntime().availableProcessors();
+ }
- public static native String GetProcessorType();
+ public static String GetProcessorType() {
+ return System.getProperty("os.arch", "Unknown");
+ }
}
diff --git a/NET/worlds/network/DNSLookup.java b/NET/worlds/network/DNSLookup.java
index 878c63d..4775a2f 100644
--- a/NET/worlds/network/DNSLookup.java
+++ b/NET/worlds/network/DNSLookup.java
@@ -128,5 +128,20 @@ public class DNSLookup implements Runnable {
}
}
- private static native String[] gethostbyname(String var0);
+ private static String[] gethostbyname(String var0) {
+ try {
+ java.net.InetAddress[] addresses = java.net.InetAddress.getAllByName(var0);
+ String[] result = new String[addresses.length];
+
+ for (int i = 0; i < addresses.length; i++) {
+ result[i] = addresses[i].getHostAddress();
+ }
+
+ return result;
+ } catch (UnknownHostException e) {
+ System.out.println("DNS lookup failed for: " + var0);
+
+ return new String[0];
+ }
+ }
}
diff --git a/NET/worlds/scape/Restorer.java b/NET/worlds/scape/Restorer.java
index fa1e774..4659518 100644
--- a/NET/worlds/scape/Restorer.java
+++ b/NET/worlds/scape/Restorer.java
@@ -219,7 +219,9 @@ public class Restorer {
return c;
}
- private native Object makeArray(Class<?> var1, int var2);
+ private Object makeArray(Class<?> var1, int var2) {
+ return java.lang.reflect.Array.newInstance(var1, var2);
+ }
public Persister[] restoreArray() throws IOException, TooNewException {
Class<?> arrayclass = null;