Skip to content

Commit 567bd15

Browse files
authored
在陶瓦联机界面启动游戏时禁用离线皮肤功能 (#4916)
1 parent 25c9ef0 commit 567bd15

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public void globalizeVersionSetting(String id) {
387387
vs.setUsesGlobal(true);
388388
}
389389

390-
public LaunchOptions getLaunchOptions(String version, JavaRuntime javaVersion, Path gameDir, List<String> javaAgents, List<String> javaArguments, boolean makeLaunchScript) {
390+
public LaunchOptions.Builder getLaunchOptions(String version, JavaRuntime javaVersion, Path gameDir, List<String> javaAgents, List<String> javaArguments, boolean makeLaunchScript) {
391391
VersionSetting vs = getVersionSetting(version);
392392

393393
LaunchOptions.Builder builder = new LaunchOptions.Builder()
@@ -461,7 +461,7 @@ public LaunchOptions getLaunchOptions(String version, JavaRuntime javaVersion, P
461461
if (vs.isAutoMemory() && builder.getJavaArguments().stream().anyMatch(it -> it.startsWith("-Xmx")))
462462
builder.setMaxMemory(null);
463463

464-
return builder.create();
464+
return builder;
465465
}
466466

467467
@Override

HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.jackhuang.hmcl.Launcher;
2323
import org.jackhuang.hmcl.auth.*;
2424
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorDownloadException;
25+
import org.jackhuang.hmcl.auth.offline.OfflineAccount;
2526
import org.jackhuang.hmcl.download.DefaultDependencyManager;
2627
import org.jackhuang.hmcl.download.DownloadProvider;
2728
import org.jackhuang.hmcl.download.LibraryAnalyzer;
@@ -81,6 +82,7 @@ public final class LauncherHelper {
8182
private final VersionSetting setting;
8283
private LauncherVisibility launcherVisibility;
8384
private boolean showLogs;
85+
private boolean disableOfflineSkin = false;
8486

8587
public LauncherHelper(Profile profile, Account account, String selectedVersion) {
8688
this.profile = Objects.requireNonNull(profile);
@@ -111,6 +113,10 @@ public void setKeep() {
111113
launcherVisibility = LauncherVisibility.KEEP;
112114
}
113115

116+
public void setDisableOfflineSkin() {
117+
disableOfflineSkin = true;
118+
}
119+
114120
public void launch() {
115121
FXUtils.checkFxUserThread();
116122

@@ -188,8 +194,12 @@ private void launch0() {
188194
.thenComposeAsync(() -> gameVersion.map(s -> new GameVerificationFixTask(dependencyManager, s, version.get())).orElse(null))
189195
.thenComposeAsync(() -> logIn(account).withStage("launch.state.logging_in"))
190196
.thenComposeAsync(authInfo -> Task.supplyAsync(() -> {
191-
LaunchOptions launchOptions = repository.getLaunchOptions(
197+
LaunchOptions.Builder launchOptionsBuilder = repository.getLaunchOptions(
192198
selectedVersion, javaVersionRef.get(), profile.getGameDir(), javaAgents, javaArguments, scriptFile != null);
199+
if (disableOfflineSkin) {
200+
launchOptionsBuilder.setDaemon(false);
201+
}
202+
LaunchOptions launchOptions = launchOptionsBuilder.create();
193203

194204
LOG.info("Here's the structure of game mod directory:\n" + FileUtils.printFileStructure(repository.getModsDirectory(selectedVersion), 10));
195205

@@ -639,10 +649,13 @@ private static CompletableFuture<JavaRuntime> downloadJava(GameJavaVersion javaV
639649
return future;
640650
}
641651

642-
private static Task<AuthInfo> logIn(Account account) {
652+
private Task<AuthInfo> logIn(Account account) {
643653
return Task.composeAsync(() -> {
644654
try {
645-
return Task.completed(account.logIn());
655+
if (disableOfflineSkin && account instanceof OfflineAccount offlineAccount)
656+
return Task.completed(offlineAccount.logInWithoutSkin());
657+
else
658+
return Task.completed(account.logIn());
646659
} catch (CredentialExpiredException e) {
647660
LOG.info("Credential has expired", e);
648661

HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaControllerPage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ public TerracottaControllerPage() {
232232
MessageDialogPane.MessageType.QUESTION
233233
).addAction(i18n("version.launch"), () -> {
234234
Profile profile = Profiles.getSelectedProfile();
235-
Versions.launch(profile, profile.getSelectedVersion(), LauncherHelper::setKeep);
235+
Versions.launch(profile, profile.getSelectedVersion(), launcherHelper -> {
236+
launcherHelper.setKeep();
237+
launcherHelper.setDisableOfflineSkin();
238+
});
236239
}).addCancel(i18n("terracotta.status.waiting.host.launch.skip"), () -> {
237240
TerracottaState.HostScanning s1 = TerracottaManager.setScanning();
238241
if (s1 != null) {

HMCL/src/main/java/org/jackhuang/hmcl/ui/terracotta/TerracottaPage.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import javafx.scene.layout.BorderPane;
2525
import javafx.scene.layout.Priority;
2626
import javafx.scene.layout.VBox;
27-
import org.jackhuang.hmcl.game.LauncherHelper;
2827
import org.jackhuang.hmcl.setting.Profile;
2928
import org.jackhuang.hmcl.setting.Profiles;
3029
import org.jackhuang.hmcl.terracotta.TerracottaMetadata;
@@ -71,7 +70,10 @@ public TerracottaPage() {
7170
AdvancedListBox toolbar = new AdvancedListBox()
7271
.addNavigationDrawerItem(i18n("version.launch"), SVG.ROCKET_LAUNCH, () -> {
7372
Profile profile = Profiles.getSelectedProfile();
74-
Versions.launch(profile, profile.getSelectedVersion(), LauncherHelper::setKeep);
73+
Versions.launch(profile, profile.getSelectedVersion(), launcherHelper -> {
74+
launcherHelper.setKeep();
75+
launcherHelper.setDisableOfflineSkin();
76+
});
7577
}, item -> {
7678
instanceChangeListenerHolder = FXUtils.onWeakChangeAndOperate(Profiles.selectedVersionProperty(),
7779
instanceName -> item.setSubtitle(StringUtils.isNotBlank(instanceName) ? instanceName : i18n("version.empty"))

HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccount.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ protected boolean loadAuthlibInjector(Skin skin) {
103103
return skin != null && skin.getType() != Skin.Type.DEFAULT;
104104
}
105105

106+
public AuthInfo logInWithoutSkin() throws AuthenticationException {
107+
// Using "legacy" user type here because "mojang" user type may cause "invalid session token" or "disconnected" when connecting to a game server.
108+
return new AuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), AuthInfo.USER_TYPE_MSA, "{}");
109+
}
110+
106111
@Override
107112
public AuthInfo logIn() throws AuthenticationException {
108-
// Using "legacy" user type here because "mojang" user type may cause "invalid session token" or "disconnected" when connecting to a game server.
109-
AuthInfo authInfo = new AuthInfo(username, uuid, UUIDTypeAdapter.fromUUID(UUID.randomUUID()), AuthInfo.USER_TYPE_MSA, "{}");
113+
AuthInfo authInfo = logInWithoutSkin();
110114

111115
if (loadAuthlibInjector(skin)) {
112116
CompletableFuture<AuthlibInjectorArtifactInfo> artifactTask = CompletableFuture.supplyAsync(() -> {

0 commit comments

Comments
 (0)