feat: Shadowable deploader

This commit is contained in:
FalsePattern committed 2025-11-13 06:29:03 +01:00
1 parent 1adafe57ad
commit 2c329d11cf
23 files changed
+2169 -1135

No files matched your search

+82
View File
@@ -47,6 +47,88 @@ minecraft_fp {
}
}
val java8Compiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(8)
vendor = JvmVendorSpec.ADOPTIUM
}
fun createSourceSet(name: String, shareDeps: Boolean): SourceSet {
val set = sourceSets.create(name) {
if (shareDeps) {
compileClasspath += sourceSets["patchedMc"].output
}
}
tasks.named<JavaCompile>(set.compileJavaTaskName).configure {
javaCompiler = java8Compiler
}
afterEvaluate {
tasks.named<JavaCompile>(set.compileJavaTaskName).configure {
this.sourceCompatibility = "8"
this.targetCompatibility = "8"
this.options.release = null
}
}
if (shareDeps) {
configurations.named(set.compileClasspathConfigurationName) {
extendsFrom(configurations.getByName("compileClasspath"))
exclude("com.falsepattern", "falsepatternlib-mc1.7.10")
}
configurations.named(set.runtimeClasspathConfigurationName) {
extendsFrom(configurations.getByName("runtimeClasspath"))
exclude("com.falsepattern", "falsepatternlib-mc1.7.10")
}
configurations.named(set.annotationProcessorConfigurationName) {
extendsFrom(configurations.getByName("annotationProcessor"))
exclude("com.falsepattern", "falsepatternlib-mc1.7.10")
}
}
return set
}
val depLoader = createSourceSet("deploader", true)
val depLoaderJar = tasks.register<Jar>(depLoader.jarTaskName) {
from(depLoader.output)
archiveBaseName = "falsepatternlib-mc1.7.10"
archiveVersion = minecraft_fp.mod.version
archiveClassifier = "deploader"
manifest {
attributes("FPLib-Deploader-Version" to "1")
}
}
val depLoaderStub = createSourceSet("deploaderStub", true)
val depLoaderStubJar = tasks.register<Jar>(depLoaderStub.jarTaskName) {
from(depLoaderStub.output)
archiveBaseName = "falsepatternlib-mc1.7.10"
archiveVersion = minecraft_fp.mod.version
archiveClassifier = "deploader_stub"
}
sourceSets["main"].compileClasspath += depLoader.output
sourceSets["main"].compileClasspath += depLoaderStub.output
afterEvaluate {
for (outgoingConfig in listOf("runtimeElements", "apiElements")) {
val outgoing = configurations.getByName(outgoingConfig)
outgoing.outgoing.artifact(depLoaderStubJar)
outgoing.outgoing.artifact(depLoaderJar)
}
}
tasks.jar {
dependsOn(depLoaderJar, depLoaderStubJar)
from(depLoaderJar.map { it.archiveFile }) {
rename { "fplib_deploader.jar" }
}
from(zipTree(depLoaderStubJar.map { it.archiveFile })) {
exclude("META-INF/MANIFEST.MF")
}
}
repositories {
exclusive(maven("horizon", "https://mvn.falsepattern.com/horizon/"), "com.gtnewhorizons.retrofuturabootstrap")
exclusive(horizon()) {
@@ -0,0 +1,56 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader;
import com.gtnewhorizons.retrofuturabootstrap.RfbApiImpl;
import lombok.val;
import net.minecraft.launchwrapper.Launch;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.Side;
import java.net.URLClassLoader;
import java.nio.file.Path;
public class Bootstrap {
public static Path MINECRAFT_HOME_PATH;
public static void bootstrap(boolean rfb, Path homePath) {
MINECRAFT_HOME_PATH = homePath;
if (rfb) {
val loader = RfbApiImpl.INSTANCE.launchClassLoader();
PreShare.initDevState(((URLClassLoader)loader).findResource("net/minecraft/world/World.class") != null);
PreShare.initClientState(((URLClassLoader)loader).findResource("net/minecraft/client/Minecraft.class") != null ||
((URLClassLoader)loader).findResource("bao.class") != null);
LowLevelCallMultiplexer.rfbDetected();
} else {
PreShare.initDevState(Launch.classLoader.findResource("net/minecraft/world/World.class") != null);
PreShare.initClientState(FMLLaunchHandler.side() == Side.CLIENT);
}
LetsEncryptHelper.replaceSSLContext();
}
public static void runDepLoader() {
DependencyLoaderImpl.executeDependencyLoading();
}
}
@@ -20,7 +20,7 @@
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.impl.dependencies;
package com.falsepattern.deploader;
import com.google.gson.annotations.Expose;
import lombok.Data;
File diff suppressed because it is too large. Load diff
@@ -20,15 +20,14 @@
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.config;
package com.falsepattern.deploader;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.core.LowLevelCallMultiplexer;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.val;
import lombok.var;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
@@ -49,7 +48,7 @@ public class EarlyConfig {
private static volatile EarlyConfig instance = null;
private static final Logger LOG = LogManager.getLogger(Tags.MODNAME + " Early Config");
private static final Logger LOG = LogManager.getLogger("FalsePatternLib Deploader Early Config");
public static @NotNull EarlyConfig getInstance() {
val config = instance;
@@ -19,9 +19,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
package com.falsepattern.deploader;
import lombok.val;
import lombok.var;
import net.minecraft.launchwrapper.Launch;
@@ -69,10 +70,7 @@ public class Internet {
connection.setConnectTimeout(3500);
connection.setReadTimeout(5000);
connection.setRequestProperty("User-Agent",
Tags.MODNAME
+ " "
+ Tags.VERSION
+ " Internet Connector"
"FalsePatternLib DepLoader Internet Connector"
+ " (https://github.com/FalsePattern/FalsePatternLib)");
for (val header : headers.entrySet()) {
val key = header.getKey();
@@ -20,10 +20,8 @@
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.impl.dependencies;
package com.falsepattern.deploader;
import com.falsepattern.lib.internal.FPLog;
import com.falsepattern.lib.internal.config.EarlyConfig;
import lombok.val;
import javax.net.ssl.SSLContext;
@@ -47,14 +45,14 @@ public class LetsEncryptHelper {
@SuppressWarnings("java:S6437")
public static void replaceSSLContext() {
if (!EarlyConfig.getInstance().enableLetsEncryptRoot()) {
FPLog.LOG.info("[LetsEncryptHelper] Disabled by config");
DependencyLoaderImpl.LOG.info("[LetsEncryptHelper] Disabled by config");
return;
}
if (patched) {
FPLog.LOG.info("[LetsEncryptHelper] Already patched");
DependencyLoaderImpl.LOG.info("[LetsEncryptHelper] Already patched");
return;
}
FPLog.LOG.info("[LetsEncryptHelper] Starting patcher");
DependencyLoaderImpl.LOG.info("[LetsEncryptHelper] Starting patcher");
patched = true;
try (val x1 = LetsEncryptHelper.class.getResourceAsStream("/letsencrypt/isrgrootx1.pem");
@@ -76,13 +74,13 @@ public class LetsEncryptHelper {
val sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
SSLContext.setDefault(sslContext);
FPLog.LOG.info("[LetsEncryptHelper] Added certificates to trust store.");
DependencyLoaderImpl.LOG.info("[LetsEncryptHelper] Added certificates to trust store.");
} catch (IOException e) {
FPLog.LOG.error("[LetsEncryptHelper] Failed to load certificates from classpath.", e);
DependencyLoaderImpl.LOG.error("[LetsEncryptHelper] Failed to load certificates from classpath.", e);
} catch (GeneralSecurityException e) {
FPLog.LOG.error("[LetsEncryptHelper] Failed to load default keystore.", e);
DependencyLoaderImpl.LOG.error("[LetsEncryptHelper] Failed to load default keystore.", e);
} catch (Throwable t) {
FPLog.LOG.error("[LetsEncryptHelper] Unknown error", t);
DependencyLoaderImpl.LOG.error("[LetsEncryptHelper] Unknown error", t);
throw t;
}
}
@@ -0,0 +1,155 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader;
import com.falsepattern.deploader.version.Version;
import lombok.NonNull;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
/**
* @since 0.10.0
*/
public class Library {
@NonNull
public final String loadingModId;
@NonNull
public final String groupId;
@NonNull
public final String artifactId;
@NonNull
public final Version minVersion;
@Nullable
public final Version maxVersion;
@NonNull
public final Version preferredVersion;
@Nullable
public final String regularSuffix;
@Nullable
public final String devSuffix;
public Library(@NonNull String loadingModId, @NonNull String groupId, @NonNull String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String regularSuffix, String devSuffix) {
this.loadingModId = loadingModId;
this.groupId = groupId;
this.artifactId = artifactId;
this.minVersion = minVersion;
this.maxVersion = maxVersion;
this.preferredVersion = preferredVersion;
this.regularSuffix = regularSuffix;
this.devSuffix = devSuffix;
}
public static LibraryBuilder builder() {
return new LibraryBuilder();
}
/**
* @since 0.10.0
*/
public static class LibraryBuilder {
private String loadingModId;
private String groupId;
private String artifactId;
private Version minVersion;
private Version maxVersion;
private Version preferredVersion;
private String regularSuffix;
private String devSuffix;
@ApiStatus.Internal
LibraryBuilder() {
}
public LibraryBuilder loadingModId(@NonNull String loadingModId) {
this.loadingModId = loadingModId;
return this;
}
public LibraryBuilder groupId(@NonNull String groupId) {
this.groupId = groupId;
return this;
}
public LibraryBuilder artifactId(@NonNull String artifactId) {
this.artifactId = artifactId;
return this;
}
public LibraryBuilder minVersion(@NonNull Version minVersion) {
this.minVersion = minVersion;
return this;
}
public LibraryBuilder maxVersion(Version maxVersion) {
this.maxVersion = maxVersion;
return this;
}
public LibraryBuilder preferredVersion(@NonNull Version preferredVersion) {
this.preferredVersion = preferredVersion;
return this;
}
public LibraryBuilder regularSuffix(String regularSuffix) {
this.regularSuffix = regularSuffix;
return this;
}
public LibraryBuilder devSuffix(String devSuffix) {
this.devSuffix = devSuffix;
return this;
}
public Library build() {
return new Library(loadingModId,
groupId,
artifactId,
minVersion,
maxVersion,
preferredVersion,
regularSuffix,
devSuffix);
}
@Override
public String toString() {
return "Library.LibraryBuilder(loadingModId="
+ this.loadingModId
+ ", groupId="
+ this.groupId
+ ", artifactId="
+ this.artifactId
+ ", minVersion="
+ this.minVersion
+ ", maxVersion="
+ this.maxVersion
+ ", preferredVersion="
+ this.preferredVersion
+ ", regularSuffix="
+ this.regularSuffix
+ ", devSuffix="
+ this.devSuffix
+ ")";
}
}
}
@@ -20,7 +20,7 @@
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.core;
package com.falsepattern.deploader;
import com.gtnewhorizons.retrofuturabootstrap.RfbApiImpl;
import lombok.experimental.UtilityClass;
@@ -20,7 +20,7 @@
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.asm;
package com.falsepattern.deploader;
public class PreShare {
private static volatile int devEnv = -1;
@@ -20,14 +20,9 @@
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal.impl.dependencies;
package com.falsepattern.deploader;
public class Pair<A, B> {
public final A a;
public final B b;
public Pair(A a, B b) {
this.a = a;
this.b = b;
}
public class Share {
public static final boolean DEV_ENV = PreShare.devEnv();
public static final boolean CLIENT = PreShare.client();
}
@@ -0,0 +1,26 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
@ApiStatus.Internal
package com.falsepattern.deploader;
import org.jetbrains.annotations.ApiStatus;
@@ -0,0 +1,78 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader.version;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.stream.Collectors;
public class ComplexVersion extends Version {
public final Version[] versions;
public ComplexVersion(@NotNull Version mainVersion, Version... subVersions) {
this.versions = new Version[subVersions.length + 1];
this.versions[0] = mainVersion;
System.arraycopy(subVersions, 0, this.versions, 1, subVersions.length);
}
public ComplexVersion(Version[] versions) {
this.versions = versions;
}
@Override
public int compareTo(@NotNull Version o) {
if (o instanceof ComplexVersion) {
val other = (ComplexVersion) o;
int count = Math.min(versions.length, other.versions.length);
for (int i = 0; i < count; i++) {
val result = versions[i].compareTo(other.versions[i]);
if (result != 0) {
return result;
}
}
if (versions.length != other.versions.length) {
return versions.length - other.versions.length;
} else {
return 0;
}
} else if (o instanceof SemanticVersion) {
val other = (SemanticVersion) o;
val result = versions[0].compareTo(other);
if (result != 0) {
return result;
}
if (versions.length > 1) {
return -1;
}
return 0;
} else {
throw new IllegalArgumentException("Could not compare version with class " + o.getClass().getName());
}
}
@Override
public String toString() {
return Arrays.stream(versions).map(Version::toString).collect(Collectors.joining("-"));
}
}
@@ -0,0 +1,51 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader.version;
import org.jetbrains.annotations.NotNull;
public class RawVersion extends Version {
public final String versionString;
public RawVersion(String versionString) {
this.versionString = versionString;
}
@Override
public int compareTo(@NotNull Version o) {
if (o instanceof RawVersion) {
return versionString.compareTo(((RawVersion) o).versionString);
} else if (o instanceof SemanticVersion) {
return 1;
} else if (o instanceof ComplexVersion) {
return 1;
} else {
throw new IllegalArgumentException("Unknown version type: " + o.getClass().getName());
}
}
@Override
public String toString() {
return versionString;
}
}
@@ -0,0 +1,180 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader.version;
import lombok.Getter;
import lombok.val;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class SemanticVersion extends Version {
@Getter
private final int majorVersion;
@Getter
private final int minorVersion;
@Getter
private final int patchVersion;
@Getter
private final String preRelease;
@Getter
private final String build;
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, String preRelease, String build) {
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
this.patchVersion = patchVersion;
preRelease = preRelease == null ? null : preRelease.trim();
build = build == null ? null : build.trim();
this.preRelease = "".equals(preRelease) ? null : preRelease;
this.build = "".equals(build) ? null : build;
}
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion, String preRelease) {
this(majorVersion, minorVersion, patchVersion, preRelease, null);
}
public SemanticVersion(int majorVersion, int minorVersion, int patchVersion) {
this(majorVersion, minorVersion, patchVersion, null, null);
}
/**
* @since 0.10.0
*/
public SemanticVersion(int majorVersion, int minorVersion) {
this(majorVersion, minorVersion, -1, null, null);
}
/**
* @since 0.10.0
*/
public SemanticVersion(int majorVersion) {
this(majorVersion, -1, -1, null, null);
}
public static SemanticVersionBuilder builder() {
return new SemanticVersionBuilder();
}
@Override
public int compareTo(@NotNull Version o) {
if (o instanceof ComplexVersion) {
val result = this.compareTo(((ComplexVersion) o).versions[0]);
if (result != 0) {
return result;
} else if (((ComplexVersion) o).versions.length > 1) {
return 1;
} else {
return 0;
}
} else if (o instanceof SemanticVersion) {
val other = (SemanticVersion) o;
if (majorVersion != other.majorVersion) {
return majorVersion - other.majorVersion;
} else if (minorVersion != other.minorVersion) {
return minorVersion - other.minorVersion;
} else if (patchVersion != other.patchVersion) {
return patchVersion - other.patchVersion;
} else if (!Objects.equals(preRelease, other.preRelease)) {
if (preRelease == null) {
return 1;
} else if (other.preRelease == null) {
return -1;
}
return preRelease.compareTo(other.preRelease);
} else {
return 0;
}
}
return 0;
}
@Override
public String toString() {
// @formatter:off
return majorVersion + (minorVersion < 0 ? "" : "." + minorVersion) +
(patchVersion < 0 ? "" : "." + patchVersion) + (preRelease == null ? "" : "-" + preRelease) +
(build == null ? "" : "+" + build);
// @formatter:on
}
/**
* @since 0.10.0
*/
public static class SemanticVersionBuilder {
private int majorVersion;
private int minorVersion = -1;
private int patchVersion = -1;
private String preRelease;
private String build;
@ApiStatus.Internal
SemanticVersionBuilder() {
}
public SemanticVersionBuilder majorVersion(int majorVersion) {
this.majorVersion = majorVersion;
return this;
}
public SemanticVersionBuilder minorVersion(int minorVersion) {
this.minorVersion = minorVersion;
return this;
}
public SemanticVersionBuilder patchVersion(int patchVersion) {
this.patchVersion = patchVersion;
return this;
}
public SemanticVersionBuilder preRelease(String preRelease) {
this.preRelease = preRelease;
return this;
}
public SemanticVersionBuilder build(String build) {
this.build = build;
return this;
}
public SemanticVersion build() {
return new SemanticVersion(majorVersion, minorVersion, patchVersion, preRelease, build);
}
@Override
public String toString() {
return "SemanticVersion.SemanticVersionBuilder(majorVersion="
+ this.majorVersion
+ ", minorVersion="
+ this.minorVersion
+ ", patchVersion="
+ this.patchVersion
+ ", preRelease="
+ this.preRelease
+ ", build="
+ this.build
+ ")";
}
}
}
@@ -0,0 +1,49 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader.version;
import com.falsepattern.deploader.DependencyLoaderImpl;
public abstract class Version implements Comparable<Version> {
protected Version() {
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Version)) {
return false;
}
return equals((Version) obj);
}
public boolean equals(Version other) {
return compareTo(other) == 0;
}
/**
*
* @since 1.7.0
*/
public static Version parse(String versionString) {
return DependencyLoaderImpl.parseVersion(versionString);
}
}
@@ -0,0 +1,26 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
@ApiStatus.Internal
package com.falsepattern.deploader.version;
import org.jetbrains.annotations.ApiStatus;
@@ -0,0 +1,235 @@
/*
* This file is part of FalsePatternLib.
*
* Copyright (C) 2022-2025 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* FalsePatternLib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* FalsePatternLib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with FalsePatternLib. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.deploader;
import com.gtnewhorizons.retrofuturabootstrap.RfbApiImpl;
import com.gtnewhorizons.retrofuturabootstrap.api.ExtensibleClassLoader;
import org.apache.commons.io.IOUtils;
import net.minecraft.launchwrapper.Launch;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
public final class Stub {
private static final String BLACKBOARD_MARKER = "FPLIB_DEPLOADER";
private static final String BLACKBOARD_RUN_DEPLOADER_MARKER = "FPLIB_RUN_DEPLOADER";
private static boolean rfbDetected = false;
private int version = -1;
private Path path = null;
//Call this from the static initializer of your coremod / RFB coremod
public static void bootstrap(boolean rfb) {
if (rfb) {
rfbDetected = true;
RFBUtil.preinit();
}
Object deploader = Launch.blackboard.get(BLACKBOARD_MARKER);
if (deploader != null) {
return;
}
Stub scanner = new Stub();
@SuppressWarnings("resource")
URLClassLoader cl = classLoader();
for (URL url: cl.getURLs()) {
try {
scanner.scanCandidate(new File(url.toURI()).toPath());
} catch (Exception ignored) {
}
}
Path mcHomeDir = gameDir();
Path mods = mcHomeDir.resolve("mods");
Path mods1710 = mods.resolve("1.7.10");
scanner.scanCandidates(mods);
scanner.scanCandidates(mods1710);
if (scanner.path == null) {
throw new IllegalStateException("Failed to find fplib deploader! Are you sure you bundled it in your jar?");
}
Path homeDir;
String homeDirStr = System.getProperty("minecraft.sharedDataDir");
if (homeDirStr == null) {
homeDirStr = System.getenv("MINECRAFT_SHARED_DATA_DIR");
}
if (homeDirStr == null) {
homeDir = mcHomeDir;
} else {
homeDir = Paths.get(homeDirStr);
}
Path libDir = homeDir.resolve("falsepattern");
if (!Files.exists(libDir)) {
try {
Files.createDirectories(libDir);
} catch (IOException e) {
throw new RuntimeException("Failed to create directory " + libDir, e);
}
}
Path deploaderFile = libDir.resolve("fplib_deploader.jar");
if (Files.exists(deploaderFile)) {
try {
Files.delete(deploaderFile);
} catch (IOException ignored) {
}
}
try (OutputStream out = Files.newOutputStream(deploaderFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
JarFile jarIn = new JarFile(scanner.path.toFile())) {
JarEntry theEntry = jarIn.getJarEntry("fplib_deploader.jar");
IOUtils.copy(jarIn.getInputStream(theEntry), out);
} catch (IOException e) {
throw new RuntimeException("Failed to write deploader jar file!", e);
}
try {
addURLToClassPath(deploaderFile.toUri().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException("Failed to add deploader to classpath!", e);
}
try {
Class<?> bootstrap = cl.loadClass("com.falsepattern.deploader.Bootstrap");
Method bootstrapMethod = bootstrap.getDeclaredMethod("bootstrap", boolean.class, Path.class);
bootstrapMethod.invoke(null, rfb, mcHomeDir);
Method runDepLoaderMethod = bootstrap.getDeclaredMethod("runDepLoader");
Launch.blackboard.put(BLACKBOARD_MARKER, bootstrap);
Launch.blackboard.put(BLACKBOARD_RUN_DEPLOADER_MARKER, runDepLoaderMethod);
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to load deploader bootstrap class!", e);
}
}
private void scanCandidates(Path dir) {
if (!Files.exists(dir) || !Files.isDirectory(dir))
return;
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
stream.forEach(this::scanCandidate);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private void scanCandidate(Path file) {
if (Files.isRegularFile(file) && file.getFileName().toString().endsWith(".jar")) {
try(JarFile jarFile = new JarFile(file.toFile())) {
JarEntry entry = jarFile.getJarEntry("fplib_deploader.jar");
if (entry != null) {
JarInputStream jarInput = new JarInputStream(jarFile.getInputStream(entry));
while (jarInput.getManifest() == null) {
jarInput.getNextJarEntry();
}
String version = jarInput.getManifest().getMainAttributes().getValue("FPLib-Deploader-Version");
if (version != null) {
int versionInt = Integer.parseInt(version);
if (versionInt > this.version) {
this.version = versionInt;
this.path = file;
}
}
}
} catch (Exception ignored) {}
}
}
public static void runDepLoader() {
Object runDepLoader = Launch.blackboard.get(BLACKBOARD_RUN_DEPLOADER_MARKER);
if (runDepLoader == null) {
throw new IllegalStateException("Tried to call runDepLoader without calling bootstrap() first!");
}
try {
((Method)runDepLoader).invoke(null);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Could not run FalsePatternLib deploader!", e);
}
}
public static void addURLToClassPath(URL url) {
if (rfbDetected) {
RFBUtil.addURLToClassPath(url);
} else {
LaunchWrapperUtil.addURLToClassPath(url);
}
}
private static URLClassLoader classLoader() {
if (rfbDetected) {
return RFBUtil.classLoader();
} else {
return LaunchWrapperUtil.classLoader();
}
}
public static Path gameDir() {
if (rfbDetected) {
return RFBUtil.gameDir();
} else {
return LaunchWrapperUtil.gameDir();
}
}
private static class RFBUtil {
static void preinit() {
ExtensibleClassLoader loader = RfbApiImpl.INSTANCE.launchClassLoader();
try {
Method exc = loader.getClass()
.getDeclaredMethod("addClassLoaderExclusion", String.class);
exc.invoke(loader, "com.falsepattern.deploader.");
} catch (Exception ignored) {}
}
static void addURLToClassPath(URL url) {
RfbApiImpl.INSTANCE.compatClassLoader().addURL(url);
}
static URLClassLoader classLoader() {
return RfbApiImpl.INSTANCE.compatClassLoader().asURLClassLoader();
}
static Path gameDir() {
return RfbApiImpl.INSTANCE.gameDirectory();
}
}
private static class LaunchWrapperUtil {
static Path gameDir() {
return Launch.minecraftHome == null ? Paths.get(".") : Launch.minecraftHome.toPath();
}
static void addURLToClassPath(URL url) {
Launch.classLoader.addURL(url);
}
static URLClassLoader classLoader() {
return Launch.classLoader;
}
}
}
@@ -23,6 +23,7 @@ package com.falsepattern.lib.dependencies;
import lombok.NonNull;
import lombok.val;
import org.jetbrains.annotations.ApiStatus;
import java.util.Arrays;
import java.util.stream.Collectors;
@@ -36,6 +37,16 @@ public class ComplexVersion extends Version {
System.arraycopy(subVersions, 0, this.versions, 1, subVersions.length);
}
@ApiStatus.Internal
public ComplexVersion(Version[] versions) {
this.versions = versions;
}
@ApiStatus.Internal
public Version[] versionsRaw() {
return this.versions;
}
@Override
public int compareTo(@NonNull Version o) {
if (o instanceof ComplexVersion) {
@@ -22,19 +22,11 @@
package com.falsepattern.lib.internal;
import com.falsepattern.lib.internal.asm.PreShare;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.val;
import net.minecraft.launchwrapper.Launch;
import java.io.IOException;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class Share {
public static final boolean DEV_ENV = PreShare.devEnv();
public static final boolean CLIENT = PreShare.client();
public static boolean EARLY_INIT_DONE = false;
}
@@ -21,10 +21,9 @@
*/
package com.falsepattern.lib.internal.asm;
import com.falsepattern.deploader.Stub;
import com.falsepattern.lib.internal.FPLog;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.impl.dependencies.DependencyLoaderImpl;
import com.falsepattern.lib.internal.impl.dependencies.LetsEncryptHelper;
import com.falsepattern.lib.internal.logging.CrashImprover;
import com.falsepattern.lib.internal.logging.NotEnoughVerbosity;
import com.falsepattern.lib.mapping.MappingManager;
@@ -36,12 +35,10 @@ import lombok.val;
import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.Name;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.SortingIndex;
import cpw.mods.fml.relauncher.Side;
import java.util.List;
import java.util.Map;
@@ -58,9 +55,7 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
private static boolean obfuscated;
static {
PreShare.initDevState(Launch.classLoader.findResource("net/minecraft/world/World.class") != null);
PreShare.initClientState(FMLLaunchHandler.side() == Side.CLIENT);
LetsEncryptHelper.replaceSSLContext();
Stub.bootstrap(false);
FPLog.LOG.info("Removing skill issues...");
try {
Class.forName("thermos.Thermos");
@@ -71,7 +66,7 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
//Scan for dependencies now
FPLog.LOG.info("Scanning for deps...");
long start = System.nanoTime();
DependencyLoaderImpl.executeDependencyLoading();
Stub.runDepLoader();
long end = System.nanoTime();
FPLog.LOG.info("Scanned in " + (end - start) / 1000000 + "ms");
//Initializing the rest
@@ -22,15 +22,11 @@
package com.falsepattern.lib.internal.asm;
import com.falsepattern.lib.internal.core.LowLevelCallMultiplexer;
import com.falsepattern.lib.internal.impl.dependencies.DependencyLoaderImpl;
import com.falsepattern.lib.internal.impl.dependencies.LetsEncryptHelper;
import com.falsepattern.deploader.Stub;
import com.gtnewhorizons.retrofuturabootstrap.RfbApiImpl;
import com.gtnewhorizons.retrofuturabootstrap.api.RfbPlugin;
import lombok.val;
import java.net.URLClassLoader;
public class RFBLoadingPlugin implements RfbPlugin {
static {
val loader = RfbApiImpl.INSTANCE.launchClassLoader();
@@ -47,11 +43,7 @@ public class RFBLoadingPlugin implements RfbPlugin {
exc.invoke(loader, "com.falsepattern.lib.internal.config.EarlyConfig");
exc.invoke(loader, "com.falsepattern.lib.internal.core.LowLevelCallMultiplexer");
} catch (Exception ignored) {}
PreShare.initDevState(((URLClassLoader)loader).findResource("net/minecraft/world/World.class") != null);
PreShare.initClientState(((URLClassLoader)loader).findResource("net/minecraft/client/Minecraft.class") != null ||
((URLClassLoader)loader).findResource("bao.class") != null);
LetsEncryptHelper.replaceSSLContext();
LowLevelCallMultiplexer.rfbDetected();
DependencyLoaderImpl.executeDependencyLoading();
Stub.bootstrap(true);
Stub.runDepLoader();
}
}
File diff suppressed because it is too large. Load diff