Skip to content

Commit 7df681f

Browse files
committed
Update 1.2.38
1 parent 399275c commit 7df681f

File tree

10 files changed

+122
-33
lines changed

10 files changed

+122
-33
lines changed

client/src/main/java/com/fox2code/foxloader/client/mixins/MixinMinecraft.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public class MixinMinecraft {
3333
@Unique private boolean closeGameDelayed;
3434
@Unique private boolean showDebugInfoPrevious;
3535

36-
@Inject(method = "run", at = @At("HEAD"))
37-
public void onRun(CallbackInfo ci) {
36+
@Inject(method = "startGame", at = @At("HEAD"))
37+
public void onStartGame(CallbackInfo ci) {
3838
ClientModLoader.Internal.notifyRun();
3939
}
4040

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fox2code.foxloader.client.mixins;
2+
3+
import com.fox2code.foxloader.updater.UpdateManager;
4+
import net.minecraft.src.client.PanelCrashReport;
5+
import net.minecraft.src.client.UnexpectedThrowable;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Unique;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
import javax.swing.*;
13+
import java.awt.*;
14+
15+
@Mixin(PanelCrashReport.class)
16+
public class MixinPanelCrashReport extends Panel {
17+
@Unique JButton updateFoxLoader;
18+
19+
@Inject(method = "<init>", at = @At("RETURN"))
20+
public void onCrash(UnexpectedThrowable var1, CallbackInfo ci) {
21+
this.updateFoxLoader = new JButton("Update FoxLoader");
22+
Dimension dimension = new Dimension(200, 50);
23+
this.updateFoxLoader.setMaximumSize(dimension);
24+
JPanel jPanel = new JPanel();
25+
jPanel.setMinimumSize(dimension);
26+
jPanel.setPreferredSize(dimension);
27+
jPanel.setBackground(null);
28+
jPanel.setLayout(new GridBagLayout());
29+
jPanel.add(this.updateFoxLoader);
30+
this.add(jPanel, BorderLayout.SOUTH);
31+
UpdateManager.getInstance().bindButtonToFoxLoaderUpdate(this.updateFoxLoader);
32+
}
33+
}

client/src/main/resources/foxloader.client.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"MixinNetherPortalHandler",
3232
"MixinPacket",
3333
"MixinPacket2Handshake",
34+
"MixinPanelCrashReport",
3435
"MixinPlayerCommandHandler",
3536
"MixinPlayerController",
3637
"MixinPlayerControllerMix",

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import java.net.*;
1212
import java.nio.file.Files;
1313
import java.security.NoSuchAlgorithmException;
14-
import java.util.function.Consumer;
1514
import java.util.jar.JarFile;
1615

1716
public class DependencyHelper {
@@ -156,6 +155,7 @@ private static File loadDependencyImpl(Dependency dependency, boolean minecraft,
156155
if (!dev && hasClass(dependency.classCheck)) return null;
157156
String postURL = resolvePostURL(dependency.name);
158157
File file = new File(mcLibraries, fixUpPath(postURL));
158+
if (!file.isAbsolute()) file = file.getAbsoluteFile();
159159
boolean justDownloaded = false;
160160
checkHashOrDelete(file, dependency, false);
161161
if (!file.exists()) {
@@ -266,6 +266,13 @@ static void addToClassPath(final File library) {
266266
}
267267

268268
public static File loadDependencyAsFile(Dependency dependency) {
269+
if (mcLibraries == null) {
270+
if (FoxLauncher.foxClassLoader != null) {
271+
// We should never reach here...
272+
throw new IllegalStateException("FoxLoader DependencyHelper didn't initialized properly");
273+
}
274+
setMCLibraryRoot();
275+
}
269276
return loadDependencyImpl(dependency, false, true);
270277
}
271278

@@ -276,7 +283,6 @@ public static void loadDependencySelf(Dependency dependency) {
276283
dependency.classCheck.replace('.', '/') + ".class") != null) {
277284
return; // Great news, we already have the library loaded!
278285
}
279-
if (mcLibraries == null) setMCLibraryRoot();
280286
File file = loadDependencyAsFile(dependency);
281287
if (file == null) {
282288
// If null it means it's already in class path.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,10 @@
1313
import org.spongepowered.asm.mixin.Mixins;
1414
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
1515

16-
import java.io.IOException;
1716
import java.io.InputStream;
1817
import java.io.InputStreamReader;
19-
import java.net.URL;
2018
import java.nio.charset.StandardCharsets;
2119
import java.util.HashMap;
22-
import java.util.HashSet;
2320
import java.util.logging.Level;
2421

2522
/**

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fox2code.foxloader.launcher.BuildConfig;
44
import com.fox2code.foxloader.launcher.FoxClassLoader;
55
import com.fox2code.foxloader.launcher.FoxLauncher;
6-
import com.fox2code.foxloader.launcher.utils.Platform;
76
import com.fox2code.foxloader.launcher.utils.SourceUtil;
87
import com.fox2code.foxloader.loader.rebuild.ClassDataProvider;
98
import com.fox2code.foxloader.loader.transformer.*;

common/src/main/java/com/fox2code/foxloader/updater/UpdateManager.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import com.fox2code.foxloader.loader.ModLoader;
77
import com.fox2code.foxloader.network.ChatColors;
88

9+
import javax.swing.*;
910
import java.io.IOException;
11+
import java.lang.ref.WeakReference;
1012
import java.net.InetAddress;
1113
import java.net.UnknownHostException;
1214
import java.util.HashMap;
@@ -23,9 +25,11 @@ public static UpdateManager getInstance() {
2325

2426
private final HashMap<String, AbstractUpdater> modsToUpdater = new HashMap<>();
2527
private final LinkedList<Function<ModContainer, AbstractUpdater>> providers = new LinkedList<>();
28+
private WeakReference<JButton> foxLoaderUpdateButton;
2629
private boolean initialized = false;
2730
private boolean hasUpdates = false;
2831
private boolean checkingUpdates = false;
32+
private boolean hasCheckedUpdates = false;
2933

3034
private UpdateManager() {}
3135

@@ -63,8 +67,21 @@ public void registerProvider(Function<ModContainer, AbstractUpdater> provider) {
6367
this.providers.add(provider);
6468
}
6569

70+
public void bindButtonToFoxLoaderUpdate(JButton button) {
71+
button.setEnabled(this.hasUpdate("foxloader"));
72+
this.foxLoaderUpdateButton = new WeakReference<>(button);
73+
// This is used in error screen, which means we may need to initialize stuff here
74+
if (!this.initialized) {
75+
this.initialize();
76+
}
77+
if (!this.hasCheckedUpdates) {
78+
this.checkUpdates();
79+
}
80+
}
81+
6682
public void checkUpdates() {
6783
if (this.checkingUpdates) return;
84+
this.hasCheckedUpdates = true;
6885
new Thread(this::checkUpdates0, "FoxLoader - Update Checker Thread").start();
6986
}
7087

@@ -97,19 +114,36 @@ private synchronized void checkUpdates0() {
97114
}
98115
this.hasUpdates = hasUpdates;
99116
this.checkingUpdates = false;
117+
AbstractUpdater abstractUpdater = modsToUpdater.get("foxloader");
100118
// If FoxLoader is wrongly installed, try to fix it
101119
if (FoxLauncher.isWronglyInstalled() &&
102120
FoxLauncher.getLauncherType().hasAutoFix) {
103121
System.out.println("It look like you were too incompetent to install FoxLoader properly");
104122
System.out.println("But don't worry, FoxLoader will install itself properly on the current instance");
105-
AbstractUpdater abstractUpdater = modsToUpdater.get("foxloader");
106123
if (abstractUpdater != null) {
107124
try {
108125
abstractUpdater.doUpdate();
109126
} catch (IOException e) {
110127
e.printStackTrace();
111128
}
112129
}
130+
} else {
131+
final JButton button = this.foxLoaderUpdateButton == null ?
132+
null : this.foxLoaderUpdateButton.get();
133+
if (button != null) {
134+
boolean hasUpdate = this.hasUpdate("foxloader");
135+
button.setEnabled(hasUpdate);
136+
if (hasUpdate) {
137+
button.addActionListener(event -> {
138+
button.setEnabled(false);
139+
try {
140+
abstractUpdater.doUpdate();
141+
} catch (IOException e) {
142+
e.printStackTrace();
143+
}
144+
});
145+
}
146+
}
113147
}
114148
}
115149

dev/src/main/groovy/com/fox2code/foxloader/dev/GradlePlugin.groovy

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import java.util.jar.JarFile
3131
class GradlePlugin implements Plugin<Project> {
3232
private static FoxLoaderDecompilerHelper decompilerHelper
3333
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create()
34+
private static final Object decompileLock = new Object()
3435
private File foxLoaderCache
3536
private File foxLoaderData
3637

@@ -383,13 +384,31 @@ class GradlePlugin implements Plugin<Project> {
383384
PreLoader.patchReIndevForDev(jar, jarFox, client)
384385
}
385386
if (config.decompileSources && decompilerHelper != null) {
386-
File unpickedJarFox = new File(foxLoaderCache,
387-
"net/silveros/" + sideName + "/" + versionFox + "/" +
388-
sideName + "-" + versionFox + "-unpicked.jar")
389-
File sourcesJarFox = new File(foxLoaderCache,
390-
"net/silveros/" + sideName + "/" + versionFox + "/" +
391-
sideName + "-" + versionFox + "-sources.jar")
392-
if (config.forceReload && sourcesJarFox.exists()) sourcesJarFox.delete()
387+
decompileSide(foxLoaderCache, config, client, versionFox, jarFox)
388+
}
389+
if (client) {
390+
project.dependencies {
391+
clientImplementation("net.silveros:" + sideName + ":${versionFox}")
392+
}
393+
} else {
394+
project.dependencies {
395+
serverImplementation("net.silveros:" + sideName + ":${versionFox}")
396+
}
397+
}
398+
}
399+
400+
private static void decompileSide(File foxLoaderCache, FoxLoaderConfig config, boolean client,
401+
String versionFox, File jarFox) {
402+
final String sideName = client ? "reindev" : "reindev-server"
403+
final String logSideName = client ? "client" : "server"
404+
File unpickedJarFox = new File(foxLoaderCache,
405+
"net/silveros/" + sideName + "/" + versionFox + "/" +
406+
sideName + "-" + versionFox + "-unpicked.jar")
407+
File sourcesJarFox = new File(foxLoaderCache,
408+
"net/silveros/" + sideName + "/" + versionFox + "/" +
409+
sideName + "-" + versionFox + "-sources.jar")
410+
if (config.forceReload && sourcesJarFox.exists()) sourcesJarFox.delete()
411+
synchronized (decompileLock) {
393412
if (!jarFileExists(sourcesJarFox)) {
394413
closeJarFileSystem(unpickedJarFox)
395414
if (unpickedJarFox.exists()) unpickedJarFox.delete()
@@ -446,20 +465,18 @@ class GradlePlugin implements Plugin<Project> {
446465
}
447466
throw throwable
448467
}
449-
}
450-
}
451-
if (client) {
452-
project.dependencies {
453-
clientImplementation("net.silveros:" + sideName + ":${versionFox}")
454-
}
455-
} else {
456-
project.dependencies {
457-
serverImplementation("net.silveros:" + sideName + ":${versionFox}")
468+
// Close not critical there, as if close fails, it's still not a big issue
469+
closeJarFileSystem(unpickedJarFox, false)
470+
closeJarFileSystem(sourcesJarFox, false)
458471
}
459472
}
460473
}
461474

462475
static void closeJarFileSystem(File file) {
476+
closeJarFileSystem(file, true)
477+
}
478+
479+
static void closeJarFileSystem(File file, boolean critical) {
463480
URI uri = new URI("jar:file", null, file.toURI().getPath(), null)
464481
FileSystem fileSystem = null
465482
try {
@@ -470,11 +487,13 @@ class GradlePlugin implements Plugin<Project> {
470487
try {
471488
Files.exists(fileSystem.getPath("META-INF/MANIFEST.MF"))
472489
} catch (ClosedFileSystemException e) {
473-
terminateProcess()
474-
Throwable root = e
475-
while (root.getCause() != null) root = root.getCause()
476-
if (!(root instanceof UserMessage)) {
477-
root.initCause(UserMessage.UNRECOVERABLE_STATE_DECOMPILE)
490+
if (critical) {
491+
terminateProcess()
492+
Throwable root = e
493+
while (root.getCause() != null) root = root.getCause()
494+
if (!(root instanceof UserMessage)) {
495+
root.initCause(UserMessage.UNRECOVERABLE_STATE_DECOMPILE)
496+
}
478497
}
479498
throw e
480499
}

final/src/main/java/com/fox2code/foxloader/installer/InstallerGUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public void installBetaCraftEx(File betaCraft) {
357357
printStream.println("addons:");
358358
}
359359
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
360-
"/betacraft-" + BuildConfig.FOXLOADER_VERSION + ".jar"),
360+
"/betacraft-" + BuildConfig.FOXLOADER_VERSION + ".jar"),
361361
Files.newOutputStream(foxLoaderBetaCraft.toPath()));
362362
} catch (IOException e) {
363363
showError(e);
@@ -499,7 +499,7 @@ public void doSilentInstall(String arg) throws IOException {
499499
for (String entry : new String[]{ // Fix in place replace!
500500
"patches/net.minecraft.json", "patches/net.minecraftforge.json"}) {
501501
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
502-
"/mmc/patches/com.fox2code.foxloader.json"),
502+
"/mmc/patches/com.fox2code.foxloader.json"),
503503
Files.newOutputStream(new File(entry).toPath()));
504504
}
505505
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.parallel=true
33
org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8
44

55
# FoxLoader properties
6-
foxloader.version=1.2.37
6+
foxloader.version=1.2.38
77
foxloader.lastReIndevTransformerChanges=1.2.37
88
# https://www.jitpack.io/#com.fox2code/FoxLoader
99

0 commit comments

Comments
 (0)