Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FG2 Support #63

Open
wants to merge 29 commits into
base: dev/0.10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fd61c8f
Experimental FG2 Support
wagyourtail Dec 10, 2021
76051bb
fix try/catch for srg
wagyourtail Dec 10, 2021
8efcf91
still need to package pack200 somehow...
wagyourtail Dec 10, 2021
ccb215d
"working" (wrong checksum)
wagyourtail Dec 11, 2021
a4e9363
closer now, still some wrong checksums...
wagyourtail Dec 11, 2021
7002312
switch to non-dev binpatches, now it wrong checksums in a different plac
wagyourtail Dec 11, 2021
3e6f79f
binpatches apply, now have to fix remapping
wagyourtail Dec 11, 2021
7940be6
merge and transform to actually be srg
wagyourtail Dec 11, 2021
2500e53
not needed anymore
wagyourtail Dec 11, 2021
47d62bd
fix srg tiny mappings creation
wagyourtail Dec 11, 2021
689eb98
well, it works, cleanup needed
wagyourtail Dec 11, 2021
4d83a45
well, that didn't quite work...
wagyourtail Dec 11, 2021
24ce766
cleanup
wagyourtail Dec 12, 2021
38234ff
fix missing liscenses
wagyourtail Dec 12, 2021
ae9bb93
slightly closer to working dev env
wagyourtail Dec 12, 2021
8023faa
fix checkstyle (except pack200 shade), closer to working dev env
wagyourtail Dec 12, 2021
9e81355
get fg2 dev launching (fix at's)
wagyourtail Dec 12, 2021
e6261e8
deleteIfExists
wagyourtail Dec 12, 2021
9140b5a
fix formatting 2
wagyourtail Dec 12, 2021
fed6b7d
fix formatting minimizing diffs 3rd pass
wagyourtail Dec 12, 2021
7554cf8
instead of else, return early for smaller diff
wagyourtail Dec 12, 2021
b69e85b
cleanup pass 4
wagyourtail Dec 12, 2021
9b0cacb
rearrange to minimize diff in refactored class
wagyourtail Dec 12, 2021
fa9d626
fixes
wagyourtail Dec 12, 2021
c8326f6
WIP Remove pack200
shedaniel Dec 13, 2021
53db9b3
Stub intermediaries
shedaniel Jul 20, 2021
14184d5
Merge remote-tracking branch 'architectury/feature/113' into dev/0.10…
shedaniel Dec 13, 2021
f4d0a19
Remove ServiceLoader
shedaniel Dec 13, 2021
718c0be
remove isForgeAndOfficial stuff from fg2 also remove extra fg2 flag
wagyourtail Dec 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/net/fabricmc/loom/api/ForgeExtensionAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.gradle.api.provider.SetProperty;
import org.jetbrains.annotations.ApiStatus;

import net.fabricmc.loom.configuration.providers.forge.fg2.Pack200Provider;

/**
* This is the forge extension api available exposed to build scripts.
*/
Expand Down Expand Up @@ -148,4 +150,6 @@ interface DataGenConsumer {
* @see ForgeLocalMod
*/
NamedDomainObjectContainer<ForgeLocalMod> getLocalMods();

Property<Pack200Provider> getPack200Provider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,6 @@ default void addTaskBeforeRun(String task) {
ForgeExtensionAPI getForge();

void forge(Action<ForgeExtensionAPI> action);

Property<Boolean> getStubIntermediaries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public static void configureCompile(Project p) {
if (extension.isForge()) {
dependencyManager.addProvider(new ForgeProvider(project));
dependencyManager.addProvider(new ForgeUserdevProvider(project));
dependencyManager.addProvider(new ForgeUniversalProvider(project));
}

if (extension.shouldGenerateSrgTiny()) {
Expand All @@ -200,7 +201,6 @@ public static void configureCompile(Project p) {
if (extension.isForge()) {
dependencyManager.addProvider(new McpConfigProvider(project));
dependencyManager.addProvider(new PatchProvider(project));
dependencyManager.addProvider(new ForgeUniversalProvider(project));
}

dependencyManager.addProvider(extension.isForge() ? new FieldMigratedMappingsProvider(project) : new MappingsProviderImpl(project));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulation
}

addDependency(Constants.Dependencies.DEV_LAUNCH_INJECTOR + Constants.Dependencies.Versions.DEV_LAUNCH_INJECTOR, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES);
addDependency(Constants.Dependencies.TERMINAL_CONSOLE_APPENDER + Constants.Dependencies.Versions.TERMINAL_CONSOLE_APPENDER, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES);

if (!getExtension().isForge() || !getExtension().getForgeProvider().isFG2()) {
addDependency(Constants.Dependencies.TERMINAL_CONSOLE_APPENDER + Constants.Dependencies.Versions.TERMINAL_CONSOLE_APPENDER, Constants.Configurations.LOOM_DEVELOPMENT_DEPENDENCIES);
}

addDependency(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS, JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME);

if (getExtension().isForge()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomGradlePlugin;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.configuration.providers.forge.fg3.MinecraftPatchedProviderFG3;
import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl;
import net.fabricmc.loom.util.FileSystemUtil;
import net.fabricmc.loom.util.ThreadingUtils;
Expand Down Expand Up @@ -116,7 +117,7 @@ public void manipulateMappings(Path mappingsJar) throws IOException {
if (getExtension().shouldGenerateSrgTiny()) {
if (Files.notExists(rawTinyMappingsWithSrg) || isRefreshDeps()) {
// Merge tiny mappings with srg
SrgMerger.mergeSrg(getProject().getLogger(), getExtension().getMappingsProvider()::getMojmapSrgFileIfPossible, getRawSrgFile(), rawTinyMappings, rawTinyMappingsWithSrg, true);
SrgMerger.mergeSrg(getProject().getLogger(), getExtension().getMappingsProvider()::getMojmapSrgFileIfPossible, getRawSrgFile(), rawTinyMappings, rawTinyMappingsWithSrg, true, extension.getSrgProvider().isLegacy());
}
}

Expand Down Expand Up @@ -203,20 +204,25 @@ public FieldVisitor visitField(int access, String name, String descriptor, Strin

Visitor visitor = new Visitor(Opcodes.ASM9);

for (MinecraftPatchedProvider.Environment environment : MinecraftPatchedProvider.Environment.values()) {
File patchedSrgJar = environment.patchedSrgJar.apply(extension.getMappingsProvider().patchedProvider);
FileSystemUtil.Delegate system = FileSystemUtil.getJarFileSystem(patchedSrgJar, false);
completer.onComplete(value -> system.close());

for (Path fsPath : (Iterable<? extends Path>) Files.walk(system.get().getPath("/"))::iterator) {
if (Files.isRegularFile(fsPath) && fsPath.toString().endsWith(".class")) {
completer.add(() -> {
byte[] bytes = Files.readAllBytes(fsPath);
new ClassReader(bytes).accept(visitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
});
if (extension.getMappingsProvider().patchedProvider instanceof MinecraftPatchedProviderFG3 pp3) {
for (MinecraftPatchedProviderFG3.Environment environment : MinecraftPatchedProviderFG3.Environment.values()) {
File patchedSrgJar = environment.patchedSrgJar.apply(pp3);
FileSystemUtil.Delegate system = FileSystemUtil.getJarFileSystem(patchedSrgJar, false);
completer.onComplete(value -> system.close());

for (Path fsPath : (Iterable<? extends Path>) Files.walk(system.get().getPath("/"))::iterator) {
if (Files.isRegularFile(fsPath) && fsPath.toString().endsWith(".class")) {
completer.add(() -> {
byte[] bytes = Files.readAllBytes(fsPath);
new ClassReader(bytes).accept(
visitor,
ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES
);
});
}
}
}
}
} //TODO: DOES FG2 NEED THIS????

completer.complete();
Map<FieldMember, String> migratedFields = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class ForgeProvider extends DependencyProvider {
private File globalCache;
private File projectCache;

private boolean fg2 = false;

public ForgeProvider(Project project) {
super(project);
}
Expand Down Expand Up @@ -75,6 +77,14 @@ public String getTargetConfig() {
return Constants.Configurations.FORGE;
}

public boolean isFG2() {
return fg2;
}

public void setFg2(boolean fg2) {
this.fg2 = fg2;
}

public static final class ForgeVersion {
private final String combined;
private final String minecraftVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -99,14 +100,73 @@ public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulation
Files.copy(resolved.toPath(), userdevJar.toPath(), StandardCopyOption.REPLACE_EXISTING);

try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:" + resolved.toURI()), ImmutableMap.of("create", false))) {
Files.copy(fs.getPath("config.json"), configJson, StandardCopyOption.REPLACE_EXISTING);
if (Files.exists(fs.getPath("config.json"))) {
//fg3+
Files.copy(fs.getPath("config.json"), configJson, StandardCopyOption.REPLACE_EXISTING);
} else {
//fg2
Files.copy(fs.getPath("dev.json"), configJson, StandardCopyOption.REPLACE_EXISTING);
}
}
}

try (Reader reader = Files.newBufferedReader(configJson)) {
json = new Gson().fromJson(reader, JsonObject.class);
}

boolean fg2 = !json.has("mcp");
getExtension().getForgeProvider().setFg2(fg2);

if (fg2) {
getProject().getLogger().info("FG2 Userdev, using default mcp_config/universal...");

String defaultMCPPath = "de.oceanlabs.mcp:mcp:" + getExtension().getMinecraftProvider().minecraftVersion() + ":srg@zip";
String defaultUniversalPath = "net.minecraftforge:forge:" + dependency.getResolvedVersion() + ":universal";

getProject().getLogger().info("Using default MCP path: " + defaultMCPPath);
getProject().getLogger().info("Using default Universal path: " + defaultUniversalPath);

addDependency(defaultMCPPath, Constants.Configurations.MCP_CONFIG);
addDependency(defaultMCPPath, Constants.Configurations.SRG);
addDependency(defaultUniversalPath, Constants.Configurations.FORGE_UNIVERSAL);

for (JsonElement lib : json.getAsJsonArray("libraries")) {
JsonObject libObj = lib.getAsJsonObject();

Dependency dep = addDependency(libObj.get("name").getAsString(), Constants.Configurations.FORGE_DEPENDENCIES);

if (libObj.get("name").getAsString().split(":").length < 4) {
((ModuleDependency) dep).attributes(attributes -> {
attributes.attribute(transformed, true);
});
}
}

for (String name : new String[] {"client", "server"}) {
LaunchProviderSettings launchSettings = getExtension().getLaunchConfigs().findByName(name);
RunConfigSettings settings = getExtension().getRunConfigs().findByName(name);

if (launchSettings != null) {
launchSettings.evaluateLater(() -> {
launchSettings.arg(Arrays.stream(json.get("minecraftArguments").getAsString().split(" ")).map(this::processTemplates).collect(Collectors.toList()));

// add missing args
launchSettings.arg("--accessToken", "FML");
});
}

if (settings != null) {
settings.evaluateLater(() -> {
settings.defaultMainClass("net.minecraft.launchwrapper.Launch");
});
}
}

return;
}

getProject().getLogger().info("FG3+ Userdev");

addDependency(json.get("mcp").getAsString(), Constants.Configurations.MCP_CONFIG);
addDependency(json.get("mcp").getAsString(), Constants.Configurations.SRG);
addDependency(json.get("universal").getAsString(), Constants.Configurations.FORGE_UNIVERSAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ public void provide(DependencyInfo dependency, Consumer<Runnable> postPopulation

Path mcpZip = dependency.resolveFile().orElseThrow(() -> new RuntimeException("Could not resolve MCPConfig")).toPath();

if (getExtension().getForgeProvider().isFG2()) {
official = false;
mappingsPath = ZipUtils.contains(mcpZip, "joined.srg") ? "joined.srg" : "config/joined.tsrg";
remapAction = null;

if (!Files.exists(mcp) || isRefreshDeps()) {
Files.copy(mcpZip, mcp, StandardCopyOption.REPLACE_EXISTING);
}

return;
}

if (!Files.exists(mcp) || !Files.exists(configJson) || isRefreshDeps()) {
Files.copy(mcpZip, mcp, StandardCopyOption.REPLACE_EXISTING);
Files.write(configJson, ZipUtils.unpack(mcp, "config.json"), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
Expand Down
Loading