Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ local.properties
app_pojavlauncher/.cxx/
.vs/
/curseforge_key.txt
/app_pojavlauncher/libs/ltw-release.aar
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public boolean dispatchGenericMotionEvent(MotionEvent event) {
CallbackBridge.sendCursorPos(CallbackBridge.mouseX, CallbackBridge.mouseY);
return true;
case MotionEvent.ACTION_SCROLL:
CallbackBridge.sendScroll((double) event.getAxisValue(MotionEvent.AXIS_HSCROLL), (double) event.getAxisValue(MotionEvent.AXIS_VSCROLL));
CallbackBridge.sendScroll(event.getAxisValue(MotionEvent.AXIS_HSCROLL), event.getAxisValue(MotionEvent.AXIS_VSCROLL));
return true;
case MotionEvent.ACTION_BUTTON_PRESS:
return sendMouseButtonUnconverted(event.getActionButton(),true);
Expand Down Expand Up @@ -338,8 +338,14 @@ public void refreshSize(boolean immediate) {
// Use the width and height of the View instead of display dimensions to avoid
// getting squiched/stretched due to inconsistencies between the layout and
// screen dimensions.
windowWidth = Tools.getDisplayFriendlyRes(getWidth(), LauncherPreferences.PREF_SCALE_FACTOR);
windowHeight = Tools.getDisplayFriendlyRes(getHeight(), LauncherPreferences.PREF_SCALE_FACTOR);
int newWidth = Tools.getDisplayFriendlyRes(getWidth(), LauncherPreferences.PREF_SCALE_FACTOR);
int newHeight = Tools.getDisplayFriendlyRes(getHeight(), LauncherPreferences.PREF_SCALE_FACTOR);
if (newHeight < 1 || newWidth < 1) {
Log.e("MGLSurface", String.format("Impossible resolution : %dx%d", newWidth, newHeight));
return;
}
windowWidth = newWidth;
windowHeight = newHeight;
if(mSurface == null){
Log.w("MGLSurface", "Attempt to refresh size on null surface");
return;
Expand Down
55 changes: 6 additions & 49 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.net.Uri;
import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.GLES30;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
Expand All @@ -48,10 +43,6 @@
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

Expand All @@ -70,6 +61,7 @@
import net.kdt.pojavlaunch.utils.DateUtils;
import net.kdt.pojavlaunch.utils.DownloadUtils;
import net.kdt.pojavlaunch.utils.FileUtils;
import net.kdt.pojavlaunch.utils.GLInfoUtils;
import net.kdt.pojavlaunch.utils.JREUtils;
import net.kdt.pojavlaunch.utils.JSONUtils;
import net.kdt.pojavlaunch.utils.MCOptionUtils;
Expand Down Expand Up @@ -233,53 +225,16 @@ private static boolean hasSodium(File gameDir) {
* Initialize OpenGL and do checks to see if the GPU of the device is affected by the render
* distance issue.

* Currently only checks whether the user has an Adreno GPU capable of OpenGL ES 3
* and surfaceless rendering installed.
* Currently only checks whether the user has an Adreno GPU capable of OpenGL ES 3.

* This issue is caused by a very severe limit on the amount of GL buffer names that could be allocated
* by the Adreno properietary GLES driver.

* @return whether the GPU is affected by the Large Thin Wrapper render distance issue on vanilla
*/
private static boolean affectedByRenderDistanceIssue() {
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
if(eglDisplay == EGL14.EGL_NO_DISPLAY || !EGL14.eglInitialize(eglDisplay, null, 0, null, 0)) return false;
int[] egl_attributes = new int[] {
EGL14.EGL_BLUE_SIZE, 8,
EGL14.EGL_GREEN_SIZE, 8,
EGL14.EGL_RED_SIZE, 8,
EGL14.EGL_ALPHA_SIZE, 8,
EGL14.EGL_DEPTH_SIZE, 24,
EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
EGL14.EGL_NONE
};
EGLConfig[] config = new EGLConfig[1];
int[] num_configs = new int[]{0};
if(!EGL14.eglChooseConfig(eglDisplay, egl_attributes, 0, config, 0, 1, num_configs, 0) || num_configs[0] == 0) {
EGL14.eglTerminate(eglDisplay);
Log.e("CheckVendor", "Failed to choose an EGL config");
return false;
}
int[] egl_context_attributes = new int[] { EGL14.EGL_CONTEXT_CLIENT_VERSION, 3, EGL14.EGL_NONE };
EGLContext context = EGL14.eglCreateContext(eglDisplay, config[0], EGL14.EGL_NO_CONTEXT, egl_context_attributes, 0);
if(context == EGL14.EGL_NO_CONTEXT) {
Log.e("CheckVendor", "Failed to create a context");
EGL14.eglTerminate(eglDisplay);
return false;
}
if(!EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, context)) {
Log.e("CheckVendor", "Failed to make context current");
EGL14.eglDestroyContext(eglDisplay, context);
EGL14.eglTerminate(eglDisplay);
}
boolean is_adreno = GLES30.glGetString(GLES30.GL_VENDOR).equals("Qualcomm") &&
GLES30.glGetString(GLES30.GL_RENDERER).contains("Adreno");
Log.e("CheckVendor", "Running Adreno graphics: "+is_adreno);
EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
EGL14.eglDestroyContext(eglDisplay, context);
EGL14.eglTerminate(eglDisplay);
return is_adreno;
GLInfoUtils.GLInfo info = GLInfoUtils.getGlInfo();
return info.isAdreno() && info.glesMajorVersion >= 3;
}

private static boolean checkRenderDistance(File gamedir) {
Expand Down Expand Up @@ -1071,6 +1026,8 @@ public static void printLauncherInfo(String gameVersion, String javaArguments) {
Logger.appendToLog("Info: API version: " + SDK_INT);
Logger.appendToLog("Info: Selected Minecraft version: " + gameVersion);
Logger.appendToLog("Info: Custom Java arguments: \"" + javaArguments + "\"");
GLInfoUtils.GLInfo info = GLInfoUtils.getGlInfo();
Logger.appendToLog("Info: Graphics device: "+info.vendor+ " "+info.renderer+" (OpenGL ES "+info.glesMajorVersion+")");
}

public interface DownloaderFeedback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ public static long getContentLengthMirrored(int downloadClass, String urlInput)
}
}

/**
* Download a file as a string from the current mirror. If the file does not exist on the mirror
* or the mirror returns an invalid string, request the file 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 contents of the downloaded file as a String.
*/
public static String downloadStringMirrored(int downloadClass, String urlInput) throws IOException{
String resultString = null;
try {
resultString = DownloadUtils.downloadString(getMirrorMapping(downloadClass,urlInput));
}catch (FileNotFoundException e) {
Log.w("DownloadMirror", "Failed to download string from mirror", e);
}
if(Tools.isValidString(resultString)) {
return resultString;
}else {
Log.w("DownloadMirror", "Downloaded string is invalid, falling back to default");
}
return DownloadUtils.downloadString(urlInput);
}

/**
* Check if the current download source is a mirror and not an official source.
* @return true if the source is a mirror, false otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ public class ModpackInstaller {
public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) throws IOException {
String versionUrl = modDetail.versionUrls[selectedVersion];
String versionHash = modDetail.versionHashes[selectedVersion];
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
String modpackName = (modDetail.title.toLowerCase(Locale.ROOT) + " " + modDetail.versionNames[selectedVersion])
.trim().replaceAll("[\\\\/:*?\"<>| \\t\\n]", "_" );
if (versionHash != null) {
modpackName += "_" + versionHash;
}
if (modpackName.length() > 255){
modpackName = modpackName.substring(0,255);
}

// Build a new minecraft instance, folder first

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class CustomSeekBarPreference extends SeekBarPreference {
private int mMin;
/** The textview associated by default to the preference */
private TextView mTextView;
/** Seekbar increment in case the max gets set */
private final int mIncrement;


@SuppressLint("PrivateResource")
Expand All @@ -31,6 +33,7 @@ public CustomSeekBarPreference(Context context, AttributeSet attrs, int defStyle
try (TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SeekBarPreference, defStyleAttr, defStyleRes)) {
mMin = a.getInt(R.styleable.SeekBarPreference_min, 0);
mIncrement = a.getInt(R.styleable.SeekBarPreference_seekBarIncrement, 0);
}
}

Expand Down Expand Up @@ -111,7 +114,12 @@ public void setSuffix(String suffix) {
*/
public void setRange(int min, int max){
setMin(min);
setMax(max);
setMaxKeepIncrement(max);
}

public void setMaxKeepIncrement(int max) {
super.setMax(max);
setSeekBarIncrement(mIncrement);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ public static void loadPreferences(Context ctx) {
*/
private static int findBestRAMAllocation(Context ctx){
int deviceRam = Tools.getTotalDeviceMemory(ctx);
if (deviceRam < 1024) return 300;
if (deviceRam < 1536) return 450;
if (deviceRam < 2048) return 600;
if (deviceRam < 1024) return 296;
if (deviceRam < 1536) return 448;
if (deviceRam < 2048) return 656;
// Limit the max for 32 bits devices more harshly
if (is32BitsDevice()) return 700;
if (is32BitsDevice()) return 696;

if (deviceRam < 3064) return 936;
if (deviceRam < 4096) return 1148;
if (deviceRam < 4096) return 1144;
if (deviceRam < 6144) return 1536;
return 2048; //Default RAM allocation for 64 bits
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onCreatePreferences(Bundle b, String str) {
if(is32BitsDevice() || deviceRam < 2048) maxRAM = Math.min(1024, deviceRam);
else maxRAM = deviceRam - (deviceRam < 3064 ? 800 : 1024); //To have a minimum for the device to breathe

memorySeekbar.setMax(maxRAM);
memorySeekbar.setMaxKeepIncrement(maxRAM);
memorySeekbar.setValue(ramAllocation);
memorySeekbar.setSuffix(" MB");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
package net.kdt.pojavlaunch.prefs.screens;

import android.content.pm.PackageManager;
import android.os.Bundle;

import androidx.preference.Preference;

import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.utils.GLInfoUtils;

public class LauncherPreferenceMiscellaneousFragment extends LauncherPreferenceFragment {
@Override
public void onCreatePreferences(Bundle b, String str) {
addPreferencesFromResource(R.xml.pref_misc);
Preference driverPreference = requirePreference("zinkPreferSystemDriver");
if(!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) {
driverPreference.setVisible(false);
}
PackageManager packageManager = driverPreference.getContext().getPackageManager();
boolean supportsTurnip = Tools.checkVulkanSupport(packageManager) && GLInfoUtils.getGlInfo().isAdreno();
driverPreference.setVisible(supportsTurnip);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,40 @@ private final class DownloaderTask implements Runnable, Tools.DownloaderFeedback
this.mSkipIfFailed = skipIfFailed;
}

private String downloadSha1() throws IOException {
String downloadedHash = DownloadMirror.downloadStringMirrored(
mDownloadClass, mTargetUrl + ".sha1"
);
if(!Tools.isValidString(downloadedHash)) return null;
// Ensure that we don't have leading/trailing whitespaces before checking hash length
downloadedHash = downloadedHash.trim();
// SHA1 is made up of 20 bytes, which means 40 hexadecimal digits, which means 40 chars
if(downloadedHash.length() != 40) return null;
return downloadedHash;
}

/*
* Maven repositories usually have the hash of a library near it, like:
* .../libraryName-1.0.jar
* .../libraryName.1.0.jar.sha1
* Since Minecraft libraries are stored in maven repositories, try to use
* this when downloading libraries without hashes in the json.
*/
private void tryGetLibrarySha1() {
String resultHash = null;
try {
resultHash = downloadSha1();
// The hash is a 40-byte download.
mInternetUsageCounter.getAndAdd(40);
}catch (IOException e) {
Log.i("MinecraftDownloader", "Failed to download hash", e);
}
if(resultHash != null) {
Log.i("MinecraftDownloader", "Got hash: "+resultHash+ " for "+FileUtils.getFileName(mTargetUrl));
mTargetSha1 = resultHash;
}
}

@Override
public void run() {
try {
Expand All @@ -405,6 +439,10 @@ public void run() {
}

private void runCatching() throws Exception {
if(mDownloadClass == DownloadMirror.DOWNLOAD_CLASS_LIBRARIES && !Tools.isValidString(mTargetSha1)) {
// If we're downloading a library, try to get sha1 since it might be available as a file
tryGetLibrarySha1();
}
if(Tools.isValidString(mTargetSha1)) {
verifyFileSha1();
}else {
Expand Down
Loading