Skip to content

Commit

Permalink
Remove the ability to download Minecraft on Local accounts. (#5560)
Browse files Browse the repository at this point in the history
* Remove the ability to pirate Minecraft through the Android CI

* Fix a few things.

* Fix local account not being able to play even when Minecraft is installed.

* Modify strings, Requires translation!

* Code cleanup

---------

Co-authored-by: something something <[email protected]>
  • Loading branch information
Weather-OS and something something authored Aug 3, 2024
1 parent ae48e8e commit 7289375
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import android.Manifest;
import android.app.NotificationManager;
import android.content.DialogInterface;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
Expand Down Expand Up @@ -132,11 +133,13 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f)
}
String normalizedVersionId = AsyncMinecraftDownloader.normalizeVersionId(prof.lastVersionId);
JMinecraftVersionList.Version mcVersion = AsyncMinecraftDownloader.getListedVersion(normalizedVersionId);

new MinecraftDownloader().start(
this,
mcVersion,
normalizedVersionId,
new ContextAwareDoneListener(this, normalizedVersionId)
new ContextAwareDoneListener(this, normalizedVersionId),
mAccountSpinner
);
return false;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.kdt.pojavlaunch.modloaders;

import com.kdt.mcgui.ProgressLayout;
import com.kdt.mcgui.mcAccountSpinner;

