Rename the injector and package it with an embedded payload for Windows, Linux, and macOS x64/ARM64. Add a core-only ImGui native build, multi-platform CI and release packaging, and shared per-user storage with legacy config migration.
55 lines
2.5 KiB
Java
55 lines
2.5 KiB
Java
package dev.zprestige.prestige.ui.mc;
|
|
|
|
import dev.zprestige.prestige.client.AppPaths;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.FileAlreadyExistsException;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.HexFormat;
|
|
import java.util.Locale;
|
|
|
|
/** Selects the native binding by JVM architecture before ImGui initializes. */
|
|
final class ImGuiNative {
|
|
private ImGuiNative() {}
|
|
|
|
static void prepare() throws IOException {
|
|
if (System.getProperty("imgui.library.path") != null) return;
|
|
String arch = System.getProperty("os.arch").toLowerCase(Locale.ROOT);
|
|
boolean arm = arch.equals("aarch64") || arch.equals("arm64");
|
|
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
|
String family = os.startsWith("windows") ? "windows" : os.contains("mac") ? "macos" : "linux";
|
|
String platform = family.equals("macos") ? "macos-universal" : family + (arm ? "-aarch64" : "-x86_64");
|
|
String filename = System.mapLibraryName("imgui-java64");
|
|
String resource = "/prestige-natives/" + platform + "/" + filename;
|
|
try (InputStream stream = ImGuiNative.class.getResourceAsStream(resource)) {
|
|
if (stream == null) {
|
|
if (arm && !family.equals("macos")) throw new IOException("Missing ARM64 ImGui binding " + resource);
|
|
return;
|
|
}
|
|
byte[] bytes = stream.readAllBytes();
|
|
String digest;
|
|
try {
|
|
digest = HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(bytes));
|
|
} catch (NoSuchAlgorithmException error) {
|
|
throw new IOException("SHA-256 is unavailable", error);
|
|
}
|
|
Path directory = AppPaths.runtime().resolve("imgui").resolve(platform).resolve(digest);
|
|
Files.createDirectories(directory);
|
|
Path library = directory.resolve(filename);
|
|
if (!Files.isRegularFile(library)) {
|
|
Path temporary = Files.createTempFile(directory, "binding-", ".tmp");
|
|
try {
|
|
Files.write(temporary, bytes);
|
|
try { Files.move(temporary, library); } catch (FileAlreadyExistsException ignored) {}
|
|
} finally {
|
|
Files.deleteIfExists(temporary);
|
|
}
|
|
}
|
|
System.setProperty("imgui.library.path", directory.toAbsolutePath().toString());
|
|
}
|
|
}
|
|
}
|