Signed-off-by: Faumaray <faumaray@gmail.com>
This commit is contained in:
22 files changed
+1274
-2
No files matched your search
+1
-1
@@ -47,7 +47,7 @@ buildNumber.properties
|
||||
# Ignore build outputs from performing a nix-build or `nix build` command
|
||||
result
|
||||
result-*
|
||||
|
||||
.direnv
|
||||
# ---> VirtualEnv
|
||||
# Virtualenv
|
||||
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
|
||||
|
||||
Whitespace-only changes.
Whitespace-only changes.
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"java.configuration.updateBuildConfiguration": "interactive"
|
||||
}
|
||||
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
pipeline {
|
||||
agent any
|
||||
tools {
|
||||
maven 'maven'
|
||||
jdk 'JDK21'
|
||||
}
|
||||
stages {
|
||||
stage ('Initialize') {
|
||||
steps {
|
||||
sh '''
|
||||
echo "PATH = ${PATH}"
|
||||
echo "M2_HOME = ${M2_HOME}"
|
||||
mvn clean
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Build') {
|
||||
steps {
|
||||
sh '''
|
||||
mvn compile
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Package') {
|
||||
steps {
|
||||
sh '''
|
||||
mvn package
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage ('Deploy') {
|
||||
steps {
|
||||
sh '''
|
||||
mvn deploy
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 VoidLoader
|
||||
Copyright (c) 2025 Faumaray
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
||||
Generated
+61
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1760524057,
|
||||
"narHash": "sha256-EVAqOteLBFmd7pKkb0+FIUyzTF61VKi7YmvP1tw4nEw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "544961dfcce86422ba200ed9a0b00dd4b1486ec5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
description = "Gradle C++ cross-compile (Linux → Windows/Mac)";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (
|
||||
system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
name = "JavaShell";
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
maven
|
||||
jdk
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.faumaray</groupId>
|
||||
<artifactId>VoidLoader</artifactId>
|
||||
<version>1.0.2-SNAPSHOT</version>
|
||||
<description>Void Mod Loader</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>VoidLoader</name>
|
||||
<url>https://git.faumaray.ru/VoidLoader</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Aleksey Selihov</name>
|
||||
<email>faumaray@gmail.com</email>
|
||||
<organization>Sonatype</organization>
|
||||
<organizationUrl>http://www.sonatype.com</organizationUrl>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:https://git.faumaray.ru/VoidLoader/VoidLoader.git</connection>
|
||||
<developerConnection>scm:git:https://github.com/Faumaray/VoidLoader.git</developerConnection>
|
||||
<url>https://git.faumaray.ru/VoidLoader/VoidLoader</url>
|
||||
</scm>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<is.snapshot>${project.version.endsWith("-SNAPSHOT")}</is.snapshot>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>5.11.0</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.13.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.13.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.googlecode.maven-download-plugin</groupId>
|
||||
<artifactId>download-maven-plugin</artifactId>
|
||||
<version>1.7.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>download-voidloader-core</id>
|
||||
<phase>generate-resources</phase>
|
||||
<goals>
|
||||
<goal>wget</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<url>https://git.faumaray.ru/VoidLoader/VoidLoaderCore/releases/download/${download.tag}/VoidLoader.zip</url>
|
||||
<unpack>false</unpack>
|
||||
<outputDirectory>${project.build.directory}</outputDirectory>
|
||||
<outputFileName>VoidLoader.zip</outputFileName>
|
||||
<skipCache>true</skipCache>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- 2) UNZIP -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<configuration>
|
||||
<exportAntProperties>true</exportAntProperties>
|
||||
<target>
|
||||
<condition property="isSnapshot">
|
||||
<contains string="${project.version}" substring="SNAPSHOT" />
|
||||
</condition>
|
||||
<condition property="download.tag"
|
||||
value="latest">
|
||||
<isset property="isSnapshot" />
|
||||
</condition>
|
||||
<property name="download.tag"
|
||||
value="${project.version}" />
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>unzip-voidloader-core</id>
|
||||
<phase>process-resources</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<mkdir dir="${project.build.directory}/generated-resources/voidloader"/>
|
||||
<unzip src="${project.build.directory}/VoidLoader.zip"
|
||||
dest="${project.build.directory}/generated-resources/voidloader"/>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- 3) COPY native/** into classes -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-native-into-classes</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/generated-resources/voidloader</directory>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<manifestEntries>
|
||||
<Main-Class>ru.faumaray.VoidLoaderMain</Main-Class>
|
||||
<Agent-Class>ru.faumaray.VoidLoaderAgent</Agent-Class>
|
||||
<Premain-Class>ru.faumaray.VoidLoaderAgent</Premain-Class>
|
||||
</manifestEntries>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.9.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<autoPublish>true</autoPublish>
|
||||
<waitUntil>published</waitUntil>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<passphraseServerId>gpg.passphrase</passphraseServerId>
|
||||
<gpgArguments>
|
||||
<arg>--pinentry-mode</arg>
|
||||
<arg>loopback</arg>
|
||||
</gpgArguments>
|
||||
<executable>gpg</executable>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<doclint>none</doclint>
|
||||
<quiet>true</quiet>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,24 @@
|
||||
package ru.faumaray;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class LaunchInfo {
|
||||
public Path mcJar;
|
||||
public List<Path> libraryPaths = new ArrayList<>();
|
||||
public String mainClass;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("LaunchInfo{ mcJar=").append(mcJar)
|
||||
.append(", mainClass=").append(mainClass)
|
||||
.append(", libs=[");
|
||||
for (Path p : libraryPaths) {
|
||||
sb.append(p).append(",");
|
||||
}
|
||||
sb.append("] }");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ru.faumaray;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface LauncherAdapter {
|
||||
/**
|
||||
* Try to locate the Minecraft jar, library paths, and main class given
|
||||
* a version, gameDir, and args. Return Optional.empty() if this adapter
|
||||
* doesn’t match this environment.
|
||||
*/
|
||||
Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args);
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
package ru.faumaray;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VoidLoaderAgent {
|
||||
private static final String TEMP_PREFIX = "VoidLoader_";
|
||||
private static File extractedMainLibrary = null;
|
||||
|
||||
private static native void nativeAgentStart();
|
||||
private static native void nativeAgentInit(String args, Instrumentation inst);
|
||||
private static native void nativeCleanup();
|
||||
|
||||
static {
|
||||
System.out.println("[VoidLoader/Java] Java agent wrapper initializing...");
|
||||
loadNativeLibraries();
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(VoidLoaderAgent::cleanup, "VoidLoader-Cleanup"));
|
||||
}
|
||||
|
||||
// --- Platform detection ---------------------------------------------------
|
||||
|
||||
private enum Platform {
|
||||
LINUX, WINDOWS, MAC;
|
||||
|
||||
static Platform detect() {
|
||||
String os = System.getProperty("os.name").toLowerCase(Locale.ROOT);
|
||||
if (os.contains("win")) return WINDOWS;
|
||||
if (os.contains("mac")) return MAC;
|
||||
return LINUX;
|
||||
}
|
||||
|
||||
String dirName() {
|
||||
return switch (this) {
|
||||
case WINDOWS -> "windows";
|
||||
case MAC -> "mac";
|
||||
default -> "linux";
|
||||
};
|
||||
}
|
||||
|
||||
String libName() {
|
||||
return switch (this) {
|
||||
case WINDOWS -> "VoidLoader.dll";
|
||||
case MAC -> "VoidLoader.dylib";
|
||||
default -> "VoidLoader.so";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// --- Extraction and loading -----------------------------------------------
|
||||
|
||||
private static void loadNativeLibraries() {
|
||||
Platform platform = Platform.detect();
|
||||
|
||||
// 1. Try system library path first
|
||||
try {
|
||||
System.loadLibrary("VoidLoader_agent");
|
||||
System.out.println("[VoidLoader/Java] Loaded from system library path");
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.out.println("[VoidLoader/Java] System library not found, extracting from JAR...");
|
||||
}
|
||||
|
||||
// 2. Extract from inside the JAR under native/<platform>/
|
||||
try {
|
||||
extractAndLoadPlatformLibraries(platform);
|
||||
} catch (Exception e) {
|
||||
System.err.println("[VoidLoader/Java] CRITICAL: Failed to load native library!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void extractAndLoadPlatformLibraries(Platform platform) throws IOException {
|
||||
String basePath = "/native/" + platform.dirName() + "/";
|
||||
String mainLib = platform.libName();
|
||||
|
||||
// Create temp directory for extracted libs
|
||||
Path tempDir = Files.createTempDirectory(TEMP_PREFIX + platform.dirName() + "_");
|
||||
tempDir.toFile().deleteOnExit();
|
||||
|
||||
// Find all entries under native/<platform>/
|
||||
List<String> resources = listResources(basePath);
|
||||
if (resources.isEmpty()) {
|
||||
throw new IOException("No native libraries found in JAR under: " + basePath);
|
||||
}
|
||||
|
||||
System.out.println("[VoidLoader/Java] Extracting " + resources.size() + " native files for " + platform.dirName());
|
||||
|
||||
// Extract all .so/.dll/.dylib
|
||||
for (String res : resources) {
|
||||
String fileName = res.substring(res.lastIndexOf('/') + 1);
|
||||
Path dest = tempDir.resolve(fileName);
|
||||
extractResource(res, dest);
|
||||
dest.toFile().deleteOnExit();
|
||||
}
|
||||
|
||||
// Mark everything executable on Unix
|
||||
if (platform != Platform.WINDOWS) {
|
||||
try {
|
||||
for (File f : Objects.requireNonNull(tempDir.toFile().listFiles())) {
|
||||
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(f.toPath());
|
||||
perms.add(PosixFilePermission.OWNER_EXECUTE);
|
||||
perms.add(PosixFilePermission.GROUP_EXECUTE);
|
||||
perms.add(PosixFilePermission.OTHERS_EXECUTE);
|
||||
Files.setPosixFilePermissions(f.toPath(), perms);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
} else {
|
||||
for (File f : Objects.requireNonNull(tempDir.toFile().listFiles()))
|
||||
f.setExecutable(true, false);
|
||||
}
|
||||
|
||||
// Load dependencies first, then main library
|
||||
File mainFile = tempDir.resolve(mainLib).toFile();
|
||||
extractedMainLibrary = mainFile;
|
||||
|
||||
List<File> deps = Arrays.stream(Objects.requireNonNull(tempDir.toFile().listFiles()))
|
||||
.filter(f -> !f.getName().equals(mainLib))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (File dep : deps) {
|
||||
try {
|
||||
System.load(dep.getAbsolutePath());
|
||||
System.out.println("[VoidLoader/Java] Loaded dependency: " + dep.getName());
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("[VoidLoader/Java] Failed to load dependency: " + dep.getName());
|
||||
}
|
||||
}
|
||||
|
||||
System.load(mainFile.getAbsolutePath());
|
||||
System.out.println("[VoidLoader/Java] Loaded main library: " + mainFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
private static void extractResource(String resourcePath, Path dest) throws IOException {
|
||||
try (InputStream in = VoidLoaderAgent.class.getResourceAsStream(resourcePath)) {
|
||||
if (in == null)
|
||||
throw new IOException("Missing resource in JAR: " + resourcePath);
|
||||
|
||||
// Ensure parent folder exists
|
||||
Files.createDirectories(dest.getParent());
|
||||
|
||||
// If it's a directory entry (shouldn't happen after listResources fix) — skip
|
||||
if (resourcePath.endsWith("/") || resourcePath.endsWith("\\")) {
|
||||
return;
|
||||
}
|
||||
|
||||
try (OutputStream out = new FileOutputStream(dest.toFile())) {
|
||||
in.transferTo(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --- Resource listing -----------------------------------------------------
|
||||
|
||||
private static List<String> listResources(String basePath) throws IOException {
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
// Use ClassLoader to locate the JAR
|
||||
String jarPath = VoidLoaderAgent.class
|
||||
.getProtectionDomain()
|
||||
.getCodeSource()
|
||||
.getLocation()
|
||||
.getPath();
|
||||
|
||||
if (jarPath.endsWith(".jar")) {
|
||||
try (java.util.jar.JarFile jar = new java.util.jar.JarFile(jarPath)) {
|
||||
var entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
var entry = entries.nextElement();
|
||||
String name = entry.getName();
|
||||
if (name.startsWith(basePath.substring(1)) && !entry.isDirectory()) {
|
||||
result.add("/" + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Fallback when running unpacked (e.g., IDE)
|
||||
File dir = new File("src/main/resources" + basePath);
|
||||
if (dir.exists()) {
|
||||
for (File f : Objects.requireNonNull(dir.listFiles())) {
|
||||
if (f.isFile()) result.add(basePath + f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// --- Agent entry points ---------------------------------------------------
|
||||
|
||||
public static void premain(String args, Instrumentation inst) {
|
||||
try {
|
||||
nativeAgentStart();
|
||||
nativeAgentInit(args != null ? args : "", inst);
|
||||
System.out.println("[VoidLoader/Java] Agent initialized - delegating to Minecraft");
|
||||
} catch (Throwable t) {
|
||||
System.err.println("[VoidLoader/Java] Error during initialization:");
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void agentmain(String args, Instrumentation inst) {
|
||||
System.out.println("[VoidLoader/Java] Dynamic attach not fully supported");
|
||||
premain(args, inst);
|
||||
}
|
||||
|
||||
public static void cleanup() {
|
||||
try {
|
||||
if (extractedMainLibrary != null && extractedMainLibrary.exists()) {
|
||||
extractedMainLibrary.delete();
|
||||
}
|
||||
nativeCleanup();
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package ru.faumaray;
|
||||
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import ru.faumaray.adapters.ATLauncherAdapter;
|
||||
import ru.faumaray.adapters.CurseForgeAdapter;
|
||||
import ru.faumaray.adapters.GDLauncherAdapter;
|
||||
import ru.faumaray.adapters.GenericLauncherAdapter;
|
||||
import ru.faumaray.adapters.MultiMCAdapter;
|
||||
import ru.faumaray.adapters.PrismLauncherAdapter;
|
||||
import ru.faumaray.adapters.VanillaLauncherAdapter;
|
||||
|
||||
public class VoidLoaderMain {
|
||||
// You might store a reference to Instrumentation if the agent was already loaded
|
||||
private static Instrumentation savedInstrumentation = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("[VoidLoader] Starting loader...");
|
||||
System.out.println(args.length > 0 ? ("[VoidLoader] Args: " + String.join(" ", args)) : "[VoidLoader] No args");
|
||||
|
||||
// Parse version and gameDir from args
|
||||
String version = null;
|
||||
Path gameDir = null;
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
if ("--version".equals(args[i])) {
|
||||
version = args[i + 1];
|
||||
}
|
||||
if ("--gameDir".equals(args[i])) {
|
||||
gameDir = Path.of(args[i + 1]);
|
||||
}
|
||||
}
|
||||
if (version == null) {
|
||||
System.err.println("[VoidLoader] Could not parse version from args");
|
||||
return;
|
||||
}
|
||||
if (gameDir == null) {
|
||||
gameDir = Path.of(System.getProperty("user.dir"));
|
||||
System.out.println("[VoidLoader] No --gameDir found; using cwd: " + gameDir);
|
||||
} else {
|
||||
System.out.println("[VoidLoader] Using gameDir: " + gameDir);
|
||||
}
|
||||
|
||||
// Instantiate adapters in desired order
|
||||
List<LauncherAdapter> adapters = List.of(
|
||||
new PrismLauncherAdapter(),
|
||||
new MultiMCAdapter(),
|
||||
new GDLauncherAdapter(),
|
||||
new CurseForgeAdapter(),
|
||||
new ATLauncherAdapter(),
|
||||
new VanillaLauncherAdapter(),
|
||||
new GenericLauncherAdapter()
|
||||
);
|
||||
|
||||
LaunchInfo chosen = null;
|
||||
for (LauncherAdapter adapter : adapters) {
|
||||
try {
|
||||
Optional<LaunchInfo> infoOpt = adapter.findLaunchInfo(version, gameDir, args);
|
||||
if (infoOpt.isPresent()) {
|
||||
LaunchInfo info = infoOpt.get();
|
||||
System.out.println("[VoidLoader] Adapter “" + adapter.getClass().getSimpleName() + "” succeeded: " + info);
|
||||
chosen = info;
|
||||
break;
|
||||
} else {
|
||||
System.out.println("[VoidLoader] Adapter “" + adapter.getClass().getSimpleName() + "” not applicable");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (chosen == null) {
|
||||
System.err.println("[VoidLoader] Failed to locate Minecraft jar with any adapter");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Build classpath URLs: libraries + Minecraft jar
|
||||
var urls = chosen.libraryPaths.stream()
|
||||
.map(p -> {
|
||||
try {
|
||||
return p.toUri().toURL();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
|
||||
URL[] arr = new URL[urls.size() + 1];
|
||||
for (int i = 0; i < urls.size(); i++) {
|
||||
arr[i] = urls.get(i);
|
||||
}
|
||||
arr[arr.length - 1] = chosen.mcJar.toUri().toURL();
|
||||
|
||||
try (URLClassLoader mcLoader = new URLClassLoader(arr, VoidLoaderMain.class.getClassLoader())) {
|
||||
|
||||
// ** Invoke agent premain ** before Minecraft main
|
||||
invokeAgentPremain();
|
||||
|
||||
Class<?> mainCls = Class.forName(chosen.mainClass, true, mcLoader);
|
||||
Method mm = mainCls.getMethod("main", String[].class);
|
||||
System.out.println("[VoidLoader] Launching main " + chosen.mainClass);
|
||||
mm.invoke(null, (Object) args);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
System.err.println("[VoidLoader] Error invoking Minecraft main");
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to call VoidLoaderAgent.premain(...) reflectively.
|
||||
* This may or may not give full instrumentation, depending on whether
|
||||
* the agent is already loaded and whether Instrumentation is available.
|
||||
*/
|
||||
private static void invokeAgentPremain() {
|
||||
try {
|
||||
Class<?> agentCls = Class.forName("ru.faumaray.VoidLoaderAgent");
|
||||
|
||||
// Try signature premain(String, Instrumentation)
|
||||
try {
|
||||
Method m = agentCls.getMethod("premain", String.class, Instrumentation.class);
|
||||
System.out.println("[VoidLoader] Invoking agent premain(String, Instrumentation)...");
|
||||
m.invoke(null, "", savedInstrumentation);
|
||||
return;
|
||||
} catch (NoSuchMethodException e) {
|
||||
// ignore, try simpler
|
||||
}
|
||||
|
||||
// Try signature premain(String)
|
||||
try {
|
||||
Method m2 = agentCls.getMethod("premain", String.class);
|
||||
System.out.println("[VoidLoader] Invoking agent premain(String)...");
|
||||
m2.invoke(null, "");
|
||||
return;
|
||||
} catch (NoSuchMethodException e2) {
|
||||
// No premain method found
|
||||
System.err.println("[VoidLoader] No premain method Found in agent class");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
System.err.println("[VoidLoader] Failed to invoke agent premain:");
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method could be used by your agent’s premain to pass the Instrumentation instance
|
||||
* into this loader, so that savedInstrumentation is non-null.
|
||||
* You might add something in your agent like:
|
||||
* VoidLoaderMain.setInstrumentation(inst);
|
||||
*/
|
||||
public static void setInstrumentation(Instrumentation inst) {
|
||||
savedInstrumentation = inst;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class ATLauncherAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// ATLauncher modpacks often have their own “modpacks/<pack>/versions” or “.minecraft/versions” layout
|
||||
// Try simple heuristics
|
||||
|
||||
// Try gameDir/versions/<version>/<version>.jar
|
||||
Path versions = gameDir.resolve("versions");
|
||||
Path versionFolder = versions.resolve(version);
|
||||
Path jar = versionFolder.resolve(version + ".jar");
|
||||
if (Files.exists(jar)) {
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
li.mcJar = jar;
|
||||
li.mainClass = "net.minecraft.client.main.Main";
|
||||
// Optionally load libraries in gameDir/libraries
|
||||
Path libs = gameDir.resolve("libraries");
|
||||
if (Files.isDirectory(libs)) {
|
||||
try {
|
||||
Files.walk(libs).forEach(p -> {
|
||||
if (p.toString().endsWith(".jar")) {
|
||||
li.libraryPaths.add(p);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return Optional.of(li);
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class CurseForgeAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// Walk upward until modpack root (where manifest.json / modpack.json is)
|
||||
Path p = gameDir;
|
||||
while (p != null) {
|
||||
if (Files.exists(p.resolve("manifest.json")) || Files.exists(p.resolve("modpack.json"))) {
|
||||
break;
|
||||
}
|
||||
p = p.getParent();
|
||||
}
|
||||
if (p == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Path root = p;
|
||||
JsonObject manifest = null;
|
||||
Path mf = root.resolve("manifest.json");
|
||||
if (!Files.exists(mf)) {
|
||||
mf = root.resolve("modpack.json");
|
||||
}
|
||||
if (!Files.exists(mf)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
try (var reader = Files.newBufferedReader(mf)) {
|
||||
manifest = new Gson().fromJson(reader, JsonObject.class);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
if (manifest == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
String mcVer = version;
|
||||
if (manifest.has("minecraft")) {
|
||||
JsonObject mc = manifest.getAsJsonObject("minecraft");
|
||||
if (mc.has("version")) {
|
||||
mcVer = mc.get("version").getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
|
||||
Path versionFolder = root.resolve("versions").resolve(mcVer);
|
||||
Path jar = versionFolder.resolve(mcVer + ".jar");
|
||||
if (!Files.exists(jar)) {
|
||||
// fallback: libraries/com/mojang path
|
||||
Path libRoot = root.resolve("libraries");
|
||||
Path mojangRel = Path.of("com", "mojang", "minecraft", mcVer,
|
||||
"minecraft-" + mcVer + "-client.jar");
|
||||
Path cand = libRoot.resolve(mojangRel);
|
||||
if (Files.exists(cand)) {
|
||||
jar = cand;
|
||||
}
|
||||
}
|
||||
if (!Files.exists(jar)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
li.mcJar = jar;
|
||||
|
||||
if (manifest.has("libraries")) {
|
||||
for (JsonElement el : manifest.getAsJsonArray("libraries")) {
|
||||
if (!el.isJsonObject()) continue;
|
||||
JsonObject lib = el.getAsJsonObject();
|
||||
if (lib.has("path")) {
|
||||
Path cand = root.resolve(lib.get("path").getAsString());
|
||||
if (Files.exists(cand)) {
|
||||
li.libraryPaths.add(cand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
li.mainClass = "net.minecraft.client.main.Main";
|
||||
return Optional.of(li);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class GDLauncherAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// GDLauncher stores a “runtime path” / data path under ~/.local/share/gdlauncher_carbon by default on Linux :contentReference[oaicite:1]{index=1}
|
||||
// Instances, libraries, assets are stored under that data path.
|
||||
// We can attempt to locate the GDLauncher root by walking up or using known environment vars.
|
||||
|
||||
// Example: If gameDir is inside an instance folder under the GD data path:
|
||||
// Walk upward until you find “instances” folder
|
||||
Path p = gameDir;
|
||||
while (p != null && !p.getFileName().toString().equals("instances")) {
|
||||
p = p.getParent();
|
||||
}
|
||||
if (p == null) {
|
||||
// alternative: maybe gameDir itself is the instance root
|
||||
p = gameDir;
|
||||
}
|
||||
// The data root is parent of instances
|
||||
Path gdRoot = p.getParent();
|
||||
if (gdRoot == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// Under gdRoot, there should be “libraries/com/mojang/minecraft/<version>/minecraft-<version>-client.jar”
|
||||
Path libRoot = gdRoot.resolve("libraries");
|
||||
Path mojangRel = Path.of("com", "mojang", "minecraft", version,
|
||||
"minecraft-" + version + "-client.jar");
|
||||
Path candidate = libRoot.resolve(mojangRel);
|
||||
if (Files.exists(candidate)) {
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
li.mcJar = candidate;
|
||||
li.mainClass = "net.minecraft.client.main.Main";
|
||||
// Optionally include libraries in libRoot as needed
|
||||
return Optional.of(li);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class GenericLauncherAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// As a last resort, try scanning known patterns under gameDir or its siblings
|
||||
|
||||
// Try gameDir/versions/<version>/<version>.jar
|
||||
Path versions = gameDir.resolve("versions");
|
||||
Path verFolder = versions.resolve(version);
|
||||
Path jar = verFolder.resolve(version + ".jar");
|
||||
if (Files.exists(jar)) {
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
li.mcJar = jar;
|
||||
li.mainClass = "net.minecraft.client.main.Main";
|
||||
// also include all .jar files under gameDir/libraries
|
||||
Path libs = gameDir.resolve("libraries");
|
||||
if (Files.isDirectory(libs)) {
|
||||
try {
|
||||
Files.walk(libs).forEach(p -> {
|
||||
if (p.toString().endsWith(".jar")) {
|
||||
li.libraryPaths.add(p);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return Optional.of(li);
|
||||
}
|
||||
|
||||
// Optionally, scan siblings or parent directories
|
||||
Path parent = gameDir.getParent();
|
||||
if (parent != null) {
|
||||
return findLaunchInfo(version, parent, args);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class MultiMCAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// Walk upward until you find “instances” folder name
|
||||
Path p = gameDir;
|
||||
while (p != null && !p.getFileName().toString().equals("instances")) {
|
||||
p = p.getParent();
|
||||
}
|
||||
if (p == null) return Optional.empty();
|
||||
Path multimcRoot = p.getParent();
|
||||
if (multimcRoot == null) return Optional.empty();
|
||||
|
||||
Path versionsRoot = multimcRoot.resolve("versions");
|
||||
Path versionFolder = versionsRoot.resolve(version);
|
||||
Path jar = versionFolder.resolve(version + ".jar");
|
||||
Path json = versionFolder.resolve(version + ".json");
|
||||
|
||||
if (!Files.exists(jar) && !Files.exists(json)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
JsonObject jObj = null;
|
||||
if (Files.exists(json)) {
|
||||
try (var reader = Files.newBufferedReader(json)) {
|
||||
jObj = new Gson().fromJson(reader, JsonObject.class);
|
||||
if (jObj.has("downloads")) {
|
||||
JsonObject dl = jObj.getAsJsonObject("downloads");
|
||||
if (dl.has("client")) {
|
||||
JsonObject client = dl.getAsJsonObject("client");
|
||||
if (client.has("path")) {
|
||||
Path cand = multimcRoot.resolve(client.get("path").getAsString());
|
||||
if (Files.exists(cand)) {
|
||||
jar = cand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
li.mcJar = jar;
|
||||
|
||||
if (jObj != null && jObj.has("libraries")) {
|
||||
for (JsonElement el : jObj.getAsJsonArray("libraries")) {
|
||||
if (!el.isJsonObject()) continue;
|
||||
JsonObject lib = el.getAsJsonObject();
|
||||
if (!lib.has("downloads")) continue;
|
||||
JsonObject dls = lib.getAsJsonObject("downloads");
|
||||
if (dls.has("artifact")) {
|
||||
JsonObject art = dls.getAsJsonObject("artifact");
|
||||
if (art.has("path")) {
|
||||
Path cand = multimcRoot.resolve(art.get("path").getAsString());
|
||||
if (Files.exists(cand)) {
|
||||
li.libraryPaths.add(cand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
li.mainClass = (jObj != null && jObj.has("mainClass"))
|
||||
? jObj.get("mainClass").getAsString()
|
||||
: "net.minecraft.client.main.Main";
|
||||
return Optional.of(li);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class PrismLauncherAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// Prism’s data root is typically ~/.local/share/PrismLauncher on Linux, or OS-specific app data. :contentReference[oaicite:0]{index=0}
|
||||
// You can derive it by walking up from an “instances” folder if gameDir is under instances/.
|
||||
Path p = gameDir;
|
||||
while (p != null && !p.getFileName().toString().equals("instances")) {
|
||||
p = p.getParent();
|
||||
}
|
||||
if (p == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Path prismRoot = p.getParent();
|
||||
if (prismRoot == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
// prismRoot/libraries/com/mojang/minecraft/<version>/minecraft-<version>-client.jar
|
||||
Path libRoot = prismRoot.resolve("libraries");
|
||||
Path mojangRel = Path.of("com", "mojang", "minecraft", version,
|
||||
"minecraft-" + version + "-client.jar");
|
||||
Path candidate = libRoot.resolve(mojangRel);
|
||||
if (Files.exists(candidate)) {
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
li.mcJar = candidate;
|
||||
// Optionally, include other library jars from prismRoot/libraries per version JSON if available
|
||||
li.mainClass = "net.minecraft.client.main.Main";
|
||||
return Optional.of(li);
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package ru.faumaray.adapters;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import ru.faumaray.LaunchInfo;
|
||||
import ru.faumaray.LauncherAdapter;
|
||||
|
||||
public class VanillaLauncherAdapter implements LauncherAdapter {
|
||||
@Override
|
||||
public Optional<LaunchInfo> findLaunchInfo(String version, Path gameDir, String[] args) {
|
||||
// Assume gameDir is or contains the “.minecraft” root (or user passed it)
|
||||
Path versions = gameDir.resolve("versions");
|
||||
Path versionFolder = versions.resolve(version);
|
||||
Path jar = versionFolder.resolve(version + ".jar");
|
||||
Path json = versionFolder.resolve(version + ".json");
|
||||
if (!Files.exists(jar) && !Files.exists(json)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
LaunchInfo li = new LaunchInfo();
|
||||
// If JSON exists, parse downloads.client and libraries
|
||||
JsonObject jObj = null;
|
||||
if (Files.exists(json)) {
|
||||
try (var reader = Files.newBufferedReader(json)) {
|
||||
jObj = new Gson().fromJson(reader, JsonObject.class);
|
||||
if (jObj.has("downloads")) {
|
||||
JsonObject dl = jObj.getAsJsonObject("downloads");
|
||||
if (dl.has("client")) {
|
||||
JsonObject client = dl.getAsJsonObject("client");
|
||||
if (client.has("path")) {
|
||||
Path cand = gameDir.resolve(client.get("path").getAsString());
|
||||
if (Files.exists(cand)) {
|
||||
jar = cand;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
li.mcJar = jar;
|
||||
|
||||
if (jObj != null && jObj.has("libraries")) {
|
||||
for (JsonElement el : jObj.getAsJsonArray("libraries")) {
|
||||
if (!el.isJsonObject()) continue;
|
||||
JsonObject lib = el.getAsJsonObject();
|
||||
if (!lib.has("downloads")) continue;
|
||||
JsonObject dls = lib.getAsJsonObject("downloads");
|
||||
if (dls.has("artifact")) {
|
||||
JsonObject art = dls.getAsJsonObject("artifact");
|
||||
if (art.has("path")) {
|
||||
Path cand = gameDir.resolve(art.get("path").getAsString());
|
||||
if (Files.exists(cand)) {
|
||||
li.libraryPaths.add(cand);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
li.mainClass = (jObj != null && jObj.has("mainClass"))
|
||||
? jObj.get("mainClass").getAsString()
|
||||
: "net.minecraft.client.main.Main";
|
||||
return Optional.of(li);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package ru.faumaray;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest {
|
||||
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@Test
|
||||
public void shouldAnswerWithTrue() {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user