Prepare for preview5

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

View File

@@ -13,7 +13,7 @@ import java.awt.mod.*;
public class Desktop
{
private MainActivity currentActivity;
private Activity currentActivity;
public enum Action
{
BROWSE, EDIT, MAIL, OPEN, PRINT
@@ -22,43 +22,36 @@ public class Desktop
public Desktop()
{
peer = Toolkit.getDefaultToolkit().createDesktopPeer();
try
{
try {
if (currentActivity == null) currentActivity = ModdingKit.getCurrentActivity();
}
catch (Exception e)
{
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static Desktop getDesktop()
{
public static Desktop getDesktop() {
return new Desktop();
}
public static boolean isDesktopSupported()
{
public static boolean isDesktopSupported() {
return true;
}
public boolean isSupported(Action action)
{
public boolean isSupported(Action action) {
return true;
}
public void browse(URI uri)
{
public void browse(URI uri) {
try {
URL url = uri.toURL();
if(url.toString().startsWith("file:")){
String fPath = url.toString().replace("file:", "");
Log.d("MineDebug:java.awt.Desktop", "Browse folder: " + fPath);
System.out.println("PojavLauncher:java.awt.Desktop: Browse folder: " + fPath);
// Current not implemented
}
else{
Log.d("MineDebug:java.awt.Desktop", "Browse URL: " + url.toString());
System.out.println("PojavLauncher:java.awt.Desktop: Browse URL: " + url.toString());
if (!url.toString().startsWith("http://") && !url.toString().startsWith("https://")){
url = new URL("http://" + url.toString());
}

View File

@@ -1,15 +1,14 @@
package java.awt.mod;
import android.app.*;
import android.graphics.*;
import android.util.*;
import java.awt.image.*;
import java.lang.reflect.*;
import java.util.*;
import net.kdt.pojavlaunch.*;
public class ModdingKit
{
public static MainActivity getCurrentActivity()
public static Activity getCurrentActivity()
{
try {
Class activityThreadClass = Class.forName("android.app.ActivityThread");
@@ -27,7 +26,7 @@ public class ModdingKit
if (!pausedField.getBoolean(activityRecord)) {
Field activityField = activityRecordClass.getDeclaredField("activity");
activityField.setAccessible(true);
MainActivity activity = (MainActivity) activityField.get(activityRecord);
Activity activity = (Activity) activityField.get(activityRecord);
return activity;
}
}

View File

@@ -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

View File

@@ -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" +

View File

@@ -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()});

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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);

View File

@@ -0,0 +1,5 @@
package net.kdt.pojavlaunch.patcher;
public class LaunchWrapperPatcher
{
}

View File

@@ -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);
}
}
}

View File

@@ -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();
}

View File

@@ -7,6 +7,9 @@ public class DependentLibrary {
public static class MDownloads
{
public MinecraftLibraryArtifact artifact;
public MDownloads(MinecraftLibraryArtifact artifact) {
this.artifact = artifact;
}
}
}

View File

@@ -1,30 +1,90 @@
/*
* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.applet;
import android.media.*;
import android.net.*;
import java.applet.*;
public class AppletAudioClip implements AudioClip
{
public AppletAudioClip(java.net.URL url)
{
super();
}
@Override
public void play()
{
// TODO: Implement this method
}
@Override
public void loop()
{
// TODO: Implement this method
}
@Override
public void stop()
{
// TODO: Implement this method
}
import java.io.*;
import java.net.*;
import java.awt.mod.*;
/**
* Applet audio clip;
*
* @author Arthur van Hoff, Kara Kytle
*/
public class AppletAudioClip implements AudioClip {
// url that this AudioClip is based on
private Uri url = null;
boolean DEBUG = false /*true*/;
MediaPlayer audioClip;
/**
* Constructs an AppletAudioClip from an URL.
*/
public AppletAudioClip(URL url) {
// store the url
this.url = Uri.parse(url.toString());
}
/**
* Constructs an AppletAudioClip from a URLConnection.
*/
public AppletAudioClip(URLConnection uc) {
this(uc.getURL());
}
/**
* For constructing directly from Jar entries, or any other
* raw Audio data. Note that the data provided must include the format
* header.
*/
public AppletAudioClip(byte[] data) {
throw new UnsupportedOperationException("Construct (byte[])");
}
/*
* Does the real work of creating an AppletAudioClip from an InputStream.
* This function is used by both constructors.
*/
void createAppletAudioClip(InputStream in) throws IOException {
try {
audioClip = new MediaPlayer();
audioClip.setDataSource(ModdingKit.getCurrentActivity(), url);
audioClip.prepare();
} catch (Exception e3) {
// no matter what happened, we throw an IOException to avoid changing the interfaces....
throw new IOException("Failed to construct the AudioClip: " + e3);
}
}
public synchronized void play() {
if (audioClip != null)
audioClip.start();
}
public synchronized void loop() {
if (audioClip != null)
audioClip.setLooping(true);
}
public synchronized void stop() {
if (audioClip != null)
audioClip.stop();
}
}