Skip to content

Commit

Permalink
Port of Commit 72032ca from QC's Pojlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Novampr committed Nov 14, 2024
1 parent 02b2a9d commit 3375e39
Show file tree
Hide file tree
Showing 8 changed files with 319 additions and 314 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pojlib;
package derifted;

import android.app.Activity;
import android.content.Intent;
Expand All @@ -13,7 +13,7 @@
import com.unity3d.player.IUnityPlayerLifecycleEvents;
import com.unity3d.player.UnityPlayer;

public class meow extends Activity implements IUnityPlayerLifecycleEvents
public class Meow extends Activity implements IUnityPlayerLifecycleEvents
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code

Expand Down
34 changes: 15 additions & 19 deletions src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,29 @@

import android.app.Activity;

import pojlib.util.JREUtils;
import pojlib.util.VLoader;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* This class is the only class used by the launcher to communicate and talk to pojlib. This keeps pojlib and launcher separate.
* If we ever make breaking change to either project, we can make a new api class to accommodate for those changes without
* having to make changes to either project deeply.
* This class is used to prepare for game launch, prepares final java arguments and sets up logging,
* provides the aarguments for Regal and gives the JVM certain information useful for debugging.
*/
public class API {
/**
* Launch the game
*
* @param activity The activity of android
* @param username the user's username
* @param versionName the minecraft version name
* @param gameDir the game directory, kind of like ".minecraft" for this
* @param assetsDir the equivelant of .minecraft/assets
* @param assetIndex this is the assetindex minecraft lists from the api
* @param formattedUuid this is the user's uuid
* @param accessToken the minecraft bearer token
* @param userType should always be "msa", used to be able to do "mojang"
* @param memoryValue the amount of ram to give to minecraft
* @param questModel the quest's model
* @param activity The activity of Android
* @param username The user's username
* @param versionName The Minecraft version name
* @param gameDir The game directory, kind of like ".minecraft" for this
* @param assetsDir The equivelant of .minecraft/assets
* @param assetIndex This is the asset index Minecraft lists from the API
* @param formattedUuid The user's UUID
* @param accessToken The Minecraft login token
* @param userType Should be "msa" always, "mojang" is legacy
* @param memoryValue The amount of ram to allocate to Minecraft
* @param vrModel The headset's model
*/
@SuppressWarnings("unused")
public static void startGame(
Expand All @@ -43,7 +39,7 @@ public static void startGame(
String userType,
String versionType,
String memoryValue,
String questModel,
String vrModel,
String mainClass,
String[] additionalArgs,
String[] mcAdditionalArgs,
Expand All @@ -59,7 +55,7 @@ public static void startGame(
JREUtils.redirectAndPrintJRELog(activity);
VLoader.setAndroidInitInfo(activity);
try {
JREUtils.launchJavaVM(activity, allArgs, mcArgs, mcAdditionalArgs, gameDir, memoryValue, questModel, mainClass, jvmHome);
JREUtils.launchJavaVM(activity, allArgs, mcArgs, mcAdditionalArgs, gameDir, memoryValue, vrModel, mainClass, jvmHome);
} catch (Throwable t) {
throw new RuntimeException("JVM has stopped.", t);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package pojlib.util;

import android.annotation.SuppressLint;
import android.content.Context;

public class Constants {
private static String filesDir;

@SuppressLint("SdCardPath")
public static String getFilesDir(Context activity) {
if (filesDir == null) {
filesDir = activity.getFilesDir().getAbsolutePath();
}
return filesDir;
}
}
package pojlib;

import android.annotation.SuppressLint;
import android.content.Context;

public class Constants {
private static String filesDir;

@SuppressLint("SdCardPath")
public static String getFilesDir(Context activity) {
if (filesDir == null) {
filesDir = activity.getFilesDir().getAbsolutePath();
}
return filesDir;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pojlib.util;
package pojlib;

import android.app.Activity;
import android.content.Context;
Expand Down Expand Up @@ -132,13 +132,13 @@ public static void relocateLibPath(Context ctx, String jvmHome) {
sNativeLibDir;
}

public static void setJavaEnvironment(Activity activity, String gameDir, String questModel, String jvmHome) throws Throwable {
public static void setJavaEnvironment(Activity activity, String gameDir, String vrModel, String jvmHome) throws Throwable {
Map<String, String> envMap = new ArrayMap<>();
envMap.put("POJLIB_NATIVEDIR", activity.getApplicationInfo().nativeLibraryDir);
envMap.put("JAVA_HOME", jvmHome);
envMap.put("HOME", gameDir);
envMap.put("TMPDIR", activity.getCacheDir().getAbsolutePath());
envMap.put("VR_MODEL", questModel);
envMap.put("VR_MODEL", vrModel);
envMap.put("POJLIB_RENDERER", "regal");

envMap.put("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
Expand Down Expand Up @@ -168,9 +168,9 @@ public static void setJavaEnvironment(Activity activity, String gameDir, String
setLdLibraryPath(jvmLibraryPath+":"+LD_LIBRARY_PATH);
}

public static int launchJavaVM(Activity activity, List<String> JVMArgs, String[] mcArgs, String[] mcAdditionalArgs, String gameDir, String memoryValue, String questModel, String mainClass, String jvmHome) throws Throwable {
public static int launchJavaVM(Activity activity, List<String> JVMArgs, String[] mcArgs, String[] mcAdditionalArgs, String gameDir, String memoryValue, String vrModel, String mainClass, String jvmHome) throws Throwable {
relocateLibPath(activity, jvmHome);
setJavaEnvironment(activity, gameDir, questModel, jvmHome);
setJavaEnvironment(activity, gameDir, vrModel, jvmHome);

List<String> userArgs = getJavaArgs(activity, gameDir, jvmHome);

Expand All @@ -180,15 +180,15 @@ public static int launchJavaVM(Activity activity, List<String> JVMArgs, String[]
userArgs.add("-Xmx" + memoryValue + "M");

userArgs.add("-XX:+UseZGC");
userArgs.add("-XX:+ZGenerational");
userArgs.add("-XX:+ZGenerational"); // Not compatible with Java 17, perhaps these should be determined by the launcher and not Pojlib?
userArgs.add("-XX:+UnlockExperimentalVMOptions");
userArgs.add("-XX:+AllowUserSignalHandlers");
userArgs.add("-XX:+UseSignalChaining");
userArgs.add("-XX:+DisableExplicitGC");
userArgs.add("-XX:+UseCriticalJavaThreadPriority");

userArgs.add("-Dorg.lwjgl.opengl.libname=libtinywrapper.so");
userArgs.add("-Dorg.lwjgl.opengles.libname=" + "/system/lib64/libGLESv3.so");
userArgs.add("-Dorg.lwjgl.egl.libname=" + "/system/lib64/libEGL_dri.so");
userArgs.add("-Dorg.lwjgl.opengles.libname=/system/lib64/libGLESv3.so");
userArgs.add("-Dorg.lwjgl.egl.libname=/system/lib64/libEGL_dri.so");

userArgs.addAll(JVMArgs);
System.out.println(JVMArgs);
Expand Down Expand Up @@ -229,7 +229,7 @@ public static List<String> getJavaArgs(Context ctx, String gameDir, String jvmHo
"-Dglfwstub.windowHeight=" + 720,
"-Dglfwstub.initEgl=false",
"-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation
"-Dnet.minecraft.clientmodname=Redacted"
"-Dnet.minecraft.clientmodname=Derifted"
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
package pojlib.util;

import android.app.Activity;
import androidx.annotation.Keep;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.ref.WeakReference;

/** Singleton class made to log on one file
* The singleton part can be removed but will require more implementation from the end-dev
*/
@Keep
public class Logger {
// getFilesDir
/* Instance variables */
private final File mLogFile;
private PrintStream mLogStream;
private WeakReference<eventLogListener> mLogListenerWeakReference = null;

private Logger(Activity activity){
mLogFile = new File(activity.getExternalFilesDir(null), "latestlog.txt");
// Make a new instance of the log file
mLogFile.delete();
try {
mLogFile.createNewFile();
mLogStream = new PrintStream(mLogFile.getAbsolutePath());
}catch (IOException e){e.printStackTrace();}

}

private static Logger logger;

public static Logger getInstance(Activity activity){
if (logger == null) {
logger = new Logger(activity);
}
return logger;
}


/** Print the text to the log file if not censored */
public void appendToLog(String text){
if(shouldCensorLog(text)) return;
appendToLogUnchecked(text);
}

/** Print the text to the log file, no china censoring there */
public void appendToLogUnchecked(String text){
mLogStream.println(text);
notifyLogListener(text);
}

/** Reset the log file, effectively erasing any previous logs */
public void reset(){
try{
mLogFile.delete();
mLogFile.createNewFile();
mLogStream = new PrintStream(mLogFile.getAbsolutePath());
}catch (IOException e){ e.printStackTrace();}
}

/**
* Perform various checks to see if the log is safe to print
* Subclasses may want to override this behavior
* @param text The text to check
* @return Whether the log should be censored
*/
private static boolean shouldCensorLog(String text){
return text.contains("Session ID is");
}

/** Small listener for anything listening to the log */
public interface eventLogListener {
void onEventLogged(String text);
}

/** Notifies the event listener, if it exists */
private void notifyLogListener(String text){
if(mLogListenerWeakReference == null) return;
eventLogListener logListener = mLogListenerWeakReference.get();
if(logListener == null){
mLogListenerWeakReference = null;
return;
}
logListener.onEventLogged(text);
}
}
package pojlib;

import android.app.Activity;
import androidx.annotation.Keep;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.lang.ref.WeakReference;

/** Singleton class made to log on one file
* The singleton part can be removed but will require more implementation from the end-dev
*/
@Keep
public class Logger {
// getFilesDir
/* Instance variables */
private final File mLogFile;
private PrintStream mLogStream;
private WeakReference<eventLogListener> mLogListenerWeakReference = null;

private Logger(Activity activity){
mLogFile = new File(activity.getExternalFilesDir(null), "latestlog.txt");
// Make a new instance of the log file
mLogFile.delete();
try {
mLogFile.createNewFile();
mLogStream = new PrintStream(mLogFile.getAbsolutePath());
}catch (IOException e){e.printStackTrace();}

}

private static Logger logger;

public static Logger getInstance(Activity activity){
if (logger == null) {
logger = new Logger(activity);
}
return logger;
}


/** Print the text to the log file if not censored */
public void appendToLog(String text){
if(shouldCensorLog(text)) return;
appendToLogUnchecked(text);
}

/** Print the text to the log file, no china censoring there */
public void appendToLogUnchecked(String text){
mLogStream.println(text);
notifyLogListener(text);
}

/** Reset the log file, effectively erasing any previous logs */
public void reset(){
try{
mLogFile.delete();
mLogFile.createNewFile();
mLogStream = new PrintStream(mLogFile.getAbsolutePath());
}catch (IOException e){ e.printStackTrace();}
}

/**
* Perform various checks to see if the log is safe to print
* Subclasses may want to override this behavior
* @param text The text to check
* @return Whether the log should be censored
*/
private static boolean shouldCensorLog(String text){
return text.contains("Session ID is");
}

/** Small listener for anything listening to the log */
public interface eventLogListener {
void onEventLogged(String text);
}

/** Notifies the event listener, if it exists */
private void notifyLogListener(String text){
if(mLogListenerWeakReference == null) return;
eventLogListener logListener = mLogListenerWeakReference.get();
if(logListener == null){
mLogListenerWeakReference = null;
return;
}
logListener.onEventLogged(text);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pojlib.util;
package pojlib;

import android.app.Activity;
import android.content.Context;
Expand Down
Loading

0 comments on commit 3375e39

Please sign in to comment.