mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-17 15:57:18 -04:00
fix(multiplayer): force using authlib-injector in multiplayer mode.
This commit is contained in:
parent
11a1c37765
commit
a70e53364d
@ -72,7 +72,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
|||||||
public final class LauncherHelper {
|
public final class LauncherHelper {
|
||||||
|
|
||||||
private final Profile profile;
|
private final Profile profile;
|
||||||
private final Account account;
|
private Account account;
|
||||||
private final String selectedVersion;
|
private final String selectedVersion;
|
||||||
private File scriptFile;
|
private File scriptFile;
|
||||||
private final VersionSetting setting;
|
private final VersionSetting setting;
|
||||||
@ -91,6 +91,14 @@ public final class LauncherHelper {
|
|||||||
|
|
||||||
private final TaskExecutorDialogPane launchingStepsPane = new TaskExecutorDialogPane(TaskCancellationAction.NORMAL);
|
private final TaskExecutorDialogPane launchingStepsPane = new TaskExecutorDialogPane(TaskCancellationAction.NORMAL);
|
||||||
|
|
||||||
|
public Account getAccount() {
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccount(Account account) {
|
||||||
|
this.account = account;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTestMode() {
|
public void setTestMode() {
|
||||||
launcherVisibility = LauncherVisibility.KEEP;
|
launcherVisibility = LauncherVisibility.KEEP;
|
||||||
showLogs = true;
|
showLogs = true;
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher
|
||||||
|
* Copyright (C) 2022 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.ui.multiplayer;
|
||||||
|
|
||||||
|
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorArtifactProvider;
|
||||||
|
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
||||||
|
import org.jackhuang.hmcl.auth.offline.Skin;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class MultiplayerOfflineAccount extends OfflineAccount {
|
||||||
|
|
||||||
|
public MultiplayerOfflineAccount(AuthlibInjectorArtifactProvider downloader, String username, UUID uuid, Skin skin) {
|
||||||
|
super(downloader, username, uuid, skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean loadAuthlibInjector(Skin skin) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -22,14 +22,19 @@ import com.jfoenix.controls.JFXDialogLayout;
|
|||||||
import javafx.beans.property.*;
|
import javafx.beans.property.*;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.Skin;
|
import javafx.scene.control.Skin;
|
||||||
|
import org.jackhuang.hmcl.auth.Account;
|
||||||
|
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
|
||||||
import org.jackhuang.hmcl.event.Event;
|
import org.jackhuang.hmcl.event.Event;
|
||||||
import org.jackhuang.hmcl.setting.DownloadProviders;
|
import org.jackhuang.hmcl.setting.DownloadProviders;
|
||||||
|
import org.jackhuang.hmcl.setting.Profile;
|
||||||
|
import org.jackhuang.hmcl.setting.Profiles;
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.ui.Controllers;
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
import org.jackhuang.hmcl.ui.construct.*;
|
import org.jackhuang.hmcl.ui.construct.*;
|
||||||
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
|
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
|
||||||
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
import org.jackhuang.hmcl.ui.decorator.DecoratorPage;
|
||||||
|
import org.jackhuang.hmcl.ui.versions.Versions;
|
||||||
import org.jackhuang.hmcl.util.HMCLService;
|
import org.jackhuang.hmcl.util.HMCLService;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
import org.jackhuang.hmcl.util.TaskCancellationAction;
|
import org.jackhuang.hmcl.util.TaskCancellationAction;
|
||||||
@ -135,6 +140,23 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
|||||||
return session.getReadOnlyProperty();
|
return session.getReadOnlyProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void launchGame() {
|
||||||
|
Profile profile = Profiles.getSelectedProfile();
|
||||||
|
Versions.launch(profile, profile.getSelectedVersion(), (launcherHelper) -> {
|
||||||
|
launcherHelper.setKeep();
|
||||||
|
Account account = launcherHelper.getAccount();
|
||||||
|
if (account instanceof OfflineAccount && !(account instanceof MultiplayerOfflineAccount)) {
|
||||||
|
OfflineAccount offlineAccount = (OfflineAccount) account;
|
||||||
|
launcherHelper.setAccount(new MultiplayerOfflineAccount(
|
||||||
|
offlineAccount.getDownloader(),
|
||||||
|
offlineAccount.getUsername(),
|
||||||
|
offlineAccount.getUUID(),
|
||||||
|
offlineAccount.getSkin()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void checkAgreement(Runnable runnable) {
|
private void checkAgreement(Runnable runnable) {
|
||||||
if (globalConfig().getMultiplayerAgreementVersion() < MultiplayerManager.HIPER_AGREEMENT_VERSION) {
|
if (globalConfig().getMultiplayerAgreementVersion() < MultiplayerManager.HIPER_AGREEMENT_VERSION) {
|
||||||
JFXDialogLayout agreementPane = new JFXDialogLayout();
|
JFXDialogLayout agreementPane = new JFXDialogLayout();
|
||||||
|
@ -33,9 +33,6 @@ import javafx.scene.control.ScrollPane;
|
|||||||
import javafx.scene.layout.*;
|
import javafx.scene.layout.*;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
import org.jackhuang.hmcl.game.LauncherHelper;
|
|
||||||
import org.jackhuang.hmcl.setting.Profile;
|
|
||||||
import org.jackhuang.hmcl.setting.Profiles;
|
|
||||||
import org.jackhuang.hmcl.task.Schedulers;
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
import org.jackhuang.hmcl.ui.Controllers;
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
import org.jackhuang.hmcl.ui.FXUtils;
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
@ -43,7 +40,6 @@ import org.jackhuang.hmcl.ui.SVG;
|
|||||||
import org.jackhuang.hmcl.ui.construct.*;
|
import org.jackhuang.hmcl.ui.construct.*;
|
||||||
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
|
import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType;
|
||||||
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
|
import org.jackhuang.hmcl.ui.decorator.DecoratorAnimatedPage;
|
||||||
import org.jackhuang.hmcl.ui.versions.Versions;
|
|
||||||
import org.jackhuang.hmcl.util.HMCLService;
|
import org.jackhuang.hmcl.util.HMCLService;
|
||||||
import org.jackhuang.hmcl.util.Lang;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
import org.jackhuang.hmcl.util.StringUtils;
|
||||||
@ -80,8 +76,7 @@ public class MultiplayerPageSkin extends DecoratorAnimatedPage.DecoratorAnimated
|
|||||||
item.setTitle(i18n("version.launch"));
|
item.setTitle(i18n("version.launch"));
|
||||||
item.setLeftGraphic(wrap(SVG::rocketLaunchOutline));
|
item.setLeftGraphic(wrap(SVG::rocketLaunchOutline));
|
||||||
item.setOnAction(e -> {
|
item.setOnAction(e -> {
|
||||||
Profile profile = Profiles.getSelectedProfile();
|
control.launchGame();
|
||||||
Versions.launch(profile, profile.getSelectedVersion(), LauncherHelper::setKeep);
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.startCategory(i18n("help"))
|
.startCategory(i18n("help"))
|
||||||
|
@ -67,6 +67,10 @@ public class OfflineAccount extends Account {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AuthlibInjectorArtifactProvider getDownloader() {
|
||||||
|
return downloader;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
return uuid;
|
return uuid;
|
||||||
@ -91,7 +95,7 @@ public class OfflineAccount extends Account {
|
|||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadAuthlibInjector(Skin skin) {
|
protected boolean loadAuthlibInjector(Skin skin) {
|
||||||
if (skin == null) return false;
|
if (skin == null) return false;
|
||||||
if (skin.getType() == Skin.Type.DEFAULT) return false;
|
if (skin.getType() == Skin.Type.DEFAULT) return false;
|
||||||
TextureModel defaultModel = TextureModel.detectUUID(getUUID());
|
TextureModel defaultModel = TextureModel.detectUUID(getUUID());
|
||||||
@ -158,7 +162,8 @@ public class OfflineAccount extends Account {
|
|||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.addCharacter(new YggdrasilServer.Character(uuid, username, skin.load(username).run()));
|
server.addCharacter(new YggdrasilServer.Character(uuid, username,
|
||||||
|
skin != null ? skin.load(username).run() : null));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// ignore
|
// ignore
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user