Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
- Prepend java as argv[0]
Browse files Browse the repository at this point in the history
- Fix override mechanism
  • Loading branch information
artdeell committed Feb 4, 2022
1 parent fb7a4b2 commit 97dace3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public static int launchJavaVM(final Activity activity,final List<String> JVMArg
initJavaRuntime();
setupExitTrap(activity.getApplication());
chdir(Tools.DIR_GAME_NEW);
userArgs.add(0,"java"); //argv[0] is the program name according to C standard.

final int exitCode = VMLauncher.launchJVM(userArgs.toArray(new String[0]));
Logger.getInstance().appendToLog("Java Exit code: " + exitCode);
Expand All @@ -340,6 +341,8 @@ public static int launchJavaVM(final Activity activity,final List<String> JVMArg
*/
public static List<String> getJavaArgs(Context ctx) {
List<String> userArguments = parseJavaArguments(LauncherPreferences.PREF_CUSTOM_JAVA_ARGS);
String resolvFile;
resolvFile = new File(Tools.DIR_DATA,"resolv.conf").getAbsolutePath();
String[] overridableArguments = new String[]{
"-Djava.home=" + Tools.DIR_HOME_JRE,
"-Djava.io.tmpdir=" + ctx.getCacheDir().getAbsolutePath(),
Expand All @@ -358,29 +361,30 @@ public static List<String> getJavaArgs(Context ctx) {
"-Dglfwstub.windowWidth=" + CallbackBridge.windowWidth,
"-Dglfwstub.windowHeight=" + CallbackBridge.windowHeight,
"-Dglfwstub.initEgl=false",

"-Dext.net.resolvPath=" +new File(Tools.DIR_DATA,"resolv.conf").getAbsolutePath(),

"-Dext.net.resolvPath=" +resolvFile,
"-Dlog4j2.formatMsgNoLookups=true", //Log4j RCE mitigation

"-Dnet.minecraft.clientmodname=" + Tools.APP_NAME,
"-Dfml.earlyprogresswindow=false" //Forge 1.14+ workaround
};


for (String userArgument : userArguments) {
for(int i=0; i < overridableArguments.length; ++i){
String overridableArgument = overridableArguments[i];
//Only java properties are considered overridable for now
if(userArgument.startsWith("-D") && userArgument.startsWith(overridableArgument.substring(0, overridableArgument.indexOf("=")))){
overridableArguments[i] = ""; //Remove the argument since it is overridden
List<String> additionalArguments = new ArrayList<>();
for(String arg : overridableArguments) {
String strippedArg = arg.substring(0,arg.indexOf('='));
boolean add = true;
for(String uarg : userArguments) {
if(uarg.startsWith(strippedArg)) {
add = false;
break;
}
}
if(add)
additionalArguments.add(arg);
else
Log.i("ArgProcessor","Arg skipped: "+arg);
}

//Add all the arguments
userArguments.addAll(Arrays.asList(overridableArguments));
userArguments.addAll(additionalArguments);
return userArguments;
}

Expand Down
3 changes: 2 additions & 1 deletion app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,6 @@
<string name="vbo_hack_description">Help with compatibility on some old versions</string>
<string name="gles_version_hack_title">Force openGL 1</string>
<string name="gles_version_hack_description">Help with compatibility on some old versions</string>

<string name="arc_capes_title">Arc Capes</string>
<string name="arc_capes_desc">Enables capes from Arc. For more information please visit https://arccapes.com</string>
</resources>

0 comments on commit 97dace3

Please sign in to comment.