Skip to content

Commit

Permalink
Improve LWJGL Install
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Sep 12, 2024
1 parent e95214a commit fda61f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pojlib/InstanceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns
String clientClasspath = Installer.installClient(minecraftVersionInfo, gameDir);
String minecraftClasspath = Installer.installLibraries(minecraftVersionInfo, gameDir);
String modLoaderClasspath = Installer.installLibraries(finalModLoaderVersionInfo, gameDir);
String lwjgl = Installer.installLwjgl(activity);
String lwjgl = UnityPlayerActivity.installLWJGL(activity);

instance.classpath = clientClasspath + File.pathSeparator + minecraftClasspath + File.pathSeparator + modLoaderClasspath + File.pathSeparator + lwjgl;

Expand Down
30 changes: 28 additions & 2 deletions src/main/java/pojlib/UnityPlayerActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pojlib;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.content.res.Configuration;
Expand All @@ -12,7 +13,10 @@
import com.unity3d.player.UnityPlayer;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

import pojlib.util.Constants;
import pojlib.util.FileUtil;

public class UnityPlayerActivity extends ActivityGroup implements IUnityPlayerLifecycleEvents
Expand Down Expand Up @@ -51,10 +55,32 @@ protected String updateUnityCommandLineArguments(String cmdLine)
mUnityPlayer = new UnityPlayer(this, this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
File zip = new File(this.getFilesDir() + "/runtimes/JRE-22");
if (!zip.exists()) {

File jre = new File(this.getFilesDir() + "/runtimes/JRE-22");
if (!jre.exists()) {
FileUtil.unzipArchiveFromAsset(this, "JRE-22.zip", this.getFilesDir() + "/runtimes/JRE-22");
}

try {
installLWJGL(this);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static String installLWJGL(Activity activity) throws IOException {
File lwjgl = new File(Constants.USER_HOME + "/lwjgl3/lwjgl-glfw-classes.jar");
byte[] lwjglAsset = FileUtil.loadFromAssetToByte(activity, "lwjgl/lwjgl-glfw-classes.jar");

if (!lwjgl.exists()) {
Objects.requireNonNull(lwjgl.getParentFile()).mkdirs();
FileUtil.write(lwjgl.getAbsolutePath(), lwjglAsset);
} else if (!FileUtil.matchingAssetFile(lwjgl, lwjglAsset)) {
Objects.requireNonNull(lwjgl.getParentFile()).mkdirs();
FileUtil.write(lwjgl.getAbsolutePath(), lwjglAsset);
}

return lwjgl.getAbsolutePath();
}

@Override
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/pojlib/install/Installer.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,6 @@ public AsyncDownload( Map.Entry<String, JsonElement> entry, VersionInfo versionI
}
}

public static String installLwjgl(Activity activity) throws IOException {
File lwjgl = new File(Constants.USER_HOME + "/lwjgl3/lwjgl-glfw-classes.jar");
if (!lwjgl.exists()) {
Objects.requireNonNull(lwjgl.getParentFile()).mkdirs();
FileUtil.write(lwjgl.getAbsolutePath(), FileUtil.loadFromAssetToByte(activity, "lwjgl/lwjgl-glfw-classes.jar"));
}
return lwjgl.getAbsolutePath();
}

//Used for mod libraries, vanilla is handled a different (tbh better) way
private static String parseLibraryNameToPath(String libraryName) {
String[] parts = libraryName.split(":");
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/pojlib/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public static byte[] loadFromAssetToByte(Context ctx, String inFile) {
return buffer;
}

public static boolean matchingAssetFile(File sourceFile, byte[] assetFile) throws IOException {
byte[] sf = Files.readAllBytes(sourceFile.toPath());
return sf == assetFile;
}

public static String read(String path) throws IOException {
return read(Files.newInputStream(Paths.get(path)));
}
Expand Down

0 comments on commit fda61f9

Please sign in to comment.