Skip to content

Commit

Permalink
Demo Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
CADIndie committed Sep 23, 2024
1 parent 8630c43 commit 745c4dc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pojlib/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public static void login(Activity activity)
}

MinecraftAccount acc = MinecraftAccount.load(activity.getFilesDir() + "/accounts");
if(acc != null && (acc.expiresOn >= System.currentTimeMillis() || !hasWifi)) {
if(acc != null && (acc.expiresOn >= System.currentTimeMillis() || !hasWifi || acc.expiresOn == 0)) {
currentAcc = acc;
API.profileImage = MinecraftAccount.getSkinFaceUrl(API.currentAcc);
API.profileName = API.currentAcc.username;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/pojlib/InstanceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Locale;

import pojlib.account.MinecraftAccount;
import pojlib.account.Msa;
import pojlib.install.FabricMeta;
import pojlib.install.Installer;
import pojlib.install.MinecraftMeta;
Expand Down Expand Up @@ -291,7 +292,7 @@ public static void launchInstance(Activity activity, MinecraftAccount account, M
API.currentInstance = instance;
JREUtils.redirectAndPrintJRELog();
VLoader.setAndroidInitInfo(activity);
JREUtils.launchJavaVM(activity, instance.generateLaunchArgs(account), instance);
JREUtils.launchJavaVM(activity, instance.generateLaunchArgs(account, !Msa.doesOwnGame), instance);
} catch (Throwable e) {
e.printStackTrace();
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/pojlib/account/Msa.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public MinecraftAccount performLogin(String msToken) throws MSAException {
acc.username = mcName;
acc.uuid = mcUuid;
acc.expiresOn = mcExpiresOn;
} else {
acc.accessToken = "0";
acc.username = "Player";
acc.uuid = "00000000-0000-0000-0000-000000000000";
acc.expiresOn = 0;
}

return acc;
Expand Down Expand Up @@ -222,9 +227,9 @@ public static boolean checkMcProfile(String mcAccessToken) throws IOException, M
mcUuid = uuidDashes;
return true;
} else {
Logger.getInstance().appendToLog("MicrosoftLogin | It seems that this Microsoft Account does not own the game.");
Logger.getInstance().appendToLog("MicrosoftLogin | It seems that this Microsoft Account does not own the game, setting game to demo mode.");
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.");
throw new MSAException("It seems like this account does not have a Minecraft profile, demo mode enabled. If you have Xbox Game Pass, please log in on https://minecraft.net/ and set it up.");
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/pojlib/util/json/MinecraftInstances.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ public static class Instance {
public ProjectInfo[] extProjects;
public boolean defaultMods;

public List<String> generateLaunchArgs(MinecraftAccount account) {
public List<String> generateLaunchArgs(MinecraftAccount account, boolean isDemoMode) {
String[] mcArgs = {"--username", account.username, "--version", versionName, "--gameDir", gameDir,
"--assetsDir", assetsDir, "--assetIndex", assetIndex, "--uuid", account.uuid.replace("-", ""),
"--accessToken", account.accessToken, "--userType", account.userType, "--versionType", "release"};

List<String> allArgs = new ArrayList<>(Arrays.asList("-cp", classpath));
allArgs.add(mainClass);
allArgs.addAll(Arrays.asList(mcArgs));
if (isDemoMode) {allArgs.add("--demo");}

return allArgs;
}

Expand Down

0 comments on commit 745c4dc

Please sign in to comment.