Skip to content

Commit

Permalink
Update 1.2.38
Browse files Browse the repository at this point in the history
  • Loading branch information
Fox2Code committed Jan 26, 2024
1 parent 399275c commit 7df681f
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class MixinMinecraft {
@Unique private boolean closeGameDelayed;
@Unique private boolean showDebugInfoPrevious;

@Inject(method = "run", at = @At("HEAD"))
public void onRun(CallbackInfo ci) {
@Inject(method = "startGame", at = @At("HEAD"))
public void onStartGame(CallbackInfo ci) {
ClientModLoader.Internal.notifyRun();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.fox2code.foxloader.client.mixins;

import com.fox2code.foxloader.updater.UpdateManager;
import net.minecraft.src.client.PanelCrashReport;
import net.minecraft.src.client.UnexpectedThrowable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import javax.swing.*;
import java.awt.*;

@Mixin(PanelCrashReport.class)
public class MixinPanelCrashReport extends Panel {
@Unique JButton updateFoxLoader;

@Inject(method = "<init>", at = @At("RETURN"))
public void onCrash(UnexpectedThrowable var1, CallbackInfo ci) {
this.updateFoxLoader = new JButton("Update FoxLoader");
Dimension dimension = new Dimension(200, 50);
this.updateFoxLoader.setMaximumSize(dimension);
JPanel jPanel = new JPanel();
jPanel.setMinimumSize(dimension);
jPanel.setPreferredSize(dimension);
jPanel.setBackground(null);
jPanel.setLayout(new GridBagLayout());
jPanel.add(this.updateFoxLoader);
this.add(jPanel, BorderLayout.SOUTH);
UpdateManager.getInstance().bindButtonToFoxLoaderUpdate(this.updateFoxLoader);
}
}
1 change: 1 addition & 0 deletions client/src/main/resources/foxloader.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"MixinNetherPortalHandler",
"MixinPacket",
"MixinPacket2Handshake",
"MixinPanelCrashReport",
"MixinPlayerCommandHandler",
"MixinPlayerController",
"MixinPlayerControllerMix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.net.*;
import java.nio.file.Files;
import java.security.NoSuchAlgorithmException;
import java.util.function.Consumer;
import java.util.jar.JarFile;

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

public static File loadDependencyAsFile(Dependency dependency) {
if (mcLibraries == null) {
if (FoxLauncher.foxClassLoader != null) {
// We should never reach here...
throw new IllegalStateException("FoxLoader DependencyHelper didn't initialized properly");
}
setMCLibraryRoot();
}
return loadDependencyImpl(dependency, false, true);
}

Expand All @@ -276,7 +283,6 @@ public static void loadDependencySelf(Dependency dependency) {
dependency.classCheck.replace('.', '/') + ".class") != null) {
return; // Great news, we already have the library loaded!
}
if (mcLibraries == null) setMCLibraryRoot();
File file = loadDependencyAsFile(dependency);
if (file == null) {
// If null it means it's already in class path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
import org.spongepowered.asm.mixin.Mixins;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.logging.Level;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fox2code.foxloader.launcher.BuildConfig;
import com.fox2code.foxloader.launcher.FoxClassLoader;
import com.fox2code.foxloader.launcher.FoxLauncher;
import com.fox2code.foxloader.launcher.utils.Platform;
import com.fox2code.foxloader.launcher.utils.SourceUtil;
import com.fox2code.foxloader.loader.rebuild.ClassDataProvider;
import com.fox2code.foxloader.loader.transformer.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.fox2code.foxloader.loader.ModLoader;
import com.fox2code.foxloader.network.ChatColors;

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

private final HashMap<String, AbstractUpdater> modsToUpdater = new HashMap<>();
private final LinkedList<Function<ModContainer, AbstractUpdater>> providers = new LinkedList<>();
private WeakReference<JButton> foxLoaderUpdateButton;
private boolean initialized = false;
private boolean hasUpdates = false;
private boolean checkingUpdates = false;
private boolean hasCheckedUpdates = false;

private UpdateManager() {}

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

public void bindButtonToFoxLoaderUpdate(JButton button) {
button.setEnabled(this.hasUpdate("foxloader"));
this.foxLoaderUpdateButton = new WeakReference<>(button);
// This is used in error screen, which means we may need to initialize stuff here
if (!this.initialized) {
this.initialize();
}
if (!this.hasCheckedUpdates) {
this.checkUpdates();
}
}

public void checkUpdates() {
if (this.checkingUpdates) return;
this.hasCheckedUpdates = true;
new Thread(this::checkUpdates0, "FoxLoader - Update Checker Thread").start();
}

Expand Down Expand Up @@ -97,19 +114,36 @@ private synchronized void checkUpdates0() {
}
this.hasUpdates = hasUpdates;
this.checkingUpdates = false;
AbstractUpdater abstractUpdater = modsToUpdater.get("foxloader");
// If FoxLoader is wrongly installed, try to fix it
if (FoxLauncher.isWronglyInstalled() &&
FoxLauncher.getLauncherType().hasAutoFix) {
System.out.println("It look like you were too incompetent to install FoxLoader properly");
System.out.println("But don't worry, FoxLoader will install itself properly on the current instance");
AbstractUpdater abstractUpdater = modsToUpdater.get("foxloader");
if (abstractUpdater != null) {
try {
abstractUpdater.doUpdate();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
final JButton button = this.foxLoaderUpdateButton == null ?
null : this.foxLoaderUpdateButton.get();
if (button != null) {
boolean hasUpdate = this.hasUpdate("foxloader");
button.setEnabled(hasUpdate);
if (hasUpdate) {
button.addActionListener(event -> {
button.setEnabled(false);
try {
abstractUpdater.doUpdate();
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
}
}

Expand Down
61 changes: 40 additions & 21 deletions dev/src/main/groovy/com/fox2code/foxloader/dev/GradlePlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import java.util.jar.JarFile
class GradlePlugin implements Plugin<Project> {
private static FoxLoaderDecompilerHelper decompilerHelper
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create()
private static final Object decompileLock = new Object()
private File foxLoaderCache
private File foxLoaderData

Expand Down Expand Up @@ -383,13 +384,31 @@ class GradlePlugin implements Plugin<Project> {
PreLoader.patchReIndevForDev(jar, jarFox, client)
}
if (config.decompileSources && decompilerHelper != null) {
File unpickedJarFox = new File(foxLoaderCache,
"net/silveros/" + sideName + "/" + versionFox + "/" +
sideName + "-" + versionFox + "-unpicked.jar")
File sourcesJarFox = new File(foxLoaderCache,
"net/silveros/" + sideName + "/" + versionFox + "/" +
sideName + "-" + versionFox + "-sources.jar")
if (config.forceReload && sourcesJarFox.exists()) sourcesJarFox.delete()
decompileSide(foxLoaderCache, config, client, versionFox, jarFox)
}
if (client) {
project.dependencies {
clientImplementation("net.silveros:" + sideName + ":${versionFox}")
}
} else {
project.dependencies {
serverImplementation("net.silveros:" + sideName + ":${versionFox}")
}
}
}

private static void decompileSide(File foxLoaderCache, FoxLoaderConfig config, boolean client,
String versionFox, File jarFox) {
final String sideName = client ? "reindev" : "reindev-server"
final String logSideName = client ? "client" : "server"
File unpickedJarFox = new File(foxLoaderCache,
"net/silveros/" + sideName + "/" + versionFox + "/" +
sideName + "-" + versionFox + "-unpicked.jar")
File sourcesJarFox = new File(foxLoaderCache,
"net/silveros/" + sideName + "/" + versionFox + "/" +
sideName + "-" + versionFox + "-sources.jar")
if (config.forceReload && sourcesJarFox.exists()) sourcesJarFox.delete()
synchronized (decompileLock) {
if (!jarFileExists(sourcesJarFox)) {
closeJarFileSystem(unpickedJarFox)
if (unpickedJarFox.exists()) unpickedJarFox.delete()
Expand Down Expand Up @@ -446,20 +465,18 @@ class GradlePlugin implements Plugin<Project> {
}
throw throwable
}
}
}
if (client) {
project.dependencies {
clientImplementation("net.silveros:" + sideName + ":${versionFox}")
}
} else {
project.dependencies {
serverImplementation("net.silveros:" + sideName + ":${versionFox}")
// Close not critical there, as if close fails, it's still not a big issue
closeJarFileSystem(unpickedJarFox, false)
closeJarFileSystem(sourcesJarFox, false)
}
}
}

static void closeJarFileSystem(File file) {
closeJarFileSystem(file, true)
}

static void closeJarFileSystem(File file, boolean critical) {
URI uri = new URI("jar:file", null, file.toURI().getPath(), null)
FileSystem fileSystem = null
try {
Expand All @@ -470,11 +487,13 @@ class GradlePlugin implements Plugin<Project> {
try {
Files.exists(fileSystem.getPath("META-INF/MANIFEST.MF"))
} catch (ClosedFileSystemException e) {
terminateProcess()
Throwable root = e
while (root.getCause() != null) root = root.getCause()
if (!(root instanceof UserMessage)) {
root.initCause(UserMessage.UNRECOVERABLE_STATE_DECOMPILE)
if (critical) {
terminateProcess()
Throwable root = e
while (root.getCause() != null) root = root.getCause()
if (!(root instanceof UserMessage)) {
root.initCause(UserMessage.UNRECOVERABLE_STATE_DECOMPILE)
}
}
throw e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public void installBetaCraftEx(File betaCraft) {
printStream.println("addons:");
}
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/betacraft-" + BuildConfig.FOXLOADER_VERSION + ".jar"),
"/betacraft-" + BuildConfig.FOXLOADER_VERSION + ".jar"),
Files.newOutputStream(foxLoaderBetaCraft.toPath()));
} catch (IOException e) {
showError(e);
Expand Down Expand Up @@ -499,7 +499,7 @@ public void doSilentInstall(String arg) throws IOException {
for (String entry : new String[]{ // Fix in place replace!
"patches/net.minecraft.json", "patches/net.minecraftforge.json"}) {
IOUtils.copyAndClose(InstallerGUI.class.getResourceAsStream(
"/mmc/patches/com.fox2code.foxloader.json"),
"/mmc/patches/com.fox2code.foxloader.json"),
Files.newOutputStream(new File(entry).toPath()));
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.parallel=true
org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8

# FoxLoader properties
foxloader.version=1.2.37
foxloader.version=1.2.38
foxloader.lastReIndevTransformerChanges=1.2.37
# https://www.jitpack.io/#com.fox2code/FoxLoader

Expand Down

0 comments on commit 7df681f

Please sign in to comment.