Prepare for preview5

This commit is contained in:
khanhduytran0 committed 2020-03-23 20:09:52 +07:00
1 parent ee10455d0c
commit 8cedf73bde
266 files changed
+323 -140

No files matched your search

@@ -3,31 +3,8 @@ import java.io.*;
public class LoggerJava
{
public static class LoggerDXPrintStream extends PrintStream {
private OnStringPrintListener mListener;
public LoggerDXPrintStream(OutputStream out, OnStringPrintListener listener)
{
super(out);
mListener = listener;
}
@Override
public void print(String s)
{
super.print(s);
if (mListener != null) mListener.onCharPrint(s);
}
@Override
public void println(String s)
{
super.println(s);
if (mListener != null) mListener.onCharPrint(s + "\n");
}
}
public static interface OnStringPrintListener {
public void onCharPrint(String s);
public void onCharPrint(char c);
}
public static class LoggerOutputStream extends FilterOutputStream
@@ -43,7 +20,7 @@ public class LoggerJava
public void write(final int charCode) throws IOException
{
super.write(charCode);
mListener.onCharPrint(Character.toString((char) charCode));
mListener.onCharPrint((char) charCode);
}
/*
@Override
@@ -461,16 +461,16 @@ public class MCLauncherActivity extends AppCompatActivity
final StringBuilder currentLog = new StringBuilder();
LoggerJava.LoggerOutputStream logOut = new LoggerJava.LoggerOutputStream(System.out, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(String s)
public void onCharPrint(char c)
{
currentLog.append(s + "\n");
currentLog.append(c);
}
});
LoggerJava.LoggerOutputStream logErr = new LoggerJava.LoggerOutputStream(System.err, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(String s)
public void onCharPrint(char c)
{
currentLog.append(s + "\n");
currentLog.append(c);
}
});
System.setOut(new PrintStream(logOut));
@@ -522,23 +522,39 @@ public class MCLauncherActivity extends AppCompatActivity
currentLog.setLength(0);
String[] libInfo = libItem.name.split(":");
outUndexLib = new File(Tools.libraries + "/" + Tools.artifactToPath(libInfo[0], libInfo[1], libInfo[2]).replace(".jar", "_orig.jar"));
String libArtifact = Tools.artifactToPath(libInfo[0], libInfo[1], libInfo[2]);
outUndexLib = new File(Tools.libraries + "/" + libArtifact.replace(".jar", "_orig.jar"));
outUndexLib.getParentFile().mkdirs();
//if (!oker) throw new RuntimeException(".thehell: " + outUndexLib.getParent());
outDexedLib = new File(Tools.libraries + "/" + Tools.artifactToPath(libInfo[0], libInfo[1], libInfo[2])); // Don't add ".jar"
outDexedLib = new File(Tools.libraries + "/" + libArtifact); // Don't add ".jar"
if (!outDexedLib.exists()) {
libPathURL = libItem.downloads.artifact.url;
Log.d(Tools.APP_NAME, "Downloading " + libPathURL + " TO FILE " + outUndexLib.getAbsolutePath());
publishProgress("1", getStr(R.string.mcl_launch_download_lib, libItem.name));
if (!outUndexLib.exists()) {
//toast(outUndexLib.getAbsolutePath());
Tools.downloadFile(
libPathURL,
outUndexLib.getAbsolutePath(),
true
);
boolean skipIfFailed = false;
if (libItem.downloads == null) {
MinecraftLibraryArtifact artifact = new MinecraftLibraryArtifact();
artifact.url = "https://libraries.minecraft.net/" + libArtifact;
libItem.downloads = new DependentLibrary.MDownloads(artifact);
skipIfFailed = true;
}
try {
libPathURL = libItem.downloads.artifact.url;
if (!outUndexLib.exists()) {
//toast(outUndexLib.getAbsolutePath());
Tools.downloadFile(
libPathURL,
outUndexLib.getAbsolutePath(),
true
);
}
} catch (Throwable th) {
if (!skipIfFailed) {
throw th;
} else {
th.printStackTrace();
}
}
convertStr = getStr(R.string.mcl_launch_convert_lib, libItem.name);
@@ -562,7 +578,7 @@ public class MCLauncherActivity extends AppCompatActivity
*/
if (!outDexedLib.exists()) {
RuntimeException dxError = new RuntimeException(getResources().getString(R.string.error_convert_lib) + "\n" + currentLog.toString());
RuntimeException dxError = new RuntimeException(getResources().getString(R.string.error_convert_lib, libItem.name) + "\n" + currentLog.toString());
dxError.setStackTrace(new StackTraceElement[0]);
throw dxError;
}
@@ -808,7 +824,7 @@ public class MCLauncherActivity extends AppCompatActivity
AlertDialog dialog = builder.create();
MFileListView flv = new MFileListView(this, dialog);
flv.listFileAt(Tools.mainpath + "/ModsManager");
flv.listFileAt(Tools.datapath + "/ModsManager");
flv.setFileSelectedListener(new MFileSelectedListener(){
@Override
@@ -872,6 +888,7 @@ public class MCLauncherActivity extends AppCompatActivity
" • LWJGL " + org.lwjgl.Sys.getVersion() + "\n" +
//" • Boardwalk memory manager (not used now).\n" +
" • gl4es: OpenGL for OpenGL ES devices by lunixbochs and ptitSeb.\n" +
" • openal_soft: OpenAL port for Android devices by apportable.\n" +
" • PojavDX (dx 1.16): tool to convert java bytecode to dex.\n" +
" • Java AWT Implementation includes:\n" +
" - Boardwalk's makeshift.\n" +
@@ -32,6 +32,8 @@ import android.graphics.drawable.Drawable;
import android.view.GestureDetector.*;
import java.util.concurrent.locks.*;
import com.kdt.pointer.*;
import net.kdt.pojavlaunch.value.*;
import java.net.*;
public class MainActivity extends Activity implements OnTouchListener
{
public static final String initText = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ";
@@ -78,11 +80,13 @@ public class MainActivity extends Activity implements OnTouchListener
private ScrollView contentScroll;
private ToggleButton toggleScrollLog;
private GestureDetector gestureDetector;
private PointerOreoWrapper pointerSurface;
private StringBuilder mQueueText = new StringBuilder();
private MinecraftVersion mVersionInfo;
/*
private LinearLayout contentCanvas;
private AWTSurfaceView contentCanvasView;
@@ -119,8 +123,7 @@ public class MainActivity extends Activity implements OnTouchListener
try {
File crashLog = Tools.lastFileModified(Tools.crashPath);
String crashContent = Tools.read(crashLog.getAbsolutePath());
if(crashLog != null && crashContent.startsWith("---- Minecraft Crash Report ----")){
if(crashLog != null && Tools.read(crashLog.getAbsolutePath()).startsWith("---- Minecraft Crash Report ----")){
d.setMessage(R.string.mcn_exit_crash);
} else {
fullyExit();
@@ -151,7 +154,8 @@ public class MainActivity extends Activity implements OnTouchListener
}
mProfile = PojavProfile.getCurrentProfileContent(this);
mVersionInfo = Tools.getVersionInfo(mProfile.getVersion());
initEnvs();
System.loadLibrary("gl04es");
//System.loadLibrary("gl4es");
@@ -667,19 +671,42 @@ public class MainActivity extends Activity implements OnTouchListener
String mcAssetsDir = Tools.ASSETS_PATH;
String userType = "mojang";
File gameDir = new File(Tools.MAIN_PATH + "/gamedir");
File gameDir = new File(Tools.MAIN_PATH);
gameDir.mkdirs();
String[] args = {
"--username", username,
"--version", versionName,
"--gameDir", gameDir.getAbsolutePath(),
"--assetsDir", mcAssetsDir,
"--assetIndex", versionName,
"--uuid", mProfile.getProfileID(),
"--accessToken", mProfile.getAccessToken(),
"--userProperties", "{}",
"--userType", userType
};
Map<String, String> varArgMap = new ArrayMap<String, String>();
varArgMap.put("auth_player_name", username);
varArgMap.put("version_name", versionName);
varArgMap.put("game_directory", gameDir.getAbsolutePath());
varArgMap.put("assets_root", mcAssetsDir);
varArgMap.put("assets_index_name", versionName);
varArgMap.put("auth_uuid", mProfile.getProfileID());
varArgMap.put("auth_access_token", mProfile.getAccessToken());
varArgMap.put("user_properties", "{}");
varArgMap.put("user_type", userType);
String[] argsFromJson = insertVariableArgument(mVersionInfo.minecraftArguments.split(" "), varArgMap);
return argsFromJson;
}
private String[] insertVariableArgument(String[] args, Map<String, String> keyValueMap) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
String argVar = null;
if (arg.startsWith("${") && arg.endsWith("}")) {
argVar = arg.substring(2, arg.length() - 2);
for (Map.Entry<String, String> keyValue : keyValueMap.entrySet()) {
if (argVar.equals(keyValue.getKey())) {
args[i] = keyValue.getValue();
}
}
}
// Check again
if (arg.startsWith("${") && arg.endsWith("}")) {
System.out.println("Warning: Can't find variable \"" + argVar + "\".");
}
}
return args;
}
@@ -692,9 +719,9 @@ public class MainActivity extends Activity implements OnTouchListener
LoggerJava.OnStringPrintListener printLog = new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(String s)
public void onCharPrint(char c)
{
appendToLog(s);
appendToLog(Character.toString(c));
}
};
@@ -715,8 +742,19 @@ public class MainActivity extends Activity implements OnTouchListener
ClassLoader loader;
loader = new DexClassLoader(classpath, optDir.getAbsolutePath(), getApplicationInfo().nativeLibraryDir, getClassLoader());
// loader = new LaunchClassLoader(); // classpath, optDir.getAbsolutePath(), getApplicationInfo().nativeLibraryDir, getClassLoader());
Class mainClass = loader.loadClass(LibrariesManager.getVersionInfo(Tools.versnDir + "/" + mProfile.getVersion() + "/" + mProfile.getVersion() + ".json").mainClass);
// BEGIN URL
/*
List<URL> urlList = new ArrayList<URL>();
for (String perJar : classpath.split(":")) {
if (perJar.isEmpty()) continue;
urlList.add(new File(perJar).toURI().toURL());
}
loader = new URLClassLoader(urlList.toArray(new URL[0]));
*/
// END URL
Class mainClass = loader.loadClass(mVersionInfo.mainClass);
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.setAccessible(true);
mainMethod.invoke(null, new Object[]{getMCArgs()});
@@ -18,7 +18,7 @@ public class PojavApplication extends Application
Tools.usingVerName = thisApp.versionName;
Tools.usingVerCode = thisApp.versionCode;
Tools.mainpath = getDir("files", MODE_PRIVATE).getParent();
Tools.datapath = getDir("files", MODE_PRIVATE).getParent();
} catch (Exception e) {
e.printStackTrace();
}
@@ -21,6 +21,7 @@ import android.text.method.*;
import android.system.*;
import android.net.*;
import static android.view.ViewGroup.LayoutParams.*;
import net.kdt.pojavlaunch.update.*;
public class PojavLoginActivity extends MineActivity
{
@@ -281,6 +282,10 @@ public class PojavLoginActivity extends MineActivity
private void initMain()
{
mkdirs(Tools.worksDir);
mkdirs(Tools.versnDir);
mkdirs(Tools.libraries);
File file0 = new File(Tools.mpProfiles);
File file1 = new File(Tools.mpModEnable);
File file2 = new File(Tools.mpModDisable);
@@ -296,7 +301,7 @@ public class PojavLoginActivity extends MineActivity
try {
mkdirs(Tools.MAIN_PATH);
Tools.copyAssetOptional(this, "options.txt", Tools.MAIN_PATH + "/gamedir");
Tools.copyAssetOptional(this, "options.txt", Tools.MAIN_PATH);
//Tools.copyAssetToFolderIfNonExist(this, "dx-f" + (isAndroid7() ? "7" : "4") + ".0.jar", Tools.worksDir, "dx.jar");
Tools.copyAssetOptional(this, "pojavdx.dex", Tools.worksDir);
@@ -308,13 +313,13 @@ public class PojavLoginActivity extends MineActivity
// Extract libraries
if (!isLibrariesExtracted()) {
mkdirs(Tools.worksDir);
mkdirs(Tools.versnDir);
Tools.extractAssetFolder(this, "libraries", Tools.worksDir);
Tools.extractAssetFolder(this, "libraries", Tools.MAIN_PATH);
setPref(PREF_IS_INSTALLED_LIBRARIES, true);
}
UpdateDataChanger.changeDataAuto("2.4", "2.4.2");
}
catch(Exception e){
Tools.showError(this, e);
@@ -8,12 +8,8 @@ public class SystemCrackResolver
}
public static void invoke(String method, Object... params) {
Class[] classParams = new Class[params.length];
for (int i = 0; i < params.length; i++) {
classParams[i] = params[i].getClass();
}
try {
Method methodObj = System.class.getDeclaredMethod(method, classParams);
Method methodObj = System.class.getDeclaredMethod(method, Object.class, int.class, Object.class, int.class, int.class);
methodObj.setAccessible(true);
methodObj.invoke(null, params);
} catch (Throwable th) {
@@ -24,21 +24,29 @@ public final class Tools
public static String APP_NAME = "null";
public static String MAIN_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/games/minecraft";
public static String ASSETS_PATH = MAIN_PATH + "/gamedir/assets";
public static String ASSETS_PATH = MAIN_PATH + "/assets";
public static int usingVerCode = 1;
public static String usingVerName = "2.0";
public static String mhomeUrl = "http://mineup.eu5.net"; // "http://kdtjavacraft.eu5.net";
public static String mainpath = "/data/data/net.kdt.pojavlaunch";
public static String worksDir = mainpath + "/app_working_dir";
public static String versnDir = worksDir + "/versions";
public static String libraries = worksDir + "/libraries";
public static String mpProfiles = mainpath + "/Users";
public static String crashPath = Tools.MAIN_PATH + "/gamedir/crash-reports";
public static String datapath = "/data/data/net.kdt.pojavlaunch";
public static String worksDir = datapath + "/app_working_dir";
// New since 2.4.2
public static String versnDir = MAIN_PATH + "/versions";
public static String libraries = MAIN_PATH + "/libraries";
// Old since 2.4.2
public static String oldGameDir = MAIN_PATH + "/gamedir";
public static String oldVersionDir = worksDir + "/versions";
public static String oldLibrariesDir = worksDir + "/libraries";
public static String mpProfiles = datapath + "/Users";
public static String crashPath = MAIN_PATH + "/crash-reports";
public static String mpModEnable = mainpath + "/ModsManager/✅Enabled";
public static String mpModDisable = mainpath + "/ModsManager/❌Disabled";
public static String mpModAddNewMo = mainpath + "/ModsManager/➕Add mod";
public static String mpModEnable = datapath + "/ModsManager/✅Enabled";
public static String mpModDisable = datapath + "/ModsManager/❌Disabled";
public static String mpModAddNewMo = datapath + "/ModsManager/➕Add mod";
public static String[] versionList = {
"1.7.3",
@@ -185,6 +193,32 @@ public final class Tools
}
public static void moveInside(String from, String to) {
File fromFile = new File(from);
for (File fromInside : fromFile.listFiles()) {
moveRecursive(fromInside.getAbsolutePath(), to);
}
fromFile.delete();
}
public static void moveRecursive(String from, String to) {
moveRecursive(new File(from), new File(to));
}
public static void moveRecursive(File from, File to) {
File toFrom = new File(to, from.getName());
try {
if (from.isDirectory()) {
for (File child : from.listFiles()) {
moveRecursive(child, toFrom);
}
}
} finally {
from.getParentFile().mkdirs();
from.renameTo(toFrom);
}
}
public static void openURL(Activity act, String url) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
act.startActivity(browserIntent);
@@ -0,0 +1,5 @@
package net.kdt.pojavlaunch.patcher;
public class LaunchWrapperPatcher
{
}
@@ -0,0 +1,45 @@
package net.kdt.pojavlaunch.update;
import java.lang.reflect.*;
import net.kdt.pojavlaunch.*;
import java.io.*;
public class UpdateDataChanger
{
/*
* Change the data from old version to this version
* For users update from:
* 2.4 --> 2.4.2
*
* /storage/sdcard0/AppProjects/PojavLauncher-2.4.2-20200323-preview4.apk
*/
@UpdateTarget(from="2.4", to="2.4.2")
public static void changeData() {
Tools.deleteRecursive(new File(Tools.oldLibrariesDir));
Tools.deleteRecursive(new File(Tools.oldVersionDir));
try {
Tools.moveInside(Tools.oldGameDir, Tools.MAIN_PATH);
} catch (Throwable th) {
th.printStackTrace();
}
}
public static void changeDataAuto(String from, String to) {
try {
/*
for (Method method : UpdateDataChanger.class.getDeclaredMethods()) {
if (method.getName().equals("changeData")) {
UpdateTarget annotation = method.getAnnotation(UpdateTarget.class);
if (annotation.from().equals(from) && annotation.to().equals(to)) {
method.invoke(null);
}
}
}
*/
changeData();
} catch (Throwable th) {
throw new RuntimeException("Unable to migrate to new data type", th);
}
}
}
@@ -0,0 +1,12 @@
package net.kdt.pojavlaunch.update;
import java.lang.annotation.*;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface UpdateTarget {
String from();
String to();
}
@@ -7,6 +7,9 @@ public class DependentLibrary {
public static class MDownloads
{
public MinecraftLibraryArtifact artifact;
public MDownloads(MinecraftLibraryArtifact artifact) {
this.artifact = artifact;
}
}
}