Preview 6.1

This commit is contained in:
khanhduytran0
2020-03-28 07:31:25 +07:00
parent 62df7b204f
commit 8dc1b841fc
442 changed files with 809 additions and 726 deletions

View File

@@ -125,8 +125,8 @@ public class FileListView extends LinearLayout
}
else{
String name = mainPath.getName();
String extension = getExtension(path);
listener.onFileSelected(mainPath, path, name, extension);
// String extension = getExtension(path);
listener.onFileSelected(mainPath, path, name);
}
}
else{

View File

@@ -4,5 +4,5 @@ import java.io.File;
public interface FileSelectedListener
{
public void onFileSelected(File file, String path, String nane, String extension);
public void onFileSelected(File file, String path, String name);
}

View File

@@ -1,11 +1,39 @@
package javax.swing;
import java.awt.Component;
import android.app.*;
import android.util.*;
import java.awt.*;
import java.awt.mod.*;
import android.content.*;
public class JOptionPane
{
public static void showMessageDialog(Component parentComponent , Object title, String message, int messageType)
{
private static boolean isOk;
public static void showMessageDialog(Component parentComponent, final Object title, final String message, int messageType) {
Log.w("JOptionPane", "[" + message + "] " + title.toString());
isOk = false;
final Activity act = ModdingKit.getCurrentActivity();
act.runOnUiThread(new Runnable(){
@Override
public void run()
{
AlertDialog.Builder dialog = new AlertDialog.Builder(act);
dialog.setTitle(title.toString());
dialog.setMessage(message);
dialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2)
{
isOk = true;
}
});
dialog.show();
}
});
while (!isOk) {}
}
}

View File

@@ -117,22 +117,24 @@ public class AndroidLWJGLKeycode {
}
public static void execKey(MainActivity mainActivity, KeyEvent keyEvent, int i, boolean isDown) {
for (Map.Entry<Integer, Integer> perKey : androidToLwjglMap.entrySet()) {
try {
// Old method works without dead chars:
/*
if (isDown) {
mainActivity.sendKeyPress((char) keyEvent.getUnicodeChar());
}
*/
System.out.println("Sending key as char: " + ((char) keyEvent.getUnicodeChar()));
mainActivity.sendKeyPress(0, (char) keyEvent.getUnicodeChar(), isDown);
} catch (Throwable th) {
th.printStackTrace();
}
for (Map.Entry<Integer, Integer> perKey : androidToLwjglMap.entrySet()) {
if (perKey.getKey() == i) {
mainActivity.sendKeyPress(perKey.getValue(), isDown);
}
}
if (!AndroidDisplay.grab) {
try {
// Old method works without dead chars:
if (isDown) {
mainActivity.sendKeyPress((char) keyEvent.getUnicodeChar());
}
} catch (Throwable th) {
th.printStackTrace();
}
}
}
}

View File

