forked from BynBang/OpenPrestige
Build offline OpenPrestige release bundles
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.
This commit is contained in:
1 parent
5152e6e0a6
commit
2d6b2a3cd1
37 files changed
+1284
-451
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package dev.zprestige.prestige.client;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class AppPaths {
|
||||
private static final Path ROOT = root();
|
||||
|
||||
private AppPaths() {}
|
||||
|
||||
public static Path configs() {
|
||||
return ROOT.resolve("configs");
|
||||
}
|
||||
|
||||
public static Path runtime() {
|
||||
return ROOT.resolve("runtime");
|
||||
}
|
||||
|
||||
private static Path root() {
|
||||
String os = System.getProperty("os.name", "");
|
||||
Path base;
|
||||
if (os.startsWith("Windows")) {
|
||||
base = env("APPDATA");
|
||||
Path home = env("USERPROFILE");
|
||||
if (base == null && home != null) base = home.resolve("AppData").resolve("Roaming");
|
||||
} else {
|
||||
Path home = env("HOME");
|
||||
if (os.startsWith("Mac")) {
|
||||
base = home == null ? null : home.resolve("Library").resolve("Application Support");
|
||||
} else {
|
||||
base = env("XDG_DATA_HOME");
|
||||
if (base == null || !base.isAbsolute()) base = home == null ? null : home.resolve(".local").resolve("share");
|
||||
}
|
||||
}
|
||||
if (base == null) base = Path.of(System.getProperty("java.io.tmpdir"));
|
||||
return base.resolve(".openprestige");
|
||||
}
|
||||
|
||||
private static Path env(String name) {
|
||||
String value = System.getenv(name);
|
||||
return value == null || value.isEmpty() ? null : Path.of(value);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.zprestige.prestige.inject;
|
||||
|
||||
import dev.zprestige.prestige.client.AppPaths;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -31,7 +32,7 @@ final class TransformCache {
|
||||
try {
|
||||
Path jar = Path.of(Bootstrap.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
if (!Files.isRegularFile(jar)) return null;
|
||||
Path dir = Path.of(System.getProperty("java.io.tmpdir"), "PrestigeLoader", "cache");
|
||||
Path dir = AppPaths.runtime().resolve("cache");
|
||||
Files.createDirectories(dir);
|
||||
prune(dir);
|
||||
return new TransformCache(dir, MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(jar)));
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.zprestige.prestige.ui;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import dev.zprestige.prestige.client.AppPaths;
|
||||
import dev.zprestige.prestige.client.Prestige;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -17,7 +18,7 @@ import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Local (offline) backend of the Configs page. Every config is one JSON file in {@code <gameDir>/prestige/configs/}:
|
||||
* Local (offline) backend of the Configs page. Every config is one JSON file in the shared OpenPrestige data directory:
|
||||
* the card metadata plus the client's own snapshot ({@code ConfigManager.saveToJson()}), which is applied again with
|
||||
* {@code ConfigManager.loadFromJson(String)}. "Public configs" lists the configs saved with Public visibility, "Personal configs"
|
||||
* lists all of them; Create saves the current module/HUD state, Update overwrites it, Delete removes the file.
|
||||
@@ -45,6 +46,10 @@ public final class LocalConfigs {
|
||||
private static String lastQuery = null;
|
||||
|
||||
static Path dir() {
|
||||
return AppPaths.configs().resolve("presets");
|
||||
}
|
||||
|
||||
private static Path legacyDir() {
|
||||
Path base;
|
||||
try { base = net.fabricmc.loader.api.FabricLoader.getInstance().getGameDir(); } catch (Throwable t) { base = Path.of("."); }
|
||||
return base.resolve("prestige").resolve("configs");
|
||||
@@ -86,21 +91,61 @@ public final class LocalConfigs {
|
||||
for (Path p : (Iterable<Path>) s.filter(f -> f.getFileName().toString().endsWith(".json"))::iterator) {
|
||||
try {
|
||||
Entry e = GSON.fromJson(Files.readString(p, StandardCharsets.UTF_8), Entry.class);
|
||||
if (e == null || e.name == null || e.name.isBlank()) continue;
|
||||
if (e.tags == null) e.tags = new ArrayList<>();
|
||||
e.tags.removeIf(java.util.Objects::isNull);
|
||||
if (e.desc == null) e.desc = "";
|
||||
if (e.author == null) e.author = "";
|
||||
if (e.date == null) e.date = "";
|
||||
ALL.add(e);
|
||||
if (normalize(e)) ALL.add(e);
|
||||
} catch (Throwable t) { System.out.println("[prestige-ui] config " + p.getFileName() + ": " + t); }
|
||||
}
|
||||
}
|
||||
importLegacy(d);
|
||||
} catch (IOException e) { System.out.println("[prestige-ui] configs dir: " + e); }
|
||||
ALL.sort(Comparator.comparingInt((Entry e) -> e.id).reversed());
|
||||
rebuild();
|
||||
}
|
||||
|
||||
private static boolean normalize(Entry entry) {
|
||||
if (entry == null || entry.name == null || entry.name.isBlank()) return false;
|
||||
if (entry.tags == null) entry.tags = new ArrayList<>();
|
||||
entry.tags.removeIf(java.util.Objects::isNull);
|
||||
if (entry.desc == null) entry.desc = "";
|
||||
if (entry.author == null) entry.author = "";
|
||||
if (entry.date == null) entry.date = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
private static JsonObject configWithoutId(Entry entry) {
|
||||
JsonObject config = GSON.toJsonTree(entry).getAsJsonObject();
|
||||
config.remove("id");
|
||||
return config;
|
||||
}
|
||||
|
||||
private static void importLegacy(Path directory) throws IOException {
|
||||
Path legacy = legacyDir().toAbsolutePath().normalize();
|
||||
if (!Files.isDirectory(legacy)) return;
|
||||
String key = java.util.UUID.nameUUIDFromBytes(legacy.toString().getBytes(StandardCharsets.UTF_8)).toString();
|
||||
Path marker = directory.resolve(".imported-" + key);
|
||||
if (Files.exists(marker)) return;
|
||||
try (Stream<Path> files = Files.list(legacy)) {
|
||||
for (Path path : files.filter(p -> p.getFileName().toString().endsWith(".json")).toList()) {
|
||||
Entry entry;
|
||||
try {
|
||||
entry = GSON.fromJson(Files.readString(path, StandardCharsets.UTF_8), Entry.class);
|
||||
} catch (RuntimeException error) {
|
||||
System.out.println("[prestige-ui] could not import " + path.getFileName() + ": " + error);
|
||||
continue;
|
||||
}
|
||||
if (!normalize(entry)) continue;
|
||||
JsonObject content = configWithoutId(entry);
|
||||
if (ALL.stream().anyMatch(existing -> configWithoutId(existing).equals(content))) continue;
|
||||
int originalId = entry.id;
|
||||
if (ALL.stream().anyMatch(existing -> existing.id == originalId)) {
|
||||
entry.id = ALL.stream().mapToInt(existing -> existing.id).max().orElse(0) + 1;
|
||||
}
|
||||
Files.writeString(file(entry), GSON.toJson(entry), StandardCharsets.UTF_8, java.nio.file.StandardOpenOption.CREATE_NEW);
|
||||
ALL.add(entry);
|
||||
}
|
||||
}
|
||||
Files.writeString(marker, "");
|
||||
}
|
||||
|
||||
private static Path file(Entry e) { return dir().resolve(e.id + "_" + e.name.replaceAll("[^A-Za-z0-9_.-]", "_") + ".json"); }
|
||||
|
||||
private static void write(Entry e) {
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import dev.zprestige.prestige.ui.Input;
|
||||
import dev.zprestige.prestige.ui.Lib;
|
||||
import dev.zprestige.prestige.ui.Theme;
|
||||
import dev.zprestige.prestige.ui.Ui;
|
||||
import dev.zprestige.prestige.client.AppPaths;
|
||||
|
||||
/** Draws the ported ClickGUI over the finished frame (called from the RenderSystem.flipFrame mixin). */
|
||||
public final class Overlay {
|
||||
@@ -40,14 +41,19 @@ public final class Overlay {
|
||||
public static volatile long lastCloseNanos;
|
||||
|
||||
static Path posFile() {
|
||||
try { return net.fabricmc.loader.api.FabricLoader.getInstance().getConfigDir().resolve("prestige_ui.json"); } catch (Throwable t) { return null; }
|
||||
return AppPaths.configs().resolve("prestige_ui.json");
|
||||
}
|
||||
static void loadPos() {
|
||||
if (posLoaded) return;
|
||||
posLoaded = true;
|
||||
try {
|
||||
Path f = posFile();
|
||||
if (f == null || !Files.exists(f)) return;
|
||||
if (!Files.exists(f)) {
|
||||
Path legacy = net.fabricmc.loader.api.FabricLoader.getInstance().getConfigDir().resolve("prestige_ui.json");
|
||||
if (!Files.isRegularFile(legacy)) return;
|
||||
Files.createDirectories(f.getParent());
|
||||
try { Files.copy(legacy, f); } catch (java.nio.file.FileAlreadyExistsException ignored) {}
|
||||
}
|
||||
String t = Files.readString(f);
|
||||
java.util.regex.Matcher mx = java.util.regex.Pattern.compile("\"x\"\\s*:\\s*(-?[0-9.]+)").matcher(t);
|
||||
java.util.regex.Matcher my = java.util.regex.Pattern.compile("\"y\"\\s*:\\s*(-?[0-9.]+)").matcher(t);
|
||||
@@ -59,7 +65,8 @@ public final class Overlay {
|
||||
static void savePos() {
|
||||
try {
|
||||
Path f = posFile();
|
||||
if (f != null) Files.writeString(f, "{\"x\": " + fracX + ", \"y\": " + fracY + ", \"allowUpscale\": " + allowUpscale + "}\n");
|
||||
Files.createDirectories(f.getParent());
|
||||
Files.writeString(f, "{\"x\": " + fracX + ", \"y\": " + fracY + ", \"allowUpscale\": " + allowUpscale + "}\n");
|
||||
} catch (Throwable t) { System.out.println("[prestige-ui] savePos " + t); }
|
||||
}
|
||||
|
||||
@@ -192,6 +199,7 @@ public final class Overlay {
|
||||
|
||||
static void init() throws Exception {
|
||||
if (inited) return;
|
||||
ImGuiNative.prepare();
|
||||
ImGui.createContext();
|
||||
ImGuiIO io = ImGui.getIO();
|
||||
io.setIniFilename(null);
|
||||
|
||||
Reference in new issue
Block a user