Skip to content

Commit 02688ce

Browse files
committed
feat:make fabric loader running on Paper
1 parent 77d7218 commit 02688ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2255
-52
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ subprojects {
4747
repositories {
4848
mavenCentral()
4949
maven(paperMavenPublicUrl)
50+
maven("https://maven.fabricmc.net")
51+
maven("https://libraries.minecraft.net/")
5052
}
5153

5254
extensions.configure<PublishingExtension> {

fabric-loader/build.gradle

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ dependencies {
108108
installer "org.ow2.asm:asm-util:${project.asm_version}"
109109
installer "net.fabricmc:sponge-mixin:${project.mixin_version}"
110110
installerLaunchWrapper "net.minecraft:launchwrapper:1.12"
111+
api("org.sharegov:mjson:1.4.1") {
112+
transitive = false
113+
}
111114

112115
// impl dependencies
113116
include 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6'
@@ -131,11 +134,12 @@ apply from: project(":fabric-loader").file('gradle/installer-json.gradle')
131134
apply from: project(":fabric-loader").file('gradle/launcher.gradle')
132135

133136
processResources {
137+
/*
134138
inputs.property "version", project.version
135139
136140
filesMatching("fabric.mod.json") {
137141
expand "version": inputs.properties.version
138-
}
142+
}*/
139143
}
140144

141145
java {
@@ -186,9 +190,10 @@ tasks.register('fatJar', ShadowJar) {
186190
from getSat4jAbout.destinationDir
187191

188192
inputs.property "archivesName", project.base.archivesName.get()
193+
/*
189194
from("LICENSE") {
190195
rename { "${it}_${inputs.properties.archivesName}" }
191-
}
196+
}*/
192197

193198
manifest {
194199
attributes(

fabric-loader/minecraft/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ dependencies {
1414
compileOnly 'org.slf4j:slf4j-api:1.8.0-beta4'
1515

1616
// launchwrapper + dependencies
17-
compileOnly ('net.minecraft:launchwrapper:1.12') {
18-
transitive = false
19-
}
17+
compileOnly (fileTree('lib/launchwrapper-1.12.jar'))
2018
//implementation 'net.sf.jopt-simple:jopt-simple:5.0.3'
2119

2220
// Unit testing for semver

fabric-loader/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import java.util.Map;
3535
import java.util.Set;
3636

37+
import mjson.Json;
38+
3739
import net.fabricmc.api.EnvType;
3840
import net.fabricmc.loader.api.ObjectShare;
3941
import net.fabricmc.loader.api.VersionParsingException;
@@ -338,7 +340,7 @@ public void initialize(FabricLauncher launcher) {
338340

339341
Log.debug(LogCategory.GAME_PROVIDER, "namespace detection result: game=%s runtime=%s mod-default=%s", gameNs, runtimeNs, config.getDefaultModDistributionNamespace());
340342

341-
if (!gameNs.equals(runtimeNs)) { // game is obfuscated / in another namespace -> remap
343+
if (isObfuscated()) { // game is obfuscated / in another namespace -> remap
342344
Map<String, Path> obfJars = new HashMap<>(3);
343345
String[] names = new String[gameJars.size()];
344346

@@ -460,6 +462,10 @@ public GameTransformer getEntrypointTransformer() {
460462
return transformer;
461463
}
462464

465+
public boolean isObfuscated() {
466+
return false; // generally no...
467+
}
468+
463469
@Override
464470
public boolean canOpenErrorGui() {
465471
if (arguments == null || envType == EnvType.CLIENT) {
@@ -491,6 +497,32 @@ public void unlockClassPath(FabricLauncher launcher) {
491497
for (Path lib : miscGameLibraries) {
492498
launcher.addToClassPath(lib);
493499
}
500+
Set<Path> loadedPaths = new HashSet<>();
501+
Json.read(System.getProperty("banner.libraries")).asJsonList().stream()
502+
.map(Json::asString)
503+
.map(Paths::get)
504+
.filter(path -> {
505+
String fileName = path.getFileName().toString().toLowerCase();
506+
return !fileName.contains("asm")
507+
&& !fileName.matches("asm-\\d+\\.jar");
508+
})
509+
.filter(path -> {
510+
try {
511+
Path absPath = path.toAbsolutePath();
512+
return !loadedPaths.contains(absPath);
513+
} catch (Exception e) {
514+
throw new RuntimeException(e);
515+
}
516+
})
517+
.forEach(path -> {
518+
try {
519+
Path absPath = path.toAbsolutePath();
520+
launcher.addToClassPath(path);
521+
loadedPaths.add(absPath);
522+
} catch (Exception e) {
523+
throw new RuntimeException(e);
524+
}
525+
});
494526
}
495527

496528
@Override

fabric-loader/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/patch/EntrypointPatch.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void process(FabricLauncher launcher, Function<String, ClassNode> classSo
107107

108108
if (gameEntrypoint == null) {
109109
// main method searches
110-
MethodNode mainMethod = findMethod(mainClass, (method) -> method.name.equals("main") && method.desc.equals("([Ljava/lang/String;)V") && isPublicStatic(method.access));
110+
MethodNode mainMethod = findMethod(mainClass, (method) -> method.name.equals("main") && method.desc.equals("(Ljoptsimple/OptionSet;)V") && isPublicStatic(method.access)); // NeoTenet - change main method
111111

112112
if (mainMethod == null) {
113113
throw new RuntimeException("Could not find main method in " + entrypoint + "!");
@@ -310,7 +310,7 @@ public void process(FabricLauncher launcher, Function<String, ClassNode> classSo
310310
}
311311
}
312312
} else {
313-
gameMethod = findMethod(mainClass, (method) -> method.name.equals("main") && method.desc.equals("([Ljava/lang/String;)V") && isPublicStatic(method.access));
313+
gameMethod = findMethod(mainClass, (method) -> method.name.equals("main") && method.desc.equals("(Ljoptsimple/OptionSet;)V") && isPublicStatic(method.access)); // NeoTenet - change main method
314314
}
315315

316316
if (gameMethod == null) {
@@ -362,7 +362,7 @@ public void process(FabricLauncher launcher, Function<String, ClassNode> classSo
362362
// If we do not find this, then we are certain this is 20w22a.
363363
MethodNode serverStartMethod = findMethod(mainClass, method -> {
364364
if ((method.access & Opcodes.ACC_SYNTHETIC) == 0 // reject non-synthetic
365-
|| method.name.equals("main") && method.desc.equals("([Ljava/lang/String;)V") // reject main method (theoretically superfluous now)
365+
|| method.name.equals("main") && method.desc.equals("(Ljoptsimple/OptionSet;)V") // reject main method (theoretically superfluous now)
366366
|| VERSION_25w14craftmine.test(gameVersion) && method.parameters.size() < 10) { // reject problematic extra methods
367367
return false;
368368
}
@@ -453,7 +453,8 @@ public void process(FabricLauncher launcher, Function<String, ClassNode> classSo
453453
return false;
454454
}
455455

456-
return constructorType.getArgumentTypes()[0].getDescriptor().equals("Ljava/lang/Thread;");
456+
return constructorType.getArgumentTypes()[0].getDescriptor().equals("Ljoptsimple/OptionSet;") && constructorType.getArgumentTypes()[2].getDescriptor().equals("Ljava/lang/Thread;")
457+
|| constructorType.getArgumentTypes()[0].getDescriptor().equals("Ljoptsimple/OptionSet;") && constructorType.getArgumentTypes()[3].getDescriptor().equals("Ljava/lang/Thread;");
457458
}
458459

459460
return false;

fabric-loader/src/main/resources/fabric-installer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
"sha512": "cd4f82589e0acc801618e4f55de2e7b85718d30cf5a7d2e5ead383dcdc2689a934abea37b81f5a7c508d9f7fc9ceb2e8ae5c8e4e958537ebb80b621814b099fb",
5252
"size": 94565
5353
},
54+
{
55+
"name": "org.sharegov:mjson:1.4.1",
56+
"url": "https://repo.maven.apache.org/maven2/"
57+
},
5458
{
5559
"name": "net.fabricmc:sponge-mixin:0.17.0+mixin.0.8.7",
5660
"url": "https://maven.fabricmc.net/",
@@ -80,4 +84,4 @@
8084
"client": "net.fabricmc.loader.impl.launch.knot.KnotClient",
8185
"server": "net.fabricmc.loader.impl.launch.knot.KnotServer"
8286
}
83-
}
87+
}

fabric-loader/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"schemaVersion": 1,
33
"id": "fabricloader",
44
"name": "Fabric Loader",
5-
"version": "${version}",
5+
"version": "0.18.4",
66
"environment": "*",
77
"description": "The base mod loader.",
88
"contact": {

paperclip/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tasks.jar {
2121

2222
//from(zipTree(java6Jar.map { it.outputs.files.singleFile }))
2323
from(zipTree(java17Jar.map { it.outputs.files.singleFile }))
24+
from(project(":fabric-loader").tasks.named("fatJar").map { it.outputs.files.singleFile })
2425

2526
manifest {
2627
attributes(

paperclip/java17/build.gradle.kts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
plugins {
22
java
3-
id("io.github.goooler.shadow") version "8.1.7"
3+
id("com.gradleup.shadow") version "9.2.0"
4+
//id("com.github.johnrengelman.shadow") version "8.1.1"
5+
}
6+
7+
configurations.all {
8+
resolutionStrategy {
9+
force("org.ow2.asm:asm:9.4")
10+
force("org.ow2.asm:asm-tree:9.4")
11+
force("org.ow2.asm:asm-commons:9.4")
12+
force("org.ow2.asm:asm-analysis:9.4")
13+
force("org.ow2.asm:asm-util:9.4")
14+
15+
exclude("org.objectweb.asm", "asm")
16+
}
417
}
518

619
java {
@@ -21,14 +34,33 @@ repositories {
2134

2235
dependencies {
2336
implementation("io.sigpipe:jbsdiff:1.0")
37+
implementation("net.fabricmc:lorenz-tiny:4.0.2") // mapping generation
38+
implementation("org.cadixdev:lorenz-io-proguard:0.5.7") // mojmap reading
39+
implementation("org.sharegov:mjson:1.4.1") {
40+
isTransitive = false
41+
}
2442
}
2543

2644
tasks.shadowJar {
2745
val prefix = "paperclip.libs"
28-
listOf("org.apache", "org.tukaani", "io.sigpipe").forEach { pack ->
46+
listOf("org.apache", "org.tukaani", "io.sigpipe", "mjson").forEach { pack ->
2947
relocate(pack, "$prefix.$pack")
3048
}
3149

3250
exclude("META-INF/LICENSE.txt")
3351
exclude("META-INF/NOTICE.txt")
52+
relocate("org.objectweb.asm", "org.teneted.shadowed.asm")
3453
}
54+
55+
/*
56+
tasks.processResources {
57+
inputs.property("gameVersion", rootProject.property("gameVersion"))
58+
inputs.property("bannerVersion", rootProject.property("bannerVersion"))
59+
/*
60+
filesMatching("banner-install.properties") {
61+
expand(
62+
Pair("gameVersion", rootProject.property("gameVersion")),
63+
Pair("bannerVersion", rootProject.property("bannerVersion"))
64+
)
65+
}*/
66+
}*/

0 commit comments

Comments
 (0)