From 6accdc88725651bacf77a2650abdf13b6eb742d0 Mon Sep 17 00:00:00 2001 From: Time-YiXian Date: Tue, 4 Aug 2026 21:03:29 +0800 Subject: [PATCH] fix(launch): fix no-sound when natives directory path contains non-ASCII characters When the instance folder name contains non-ASCII characters (e.g. Chinese), the java.library.path is set to a path with those characters. JDK 17+ uses the ANSI-native API (LoadLibraryA) internally to resolve native libraries, which cannot handle non-ASCII paths - native libraries such as OpenAL32.dll fail to load, resulting in games launching with video but no audio. This is triggered when running 1.6.4 with FishModLoader, which depends on LWJGL 2.9.4, under JDK 17 with a Chinese-character instance folder name. Redirect getNativeFolder() to an ASCII-only temp path under java.io.tmpdir when the default path contains non-ASCII characters. This is the Windows equivalent of the existing Linux/macOS symlink workaround introduced in #1141. Fixes #1141 for Windows. --- .../org/jackhuang/hmcl/launch/DefaultLauncher.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java index 4ef8e3af8bd..606a5618c9b 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java @@ -556,7 +556,15 @@ protected Map getConfigurations() { /// Returns the native library directory selected by the launch options. private Path getNativeFolder() { if (StringUtils.isBlank(options.getNativesDir())) { - return repository.getNativeDirectory(manifest.id(), options.getJava().getPlatform()); + Path defaultPath = repository.getNativeDirectory(manifest.id(), options.getJava().getPlatform()); + // JDK 17+ uses the ANSI-native LoadLibraryA internally, + // which cannot resolve native libraries from non-ASCII paths. + // Use a temp directory with ASCII-only path as a workaround. + if (!StringUtils.isASCII(defaultPath.toString())) { + return Paths.get(System.getProperty("java.io.tmpdir"), + "hmcl-natives-" + Math.abs(manifest.id().id().hashCode()) + "-" + options.getJava().getPlatform()); + } + return defaultPath; } return Path.of(options.getNativesDir());