Automatically add the resource pack and set renderer for 1.17 on GL4ES

This commit is contained in:
artdeell 2021-07-22 19:50:09 +03:00
parent 7318f00b2d
commit 752d46ea12
4 changed files with 167 additions and 1 deletions

Binary file not shown.

View File

@ -2,6 +2,7 @@ package net.kdt.pojavlaunch.tasks;
import android.app.*;
import android.content.*;
import android.content.res.AssetManager;
import android.graphics.*;
import android.os.*;
import android.util.*;
@ -116,6 +117,10 @@ public class MinecraftDownloaderTask extends AsyncTask<String, String, Throwable
}
} //if else, we are satisfied
}
{
int mcReleaseDate = Integer.parseInt(verInfo.releaseTime.substring(0, 10).replace("-", ""));
if(mcReleaseDate > 20210225) V117CompatUtil.runCheck(p1[0],mActivity);
}
try {
assets = downloadIndex(verInfo.assets, new File(Tools.ASSETS_PATH, "indexes/" + verInfo.assets + ".json"));
} catch (IOException e) {

View File

@ -0,0 +1,158 @@
package net.kdt.pojavlaunch.utils;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import androidx.appcompat.app.AlertDialog;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.tasks.MinecraftDownloaderTask;
import net.kdt.pojavlaunch.value.PerVersionConfig;
import org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
public class V117CompatUtil {
/*
/*
New rendering engine was added in snapshot 21w10a
21a08b (FP (GL2) engine): 20210225
21w10a (non-FP engine): 20210310
boolean skipResDialog = false;
if(mcReleaseDate > 20210225) skipResDialog = true;
PerVersionConfig.update(); //Prepare the PVC
PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(p1[0]); //Get the version config...
if (cfg == null) {
cfg = new PerVersionConfig.VersionConfig();//or create a new one!
PerVersionConfig.configMap.put(p1[0], cfg);//and put it into the base
}
MCOptionUtils.load();
if(!skipResDialog) {
AtomicBoolean proceed = new AtomicBoolean(false);
Object lock = new Object();
mActivity.runOnUiThread(() -> {
AlertDialog.Builder bldr = new AlertDialog.Builder(mActivity);
bldr.setTitle(R.string.global_warinng);
bldr.setMessage(R.string.compat_117_message);
bldr.setPositiveButton(android.R.string.ok, (dialog, which) -> {
proceed.set(true);
synchronized (lock) { lock.notifyAll(); }
dialog.dismiss();
});
bldr.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
synchronized (lock) { lock.notifyAll(); }
dialog.dismiss();
});
bldr.setCancelable(false);
bldr.show();
});
synchronized (lock) {
lock.wait();
}
if(proceed.get()) {
File resourcepacksDir = new File(cfg.gamePath==null? Tools.DIR_GAME_NEW:cfg.gamePath,"resourcepacks");
if(!resourcepacksDir.exists()) resourcepacksDir.mkdirs();
FileOutputStream fos = new FileOutputStream(new File(resourcepacksDir,"assets-v0.zip"));
InputStream is = this.mActivity.getAssets().open("assets-v0.zip");
IOUtils.copy(is,fos);
is.close();fos.close();
String resourcepacks = MCOptionUtils.get("resourcePacks");
if(resourcepacks == null || !resourcepacks.contains("assets-v0.zip")) {
List<String> resPacksArray = resourcepacks == null ? new ArrayList(): Arrays.asList()
}
}else throw new MinecraftDownloaderTask.SilentException();
}
*/
private static List<String> getTexturePackList(String param) {
Log.i("V117CompatDebug",param);
if("[]".equals(param)) return new ArrayList<>();
Log.i("V117CompatDebug","ph2");
if(param == null) return new ArrayList<>();
Log.i("V117CompatDebug","ph3");
String rawList = param.substring(1,param.length()-1);
Log.i("V117CompatDebug",rawList);
return new ArrayList<>(Arrays.asList(rawList.split(",")));
}
private static String regenPackList(List<String> packs) {
if(packs.size()==0) return "[]";
String ret = "["+packs.get(0);
for(int i = 1; i < packs.size(); i++) {
ret += ","+packs.get(i);
}
ret += "]";
return ret;
}
public static void runCheck(String version, Activity ctx) throws Exception{
PerVersionConfig.VersionConfig cfg = PerVersionConfig.configMap.get(version);
MCOptionUtils.load();
List<String> packList =getTexturePackList(MCOptionUtils.get("resourcePacks"));
String renderer = cfg != null && cfg.renderer != null?cfg.renderer:LauncherPreferences.PREF_RENDERER;
if(renderer.equals("vulkan_zink")) return; //don't install for zink users;
if(packList.contains("\"assets-v0.zip\"") && renderer.equals("opengles2_5")) return;
Object lock = new Object();
AtomicBoolean proceed = new AtomicBoolean(false);
ctx.runOnUiThread(() -> {
AlertDialog.Builder bldr = new AlertDialog.Builder(ctx);
bldr.setTitle(R.string.global_warinng);
bldr.setMessage(R.string.compat_117_message);
bldr.setPositiveButton(android.R.string.ok, (dialog, which) -> {
proceed.set(true);
synchronized (lock) { lock.notifyAll(); }
dialog.dismiss();
});
bldr.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
synchronized (lock) { lock.notifyAll(); }
dialog.dismiss();
});
bldr.setCancelable(false);
bldr.show();
});
synchronized (lock) {
lock.wait();
}
if(proceed.get()) {
if (cfg == null) {
cfg = new PerVersionConfig.VersionConfig();
PerVersionConfig.configMap.put(version, cfg);
}
cfg.renderer = "opengles2_5";
String path = Tools.DIR_GAME_NEW;
if(cfg.gamePath != null && !cfg.gamePath.isEmpty()) path = cfg.gamePath;
copyResourcePack(path,ctx.getAssets());
packList.add(0,"\"assets-v0.zip\"");
MCOptionUtils.set("resourcePacks",regenPackList(packList));
MCOptionUtils.save();
PerVersionConfig.update();
}else{
throw new MinecraftDownloaderTask.SilentException();
}
}
public static void copyResourcePack(String gameDir, AssetManager am) throws IOException {
File resourcepacksDir = new File(gameDir,"resourcepacks");
if(!resourcepacksDir.exists()) resourcepacksDir.mkdirs();
FileOutputStream fos = new FileOutputStream(new File(resourcepacksDir,"assets-v0.zip"));
InputStream is = am.open("assets-v0.zip");
IOUtils.copy(is,fos);
is.close();fos.close();
}
}

View File

@ -108,12 +108,12 @@
<string name="mcl_setting_veroption_snapshot">Snapshot</string>
<string name="mcl_setting_veroption_oldalpha">Old-alpha</string>
<string name="mcl_setting_veroption_oldbeta">Old-beta</string>
<string name="mcl_version_clone">Clone</string>
<!-- Global strings -->
<string name="global_edit">Edit</string>
<string name="global_error">Error</string>
<string name="global_warinng">Warning</string>
<string name="global_load">Load</string>
<string name="global_name">Name</string>
<string name="global_remove">Remove</string>
@ -223,4 +223,7 @@
<string name="multirt_config_setdefault_already">Default</string>
<string name="multirt_config_removeerror_last">You must have at least one Java Runtime installed</string>
<string name="multirt_nocompartiblert">Can\'t find any compartible Java Runtime</string>
<string name="compat_117_message">Minecraft 21w10a+ requires the OpenGL 3.2 core profile. Sadly, GL4ES wrapper doesn\'t fully support it at the moment, but there are some additional resources you can install to run these versions. Press OK to confirm installation, and press Cancel to abort launch.</string>
</resources>