Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into modern
  • Loading branch information
Wyvest committed Nov 18, 2024
2 parents a2ab6ab + b22e1d5 commit 5731d8e
Show file tree
Hide file tree
Showing 70 changed files with 2,273 additions and 1,437 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "org.polyfrost.oneconfig"
version = "1.1.0-alpha.5"
version = "1.1.0-alpha.34"

allprojects {
apply(plugin = "maven-publish")
Expand All @@ -18,7 +18,8 @@ allprojects {

repositories {
mavenCentral()
maven("https://repo.polyfrost.org/releases")
maven("https://repo.polyfrost.org/releases")
maven("https://repo.polyfrost.org/snapshots")
maven("https://maven.neoforged.net/releases")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.net.URL;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.apache.logging.log4j.core.Appender;
Expand All @@ -28,9 +31,13 @@ default void provideLogAppender(Consumer<Appender> appenderConsumer) {
* @since 1.1.0
*/
interface RuntimeAccess {
void appendToClassPath(boolean mod, @NotNull URL @NotNull... urls);
void appendToClassPath(String id, boolean mod, @NotNull URL @NotNull... urls);

ClassLoader getClassLoader();

default Map<String, List<URL>> getAppendedUrls() {
return Collections.emptyMap();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected LoaderBase(
this.capabilities = capabilities;

Logger logger = LogManager.getLogger(getClass());
if (version.equalsIgnoreCase(UNKNOWN_VERSION)) {
if (UNKNOWN_VERSION.equalsIgnoreCase(version)) {
logger.warn("Jar version is unknown, please report this.");
}

Expand Down Expand Up @@ -79,4 +79,10 @@ public Result filter(LogEvent event) {
* Initializes and runs the current loader.
*/
public abstract void load();

public abstract void postLoad();

public static boolean isDevMode() {
return Objects.equals(System.getProperty("oneconfig.loader.dev"), "true");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.polyfrost.oneconfig.loader.relaunch;

import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Field;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface Detection {
void checkRelaunch(String id, List<URL> urls, Field classLoaderExceptionsField, Set<String> classLoaderExceptions, Field transformerExceptionsField, Set<String> transformerExceptions, Field resourceCacheField, Map<String, byte[]> resourceCache, Field negativeResourceCacheField, Set<String> negativeResourceCache) throws Exception;
boolean isRelaunch();
void setRelaunch(boolean relaunch);
@Nullable List<URL> getDetectedUrls();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.polyfrost.oneconfig.loader.relaunch;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

public interface DetectionSupplier {

/**
* Will try to get an instance of {@link DetectionSupplier} using a service loader, otherwise will return a no-op instance.
*
* @author Deftu
* @since 1.1.0-alpha.x
*/
static DetectionSupplier maybeCreate() {
ServiceLoader<DetectionSupplier> loader = ServiceLoader.load(DetectionSupplier.class);
Iterator<DetectionSupplier> iterator = loader.iterator();
if (iterator.hasNext()) {
return iterator.next();
}

return DetectionSupplier.DetectionSupplierNoOp.INSTANCE;
}

List<Detection> createDetectionList();

class DetectionSupplierNoOp implements DetectionSupplier {

public static final DetectionSupplierNoOp INSTANCE = new DetectionSupplierNoOp();

@Override
public List<Detection> createDetectionList() {
return new ArrayList<>(); // No-op
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.polyfrost.oneconfig.loader.relaunch;

import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;

/**
* @author Deftu
* @since 1.1.0-alpha.x
*/
public interface Relaunch {

/**
* Will try to get an instance of {@link Relaunch} using a service loader, otherwise will return a no-op instance.
*
* @author Deftu
* @since 1.1.0-alpha.x
*/
static Relaunch maybeCreate() {
ServiceLoader<Relaunch> loader = ServiceLoader.load(Relaunch.class);
Iterator<Relaunch> iterator = loader.iterator();
if (iterator.hasNext()) {
return iterator.next();
}

return RelaunchNoOp.INSTANCE;
}

/**
* @author Deftu
* @since 1.1.0-alpha.x
*/
void maybeRelaunch(DetectionSupplier detectionSupplier, Map<String, List<URL>> urls);

/**
* @author Deftu
* @since 1.1.0-alpha.x
*/
class RelaunchNoOp implements Relaunch {
public static final RelaunchNoOp INSTANCE = new RelaunchNoOp();

@Override
public void maybeRelaunch(DetectionSupplier detectionSupplier, Map<String, List<URL>> urls) {
// No-op
}
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.polyfrost.oneconfig.loader.utils;
package org.polyfrost.oneconfig.loader.ui;

import lombok.extern.log4j.Log4j2;
import org.jetbrains.annotations.NotNull;
Expand All @@ -24,13 +24,6 @@ public class ErrorHandler {
private static final boolean CENTER_BODY = false;
private static final int ICON_SIZE = 64;

private static final Color GRAY_900 = new Color(13, 14, 15, 255);
private static final Color GRAY_700 = new Color(34, 35, 38);
private static final Color PRIMARY_500 = new Color(26, 103, 255);
private static final Color PRIMARY_500_80 = new Color(26, 103, 204);
private static final Color WHITE_80 = new Color(255, 255, 255, 204);
private static final Color TRANSPARENT = new Color(0, 0, 0, 0);

private ErrorHandler() {
throw new IllegalStateException("This class cannot be instantiated.");
}
Expand Down Expand Up @@ -150,13 +143,13 @@ private static void setSwingStyle() {
}
}

UIManager.put("OptionPane.background", GRAY_900);
UIManager.put("Panel.background", GRAY_900);
UIManager.put("OptionPane.messageForeground", WHITE_80);
UIManager.put("Button.background", PRIMARY_500);
UIManager.put("Button.select", PRIMARY_500_80);
UIManager.put("Button.foreground", WHITE_80);
UIManager.put("Button.focus", TRANSPARENT);
UIManager.put("OptionPane.background", Palette.GRAY_900);
UIManager.put("Panel.background", Palette.GRAY_900);
UIManager.put("OptionPane.messageForeground", Palette.WHITE_80);
UIManager.put("Button.background", Palette.PRIMARY_500);
UIManager.put("Button.select", Palette.PRIMARY_500_80);
UIManager.put("Button.foreground", Palette.WHITE_80);
UIManager.put("Button.focus", Palette.TRANSPARENT);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.polyfrost.oneconfig.loader.ui;

import java.awt.*;

public class Palette {

public static final Color GRAY_900 = new Color(13, 14, 15, 255);
public static final Color GRAY_700 = new Color(34, 35, 38);
public static final Color PRIMARY_500 = new Color(26, 103, 255);
public static final Color PRIMARY_500_80 = new Color(26, 103, 204);
public static final Color WHITE_80 = new Color(255, 255, 255, 204);
public static final Color TRANSPARENT = new Color(0, 0, 0, 0);

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package org.polyfrost.oneconfig.loader.utils;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarInputStream;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Utility class for IO operations.
Expand All @@ -14,6 +22,8 @@
* @since 1.1.0
*/
public class IOUtils {
private static final Pattern VERSION_REGEX = Pattern.compile("(?<major>\\d+).(?<minor>\\d+).?(?<patch>\\d+)?");

private IOUtils() {
throw new IllegalStateException("This class cannot be instantiated.");
}
Expand Down Expand Up @@ -59,4 +69,15 @@ private IOUtils() {
}
}
}

public static byte[] readFully(InputStream inputStream) throws IOException {
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}

return output.toByteArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.apache.logging.log4j.LogManager;

import org.polyfrost.oneconfig.loader.base.LoaderBase;
import org.polyfrost.oneconfig.loader.ui.ErrorHandler;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ shadow = "8.1.1"
lombok = "8.6"

annotations = "24.1.0"
log4j = "2.19.0" # real MC uses older versions of log4j but that doesn't really matter in this case
log4j = "2.0-beta9" # real MC uses older versions of log4j but that doesn't really matter in this case
gson = "2.2.4" # same for Gson, let's use the oldest version to ensure compatibility

[plugins]
Expand Down
7 changes: 7 additions & 0 deletions relaunch/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencies {
implementation(projects.common)
include("org.polyfrost:polyio:0.1.0")

compileOnly("net.minecraft:launchwrapper:1.12")
compileOnly("com.google.guava:guava:17.0")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.polyfrost.oneconfig.loader.relaunch;

import org.polyfrost.oneconfig.loader.relaunch.detection.AsmDetection;
import org.polyfrost.oneconfig.loader.relaunch.detection.ExcludedKotlinDetection;
import org.polyfrost.oneconfig.loader.relaunch.detection.MixinDetection;
import org.polyfrost.oneconfig.loader.relaunch.detection.PreloadLibraryDetection;
import org.polyfrost.oneconfig.loader.relaunch.detection.SignedMixinDetection;

import java.util.ArrayList;
import java.util.List;

public class DetectionSupplierImpl implements DetectionSupplier {

public List<Detection> createDetectionList() {
return new ArrayList<Detection>() {
{
add(new AsmDetection());
add(new ExcludedKotlinDetection());
add(new SignedMixinDetection());
addAll(createComplexPreloadLibraryDetectionList());
add(new PreloadLibraryDetection("org.spongepowered:mixin", "org", "spongepowered"));
add(new MixinDetection());
}
};
}

private List<Detection> createComplexPreloadLibraryDetectionList() {
return new ArrayList<Detection>() {
{
String[][][] paths = {
{{"org.jetbrains.kotlin"}, {"kotlin"}},
{{"org.jetbrains.kotlinx"}, {"kotlinx", "coroutines"}},
{{"org.polyfrost:universalcraft"}, {"org", "polyfrost", "universal"}},
{{"org.polyfrost:polyui"}, {"org", "polyfrost", "polyui"}}
};

for (String[][] path : paths) {
add(new PreloadLibraryDetection(path[0][0], path[1]));
}
}
};
}

}
Loading

0 comments on commit 5731d8e

Please sign in to comment.