diff --git a/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java b/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java index dde2f39b..a3d75503 100644 --- a/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java +++ b/jre_lwjgl3glfw/src/main/java/org/lwjgl/glfw/GLFW.java @@ -624,9 +624,7 @@ private Functions() {} SetWindowHint = apiGetFunctionAddress(GLFW, "pojavSetWindowHint"), SwapBuffers = apiGetFunctionAddress(GLFW, "pojavSwapBuffers"), SwapInterval = apiGetFunctionAddress(GLFW, "pojavSwapInterval"), - PumpEvents = apiGetFunctionAddress(GLFW, "pojavPumpEvents"), - StopPumping = apiGetFunctionAddress(GLFW, "pojavStopPumping"), - StartPumping = apiGetFunctionAddress(GLFW, "pojavStartPumping"); + PumpEvents = apiGetFunctionAddress(GLFW, "pojavPumpEvents"); } public static SharedLibrary getLibrary() { @@ -1083,9 +1081,7 @@ public static void glfwPollEvents() { // Prevent these with this code. if(mGLFWInputPumping) return; mGLFWInputPumping = true; - callV(Functions.StartPumping); for (Long ptr : mGLFWWindowMap.keySet()) callJV(ptr, Functions.PumpEvents); - callV(Functions.StopPumping); mGLFWInputPumping = false; } diff --git a/src/main/java/pojlib/API.java b/src/main/java/pojlib/API.java index 8297c7db..8ef3c100 100644 --- a/src/main/java/pojlib/API.java +++ b/src/main/java/pojlib/API.java @@ -199,7 +199,7 @@ public static void login(Activity activity) ConnectivityManager connManager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkCapabilities capabilities = connManager.getNetworkCapabilities(connManager.getActiveNetwork()); - boolean hasWifi = false; + boolean hasWifi = true; if(capabilities != null) { hasWifi = capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI); diff --git a/src/main/java/pojlib/InstanceHandler.java b/src/main/java/pojlib/InstanceHandler.java index 5fcddf9a..543e973d 100644 --- a/src/main/java/pojlib/InstanceHandler.java +++ b/src/main/java/pojlib/InstanceHandler.java @@ -181,7 +181,7 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns String clientClasspath = Installer.installClient(minecraftVersionInfo, gameDir); String minecraftClasspath = Installer.installLibraries(minecraftVersionInfo, gameDir); String modLoaderClasspath = Installer.installLibraries(finalModLoaderVersionInfo, gameDir); - String lwjgl = Installer.installLwjgl(activity); + String lwjgl = UnityPlayerActivity.installLWJGL(activity); instance.classpath = clientClasspath + File.pathSeparator + minecraftClasspath + File.pathSeparator + modLoaderClasspath + File.pathSeparator + lwjgl; diff --git a/src/main/java/pojlib/UnityPlayerActivity.java b/src/main/java/pojlib/UnityPlayerActivity.java index 7171f137..696d45ea 100644 --- a/src/main/java/pojlib/UnityPlayerActivity.java +++ b/src/main/java/pojlib/UnityPlayerActivity.java @@ -1,7 +1,6 @@ package pojlib; import static android.os.Build.VERSION.SDK_INT; - import static org.lwjgl.glfw.CallbackBridge.sendKeyPress; import static org.lwjgl.glfw.CallbackBridge.sendMouseButton; @@ -19,6 +18,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.Window; +import android.view.WindowManager; import com.unity3d.player.IUnityPlayerLifecycleEvents; import com.unity3d.player.UnityPlayer; @@ -26,6 +26,8 @@ import org.lwjgl.glfw.CallbackBridge; import java.io.File; +import java.io.IOException; +import java.util.Objects; import fr.spse.gamepad_remapper.RemapperManager; import fr.spse.gamepad_remapper.RemapperView; @@ -35,8 +37,8 @@ import pojlib.input.LwjglGlfwKeycode; import pojlib.input.gamepad.DefaultDataProvider; import pojlib.input.gamepad.Gamepad; +import pojlib.util.Constants; import pojlib.util.FileUtil; -import pojlib.util.Logger; public class UnityPlayerActivity extends ActivityGroup implements IUnityPlayerLifecycleEvents, GrabListener { @@ -79,9 +81,11 @@ protected String updateUnityCommandLineArguments(String cmdLine) mUnityPlayer = new UnityPlayer(this, this); setContentView(mUnityPlayer); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); mUnityPlayer.requestFocus(); - File zip = new File(this.getFilesDir() + "/runtimes/JRE-22"); - if (!zip.exists()) { + + File jre = new File(this.getFilesDir() + "/runtimes/JRE-22"); + if (!jre.exists()) { FileUtil.unzipArchiveFromAsset(this, "JRE-22.zip", this.getFilesDir() + "/runtimes/JRE-22"); } @@ -107,6 +111,21 @@ protected String updateUnityCommandLineArguments(String cmdLine) CallbackBridge.nativeSetUseInputStackQueue(true); } + public static String installLWJGL(Activity activity) throws IOException { + File lwjgl = new File(Constants.USER_HOME + "/lwjgl3/lwjgl-glfw-classes.jar"); + byte[] lwjglAsset = FileUtil.loadFromAssetToByte(activity, "lwjgl/lwjgl-glfw-classes.jar"); + + if (!lwjgl.exists()) { + Objects.requireNonNull(lwjgl.getParentFile()).mkdirs(); + FileUtil.write(lwjgl.getAbsolutePath(), lwjglAsset); + } else if (!FileUtil.matchingAssetFile(lwjgl, lwjglAsset)) { + Objects.requireNonNull(lwjgl.getParentFile()).mkdirs(); + FileUtil.write(lwjgl.getAbsolutePath(), lwjglAsset); + } + + return lwjgl.getAbsolutePath(); + } + public static DisplayMetrics getDisplayMetrics(Activity activity) { DisplayMetrics displayMetrics = new DisplayMetrics(); diff --git a/src/main/java/pojlib/account/LoginHelper.java b/src/main/java/pojlib/account/LoginHelper.java index bdcc2f28..ccf63e40 100644 --- a/src/main/java/pojlib/account/LoginHelper.java +++ b/src/main/java/pojlib/account/LoginHelper.java @@ -98,13 +98,14 @@ public static void beginLogin(Activity activity) { while(res.account() == null); try { API.currentAcc = MinecraftAccount.login(activity.getFilesDir() + "/accounts", new String[]{res.accessToken(), String.valueOf(res.expiresOnDate().getTime())}); - } catch (IOException | JSONException e) { - e.printStackTrace(); + } catch (IOException | JSONException | MSAException e) { + Logger.getInstance().appendToLog("Unable to load account! | " + e); } API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc); API.profileName = API.currentAcc.username; } catch (ExecutionException | InterruptedException e) { - throw new MSAException("MicrosoftLogin | Something went wrong! Couldn't reach the Microsoft Auth servers.", e); + Logger.getInstance().appendToLog("MicrosoftLogin | Something went wrong! Couldn't reach the Microsoft Auth servers."); + API.msaMessage = "MicrosoftLogin | Something went wrong! Couldn't reach the Microsoft Auth servers."; } }); diff --git a/src/main/java/pojlib/account/MinecraftAccount.java b/src/main/java/pojlib/account/MinecraftAccount.java index 8eeae831..5fc1db8f 100644 --- a/src/main/java/pojlib/account/MinecraftAccount.java +++ b/src/main/java/pojlib/account/MinecraftAccount.java @@ -15,6 +15,7 @@ import pojlib.util.Constants; import pojlib.util.GsonUtils; import pojlib.util.Logger; +import pojlib.util.MSAException; public class MinecraftAccount { public String accessToken; @@ -24,9 +25,9 @@ public class MinecraftAccount { public final String userType = "msa"; - public static MinecraftAccount login(String gameDir, String[] response) throws IOException, JSONException { + public static MinecraftAccount login(String gameDir, String[] response) throws MSAException, IOException, JSONException { String mcToken = Msa.acquireXBLToken(response[0]); - Msa instance = new Msa(false, mcToken); + Msa instance = new Msa(); MinecraftAccount account = instance.performLogin(mcToken); account.expiresIn = Long.parseLong(response[1]); @@ -54,7 +55,7 @@ public static MinecraftAccount load(String path, @Nullable String newToken, @Nul } GsonUtils.objectToJsonFile(path + "/account.json", acc); return acc; - } catch (IOException | JSONException e) { + } catch (IOException | JSONException | MSAException e) { Logger.getInstance().appendToLog("Unable to load account! | " + e); return null; } diff --git a/src/main/java/pojlib/account/Msa.java b/src/main/java/pojlib/account/Msa.java index e290f8f3..0a1547a4 100644 --- a/src/main/java/pojlib/account/Msa.java +++ b/src/main/java/pojlib/account/Msa.java @@ -32,9 +32,6 @@ public class Msa { - - private final boolean mIsRefresh; - private final String mAuthCode; private static final Map XSTS_ERRORS; static { XSTS_ERRORS = new ArrayMap<>(); @@ -46,26 +43,20 @@ public class Msa { } /* Fields used to fill the account */ - public String msRefreshToken; public static String mcName; public String mcToken; public static String mcUuid; public static boolean doesOwnGame; public long expiresAt; - public Msa(boolean isRefresh, String authCode){ - mIsRefresh = isRefresh; - mAuthCode = authCode; - } - /** Performs a full login, calling back listeners appropriately */ - public MinecraftAccount performLogin(String xblToken) { + public MinecraftAccount performLogin(String xblToken) throws MSAException { try { String[] xsts = acquireXsts(xblToken); if(xsts == null) { return null; } - String mcToken = acquireMinecraftToken(xsts[0], xsts[1]); + acquireMinecraftToken(xsts[0], xsts[1]); fetchOwnedItems(mcToken); checkMcProfile(mcToken); @@ -78,17 +69,17 @@ public MinecraftAccount performLogin(String xblToken) { acc.expiresIn = expiresAt; } else { Logger.getInstance().appendToLog("MicrosoftLogin | Unknown Error occurred."); - throw new MSAException("MicrosoftLogin | Unknown Error occurred.", null); + throw new MSAException("MicrosoftLogin | Unknown Error occurred."); } return acc; } catch (Exception e) { Logger.getInstance().appendToLog("MicrosoftLogin | Exception thrown during authentication " + e); - throw new MSAException("MicrosoftLogin | Exception thrown during authentication ", e); + throw new MSAException("MicrosoftLogin | Exception thrown during authentication "); } } - static String acquireXBLToken(String accessToken) throws IOException, JSONException { + static String acquireXBLToken(String accessToken) throws IOException, MSAException, JSONException { URL url = new URL(Constants.XBL_AUTH_URL); JSONObject data = new JSONObject(); @@ -118,7 +109,7 @@ static String acquireXBLToken(String accessToken) throws IOException, JSONExcept } /** @return [uhs, token]*/ - private String[] acquireXsts(String xblToken) throws IOException, JSONException { + private String[] acquireXsts(String xblToken) throws IOException, JSONException, MSAException { URL url = new URL(Constants.XSTS_AUTH_URL); JSONObject data = new JSONObject(); @@ -153,16 +144,16 @@ private String[] acquireXsts(String xblToken) throws IOException, JSONException String locale_id = XSTS_ERRORS.get(xerr); if(locale_id != null) { Logger.getInstance().appendToLog(responseContents); - throw new MSAException(responseContents, null); + throw new MSAException(responseContents); } // Logger.getInstance().appendToLog("Unknown error returned from Xbox Live\n" + responseContents); - throw new MSAException("Unknown error returned from Xbox Live", null); + throw new MSAException("Unknown error returned from Xbox Live"); } else{ throw getResponseThrowable(conn); } } - private String acquireMinecraftToken(String xblUhs, String xblXsts) throws IOException, JSONException { + private void acquireMinecraftToken(String xblUhs, String xblXsts) throws IOException, MSAException, JSONException { URL url = new URL(Constants.MC_LOGIN_URL); JSONObject data = new JSONObject(); @@ -178,17 +169,16 @@ private String acquireMinecraftToken(String xblUhs, String xblXsts) throws IOExc } if(conn.getResponseCode() >= 200 && conn.getResponseCode() < 300) { - expiresAt = System.currentTimeMillis() + 86400000; JSONObject jo = new JSONObject(FileUtil.read(conn.getInputStream())); conn.disconnect(); + expiresAt = System.currentTimeMillis() + (jo.getInt("expires_in") * 1000L); mcToken = jo.getString("access_token"); - return jo.getString("access_token"); }else{ throw getResponseThrowable(conn); } } - private void fetchOwnedItems(String mcAccessToken) throws IOException { + private void fetchOwnedItems(String mcAccessToken) throws MSAException, IOException { URL url = new URL(Constants.MC_STORE_URL); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); @@ -204,7 +194,7 @@ private void fetchOwnedItems(String mcAccessToken) throws IOException { } // Returns false for failure // - public static boolean checkMcProfile(String mcAccessToken) throws IOException, JSONException { + public static boolean checkMcProfile(String mcAccessToken) throws IOException, MSAException, JSONException { URL url = new URL(Constants.MC_PROFILE_URL); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); @@ -231,7 +221,7 @@ public static boolean checkMcProfile(String mcAccessToken) throws IOException, J } else { Logger.getInstance().appendToLog("MicrosoftLogin | It seems that this Microsoft Account does not own the game."); doesOwnGame = false; - throw new MSAException("It seems like this account does not have a Minecraft profile. If you have Xbox Game Pass, please log in on https://minecraft.net/ and set it up.", null); + throw new MSAException("It seems like this account does not have a Minecraft profile. If you have Xbox Game Pass, please log in on https://minecraft.net/ and set it up."); } } @@ -266,11 +256,11 @@ private static String convertToFormData(String... data) throws UnsupportedEncodi return builder.toString(); } - private static RuntimeException getResponseThrowable(HttpURLConnection conn) throws IOException { + private static MSAException getResponseThrowable(HttpURLConnection conn) throws IOException, MSAException { Logger.getInstance().appendToLog("MicrosoftLogin | Error code: " + conn.getResponseCode() + ": " + conn.getResponseMessage()); if(conn.getResponseCode() == 429) { - throw new MSAException("Too many requests, please try again later.", null); + throw new MSAException("Too many requests, please try again later."); } - throw new MSAException(conn.getResponseMessage(), null); + throw new MSAException(conn.getResponseMessage()); } } \ No newline at end of file diff --git a/src/main/java/pojlib/install/Installer.java b/src/main/java/pojlib/install/Installer.java index bdb39bd3..3efbc7c5 100644 --- a/src/main/java/pojlib/install/Installer.java +++ b/src/main/java/pojlib/install/Installer.java @@ -161,15 +161,6 @@ public AsyncDownload( Map.Entry entry, VersionInfo versionI } } - public static String installLwjgl(Activity activity) throws IOException { - File lwjgl = new File(Constants.USER_HOME + "/lwjgl3/lwjgl-glfw-classes.jar"); - if (!lwjgl.exists()) { - Objects.requireNonNull(lwjgl.getParentFile()).mkdirs(); - FileUtil.write(lwjgl.getAbsolutePath(), FileUtil.loadFromAssetToByte(activity, "lwjgl/lwjgl-glfw-classes.jar")); - } - return lwjgl.getAbsolutePath(); - } - //Used for mod libraries, vanilla is handled a different (tbh better) way private static String parseLibraryNameToPath(String libraryName) { String[] parts = libraryName.split(":"); diff --git a/src/main/java/pojlib/util/FileUtil.java b/src/main/java/pojlib/util/FileUtil.java index 553cbcb2..e149b77b 100644 --- a/src/main/java/pojlib/util/FileUtil.java +++ b/src/main/java/pojlib/util/FileUtil.java @@ -37,6 +37,11 @@ public static byte[] loadFromAssetToByte(Context ctx, String inFile) { return buffer; } + public static boolean matchingAssetFile(File sourceFile, byte[] assetFile) throws IOException { + byte[] sf = Files.readAllBytes(sourceFile.toPath()); + return sf == assetFile; + } + public static String read(String path) throws IOException { return read(Files.newInputStream(Paths.get(path))); } @@ -55,6 +60,9 @@ public static void write(String path, byte[] content) throws IOException { File outPath = new File(path); Objects.requireNonNull(outPath.getParentFile()).mkdirs(); + if(!outPath.exists()) { + outPath.createNewFile(); + } BufferedOutputStream fos = new BufferedOutputStream(Files.newOutputStream(outPath.toPath())); fos.write(content, 0, content.length); diff --git a/src/main/java/pojlib/util/MSAException.java b/src/main/java/pojlib/util/MSAException.java index c671bfe1..5b6e1edb 100644 --- a/src/main/java/pojlib/util/MSAException.java +++ b/src/main/java/pojlib/util/MSAException.java @@ -1,11 +1,9 @@ package pojlib.util; -import androidx.annotation.Nullable; import pojlib.API; -public class MSAException extends RuntimeException { - public MSAException(String msaMessage, @Nullable Throwable cause) { - super(msaMessage, cause); +public class MSAException extends Exception { + public MSAException(String msaMessage) { API.msaMessage = msaMessage; } } diff --git a/src/main/java/pojlib/util/json/MinecraftInstances.java b/src/main/java/pojlib/util/json/MinecraftInstances.java index d4eea967..2b7260be 100644 --- a/src/main/java/pojlib/util/json/MinecraftInstances.java +++ b/src/main/java/pojlib/util/json/MinecraftInstances.java @@ -48,7 +48,7 @@ public static class Instance { public List generateLaunchArgs(MinecraftAccount account) { String[] mcArgs = {"--username", account.username, "--version", versionName, "--gameDir", gameDir, - "--assetsDir", assetsDir, "--assetIndex", assetIndex, "--uuid", account.uuid.replaceAll("-", ""), + "--assetsDir", assetsDir, "--assetIndex", assetIndex, "--uuid", account.uuid, "--accessToken", account.accessToken, "--userType", account.userType, "--versionType", "release"}; List allArgs = new ArrayList<>(Arrays.asList("-cp", classpath)); diff --git a/src/main/jniLibs/arm64-v8a/libtinywrapper.so b/src/main/jniLibs/arm64-v8a/libtinywrapper.so index d64c375b..354918aa 100644 --- a/src/main/jniLibs/arm64-v8a/libtinywrapper.so +++ b/src/main/jniLibs/arm64-v8a/libtinywrapper.so @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bcc6ef3ae7e5fe3c8e307d276c001c9f32e64d83fe5d64578c7531f1c914998e -size 11628208 +oid sha256:56b794b41f3efa18b948739c12ac3fff9ee69be60d324e5b6c776183b2837fff +size 11688344