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

Support split client/server intermediary for old Minecraft versions #912

Merged
merged 11 commits into from
Jul 9, 2024
Merged
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dependencies {
// impl dependencies
include 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6'
include 'org.ow2.sat4j:org.ow2.sat4j.pb:2.3.6'
include "net.fabricmc:tiny-remapper:0.10.1"
include "net.fabricmc:tiny-remapper:0.10.2"
include "net.fabricmc:access-widener:2.1.0"
include ('net.fabricmc:mapping-io:0.5.0') {
// Mapping-io depends on ASM, dont bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.ObjectShare;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
import net.fabricmc.loader.api.metadata.ModDependency;
import net.fabricmc.loader.api.metadata.version.VersionPredicate;
import net.fabricmc.loader.impl.FabricLoaderImpl;
import net.fabricmc.loader.impl.FormattedException;
import net.fabricmc.loader.impl.game.GameProvider;
Expand Down Expand Up @@ -318,10 +320,22 @@ public void initialize(FabricLauncher launcher) {
obfJars.put("realms", realmsJar);
}

String sourceNamespace = "official";

try {
VersionPredicate mergedVersionPredicate = VersionPredicate.parse(">=1.3");

if (!mergedVersionPredicate.test(Version.parse(getNormalizedGameVersion()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a system property to enable (or disable?)? You should still be able to easily set when installing loader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a system property for "merged intermediaries" or for the source namespace?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its important for there to still be a way to still be able to use the previous "merged" intermediaries on these older versions. Another option could be to just check what source namespaces are present in the current mapping set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should be the default then? previous or new "merged"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could probably just check the namespaces, if it has official then use that, if not use one of the others. Removes the need for the version comparision as well.

sourceNamespace = envType == EnvType.CLIENT ? "clientOfficial" : "serverOfficial";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Leaving a comment, as requested by @thecatcore) Treating an enum value as a boolean feels wrong, even if it will always realistically be one or the other.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case it's fine, even if strictly something like a switch statement would be better. I don't see that enum getting another value.

}
} catch (VersionParsingException ignored) {
Log.warn(LogCategory.GAME_PROVIDER, "Failed to determine source namespace for remapping, defaulting to 'official'...");
}

obfJars = GameProviderHelper.deobfuscate(obfJars,
getGameId(), getNormalizedGameVersion(),
getLaunchDirectory(),
launcher);
launcher, sourceNamespace);

for (int i = 0; i < gameJars.size(); i++) {
Path newJar = obfJars.get(names[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public static final class FindResult {
private static boolean emittedInfo = false;

public static Map<String, Path> deobfuscate(Map<String, Path> inputFileMap, String gameId, String gameVersion, Path gameDir, FabricLauncher launcher) {
return deobfuscate(inputFileMap, gameId, gameVersion, gameDir, launcher, "official");
}

public static Map<String, Path> deobfuscate(Map<String, Path> inputFileMap, String gameId, String gameVersion, Path gameDir, FabricLauncher launcher, String sourceNamespace) {
Log.debug(LogCategory.GAME_REMAP, "Requesting deobfuscation of %s", inputFileMap);

if (launcher.isDevelopment()) { // in-dev is already deobfuscated
Expand Down Expand Up @@ -184,7 +188,7 @@ public static Map<String, Path> deobfuscate(Map<String, Path> inputFileMap, Stri
return inputFileMap;
}

if (!namespaces.contains(targetNamespace)) {
if (!namespaces.contains(targetNamespace) || !namespaces.contains(sourceNamespace)) {
Log.debug(LogCategory.GAME_REMAP, "Missing namespace in mappings, using input files");
return inputFileMap;
}
Expand Down Expand Up @@ -239,7 +243,7 @@ public static Map<String, Path> deobfuscate(Map<String, Path> inputFileMap, Stri

try {
Files.createDirectories(deobfJarDir);
deobfuscate0(inputFiles, outputFiles, tmpFiles, mappingConfig.getMappings(), targetNamespace, launcher);
deobfuscate0(inputFiles, outputFiles, tmpFiles, mappingConfig.getMappings(), sourceNamespace, targetNamespace, launcher);
} catch (IOException e) {
throw new RuntimeException("error remapping game jars "+inputFiles, e);
}
Expand All @@ -266,9 +270,9 @@ private static Path getDeobfJarDir(Path gameDir, String gameId, String gameVersi
return ret.resolve(versionDirName.toString().replaceAll("[^\\w\\-\\. ]+", "_"));
}

private static void deobfuscate0(List<Path> inputFiles, List<Path> outputFiles, List<Path> tmpFiles, MappingTree mappings, String targetNamespace, FabricLauncher launcher) throws IOException {
private static void deobfuscate0(List<Path> inputFiles, List<Path> outputFiles, List<Path> tmpFiles, MappingTree mappings, String sourceNamespace, String targetNamespace, FabricLauncher launcher) throws IOException {
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyRemapperMappingsHelper.create(mappings, "official", targetNamespace))
.withMappings(TinyRemapperMappingsHelper.create(mappings, sourceNamespace, targetNamespace))
.rebuildSourceFilenames(true)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,12 @@

import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.tinyremapper.IMappingProvider;
import net.fabricmc.tinyremapper.TinyUtils;

public class TinyRemapperMappingsHelper {
private TinyRemapperMappingsHelper() { }

private static IMappingProvider.Member memberOf(String className, String memberName, String descriptor) {
return new IMappingProvider.Member(className, memberName, descriptor);
}

public static IMappingProvider create(MappingTree mappings, String from, String to) {
return (acceptor) -> {
final int fromId = mappings.getNamespaceId(from);
final int toId = mappings.getNamespaceId(to);

for (MappingTree.ClassMapping classDef : mappings.getClasses()) {
final String className = classDef.getName(fromId);
String dstName = classDef.getName(toId);

if (dstName == null) {
dstName = className;
}

acceptor.acceptClass(className, dstName);

for (MappingTree.FieldMapping field : classDef.getFields()) {
acceptor.acceptField(memberOf(className, field.getName(fromId), field.getDesc(fromId)), field.getName(toId));
}

for (MappingTree.MethodMapping method : classDef.getMethods()) {
IMappingProvider.Member methodIdentifier = memberOf(className, method.getName(fromId), method.getDesc(fromId));
acceptor.acceptMethod(methodIdentifier, method.getName(toId));
}
}
};
return TinyUtils.createMappingProvider(mappings, from, to);
}
}
Loading