@@ -21,6 +21,7 @@ public class JMinecraftVersionList {
public String mainClass;
public String minecraftArguments;
public int minimumLauncherVersion;
public DependentLibrary optifineLib;
public String releaseTime;
public String time;
public String type;

View File

@@ -10,18 +10,23 @@ public class LoggerJava
public static class LoggerOutputStream extends FilterOutputStream
{
private OnStringPrintListener mListener;
public LoggerOutputStream(OutputStream out, OnStringPrintListener listener)
{
private PrintStream mPrinter;
public LoggerOutputStream(PrintStream out, OnStringPrintListener listener) {
super(out);
mPrinter = out;
mListener = listener;
}
@Override
public void write(final int charCode) throws IOException
{
public void write(final int charCode) throws IOException {
super.write(charCode);
mListener.onCharPrint((char) charCode);
}
public PrintStream getRootStream() {
return mPrinter;
}
/*
@Override
public void write(byte[] b) throws IOException

View File

@@ -28,6 +28,9 @@ import android.app.AlertDialog;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import libcore.util.*;
import dalvik.system.*;
import java.lang.reflect.*;
import net.kdt.pojavlaunch.patcher.*;
//import android.support.v7.view.menu.*;
//import net.zhuoweizhang.boardwalk.downloader.*;
@@ -143,80 +146,7 @@ public class MCLauncherActivity extends AppCompatActivity
versionSelector = (Spinner) findId(R.id.launcherMainSelectVersion);
versionSelector.setAdapter(adapter);
new AsyncTask<Void, Void, ArrayList<String>>(){
@Override
protected ArrayList<String> doInBackground(Void[] p1)
{
try{
versionList = gson.fromJson(DownloadUtils.downloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json"), JMinecraftVersionList.class);
ArrayList<String> versionStringList = filter(versionList.versions, fVers.listFiles());
return versionStringList;
} catch (Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(ArrayList<String> result)
{
super.onPostExecute(result);
final PopupMenu popup = new PopupMenu(MCLauncherActivity.this, versionSelector);
popup.getMenuInflater().inflate(R.menu.menu_versionopt, popup.getMenu());
if(result != null && result.size() > 0) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MCLauncherActivity.this, android.R.layout.simple_spinner_item, result);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
versionSelector.setAdapter(adapter);
versionSelector.setSelection(selectAt(result.toArray(new String[0]), profile.getVersion()));
} else {
versionSelector.setSelection(selectAt(availableVersions, profile.getVersion()));
}
versionSelector.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> p1, View p2, int p3, long p4)
{
String version = p1.getItemAtPosition(p3).toString();
profile.setVersion(version);
PojavProfile.setCurrentProfile(MCLauncherActivity.this, profile);
if (PojavProfile.isFileType(MCLauncherActivity.this)) {
PojavProfile.setCurrentProfile(MCLauncherActivity.this, MCProfile.build(profile));
}
tvVersion.setText(getStr(R.string.mcl_version_msg, version));
}
@Override
public void onNothingSelected(AdapterView<?> p1)
{
// TODO: Implement this method
}
});
versionSelector.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> p1, View p2, int p3, long p4)
{
// Implement copy, remove, reinstall,...
popup.show();
return true;
}
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return true;
}
});
tvVersion.setText(getStr(R.string.mcl_version_msg) + versionSelector.getSelectedItem());
}
}.execute();
new RefreshVersionListTask().execute();
launchProgress = (ProgressBar) findId(R.id.progressDownloadBar);
launchTextStatus = (TextView) findId(R.id.progressDownloadText);
@@ -231,6 +161,80 @@ public class MCLauncherActivity extends AppCompatActivity
statusIsLaunching(false);
}
public class RefreshVersionListTask extends AsyncTask<Void, Void, ArrayList<String>>{
@Override
protected ArrayList<String> doInBackground(Void[] p1)
{
try{
versionList = gson.fromJson(DownloadUtils.downloadString("https://launchermeta.mojang.com/mc/game/version_manifest.json"), JMinecraftVersionList.class);
ArrayList<String> versionStringList = filter(versionList.versions, new File(Tools.versnDir).listFiles());
return versionStringList;
} catch (Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(ArrayList<String> result)
{
super.onPostExecute(result);
final PopupMenu popup = new PopupMenu(MCLauncherActivity.this, versionSelector);
popup.getMenuInflater().inflate(R.menu.menu_versionopt, popup.getMenu());
if(result != null && result.size() > 0) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MCLauncherActivity.this, android.R.layout.simple_spinner_item, result);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
versionSelector.setAdapter(adapter);
versionSelector.setSelection(selectAt(result.toArray(new String[0]), profile.getVersion()));
} else {
versionSelector.setSelection(selectAt(availableVersions, profile.getVersion()));
}
versionSelector.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> p1, View p2, int p3, long p4)
{
String version = p1.getItemAtPosition(p3).toString();
profile.setVersion(version);
PojavProfile.setCurrentProfile(MCLauncherActivity.this, profile);
if (PojavProfile.isFileType(MCLauncherActivity.this)) {
PojavProfile.setCurrentProfile(MCLauncherActivity.this, MCProfile.build(profile));
}
tvVersion.setText(getStr(R.string.mcl_version_msg, version));
}
@Override
public void onNothingSelected(AdapterView<?> p1)
{
// TODO: Implement this method
}
});
versionSelector.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener(){
@Override
public boolean onItemLongClick(AdapterView<?> p1, View p2, int p3, long p4)
{
// Implement copy, remove, reinstall,...
popup.show();
return true;
}
});
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
return true;
}
});
tvVersion.setText(getStr(R.string.mcl_version_msg) + versionSelector.getSelectedItem());
}
}
@Override
protected void onPostResume()
{
@@ -456,26 +460,26 @@ public class MCLauncherActivity extends AppCompatActivity
@Override
protected Throwable doInBackground(final String[] p1)
{
//Version name
Throwable throwable = null;
final StringBuilder currentLog = new StringBuilder();
LoggerJava.LoggerOutputStream logOut = new LoggerJava.LoggerOutputStream(System.out, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(char c)
{
currentLog.append(c);
}
});
LoggerJava.LoggerOutputStream logErr = new LoggerJava.LoggerOutputStream(System.err, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(char c)
{
currentLog.append(c);
}
});
System.setOut(new PrintStream(logOut));
System.setErr(new PrintStream(logErr));
try {
final StringBuilder currentLog = new StringBuilder();
LoggerJava.LoggerOutputStream logOut = new LoggerJava.LoggerOutputStream(System.out, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(char c)
{
currentLog.append(c);
}
});
LoggerJava.LoggerOutputStream logErr = new LoggerJava.LoggerOutputStream(System.err, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(char c)
{
currentLog.append(c);
}
});
System.setOut(new PrintStream(logOut));
System.setErr(new PrintStream(logErr));
final String downVName = "/" + p1[0] + "/" + p1[0];
//Downloading libraries
@@ -562,7 +566,8 @@ public class MCLauncherActivity extends AppCompatActivity
convertStr = getStr(R.string.mcl_launch_convert_lib, libItem.name);
publishProgress("1", convertStr);
Tools.runDx(MCLauncherActivity.this, outUndexLib.getAbsolutePath(), outDexedLib.getAbsolutePath(), new PojavDXManager.Listen(){
boolean isOptifine = libItem.name.startsWith(Tools.optifineLib);
Tools.runDx(MCLauncherActivity.this, outUndexLib.getAbsolutePath(), outDexedLib.getAbsolutePath(), isOptifine , new PojavDXManager.Listen(){
@Override
public void onReceived(String step, int maxProg, int currProg)
@@ -632,9 +637,9 @@ public class MCLauncherActivity extends AppCompatActivity
outUnpatchedConvert.delete();
}
}
} catch (Exception e) {
} catch (Throwable e) {
launchWithError = true;
return e;
throw e;
}
publishProgress("7", getStr(R.string.mcl_launch_cleancache));
@@ -666,10 +671,13 @@ public class MCLauncherActivity extends AppCompatActivity
} finally {
isAssetsProcessing = false;
}
} catch(Throwable th){
return th;
} catch (Throwable th){
throwable = th;
} finally {
System.setErr(logErr.getRootStream());
System.setOut(logOut.getRootStream());
return throwable;
}
return null;
}
private int addProgress = 0; // 34
@@ -695,7 +703,7 @@ public class MCLauncherActivity extends AppCompatActivity
JarSigner.sign(in, out);
new File(in).delete();
Tools.clearDuplicateFiles(new File(out).getParentFile());
// Tools.clearDuplicateFiles(new File(out).getParentFile());
}
@Override
@@ -807,6 +815,50 @@ public class MCLauncherActivity extends AppCompatActivity
});
}
public void launcherMenu(View view)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.mcl_options);
builder.setItems(R.array.mcl_options, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2)
{
switch(p2){
case 0:{ // Mods manager
modManager();
} break;
case 1:{ // OptiFine installer
installOptiFine();
} break;
case 2:{ // Check update
checkUpdate();
} break;
case 3:{ // Settings
startActivity(new Intent(MCLauncherActivity.this, PojavPreferenceActivity.class));
} break;
case 4:{ // About
final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this);
aboutB.setTitle(R.string.mcl_option_about);
try
{
aboutB.setMessage(String.format(Tools.read(getAssets().open("about_en.txt")),
Tools.APP_NAME,
Tools.usingVerName,
org.lwjgl.Sys.getVersion())
);
} catch (Exception e) {
throw new RuntimeException(e);
}
aboutB.setPositiveButton(android.R.string.ok, null);
aboutB.show();
} break;
}
}
});
builder.show();
}
public void modManager()
{
File file1 = new File(Tools.mpModEnable);
@@ -848,6 +900,7 @@ public class MCLauncherActivity extends AppCompatActivity
dialog.setView(flv);
dialog.show();
}
public void openSelectMod()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -856,52 +909,154 @@ public class MCLauncherActivity extends AppCompatActivity
AlertDialog dialog = builder.create();
FileListView flv = new FileListView(this);
dialog.setView(flv);
dialog.show();
}
private void installOptiFine() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select OptiFine jar file");
builder.setPositiveButton(android.R.string.cancel, null);
final AlertDialog dialog = builder.create();
FileListView flv = new FileListView(this);
flv.setFileSelectedListener(new FileSelectedListener(){
@Override
public void onFileSelected(File file, String path, String name) {
if (name.endsWith(".jar")) {
doInstallOptiFine(file);
dialog.dismiss();
}
}
});
dialog.setView(flv);
dialog.show();
}
public void launcherMenu(View view)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.mcl_options);
builder.setItems(R.array.mcl_options, new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface p1, int p2)
{
switch(p2){
case 0:{ // Mods manager
modManager();
} break;
case 1:{ // Check update
checkUpdate();
} break;
case 2:{ // Settings
startActivity(new Intent(MCLauncherActivity.this, PojavPreferenceActivity.class));
} break;
case 3:{ // About
final AlertDialog.Builder aboutB = new AlertDialog.Builder(MCLauncherActivity.this);
aboutB.setTitle(R.string.mcl_option_about);
try
{
aboutB.setMessage(String.format(Tools.read(getAssets().open("about_en.txt")),
Tools.APP_NAME,
Tools.usingVerName,
org.lwjgl.Sys.getVersion())
);
} catch (Exception e) {
throw new RuntimeException(e);
}
aboutB.setPositiveButton(android.R.string.ok, null);
aboutB.show();
} break;
}
}
});
builder.show();
private void doInstallOptiFine(File optifineFile) {
new OptiFineInstaller().execute(optifineFile);
}
private class OptiFineInstaller extends AsyncTask<File, String, Throwable>
{
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(MCLauncherActivity.this);
dialog.setTitle("Installing OptiFine");
dialog.setMessage("Prepaping");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setCancelable(false);
dialog.show();
}
@Override
protected Throwable doInBackground(File[] file) {
final StringBuilder currentLog = new StringBuilder();
LoggerJava.LoggerOutputStream logOut = new LoggerJava.LoggerOutputStream(System.out, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(char c)
{
currentLog.append(c);
}
});
LoggerJava.LoggerOutputStream logErr = new LoggerJava.LoggerOutputStream(System.err, new LoggerJava.OnStringPrintListener(){
@Override
public void onCharPrint(char c)
{
currentLog.append(c);
}
});
Throwable throwable = null;
File convertedFile = null;
try {
String origMd5 = OptiFinePatcher.calculateMD5(file[0]);
convertedFile = new File(Tools.optifineDir, origMd5 + ".jar");
if (!convertedFile.exists()) {
publishProgress("(1/5) Patching OptiFine Installer");
String[] output = Tools.patchOptifineInstaller(MCLauncherActivity.this, file[0]);
File patchedFile = new File(output[1]);
publishProgress("(2/5) Converting OptiFine");
System.setOut(new PrintStream(logOut));
System.setErr(new PrintStream(logErr));
Tools.runDx(MCLauncherActivity.this, patchedFile.getAbsolutePath(), convertedFile.getAbsolutePath(), true, null);
if (!convertedFile.exists()) {
RuntimeException dxError = new RuntimeException(getResources().getString(R.string.error_convert_lib, "OptiFine") + "\n" + currentLog.toString());
dxError.setStackTrace(new StackTraceElement[0]);
throw dxError;
}
patchedFile.delete();
}
publishProgress("(3/5) Launching OptiFine installer");
File optDir = getDir("dalvik-cache", 0);
optDir.mkdir();
DexClassLoader loader = new DexClassLoader(convertedFile.getAbsolutePath(), optDir.getAbsolutePath(), getApplicationInfo().nativeLibraryDir, getClass().getClassLoader());
Tools.insertOptiFinePath(loader, convertedFile.getAbsolutePath());
Class installerClass = loader.loadClass("optifine.AndroidInstaller");
Method installerMethod = installerClass.getDeclaredMethod("doInstall", File.class);
installerMethod.invoke(null, new File(Tools.MAIN_PATH));
publishProgress("(4/5) Patching OptiFine Tweaker");
String optifineCurr = ((String) fromConfig(loader, "MC_VERSION")) + "_" + ((String) fromConfig(loader, "OF_EDITION"));
new OptiFinePatcher(new File(Tools.libraries, "optifine/OptiFine/" + optifineCurr + "/OptiFine-" + optifineCurr + "_orig.jar")).saveTweaker();
publishProgress("(5/5) Done!");
Thread.sleep(500);
} catch (Throwable th) {
throwable = th;
} finally {
System.setOut(logOut.getRootStream());
System.setErr(logErr.getRootStream());
/*
if (throwable != null && convertedFile != null) {
convertedFile.delete();
}
*/
return throwable;
}
}
private Object fromConfig(DexClassLoader loader, String name) throws ReflectiveOperationException {
Field f = loader.loadClass("Config").getDeclaredField(name);
f.setAccessible(true);
return f.get(null);
}
@Override
protected void onProgressUpdate(String[] text) {
super.onProgressUpdate(text);
dialog.setMessage(text[0]);
}
@Override
protected void onPostExecute(Throwable th) {
super.onPostExecute(th);
dialog.dismiss();
new RefreshVersionListTask().execute();
if (th == null) {
Toast.makeText(MCLauncherActivity.this, R.string.toast_optifine_success, Toast.LENGTH_SHORT).show();
} else {
Tools.showError(MCLauncherActivity.this, th);
}
}
}
public void updateAppProcess(final String ver)
{
new Thread(new Runnable(){
@@ -922,8 +1077,8 @@ public class MCLauncherActivity extends AppCompatActivity
}
}).start();
}
public void checkUpdate()
{
public void checkUpdate() {
final ProgressDialog progUp = new ProgressDialog(this);
progUp.setMessage(getStr(R.string.mcl_option_checkupdate));
progUp.setCancelable(false);

View File

@@ -319,9 +319,9 @@ public class MainActivity extends Activity implements OnTouchListener
float mouseY = mousePointer.getTranslationY();
if (gestureDetector.onTouchEvent(event)) {
AndroidDisplay.putMouseEventWithCoords(MainActivity.this.rightOverride ? (byte) 1 : (byte) 0, (byte) 0, (int) mouseX, (int) (AndroidDisplay.windowHeight - mouseY), 0, System.nanoTime());
AndroidDisplay.putMouseEventWithCoords(MainActivity.this.rightOverride ? (byte) 1 : (byte) 0, (byte) 1, (int) mouseX, (int) (AndroidDisplay.windowHeight - mouseY), 0, System.nanoTime());
if (!MainActivity.this.rightOverride) {
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 1, (int) mouseX, (int) (AndroidDisplay.windowHeight - mouseY), 0, System.nanoTime());
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 0, (int) mouseX, (int) (AndroidDisplay.windowHeight - mouseY), 0, System.nanoTime());
if (!rightOverride) {
AndroidDisplay.mouseLeft = true;
}
@@ -342,7 +342,7 @@ public class MainActivity extends Activity implements OnTouchListener
case MotionEvent.ACTION_UP: // 1
case MotionEvent.ACTION_CANCEL: // 3
case MotionEvent.ACTION_POINTER_UP: // 6
if (!MainActivity.this.rightOverride) {
if (!rightOverride) {
AndroidDisplay.mouseLeft = false;
}
break;
@@ -388,14 +388,14 @@ public class MainActivity extends Activity implements OnTouchListener
@Override
public boolean onTouch(View p1, MotionEvent e)
{
int x = ((int) e.getX()) / MainActivity.this.scaleFactor;
int y = (MainActivity.this.glSurfaceView.getHeight() - ((int) e.getY())) / MainActivity.this.scaleFactor;
if (MainActivity.this.handleGuiBar(x, y, e)) {
int x = ((int) e.getX()) / scaleFactor;
int y = (glSurfaceView.getHeight() - ((int) e.getY())) / scaleFactor;
if (handleGuiBar(x, y, e)) {
return true;
} else if (!AndroidDisplay.grab && gestureDetector.onTouchEvent(e)) {
AndroidDisplay.putMouseEventWithCoords(MainActivity.this.rightOverride ? (byte) 1 : (byte) 0, (byte) 0, x, y, 0, System.nanoTime());
AndroidDisplay.putMouseEventWithCoords(MainActivity.this.rightOverride ? (byte) 1 : (byte) 0, (byte) 1, x, y, 0, System.nanoTime());
if (!MainActivity.this.rightOverride) {
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 1, x, y, 0, System.nanoTime());
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 0, x, y, 0, System.nanoTime());
if (!rightOverride) {
AndroidDisplay.mouseLeft = true;
}
return true;
@@ -405,15 +405,15 @@ public class MainActivity extends Activity implements OnTouchListener
switch (e.getActionMasked()) {
case e.ACTION_DOWN: // 0
case e.ACTION_POINTER_DOWN: // 5
if (!MainActivity.this.rightOverride) {
if (!rightOverride) {
AndroidDisplay.mouseLeft = true;
}
if (AndroidDisplay.grab) {
AndroidDisplay.putMouseEventWithCoords(MainActivity.this.rightOverride ? (byte) 1 : (byte) 0, (byte) 1, x, y, 0, System.nanoTime());
MainActivity.this.initialX = x;
MainActivity.this.initialY = y;
MainActivity.this.theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, 500);
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 1, x, y, 0, System.nanoTime());
initialX = x;
initialY = y;
theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, 500);
break;
}
break;
@@ -421,25 +421,28 @@ public class MainActivity extends Activity implements OnTouchListener
case e.ACTION_UP: // 1
case e.ACTION_CANCEL: // 3
case e.ACTION_POINTER_UP: // 6
AndroidDisplay.putMouseEventWithCoords(MainActivity.this.rightOverride ? (byte) 1 : (byte) 0, (byte) 0, x, y, 0, System.nanoTime());
if (!MainActivity.this.rightOverride) {
AndroidDisplay.putMouseEventWithCoords(rightOverride ? (byte) 1 : (byte) 0, (byte) 0, x, y, 0, System.nanoTime());
if (!rightOverride) {
AndroidDisplay.mouseLeft = false;
}
if (AndroidDisplay.grab) {
MainActivity.this.initialX = x;
MainActivity.this.initialY = y;
MainActivity.this.theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, 500);
if (!MainActivity.this.triggeredLeftMouseButton && Math.abs(MainActivity.this.initialX - x) < MainActivity.this.fingerStillThreshold && Math.abs(MainActivity.this.initialY - y) < MainActivity.this.fingerStillThreshold) {
MainActivity.this.sendMouseButton(1, true);
MainActivity.this.sendMouseButton(1, false);
/*
initialX = x;
initialY = y;
theHandler.sendEmptyMessageDelayed(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK, 500);
*/
if (!triggeredLeftMouseButton && Math.abs(initialX - x) < fingerStillThreshold && Math.abs(initialY - y) < fingerStillThreshold) {
sendMouseButton(1, true);
sendMouseButton(1, false);
}
if (MainActivity.this.triggeredLeftMouseButton) {
MainActivity.this.sendMouseButton(0, false);
if (triggeredLeftMouseButton) {
sendMouseButton(0, false);
}
MainActivity.this.triggeredLeftMouseButton = false;
MainActivity.this.theHandler.removeMessages(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK);
triggeredLeftMouseButton = false;
theHandler.removeMessages(MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK);
break;
}
break;
@@ -484,7 +487,7 @@ public class MainActivity extends Activity implements OnTouchListener
@Override
public void onSurfaceCreated(GL10 gl, javax.microedition.khronos.egl.EGLConfig p2)
{
MainActivity.this.calculateMcScale();
calculateMcScale();
EGL10 egl10 = (EGL10) EGLContext.getEGL();
AndroidContextImplementation.theEgl = egl10;
@@ -516,8 +519,8 @@ public class MainActivity extends Activity implements OnTouchListener
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
AndroidDisplay.windowWidth = width / MainActivity.this.scaleFactor;
AndroidDisplay.windowHeight = height / MainActivity.this.scaleFactor;
AndroidDisplay.windowWidth = width / scaleFactor;
AndroidDisplay.windowHeight = height / scaleFactor;
}
});
glSurfaceView.setPreserveEGLContextOnPause(true);
@@ -591,7 +594,7 @@ public class MainActivity extends Activity implements OnTouchListener
protected void onPause()
{
if (AndroidDisplay.grab){
onBackPressed();
sendKeyPress(Keyboard.KEY_ESCAPE);
}
super.onPause();
}
@@ -718,10 +721,19 @@ public class MainActivity extends Activity implements OnTouchListener
System.out.println("> Running Minecraft with classpath:");
System.out.println(launchClassPath);
System.out.println();
// Load classpath
DexClassLoader launchBaseLoader = new DexClassLoader(launchClassPath, launchOptimizedDirectory, launchLibrarySearchPath, getClassLoader());
// Setup OptiFine
if (mVersionInfo.optifineLib != null) {
String[] optifineInfo = mVersionInfo.optifineLib.name.split(":");
String optifineJar = Tools.artifactToPath(optifineInfo[0], optifineInfo[1], optifineInfo[2]);
ClassLoader launchBaseLoader;
launchBaseLoader = new DexClassLoader(launchClassPath, launchOptimizedDirectory, launchLibrarySearchPath, getClassLoader());
Tools.insertOptiFinePath(launchBaseLoader, optifineJar);
}
// Launch Minecraft
Class mainClass = launchBaseLoader.loadClass(mVersionInfo.mainClass);
Method mainMethod = mainClass.getMethod("main", String[].class);
mainMethod.setAccessible(true);
@@ -818,9 +830,9 @@ public class MainActivity extends Activity implements OnTouchListener
case MainActivity.MSG_LEFT_MOUSE_BUTTON_CHECK /*1028*/:
int x = AndroidDisplay.mouseX;
int y = AndroidDisplay.mouseY;
if (AndroidDisplay.grab && Math.abs(MainActivity.this.initialX - x) < MainActivity.this.fingerStillThreshold && Math.abs(MainActivity.this.initialY - y) < MainActivity.this.fingerStillThreshold) {
MainActivity.this.triggeredLeftMouseButton = true;
MainActivity.this.sendMouseButton(0, true);
if (AndroidDisplay.grab && Math.abs(initialX - x) < fingerStillThreshold && Math.abs(initialY - y) < fingerStillThreshold) {
triggeredLeftMouseButton = true;
sendMouseButton(0, true);
return;
}
return;
@@ -954,7 +966,7 @@ public class MainActivity extends Activity implements OnTouchListener
@Override
public void onBackPressed() {
sendKeyPress(Keyboard.KEY_ESCAPE);
// Prevent back
}
public void hideKeyboard() {
@@ -997,7 +1009,6 @@ public class MainActivity extends Activity implements OnTouchListener
public void sendMouseButton(int button, boolean status) {
AndroidDisplay.setMouseButtonInGrabMode((byte) button, status ? (byte) 1 : (byte) 0);
new Throwable("MouseRecord").printStackTrace();
}
public void calculateMcScale() {

View File

@@ -6,17 +6,20 @@ import android.content.res.*;
import android.net.*;
import android.os.*;
import android.util.*;
import android.widget.*;
import com.google.gson.*;
import dalvik.system.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.charset.*;
import java.util.*;
import java.util.jar.*;
import java.util.zip.*;
import net.kdt.pojavlaunch.util.*;
import net.kdt.pojavlaunch.value.*;
import org.apache.commons.codec.digest.*;
import android.widget.*;
import libcore.util.*;
import net.kdt.pojavlaunch.patcher.*;
import java.lang.reflect.*;
import dalvik.system.*;
public final class Tools
{
@@ -35,6 +38,7 @@ public final class Tools
// New since 2.4.2
public static String versnDir = MAIN_PATH + "/versions";
public static String libraries = MAIN_PATH + "/libraries";
public static String optifineDir = MAIN_PATH + "/optifine";
// Old since 2.4.2
public static String oldGameDir = MAIN_PATH + "/gamedir";
@@ -48,6 +52,8 @@ public final class Tools
public static String mpModDisable = datapath + "/ModsManager/❌Disabled";
public static String mpModAddNewMo = datapath + "/ModsManager/Add mod";
public static String optifineLib = "optifine:OptiFine";
public static String[] versionList = {
"1.7.3",
"1.7.10",
@@ -69,16 +75,22 @@ public final class Tools
return new File(versnDir + "/" + version + "/optifine.jar").exists();
}
private static boolean isClientFirst = false;
public static String generate(String version) throws IOException
{
StringBuilder libStr = new StringBuilder(); //versnDir + "/" + version + "/" + version + ".jar:";
String[] classpath = generateLibClasspath(getVersionInfo(version).libraries);
libStr.append(getPatchedFile(version));
for (String perJar : classpath) {
libStr.append(":" + perJar);
if (isClientFirst) {
libStr.append(getPatchedFile(version));
}
for (String perJar : classpath) {
libStr.append((isClientFirst ? ":" : "") + perJar + (!isClientFirst ? ":" : ""));
}
if (!isClientFirst) {
libStr.append(getPatchedFile(version));
}
return libStr.toString();
}
@@ -110,6 +122,13 @@ public final class Tools
}
}
public static void insertOptiFinePath(DexClassLoader loader, String optifineJar) throws NoSuchFieldException, IllegalAccessException, IllegalArgumentException, ClassNotFoundException {
Class optifineClass = loader.loadClass("optifine.AndroidOptiFineUtilities");
Field optifinePathField = optifineClass.getDeclaredField("originalOptifineJar");
optifinePathField.setAccessible(true);
optifinePathField.set(null, optifineJar);
}
/*
public static void extractLibraries(Activity ctx) throws Exception
{
@@ -223,7 +242,7 @@ public final class Tools
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
act.startActivity(browserIntent);
}
/*
public static void clearDuplicateFiles(File f) throws IOException {
List<File> list = Arrays.asList(f.listFiles());
for (File file : list) {
@@ -233,7 +252,7 @@ public final class Tools
continue;
}
String md5 = DigestUtils.md5Hex(new FileInputStream(file));
String md5 = Md5Crypt.md5Crypt(read(file));
list.remove(file);
clearDuplicateFilesByMD5(list.toArray(new File[0]), md5);
}
@@ -247,7 +266,7 @@ public final class Tools
}
}
}
*/
public static String[] generateLibClasspath(DependentLibrary[] libs)
{
List<String> libDir = new ArrayList<String>();
@@ -258,6 +277,17 @@ public final class Tools
return libDir.toArray(new String[0]);
}
public static String[] patchOptifineInstaller(Activity ctx, File inFile) throws Exception {
File optifineDirFile = new File(optifineDir);
optifineDirFile.mkdir();
// Extract patch files
extractAssetFolder(ctx, "optifine_patch", optifineDir);
// Patch OptiFine!
return new OptiFinePatcher(inFile).saveInstaller(optifineDirFile);
}
private static int selectCompatibleSdkInt() {
int currSdkInt = Build.VERSION.SDK_INT;
if (currSdkInt < 23) {
@@ -272,13 +302,18 @@ public final class Tools
}
public static void runDx(final Activity ctx, String fileIn, String fileOut, PojavDXManager.Listen listener) throws Exception
{
runDx(ctx, fileIn, fileOut, false, listener);
}
public static void runDx(final Activity ctx, String fileIn, String fileOut, boolean keepClass, PojavDXManager.Listen listener) throws Exception
{
PojavDXManager.setListener(listener);
File optDir = ctx.getDir("dalvik-cache", 0);
optDir.mkdirs();
com.pojavdx.dx.command.Main.main(new String[]{"--dex", "--verbose", "--min-sdk-version=" + selectCompatibleSdkInt() , "--multi-dex", "--no-optimize", "--num-threads=4", "--output", fileOut, fileIn});
com.pojavdx.dx.command.Main.main(new String[]{"--dex", (keepClass ? "--keep-classes" : "--verbose"), "--verbose", "--min-sdk-version=" + selectCompatibleSdkInt() , "--multi-dex", "--no-optimize", "--num-threads=4", "--output", fileOut, fileIn});
//return Runtime.getRuntime().exec("echo IN:" + fileIn + ";OUT:" + fileOut);
}
@@ -286,6 +321,12 @@ public final class Tools
public static JMinecraftVersionList.Version getVersionInfo(String versionName) {
try {
JMinecraftVersionList.Version customVer = new Gson().fromJson(read(versnDir + "/" + versionName + "/" + versionName + ".json"), JMinecraftVersionList.Version.class);
for (DependentLibrary lib : customVer.libraries) {
if (lib.name.startsWith(optifineLib)) {
customVer.optifineLib = lib;
break;
}
}
if (customVer.inheritsFrom == null) {
return customVer;
} else {
@@ -294,6 +335,7 @@ public final class Tools
inheritsVer.id = customVer.id;
inheritsVer.mainClass = customVer.mainClass;
inheritsVer.minecraftArguments = customVer.minecraftArguments;
inheritsVer.optifineLib = customVer.optifineLib;
inheritsVer.releaseTime = customVer.releaseTime;
inheritsVer.time = customVer.time;
inheritsVer.type = customVer.type;

View File

@@ -1,17 +0,0 @@
package net.kdt.pojavlaunch.optifine;
import com.google.gson.*;
import java.nio.charset.*;
import net.kdt.pojavlaunch.value.*;
import net.kdt.pojavlaunch.util.*;
import java.io.*;
import net.kdt.pojavlaunch.*;
public class Optifine
{
public static OptifineVersion.VersionList getList() throws Exception
{
String optifineStr = DownloadUtils.downloadString(Tools.mhomeUrl + "/optifine.json");
return new Gson().fromJson(optifineStr, OptifineVersion.VersionList.class);
}
}

View File

@@ -1,10 +0,0 @@
package net.kdt.pojavlaunch.optifine;
public class OptifineVersion
{
public VersionList[] versions;
public static class VersionList {
public String version;
public String linkUrl;
}
}

View File

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

View File

@@ -0,0 +1,121 @@
package net.kdt.pojavlaunch.patcher;
import android.util.*;
import java.io.*;
import java.math.*;
import java.security.*;
import java.util.*;
import java.util.jar.*;
import net.kdt.pojavlaunch.*;
public class OptiFinePatcher
{
private File input;
private JarFile inputFile;
private Enumeration<? extends JarEntry> inputEntries;
public OptiFinePatcher(File input) throws IOException {
this.input = input;
inputFile = new JarFile(input);
inputEntries = inputFile.entries();
}
public String[] saveInstaller(File patchDir) throws Exception {
String md5File = calculateMD5(input);
File optifineJar = new File(patchDir, md5File + "_OptiFine_patched.jar");
BufferedOutputStream optifineBuf = new BufferedOutputStream(new FileOutputStream(optifineJar));
JarOutputStream optifineJarStream = new JarOutputStream(optifineBuf);
while (inputEntries.hasMoreElements()) {
JarEntry inEntry = inputEntries.nextElement();
if (!inEntry.getName().equals("optifine/OptiFineClassTransformer.class")) {
optifineJarStream.putNextEntry(inEntry);
optifineJarStream.write(Tools.getByteArray(inputFile.getInputStream(inEntry)));
optifineJarStream.closeEntry();
}
}
for (File patchClass : new File(patchDir, "optifine_patch").listFiles()) {
if (patchClass.isFile()) {
byte[] bArr = Tools.getByteArray(patchClass.getAbsolutePath());
String patchName = patchClass.getName();
JarEntry entry = new JarEntry("optifine/" + patchName.replace(".class.patch", ".class"));
entry.setSize(bArr.length);
optifineJarStream.putNextEntry(entry);
optifineJarStream.write(bArr);
optifineJarStream.closeEntry();
}
}
optifineJarStream.finish();
optifineJarStream.flush();
optifineBuf.flush();
optifineBuf.close();
return new String[]{md5File, optifineJar.getAbsolutePath()};
}
public void saveTweaker() throws Exception {
File patchedFile = new File(input.getAbsolutePath().replace(".jar", "_patched.jar"));
BufferedOutputStream optifineBuf = new BufferedOutputStream(new FileOutputStream(patchedFile));
JarOutputStream optifineJarStream = new JarOutputStream(optifineBuf);
while (inputEntries.hasMoreElements()) {
JarEntry inEntry = inputEntries.nextElement();
if (!inEntry.getName().startsWith("classes") && !inEntry.getName().endsWith(".dex")) {
optifineJarStream.putNextEntry(inEntry);
optifineJarStream.write(Tools.getByteArray(inputFile.getInputStream(inEntry)));
optifineJarStream.closeEntry();
}
}
optifineJarStream.finish();
optifineJarStream.flush();
optifineBuf.flush();
optifineBuf.close();
input.delete();
patchedFile.renameTo(input);
}
public static String calculateMD5(File updateFile) {
MessageDigest digest;
String TAG = "MD5Check";
try {
digest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "Exception while getting digest", e);
return null;
}
InputStream is;
try {
is = new FileInputStream(updateFile);
} catch (FileNotFoundException e) {
Log.e(TAG, "Exception while getting FileInputStream", e);
return null;
}
byte[] buffer = new byte[8192];
int read;
try {
while ((read = is.read(buffer)) > 0) {
digest.update(buffer, 0, read);
}
byte[] md5sum = digest.digest();
BigInteger bigInt = new BigInteger(1, md5sum);
String output = bigInt.toString(16);
// Fill to 32 chars
output = String.format("%32s", output).replace(' ', '0');
return output;
} catch (IOException e) {
throw new RuntimeException("Unable to process file for MD5", e);
} finally {
try {
is.close();
} catch (IOException e) {
Log.e(TAG, "Exception on closing MD5 input stream", e);
}
}
}
}

View File

@@ -46,7 +46,7 @@ public class PojavPreferenceActivity extends MineActivity
mainPrefEdit.commit();
}
});
viewSeekProgress.setText(viewSeekDxRef.getProgress() + "/" + 0xFFFF);
viewSeekProgress.setText((viewSeekDxRef.getProgress() + 0xFFF) + "/" + 0xFFFF);
}
@Override

View File

@@ -13,9 +13,9 @@ public class JarSigner
{
private static final String DEX_IN_JAR_NAME = "classes.dex";
private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
private TreeMap<String, byte[]> outputResources = new TreeMap<String, byte[]>();
public static void sign(String inputJar, String outputJar) throws Exception
{
new JarSigner(inputJar, outputJar);
@@ -24,7 +24,7 @@ public class JarSigner
{
ZipFile jarFile = new ZipFile(inputJar);
Enumeration<? extends ZipEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
outputResources.put(entry.getName(), Tools.getByteArray(jarFile.getInputStream(entry)));
@@ -33,13 +33,13 @@ public class JarSigner
}
private byte[] makeManifest() {
StringBuilder baos = new StringBuilder();
// First, put some general information:
baos.append("Manifest-Version: 1.0\n");
baos.append("Created-By: " + Tools.usingVerName + " (" + Tools.APP_NAME + ": JarSigner)\n");
baos.append("Build-Jdk: 1.6.0_29");
baos.append("Dex-Location: " + DEX_IN_JAR_NAME + "\n");
return baos.toString().getBytes();
}
private boolean createJar(String fileName) {
@@ -62,14 +62,14 @@ public class JarSigner
int length = contents.length;
entry.setSize(length);
/*
if (args.verbose) {
context.out.println("writing " + name + "; size " + length + "...");
}
*/
if (args.verbose) {
context.out.println("writing " + name + "; size " + length + "...");
}
*/
if (name.endsWith(".SF") ||
name.endsWith(".RSA")) {
// Remove these files.
continue;
// Remove these files.
continue;
} else if (name.endsWith(MANIFEST_PATH)) {
length = manifest.length;
jarOut.putNextEntry(entry);
@@ -80,7 +80,7 @@ public class JarSigner
jarOut.write(contents);
jarOut.closeEntry();
}
}
} finally {
jarOut.finish();