From 0b643476f48438e3bf1d4ce27a23b4df21d8acbe Mon Sep 17 00:00:00 2001 From: Adam Tunnic Date: Wed, 15 Dec 2021 13:14:48 -0500 Subject: [PATCH] WIP Demo mode stuff Sign in with a Microsoft account that doesn't own the game, demo_user will be made. This is very much WIP as my iPhone 7 doesn't feel like launching PojavLauncher. --- .../main/java/net/kdt/pojavlaunch/Tools.java | 17 +++++++++++++++ .../microsoft/MicrosoftAuthTask.java | 7 +++++++ .../authenticator/microsoft/Msa.java | 9 +++++++- Natives/CMakeLists.txt | 2 ++ Natives/LauncherPreferences.m | 1 + Natives/LoginViewController.m | 21 ++++++++++++------- 6 files changed, 49 insertions(+), 8 deletions(-) diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java index e0bc482e..cfedfddc 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -107,6 +107,23 @@ public final class Tools javaArgList.add(versionInfo.mainClass); javaArgList.addAll(Arrays.asList(launchArgs)); + if(profile.username.equals("demo_user")) { + File demoHome = new File(DIR_GAME_HOME + "/demo"); + if(demoHome.exists()) { + for (File demoStuff : demoHome.listFiles()) { demoStuff.delete(); } + } else { + demoHome.mkdirs(); + } + javaArgList.add("-Duser.home=" + DIR_GAME_HOME + "/demo"); + File demoDir = new File(DIR_GAME_NEW + "/demo"); + if(demoDir.exists()) { + for (File demoStuff : demoDir.listFiles()) { demoStuff.delete(); } + } else { + demoDir.mkdirs(); + } + javaArgList.add("-Duser.dir=" + DIR_GAME_NEW + "/demo"); + javaArgList.add("--demo"); + } // Debug /* diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/MicrosoftAuthTask.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/MicrosoftAuthTask.java index 046ccbc7..bf5bb7b6 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/MicrosoftAuthTask.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/MicrosoftAuthTask.java @@ -46,6 +46,13 @@ public class MicrosoftAuthTask { acc.profileId = msa.mcUuid; acc.isMicrosoft = true; acc.msaRefreshToken = msa.msRefreshToken; + } else if(msa.doesDemo) { + acc.clientToken = "0"; /* FIXME */ + acc.accessToken = "-1"; // Differentiate from local accounts + acc.username = "demo_user"; + acc.profileId = "25e00594-cf57-3f87-b3af-3f06591be252"; + acc.isMicrosoft = false; + acc.msaRefreshToken = "0"; } acc.save(); diff --git a/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/Msa.java b/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/Msa.java index e7b9c667..59609d08 100644 --- a/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/Msa.java +++ b/JavaApp/src/main/java/net/kdt/pojavlaunch/authenticator/microsoft/Msa.java @@ -38,6 +38,7 @@ public class Msa { public String mcToken; public String mcUuid; public boolean doesOwnGame; + public boolean doesDemo; public Msa(MicrosoftAuthTask task, boolean isRefresh, String authCode) throws IOException, JSONException { this.task = task; @@ -270,10 +271,16 @@ public class Msa { // Log.i("MicroAuth","Uuid Minecraft = " + uuidDashes); mcName=name; mcUuid=uuidDashes; - }else{ + } else if(conn.getResponseCode() == 404) { + // Demo mode stuff + doesOwnGame = false; + doesDemo = true; + } else { // Log.i("MicroAuth","It seems that this Microsoft Account does not own the game."); doesOwnGame = false; + doesDemo = false; throwResponseError(conn); + } } diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index dac0a2ff..e6c0acd6 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -75,6 +75,8 @@ target_link_libraries(PojavLauncher "-framework CoreGraphics" "-framework QuartzCore" "-framework UIKit" + "-framework SafariServices" + "-framework WebKit" ) set_target_properties(PojavLauncher PROPERTIES MACOSX_BUNDLE TRUE diff --git a/Natives/LauncherPreferences.m b/Natives/LauncherPreferences.m index ea000534..bc490a6c 100644 --- a/Natives/LauncherPreferences.m +++ b/Natives/LauncherPreferences.m @@ -43,6 +43,7 @@ void loadPreferences() { setDefaultValueForPref(@"local_warn", @YES); setDefaultValueForPref(@"mem_warn", @YES); setDefaultValueForPref(@"java_warn", @YES); + setDefaultValueForPref(@"demo_warn", @YES); setDefaultValueForPref(@"jb_warn", @YES); setDefaultValueForPref(@"customctrl_warn", @YES); setDefaultValueForPref(@"disable_gl4es_shaderconv", @NO); diff --git a/Natives/LoginViewController.m b/Natives/LoginViewController.m index 33470040..16746b85 100644 --- a/Natives/LoginViewController.m +++ b/Natives/LoginViewController.m @@ -58,7 +58,7 @@ if(getenv("POJAV_DETECTEDJB")) { if(![[NSFileManager defaultManager] fileExistsAtPath:@"/.procursus_strapped"] && [getPreference(@"jb_warn") boolValue] == YES) { - NSString *jbMessage = [NSString stringWithFormat:@"Your current jailbreak (%s) does not have the Procursus bootstrap, which means that certain issues may occur that cannot be fixed. Please switch to a completely supported jailbreak, if possible.", getenv("POJAV_DETECTEDJB")]; + NSString *jbMessage = [NSString stringWithFormat:@"Your current jailbreak (%s) does not have the Procursus bootstrap, which means that certain issues may occur that cannot be fixed. Please switch to a completely supported jailbreak, if possible. See the FAQ page for more information.", getenv("POJAV_DETECTEDJB")]; UIAlertController *jbAlert = [UIAlertController alertControllerWithTitle:@"Jailbreak not completely supported." message:jbMessage preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]; [self presentViewController:jbAlert animated:YES completion:nil]; @@ -302,7 +302,7 @@ - (void)loginOffline:(UIButton *)sender { if ([getPreference(@"local_warn") boolValue] == YES) { - UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:@"Offline mode is now Local mode." message:@"You can continue to play installed versions, but you can no longer download Minecraft without a paid account. No support will be provided for issues with local accounts, or other means of acquiring Minecraft. See our website for more information."preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:@"Offline mode is now Local mode." message:@"You can continue to play installed versions, but you can no longer download Minecraft without a paid account. No support will be provided for issues with local accounts, or other means of acquiring Minecraft. See the FAQ for more information."preferredStyle:UIAlertControllerStyleActionSheet]; [self setPopoverProperties:offlineAlert.popoverPresentationController sender:sender]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginUsername:TYPE_OFFLINE];}]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; @@ -316,11 +316,18 @@ } - (void)loginDemo:(UIButton *)sender { - UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:@"This option is currently unavailable." message:@"It will be fully implemented in a future update." preferredStyle:UIAlertControllerStyleActionSheet]; - [self setPopoverProperties:offlineAlert.popoverPresentationController sender:sender]; - UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; - [self presentViewController:offlineAlert animated:YES completion:nil]; - [offlineAlert addAction:ok]; + if ([getPreference(@"demo_warn") boolValue] == YES) { + UIAlertController *offlineAlert = [UIAlertController alertControllerWithTitle:@"This option is in beta." message:@"As a replacement to offline and local mode, demo mode will allow you to sign into a Microsoft account that does not own the game and play the Java Edition trial, introduced in 1.3.1 and newer versions. Older versions contain the full game, as the official launcher does not place these restrictions. See our website to learn more about this transition from offline mode."preferredStyle:UIAlertControllerStyleActionSheet]; + [self setPopoverProperties:offlineAlert.popoverPresentationController sender:sender]; + UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self loginMicrosoft];}]; + UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {[self accountType:sender];}]; + [self presentViewController:offlineAlert animated:YES completion:nil]; + [offlineAlert addAction:ok]; + [offlineAlert addAction:cancel]; + setPreference(@"demo_warn", @NO); + } else { + [self loginMicrosoft]; + } } - (void)loginAccount:(UIButton *)sender {