import net.kdt.pojavlaunch.JMinecraftVersionList;
import net.kdt.pojavlaunch.R;
Expand All @@ -19,6 +20,7 @@ public class OptiFineDownloadTask implements Runnable, Tools.DownloaderFeedback,
private static final Pattern sMcVersionPattern = Pattern.compile("([0-9]+)\\.([0-9]+)\\.?([0-9]+)?");
private final OptiFineUtils.OptiFineVersion mOptiFineVersion;
private final File mDestinationFile;
private mcAccountSpinner mAccountSpinner;
private final ModloaderDownloadListener mListener;
private final Object mMinecraftDownloadLock = new Object();
private Throwable mDownloaderThrowable;
Expand Down Expand Up @@ -87,9 +89,12 @@ public boolean downloadMinecraft(String minecraftVersion) {
// the string is always normalized
JMinecraftVersionList.Version minecraftJsonVersion = AsyncMinecraftDownloader.getListedVersion(minecraftVersion);
if(minecraftJsonVersion == null) return false;
if(mAccountSpinner.getSelectedAccount() == null){
return false;
}
try {
synchronized (mMinecraftDownloadLock) {
new MinecraftDownloader().start(null, minecraftJsonVersion, minecraftVersion, this);
new MinecraftDownloader().start(null, minecraftJsonVersion, minecraftVersion, this, mAccountSpinner);
mMinecraftDownloadLock.wait();
}
}catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import android.app.Activity;
import android.util.Log;
import android.content.DialogInterface;
import android.widget.Toast;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import com.kdt.mcgui.ProgressLayout;

Expand All @@ -25,6 +29,8 @@
import net.kdt.pojavlaunch.value.MinecraftClientInfo;
import net.kdt.pojavlaunch.value.MinecraftLibraryArtifact;

import com.kdt.mcgui.mcAccountSpinner;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -45,6 +51,8 @@ public class MinecraftDownloader {
private long mDownloadFileCount;
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 mcAccountSpinner mcAccount;
private Activity mActivity;

private static final ThreadLocal<byte[]> sThreadLocalDownloadBuffer = new ThreadLocal<>();

Expand All @@ -57,7 +65,9 @@ public class MinecraftDownloader {
*/
public void start(@Nullable Activity activity, @Nullable JMinecraftVersionList.Version version,
@NonNull String realVersion, // this was there for a reason
@NonNull AsyncMinecraftDownloader.DoneListener listener) {
@NonNull AsyncMinecraftDownloader.DoneListener listener,
@NonNull mcAccountSpinner minecraftAccount) {
this.mcAccount = minecraftAccount;
sExecutorService.execute(() -> {
try {
downloadGame(activity, version, realVersion);
Expand Down Expand Up @@ -98,7 +108,9 @@ private void downloadGame(Activity activity, JMinecraftVersionList.Version verIn

// I have tried pre-filling the queue directly instead of doing this, but it didn't work.
// What a shame.
for(DownloaderTask scheduledTask : mScheduledDownloadTasks) downloaderPool.execute(scheduledTask);
for(DownloaderTask scheduledTask : mScheduledDownloadTasks) {
downloaderPool.execute(scheduledTask);
}
downloaderPool.shutdown();

try {
Expand Down Expand Up @@ -212,9 +224,12 @@ private boolean downloadAndProcessMetadata(Activity activity, JMinecraftVersionL


MinecraftClientInfo minecraftClientInfo = getClientInfo(verInfo);
if(minecraftClientInfo != null) scheduleGameJarDownload(minecraftClientInfo, versionName);

if(verInfo.libraries != null) scheduleLibraryDownloads(verInfo.libraries);
if(minecraftClientInfo != null){
scheduleGameJarDownload(minecraftClientInfo, versionName);
}
if(verInfo.libraries != null) {
scheduleLibraryDownloads(verInfo.libraries);
}

if(verInfo.logging != null) scheduleLoggingAssetDownloadIfNeeded(verInfo.logging);

Expand All @@ -235,7 +250,7 @@ private void scheduleDownload(File targetFile, int downloadClass, String url, St
FileUtils.ensureParentDirectory(targetFile);
mDownloadFileCount++;
mScheduledDownloadTasks.add(
new DownloaderTask(targetFile, downloadClass, url, sha1, size, skipIfFailed)
new DownloaderTask(targetFile, downloadClass, url, sha1, size, skipIfFailed, mcAccount)
);
}

Expand Down Expand Up @@ -350,15 +365,17 @@ private final class DownloaderTask implements Runnable, Tools.DownloaderFeedback
private final boolean mSkipIfFailed;
private int mLastCurr;
private final long mDownloadSize;
private mcAccountSpinner minecraftAccount;

DownloaderTask(File targetPath, int downloadClass, String targetUrl, String targetSha1,
long downloadSize, boolean skipIfFailed) {
long downloadSize, boolean skipIfFailed, mcAccountSpinner minecraftAccount) {
this.mTargetPath = targetPath;
this.mTargetUrl = targetUrl;
this.mTargetSha1 = targetSha1;
this.mDownloadClass = downloadClass;
this.mDownloadSize = downloadSize;
this.mSkipIfFailed = skipIfFailed;
this.minecraftAccount = minecraftAccount;
}

@Override
Expand All @@ -377,7 +394,9 @@ private void runCatching() throws Exception {
mTargetSha1 = null; // Nullify SHA1 as DownloadUtils.ensureSha1 only checks for null,
// not for string validity
if(mTargetPath.exists()) finishWithoutDownloading();
else downloadFile();
else {
downloadFile();
}
}
}

Expand All @@ -392,6 +411,10 @@ private void verifyFileSha1() throws Exception {
}

private void downloadFile() throws Exception {
if (minecraftAccount.getSelectedAccount().isLocal()) {
throw new RuntimeException("Download failed. Please make sure you own a legal copy of Minecraft, Java Edition.");
}

try {
DownloadUtils.ensureSha1(mTargetPath, mTargetSha1, () -> {
DownloadMirror.downloadFileMirrored(mDownloadClass, mTargetUrl, mTargetPath,
Expand Down
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/res/values-en-rGB/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
<string name="main_add_account">Add account</string>
<string name="tasks_ongoing">Tasks are in progress, please wait</string>
<string name="no_saved_accounts">No saved accounts</string>
<string name="mc_download_failed">Failed to download Minecraft! This could be due to bad network connection, incorrectly placed files, etc..</string>
<string name="mc_download_failed">Failed to download Minecraft! This could be due to bad network connection, incorrectly placed files or you're trying to download Minecraft from a Local account.</string>
<string name="xerr_unknown">Unknown Xbox Live API error %d</string>
<string name="xerr_no_account">You don\'t seem to have an Xbox Live account. Please log in once on https://minecraft.net/ and try again.</string>
<string name="xerr_adult_verification">An adult needs to verify your account.</string>
Expand Down
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
<string name="main_add_account">Add account</string>
<string name="tasks_ongoing">Tasks are in progress, please wait</string>
<string name="no_saved_accounts">No saved accounts</string>
<string name="mc_download_failed">Failed to download Minecraft! This could be due to bad network connection, incorrectly placed files, etc..</string>
<string name="mc_download_failed">Failed to download Minecraft! This could be due to bad network connection, incorrectly placed files or you're trying to download Minecraft from a Local account.</string>
<string name="xerr_unknown">Unknown Xbox Live API error %d</string>
<string name="xerr_no_account">You don\'t seem to have an Xbox Live account. Please log in once on https://minecraft.net/ and try again.</string>
<string name="xerr_adult_verification">An adult needs to verify your account.</string>
Expand Down

0 comments on commit 7289375

Please sign in to comment.