mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 08:35:37 -04:00
Merge pull request #4151 from PojavLauncherTeam/ffmpeg-plugin
I forgot to switch branches in android studio
This commit is contained in:
commit
f724fb4d4f
@ -144,7 +144,7 @@ dependencies {
|
|||||||
// implementation 'com.intuit.ssp:ssp-android:1.0.5'
|
// implementation 'com.intuit.ssp:ssp-android:1.0.5'
|
||||||
|
|
||||||
implementation 'org.tukaani:xz:1.8'
|
implementation 'org.tukaani:xz:1.8'
|
||||||
implementation 'com.github.PojavLauncherTeam:exp4j:master-SNAPSHOT'
|
implementation 'com.github.PojavLauncherTeam:exp4j:60eaec6f78'
|
||||||
// implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'
|
// implementation 'net.sourceforge.streamsupport:streamsupport-cfuture:1.7.0'
|
||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,10 @@ import android.widget.*;
|
|||||||
import androidx.activity.OnBackPressedCallback;
|
import androidx.activity.OnBackPressedCallback;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
import net.kdt.pojavlaunch.customcontrols.keyboard.AwtCharSender;
|
import net.kdt.pojavlaunch.customcontrols.keyboard.AwtCharSender;
|
||||||
import net.kdt.pojavlaunch.customcontrols.keyboard.TouchCharInput;
|
import net.kdt.pojavlaunch.customcontrols.keyboard.TouchCharInput;
|
||||||
@ -123,13 +126,20 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MultiRTUtils.setRuntimeNamed(LauncherPreferences.PREF_DEFAULT_RUNTIME);
|
|
||||||
|
|
||||||
placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2);
|
placeMouseAt(CallbackBridge.physicalWidth / 2, CallbackBridge.physicalHeight / 2);
|
||||||
|
|
||||||
final File modFile = (File) getIntent().getExtras().getSerializable("modFile");
|
final File modFile = (File) getIntent().getExtras().getSerializable("modFile");
|
||||||
final String javaArgs = getIntent().getExtras().getString("javaArgs");
|
final String javaArgs = getIntent().getExtras().getString("javaArgs");
|
||||||
|
|
||||||
|
int javaVersion = getJavaVersion(modFile);
|
||||||
|
String jreName = javaVersion == -1 ? null : MultiRTUtils.getNearestJreName(javaVersion);
|
||||||
|
if(jreName != null) {
|
||||||
|
MultiRTUtils.setRuntimeNamed(jreName);
|
||||||
|
}else{
|
||||||
|
MultiRTUtils.setRuntimeNamed(LauncherPreferences.PREF_DEFAULT_RUNTIME);
|
||||||
|
}
|
||||||
|
|
||||||
mSkipDetectMod = getIntent().getExtras().getBoolean("skipDetectMod", false);
|
mSkipDetectMod = getIntent().getExtras().getBoolean("skipDetectMod", false);
|
||||||
if (mSkipDetectMod) {
|
if (mSkipDetectMod) {
|
||||||
new Thread(() -> launchJavaRuntime(modFile, javaArgs), "JREMainThread").start();
|
new Thread(() -> launchJavaRuntime(modFile, javaArgs), "JREMainThread").start();
|
||||||
@ -309,4 +319,34 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc
|
|||||||
public void toggleKeyboard(View view) {
|
public void toggleKeyboard(View view) {
|
||||||
mTouchCharInput.switchKeyboardState();
|
mTouchCharInput.switchKeyboardState();
|
||||||
}
|
}
|
||||||
|
public int getJavaVersion(File modFile) {
|
||||||
|
try (ZipFile zipFile = new ZipFile(modFile)){
|
||||||
|
ZipEntry manifest = zipFile.getEntry("META-INF/MANIFEST.MF");
|
||||||
|
if(manifest == null) return -1;
|
||||||
|
String manifestString = Tools.read(zipFile.getInputStream(manifest));
|
||||||
|
String mainClass = Tools.extractUntilCharacter(manifestString, "Main-Class:", '\n');
|
||||||
|
if(mainClass == null) return -1;
|
||||||
|
mainClass = mainClass.trim().replace('.', '/') + ".class";
|
||||||
|
ZipEntry mainClassFile = zipFile.getEntry(mainClass);
|
||||||
|
if(mainClassFile == null) return -1;
|
||||||
|
InputStream classStream = zipFile.getInputStream(mainClassFile);
|
||||||
|
byte[] bytesWeNeed = new byte[8];
|
||||||
|
int readCount = classStream.read(bytesWeNeed);
|
||||||
|
if(readCount < 8) return -1;
|
||||||
|
classStream.close();
|
||||||
|
ByteBuffer byteBuffer = ByteBuffer.wrap(bytesWeNeed);
|
||||||
|
if(byteBuffer.getInt() != 0xCAFEBABE) return -1;
|
||||||
|
short minorVersion = byteBuffer.getShort();
|
||||||
|
short majorVersion = byteBuffer.getShort();
|
||||||
|
Log.i("JavaGUILauncher", majorVersion+","+minorVersion);
|
||||||
|
return classVersionToJavaVersion(majorVersion);
|
||||||
|
}catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static int classVersionToJavaVersion(int majorVersion) {
|
||||||
|
if(majorVersion < 46) return 2; // there isn't even an arm64 port of jre 1.1 (or anything before 1.8 in fact)
|
||||||
|
return majorVersion - 44;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -967,4 +967,13 @@ public final class Tools {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String extractUntilCharacter(String input, String whatFor, char terminator) {
|
||||||
|
int whatForStart = input.indexOf(whatFor);
|
||||||
|
if(whatForStart == -1) return null;
|
||||||
|
whatForStart += whatFor.length();
|
||||||
|
int terminatorIndex = input.indexOf(terminator, whatForStart);
|
||||||
|
if(terminatorIndex == -1) return null;
|
||||||
|
return input.substring(whatForStart, terminatorIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user