diff --git a/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java b/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java index 2410cbd90..cd481afb7 100644 --- a/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java +++ b/minecraft/src/main/java/net/fabricmc/loader/impl/game/minecraft/MinecraftGameProvider.java @@ -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; @@ -318,10 +319,19 @@ public void initialize(FabricLauncher launcher) { obfJars.put("realms", realmsJar); } + String sourceNamespace = "official"; + + MappingConfiguration mappingConfig = launcher.getMappingConfiguration(); + List 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]); diff --git a/src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java b/src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java index fdf5cadd8..dd3ace119 100644 --- a/src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java +++ b/src/main/java/net/fabricmc/loader/impl/discovery/RuntimeModRemapper.java @@ -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 { @@ -76,7 +76,7 @@ public static void remap(Collection 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(); diff --git a/src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java b/src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java index 0e724ef1c..22c90b9dc 100644 --- a/src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java +++ b/src/main/java/net/fabricmc/loader/impl/game/GameProviderHelper.java @@ -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() { } @@ -156,6 +156,10 @@ public static final class FindResult { private static boolean emittedInfo = false; public static Map deobfuscate(Map inputFileMap, String gameId, String gameVersion, Path gameDir, FabricLauncher launcher) { + return deobfuscate(inputFileMap, gameId, gameVersion, gameDir, launcher, "official"); + } + + public static Map deobfuscate(Map 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 @@ -184,7 +188,7 @@ public static Map deobfuscate(Map 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; } @@ -239,7 +243,7 @@ public static Map deobfuscate(Map 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); } @@ -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 inputFiles, List outputFiles, List tmpFiles, MappingTree mappings, String targetNamespace, FabricLauncher launcher) throws IOException { + private static void deobfuscate0(List inputFiles, List outputFiles, List 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(); diff --git a/src/main/java/net/fabricmc/loader/impl/util/mappings/TinyRemapperMappingsHelper.java b/src/main/java/net/fabricmc/loader/impl/util/mappings/TinyRemapperMappingsHelper.java deleted file mode 100644 index d8d012cee..000000000 --- a/src/main/java/net/fabricmc/loader/impl/util/mappings/TinyRemapperMappingsHelper.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.fabricmc.loader.impl.util.mappings; - -import net.fabricmc.mappingio.tree.MappingTree; -import net.fabricmc.tinyremapper.IMappingProvider; - -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)); - } - } - }; - } -}