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

Commit

Permalink
Upstreamify profiles (PojavLauncherTeam#2765)
Browse files Browse the repository at this point in the history
* add Arc capes DNS injector

* Bug fix: Arc DNS injector breaks on Java 17

Error:
Failed to inject cache!
java.lang.reflect.InaccessibleObjectException: Unable to make java.net.InetAddress$CachedAddresses(java.lang.String,java.net.InetAddress[],long) accessible: module java.base does not "opens java.net" to unnamed module @4157f54e

* Validate assets even if it’s fully downloaded (PojavLauncherTeam#2730)

* Update MinecraftDownloaderTask.java

Co-authored-by: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com>
  • Loading branch information
artdeell and khanhduytran0 authored Feb 20, 2022
1 parent d7556c3 commit 0b4d775
Show file tree
Hide file tree
Showing 16 changed files with 1,047 additions and 7 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ private void initMain() throws Throwable {
// TODO: Remove after implement.
Tools.copyAssetFile(this, "launcher_profiles.json", Tools.DIR_GAME_NEW, false);
Tools.copyAssetFile(this,"resolv.conf",Tools.DIR_DATA, true);
Tools.copyAssetFile(this,"arc_dns_injector.jar",Tools.DIR_DATA, true);
AssetManager am = this.getAssets();

unpackComponent(am, "caciocavallo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public static void launchMinecraft(final Activity activity, MinecraftAccount pro
// Only Java 8 supports headful AWT for now
if (JREUtils.jreReleaseList.get("JAVA_VERSION").equals("1.8.0")) {
getCacioJavaArgs(javaArgList, false);
} else if (LauncherPreferences.PREF_ARC_CAPES) {
// Opens the java.net package to Arc DNS injector on Java 9+
javaArgList.add("--add-opens=java.base/java.net=ALL-UNNAMED");
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class LauncherPreferences
public static boolean PREF_VBO_DISABLE_HACK = false;
public static boolean PREF_VIRTUAL_MOUSE_START = false;
public static boolean PREF_OPENGL_VERSION_HACK = false;
public static boolean PREF_ARC_CAPES = false;


public static void loadPreferences(Context ctx) {
Expand Down Expand Up @@ -73,6 +74,7 @@ public static void loadPreferences(Context ctx) {
PREF_ENABLE_PROFILES = DEFAULT_PREF.getBoolean("enable_profiles", false);
PREF_VIRTUAL_MOUSE_START = DEFAULT_PREF.getBoolean("mouse_start", false);
PREF_OPENGL_VERSION_HACK = DEFAULT_PREF.getBoolean("gles_version_hack", false);
PREF_ARC_CAPES = DEFAULT_PREF.getBoolean("arc_capes",false);

/*
if (PREF_CUSTOM_JAVA_ARGS.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ public void downloadAssets(final JAssets assets, String assetsVersion, final Fil
LinkedBlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>();
final ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 500, TimeUnit.MILLISECONDS, workQueue);
mActivity.mIsAssetsProcessing = true;
File hasDownloadedFile = new File(outputDir, "downloaded/" + assetsVersion + ".downloaded");
if (!hasDownloadedFile.exists()) {
//File hasDownloadedFile = new File(outputDir, "downloaded/" + assetsVersion + ".downloaded");
if (true) { //(!hasDownloadedFile.exists()) {
System.out.println("Assets begin time: " + System.currentTimeMillis());
Map<String, JAssetInfo> assetsObjects = assets.objects;
int assetsSizeBytes=0;
Expand Down Expand Up @@ -501,8 +501,8 @@ public void downloadAssets(final JAssets assets, String assetsVersion, final Fil
}
if(mActivity.mIsAssetsProcessing) {
System.out.println("Unskipped download done!");
if(!hasDownloadedFile.getParentFile().exists())hasDownloadedFile.getParentFile().mkdirs();
hasDownloadedFile.createNewFile();
//if(!hasDownloadedFile.getParentFile().exists())hasDownloadedFile.getParentFile().mkdirs();
//hasDownloadedFile.createNewFile();
}else{
System.out.println("Skipped!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ 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[]{

ArrayList<String> overridableArguments = new ArrayList<>(Arrays.asList(
"-Djava.home=" + Tools.DIR_HOME_JRE,
"-Djava.io.tmpdir=" + ctx.getCacheDir().getAbsolutePath(),
"-Duser.home=" + new File(Tools.DIR_GAME_NEW).getParent(),
Expand All @@ -366,7 +367,10 @@ public static List<String> getJavaArgs(Context ctx) {

"-Dnet.minecraft.clientmodname=" + Tools.APP_NAME,
"-Dfml.earlyprogresswindow=false" //Forge 1.14+ workaround
};
));
if(LauncherPreferences.PREF_ARC_CAPES) {
overridableArguments.add("-javaagent:"+new File(Tools.DIR_DATA,"arc_dns_injector.jar").getAbsolutePath()+"=23.95.137.176");
}
List<String> additionalArguments = new ArrayList<>();
for(String arg : overridableArguments) {
String strippedArg = arg.substring(0,arg.indexOf('='));
Expand Down
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,5 @@
<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>
<string name="arc_capes_desc">Enables capes from Arc. For more information please visit https://arccapes.com. Requires OptiFine.</string>
</resources>
5 changes: 5 additions & 0 deletions app_pojavlauncher/src/main/res/xml/pref_misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
android:key="checkLibraries"
android:summary="@string/mcl_setting_check_libraries_subtitle"
android:title="@string/mcl_setting_check_libraries" />
<SwitchPreference
android:defaultValue="false"
android:key="arc_capes"
android:summary="@string/arc_capes_desc"
android:title="@string/arc_capes_title" />

</PreferenceCategory>

Expand Down
1 change: 1 addition & 0 deletions arc_dns_injector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
15 changes: 15 additions & 0 deletions arc_dns_injector/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id 'java-library'
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
jar {
manifest {
attributes("Manifest-Version": "1.0",
"PreMain-Class": "git.artdeell.arcdns.ArcDNSInjectorAgent")
}
destinationDirectory.set(file("../app_pojavlauncher/src/main/assets/"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package git.artdeell.arcdns;

public class ArcDNSInjectorAgent {
public static void premain(String args) {
System.out.println("Arc Capes DNS Injector");
System.out.println("Parts of Alibaba's DCM library were used, please read https://github.com/alibaba/java-dns-cache-manipulator/blob/main/README.md for more info");
try {
String[] injectedIps = new String[]{args};
if (CacheUtilCommons.isJavaVersionAtMost8()) {
CacheUtil_J8.setInetAddressCache("s.optifine.net", injectedIps, CacheUtilCommons.NEVER_EXPIRATION);
} else {
CacheUtil_J9.setInetAddressCache("s.optifine.net", injectedIps, CacheUtilCommons.NEVER_EXPIRATION);
}
System.out.println("Added DNS cache entry: s.optifine.net/"+args);
}catch (Exception e) {
System.out.println("Failed to inject cache!");
e.printStackTrace();
}
}
}
Loading

0 comments on commit 0b4d775

Please sign in to comment.