Skip to content

Commit 6d45b1a

Browse files
committed
Properly load classpath mods into FoxLoader
1 parent 3176709 commit 6d45b1a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

common/src/main/java/com/fox2code/foxloader/launcher/FoxLauncher.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import javax.swing.*;
77
import java.awt.*;
88
import java.io.File;
9+
import java.net.MalformedURLException;
910
import java.net.URL;
10-
import java.util.HashMap;
11-
import java.util.Objects;
11+
import java.util.*;
1212
import java.util.logging.Logger;
13+
import java.util.regex.Pattern;
1314

1415
public class FoxLauncher {
1516
static {
@@ -44,6 +45,7 @@ public class FoxLauncher {
4445
public static final HashMap<String, Object> mixinProperties = new HashMap<>();
4546
static LauncherType launcherType = LauncherType.UNKNOWN;
4647
private static boolean client, wronglyInstalled, wronglyInstalledUnrecoverable;
48+
private static final LinkedList<File> filesToLoad = new LinkedList<>();
4749
static FoxClassLoader foxClassLoader;
4850
static File gameDir;
4951
public static String initialUsername;
@@ -111,6 +113,7 @@ static void initForClientFromArgs(String[] args) {
111113
foxClassLoader.addTransformerExclusion("com.fox2code.jfallback.");
112114
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
113115
installLoggerHelper(true); // Install special logger before libraries loading
116+
initializeClassPath(); // Initialize class path before libraries loading
114117
DependencyHelper.loadDependencies(true);
115118
}
116119

@@ -159,9 +162,29 @@ static void initForServerFromArgs(String[] args) {
159162
foxClassLoader.addTransformerExclusion("com.fox2code.jfallback.");
160163
foxClassLoader.addTransformerExclusion("com.fox2code.foxloader.loader.");
161164
installLoggerHelper(false); // Install special logger before libraries loading
165+
initializeClassPath(); // Initialize class path before libraries loading
162166
DependencyHelper.loadDependencies(false);
163167
}
164168

169+
private static void initializeClassPath() {
170+
String javaHome = System.getProperty("java.home");
171+
String classPath = System.getProperty("java.class.path");
172+
Pattern pattern = Pattern.compile(File.pathSeparator, Pattern.LITERAL);
173+
for (String path : pattern.split(classPath)) {
174+
if (path.startsWith(javaHome)) continue;
175+
File file = new File(path).getAbsoluteFile();
176+
if (file.isDirectory()) {
177+
try {
178+
foxClassLoader.addURL(file.toURI().toURL());
179+
} catch (MalformedURLException e) {
180+
e.printStackTrace(hasLogger ? System.err : System.out);
181+
}
182+
} else {
183+
filesToLoad.add(file);
184+
}
185+
}
186+
}
187+
165188
private static void installLoggerHelper(boolean client) {
166189
if (hasLogger) return;
167190
boolean installed = false;
@@ -176,6 +199,10 @@ private static void installLoggerHelper(boolean client) {
176199
hasLogger = installed;
177200
}
178201

202+
public static Iterator<File> fileToLoadIterator() {
203+
return filesToLoad.iterator();
204+
}
205+
179206
public static void installLoggerHelperOn(Logger logger) {
180207
if (hasLogger) LoggerHelper.installOn(logger);
181208
}

common/src/main/java/com/fox2code/foxloader/loader/ModLoader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ static void initializeModdedInstance(boolean client) {
113113
coreMods.add(coremod);
114114
}
115115
PreLoader.loadPrePatches(client, true);
116+
Iterator<File> fileIterator = FoxLauncher.fileToLoadIterator();
117+
while (fileIterator.hasNext()) {
118+
File file = fileIterator.next();
119+
if (file.getName().endsWith(".jar")) {
120+
loadModContainerFromJar(file, false);
121+
}
122+
}
116123
for (File mod : Objects.requireNonNull(mods.listFiles(
117124
(dir, name) -> name.endsWith(".jar")))) {
118125
loadModContainerFromJar(mod, false);

0 commit comments

Comments
 (0)