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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.fabricmc.loader.impl.game.minecraft.patch.TinyFDPatch;
import net.fabricmc.loader.impl.game.patch.GameTransformer;
import net.fabricmc.loader.impl.launch.FabricLauncher;
import net.fabricmc.loader.impl.launch.MappingConfiguration;
import net.fabricmc.loader.impl.metadata.BuiltinModMetadata;
import net.fabricmc.loader.impl.metadata.ModDependencyImpl;
import net.fabricmc.loader.impl.util.Arguments;
Expand Down Expand Up @@ -318,10 +319,19 @@ public void initialize(FabricLauncher launcher) {
obfJars.put("realms", realmsJar);
}

String sourceNamespace = "official";

MappingConfiguration mappingConfig = launcher.getMappingConfiguration();
List<String> mappingNamespaces = mappingConfig.getNamespaces();

if (mappingNamespaces != null && !mappingNamespaces.contains(sourceNamespace)) {
sourceNamespace = envType == EnvType.CLIENT ? "clientOfficial" : "serverOfficial";
}

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 @@ -50,11 +50,11 @@
import net.fabricmc.loader.impl.util.SystemProperties;
import net.fabricmc.loader.impl.util.log.Log;
import net.fabricmc.loader.impl.util.log.LogCategory;
import net.fabricmc.loader.impl.util.mappings.TinyRemapperMappingsHelper;
import net.fabricmc.tinyremapper.InputTag;
import net.fabricmc.tinyremapper.NonClassCopyMode;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import net.fabricmc.tinyremapper.extension.mixin.MixinExtension;

public final class RuntimeModRemapper {
Expand All @@ -76,7 +76,7 @@ public static void remap(Collection<ModCandidate> modCandidates, Path tmpDir, Pa
FabricLauncher launcher = FabricLauncherBase.getLauncher();

TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyRemapperMappingsHelper.create(launcher.getMappingConfiguration().getMappings(), "intermediary", launcher.getTargetNamespace()))
.withMappings(TinyUtils.createMappingProvider(launcher.getMappingConfiguration().getMappings(), "intermediary", launcher.getTargetNamespace()))
.renameInvalidLocals(false)
.extension(new MixinExtension(remapMixins::contains))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import net.fabricmc.loader.impl.util.UrlUtil;
import net.fabricmc.loader.impl.util.log.Log;
import net.fabricmc.loader.impl.util.log.LogCategory;
import net.fabricmc.loader.impl.util.mappings.TinyRemapperMappingsHelper;
import net.fabricmc.mappingio.tree.MappingTree;
import net.fabricmc.tinyremapper.InputTag;
import net.fabricmc.tinyremapper.NonClassCopyMode;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;

public final class GameProviderHelper {
private GameProviderHelper() { }
Expand Down 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(TinyUtils.createMappingProvider(mappings, sourceNamespace, targetNamespace))
.rebuildSourceFilenames(true)
.build();

Expand Down

This file was deleted.

Loading