Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
967bb9da67 | ||
|
|
1b3d5c6ec3 | ||
|
|
43e7620ac3 | ||
|
|
cd751fa161 | ||
|
|
488501249e | ||
|
|
80e0a6aac8 | ||
|
|
dd15d8a469 | ||
|
|
93924b429b | ||
|
|
a77271df03 | ||
|
|
5d80d9baec | ||
|
|
99c8ea2bfd | ||
|
|
9a7fb2ae69 | ||
|
|
f2e95b6e65 | ||
|
|
8cc5cca99f | ||
|
|
dcbb1e010e | ||
|
|
b3df2645e5 | ||
|
|
38e47687fa | ||
|
|
4738e1aa59 | ||
|
|
e0fcb1e67d | ||
|
|
89f0254106 |
No files matched your search
@@ -1,3 +1,3 @@
|
||||
1. This app (while idle) does NOT collect any sensitive information, and does NOT use network (exception is the "News" page, it uses network to load the launcher news)
|
||||
1. This app (while idle) does NOT collect any sensitive information, and uses network for downloading Minecraft resources.
|
||||
2. While running Minecraft, app also does NOT collect any sensitive information about your device. Snooper by Mojang does.
|
||||
3. Some sensitive data is stored in crash reports after the game crashes, but it's not being shared to anyone except the current user.
|
||||
@@ -112,7 +112,7 @@ Then, run these commands ~~or build using Android Studio~~.
|
||||
- Probably more, that's why we have a bug tracker ;)
|
||||
|
||||
## License
|
||||
- PojavLauncher is licensed under [GNU GPLv3](https://github.com/khanhduytran0/PojavLauncher/blob/master/LICENSE).
|
||||
- PojavLauncher is licensed under [GNU LGPLv3](https://github.com/PojavLauncherTeam/PojavLauncher/blob/v3_openjdk/LICENSE).
|
||||
|
||||
## Contributing
|
||||
Contributions are welcome! We welcome any type of contribution, not only code. For example, you can help the wiki shape up. You can help the [translation](https://crowdin.com/project/pojavlauncher) too!
|
||||
|
||||
+6
-1
@@ -17,7 +17,7 @@ public class LeftClickGesture extends ValidatorGesture {
|
||||
private boolean mMouseActivated;
|
||||
|
||||
public LeftClickGesture(Handler handler) {
|
||||
super(handler, LauncherPreferences.PREF_LONGPRESS_TRIGGER);
|
||||
super(handler);
|
||||
}
|
||||
|
||||
public final void inputEvent() {
|
||||
@@ -27,6 +27,11 @@ public class LeftClickGesture extends ValidatorGesture {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getGestureDelay() {
|
||||
return LauncherPreferences.PREF_LONGPRESS_TRIGGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAndTrigger() {
|
||||
boolean fingerStill = LeftClickGesture.isFingerStill(mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY, FINGER_STILL_THRESHOLD);
|
||||
|
||||
+7
-2
@@ -6,12 +6,12 @@ import net.kdt.pojavlaunch.LwjglGlfwKeycode;
|
||||
|
||||
import org.lwjgl.glfw.CallbackBridge;
|
||||
|
||||
public class RightClickGesture extends ValidatorGesture{
|
||||
public class RightClickGesture extends ValidatorGesture {
|
||||
private boolean mGestureEnabled = true;
|
||||
private boolean mGestureValid = true;
|
||||
private float mGestureStartX, mGestureStartY, mGestureEndX, mGestureEndY;
|
||||
public RightClickGesture(Handler mHandler) {
|
||||
super(mHandler, 150);
|
||||
super(mHandler);
|
||||
}
|
||||
|
||||
public final void inputEvent() {
|
||||
@@ -29,6 +29,11 @@ public class RightClickGesture extends ValidatorGesture{
|
||||
mGestureEndY += deltaY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getGestureDelay() {
|
||||
return 150;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkAndTrigger() {
|
||||
// If the validate() method was called, it means that the user held on for too long. The cancellation should be ignored.
|
||||
|
||||
+9
-6
@@ -9,16 +9,13 @@ import android.os.Handler;
|
||||
public abstract class ValidatorGesture implements Runnable{
|
||||
private final Handler mHandler;
|
||||
private boolean mGestureActive;
|
||||
private final int mRequiredDuration;
|
||||
|
||||
/**
|
||||
* @param mHandler the Handler that will be used for calling back the checkAndTrigger() method.
|
||||
* This Handler should run on the same thread as the callee of submit()/cancel()
|
||||
* @param mRequiredDuration the duration after which the class will call checkAndTrigger().
|
||||
*/
|
||||
public ValidatorGesture(Handler mHandler, int mRequiredDuration) {
|
||||
public ValidatorGesture(Handler mHandler) {
|
||||
this.mHandler = mHandler;
|
||||
this.mRequiredDuration = mRequiredDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,7 +25,7 @@ public abstract class ValidatorGesture implements Runnable{
|
||||
*/
|
||||
public final boolean submit() {
|
||||
if(mGestureActive) return false;
|
||||
mHandler.postDelayed(this, mRequiredDuration);
|
||||
mHandler.postDelayed(this, getGestureDelay());
|
||||
mGestureActive = true;
|
||||
return true;
|
||||
}
|
||||
@@ -55,7 +52,13 @@ public abstract class ValidatorGesture implements Runnable{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called after mRequiredDuration milliseconds, if the gesture was not cancelled.
|
||||
* This method will be called during gesture submission to determine the gesture check duration.
|
||||
* @return the required gesture check duration in milliseconds
|
||||
*/
|
||||
protected abstract int getGestureDelay();
|
||||
|
||||
/**
|
||||
* This method will be called after getGestureDelay() milliseconds, if the gesture was not cancelled.
|
||||
* @return false if you want to mark this gesture as "inactive"
|
||||
* true otherwise
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@ public class DownloadMirror {
|
||||
return;
|
||||
}catch (FileNotFoundException e) {
|
||||
Log.w("DownloadMirror", "Cannot find the file on the mirror", e);
|
||||
Log.i("DownloadMirror", "Failling back to default source");
|
||||
Log.i("DownloadMirror", "Falling back to default source");
|
||||
}
|
||||
DownloadUtils.downloadFileMonitored(urlInput, outputFile, buffer, monitor);
|
||||
}
|
||||
@@ -63,11 +63,30 @@ public class DownloadMirror {
|
||||
return;
|
||||
}catch (FileNotFoundException e) {
|
||||
Log.w("DownloadMirror", "Cannot find the file on the mirror", e);
|
||||
Log.i("DownloadMirror", "Failling back to default source");
|
||||
Log.i("DownloadMirror", "Falling back to default source");
|
||||
}
|
||||
DownloadUtils.downloadFile(urlInput, outputFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content length of a file on the current mirror. If the file is missing on the mirror,
|
||||
* or the mirror does not give out the length, request the length from the original source
|
||||
* @param downloadClass Class of the download. Can either be DOWNLOAD_CLASS_LIBRARIES,
|
||||
* DOWNLOAD_CLASS_METADATA or DOWNLOAD_CLASS_ASSETS
|
||||
* @param urlInput The original (Mojang) URL for the download
|
||||
* @return the length of the file denoted by the URL in bytes, or -1 if not available
|
||||
*/
|
||||
public static long getContentLengthMirrored(int downloadClass, String urlInput) throws IOException {
|
||||
long length = DownloadUtils.getContentLength(getMirrorMapping(downloadClass, urlInput));
|
||||
if(length < 1) {
|
||||
Log.w("DownloadMirror", "Unable to get content length from mirror");
|
||||
Log.i("DownloadMirror", "Falling back to default source");
|
||||
return DownloadUtils.getContentLength(urlInput);
|
||||
}else {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current download source is a mirror and not an official source.
|
||||
* @return true if the source is a mirror, false otherwise
|
||||
|
||||
@@ -5,15 +5,21 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class FFmpegPlugin {
|
||||
public static boolean isAvailable = false;
|
||||
public static String libraryPath;
|
||||
public static String executablePath;
|
||||
public static void discover(Context context) {
|
||||
PackageManager manager = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo ffmpegPluginInfo = manager.getPackageInfo("net.kdt.pojavlaunch.ffmpeg", PackageManager.GET_SHARED_LIBRARY_FILES);
|
||||
libraryPath = ffmpegPluginInfo.applicationInfo.nativeLibraryDir;
|
||||
isAvailable = true;
|
||||
File ffmpegExecutable = new File(libraryPath, "libffmpeg.so");
|
||||
executablePath = ffmpegExecutable.getAbsolutePath();
|
||||
// Older plugin versions still have the old executable location
|
||||
isAvailable = ffmpegExecutable.exists();
|
||||
}catch (Exception e) {
|
||||
Log.i("FFmpegPlugin", "Failed to discover plugin", e);
|
||||
}
|
||||
|
||||
+52
-16
@@ -37,14 +37,18 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class MinecraftDownloader {
|
||||
private static final double ONE_MEGABYTE = (1024d * 1024d);
|
||||
public static final String MINECRAFT_RES = "https://resources.download.minecraft.net/";
|
||||
private AtomicReference<Exception> mDownloaderThreadException;
|
||||
private ArrayList<DownloaderTask> mScheduledDownloadTasks;
|
||||
private AtomicLong mDownloadFileCounter;
|
||||
private AtomicLong mDownloadSizeCounter;
|
||||
private long mDownloadFileCount;
|
||||
private AtomicLong mProcessedFileCounter;
|
||||
private AtomicLong mProcessedSizeCounter; // Total bytes of processed files (passed SHA1 or downloaded)
|
||||
private AtomicLong mInternetUsageCounter; // How many bytes downloaded over Internet
|
||||
private long mTotalFileCount;
|
||||
private long mTotalSize;
|
||||
private File mSourceJarFile; // The source client JAR picked during the inheritance process
|
||||
private File mTargetJarFile; // The destination client JAR to which the source will be copied to.
|
||||
private boolean mUseFileCounter; // Whether a file counter or a size counter should be used for progress
|
||||
|
||||
private static final ThreadLocal<byte[]> sThreadLocalDownloadBuffer = new ThreadLocal<>();
|
||||
|
||||
@@ -80,12 +84,15 @@ public class MinecraftDownloader {
|
||||
// Put up a dummy progress line, for the activity to start the service and do all the other necessary
|
||||
// work to keep the launcher alive. We will replace this line when we will start downloading stuff.
|
||||
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, 0, R.string.newdl_starting);
|
||||
SpeedCalculator speedCalculator = new SpeedCalculator();
|
||||
|
||||
mTargetJarFile = createGameJarPath(versionName);
|
||||
mScheduledDownloadTasks = new ArrayList<>();
|
||||
mDownloadFileCounter = new AtomicLong(0);
|
||||
mDownloadSizeCounter = new AtomicLong(0);
|
||||
mProcessedFileCounter = new AtomicLong(0);
|
||||
mProcessedSizeCounter = new AtomicLong(0);
|
||||
mInternetUsageCounter = new AtomicLong(0);
|
||||
mDownloaderThreadException = new AtomicReference<>(null);
|
||||
mUseFileCounter = false;
|
||||
|
||||
if(!downloadAndProcessMetadata(activity, verInfo, versionName)) {
|
||||
throw new RuntimeException(activity.getString(R.string.exception_failed_to_unpack_jre17));
|
||||
@@ -104,11 +111,9 @@ public class MinecraftDownloader {
|
||||
try {
|
||||
while (mDownloaderThreadException.get() == null &&
|
||||
!downloaderPool.awaitTermination(33, TimeUnit.MILLISECONDS)) {
|
||||
long dlFileCounter = mDownloadFileCounter.get();
|
||||
int progress = (int)((dlFileCounter * 100L) / mDownloadFileCount);
|
||||
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, progress,
|
||||
R.string.newdl_downloading_game_files, dlFileCounter,
|
||||
mDownloadFileCount, (double)mDownloadSizeCounter.get() / (1024d * 1024d));
|
||||
double speed = speedCalculator.feed(mInternetUsageCounter.get()) / ONE_MEGABYTE;
|
||||
if(mUseFileCounter) reportProgressFileCounter(speed);
|
||||
else reportProgressSizeCounter(speed);
|
||||
}
|
||||
Exception thrownException = mDownloaderThreadException.get();
|
||||
if(thrownException != null) {
|
||||
@@ -123,6 +128,23 @@ public class MinecraftDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
private void reportProgressFileCounter(double speed) {
|
||||
long dlFileCounter = mProcessedFileCounter.get();
|
||||
int progress = (int)((dlFileCounter * 100L) / mTotalFileCount);
|
||||
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, progress,
|
||||
R.string.newdl_downloading_game_files, dlFileCounter,
|
||||
mTotalFileCount, speed);
|
||||
}
|
||||
|
||||
private void reportProgressSizeCounter(double speed) {
|
||||
long dlFileSize = mProcessedSizeCounter.get();
|
||||
double dlSizeMegabytes = (double) dlFileSize / ONE_MEGABYTE;
|
||||
double dlTotalMegabytes = (double) mTotalSize / ONE_MEGABYTE;
|
||||
int progress = (int)((dlFileSize * 100L) / mTotalSize);
|
||||
ProgressLayout.setProgress(ProgressLayout.DOWNLOAD_MINECRAFT, progress,
|
||||
R.string.newdl_downloading_game_files_size, dlSizeMegabytes, dlTotalMegabytes, speed);
|
||||
}
|
||||
|
||||
private File createGameJsonPath(String versionId) {
|
||||
return new File(Tools.DIR_HOME_VERSION, versionId + File.separator + versionId + ".json");
|
||||
}
|
||||
@@ -233,7 +255,19 @@ public class MinecraftDownloader {
|
||||
private void scheduleDownload(File targetFile, int downloadClass, String url, String sha1,
|
||||
long size, boolean skipIfFailed) throws IOException {
|
||||
FileUtils.ensureParentDirectory(targetFile);
|
||||
mDownloadFileCount++;
|
||||
mTotalFileCount++;
|
||||
if(size < 0) {
|
||||
size = DownloadMirror.getContentLengthMirrored(downloadClass, url);
|
||||
}
|
||||
if(size < 0) {
|
||||
// If we were unable to get the content length ourselves, we automatically fall back
|
||||
// to tracking the progress using the file counter.
|
||||
size = 0;
|
||||
mUseFileCounter = true;
|
||||
Log.i("MinecraftDownloader", "Failed to determine size of "+targetFile.getName()+", switching to file counter");
|
||||
}else {
|
||||
mTotalSize += size;
|
||||
}
|
||||
mScheduledDownloadTasks.add(
|
||||
new DownloaderTask(targetFile, downloadClass, url, sha1, size, skipIfFailed)
|
||||
);
|
||||
@@ -401,18 +435,20 @@ public class MinecraftDownloader {
|
||||
}catch (Exception e) {
|
||||
if(!mSkipIfFailed) throw e;
|
||||
}
|
||||
mDownloadFileCounter.incrementAndGet();
|
||||
mProcessedFileCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
private void finishWithoutDownloading() {
|
||||
mDownloadFileCounter.incrementAndGet();
|
||||
mDownloadSizeCounter.addAndGet(mDownloadSize);
|
||||
mProcessedFileCounter.incrementAndGet();
|
||||
mProcessedSizeCounter.addAndGet(mDownloadSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgress(int curr, int max) {
|
||||
mDownloadSizeCounter.addAndGet(curr - mLastCurr);
|
||||
mLastCurr = curr;
|
||||
int delta = curr - mLastCurr;
|
||||
mProcessedSizeCounter.addAndGet(delta);
|
||||
mInternetUsageCounter.addAndGet(delta);
|
||||
mLastCurr = curr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package net.kdt.pojavlaunch.tasks;
|
||||
|
||||
/**
|
||||
* A simple class to calculate the average Internet speed using a simple moving average.
|
||||
*/
|
||||
public class SpeedCalculator {
|
||||
private long mLastMillis;
|
||||
private long mLastBytes;
|
||||
private int mIndex;
|
||||
private final double[] mPreviousInputs;
|
||||
private double mSum;
|
||||
|
||||
public SpeedCalculator() {
|
||||
this(64);
|
||||
}
|
||||
|
||||
public SpeedCalculator(int averageDepth) {
|
||||
mPreviousInputs = new double[averageDepth];
|
||||
}
|
||||
|
||||
private double addToAverage(double speed) {
|
||||
mSum -= mPreviousInputs[mIndex];
|
||||
mSum += speed;
|
||||
mPreviousInputs[mIndex] = speed;
|
||||
if(++mIndex == mPreviousInputs.length) mIndex = 0;
|
||||
double dLength = mPreviousInputs.length;
|
||||
return (mSum + (dLength / 2d)) / dLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current amount of bytes downloaded.
|
||||
* @param bytes the new amount of bytes downloaded
|
||||
* @return the current download speed in bytes per second
|
||||
*/
|
||||
public double feed(long bytes) {
|
||||
long millis = System.currentTimeMillis();
|
||||
long deltaBytes = bytes - mLastBytes;
|
||||
long deltaMillis = millis - mLastMillis;
|
||||
mLastBytes = bytes;
|
||||
mLastMillis = millis;
|
||||
double speed = (double)deltaBytes / ((double)deltaMillis / 1000d);
|
||||
return addToAverage(speed);
|
||||
}
|
||||
}
|
||||
@@ -155,6 +155,23 @@ public class DownloadUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content length for a given URL.
|
||||
* @param url the URL to get the length for
|
||||
* @return the length in bytes or -1 if not available
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public static long getContentLength(String url) throws IOException {
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection();
|
||||
urlConnection.setRequestMethod("HEAD");
|
||||
urlConnection.setDoInput(false);
|
||||
urlConnection.setDoOutput(false);
|
||||
urlConnection.connect();
|
||||
int responseCode = urlConnection.getResponseCode();
|
||||
if(responseCode >= 200 && responseCode <= 299) return urlConnection.getContentLength();
|
||||
return -1;
|
||||
}
|
||||
|
||||
public interface ParseCallback<T> {
|
||||
T process(String input) throws ParseException;
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public class JREUtils {
|
||||
envMap.put("LD_LIBRARY_PATH", LD_LIBRARY_PATH);
|
||||
envMap.put("PATH", jreHome + "/bin:" + Os.getenv("PATH"));
|
||||
if(FFmpegPlugin.isAvailable) {
|
||||
envMap.put("PATH", FFmpegPlugin.libraryPath+":"+envMap.get("PATH"));
|
||||
envMap.put("POJAV_FFMPEG_PATH", FFmpegPlugin.executablePath);
|
||||
}
|
||||
|
||||
if(LOCAL_RENDERER != null) {
|
||||
@@ -368,7 +368,8 @@ public class JREUtils {
|
||||
|
||||
"-Dnet.minecraft.clientmodname=" + Tools.APP_NAME,
|
||||
"-Dfml.earlyprogresswindow=false", //Forge 1.14+ workaround
|
||||
"-Dloader.disable_forked_guis=true"
|
||||
"-Dloader.disable_forked_guis=true",
|
||||
"-Djdk.lang.Process.launchMechanism=FORK" // Default is POSIX_SPAWN which requires starting jspawnhelper, which doesn't work on Android
|
||||
));
|
||||
if(LauncherPreferences.PREF_ARC_CAPES) {
|
||||
overridableArguments.add("-javaagent:"+new File(Tools.DIR_DATA,"arc_dns_injector/arc_dns_injector.jar").getAbsolutePath()+"=23.95.137.176");
|
||||
|
||||
@@ -45,6 +45,8 @@ LOCAL_SRC_FILES := \
|
||||
jre_launcher.c \
|
||||
utils.c \
|
||||
stdio_is.c \
|
||||
java_exec_hooks.c \
|
||||
lwjgl_dlopen_hook.c \
|
||||
driver_helper/nsbypass.c
|
||||
|
||||
ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
|
||||
|
||||
@@ -258,14 +258,18 @@ EXTERNAL_API void* pojavCreateContext(void* contextSrc) {
|
||||
return br_init_context((basic_render_window_t*)contextSrc);
|
||||
}
|
||||
|
||||
EXTERNAL_API JNIEXPORT jlong JNICALL
|
||||
Java_org_lwjgl_vulkan_VK_getVulkanDriverHandle(ABI_COMPAT JNIEnv *env, ABI_COMPAT jclass thiz) {
|
||||
printf("EGLBridge: LWJGL-side Vulkan loader requested the Vulkan handle\n");
|
||||
// The code below still uses the env var because
|
||||
void* maybe_load_vulkan() {
|
||||
// We use the env var because
|
||||
// 1. it's easier to do that
|
||||
// 2. it won't break if something will try to load vulkan and osmesa simultaneously
|
||||
if(getenv("VULKAN_PTR") == NULL) load_vulkan();
|
||||
return strtoul(getenv("VULKAN_PTR"), NULL, 0x10);
|
||||
return (void*) strtoul(getenv("VULKAN_PTR"), NULL, 0x10);
|
||||
}
|
||||
|
||||
EXTERNAL_API JNIEXPORT jlong JNICALL
|
||||
Java_org_lwjgl_vulkan_VK_getVulkanDriverHandle(ABI_COMPAT JNIEnv *env, ABI_COMPAT jclass thiz) {
|
||||
printf("EGLBridge: LWJGL-side Vulkan loader requested the Vulkan handle\n");
|
||||
return (jlong) maybe_load_vulkan();
|
||||
}
|
||||
|
||||
EXTERNAL_API void pojavSwapInterval(int interval) {
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#define EVENT_TYPE_MOUSE_BUTTON 1006
|
||||
#define EVENT_TYPE_SCROLL 1007
|
||||
|
||||
jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
||||
|
||||
static void registerFunctions(JNIEnv *env);
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
@@ -59,7 +57,7 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
|
||||
jobject mouseDownBufferJ = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetStaticObjectField(pojav_environ->runtimeJNIEnvPtr_JRE, pojav_environ->vmGlfwClass, field_mouseDownBuffer);
|
||||
pojav_environ->mouseDownBuffer = (*pojav_environ->runtimeJNIEnvPtr_JRE)->GetDirectBufferAddress(pojav_environ->runtimeJNIEnvPtr_JRE, mouseDownBufferJ);
|
||||
hookExec();
|
||||
installLinkerBugMitigation();
|
||||
installLwjglDlopenHook();
|
||||
installEMUIIteratorMititgation();
|
||||
}
|
||||
|
||||
@@ -230,82 +228,6 @@ void sendData(int type, int i1, int i2, int i3, int i4) {
|
||||
atomic_fetch_add_explicit(&pojav_environ->eventCounter, 1, memory_order_acquire);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooked version of java.lang.UNIXProcess.forkAndExec()
|
||||
* which is used to handle the "open" command.
|
||||
*/
|
||||
jint
|
||||
hooked_ProcessImpl_forkAndExec(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream) {
|
||||
char *pProg = (char *)((*env)->GetByteArrayElements(env, prog, NULL));
|
||||
|
||||
// Here we only handle the "xdg-open" command
|
||||
if (strcmp(basename(pProg), "xdg-open") != 0) {
|
||||
(*env)->ReleaseByteArrayElements(env, prog, (jbyte *)pProg, 0);
|
||||
return orig_ProcessImpl_forkAndExec(env, process, mode, helperpath, prog, argBlock, argc, envBlock, envc, dir, std_fds, redirectErrorStream);
|
||||
}
|
||||
(*env)->ReleaseByteArrayElements(env, prog, (jbyte *)pProg, 0);
|
||||
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(env, NULL, /* CLIPBOARD_OPEN */ 2002, argBlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hookExec() {
|
||||
jclass cls;
|
||||
orig_ProcessImpl_forkAndExec = dlsym(RTLD_DEFAULT, "Java_java_lang_UNIXProcess_forkAndExec");
|
||||
if (!orig_ProcessImpl_forkAndExec) {
|
||||
orig_ProcessImpl_forkAndExec = dlsym(RTLD_DEFAULT, "Java_java_lang_ProcessImpl_forkAndExec");
|
||||
cls = (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "java/lang/ProcessImpl");
|
||||
} else {
|
||||
cls = (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "java/lang/UNIXProcess");
|
||||
}
|
||||
JNINativeMethod methods[] = {
|
||||
{"forkAndExec", "(I[B[B[BI[BI[B[IZ)I", (void *)&hooked_ProcessImpl_forkAndExec}
|
||||
};
|
||||
(*pojav_environ->runtimeJNIEnvPtr_JRE)->RegisterNatives(pojav_environ->runtimeJNIEnvPtr_JRE, cls, methods, 1);
|
||||
printf("Registered forkAndExec\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Basically a verbatim implementation of ndlopen(), found at
|
||||
* https://github.com/PojavLauncherTeam/lwjgl3/blob/3.3.1/modules/lwjgl/core/src/generated/c/linux/org_lwjgl_system_linux_DynamicLinkLoader.c#L11
|
||||
* The idea is that since, on Android 10 and earlier, the linker doesn't really do namespace nesting.
|
||||
* It is not a problem as most of the libraries are in the launcher path, but when you try to run
|
||||
* VulkanMod which loads shaderc outside of the default jni libs directory through this method,
|
||||
* it can't load it because the path is not in the allowed paths for the anonymous namesapce.
|
||||
* This method fixes the issue by being in libpojavexec, and thus being in the classloader namespace
|
||||
*/
|
||||
jlong ndlopen_bugfix(__attribute__((unused)) JNIEnv *env,
|
||||
__attribute__((unused)) jclass class,
|
||||
jlong filename_ptr,
|
||||
jint jmode) {
|
||||
const char* filename = (const char*) filename_ptr;
|
||||
int mode = (int)jmode;
|
||||
return (jlong) dlopen(filename, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the linker bug mitigation for Android 10 and lower. Fixes VulkanMod crashing on these
|
||||
* Android versions due to missing namespace nesting.
|
||||
*/
|
||||
void installLinkerBugMitigation() {
|
||||
if(android_get_device_api_level() >= 30) return;
|
||||
__android_log_print(ANDROID_LOG_INFO, "Api29LinkerFix", "API < 30 detected, installing linker bug mitigation");
|
||||
JNIEnv* env = pojav_environ->runtimeJNIEnvPtr_JRE;
|
||||
jclass dynamicLinkLoader = (*env)->FindClass(env, "org/lwjgl/system/linux/DynamicLinkLoader");
|
||||
if(dynamicLinkLoader == NULL) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Api29LinkerFix", "Failed to find the target class");
|
||||
(*env)->ExceptionClear(env);
|
||||
return;
|
||||
}
|
||||
JNINativeMethod ndlopenMethod[] = {
|
||||
{"ndlopen", "(JI)J", &ndlopen_bugfix}
|
||||
};
|
||||
if((*env)->RegisterNatives(env, dynamicLinkLoader, ndlopenMethod, 1) != 0) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "Api29LinkerFix", "Failed to register the bugfix method");
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is meant as a substitute for SharedLibraryUtil.getLibraryPath() that just returns 0
|
||||
* (thus making the parent Java function return null). This is done to avoid using the LWJGL's default function,
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// Created by maks on 05.01.2025.
|
||||
//
|
||||
|
||||
#include <jni.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <environ/environ.h>
|
||||
#include <android/log.h>
|
||||
#include <utils.h>
|
||||
|
||||
static jint (*orig_ProcessImpl_forkAndExec)(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream);
|
||||
|
||||
// Turn a C-style string into a Java byte array
|
||||
static jbyteArray stringToBytes(JNIEnv *env, const char* string) {
|
||||
const jsize string_data_len = (jsize)(strlen(string) + 1);
|
||||
jbyteArray result = (*env)->NewByteArray(env, (jsize)string_data_len);
|
||||
(*env)->SetByteArrayRegion(env, result, 0, (jsize)string_data_len, (const jbyte*) string);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Replace the env block with the one that has the desired LD_LIBRARY_PATH/PATH.
|
||||
// (Due to my laziness this ignores the current contents of the block)
|
||||
static void replaceLibPathInEnvBlock(JNIEnv *env, jbyteArray* envBlock, jint* envc, const char* directory) {
|
||||
static bool env_block_replacement_warning = false;
|
||||
if(*envBlock != NULL && !env_block_replacement_warning) {
|
||||
printf("exec_hooks WARN: replaceLibPathInEnvBlock does not preserve original env. Please notify PojavLauncherTeam if you need that feature\n");
|
||||
env_block_replacement_warning = true;
|
||||
}
|
||||
char envStr[1024];
|
||||
jsize new_envl = snprintf(envStr, sizeof(envStr) / sizeof(char), "LD_LIBRARY_PATH=%s%cPATH=%s", directory, 0 ,directory) + 1;
|
||||
jbyteArray newBlock = (*env)->NewByteArray(env, new_envl);
|
||||
(*env)->SetByteArrayRegion(env, newBlock, 0, new_envl, (jbyte*) envStr);
|
||||
*envBlock = newBlock;
|
||||
*envc = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooked version of java.lang.UNIXProcess.forkAndExec()
|
||||
* which is used to handle the "open" command and "ffmpeg" invocations
|
||||
*/
|
||||
static jint hooked_ProcessImpl_forkAndExec(JNIEnv *env, jobject process, jint mode, jbyteArray helperpath, jbyteArray prog, jbyteArray argBlock, jint argc, jbyteArray envBlock, jint envc, jbyteArray dir, jintArray std_fds, jboolean redirectErrorStream) {
|
||||
const char *pProg = (char *)((*env)->GetByteArrayElements(env, prog, NULL));
|
||||
const char* pProgBaseName = basename(pProg);
|
||||
const size_t basename_len = strlen(pProgBaseName);
|
||||
char prog_basename[basename_len];
|
||||
memcpy(&prog_basename, pProgBaseName, basename_len + 1);
|
||||
(*env)->ReleaseByteArrayElements(env, prog, (jbyte *)pProg, 0);
|
||||
|
||||
if(strcmp(prog_basename, "xdg-open") == 0) {
|
||||
// When invoking xdg-open, send the open URL into Android
|
||||
Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(env, NULL, CLIPBOARD_OPEN, argBlock);
|
||||
return 0;
|
||||
}else if(strcmp(prog_basename, "ffmpeg") == 0) {
|
||||
// When invoking ffmpeg, always replace the program path with the path to ffmpeg from the plugin.
|
||||
// This allows us to replace the executable name, which is needed because android doesn't allow
|
||||
// us to put files that don't start with "lib" and end with ".so" into folders that we can execute
|
||||
// from
|
||||
|
||||
// Also add LD_LIBRARY_PATH and PATH for the lib in order to override the ones from the launcher, since
|
||||
// they may interfere with ffmpeg dependencies.
|
||||
const char* ffmpeg_path = getenv("POJAV_FFMPEG_PATH");
|
||||
if(ffmpeg_path != NULL) {
|
||||
replaceLibPathInEnvBlock(env, &envBlock, &envc, dirname(ffmpeg_path));
|
||||
prog = stringToBytes(env, ffmpeg_path);
|
||||
}
|
||||
}
|
||||
return orig_ProcessImpl_forkAndExec(env, process, mode, helperpath, prog, argBlock, argc, envBlock, envc, dir, std_fds, redirectErrorStream);
|
||||
}
|
||||
|
||||
// Hook the forkAndExec method in the Java runtime for custom executable overriding.
|
||||
void hookExec() {
|
||||
jclass cls;
|
||||
orig_ProcessImpl_forkAndExec = dlsym(RTLD_DEFAULT, "Java_java_lang_UNIXProcess_forkAndExec");
|
||||
if (!orig_ProcessImpl_forkAndExec) {
|
||||
orig_ProcessImpl_forkAndExec = dlsym(RTLD_DEFAULT, "Java_java_lang_ProcessImpl_forkAndExec");
|
||||
cls = (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "java/lang/ProcessImpl");
|
||||
} else {
|
||||
cls = (*pojav_environ->runtimeJNIEnvPtr_JRE)->FindClass(pojav_environ->runtimeJNIEnvPtr_JRE, "java/lang/UNIXProcess");
|
||||
}
|
||||
JNINativeMethod methods[] = {
|
||||
{"forkAndExec", "(I[B[B[BI[BI[B[IZ)I", (void *)&hooked_ProcessImpl_forkAndExec}
|
||||
};
|
||||
(*pojav_environ->runtimeJNIEnvPtr_JRE)->RegisterNatives(pojav_environ->runtimeJNIEnvPtr_JRE, cls, methods, 1);
|
||||
printf("Registered forkAndExec\n");
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Created by maks on 06.01.2025.
|
||||
//
|
||||
|
||||
#include <android/api-level.h>
|
||||
#include <android/log.h>
|
||||
#include <jni.h>
|
||||
|
||||
#include <environ/environ.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern void* maybe_load_vulkan();
|
||||
|
||||
/**
|
||||
* Basically a verbatim implementation of ndlopen(), found at
|
||||
* https://github.com/PojavLauncherTeam/lwjgl3/blob/3.3.1/modules/lwjgl/core/src/generated/c/linux/org_lwjgl_system_linux_DynamicLinkLoader.c#L11
|
||||
* but with our own additions for stuff like vulkanmod.
|
||||
*/
|
||||
static jlong ndlopen_bugfix(__attribute__((unused)) JNIEnv *env,
|
||||
__attribute__((unused)) jclass class,
|
||||
jlong filename_ptr,
|
||||
jint jmode) {
|
||||
const char* filename = (const char*) filename_ptr;
|
||||
|
||||
// Oveeride vulkan loading to let us load vulkan ourselves
|
||||
if(strstr(filename, "libvulkan.so") == filename) {
|
||||
printf("LWJGL linkerhook: replacing load for libvulkan.so with custom driver\n");
|
||||
return (jlong) maybe_load_vulkan();
|
||||
}
|
||||
|
||||
// This hook also serves the task of mitigating a bug: the idea is that since, on Android 10 and
|
||||
// earlier, the linker doesn't really do namespace nesting.
|
||||
// It is not a problem as most of the libraries are in the launcher path, but when you try to run
|
||||
// VulkanMod which loads shaderc outside of the default jni libs directory through this method,
|
||||
// it can't load it because the path is not in the allowed paths for the anonymous namesapce.
|
||||
// This method fixes the issue by being in libpojavexec, and thus being in the classloader namespace
|
||||
|
||||
int mode = (int)jmode;
|
||||
return (jlong) dlopen(filename, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the LWJGL dlopen hook. This allows us to mitigate linker bugs and add custom library overrides.
|
||||
*/
|
||||
void installLwjglDlopenHook() {
|
||||
__android_log_print(ANDROID_LOG_INFO, "LwjglLinkerHook", "Installing LWJGL dlopen() hook");
|
||||
JNIEnv* env = pojav_environ->runtimeJNIEnvPtr_JRE;
|
||||
jclass dynamicLinkLoader = (*env)->FindClass(env, "org/lwjgl/system/linux/DynamicLinkLoader");
|
||||
if(dynamicLinkLoader == NULL) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "LwjglLinkerHook", "Failed to find the target class");
|
||||
(*env)->ExceptionClear(env);
|
||||
return;
|
||||
}
|
||||
JNINativeMethod ndlopenMethod[] = {
|
||||
{"ndlopen", "(JI)J", &ndlopen_bugfix}
|
||||
};
|
||||
if((*env)->RegisterNatives(env, dynamicLinkLoader, ndlopenMethod, 1) != 0) {
|
||||
__android_log_print(ANDROID_LOG_ERROR, "LwjglLinkerHook", "Failed to register the hooked method");
|
||||
(*env)->ExceptionClear(env);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
#define CLIPBOARD_COPY 2000
|
||||
#define CLIPBOARD_PASTE 2001
|
||||
#define CLIPBOARD_OPEN 2002
|
||||
|
||||
char** convert_to_char_array(JNIEnv *env, jobjectArray jstringArray);
|
||||
jobjectArray convert_from_char_array(JNIEnv *env, char **charArray, int num_rows);
|
||||
@@ -10,7 +12,7 @@ void free_char_array(JNIEnv *env, jobjectArray jstringArray, const char **charAr
|
||||
jstring convertStringJVM(JNIEnv* srcEnv, JNIEnv* dstEnv, jstring srcStr);
|
||||
|
||||
void hookExec();
|
||||
void installLinkerBugMitigation();
|
||||
void installLwjglDlopenHook();
|
||||
void installEMUIIteratorMititgation();
|
||||
JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNIEnv* env, jclass clazz, jint action, jbyteArray copySrc);
|
||||
|
||||
@@ -374,7 +374,8 @@
|
||||
<string name="exception_failed_to_unpack_jre17">Failed to install JRE 17</string>
|
||||
<string name="newdl_starting">Reading game metadata…</string>
|
||||
<string name="newdl_downloading_metadata">Downloading game metadata (%s)</string>
|
||||
<string name="newdl_downloading_game_files">Downloading game files… (%d/%d, %.2f MB)</string>
|
||||
<string name="newdl_downloading_game_files">Downloading game… (%d/%d, %.2f MB/s)</string>
|
||||
<string name="newdl_downloading_game_files_size">Downloading game… (%.2f/%.2f MB, %.2f MB/s)</string>
|
||||
<string name="cropper_title">Select image region</string>
|
||||
<string name="cropper_lock_vertical">V. lock</string>
|
||||
<string name="cropper_lock_horizontal">H. lock</string>
|
||||
|
||||
Reference in new issue
Block a user